Compare commits

..

17 Commits

Author SHA1 Message Date
Guido D'Orsi
dda9672dcb Merge pull request #1680 from garden-co/changeset-release/main
Version Packages
2025-03-24 13:54:19 +01:00
github-actions[bot]
a86cd0e74e Version Packages 2025-03-24 12:45:13 +00:00
Guido D'Orsi
95e84a2ca7 Merge pull request #1720 from garden-co/image-targetWidth
feat: add targetWidth option to ProgressiveImage
2025-03-24 13:42:19 +01:00
Guido D'Orsi
e7c85b7575 feat: add targetWidth option to ProgressiveImage 2025-03-24 13:13:45 +01:00
Guido D'Orsi
8ad57f9d50 Merge pull request #1471 from garden-co/jazz-739-handle-reloading-page-while-image-upload-is-in-progress
jazz-739-handle-reloading-page-while-image-upload-is-in-progress
2025-03-24 12:30:47 +01:00
Benjamin S. Leveritt
4a0f70692f Update healthy-peas-kick.md 2025-03-24 11:29:34 +00:00
Guido D'Orsi
51db96e8d0 chore: align the lockfile with main 2025-03-24 12:20:18 +01:00
Guido D'Orsi
4b0b27bde7 Merge remote-tracking branch 'origin/main' into jazz-739-handle-reloading-page-while-image-upload-is-in-progress 2025-03-24 12:19:50 +01:00
Guido D'Orsi
29a177224d test: add a test for createImage 2025-03-24 12:19:12 +01:00
Guido D'Orsi
63ccdaa3b2 chore: remove vitest file 2025-03-24 11:58:26 +01:00
Guido D'Orsi
8ed144e857 chore: changeset 2025-03-24 11:01:54 +01:00
Guido D'Orsi
c9e2ab69bf feat: mark the package as async and remove the setTimeout 2025-03-24 11:00:03 +01:00
Benjamin S. Leveritt
02fe68d207 Adds equality check to sessionID comparison 2025-03-13 14:29:42 +00:00
Benjamin S. Leveritt
0f87cfbbb0 Fixes sort order fallback when madeAt is identical 2025-03-13 13:41:44 +00:00
Guido D'Orsi
cc1eb6da90 Merge pull request #1506 from garden-co/image-upload-ux
Image upload example UX improvement
2025-03-13 08:34:15 +00:00
Benjamin S. Leveritt
f7b91b7ce1 Adds unload notification while uploading 2025-03-13 08:34:15 +00:00
Benjamin S. Leveritt
e2b1247969 Return promise while processing image 2025-03-13 08:34:15 +00:00
144 changed files with 966 additions and 1372 deletions

View File

@@ -1,18 +0,0 @@
---
"jazz-tailwind-demo-auth-starter": patch
"file-share-svelte": patch
"jazz-password-manager": patch
"version-history": patch
"passkey-svelte": patch
"chat-rn-clerk": patch
"jazz-example-music-player": patch
"passphrase": patch
"multiauth": patch
"reactions": patch
"passkey": patch
"clerk": patch
"jazz-example-pets": patch
"jazz-example-todo": patch
---
Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.

View File

@@ -1,5 +0,0 @@
---
"create-jazz-app": patch
---
add directory param to create-jazz-app

View File

@@ -1,6 +0,0 @@
---
"jazz-inspector": patch
"jazz-inspector-app": patch
---
UI and JSON display improvements

View File

@@ -1,6 +0,0 @@
---
"jazz-inspector-app": patch
"jazz-inspector": patch
---
isolate class name hashing on inspector

View File

@@ -1,5 +0,0 @@
---
"jazz-tools": patch
---
Export CoFeedEntry type

View File

@@ -1,5 +1,16 @@
# chat-rn-clerk
## 1.0.87
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-react-native@0.11.6
- jazz-tools@0.11.6
- jazz-react-native-auth-clerk@0.11.6
- jazz-react-native-media-images@0.11.6
## 1.0.86
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "chat-rn-clerk",
"main": "index.js",
"version": "1.0.86",
"version": "1.0.87",
"scripts": {
"build": "expo export -p ios",
"start": "expo start",

View File

@@ -1,5 +1,13 @@
# chat-rn
## 1.0.83
### Patch Changes
- Updated dependencies [e7c85b7]
- jazz-react-native@0.11.6
- jazz-tools@0.11.6
## 1.0.82
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-rn",
"version": "1.0.82",
"version": "1.0.83",
"main": "index.js",
"scripts": {
"build": "expo export -p ios",

View File

@@ -1,5 +1,14 @@
# chat-vue
## 0.0.68
### Patch Changes
- Updated dependencies [e7c85b7]
- jazz-tools@0.11.6
- jazz-vue@0.11.6
- jazz-browser@0.11.6
## 0.0.67
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-vue",
"version": "0.0.67",
"version": "0.0.68",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,18 @@
# jazz-example-chat
## 0.0.165
### Patch Changes
- Updated dependencies [e7c85b7]
- Updated dependencies [09f0a98]
- Updated dependencies [11da4d1]
- Updated dependencies [8ed144e]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-inspector@0.11.6
- jazz-browser-media-images@0.11.6
## 0.0.164
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-chat",
"private": true,
"version": "0.0.164",
"version": "0.0.165",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,15 @@
# minimal-auth-clerk
## 0.0.64
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-react-auth-clerk@0.11.6
## 0.0.63
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "clerk",
"private": true,
"version": "0.0.63",
"version": "0.0.64",
"type": "module",
"scripts": {
"dev": "vite",
@@ -13,7 +13,7 @@
"dependencies": {
"@clerk/clerk-react": "^5.4.1",
"jazz-react": "workspace:*",
"jazz-react-auth-clerk": "workspace:0.11.5",
"jazz-react-auth-clerk": "workspace:0.11.6",
"jazz-tools": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"

View File

@@ -1,5 +1,14 @@
# file-share-svelte
## 0.0.48
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-tools@0.11.6
- jazz-svelte@0.11.6
## 0.0.47
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "file-share-svelte",
"version": "0.0.47",
"version": "0.0.48",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,13 @@
# jazz-tailwind-demo-auth-starter
## 0.0.4
### Patch Changes
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
## 0.0.3
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "filestream",
"private": true,
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,15 @@
# form
## 0.1.6
### Patch Changes
- Updated dependencies [e7c85b7]
- Updated dependencies [8ed144e]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-browser-media-images@0.11.6
## 0.1.5
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "form",
"private": true,
"version": "0.1.5",
"version": "0.1.6",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,15 @@
# image-upload
## 0.0.62
### Patch Changes
- Updated dependencies [e7c85b7]
- Updated dependencies [8ed144e]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-browser-media-images@0.11.6
## 0.0.61
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "image-upload",
"private": true,
"version": "0.0.61",
"version": "0.0.62",
"type": "module",
"scripts": {
"dev": "vite",
@@ -24,6 +24,9 @@
"@vitejs/plugin-react": "^4.3.3",
"globals": "^15.11.0",
"typescript": "~5.6.2",
"vite": "^6.0.11"
"vite": "^6.0.11",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.27",
"tailwindcss": "^3.4.17"
}
}

View File

@@ -3,7 +3,7 @@ import ImageUpload from "./ImageUpload.tsx";
function App() {
return (
<>
<main className="container">
<main className="container py-16">
<ImageUpload />
</main>
</>

View File

@@ -1,60 +1,97 @@
import { createImage } from "jazz-browser-media-images";
import { ProgressiveImg, useAccount } from "jazz-react";
import { ImageDefinition } from "jazz-tools";
import { ChangeEvent, useRef } from "react";
function Image({ image }: { image: ImageDefinition }) {
return (
<ProgressiveImg image={image}>
{({ src }) => <img src={src} />}
</ProgressiveImg>
);
}
import { ChangeEvent, useEffect, useRef, useState } from "react";
export default function ImageUpload() {
const { me } = useAccount();
const [imagePreviewUrl, setImagePreviewUrl] = useState<string | null>(null);
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
if (imagePreviewUrl) {
e.preventDefault();
return "Upload in progress. Are you sure you want to leave?";
}
};
window.addEventListener("beforeunload", handleBeforeUnload);
return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
if (imagePreviewUrl) {
URL.revokeObjectURL(imagePreviewUrl);
}
};
}, [imagePreviewUrl]);
const onImageChange = async (event: ChangeEvent<HTMLInputElement>) => {
if (!me?.profile) return;
const file = event.currentTarget.files?.[0];
if (file) {
me.profile.image = await createImage(file, {
owner: me.profile._owner,
});
const objectUrl = URL.createObjectURL(file);
setImagePreviewUrl(objectUrl);
try {
me.profile.image = await createImage(file, {
owner: me.profile._owner,
});
} catch (error) {
console.error("Error uploading image:", error);
} finally {
URL.revokeObjectURL(objectUrl);
setImagePreviewUrl(null);
}
}
};
const deleteImage = () => {
if (!me?.profile) return;
me.profile.image = null;
};
return (
<>
<div>{me?.profile?.image && <Image image={me.profile.image} />}</div>
if (me?.profile?.image) {
return (
<>
<ProgressiveImg image={me.profile.image}>
{({ src }) => <img alt="" src={src} className="w-full h-auto" />}
</ProgressiveImg>
<div>
{me?.profile?.image ? (
<button type="button" onClick={deleteImage}>
Delete image
</button>
) : (
<div>
<label>Upload image</label>
<input
ref={inputRef}
type="file"
accept="image/png, image/jpeg, image/gif"
onChange={onImageChange}
/>
</div>
)}
<button type="button" onClick={deleteImage} className="mt-5">
Delete image
</button>
</>
);
}
if (imagePreviewUrl) {
return (
<div className="relative">
<p className="z-10 absolute font-semibold text-gray-900 inset-0 flex items-center justify-center">
Uploading image...
</p>
<img
src={imagePreviewUrl}
alt="Preview"
className="opacity-50 w-full h-auto"
/>
</div>
</>
);
}
return (
<div className="flex flex-col gap-3">
<label htmlFor="image">Image</label>
<input
id="image"
name="image"
ref={inputRef}
type="file"
accept="image/png, image/jpeg, image/gif, image/bmp"
onChange={onImageChange}
/>
</div>
);
}

View File

@@ -1,82 +1,3 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
--border-color: #2f2e2d;
}
html,
body,
#root {
height: 100%;
}
body {
margin: 0;
}
button {
border-radius: 8px;
border: 0;
padding: 0.6em 1.2em;
font-weight: 500;
background-color: #1a1a1a;
cursor: pointer;
}
@media (prefers-color-scheme: light) {
:root {
--border-color: #e5e5e5;
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
* {
border-color: var(--border-color);
}
header,
main {
padding: 0.5rem 0;
}
header {
border-bottom: 1px solid var(--border-color);
margin-bottom: 2rem;
}
nav {
display: flex;
align-items: center;
justify-content: space-between;
}
.container {
margin-right: auto;
margin-left: auto;
padding: 2rem 0.75rem;
max-width: 800px;
}
label {
display: block;
margin-bottom: 0.25rem;
}
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@@ -10,14 +10,9 @@ const config: Config = {
DEFAULT: "0.75rem",
sm: "1rem",
},
screens: {
lg: "600px",
xl: "600px",
},
},
},
},
plugins: [],
} as const;
export default config;

View File

@@ -1,5 +1,18 @@
# jazz-example-inspector
## 0.0.115
### Patch Changes
- 09f0a98: UI and JSON display improvements
- 11da4d1: isolate class name hashing on inspector
- Updated dependencies [09f0a98]
- Updated dependencies [11da4d1]
- Updated dependencies [8ed144e]
- jazz-inspector@0.11.6
- cojson@0.11.6
- cojson-transport-ws@0.11.6
## 0.0.114
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-inspector-app",
"private": true,
"version": "0.0.114",
"version": "0.0.115",
"type": "module",
"scripts": {
"dev": "vite",
@@ -13,8 +13,8 @@
"dependencies": {
"jazz-inspector": "workspace:*",
"clsx": "^2.0.0",
"cojson": "workspace:0.11.5",
"cojson-transport-ws": "workspace:0.11.5",
"cojson": "workspace:0.11.6",
"cojson-transport-ws": "workspace:0.11.6",
"hash-slash": "workspace:0.2.2",
"lucide-react": "^0.274.0",
"react": "^18.3.1",

View File

@@ -1,3 +0,0 @@
VITE_CURSOR_FEED_ID=example-cursor-feed-id
VITE_GROUP_ID=co_example-group-id
VITE_OLD_CURSOR_AGE_SECONDS=5

View File

@@ -1,28 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
/test-results/
/playwright-report/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
playwright-report

View File

@@ -1,3 +0,0 @@
# Multi-cursor example
An example app of using Jazz for showing multiple-cursors on a simple canvas.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,16 +0,0 @@
<!doctype html>
<html lang="en" class="h-full">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Jazz | Multi-cursors</title>
</head>
<body class="h-full flex flex-col">
<div id="root" class="align-self-center flex-1"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@@ -1,35 +0,0 @@
{
"name": "multi-cursors",
"private": true,
"version": "0.0.58",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"format-and-lint": "biome check .",
"format-and-lint:fix": "biome check . --write"
},
"dependencies": {
"@react-spring/web": "^9.7.5",
"jazz-react": "workspace:*",
"jazz-tools": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"globals": "^15.11.0",
"is-ci": "^3.0.1",
"postcss": "^8.4.27",
"tailwindcss": "^3.4.17",
"typescript": "~5.6.2",
"vite": "^6.0.11"
}
}

View File

@@ -1,65 +0,0 @@
import { useAccount } from "jazz-react";
import { Group, type ID } from "jazz-tools";
import { useEffect, useState } from "react";
import { Logo } from "./Logo";
import Container from "./components/Container";
import { CursorFeed } from "./schema";
import { getName } from "./utils/getName";
import { loadCursorContainer } from "./utils/loadCursorContainer";
const cursorFeedIDToLoad = import.meta.env.VITE_CURSOR_FEED_ID;
const groupIDToLoad = import.meta.env.VITE_GROUP_ID;
function App() {
const { me } = useAccount();
const [loaded, setLoaded] = useState(false);
const [cursorFeedID, setCursorFeedID] = useState<ID<CursorFeed> | null>(null);
useEffect(() => {
if (!me?.id) return;
const loadCursorFeed = async () => {
const id = await loadCursorContainer(
me,
cursorFeedIDToLoad as ID<CursorFeed>,
groupIDToLoad as ID<Group>,
);
if (id) {
setCursorFeedID(id);
setLoaded(true);
}
};
loadCursorFeed();
}, [me?.id]);
return (
<>
<main className="h-screen">
{loaded && cursorFeedID ? (
<Container cursorFeedID={cursorFeedID} />
) : (
<div>Loading...</div>
)}
</main>
<footer className="fixed bottom-4 right-4 flex items-center gap-4">
<input
type="text"
value={getName(me?.profile?.name, me?.sessionID)}
onChange={(e) => {
if (!me?.profile) return;
me.profile.name = e.target.value;
}}
placeholder="Your name"
className="px-2 py-1 rounded border pointer-events-auto"
autoComplete="off"
maxLength={32}
/>
<div className="pointer-events-none">
<Logo />
</div>
</footer>
</>
);
}
export default App;

View File

@@ -1,21 +0,0 @@
export function Logo() {
return (
<svg
viewBox="0 0 386 146"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="text-black w-48 mx-auto"
>
<path
d="M176.725 33.865H188.275V22.7H176.725V33.865ZM164.9 129.4H172.875C182.72 129.4 188.275 123.9 188.275 114.22V43.6H176.725V109.545C176.725 115.65 173.975 118.51 167.925 118.51H164.9V129.4ZM245.298 53.28C241.613 45.47 233.363 41.95 222.748 41.95C208.998 41.95 200.748 48.44 197.888 58.615L208.613 61.915C210.648 55.315 216.368 52.565 222.638 52.565C231.933 52.565 235.673 56.415 236.058 64.61C226.433 65.93 216.643 67.195 209.768 69.23C200.583 72.145 195.743 77.865 195.743 86.83C195.743 96.51 202.673 104.65 215.818 104.65C225.443 104.65 232.318 101.35 237.213 94.365V103H247.388V66.425C247.388 61.475 247.168 57.185 245.298 53.28ZM217.853 95.245C210.483 95.245 207.128 91.34 207.128 86.72C207.128 82.045 210.593 79.515 215.323 77.92C220.328 76.435 226.983 75.5 235.948 74.18C235.893 76.93 235.673 80.725 234.738 83.475C233.418 89.25 227.643 95.245 217.853 95.245ZM251.22 103H301.545V92.715H269.535L303.195 45.47V43.6H254.3V53.885H284.935L251.22 101.185V103ZM304.815 103H355.14V92.715H323.13L356.79 45.47V43.6H307.895V53.885H338.53L304.815 101.185V103Z"
fill="currentColor"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M136.179 44.8277C136.179 44.8277 136.179 44.8277 136.179 44.8276V21.168C117.931 28.5527 97.9854 32.6192 77.0897 32.6192C65.1466 32.6192 53.5138 31.2908 42.331 28.7737V51.4076C42.331 51.4076 42.331 51.4076 42.331 51.4076V81.1508C41.2955 80.4385 40.1568 79.8458 38.9405 79.3915C36.1732 78.358 33.128 78.0876 30.1902 78.6145C27.2524 79.1414 24.5539 80.4419 22.4358 82.3516C20.3178 84.2613 18.8754 86.6944 18.291 89.3433C17.7066 91.9921 18.0066 94.7377 19.1528 97.2329C20.2991 99.728 22.2403 101.861 24.7308 103.361C27.2214 104.862 30.1495 105.662 33.1448 105.662H33.1455C33.6061 105.662 33.8365 105.662 34.0314 105.659C44.5583 105.449 53.042 96.9656 53.2513 86.4386C53.2534 86.3306 53.2544 86.2116 53.2548 86.0486H53.2552V85.7149L53.2552 85.5521V82.0762L53.2552 53.1993C61.0533 54.2324 69.0092 54.7656 77.0897 54.7656C77.6696 54.7656 78.2489 54.7629 78.8276 54.7574V110.696C77.792 109.983 76.6533 109.391 75.437 108.936C72.6697 107.903 69.6246 107.632 66.6867 108.159C63.7489 108.686 61.0504 109.987 58.9323 111.896C56.8143 113.806 55.3719 116.239 54.7875 118.888C54.2032 121.537 54.5031 124.283 55.6494 126.778C56.7956 129.273 58.7368 131.405 61.2273 132.906C63.7179 134.406 66.646 135.207 69.6414 135.207C70.1024 135.207 70.3329 135.207 70.5279 135.203C81.0548 134.994 89.5385 126.51 89.7478 115.983C89.7517 115.788 89.7517 115.558 89.7517 115.097V111.621L89.7517 54.3266C101.962 53.4768 113.837 51.4075 125.255 48.2397V80.9017C124.219 80.1894 123.081 79.5966 121.864 79.1424C119.097 78.1089 116.052 77.8384 113.114 78.3653C110.176 78.8922 107.478 80.1927 105.36 82.1025C103.242 84.0122 101.799 86.4453 101.215 89.0941C100.631 91.743 100.931 94.4886 102.077 96.9837C103.223 99.4789 105.164 101.612 107.655 103.112C110.145 104.612 113.073 105.413 116.069 105.413C116.53 105.413 116.76 105.413 116.955 105.409C127.482 105.2 135.966 96.7164 136.175 86.1895C136.179 85.9945 136.179 85.764 136.179 85.3029V81.8271L136.179 44.8277Z"
fill="#3313F7"
/>
</svg>
);
}

View File

@@ -1 +0,0 @@
export const apiKey = "jazz-multi-cursors@garden.co";

View File

@@ -1,76 +0,0 @@
import { useAccount } from "jazz-react";
import { CoFeedEntry, co } from "jazz-tools";
import { CursorMoveEvent, useCanvas } from "../hooks/useCanvas";
import { Cursor as CursorType } from "../types";
import { getColor } from "../utils/getColor";
import { getName } from "../utils/getName";
import { CanvasBackground } from "./CanvasBackground";
import { CanvasDemoContent } from "./CanvasDemoContent";
import { Cursor } from "./Cursor";
const OLD_CURSOR_AGE_SECONDS = Number(
import.meta.env.VITE_OLD_CURSOR_AGE_SECONDS,
);
interface CanvasProps {
remoteCursors: CoFeedEntry<co<CursorType>>[];
onCursorMove: (move: CursorMoveEvent) => void;
name: string;
}
function Canvas({ remoteCursors, onCursorMove, name }: CanvasProps) {
const { me } = useAccount();
const {
svgProps,
isDragging,
isMouseOver,
mousePosition,
bgPosition,
dottedGridSize,
} = useCanvas({ onCursorMove });
return (
<svg width="100%" height="100%" {...svgProps}>
<CanvasBackground
bgPosition={bgPosition}
dottedGridSize={dottedGridSize}
/>
<CanvasDemoContent />
{remoteCursors.map((entry) => {
if (
entry.tx.sessionID === me?.sessionID ||
(OLD_CURSOR_AGE_SECONDS &&
entry.madeAt < new Date(Date.now() - 1000 * OLD_CURSOR_AGE_SECONDS))
) {
return null;
}
return (
<Cursor
key={entry.tx.sessionID}
position={entry.value.position}
color={getColor(entry.tx.sessionID)}
isDragging={false}
isRemote={true}
name={getName(entry.by?.profile?.name, entry.tx.sessionID)}
/>
);
})}
{isMouseOver ? (
<Cursor
position={mousePosition}
color="#FF69B4"
isDragging={isDragging}
isRemote={false}
name={name}
/>
) : null}
</svg>
);
}
export default Canvas;

View File

@@ -1,33 +0,0 @@
interface CanvasBackgroundProps {
bgPosition: { x: number; y: number };
dottedGridSize: number;
}
export function CanvasBackground({
bgPosition,
dottedGridSize,
}: CanvasBackgroundProps) {
const bgProps = { x: "-10000", y: "-10000", width: "20000", height: "20000" };
return (
<>
<defs>
<pattern
id="dottedGrid"
width={dottedGridSize}
height={dottedGridSize}
patternUnits="userSpaceOnUse"
patternContentUnits="userSpaceOnUse"
>
<circle cx="20" cy="20" r="2" fill="oklch(0.923 0.003 48.717)" />
</pattern>
</defs>
{/* backgrounds using translate to appear infinite by moving it to visible area */}
<g transform={`translate(${bgPosition.x}, ${bgPosition.y})`}>
<rect {...bgProps} fill="oklch(0.97 0.001 106.424)" />
<rect {...bgProps} fill="url(#dottedGrid)" />
</g>
</>
);
}

View File

@@ -1,19 +0,0 @@
export function CanvasDemoContent() {
return (
<>
<circle cx={0} cy={0} r="200" fill="oklch(0.985 0.001 106.423)" />
<text
x={0}
y={0}
textAnchor="middle"
dominantBaseline="middle"
fontSize="32"
fontFamily="ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace"
fill="#3318F7"
>
Hello, World!
</text>
</>
);
}

View File

@@ -1,30 +0,0 @@
import { useAccount, useCoState } from "jazz-react";
import { ID } from "jazz-tools";
import { CursorFeed } from "../schema";
import { getName } from "../utils/getName";
import Canvas from "./Canvas";
/** A higher order component that wraps the canvas. */
function Container({ cursorFeedID }: { cursorFeedID: ID<CursorFeed> }) {
const { me } = useAccount();
const cursors = useCoState(CursorFeed, cursorFeedID, []);
return (
<Canvas
onCursorMove={(move) => {
if (!(cursors && me)) return;
cursors.push({
position: {
x: move.position.x,
y: move.position.y,
},
});
}}
remoteCursors={Object.values(cursors?.perSession ?? {})}
name={getName(me?.profile?.name, me?.sessionID)}
/>
);
}
export default Container;

View File

@@ -1,64 +0,0 @@
import { animated, to, useSpring } from "@react-spring/web";
interface CursorProps {
position: { x: number; y: number };
color: string;
isDragging: boolean;
isRemote: boolean;
name: string;
}
export function Cursor({
position,
color,
isDragging,
isRemote,
name,
}: CursorProps) {
const springs = useSpring({
x: position.x,
y: position.y,
immediate: !isRemote,
config: {
tension: 170,
friction: 26,
},
});
return (
<animated.g
transform={to(
[springs.x, springs.y],
(x: number, y: number) => `translate(${x}, ${y})`,
)}
>
<polygon
points="0,0 0,20 14.3,14.3"
fill={
isDragging ? color : `color-mix(in oklch, ${color}, transparent 56%)`
}
stroke={color}
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
/>
<text
x="10"
y="25"
fill={color}
stroke="white"
strokeWidth="3"
strokeLinejoin="round"
paintOrder="stroke"
fontSize="14"
dominantBaseline="hanging"
style={{
fontFamily: "Inter, Manrope, system-ui, sans-serif",
fontWeight: 500,
}}
>
{name}
</text>
</animated.g>
);
}

View File

@@ -1,138 +0,0 @@
import { useCallback, useEffect, useState } from "react";
import { throttleTime } from "../utils/throttleTime";
export interface CursorMoveEvent {
position: { x: number; y: number };
isDragging: boolean;
}
export function useCanvas({
onCursorMove,
throttleMs = 100,
}: {
onCursorMove: (event: CursorMoveEvent) => void;
throttleMs?: number;
}) {
const [viewBox, setViewBox] = useState({
x: 0,
y: 0,
width: window.innerWidth,
height: window.innerHeight,
});
const [isDragging, setIsDragging] = useState(false);
const [isMouseOver, setIsMouseOver] = useState(false);
const [dragStart, setDragStart] = useState({ x: 0, y: 0 });
const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
const onCursorMoveThrottled = useCallback(
throttleTime((move: CursorMoveEvent) => onCursorMove(move), throttleMs),
[onCursorMove, throttleMs],
);
useEffect(() => {
const handleResize = () => {
setViewBox((prev) => ({
...prev,
width: window.innerWidth,
height: window.innerHeight,
}));
};
setViewBox((prev) => ({
...prev,
x: -window.innerWidth / 2,
y: -window.innerHeight / 2,
}));
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);
const handleMouseDown = (e: React.MouseEvent<SVGSVGElement>) => {
setIsDragging(true);
setDragStart({
x: e.clientX,
y: e.clientY,
});
onCursorMoveThrottled({
position: mousePosition,
isDragging: true,
});
};
const handleMouseUp = () => {
setIsDragging(false);
onCursorMoveThrottled({
position: mousePosition,
isDragging: false,
});
};
const handleMouseEnter = () => setIsMouseOver(true);
const handleMouseLeave = () => {
setIsMouseOver(false);
setIsDragging(false);
onCursorMoveThrottled({
position: mousePosition,
isDragging: false,
});
};
const handleMouseMove = (e: React.MouseEvent<SVGSVGElement>) => {
const svg = e.currentTarget;
const ctm = svg.getScreenCTM();
if (!ctm) throw new Error("can't get SVG screen CTM");
const point = svg.createSVGPoint();
point.x = e.clientX;
point.y = e.clientY;
const svgPoint = point.matrixTransform(ctm.inverse());
setMousePosition(svgPoint);
onCursorMoveThrottled({
position: svgPoint,
isDragging,
});
if (!isDragging) return;
const dx = e.clientX - dragStart.x;
const dy = e.clientY - dragStart.y;
setViewBox((prev) => ({ ...prev, x: prev.x - dx, y: prev.y - dy }));
setDragStart({ x: e.clientX, y: e.clientY });
};
const dottedGridSize = 40;
const bgPosition = {
x: Math.floor(viewBox.x / dottedGridSize) * dottedGridSize,
y: Math.floor(viewBox.y / dottedGridSize) * dottedGridSize,
};
const handlers = {
onMouseDown: handleMouseDown,
onMouseUp: handleMouseUp,
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
onMouseMove: handleMouseMove,
};
const svgProps: React.SVGProps<SVGSVGElement> = {
...handlers,
viewBox: `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`,
className: "select-none cursor-none",
};
return {
svgProps,
isDragging,
isMouseOver,
mousePosition,
bgPosition,
dottedGridSize,
};
}

View File

@@ -1,3 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@@ -1,27 +0,0 @@
import { JazzProvider } from "jazz-react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
import { apiKey } from "./apiKey.ts";
import { CursorAccount } from "./schema.ts";
declare module "jazz-react" {
export interface Register {
Account: CursorAccount;
}
}
createRoot(document.getElementById("root")!).render(
<StrictMode>
<JazzProvider
sync={{
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
when: "always",
}}
AccountSchema={CursorAccount}
>
<App />
</JazzProvider>
</StrictMode>,
);

View File

@@ -1,51 +0,0 @@
import { Account, CoFeed, CoMap, Group, Profile, co } from "jazz-tools";
import type { Camera, Cursor } from "./types";
export class CursorFeed extends CoFeed.Of(co.json<Cursor>()) {}
export class CursorProfile extends Profile {
name = co.string;
}
export class CursorRoot extends CoMap {
camera = co.json<Camera>();
cursors = co.ref(CursorFeed);
}
export class CursorContainer extends CoMap {
cursorFeed = co.ref(CursorFeed);
}
export class CursorAccount extends Account {
profile = co.ref(CursorProfile);
root = co.ref(CursorRoot);
/** The account migration is run on account creation and on every log-in.
* You can use it to set up the account root and any other initial CoValues you need.
*/
migrate(this: CursorAccount) {
if (this.root === undefined) {
this.root = CursorRoot.create({
camera: {
position: {
x: 0,
y: 0,
},
},
cursors: CursorFeed.create([]),
});
}
if (this.profile === undefined) {
const group = Group.create();
group.addMember("everyone", "reader"); // The profile info is visible to everyone
this.profile = CursorProfile.create(
{
name: "Anonymous user",
},
group,
);
}
}
}

View File

@@ -1,20 +0,0 @@
export type Vec2 = {
x: number;
y: number;
};
export type Cursor = {
position: Vec2;
};
export type Camera = {
position: Vec2;
};
export type RemoteCursor = Cursor & {
id: ID;
color: string;
name: string;
isRemote: true;
isDragging: boolean;
};

View File

@@ -1,29 +0,0 @@
/**
* Converts a string (like a coID) to a consistent color with controlled brightness
* Uses Oklch color model for better perceptual uniformity
* @param str - The string to convert to a color (typically a coID)
* @returns An Oklch color string
*/
export const getColor = (str: string): string => {
// Simple hash function to get a number from a string
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
// Convert to a positive number
hash = Math.abs(hash);
// Use the hash to determine the hue (0-360)
// This spreads colors around the entire color wheel
const hue = hash % 360;
// Use fixed values for lightness and chroma to ensure consistent brightness
// Lightness: 0.65 gives good visibility on both light and dark backgrounds
// Chroma: 0.15 gives vibrant but not overpowering colors
const lightness = 0.65;
const chroma = 0.15;
// Return the color as an Oklch string
return `oklch(${lightness} ${chroma} ${hue})`;
};

View File

@@ -1,44 +0,0 @@
import { Account, ID, SessionID } from "jazz-tools";
const animals = [
"elephant",
"penguin",
"giraffe",
"octopus",
"kangaroo",
"dolphin",
"cheetah",
"koala",
"platypus",
"pangolin",
"tiger",
"zebra",
"panda",
"lion",
"honey badger",
"hippo",
];
/**
* Get a psuedo-random username.
* @param str The string to get the username from.
* @returns A psuedo-random username.
*/
export function getRandomUsername(str: string) {
return `Anonymous ${animals[Math.abs(str.split("").reduce((acc, char) => acc + char.charCodeAt(0), 0)) % animals.length]}`;
}
/**
* Get the name of a user. If the name is "Anonymous user" or not set, return a random username.
* @param name The name of the user.
* @param id The id of the user.
* @returns The psuedo-random name of the user.
*/
export function getName(
name: string | undefined,
id: ID<Account> | SessionID | undefined,
) {
if (name === "Anonymous user" || !name || !id)
return getRandomUsername(id ?? "");
return name;
}

View File

@@ -1,65 +0,0 @@
import { Account, Group, type ID } from "jazz-tools";
import { CursorContainer, CursorFeed } from "../schema";
export async function loadGroup(me: Account, groupID: ID<Group>) {
const group = await Group.load(groupID, {});
if (group === undefined) {
const group = Group.create({
owner: me,
});
group.addMember("everyone", "writer");
console.log("Created group:", group.id);
return group;
}
return group;
}
/**
* Loads the cursor container for the given cursor feed ID.
* If the cursor container does not exist, it creates a new one.
* If the cursor container exists, it loads the existing one.
* @param me - The account of the current user.
* @param cursorFeedID - The ID of the cursor feed.
* @param groupID - The ID of the group.
*/
export async function loadCursorContainer(
me: Account,
cursorFeedID: ID<CursorFeed>,
groupID: ID<Group>,
): Promise<ID<CursorFeed> | undefined> {
if (!me) return;
const group = await loadGroup(me, groupID);
const cursorContainerID = CursorContainer.findUnique(
cursorFeedID,
group?.id as ID<Group>,
);
const cursorContainer = await CursorContainer.load(cursorContainerID, {
cursorFeed: [],
});
if (cursorContainer === undefined) {
console.log("Global cursors does not exist, creating...");
const cursorContainer = CursorContainer.create(
{
cursorFeed: CursorFeed.create([], {
owner: group,
}),
},
{
owner: group,
unique: cursorFeedID,
},
);
console.log("Created global cursors", cursorContainer.id);
if (cursorContainer.cursorFeed === null) {
throw new Error("cursorFeed is null");
}
return cursorContainer.cursorFeed.id;
} else {
console.log(
"Global cursors already exists, loading...",
cursorContainer.id,
);
return cursorContainer.cursorFeed.id;
}
}

View File

@@ -1,68 +0,0 @@
/**
* Options for the throttleTime function
*/
interface ThrottleOptions {
/** Whether to invoke on the leading edge of the timeout (default: true) */
leading?: boolean;
/** Whether to invoke on the trailing edge of the timeout (default: true) */
trailing?: boolean;
}
/**
* Creates a throttled function that only invokes the provided function
* at most once per every `wait` milliseconds.
*
* @param func - The function to throttle
* @param wait - The number of milliseconds to throttle invocations to
* @param options - The options object
* @returns Returns the new throttled function
*/
export function throttleTime<T extends (...args: any[]) => any>(
func: T,
wait: number,
options: ThrottleOptions = {},
): (...args: Parameters<T>) => ReturnType<T> | undefined {
const { leading = true, trailing = true } = options;
let timeout: NodeJS.Timeout | null = null;
let previous = 0;
let result: ReturnType<T> | undefined;
let context: any;
let args: Parameters<T>;
const later = (): void => {
previous = !leading ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null!;
};
return function throttled(
this: any,
...params: Parameters<T>
): ReturnType<T> | undefined {
const now = Date.now();
if (!previous && !leading) previous = now;
const remaining = wait - (now - previous);
context = this;
args = params;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null!;
} else if (!timeout && trailing) {
timeout = setTimeout(later, remaining);
}
return result;
};
}

View File

@@ -1 +0,0 @@
/// <reference types="vite/client" />

View File

@@ -1,24 +0,0 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}

View File

@@ -1,7 +0,0 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

View File

@@ -1,22 +0,0 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}

View File

@@ -1,8 +0,0 @@
{
"build": {
"env": {
"APP_NAME": "multi-cursors"
}
},
"ignoreCommand": "node ../../ignore-vercel-build.js"
}

View File

@@ -1,7 +0,0 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
});

View File

@@ -1,5 +1,15 @@
# multiauth
## 0.0.5
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-react-auth-clerk@0.11.6
## 0.0.4
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "multiauth",
"private": true,
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,17 @@
# jazz-example-musicplayer
## 0.0.86
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- Updated dependencies [09f0a98]
- Updated dependencies [11da4d1]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-inspector@0.11.6
## 0.0.85
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-music-player",
"private": true,
"version": "0.0.85",
"version": "0.0.86",
"type": "module",
"scripts": {
"dev": "vite",
@@ -22,8 +22,8 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-inspector": "workspace:*",
"jazz-react": "workspace:0.11.5",
"jazz-tools": "workspace:0.11.5",
"jazz-react": "workspace:0.11.6",
"jazz-tools": "workspace:0.11.6",
"lucide-react": "^0.274.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",

View File

@@ -1,5 +1,13 @@
# organization
## 0.0.58
### Patch Changes
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
## 0.0.57
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "organization",
"private": true,
"version": "0.0.57",
"version": "0.0.58",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,12 @@
# passkey-svelte
## 0.0.52
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- jazz-svelte@0.11.6
## 0.0.51
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "passkey-svelte",
"version": "0.0.51",
"version": "0.0.52",
"type": "module",
"private": true,
"scripts": {

View File

@@ -1,5 +1,14 @@
# minimal-auth-passkey
## 0.0.63
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
## 0.0.62
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passkey",
"private": true,
"version": "0.0.62",
"version": "0.0.63",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,14 @@
# passphrase
## 0.0.60
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
## 0.0.59
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passphrase",
"private": true,
"version": "0.0.59",
"version": "0.0.60",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,14 @@
# jazz-password-manager
## 0.0.84
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
## 0.0.83
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-password-manager",
"private": true,
"version": "0.0.83",
"version": "0.0.84",
"type": "module",
"scripts": {
"dev": "vite",
@@ -12,8 +12,8 @@
"clean-install": "rm -rf node_modules pnpm-lock.yaml && pnpm install"
},
"dependencies": {
"jazz-react": "workspace:0.11.5",
"jazz-tools": "workspace:0.11.5",
"jazz-react": "workspace:0.11.6",
"jazz-tools": "workspace:0.11.6",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.41.5",

View File

@@ -1,5 +1,16 @@
# jazz-example-pets
## 0.0.182
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- Updated dependencies [8ed144e]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-browser-media-images@0.11.6
## 0.0.181
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-pets",
"private": true,
"version": "0.0.181",
"version": "0.0.182",
"type": "module",
"scripts": {
"dev": "vite",
@@ -19,9 +19,9 @@
"@radix-ui/react-toast": "^1.1.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-browser-media-images": "workspace:0.11.5",
"jazz-react": "workspace:0.11.5",
"jazz-tools": "workspace:0.11.5",
"jazz-browser-media-images": "workspace:0.11.6",
"jazz-react": "workspace:0.11.6",
"jazz-tools": "workspace:0.11.6",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",
"react": "^18.3.1",
@@ -41,7 +41,7 @@
"@vitejs/plugin-react-swc": "^3.3.2",
"autoprefixer": "^10.4.20",
"is-ci": "^3.0.1",
"jazz-run": "workspace:0.11.5",
"jazz-run": "workspace:0.11.6",
"postcss": "^8.4.27",
"tailwindcss": "^3.4.17",
"typescript": "~5.6.2",

View File

@@ -1,5 +1,16 @@
# reactions
## 0.0.62
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- Updated dependencies [8ed144e]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-browser-media-images@0.11.6
## 0.0.61
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "reactions",
"private": true,
"version": "0.0.61",
"version": "0.0.62",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,14 @@
# todo-vue
## 0.0.66
### Patch Changes
- Updated dependencies [e7c85b7]
- jazz-tools@0.11.6
- jazz-vue@0.11.6
- jazz-browser@0.11.6
## 0.0.65
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "todo-vue",
"version": "0.0.65",
"version": "0.0.66",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,14 @@
# jazz-example-todo
## 0.0.181
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- jazz-react@0.11.6
- jazz-tools@0.11.6
## 0.0.180
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-todo",
"private": true,
"version": "0.0.180",
"version": "0.0.181",
"type": "module",
"scripts": {
"dev": "vite",
@@ -16,8 +16,8 @@
"@radix-ui/react-toast": "^1.1.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-react": "workspace:0.11.5",
"jazz-tools": "workspace:0.11.5",
"jazz-react": "workspace:0.11.6",
"jazz-tools": "workspace:0.11.6",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",
"react": "^18.3.1",

View File

@@ -1,5 +1,17 @@
# version-history
## 0.0.59
### Patch Changes
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
- Updated dependencies [e7c85b7]
- Updated dependencies [09f0a98]
- Updated dependencies [11da4d1]
- jazz-react@0.11.6
- jazz-tools@0.11.6
- jazz-inspector@0.11.6
## 0.0.58
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "version-history",
"private": true,
"version": "0.0.58",
"version": "0.0.59",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,13 @@
# cojson-storage-indexeddb
## 0.11.6
### Patch Changes
- Updated dependencies [8ed144e]
- cojson@0.11.6
- cojson-storage@0.11.6
## 0.11.5
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "cojson-storage-indexeddb",
"version": "0.11.5",
"version": "0.11.6",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",

View File

@@ -1,5 +1,13 @@
# cojson-storage-sqlite
## 0.11.6
### Patch Changes
- Updated dependencies [8ed144e]
- cojson@0.11.6
- cojson-storage@0.11.6
## 0.11.5
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "cojson-storage-rn-sqlite",
"type": "module",
"version": "0.11.5",
"version": "0.11.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",

View File

@@ -1,5 +1,13 @@
# cojson-storage-sqlite
## 0.11.6
### Patch Changes
- Updated dependencies [8ed144e]
- cojson@0.11.6
- cojson-storage@0.11.6
## 0.11.5
### Patch Changes

View File

@@ -1,13 +1,13 @@
{
"name": "cojson-storage-sqlite",
"type": "module",
"version": "0.11.5",
"version": "0.11.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"dependencies": {
"better-sqlite3": "^11.7.0",
"cojson": "workspace:0.11.5",
"cojson": "workspace:0.11.6",
"cojson-storage": "workspace:*"
},
"devDependencies": {

View File

@@ -1,5 +1,12 @@
# cojson-storage
## 0.11.6
### Patch Changes
- Updated dependencies [8ed144e]
- cojson@0.11.6
## 0.11.5
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "cojson-storage",
"version": "0.11.5",
"version": "0.11.6",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",

View File

@@ -1,5 +1,12 @@
# cojson-transport-nodejs-ws
## 0.11.6
### Patch Changes
- Updated dependencies [8ed144e]
- cojson@0.11.6
## 0.11.5
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "cojson-transport-ws",
"type": "module",
"version": "0.11.5",
"version": "0.11.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",

View File

@@ -1,5 +1,11 @@
# cojson
## 0.11.6
### Patch Changes
- 8ed144e: Fix transaction sorting when the timestamps are equal
## 0.11.5
### Patch Changes

View File

@@ -25,7 +25,7 @@
},
"type": "module",
"license": "MIT",
"version": "0.11.5",
"version": "0.11.6",
"devDependencies": {
"@opentelemetry/sdk-metrics": "^1.29.0",
"typescript": "~5.6.2",

View File

@@ -573,7 +573,11 @@ export class CoValueCore {
) {
return (
a.madeAt - b.madeAt ||
(a.txID.sessionID < b.txID.sessionID ? -1 : 1) ||
(a.txID.sessionID === b.txID.sessionID
? 0
: a.txID.sessionID < b.txID.sessionID
? -1
: 1) ||
a.txID.txIndex - b.txID.txIndex
);
}

View File

@@ -79,6 +79,22 @@ export class RawCoStreamView<
throw new Error("Not yet implemented");
}
/** @internal */
protected compareStreamItems(
a: CoStreamItem<Item>,
b: CoStreamItem<Item>,
): number {
return (
a.madeAt - b.madeAt ||
(a.tx.sessionID === b.tx.sessionID
? 0
: a.tx.sessionID < b.tx.sessionID
? -1
: 1) ||
a.tx.txIndex - b.tx.txIndex
);
}
/** @internal */
protected processNewTransactions() {
const changeEntries = new Set<CoStreamItem<Item>[]>();
@@ -104,12 +120,7 @@ export class RawCoStreamView<
}
for (const entries of changeEntries) {
entries.sort(
(a, b) =>
a.madeAt - b.madeAt ||
(a.tx.sessionID < b.tx.sessionID ? -1 : 1) ||
a.tx.txIndex - b.tx.txIndex,
);
entries.sort(this.compareStreamItems);
}
}

View File

@@ -1,8 +1,14 @@
import { describe, expect, test } from "vitest";
import { expectStream } from "../coValue.js";
import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore.js";
import { RawBinaryCoStream } from "../coValues/coStream.js";
import {
BinaryStreamItem,
CoStreamItem,
RawBinaryCoStream,
RawCoStreamView,
} from "../coValues/coStream.js";
import { WasmCrypto } from "../crypto/WasmCrypto.js";
import { SessionID } from "../ids.js";
import { LocalNode } from "../localNode.js";
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
@@ -299,3 +305,114 @@ describe("isBinaryStreamEnded", () => {
expect(stream.isBinaryStreamEnded()).toBe(false);
});
});
describe("Binary stream order", () => {
class TestStreamView extends RawCoStreamView<BinaryStreamItem> {
public testCompareItems(
a: CoStreamItem<BinaryStreamItem>,
b: CoStreamItem<BinaryStreamItem>,
): number {
return this.compareStreamItems(a, b);
}
}
test("sorts by madeAt timestamp first", () => {
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
const coValue = node.createCoValue({
type: "costream",
ruleset: { type: "unsafeAllowAll" },
meta: { type: "binary" },
...Crypto.createdNowUnique(),
});
const content = coValue.getCurrentContent();
if (!(content instanceof RawBinaryCoStream)) {
throw new Error("Expected binary stream");
}
const testView = new TestStreamView(content.core);
const itemA: CoStreamItem<BinaryStreamItem> = {
value: { type: "start", mimeType: "text/plain" },
madeAt: 100,
tx: { sessionID: node.currentSessionID, txIndex: 0 },
};
const itemB: CoStreamItem<BinaryStreamItem> = {
value: { type: "chunk", chunk: "binary_UAwECAQ" },
madeAt: 200,
tx: { sessionID: node.currentSessionID, txIndex: 1 },
};
expect(testView.testCompareItems(itemA, itemB)).toBeLessThan(0);
expect(testView.testCompareItems(itemB, itemA)).toBeGreaterThan(0);
});
test("sorts by sessionID when timestamps are equal", () => {
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
const coValue = node.createCoValue({
type: "costream",
ruleset: { type: "unsafeAllowAll" },
meta: { type: "binary" },
...Crypto.createdNowUnique(),
});
const content = coValue.getCurrentContent();
if (!(content instanceof RawBinaryCoStream)) {
throw new Error("Expected binary stream");
}
const testView = new TestStreamView(content.core);
const timestamp = Date.now();
const itemA: CoStreamItem<BinaryStreamItem> = {
value: { type: "start", mimeType: "text/plain" },
madeAt: timestamp,
tx: { sessionID: "a" as SessionID, txIndex: 0 },
};
const itemB: CoStreamItem<BinaryStreamItem> = {
value: { type: "chunk", chunk: "binary_UAwECAQ" },
madeAt: timestamp,
tx: { sessionID: "b" as SessionID, txIndex: 0 },
};
expect(testView.testCompareItems(itemA, itemB)).toBeLessThan(0);
expect(testView.testCompareItems(itemB, itemA)).toBeGreaterThan(0);
});
test("sorts by txIndex when timestamps and sessionIDs are equal", () => {
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
const coValue = node.createCoValue({
type: "costream",
ruleset: { type: "unsafeAllowAll" },
meta: { type: "binary" },
...Crypto.createdNowUnique(),
});
const content = coValue.getCurrentContent();
if (!(content instanceof RawBinaryCoStream)) {
throw new Error("Expected binary stream");
}
const testView = new TestStreamView(content.core);
const timestamp = Date.now();
const sessionID = node.currentSessionID;
const itemA: CoStreamItem<BinaryStreamItem> = {
value: { type: "start", mimeType: "text/plain" },
madeAt: timestamp,
tx: { sessionID, txIndex: 0 },
};
const itemB: CoStreamItem<BinaryStreamItem> = {
value: { type: "chunk", chunk: "binary_UAwECAQ" },
madeAt: timestamp,
tx: { sessionID, txIndex: 1 },
};
// Expect itemA to be before itemB
expect(testView.testCompareItems(itemA, itemB)).toBeLessThan(0);
expect(testView.testCompareItems(itemB, itemA)).toBeGreaterThan(0);
});
});

View File

@@ -1,5 +1,11 @@
# create-jazz-app
## 0.1.15
### Patch Changes
- 7e945b5: add directory param to create-jazz-app
## 0.1.14
### Patch Changes

View File

@@ -5,7 +5,7 @@
"types": "src/index.ts",
"type": "module",
"license": "MIT",
"version": "0.1.14",
"version": "0.1.15",
"bin": {
"create-jazz-app": "./dist/index.js"
},

Some files were not shown because too many files have changed in this diff Show More