Compare commits
117 Commits
feat/incre
...
jazz-svelt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f122147f03 | ||
|
|
4e1bcde8b2 | ||
|
|
eaef418151 | ||
|
|
8d17b192d0 | ||
|
|
9a56bb3d25 | ||
|
|
b6c6a0ae64 | ||
|
|
e000774b3b | ||
|
|
6f6cf23bc8 | ||
|
|
77a718656c | ||
|
|
6c86c4f7ee | ||
|
|
72508332fb | ||
|
|
0ac88b4c80 | ||
|
|
11460b6f9f | ||
|
|
71b93909e6 | ||
|
|
26646cde0c | ||
|
|
4033e95a50 | ||
|
|
f379fcc176 | ||
|
|
66d59b31d5 | ||
|
|
1e6da19d5e | ||
|
|
d6ea4d4662 | ||
|
|
84b5dd8a0b | ||
|
|
c730016572 | ||
|
|
7677ca5240 | ||
|
|
cffe482f75 | ||
|
|
4019918b2b | ||
|
|
a140f555ba | ||
|
|
7b0d10a293 | ||
|
|
156fba66e3 | ||
|
|
95d6928d91 | ||
|
|
2b94bc8af0 | ||
|
|
6e56a4351f | ||
|
|
2013846d7b | ||
|
|
2957362ab0 | ||
|
|
10de4b6fc9 | ||
|
|
2433344778 | ||
|
|
4c01459942 | ||
|
|
b23969ed0e | ||
|
|
023fb4e1c7 | ||
|
|
73963a7056 | ||
|
|
2b0d1b0e32 | ||
|
|
5aad79005d | ||
|
|
35cc6137e7 | ||
|
|
8dacdd6e2f | ||
|
|
5b0580bfda | ||
|
|
2bed7e845d | ||
|
|
76976026b7 | ||
|
|
10ea8fbf88 | ||
|
|
bd86b159b9 | ||
|
|
c4f5241818 | ||
|
|
181f433477 | ||
|
|
3897a7e137 | ||
|
|
5082ecef3f | ||
|
|
268e433870 | ||
|
|
6c185160c5 | ||
|
|
d18323b74a | ||
|
|
edd91791c9 | ||
|
|
958b13c050 | ||
|
|
bbe140f7be | ||
|
|
1625f82ab7 | ||
|
|
843f729a62 | ||
|
|
cc4631bb42 | ||
|
|
3665ef0088 | ||
|
|
e13039818e | ||
|
|
2e79487982 | ||
|
|
fc2c045a8d | ||
|
|
69bb94be06 | ||
|
|
228c8fa796 | ||
|
|
a34b850824 | ||
|
|
96d518bb97 | ||
|
|
8355f5674d | ||
|
|
5c1d04ee88 | ||
|
|
2ef98d01b0 | ||
|
|
15a86a3014 | ||
|
|
9c49704cf9 | ||
|
|
44f0d8d5c7 | ||
|
|
d7af97d63f | ||
|
|
9d0c9dc6ea | ||
|
|
8d3849e27b | ||
|
|
92ca86ac75 | ||
|
|
654a5caf69 | ||
|
|
a4f2e99370 | ||
|
|
2c3761c8e8 | ||
|
|
c91bcf9745 | ||
|
|
c1db6e087a | ||
|
|
9d8cc194e0 | ||
|
|
de11fdd07a | ||
|
|
1b18801133 | ||
|
|
02f3c31205 | ||
|
|
e5af81bf27 | ||
|
|
3b189e4def | ||
|
|
7fe50922cc | ||
|
|
e13b9d2689 | ||
|
|
523196acdd | ||
|
|
24d291b65f | ||
|
|
3367787f37 | ||
|
|
e7ae1359c0 | ||
|
|
55e81849fe | ||
|
|
a2ad4a7dc3 | ||
|
|
dbaa1dfe3f | ||
|
|
452d5f3030 | ||
|
|
16263442a7 | ||
|
|
15384db02d | ||
|
|
fa13fbf247 | ||
|
|
291562aafe | ||
|
|
b8ff6d2195 | ||
|
|
f0483b2500 | ||
|
|
90138a6848 | ||
|
|
b55c276296 | ||
|
|
539f2b23ef | ||
|
|
daea669cb2 | ||
|
|
55793722ff | ||
|
|
849f716700 | ||
|
|
39d50ef040 | ||
|
|
73b120637c | ||
|
|
f41f61ffd3 | ||
|
|
3436728416 | ||
|
|
7ad2210a7f |
@@ -1,6 +0,0 @@
|
||||
---
|
||||
"jazz-tools": minor
|
||||
"cojson": minor
|
||||
---
|
||||
|
||||
Check CoValue access permissions when loading
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"jazz-tools": minor
|
||||
---
|
||||
|
||||
Implement new API for deep loading
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"cojson": minor
|
||||
---
|
||||
|
||||
Return the EVERYONE role if the account is not direct a member of the group
|
||||
@@ -1,5 +1,38 @@
|
||||
# chat-rn-clerk
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "chat-rn-clerk",
|
||||
"main": "index.js",
|
||||
"version": "1.0.87",
|
||||
"version": "1.0.90",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
"start": "expo start",
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
# chat-rn
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-rn",
|
||||
"version": "1.0.83",
|
||||
"version": "1.0.86",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
# chat-vue
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-vue",
|
||||
"version": "0.0.68",
|
||||
"version": "0.0.71",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
# jazz-example-chat
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-chat",
|
||||
"private": true,
|
||||
"version": "0.0.165",
|
||||
"version": "0.0.168",
|
||||
"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:*",
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
# minimal-auth-clerk
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "clerk",
|
||||
"private": true,
|
||||
"version": "0.0.64",
|
||||
"version": "0.0.67",
|
||||
"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.0",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
# file-share-svelte
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "file-share-svelte",
|
||||
"version": "0.0.48",
|
||||
"version": "0.0.51",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# jazz-tailwind-demo-auth-starter
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "filestream",
|
||||
"private": true,
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.7",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# form
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "form",
|
||||
"private": true,
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.9",
|
||||
"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",
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# image-upload
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "image-upload",
|
||||
"private": true,
|
||||
"version": "0.0.62",
|
||||
"version": "0.0.65",
|
||||
"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",
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
# jazz-example-inspector
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-inspector-app",
|
||||
"private": true,
|
||||
"version": "0.0.115",
|
||||
"version": "0.0.118",
|
||||
"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.0",
|
||||
"cojson-transport-ws": "workspace:0.12.0",
|
||||
"hash-slash": "workspace:0.2.2",
|
||||
"lucide-react": "^0.274.0",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
3
examples/multi-cursors/.env
Normal file
3
examples/multi-cursors/.env
Normal file
@@ -0,0 +1,3 @@
|
||||
VITE_CURSOR_FEED_ID=multi-cursors-250425-1708
|
||||
VITE_GROUP_ID=co_zXE8C8sd9QxEbxnt3neRvFRPFUc
|
||||
VITE_OLD_CURSOR_AGE_SECONDS=36000
|
||||
3
examples/multi-cursors/.env.local.example
Normal file
3
examples/multi-cursors/.env.local.example
Normal file
@@ -0,0 +1,3 @@
|
||||
VITE_CURSOR_FEED_ID=example-cursor-feed-id
|
||||
VITE_GROUP_ID=co_example-group-id
|
||||
VITE_OLD_CURSOR_AGE_SECONDS=5
|
||||
28
examples/multi-cursors/.gitignore
vendored
Normal file
28
examples/multi-cursors/.gitignore
vendored
Normal 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
|
||||
29
examples/multi-cursors/CHANGELOG.md
Normal file
29
examples/multi-cursors/CHANGELOG.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# multi-cursors
|
||||
|
||||
## 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
|
||||
3
examples/multi-cursors/README.md
Normal file
3
examples/multi-cursors/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Multi-cursor example
|
||||
|
||||
An example app of using Jazz for showing multiple-cursors on a simple canvas.
|
||||
BIN
examples/multi-cursors/favicon.ico
Normal file
BIN
examples/multi-cursors/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
16
examples/multi-cursors/index.html
Normal file
16
examples/multi-cursors/index.html
Normal 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>
|
||||
35
examples/multi-cursors/package.json
Normal file
35
examples/multi-cursors/package.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "multi-cursors",
|
||||
"private": true,
|
||||
"version": "0.0.61",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
6
examples/multi-cursors/postcss.config.js
Normal file
6
examples/multi-cursors/postcss.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
65
examples/multi-cursors/src/App.tsx
Normal file
65
examples/multi-cursors/src/App.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
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;
|
||||
21
examples/multi-cursors/src/Logo.tsx
Normal file
21
examples/multi-cursors/src/Logo.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
1
examples/multi-cursors/src/apiKey.ts
Normal file
1
examples/multi-cursors/src/apiKey.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const apiKey = "jazz-multi-cursors@garden.co";
|
||||
76
examples/multi-cursors/src/components/Canvas.tsx
Normal file
76
examples/multi-cursors/src/components/Canvas.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
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;
|
||||
33
examples/multi-cursors/src/components/CanvasBackground.tsx
Normal file
33
examples/multi-cursors/src/components/CanvasBackground.tsx
Normal 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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
19
examples/multi-cursors/src/components/CanvasDemoContent.tsx
Normal file
19
examples/multi-cursors/src/components/CanvasDemoContent.tsx
Normal 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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
30
examples/multi-cursors/src/components/Container.tsx
Normal file
30
examples/multi-cursors/src/components/Container.tsx
Normal 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;
|
||||
64
examples/multi-cursors/src/components/Cursor.tsx
Normal file
64
examples/multi-cursors/src/components/Cursor.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
138
examples/multi-cursors/src/hooks/useCanvas.ts
Normal file
138
examples/multi-cursors/src/hooks/useCanvas.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
3
examples/multi-cursors/src/index.css
Normal file
3
examples/multi-cursors/src/index.css
Normal file
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
27
examples/multi-cursors/src/main.tsx
Normal file
27
examples/multi-cursors/src/main.tsx
Normal 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>,
|
||||
);
|
||||
51
examples/multi-cursors/src/schema.ts
Normal file
51
examples/multi-cursors/src/schema.ts
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
examples/multi-cursors/src/types.d.ts
vendored
Normal file
20
examples/multi-cursors/src/types.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
};
|
||||
29
examples/multi-cursors/src/utils/getColor.ts
Normal file
29
examples/multi-cursors/src/utils/getColor.ts
Normal 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})`;
|
||||
};
|
||||
44
examples/multi-cursors/src/utils/getName.ts
Normal file
44
examples/multi-cursors/src/utils/getName.ts
Normal 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;
|
||||
}
|
||||
66
examples/multi-cursors/src/utils/loadCursorContainer.ts
Normal file
66
examples/multi-cursors/src/utils/loadCursorContainer.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
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 === null) {
|
||||
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, {
|
||||
resolve: {
|
||||
cursorFeed: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (cursorContainer === null) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
68
examples/multi-cursors/src/utils/throttleTime.ts
Normal file
68
examples/multi-cursors/src/utils/throttleTime.ts
Normal 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;
|
||||
};
|
||||
}
|
||||
1
examples/multi-cursors/src/vite-env.d.ts
vendored
Normal file
1
examples/multi-cursors/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
23
examples/multi-cursors/tailwind.config.ts
Normal file
23
examples/multi-cursors/tailwind.config.ts
Normal 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;
|
||||
24
examples/multi-cursors/tsconfig.app.json
Normal file
24
examples/multi-cursors/tsconfig.app.json
Normal 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"]
|
||||
}
|
||||
7
examples/multi-cursors/tsconfig.json
Normal file
7
examples/multi-cursors/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
22
examples/multi-cursors/tsconfig.node.json
Normal file
22
examples/multi-cursors/tsconfig.node.json
Normal 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"]
|
||||
}
|
||||
8
examples/multi-cursors/vercel.json
Normal file
8
examples/multi-cursors/vercel.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"build": {
|
||||
"env": {
|
||||
"APP_NAME": "multi-cursors"
|
||||
}
|
||||
},
|
||||
"ignoreCommand": "node ../../ignore-vercel-build.js"
|
||||
}
|
||||
7
examples/multi-cursors/vite.config.ts
Normal file
7
examples/multi-cursors/vite.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { defineConfig } from "vite";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
});
|
||||
@@ -1,5 +1,36 @@
|
||||
# multiauth
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "multiauth",
|
||||
"private": true,
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.8",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
# jazz-example-musicplayer
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-music-player",
|
||||
"private": true,
|
||||
"version": "0.0.86",
|
||||
"version": "0.0.89",
|
||||
"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.0",
|
||||
"jazz-tools": "workspace:0.12.0",
|
||||
"lucide-react": "^0.274.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# organization
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "organization",
|
||||
"private": true,
|
||||
"version": "0.0.58",
|
||||
"version": "0.0.61",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# passkey-svelte
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "passkey-svelte",
|
||||
"version": "0.0.52",
|
||||
"version": "0.0.55",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# minimal-auth-passkey
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "passkey",
|
||||
"private": true,
|
||||
"version": "0.0.63",
|
||||
"version": "0.0.66",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# passphrase
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "passphrase",
|
||||
"private": true,
|
||||
"version": "0.0.60",
|
||||
"version": "0.0.63",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# jazz-password-manager
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-password-manager",
|
||||
"private": true,
|
||||
"version": "0.0.84",
|
||||
"version": "0.0.87",
|
||||
"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.0",
|
||||
"jazz-tools": "workspace:0.12.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-hook-form": "^7.41.5",
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# jazz-example-pets
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-pets",
|
||||
"private": true,
|
||||
"version": "0.0.182",
|
||||
"version": "0.0.185",
|
||||
"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.0",
|
||||
"jazz-tools": "workspace:0.12.0",
|
||||
"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.0",
|
||||
"postcss": "^8.4.27",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "~5.6.2",
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# reactions
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "reactions",
|
||||
"private": true,
|
||||
"version": "0.0.62",
|
||||
"version": "0.0.65",
|
||||
"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",
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
# todo-vue
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "todo-vue",
|
||||
"version": "0.0.66",
|
||||
"version": "0.0.69",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# jazz-example-todo
|
||||
|
||||
## 0.0.184
|
||||
|
||||
### 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.183
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.182
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [4019918]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react@0.11.7
|
||||
|
||||
## 0.0.181
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-todo",
|
||||
"private": true,
|
||||
"version": "0.0.181",
|
||||
"version": "0.0.184",
|
||||
"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.6",
|
||||
"jazz-tools": "workspace:0.11.6",
|
||||
"jazz-react": "workspace:0.12.0",
|
||||
"jazz-tools": "workspace:0.12.0",
|
||||
"lucide-react": "^0.274.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
# version-history
|
||||
|
||||
## 0.0.62
|
||||
|
||||
### 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.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [71b9390]
|
||||
- jazz-inspector@0.11.8
|
||||
- jazz-react@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.60
|
||||
|
||||
### 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.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "version-history",
|
||||
"private": true,
|
||||
"version": "0.0.59",
|
||||
"version": "0.0.62",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { clsx } from "clsx";
|
||||
import Link from "next/link";
|
||||
import { forwardRef } from "react";
|
||||
import { Icon } from "./Icon";
|
||||
import type { IconName } from "./Icon";
|
||||
import { Spinner } from "./Spinner";
|
||||
|
||||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
@@ -9,7 +10,7 @@ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
size?: "sm" | "md" | "lg";
|
||||
href?: string;
|
||||
newTab?: boolean;
|
||||
icon?: string;
|
||||
icon?: IconName;
|
||||
loading?: boolean;
|
||||
loadingText?: string;
|
||||
children?: React.ReactNode;
|
||||
|
||||
@@ -113,6 +113,8 @@ const strokeWidths = {
|
||||
"9xl": 1,
|
||||
};
|
||||
|
||||
export type IconName = keyof typeof icons;
|
||||
|
||||
export function Icon({
|
||||
name,
|
||||
icon,
|
||||
@@ -120,7 +122,7 @@ export function Icon({
|
||||
className,
|
||||
...svgProps
|
||||
}: {
|
||||
name?: string;
|
||||
name?: IconName;
|
||||
icon?: LucideIcon;
|
||||
size?: keyof typeof sizes;
|
||||
className?: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import clsx from "clsx";
|
||||
import { Card } from "../atoms/Card";
|
||||
import { Icon } from "../atoms/Icon";
|
||||
import { Icon, IconName } from "../atoms/Icon";
|
||||
import { Prose } from "./Prose";
|
||||
|
||||
export function FeatureCard({
|
||||
@@ -11,7 +11,7 @@ export function FeatureCard({
|
||||
className,
|
||||
}: {
|
||||
label: React.ReactNode;
|
||||
icon?: string;
|
||||
icon?: IconName;
|
||||
explanation?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
|
||||
@@ -13,12 +13,13 @@ import { usePathname } from "next/navigation";
|
||||
import { ComponentType, ReactNode, useEffect, useState } from "react";
|
||||
import { isActive } from "../../utils/nav";
|
||||
import { Icon } from "../atoms/Icon";
|
||||
import type { IconName } from "../atoms/Icon";
|
||||
import { BreadCrumb } from "../molecules/Breadcrumb";
|
||||
import { SocialLinks, SocialLinksProps } from "./SocialLinks";
|
||||
|
||||
type NavItemProps = {
|
||||
href: string;
|
||||
icon?: string;
|
||||
icon?: IconName;
|
||||
title: string;
|
||||
firstOnRight?: boolean;
|
||||
newTab?: boolean;
|
||||
@@ -38,7 +39,7 @@ type NavProps = {
|
||||
export type NavSection = {
|
||||
name: string;
|
||||
content: ReactNode;
|
||||
icon: string;
|
||||
icon: IconName;
|
||||
};
|
||||
|
||||
function NavItem({
|
||||
@@ -134,7 +135,11 @@ export function MobileNav({
|
||||
sections,
|
||||
themeToggle: ThemeToggle,
|
||||
}: NavProps) {
|
||||
const primarySection = {
|
||||
const primarySection: {
|
||||
name: string;
|
||||
icon: IconName;
|
||||
content: ReactNode;
|
||||
} = {
|
||||
name: "Menu",
|
||||
icon: "menu",
|
||||
content: (
|
||||
@@ -254,7 +259,7 @@ export function MobileNav({
|
||||
onClick={() => toggle(section.name)}
|
||||
key={section.name}
|
||||
>
|
||||
<Icon name={section.icon} size="xs" />
|
||||
{section.icon && <Icon name={section.icon} size="xs" />}
|
||||
{section.name}
|
||||
</button>
|
||||
),
|
||||
|
||||
@@ -49,7 +49,7 @@ function highlightPlugin() {
|
||||
token.content.includes("// old"),
|
||||
);
|
||||
const isBinnedLine = line.some((token) =>
|
||||
token.content.includes("// *bin*"),
|
||||
token.content.includes("// [!code --]"),
|
||||
);
|
||||
const isHighlighted = line.some((token) =>
|
||||
token.content.includes("// *highlight*"),
|
||||
@@ -70,7 +70,7 @@ function highlightPlugin() {
|
||||
line
|
||||
.map((token) => {
|
||||
let color = isHighlighted ? "currentColor" : token.color;
|
||||
return `<span style="color: ${color};${isSubduedLine ? "opacity: 0.4;" : ""}">${escape(token.content.replace("// old", "").replace("// *bin*", "").replace("// *highlight*", ""))}</span>`;
|
||||
return `<span style="color: ${color};${isSubduedLine ? "opacity: 0.4;" : ""}">${escape(token.content.replace("// old", "").replace("// [!code --]", "").replace("// *highlight*", ""))}</span>`;
|
||||
})
|
||||
.join("") +
|
||||
"</span>"
|
||||
|
||||
@@ -543,7 +543,7 @@ function App() { // old
|
||||
(window.location.search?.replace("?project=", "") || undefined) as ID<Project> | undefined
|
||||
);
|
||||
// old
|
||||
const issue = useCoState(Issue, issueID); // *bin*
|
||||
const issue = useCoState(Issue, issueID); // [!code --]
|
||||
// old
|
||||
const createProject = () => {
|
||||
const group = Group.create();
|
||||
@@ -622,7 +622,7 @@ Two things to note here:
|
||||
- We only need to use `useCoState` on the Project, and the nested `ListOfIssues` and each `Issue` will be **automatically loaded and subscribed to when we access them.**
|
||||
- However, because either the `Project`, `ListOfIssues`, or each `Issue` might not be loaded yet, we have to check for them being defined.
|
||||
|
||||
### Precise loading depths
|
||||
### Precise resolve queries
|
||||
|
||||
The load-and-subscribe-on-access is a convenient way to have your rendering drive data loading (including in nested components!) and lets you quickly chuck UIs together without worrying too much about the shape of all data you'll need.
|
||||
|
||||
@@ -665,7 +665,7 @@ export function ProjectComponent({ projectID }: { projectID: ID<Project> }) {//
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The loading-depth spec `{ resolve: { issues: { $each: true } } }` means "in `Project`, load `issues` and load each item in `issues` deeply". (Since an `Issue` doesn't have any further references, "deeply" actually means all its properties will be available).
|
||||
The resolve query `{ resolve: { issues: { $each: true } } }` means "in `Project`, load `issues` and load each item in `issues` deeply". (Since an `Issue` doesn't have any further references, "deeply" actually means all its properties will be available).
|
||||
|
||||
- Now, we can get rid of a lot of conditional accesses because we know that once `project` is loaded, `project.issues` and each `Issue` in it will be loaded as well.
|
||||
- This also results in only one rerender and visual update when everything is loaded, which is faster (especially for long lists) and gives you more control over the loading UX.
|
||||
@@ -712,7 +712,7 @@ function App() { // old
|
||||
// old
|
||||
const createProject = () => { // old
|
||||
const group = Group.create(); // old
|
||||
group.addMember("everyone", "writer"); // *bin*
|
||||
group.addMember("everyone", "writer"); // [!code --]
|
||||
// old
|
||||
const newProject = Project.create( // old
|
||||
{ // old
|
||||
|
||||
@@ -286,7 +286,7 @@ To display images, use the `ProgressiveImg` component from `jazz-react-native`.
|
||||
import { Image } from "react-native";
|
||||
|
||||
// Inside your render function:
|
||||
<ProgressiveImg image={someCovalue.image} maxWidth={1024}>
|
||||
<ProgressiveImg image={someCovalue.image} targetWidth={1024}>
|
||||
{({ src, res, originalSize }) => (
|
||||
<Image
|
||||
source={{ uri: src }}
|
||||
@@ -305,7 +305,7 @@ To display images, use the `ProgressiveImg` component from `jazz-react-native`.
|
||||
The `ProgressiveImg` component:
|
||||
- Automatically handles different image formats
|
||||
- Provides progressive loading with placeholder images
|
||||
- Supports different resolutions based on the `maxWidth` prop
|
||||
- Supports different resolutions based on the `targetWidth` prop
|
||||
- Works seamlessly with React Native's `Image` component
|
||||
|
||||
For a complete implementation example, see the [Chat Example](https://github.com/garden-co/jazz/blob/main/examples/chat-rn-clerk/app/chat/[chatId].tsx).
|
||||
|
||||
@@ -112,7 +112,7 @@ declare module "jazz-react" {// old
|
||||
## Resolving CoValues starting at `profile` or `root`
|
||||
|
||||
<ContentByFramework framework="react">
|
||||
To use per-user data in your app, you typically use `useAccount` somewhere in a high-level component, specifying which references to resolve using a depth-spec (see [Subscribing & deep loading](/docs/using-covalues/subscription-and-loading)).
|
||||
To use per-user data in your app, you typically use `useAccount` somewhere in a high-level component, specifying which references to resolve using a resolve query (see [Subscribing & deep loading](/docs/using-covalues/subscription-and-loading)).
|
||||
|
||||
<CodeGroup>
|
||||
{/* prettier-ignore */}
|
||||
@@ -163,12 +163,12 @@ export class MyAppAccount extends Account {
|
||||
profile = co.ref(MyAppProfile);
|
||||
|
||||
async migrate(this: MyAppAccount, creationProps?: { name: string }) {
|
||||
// we specifically need to check for undefined,
|
||||
// we specifically need to check for undefined,
|
||||
// because the root might simply be not loaded (`null`) yet
|
||||
if (this.root === undefined) {
|
||||
this.root = MyAppRoot.create({
|
||||
// Using a group to set the owner is always a good idea.
|
||||
// This way if in the future we want to share
|
||||
// This way if in the future we want to share
|
||||
// this coValue we can do so easily.
|
||||
myChats: ListOfChats.create([], Group.create()),
|
||||
myContacts: ListOfAccounts.create([], Group.create())
|
||||
@@ -218,8 +218,8 @@ export class MyAppAccount extends Account {
|
||||
root: {},
|
||||
});
|
||||
|
||||
// we specifically need to check for undefined,
|
||||
// because myBookmarks might simply be not loaded (`null`) yet
|
||||
// we specifically need to check for undefined,
|
||||
// because myBookmarks might simply be not loaded (`null`) yet
|
||||
if (root.myBookmarks === undefined) {
|
||||
root.myBookmarks = ListOfBookmarks.create([], Group.create());
|
||||
}
|
||||
@@ -228,9 +228,9 @@ export class MyAppAccount extends Account {
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
{/*
|
||||
TODO: Add best practice: only ever add fields
|
||||
{/*
|
||||
TODO: Add best practice: only ever add fields
|
||||
|
||||
Note: explain and reassure that there will be more guardrails in the future
|
||||
Note: explain and reassure that there will be more guardrails in the future
|
||||
https://github.com/garden-co/jazz/issues/1160
|
||||
*/}
|
||||
|
||||
@@ -29,9 +29,9 @@ Here is what's changed in this release:
|
||||
{/* prettier-ignore */}
|
||||
```tsx
|
||||
<JazzProvider
|
||||
auth={authMethod} // removed // *bin*
|
||||
peer="wss://cloud.jazz.tools/?key=you@example.com" // moved into sync // *bin*
|
||||
sync={{ peer: "wss://cloud.jazz.tools/?key=you@example.com" }} // *add*
|
||||
auth={authMethod} // removed // [!code --]
|
||||
peer="wss://cloud.jazz.tools/?key=you@example.com" // moved into sync // [!code --]
|
||||
sync={{ peer: "wss://cloud.jazz.tools/?key=you@example.com" }} // [!code ++]
|
||||
>
|
||||
<App />
|
||||
</JazzProvider>
|
||||
|
||||
@@ -1,110 +1,299 @@
|
||||
import { CodeGroup } from '@/components/forMdx'
|
||||
|
||||
export const metadata = { title: "Jazz 0.11.0 - Deeply resolved data" };
|
||||
export const metadata = { title: "Jazz 0.12.0 - Deeply resolved data" };
|
||||
|
||||
# Jazz 0.11.0 - Deeply resolved data
|
||||
# Jazz 0.12.0 - Deeply resolved data
|
||||
|
||||
<h2 className="not-prose text-sm text-stone-600 dark:text-stone-400 mb-5 pb-2 border-b">
|
||||
15 March 2025
|
||||
</h2>
|
||||
Jazz 0.12.0 makes it easier and safer to load nested data. You can now specify exactly which nested data you want to load, and Jazz will check permissions and handle missing data gracefully. This helps catch errors earlier during development and makes your code more reliable.
|
||||
|
||||
<div>
|
||||
Jazz 0.11.0 makes it easier and safer to load nested data. You can now specify exactly which nested data you want to load, and Jazz will check permissions and handle missing data gracefully. This helps catch errors earlier during development and makes your code more reliable.
|
||||
## What's new?
|
||||
|
||||
<h3>What's new?</h3>
|
||||
- New resolve API for a more type-safe deep loading
|
||||
- Improved permission checks on deep loading
|
||||
- Easier type safety with the Resolved type
|
||||
</div>
|
||||
- New resolve API for a more type-safe deep loading
|
||||
- A single, consistent load option for all loading methods
|
||||
- Improved permission checks on deep loading
|
||||
- Easier type safety with the `Resolved` type helper
|
||||
|
||||
<h3>New Resolve API</h3>
|
||||
<div>
|
||||
We're introducing a new resolve API for deep loading, more friendly to TypeScript, IDE autocompletion and LLMs.
|
||||
|
||||
To get started with the new resolve API, replace empty array/object parameters with structured resolve configs:
|
||||
## Breaking changes
|
||||
|
||||
### New Resolve API
|
||||
|
||||
We're introducing a new resolve API for deep loading, more friendly to TypeScript, IDE autocompletion and LLMs.
|
||||
|
||||
**Major changes:**
|
||||
|
||||
1. Functions and hooks for loading now take the resolve query as an explicit nested `resolve` prop
|
||||
2. Shallowly loading a collection is now done with `true` instead of `[]` or `{}`
|
||||
|
||||
<CodeGroup>
|
||||
{/* prettier-ignore */}
|
||||
```tsx
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451
|
||||
import { CoMap, CoList, co, Account } from "jazz-tools";
|
||||
import { useAccount } from "jazz-react";
|
||||
class AccountRoot extends CoMap { friends = co.ref(ListOfAccounts); }
|
||||
class ListOfAccounts extends CoList.Of(co.ref(Account)) {}
|
||||
class MyAppAccount extends Account { root = co.ref(AccountRoot);}
|
||||
declare module "jazz-react" { interface Register { Account: MyAppAccount; } }
|
||||
// ---cut-before---
|
||||
// Before
|
||||
const playlist = useCoState(Playlist, id, [{}]);
|
||||
const { me } = useAccount({ root: { playlists: [] } });
|
||||
// @ts-expect-error
|
||||
const { me } = useAccount({ root: { friends: [] } }); // [!code --]
|
||||
|
||||
// After
|
||||
const playlist = useCoState(Playlist, id, {
|
||||
resolve: { $each: true }
|
||||
});
|
||||
const { me } = useAccount({
|
||||
resolve: { root: { playlists: true } }
|
||||
const { me } = useAccount({ // [!code ++]
|
||||
resolve: { root: { friends: true } } // [!code ++]
|
||||
}); // [!code ++]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
3. For collections, resolving items deeply is now done with a special `$each` key.
|
||||
|
||||
For a `CoList`:
|
||||
|
||||
<CodeGroup>
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451
|
||||
import { CoList, co, ID, CoMap } from "jazz-tools";
|
||||
import { useCoState } from "jazz-react";
|
||||
|
||||
// ---cut-before---
|
||||
class Task extends CoMap { }
|
||||
class ListOfTasks extends CoList.Of(co.ref(Task)) {}
|
||||
|
||||
const id = "co_123" as ID<Task>;
|
||||
|
||||
// Before
|
||||
// @ts-expect-error
|
||||
const tasks = useCoState(ListOfTasks, id, [{}]); // [!code --]
|
||||
|
||||
// After
|
||||
const tasks = useCoState(ListOfTasks, id, { resolve: { $each: true } }); // [!code ++]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
For a `CoMap.Record`:
|
||||
|
||||
<CodeGroup>
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451
|
||||
import { CoMap, co, Account, ID } from "jazz-tools";
|
||||
import { useCoState } from "jazz-react";
|
||||
class MyAppAccount extends Account {}
|
||||
const id = "co_123" as ID<UsersByUsername>;
|
||||
|
||||
// ---cut-before---
|
||||
class UsersByUsername extends CoMap.Record(co.ref(MyAppAccount)) {}
|
||||
|
||||
// Before
|
||||
// @ts-expect-error
|
||||
const usersByUsername = useCoState(UsersByUsername, id, [{}]); // [!code --]
|
||||
|
||||
// After
|
||||
const usersByUsername = useCoState(UsersByUsername, id, { // [!code ++]
|
||||
resolve: { $each: true } // [!code ++]
|
||||
}); // [!code ++]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
Nested loading — note how it's now less terse, but more readable:
|
||||
|
||||
<CodeGroup>
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451
|
||||
import { CoList, CoMap, co, Account, ID } from "jazz-tools";
|
||||
import { useCoState } from "jazz-react";
|
||||
|
||||
const id = "co_123" as ID<ListOfTasks>;
|
||||
|
||||
// ---cut-before---
|
||||
class Org extends CoMap {
|
||||
name = co.string;
|
||||
}
|
||||
|
||||
class Assignee extends CoMap {
|
||||
name = co.string;
|
||||
org = co.ref(Org);
|
||||
}
|
||||
class ListOfAssignees extends CoList.Of(co.ref(Assignee)) {}
|
||||
|
||||
class Task extends CoMap {
|
||||
content = co.string;
|
||||
assignees = co.ref(ListOfAssignees);
|
||||
}
|
||||
class ListOfTasks extends CoList.Of(co.ref(Task)) {}
|
||||
|
||||
// Before
|
||||
// @ts-expect-error
|
||||
const tasksWithAssigneesAndTheirOrgs = useCoState(ListOfTasks, id, [{ // [!code --]
|
||||
assignees: [{ org: {}}]} // [!code --]
|
||||
]); // [!code --]
|
||||
|
||||
// After
|
||||
const tasksWithAssigneesAndTheirOrgs = useCoState(ListOfTasks, id, { // [!code ++]
|
||||
resolve: { // [!code ++]
|
||||
$each: { // [!code ++]
|
||||
assignees: { // [!code ++]
|
||||
$each: { org: true } // [!code ++]
|
||||
} // [!code ++]
|
||||
} // [!code ++]
|
||||
} // [!code ++]
|
||||
}); // [!code ++]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
It's also a lot more auto-complete friendly:
|
||||
|
||||
<CodeGroup>
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451 2353 2581
|
||||
import { CoList, CoMap, co, ID } from "jazz-tools";
|
||||
import { useCoState } from "jazz-react";
|
||||
|
||||
class Org extends CoMap { name = co.string; }
|
||||
class Assignee extends CoMap { org = co.ref(Org); }
|
||||
class ListOfAssignees extends CoList.Of(co.ref(Assignee)) {}
|
||||
class Task extends CoMap { assignees = co.ref(ListOfAssignees); }
|
||||
class ListOfTasks extends CoList.Of(co.ref(Task)) {}
|
||||
const id = "co_123" as ID<ListOfTasks>;
|
||||
|
||||
// ---cut-before---
|
||||
const tasksWithAssigneesAndTheirOrgs = useCoState(ListOfTasks, id, {
|
||||
resolve: {
|
||||
$each: {
|
||||
assignees: {
|
||||
$
|
||||
// ^|
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The new API works across all loading methods:
|
||||
### A single, consistent load option
|
||||
|
||||
The new API works across all loading methods, and separating out the resolve query means
|
||||
other options with default values are easier to manage, for example: loading a value as a specific account instead of using the implicit current account:
|
||||
|
||||
<CodeGroup>
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
```ts twoslash
|
||||
// @noErrors: 2451
|
||||
import { co, Account, CoMap, CoList, ID } from "jazz-tools";
|
||||
|
||||
class Track extends CoMap {}
|
||||
class ListOfTracks extends CoList.Of(co.ref(Track)) {}
|
||||
class Playlist extends CoMap { tracks = co.ref(ListOfTracks); }
|
||||
const id = "co_123" as ID<Playlist>;
|
||||
const otherAccount = {} as Account;
|
||||
|
||||
// ---cut-before---
|
||||
// Before
|
||||
Playlist.load(id, account, {
|
||||
tracks: [],
|
||||
});
|
||||
// @ts-expect-error
|
||||
Playlist.load(id, otherAccount, { // [!code --]
|
||||
tracks: [], // [!code --]
|
||||
}); // [!code --]
|
||||
|
||||
// After
|
||||
Playlist.load(id, {
|
||||
loadAs: account,
|
||||
resolve: { tracks: true }
|
||||
});
|
||||
Playlist.load(id, { // [!code ++]
|
||||
loadAs: otherAccount, // [!code ++]
|
||||
resolve: { tracks: true } // [!code ++]
|
||||
}); // [!code ++]
|
||||
```
|
||||
</CodeGroup>
|
||||
</div>
|
||||
|
||||
<h3>Improved permission checks on deep loading</h3>
|
||||
<div>
|
||||
Now `useCoState` will return `null` when the current user lacks permissions to load the requested data.
|
||||
### Improved permission checks on deep loading
|
||||
|
||||
Previously, `useCoState` would return `undefined` if the current user lacked permissions, making it hard to tell if the value is loading or if it's missing.
|
||||
Now `useCoState` will return `null` when the current user lacks permissions to load requested data.
|
||||
|
||||
Now `undefined` means that the value is definitely loading, and `null` means that the value is temporarily missing.
|
||||
Previously, `useCoState` would return `undefined` if the current user lacked permissions, making it hard to tell if the value is loading or if it's missing.
|
||||
|
||||
We also have implemented a more granular permission checking, where if an optional coValue cannot be accessed, useCoState will return the data stripped of that coValue.
|
||||
Now `undefined` means that the value is definitely loading, and `null` means that the value is temporarily missing.
|
||||
|
||||
We also have implemented a more granular permission checking, where if an *optional* CoValue cannot be accessed, `useCoState` will return the data stripped of that CoValue.
|
||||
|
||||
**Note:** The state handling around loading and error states will become more detailed and easy-to-handle in future releases, so this is just a small step towards consistency.
|
||||
|
||||
<CodeGroup>
|
||||
{/* prettier-ignore */}
|
||||
```tsx
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451
|
||||
import React from "react";
|
||||
import { CoList, CoMap, co, ID } from "jazz-tools";
|
||||
import { useCoState } from "jazz-react";
|
||||
class Track extends CoMap {}
|
||||
function TrackComponent({ track }: { track: Track }) {return ""}
|
||||
|
||||
// ---cut-before---
|
||||
class ListOfTracks extends CoList.Of(co.optional.ref(Track)) {}
|
||||
// Before (ambiguous states)
|
||||
const value = useCoState(ListOfTracks, id, [{}]);
|
||||
if (value === undefined) return <div>Loading or access denied</div>;
|
||||
if (value === null) return <div>Not found</div>;
|
||||
|
||||
// After
|
||||
const value = useCoState(ListOfTracks, id, { resolve: { $each: true } });
|
||||
if (value === undefined) return <div>Loading...</div>;
|
||||
if (value === null) return <div>Not found or access denied</div>;
|
||||
function TrackListComponent({ id }: { id: ID<ListOfTracks> }) {
|
||||
// Before (ambiguous states)
|
||||
// @ts-expect-error
|
||||
const tracks = useCoState(ListOfTracks, id, [{}]); // [!code --]
|
||||
if (tracks === undefined) return <div>Loading or access denied</div>; // [!code --]
|
||||
if (tracks === null) return <div>Not found</div>; // [!code --]
|
||||
|
||||
// If the current user lacks permissions to load a Track, the ListOfTracks will be returned without that Track.
|
||||
return tracks.map(track => track && <MusicTrack track={track} />);
|
||||
// After
|
||||
const tracks = useCoState(ListOfTracks, id, { resolve: { $each: true } }); // [!code ++]
|
||||
if (tracks === undefined) return <div>Loading...</div>; // [!code ++]
|
||||
if (tracks === null) return <div>Not found or access denied</div>; // [!code ++]
|
||||
|
||||
// This will only show tracks that we have access to and that are loaded.
|
||||
return tracks.map(track => track && <TrackComponent track={track} />);
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
</div>
|
||||
|
||||
<h3>Type Safety Improvements</h3>
|
||||
<div>
|
||||
The new `Resolved` type can be used to define what kind of deeply loaded data you expect in your parameters:
|
||||
The same change is applied to the load function, so now it returns `null` instead of `undefined` when the value is missing.
|
||||
|
||||
<CodeGroup>
|
||||
{/* prettier-ignore */}
|
||||
```ts
|
||||
<CodeGroup>
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451
|
||||
import { CoMap, co, ID } from "jazz-tools";
|
||||
import { useAccount } from "jazz-react";
|
||||
|
||||
class MyCoMap extends CoMap {}
|
||||
const id = "co_123" as ID<MyCoMap>;
|
||||
|
||||
// ---cut-before---
|
||||
// Before
|
||||
// @ts-expect-error
|
||||
const map = await MyCoMap.load(id);
|
||||
if (map === undefined) {
|
||||
throw new Error("Map not found");
|
||||
}
|
||||
|
||||
// After
|
||||
const map = await MyCoMap.load(id);
|
||||
if (map === null) {
|
||||
throw new Error("Map not found or access denied");
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
## New Features
|
||||
|
||||
### The `Resolved` type helper
|
||||
|
||||
The new `Resolved` type can be used to define what kind of deeply loaded data you expect in your parameters, using the same resolve query syntax as the new loading APIs:
|
||||
|
||||
<CodeGroup>
|
||||
```tsx twoslash
|
||||
// @noErrors: 2451
|
||||
import React from "react";
|
||||
import { Resolved, CoMap, CoList, co } from "jazz-tools";
|
||||
class Track extends CoMap {}
|
||||
class ListOfTracks extends CoList.Of(co.ref(Track)) {}
|
||||
class Playlist extends CoMap { tracks = co.ref(ListOfTracks); }
|
||||
function TrackComponent({ track }: { track: Track }) {return ""}
|
||||
|
||||
// ---cut-before---
|
||||
type PlaylistResolved = Resolved<Playlist, {
|
||||
tracks: { $each: true }
|
||||
}>;
|
||||
|
||||
// After
|
||||
function TrackList({ playlist }: { playlist: PlaylistResolved }) {
|
||||
function TrackListComponent({ playlist }: { playlist: PlaylistResolved }) {
|
||||
// Safe access to resolved tracks
|
||||
return playlist.tracks.map(track => /* ... */);
|
||||
return playlist.tracks.map(track => <TrackComponent track={track} />);
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
</div>
|
||||
|
||||
@@ -25,9 +25,9 @@ So we decided to remove `createJazzRNApp` step and to provide the types through
|
||||
import { JazzProvider, useDemoAuth, DemoAuthBasicUI } from "jazz-react-native";
|
||||
import { MyAppAccount } from "./schema";
|
||||
|
||||
// Remove these lines // *bin*
|
||||
const Jazz = createJazzRNApp({ AccountSchema: MyAppAccount }); // *bin*
|
||||
export const { useAccount, useCoState } = Jazz; // *bin*
|
||||
// Remove these lines // [!code --]
|
||||
const Jazz = createJazzRNApp({ AccountSchema: MyAppAccount }); // [!code --]
|
||||
export const { useAccount, useCoState } = Jazz; // [!code --]
|
||||
|
||||
export function JazzAndAuth({ children }: { children: React.ReactNode }) { // old
|
||||
const [auth, state] = useDemoAuth(); // old
|
||||
@@ -66,8 +66,8 @@ This change improves IDE intellisense support and simplifies imports:
|
||||
{/* prettier-ignore */}
|
||||
```tsx
|
||||
// Replace local imports with "jazz-react-native" imports
|
||||
import { useAccount } from "./main"; // *bin*
|
||||
import { useAccount } from "jazz-react-native"; // *add*
|
||||
import { useAccount } from "./main"; // [!code --]
|
||||
import { useAccount } from "jazz-react-native"; // [!code ++]
|
||||
|
||||
export function Hello() {
|
||||
const { me } = useAccount();
|
||||
|
||||
@@ -24,9 +24,9 @@ So we decided to remove `createJazzReactApp` step and to provide the types throu
|
||||
import { JazzProvider, usePasskeyAuth, PasskeyAuthBasicUI } from "jazz-react";
|
||||
import { MyAppAccount } from "./schema";
|
||||
|
||||
// Remove these lines // *bin*
|
||||
const Jazz = createJazzReactApp({ AccountSchema: MyAppAccount }); // *bin*
|
||||
export const { useAccount, useCoState } = Jazz; // *bin*
|
||||
// Remove these lines // [!code --]
|
||||
const Jazz = createJazzReactApp({ AccountSchema: MyAppAccount }); // [!code --]
|
||||
export const { useAccount, useCoState } = Jazz; // [!code --]
|
||||
|
||||
export function JazzAndAuth({ children }: { children: React.ReactNode }) { // old
|
||||
const [passkeyAuth, passKeyState] = usePasskeyAuth({ appName }); // old
|
||||
@@ -37,7 +37,7 @@ So we decided to remove `createJazzReactApp` step and to provide the types throu
|
||||
<JazzProvider
|
||||
auth={passkeyAuth} // old
|
||||
peer="wss://cloud.jazz.tools/?key=you@example.com" // old
|
||||
AccountSchema={MyAppAccount} {/* The custom Account schema is passed here */} // *add*
|
||||
AccountSchema={MyAppAccount} {/* The custom Account schema is passed here */} // [!code ++]
|
||||
>
|
||||
{children} // old
|
||||
</JazzProvider>
|
||||
@@ -47,11 +47,11 @@ So we decided to remove `createJazzReactApp` step and to provide the types throu
|
||||
}
|
||||
|
||||
// Register the Account schema so `useAccount` returns our custom `MyAppAccount`
|
||||
declare module "jazz-react" { // *add*
|
||||
interface Register { // *add*
|
||||
Account: MyAppAccount; // *add*
|
||||
} // *add*
|
||||
} // *add*
|
||||
declare module "jazz-react" { // [!code ++]
|
||||
interface Register { // [!code ++]
|
||||
Account: MyAppAccount; // [!code ++]
|
||||
} // [!code ++]
|
||||
} // [!code ++]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -65,8 +65,8 @@ This change improves IDE intellisense support and simplifies imports:
|
||||
{/* prettier-ignore */}
|
||||
```tsx
|
||||
// Replace local imports with "jazz-react" imports
|
||||
import { useAccount } from "./main"; // *bin*
|
||||
import { useAccount } from "jazz-react"; // *add*
|
||||
import { useAccount } from "./main"; // [!code --]
|
||||
import { useAccount } from "jazz-react"; // [!code ++]
|
||||
|
||||
export function Hello() {
|
||||
const { me } = useAccount();
|
||||
|
||||
@@ -32,7 +32,7 @@ So we decided to remove `createJazzApp` step and to provide the types through na
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { Provider } from '$lib/jazz'; // *bin*
|
||||
import { Provider } from '$lib/jazz'; // [!code --]
|
||||
import { JazzProvider } from 'jazz-svelte';
|
||||
|
||||
// Example configuration for authentication and peer connection
|
||||
@@ -62,8 +62,8 @@ So we decided to remove `createJazzApp` step and to provide the types through na
|
||||
```svelte
|
||||
|
||||
<script lang="ts">
|
||||
import { useAccount } from '$lib/jazz'; // *bin*
|
||||
import { useAccount } from 'jazz-svelte'; // *add*
|
||||
import { useAccount } from '$lib/jazz'; // [!code --]
|
||||
import { useAccount } from 'jazz-svelte'; // [!code ++]
|
||||
|
||||
const { me } = useAccount();
|
||||
</script>
|
||||
|
||||
@@ -28,10 +28,10 @@ import App from "./App.vue"; // old
|
||||
import router from "./router"; // old
|
||||
import { ToDoAccount } from "./schema"; // old
|
||||
|
||||
// Remove these lines // *bin*
|
||||
const Jazz = createJazzVueApp<ToDoAccount>({ AccountSchema: ToDoAccount }); // *bin*
|
||||
export const { useAccount, useCoState } = Jazz; // *bin*
|
||||
const { JazzProvider } = Jazz; // *bin*
|
||||
// Remove these lines // [!code --]
|
||||
const Jazz = createJazzVueApp<ToDoAccount>({ AccountSchema: ToDoAccount }); // [!code --]
|
||||
export const { useAccount, useCoState } = Jazz; // [!code --]
|
||||
const { JazzProvider } = Jazz; // [!code --]
|
||||
|
||||
const RootComponent = defineComponent({ // old
|
||||
name: "RootComponent", // old
|
||||
@@ -86,8 +86,8 @@ This change improves IDE intellisense support and simplifies imports:
|
||||
|
||||
<script setup lang="ts">
|
||||
// Replace local imports with "jazz-vue" imports
|
||||
import { useAccount } from "./main"; // *bin*
|
||||
import { useAccount } from "jazz-vue"; // *add*
|
||||
import { useAccount } from "./main"; // [!code --]
|
||||
import { useAccount } from "jazz-vue"; // [!code ++]
|
||||
|
||||
const { me, logOut } = useAccount();
|
||||
</script>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { CodeGroup } from "@/components/forMdx";
|
||||
|
||||
export const metadata = { title: "Metadata & time-travel" };
|
||||
export const metadata = { title: "History & time-travel" };
|
||||
|
||||
# Metadata & time-travel
|
||||
# History & time-travel
|
||||
|
||||
One of Jazz's most powerful features is that every CoValue automatically tracks its complete edit history. This means you can see who changed what and when, examine the state of your data at any point in time, and build features like audit logs, activity feeds, and undo/redo functionality. This page explores how to access and work with the rich metadata that comes with every CoValue.
|
||||
|
||||
@@ -115,11 +115,11 @@ Activity feeds are a great way to see recent changes to a CoValue, helping users
|
||||
function getRecentActivity(project: Project) {
|
||||
const activity = [];
|
||||
const hourAgo = new Date(Date.now() - 3600000);
|
||||
|
||||
|
||||
for (const field of Object.keys(project)) {
|
||||
// Skip if the field doesn't have edits
|
||||
if (!project._edits[field as keyof typeof project._edits]) continue;
|
||||
|
||||
|
||||
for (const edit of project._edits[field as keyof typeof project._edits].all) {
|
||||
if (edit.madeAt > hourAgo) {
|
||||
activity.push({
|
||||
@@ -128,10 +128,10 @@ function getRecentActivity(project: Project) {
|
||||
by: edit.by,
|
||||
at: edit.madeAt
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return activity.sort((a, b) => b.at.getTime() - a.at.getTime());
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ recentActivity.forEach(activity => {
|
||||
|
||||
CoValues track their entire history of changes, creating a timeline you can explore. You can see who changed what and when, or even view past states of the data. This capability enables powerful debugging tools and user-facing features like history browsing and restoration of previous versions:
|
||||
|
||||
<CodeGroup>
|
||||
<CodeGroup>
|
||||
```ts
|
||||
class Task extends CoMap {
|
||||
title = co.string;
|
||||
@@ -206,7 +206,7 @@ class Project extends CoMap {
|
||||
function findStatusChange(project: Project, targetStatus: string) {
|
||||
// Get all the edits for the status field
|
||||
const statusEdits = project._edits.status.all;
|
||||
|
||||
|
||||
for (const edit of statusEdits) {
|
||||
if (edit.value === targetStatus) {
|
||||
console.log({
|
||||
@@ -233,7 +233,7 @@ The time travel capabilities of CoValues enable several practical use cases that
|
||||
function getTaskStatusHistory(task: Task, days: number = 7) {
|
||||
const statusHistory = [];
|
||||
const dayInMs = 86400000;
|
||||
|
||||
|
||||
// Check every day for the past week
|
||||
for (let day = 0; day < days; day++) {
|
||||
const timePoint = new Date(Date.now() - day * dayInMs);
|
||||
@@ -245,7 +245,7 @@ function getTaskStatusHistory(task: Task, days: number = 7) {
|
||||
priority: state.priority
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return statusHistory;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user