Compare commits
317 Commits
jazz-react
...
fix/code-h
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d73896b24c | ||
|
|
1ab581358e | ||
|
|
9fca21a3f8 | ||
|
|
a11f531d4b | ||
|
|
9dd717bf0e | ||
|
|
42551bb4fd | ||
|
|
5c5de61cb6 | ||
|
|
7fdfc7fddb | ||
|
|
b108c6166e | ||
|
|
e0bc9a7f67 | ||
|
|
f900495f8d | ||
|
|
4188c7a18d | ||
|
|
7315960477 | ||
|
|
815f485ee5 | ||
|
|
402008a08f | ||
|
|
bc1576cb92 | ||
|
|
acbe66ed60 | ||
|
|
ec1fd2aaa2 | ||
|
|
bd796555f2 | ||
|
|
153f6ec245 | ||
|
|
42d007da13 | ||
|
|
c764eeff56 | ||
|
|
a7a00e6a7c | ||
|
|
bc65695eee | ||
|
|
153231aecb | ||
|
|
d814899d71 | ||
|
|
0b6c35c08a | ||
|
|
e62ea5a8ac | ||
|
|
a5bffd7312 | ||
|
|
9aa91ec525 | ||
|
|
9b8c299ba5 | ||
|
|
7486ca768d | ||
|
|
fa4d501eb0 | ||
|
|
a126d5dbf8 | ||
|
|
d697cc5713 | ||
|
|
d95c8cc302 | ||
|
|
9dee93af1b | ||
|
|
0dffa407a8 | ||
|
|
0d97f161bd | ||
|
|
b9525b675e | ||
|
|
5a00fe0862 | ||
|
|
3db07f541f | ||
|
|
0db2e60d09 | ||
|
|
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 | ||
|
|
b04e2be665 | ||
|
|
e13b9d2689 | ||
|
|
523196acdd | ||
|
|
24d291b65f | ||
|
|
3367787f37 | ||
|
|
e7ae1359c0 | ||
|
|
55e81849fe | ||
|
|
a2ad4a7dc3 | ||
|
|
dbaa1dfe3f | ||
|
|
452d5f3030 | ||
|
|
80b1535cdf | ||
|
|
16263442a7 | ||
|
|
15384db02d | ||
|
|
fa13fbf247 | ||
|
|
291562aafe | ||
|
|
b8ff6d2195 | ||
|
|
f0483b2500 | ||
|
|
dda9672dcb | ||
|
|
a86cd0e74e | ||
|
|
95e84a2ca7 | ||
|
|
e7c85b7575 | ||
|
|
90138a6848 | ||
|
|
8ad57f9d50 | ||
|
|
4a0f70692f | ||
|
|
51db96e8d0 | ||
|
|
4b0b27bde7 | ||
|
|
29a177224d | ||
|
|
63ccdaa3b2 | ||
|
|
8ed144e857 | ||
|
|
c9e2ab69bf | ||
|
|
b55c276296 | ||
|
|
539f2b23ef | ||
|
|
daea669cb2 | ||
|
|
55793722ff | ||
|
|
849f716700 | ||
|
|
39d50ef040 | ||
|
|
73b120637c | ||
|
|
f41f61ffd3 | ||
|
|
3436728416 | ||
|
|
7ad2210a7f | ||
|
|
4263c30753 | ||
|
|
416dd79b50 | ||
|
|
11da4d1366 | ||
|
|
6e794c3fed | ||
|
|
080a718c4d | ||
|
|
e5891f77ca | ||
|
|
e141c8779b | ||
|
|
868c49d096 | ||
|
|
bdc78c55fc | ||
|
|
2dbe990c22 | ||
|
|
60b8dbc33c | ||
|
|
5337edf717 | ||
|
|
fe60a88de9 | ||
|
|
939e1d7a3c | ||
|
|
19871690e4 | ||
|
|
064900d5f9 | ||
|
|
8e44caaebc | ||
|
|
c95f344c41 | ||
|
|
7320adc58d | ||
|
|
57a92f4aa0 | ||
|
|
c9b2b01928 | ||
|
|
5b97ac3b92 | ||
|
|
09f0a98eef | ||
|
|
3d8babdbb6 | ||
|
|
f10004c6bc | ||
|
|
33ecca3d10 | ||
|
|
bc601d809b | ||
|
|
cc8462f071 | ||
|
|
790d5dde40 | ||
|
|
7326a19373 | ||
|
|
f39c87b181 | ||
|
|
e19681a4a7 | ||
|
|
c5a3b29c61 | ||
|
|
79513379c8 | ||
|
|
1271a6f753 | ||
|
|
77f58ddcad | ||
|
|
7e945b5eac | ||
|
|
deea2222cb | ||
|
|
ff4a839dca | ||
|
|
fb053a0dd5 | ||
|
|
253b775bff | ||
|
|
831fce6d55 | ||
|
|
e3f85f997c | ||
|
|
44043991fb | ||
|
|
60af229bcc | ||
|
|
be6dafc36a | ||
|
|
cdf3ed898f | ||
|
|
d2379eacd7 | ||
|
|
0525d5c056 | ||
|
|
7803a7a85e | ||
|
|
e9d131cc9c | ||
|
|
4f2730fa00 | ||
|
|
b416136b12 | ||
|
|
56869c3593 | ||
|
|
bce7dade72 | ||
|
|
2c00f93141 | ||
|
|
1bfa9bb1de | ||
|
|
9106881d19 | ||
|
|
75319a6eaf | ||
|
|
01e54ddf4e | ||
|
|
8f6e16a899 | ||
|
|
a4e342a59b | ||
|
|
73b71df524 | ||
|
|
fcaa5dddda | ||
|
|
c27fadc4e0 | ||
|
|
56af3c7412 | ||
|
|
5e5ef10675 | ||
|
|
2efc55f9bf | ||
|
|
7101f10573 | ||
|
|
3849392272 | ||
|
|
ce1fc720c1 | ||
|
|
4eb634175d | ||
|
|
adc6343531 | ||
|
|
c745e099fe | ||
|
|
970c9f5c6c | ||
|
|
4e3986ae98 | ||
|
|
6c691bf641 | ||
|
|
d03ba7fdd0 | ||
|
|
35cb7d8988 | ||
|
|
0e40a9daab | ||
|
|
bd1996c458 | ||
|
|
373ebec04c | ||
|
|
7fedbeb8e4 | ||
|
|
4bfc23091c | ||
|
|
6e5ea6f19c | ||
|
|
bcd67cb23f | ||
|
|
27781ed778 | ||
|
|
eb097ecdb1 | ||
|
|
cdae2603ba | ||
|
|
2b3490cce2 | ||
|
|
4baba65cdd | ||
|
|
c6ef96d642 | ||
|
|
3d882f0442 | ||
|
|
f61d568c9d | ||
|
|
02fe68d207 | ||
|
|
0f87cfbbb0 | ||
|
|
3615b4871b | ||
|
|
cc1eb6da90 | ||
|
|
f7b91b7ce1 | ||
|
|
e2b1247969 | ||
|
|
6dd02d289c | ||
|
|
33a4944ba3 | ||
|
|
e367b6056d | ||
|
|
f3f56b9be0 | ||
|
|
4cae6bad34 | ||
|
|
17f2ef57de | ||
|
|
3a4d111a37 | ||
|
|
1e18c7f5fc | ||
|
|
8c7a6b27ed | ||
|
|
91f96e1188 | ||
|
|
65b2947c18 | ||
|
|
f9147dae85 | ||
|
|
28dac10723 | ||
|
|
9cb11e38dd | ||
|
|
21309953ee | ||
|
|
bc2f37df37 | ||
|
|
57ffac4432 | ||
|
|
f3e4bacb33 | ||
|
|
626d43f07b | ||
|
|
1f5d073035 | ||
|
|
a3b607e799 | ||
|
|
8fb93502af | ||
|
|
36774122e0 | ||
|
|
a6923128c1 | ||
|
|
706ca62feb | ||
|
|
01523dcca3 | ||
|
|
77f039b561 | ||
|
|
d661ba77be | ||
|
|
f8fbc59b6f | ||
|
|
cce0d22007 | ||
|
|
e3ff76e9cb | ||
|
|
4cbf71bff7 | ||
|
|
ceb060243a | ||
|
|
a70bebb96a | ||
|
|
b3b2507c35 | ||
|
|
6a8fa16b49 | ||
|
|
1f08807701 | ||
|
|
ba4a7f6170 | ||
|
|
a2854e3602 | ||
|
|
4ea87dc494 | ||
|
|
d8c87c5314 | ||
|
|
46f624a12e | ||
|
|
86ce770f38 |
5
.changeset/good-parrots-rhyme.md
Normal file
5
.changeset/good-parrots-rhyme.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"multiauth": patch
|
||||
---
|
||||
|
||||
Use the new Resolve API
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
8
.idea/jazz.iml
generated
Normal file
8
.idea/jazz.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/jazz.iml" filepath="$PROJECT_DIR$/.idea/jazz.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
19
.idea/php.xml
generated
Normal file
19
.idea/php.xml
generated
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/prettier.xml
generated
Normal file
6
.idea/prettier.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PrettierConfiguration">
|
||||
<option name="myConfigurationMode" value="AUTOMATIC" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,5 +1,58 @@
|
||||
# chat-rn-clerk
|
||||
|
||||
## 1.0.91
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.12.1
|
||||
- jazz-react-native-auth-clerk@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
- jazz-react-native-media-images@0.12.1
|
||||
|
||||
## 1.0.90
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-react-native@0.12.0
|
||||
- jazz-react-native-auth-clerk@0.12.0
|
||||
- jazz-react-native-media-images@0.12.0
|
||||
|
||||
## 1.0.89
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.11.8
|
||||
- jazz-react-native-auth-clerk@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
- jazz-react-native-media-images@0.11.8
|
||||
|
||||
## 1.0.88
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react-native@0.11.7
|
||||
- jazz-react-native-auth-clerk@0.11.7
|
||||
- jazz-react-native-media-images@0.11.7
|
||||
|
||||
## 1.0.87
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
|
||||
- Updated dependencies [e7c85b7]
|
||||
- jazz-react-native@0.11.6
|
||||
- jazz-tools@0.11.6
|
||||
- jazz-react-native-auth-clerk@0.11.6
|
||||
- jazz-react-native-media-images@0.11.6
|
||||
|
||||
## 1.0.86
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function Conversation() {
|
||||
const { me } = useAccount();
|
||||
const [chat, setChat] = useState<Chat>();
|
||||
const [message, setMessage] = useState("");
|
||||
const loadedChat = useCoState(Chat, chat?.id, [{}]);
|
||||
const loadedChat = useCoState(Chat, chat?.id, { resolve: { $each: true } });
|
||||
const navigation = useNavigation();
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
|
||||
@@ -71,7 +71,7 @@ export default function Conversation() {
|
||||
|
||||
const loadChat = async (chatId: ID<Chat>) => {
|
||||
try {
|
||||
const chat = await Chat.load(chatId, me, []);
|
||||
const chat = await Chat.load(chatId, me);
|
||||
setChat(chat);
|
||||
} catch (error) {
|
||||
console.log("Error loading chat", error);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "chat-rn-clerk",
|
||||
"main": "index.js",
|
||||
"version": "1.0.86",
|
||||
"version": "1.0.91",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
"start": "expo start",
|
||||
|
||||
@@ -12,7 +12,6 @@ export function JazzAndAuth({ children }: PropsWithChildren) {
|
||||
storage="sqlite"
|
||||
sync={{
|
||||
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
|
||||
when: "signedUp", // This makes the app work in local mode when the user is not authenticated
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
# chat-rn
|
||||
|
||||
## 1.0.87
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 1.0.86
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-react-native@0.12.0
|
||||
|
||||
## 1.0.85
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react-native@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 1.0.84
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react-native@0.11.7
|
||||
|
||||
## 1.0.83
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7c85b7]
|
||||
- jazz-react-native@0.11.6
|
||||
- jazz-tools@0.11.6
|
||||
|
||||
## 1.0.82
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-rn",
|
||||
"version": "1.0.82",
|
||||
"version": "1.0.87",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "expo export -p ios",
|
||||
|
||||
@@ -20,7 +20,7 @@ import { Chat, Message } from "./schema";
|
||||
export default function ChatScreen({ navigation }: { navigation: any }) {
|
||||
const { me, logOut } = useAccount();
|
||||
const [chatId, setChatId] = useState<ID<Chat>>();
|
||||
const loadedChat = useCoState(Chat, chatId, [{}]);
|
||||
const loadedChat = useCoState(Chat, chatId, { resolve: { $each: true } });
|
||||
const [message, setMessage] = useState("");
|
||||
const profile = useCoState(Profile, me._refs.profile?.id, {});
|
||||
|
||||
|
||||
@@ -1,5 +1,53 @@
|
||||
# chat-vue
|
||||
|
||||
## 0.0.72
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
- jazz-vue@0.12.1
|
||||
|
||||
## 0.0.71
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- Updated dependencies [4c01459]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-vue@0.12.0
|
||||
- jazz-browser@0.12.0
|
||||
|
||||
## 0.0.70
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-browser@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
- jazz-vue@0.11.8
|
||||
|
||||
## 0.0.69
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-browser@0.11.7
|
||||
- jazz-vue@0.11.7
|
||||
|
||||
## 0.0.68
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7c85b7]
|
||||
- jazz-tools@0.11.6
|
||||
- jazz-vue@0.11.6
|
||||
- jazz-browser@0.11.6
|
||||
|
||||
## 0.0.67
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -11,12 +11,12 @@ You can either
|
||||
|
||||
Create a new Jazz project, and use this example as a template.
|
||||
```bash
|
||||
npx create-jazz-app@latest --example chat-vue --project-name chat-vue
|
||||
npx create-jazz-app@latest chat-vue-app --example chat-vue
|
||||
```
|
||||
|
||||
Go to the new project directory.
|
||||
```bash
|
||||
cd chat-vue
|
||||
cd chat-vue-app
|
||||
```
|
||||
|
||||
Run the dev server.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-vue",
|
||||
"version": "0.0.67",
|
||||
"version": "0.0.72",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -49,7 +49,7 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const chat = useCoState(Chat, props.chatId, [{}]);
|
||||
const chat = useCoState(Chat, props.chatId, { resolve: { $each: true } });
|
||||
const showNLastMessages = ref(30);
|
||||
|
||||
const displayedMessages = computed(() => {
|
||||
|
||||
@@ -1,5 +1,60 @@
|
||||
# jazz-example-chat
|
||||
|
||||
## 0.0.169
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-inspector@0.12.1
|
||||
- jazz-react@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 0.0.168
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- Updated dependencies [9a56bb3]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-inspector@0.12.0
|
||||
- jazz-react@0.12.0
|
||||
|
||||
## 0.0.167
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [71b9390]
|
||||
- jazz-inspector@0.11.8
|
||||
- jazz-react@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.166
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [2c3761c]
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [4019918]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-inspector@0.11.7
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react@0.11.7
|
||||
|
||||
## 0.0.165
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7c85b7]
|
||||
- Updated dependencies [09f0a98]
|
||||
- Updated dependencies [11da4d1]
|
||||
- Updated dependencies [8ed144e]
|
||||
- jazz-react@0.11.6
|
||||
- jazz-tools@0.11.6
|
||||
- jazz-inspector@0.11.6
|
||||
- jazz-browser-media-images@0.11.6
|
||||
|
||||
## 0.0.164
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -13,12 +13,12 @@ You can either
|
||||
|
||||
Create a new Jazz project, and use this example as a template.
|
||||
```bash
|
||||
npx create-jazz-app@latest --example chat --project-name chat
|
||||
npx create-jazz-app@latest chat-app --example chat
|
||||
```
|
||||
|
||||
Go to the new project directory.
|
||||
```bash
|
||||
cd chat
|
||||
cd chat-app
|
||||
```
|
||||
|
||||
Run the dev server.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-example-chat",
|
||||
"private": true,
|
||||
"version": "0.0.164",
|
||||
"version": "0.0.169",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -15,7 +15,7 @@
|
||||
"dependencies": {
|
||||
"clsx": "^2.0.0",
|
||||
"hash-slash": "workspace:*",
|
||||
"jazz-browser-media-images": "workspace:*",
|
||||
"jazz-inspector": "workspace:*",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"lucide-react": "^0.274.0",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { apiKey } from "@/apiKey.ts";
|
||||
import { getRandomUsername, inIframe, onChatLoad } from "@/util.ts";
|
||||
import { useIframeHashRouter } from "hash-slash";
|
||||
import { JazzInspector } from "jazz-inspector";
|
||||
import { JazzProvider, useAccount } from "jazz-react";
|
||||
import { Group, ID } from "jazz-tools";
|
||||
import { StrictMode } from "react";
|
||||
@@ -61,6 +62,7 @@ createRoot(document.getElementById("root")!).render(
|
||||
defaultProfileName={defaultProfileName}
|
||||
>
|
||||
<App />
|
||||
<JazzInspector />
|
||||
</JazzProvider>
|
||||
</StrictMode>
|
||||
</ThemeProvider>,
|
||||
|
||||
@@ -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";
|
||||
@@ -17,8 +16,8 @@ import {
|
||||
} from "./ui.tsx";
|
||||
|
||||
export function ChatScreen(props: { chatID: ID<Chat> }) {
|
||||
const chat = useCoState(Chat, props.chatID, { resolve: { $each: true } });
|
||||
const account = useAccount();
|
||||
const chat = useCoState(Chat, props.chatID, [{}]);
|
||||
const [showNLastMessages, setShowNLastMessages] = useState(30);
|
||||
|
||||
if (!chat)
|
||||
|
||||
@@ -1,5 +1,54 @@
|
||||
# minimal-auth-clerk
|
||||
|
||||
## 0.0.68
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.12.1
|
||||
- jazz-react-auth-clerk@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 0.0.67
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-react@0.12.0
|
||||
- jazz-react-auth-clerk@0.12.0
|
||||
|
||||
## 0.0.66
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.11.8
|
||||
- jazz-react-auth-clerk@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.65
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [4019918]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react@0.11.7
|
||||
- jazz-react-auth-clerk@0.11.7
|
||||
|
||||
## 0.0.64
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
|
||||
- Updated dependencies [e7c85b7]
|
||||
- jazz-react@0.11.6
|
||||
- jazz-tools@0.11.6
|
||||
- jazz-react-auth-clerk@0.11.6
|
||||
|
||||
## 0.0.63
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -15,12 +15,12 @@ You can either
|
||||
|
||||
Create a new Jazz project, and use this example as a template.
|
||||
```bash
|
||||
npx create-jazz-app@latest --example clerk --project-name clerk
|
||||
npx create-jazz-app@latest clerk-app --example clerk
|
||||
```
|
||||
|
||||
Go to the new project directory.
|
||||
```bash
|
||||
cd clerk
|
||||
cd clerk-app
|
||||
```
|
||||
|
||||
Run the dev server.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "clerk",
|
||||
"private": true,
|
||||
"version": "0.0.63",
|
||||
"version": "0.0.68",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -13,7 +13,7 @@
|
||||
"dependencies": {
|
||||
"@clerk/clerk-react": "^5.4.1",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-react-auth-clerk": "workspace:0.11.5",
|
||||
"jazz-react-auth-clerk": "workspace:0.12.1",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
|
||||
@@ -21,7 +21,6 @@ function JazzProvider({ children }: { children: React.ReactNode }) {
|
||||
clerk={clerk}
|
||||
sync={{
|
||||
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
|
||||
when: "signedUp", // This makes the app work in local mode when the user is not authenticated
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,5 +1,48 @@
|
||||
# file-share-svelte
|
||||
|
||||
## 0.0.52
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 0.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-svelte@0.12.0
|
||||
|
||||
## 0.0.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-svelte@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.49
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-svelte@0.11.7
|
||||
|
||||
## 0.0.48
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 1bfa9bb: Removed when="singedUp" from examples apps' Jazz providers. This is a really niche use-case option and can lead to broken-feeling experiences when anonymous users try to load something.
|
||||
- Updated dependencies [e7c85b7]
|
||||
- jazz-tools@0.11.6
|
||||
- jazz-svelte@0.11.6
|
||||
|
||||
## 0.0.47
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "file-share-svelte",
|
||||
"version": "0.0.47",
|
||||
"version": "0.0.52",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
AccountSchema={FileShareAccount}
|
||||
sync={{
|
||||
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
|
||||
when: "signedUp",
|
||||
}}
|
||||
>
|
||||
<PasskeyAuthBasicUI appName="File Share">
|
||||
|
||||
@@ -1,5 +1,48 @@
|
||||
# jazz-tailwind-demo-auth-starter
|
||||
|
||||
## 0.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-react@0.12.0
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [4019918]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react@0.11.7
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7c85b7]
|
||||
- jazz-react@0.11.6
|
||||
- jazz-tools@0.11.6
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "filestream",
|
||||
"private": true,
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.8",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
# form
|
||||
|
||||
## 0.1.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 0.1.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-react@0.12.0
|
||||
|
||||
## 0.1.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.1.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [4019918]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react@0.11.7
|
||||
|
||||
## 0.1.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7c85b7]
|
||||
- Updated dependencies [8ed144e]
|
||||
- jazz-react@0.11.6
|
||||
- jazz-tools@0.11.6
|
||||
- jazz-browser-media-images@0.11.6
|
||||
|
||||
## 0.1.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -28,12 +28,12 @@ You can either
|
||||
|
||||
Create a new Jazz project, and use this example as a template.
|
||||
```bash
|
||||
npx create-jazz-app@latest --example form --project-name form
|
||||
npx create-jazz-app@latest form-app --example form
|
||||
```
|
||||
|
||||
Go to the new project directory.
|
||||
```bash
|
||||
cd form
|
||||
cd form-app
|
||||
```
|
||||
|
||||
Run the dev server.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "form",
|
||||
"private": true,
|
||||
"version": "0.1.5",
|
||||
"version": "0.1.10",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -12,7 +12,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"hash-slash": "workspace:*",
|
||||
"jazz-browser-media-images": "workspace:*",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -12,7 +12,9 @@ import {
|
||||
} from "./schema.ts";
|
||||
|
||||
export function CreateOrder() {
|
||||
const { me } = useAccount({ root: { draft: {}, orders: [] } });
|
||||
const { me } = useAccount({
|
||||
resolve: { root: { draft: true, orders: true } },
|
||||
});
|
||||
const router = useIframeHashRouter();
|
||||
const [errors, setErrors] = useState<string[]>([]);
|
||||
|
||||
@@ -60,7 +62,7 @@ function CreateOrderForm({
|
||||
onSave: (draft: DraftBubbleTeaOrder) => void;
|
||||
}) {
|
||||
const draft = useCoState(DraftBubbleTeaOrder, id, {
|
||||
addOns: [],
|
||||
resolve: { addOns: true },
|
||||
});
|
||||
|
||||
if (!draft) return;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useAccount } from "jazz-react";
|
||||
|
||||
export function DraftIndicator() {
|
||||
const { me } = useAccount({
|
||||
root: { draft: {} },
|
||||
resolve: { root: { draft: true } },
|
||||
});
|
||||
|
||||
if (me?.root.draft?.hasChanges) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { OrderThumbnail } from "./OrderThumbnail.tsx";
|
||||
import { BubbleTeaOrder } from "./schema.ts";
|
||||
|
||||
export function EditOrder(props: { id: ID<BubbleTeaOrder> }) {
|
||||
const order = useCoState(BubbleTeaOrder, props.id, []);
|
||||
const order = useCoState(BubbleTeaOrder, props.id);
|
||||
|
||||
if (!order) return;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { OrderThumbnail } from "./OrderThumbnail.tsx";
|
||||
|
||||
export function Orders() {
|
||||
const { me } = useAccount({
|
||||
root: { orders: [] },
|
||||
resolve: { root: { orders: true } },
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
# image-upload
|
||||
|
||||
## 0.0.66
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 0.0.65
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-react@0.12.0
|
||||
|
||||
## 0.0.64
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.63
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [4019918]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react@0.11.7
|
||||
|
||||
## 0.0.62
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e7c85b7]
|
||||
- Updated dependencies [8ed144e]
|
||||
- jazz-react@0.11.6
|
||||
- jazz-tools@0.11.6
|
||||
- jazz-browser-media-images@0.11.6
|
||||
|
||||
## 0.0.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -15,12 +15,12 @@ You can either
|
||||
|
||||
Create a new Jazz project, and use this example as a template.
|
||||
```bash
|
||||
npx create-jazz-app@latest --example image-upload --project-name image-upload
|
||||
npx create-jazz-app@latest image-upload-app --example image-upload
|
||||
```
|
||||
|
||||
Go to the new project directory.
|
||||
```bash
|
||||
cd image-upload
|
||||
cd image-upload-app
|
||||
```
|
||||
|
||||
Run the dev server.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "image-upload",
|
||||
"private": true,
|
||||
"version": "0.0.61",
|
||||
"version": "0.0.66",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -11,7 +11,6 @@
|
||||
"format-and-lint:fix": "biome check . --write"
|
||||
},
|
||||
"dependencies": {
|
||||
"jazz-browser-media-images": "workspace:*",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
@@ -24,6 +23,9 @@
|
||||
"@vitejs/plugin-react": "^4.3.3",
|
||||
"globals": "^15.11.0",
|
||||
"typescript": "~5.6.2",
|
||||
"vite": "^6.0.11"
|
||||
"vite": "^6.0.11",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"postcss": "^8.4.27",
|
||||
"tailwindcss": "^3.4.17"
|
||||
}
|
||||
}
|
||||
|
||||
6
examples/image-upload/postcss.config.js
Normal file
6
examples/image-upload/postcss.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
@@ -3,7 +3,7 @@ import ImageUpload from "./ImageUpload.tsx";
|
||||
function App() {
|
||||
return (
|
||||
<>
|
||||
<main className="container">
|
||||
<main className="container py-16">
|
||||
<ImageUpload />
|
||||
</main>
|
||||
</>
|
||||
|
||||
@@ -1,60 +1,96 @@
|
||||
import { createImage } from "jazz-browser-media-images";
|
||||
import { ProgressiveImg, useAccount } from "jazz-react";
|
||||
import { ImageDefinition } from "jazz-tools";
|
||||
import { ChangeEvent, useRef } from "react";
|
||||
|
||||
function Image({ image }: { image: ImageDefinition }) {
|
||||
return (
|
||||
<ProgressiveImg image={image}>
|
||||
{({ src }) => <img src={src} />}
|
||||
</ProgressiveImg>
|
||||
);
|
||||
}
|
||||
import { ProgressiveImg, createImage, useAccount } from "jazz-react";
|
||||
import { ChangeEvent, useEffect, useRef, useState } from "react";
|
||||
|
||||
export default function ImageUpload() {
|
||||
const { me } = useAccount();
|
||||
|
||||
const [imagePreviewUrl, setImagePreviewUrl] = useState<string | null>(null);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
|
||||
if (imagePreviewUrl) {
|
||||
e.preventDefault();
|
||||
return "Upload in progress. Are you sure you want to leave?";
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||
return () => {
|
||||
window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||
|
||||
if (imagePreviewUrl) {
|
||||
URL.revokeObjectURL(imagePreviewUrl);
|
||||
}
|
||||
};
|
||||
}, [imagePreviewUrl]);
|
||||
|
||||
const onImageChange = async (event: ChangeEvent<HTMLInputElement>) => {
|
||||
if (!me?.profile) return;
|
||||
|
||||
const file = event.currentTarget.files?.[0];
|
||||
|
||||
if (file) {
|
||||
me.profile.image = await createImage(file, {
|
||||
owner: me.profile._owner,
|
||||
});
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
setImagePreviewUrl(objectUrl);
|
||||
|
||||
try {
|
||||
me.profile.image = await createImage(file, {
|
||||
owner: me.profile._owner,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error uploading image:", error);
|
||||
} finally {
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
setImagePreviewUrl(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const deleteImage = () => {
|
||||
if (!me?.profile) return;
|
||||
|
||||
me.profile.image = null;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>{me?.profile?.image && <Image image={me.profile.image} />}</div>
|
||||
if (me?.profile?.image) {
|
||||
return (
|
||||
<>
|
||||
<ProgressiveImg image={me.profile.image}>
|
||||
{({ src }) => <img alt="" src={src} className="w-full h-auto" />}
|
||||
</ProgressiveImg>
|
||||
|
||||
<div>
|
||||
{me?.profile?.image ? (
|
||||
<button type="button" onClick={deleteImage}>
|
||||
Delete image
|
||||
</button>
|
||||
) : (
|
||||
<div>
|
||||
<label>Upload image</label>
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept="image/png, image/jpeg, image/gif"
|
||||
onChange={onImageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<button type="button" onClick={deleteImage} className="mt-5">
|
||||
Delete image
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (imagePreviewUrl) {
|
||||
return (
|
||||
<div className="relative">
|
||||
<p className="z-10 absolute font-semibold text-gray-900 inset-0 flex items-center justify-center">
|
||||
Uploading image...
|
||||
</p>
|
||||
<img
|
||||
src={imagePreviewUrl}
|
||||
alt="Preview"
|
||||
className="opacity-50 w-full h-auto"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<label htmlFor="image">Image</label>
|
||||
<input
|
||||
id="image"
|
||||
name="image"
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept="image/png, image/jpeg, image/gif, image/bmp"
|
||||
onChange={onImageChange}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,82 +1,3 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
--border-color: #2f2e2d;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 0;
|
||||
padding: 0.6em 1.2em;
|
||||
font-weight: 500;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
--border-color: #e5e5e5;
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
|
||||
* {
|
||||
border-color: var(--border-color);
|
||||
}
|
||||
|
||||
header,
|
||||
main {
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
|
||||
header {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
padding: 2rem 0.75rem;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
18
examples/image-upload/tailwind.config.ts
Normal file
18
examples/image-upload/tailwind.config.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export default config;
|
||||
@@ -1,5 +1,61 @@
|
||||
# jazz-example-inspector
|
||||
|
||||
## 0.0.119
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5a00fe0]
|
||||
- cojson@0.12.1
|
||||
- cojson-transport-ws@0.12.1
|
||||
- jazz-inspector@0.12.1
|
||||
|
||||
## 0.0.118
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [9a56bb3]
|
||||
- cojson@0.12.0
|
||||
- jazz-inspector@0.12.0
|
||||
- cojson-transport-ws@0.12.0
|
||||
|
||||
## 0.0.117
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [71b9390]
|
||||
- Updated dependencies [6c86c4f]
|
||||
- Updated dependencies [9d0c9dc]
|
||||
- jazz-inspector@0.11.8
|
||||
- cojson@0.11.8
|
||||
- cojson-transport-ws@0.11.8
|
||||
|
||||
## 0.0.116
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 2c3761c: fix: CoFeed and FileStream are showing as CoStream
|
||||
- Updated dependencies [2c3761c]
|
||||
- Updated dependencies [2b94bc8]
|
||||
- Updated dependencies [2957362]
|
||||
- jazz-inspector@0.11.7
|
||||
- cojson@0.11.7
|
||||
- cojson-transport-ws@0.11.7
|
||||
|
||||
## 0.0.115
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 09f0a98: UI and JSON display improvements
|
||||
- 11da4d1: isolate class name hashing on inspector
|
||||
- Updated dependencies [09f0a98]
|
||||
- Updated dependencies [11da4d1]
|
||||
- Updated dependencies [8ed144e]
|
||||
- jazz-inspector@0.11.6
|
||||
- cojson@0.11.6
|
||||
- cojson-transport-ws@0.11.6
|
||||
|
||||
## 0.0.114
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-inspector-app",
|
||||
"private": true,
|
||||
"version": "0.0.114",
|
||||
"version": "0.0.119",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -11,27 +11,19 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-checkbox": "^1.0.4",
|
||||
"@radix-ui/react-slot": "^1.1.1",
|
||||
"@radix-ui/react-toast": "^1.1.4",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"jazz-inspector": "workspace:*",
|
||||
"clsx": "^2.0.0",
|
||||
"cojson": "workspace:0.11.5",
|
||||
"cojson-transport-ws": "workspace:0.11.5",
|
||||
"cojson": "workspace:0.12.1",
|
||||
"cojson-transport-ws": "workspace:0.12.1",
|
||||
"hash-slash": "workspace:0.2.2",
|
||||
"lucide-react": "^0.274.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router": "^6.16.0",
|
||||
"react-router-dom": "^6.16.0",
|
||||
"react-use": "^17.4.0",
|
||||
"tailwind-merge": "^1.14.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"uniqolor": "^1.1.0"
|
||||
"react-use": "^17.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/qrcode": "^1.5.1",
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||
|
||||
@@ -1,92 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--background: 0 0% 100%;
|
||||
--foreground: 20 14.3% 4.1%;
|
||||
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 20 14.3% 4.1%;
|
||||
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 20 14.3% 4.1%;
|
||||
|
||||
--primary: 24 9.8% 10%;
|
||||
--primary-foreground: 60 9.1% 97.8%;
|
||||
|
||||
--secondary: 60 4.8% 95.9%;
|
||||
--secondary-foreground: 24 9.8% 10%;
|
||||
|
||||
--muted: 60 4.8% 95.9%;
|
||||
--muted-foreground: 25 5.3% 44.7%;
|
||||
|
||||
--accent: 60 4.8% 95.9%;
|
||||
--accent-foreground: 24 9.8% 10%;
|
||||
|
||||
--destructive: 0 84.2% 60.2%;
|
||||
--destructive-foreground: 60 9.1% 97.8%;
|
||||
|
||||
--border: 20 5.9% 90%;
|
||||
--input: 20 5.9% 90%;
|
||||
--ring: 20 14.3% 4.1%;
|
||||
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: 20 14.3% 4.1%;
|
||||
--foreground: 60 9.1% 97.8%;
|
||||
|
||||
--card: 20 14.3% 4.1%;
|
||||
--card-foreground: 60 9.1% 97.8%;
|
||||
|
||||
--popover: 20 14.3% 4.1%;
|
||||
--popover-foreground: 60 9.1% 97.8%;
|
||||
|
||||
--primary: 60 9.1% 97.8%;
|
||||
--primary-foreground: 24 9.8% 10%;
|
||||
|
||||
--secondary: 12 6.5% 15.1%;
|
||||
--secondary-foreground: 60 9.1% 97.8%;
|
||||
|
||||
--muted: 12 6.5% 15.1%;
|
||||
--muted-foreground: 24 5.4% 63.9%;
|
||||
|
||||
--accent: 12 6.5% 15.1%;
|
||||
--accent-foreground: 60 9.1% 97.8%;
|
||||
|
||||
--destructive: 0 62.8% 30.6%;
|
||||
--destructive-foreground: 60 9.1% 97.8%;
|
||||
|
||||
--border: 12 6.5% 15.1%;
|
||||
--input: 12 6.5% 15.1%;
|
||||
--ring: 24 5.7% 82.9%;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.animate-in {
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
transform: translateZ(400px) translateY(30px) scale(1.05);
|
||||
opacity: 0.4;
|
||||
}
|
||||
to {
|
||||
transform: translateZ(0) scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import React from "react";
|
||||
import { PageInfo } from "./types";
|
||||
|
||||
interface BreadcrumbsProps {
|
||||
path: PageInfo[];
|
||||
onBreadcrumbClick: (index: number) => void;
|
||||
}
|
||||
|
||||
export const Breadcrumbs: React.FC<BreadcrumbsProps> = ({
|
||||
path,
|
||||
onBreadcrumbClick,
|
||||
}) => {
|
||||
return (
|
||||
<div className="z-20 relative bg-indigo-400/10 backdrop-blur-sm rounded-lg inline-flex px-2 py-1 whitespace-pre transition-all items-center space-x-1 min-h-10">
|
||||
<button
|
||||
onClick={() => onBreadcrumbClick(-1)}
|
||||
className="flex items-center justify-center p-1 rounded-sm hover:bg-indigo-500/10 transition-colors"
|
||||
aria-label="Go to home"
|
||||
>
|
||||
<img src="jazz-logo.png" alt="Jazz Logo" className="size-5" />
|
||||
</button>
|
||||
{path.map((page, index) => {
|
||||
return (
|
||||
<span key={index} className="inline-block first:pl-1 last:pr-1">
|
||||
{index === 0 ? null : (
|
||||
<span className="text-indigo-500/30">{" / "}</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => onBreadcrumbClick(index)}
|
||||
className="text-indigo-700 hover:underline"
|
||||
>
|
||||
{index === 0 ? page.name || "Root" : page.name}
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,344 +0,0 @@
|
||||
import {
|
||||
CoID,
|
||||
LocalNode,
|
||||
RawBinaryCoStream,
|
||||
RawCoStream,
|
||||
RawCoValue,
|
||||
} from "cojson";
|
||||
import { base64URLtoBytes } from "cojson";
|
||||
import { BinaryStreamItem, BinaryStreamStart, CoStreamItem } from "cojson";
|
||||
import { JsonObject, JsonValue } from "cojson";
|
||||
import { ArrowDownToLine } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { PageInfo } from "./types";
|
||||
import { AccountOrGroupPreview } from "./value-renderer";
|
||||
|
||||
// typeguard for BinaryStreamStart
|
||||
function isBinaryStreamStart(item: unknown): item is BinaryStreamStart {
|
||||
return (
|
||||
typeof item === "object" &&
|
||||
item !== null &&
|
||||
"type" in item &&
|
||||
item.type === "start"
|
||||
);
|
||||
}
|
||||
|
||||
function detectCoStreamType(value: RawCoStream | RawBinaryCoStream) {
|
||||
const firstKey = Object.keys(value.items)[0];
|
||||
if (!firstKey)
|
||||
return {
|
||||
type: "unknown",
|
||||
};
|
||||
|
||||
const items = value.items[firstKey as never]?.map((v) => v.value);
|
||||
|
||||
if (!items)
|
||||
return {
|
||||
type: "unknown",
|
||||
};
|
||||
const firstItem = items[0];
|
||||
if (!firstItem)
|
||||
return {
|
||||
type: "unknown",
|
||||
};
|
||||
// This is a binary stream
|
||||
if (isBinaryStreamStart(firstItem)) {
|
||||
return {
|
||||
type: "binary",
|
||||
items: items as BinaryStreamItem[],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: "coStream",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function getBlobFromCoStream({
|
||||
items,
|
||||
onlyFirstChunk = false,
|
||||
}: {
|
||||
items: BinaryStreamItem[];
|
||||
onlyFirstChunk?: boolean;
|
||||
}) {
|
||||
if (onlyFirstChunk && items.length > 1) {
|
||||
items = items.slice(0, 2);
|
||||
}
|
||||
|
||||
const chunks: Uint8Array[] = [];
|
||||
|
||||
const binary_U_prefixLength = 8;
|
||||
|
||||
let lastProgressUpdate = Date.now();
|
||||
|
||||
for (const item of items.slice(1)) {
|
||||
if (item.type === "end") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (item.type !== "chunk") {
|
||||
console.error("Invalid binary stream chunk", item);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const chunk = base64URLtoBytes(item.chunk.slice(binary_U_prefixLength));
|
||||
// totalLength += chunk.length;
|
||||
chunks.push(chunk);
|
||||
|
||||
if (Date.now() - lastProgressUpdate > 100) {
|
||||
lastProgressUpdate = Date.now();
|
||||
}
|
||||
}
|
||||
const defaultMime = "mimeType" in items[0] ? items[0].mimeType : null;
|
||||
|
||||
const blob = new Blob(chunks, defaultMime ? { type: defaultMime } : {});
|
||||
|
||||
const mimeType =
|
||||
defaultMime === "" ? await detectPDFMimeType(blob) : defaultMime;
|
||||
|
||||
return {
|
||||
blob,
|
||||
mimeType: mimeType as string,
|
||||
unfinishedChunks: items.length > 1,
|
||||
totalSize:
|
||||
"totalSizeBytes" in items[0]
|
||||
? (items[0].totalSizeBytes as number)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const detectPDFMimeType = async (blob: Blob): Promise<string> => {
|
||||
const arrayBuffer = await blob.slice(0, 4).arrayBuffer();
|
||||
const uint8Array = new Uint8Array(arrayBuffer);
|
||||
const header = uint8Array.reduce(
|
||||
(acc, byte) => acc + String.fromCharCode(byte),
|
||||
"",
|
||||
);
|
||||
|
||||
if (header === "%PDF") {
|
||||
return "application/pdf";
|
||||
}
|
||||
return "application/octet-stream";
|
||||
};
|
||||
|
||||
const BinaryDownloadButton = ({
|
||||
pdfBlob,
|
||||
fileName = "document",
|
||||
label,
|
||||
mimeType,
|
||||
}: {
|
||||
pdfBlob: Blob;
|
||||
mimeType?: string;
|
||||
fileName?: string;
|
||||
label: string;
|
||||
}) => {
|
||||
const downloadFile = () => {
|
||||
const url = URL.createObjectURL(
|
||||
new Blob([pdfBlob], mimeType ? { type: mimeType } : {}),
|
||||
);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download =
|
||||
mimeType === "application/pdf" ? `${fileName}.pdf` : fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
className="flex items-center gap-2 px-2 py-1 text-gray-900 border border-gray-900/10 bg-clip-border shadow-sm transition-colors rounded bg-gray-50 text-sm"
|
||||
onClick={downloadFile}
|
||||
>
|
||||
<ArrowDownToLine size={16} />
|
||||
{label}
|
||||
{/* Download {mimeType === "application/pdf" ? "PDF" : "File"} */}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
const LabelContentPair = ({
|
||||
label,
|
||||
content,
|
||||
}: {
|
||||
label: string;
|
||||
content: React.ReactNode;
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5 ">
|
||||
<span className="uppercase text-xs font-medium text-gray-600 tracking-wide">
|
||||
{label}
|
||||
</span>
|
||||
<span>{content}</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function RenderCoBinaryStream({
|
||||
value,
|
||||
items,
|
||||
}: {
|
||||
items: BinaryStreamItem[];
|
||||
value: RawBinaryCoStream;
|
||||
}) {
|
||||
const [file, setFile] = useState<
|
||||
| {
|
||||
blob: Blob;
|
||||
mimeType: string;
|
||||
unfinishedChunks: boolean;
|
||||
totalSize: number | undefined;
|
||||
}
|
||||
| undefined
|
||||
| null
|
||||
>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// load only the first chunk to get the mime type and size
|
||||
getBlobFromCoStream({
|
||||
items,
|
||||
onlyFirstChunk: true,
|
||||
})
|
||||
.then((v) => {
|
||||
if (v) {
|
||||
setFile(v);
|
||||
if (v.mimeType.includes("image")) {
|
||||
// If it's an image, load the full blob
|
||||
getBlobFromCoStream({
|
||||
items,
|
||||
}).then((s) => {
|
||||
if (s) setFile(s);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
}, [items]);
|
||||
|
||||
if (!isLoading && !file) return <div>No blob</div>;
|
||||
|
||||
if (isLoading) return <div>Loading...</div>;
|
||||
if (!file) return <div>No blob</div>;
|
||||
|
||||
const { blob, mimeType } = file;
|
||||
|
||||
const sizeInKB = (file.totalSize || 0) / 1024;
|
||||
|
||||
return (
|
||||
<div className="space-y-8 mt-4">
|
||||
<div className="grid grid-cols-3 gap-2 max-w-3xl">
|
||||
<LabelContentPair
|
||||
label="Mime Type"
|
||||
content={
|
||||
<span className="font-mono bg-gray-100 rounded px-2 py-1 text-sm">
|
||||
{mimeType || "No mime type"}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<LabelContentPair
|
||||
label="Size"
|
||||
content={<span>{sizeInKB.toFixed(2)} KB</span>}
|
||||
/>
|
||||
<LabelContentPair
|
||||
label="Download"
|
||||
content={
|
||||
<BinaryDownloadButton
|
||||
fileName={value.id.toString()}
|
||||
pdfBlob={blob}
|
||||
mimeType={mimeType}
|
||||
label={
|
||||
mimeType === "application/pdf"
|
||||
? "Download PDF"
|
||||
: "Download File"
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{mimeType === "image/png" || mimeType === "image/jpeg" ? (
|
||||
<LabelContentPair
|
||||
label="Preview"
|
||||
content={
|
||||
<div className="bg-gray-50 p-3 rounded-sm">
|
||||
<RenderBlobImage blob={blob} />
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RenderCoStream({
|
||||
value,
|
||||
node,
|
||||
}: {
|
||||
value: RawCoStream;
|
||||
node: LocalNode;
|
||||
}) {
|
||||
const streamPerUser = Object.keys(value.items);
|
||||
const userCoIds = streamPerUser.map((stream) => stream.split("_session")[0]);
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{userCoIds.map((id, idx) => (
|
||||
<div
|
||||
className="bg-gray-100 p-3 rounded-lg transition-colors overflow-hidden bg-white border hover:bg-gray-100/5 cursor-pointer shadow-sm"
|
||||
key={id}
|
||||
>
|
||||
<AccountOrGroupPreview coId={id as CoID<RawCoValue>} node={node} />
|
||||
{/* @ts-expect-error - TODO: fix types */}
|
||||
{value.items[streamPerUser[idx]]?.map(
|
||||
(item: CoStreamItem<JsonValue>) => (
|
||||
<div>
|
||||
{new Date(item.madeAt).toLocaleString()}{" "}
|
||||
{JSON.stringify(item.value)}
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function CoStreamView({
|
||||
value,
|
||||
node,
|
||||
}: {
|
||||
data: JsonObject;
|
||||
onNavigate: (pages: PageInfo[]) => void;
|
||||
node: LocalNode;
|
||||
value: RawCoStream;
|
||||
}) {
|
||||
// if (!value) return <div>No value</div>;
|
||||
|
||||
const streamType = detectCoStreamType(value);
|
||||
|
||||
if (streamType.type === "binary") {
|
||||
if (streamType.items === undefined) {
|
||||
return <div>No binary stream</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<RenderCoBinaryStream
|
||||
value={value as RawBinaryCoStream}
|
||||
items={streamType.items}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (streamType.type === "coStream") {
|
||||
return <RenderCoStream value={value} node={node} />;
|
||||
}
|
||||
|
||||
if (streamType.type === "unknown") return <div>Unknown stream type</div>;
|
||||
|
||||
return <div>Unknown stream type</div>;
|
||||
}
|
||||
|
||||
function RenderBlobImage({ blob }: { blob: Blob }) {
|
||||
const urlCreator = window.URL || window.webkitURL;
|
||||
return <img src={urlCreator.createObjectURL(blob)} />;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
import clsx from "clsx";
|
||||
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||
import { JsonObject } from "cojson";
|
||||
import { ResolveIcon } from "./type-icon";
|
||||
import { PageInfo, isCoId } from "./types";
|
||||
import { CoMapPreview, ValueRenderer } from "./value-renderer";
|
||||
|
||||
export function GridView({
|
||||
data,
|
||||
onNavigate,
|
||||
node,
|
||||
}: {
|
||||
data: JsonObject;
|
||||
onNavigate: (pages: PageInfo[]) => void;
|
||||
node: LocalNode;
|
||||
}) {
|
||||
const entries = Object.entries(data);
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 p-2">
|
||||
{entries.map(([key, child], childIndex) => (
|
||||
<div
|
||||
key={childIndex}
|
||||
className={clsx(
|
||||
"bg-gray-100 p-3 rounded-lg transition-colors overflow-hidden",
|
||||
isCoId(child)
|
||||
? "bg-white border hover:bg-gray-100/5 cursor-pointer shadow-sm"
|
||||
: "bg-gray-50",
|
||||
)}
|
||||
onClick={() =>
|
||||
isCoId(child) &&
|
||||
onNavigate([{ coId: child as CoID<RawCoValue>, name: key }])
|
||||
}
|
||||
>
|
||||
<h3 className="truncate">
|
||||
{isCoId(child) ? (
|
||||
<span className="font-medium flex justify-between">
|
||||
{key}
|
||||
|
||||
<div className="px-2 py-1 text-xs bg-gray-100 rounded">
|
||||
<ResolveIcon coId={child as CoID<RawCoValue>} node={node} />
|
||||
</div>
|
||||
</span>
|
||||
) : (
|
||||
<span>{key}</span>
|
||||
)}
|
||||
</h3>
|
||||
<div className="mt-2 text-sm">
|
||||
{isCoId(child) ? (
|
||||
<CoMapPreview coId={child as CoID<RawCoValue>} node={node} />
|
||||
) : (
|
||||
<ValueRenderer
|
||||
json={child}
|
||||
onCoIDClick={(coId) => {
|
||||
onNavigate([{ coId, name: key }]);
|
||||
}}
|
||||
compact
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { LocalNode } from "cojson";
|
||||
import { Breadcrumbs } from "./breadcrumbs";
|
||||
import { PageStack } from "./page-stack";
|
||||
import { PageInfo } from "./types";
|
||||
import { Breadcrumbs, PageStack } from "jazz-inspector";
|
||||
import type { PageInfo } from "jazz-inspector";
|
||||
import { usePagePath } from "./use-page-path";
|
||||
|
||||
export default function CoJsonViewer({
|
||||
|
||||
@@ -9,12 +9,17 @@ import {
|
||||
} from "cojson";
|
||||
import { createWebSocketPeer } from "cojson-transport-ws";
|
||||
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
||||
import { Trash2 } from "lucide-react";
|
||||
import {
|
||||
Breadcrumbs,
|
||||
Button,
|
||||
Icon,
|
||||
Input,
|
||||
PageStack,
|
||||
Select,
|
||||
} from "jazz-inspector";
|
||||
import { resolveCoValue, useResolvedCoValue } from "jazz-inspector";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Breadcrumbs } from "./breadcrumbs";
|
||||
import { PageStack } from "./page-stack";
|
||||
import { usePagePath } from "./use-page-path";
|
||||
import { resolveCoValue, useResolvedCoValue } from "./use-resolve-covalue";
|
||||
|
||||
interface Account {
|
||||
id: CoID<RawAccount>;
|
||||
@@ -121,15 +126,23 @@ export default function CoJsonViewerApp() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full h-screen bg-gray-100 p-4 overflow-hidden flex flex-col">
|
||||
<div className="flex items-center mb-4 gap-4">
|
||||
<div
|
||||
className={clsx(
|
||||
"h-screen overflow-hidden flex flex-col",
|
||||
" text-stone-700 bg-white",
|
||||
"dark:text-stone-300 dark:bg-stone-950",
|
||||
)}
|
||||
>
|
||||
<header className="flex items-center gap-4 p-3">
|
||||
<Breadcrumbs path={path} onBreadcrumbClick={goToIndex} />
|
||||
<div className="flex-1">
|
||||
<form onSubmit={handleCoValueIdSubmit}>
|
||||
{path.length !== 0 && (
|
||||
<input
|
||||
className="border p-2 rounded-lg min-w-[21rem] font-mono"
|
||||
<Input
|
||||
className="min-w-[21rem] font-mono"
|
||||
placeholder="co_z1234567890abcdef123456789"
|
||||
label="CoValue ID"
|
||||
hideLabel
|
||||
value={coValueId}
|
||||
onChange={(e) =>
|
||||
setCoValueId(e.target.value as CoID<RawCoValue>)
|
||||
@@ -145,7 +158,7 @@ export default function CoJsonViewerApp() {
|
||||
deleteCurrentAccount={deleteCurrentAccount}
|
||||
localNode={localNode}
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<PageStack
|
||||
path={path}
|
||||
@@ -153,49 +166,39 @@ export default function CoJsonViewerApp() {
|
||||
goBack={goBack}
|
||||
addPages={addPages}
|
||||
>
|
||||
{!currentAccount ? (
|
||||
<AddAccountForm addAccount={addAccount} />
|
||||
) : (
|
||||
{!currentAccount && <AddAccountForm addAccount={addAccount} />}
|
||||
|
||||
{currentAccount && path.length <= 0 && (
|
||||
<form
|
||||
onSubmit={handleCoValueIdSubmit}
|
||||
aria-hidden={path.length !== 0}
|
||||
className={clsx(
|
||||
"flex flex-col justify-center items-center gap-2 h-full w-full mb-20 ",
|
||||
"transition-all duration-150",
|
||||
path.length > 0
|
||||
? "opacity-0 -translate-y-2 scale-95"
|
||||
: "opacity-100",
|
||||
)}
|
||||
className="flex flex-col relative -top-6 justify-center gap-2 h-full w-full max-w-sm mx-auto"
|
||||
>
|
||||
<fieldset className="flex flex-col gap-2 text-sm">
|
||||
<h2 className="text-3xl font-medium text-gray-950 text-center mb-4">
|
||||
Jazz CoValue Inspector
|
||||
</h2>
|
||||
<input
|
||||
className="border p-4 rounded-lg min-w-[21rem] font-mono"
|
||||
placeholder="co_z1234567890abcdef123456789"
|
||||
value={coValueId}
|
||||
onChange={(e) =>
|
||||
setCoValueId(e.target.value as CoID<RawCoValue>)
|
||||
}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-indigo-500 hover:bg-indigo-500/80 text-white px-4 py-2 rounded-md"
|
||||
>
|
||||
Inspect
|
||||
</button>
|
||||
<hr />
|
||||
<button
|
||||
type="button"
|
||||
className="border inline-block px-2 py-1.5 text-black rounded"
|
||||
onClick={() => {
|
||||
setPage(currentAccount.id);
|
||||
}}
|
||||
>
|
||||
Inspect My Account
|
||||
</button>
|
||||
</fieldset>
|
||||
<h1 className="text-lg text-center font-medium mb-4 text-stone-900 dark:text-white">
|
||||
Jazz CoValue Inspector
|
||||
</h1>
|
||||
<Input
|
||||
label="CoValue ID"
|
||||
className="font-mono"
|
||||
hideLabel
|
||||
placeholder="co_z1234567890abcdef123456789"
|
||||
value={coValueId}
|
||||
onChange={(e) => setCoValueId(e.target.value as CoID<RawCoValue>)}
|
||||
/>
|
||||
<Button type="submit" variant="primary">
|
||||
Inspect CoValue
|
||||
</Button>
|
||||
|
||||
<p className="text-center">or</p>
|
||||
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setPage(currentAccount.id);
|
||||
}}
|
||||
>
|
||||
Inspect my account
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</PageStack>
|
||||
@@ -217,8 +220,11 @@ function AccountSwitcher({
|
||||
localNode: LocalNode | null;
|
||||
}) {
|
||||
return (
|
||||
<div className="relative flex items-center gap-1">
|
||||
<select
|
||||
<div className="relative flex items-stretch gap-1">
|
||||
<Select
|
||||
label="Account to inspect"
|
||||
hideLabel
|
||||
className="label:sr-only max-w-96"
|
||||
value={currentAccount?.id || "add-account"}
|
||||
onChange={(e) => {
|
||||
if (e.target.value === "add-account") {
|
||||
@@ -228,7 +234,6 @@ function AccountSwitcher({
|
||||
setCurrentAccount(account || null);
|
||||
}
|
||||
}}
|
||||
className="p-2 px-4 bg-gray-100/50 border border-indigo-500/10 backdrop-blur-sm rounded-md text-indigo-700 appearance-none"
|
||||
>
|
||||
{accounts.map((account) => (
|
||||
<option key={account.id} value={account.id}>
|
||||
@@ -240,15 +245,16 @@ function AccountSwitcher({
|
||||
</option>
|
||||
))}
|
||||
<option value="add-account">Add account</option>
|
||||
</select>
|
||||
</Select>
|
||||
{currentAccount && (
|
||||
<button
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={deleteCurrentAccount}
|
||||
className="p-3 rounded hover:bg-gray-200 transition-colors"
|
||||
title="Delete Account"
|
||||
className="rounded-md p-2 ml-1"
|
||||
aria-label="Remove account"
|
||||
>
|
||||
<Trash2 size={16} className="text-gray-500" />
|
||||
</button>
|
||||
<Icon name="delete" className="text-gray-500" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -272,30 +278,34 @@ function AddAccountForm({
|
||||
return (
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="flex flex-col gap-2 max-w-md mx-auto h-full justify-center"
|
||||
className="flex flex-col gap-3 max-w-md mx-auto h-full justify-center"
|
||||
>
|
||||
<h2 className="text-2xl font-medium text-gray-900 mb-3">
|
||||
Add an Account to Inspect
|
||||
<h2 className="text-2xl font-medium text-gray-900 dark:text-white">
|
||||
Add an account to inspect
|
||||
</h2>
|
||||
<input
|
||||
className="border py-2 px-3 rounded-md"
|
||||
placeholder="Account ID"
|
||||
<p className="leading-relaxed mb-5">
|
||||
Use the{" "}
|
||||
<code className="whitespace-nowrap text-stone-900 dark:text-white font-semibold">
|
||||
jazz-logged-in-secret
|
||||
</code>{" "}
|
||||
local storage key from within your Jazz app for your account
|
||||
credentials.
|
||||
</p>
|
||||
<Input
|
||||
label="Account ID"
|
||||
value={id}
|
||||
placeholder="co_z1234567890abcdef123456789"
|
||||
onChange={(e) => setId(e.target.value)}
|
||||
/>
|
||||
<input
|
||||
<Input
|
||||
label="Account secret"
|
||||
type="password"
|
||||
className="border py-2 px-3 rounded-md"
|
||||
placeholder="Account Secret"
|
||||
value={secret}
|
||||
onChange={(e) => setSecret(e.target.value)}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-indigo-500 text-white px-4 py-2 rounded-md"
|
||||
>
|
||||
Add Account
|
||||
</button>
|
||||
<Button className="mt-3" type="submit">
|
||||
Add account
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||
import { Page } from "./page"; // Assuming you have a Page component
|
||||
|
||||
// Define the structure of a page in the path
|
||||
interface PageInfo {
|
||||
coId: CoID<RawCoValue>;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
// Props for the PageStack component
|
||||
interface PageStackProps {
|
||||
path: PageInfo[];
|
||||
node?: LocalNode | null;
|
||||
goBack: () => void;
|
||||
addPages: (pages: PageInfo[]) => void;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export function PageStack({
|
||||
path,
|
||||
node,
|
||||
goBack,
|
||||
addPages,
|
||||
children,
|
||||
}: PageStackProps) {
|
||||
return (
|
||||
<div className="relative mt-4 h-[calc(100vh-6rem)]">
|
||||
{children && <div className="absolute inset-0 pb-20">{children}</div>}
|
||||
{node &&
|
||||
path.map((page, index) => (
|
||||
<Page
|
||||
key={`${page.coId}-${index}`}
|
||||
coId={page.coId}
|
||||
node={node}
|
||||
name={page.name || page.coId}
|
||||
onHeaderClick={goBack}
|
||||
onNavigate={addPages}
|
||||
isTopLevel={index === path.length - 1}
|
||||
style={{
|
||||
transform: `translateZ(${(index - path.length + 1) * 200}px) scale(${
|
||||
1 - (path.length - index - 1) * 0.05
|
||||
}) translateY(${-(index - path.length + 1) * -4}%)`,
|
||||
opacity: 1 - (path.length - index - 1) * 0.05,
|
||||
zIndex: index,
|
||||
transitionProperty: "transform, opacity",
|
||||
transitionDuration: "0.3s",
|
||||
transitionTimingFunction: "ease-out",
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
import clsx from "clsx";
|
||||
import { CoID, LocalNode, RawCoStream, RawCoValue } from "cojson";
|
||||
import { useEffect, useState } from "react";
|
||||
import { CoStreamView } from "./co-stream-view";
|
||||
import { GridView } from "./grid-view";
|
||||
import { TableView } from "./table-viewer";
|
||||
import { TypeIcon } from "./type-icon";
|
||||
import { PageInfo } from "./types";
|
||||
import { useResolvedCoValue } from "./use-resolve-covalue";
|
||||
import { AccountOrGroupPreview } from "./value-renderer";
|
||||
|
||||
type PageProps = {
|
||||
coId: CoID<RawCoValue>;
|
||||
node: LocalNode;
|
||||
name: string;
|
||||
onNavigate: (newPages: PageInfo[]) => void;
|
||||
onHeaderClick?: () => void;
|
||||
isTopLevel?: boolean;
|
||||
style: React.CSSProperties;
|
||||
};
|
||||
|
||||
export function Page({
|
||||
coId,
|
||||
node,
|
||||
name,
|
||||
onNavigate,
|
||||
onHeaderClick,
|
||||
style,
|
||||
isTopLevel,
|
||||
}: PageProps) {
|
||||
const { value, snapshot, type, extendedType } = useResolvedCoValue(
|
||||
coId,
|
||||
node,
|
||||
);
|
||||
const [viewMode, setViewMode] = useState<"grid" | "table">("grid");
|
||||
|
||||
const supportsTableView = type === "colist" || extendedType === "record";
|
||||
|
||||
// Automatically switch to table view if the page is a CoMap record
|
||||
useEffect(() => {
|
||||
if (supportsTableView) {
|
||||
setViewMode("table");
|
||||
}
|
||||
}, [supportsTableView]);
|
||||
|
||||
if (snapshot === "unavailable") {
|
||||
return <div style={style}>Data unavailable</div>;
|
||||
}
|
||||
|
||||
if (!snapshot) {
|
||||
return <div style={style}></div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={style}
|
||||
className={clsx(
|
||||
"absolute inset-0 border border-gray-900/5 bg-clip-padding bg-white rounded-xl shadow-lg p-6 animate-in",
|
||||
)}
|
||||
>
|
||||
{!isTopLevel && (
|
||||
<div
|
||||
className="absolute inset-x-0 top-0 h-10"
|
||||
aria-label="Back"
|
||||
onClick={() => {
|
||||
onHeaderClick?.();
|
||||
}}
|
||||
aria-hidden="true"
|
||||
></div>
|
||||
)}
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="text-2xl font-bold flex items-start flex-col gap-1">
|
||||
<span>
|
||||
{name}
|
||||
{typeof snapshot === "object" && "name" in snapshot ? (
|
||||
<span className="text-gray-600 font-medium">
|
||||
{" "}
|
||||
{
|
||||
(
|
||||
snapshot as {
|
||||
name: string;
|
||||
}
|
||||
).name
|
||||
}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</h2>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-gray-700 font-medium py-0.5 px-1 -ml-0.5 rounded bg-gray-700/5 inline-block font-mono">
|
||||
{type && <TypeIcon type={type} extendedType={extendedType} />}
|
||||
</span>
|
||||
<span className="text-xs text-gray-700 font-medium py-0.5 px-1 -ml-0.5 rounded bg-gray-700/5 inline-block font-mono">
|
||||
{coId}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{/* {supportsTableView && (
|
||||
<button
|
||||
onClick={toggleViewMode}
|
||||
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors"
|
||||
>
|
||||
{viewMode === "grid" ? "Table View" : "Grid View"}
|
||||
</button>
|
||||
)} */}
|
||||
</div>
|
||||
<div className="overflow-auto max-h-[calc(100%-4rem)]">
|
||||
{type === "costream" ? (
|
||||
<CoStreamView
|
||||
data={snapshot}
|
||||
onNavigate={onNavigate}
|
||||
node={node}
|
||||
value={value as RawCoStream}
|
||||
/>
|
||||
) : viewMode === "grid" ? (
|
||||
<GridView data={snapshot} onNavigate={onNavigate} node={node} />
|
||||
) : (
|
||||
<TableView data={snapshot} node={node} onNavigate={onNavigate} />
|
||||
)}
|
||||
{/* --- */}
|
||||
{extendedType !== "account" && extendedType !== "group" && (
|
||||
<div className="text-xs text-gray-500 mt-4">
|
||||
Owned by{" "}
|
||||
<AccountOrGroupPreview
|
||||
coId={value.group.id}
|
||||
node={node}
|
||||
showId
|
||||
onClick={() => {
|
||||
onNavigate([{ coId: value.group.id, name: "owner" }]);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||
import { JsonObject } from "cojson";
|
||||
import { useMemo, useState } from "react";
|
||||
import { LinkIcon } from "../link-icon";
|
||||
import { PageInfo } from "./types";
|
||||
import { useResolvedCoValues } from "./use-resolve-covalue";
|
||||
import { ValueRenderer } from "./value-renderer";
|
||||
|
||||
export function TableView({
|
||||
data,
|
||||
node,
|
||||
onNavigate,
|
||||
}: {
|
||||
data: JsonObject;
|
||||
node: LocalNode;
|
||||
onNavigate: (pages: PageInfo[]) => void;
|
||||
}) {
|
||||
const [visibleRowsCount, setVisibleRowsCount] = useState(10);
|
||||
const [coIdArray, visibleRows] = useMemo(() => {
|
||||
const coIdArray = Array.isArray(data)
|
||||
? data
|
||||
: Object.values(data).every(
|
||||
(k) => typeof k === "string" && k.startsWith("co_"),
|
||||
)
|
||||
? Object.values(data).map((k) => k as CoID<RawCoValue>)
|
||||
: [];
|
||||
|
||||
const visibleRows = coIdArray.slice(0, visibleRowsCount);
|
||||
|
||||
return [coIdArray, visibleRows];
|
||||
}, [data, visibleRowsCount]);
|
||||
const resolvedRows = useResolvedCoValues(visibleRows, node);
|
||||
|
||||
const hasMore = visibleRowsCount < coIdArray.length;
|
||||
|
||||
if (!coIdArray.length) {
|
||||
return <div>No data to display</div>;
|
||||
}
|
||||
|
||||
if (resolvedRows.length === 0) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
const keys = Array.from(
|
||||
new Set(resolvedRows.flatMap((item) => Object.keys(item.snapshot || {}))),
|
||||
);
|
||||
|
||||
const loadMore = () => {
|
||||
setVisibleRowsCount((prevVisibleRows) => prevVisibleRows + 10);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<table className="min-w-full divide-y divide-gray-200">
|
||||
<thead className="sticky top-0 border-b">
|
||||
<tr>
|
||||
{["", ...keys].map((key) => (
|
||||
<th
|
||||
key={key}
|
||||
className="px-4 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 rounded"
|
||||
>
|
||||
{key}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
{resolvedRows.slice(0, visibleRowsCount).map((item, index) => (
|
||||
<tr key={index}>
|
||||
<td className="px-1 py-0">
|
||||
<button
|
||||
onClick={() =>
|
||||
onNavigate([
|
||||
{
|
||||
coId: item.value!.id,
|
||||
name: index.toString(),
|
||||
},
|
||||
])
|
||||
}
|
||||
className="px-4 py-4 whitespace-nowrap text-sm text-gray-500 hover:text-blue-500 hover:bg-gray-100 rounded"
|
||||
>
|
||||
<LinkIcon />
|
||||
</button>
|
||||
</td>
|
||||
{keys.map((key) => (
|
||||
<td
|
||||
key={key}
|
||||
className="px-4 py-4 whitespace-nowrap text-sm text-gray-500"
|
||||
>
|
||||
<ValueRenderer
|
||||
json={(item.snapshot as JsonObject)[key]}
|
||||
onCoIDClick={(coId) => {
|
||||
async function handleClick() {
|
||||
onNavigate([
|
||||
{
|
||||
coId: item.value!.id,
|
||||
name: index.toString(),
|
||||
},
|
||||
{
|
||||
coId: coId,
|
||||
name: key,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
handleClick();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<div className="py-4 text-gray-500 flex items-center justify-between gap-2">
|
||||
<span>
|
||||
Showing {Math.min(visibleRowsCount, coIdArray.length)} of{" "}
|
||||
{coIdArray.length}
|
||||
</span>
|
||||
{hasMore && (
|
||||
<div className="text-center">
|
||||
<button
|
||||
onClick={loadMore}
|
||||
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
||||
>
|
||||
Load More
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||
import {
|
||||
CoJsonType,
|
||||
ExtendedCoJsonType,
|
||||
useResolvedCoValue,
|
||||
} from "./use-resolve-covalue";
|
||||
|
||||
export const TypeIcon = ({
|
||||
type,
|
||||
extendedType,
|
||||
}: {
|
||||
type: CoJsonType;
|
||||
extendedType?: ExtendedCoJsonType;
|
||||
}) => {
|
||||
const iconMap: Record<ExtendedCoJsonType | CoJsonType, string> = {
|
||||
record: "{} Record",
|
||||
image: "🖼️ Image",
|
||||
comap: "{} CoMap",
|
||||
costream: "≋ CoStream",
|
||||
colist: "☰ CoList",
|
||||
account: "👤 Account",
|
||||
group: "👥 Group",
|
||||
};
|
||||
|
||||
const iconKey = extendedType || type;
|
||||
const icon = iconMap[iconKey as keyof typeof iconMap];
|
||||
|
||||
return icon ? <span className="font-mono">{icon}</span> : null;
|
||||
};
|
||||
|
||||
export const ResolveIcon = ({
|
||||
coId,
|
||||
node,
|
||||
}: {
|
||||
coId: CoID<RawCoValue>;
|
||||
node: LocalNode;
|
||||
}) => {
|
||||
const { type, extendedType, snapshot } = useResolvedCoValue(coId, node);
|
||||
|
||||
if (snapshot === "unavailable" && !type) {
|
||||
return <div className="text-gray-600 font-medium">Unavailable</div>;
|
||||
}
|
||||
|
||||
if (!type) return <div className="whitespace-pre w-14 font-mono"> </div>;
|
||||
|
||||
return <TypeIcon type={type} extendedType={extendedType} />;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
import { CoID, RawCoValue } from "cojson";
|
||||
|
||||
export type PageInfo = {
|
||||
coId: CoID<RawCoValue>;
|
||||
name?: string;
|
||||
};
|
||||
|
||||
export const isCoId = (coId: unknown): coId is CoID<RawCoValue> =>
|
||||
typeof coId === "string" && coId.startsWith("co_");
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CoID, RawCoValue } from "cojson";
|
||||
import { PageInfo } from "jazz-inspector";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { PageInfo } from "./types";
|
||||
|
||||
export function usePagePath(defaultPath?: PageInfo[]) {
|
||||
const [path, setPath] = useState<PageInfo[]>(() => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,260 +0,0 @@
|
||||
import clsx from "clsx";
|
||||
import { CoID, JsonValue, LocalNode, RawCoValue } from "cojson";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { LinkIcon } from "../link-icon";
|
||||
import {
|
||||
isBrowserImage,
|
||||
resolveCoValue,
|
||||
useResolvedCoValue,
|
||||
} from "./use-resolve-covalue";
|
||||
|
||||
// Is there a chance we can pass the actual CoValue here?
|
||||
export function ValueRenderer({
|
||||
json,
|
||||
compact,
|
||||
onCoIDClick,
|
||||
}: {
|
||||
json: JsonValue | undefined;
|
||||
compact?: boolean;
|
||||
onCoIDClick?: (childNode: CoID<RawCoValue>) => void;
|
||||
}) {
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
|
||||
if (typeof json === "undefined" || json === undefined) {
|
||||
return <span className="text-gray-400">undefined</span>;
|
||||
}
|
||||
|
||||
if (json === null) {
|
||||
return <span className="text-gray-400">null</span>;
|
||||
}
|
||||
|
||||
if (typeof json === "string" && json.startsWith("co_")) {
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
"inline-flex gap-1 items-center",
|
||||
onCoIDClick && "text-blue-500 cursor-pointer hover:underline",
|
||||
)}
|
||||
onClick={() => {
|
||||
onCoIDClick?.(json as CoID<RawCoValue>);
|
||||
}}
|
||||
>
|
||||
{json}
|
||||
{onCoIDClick && <LinkIcon />}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof json === "string") {
|
||||
return (
|
||||
<span className="text-green-900 font-mono">
|
||||
{/* <span className="select-none opacity-70">{'"'}</span> */}
|
||||
{json}
|
||||
{/* <span className="select-none opacity-70">{'"'}</span> */}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof json === "number") {
|
||||
return <span className="text-purple-500">{json}</span>;
|
||||
}
|
||||
|
||||
if (typeof json === "boolean") {
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
json
|
||||
? "text-green-700 bg-green-700/5"
|
||||
: "text-amber-700 bg-amber-500/5",
|
||||
"font-mono",
|
||||
"inline-block px-1 py-0.5 rounded",
|
||||
)}
|
||||
>
|
||||
{json.toString()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (Array.isArray(json)) {
|
||||
return (
|
||||
<span title={JSON.stringify(json)}>
|
||||
Array <span className="text-gray-500">({json.length})</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof json === "object") {
|
||||
return (
|
||||
<span
|
||||
title={JSON.stringify(json, null, 2)}
|
||||
className="inline-block max-w-64"
|
||||
>
|
||||
{compact ? (
|
||||
<span>
|
||||
Object{" "}
|
||||
<span className="text-gray-500">({Object.keys(json).length})</span>
|
||||
<pre className="mt-1 text-sm whitespace-pre-wrap">
|
||||
{isExpanded
|
||||
? JSON.stringify(json, null, 2)
|
||||
: JSON.stringify(json, null, 2)
|
||||
.split("\n")
|
||||
.slice(0, 3)
|
||||
.join("\n") + (Object.keys(json).length > 2 ? "\n..." : "")}
|
||||
</pre>
|
||||
<button
|
||||
onClick={() => setIsExpanded(!isExpanded)}
|
||||
className="text-xs text-gray-500 hover:text-gray-700"
|
||||
>
|
||||
{isExpanded ? "Show less" : "Show more"}
|
||||
</button>
|
||||
</span>
|
||||
) : (
|
||||
<pre className="whitespace-pre-wrap">
|
||||
{JSON.stringify(json, null, 2)}
|
||||
</pre>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return <span>{String(json)}</span>;
|
||||
}
|
||||
|
||||
export const CoMapPreview = ({
|
||||
coId,
|
||||
node,
|
||||
limit = 6,
|
||||
}: {
|
||||
coId: CoID<RawCoValue>;
|
||||
node: LocalNode;
|
||||
limit?: number;
|
||||
}) => {
|
||||
const { value, snapshot, type, extendedType } = useResolvedCoValue(
|
||||
coId,
|
||||
node,
|
||||
);
|
||||
|
||||
if (!snapshot) {
|
||||
return (
|
||||
<div className="rounded bg-gray-100 animate-pulse whitespace-pre w-24">
|
||||
{" "}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (snapshot === "unavailable" && !value) {
|
||||
return <div className="text-gray-500">Unavailable</div>;
|
||||
}
|
||||
|
||||
if (extendedType === "image" && isBrowserImage(snapshot)) {
|
||||
return (
|
||||
<div>
|
||||
<img
|
||||
src={snapshot.placeholderDataURL}
|
||||
className="size-8 border-2 border-white drop-shadow-md my-2"
|
||||
/>
|
||||
<span className="text-gray-500 text-sm">
|
||||
{snapshot.originalSize[0]} x {snapshot.originalSize[1]}
|
||||
</span>
|
||||
|
||||
{/* <CoMapPreview coId={value[]} node={node} /> */}
|
||||
{/* <ProgressiveImg image={value}>
|
||||
{({ src }) => <img src={src} className={clsx("w-full")} />}
|
||||
</ProgressiveImg> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (extendedType === "record") {
|
||||
return (
|
||||
<div>
|
||||
Record{" "}
|
||||
<span className="text-gray-500">({Object.keys(snapshot).length})</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (type === "colist") {
|
||||
return (
|
||||
<div>
|
||||
List{" "}
|
||||
<span className="text-gray-500">
|
||||
({(snapshot as unknown as []).length})
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="text-sm flex flex-col gap-2 items-start">
|
||||
<div className="grid grid-cols-[auto_1fr] gap-2">
|
||||
{Object.entries(snapshot)
|
||||
.slice(0, limit)
|
||||
.map(([key, value]) => (
|
||||
<React.Fragment key={key}>
|
||||
<span className="font-medium">{key}: </span>
|
||||
<span>
|
||||
<ValueRenderer json={value} />
|
||||
</span>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
{Object.entries(snapshot).length > limit && (
|
||||
<div className="text-left text-xs text-gray-500 mt-2">
|
||||
{Object.entries(snapshot).length - limit} more
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export function AccountOrGroupPreview({
|
||||
coId,
|
||||
node,
|
||||
showId = false,
|
||||
onClick,
|
||||
}: {
|
||||
coId: CoID<RawCoValue>;
|
||||
node: LocalNode;
|
||||
showId?: boolean;
|
||||
onClick?: (name?: string) => void;
|
||||
}) {
|
||||
const { snapshot, extendedType } = useResolvedCoValue(coId, node);
|
||||
const [name, setName] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (extendedType === "account") {
|
||||
resolveCoValue(
|
||||
(snapshot as unknown as { profile: CoID<RawCoValue> }).profile,
|
||||
node,
|
||||
).then(({ snapshot }) => {
|
||||
if (
|
||||
typeof snapshot === "object" &&
|
||||
"name" in snapshot &&
|
||||
typeof snapshot.name === "string"
|
||||
) {
|
||||
setName(snapshot.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [snapshot, node, extendedType]);
|
||||
|
||||
if (!snapshot) return <span>Loading...</span>;
|
||||
if (extendedType !== "account" && extendedType !== "group") {
|
||||
return <span>CoID is not an account or group</span>;
|
||||
}
|
||||
|
||||
const displayName = extendedType === "account" ? name || "Account" : "Group";
|
||||
const displayText = showId ? `${displayName} (${coId})` : displayName;
|
||||
|
||||
const props = onClick
|
||||
? {
|
||||
onClick: () => onClick(displayName),
|
||||
className: "text-blue-500 cursor-pointer hover:underline",
|
||||
}
|
||||
: {
|
||||
className: "text-gray-500",
|
||||
};
|
||||
|
||||
return <span {...props}>{displayText}</span>;
|
||||
}
|
||||
@@ -1,5 +1,30 @@
|
||||
import type { Config } from "tailwindcss";
|
||||
import animate from "tailwindcss-animate";
|
||||
import plugin from "tailwindcss/plugin";
|
||||
|
||||
const stonePalette = {
|
||||
50: "oklch(0.988281 0.002 75)",
|
||||
100: "oklch(0.980563 0.002 75)",
|
||||
200: "oklch(0.917969 0.002 75)",
|
||||
300: "oklch(0.853516 0.002 75)",
|
||||
400: "oklch(0.789063 0.002 75)",
|
||||
500: "oklch(0.726563 0.002 75)",
|
||||
600: "oklch(0.613281 0.002 75)",
|
||||
700: "oklch(0.523438 0.002 75)",
|
||||
800: "oklch(0.412109 0.002 75)",
|
||||
900: "oklch(0.302734 0.002 75)",
|
||||
925: "oklch(0.220000 0.002 75)",
|
||||
950: "oklch(0.193359 0.002 75)",
|
||||
};
|
||||
|
||||
const stonePaletteWithAlpha = { ...stonePalette };
|
||||
|
||||
Object.keys(stonePalette).forEach((key) => {
|
||||
// @ts-ignore
|
||||
stonePaletteWithAlpha[key] = stonePaletteWithAlpha[key].replace(
|
||||
")",
|
||||
"/ <alpha-value>)",
|
||||
);
|
||||
});
|
||||
|
||||
const config: Config = {
|
||||
content: [
|
||||
@@ -18,62 +43,26 @@ const config: Config = {
|
||||
},
|
||||
extend: {
|
||||
colors: {
|
||||
border: "hsl(var(--border))",
|
||||
input: "hsl(var(--input))",
|
||||
ring: "hsl(var(--ring))",
|
||||
background: "hsl(var(--background))",
|
||||
foreground: "hsl(var(--foreground))",
|
||||
primary: {
|
||||
DEFAULT: "hsl(var(--primary))",
|
||||
foreground: "hsl(var(--primary-foreground))",
|
||||
stone: stonePaletteWithAlpha,
|
||||
gray: stonePaletteWithAlpha,
|
||||
blue: {
|
||||
50: "#f5f7ff",
|
||||
100: "#ebf0fe",
|
||||
200: "#d6e0fd",
|
||||
300: "#b3c7fc",
|
||||
400: "#8aa6f9",
|
||||
500: "#5870F1",
|
||||
600: "#3651E7",
|
||||
700: "#3313F7",
|
||||
800: "#2A12BE",
|
||||
900: "#12046A",
|
||||
950: "#1e1b4b",
|
||||
DEFAULT: "#3313F7",
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: "hsl(var(--secondary))",
|
||||
foreground: "hsl(var(--secondary-foreground))",
|
||||
},
|
||||
destructive: {
|
||||
DEFAULT: "hsl(var(--destructive))",
|
||||
foreground: "hsl(var(--destructive-foreground))",
|
||||
},
|
||||
muted: {
|
||||
DEFAULT: "hsl(var(--muted))",
|
||||
foreground: "hsl(var(--muted-foreground))",
|
||||
},
|
||||
accent: {
|
||||
DEFAULT: "hsl(var(--accent))",
|
||||
foreground: "hsl(var(--accent-foreground))",
|
||||
},
|
||||
popover: {
|
||||
DEFAULT: "hsl(var(--popover))",
|
||||
foreground: "hsl(var(--popover-foreground))",
|
||||
},
|
||||
card: {
|
||||
DEFAULT: "hsl(var(--card))",
|
||||
foreground: "hsl(var(--card-foreground))",
|
||||
},
|
||||
},
|
||||
borderRadius: {
|
||||
lg: "var(--radius)",
|
||||
md: "calc(var(--radius) - 2px)",
|
||||
sm: "calc(var(--radius) - 4px)",
|
||||
},
|
||||
keyframes: {
|
||||
"accordion-down": {
|
||||
from: { height: "0" },
|
||||
to: { height: "var(--radix-accordion-content-height)" },
|
||||
},
|
||||
"accordion-up": {
|
||||
from: { height: "var(--radix-accordion-content-height)" },
|
||||
to: { height: "0" },
|
||||
},
|
||||
},
|
||||
animation: {
|
||||
"accordion-down": "accordion-down 0.2s ease-out",
|
||||
"accordion-up": "accordion-up 0.2s ease-out",
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [animate],
|
||||
plugins: [plugin(({ addVariant }) => addVariant("label", "& :is(label)"))],
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
||||
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=multi-cursors-250425-1708
|
||||
VITE_GROUP_ID=co_zXE8C8sd9QxEbxnt3neRvFRPFUc
|
||||
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
|
||||
36
examples/multi-cursors/CHANGELOG.md
Normal file
36
examples/multi-cursors/CHANGELOG.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# multi-cursors
|
||||
|
||||
## 0.0.62
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.12.1
|
||||
- jazz-tools@0.12.1
|
||||
|
||||
## 0.0.61
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [01523dc]
|
||||
- Updated dependencies [4ea87dc]
|
||||
- Updated dependencies [1e6da19]
|
||||
- Updated dependencies [b6c6a0a]
|
||||
- jazz-tools@0.12.0
|
||||
- jazz-react@0.12.0
|
||||
|
||||
## 0.0.60
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-react@0.11.8
|
||||
- jazz-tools@0.11.8
|
||||
|
||||
## 0.0.59
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [a140f55]
|
||||
- Updated dependencies [4019918]
|
||||
- Updated dependencies [2b0d1b0]
|
||||
- jazz-tools@0.11.7
|
||||
- jazz-react@0.11.7
|
||||
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.62",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"preview": "vite preview",
|
||||
"format-and-lint": "biome check .",
|
||||
"format-and-lint:fix": "biome check . --write",
|
||||
"test": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-spring/web": "^9.7.5",
|
||||
"jazz-react": "workspace:*",
|
||||
"jazz-tools": "workspace:*",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@vitejs/plugin-react": "^4.3.3",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"globals": "^15.11.0",
|
||||
"is-ci": "^3.0.1",
|
||||
"postcss": "^8.4.27",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "~5.6.2",
|
||||
"vite": "^6.0.11",
|
||||
"vitest": "3.0.5"
|
||||
}
|
||||
}
|
||||
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: {},
|
||||
},
|
||||
};
|
||||
66
examples/multi-cursors/src/App.tsx
Normal file
66
examples/multi-cursors/src/App.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import { useAccount } from "jazz-react";
|
||||
import { Group, type ID } from "jazz-tools";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Logo } from "./Logo";
|
||||
import Container from "./components/Container";
|
||||
import { CursorFeed } from "./schema";
|
||||
import { getName } from "./utils/getName";
|
||||
import { loadCursorContainer } from "./utils/loadCursorContainer";
|
||||
|
||||
const cursorFeedIDToLoad = import.meta.env.VITE_CURSOR_FEED_ID;
|
||||
const groupIDToLoad = import.meta.env.VITE_GROUP_ID;
|
||||
|
||||
function App() {
|
||||
const { me } = useAccount();
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [cursorFeedID, setCursorFeedID] = useState<ID<CursorFeed> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("Loading cursor feed...", me.id);
|
||||
if (!me?.id) return;
|
||||
const loadCursorFeed = async () => {
|
||||
const id = await loadCursorContainer(
|
||||
me,
|
||||
cursorFeedIDToLoad as ID<CursorFeed>,
|
||||
groupIDToLoad as ID<Group>,
|
||||
);
|
||||
if (id) {
|
||||
setCursorFeedID(id);
|
||||
setLoaded(true);
|
||||
}
|
||||
};
|
||||
loadCursorFeed();
|
||||
}, [me?.id]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<main className="h-screen">
|
||||
{loaded && cursorFeedID ? (
|
||||
<Container cursorFeedID={cursorFeedID} />
|
||||
) : (
|
||||
<div>Loading...</div>
|
||||
)}
|
||||
</main>
|
||||
|
||||
<footer className="fixed bottom-4 right-4 flex items-center gap-4">
|
||||
<input
|
||||
type="text"
|
||||
value={getName(me?.profile?.name, me?.sessionID)}
|
||||
onChange={(e) => {
|
||||
if (!me?.profile) return;
|
||||
me.profile.name = e.target.value;
|
||||
}}
|
||||
placeholder="Your name"
|
||||
className="px-2 py-1 rounded border pointer-events-auto"
|
||||
autoComplete="off"
|
||||
maxLength={32}
|
||||
/>
|
||||
<div className="pointer-events-none">
|
||||
<Logo />
|
||||
</div>
|
||||
</footer>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
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";
|
||||
16
examples/multi-cursors/src/components/Boundary.tsx
Normal file
16
examples/multi-cursors/src/components/Boundary.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ViewBox } from "../types";
|
||||
|
||||
export function Boundary({ bounds }: { bounds: ViewBox }) {
|
||||
return (
|
||||
<>
|
||||
<rect
|
||||
x={bounds.x}
|
||||
y={bounds.y}
|
||||
width={bounds.width}
|
||||
height={bounds.height}
|
||||
stroke="red"
|
||||
fill="none"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
102
examples/multi-cursors/src/components/Canvas.tsx
Normal file
102
examples/multi-cursors/src/components/Canvas.tsx
Normal file
@@ -0,0 +1,102 @@
|
||||
import { useAccount } from "jazz-react";
|
||||
import { CoFeedEntry, co } from "jazz-tools";
|
||||
import { CursorMoveEvent, useCanvas } from "../hooks/useCanvas";
|
||||
import { Cursor as CursorType, ViewBox } from "../types";
|
||||
import { centerOfBounds } from "../utils/centerOfBounds";
|
||||
import { getColor } from "../utils/getColor";
|
||||
import { getName } from "../utils/getName";
|
||||
import { Boundary } from "./Boundary";
|
||||
import { CanvasBackground } from "./CanvasBackground";
|
||||
import { CanvasDemoContent } from "./CanvasDemoContent";
|
||||
import { Cursor } from "./Cursor";
|
||||
|
||||
const OLD_CURSOR_AGE_SECONDS = Number(
|
||||
import.meta.env.VITE_OLD_CURSOR_AGE_SECONDS,
|
||||
);
|
||||
|
||||
const DEBUG = import.meta.env.VITE_DEBUG === "true";
|
||||
|
||||
// For debugging purposes, we can set a fixed bounds
|
||||
const debugBounds: ViewBox = {
|
||||
x: 320,
|
||||
y: 320,
|
||||
width: 640,
|
||||
height: 640,
|
||||
};
|
||||
|
||||
interface CanvasProps {
|
||||
remoteCursors: CoFeedEntry<co<CursorType>>[];
|
||||
onCursorMove: (move: CursorMoveEvent) => void;
|
||||
name: string;
|
||||
}
|
||||
|
||||
function Canvas({ remoteCursors, onCursorMove, name }: CanvasProps) {
|
||||
const { me } = useAccount();
|
||||
|
||||
const {
|
||||
svgProps,
|
||||
isDragging,
|
||||
isMouseOver,
|
||||
mousePosition,
|
||||
bgPosition,
|
||||
dottedGridSize,
|
||||
viewBox,
|
||||
} = useCanvas({ onCursorMove });
|
||||
|
||||
const bounds = DEBUG ? debugBounds : viewBox;
|
||||
const center = centerOfBounds(bounds);
|
||||
|
||||
return (
|
||||
<svg width="100%" height="100%" {...svgProps}>
|
||||
<CanvasBackground
|
||||
bgPosition={bgPosition}
|
||||
dottedGridSize={dottedGridSize}
|
||||
/>
|
||||
|
||||
<CanvasDemoContent />
|
||||
{DEBUG && <Boundary bounds={bounds} />}
|
||||
|
||||
{remoteCursors.map((entry) => {
|
||||
if (
|
||||
entry.tx.sessionID === me?.sessionID ||
|
||||
(OLD_CURSOR_AGE_SECONDS &&
|
||||
entry.madeAt < new Date(Date.now() - 1000 * OLD_CURSOR_AGE_SECONDS))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const name = getName(entry.by?.profile?.name, entry.tx.sessionID);
|
||||
const color = getColor(entry.tx.sessionID);
|
||||
const age = new Date().getTime() - new Date(entry.madeAt).getTime();
|
||||
|
||||
return (
|
||||
<Cursor
|
||||
key={entry.tx.sessionID}
|
||||
position={entry.value.position}
|
||||
color={color}
|
||||
isDragging={false}
|
||||
isRemote={true}
|
||||
name={name}
|
||||
age={age}
|
||||
centerOfBounds={center}
|
||||
bounds={bounds}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
{isMouseOver ? (
|
||||
<Cursor
|
||||
position={mousePosition}
|
||||
color="#FF69B4"
|
||||
isDragging={isDragging}
|
||||
isRemote={false}
|
||||
name={name}
|
||||
centerOfBounds={center}
|
||||
bounds={bounds}
|
||||
/>
|
||||
) : null}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export default Canvas;
|
||||
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;
|
||||
141
examples/multi-cursors/src/components/Cursor.tsx
Normal file
141
examples/multi-cursors/src/components/Cursor.tsx
Normal file
@@ -0,0 +1,141 @@
|
||||
import { animated, to, useSpring } from "@react-spring/web";
|
||||
import { Vec2, ViewBox } from "../types";
|
||||
import { calculateBoundaryIntersection } from "../utils/boundaryIntersection";
|
||||
import { isOutOfBounds } from "../utils/isOutOfBounds";
|
||||
import { CursorLabel } from "./CursorLabel";
|
||||
|
||||
interface CursorProps {
|
||||
position: { x: number; y: number };
|
||||
color: string;
|
||||
isDragging: boolean;
|
||||
isRemote: boolean;
|
||||
name: string;
|
||||
age?: number;
|
||||
centerOfBounds: Vec2;
|
||||
bounds?: ViewBox;
|
||||
}
|
||||
|
||||
const LABEL_BOUNDS_PADDING = 32;
|
||||
const CURSOR_VISIBILITY_OFFSET = 20;
|
||||
|
||||
export function Cursor({
|
||||
position,
|
||||
color,
|
||||
isDragging,
|
||||
isRemote,
|
||||
name,
|
||||
age = 0,
|
||||
centerOfBounds,
|
||||
bounds,
|
||||
}: CursorProps) {
|
||||
if (!bounds) return null;
|
||||
|
||||
const intersectionPoint = calculateBoundaryIntersection(
|
||||
centerOfBounds,
|
||||
position,
|
||||
bounds,
|
||||
);
|
||||
|
||||
const labelBounds = {
|
||||
x: bounds.x + LABEL_BOUNDS_PADDING / 2,
|
||||
y: bounds.y + LABEL_BOUNDS_PADDING / 2,
|
||||
width: bounds.width - LABEL_BOUNDS_PADDING,
|
||||
height: bounds.height - LABEL_BOUNDS_PADDING,
|
||||
};
|
||||
|
||||
const cursorIntersectionPoint = calculateBoundaryIntersection(
|
||||
centerOfBounds,
|
||||
position,
|
||||
labelBounds,
|
||||
);
|
||||
|
||||
const isStrictlyOutOfBounds = isOutOfBounds(position, bounds);
|
||||
const shouldHideCursor = isOutOfBounds(
|
||||
position,
|
||||
bounds,
|
||||
CURSOR_VISIBILITY_OFFSET,
|
||||
);
|
||||
|
||||
const springs = useSpring({
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
opacity: age > 60000 ? 0 : 1,
|
||||
immediate: !isRemote,
|
||||
config: {
|
||||
tension: 170,
|
||||
friction: 26,
|
||||
},
|
||||
});
|
||||
|
||||
const intersectionSprings = useSpring({
|
||||
x: intersectionPoint.x,
|
||||
y: intersectionPoint.y,
|
||||
config: {
|
||||
tension: 170,
|
||||
friction: 26,
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<animated.g
|
||||
transform={to(
|
||||
[springs.x, springs.y],
|
||||
(x: number, y: number) => `translate(${x}, ${y})`,
|
||||
)}
|
||||
>
|
||||
{isStrictlyOutOfBounds ? (
|
||||
<circle cx={0} cy={0} r={4} fill={color} />
|
||||
) : null}
|
||||
{!shouldHideCursor ? (
|
||||
<polygon
|
||||
points="0,0 0,20 14.3,14.3"
|
||||
fill={
|
||||
isDragging
|
||||
? color
|
||||
: `color-mix(in oklch, ${color}, transparent 56%)`
|
||||
}
|
||||
stroke={color}
|
||||
strokeWidth="3"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
) : null}
|
||||
</animated.g>
|
||||
|
||||
{isRemote ? (
|
||||
<>
|
||||
<CursorLabel
|
||||
name={name}
|
||||
color={color}
|
||||
position={cursorIntersectionPoint}
|
||||
bounds={bounds}
|
||||
isOutOfBounds={isStrictlyOutOfBounds}
|
||||
/>
|
||||
{isStrictlyOutOfBounds ? (
|
||||
<animated.g
|
||||
transform={to(
|
||||
[intersectionSprings.x, intersectionSprings.y],
|
||||
(x: number, y: number) => {
|
||||
const angle =
|
||||
Math.atan2(centerOfBounds.y - y, centerOfBounds.x - x) *
|
||||
(180 / Math.PI);
|
||||
return `translate(${x}, ${y}) rotate(${angle})`;
|
||||
},
|
||||
)}
|
||||
>
|
||||
<path
|
||||
d="M 8,-4 L 2,0 L 8,4"
|
||||
fill="none"
|
||||
stroke={color}
|
||||
strokeWidth="3"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</animated.g>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
93
examples/multi-cursors/src/components/CursorLabel.tsx
Normal file
93
examples/multi-cursors/src/components/CursorLabel.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
import { animated, to, useSpring } from "@react-spring/web";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Vec2, ViewBox } from "../types";
|
||||
import { getLabelPosition } from "../utils/getLabelPosition";
|
||||
|
||||
const DEBUG = import.meta.env.VITE_DEBUG === "true";
|
||||
|
||||
interface CursorLabelProps {
|
||||
name: string;
|
||||
color: string;
|
||||
position: Vec2;
|
||||
bounds?: ViewBox;
|
||||
isOutOfBounds?: boolean;
|
||||
}
|
||||
|
||||
interface TextDimensions {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export function CursorLabel({
|
||||
name,
|
||||
color,
|
||||
position,
|
||||
bounds,
|
||||
isOutOfBounds,
|
||||
}: CursorLabelProps) {
|
||||
const textRef = useRef<SVGTextElement>(null);
|
||||
const [dimensions, setDimensions] = useState<TextDimensions>({
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const bbox = textRef.current?.getBBox();
|
||||
setDimensions({ width: bbox?.width ?? 0, height: bbox?.height ?? 0 });
|
||||
}, [name]);
|
||||
|
||||
const labelPosition = getLabelPosition(
|
||||
position,
|
||||
dimensions,
|
||||
bounds,
|
||||
isOutOfBounds,
|
||||
);
|
||||
const labelSprings = useSpring<Vec2>({
|
||||
...labelPosition,
|
||||
config: {
|
||||
tension: 170,
|
||||
friction: 26,
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<animated.text
|
||||
ref={textRef}
|
||||
x={to([labelSprings.x], (x) => x)}
|
||||
y={to([labelSprings.y], (y) => y)}
|
||||
fill={color}
|
||||
stroke="white"
|
||||
strokeWidth="3"
|
||||
strokeLinejoin="round"
|
||||
paintOrder="stroke"
|
||||
fontSize="14"
|
||||
dominantBaseline="hanging"
|
||||
textAnchor="start"
|
||||
>
|
||||
{name}
|
||||
</animated.text>
|
||||
{DEBUG ? (
|
||||
<>
|
||||
<text x={position.x} y={position.y} fill="red" fontSize="8">
|
||||
{position.x}, {position.y}
|
||||
</text>
|
||||
<text x={labelPosition.x} y={labelPosition.y} fill="red" fontSize="8">
|
||||
{bounds
|
||||
? `${bounds.x - labelPosition.x}, ${bounds.y - labelPosition.y}`
|
||||
: "no bounds"}
|
||||
</text>
|
||||
<line
|
||||
x1={position.x}
|
||||
y1={position.y}
|
||||
x2={labelPosition.x}
|
||||
y2={labelPosition.y}
|
||||
stroke="red"
|
||||
strokeWidth="1"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
140
examples/multi-cursors/src/hooks/useCanvas.ts
Normal file
140
examples/multi-cursors/src/hooks/useCanvas.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import type { ViewBox } from "../types";
|
||||
import { throttleTime } from "../utils/throttleTime";
|
||||
|
||||
export interface CursorMoveEvent {
|
||||
position: { x: number; y: number };
|
||||
isDragging: boolean;
|
||||
}
|
||||
|
||||
export function useCanvas({
|
||||
onCursorMove,
|
||||
throttleMs = 100,
|
||||
}: {
|
||||
onCursorMove: (event: CursorMoveEvent) => void;
|
||||
throttleMs?: number;
|
||||
}) {
|
||||
const [viewBox, setViewBox] = useState<ViewBox>({
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const [isMouseOver, setIsMouseOver] = useState(false);
|
||||
const [dragStart, setDragStart] = useState({ x: 0, y: 0 });
|
||||
const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
|
||||
|
||||
const onCursorMoveThrottled = useCallback(
|
||||
throttleTime((move: CursorMoveEvent) => onCursorMove(move), throttleMs),
|
||||
[onCursorMove, throttleMs],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
setViewBox((prev) => ({
|
||||
...prev,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
}));
|
||||
};
|
||||
|
||||
setViewBox((prev) => ({
|
||||
...prev,
|
||||
x: -window.innerWidth / 2,
|
||||
y: -window.innerHeight / 2,
|
||||
}));
|
||||
|
||||
window.addEventListener("resize", handleResize);
|
||||
return () => window.removeEventListener("resize", handleResize);
|
||||
}, []);
|
||||
|
||||
const handleMouseDown = (e: React.MouseEvent<SVGSVGElement>) => {
|
||||
setIsDragging(true);
|
||||
setDragStart({
|
||||
x: e.clientX,
|
||||
y: e.clientY,
|
||||
});
|
||||
|
||||
onCursorMoveThrottled({
|
||||
position: mousePosition,
|
||||
isDragging: true,
|
||||
});
|
||||
};
|
||||
const handleMouseUp = () => {
|
||||
setIsDragging(false);
|
||||
|
||||
onCursorMoveThrottled({
|
||||
position: mousePosition,
|
||||
isDragging: false,
|
||||
});
|
||||
};
|
||||
const handleMouseEnter = () => setIsMouseOver(true);
|
||||
const handleMouseLeave = () => {
|
||||
setIsMouseOver(false);
|
||||
setIsDragging(false);
|
||||
|
||||
onCursorMoveThrottled({
|
||||
position: mousePosition,
|
||||
isDragging: false,
|
||||
});
|
||||
};
|
||||
|
||||
const handleMouseMove = (e: React.MouseEvent<SVGSVGElement>) => {
|
||||
const svg = e.currentTarget;
|
||||
const ctm = svg.getScreenCTM();
|
||||
|
||||
if (!ctm) throw new Error("can't get SVG screen CTM");
|
||||
|
||||
const point = svg.createSVGPoint();
|
||||
point.x = e.clientX;
|
||||
point.y = e.clientY;
|
||||
const svgPoint = point.matrixTransform(ctm.inverse());
|
||||
|
||||
setMousePosition(svgPoint);
|
||||
|
||||
onCursorMoveThrottled({
|
||||
position: svgPoint,
|
||||
isDragging,
|
||||
});
|
||||
|
||||
if (!isDragging) return;
|
||||
|
||||
const dx = e.clientX - dragStart.x;
|
||||
const dy = e.clientY - dragStart.y;
|
||||
|
||||
setViewBox((prev) => ({ ...prev, x: prev.x - dx, y: prev.y - dy }));
|
||||
setDragStart({ x: e.clientX, y: e.clientY });
|
||||
};
|
||||
|
||||
const dottedGridSize = 40;
|
||||
|
||||
const bgPosition = {
|
||||
x: Math.floor(viewBox.x / dottedGridSize) * dottedGridSize,
|
||||
y: Math.floor(viewBox.y / dottedGridSize) * dottedGridSize,
|
||||
};
|
||||
|
||||
const handlers = {
|
||||
onMouseDown: handleMouseDown,
|
||||
onMouseUp: handleMouseUp,
|
||||
onMouseEnter: handleMouseEnter,
|
||||
onMouseLeave: handleMouseLeave,
|
||||
onMouseMove: handleMouseMove,
|
||||
};
|
||||
|
||||
const svgProps: React.SVGProps<SVGSVGElement> = {
|
||||
...handlers,
|
||||
viewBox: `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`,
|
||||
className: "select-none cursor-none",
|
||||
};
|
||||
|
||||
return {
|
||||
svgProps,
|
||||
isDragging,
|
||||
isMouseOver,
|
||||
mousePosition,
|
||||
bgPosition,
|
||||
dottedGridSize,
|
||||
viewBox,
|
||||
};
|
||||
}
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
examples/multi-cursors/src/types.d.ts
vendored
Normal file
27
examples/multi-cursors/src/types.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
export type Vec2 = {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
export type Cursor = {
|
||||
position: Vec2;
|
||||
};
|
||||
|
||||
export type Camera = {
|
||||
position: Vec2;
|
||||
};
|
||||
|
||||
export type RemoteCursor = Cursor & {
|
||||
id: ID;
|
||||
color: string;
|
||||
name: string;
|
||||
isRemote: true;
|
||||
isDragging: boolean;
|
||||
};
|
||||
|
||||
export type ViewBox = {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { calculateBoundaryIntersection } from "../boundaryIntersection";
|
||||
|
||||
describe("calculateBoundaryIntersection", () => {
|
||||
const bounds = { x: 0, y: 0, width: 100, height: 100 };
|
||||
|
||||
it("should handle vertical lines (dx = 0)", () => {
|
||||
const center = { x: 50, y: 50 };
|
||||
const point = { x: 50, y: 150 }; // Straight up from center
|
||||
|
||||
const intersection = calculateBoundaryIntersection(center, point, bounds);
|
||||
|
||||
expect(intersection).toEqual({ x: 50, y: 100 }); // Should intersect at bottom boundary
|
||||
});
|
||||
|
||||
it("should handle horizontal lines (dy = 0)", () => {
|
||||
const center = { x: 50, y: 50 };
|
||||
const point = { x: 150, y: 50 }; // Straight right from center
|
||||
|
||||
const intersection = calculateBoundaryIntersection(center, point, bounds);
|
||||
|
||||
expect(intersection).toEqual({ x: 100, y: 50 }); // Should intersect at right boundary
|
||||
});
|
||||
|
||||
it("should handle vertical lines at boundaries", () => {
|
||||
const center = { x: 0, y: 50 };
|
||||
const point = { x: 0, y: 150 }; // Vertical line at x=0
|
||||
|
||||
const intersection = calculateBoundaryIntersection(center, point, bounds);
|
||||
|
||||
expect(intersection).toEqual({ x: 0, y: 100 }); // Should intersect at bottom boundary
|
||||
});
|
||||
|
||||
it("should handle horizontal lines at boundaries", () => {
|
||||
const center = { x: 50, y: 0 };
|
||||
const point = { x: 150, y: 0 }; // Horizontal line at y=0
|
||||
|
||||
const intersection = calculateBoundaryIntersection(center, point, bounds);
|
||||
|
||||
expect(intersection).toEqual({ x: 100, y: 0 }); // Should intersect at right boundary
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getLabelPosition } from "../getLabelPosition";
|
||||
|
||||
describe("getLabelPosition", () => {
|
||||
const dimensions = { width: 100, height: 20 };
|
||||
const bounds = { x: 0, y: 0, width: 1000, height: 1000 };
|
||||
|
||||
it("should position label with default offset when cursor is in bounds", () => {
|
||||
const position = { x: 500, y: 500 };
|
||||
const result = getLabelPosition(position, dimensions, bounds, false);
|
||||
|
||||
expect(result).toEqual({
|
||||
x: position.x + 15,
|
||||
y: position.y + 25,
|
||||
});
|
||||
});
|
||||
|
||||
it("should position label with default offset when bounds are undefined", () => {
|
||||
const position = { x: 500, y: 500 };
|
||||
const result = getLabelPosition(position, dimensions, undefined, true);
|
||||
|
||||
expect(result).toEqual({
|
||||
x: position.x + 15,
|
||||
y: position.y + 25,
|
||||
});
|
||||
});
|
||||
|
||||
it("should adjust label position based on cursor position when out of bounds", () => {
|
||||
const position = { x: 800, y: 600 };
|
||||
const result = getLabelPosition(position, dimensions, bounds, true);
|
||||
|
||||
// At x=800, percentageH = 0.8, so x offset should be -80 (0.8 * width)
|
||||
// At y=600, percentageV = 0.6, so y offset should be -12 (0.6 * height)
|
||||
expect(result).toEqual({
|
||||
x: position.x - 0.8 * dimensions.width,
|
||||
y: position.y - 0.6 * dimensions.height,
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle cursor at bounds edges", () => {
|
||||
const position = { x: 1000, y: 1000 }; // Bottom-right corner
|
||||
const result = getLabelPosition(position, dimensions, bounds, true);
|
||||
|
||||
// At the edges, percentages should be 1, so full dimension should be subtracted
|
||||
expect(result).toEqual({
|
||||
x: position.x - dimensions.width,
|
||||
y: position.y - dimensions.height,
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle cursor at bounds origin", () => {
|
||||
const position = { x: 0, y: 0 }; // Top-left corner
|
||||
const result = getLabelPosition(position, dimensions, bounds, true);
|
||||
|
||||
// At origin, percentages should be 0, so no offset from position
|
||||
expect(result).toEqual({
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isOutOfBounds } from "../isOutOfBounds";
|
||||
|
||||
describe("isOutOfBounds", () => {
|
||||
it("should return true if the position is out of bounds", () => {
|
||||
expect(
|
||||
isOutOfBounds(
|
||||
{ x: 101, y: 101 },
|
||||
{ x: 0, y: 0, width: 100, height: 100 },
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if the position is within bounds", () => {
|
||||
expect(
|
||||
isOutOfBounds({ x: 50, y: 50 }, { x: 0, y: 0, width: 100, height: 100 }),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if the position is inside the grace area", () => {
|
||||
expect(
|
||||
isOutOfBounds(
|
||||
{ x: 110, y: 110 },
|
||||
{ x: 0, y: 0, width: 100, height: 100 },
|
||||
20,
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
77
examples/multi-cursors/src/utils/boundaryIntersection.ts
Normal file
77
examples/multi-cursors/src/utils/boundaryIntersection.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { Vec2, ViewBox } from "../types";
|
||||
|
||||
/**
|
||||
* Calculate the intersection point of a line and a boundary.
|
||||
* @param center - The origin of the line.
|
||||
* @param point - The end of the line to calculate the intersection for.
|
||||
* @param bounds - The bounds of the boundary.
|
||||
* @returns The intersection point.
|
||||
*/
|
||||
export function calculateBoundaryIntersection(
|
||||
center: Vec2,
|
||||
point: Vec2,
|
||||
bounds: ViewBox,
|
||||
): Vec2 {
|
||||
// Calculate direction vector
|
||||
const dx = point.x - center.x;
|
||||
const dy = point.y - center.y;
|
||||
|
||||
// Calculate all possible intersections
|
||||
let horizontalIntersection: Vec2 | null = null;
|
||||
let verticalIntersection: Vec2 | null = null;
|
||||
|
||||
// Check horizontal bounds
|
||||
if (dx !== 0) {
|
||||
// Skip horizontal bounds check if line is vertical
|
||||
if (point.x < bounds.x) {
|
||||
const y = center.y + (dy * (bounds.x - center.x)) / dx;
|
||||
if (y >= bounds.y && y <= bounds.y + bounds.height) {
|
||||
horizontalIntersection = { x: bounds.x, y };
|
||||
}
|
||||
} else if (point.x > bounds.x + bounds.width) {
|
||||
const y = center.y + (dy * (bounds.x + bounds.width - center.x)) / dx;
|
||||
if (y >= bounds.y && y <= bounds.y + bounds.height) {
|
||||
horizontalIntersection = { x: bounds.x + bounds.width, y };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check vertical bounds
|
||||
if (dy !== 0) {
|
||||
// Skip vertical bounds check if line is horizontal
|
||||
if (point.y < bounds.y) {
|
||||
const x = center.x + (dx * (bounds.y - center.y)) / dy;
|
||||
if (x >= bounds.x && x <= bounds.x + bounds.width) {
|
||||
verticalIntersection = { x, y: bounds.y };
|
||||
}
|
||||
} else if (point.y > bounds.y + bounds.height) {
|
||||
const x = center.x + (dx * (bounds.y + bounds.height - center.y)) / dy;
|
||||
if (x >= bounds.x && x <= bounds.x + bounds.width) {
|
||||
verticalIntersection = { x, y: bounds.y + bounds.height };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Choose the intersection point that's closest to the actual point
|
||||
if (horizontalIntersection && verticalIntersection) {
|
||||
const horizontalDist = Math.hypot(
|
||||
point.x - horizontalIntersection.x,
|
||||
point.y - horizontalIntersection.y,
|
||||
);
|
||||
const verticalDist = Math.hypot(
|
||||
point.x - verticalIntersection.x,
|
||||
point.y - verticalIntersection.y,
|
||||
);
|
||||
return horizontalDist < verticalDist
|
||||
? horizontalIntersection
|
||||
: verticalIntersection;
|
||||
}
|
||||
|
||||
return (
|
||||
horizontalIntersection ||
|
||||
verticalIntersection || {
|
||||
x: Math.max(bounds.x, Math.min(bounds.x + bounds.width, point.x)),
|
||||
y: Math.max(bounds.y, Math.min(bounds.y + bounds.height, point.y)),
|
||||
}
|
||||
);
|
||||
}
|
||||
17
examples/multi-cursors/src/utils/centerOfBounds.ts
Normal file
17
examples/multi-cursors/src/utils/centerOfBounds.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Vec2, ViewBox } from "../types";
|
||||
|
||||
/**
|
||||
* Get the center of a bounds.
|
||||
* @param bounds - The bounds to get the center of.
|
||||
* @returns The center of the bounds.
|
||||
*/
|
||||
export function centerOfBounds(bounds?: ViewBox): Vec2 {
|
||||
if (!bounds) {
|
||||
return { x: 0, y: 0 };
|
||||
}
|
||||
|
||||
return {
|
||||
x: bounds.x + bounds.width / 2,
|
||||
y: bounds.y + bounds.height / 2,
|
||||
};
|
||||
}
|
||||
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})`;
|
||||
};
|
||||
40
examples/multi-cursors/src/utils/getLabelPosition.ts
Normal file
40
examples/multi-cursors/src/utils/getLabelPosition.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Vec2, ViewBox } from "../types";
|
||||
|
||||
interface TextDimensions {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface LabelPosition {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the position of a cursor label based on cursor position, label dimensions, and bounds
|
||||
* Such that the label is always on the same side of the bounds as the cursor
|
||||
* @param position - The cursor position
|
||||
* @param dimensions - The dimensions of the label text
|
||||
* @param bounds - The viewport bounds
|
||||
* @param isOutOfBounds - Whether the cursor is outside the bounds
|
||||
* @returns The calculated label position
|
||||
*/
|
||||
export function getLabelPosition(
|
||||
position: Vec2,
|
||||
dimensions: TextDimensions,
|
||||
bounds?: ViewBox,
|
||||
isOutOfBounds?: boolean,
|
||||
): LabelPosition {
|
||||
if (!isOutOfBounds || !bounds) {
|
||||
return { x: position.x + 15, y: position.y + 25 };
|
||||
}
|
||||
|
||||
// Calculate the percentage of the bounds that the intersection point is from the left
|
||||
const percentageH = (position.x - bounds.x) / bounds.width;
|
||||
const percentageV = (position.y - bounds.y) / bounds.height;
|
||||
|
||||
return {
|
||||
x: position.x - percentageH * dimensions.width,
|
||||
y: position.y - percentageV * dimensions.height,
|
||||
};
|
||||
}
|
||||
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;
|
||||
}
|
||||
21
examples/multi-cursors/src/utils/isOutOfBounds.ts
Normal file
21
examples/multi-cursors/src/utils/isOutOfBounds.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Vec2, ViewBox } from "../types";
|
||||
|
||||
/**
|
||||
* Check if a position is out of bounds of a view box.
|
||||
* @param position - The position to check.
|
||||
* @param bounds - The bounds of the view box.
|
||||
* @param grace - The grace distance to allow for the position to be out of bounds.
|
||||
* @returns True if the position is out of bounds, false otherwise.
|
||||
*/
|
||||
export function isOutOfBounds(
|
||||
position: Vec2,
|
||||
bounds: ViewBox,
|
||||
grace: number = 0,
|
||||
): boolean {
|
||||
return (
|
||||
position.x < bounds.x - grace ||
|
||||
position.x > bounds.x + bounds.width + grace ||
|
||||
position.y < bounds.y - grace ||
|
||||
position.y > bounds.y + bounds.height + grace
|
||||
);
|
||||
}
|
||||
83
examples/multi-cursors/src/utils/loadCursorContainer.ts
Normal file
83
examples/multi-cursors/src/utils/loadCursorContainer.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { Account, Group, type ID } from "jazz-tools";
|
||||
import { CursorContainer, CursorFeed } from "../schema";
|
||||
|
||||
/**
|
||||
* Creates a new group to own the cursor container.
|
||||
* @param me - The account of the current user.
|
||||
* @returns The group.
|
||||
*/
|
||||
function createGroup(me: Account) {
|
||||
const group = Group.create({
|
||||
owner: me,
|
||||
});
|
||||
group.addMember("everyone", "writer");
|
||||
console.log("Created group");
|
||||
console.log(`Add "VITE_GROUP_ID=${group.id}" to your .env file`);
|
||||
return group;
|
||||
}
|
||||
|
||||
export async function loadGroup(me: Account, groupID: ID<Group>) {
|
||||
if (groupID === undefined) {
|
||||
console.log("No group ID found in .env, creating group...");
|
||||
return createGroup(me);
|
||||
}
|
||||
const group = await Group.load(groupID, {});
|
||||
if (group === null || group === undefined) {
|
||||
console.log("Group not found, creating group...");
|
||||
return createGroup(me);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the cursor container for the given cursor feed ID.
|
||||
* If the cursor container does not exist, it creates a new one.
|
||||
* If the cursor container exists, it loads the existing one.
|
||||
* @param me - The account of the current user.
|
||||
* @param cursorFeedID - The ID of the cursor feed.
|
||||
* @param groupID - The ID of the group.
|
||||
*/
|
||||
export async function loadCursorContainer(
|
||||
me: Account,
|
||||
cursorFeedID = "cursor-feed",
|
||||
groupID: ID<Group>,
|
||||
): Promise<ID<CursorFeed> | undefined> {
|
||||
if (!me) return;
|
||||
console.log("Loading group...");
|
||||
const group = await loadGroup(me, groupID);
|
||||
|
||||
const cursorContainerID = CursorContainer.findUnique(
|
||||
cursorFeedID,
|
||||
group?.id as ID<Group>,
|
||||
);
|
||||
console.log("Loading cursor container:", cursorContainerID);
|
||||
const cursorContainer = await CursorContainer.load(cursorContainerID, {
|
||||
resolve: {
|
||||
cursorFeed: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (cursorContainer === null || cursorContainer === undefined) {
|
||||
console.log("Global cursors does not exist, creating...");
|
||||
const cursorContainer = CursorContainer.create(
|
||||
{
|
||||
cursorFeed: CursorFeed.create([], group),
|
||||
},
|
||||
{
|
||||
owner: group,
|
||||
unique: cursorFeedID,
|
||||
},
|
||||
);
|
||||
console.log("Created global cursors", cursorContainer.id);
|
||||
if (cursorContainer.cursorFeed === null) {
|
||||
throw new Error("cursorFeed is null");
|
||||
}
|
||||
return cursorContainer.cursorFeed.id;
|
||||
} else {
|
||||
console.log(
|
||||
"Global cursors already exists, loading...",
|
||||
cursorContainer.id,
|
||||
);
|
||||
return cursorContainer.cursorFeed?.id;
|
||||
}
|
||||
}
|
||||
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;
|
||||
};
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user