Compare commits

...

120 Commits

Author SHA1 Message Date
Trisha Lim
d73896b24c missing highlight 2025-04-01 16:28:09 +07:00
Trisha Lim
1ab581358e replace focus styles with green 2025-04-01 16:13:19 +07:00
Trisha Lim
9fca21a3f8 remove line highlight for old lines, add highlight for focus 2025-04-01 16:12:13 +07:00
Guido D'Orsi
a11f531d4b Merge pull request #1752 from garden-co/fix/twoslash-dark
fix popover dark mode colors
2025-04-01 11:10:33 +02:00
Trisha Lim
9dd717bf0e lint fixes 2025-04-01 11:36:02 +07:00
Trisha Lim
42551bb4fd fix console errors on react guide 2025-04-01 11:34:49 +07:00
Benjamin S. Leveritt
5c5de61cb6 Merge pull request #1755 from garden-co/fix-multiauth-resolve
Use the new Resolve API for the multiauth example app
2025-03-31 17:44:56 +01:00
pax-k
7fdfc7fddb chore: changeset 2025-03-31 19:43:56 +03:00
pax-k
b108c6166e chore: changeset 2025-03-31 14:42:31 +03:00
pax-k
e0bc9a7f67 fix(example): use the new Resolve API 2025-03-31 14:41:39 +03:00
Benjamin S. Leveritt
f900495f8d Merge pull request #1742 from garden-co/1731-add-out-of-bounds-indicator
1731 Add out of bounds indicator
2025-03-31 12:13:25 +01:00
Benjamin S. Leveritt
4188c7a18d Rename variables 2025-03-31 11:49:48 +01:00
Benjamin S. Leveritt
7315960477 Fixes from comments 2025-03-31 11:40:41 +01:00
Benjamin S. Leveritt
815f485ee5 Fix log 2025-03-31 09:57:05 +01:00
Benjamin S. Leveritt
402008a08f Drop console.logs from build 2025-03-31 09:57:05 +01:00
Benjamin S. Leveritt
bc1576cb92 Adds tests 2025-03-31 09:57:05 +01:00
Benjamin S. Leveritt
acbe66ed60 Replace out of bounds circle with arrow 2025-03-31 09:57:04 +01:00
Benjamin S. Leveritt
ec1fd2aaa2 Fix cursor label positioning relative to the bounds 2025-03-31 09:57:04 +01:00
Benjamin S. Leveritt
bd796555f2 Tweaks label 2025-03-31 09:57:04 +01:00
Benjamin S. Leveritt
153f6ec245 Add proportional label placement 2025-03-31 09:57:04 +01:00
Benjamin S. Leveritt
42d007da13 WIP cursor labels 2025-03-31 09:57:04 +01:00
Benjamin S. Leveritt
c764eeff56 Adds debug flag 2025-03-31 09:57:04 +01:00
Benjamin S. Leveritt
a7a00e6a7c Joins label 2025-03-31 09:57:04 +01:00
Benjamin S. Leveritt
bc65695eee Merges OutOfBoundsMarker with Cursor 2025-03-31 09:57:03 +01:00
Benjamin S. Leveritt
153231aecb Removes OoB labels 2025-03-31 09:57:03 +01:00
Benjamin S. Leveritt
d814899d71 Adds an out of bounds marker 2025-03-31 09:57:03 +01:00
Benjamin S. Leveritt
0b6c35c08a Adds isOutOfBounds test 2025-03-31 09:57:03 +01:00
Benjamin S. Leveritt
e62ea5a8ac Adds Boundary viz 2025-03-31 09:57:03 +01:00
Benjamin S. Leveritt
a5bffd7312 Adds ViewBox type 2025-03-31 09:57:03 +01:00
Benjamin S. Leveritt
9aa91ec525 Adds additional logging during bootstrapping
More logs
2025-03-31 09:57:03 +01:00
Benjamin S. Leveritt
9b8c299ba5 Add basic creds to .env.example 2025-03-31 09:57:03 +01:00
Guido D'Orsi
7486ca768d Merge pull request #1753 from garden-co/fix/llms-txt-content
fix: missing content on llms.txt
2025-03-31 10:25:01 +02:00
Trisha Lim
fa4d501eb0 fix missing intro page on llms.txt 2025-03-31 08:43:38 +07:00
Trisha Lim
a126d5dbf8 fix: missing content on llms.txt 2025-03-31 08:35:43 +07:00
Trisha Lim
d697cc5713 fix popover dark mode colors 2025-03-30 23:10:57 +07:00
Guido D'Orsi
d95c8cc302 Merge pull request #1717 from garden-co/fix/missing-toc
fix: missing TOC on docs intro
2025-03-30 00:09:05 +01:00
Trisha Lim
9dee93af1b fix missing TOC on docs intro 2025-03-29 20:03:34 +07:00
Guido D'Orsi
0dffa407a8 Merge pull request #1748 from garden-co/changeset-release/main
Version Packages
2025-03-28 15:39:11 +01:00
github-actions[bot]
0d97f161bd Version Packages 2025-03-28 13:09:50 +00:00
Guido D'Orsi
b9525b675e Merge pull request #1747 from garden-co/perf/linked-list-queue
perf: re-introducing linked lists on PriorityBasedMessageQueue
2025-03-28 14:07:25 +01:00
Guido D'Orsi
5a00fe0862 perf: re-introducing linked lists on PriorityBasedMessageQueue 2025-03-28 12:54:44 +01:00
Guido D'Orsi
3db07f541f Merge pull request #1746 from garden-co/feat/upgrade-typedoc
fix(homepage): upgrade typedoc to v0.27 and ts v5.7
2025-03-28 12:12:04 +01:00
Guido D'Orsi
0db2e60d09 fix(homepage): upgrade typedoc to v0.27 and ts v5.7 2025-03-28 12:06:36 +01:00
Guido D'Orsi
f122147f03 Merge pull request #1745 from garden-co/changeset-release/main
Version Packages
2025-03-28 11:06:11 +01:00
github-actions[bot]
4e1bcde8b2 Version Packages 2025-03-28 10:02:02 +00:00
Guido D'Orsi
eaef418151 Merge pull request #1642 from garden-co/0-12-0
Jazz 0.12.0 - A clearer syntax for deep loading
2025-03-28 10:59:18 +01:00
Guido D'Orsi
8d17b192d0 Merge pull request #1743 from garden-co/improve-link-accounts
fix: make the linkAccounts test utility wait for the accounts coValues to be synced
2025-03-28 10:04:29 +01:00
Trisha Lim
9a56bb3d25 fix missing icon (#1744) 2025-03-28 14:08:32 +07:00
Guido D'Orsi
b6c6a0ae64 fix: make the linkAccounts test utility wait for the accounts coValues to be synced 2025-03-27 22:24:28 +01:00
Guido D'Orsi
e000774b3b Merge pull request #1739 from garden-co/changeset-release/main
Version Packages
2025-03-27 18:45:09 +01:00
github-actions[bot]
6f6cf23bc8 Version Packages 2025-03-27 17:38:35 +00:00
Guido D'Orsi
77a718656c Merge pull request #1741 from garden-co/issue-1373
fix: fixes expected header to be sent in first message error
2025-03-27 18:35:27 +01:00
Guido D'Orsi
6c86c4f7ee fix: fixes expected header to be sent in first message error 2025-03-27 18:34:39 +01:00
Guido D'Orsi
72508332fb Merge pull request #1728 from garden-co/gio/update-otel-dep
chore: update @opentelemetry/api dependency
2025-03-27 18:29:38 +01:00
Guido D'Orsi
0ac88b4c80 test: repro for expected header to be sent in first message 2025-03-27 17:41:01 +01:00
pax-k
11460b6f9f fix(cursor): refactored docs to include changes for Jazz v0.12.0 - Deeply resolved data 2025-03-27 18:34:03 +02:00
Trisha Lim
71b93909e6 fix(inspector): install clsx, remove lucide-react (#1737)
* install clsx

* remove lucide-react

* add changeset
2025-03-27 21:02:06 +07:00
Guido D'Orsi
26646cde0c chore: migrate code to the new resolve spec after merging with main 2025-03-27 12:02:06 +01:00
Guido D'Orsi
4033e95a50 Merge remote-tracking branch 'origin/main' into 0-12-0 2025-03-27 11:52:15 +01:00
Guido D'Orsi
f379fcc176 Merge pull request #1730 from garden-co/changeset-release/main
Version Packages
2025-03-27 11:49:13 +01:00
Guido D'Orsi
66d59b31d5 Merge pull request #1732 from garden-co/docs/loading-errors
docs: document loading errors
2025-03-27 11:48:23 +01:00
github-actions[bot]
d6ea4d4662 Version Packages 2025-03-27 10:37:27 +00:00
Guido D'Orsi
84b5dd8a0b Merge pull request #1719 from garden-co/feat/react-create-image
feat: re-export createImage on jazz-react
2025-03-27 11:35:02 +01:00
Guido D'Orsi
c730016572 Merge pull request #1726 from garden-co/fix/inspector-covalue-types
fix(inspector): CoFeeds and FileStreams are showing as "CoStream"
2025-03-27 11:32:53 +01:00
Guido D'Orsi
7677ca5240 Merge pull request #1735 from garden-co/feat/optimize-subscription-updates
fix: trigger a single update when loading a locally available list of items
2025-03-27 11:25:22 +01:00
Guido D'Orsi
cffe482f75 fix: apply the sync resolution on the ref access only during fullfillDepth to avoid issues with Svelte 2025-03-27 10:51:34 +01:00
Guido D'Orsi
4019918b2b feat: re-export createImage on jazz-react 2025-03-27 09:48:49 +01:00
Guido D'Orsi
a140f555ba fix: trigger a single update when loading a locally available list of items 2025-03-26 19:02:31 +01:00
Guido D'Orsi
7b0d10a293 Merge pull request #1734 from garden-co/feat/optimize-group-role
perf: optimize Group.roleOf getter and made the transactions validation incremental for CoMap and CoFeed
2025-03-26 17:58:40 +01:00
Guido D'Orsi
156fba66e3 perf: optimize determineValidTransactions for when all the transactions are already known 2025-03-26 14:49:55 +01:00
Guido D'Orsi
95d6928d91 perf: made the transactions validation incremental for CoMap and CoFeed 2025-03-26 14:25:51 +01:00
Guido D'Orsi
2b94bc8af0 perf: optimize Group.roleOf getter 2025-03-26 14:08:24 +01:00
Guido D'Orsi
6e56a4351f Merge pull request #1733 from garden-co/fix/throw-invalid-ids
fix: handle invalid or undefined id
2025-03-26 11:56:17 +01:00
Guido D'Orsi
2013846d7b fix: ignore messages with an invalid or undefined id 2025-03-26 11:47:11 +01:00
Guido D'Orsi
2957362ab0 fix: throw when loading a coValue with an invalid or undefined id 2025-03-26 11:46:54 +01:00
Benjamin S. Leveritt
b23969ed0e Merge pull request #1706 from garden-co/1704-multi-cursor-example
1704 multi cursor example
2025-03-26 07:05:50 +00:00
Benjamin S. Leveritt
023fb4e1c7 Limit name length 2025-03-26 07:01:05 +00:00
Benjamin S. Leveritt
73963a7056 Tweak patch note 2025-03-26 07:00:52 +00:00
James Vickery
2b0d1b0e32 jazz-tools patch 2025-03-25 20:34:44 +00:00
James Vickery
5aad79005d rm tests 2025-03-25 20:29:09 +00:00
James Vickery
35cc6137e7 bits and bobs 2025-03-25 19:32:30 +00:00
Giordano Ricci
9d0c9dc6ea chore: update @opentelemetry/api dependency 2025-03-25 15:20:34 +00:00
Benjamin S. Leveritt
8d3849e27b Bury your dead 2025-03-25 12:57:46 +00:00
Benjamin S. Leveritt
92ca86ac75 Rename Cursor 2025-03-25 12:45:17 +00:00
Benjamin S. Leveritt
654a5caf69 Rename user detail getters 2025-03-25 12:42:13 +00:00
Benjamin S. Leveritt
a4f2e99370 Moves to useCoState 2025-03-25 12:38:57 +00:00
Trisha Lim
2c3761c8e8 add changeset 2025-03-25 18:52:16 +07:00
Trisha Lim
c91bcf9745 inspector: show CoStream as CoFeed 2025-03-25 18:32:37 +07:00
Trisha Lim
c1db6e087a reuse use-resolve-covalue 2025-03-25 18:31:14 +07:00
Trisha Lim
9d8cc194e0 inspector: show files as FileStream instead of CoStream 2025-03-25 18:30:45 +07:00
Trisha Lim
de11fdd07a collapse upgrade guides on side nav 2025-03-25 18:14:42 +07:00
Benjamin S. Leveritt
1b18801133 Fix depth indentation 2025-03-25 18:14:42 +07:00
Trisha Lim
02f3c31205 make framework selector sticky, add gradient to bottom 2025-03-25 18:14:42 +07:00
Trisha Lim
e5af81bf27 reduce spacing in TOC to match left nav 2025-03-25 18:14:42 +07:00
Guido D'Orsi
e13b9d2689 Merge pull request #1721 from garden-co/image-targetWidth
docs: replace maxWidth with targetWidth as the go-to API for defining  the target resolution
2025-03-25 11:02:31 +01:00
Guido D'Orsi
523196acdd Merge pull request #1723 from garden-co/fix/inspector-no-data
fix: inspector shows "no data" when there's data
2025-03-25 10:26:05 +01:00
Benjamin S. Leveritt
24d291b65f Add changable names 2025-03-25 07:38:54 +00:00
Trisha Lim
3367787f37 fix embedded inspector bg color 2025-03-25 13:55:09 +07:00
Trisha Lim
e7ae1359c0 fix: no data shown on comap if navigating from colist 2025-03-25 13:42:40 +07:00
Benjamin S. Leveritt
55e81849fe Checks for anon 2025-03-24 20:25:52 +00:00
Benjamin S. Leveritt
a2ad4a7dc3 Add random name labels 2025-03-24 20:23:17 +00:00
Benjamin S. Leveritt
dbaa1dfe3f Fix import order 2025-03-24 17:55:08 +00:00
Benjamin S. Leveritt
452d5f3030 Adds interpolation to the remote cursors 2025-03-24 17:53:03 +00:00
Benjamin S. Leveritt
16263442a7 Refactor ids into .env 2025-03-24 17:24:01 +00:00
Benjamin S. Leveritt
15384db02d Working cursors 2025-03-24 15:40:26 +00:00
Benjamin S. Leveritt
fa13fbf247 Debugging cursors 2025-03-24 15:30:39 +00:00
James Vickery
291562aafe replace useRef with useCallback 2025-03-24 14:43:24 +00:00
Benjamin S. Leveritt
b8ff6d2195 Adds some remote cursors 2025-03-24 14:29:50 +00:00
Guido D'Orsi
f0483b2500 docs: replace maxWidth with targetWidth as the go-to API for defining the target resolution 2025-03-24 14:16:51 +01:00
Benjamin S. Leveritt
90138a6848 Simplify schema 2025-03-24 11:50:27 +00:00
James Vickery
b55c276296 update vercel.json app name 2025-03-24 08:55:44 +00:00
Benjamin S. Leveritt
539f2b23ef Fix formatting 2025-03-24 08:55:44 +00:00
Benjamin S. Leveritt
daea669cb2 Adds global Cursors feed 2025-03-24 08:55:44 +00:00
James Vickery
55793722ff throttled onCursorMove 2025-03-24 08:55:44 +00:00
James Vickery
849f716700 cursors and stuff! 2025-03-24 08:55:43 +00:00
James Vickery
39d50ef040 a super cool draggable canvas 2025-03-24 08:55:43 +00:00
Benjamin S. Leveritt
73b120637c Add pointer tracking 2025-03-24 08:55:43 +00:00
Benjamin S. Leveritt
f41f61ffd3 Add canvas 2025-03-24 08:55:43 +00:00
Benjamin S. Leveritt
3436728416 Add example app 2025-03-24 08:55:43 +00:00
Trisha Lim
7ad2210a7f fix select component attributes 2025-03-24 15:14:49 +07:00
267 changed files with 5414 additions and 1137 deletions

View File

@@ -1,6 +0,0 @@
---
"jazz-tools": minor
"cojson": minor
---
Check CoValue access permissions when loading

View File

@@ -1,5 +0,0 @@
---
"jazz-tools": minor
---
Implement new API for deep loading

View File

@@ -1,5 +0,0 @@
---
"jazz-tools": minor
---
The .load function now returns `null` on error

View File

@@ -1,5 +0,0 @@
---
"cojson": minor
---
Return the EVERYONE role if the account is not direct a member of the group

View File

@@ -0,0 +1,5 @@
---
"multiauth": patch
---
Use the new Resolve API

View File

@@ -1,5 +0,0 @@
---
"jazz-vue": patch
---
Fix types compilation for useAccount

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

8
.idea/jazz.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/jazz.iml" filepath="$PROJECT_DIR$/.idea/jazz.iml" />
</modules>
</component>
</project>

19
.idea/php.xml generated Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project>

6
.idea/prettier.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PrettierConfiguration">
<option name="myConfigurationMode" value="AUTOMATIC" />
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -1,5 +1,47 @@
# chat-rn-clerk
## 1.0.91
### Patch Changes
- jazz-react-native@0.12.1
- jazz-react-native-auth-clerk@0.12.1
- jazz-tools@0.12.1
- jazz-react-native-media-images@0.12.1
## 1.0.90
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react-native@0.12.0
- jazz-react-native-auth-clerk@0.12.0
- jazz-react-native-media-images@0.12.0
## 1.0.89
### Patch Changes
- jazz-react-native@0.11.8
- jazz-react-native-auth-clerk@0.11.8
- jazz-tools@0.11.8
- jazz-react-native-media-images@0.11.8
## 1.0.88
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react-native@0.11.7
- jazz-react-native-auth-clerk@0.11.7
- jazz-react-native-media-images@0.11.7
## 1.0.87
### Patch Changes

View File

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

View File

@@ -1,5 +1,39 @@
# chat-rn
## 1.0.87
### Patch Changes
- jazz-react-native@0.12.1
- jazz-tools@0.12.1
## 1.0.86
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react-native@0.12.0
## 1.0.85
### Patch Changes
- jazz-react-native@0.11.8
- jazz-tools@0.11.8
## 1.0.84
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react-native@0.11.7
## 1.0.83
### Patch Changes

View File

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

View File

@@ -1,5 +1,44 @@
# chat-vue
## 0.0.72
### Patch Changes
- jazz-browser@0.12.1
- jazz-tools@0.12.1
- jazz-vue@0.12.1
## 0.0.71
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- Updated dependencies [4c01459]
- jazz-tools@0.12.0
- jazz-vue@0.12.0
- jazz-browser@0.12.0
## 0.0.70
### Patch Changes
- jazz-browser@0.11.8
- jazz-tools@0.11.8
- jazz-vue@0.11.8
## 0.0.69
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-browser@0.11.7
- jazz-vue@0.11.7
## 0.0.68
### Patch Changes

View File

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

View File

@@ -1,5 +1,47 @@
# jazz-example-chat
## 0.0.169
### Patch Changes
- jazz-inspector@0.12.1
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.168
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- Updated dependencies [9a56bb3]
- jazz-tools@0.12.0
- jazz-inspector@0.12.0
- jazz-react@0.12.0
## 0.0.167
### Patch Changes
- Updated dependencies [71b9390]
- jazz-inspector@0.11.8
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.166
### Patch Changes
- Updated dependencies [2c3761c]
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-inspector@0.11.7
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.165
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-chat",
"private": true,
"version": "0.0.165",
"version": "0.0.169",
"type": "module",
"scripts": {
"dev": "vite",
@@ -15,7 +15,6 @@
"dependencies": {
"clsx": "^2.0.0",
"hash-slash": "workspace:*",
"jazz-browser-media-images": "workspace:*",
"jazz-inspector": "workspace:*",
"jazz-react": "workspace:*",
"jazz-tools": "workspace:*",

View File

@@ -1,5 +1,4 @@
import { createImage } from "jazz-browser-media-images";
import { useAccount, useCoState } from "jazz-react";
import { createImage, useAccount, useCoState } from "jazz-react";
import { Account, ID } from "jazz-tools";
import { useState } from "react";
import { Chat, Message } from "./schema.ts";

View File

@@ -1,5 +1,44 @@
# minimal-auth-clerk
## 0.0.68
### Patch Changes
- jazz-react@0.12.1
- jazz-react-auth-clerk@0.12.1
- jazz-tools@0.12.1
## 0.0.67
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
- jazz-react-auth-clerk@0.12.0
## 0.0.66
### Patch Changes
- jazz-react@0.11.8
- jazz-react-auth-clerk@0.11.8
- jazz-tools@0.11.8
## 0.0.65
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
- jazz-react-auth-clerk@0.11.7
## 0.0.64
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "clerk",
"private": true,
"version": "0.0.64",
"version": "0.0.68",
"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.6",
"jazz-react-auth-clerk": "workspace:0.12.1",
"jazz-tools": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"

View File

@@ -1,5 +1,39 @@
# file-share-svelte
## 0.0.52
### Patch Changes
- jazz-svelte@0.12.1
- jazz-tools@0.12.1
## 0.0.51
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-svelte@0.12.0
## 0.0.50
### Patch Changes
- jazz-svelte@0.11.8
- jazz-tools@0.11.8
## 0.0.49
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-svelte@0.11.7
## 0.0.48
### Patch Changes

View File

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

View File

@@ -1,5 +1,40 @@
# jazz-tailwind-demo-auth-starter
## 0.0.8
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.7
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.6
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.5
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.4
### Patch Changes

View File

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

View File

@@ -1,5 +1,40 @@
# form
## 0.1.10
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.1.9
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.1.8
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.1.7
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.1.6
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "form",
"private": true,
"version": "0.1.6",
"version": "0.1.10",
"type": "module",
"scripts": {
"dev": "vite",
@@ -12,7 +12,6 @@
},
"dependencies": {
"hash-slash": "workspace:*",
"jazz-browser-media-images": "workspace:*",
"jazz-react": "workspace:*",
"jazz-tools": "workspace:*",
"react": "^18.3.1",

View File

@@ -1,5 +1,40 @@
# image-upload
## 0.0.66
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.65
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.64
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.63
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.62
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "image-upload",
"private": true,
"version": "0.0.62",
"version": "0.0.66",
"type": "module",
"scripts": {
"dev": "vite",
@@ -11,7 +11,6 @@
"format-and-lint:fix": "biome check . --write"
},
"dependencies": {
"jazz-browser-media-images": "workspace:*",
"jazz-react": "workspace:*",
"jazz-tools": "workspace:*",
"react": "^18.3.1",

View File

@@ -1,5 +1,4 @@
import { createImage } from "jazz-browser-media-images";
import { ProgressiveImg, useAccount } from "jazz-react";
import { ProgressiveImg, createImage, useAccount } from "jazz-react";
import { ChangeEvent, useEffect, useRef, useState } from "react";
export default function ImageUpload() {

View File

@@ -1,5 +1,48 @@
# jazz-example-inspector
## 0.0.119
### Patch Changes
- Updated dependencies [5a00fe0]
- cojson@0.12.1
- cojson-transport-ws@0.12.1
- jazz-inspector@0.12.1
## 0.0.118
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [01523dc]
- Updated dependencies [9a56bb3]
- cojson@0.12.0
- jazz-inspector@0.12.0
- cojson-transport-ws@0.12.0
## 0.0.117
### Patch Changes
- Updated dependencies [71b9390]
- Updated dependencies [6c86c4f]
- Updated dependencies [9d0c9dc]
- jazz-inspector@0.11.8
- cojson@0.11.8
- cojson-transport-ws@0.11.8
## 0.0.116
### Patch Changes
- 2c3761c: fix: CoFeed and FileStream are showing as CoStream
- Updated dependencies [2c3761c]
- Updated dependencies [2b94bc8]
- Updated dependencies [2957362]
- jazz-inspector@0.11.7
- cojson@0.11.7
- cojson-transport-ws@0.11.7
## 0.0.115
### Patch Changes

View File

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

View File

@@ -17,9 +17,9 @@ import {
PageStack,
Select,
} from "jazz-inspector";
import { resolveCoValue, useResolvedCoValue } from "jazz-inspector";
import React, { useState, useEffect } from "react";
import { usePagePath } from "./use-page-path";
import { resolveCoValue, useResolvedCoValue } from "./use-resolve-covalue";
interface Account {
id: CoID<RawAccount>;

View File

@@ -1,216 +0,0 @@
import { CoID, LocalNode, RawBinaryCoStream, RawCoValue } from "cojson";
import { useEffect, useState } from "react";
export type CoJsonType = "comap" | "costream" | "colist";
export type ExtendedCoJsonType = "image" | "record" | "account" | "group";
type JSON = string | number | boolean | null | JSON[] | { [key: string]: JSON };
type JSONObject = { [key: string]: JSON };
type ResolvedImageDefinition = {
originalSize: [number, number];
placeholderDataURL?: string;
[res: `${number}x${number}`]: RawBinaryCoStream["id"];
};
// Type guard for browser image
export const isBrowserImage = (
coValue: JSONObject,
): coValue is ResolvedImageDefinition => {
return "originalSize" in coValue && "placeholderDataURL" in coValue;
};
export type ResolvedGroup = {
readKey: string;
[key: string]: JSON;
};
export const isGroup = (coValue: JSONObject): coValue is ResolvedGroup => {
return "readKey" in coValue;
};
export type ResolvedAccount = {
profile: {
name: string;
};
[key: string]: JSON;
};
export const isAccount = (coValue: JSONObject): coValue is ResolvedAccount => {
return isGroup(coValue) && "profile" in coValue;
};
export async function resolveCoValue(
coValueId: CoID<RawCoValue>,
node: LocalNode,
): Promise<
| {
value: RawCoValue;
snapshot: JSONObject;
type: CoJsonType | null;
extendedType: ExtendedCoJsonType | undefined;
}
| {
value: undefined;
snapshot: "unavailable";
type: null;
extendedType: undefined;
}
> {
const value = await node.load(coValueId);
if (value === "unavailable") {
return {
value: undefined,
snapshot: "unavailable",
type: null,
extendedType: undefined,
};
}
const snapshot = value.toJSON() as JSONObject;
const type = value.type as CoJsonType;
// Determine extended type
let extendedType: ExtendedCoJsonType | undefined;
if (type === "comap") {
if (isBrowserImage(snapshot)) {
extendedType = "image";
} else if (isAccount(snapshot)) {
extendedType = "account";
} else if (isGroup(snapshot)) {
extendedType = "group";
} else {
// This check is a bit of a hack
// There might be a better way to do this
const children = Object.values(snapshot).slice(0, 10);
if (
children.every((c) => typeof c === "string" && c.startsWith("co_")) &&
children.length > 3
) {
extendedType = "record";
}
}
}
return {
value,
snapshot,
type,
extendedType,
};
}
function subscribeToCoValue(
coValueId: CoID<RawCoValue>,
node: LocalNode,
callback: (result: Awaited<ReturnType<typeof resolveCoValue>>) => void,
) {
return node.subscribe(coValueId, (value) => {
if (value === "unavailable") {
callback({
value: undefined,
snapshot: "unavailable",
type: null,
extendedType: undefined,
});
} else {
const snapshot = value.toJSON() as JSONObject;
const type = value.type as CoJsonType;
let extendedType: ExtendedCoJsonType | undefined;
if (type === "comap") {
if (isBrowserImage(snapshot)) {
extendedType = "image";
} else if (isAccount(snapshot)) {
extendedType = "account";
} else if (isGroup(snapshot)) {
extendedType = "group";
} else {
const children = Object.values(snapshot).slice(0, 10);
if (
children.every(
(c) => typeof c === "string" && c.startsWith("co_"),
) &&
children.length > 3
) {
extendedType = "record";
}
}
}
callback({
value,
snapshot,
type,
extendedType,
});
}
});
}
export function useResolvedCoValue(
coValueId: CoID<RawCoValue>,
node: LocalNode,
) {
const [result, setResult] =
useState<Awaited<ReturnType<typeof resolveCoValue>>>();
useEffect(() => {
let isMounted = true;
const unsubscribe = subscribeToCoValue(coValueId, node, (newResult) => {
if (isMounted) {
setResult(newResult);
}
});
return () => {
isMounted = false;
unsubscribe();
};
}, [coValueId, node]);
return (
result || {
value: undefined,
snapshot: undefined,
type: undefined,
extendedType: undefined,
}
);
}
export function useResolvedCoValues(
coValueIds: CoID<RawCoValue>[],
node: LocalNode,
) {
const [results, setResults] = useState<
Awaited<ReturnType<typeof resolveCoValue>>[]
>([]);
useEffect(() => {
let isMounted = true;
const unsubscribes: (() => void)[] = [];
coValueIds.forEach((coValueId, index) => {
const unsubscribe = subscribeToCoValue(coValueId, node, (newResult) => {
if (isMounted) {
setResults((prevResults) => {
const newResults = [...prevResults];
newResults[index] = newResult;
return newResults;
});
}
});
unsubscribes.push(unsubscribe);
});
return () => {
isMounted = false;
unsubscribes.forEach((unsubscribe) => unsubscribe());
};
}, [coValueIds, node]);
return results;
}

View File

@@ -0,0 +1,3 @@
VITE_CURSOR_FEED_ID=multi-cursors-250425-1708
VITE_GROUP_ID=co_zXE8C8sd9QxEbxnt3neRvFRPFUc
VITE_OLD_CURSOR_AGE_SECONDS=36000

View File

@@ -0,0 +1,3 @@
VITE_CURSOR_FEED_ID=multi-cursors-250425-1708
VITE_GROUP_ID=co_zXE8C8sd9QxEbxnt3neRvFRPFUc
VITE_OLD_CURSOR_AGE_SECONDS=5

28
examples/multi-cursors/.gitignore vendored Normal file
View File

@@ -0,0 +1,28 @@
# 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

@@ -0,0 +1,36 @@
# multi-cursors
## 0.0.62
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.61
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.60
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.59
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,16 @@
<!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

@@ -0,0 +1,35 @@
{
"name": "multi-cursors",
"private": true,
"version": "0.0.62",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"format-and-lint": "biome check .",
"format-and-lint:fix": "biome check . --write",
"test": "vitest"
},
"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",
"vitest": "3.0.5"
}
}

View File

@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

View File

@@ -0,0 +1,66 @@
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(() => {
console.log("Loading cursor feed...", me.id);
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

@@ -0,0 +1,21 @@
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

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

View File

@@ -0,0 +1,16 @@
import { ViewBox } from "../types";
export function Boundary({ bounds }: { bounds: ViewBox }) {
return (
<>
<rect
x={bounds.x}
y={bounds.y}
width={bounds.width}
height={bounds.height}
stroke="red"
fill="none"
/>
</>
);
}

View File

@@ -0,0 +1,102 @@
import { useAccount } from "jazz-react";
import { CoFeedEntry, co } from "jazz-tools";
import { CursorMoveEvent, useCanvas } from "../hooks/useCanvas";
import { Cursor as CursorType, ViewBox } from "../types";
import { centerOfBounds } from "../utils/centerOfBounds";
import { getColor } from "../utils/getColor";
import { getName } from "../utils/getName";
import { Boundary } from "./Boundary";
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,
);
const DEBUG = import.meta.env.VITE_DEBUG === "true";
// For debugging purposes, we can set a fixed bounds
const debugBounds: ViewBox = {
x: 320,
y: 320,
width: 640,
height: 640,
};
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,
viewBox,
} = useCanvas({ onCursorMove });
const bounds = DEBUG ? debugBounds : viewBox;
const center = centerOfBounds(bounds);
return (
<svg width="100%" height="100%" {...svgProps}>
<CanvasBackground
bgPosition={bgPosition}
dottedGridSize={dottedGridSize}
/>
<CanvasDemoContent />
{DEBUG && <Boundary bounds={bounds} />}
{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;
}
const name = getName(entry.by?.profile?.name, entry.tx.sessionID);
const color = getColor(entry.tx.sessionID);
const age = new Date().getTime() - new Date(entry.madeAt).getTime();
return (
<Cursor
key={entry.tx.sessionID}
position={entry.value.position}
color={color}
isDragging={false}
isRemote={true}
name={name}
age={age}
centerOfBounds={center}
bounds={bounds}
/>
);
})}
{isMouseOver ? (
<Cursor
position={mousePosition}
color="#FF69B4"
isDragging={isDragging}
isRemote={false}
name={name}
centerOfBounds={center}
bounds={bounds}
/>
) : null}
</svg>
);
}
export default Canvas;

View File

@@ -0,0 +1,33 @@
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

@@ -0,0 +1,19 @@
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

@@ -0,0 +1,30 @@
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, { resolve: true });
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

@@ -0,0 +1,141 @@
import { animated, to, useSpring } from "@react-spring/web";
import { Vec2, ViewBox } from "../types";
import { calculateBoundaryIntersection } from "../utils/boundaryIntersection";
import { isOutOfBounds } from "../utils/isOutOfBounds";
import { CursorLabel } from "./CursorLabel";
interface CursorProps {
position: { x: number; y: number };
color: string;
isDragging: boolean;
isRemote: boolean;
name: string;
age?: number;
centerOfBounds: Vec2;
bounds?: ViewBox;
}
const LABEL_BOUNDS_PADDING = 32;
const CURSOR_VISIBILITY_OFFSET = 20;
export function Cursor({
position,
color,
isDragging,
isRemote,
name,
age = 0,
centerOfBounds,
bounds,
}: CursorProps) {
if (!bounds) return null;
const intersectionPoint = calculateBoundaryIntersection(
centerOfBounds,
position,
bounds,
);
const labelBounds = {
x: bounds.x + LABEL_BOUNDS_PADDING / 2,
y: bounds.y + LABEL_BOUNDS_PADDING / 2,
width: bounds.width - LABEL_BOUNDS_PADDING,
height: bounds.height - LABEL_BOUNDS_PADDING,
};
const cursorIntersectionPoint = calculateBoundaryIntersection(
centerOfBounds,
position,
labelBounds,
);
const isStrictlyOutOfBounds = isOutOfBounds(position, bounds);
const shouldHideCursor = isOutOfBounds(
position,
bounds,
CURSOR_VISIBILITY_OFFSET,
);
const springs = useSpring({
x: position.x,
y: position.y,
opacity: age > 60000 ? 0 : 1,
immediate: !isRemote,
config: {
tension: 170,
friction: 26,
},
});
const intersectionSprings = useSpring({
x: intersectionPoint.x,
y: intersectionPoint.y,
config: {
tension: 170,
friction: 26,
},
});
return (
<>
<animated.g
transform={to(
[springs.x, springs.y],
(x: number, y: number) => `translate(${x}, ${y})`,
)}
>
{isStrictlyOutOfBounds ? (
<circle cx={0} cy={0} r={4} fill={color} />
) : null}
{!shouldHideCursor ? (
<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"
/>
) : null}
</animated.g>
{isRemote ? (
<>
<CursorLabel
name={name}
color={color}
position={cursorIntersectionPoint}
bounds={bounds}
isOutOfBounds={isStrictlyOutOfBounds}
/>
{isStrictlyOutOfBounds ? (
<animated.g
transform={to(
[intersectionSprings.x, intersectionSprings.y],
(x: number, y: number) => {
const angle =
Math.atan2(centerOfBounds.y - y, centerOfBounds.x - x) *
(180 / Math.PI);
return `translate(${x}, ${y}) rotate(${angle})`;
},
)}
>
<path
d="M 8,-4 L 2,0 L 8,4"
fill="none"
stroke={color}
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
/>
</animated.g>
) : null}
</>
) : null}
</>
);
}

View File

@@ -0,0 +1,93 @@
import { animated, to, useSpring } from "@react-spring/web";
import { useEffect, useRef, useState } from "react";
import { Vec2, ViewBox } from "../types";
import { getLabelPosition } from "../utils/getLabelPosition";
const DEBUG = import.meta.env.VITE_DEBUG === "true";
interface CursorLabelProps {
name: string;
color: string;
position: Vec2;
bounds?: ViewBox;
isOutOfBounds?: boolean;
}
interface TextDimensions {
width: number;
height: number;
}
export function CursorLabel({
name,
color,
position,
bounds,
isOutOfBounds,
}: CursorLabelProps) {
const textRef = useRef<SVGTextElement>(null);
const [dimensions, setDimensions] = useState<TextDimensions>({
width: 0,
height: 0,
});
useEffect(() => {
const bbox = textRef.current?.getBBox();
setDimensions({ width: bbox?.width ?? 0, height: bbox?.height ?? 0 });
}, [name]);
const labelPosition = getLabelPosition(
position,
dimensions,
bounds,
isOutOfBounds,
);
const labelSprings = useSpring<Vec2>({
...labelPosition,
config: {
tension: 170,
friction: 26,
},
});
return (
<>
<animated.text
ref={textRef}
x={to([labelSprings.x], (x) => x)}
y={to([labelSprings.y], (y) => y)}
fill={color}
stroke="white"
strokeWidth="3"
strokeLinejoin="round"
paintOrder="stroke"
fontSize="14"
dominantBaseline="hanging"
textAnchor="start"
>
{name}
</animated.text>
{DEBUG ? (
<>
<text x={position.x} y={position.y} fill="red" fontSize="8">
{position.x}, {position.y}
</text>
<text x={labelPosition.x} y={labelPosition.y} fill="red" fontSize="8">
{bounds
? `${bounds.x - labelPosition.x}, ${bounds.y - labelPosition.y}`
: "no bounds"}
</text>
<line
x1={position.x}
y1={position.y}
x2={labelPosition.x}
y2={labelPosition.y}
stroke="red"
strokeWidth="1"
strokeLinejoin="round"
/>
</>
) : null}
</>
);
}

View File

@@ -0,0 +1,140 @@
import { useCallback, useEffect, useState } from "react";
import type { ViewBox } from "../types";
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<ViewBox>({
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,
viewBox,
};
}

View File

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

View File

@@ -0,0 +1,27 @@
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

@@ -0,0 +1,51 @@
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,
);
}
}
}

27
examples/multi-cursors/src/types.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
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;
};
export type ViewBox = {
x: number;
y: number;
width: number;
height: number;
};

View File

@@ -0,0 +1,42 @@
import { describe, expect, it } from "vitest";
import { calculateBoundaryIntersection } from "../boundaryIntersection";
describe("calculateBoundaryIntersection", () => {
const bounds = { x: 0, y: 0, width: 100, height: 100 };
it("should handle vertical lines (dx = 0)", () => {
const center = { x: 50, y: 50 };
const point = { x: 50, y: 150 }; // Straight up from center
const intersection = calculateBoundaryIntersection(center, point, bounds);
expect(intersection).toEqual({ x: 50, y: 100 }); // Should intersect at bottom boundary
});
it("should handle horizontal lines (dy = 0)", () => {
const center = { x: 50, y: 50 };
const point = { x: 150, y: 50 }; // Straight right from center
const intersection = calculateBoundaryIntersection(center, point, bounds);
expect(intersection).toEqual({ x: 100, y: 50 }); // Should intersect at right boundary
});
it("should handle vertical lines at boundaries", () => {
const center = { x: 0, y: 50 };
const point = { x: 0, y: 150 }; // Vertical line at x=0
const intersection = calculateBoundaryIntersection(center, point, bounds);
expect(intersection).toEqual({ x: 0, y: 100 }); // Should intersect at bottom boundary
});
it("should handle horizontal lines at boundaries", () => {
const center = { x: 50, y: 0 };
const point = { x: 150, y: 0 }; // Horizontal line at y=0
const intersection = calculateBoundaryIntersection(center, point, bounds);
expect(intersection).toEqual({ x: 100, y: 0 }); // Should intersect at right boundary
});
});

View File

@@ -0,0 +1,61 @@
import { describe, expect, it } from "vitest";
import { getLabelPosition } from "../getLabelPosition";
describe("getLabelPosition", () => {
const dimensions = { width: 100, height: 20 };
const bounds = { x: 0, y: 0, width: 1000, height: 1000 };
it("should position label with default offset when cursor is in bounds", () => {
const position = { x: 500, y: 500 };
const result = getLabelPosition(position, dimensions, bounds, false);
expect(result).toEqual({
x: position.x + 15,
y: position.y + 25,
});
});
it("should position label with default offset when bounds are undefined", () => {
const position = { x: 500, y: 500 };
const result = getLabelPosition(position, dimensions, undefined, true);
expect(result).toEqual({
x: position.x + 15,
y: position.y + 25,
});
});
it("should adjust label position based on cursor position when out of bounds", () => {
const position = { x: 800, y: 600 };
const result = getLabelPosition(position, dimensions, bounds, true);
// At x=800, percentageH = 0.8, so x offset should be -80 (0.8 * width)
// At y=600, percentageV = 0.6, so y offset should be -12 (0.6 * height)
expect(result).toEqual({
x: position.x - 0.8 * dimensions.width,
y: position.y - 0.6 * dimensions.height,
});
});
it("should handle cursor at bounds edges", () => {
const position = { x: 1000, y: 1000 }; // Bottom-right corner
const result = getLabelPosition(position, dimensions, bounds, true);
// At the edges, percentages should be 1, so full dimension should be subtracted
expect(result).toEqual({
x: position.x - dimensions.width,
y: position.y - dimensions.height,
});
});
it("should handle cursor at bounds origin", () => {
const position = { x: 0, y: 0 }; // Top-left corner
const result = getLabelPosition(position, dimensions, bounds, true);
// At origin, percentages should be 0, so no offset from position
expect(result).toEqual({
x: position.x,
y: position.y,
});
});
});

View File

@@ -0,0 +1,29 @@
import { describe, expect, it } from "vitest";
import { isOutOfBounds } from "../isOutOfBounds";
describe("isOutOfBounds", () => {
it("should return true if the position is out of bounds", () => {
expect(
isOutOfBounds(
{ x: 101, y: 101 },
{ x: 0, y: 0, width: 100, height: 100 },
),
).toBe(true);
});
it("should return false if the position is within bounds", () => {
expect(
isOutOfBounds({ x: 50, y: 50 }, { x: 0, y: 0, width: 100, height: 100 }),
).toBe(false);
});
it("should return false if the position is inside the grace area", () => {
expect(
isOutOfBounds(
{ x: 110, y: 110 },
{ x: 0, y: 0, width: 100, height: 100 },
20,
),
).toBe(false);
});
});

View File

@@ -0,0 +1,77 @@
import { Vec2, ViewBox } from "../types";
/**
* Calculate the intersection point of a line and a boundary.
* @param center - The origin of the line.
* @param point - The end of the line to calculate the intersection for.
* @param bounds - The bounds of the boundary.
* @returns The intersection point.
*/
export function calculateBoundaryIntersection(
center: Vec2,
point: Vec2,
bounds: ViewBox,
): Vec2 {
// Calculate direction vector
const dx = point.x - center.x;
const dy = point.y - center.y;
// Calculate all possible intersections
let horizontalIntersection: Vec2 | null = null;
let verticalIntersection: Vec2 | null = null;
// Check horizontal bounds
if (dx !== 0) {
// Skip horizontal bounds check if line is vertical
if (point.x < bounds.x) {
const y = center.y + (dy * (bounds.x - center.x)) / dx;
if (y >= bounds.y && y <= bounds.y + bounds.height) {
horizontalIntersection = { x: bounds.x, y };
}
} else if (point.x > bounds.x + bounds.width) {
const y = center.y + (dy * (bounds.x + bounds.width - center.x)) / dx;
if (y >= bounds.y && y <= bounds.y + bounds.height) {
horizontalIntersection = { x: bounds.x + bounds.width, y };
}
}
}
// Check vertical bounds
if (dy !== 0) {
// Skip vertical bounds check if line is horizontal
if (point.y < bounds.y) {
const x = center.x + (dx * (bounds.y - center.y)) / dy;
if (x >= bounds.x && x <= bounds.x + bounds.width) {
verticalIntersection = { x, y: bounds.y };
}
} else if (point.y > bounds.y + bounds.height) {
const x = center.x + (dx * (bounds.y + bounds.height - center.y)) / dy;
if (x >= bounds.x && x <= bounds.x + bounds.width) {
verticalIntersection = { x, y: bounds.y + bounds.height };
}
}
}
// Choose the intersection point that's closest to the actual point
if (horizontalIntersection && verticalIntersection) {
const horizontalDist = Math.hypot(
point.x - horizontalIntersection.x,
point.y - horizontalIntersection.y,
);
const verticalDist = Math.hypot(
point.x - verticalIntersection.x,
point.y - verticalIntersection.y,
);
return horizontalDist < verticalDist
? horizontalIntersection
: verticalIntersection;
}
return (
horizontalIntersection ||
verticalIntersection || {
x: Math.max(bounds.x, Math.min(bounds.x + bounds.width, point.x)),
y: Math.max(bounds.y, Math.min(bounds.y + bounds.height, point.y)),
}
);
}

View File

@@ -0,0 +1,17 @@
import { Vec2, ViewBox } from "../types";
/**
* Get the center of a bounds.
* @param bounds - The bounds to get the center of.
* @returns The center of the bounds.
*/
export function centerOfBounds(bounds?: ViewBox): Vec2 {
if (!bounds) {
return { x: 0, y: 0 };
}
return {
x: bounds.x + bounds.width / 2,
y: bounds.y + bounds.height / 2,
};
}

View File

@@ -0,0 +1,29 @@
/**
* 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

@@ -0,0 +1,40 @@
import { Vec2, ViewBox } from "../types";
interface TextDimensions {
width: number;
height: number;
}
interface LabelPosition {
x: number;
y: number;
}
/**
* Calculate the position of a cursor label based on cursor position, label dimensions, and bounds
* Such that the label is always on the same side of the bounds as the cursor
* @param position - The cursor position
* @param dimensions - The dimensions of the label text
* @param bounds - The viewport bounds
* @param isOutOfBounds - Whether the cursor is outside the bounds
* @returns The calculated label position
*/
export function getLabelPosition(
position: Vec2,
dimensions: TextDimensions,
bounds?: ViewBox,
isOutOfBounds?: boolean,
): LabelPosition {
if (!isOutOfBounds || !bounds) {
return { x: position.x + 15, y: position.y + 25 };
}
// Calculate the percentage of the bounds that the intersection point is from the left
const percentageH = (position.x - bounds.x) / bounds.width;
const percentageV = (position.y - bounds.y) / bounds.height;
return {
x: position.x - percentageH * dimensions.width,
y: position.y - percentageV * dimensions.height,
};
}

View File

@@ -0,0 +1,44 @@
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

@@ -0,0 +1,21 @@
import { Vec2, ViewBox } from "../types";
/**
* Check if a position is out of bounds of a view box.
* @param position - The position to check.
* @param bounds - The bounds of the view box.
* @param grace - The grace distance to allow for the position to be out of bounds.
* @returns True if the position is out of bounds, false otherwise.
*/
export function isOutOfBounds(
position: Vec2,
bounds: ViewBox,
grace: number = 0,
): boolean {
return (
position.x < bounds.x - grace ||
position.x > bounds.x + bounds.width + grace ||
position.y < bounds.y - grace ||
position.y > bounds.y + bounds.height + grace
);
}

View File

@@ -0,0 +1,83 @@
import { Account, Group, type ID } from "jazz-tools";
import { CursorContainer, CursorFeed } from "../schema";
/**
* Creates a new group to own the cursor container.
* @param me - The account of the current user.
* @returns The group.
*/
function createGroup(me: Account) {
const group = Group.create({
owner: me,
});
group.addMember("everyone", "writer");
console.log("Created group");
console.log(`Add "VITE_GROUP_ID=${group.id}" to your .env file`);
return group;
}
export async function loadGroup(me: Account, groupID: ID<Group>) {
if (groupID === undefined) {
console.log("No group ID found in .env, creating group...");
return createGroup(me);
}
const group = await Group.load(groupID, {});
if (group === null || group === undefined) {
console.log("Group not found, creating group...");
return createGroup(me);
}
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 = "cursor-feed",
groupID: ID<Group>,
): Promise<ID<CursorFeed> | undefined> {
if (!me) return;
console.log("Loading group...");
const group = await loadGroup(me, groupID);
const cursorContainerID = CursorContainer.findUnique(
cursorFeedID,
group?.id as ID<Group>,
);
console.log("Loading cursor container:", cursorContainerID);
const cursorContainer = await CursorContainer.load(cursorContainerID, {
resolve: {
cursorFeed: true,
},
});
if (cursorContainer === null || cursorContainer === undefined) {
console.log("Global cursors does not exist, creating...");
const cursorContainer = CursorContainer.create(
{
cursorFeed: CursorFeed.create([], 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

@@ -0,0 +1,68 @@
/**
* 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

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

View File

@@ -0,0 +1,23 @@
import type { Config } from "tailwindcss";
const config: Config = {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {
container: {
center: true,
padding: {
DEFAULT: "0.75rem",
sm: "1rem",
},
screens: {
lg: "600px",
xl: "600px",
},
},
},
},
plugins: [],
} as const;
export default config;

View File

@@ -0,0 +1,24 @@
{
"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

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

View File

@@ -0,0 +1,22 @@
{
"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

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

View File

@@ -0,0 +1,15 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
build: {
minify: "esbuild",
terserOptions: {
compress: {
drop_console: true,
},
},
},
});

View File

@@ -1,5 +1,44 @@
# multiauth
## 0.0.9
### Patch Changes
- jazz-react@0.12.1
- jazz-react-auth-clerk@0.12.1
- jazz-tools@0.12.1
## 0.0.8
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
- jazz-react-auth-clerk@0.12.0
## 0.0.7
### Patch Changes
- jazz-react@0.11.8
- jazz-react-auth-clerk@0.11.8
- jazz-tools@0.11.8
## 0.0.6
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
- jazz-react-auth-clerk@0.11.7
## 0.0.5
### Patch Changes

View File

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

View File

@@ -1,7 +1,7 @@
import { useAccount, useIsAuthenticated } from "jazz-react";
export function Home() {
const { me, logOut } = useAccount({ root: {} });
const { me, logOut } = useAccount({ resolve: { root: true } });
const isAuthenticated = useIsAuthenticated();
if (!me) return;

View File

@@ -1,5 +1,47 @@
# jazz-example-musicplayer
## 0.0.90
### Patch Changes
- jazz-inspector@0.12.1
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.89
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- Updated dependencies [9a56bb3]
- jazz-tools@0.12.0
- jazz-inspector@0.12.0
- jazz-react@0.12.0
## 0.0.88
### Patch Changes
- Updated dependencies [71b9390]
- jazz-inspector@0.11.8
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.87
### Patch Changes
- Updated dependencies [2c3761c]
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-inspector@0.11.7
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.86
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-music-player",
"private": true,
"version": "0.0.86",
"version": "0.0.90",
"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.6",
"jazz-tools": "workspace:0.11.6",
"jazz-react": "workspace:0.12.1",
"jazz-tools": "workspace:0.12.1",
"lucide-react": "^0.274.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",

View File

@@ -1,5 +1,40 @@
# organization
## 0.0.62
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.61
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.60
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.59
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.58
### Patch Changes

View File

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

View File

@@ -1,5 +1,29 @@
# passkey-svelte
## 0.0.56
### Patch Changes
- jazz-svelte@0.12.1
## 0.0.55
### Patch Changes
- jazz-svelte@0.12.0
## 0.0.54
### Patch Changes
- jazz-svelte@0.11.8
## 0.0.53
### Patch Changes
- jazz-svelte@0.11.7
## 0.0.52
### Patch Changes

View File

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

View File

@@ -1,5 +1,40 @@
# minimal-auth-passkey
## 0.0.67
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.66
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.65
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.64
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.63
### Patch Changes

View File

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

View File

@@ -1,5 +1,40 @@
# passphrase
## 0.0.64
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.63
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.62
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.61
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.60
### Patch Changes

View File

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

View File

@@ -1,5 +1,40 @@
# jazz-password-manager
## 0.0.88
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.87
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.86
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.85
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.84
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-password-manager",
"private": true,
"version": "0.0.84",
"version": "0.0.88",
"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.6",
"jazz-tools": "workspace:0.11.6",
"jazz-react": "workspace:0.12.1",
"jazz-tools": "workspace:0.12.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.41.5",

View File

@@ -1,5 +1,40 @@
# jazz-example-pets
## 0.0.186
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.185
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.184
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.183
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.182
### Patch Changes

View File

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

View File

@@ -1,10 +1,8 @@
import { createImage } from "jazz-browser-media-images";
/* eslint-disable react-hooks/exhaustive-deps */
import { ChangeEvent, useCallback, useState } from "react";
import { useNavigate } from "react-router";
import { ProgressiveImg } from "jazz-react";
import { useAccount, useCoState } from "jazz-react";
import { createImage, useAccount, useCoState } from "jazz-react";
import { CoMap, Group, ID, ImageDefinition, co } from "jazz-tools";
import { PetPost, PetReactions } from "./1_schema";
import { Button, Input } from "./basicComponents";

View File

@@ -1,5 +1,40 @@
# reactions
## 0.0.66
### Patch Changes
- jazz-react@0.12.1
- jazz-tools@0.12.1
## 0.0.65
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- jazz-tools@0.12.0
- jazz-react@0.12.0
## 0.0.64
### Patch Changes
- jazz-react@0.11.8
- jazz-tools@0.11.8
## 0.0.63
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [4019918]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-react@0.11.7
## 0.0.62
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "reactions",
"private": true,
"version": "0.0.62",
"version": "0.0.66",
"type": "module",
"scripts": {
"dev": "vite",
@@ -12,7 +12,6 @@
},
"dependencies": {
"hash-slash": "workspace:*",
"jazz-browser-media-images": "workspace:*",
"jazz-react": "workspace:*",
"jazz-tools": "workspace:*",
"react": "^18.3.1",

View File

@@ -1,5 +1,44 @@
# todo-vue
## 0.0.70
### Patch Changes
- jazz-browser@0.12.1
- jazz-tools@0.12.1
- jazz-vue@0.12.1
## 0.0.69
### Patch Changes
- Updated dependencies [01523dc]
- Updated dependencies [4ea87dc]
- Updated dependencies [1e6da19]
- Updated dependencies [b6c6a0a]
- Updated dependencies [4c01459]
- jazz-tools@0.12.0
- jazz-vue@0.12.0
- jazz-browser@0.12.0
## 0.0.68
### Patch Changes
- jazz-browser@0.11.8
- jazz-tools@0.11.8
- jazz-vue@0.11.8
## 0.0.67
### Patch Changes
- Updated dependencies [a140f55]
- Updated dependencies [2b0d1b0]
- jazz-tools@0.11.7
- jazz-browser@0.11.7
- jazz-vue@0.11.7
## 0.0.66
### Patch Changes

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