Compare commits
509 Commits
cojson@0.4
...
cojson@0.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c14a0e05be | ||
|
|
016dd3a5dd | ||
|
|
5c4ca9103c | ||
|
|
b4aad92907 | ||
|
|
56d1e095a1 | ||
|
|
6dee9aae49 | ||
|
|
a10bff981e | ||
|
|
e333f7884a | ||
|
|
8ea7bf237b | ||
|
|
5e8409fa08 | ||
|
|
23354c1767 | ||
|
|
0efb69d0db | ||
|
|
0462c4e41b | ||
|
|
70a5673197 | ||
|
|
9ec3203485 | ||
|
|
1a46f9b2e1 | ||
|
|
77bb26a8d7 | ||
|
|
2a36dcf592 | ||
|
|
fc2bcadbe2 | ||
|
|
46b0cc1adb | ||
|
|
d75d1c6a3f | ||
|
|
13b236aeed | ||
|
|
1c0a61b0b2 | ||
|
|
ceb92438f4 | ||
|
|
9bdd62ed4c | ||
|
|
3f5ef7e799 | ||
|
|
e7a573fa94 | ||
|
|
364060eaa7 | ||
|
|
a3ddc3d5e0 | ||
|
|
185f747adb | ||
|
|
895d281088 | ||
|
|
b44e4354f7 | ||
|
|
3fcb0665ec | ||
|
|
be49d33ce5 | ||
|
|
c7dae1608b | ||
|
|
b020c5868b | ||
|
|
eae42d3afe | ||
|
|
a816e2436e | ||
|
|
b09e35e372 | ||
|
|
d2c8121c9c | ||
|
|
380bb88ffa | ||
|
|
e0e3726b3c | ||
|
|
c2253a7979 | ||
|
|
9d244226ec | ||
|
|
71df5e3a59 | ||
|
|
3a738dad88 | ||
|
|
56d301cfde | ||
|
|
5efec6d5ea | ||
|
|
32769b24f1 | ||
|
|
6ab53c263d | ||
|
|
e7f3e4e242 | ||
|
|
8bb5201647 | ||
|
|
a9fc94f53d | ||
|
|
ca7c0510d1 | ||
|
|
1bf16f0859 | ||
|
|
21b503c188 | ||
|
|
0053e9796c | ||
|
|
e84941b1b1 | ||
|
|
57f6f8d67e | ||
|
|
5b8e69d973 | ||
|
|
7213b1bfa3 | ||
|
|
11f0770f08 | ||
|
|
44e6dc3ae8 | ||
|
|
b5d20d2488 | ||
|
|
0185545838 | ||
|
|
8c8f85859c | ||
|
|
104384409e | ||
|
|
179827ae56 | ||
|
|
6645829876 | ||
|
|
68cb302722 | ||
|
|
8dc33f2790 | ||
|
|
5f64ba326c | ||
|
|
7ccb15107c | ||
|
|
b102964743 | ||
|
|
216d50a09c | ||
|
|
07ea59fdcb | ||
|
|
932a84a47f | ||
|
|
34dda7bdbd | ||
|
|
49fa153581 | ||
|
|
c80b827775 | ||
|
|
a2bf9f988a | ||
|
|
ac27b2d5c2 | ||
|
|
c813518fdc | ||
|
|
d5034ed5c3 | ||
|
|
cf2c29a365 | ||
|
|
d948823db6 | ||
|
|
060ad4630d | ||
|
|
0ddceac4c0 | ||
|
|
a862cb8819 | ||
|
|
4246aed7db | ||
|
|
41554e0e0b | ||
|
|
93c4d8155e | ||
|
|
24eefd49f1 | ||
|
|
e712f1e8ef | ||
|
|
33db0fd654 | ||
|
|
478ded93de | ||
|
|
89ad1fb79d | ||
|
|
1ba40806ec | ||
|
|
73ae281e4a | ||
|
|
a35353c987 | ||
|
|
1cb91003cc | ||
|
|
d850022491 | ||
|
|
93792ab6f6 | ||
|
|
95dfe7af6a | ||
|
|
734258eb17 | ||
|
|
f3bcf96fad | ||
|
|
5cf0bc1911 | ||
|
|
d32a6b275f | ||
|
|
6caba9f8e7 | ||
|
|
641f1dbfbe | ||
|
|
58d9a104d6 | ||
|
|
7b9d24c8ef | ||
|
|
4225fdd537 | ||
|
|
9fdc91c6de | ||
|
|
93d8c85e5c | ||
|
|
929cddc3c3 | ||
|
|
e0bc63f016 | ||
|
|
b29ac306ea | ||
|
|
e8e883f4d6 | ||
|
|
3325ff1cd6 | ||
|
|
4fe14f03b4 | ||
|
|
90e2a661e4 | ||
|
|
6ed53ecb79 | ||
|
|
c18775766c | ||
|
|
4bb3a6209a | ||
|
|
0f44a547a4 | ||
|
|
1e2f6d8f14 | ||
|
|
7e5b176930 | ||
|
|
b420eab503 | ||
|
|
b370e2e14e | ||
|
|
1fabee297d | ||
|
|
484dc460c5 | ||
|
|
0cb8756124 | ||
|
|
95d0f0221b | ||
|
|
0c9c0fcd60 | ||
|
|
8be0dd133c | ||
|
|
e68e0ada0d | ||
|
|
49a7349e4d | ||
|
|
979c7241a4 | ||
|
|
e011e4a049 | ||
|
|
92bccf5974 | ||
|
|
2c1d6dcb8f | ||
|
|
75f45ec0b2 | ||
|
|
c0ebcadda9 | ||
|
|
109e9b6a5b | ||
|
|
d0c3d08e42 | ||
|
|
7514830edb | ||
|
|
6f27128b87 | ||
|
|
376518d4ef | ||
|
|
272fc85c13 | ||
|
|
579e4f93ee | ||
|
|
a9accdc3a8 | ||
|
|
b403db51d4 | ||
|
|
108cae037f | ||
|
|
c51897ab9e | ||
|
|
67171cb07a | ||
|
|
6ae3bf6ac9 | ||
|
|
b64b15877a | ||
|
|
19f52b7361 | ||
|
|
9dcd15dbc8 | ||
|
|
a423eeea3b | ||
|
|
99be6a3566 | ||
|
|
e97f730c0f | ||
|
|
f5642335ff | ||
|
|
bf0f8ec824 | ||
|
|
fb9ef4ea20 | ||
|
|
86363197cd | ||
|
|
e93187c971 | ||
|
|
1a86e13cf1 | ||
|
|
b863c1d20a | ||
|
|
4c8d658c25 | ||
|
|
69d37437ef | ||
|
|
220bdbae62 | ||
|
|
b23b556b79 | ||
|
|
ce721cf3d1 | ||
|
|
41363415fe | ||
|
|
b91d0769d5 | ||
|
|
ad16690826 | ||
|
|
ca7b81c36a | ||
|
|
a632ce1477 | ||
|
|
ca7011e9af | ||
|
|
34df432ee8 | ||
|
|
dfa7178041 | ||
|
|
a3e9a3b686 | ||
|
|
599db049f2 | ||
|
|
7cba6dd690 | ||
|
|
2d406c9d58 | ||
|
|
d8fe2b10f1 | ||
|
|
c8343626ba | ||
|
|
5b188ec093 | ||
|
|
7ebbd80049 | ||
|
|
74c9e5d36d | ||
|
|
1a3530747f | ||
|
|
79899b9b18 | ||
|
|
6ef6a2f507 | ||
|
|
ab6d15c9f7 | ||
|
|
a0dc9139a2 | ||
|
|
220fa319d5 | ||
|
|
183d505a5e | ||
|
|
f960e7e736 | ||
|
|
d68ac84e03 | ||
|
|
30fbe2b6d7 | ||
|
|
e3a00570e1 | ||
|
|
499e02685a | ||
|
|
6b0418f772 | ||
|
|
1200aae47d | ||
|
|
20fdb09b33 | ||
|
|
522b12dc42 | ||
|
|
a7cd0dcce5 | ||
|
|
fd86c11336 | ||
|
|
4fc414d744 | ||
|
|
6d49e9b06c | ||
|
|
8b866e288b | ||
|
|
bf22588b0e | ||
|
|
60d5ca2811 | ||
|
|
9e5dcdfa69 | ||
|
|
3cc39dd5ed | ||
|
|
6878060346 | ||
|
|
9840061137 | ||
|
|
6f84e00463 | ||
|
|
1e82d0d34e | ||
|
|
f35bc468b3 | ||
|
|
719071c286 | ||
|
|
c4b439e2e6 | ||
|
|
77c2b56ceb | ||
|
|
0b17b7ad5a | ||
|
|
db3011a1c9 | ||
|
|
b47c695b97 | ||
|
|
55c1c893ba | ||
|
|
bde684fe30 | ||
|
|
89b6c9004b | ||
|
|
97cdfbddaf | ||
|
|
584ee2d136 | ||
|
|
21771c4725 | ||
|
|
7e8f1bed15 | ||
|
|
226ae03603 | ||
|
|
96c494f5ee | ||
|
|
23ba00422f | ||
|
|
52675c9c68 | ||
|
|
1b113e0114 | ||
|
|
0a930f5eeb | ||
|
|
84f5a83648 | ||
|
|
5fa277c254 | ||
|
|
d49c7f2dd4 | ||
|
|
a78f1688d9 | ||
|
|
cd37a846d8 | ||
|
|
63374ccb6d | ||
|
|
efe2d91fb3 | ||
|
|
234b2a019b | ||
|
|
4bbcd366bc | ||
|
|
5724f8747a | ||
|
|
38d44103d1 | ||
|
|
96a7ff68e7 | ||
|
|
fb78a55f76 | ||
|
|
fdc7fc7bcf | ||
|
|
ed5643aaf1 | ||
|
|
ac431ef9ef | ||
|
|
0940508637 | ||
|
|
704af7d04c | ||
|
|
e4e476a834 | ||
|
|
ece35b3c6f | ||
|
|
b26eab50b3 | ||
|
|
b42313a285 | ||
|
|
129e2c1668 | ||
|
|
87ddb81562 | ||
|
|
daee49cd9d | ||
|
|
3aaf773b0a | ||
|
|
460478fc65 | ||
|
|
fe8b5f45b9 | ||
|
|
01ac646c8e | ||
|
|
d4b9fbcc60 | ||
|
|
1cfa279543 | ||
|
|
e35be73bcc | ||
|
|
f8a5c46e18 | ||
|
|
1c7d85ce76 | ||
|
|
19004b4c36 | ||
|
|
930fa689a7 | ||
|
|
18a7b2d6b4 | ||
|
|
d2e03ff9d3 | ||
|
|
77a9c8395e | ||
|
|
c4151fcb95 | ||
|
|
4c5c21bba2 | ||
|
|
f0f6f1b71c | ||
|
|
a9d6d5a1db | ||
|
|
7849ce6de7 | ||
|
|
354bdcdbfb | ||
|
|
8ecd3e88c8 | ||
|
|
85d2b627f1 | ||
|
|
88fd92e4dc | ||
|
|
952982e7ea | ||
|
|
22e7c27af7 | ||
|
|
59c18c34de | ||
|
|
6acbaede44 | ||
|
|
1a44f875b3 | ||
|
|
9d935fe1d0 | ||
|
|
e5eed5b9b7 | ||
|
|
05a549f04f | ||
|
|
a5e68a4fae | ||
|
|
016a9e342a | ||
|
|
627d8950ae | ||
|
|
770ce08c10 | ||
|
|
69ac514b3b | ||
|
|
b1481748f9 | ||
|
|
49944e323f | ||
|
|
15310db389 | ||
|
|
ea5c5a2604 | ||
|
|
e461dd1355 | ||
|
|
e299c3e9d8 | ||
|
|
406c47271f | ||
|
|
05c7efea85 | ||
|
|
ce7ddf7055 | ||
|
|
beb40b5db6 | ||
|
|
2def752cc4 | ||
|
|
bacf3ae86a | ||
|
|
0fef382f2e | ||
|
|
95523d8538 | ||
|
|
71f7220bfd | ||
|
|
2212c6deac | ||
|
|
fb3efe4cfd | ||
|
|
e66ac6a7d0 | ||
|
|
7ab3908848 | ||
|
|
921f1fbfe8 | ||
|
|
2ac455f8b5 | ||
|
|
1ce881aed2 | ||
|
|
b1b5140951 | ||
|
|
b109c23233 | ||
|
|
a7a34a0b6e | ||
|
|
4bf63934e1 | ||
|
|
16f572282f | ||
|
|
44380c3700 | ||
|
|
dc46cb1386 | ||
|
|
3ccb1e8ad7 | ||
|
|
d973c5f48b | ||
|
|
f4af78c834 | ||
|
|
e6d323fd30 | ||
|
|
e6ab56aeb5 | ||
|
|
779765b649 | ||
|
|
6da730779a | ||
|
|
a3e77edc57 | ||
|
|
ed00308986 | ||
|
|
89e9092e0f | ||
|
|
f8b11754c8 | ||
|
|
4b38d0793c | ||
|
|
b2156f8154 | ||
|
|
3a5422e635 | ||
|
|
54d3d76868 | ||
|
|
f4dc0ec1b7 | ||
|
|
f500db2dd3 | ||
|
|
95f64f9934 | ||
|
|
cccb0e1a21 | ||
|
|
b434a4227f | ||
|
|
6ba4dc1f04 | ||
|
|
2fe4c81d1e | ||
|
|
5c00264184 | ||
|
|
c744849c9b | ||
|
|
f59b278f00 | ||
|
|
b26c155d5f | ||
|
|
6da79b8745 | ||
|
|
0b92591b17 | ||
|
|
974456db54 | ||
|
|
a1326a80fe | ||
|
|
00d6946b24 | ||
|
|
c4ffde93c0 | ||
|
|
37bfe967ea | ||
|
|
9abbbfd6fb | ||
|
|
155cd08e39 | ||
|
|
e2e6bdf3bd | ||
|
|
810c42c743 | ||
|
|
99e4c1301e | ||
|
|
8c86a831fc | ||
|
|
5e976416a4 | ||
|
|
0339e14260 | ||
|
|
4b94fcebf1 | ||
|
|
ddd2a79f37 | ||
|
|
01a8f2dab3 | ||
|
|
801629d2c1 | ||
|
|
87d62c941f | ||
|
|
7e6e0fdcc5 | ||
|
|
a73b07424c | ||
|
|
0f9b983132 | ||
|
|
43e25902d3 | ||
|
|
2c27c8517f | ||
|
|
b496058a0e | ||
|
|
4313663bd1 | ||
|
|
dbdbfbd07a | ||
|
|
184b23d61f | ||
|
|
5c03b4f668 | ||
|
|
bdbe777d68 | ||
|
|
a838a18647 | ||
|
|
dd8dba63ea | ||
|
|
3f5a664ee7 | ||
|
|
707292e1ff | ||
|
|
9a81b63943 | ||
|
|
30216b7b80 | ||
|
|
b2fc91c2ce | ||
|
|
ef0328833c | ||
|
|
6a93f17a4a | ||
|
|
01bd07ac66 | ||
|
|
88859cfeca | ||
|
|
dfe563e2bc | ||
|
|
7fc0ff981d | ||
|
|
1a9132102d | ||
|
|
d39638282f | ||
|
|
219071654d | ||
|
|
7c415db7bd | ||
|
|
4354c340fc | ||
|
|
a4b484fa36 | ||
|
|
3757d12dc4 | ||
|
|
c3a97b29a9 | ||
|
|
b65e30ec70 | ||
|
|
23a1e0266a | ||
|
|
76acecfe50 | ||
|
|
5031c77afb | ||
|
|
af90b8c989 | ||
|
|
d06b4adad0 | ||
|
|
b961cde946 | ||
|
|
8cbbe2f312 | ||
|
|
c15a49d82d | ||
|
|
fc5b670c73 | ||
|
|
c8adcc4c47 | ||
|
|
41a755fe41 | ||
|
|
8def1bb29e | ||
|
|
d379b04e33 | ||
|
|
17a30e054e | ||
|
|
93809911de | ||
|
|
edeb2ca9f4 | ||
|
|
01662fc3b8 | ||
|
|
7d8f4b4c00 | ||
|
|
e2a3896bf0 | ||
|
|
446de8e0ff | ||
|
|
5ae6c95878 | ||
|
|
7cde349a50 | ||
|
|
61e640f574 | ||
|
|
ed122d9d8e | ||
|
|
34817f4536 | ||
|
|
134d2f0fda | ||
|
|
142973827c | ||
|
|
0998a0eabf | ||
|
|
a96108478b | ||
|
|
47444888c3 | ||
|
|
a4769058f4 | ||
|
|
a4cf4c40d4 | ||
|
|
934fe4d29b | ||
|
|
408012f2e5 | ||
|
|
d0078b830e | ||
|
|
f7f091e18c | ||
|
|
a969430247 | ||
|
|
e52948b2b7 | ||
|
|
53bb1b230b | ||
|
|
54e83aeaaa | ||
|
|
aa3129cab5 | ||
|
|
90520dddd7 | ||
|
|
03eb77070a | ||
|
|
4ba5c255b6 | ||
|
|
01817db873 | ||
|
|
46fcbd6c01 | ||
|
|
aa3e3de09e | ||
|
|
af3d48764d | ||
|
|
091f36b736 | ||
|
|
7107f79f42 | ||
|
|
9922db2336 | ||
|
|
75db570198 | ||
|
|
28a09f377b | ||
|
|
fd2e0855bb | ||
|
|
82e1d57bd6 | ||
|
|
a2fbb0b0c8 | ||
|
|
8feddf9932 | ||
|
|
feed34b1cf | ||
|
|
662c980cf2 | ||
|
|
f5ae530890 | ||
|
|
46bf7dd3ce | ||
|
|
5d4eb38204 | ||
|
|
66da658075 | ||
|
|
3477b74573 | ||
|
|
f3de4906b7 | ||
|
|
caded3f189 | ||
|
|
5196395495 | ||
|
|
8089a7ed9f | ||
|
|
99230d31d2 | ||
|
|
94bca03f59 | ||
|
|
49719b6e6d | ||
|
|
1bdb781452 | ||
|
|
c336f69a6b | ||
|
|
c8cb1ce208 | ||
|
|
814a6a80cd | ||
|
|
5fdfe18b32 | ||
|
|
7b7a74778b | ||
|
|
39dbd46556 | ||
|
|
1db4a14be4 | ||
|
|
4a4ea4e196 | ||
|
|
e0724441eb | ||
|
|
5d47895515 | ||
|
|
c1dfac7260 | ||
|
|
bf29cb3bae | ||
|
|
a0a9b3f851 | ||
|
|
4c4deb22c9 | ||
|
|
a42c497055 | ||
|
|
f1dcdb20bc | ||
|
|
46330ae201 | ||
|
|
bfe3595b4c | ||
|
|
34c39e6a55 | ||
|
|
5a85501919 | ||
|
|
97a4282e5e | ||
|
|
39c13b50a3 | ||
|
|
ad304e321b | ||
|
|
8c0b2da461 | ||
|
|
72fce45b2b | ||
|
|
1f49d7fda6 | ||
|
|
16b3e1381b |
8
.changeset/README.md
Normal file
8
.changeset/README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Changesets
|
||||||
|
|
||||||
|
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
||||||
|
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
||||||
|
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
||||||
|
|
||||||
|
We have a quick list of common questions to get you started engaging with this project in
|
||||||
|
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
||||||
24
.changeset/config.json
Normal file
24
.changeset/config.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
|
||||||
|
"changelog": "@changesets/cli/changelog",
|
||||||
|
"commit": false,
|
||||||
|
"fixed": [],
|
||||||
|
"linked": [
|
||||||
|
[
|
||||||
|
"cojson",
|
||||||
|
"jazz-tools",
|
||||||
|
"jazz-browser",
|
||||||
|
"jazz-browser-media-images",
|
||||||
|
"jazz-react",
|
||||||
|
"jazz-nodejs",
|
||||||
|
"jazz-run",
|
||||||
|
"cojson-transport-ws",
|
||||||
|
"cojson-storage-indexeddb",
|
||||||
|
"cojson-storage-sqlite"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"access": "public",
|
||||||
|
"baseBranch": "main",
|
||||||
|
"updateInternalDependencies": "patch",
|
||||||
|
"ignore": []
|
||||||
|
}
|
||||||
31
.github/workflows/build-and-deploy.yaml
vendored
31
.github/workflows/build-and-deploy.yaml
vendored
@@ -7,22 +7,26 @@ on:
|
|||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-examples:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
example: ["todo", "pets", "twit"]
|
example: ["chat", "pets", "todo", "inspector"]
|
||||||
|
# example: ["twit", "chat", "counter-js-auth0", "pets", "twit", "file-drop", "inspector"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
|
with:
|
||||||
|
version: 8
|
||||||
|
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: 'yarn'
|
cache: 'pnpm'
|
||||||
cache-dependency-path: yarn.lock
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
@@ -34,14 +38,10 @@ jobs:
|
|||||||
username: gardencmp
|
username: gardencmp
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Nuke Workspace
|
- name: Pnpm Build
|
||||||
run: |
|
run: |
|
||||||
rm package.json yarn.lock;
|
pnpm install
|
||||||
|
pnpm turbo build;
|
||||||
- name: Yarn Build
|
|
||||||
run: |
|
|
||||||
yarn install --frozen-lockfile;
|
|
||||||
yarn build;
|
|
||||||
working-directory: ./examples/${{ matrix.example }}
|
working-directory: ./examples/${{ matrix.example }}
|
||||||
|
|
||||||
- name: Docker Build & Push
|
- name: Docker Build & Push
|
||||||
@@ -53,12 +53,13 @@ jobs:
|
|||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
deploy:
|
deploy-examples:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
needs: build-examples
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
example: ["todo", "pets", "twit"]
|
example: ["chat", "pets", "todo", "inspector"]
|
||||||
|
# example: ["twit", "chat", "counter-js-auth0", "pets", "twit", "file-drop", "inspector"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -86,5 +87,5 @@ jobs:
|
|||||||
|
|
||||||
envsubst '${DOCKER_USER} ${DOCKER_PASSWORD} ${DOCKER_TAG} ${BRANCH_SUFFIX} ${BRANCH_SUBDOMAIN}' < job-template.nomad > job-instance.nomad;
|
envsubst '${DOCKER_USER} ${DOCKER_PASSWORD} ${DOCKER_TAG} ${BRANCH_SUFFIX} ${BRANCH_SUBDOMAIN}' < job-template.nomad > job-instance.nomad;
|
||||||
cat job-instance.nomad;
|
cat job-instance.nomad;
|
||||||
NOMAD_ADDR='http://control1v2-london:4646' nomad job run job-instance.nomad;
|
NOMAD_ADDR=${{ secrets.NOMAD_ADDR }} nomad job run job-instance.nomad;
|
||||||
working-directory: ./examples/${{ matrix.example }}
|
working-directory: ./examples/${{ matrix.example }}
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@ node_modules
|
|||||||
yarn-error.log
|
yarn-error.log
|
||||||
lerna-debug.log
|
lerna-debug.log
|
||||||
docsTmp
|
docsTmp
|
||||||
|
.DS_Store
|
||||||
|
.turbo
|
||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"typescript.tsdk": "node_modules/typescript/lib"
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Copyright 2023, Garden Computing, Inc.
|
Copyright 2024, Garden Computing, Inc.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
118
README.md
118
README.md
@@ -1,116 +1,12 @@
|
|||||||
# Jazz - instant sync
|
# Jazz - Instant sync
|
||||||
|
|
||||||
<sub>Homepage: [jazz.tools](https://jazz.tools) — Docs: [DOCS.md](./DOCS.md) — Community & support: [Discord](https://discord.gg/utDMjHYg42) — Updates: [Twitter](https://twitter.com/jazz_tools) & [Email](https://gcmp.io/news)</sub>
|
|
||||||
|
|
||||||
**Jazz is an open-source toolkit for building apps with *secure sync.***
|
|
||||||
|
|
||||||
Quickly build and ship apps with:
|
|
||||||
|
|
||||||
- **Cross-device sync**
|
|
||||||
- **Collaborative features** (incl. real-time multiplayer)
|
|
||||||
- **Instantly reacting UIs**
|
|
||||||
- Local-first storage & offline support
|
|
||||||
- File upload and real-time media streaming
|
|
||||||
|
|
||||||
# What is *secure sync*?
|
|
||||||
|
|
||||||
**Sync** means that, *instead of making API requests*, you:
|
|
||||||
|
|
||||||
- **Read and write data as if it was local** — from anywhere in your app.
|
|
||||||
- **Always have data synced to wherever it's needed, instantly:** to other devices of the same user, to other users, to your backend, to your local machine for debugging, etc.
|
|
||||||
|
|
||||||
**Secure** means that, *instead of relying on your API or DB for access control*, you:
|
|
||||||
|
|
||||||
- **Set fine-grained, role-based permissions in `Group`s** that are **synced along with your data**.
|
|
||||||
- **Permissions *verifiably enforced* everywhere,** using encryption & signatures under the hood.
|
|
||||||
- **Change roles dynamically** for evolving teams, expiring invite links and more.
|
|
||||||
|
|
||||||
# What's special about Jazz?
|
|
||||||
|
|
||||||
Compared to other libraries and frameworks for local-first, sync-based or real-time apps, these are some of the things that make Jazz unique:
|
|
||||||
|
|
||||||
- **Jazz is a *batteries-included,* vertically integrated toolkit,** offering everything you need to build an app, including auth, permissions, data model, sync, conflict resolution, blob storage, file uploads, real-time media streaming and more.
|
|
||||||
- **Jazz has a *small API surface* of only a few abstractions to learn,** which combine in powerful ways to implement a broad set of features.
|
|
||||||
- **Jazz *granularly* loads and caches *only the data that is needed*,** combining *local-first* instant UI reactivity and offline support with the on-demand data efficiency of conventional APIs
|
|
||||||
- **Jazz supports end-to-end encryption, but doesn't require it,** allowing you to either manage your user's secret keys for them (based on existing auth flows) or letting your users
|
|
||||||
- **Jazz is based on CoJSON, a soon-to-be *open standard,*** which means that there will be a whole ecosystem of compatible libraries and frameworks in a variety of environments — and it will be easy to achieve (secure) interop between Jazz/CoJSON-based apps and services.
|
|
||||||
|
|
||||||
# Jazz Global Mesh
|
|
||||||
|
|
||||||
Jazz is open source and you can run your own sync & storage server, but to really provide you with everything you need, we're also running
|
|
||||||
**[Jazz Global Mesh](https://jazz.tools/mesh)**, a globally distributed mesh of servers optimized for:
|
|
||||||
|
|
||||||
- **Ultra-low-latency sync** (with geo-aware edge caching and optimal routing)
|
|
||||||
- **Low-cost, reliable storage**
|
|
||||||
|
|
||||||
|
|
||||||
**Jazz Global Mesh is free for small volumes of data** and it's the **default syncing peer,** so you can **start building multi-user Jazz apps with persistent data in minutes,** using only frontend code!
|
|
||||||
|
|
||||||
# Getting started
|
**Jazz is an open-source toolkit for building apps with *distributed state.***
|
||||||
|
|
||||||
## Example App Walkthrough
|
- Homepage: [jazz.tools](https://jazz.tools)
|
||||||
|
- Docs: [jazz.tools/docs](https://jazz.tools/docs)
|
||||||
|
- Community & support: [Discord](https://discord.gg/utDMjHYg42)
|
||||||
|
- Updates: [Twitter](https://twitter.com/jazz_tools) & [Email](https://gcmp.io/news)
|
||||||
|
|
||||||
**For now the best tutorial is the walkthrough of the [Todo List Example App](#todo-list).**
|
Copyright 2024 — Garden Computing, Inc.
|
||||||
|
|
||||||
## General Scenarios
|
|
||||||
|
|
||||||
### Building a new, entirely sync-based React app
|
|
||||||
|
|
||||||
1. Define your data model with [cojson Collaborative Values (CoValues)](./DOCS.md#covalue).
|
|
||||||
2. Implement permission logic using [cojson Groups](./DOCS.md#group).
|
|
||||||
3. Build a user interface with [jazz-react](./DOCS.md#jazz-react) and [auto-sub](./DOCS.md#useautosubid).
|
|
||||||
|
|
||||||
### Gradually adding sync to an existing React app
|
|
||||||
|
|
||||||
Gradually migrate app features to use sync:
|
|
||||||
|
|
||||||
1. Define data model for small aspect of your app with [cojson Collaborative Values (CoValues)](./DOCS.md#covalue).
|
|
||||||
- Schema adapters/importers for Prisma/Drizzle/PostgreSQL introspection coming soon.
|
|
||||||
2. Map existing permission logic with [cojson Groups](./DOCS.md#group) & integrate existing auth.
|
|
||||||
- Auth integrations coming soon.
|
|
||||||
3. Replace some of the React state and API requests in your UI with [jazz-react](./DOCS.md#jazz-react) and [auto-sub](./DOCS.md#useautosubid).
|
|
||||||
|
|
||||||
# Example Apps
|
|
||||||
|
|
||||||
## Todo List
|
|
||||||
|
|
||||||
**A simple collaborative todo list app.**
|
|
||||||
|
|
||||||
Live version: https://example-todo.jazz.tools
|
|
||||||
|
|
||||||
Source code & walkthrough: [`./examples/todo`](./examples/todo)
|
|
||||||
|
|
||||||
Demonstrates:
|
|
||||||
- Defining a data model with `CoMap`s and `CoList`s
|
|
||||||
- Creating data and setting permissions with `Group`s
|
|
||||||
- Fetching, rendering & editing data from nested `CoValue`s with reactive synced queries
|
|
||||||
|
|
||||||
|
|
||||||
## Rate-My-Pet
|
|
||||||
|
|
||||||
**A simple social polling app.**
|
|
||||||
|
|
||||||
Live version: https://example-pets.jazz.tools
|
|
||||||
|
|
||||||
Source code (walkthrough coming soon): [`./examples/pets`](./examples/pets)
|
|
||||||
|
|
||||||
Demonstrates:
|
|
||||||
- Implementing per-account data streams (reactions) with `CoStream`s
|
|
||||||
- Implementing image upload and progressive image streaming using helpers from `jazz-react-media-images` (on top of CoJSON's `BinaryCoStreams` & `ImageDefinition` convention)
|
|
||||||
|
|
||||||
|
|
||||||
# Documentation & API Reference
|
|
||||||
|
|
||||||
For now, docs are hosted in a single well-structured markdown file: [`./DOCS.md`](./DOCS.md).
|
|
||||||
|
|
||||||
- [Package Overview](./DOCS.md#overview)
|
|
||||||
- [`jazz-react` API](./DOCS.md#jazz-react)
|
|
||||||
- [`cojson` API](./DOCS.md#cojson)
|
|
||||||
- [`jazz-browser-media-images` API](./DOCS.md#jazz-browser-media-images)
|
|
||||||
|
|
||||||
|
|
||||||
In the future we'll build a dedicated docs page on the Jazz homepage.
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
Copyright 2023 — Garden Computing, Inc.
|
|
||||||
13
examples/chat/.eslintrc.cjs
Normal file
13
examples/chat/.eslintrc.cjs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
env: { browser: true, es2020: true },
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'plugin:react-hooks/recommended',
|
||||||
|
],
|
||||||
|
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: ['react-refresh'],
|
||||||
|
rules: {},
|
||||||
|
}
|
||||||
674
examples/chat/CHANGELOG.md
Normal file
674
examples/chat/CHANGELOG.md
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
# jazz-example-chat
|
||||||
|
|
||||||
|
## 0.0.75
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.28
|
||||||
|
- jazz-react@0.7.28
|
||||||
|
- jazz-tools@0.7.28
|
||||||
|
|
||||||
|
## 0.0.74
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.27
|
||||||
|
|
||||||
|
## 0.0.73
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.26
|
||||||
|
- jazz-react@0.7.26
|
||||||
|
- jazz-tools@0.7.26
|
||||||
|
|
||||||
|
## 0.0.72
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.25
|
||||||
|
- jazz-react@0.7.25
|
||||||
|
|
||||||
|
## 0.0.71
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.24
|
||||||
|
- jazz-react@0.7.24
|
||||||
|
|
||||||
|
## 0.0.70
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.23
|
||||||
|
- jazz-react@0.7.23
|
||||||
|
- jazz-tools@0.7.23
|
||||||
|
|
||||||
|
## 0.0.69
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.22
|
||||||
|
|
||||||
|
## 0.0.68
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.21
|
||||||
|
- jazz-react@0.7.21
|
||||||
|
|
||||||
|
## 0.0.67
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.20
|
||||||
|
- jazz-react@0.7.20
|
||||||
|
|
||||||
|
## 0.0.66
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.19
|
||||||
|
- jazz-react@0.7.19
|
||||||
|
|
||||||
|
## 0.0.65
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.18
|
||||||
|
- jazz-react@0.7.18
|
||||||
|
- jazz-tools@0.7.18
|
||||||
|
|
||||||
|
## 0.0.64
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.17
|
||||||
|
- jazz-react@0.7.17
|
||||||
|
- jazz-tools@0.7.17
|
||||||
|
|
||||||
|
## 0.0.63
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.16
|
||||||
|
- jazz-react@0.7.16
|
||||||
|
|
||||||
|
## 0.0.62
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.15
|
||||||
|
|
||||||
|
## 0.0.61
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.14
|
||||||
|
- jazz-tools@0.7.14
|
||||||
|
- jazz-react@0.7.14
|
||||||
|
|
||||||
|
## 0.0.60
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.13
|
||||||
|
- jazz-react@0.7.13
|
||||||
|
|
||||||
|
## 0.0.59
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.12
|
||||||
|
- jazz-react@0.7.12
|
||||||
|
|
||||||
|
## 0.0.58
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.11
|
||||||
|
- jazz-react@0.7.11
|
||||||
|
- jazz-tools@0.7.11
|
||||||
|
|
||||||
|
## 0.0.57
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.10
|
||||||
|
- jazz-react@0.7.10
|
||||||
|
- jazz-tools@0.7.10
|
||||||
|
|
||||||
|
## 0.0.56
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.9
|
||||||
|
- jazz-react@0.7.9
|
||||||
|
- jazz-tools@0.7.9
|
||||||
|
|
||||||
|
## 0.0.55
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.8
|
||||||
|
- jazz-react@0.7.8
|
||||||
|
|
||||||
|
## 0.0.54
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [9fdc91c]
|
||||||
|
- jazz-react@0.7.7
|
||||||
|
|
||||||
|
## 0.0.53
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.6
|
||||||
|
- jazz-react@0.7.6
|
||||||
|
|
||||||
|
## 0.0.52
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.5
|
||||||
|
|
||||||
|
## 0.0.51
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.4
|
||||||
|
|
||||||
|
## 0.0.50
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.3
|
||||||
|
- jazz-react@0.7.3
|
||||||
|
|
||||||
|
## 0.0.49
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.2
|
||||||
|
|
||||||
|
## 0.0.48
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.1
|
||||||
|
- jazz-react@0.7.1
|
||||||
|
|
||||||
|
## 0.0.47
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [96c494f]
|
||||||
|
- Updated dependencies [59c18c3]
|
||||||
|
- Updated dependencies [19f52b7]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [d8fe2b1]
|
||||||
|
- Updated dependencies [19004b4]
|
||||||
|
- Updated dependencies [a78f168]
|
||||||
|
- Updated dependencies [1200aae]
|
||||||
|
- Updated dependencies [60d5ca2]
|
||||||
|
- Updated dependencies [52675c9]
|
||||||
|
- Updated dependencies [129e2c1]
|
||||||
|
- Updated dependencies [6d49e9b]
|
||||||
|
- Updated dependencies [1cfa279]
|
||||||
|
- Updated dependencies [704af7d]
|
||||||
|
- Updated dependencies [e97f730]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [460478f]
|
||||||
|
- Updated dependencies [6b0418f]
|
||||||
|
- Updated dependencies [e299c3e]
|
||||||
|
- Updated dependencies [ed5643a]
|
||||||
|
- Updated dependencies [bde684f]
|
||||||
|
- Updated dependencies [bf0f8ec]
|
||||||
|
- Updated dependencies [c4151fc]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [01ac646]
|
||||||
|
- Updated dependencies [a5e68a4]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [952982e]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [5fa277c]
|
||||||
|
- Updated dependencies [60d5ca2]
|
||||||
|
- Updated dependencies [21771c4]
|
||||||
|
- Updated dependencies [77c2b56]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [d2e03ff]
|
||||||
|
- Updated dependencies [354bdcd]
|
||||||
|
- Updated dependencies [ece35b3]
|
||||||
|
- Updated dependencies [60d5ca2]
|
||||||
|
- Updated dependencies [69ac514]
|
||||||
|
- Updated dependencies [f8a5c46]
|
||||||
|
- Updated dependencies [f0f6f1b]
|
||||||
|
- Updated dependencies [e5eed5b]
|
||||||
|
- Updated dependencies [1a44f87]
|
||||||
|
- Updated dependencies [627d895]
|
||||||
|
- Updated dependencies [1200aae]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [ece35b3]
|
||||||
|
- Updated dependencies [38d4410]
|
||||||
|
- Updated dependencies [85d2b62]
|
||||||
|
- Updated dependencies [fd86c11]
|
||||||
|
- Updated dependencies [52675c9]
|
||||||
|
- jazz-tools@0.7.0
|
||||||
|
- cojson@0.7.0
|
||||||
|
- jazz-react@0.7.0
|
||||||
|
- hash-slash@0.2.0
|
||||||
|
|
||||||
|
## 0.0.47-alpha.42
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.42
|
||||||
|
- cojson@0.7.0-alpha.42
|
||||||
|
- jazz-react@0.7.0-alpha.42
|
||||||
|
|
||||||
|
## 0.0.47-alpha.41
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-tools@0.7.0-alpha.41
|
||||||
|
- jazz-react@0.7.0-alpha.41
|
||||||
|
|
||||||
|
## 0.0.47-alpha.40
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.40
|
||||||
|
|
||||||
|
## 0.0.47-alpha.39
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.0-alpha.39
|
||||||
|
- jazz-react@0.7.0-alpha.39
|
||||||
|
- jazz-tools@0.7.0-alpha.39
|
||||||
|
|
||||||
|
## 0.0.47-alpha.38
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.38
|
||||||
|
- jazz-react@0.7.0-alpha.38
|
||||||
|
- cojson@0.7.0-alpha.38
|
||||||
|
|
||||||
|
## 0.0.47-alpha.37
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.37
|
||||||
|
- cojson@0.7.0-alpha.37
|
||||||
|
- jazz-tools@0.7.0-alpha.37
|
||||||
|
|
||||||
|
## 0.0.47-alpha.36
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [6b0418f]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- cojson@0.7.0-alpha.36
|
||||||
|
- jazz-tools@0.7.0-alpha.36
|
||||||
|
- jazz-react@0.7.0-alpha.36
|
||||||
|
|
||||||
|
## 0.0.47-alpha.35
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.0-alpha.35
|
||||||
|
- jazz-tools@0.7.0-alpha.35
|
||||||
|
- jazz-react@0.7.0-alpha.35
|
||||||
|
|
||||||
|
## 0.0.47-alpha.34
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.34
|
||||||
|
- jazz-react@0.7.0-alpha.34
|
||||||
|
|
||||||
|
## 0.0.47-alpha.33
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.33
|
||||||
|
|
||||||
|
## 0.0.47-alpha.32
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- hash-slash@0.2.0-alpha.3
|
||||||
|
- jazz-tools@0.7.0-alpha.32
|
||||||
|
- jazz-react@0.7.0-alpha.32
|
||||||
|
|
||||||
|
## 0.0.47-alpha.31
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.31
|
||||||
|
- jazz-react@0.7.0-alpha.31
|
||||||
|
|
||||||
|
## 0.0.47-alpha.30
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.30
|
||||||
|
- jazz-react@0.7.0-alpha.30
|
||||||
|
|
||||||
|
## 0.0.47-alpha.29
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.29
|
||||||
|
- cojson@0.7.0-alpha.29
|
||||||
|
- jazz-react@0.7.0-alpha.29
|
||||||
|
|
||||||
|
## 0.0.47-alpha.28
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.28
|
||||||
|
- cojson@0.7.0-alpha.28
|
||||||
|
- jazz-react@0.7.0-alpha.28
|
||||||
|
|
||||||
|
## 0.0.47-alpha.27
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.27
|
||||||
|
- cojson@0.7.0-alpha.27
|
||||||
|
- jazz-react@0.7.0-alpha.27
|
||||||
|
|
||||||
|
## 0.0.47-alpha.26
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.26
|
||||||
|
- jazz-react@0.7.0-alpha.26
|
||||||
|
|
||||||
|
## 0.0.47-alpha.25
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.25
|
||||||
|
- jazz-react@0.7.0-alpha.25
|
||||||
|
|
||||||
|
## 0.0.47-alpha.24
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.24
|
||||||
|
- cojson@0.7.0-alpha.24
|
||||||
|
- jazz-react@0.7.0-alpha.24
|
||||||
|
|
||||||
|
## 0.0.47-alpha.23
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.23
|
||||||
|
- jazz-react@0.7.0-alpha.23
|
||||||
|
|
||||||
|
## 0.0.47-alpha.22
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.22
|
||||||
|
- jazz-react@0.7.0-alpha.22
|
||||||
|
|
||||||
|
## 0.0.47-alpha.21
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.21
|
||||||
|
- jazz-tools@0.7.0-alpha.21
|
||||||
|
|
||||||
|
## 0.0.47-alpha.20
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.20
|
||||||
|
- jazz-tools@0.7.0-alpha.20
|
||||||
|
|
||||||
|
## 0.0.47-alpha.19
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.19
|
||||||
|
- jazz-react@0.7.0-alpha.19
|
||||||
|
|
||||||
|
## 0.0.47-alpha.18
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.0-alpha.18
|
||||||
|
|
||||||
|
## 0.0.47-alpha.17
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.17
|
||||||
|
- jazz-react@0.7.0-alpha.17
|
||||||
|
|
||||||
|
## 0.0.47-alpha.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.16
|
||||||
|
- jazz-react@0.7.0-alpha.16
|
||||||
|
|
||||||
|
## 0.0.47-alpha.15
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.15
|
||||||
|
- jazz-react@0.7.0-alpha.15
|
||||||
|
|
||||||
|
## 0.0.47-alpha.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.14
|
||||||
|
- jazz-react@0.7.0-alpha.14
|
||||||
|
|
||||||
|
## 0.0.47-alpha.13
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.13
|
||||||
|
- jazz-react@0.7.0-alpha.13
|
||||||
|
|
||||||
|
## 0.0.47-alpha.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.12
|
||||||
|
- jazz-tools@0.7.0-alpha.12
|
||||||
|
|
||||||
|
## 0.0.47-alpha.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.11
|
||||||
|
- jazz-tools@0.7.0-alpha.11
|
||||||
|
- cojson@0.7.0-alpha.11
|
||||||
|
|
||||||
|
## 0.0.47-alpha.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.10
|
||||||
|
- jazz-tools@0.7.0-alpha.10
|
||||||
|
- cojson@0.7.0-alpha.10
|
||||||
|
|
||||||
|
## 0.0.47-alpha.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.9
|
||||||
|
- jazz-tools@0.7.0-alpha.9
|
||||||
|
|
||||||
|
## 0.0.47-alpha.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.8
|
||||||
|
- jazz-tools@0.7.0-alpha.8
|
||||||
|
|
||||||
|
## 0.0.47-alpha.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.7
|
||||||
|
- jazz-tools@0.7.0-alpha.7
|
||||||
|
- cojson@0.7.0-alpha.7
|
||||||
|
|
||||||
|
## 0.0.47-alpha.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.6
|
||||||
|
- jazz-tools@0.7.0-alpha.6
|
||||||
|
|
||||||
|
## 0.0.47-alpha.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.5
|
||||||
|
- jazz-tools@0.7.0-alpha.5
|
||||||
|
- cojson@0.7.0-alpha.5
|
||||||
|
|
||||||
|
## 0.0.47-alpha.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.4
|
||||||
|
- jazz-react@0.7.0-alpha.4
|
||||||
|
|
||||||
|
## 0.0.47-alpha.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.3
|
||||||
|
- jazz-react@0.7.0-alpha.3
|
||||||
|
|
||||||
|
## 0.0.47-alpha.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- hash-slash@0.2.0-alpha.2
|
||||||
|
- jazz-react@0.7.0-alpha.2
|
||||||
|
- jazz-tools@0.7.0-alpha.2
|
||||||
|
|
||||||
|
## 0.0.47-alpha.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- hash-slash@0.2.0-alpha.1
|
||||||
|
- jazz-react@0.7.0-alpha.1
|
||||||
|
- jazz-tools@0.7.0-alpha.1
|
||||||
|
- cojson@0.7.0-alpha.1
|
||||||
|
|
||||||
|
## 0.0.47-alpha.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- hash-slash@0.2.0-alpha.0
|
||||||
|
- jazz-react@0.7.0-alpha.0
|
||||||
|
- jazz-tools@0.7.0-alpha.0
|
||||||
|
- cojson@0.7.0-alpha.0
|
||||||
|
|
||||||
|
## 0.0.46
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.5.0
|
||||||
|
- jazz-react-auth-local@0.4.16
|
||||||
42
examples/chat/README.md
Normal file
42
examples/chat/README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Jazz Chat Example
|
||||||
|
|
||||||
|
Live version: https://example-chat.jazz.tools
|
||||||
|
|
||||||
|
## Installing & running the example locally
|
||||||
|
|
||||||
|
(this requires `pnpm` to be installed, see [https://pnpm.io/installation](https://pnpm.io/installation))
|
||||||
|
|
||||||
|
Start by checking out `jazz`
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/gardencmp/jazz.git
|
||||||
|
cd jazz/examples/chat
|
||||||
|
pnpm pack --pack-destination /tmp
|
||||||
|
mkdir -p ~/jazz-examples/chat # or any other directory
|
||||||
|
tar -xf /tmp/jazz-example-chat-* --strip-components 1 -C ~/jazz-examples/chat
|
||||||
|
cd ~/jazz-examples/chat
|
||||||
|
```
|
||||||
|
|
||||||
|
This ensures that you have the example app without git history and independent of the Jazz multi-package monorepo.
|
||||||
|
|
||||||
|
Install dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install
|
||||||
|
```
|
||||||
|
|
||||||
|
Start the dev server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Questions / problems / feedback
|
||||||
|
|
||||||
|
If you have feedback, let us know on [Discord](https://discord.gg/utDMjHYg42) or open an issue or PR to fix something that seems wrong.
|
||||||
|
|
||||||
|
|
||||||
|
## Configuration: sync server
|
||||||
|
|
||||||
|
By default, the example app uses [Jazz Global Mesh](https://jazz.tools/mesh) (`wss://sync.jazz.tools`) - so cross-device use, invites and collaboration should just work.
|
||||||
|
|
||||||
|
You can also run a local sync server by running `npx cojson-simple-sync` and adding the query param `?sync=ws://localhost:4200` to the URL of the example app (for example: `http://localhost:5173/?sync=ws://localhost:4200`), or by setting the `sync` parameter of the `<Jazz.Provider>` provider component in [./src/2_main.tsx](./src/2_main.tsx).
|
||||||
14
examples/chat/index.html
Normal file
14
examples/chat/index.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/png" href="/jazz-logo.png" />
|
||||||
|
<link rel="stylesheet" href="/src/index.css" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Jazz Chat Example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/app.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
56
examples/chat/job-template.nomad
Normal file
56
examples/chat/job-template.nomad
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
job "chat$BRANCH_SUFFIX" {
|
||||||
|
region = "global"
|
||||||
|
datacenters = ["*"]
|
||||||
|
|
||||||
|
group "static" {
|
||||||
|
count = 4
|
||||||
|
|
||||||
|
network {
|
||||||
|
port "http" {
|
||||||
|
to = 80
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constraint {
|
||||||
|
attribute = "${node.class}"
|
||||||
|
operator = "="
|
||||||
|
value = "mesh"
|
||||||
|
}
|
||||||
|
|
||||||
|
spread {
|
||||||
|
attribute = "${node.datacenter}"
|
||||||
|
weight = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
constraint {
|
||||||
|
distinct_hosts = true
|
||||||
|
}
|
||||||
|
|
||||||
|
task "server" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "$DOCKER_TAG"
|
||||||
|
ports = ["http"]
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
username = "$DOCKER_USER"
|
||||||
|
password = "$DOCKER_PASSWORD"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
tags = ["public"]
|
||||||
|
name = "chat$BRANCH_SUFFIX"
|
||||||
|
port = "http"
|
||||||
|
provider = "consul"
|
||||||
|
}
|
||||||
|
|
||||||
|
resources {
|
||||||
|
cpu = 50 # MHz
|
||||||
|
memory = 50 # MB
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# deploy bump 4
|
||||||
54
examples/chat/package.json
Normal file
54
examples/chat/package.json
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"name": "jazz-example-chat",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.75",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc && vite build",
|
||||||
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
|
"format": "echo 'chat example is codegolfed'",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{ts,tsx}": "eslint --fix",
|
||||||
|
"*.{js,jsx,mdx,json}": "prettier --write"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/react-checkbox": "^1.0.4",
|
||||||
|
"@radix-ui/react-slot": "^1.0.2",
|
||||||
|
"@radix-ui/react-toast": "^1.1.4",
|
||||||
|
"@types/qrcode": "^1.5.1",
|
||||||
|
"class-variance-authority": "^0.7.0",
|
||||||
|
"clsx": "^2.0.0",
|
||||||
|
"hash-slash": "workspace:*",
|
||||||
|
"jazz-tools": "workspace:*",
|
||||||
|
"jazz-react": "workspace:*",
|
||||||
|
"cojson": "workspace:*",
|
||||||
|
"lucide-react": "^0.274.0",
|
||||||
|
"qrcode": "^1.5.3",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0",
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^18.2.15",
|
||||||
|
"@types/react-dom": "^18.2.7",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||||
|
"@typescript-eslint/parser": "^6.0.0",
|
||||||
|
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||||
|
"autoprefixer": "^10.4.14",
|
||||||
|
"eslint": "^8.45.0",
|
||||||
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.3",
|
||||||
|
"postcss": "^8.4.27",
|
||||||
|
"tailwindcss": "^3.3.3",
|
||||||
|
"typescript": "^5.0.2",
|
||||||
|
"vite": "^5.0.10"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
43
examples/chat/src/app.tsx
Normal file
43
examples/chat/src/app.tsx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { CoMap, CoList, co, Group, ID } from "jazz-tools";
|
||||||
|
import { createJazzReactContext, DemoAuth } from "jazz-react";
|
||||||
|
import { createRoot } from "react-dom/client";
|
||||||
|
import { useIframeHashRouter } from "hash-slash";
|
||||||
|
import { ChatScreen } from "./chatScreen.tsx";
|
||||||
|
import { StrictMode } from "react";
|
||||||
|
|
||||||
|
export class Message extends CoMap {
|
||||||
|
text = co.string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Chat extends CoList.Of(co.ref(Message)) {}
|
||||||
|
|
||||||
|
const Jazz = createJazzReactContext({
|
||||||
|
auth: DemoAuth({ appName: "Jazz Chat" }),
|
||||||
|
peer: `wss://mesh.jazz.tools/?key=you@example.com`
|
||||||
|
});
|
||||||
|
export const { useAccount, useCoState } = Jazz;
|
||||||
|
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const { me, logOut } = useAccount();
|
||||||
|
|
||||||
|
const createChat = () => {
|
||||||
|
const group = Group.create({ owner: me });
|
||||||
|
group.addMember("everyone", "writer");
|
||||||
|
const chat = Chat.create([], { owner: group });
|
||||||
|
location.hash = "/chat/" + chat.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
return <div className="flex flex-col items-center justify-between w-screen h-screen p-2 dark:bg-black dark:text-white">
|
||||||
|
<div className="rounded mb-5 px-2 py-1 text-sm self-end">
|
||||||
|
{me.profile?.name} · <button onClick={logOut}>Log Out</button>
|
||||||
|
</div>
|
||||||
|
{useIframeHashRouter().route({
|
||||||
|
'/': () => createChat() as never,
|
||||||
|
'/chat/:id': (id) => <ChatScreen chatID={id as ID<Chat>} />
|
||||||
|
})}
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
createRoot(document.getElementById("root")!)
|
||||||
|
.render(<StrictMode><Jazz.Provider><App/></Jazz.Provider></StrictMode>);
|
||||||
42
examples/chat/src/chatScreen.tsx
Normal file
42
examples/chat/src/chatScreen.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { ID } from 'jazz-tools';
|
||||||
|
import { Chat, Message, useCoState } from './app.tsx';
|
||||||
|
|
||||||
|
export function ChatScreen(props: { chatID: ID<Chat> }) {
|
||||||
|
const chat = useCoState(Chat, props.chatID, [{}]);
|
||||||
|
|
||||||
|
return chat ? <div className='w-full max-w-xl h-full flex flex-col items-stretch'>
|
||||||
|
{chat.length > 0
|
||||||
|
? chat.map((msg) => <ChatBubble msg={msg} key={msg.id} />)
|
||||||
|
: <div className='m-auto text-sm'>(Empty chat)</div>}
|
||||||
|
<ChatInput onSubmit={(text) => {
|
||||||
|
chat.push(
|
||||||
|
Message.create({ text }, { owner: chat._owner })
|
||||||
|
);
|
||||||
|
}} />
|
||||||
|
</div> : <div>Loading...</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChatBubble(props: { msg: Message }) {
|
||||||
|
const lastEdit = props.msg._edits.text;
|
||||||
|
const align = lastEdit.by?.isMe ? 'items-end' : 'items-start';
|
||||||
|
|
||||||
|
return <div className={`${align} flex flex-col`}>
|
||||||
|
<div className='rounded-xl bg-stone-100 dark:bg-stone-700 dark:text-white py-2 px-4 mt-2 min-w-[5rem]'>
|
||||||
|
{ props.msg.text }
|
||||||
|
</div>
|
||||||
|
<div className='text-xs text-neutral-500 ml-2'>
|
||||||
|
{ lastEdit.by?.profile?.name }{' '}
|
||||||
|
{ lastEdit.madeAt?.toLocaleTimeString() }
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChatInput(props: { onSubmit: (text: string) => void }) {
|
||||||
|
return <input className='rounded p-2 border mt-auto dark:bg-black dark:text-white border-stone-300 dark:border-stone-700'
|
||||||
|
placeholder='Type a message and press Enter'
|
||||||
|
onKeyDown={({ key, currentTarget: input }) => {
|
||||||
|
if (key !== 'Enter' || !input.value) return;
|
||||||
|
props.onSubmit(input.value);
|
||||||
|
input.value = '';
|
||||||
|
}} />;
|
||||||
|
}
|
||||||
78
examples/chat/src/index.css
Normal file
78
examples/chat/src/index.css
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
75
examples/chat/tailwind.config.js
Normal file
75
examples/chat/tailwind.config.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: [
|
||||||
|
'./pages/**/*.{ts,tsx}',
|
||||||
|
'./components/**/*.{ts,tsx}',
|
||||||
|
'./app/**/*.{ts,tsx}',
|
||||||
|
'./src/**/*.{ts,tsx}',
|
||||||
|
],
|
||||||
|
theme: {
|
||||||
|
container: {
|
||||||
|
center: true,
|
||||||
|
padding: "2rem",
|
||||||
|
screens: {
|
||||||
|
"2xl": "1400px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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))",
|
||||||
|
},
|
||||||
|
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: [require("tailwindcss-animate")],
|
||||||
|
}
|
||||||
24
examples/inspector/.gitignore
vendored
Normal file
24
examples/inspector/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
72
examples/inspector/CHANGELOG.md
Normal file
72
examples/inspector/CHANGELOG.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# jazz-example-chat
|
||||||
|
|
||||||
|
## 0.0.54
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.28
|
||||||
|
- cojson-transport-ws@0.7.28
|
||||||
|
|
||||||
|
## 0.0.53
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson-transport-ws@0.7.27
|
||||||
|
|
||||||
|
## 0.0.52
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.26
|
||||||
|
- cojson-transport-ws@0.7.26
|
||||||
|
|
||||||
|
## 0.0.51
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.23
|
||||||
|
- cojson-transport-ws@0.7.23
|
||||||
|
|
||||||
|
## 0.0.50
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson-transport-ws@0.7.22
|
||||||
|
|
||||||
|
## 0.0.49
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.18
|
||||||
|
- cojson-transport-ws@0.7.18
|
||||||
|
|
||||||
|
## 0.0.48
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.7.17
|
||||||
|
- cojson-transport-ws@0.7.17
|
||||||
|
|
||||||
|
## 0.0.47
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- cojson@0.6.7
|
||||||
|
- jazz-react@0.5.5
|
||||||
|
- jazz-react-auth-local@0.4.18
|
||||||
|
|
||||||
|
## 0.0.46
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.5.0
|
||||||
|
- jazz-react-auth-local@0.4.16
|
||||||
4
examples/inspector/Dockerfile
Normal file
4
examples/inspector/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FROM caddy:2.7.3-alpine
|
||||||
|
LABEL org.opencontainers.image.source="https://github.com/gardencmp/jazz"
|
||||||
|
|
||||||
|
COPY ./dist /usr/share/caddy/
|
||||||
42
examples/inspector/README.md
Normal file
42
examples/inspector/README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Jazz Chat Example
|
||||||
|
|
||||||
|
Live version: https://example-chat.jazz.tools
|
||||||
|
|
||||||
|
## Installing & running the example locally
|
||||||
|
|
||||||
|
(this requires `pnpm` to be installed, see [https://pnpm.io/installation](https://pnpm.io/installation))
|
||||||
|
|
||||||
|
Start by checking out `jazz`
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/gardencmp/jazz.git
|
||||||
|
cd jazz/examples/chat
|
||||||
|
pnpm pack --pack-destination /tmp
|
||||||
|
mkdir -p ~/jazz-examples/chat # or any other directory
|
||||||
|
tar -xf /tmp/jazz-example-chat-* --strip-components 1 -C ~/jazz-examples/chat
|
||||||
|
cd ~/jazz-examples/chat
|
||||||
|
```
|
||||||
|
|
||||||
|
This ensures that you have the example app without git history and independent of the Jazz multi-package monorepo.
|
||||||
|
|
||||||
|
Install dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install
|
||||||
|
```
|
||||||
|
|
||||||
|
Start the dev server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Questions / problems / feedback
|
||||||
|
|
||||||
|
If you have feedback, let us know on [Discord](https://discord.gg/utDMjHYg42) or open an issue or PR to fix something that seems wrong.
|
||||||
|
|
||||||
|
|
||||||
|
## Configuration: sync server
|
||||||
|
|
||||||
|
By default, the example app uses [Jazz Global Mesh](https://jazz.tools/mesh) (`wss://sync.jazz.tools`) - so cross-device use, invites and collaboration should just work.
|
||||||
|
|
||||||
|
You can also run a local sync server by running `npx cojson-simple-sync` and adding the query param `?sync=ws://localhost:4200` to the URL of the example app (for example: `http://localhost:5173/?sync=ws://localhost:4200`), or by setting the `sync` parameter of the `<WithJazz>` provider component in [./src/2_main.tsx](./src/2_main.tsx).
|
||||||
17
examples/inspector/index.html
Normal file
17
examples/inspector/index.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/png" href="/jazz-logo.png" />
|
||||||
|
<link rel="stylesheet" href="/src/index.css" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Jazz Inspector</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/app.tsx"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
56
examples/inspector/job-template.nomad
Normal file
56
examples/inspector/job-template.nomad
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
job "inspector$BRANCH_SUFFIX" {
|
||||||
|
region = "global"
|
||||||
|
datacenters = ["*"]
|
||||||
|
|
||||||
|
group "static" {
|
||||||
|
count = 4
|
||||||
|
|
||||||
|
network {
|
||||||
|
port "http" {
|
||||||
|
to = 80
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constraint {
|
||||||
|
attribute = "${node.class}"
|
||||||
|
operator = "="
|
||||||
|
value = "mesh"
|
||||||
|
}
|
||||||
|
|
||||||
|
spread {
|
||||||
|
attribute = "${node.datacenter}"
|
||||||
|
weight = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
constraint {
|
||||||
|
distinct_hosts = true
|
||||||
|
}
|
||||||
|
|
||||||
|
task "server" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "$DOCKER_TAG"
|
||||||
|
ports = ["http"]
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
username = "$DOCKER_USER"
|
||||||
|
password = "$DOCKER_PASSWORD"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
tags = ["public"]
|
||||||
|
name = "inspector$BRANCH_SUFFIX"
|
||||||
|
port = "http"
|
||||||
|
provider = "consul"
|
||||||
|
}
|
||||||
|
|
||||||
|
resources {
|
||||||
|
cpu = 50 # MHz
|
||||||
|
memory = 50 # MB
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# deploy bump 4
|
||||||
48
examples/inspector/package.json
Normal file
48
examples/inspector/package.json
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"name": "jazz-inspector",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.54",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc && vite build",
|
||||||
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/react-checkbox": "^1.0.4",
|
||||||
|
"@radix-ui/react-slot": "^1.0.2",
|
||||||
|
"@radix-ui/react-toast": "^1.1.4",
|
||||||
|
"@types/qrcode": "^1.5.1",
|
||||||
|
"class-variance-authority": "^0.7.0",
|
||||||
|
"clsx": "^2.0.0",
|
||||||
|
"hash-slash": "workspace:*",
|
||||||
|
"cojson": "workspace:*",
|
||||||
|
"cojson-transport-ws": "workspace:*",
|
||||||
|
"lucide-react": "^0.274.0",
|
||||||
|
"qrcode": "^1.5.3",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0",
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^18.2.15",
|
||||||
|
"@types/react-dom": "^18.2.7",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||||
|
"@typescript-eslint/parser": "^6.0.0",
|
||||||
|
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||||
|
"autoprefixer": "^10.4.14",
|
||||||
|
"eslint": "^8.45.0",
|
||||||
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.3",
|
||||||
|
"postcss": "^8.4.27",
|
||||||
|
"tailwindcss": "^3.3.3",
|
||||||
|
"typescript": "^5.0.2",
|
||||||
|
"vite": "^5.0.10"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
plugins: {
|
plugins: {
|
||||||
tailwindcss: {},
|
tailwindcss: {},
|
||||||
autoprefixer: {},
|
autoprefixer: {},
|
||||||
BIN
examples/inspector/public/jazz-logo.png
Normal file
BIN
examples/inspector/public/jazz-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
4
examples/inspector/src/app.tsx
Normal file
4
examples/inspector/src/app.tsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import ReactDOM from "react-dom/client";
|
||||||
|
import App from "./viewer/new-app";
|
||||||
|
|
||||||
|
ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
|
||||||
92
examples/inspector/src/index.css
Normal file
92
examples/inspector/src/index.css
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
examples/inspector/src/link-icon.tsx
Normal file
18
examples/inspector/src/link-icon.tsx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
export function LinkIcon() {
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
strokeWidth={1.5}
|
||||||
|
stroke="currentColor"
|
||||||
|
className="w-3 h-3"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
42
examples/inspector/src/viewer/breadcrumbs.tsx
Normal file
42
examples/inspector/src/viewer/breadcrumbs.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
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>
|
||||||
|
);
|
||||||
|
};
|
||||||
353
examples/inspector/src/viewer/co-stream-view.tsx
Normal file
353
examples/inspector/src/viewer/co-stream-view.tsx
Normal file
@@ -0,0 +1,353 @@
|
|||||||
|
import {
|
||||||
|
CoID,
|
||||||
|
LocalNode,
|
||||||
|
RawBinaryCoStream,
|
||||||
|
RawCoStream,
|
||||||
|
RawCoValue,
|
||||||
|
} from "cojson";
|
||||||
|
import { JsonObject, JsonValue } from "cojson/src/jsonValue";
|
||||||
|
import { PageInfo } from "./types";
|
||||||
|
import { base64URLtoBytes } from "cojson/src/base64url";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { ArrowDownToLine } from "lucide-react";
|
||||||
|
import {
|
||||||
|
BinaryStreamItem,
|
||||||
|
BinaryStreamStart,
|
||||||
|
CoStreamItem,
|
||||||
|
} from "cojson/src/coValues/coStream";
|
||||||
|
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)} />;
|
||||||
|
}
|
||||||
73
examples/inspector/src/viewer/grid-view.tsx
Normal file
73
examples/inspector/src/viewer/grid-view.tsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||||
|
import { JsonObject } from "cojson/src/jsonValue";
|
||||||
|
import { CoMapPreview, ValueRenderer } from "./value-renderer";
|
||||||
|
import clsx from "clsx";
|
||||||
|
import { PageInfo, isCoId } from "./types";
|
||||||
|
import { ResolveIcon } from "./type-icon";
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
27
examples/inspector/src/viewer/index.tsx
Normal file
27
examples/inspector/src/viewer/index.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { LocalNode } from "cojson";
|
||||||
|
import { Breadcrumbs } from "./breadcrumbs";
|
||||||
|
import { usePagePath } from "./use-page-path";
|
||||||
|
import { PageInfo } from "./types";
|
||||||
|
import { PageStack } from "./page-stack";
|
||||||
|
|
||||||
|
export default function CoJsonViewer({
|
||||||
|
defaultPath,
|
||||||
|
node,
|
||||||
|
}: {
|
||||||
|
defaultPath?: PageInfo[];
|
||||||
|
node: LocalNode;
|
||||||
|
}) {
|
||||||
|
const { path, addPages, goToIndex, goBack } = usePagePath(defaultPath);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full h-screen bg-gray-100 p-4 overflow-hidden">
|
||||||
|
<Breadcrumbs path={path} onBreadcrumbClick={goToIndex} />
|
||||||
|
<PageStack
|
||||||
|
path={path}
|
||||||
|
node={node}
|
||||||
|
goBack={goBack}
|
||||||
|
addPages={addPages}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
310
examples/inspector/src/viewer/new-app.tsx
Normal file
310
examples/inspector/src/viewer/new-app.tsx
Normal file
@@ -0,0 +1,310 @@
|
|||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import {
|
||||||
|
LocalNode,
|
||||||
|
CoID,
|
||||||
|
RawCoValue,
|
||||||
|
RawAccount,
|
||||||
|
AgentSecret,
|
||||||
|
AccountID,
|
||||||
|
cojsonInternals,
|
||||||
|
WasmCrypto,
|
||||||
|
} from "cojson";
|
||||||
|
import { createWebSocketPeer } from "cojson-transport-ws";
|
||||||
|
import { Trash2 } from "lucide-react";
|
||||||
|
import { Breadcrumbs } from "./breadcrumbs";
|
||||||
|
import { usePagePath } from "./use-page-path";
|
||||||
|
import { PageStack } from "./page-stack";
|
||||||
|
import { resolveCoValue, useResolvedCoValue } from "./use-resolve-covalue";
|
||||||
|
import clsx from "clsx";
|
||||||
|
|
||||||
|
interface Account {
|
||||||
|
id: CoID<RawAccount>;
|
||||||
|
secret: AgentSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CoJsonViewerApp() {
|
||||||
|
const [accounts, setAccounts] = useState<Account[]>(() => {
|
||||||
|
const storedAccounts = localStorage.getItem("inspectorAccounts");
|
||||||
|
return storedAccounts ? JSON.parse(storedAccounts) : [];
|
||||||
|
});
|
||||||
|
const [currentAccount, setCurrentAccount] = useState<Account | null>(() => {
|
||||||
|
const lastSelectedId = localStorage.getItem("lastSelectedAccountId");
|
||||||
|
if (lastSelectedId) {
|
||||||
|
const lastAccount = accounts.find(
|
||||||
|
(account) => account.id === lastSelectedId,
|
||||||
|
);
|
||||||
|
return lastAccount || null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
const [localNode, setLocalNode] = useState<LocalNode | null>(null);
|
||||||
|
const [coValueId, setCoValueId] = useState<CoID<RawCoValue> | "">("");
|
||||||
|
const { path, addPages, goToIndex, goBack, setPage } = usePagePath();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem("inspectorAccounts", JSON.stringify(accounts));
|
||||||
|
}, [accounts]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentAccount) {
|
||||||
|
localStorage.setItem("lastSelectedAccountId", currentAccount.id);
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem("lastSelectedAccountId");
|
||||||
|
}
|
||||||
|
}, [currentAccount]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!currentAccount) {
|
||||||
|
setLocalNode(null);
|
||||||
|
goToIndex(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WasmCrypto.create().then(async (crypto) => {
|
||||||
|
const wsPeer = createWebSocketPeer({
|
||||||
|
id: "mesh",
|
||||||
|
websocket: new WebSocket("wss://mesh.jazz.tools"),
|
||||||
|
role: "server",
|
||||||
|
});
|
||||||
|
const node = await LocalNode.withLoadedAccount({
|
||||||
|
accountID: currentAccount.id,
|
||||||
|
accountSecret: currentAccount.secret,
|
||||||
|
sessionID: cojsonInternals.newRandomSessionID(
|
||||||
|
currentAccount.id,
|
||||||
|
),
|
||||||
|
peersToLoadFrom: [wsPeer],
|
||||||
|
crypto,
|
||||||
|
migration: async () => {
|
||||||
|
console.log("Not running any migration in inspector");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
setLocalNode(node);
|
||||||
|
});
|
||||||
|
}, [currentAccount, goToIndex]);
|
||||||
|
|
||||||
|
const addAccount = (id: AccountID, secret: AgentSecret) => {
|
||||||
|
const newAccount = { id, secret };
|
||||||
|
setAccounts([...accounts, newAccount]);
|
||||||
|
setCurrentAccount(newAccount);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteCurrentAccount = () => {
|
||||||
|
if (currentAccount) {
|
||||||
|
const updatedAccounts = accounts.filter(
|
||||||
|
(account) => account.id !== currentAccount.id,
|
||||||
|
);
|
||||||
|
setAccounts(updatedAccounts);
|
||||||
|
setCurrentAccount(
|
||||||
|
updatedAccounts.length > 0 ? updatedAccounts[0] : null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCoValueIdSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (coValueId) {
|
||||||
|
setPage(coValueId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full h-screen bg-gray-100 p-4 overflow-hidden flex flex-col">
|
||||||
|
<div className="flex justify-between items-center mb-4">
|
||||||
|
<Breadcrumbs path={path} onBreadcrumbClick={goToIndex} />
|
||||||
|
<AccountSwitcher
|
||||||
|
accounts={accounts}
|
||||||
|
currentAccount={currentAccount}
|
||||||
|
setCurrentAccount={setCurrentAccount}
|
||||||
|
deleteCurrentAccount={deleteCurrentAccount}
|
||||||
|
localNode={localNode}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<PageStack
|
||||||
|
path={path}
|
||||||
|
node={localNode}
|
||||||
|
goBack={goBack}
|
||||||
|
addPages={addPages}
|
||||||
|
>
|
||||||
|
{!currentAccount ? (
|
||||||
|
<AddAccountForm addAccount={addAccount} />
|
||||||
|
) : (
|
||||||
|
<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",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<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={() => {
|
||||||
|
setCoValueId(currentAccount.id);
|
||||||
|
setPage(currentAccount.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Inspect My Account
|
||||||
|
</button>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</PageStack>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AccountSwitcher({
|
||||||
|
accounts,
|
||||||
|
currentAccount,
|
||||||
|
setCurrentAccount,
|
||||||
|
deleteCurrentAccount,
|
||||||
|
localNode,
|
||||||
|
}: {
|
||||||
|
accounts: Account[];
|
||||||
|
currentAccount: Account | null;
|
||||||
|
setCurrentAccount: (account: Account | null) => void;
|
||||||
|
deleteCurrentAccount: () => void;
|
||||||
|
localNode: LocalNode | null;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="relative flex items-center gap-1">
|
||||||
|
<select
|
||||||
|
value={currentAccount?.id || "add-account"}
|
||||||
|
onChange={(e) => {
|
||||||
|
if (e.target.value === "add-account") {
|
||||||
|
setCurrentAccount(null);
|
||||||
|
} else {
|
||||||
|
const account = accounts.find(
|
||||||
|
(a) => a.id === e.target.value,
|
||||||
|
);
|
||||||
|
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}>
|
||||||
|
{localNode ? (
|
||||||
|
<AccountNameDisplay
|
||||||
|
accountId={account.id}
|
||||||
|
node={localNode}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
account.id
|
||||||
|
)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
<option value="add-account">Add account</option>
|
||||||
|
</select>
|
||||||
|
{currentAccount && (
|
||||||
|
<button
|
||||||
|
onClick={deleteCurrentAccount}
|
||||||
|
className="p-3 rounded hover:bg-gray-200 transition-colors"
|
||||||
|
title="Delete Account"
|
||||||
|
>
|
||||||
|
<Trash2 size={16} className="text-gray-500" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AddAccountForm({
|
||||||
|
addAccount,
|
||||||
|
}: {
|
||||||
|
addAccount: (id: AccountID, secret: AgentSecret) => void;
|
||||||
|
}) {
|
||||||
|
const [id, setId] = useState("");
|
||||||
|
const [secret, setSecret] = useState("");
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
addAccount(id as AccountID, secret as AgentSecret);
|
||||||
|
setId("");
|
||||||
|
setSecret("");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
className="flex flex-col gap-2 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>
|
||||||
|
<input
|
||||||
|
className="border py-2 px-3 rounded-md"
|
||||||
|
placeholder="Account ID"
|
||||||
|
value={id}
|
||||||
|
onChange={(e) => setId(e.target.value)}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
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>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AccountNameDisplay({
|
||||||
|
accountId,
|
||||||
|
node,
|
||||||
|
}: {
|
||||||
|
accountId: CoID<RawAccount>;
|
||||||
|
node: LocalNode;
|
||||||
|
}) {
|
||||||
|
const { snapshot } = useResolvedCoValue(accountId, node);
|
||||||
|
const [name, setName] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (snapshot && typeof snapshot === "object" && "profile" in snapshot) {
|
||||||
|
const profileId = snapshot.profile as CoID<RawCoValue>;
|
||||||
|
resolveCoValue(profileId, node).then((profileResult) => {
|
||||||
|
if (
|
||||||
|
profileResult.snapshot &&
|
||||||
|
typeof profileResult.snapshot === "object" &&
|
||||||
|
"name" in profileResult.snapshot
|
||||||
|
) {
|
||||||
|
setName(profileResult.snapshot.name as string);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [snapshot, node]);
|
||||||
|
|
||||||
|
return name ? `${name} <${accountId}>` : accountId;
|
||||||
|
}
|
||||||
55
examples/inspector/src/viewer/page-stack.tsx
Normal file
55
examples/inspector/src/viewer/page-stack.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { Page } from "./page"; // Assuming you have a Page component
|
||||||
|
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||||
|
|
||||||
|
// 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
154
examples/inspector/src/viewer/page.tsx
Normal file
154
examples/inspector/src/viewer/page.tsx
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
import clsx from "clsx";
|
||||||
|
import { CoID, LocalNode, RawCoStream, RawCoValue } from "cojson";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useResolvedCoValue } from "./use-resolve-covalue";
|
||||||
|
import { GridView } from "./grid-view";
|
||||||
|
import { PageInfo } from "./types";
|
||||||
|
import { TableView } from "./table-viewer";
|
||||||
|
import { TypeIcon } from "./type-icon";
|
||||||
|
import { CoStreamView } from "./co-stream-view";
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
142
examples/inspector/src/viewer/table-viewer.tsx
Normal file
142
examples/inspector/src/viewer/table-viewer.tsx
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
import { CoID, LocalNode, RawCoValue } from "cojson";
|
||||||
|
import { JsonObject } from "cojson/src/jsonValue";
|
||||||
|
import { PageInfo } from "./types";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import { ValueRenderer } from "./value-renderer";
|
||||||
|
import { LinkIcon } from "../link-icon";
|
||||||
|
import { useResolvedCoValues } from "./use-resolve-covalue";
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
47
examples/inspector/src/viewer/type-icon.tsx
Normal file
47
examples/inspector/src/viewer/type-icon.tsx
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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} />;
|
||||||
|
};
|
||||||
9
examples/inspector/src/viewer/types.ts
Normal file
9
examples/inspector/src/viewer/types.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
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_");
|
||||||
107
examples/inspector/src/viewer/use-page-path.ts
Normal file
107
examples/inspector/src/viewer/use-page-path.ts
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
import { PageInfo } from "./types";
|
||||||
|
import { CoID, RawCoValue } from "cojson";
|
||||||
|
|
||||||
|
export function usePagePath(defaultPath?: PageInfo[]) {
|
||||||
|
const [path, setPath] = useState<PageInfo[]>(() => {
|
||||||
|
const hash = window.location.hash.slice(2); // Remove '#/'
|
||||||
|
if (hash) {
|
||||||
|
try {
|
||||||
|
return decodePathFromHash(hash);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to parse hash:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultPath || [];
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatePath = useCallback((newPath: PageInfo[]) => {
|
||||||
|
setPath(newPath);
|
||||||
|
const hash = encodePathToHash(newPath);
|
||||||
|
window.location.hash = `#/${hash}`;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleHashChange = () => {
|
||||||
|
const hash = window.location.hash.slice(2);
|
||||||
|
if (hash) {
|
||||||
|
try {
|
||||||
|
const newPath = decodePathFromHash(hash);
|
||||||
|
setPath(newPath);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to parse hash:", e);
|
||||||
|
}
|
||||||
|
} else if (defaultPath) {
|
||||||
|
setPath(defaultPath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("hashchange", handleHashChange);
|
||||||
|
return () => window.removeEventListener("hashchange", handleHashChange);
|
||||||
|
}, [defaultPath]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
defaultPath &&
|
||||||
|
JSON.stringify(path) !== JSON.stringify(defaultPath)
|
||||||
|
) {
|
||||||
|
updatePath(defaultPath);
|
||||||
|
}
|
||||||
|
}, [defaultPath, path, updatePath]);
|
||||||
|
|
||||||
|
const addPages = useCallback(
|
||||||
|
(newPages: PageInfo[]) => {
|
||||||
|
updatePath([...path, ...newPages]);
|
||||||
|
},
|
||||||
|
[path, updatePath],
|
||||||
|
);
|
||||||
|
|
||||||
|
const goToIndex = useCallback(
|
||||||
|
(index: number) => {
|
||||||
|
updatePath(path.slice(0, index + 1));
|
||||||
|
},
|
||||||
|
[path, updatePath],
|
||||||
|
);
|
||||||
|
|
||||||
|
const setPage = useCallback(
|
||||||
|
(coId: CoID<RawCoValue>) => {
|
||||||
|
updatePath([{ coId, name: "Root" }]);
|
||||||
|
},
|
||||||
|
[updatePath],
|
||||||
|
);
|
||||||
|
|
||||||
|
const goBack = useCallback(() => {
|
||||||
|
if (path.length > 1) {
|
||||||
|
updatePath(path.slice(0, path.length - 1));
|
||||||
|
}
|
||||||
|
}, [path, updatePath]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
path,
|
||||||
|
setPage,
|
||||||
|
addPages,
|
||||||
|
goToIndex,
|
||||||
|
goBack,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodePathToHash(path: PageInfo[]): string {
|
||||||
|
return path
|
||||||
|
.map((page) => {
|
||||||
|
if (page.name && page.name !== "Root") {
|
||||||
|
return `${page.coId}:${encodeURIComponent(page.name)}`;
|
||||||
|
}
|
||||||
|
return page.coId;
|
||||||
|
})
|
||||||
|
.join("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodePathFromHash(hash: string): PageInfo[] {
|
||||||
|
return hash.split("/").map((segment) => {
|
||||||
|
const [coId, encodedName] = segment.split(":");
|
||||||
|
return {
|
||||||
|
coId,
|
||||||
|
name: encodedName ? decodeURIComponent(encodedName) : undefined,
|
||||||
|
} as PageInfo;
|
||||||
|
});
|
||||||
|
}
|
||||||
152
examples/inspector/src/viewer/use-resolve-covalue.ts
Normal file
152
examples/inspector/src/viewer/use-resolve-covalue.ts
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useResolvedCoValue(
|
||||||
|
coValueId: CoID<RawCoValue>,
|
||||||
|
node: LocalNode,
|
||||||
|
) {
|
||||||
|
const [result, setResult] =
|
||||||
|
useState<Awaited<ReturnType<typeof resolveCoValue>>>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
resolveCoValue(coValueId, node).then(setResult);
|
||||||
|
}, [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(() => {
|
||||||
|
console.log("RETECHING", coValueIds);
|
||||||
|
const fetchResults = async () => {
|
||||||
|
if (coValueIds.length === 0) return;
|
||||||
|
const resolvedValues = await Promise.all(
|
||||||
|
coValueIds.map((coValueId) => resolveCoValue(coValueId, node)),
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log({ resolvedValues });
|
||||||
|
setResults(resolvedValues);
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchResults();
|
||||||
|
}, [coValueIds, node]);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
248
examples/inspector/src/viewer/value-renderer.tsx
Normal file
248
examples/inspector/src/viewer/value-renderer.tsx
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
import clsx from "clsx";
|
||||||
|
import { CoID, JsonValue, LocalNode, RawCoValue } from "cojson";
|
||||||
|
import { LinkIcon } from "../link-icon";
|
||||||
|
import {
|
||||||
|
isBrowserImage,
|
||||||
|
resolveCoValue,
|
||||||
|
useResolvedCoValue,
|
||||||
|
} from "./use-resolve-covalue";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}) {
|
||||||
|
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 truncate"
|
||||||
|
>
|
||||||
|
{compact ? (
|
||||||
|
<span>
|
||||||
|
Object{" "}
|
||||||
|
<span className="text-gray-500">
|
||||||
|
({Object.keys(json).length})
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
JSON.stringify(json, null, 2)
|
||||||
|
)}
|
||||||
|
</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
examples/inspector/src/vite-env.d.ts
vendored
Normal file
1
examples/inspector/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
75
examples/inspector/tailwind.config.js
Normal file
75
examples/inspector/tailwind.config.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: [
|
||||||
|
'./pages/**/*.{ts,tsx}',
|
||||||
|
'./components/**/*.{ts,tsx}',
|
||||||
|
'./app/**/*.{ts,tsx}',
|
||||||
|
'./src/**/*.{ts,tsx}',
|
||||||
|
],
|
||||||
|
theme: {
|
||||||
|
container: {
|
||||||
|
center: true,
|
||||||
|
padding: "2rem",
|
||||||
|
screens: {
|
||||||
|
"2xl": "1400px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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))",
|
||||||
|
},
|
||||||
|
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: [require("tailwindcss-animate")],
|
||||||
|
}
|
||||||
29
examples/inspector/tsconfig.json
Normal file
29
examples/inspector/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
|
}
|
||||||
10
examples/inspector/tsconfig.node.json
Normal file
10
examples/inspector/tsconfig.node.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"composite": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowSyntheticDefaultImports": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
16
examples/inspector/vite.config.ts
Normal file
16
examples/inspector/vite.config.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react-swc'
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@": path.resolve(__dirname, "./src"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
minify: false
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -5,6 +5,7 @@ module.exports = {
|
|||||||
'eslint:recommended',
|
'eslint:recommended',
|
||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
'plugin:react-hooks/recommended',
|
'plugin:react-hooks/recommended',
|
||||||
|
'prettier'
|
||||||
],
|
],
|
||||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
|
|||||||
9
examples/pets/.prettierrc.js
Normal file
9
examples/pets/.prettierrc.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/** @type {import("prettier").Config} */
|
||||||
|
const config = {
|
||||||
|
trailingComma: "all",
|
||||||
|
tabWidth: 4,
|
||||||
|
semi: true,
|
||||||
|
singleQuote: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
699
examples/pets/CHANGELOG.md
Normal file
699
examples/pets/CHANGELOG.md
Normal file
@@ -0,0 +1,699 @@
|
|||||||
|
# jazz-example-pets
|
||||||
|
|
||||||
|
## 0.0.93
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.28
|
||||||
|
- jazz-tools@0.7.28
|
||||||
|
- jazz-browser-media-images@0.7.28
|
||||||
|
|
||||||
|
## 0.0.92
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-browser-media-images@0.7.27
|
||||||
|
- jazz-react@0.7.27
|
||||||
|
|
||||||
|
## 0.0.91
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.26
|
||||||
|
- jazz-tools@0.7.26
|
||||||
|
- jazz-browser-media-images@0.7.26
|
||||||
|
|
||||||
|
## 0.0.90
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.25
|
||||||
|
- jazz-browser-media-images@0.7.25
|
||||||
|
- jazz-react@0.7.25
|
||||||
|
|
||||||
|
## 0.0.89
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.24
|
||||||
|
- jazz-browser-media-images@0.7.24
|
||||||
|
- jazz-react@0.7.24
|
||||||
|
|
||||||
|
## 0.0.88
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.23
|
||||||
|
- jazz-tools@0.7.23
|
||||||
|
- jazz-browser-media-images@0.7.23
|
||||||
|
|
||||||
|
## 0.0.87
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-browser-media-images@0.7.22
|
||||||
|
- jazz-react@0.7.22
|
||||||
|
|
||||||
|
## 0.0.86
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.21
|
||||||
|
- jazz-browser-media-images@0.7.21
|
||||||
|
- jazz-react@0.7.21
|
||||||
|
|
||||||
|
## 0.0.85
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.20
|
||||||
|
- jazz-browser-media-images@0.7.20
|
||||||
|
- jazz-react@0.7.20
|
||||||
|
|
||||||
|
## 0.0.84
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.19
|
||||||
|
- jazz-browser-media-images@0.7.19
|
||||||
|
- jazz-react@0.7.19
|
||||||
|
|
||||||
|
## 0.0.83
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.18
|
||||||
|
- jazz-tools@0.7.18
|
||||||
|
- jazz-browser-media-images@0.7.18
|
||||||
|
|
||||||
|
## 0.0.82
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.17
|
||||||
|
- jazz-tools@0.7.17
|
||||||
|
- jazz-browser-media-images@0.7.17
|
||||||
|
|
||||||
|
## 0.0.81
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.16
|
||||||
|
- jazz-browser-media-images@0.7.16
|
||||||
|
- jazz-react@0.7.16
|
||||||
|
|
||||||
|
## 0.0.80
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.15
|
||||||
|
|
||||||
|
## 0.0.79
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.14
|
||||||
|
- jazz-react@0.7.14
|
||||||
|
- jazz-browser-media-images@0.7.14
|
||||||
|
|
||||||
|
## 0.0.78
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.13
|
||||||
|
- jazz-browser-media-images@0.7.13
|
||||||
|
- jazz-react@0.7.13
|
||||||
|
|
||||||
|
## 0.0.77
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.12
|
||||||
|
- jazz-browser-media-images@0.7.12
|
||||||
|
- jazz-react@0.7.12
|
||||||
|
|
||||||
|
## 0.0.76
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.11
|
||||||
|
- jazz-tools@0.7.11
|
||||||
|
- jazz-browser-media-images@0.7.11
|
||||||
|
|
||||||
|
## 0.0.75
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.10
|
||||||
|
- jazz-tools@0.7.10
|
||||||
|
- jazz-browser-media-images@0.7.10
|
||||||
|
|
||||||
|
## 0.0.74
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.9
|
||||||
|
- jazz-tools@0.7.9
|
||||||
|
- jazz-browser-media-images@0.7.9
|
||||||
|
|
||||||
|
## 0.0.73
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.8
|
||||||
|
- jazz-browser-media-images@0.7.8
|
||||||
|
- jazz-react@0.7.8
|
||||||
|
|
||||||
|
## 0.0.72
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [9fdc91c]
|
||||||
|
- jazz-react@0.7.7
|
||||||
|
|
||||||
|
## 0.0.71
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.6
|
||||||
|
- jazz-browser-media-images@0.7.6
|
||||||
|
- jazz-react@0.7.6
|
||||||
|
|
||||||
|
## 0.0.70
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.5
|
||||||
|
- jazz-browser-media-images@0.7.5
|
||||||
|
|
||||||
|
## 0.0.69
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.4
|
||||||
|
|
||||||
|
## 0.0.68
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.3
|
||||||
|
- jazz-browser-media-images@0.7.3
|
||||||
|
- jazz-react@0.7.3
|
||||||
|
|
||||||
|
## 0.0.67
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.2
|
||||||
|
|
||||||
|
## 0.0.66
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.1
|
||||||
|
- jazz-browser-media-images@0.7.1
|
||||||
|
- jazz-react@0.7.1
|
||||||
|
|
||||||
|
## 0.0.65
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [96c494f]
|
||||||
|
- Updated dependencies [59c18c3]
|
||||||
|
- Updated dependencies [19f52b7]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [d8fe2b1]
|
||||||
|
- Updated dependencies [19004b4]
|
||||||
|
- Updated dependencies [a78f168]
|
||||||
|
- Updated dependencies [52675c9]
|
||||||
|
- Updated dependencies [129e2c1]
|
||||||
|
- Updated dependencies [6d49e9b]
|
||||||
|
- Updated dependencies [1cfa279]
|
||||||
|
- Updated dependencies [704af7d]
|
||||||
|
- Updated dependencies [e97f730]
|
||||||
|
- Updated dependencies [460478f]
|
||||||
|
- Updated dependencies [6b0418f]
|
||||||
|
- Updated dependencies [e299c3e]
|
||||||
|
- Updated dependencies [ed5643a]
|
||||||
|
- Updated dependencies [bde684f]
|
||||||
|
- Updated dependencies [c4151fc]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [01ac646]
|
||||||
|
- Updated dependencies [a5e68a4]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [952982e]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [5fa277c]
|
||||||
|
- Updated dependencies [60d5ca2]
|
||||||
|
- Updated dependencies [21771c4]
|
||||||
|
- Updated dependencies [77c2b56]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [d2e03ff]
|
||||||
|
- Updated dependencies [354bdcd]
|
||||||
|
- Updated dependencies [ece35b3]
|
||||||
|
- Updated dependencies [60d5ca2]
|
||||||
|
- Updated dependencies [69ac514]
|
||||||
|
- Updated dependencies [f8a5c46]
|
||||||
|
- Updated dependencies [f0f6f1b]
|
||||||
|
- Updated dependencies [e5eed5b]
|
||||||
|
- Updated dependencies [1a44f87]
|
||||||
|
- Updated dependencies [627d895]
|
||||||
|
- Updated dependencies [1200aae]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [ece35b3]
|
||||||
|
- Updated dependencies [38d4410]
|
||||||
|
- Updated dependencies [85d2b62]
|
||||||
|
- Updated dependencies [fd86c11]
|
||||||
|
- Updated dependencies [52675c9]
|
||||||
|
- jazz-tools@0.7.0
|
||||||
|
- jazz-browser-media-images@0.7.0
|
||||||
|
- jazz-react@0.7.0
|
||||||
|
|
||||||
|
## 0.0.65-alpha.42
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.42
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.40
|
||||||
|
- jazz-react@0.7.0-alpha.42
|
||||||
|
|
||||||
|
## 0.0.65-alpha.41
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-tools@0.7.0-alpha.41
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.39
|
||||||
|
- jazz-react@0.7.0-alpha.41
|
||||||
|
|
||||||
|
## 0.0.65-alpha.40
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.40
|
||||||
|
|
||||||
|
## 0.0.65-alpha.39
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.0-alpha.39
|
||||||
|
- jazz-tools@0.7.0-alpha.39
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.38
|
||||||
|
|
||||||
|
## 0.0.65-alpha.38
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.38
|
||||||
|
- jazz-react@0.7.0-alpha.38
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.37
|
||||||
|
|
||||||
|
## 0.0.65-alpha.37
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.37
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.36
|
||||||
|
- jazz-tools@0.7.0-alpha.37
|
||||||
|
|
||||||
|
## 0.0.65-alpha.36
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [6b0418f]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- jazz-tools@0.7.0-alpha.36
|
||||||
|
- jazz-react@0.7.0-alpha.36
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.35
|
||||||
|
|
||||||
|
## 0.0.65-alpha.35
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.35
|
||||||
|
- jazz-react@0.7.0-alpha.35
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.34
|
||||||
|
|
||||||
|
## 0.0.65-alpha.34
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.34
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.33
|
||||||
|
- jazz-react@0.7.0-alpha.34
|
||||||
|
|
||||||
|
## 0.0.65-alpha.33
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.33
|
||||||
|
|
||||||
|
## 0.0.65-alpha.32
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.32
|
||||||
|
- jazz-react@0.7.0-alpha.32
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.32
|
||||||
|
|
||||||
|
## 0.0.65-alpha.31
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.31
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.31
|
||||||
|
- jazz-react@0.7.0-alpha.31
|
||||||
|
|
||||||
|
## 0.0.65-alpha.30
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.30
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.30
|
||||||
|
- jazz-react@0.7.0-alpha.30
|
||||||
|
|
||||||
|
## 0.0.65-alpha.29
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.29
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.29
|
||||||
|
- jazz-react@0.7.0-alpha.29
|
||||||
|
|
||||||
|
## 0.0.65-alpha.28
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.28
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.28
|
||||||
|
- jazz-react@0.7.0-alpha.28
|
||||||
|
|
||||||
|
## 0.0.65-alpha.27
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.27
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.27
|
||||||
|
- jazz-react@0.7.0-alpha.27
|
||||||
|
|
||||||
|
## 0.0.65-alpha.26
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.26
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.26
|
||||||
|
- jazz-react@0.7.0-alpha.26
|
||||||
|
|
||||||
|
## 0.0.65-alpha.25
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.25
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.25
|
||||||
|
- jazz-react@0.7.0-alpha.25
|
||||||
|
|
||||||
|
## 0.0.65-alpha.24
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.24
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.24
|
||||||
|
- jazz-react@0.7.0-alpha.24
|
||||||
|
|
||||||
|
## 0.0.65-alpha.23
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.23
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.23
|
||||||
|
- jazz-react@0.7.0-alpha.23
|
||||||
|
|
||||||
|
## 0.0.65-alpha.22
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.22
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.22
|
||||||
|
- jazz-react@0.7.0-alpha.22
|
||||||
|
|
||||||
|
## 0.0.65-alpha.21
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.21
|
||||||
|
- jazz-tools@0.7.0-alpha.21
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.21
|
||||||
|
|
||||||
|
## 0.0.65-alpha.20
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.20
|
||||||
|
- jazz-tools@0.7.0-alpha.20
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.20
|
||||||
|
|
||||||
|
## 0.0.65-alpha.19
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.19
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.19
|
||||||
|
- jazz-react@0.7.0-alpha.19
|
||||||
|
|
||||||
|
## 0.0.65-alpha.18
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.18
|
||||||
|
- jazz-react@0.7.0-alpha.18
|
||||||
|
|
||||||
|
## 0.0.65-alpha.17
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.17
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.17
|
||||||
|
- jazz-react@0.7.0-alpha.17
|
||||||
|
|
||||||
|
## 0.0.65-alpha.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.16
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.16
|
||||||
|
- jazz-react@0.7.0-alpha.16
|
||||||
|
|
||||||
|
## 0.0.65-alpha.15
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.15
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.15
|
||||||
|
- jazz-react@0.7.0-alpha.15
|
||||||
|
|
||||||
|
## 0.0.65-alpha.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.14
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.14
|
||||||
|
- jazz-react@0.7.0-alpha.14
|
||||||
|
|
||||||
|
## 0.0.65-alpha.13
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.13
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.13
|
||||||
|
- jazz-react@0.7.0-alpha.13
|
||||||
|
|
||||||
|
## 0.0.65-alpha.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.12
|
||||||
|
- jazz-react@0.7.0-alpha.12
|
||||||
|
- jazz-tools@0.7.0-alpha.12
|
||||||
|
|
||||||
|
## 0.0.65-alpha.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.11
|
||||||
|
- jazz-react@0.7.0-alpha.11
|
||||||
|
- jazz-tools@0.7.0-alpha.11
|
||||||
|
|
||||||
|
## 0.0.65-alpha.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.10
|
||||||
|
- jazz-react@0.7.0-alpha.10
|
||||||
|
- jazz-tools@0.7.0-alpha.10
|
||||||
|
|
||||||
|
## 0.0.65-alpha.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.9
|
||||||
|
- jazz-react@0.7.0-alpha.9
|
||||||
|
- jazz-tools@0.7.0-alpha.9
|
||||||
|
|
||||||
|
## 0.0.65-alpha.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.8
|
||||||
|
- jazz-react@0.7.0-alpha.8
|
||||||
|
- jazz-tools@0.7.0-alpha.8
|
||||||
|
|
||||||
|
## 0.0.65-alpha.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.7
|
||||||
|
- jazz-react@0.7.0-alpha.7
|
||||||
|
- jazz-tools@0.7.0-alpha.7
|
||||||
|
|
||||||
|
## 0.0.65-alpha.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.6
|
||||||
|
- jazz-react@0.7.0-alpha.6
|
||||||
|
- jazz-tools@0.7.0-alpha.6
|
||||||
|
|
||||||
|
## 0.0.65-alpha.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.5
|
||||||
|
- jazz-react@0.7.0-alpha.5
|
||||||
|
- jazz-tools@0.7.0-alpha.5
|
||||||
|
|
||||||
|
## 0.0.65-alpha.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.4
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.4
|
||||||
|
- jazz-react@0.7.0-alpha.4
|
||||||
|
|
||||||
|
## 0.0.65-alpha.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.3
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.3
|
||||||
|
- jazz-react@0.7.0-alpha.3
|
||||||
|
|
||||||
|
## 0.0.65-alpha.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.2
|
||||||
|
- jazz-react@0.7.0-alpha.2
|
||||||
|
- jazz-tools@0.7.0-alpha.2
|
||||||
|
|
||||||
|
## 0.0.65-alpha.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.1
|
||||||
|
- jazz-react@0.7.0-alpha.1
|
||||||
|
- jazz-tools@0.7.0-alpha.1
|
||||||
|
|
||||||
|
## 0.0.65-alpha.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.7.0-alpha.0
|
||||||
|
- jazz-react@0.7.0-alpha.0
|
||||||
|
- jazz-tools@0.7.0-alpha.0
|
||||||
|
|
||||||
|
## 0.0.64
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.6.0
|
||||||
|
|
||||||
|
## 0.0.63
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-browser-media-images@0.5.0
|
||||||
|
- jazz-react@0.5.0
|
||||||
|
- jazz-react-auth-local@0.4.16
|
||||||
@@ -4,41 +4,32 @@ Live version: https://example-pets.jazz.tools
|
|||||||
|
|
||||||
## Installing & running the example locally
|
## Installing & running the example locally
|
||||||
|
|
||||||
Start by checking out just the example app to a folder:
|
(this requires `pnpm` to be installed, see [https://pnpm.io/installation](https://pnpm.io/installation))
|
||||||
|
|
||||||
|
Start by checking out `jazz`
|
||||||
```bash
|
```bash
|
||||||
npx degit gardencmp/jazz/examples/pets jazz-example-pets
|
git clone https://github.com/gardencmp/jazz.git
|
||||||
cd jazz-example-pets
|
cd jazz/examples/pets
|
||||||
|
pnpm pack --pack-destination /tmp
|
||||||
|
mkdir -p ~/jazz-examples/pets # or any other directory
|
||||||
|
tar -xf /tmp/jazz-example-pets-* --strip-components 1 -C ~/jazz-examples/pets
|
||||||
|
cd ~/jazz-examples/pets
|
||||||
```
|
```
|
||||||
|
|
||||||
(This ensures that you have the example app without git history or our multi-package monorepo)
|
This ensures that you have the example app without git history and independent of the Jazz multi-package monorepo.
|
||||||
|
|
||||||
Install dependencies:
|
Install dependencies:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install
|
pnpm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Start the dev server:
|
Start the dev server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
pnpm dev
|
||||||
```
|
```
|
||||||
|
|
||||||
## Structure
|
|
||||||
|
|
||||||
TODO
|
|
||||||
|
|
||||||
## Walkthrough
|
|
||||||
|
|
||||||
### Main parts
|
|
||||||
|
|
||||||
TODO
|
|
||||||
|
|
||||||
### Helpers
|
|
||||||
|
|
||||||
TODO
|
|
||||||
|
|
||||||
## Questions / problems / feedback
|
## Questions / problems / feedback
|
||||||
|
|
||||||
If you have feedback, let us know on [Discord](https://discord.gg/utDMjHYg42) or open an issue or PR to fix something that seems wrong.
|
If you have feedback, let us know on [Discord](https://discord.gg/utDMjHYg42) or open an issue or PR to fix something that seems wrong.
|
||||||
@@ -48,4 +39,4 @@ If you have feedback, let us know on [Discord](https://discord.gg/utDMjHYg42) or
|
|||||||
|
|
||||||
By default, the example app uses [Jazz Global Mesh](https://jazz.tools/mesh) (`wss://sync.jazz.tools`) - so cross-device use, invites and collaboration should just work.
|
By default, the example app uses [Jazz Global Mesh](https://jazz.tools/mesh) (`wss://sync.jazz.tools`) - so cross-device use, invites and collaboration should just work.
|
||||||
|
|
||||||
You can also run a local sync server by running `npx cojson-simple-sync` and adding the query param `?sync=ws://localhost:4200` to the URL of the example app (for example: `http://localhost:5173/?sync=ws://localhost:4200`), or by setting the `sync` parameter of the `<WithJazz>` provider component in [./src/0_main.tsx](./src/0_main.tsx).
|
You can also run a local sync server by running `npx cojson-simple-sync` and adding the query param `?sync=ws://localhost:4200` to the URL of the example app (for example: `http://localhost:5173/?sync=ws://localhost:4200`), or by setting the `sync` parameter of the `<Jazz.Provider>` provider component in [./src/2_main.tsx](./src/2_main.tsx).
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ job "example-pets$BRANCH_SUFFIX" {
|
|||||||
datacenters = ["*"]
|
datacenters = ["*"]
|
||||||
|
|
||||||
group "static" {
|
group "static" {
|
||||||
count = 8
|
count = 4
|
||||||
|
|
||||||
network {
|
network {
|
||||||
port "http" {
|
port "http" {
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "jazz-example-pets",
|
"name": "jazz-example-pets",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.20",
|
"version": "0.0.93",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
|
"format": "prettier --write './src/**/*.{ts,tsx}'",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{ts,tsx}": "eslint --fix",
|
||||||
|
"*.{js,jsx,mdx,json}": "prettier --write"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-checkbox": "^1.0.4",
|
"@radix-ui/react-checkbox": "^1.0.4",
|
||||||
"@radix-ui/react-slot": "^1.0.2",
|
"@radix-ui/react-slot": "^1.0.2",
|
||||||
@@ -16,9 +21,9 @@
|
|||||||
"@types/qrcode": "^1.5.1",
|
"@types/qrcode": "^1.5.1",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.0.0",
|
"clsx": "^2.0.0",
|
||||||
"jazz-browser-media-images": "^0.4.8",
|
"jazz-browser-media-images": "workspace:*",
|
||||||
"jazz-react": "^0.4.7",
|
"jazz-react": "workspace:*",
|
||||||
"jazz-react-auth-local": "^0.4.7",
|
"jazz-tools": "workspace:*",
|
||||||
"lucide-react": "^0.274.0",
|
"lucide-react": "^0.274.0",
|
||||||
"qrcode": "^1.5.3",
|
"qrcode": "^1.5.3",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
|
|||||||
59
examples/pets/src/1_schema.ts
Normal file
59
examples/pets/src/1_schema.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import {
|
||||||
|
Account,
|
||||||
|
CoList,
|
||||||
|
CoMap,
|
||||||
|
CoStream,
|
||||||
|
ImageDefinition,
|
||||||
|
Profile,
|
||||||
|
co,
|
||||||
|
} from "jazz-tools";
|
||||||
|
|
||||||
|
/** Walkthrough: Defining the data model with CoJSON
|
||||||
|
*
|
||||||
|
* Here, we define our main data model of TODO
|
||||||
|
*
|
||||||
|
* TODO
|
||||||
|
**/
|
||||||
|
|
||||||
|
export const ReactionTypes = [
|
||||||
|
"aww",
|
||||||
|
"love",
|
||||||
|
"haha",
|
||||||
|
"wow",
|
||||||
|
"tiny",
|
||||||
|
"chonkers",
|
||||||
|
] as const;
|
||||||
|
export type ReactionType = (typeof ReactionTypes)[number];
|
||||||
|
|
||||||
|
export class PetReactions extends CoStream.Of(co.json<ReactionType>()) {}
|
||||||
|
|
||||||
|
export class PetPost extends CoMap {
|
||||||
|
name = co.string;
|
||||||
|
image = co.ref(ImageDefinition);
|
||||||
|
reactions = co.ref(PetReactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ListOfPosts extends CoList.Of(co.ref(PetPost)) {}
|
||||||
|
|
||||||
|
export class PetAccountRoot extends CoMap {
|
||||||
|
posts = co.ref(ListOfPosts);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PetAccount extends Account {
|
||||||
|
profile = co.ref(Profile);
|
||||||
|
root = co.ref(PetAccountRoot);
|
||||||
|
|
||||||
|
migrate(this: PetAccount, creationProps?: { name: string }) {
|
||||||
|
super.migrate(creationProps);
|
||||||
|
if (!this._refs.root) {
|
||||||
|
this.root = PetAccountRoot.create(
|
||||||
|
{
|
||||||
|
posts: ListOfPosts.create([], { owner: this }),
|
||||||
|
},
|
||||||
|
{ owner: this },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Walkthrough: Continue with ./2_App.tsx */
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import {
|
|
||||||
AccountMigration,
|
|
||||||
CoList,
|
|
||||||
CoMap,
|
|
||||||
CoStream,
|
|
||||||
Media,
|
|
||||||
Profile,
|
|
||||||
} from "cojson";
|
|
||||||
|
|
||||||
/** Walkthrough: Defining the data model with CoJSON
|
|
||||||
*
|
|
||||||
* Here, we define our main data model of TODO
|
|
||||||
*
|
|
||||||
* TODO
|
|
||||||
**/
|
|
||||||
|
|
||||||
export type PetPost = CoMap<{
|
|
||||||
name: string;
|
|
||||||
image: Media.ImageDefinition["id"];
|
|
||||||
reactions: PetReactions["id"];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export const REACTION_TYPES = [
|
|
||||||
"aww",
|
|
||||||
"love",
|
|
||||||
"haha",
|
|
||||||
"wow",
|
|
||||||
"tiny",
|
|
||||||
"chonkers",
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export type ReactionType = (typeof REACTION_TYPES)[number];
|
|
||||||
|
|
||||||
export type PetReactions = CoStream<ReactionType>;
|
|
||||||
|
|
||||||
export type ListOfPosts = CoList<PetPost["id"]>;
|
|
||||||
|
|
||||||
export type PetAccountRoot = CoMap<{
|
|
||||||
posts: ListOfPosts["id"];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export const migration: AccountMigration<Profile, PetAccountRoot> = (account) => {
|
|
||||||
if (!account.get("root")) {
|
|
||||||
const root = account.createMap<PetAccountRoot>({
|
|
||||||
posts: account.createList<ListOfPosts>().id,
|
|
||||||
});
|
|
||||||
account.set("root", root.id);
|
|
||||||
console.log("Created root", root.id);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Walkthrough: Continue with ./2_App.tsx */
|
|
||||||
@@ -3,8 +3,7 @@ import ReactDOM from "react-dom/client";
|
|||||||
import { Link, RouterProvider, createHashRouter } from "react-router-dom";
|
import { Link, RouterProvider, createHashRouter } from "react-router-dom";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
import { WithJazz, useJazz, useAcceptInvite } from "jazz-react";
|
import { createJazzReactContext, PasskeyAuth } from "jazz-react";
|
||||||
import { LocalAuth } from "jazz-react-auth-local";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -14,8 +13,7 @@ import {
|
|||||||
import { PrettyAuthUI } from "./components/Auth.tsx";
|
import { PrettyAuthUI } from "./components/Auth.tsx";
|
||||||
import { NewPetPostForm } from "./3_NewPetPostForm.tsx";
|
import { NewPetPostForm } from "./3_NewPetPostForm.tsx";
|
||||||
import { RatePetPostUI } from "./4_RatePetPostUI.tsx";
|
import { RatePetPostUI } from "./4_RatePetPostUI.tsx";
|
||||||
import { PetAccountRoot, migration } from "./1_types.ts";
|
import { PetAccount, PetPost } from "./1_schema.ts";
|
||||||
import { AccountMigration, Profile } from "cojson";
|
|
||||||
|
|
||||||
/** Walkthrough: The top-level provider `<WithJazz/>`
|
/** Walkthrough: The top-level provider `<WithJazz/>`
|
||||||
*
|
*
|
||||||
@@ -26,22 +24,30 @@ import { AccountMigration, Profile } from "cojson";
|
|||||||
|
|
||||||
const appName = "Jazz Rate My Pet Example";
|
const appName = "Jazz Rate My Pet Example";
|
||||||
|
|
||||||
const auth = LocalAuth({
|
const auth = PasskeyAuth<PetAccount>({
|
||||||
appName,
|
appName,
|
||||||
Component: PrettyAuthUI,
|
Component: PrettyAuthUI,
|
||||||
|
accountSchema: PetAccount,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const Jazz = createJazzReactContext({
|
||||||
|
auth,
|
||||||
|
peer: "wss://mesh.jazz.tools/?key=you@example.com",
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
|
export const { useAccount, useCoState, useAcceptInvite } = Jazz;
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<TitleAndLogo name={appName} />
|
<TitleAndLogo name={appName} />
|
||||||
<div className="flex flex-col h-full items-center justify-start gap-10 pt-10 pb-10 px-5">
|
<div className="flex flex-col h-full items-center justify-start gap-10 pt-10 pb-10 px-5">
|
||||||
<WithJazz auth={auth} migration={migration as AccountMigration}>
|
<Jazz.Provider loading={<div>Loading</div>}>
|
||||||
<App />
|
<App />
|
||||||
</WithJazz>
|
</Jazz.Provider>
|
||||||
</div>
|
</div>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</React.StrictMode>
|
</React.StrictMode>,
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Walkthrough: Creating pet posts & routing in `<App/>`
|
/** Walkthrough: Creating pet posts & routing in `<App/>`
|
||||||
@@ -52,7 +58,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { logOut } = useJazz();
|
const { logOut } = useAccount();
|
||||||
|
|
||||||
const router = createHashRouter([
|
const router = createHashRouter([
|
||||||
{
|
{
|
||||||
@@ -73,7 +79,10 @@ export default function App() {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useAcceptInvite((petPostID) => router.navigate("/pet/" + petPostID));
|
useAcceptInvite({
|
||||||
|
invitedObjectSchema: PetPost,
|
||||||
|
onAccept: (petPostID) => router.navigate("/pet/" + petPostID),
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -90,7 +99,7 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function PostOverview() {
|
export function PostOverview() {
|
||||||
const { me } = useJazz<Profile, PetAccountRoot>();
|
const { me } = useAccount();
|
||||||
|
|
||||||
const myPosts = me.root?.posts;
|
const myPosts = me.root?.posts;
|
||||||
|
|
||||||
@@ -105,7 +114,7 @@ export function PostOverview() {
|
|||||||
<Link key={post.id} to={"/pet/" + post.id}>
|
<Link key={post.id} to={"/pet/" + post.id}>
|
||||||
{post.name}
|
{post.name}
|
||||||
</Link>
|
</Link>
|
||||||
)
|
),
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
|||||||
@@ -1,62 +1,63 @@
|
|||||||
import { ChangeEvent, useCallback, useState } from "react";
|
import { ChangeEvent, useCallback, useState } from "react";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
|
import { createImage } from "jazz-browser-media-images";
|
||||||
|
|
||||||
import { CoID, CoMap, Media, Profile } from "cojson";
|
import { PetPost, PetReactions } from "./1_schema";
|
||||||
import { useAutoSub, useJazz } from "jazz-react";
|
|
||||||
import { BrowserImage, createImage } from "jazz-browser-media-images";
|
|
||||||
|
|
||||||
import { PetAccountRoot, PetPost, PetReactions } from "./1_types";
|
|
||||||
|
|
||||||
import { Input, Button } from "./basicComponents";
|
import { Input, Button } from "./basicComponents";
|
||||||
|
import { useAccount, useCoState } from "./2_main";
|
||||||
|
import { CoMap, Group, ID, ImageDefinition, co } from "jazz-tools";
|
||||||
|
import { ProgressiveImg } from "jazz-react";
|
||||||
|
|
||||||
/** Walkthrough: TODO
|
/** Walkthrough: TODO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type PartialPetPost = CoMap<{
|
class PartialPetPost extends CoMap {
|
||||||
name: string;
|
name = co.string;
|
||||||
image?: Media.ImageDefinition["id"];
|
image = co.ref(ImageDefinition, { optional: true });
|
||||||
reactions: PetReactions["id"];
|
reactions = co.ref(PetReactions);
|
||||||
}>;
|
}
|
||||||
|
|
||||||
export function NewPetPostForm() {
|
export function NewPetPostForm() {
|
||||||
const { me } = useJazz<Profile, PetAccountRoot>();
|
const { me } = useAccount();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [newPostId, setNewPostId] = useState<
|
const [newPostId, setNewPostId] = useState<ID<PartialPetPost> | undefined>(
|
||||||
CoID<PartialPetPost> | undefined
|
undefined,
|
||||||
>(undefined);
|
);
|
||||||
|
|
||||||
const newPetPost = useAutoSub(newPostId);
|
const newPetPost = useCoState(PartialPetPost, newPostId);
|
||||||
|
|
||||||
const onChangeName = useCallback(
|
const onChangeName = useCallback(
|
||||||
(name: string) => {
|
(name: string) => {
|
||||||
if (newPetPost) {
|
if (newPetPost) {
|
||||||
newPetPost.set({ name });
|
newPetPost.name = name;
|
||||||
} else {
|
} else {
|
||||||
const petPostGroup = me.createGroup();
|
const petPostGroup = Group.create({ owner: me });
|
||||||
const petPost = petPostGroup.createMap<PartialPetPost>({
|
const petPost = PartialPetPost.create(
|
||||||
name,
|
{
|
||||||
reactions: petPostGroup.createStream<PetReactions>().id,
|
name,
|
||||||
});
|
reactions: PetReactions.create([], { owner: me }),
|
||||||
|
},
|
||||||
|
{ owner: petPostGroup },
|
||||||
|
);
|
||||||
|
|
||||||
setNewPostId(petPost.id);
|
setNewPostId(petPost.id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[me, newPetPost]
|
[me, newPetPost],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onImageSelected = useCallback(
|
const onImageSelected = useCallback(
|
||||||
async (event: ChangeEvent<HTMLInputElement>) => {
|
async (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
if (!newPetPost || !event.target.files) return;
|
if (!newPetPost || !event.target.files) return;
|
||||||
|
|
||||||
const image = await createImage(
|
const image = await createImage(event.target.files[0], {
|
||||||
event.target.files[0],
|
owner: newPetPost._owner,
|
||||||
newPetPost.meta.group
|
});
|
||||||
);
|
|
||||||
|
|
||||||
newPetPost.set({ image: image.id });
|
newPetPost.image = image;
|
||||||
},
|
},
|
||||||
[newPetPost]
|
[newPetPost],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onSubmit = useCallback(() => {
|
const onSubmit = useCallback(() => {
|
||||||
@@ -67,7 +68,7 @@ export function NewPetPostForm() {
|
|||||||
throw new Error("No posts list found");
|
throw new Error("No posts list found");
|
||||||
}
|
}
|
||||||
|
|
||||||
myPosts.append(newPetPost.id as PetPost["id"]);
|
myPosts.push(newPetPost as PetPost);
|
||||||
|
|
||||||
navigate("/pet/" + newPetPost.id);
|
navigate("/pet/" + newPetPost.id);
|
||||||
}, [me.root?.posts, newPetPost, navigate]);
|
}, [me.root?.posts, newPetPost, navigate]);
|
||||||
@@ -84,13 +85,11 @@ export function NewPetPostForm() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{newPetPost?.image ? (
|
{newPetPost?.image ? (
|
||||||
<img
|
<ProgressiveImg image={newPetPost.image}>
|
||||||
className="w-80 max-w-full rounded"
|
{({ src }) => (
|
||||||
src={
|
<img className="w-80 max-w-full rounded" src={src} />
|
||||||
newPetPost?.image.as(BrowserImage)
|
)}
|
||||||
?.highestResSrcOrPlaceholder
|
</ProgressiveImg>
|
||||||
}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
<Input
|
<Input
|
||||||
type="file"
|
type="file"
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import { CoID } from "cojson";
|
|
||||||
|
|
||||||
import { PetPost, ReactionType, REACTION_TYPES, PetReactions } from "./1_types";
|
import { PetPost, PetReactions, ReactionTypes } from "./1_schema";
|
||||||
|
|
||||||
import { ShareButton } from "./components/ShareButton";
|
import { ShareButton } from "./components/ShareButton";
|
||||||
import { Button, Skeleton } from "./basicComponents";
|
import { Button, Skeleton } from "./basicComponents";
|
||||||
import { BrowserImage } from "jazz-browser-media-images";
|
|
||||||
import uniqolor from "uniqolor";
|
import uniqolor from "uniqolor";
|
||||||
import { Resolved, useAutoSub } from "jazz-react";
|
import { ID } from "jazz-tools";
|
||||||
|
import { useCoState } from "./2_main";
|
||||||
|
import { ProgressiveImg } from "jazz-react";
|
||||||
|
|
||||||
/** Walkthrough: TODO
|
/** Walkthrough: TODO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const reactionEmojiMap: { [reaction in ReactionType]: string } = {
|
const reactionEmojiMap: {
|
||||||
|
[reaction in (typeof ReactionTypes)[number]]: string;
|
||||||
|
} = {
|
||||||
aww: "😍",
|
aww: "😍",
|
||||||
love: "❤️",
|
love: "❤️",
|
||||||
haha: "😂",
|
haha: "😂",
|
||||||
@@ -22,9 +24,9 @@ const reactionEmojiMap: { [reaction in ReactionType]: string } = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function RatePetPostUI() {
|
export function RatePetPostUI() {
|
||||||
const petPostID = useParams<{ petPostId: CoID<PetPost> }>().petPostId;
|
const petPostID = useParams<{ petPostId: ID<PetPost> }>().petPostId;
|
||||||
|
|
||||||
const petPost = useAutoSub(petPostID);
|
const petPost = useCoState(PetPost, petPostID);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-8">
|
<div className="flex flex-col gap-8">
|
||||||
@@ -33,22 +35,18 @@ export function RatePetPostUI() {
|
|||||||
<ShareButton petPost={petPost} />
|
<ShareButton petPost={petPost} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{petPost?.image && (
|
<ProgressiveImg image={petPost?.image}>
|
||||||
<img
|
{({ src }) => (
|
||||||
className="w-80 max-w-full rounded"
|
<img className="w-80 max-w-full rounded" src={src} />
|
||||||
src={
|
)}
|
||||||
petPost.image.as(BrowserImage)
|
</ProgressiveImg>
|
||||||
?.highestResSrcOrPlaceholder
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="flex justify-between max-w-xs flex-wrap">
|
<div className="flex justify-between max-w-xs flex-wrap">
|
||||||
{REACTION_TYPES.map((reactionType) => (
|
{ReactionTypes.map((reactionType) => (
|
||||||
<Button
|
<Button
|
||||||
key={reactionType}
|
key={reactionType}
|
||||||
variant={
|
variant={
|
||||||
petPost?.reactions?.me?.last === reactionType
|
petPost?.reactions?.byMe?.value === reactionType
|
||||||
? "default"
|
? "default"
|
||||||
: "outline"
|
: "outline"
|
||||||
}
|
}
|
||||||
@@ -63,26 +61,22 @@ export function RatePetPostUI() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{petPost?.meta.group.myRole() === "admin" && petPost.reactions && (
|
{petPost?._owner.myRole() === "admin" && petPost.reactions && (
|
||||||
<ReactionOverview petReactions={petPost.reactions} />
|
<ReactionOverview petReactions={petPost.reactions} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReactionOverview({
|
function ReactionOverview({ petReactions }: { petReactions: PetReactions }) {
|
||||||
petReactions,
|
|
||||||
}: {
|
|
||||||
petReactions: Resolved<PetReactions>;
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Reactions</h2>
|
<h2>Reactions</h2>
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
{REACTION_TYPES.map((reactionType) => {
|
{ReactionTypes.map((reactionType) => {
|
||||||
const reactionsOfThisType = petReactions.perAccount
|
const reactionsOfThisType = Object.values(
|
||||||
.map(([, reaction]) => reaction)
|
petReactions,
|
||||||
.filter(({ last }) => last === reactionType);
|
).filter((entry) => entry.value === reactionType);
|
||||||
|
|
||||||
if (reactionsOfThisType.length === 0) return null;
|
if (reactionsOfThisType.length === 0) return null;
|
||||||
|
|
||||||
@@ -106,7 +100,7 @@ function ReactionOverview({
|
|||||||
className="mt-1 w-[50px] h-[1em] rounded-full"
|
className="mt-1 w-[50px] h-[1em] rounded-full"
|
||||||
key={idx}
|
key={idx}
|
||||||
/>
|
/>
|
||||||
)
|
),
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { type ClassValue, clsx } from "clsx"
|
import { type ClassValue, clsx } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge"
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export function ThemeProvider({
|
|||||||
...props
|
...props
|
||||||
}: ThemeProviderProps) {
|
}: ThemeProviderProps) {
|
||||||
const [theme, setTheme] = useState(
|
const [theme, setTheme] = useState(
|
||||||
() => localStorage.getItem(storageKey) || defaultTheme
|
() => localStorage.getItem(storageKey) || defaultTheme,
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -35,7 +35,7 @@ export function ThemeProvider({
|
|||||||
|
|
||||||
if (theme === "system") {
|
if (theme === "system") {
|
||||||
const systemTheme = window.matchMedia(
|
const systemTheme = window.matchMedia(
|
||||||
"(prefers-color-scheme: dark)"
|
"(prefers-color-scheme: dark)",
|
||||||
).matches
|
).matches
|
||||||
? "dark"
|
? "dark"
|
||||||
: "light";
|
: "light";
|
||||||
@@ -62,6 +62,7 @@ export function ThemeProvider({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export const useTheme = () => {
|
export const useTheme = () => {
|
||||||
const context = useContext(ThemeProviderContext);
|
const context = useContext(ThemeProviderContext);
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +1,58 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { Slot } from "@radix-ui/react-slot"
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
default:
|
||||||
destructive:
|
"bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
destructive:
|
||||||
outline:
|
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
outline:
|
||||||
secondary:
|
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
||||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
secondary:
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
},
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
size: {
|
},
|
||||||
default: "h-10 px-4 py-2",
|
size: {
|
||||||
sm: "h-9 rounded-md px-3",
|
default: "h-10 px-4 py-2",
|
||||||
lg: "h-11 rounded-md px-8",
|
sm: "h-9 rounded-md px-3",
|
||||||
icon: "h-10 w-10",
|
lg: "h-11 rounded-md px-8",
|
||||||
},
|
icon: "h-10 w-10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
);
|
||||||
variant: "default",
|
|
||||||
size: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export interface ButtonProps
|
export interface ButtonProps
|
||||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
VariantProps<typeof buttonVariants> {
|
VariantProps<typeof buttonVariants> {
|
||||||
asChild?: boolean
|
asChild?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||||
const Comp = asChild ? Slot : "button"
|
const Comp = asChild ? Slot : "button";
|
||||||
return (
|
return (
|
||||||
<Comp
|
<Comp
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
Button.displayName = "Button"
|
Button.displayName = "Button";
|
||||||
|
|
||||||
export { Button, buttonVariants }
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
|
export { Button, buttonVariants };
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
export interface InputProps
|
export interface InputProps
|
||||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
({ className, type, ...props }, ref) => {
|
({ className, type, ...props }, ref) => {
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
type={type}
|
type={type}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
Input.displayName = "Input"
|
Input.displayName = "Input";
|
||||||
|
|
||||||
export { Input }
|
export { Input };
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
function Skeleton({
|
function Skeleton({
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn("animate-pulse rounded-md bg-muted", className)}
|
className={cn("animate-pulse rounded-md bg-muted", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Skeleton }
|
export { Skeleton };
|
||||||
|
|||||||
@@ -1,127 +1,127 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as ToastPrimitives from "@radix-ui/react-toast"
|
import * as ToastPrimitives from "@radix-ui/react-toast";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
import { X } from "lucide-react"
|
import { X } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
const ToastProvider = ToastPrimitives.Provider
|
const ToastProvider = ToastPrimitives.Provider;
|
||||||
|
|
||||||
const ToastViewport = React.forwardRef<
|
const ToastViewport = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Viewport
|
<ToastPrimitives.Viewport
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
|
||||||
|
|
||||||
const toastVariants = cva(
|
const toastVariants = cva(
|
||||||
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "border bg-background text-foreground",
|
default: "border bg-background text-foreground",
|
||||||
destructive:
|
destructive:
|
||||||
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
);
|
||||||
variant: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const Toast = React.forwardRef<
|
const Toast = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
||||||
VariantProps<typeof toastVariants>
|
VariantProps<typeof toastVariants>
|
||||||
>(({ className, variant, ...props }, ref) => {
|
>(({ className, variant, ...props }, ref) => {
|
||||||
return (
|
return (
|
||||||
<ToastPrimitives.Root
|
<ToastPrimitives.Root
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(toastVariants({ variant }), className)}
|
className={cn(toastVariants({ variant }), className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
Toast.displayName = ToastPrimitives.Root.displayName
|
Toast.displayName = ToastPrimitives.Root.displayName;
|
||||||
|
|
||||||
const ToastAction = React.forwardRef<
|
const ToastAction = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Action>,
|
React.ElementRef<typeof ToastPrimitives.Action>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Action
|
<ToastPrimitives.Action
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastAction.displayName = ToastPrimitives.Action.displayName
|
ToastAction.displayName = ToastPrimitives.Action.displayName;
|
||||||
|
|
||||||
const ToastClose = React.forwardRef<
|
const ToastClose = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Close>,
|
React.ElementRef<typeof ToastPrimitives.Close>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Close
|
<ToastPrimitives.Close
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
toast-close=""
|
toast-close=""
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4" />
|
<X className="h-4 w-4" />
|
||||||
</ToastPrimitives.Close>
|
</ToastPrimitives.Close>
|
||||||
))
|
));
|
||||||
ToastClose.displayName = ToastPrimitives.Close.displayName
|
ToastClose.displayName = ToastPrimitives.Close.displayName;
|
||||||
|
|
||||||
const ToastTitle = React.forwardRef<
|
const ToastTitle = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Title
|
<ToastPrimitives.Title
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("text-sm font-semibold", className)}
|
className={cn("text-sm font-semibold", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
||||||
|
|
||||||
const ToastDescription = React.forwardRef<
|
const ToastDescription = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Description>,
|
React.ElementRef<typeof ToastPrimitives.Description>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Description
|
<ToastPrimitives.Description
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("text-sm opacity-90", className)}
|
className={cn("text-sm opacity-90", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
ToastDescription.displayName = ToastPrimitives.Description.displayName;
|
||||||
|
|
||||||
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
|
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
|
||||||
|
|
||||||
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
type ToastActionElement = React.ReactElement<typeof ToastAction>;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
type ToastProps,
|
type ToastProps,
|
||||||
type ToastActionElement,
|
type ToastActionElement,
|
||||||
ToastProvider,
|
ToastProvider,
|
||||||
ToastViewport,
|
ToastViewport,
|
||||||
Toast,
|
Toast,
|
||||||
ToastTitle,
|
ToastTitle,
|
||||||
ToastDescription,
|
ToastDescription,
|
||||||
ToastClose,
|
ToastClose,
|
||||||
ToastAction,
|
ToastAction,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,33 +1,41 @@
|
|||||||
import {
|
import {
|
||||||
Toast,
|
Toast,
|
||||||
ToastClose,
|
ToastClose,
|
||||||
ToastDescription,
|
ToastDescription,
|
||||||
ToastProvider,
|
ToastProvider,
|
||||||
ToastTitle,
|
ToastTitle,
|
||||||
ToastViewport,
|
ToastViewport,
|
||||||
} from "@/basicComponents/ui/toast"
|
} from "@/basicComponents/ui/toast";
|
||||||
import { useToast } from "@/basicComponents/ui/use-toast"
|
import { useToast } from "@/basicComponents/ui/use-toast";
|
||||||
|
|
||||||
export function Toaster() {
|
export function Toaster() {
|
||||||
const { toasts } = useToast()
|
const { toasts } = useToast();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToastProvider>
|
<ToastProvider>
|
||||||
{toasts.map(function ({ id, title, description, action, ...props }) {
|
{toasts.map(function ({
|
||||||
return (
|
id,
|
||||||
<Toast key={id} {...props}>
|
title,
|
||||||
<div className="grid gap-1">
|
description,
|
||||||
{title && <ToastTitle>{title}</ToastTitle>}
|
action,
|
||||||
{description && (
|
...props
|
||||||
<ToastDescription>{description}</ToastDescription>
|
}) {
|
||||||
)}
|
return (
|
||||||
</div>
|
<Toast key={id} {...props}>
|
||||||
{action}
|
<div className="grid gap-1">
|
||||||
<ToastClose />
|
{title && <ToastTitle>{title}</ToastTitle>}
|
||||||
</Toast>
|
{description && (
|
||||||
)
|
<ToastDescription>
|
||||||
})}
|
{description}
|
||||||
<ToastViewport />
|
</ToastDescription>
|
||||||
</ToastProvider>
|
)}
|
||||||
)
|
</div>
|
||||||
|
{action}
|
||||||
|
<ToastClose />
|
||||||
|
</Toast>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<ToastViewport />
|
||||||
|
</ToastProvider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,192 +1,193 @@
|
|||||||
// Inspired by react-hot-toast library
|
// Inspired by react-hot-toast library
|
||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ToastActionElement,
|
ToastActionElement,
|
||||||
ToastProps,
|
ToastProps,
|
||||||
} from "@/basicComponents/ui/toast"
|
} from "@/basicComponents/ui/toast";
|
||||||
|
|
||||||
const TOAST_LIMIT = 1
|
const TOAST_LIMIT = 1;
|
||||||
const TOAST_REMOVE_DELAY = 1000000
|
const TOAST_REMOVE_DELAY = 1000000;
|
||||||
|
|
||||||
type ToasterToast = ToastProps & {
|
type ToasterToast = ToastProps & {
|
||||||
id: string
|
id: string;
|
||||||
title?: React.ReactNode
|
title?: React.ReactNode;
|
||||||
description?: React.ReactNode
|
description?: React.ReactNode;
|
||||||
action?: ToastActionElement
|
action?: ToastActionElement;
|
||||||
}
|
};
|
||||||
|
|
||||||
const actionTypes = {
|
const actionTypes = {
|
||||||
ADD_TOAST: "ADD_TOAST",
|
ADD_TOAST: "ADD_TOAST",
|
||||||
UPDATE_TOAST: "UPDATE_TOAST",
|
UPDATE_TOAST: "UPDATE_TOAST",
|
||||||
DISMISS_TOAST: "DISMISS_TOAST",
|
DISMISS_TOAST: "DISMISS_TOAST",
|
||||||
REMOVE_TOAST: "REMOVE_TOAST",
|
REMOVE_TOAST: "REMOVE_TOAST",
|
||||||
} as const
|
} as const;
|
||||||
|
|
||||||
let count = 0
|
let count = 0;
|
||||||
|
|
||||||
function genId() {
|
function genId() {
|
||||||
count = (count + 1) % Number.MAX_VALUE
|
count = (count + 1) % Number.MAX_VALUE;
|
||||||
return count.toString()
|
return count.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionType = typeof actionTypes
|
type ActionType = typeof actionTypes;
|
||||||
|
|
||||||
type Action =
|
type Action =
|
||||||
| {
|
| {
|
||||||
type: ActionType["ADD_TOAST"]
|
type: ActionType["ADD_TOAST"];
|
||||||
toast: ToasterToast
|
toast: ToasterToast;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: ActionType["UPDATE_TOAST"]
|
type: ActionType["UPDATE_TOAST"];
|
||||||
toast: Partial<ToasterToast>
|
toast: Partial<ToasterToast>;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: ActionType["DISMISS_TOAST"]
|
type: ActionType["DISMISS_TOAST"];
|
||||||
toastId?: ToasterToast["id"]
|
toastId?: ToasterToast["id"];
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: ActionType["REMOVE_TOAST"]
|
type: ActionType["REMOVE_TOAST"];
|
||||||
toastId?: ToasterToast["id"]
|
toastId?: ToasterToast["id"];
|
||||||
}
|
};
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
toasts: ToasterToast[]
|
toasts: ToasterToast[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
||||||
|
|
||||||
const addToRemoveQueue = (toastId: string) => {
|
const addToRemoveQueue = (toastId: string) => {
|
||||||
if (toastTimeouts.has(toastId)) {
|
if (toastTimeouts.has(toastId)) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
toastTimeouts.delete(toastId)
|
toastTimeouts.delete(toastId);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "REMOVE_TOAST",
|
type: "REMOVE_TOAST",
|
||||||
toastId: toastId,
|
toastId: toastId,
|
||||||
})
|
});
|
||||||
}, TOAST_REMOVE_DELAY)
|
}, TOAST_REMOVE_DELAY);
|
||||||
|
|
||||||
toastTimeouts.set(toastId, timeout)
|
toastTimeouts.set(toastId, timeout);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const reducer = (state: State, action: Action): State => {
|
export const reducer = (state: State, action: Action): State => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "ADD_TOAST":
|
case "ADD_TOAST":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
||||||
}
|
};
|
||||||
|
|
||||||
case "UPDATE_TOAST":
|
case "UPDATE_TOAST":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toasts: state.toasts.map((t) =>
|
toasts: state.toasts.map((t) =>
|
||||||
t.id === action.toast.id ? { ...t, ...action.toast } : t
|
t.id === action.toast.id ? { ...t, ...action.toast } : t,
|
||||||
),
|
),
|
||||||
}
|
};
|
||||||
|
|
||||||
case "DISMISS_TOAST": {
|
case "DISMISS_TOAST": {
|
||||||
const { toastId } = action
|
const { toastId } = action;
|
||||||
|
|
||||||
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
||||||
// but I'll keep it here for simplicity
|
// but I'll keep it here for simplicity
|
||||||
if (toastId) {
|
if (toastId) {
|
||||||
addToRemoveQueue(toastId)
|
addToRemoveQueue(toastId);
|
||||||
} else {
|
} else {
|
||||||
state.toasts.forEach((toast) => {
|
state.toasts.forEach((toast) => {
|
||||||
addToRemoveQueue(toast.id)
|
addToRemoveQueue(toast.id);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toasts: state.toasts.map((t) =>
|
toasts: state.toasts.map((t) =>
|
||||||
t.id === toastId || toastId === undefined
|
t.id === toastId || toastId === undefined
|
||||||
? {
|
? {
|
||||||
...t,
|
...t,
|
||||||
open: false,
|
open: false,
|
||||||
}
|
}
|
||||||
: t
|
: t,
|
||||||
),
|
),
|
||||||
}
|
};
|
||||||
}
|
|
||||||
case "REMOVE_TOAST":
|
|
||||||
if (action.toastId === undefined) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
toasts: [],
|
|
||||||
}
|
}
|
||||||
}
|
case "REMOVE_TOAST":
|
||||||
return {
|
if (action.toastId === undefined) {
|
||||||
...state,
|
return {
|
||||||
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
...state,
|
||||||
}
|
toasts: [],
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const listeners: Array<(state: State) => void> = []
|
const listeners: Array<(state: State) => void> = [];
|
||||||
|
|
||||||
let memoryState: State = { toasts: [] }
|
let memoryState: State = { toasts: [] };
|
||||||
|
|
||||||
function dispatch(action: Action) {
|
function dispatch(action: Action) {
|
||||||
memoryState = reducer(memoryState, action)
|
memoryState = reducer(memoryState, action);
|
||||||
listeners.forEach((listener) => {
|
listeners.forEach((listener) => {
|
||||||
listener(memoryState)
|
listener(memoryState);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
type Toast = Omit<ToasterToast, "id">
|
type Toast = Omit<ToasterToast, "id">;
|
||||||
|
|
||||||
function toast({ ...props }: Toast) {
|
function toast({ ...props }: Toast) {
|
||||||
const id = genId()
|
const id = genId();
|
||||||
|
|
||||||
|
const update = (props: ToasterToast) =>
|
||||||
|
dispatch({
|
||||||
|
type: "UPDATE_TOAST",
|
||||||
|
toast: { ...props, id },
|
||||||
|
});
|
||||||
|
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
|
||||||
|
|
||||||
const update = (props: ToasterToast) =>
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "UPDATE_TOAST",
|
type: "ADD_TOAST",
|
||||||
toast: { ...props, id },
|
toast: {
|
||||||
})
|
...props,
|
||||||
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
|
id,
|
||||||
|
open: true,
|
||||||
|
onOpenChange: (open) => {
|
||||||
|
if (!open) dismiss();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
dispatch({
|
return {
|
||||||
type: "ADD_TOAST",
|
id: id,
|
||||||
toast: {
|
dismiss,
|
||||||
...props,
|
update,
|
||||||
id,
|
};
|
||||||
open: true,
|
|
||||||
onOpenChange: (open) => {
|
|
||||||
if (!open) dismiss()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: id,
|
|
||||||
dismiss,
|
|
||||||
update,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function useToast() {
|
function useToast() {
|
||||||
const [state, setState] = React.useState<State>(memoryState)
|
const [state, setState] = React.useState<State>(memoryState);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
listeners.push(setState)
|
listeners.push(setState);
|
||||||
return () => {
|
return () => {
|
||||||
const index = listeners.indexOf(setState)
|
const index = listeners.indexOf(setState);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
listeners.splice(index, 1)
|
listeners.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}, [state])
|
}, [state]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toast,
|
toast,
|
||||||
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
|
dismiss: (toastId?: string) =>
|
||||||
}
|
dispatch({ type: "DISMISS_TOAST", toastId }),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useToast, toast }
|
export { useToast, toast };
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
import { LocalAuthComponent } from "jazz-react-auth-local";
|
import { PasskeyAuth } from "jazz-react";
|
||||||
|
|
||||||
import { Input, Button } from "../basicComponents";
|
import { Input, Button } from "../basicComponents";
|
||||||
|
|
||||||
export const PrettyAuthUI: LocalAuthComponent = ({
|
export const PrettyAuthUI: PasskeyAuth.Component = ({
|
||||||
loading,
|
loading,
|
||||||
logIn,
|
logIn,
|
||||||
signUp,
|
signUp,
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
import { PetPost } from "../1_types";
|
import { PetPost } from "../1_schema";
|
||||||
|
|
||||||
import { Resolved, createInviteLink } from "jazz-react";
|
import { createInviteLink } from "jazz-react";
|
||||||
import QRCode from "qrcode";
|
import QRCode from "qrcode";
|
||||||
|
|
||||||
import { useToast, Button } from "../basicComponents";
|
import { useToast, Button } from "../basicComponents";
|
||||||
|
|
||||||
export function ShareButton({ petPost }: { petPost?: Resolved<PetPost> }) {
|
export function ShareButton({ petPost }: { petPost?: PetPost }) {
|
||||||
const [existingInviteLink, setExistingInviteLink] = useState<string>();
|
const [existingInviteLink, setExistingInviteLink] = useState<string>();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
petPost?.meta.group.myRole() === "admin" && (
|
petPost?._owner.myRole() === "admin" && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
className="py-0"
|
className="py-0"
|
||||||
@@ -34,7 +34,7 @@ export function ShareButton({ petPost }: { petPost?: Resolved<PetPost> }) {
|
|||||||
description: (
|
description: (
|
||||||
<img src={qr} className="w-20 h-20" />
|
<img src={qr} className="w-20 h-20" />
|
||||||
),
|
),
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ module.exports = {
|
|||||||
'eslint:recommended',
|
'eslint:recommended',
|
||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
'plugin:react-hooks/recommended',
|
'plugin:react-hooks/recommended',
|
||||||
|
'prettier'
|
||||||
],
|
],
|
||||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
|
|||||||
9
examples/todo/.prettierrc.js
Normal file
9
examples/todo/.prettierrc.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/** @type {import("prettier").Config} */
|
||||||
|
const config = {
|
||||||
|
trailingComma: "all",
|
||||||
|
tabWidth: 4,
|
||||||
|
semi: true,
|
||||||
|
singleQuote: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
625
examples/todo/CHANGELOG.md
Normal file
625
examples/todo/CHANGELOG.md
Normal file
@@ -0,0 +1,625 @@
|
|||||||
|
# jazz-example-todo
|
||||||
|
|
||||||
|
## 0.0.92
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.28
|
||||||
|
- jazz-tools@0.7.28
|
||||||
|
|
||||||
|
## 0.0.91
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.27
|
||||||
|
|
||||||
|
## 0.0.90
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.26
|
||||||
|
- jazz-tools@0.7.26
|
||||||
|
|
||||||
|
## 0.0.89
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.25
|
||||||
|
- jazz-react@0.7.25
|
||||||
|
|
||||||
|
## 0.0.88
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.24
|
||||||
|
- jazz-react@0.7.24
|
||||||
|
|
||||||
|
## 0.0.87
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.23
|
||||||
|
- jazz-tools@0.7.23
|
||||||
|
|
||||||
|
## 0.0.86
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.22
|
||||||
|
|
||||||
|
## 0.0.85
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.21
|
||||||
|
- jazz-react@0.7.21
|
||||||
|
|
||||||
|
## 0.0.84
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.20
|
||||||
|
- jazz-react@0.7.20
|
||||||
|
|
||||||
|
## 0.0.83
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.19
|
||||||
|
- jazz-react@0.7.19
|
||||||
|
|
||||||
|
## 0.0.82
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.18
|
||||||
|
- jazz-tools@0.7.18
|
||||||
|
|
||||||
|
## 0.0.81
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.17
|
||||||
|
- jazz-tools@0.7.17
|
||||||
|
|
||||||
|
## 0.0.80
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.16
|
||||||
|
- jazz-react@0.7.16
|
||||||
|
|
||||||
|
## 0.0.79
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.15
|
||||||
|
|
||||||
|
## 0.0.78
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.14
|
||||||
|
- jazz-react@0.7.14
|
||||||
|
|
||||||
|
## 0.0.77
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.13
|
||||||
|
- jazz-react@0.7.13
|
||||||
|
|
||||||
|
## 0.0.76
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.12
|
||||||
|
- jazz-react@0.7.12
|
||||||
|
|
||||||
|
## 0.0.75
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.11
|
||||||
|
- jazz-tools@0.7.11
|
||||||
|
|
||||||
|
## 0.0.74
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.10
|
||||||
|
- jazz-tools@0.7.10
|
||||||
|
|
||||||
|
## 0.0.73
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.9
|
||||||
|
- jazz-tools@0.7.9
|
||||||
|
|
||||||
|
## 0.0.72
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.8
|
||||||
|
- jazz-react@0.7.8
|
||||||
|
|
||||||
|
## 0.0.71
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [9fdc91c]
|
||||||
|
- jazz-react@0.7.7
|
||||||
|
|
||||||
|
## 0.0.70
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.6
|
||||||
|
- jazz-react@0.7.6
|
||||||
|
|
||||||
|
## 0.0.69
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.5
|
||||||
|
|
||||||
|
## 0.0.68
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.4
|
||||||
|
|
||||||
|
## 0.0.67
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.3
|
||||||
|
- jazz-react@0.7.3
|
||||||
|
|
||||||
|
## 0.0.66
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.2
|
||||||
|
|
||||||
|
## 0.0.65
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.1
|
||||||
|
- jazz-react@0.7.1
|
||||||
|
|
||||||
|
## 0.0.64
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [96c494f]
|
||||||
|
- Updated dependencies [59c18c3]
|
||||||
|
- Updated dependencies [19f52b7]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [d8fe2b1]
|
||||||
|
- Updated dependencies [19004b4]
|
||||||
|
- Updated dependencies [a78f168]
|
||||||
|
- Updated dependencies [52675c9]
|
||||||
|
- Updated dependencies [129e2c1]
|
||||||
|
- Updated dependencies [6d49e9b]
|
||||||
|
- Updated dependencies [1cfa279]
|
||||||
|
- Updated dependencies [704af7d]
|
||||||
|
- Updated dependencies [e97f730]
|
||||||
|
- Updated dependencies [460478f]
|
||||||
|
- Updated dependencies [6b0418f]
|
||||||
|
- Updated dependencies [e299c3e]
|
||||||
|
- Updated dependencies [ed5643a]
|
||||||
|
- Updated dependencies [bde684f]
|
||||||
|
- Updated dependencies [c4151fc]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [01ac646]
|
||||||
|
- Updated dependencies [a5e68a4]
|
||||||
|
- Updated dependencies [8636319]
|
||||||
|
- Updated dependencies [952982e]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [5fa277c]
|
||||||
|
- Updated dependencies [60d5ca2]
|
||||||
|
- Updated dependencies [21771c4]
|
||||||
|
- Updated dependencies [77c2b56]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [d2e03ff]
|
||||||
|
- Updated dependencies [354bdcd]
|
||||||
|
- Updated dependencies [ece35b3]
|
||||||
|
- Updated dependencies [60d5ca2]
|
||||||
|
- Updated dependencies [69ac514]
|
||||||
|
- Updated dependencies [f8a5c46]
|
||||||
|
- Updated dependencies [f0f6f1b]
|
||||||
|
- Updated dependencies [e5eed5b]
|
||||||
|
- Updated dependencies [1a44f87]
|
||||||
|
- Updated dependencies [627d895]
|
||||||
|
- Updated dependencies [1200aae]
|
||||||
|
- Updated dependencies [63374cc]
|
||||||
|
- Updated dependencies [ece35b3]
|
||||||
|
- Updated dependencies [38d4410]
|
||||||
|
- Updated dependencies [85d2b62]
|
||||||
|
- Updated dependencies [fd86c11]
|
||||||
|
- Updated dependencies [52675c9]
|
||||||
|
- jazz-tools@0.7.0
|
||||||
|
- jazz-react@0.7.0
|
||||||
|
|
||||||
|
## 0.0.64-alpha.42
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.42
|
||||||
|
- jazz-react@0.7.0-alpha.42
|
||||||
|
|
||||||
|
## 0.0.64-alpha.41
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-tools@0.7.0-alpha.41
|
||||||
|
- jazz-react@0.7.0-alpha.41
|
||||||
|
|
||||||
|
## 0.0.64-alpha.40
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.40
|
||||||
|
|
||||||
|
## 0.0.64-alpha.39
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.0-alpha.39
|
||||||
|
- jazz-tools@0.7.0-alpha.39
|
||||||
|
|
||||||
|
## 0.0.64-alpha.38
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.38
|
||||||
|
- jazz-react@0.7.0-alpha.38
|
||||||
|
|
||||||
|
## 0.0.64-alpha.37
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.37
|
||||||
|
- jazz-tools@0.7.0-alpha.37
|
||||||
|
|
||||||
|
## 0.0.64-alpha.36
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- Updated dependencies [6b0418f]
|
||||||
|
- Updated dependencies [1a35307]
|
||||||
|
- jazz-tools@0.7.0-alpha.36
|
||||||
|
- jazz-react@0.7.0-alpha.36
|
||||||
|
|
||||||
|
## 0.0.64-alpha.35
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.35
|
||||||
|
- jazz-react@0.7.0-alpha.35
|
||||||
|
|
||||||
|
## 0.0.64-alpha.34
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.34
|
||||||
|
- jazz-react@0.7.0-alpha.34
|
||||||
|
|
||||||
|
## 0.0.64-alpha.33
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.33
|
||||||
|
|
||||||
|
## 0.0.64-alpha.32
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.32
|
||||||
|
- jazz-react@0.7.0-alpha.32
|
||||||
|
|
||||||
|
## 0.0.64-alpha.31
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.31
|
||||||
|
- jazz-react@0.7.0-alpha.31
|
||||||
|
|
||||||
|
## 0.0.64-alpha.30
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.30
|
||||||
|
- jazz-react@0.7.0-alpha.30
|
||||||
|
|
||||||
|
## 0.0.64-alpha.29
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.29
|
||||||
|
- jazz-react@0.7.0-alpha.29
|
||||||
|
|
||||||
|
## 0.0.64-alpha.28
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.28
|
||||||
|
- jazz-react@0.7.0-alpha.28
|
||||||
|
|
||||||
|
## 0.0.64-alpha.27
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.27
|
||||||
|
- jazz-react@0.7.0-alpha.27
|
||||||
|
|
||||||
|
## 0.0.64-alpha.26
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.26
|
||||||
|
- jazz-react@0.7.0-alpha.26
|
||||||
|
|
||||||
|
## 0.0.64-alpha.25
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.25
|
||||||
|
- jazz-react@0.7.0-alpha.25
|
||||||
|
|
||||||
|
## 0.0.64-alpha.24
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.24
|
||||||
|
- jazz-react@0.7.0-alpha.24
|
||||||
|
|
||||||
|
## 0.0.64-alpha.23
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.23
|
||||||
|
- jazz-react@0.7.0-alpha.23
|
||||||
|
|
||||||
|
## 0.0.64-alpha.22
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.22
|
||||||
|
- jazz-react@0.7.0-alpha.22
|
||||||
|
|
||||||
|
## 0.0.64-alpha.21
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.21
|
||||||
|
- jazz-tools@0.7.0-alpha.21
|
||||||
|
|
||||||
|
## 0.0.64-alpha.20
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.20
|
||||||
|
- jazz-tools@0.7.0-alpha.20
|
||||||
|
|
||||||
|
## 0.0.64-alpha.19
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.19
|
||||||
|
- jazz-react@0.7.0-alpha.19
|
||||||
|
|
||||||
|
## 0.0.64-alpha.18
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- jazz-react@0.7.0-alpha.18
|
||||||
|
|
||||||
|
## 0.0.64-alpha.17
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.17
|
||||||
|
- jazz-react@0.7.0-alpha.17
|
||||||
|
|
||||||
|
## 0.0.64-alpha.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.16
|
||||||
|
- jazz-react@0.7.0-alpha.16
|
||||||
|
|
||||||
|
## 0.0.64-alpha.15
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.15
|
||||||
|
- jazz-react@0.7.0-alpha.15
|
||||||
|
|
||||||
|
## 0.0.64-alpha.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.14
|
||||||
|
- jazz-react@0.7.0-alpha.14
|
||||||
|
|
||||||
|
## 0.0.64-alpha.13
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.13
|
||||||
|
- jazz-react@0.7.0-alpha.13
|
||||||
|
|
||||||
|
## 0.0.64-alpha.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.12
|
||||||
|
- jazz-tools@0.7.0-alpha.12
|
||||||
|
|
||||||
|
## 0.0.64-alpha.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.11
|
||||||
|
- jazz-tools@0.7.0-alpha.11
|
||||||
|
|
||||||
|
## 0.0.64-alpha.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.10
|
||||||
|
- jazz-tools@0.7.0-alpha.10
|
||||||
|
|
||||||
|
## 0.0.64-alpha.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.9
|
||||||
|
- jazz-tools@0.7.0-alpha.9
|
||||||
|
|
||||||
|
## 0.0.64-alpha.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.8
|
||||||
|
- jazz-tools@0.7.0-alpha.8
|
||||||
|
|
||||||
|
## 0.0.64-alpha.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.7
|
||||||
|
- jazz-tools@0.7.0-alpha.7
|
||||||
|
|
||||||
|
## 0.0.64-alpha.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.6
|
||||||
|
- jazz-tools@0.7.0-alpha.6
|
||||||
|
|
||||||
|
## 0.0.64-alpha.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.5
|
||||||
|
- jazz-tools@0.7.0-alpha.5
|
||||||
|
|
||||||
|
## 0.0.64-alpha.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.4
|
||||||
|
- jazz-react@0.7.0-alpha.4
|
||||||
|
|
||||||
|
## 0.0.64-alpha.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-tools@0.7.0-alpha.3
|
||||||
|
- jazz-react@0.7.0-alpha.3
|
||||||
|
|
||||||
|
## 0.0.64-alpha.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.2
|
||||||
|
- jazz-tools@0.7.0-alpha.2
|
||||||
|
|
||||||
|
## 0.0.64-alpha.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.1
|
||||||
|
- jazz-tools@0.7.0-alpha.1
|
||||||
|
|
||||||
|
## 0.0.64-alpha.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.7.0-alpha.0
|
||||||
|
- cojson@0.7.0-alpha.0
|
||||||
|
|
||||||
|
## 0.0.63
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- jazz-react@0.5.0
|
||||||
|
- jazz-react-auth-local@0.4.16
|
||||||
@@ -4,32 +4,37 @@ Live version: https://example-todo.jazz.tools
|
|||||||
|
|
||||||
## Installing & running the example locally
|
## Installing & running the example locally
|
||||||
|
|
||||||
Start by checking out just the example app to a folder:
|
(this requires `pnpm` to be installed, see [https://pnpm.io/installation](https://pnpm.io/installation))
|
||||||
|
|
||||||
|
Start by checking out `jazz`
|
||||||
```bash
|
```bash
|
||||||
npx degit gardencmp/jazz/examples/todo jazz-example-todo
|
git clone https://github.com/gardencmp/jazz.git
|
||||||
cd jazz-example-todo
|
cd jazz/examples/todo
|
||||||
|
pnpm pack --pack-destination /tmp
|
||||||
|
mkdir -p ~/jazz-examples/todo # or any other directory
|
||||||
|
tar -xf /tmp/jazz-example-todo-* --strip-components 1 -C ~/jazz-examples/todo
|
||||||
|
cd ~/jazz-examples/todo
|
||||||
```
|
```
|
||||||
|
|
||||||
(This ensures that you have the example app without git history or our multi-package monorepo)
|
This ensures that you have the example app without git history and independent of the Jazz multi-package monorepo.
|
||||||
|
|
||||||
Install dependencies:
|
Install dependencies:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install
|
pnpm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Start the dev server:
|
Start the dev server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
pnpm dev
|
||||||
```
|
```
|
||||||
|
|
||||||
## Structure
|
## Structure
|
||||||
|
|
||||||
- [`src/basicComponents`](./src/basicComponents): simple components to build the UI, unrelated to Jazz (uses [shadcn/ui](https://ui.shadcn.com))
|
- [`src/basicComponents`](./src/basicComponents): simple components to build the UI, unrelated to Jazz (uses [shadcn/ui](https://ui.shadcn.com))
|
||||||
- [`src/components`](./src/components/): helper components that do contain Jazz-specific logic, but aren't very relevant to understand the basics of Jazz and CoJSON
|
- [`src/components`](./src/components/): helper components that do contain Jazz-specific logic, but aren't very relevant to understand the basics of Jazz and CoJSON
|
||||||
- [`src/1_types.ts`](./src/1_types.ts),
|
- [`src/1_schema.ts`](./src/1_schema.ts),
|
||||||
[`src/2_main.tsx`](./src/2_main.tsx),
|
[`src/2_main.tsx`](./src/2_main.tsx),
|
||||||
[`src/3_NewProjectForm.tsx`](./src/3_NewProjectForm.tsx),
|
[`src/3_NewProjectForm.tsx`](./src/3_NewProjectForm.tsx),
|
||||||
[`src/4_ProjectTodoTable.tsx`](./src/4_ProjectTodoTable.tsx): the main files for this example, see the walkthrough below
|
[`src/4_ProjectTodoTable.tsx`](./src/4_ProjectTodoTable.tsx): the main files for this example, see the walkthrough below
|
||||||
@@ -38,7 +43,7 @@ npm run dev
|
|||||||
|
|
||||||
### Main parts
|
### Main parts
|
||||||
|
|
||||||
1. Defining the data model with CoJSON: [`src/1_types.ts`](./src/1_types.ts)
|
1. Defining the data model with CoJSON: [`src/1_schema.ts`](./src/1_schema.ts)
|
||||||
|
|
||||||
2. The top-level provider `<WithJazz/>` and routing: [`src/2_main.tsx`](./src/2_main.tsx)
|
2. The top-level provider `<WithJazz/>` and routing: [`src/2_main.tsx`](./src/2_main.tsx)
|
||||||
|
|
||||||
@@ -48,7 +53,7 @@ npm run dev
|
|||||||
|
|
||||||
### Helpers
|
### Helpers
|
||||||
|
|
||||||
- (not yet explained) Creating invite links/QR codes with `<InviteButton/>`: [`src/components/InviteButton.tsx`](./src/components/InviteButton.tsx)
|
- (not yet explained) Creating Invite Links/QR codes with `<InviteButton/>`: [`src/components/InviteButton.tsx`](./src/components/InviteButton.tsx)
|
||||||
|
|
||||||
This is the whole Todo List app!
|
This is the whole Todo List app!
|
||||||
|
|
||||||
@@ -61,4 +66,4 @@ If you have feedback, let us know on [Discord](https://discord.gg/utDMjHYg42) or
|
|||||||
|
|
||||||
By default, the example app uses [Jazz Global Mesh](https://jazz.tools/mesh) (`wss://sync.jazz.tools`) - so cross-device use, invites and collaboration should just work.
|
By default, the example app uses [Jazz Global Mesh](https://jazz.tools/mesh) (`wss://sync.jazz.tools`) - so cross-device use, invites and collaboration should just work.
|
||||||
|
|
||||||
You can also run a local sync server by running `npx cojson-simple-sync` and adding the query param `?sync=ws://localhost:4200` to the URL of the example app (for example: `http://localhost:5173/?sync=ws://localhost:4200`), or by setting the `sync` parameter of the `<WithJazz>` provider component in [./src/2_main.tsx](./src/2_main.tsx).
|
You can also run a local sync server by running `npx cojson-simple-sync` and adding the query param `?sync=ws://localhost:4200` to the URL of the example app (for example: `http://localhost:5173/?sync=ws://localhost:4200`), or by setting the `sync` parameter of the `<Jazz.Provider>` provider component in [./src/2_main.tsx](./src/2_main.tsx).
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ job "example-todo$BRANCH_SUFFIX" {
|
|||||||
datacenters = ["*"]
|
datacenters = ["*"]
|
||||||
|
|
||||||
group "static" {
|
group "static" {
|
||||||
count = 8
|
count = 4
|
||||||
|
|
||||||
network {
|
network {
|
||||||
port "http" {
|
port "http" {
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "jazz-example-todo",
|
"name": "jazz-example-todo",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.44",
|
"version": "0.0.92",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
|
"format": "prettier --write './src/**/*.{ts,tsx}'",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{ts,tsx}": "eslint --fix",
|
||||||
|
"*.{js,jsx,mdx,json}": "prettier --write"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-checkbox": "^1.0.4",
|
"@radix-ui/react-checkbox": "^1.0.4",
|
||||||
"@radix-ui/react-slot": "^1.0.2",
|
"@radix-ui/react-slot": "^1.0.2",
|
||||||
@@ -16,8 +21,8 @@
|
|||||||
"@types/qrcode": "^1.5.1",
|
"@types/qrcode": "^1.5.1",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.0.0",
|
"clsx": "^2.0.0",
|
||||||
"jazz-react": "^0.4.7",
|
"jazz-react": "workspace:*",
|
||||||
"jazz-react-auth-local": "^0.4.7",
|
"jazz-tools": "workspace:*",
|
||||||
"lucide-react": "^0.274.0",
|
"lucide-react": "^0.274.0",
|
||||||
"qrcode": "^1.5.3",
|
"qrcode": "^1.5.3",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
@@ -36,6 +41,7 @@
|
|||||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||||
"autoprefixer": "^10.4.14",
|
"autoprefixer": "^10.4.14",
|
||||||
"eslint": "^8.45.0",
|
"eslint": "^8.45.0",
|
||||||
|
"eslint-config-prettier": "^9.1.0",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.3",
|
"eslint-plugin-react-refresh": "^0.4.3",
|
||||||
"postcss": "^8.4.27",
|
"postcss": "^8.4.27",
|
||||||
|
|||||||
55
examples/todo/src/1_schema.ts
Normal file
55
examples/todo/src/1_schema.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { Account, CoList, CoMap, Profile, co } from "jazz-tools";
|
||||||
|
|
||||||
|
/** Walkthrough: Defining the data model with CoJSON
|
||||||
|
*
|
||||||
|
* Here, we define our main data model of tasks, lists of tasks and projects
|
||||||
|
* using CoJSON's collaborative map and list types, CoMap & CoList.
|
||||||
|
*
|
||||||
|
* CoMap values and CoLists items can contain:
|
||||||
|
* - arbitrary immutable JSON
|
||||||
|
* - other CoValues
|
||||||
|
**/
|
||||||
|
|
||||||
|
/** An individual task which collaborators can tick or rename */
|
||||||
|
export class Task extends CoMap {
|
||||||
|
done = co.boolean;
|
||||||
|
text = co.string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ListOfTasks extends CoList.Of(co.ref(Task)) {}
|
||||||
|
|
||||||
|
/** Our top level object: a project with a title, referencing a list of tasks */
|
||||||
|
export class TodoProject extends CoMap {
|
||||||
|
title = co.string;
|
||||||
|
tasks = co.ref(ListOfTasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ListOfProjects extends CoList.Of(co.ref(TodoProject)) {}
|
||||||
|
|
||||||
|
/** The account root is an app-specific per-user private `CoMap`
|
||||||
|
* where you can store top-level objects for that user */
|
||||||
|
export class TodoAccountRoot extends CoMap {
|
||||||
|
projects = co.ref(ListOfProjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TodoAccount extends Account {
|
||||||
|
profile = co.ref(Profile);
|
||||||
|
root = co.ref(TodoAccountRoot);
|
||||||
|
|
||||||
|
/** 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: TodoAccount, creationProps?: { name: string }) {
|
||||||
|
super.migrate(creationProps);
|
||||||
|
if (!this._refs.root) {
|
||||||
|
this.root = TodoAccountRoot.create(
|
||||||
|
{
|
||||||
|
projects: ListOfProjects.create([], { owner: this }),
|
||||||
|
},
|
||||||
|
{ owner: this },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Walkthrough: Continue with ./2_main.tsx */
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { CoMap, CoList, AccountMigration, Profile } from "cojson";
|
|
||||||
|
|
||||||
/** Walkthrough: Defining the data model with CoJSON
|
|
||||||
*
|
|
||||||
* Here, we define our main data model of tasks, lists of tasks and projects
|
|
||||||
* using CoJSON's collaborative map and list types, CoMap & CoList.
|
|
||||||
*
|
|
||||||
* CoMap values and CoLists items can contain:
|
|
||||||
* - arbitrary immutable JSON
|
|
||||||
* - references to other CoValues by their CoID
|
|
||||||
**/
|
|
||||||
|
|
||||||
/** An individual task which collaborators can tick or rename */
|
|
||||||
export type Task = CoMap<{ done: boolean; text: string; }>;
|
|
||||||
|
|
||||||
export type ListOfTasks = CoList<Task["id"]>;
|
|
||||||
|
|
||||||
/** Our top level object: a project with a title, referencing a list of tasks */
|
|
||||||
export type TodoProject = CoMap<{
|
|
||||||
title: string;
|
|
||||||
/** A collaborative, ordered list of tasks */
|
|
||||||
tasks: ListOfTasks["id"];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type ListOfProjects = CoList<TodoProject["id"]>;
|
|
||||||
|
|
||||||
export type TodoAccountRoot = CoMap<{
|
|
||||||
projects: ListOfProjects["id"];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export const migration: AccountMigration<Profile, TodoAccountRoot> = (account) => {
|
|
||||||
if (!account.get("root")) {
|
|
||||||
account.set(
|
|
||||||
"root",
|
|
||||||
account.createMap<TodoAccountRoot>({
|
|
||||||
projects: account.createList<ListOfProjects>().id,
|
|
||||||
}).id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Walkthrough: Continue with ./2_main.tsx */
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from "react";
|
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import {
|
import {
|
||||||
RouterProvider,
|
RouterProvider,
|
||||||
@@ -7,8 +6,7 @@ import {
|
|||||||
} from "react-router-dom";
|
} from "react-router-dom";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
import { WithJazz, useJazz, useAcceptInvite } from "jazz-react";
|
import { createJazzReactContext, PasskeyAuth } from "jazz-react";
|
||||||
import { LocalAuth } from "jazz-react-auth-local";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -18,36 +16,44 @@ import {
|
|||||||
import { PrettyAuthUI } from "./components/Auth.tsx";
|
import { PrettyAuthUI } from "./components/Auth.tsx";
|
||||||
import { NewProjectForm } from "./3_NewProjectForm.tsx";
|
import { NewProjectForm } from "./3_NewProjectForm.tsx";
|
||||||
import { ProjectTodoTable } from "./4_ProjectTodoTable.tsx";
|
import { ProjectTodoTable } from "./4_ProjectTodoTable.tsx";
|
||||||
import { TodoAccountRoot, migration } from "./1_types.ts";
|
import { TodoAccount, TodoProject } from "./1_schema.ts";
|
||||||
import { AccountMigration, Profile } from "cojson";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walkthrough: The top-level provider `<WithJazz/>`
|
* Walkthrough: The top-level provider `<Jazz.Provider/>`
|
||||||
*
|
*
|
||||||
* This shows how to use the top-level provider `<WithJazz/>`,
|
* This shows how to use the top-level provider `<Jazz.Provider/>`,
|
||||||
* which provides the rest of the app with a `LocalNode` (used through `useJazz` later),
|
* which provides the rest of the app with a controlled account (used through `useAccount` later).
|
||||||
* based on `LocalAuth` that uses Passkeys (aka WebAuthn) to store a user's account secret
|
* Here we use `PasskeyAuth`, which uses Passkeys (aka WebAuthn) to store a user's account secret
|
||||||
* - no backend needed.
|
* - no backend needed.
|
||||||
|
*
|
||||||
|
* `<Jazz.Provider/>` also runs our account migration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const appName = "Jazz Todo List Example";
|
const appName = "Jazz Todo List Example";
|
||||||
|
|
||||||
const auth = LocalAuth({
|
const auth = PasskeyAuth<TodoAccount>({
|
||||||
appName,
|
appName,
|
||||||
Component: PrettyAuthUI,
|
Component: PrettyAuthUI,
|
||||||
|
accountSchema: TodoAccount,
|
||||||
});
|
});
|
||||||
|
const Jazz = createJazzReactContext<TodoAccount>({
|
||||||
|
auth,
|
||||||
|
peer: "wss://mesh.jazz.tools/?key=you@example.com",
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
|
export const { useAccount, useCoState, useAcceptInvite } = Jazz;
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||||
<React.StrictMode>
|
// <React.StrictMode>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<TitleAndLogo name={appName} />
|
<TitleAndLogo name={appName} />
|
||||||
<div className="flex flex-col h-full items-center justify-start gap-10 pt-10 pb-10 px-5">
|
<div className="flex flex-col h-full items-center justify-start gap-10 pt-10 pb-10 px-5">
|
||||||
<WithJazz auth={auth} migration={migration as AccountMigration}>
|
<Jazz.Provider>
|
||||||
<App />
|
<App />
|
||||||
</WithJazz>
|
</Jazz.Provider>
|
||||||
</div>
|
</div>
|
||||||
</ThemeProvider>
|
</ThemeProvider>,
|
||||||
</React.StrictMode>
|
// </React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,10 +63,9 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
|||||||
* on the CoValue ID (CoID) of our TodoProject, stored in the URL hash
|
* on the CoValue ID (CoID) of our TodoProject, stored in the URL hash
|
||||||
* - which can also contain invite links.
|
* - which can also contain invite links.
|
||||||
*/
|
*/
|
||||||
|
export default function App() {
|
||||||
function App() {
|
// logOut logs out the AuthProvider passed to `<Jazz.Provider/>` above.
|
||||||
// logOut logs out the AuthProvider passed to `<WithJazz/>` above.
|
const { logOut } = useAccount();
|
||||||
const { logOut } = useJazz();
|
|
||||||
|
|
||||||
const router = createHashRouter([
|
const router = createHashRouter([
|
||||||
{
|
{
|
||||||
@@ -79,7 +84,11 @@ function App() {
|
|||||||
|
|
||||||
// `useAcceptInvite()` is a hook that accepts an invite link from the URL hash,
|
// `useAcceptInvite()` is a hook that accepts an invite link from the URL hash,
|
||||||
// and on success calls our callback where we navigate to the project that we were just invited to.
|
// and on success calls our callback where we navigate to the project that we were just invited to.
|
||||||
useAcceptInvite((projectID) => router.navigate("/project/" + projectID));
|
useAcceptInvite({
|
||||||
|
invitedObjectSchema: TodoProject,
|
||||||
|
forValueHint: "project",
|
||||||
|
onAccept: (projectID) => router.navigate("/project/" + projectID),
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -95,21 +104,23 @@ function App() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function HomeScreen() {
|
function HomeScreen() {
|
||||||
const { me } = useJazz<Profile, TodoAccountRoot>();
|
const { me } = useAccount({
|
||||||
|
root: { projects: [{}] },
|
||||||
|
});
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{me.root?.projects?.length ? <h1>My Projects</h1> : null}
|
{me?.root.projects.length ? <h1>My Projects</h1> : null}
|
||||||
{me.root?.projects?.map((project) => {
|
{me?.root.projects.map((project) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
key={project?.id}
|
key={project.id}
|
||||||
onClick={() => navigate("/project/" + project?.id)}
|
onClick={() => navigate("/project/" + project?.id)}
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
>
|
>
|
||||||
{project?.title}
|
{project.title}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
|
||||||
import { useJazz } from "jazz-react";
|
import { ListOfTasks, TodoProject } from "./1_schema";
|
||||||
|
|
||||||
import { ListOfTasks, TodoAccountRoot, TodoProject } from "./1_types";
|
|
||||||
|
|
||||||
import { SubmittableInput } from "./basicComponents";
|
import { SubmittableInput } from "./basicComponents";
|
||||||
|
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { Profile } from "cojson";
|
import { useAccount } from "./2_main";
|
||||||
|
import { Group } from "jazz-tools";
|
||||||
|
|
||||||
export function NewProjectForm() {
|
export function NewProjectForm() {
|
||||||
// `me` represents the current user account, which will determine
|
// `me` represents the current user account, which will determine
|
||||||
// access rights to CoValues. We get it from the top-level provider `<WithJazz/>`.
|
// access rights to CoValues. We get it from the top-level provider `<WithJazz/>`.
|
||||||
const { me } = useJazz<Profile, TodoAccountRoot>();
|
const { me } = useAccount();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const createProject = useCallback(
|
const createProject = useCallback(
|
||||||
@@ -22,19 +21,22 @@ export function NewProjectForm() {
|
|||||||
// To create a new todo project, we first create a `Group`,
|
// To create a new todo project, we first create a `Group`,
|
||||||
// which is a scope for defining access rights (reader/writer/admin)
|
// which is a scope for defining access rights (reader/writer/admin)
|
||||||
// of its members, which will apply to all CoValues owned by that group.
|
// of its members, which will apply to all CoValues owned by that group.
|
||||||
const projectGroup = me.createGroup();
|
const projectGroup = Group.create({ owner: me });
|
||||||
|
|
||||||
// Then we create an empty todo project within that group
|
// Then we create an empty todo project within that group
|
||||||
const project = projectGroup.createMap<TodoProject>({
|
const project = TodoProject.create(
|
||||||
title,
|
{
|
||||||
tasks: projectGroup.createList<ListOfTasks>().id,
|
title,
|
||||||
});
|
tasks: ListOfTasks.create([], { owner: projectGroup }),
|
||||||
|
},
|
||||||
|
{ owner: projectGroup },
|
||||||
|
);
|
||||||
|
|
||||||
me.root?.projects?.append(project.id);
|
me.root?.projects?.push(project);
|
||||||
|
|
||||||
navigate("/project/" + project.id);
|
navigate("/project/" + project.id);
|
||||||
},
|
},
|
||||||
[me, navigate]
|
[me, navigate],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
|
||||||
import { CoID } from "cojson";
|
import { TodoProject, Task } from "./1_schema";
|
||||||
|
|
||||||
import { TodoProject, Task } from "./1_types";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -19,7 +17,8 @@ import {
|
|||||||
import { InviteButton } from "./components/InviteButton";
|
import { InviteButton } from "./components/InviteButton";
|
||||||
import uniqolor from "uniqolor";
|
import uniqolor from "uniqolor";
|
||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import { Resolved, useAutoSub } from "jazz-react";
|
import { ID } from "jazz-tools";
|
||||||
|
import { useCoState } from "./2_main";
|
||||||
|
|
||||||
/** Walkthrough: Reactively rendering a todo project as a table,
|
/** Walkthrough: Reactively rendering a todo project as a table,
|
||||||
* adding and editing tasks
|
* adding and editing tasks
|
||||||
@@ -30,13 +29,13 @@ import { Resolved, useAutoSub } from "jazz-react";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function ProjectTodoTable() {
|
export function ProjectTodoTable() {
|
||||||
const projectId = useParams<{ projectId: CoID<TodoProject> }>().projectId;
|
const projectId = useParams<{ projectId: ID<TodoProject> }>().projectId;
|
||||||
|
|
||||||
// `useAutoSub()` reactively subscribes to updates to a CoValue's
|
// `useAutoSub()` reactively subscribes to updates to a CoValue's
|
||||||
// content - whether we create edits locally, load persisted data, or receive
|
// content - whether we create edits locally, load persisted data, or receive
|
||||||
// sync updates from other devices or participants!
|
// sync updates from other devices or participants!
|
||||||
// It also recursively resolves and subsribes to all referenced CoValues.
|
// It also recursively resolves and subsribes to all referenced CoValues.
|
||||||
const project = useAutoSub(projectId);
|
const project = useCoState(TodoProject, projectId);
|
||||||
|
|
||||||
// `createTask` is similar to `createProject` we saw earlier, creating a new CoMap
|
// `createTask` is similar to `createProject` we saw earlier, creating a new CoMap
|
||||||
// for a new task (in the same group as the project), and then
|
// for a new task (in the same group as the project), and then
|
||||||
@@ -44,17 +43,18 @@ export function ProjectTodoTable() {
|
|||||||
const createTask = useCallback(
|
const createTask = useCallback(
|
||||||
(text: string) => {
|
(text: string) => {
|
||||||
if (!project?.tasks || !text) return;
|
if (!project?.tasks || !text) return;
|
||||||
const task = project.meta.group.createMap<Task>({
|
const task = Task.create(
|
||||||
done: false,
|
{
|
||||||
text,
|
done: false,
|
||||||
});
|
text,
|
||||||
|
},
|
||||||
|
{ owner: project._owner },
|
||||||
|
);
|
||||||
|
|
||||||
// project.tasks is immutable, but `append` will create an edit
|
// push will cause useCoState to rerender this component, both here and on other devices
|
||||||
// that will cause useAutoSub to rerender this component
|
project.tasks.push(task);
|
||||||
// - here and on other devices!
|
|
||||||
project.tasks.append(task.id);
|
|
||||||
},
|
},
|
||||||
[project?.tasks, project?.meta.group]
|
[project?.tasks, project?._owner],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -74,7 +74,7 @@ export function ProjectTodoTable() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
</h1>
|
</h1>
|
||||||
<InviteButton value={project} />
|
<InviteButton value={project} valueHint="project" />
|
||||||
</div>
|
</div>
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
@@ -85,7 +85,7 @@ export function ProjectTodoTable() {
|
|||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{project?.tasks?.map(
|
{project?.tasks?.map(
|
||||||
(task) => task && <TaskRow key={task.id} task={task} />
|
(task) => task && <TaskRow key={task.id} task={task} />,
|
||||||
)}
|
)}
|
||||||
<NewTaskInputRow
|
<NewTaskInputRow
|
||||||
createTask={createTask}
|
createTask={createTask}
|
||||||
@@ -97,7 +97,7 @@ export function ProjectTodoTable() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TaskRow({ task }: { task: Resolved<Task> | undefined }) {
|
export function TaskRow({ task }: { task: Task | undefined }) {
|
||||||
return (
|
return (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
@@ -108,7 +108,7 @@ export function TaskRow({ task }: { task: Resolved<Task> | undefined }) {
|
|||||||
// Tick or untick the task
|
// Tick or untick the task
|
||||||
// Task is also immutable, but this will update all queries
|
// Task is also immutable, but this will update all queries
|
||||||
// that include this task as a reference
|
// that include this task as a reference
|
||||||
task?.set({ done: !!checked });
|
if (task) task.done = !!checked;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
@@ -124,12 +124,12 @@ export function TaskRow({ task }: { task: Resolved<Task> | undefined }) {
|
|||||||
{
|
{
|
||||||
// Here we see for the first time how we can access edit history
|
// Here we see for the first time how we can access edit history
|
||||||
// for a CoValue, and use it to display who created the task.
|
// for a CoValue, and use it to display who created the task.
|
||||||
task?.meta.edits.text?.by?.profile?.name ? (
|
task?._edits.text?.by?.profile?.name ? (
|
||||||
<span
|
<span
|
||||||
className="rounded-full py-0.5 px-2 text-xs"
|
className="rounded-full py-0.5 px-2 text-xs"
|
||||||
style={uniqueColoring(task.meta.edits.text.by.id)}
|
style={uniqueColoring(task._edits.text.by.id)}
|
||||||
>
|
>
|
||||||
{task.meta.edits.text.by.profile.name}
|
{task._edits.text.by.profile.name}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<Skeleton className="mt-1 w-[50px] h-[1em] rounded-full" />
|
<Skeleton className="mt-1 w-[50px] h-[1em] rounded-full" />
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export function SubmittableInput({
|
|||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const textEl = e.currentTarget.elements.namedItem(
|
const textEl = e.currentTarget.elements.namedItem(
|
||||||
"text"
|
"text",
|
||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
onSubmit(textEl.value);
|
onSubmit(textEl.value);
|
||||||
textEl.value = "";
|
textEl.value = "";
|
||||||
@@ -31,7 +31,11 @@ export function SubmittableInput({
|
|||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
<Button asChild type="submit" className="flex-shrink flex-1 cursor-pointer">
|
<Button
|
||||||
|
asChild
|
||||||
|
type="submit"
|
||||||
|
className="flex-shrink flex-1 cursor-pointer"
|
||||||
|
>
|
||||||
<Input type="submit" value={label} disabled={disabled} />
|
<Input type="submit" value={label} disabled={disabled} />
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { Toaster } from ".";
|
import { Toaster } from ".";
|
||||||
|
|
||||||
export function TitleAndLogo({name}: {name: string}) {
|
export function TitleAndLogo({ name }: { name: string }) {
|
||||||
return <>
|
return (
|
||||||
<div className="flex items-center gap-2 justify-center mt-5">
|
<>
|
||||||
|
<div className="flex items-center gap-2 justify-center mt-5">
|
||||||
<img src="jazz-logo.png" className="h-5" /> {name}
|
<img src="jazz-logo.png" className="h-5" /> {name}
|
||||||
</div>
|
</div>
|
||||||
<Toaster />
|
<Toaster />
|
||||||
</>
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { type ClassValue, clsx } from "clsx"
|
import { type ClassValue, clsx } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge"
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export function ThemeProvider({
|
|||||||
...props
|
...props
|
||||||
}: ThemeProviderProps) {
|
}: ThemeProviderProps) {
|
||||||
const [theme, setTheme] = useState(
|
const [theme, setTheme] = useState(
|
||||||
() => localStorage.getItem(storageKey) || defaultTheme
|
() => localStorage.getItem(storageKey) || defaultTheme,
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -35,7 +35,7 @@ export function ThemeProvider({
|
|||||||
|
|
||||||
if (theme === "system") {
|
if (theme === "system") {
|
||||||
const systemTheme = window.matchMedia(
|
const systemTheme = window.matchMedia(
|
||||||
"(prefers-color-scheme: dark)"
|
"(prefers-color-scheme: dark)",
|
||||||
).matches
|
).matches
|
||||||
? "dark"
|
? "dark"
|
||||||
: "light";
|
: "light";
|
||||||
@@ -62,6 +62,7 @@ export function ThemeProvider({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export const useTheme = () => {
|
export const useTheme = () => {
|
||||||
const context = useContext(ThemeProviderContext);
|
const context = useContext(ThemeProviderContext);
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +1,58 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { Slot } from "@radix-ui/react-slot"
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
default:
|
||||||
destructive:
|
"bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
destructive:
|
||||||
outline:
|
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
outline:
|
||||||
secondary:
|
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
||||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
secondary:
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
},
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
size: {
|
},
|
||||||
default: "h-10 px-4 py-2",
|
size: {
|
||||||
sm: "h-9 rounded-md px-3",
|
default: "h-10 px-4 py-2",
|
||||||
lg: "h-11 rounded-md px-8",
|
sm: "h-9 rounded-md px-3",
|
||||||
icon: "h-10 w-10",
|
lg: "h-11 rounded-md px-8",
|
||||||
},
|
icon: "h-10 w-10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
);
|
||||||
variant: "default",
|
|
||||||
size: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export interface ButtonProps
|
export interface ButtonProps
|
||||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
VariantProps<typeof buttonVariants> {
|
VariantProps<typeof buttonVariants> {
|
||||||
asChild?: boolean
|
asChild?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||||
const Comp = asChild ? Slot : "button"
|
const Comp = asChild ? Slot : "button";
|
||||||
return (
|
return (
|
||||||
<Comp
|
<Comp
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
Button.displayName = "Button"
|
Button.displayName = "Button";
|
||||||
|
|
||||||
export { Button, buttonVariants }
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
|
export { Button, buttonVariants };
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
||||||
import { Check } from "lucide-react"
|
import { Check } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
const Checkbox = React.forwardRef<
|
const Checkbox = React.forwardRef<
|
||||||
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<CheckboxPrimitive.Root
|
<CheckboxPrimitive.Root
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
|
||||||
<CheckboxPrimitive.Indicator
|
|
||||||
className={cn("flex items-center justify-center text-current")}
|
|
||||||
>
|
>
|
||||||
<Check className="h-4 w-4" />
|
<CheckboxPrimitive.Indicator
|
||||||
</CheckboxPrimitive.Indicator>
|
className={cn("flex items-center justify-center text-current")}
|
||||||
</CheckboxPrimitive.Root>
|
>
|
||||||
))
|
<Check className="h-4 w-4" />
|
||||||
Checkbox.displayName = CheckboxPrimitive.Root.displayName
|
</CheckboxPrimitive.Indicator>
|
||||||
|
</CheckboxPrimitive.Root>
|
||||||
|
));
|
||||||
|
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
|
||||||
|
|
||||||
export { Checkbox }
|
export { Checkbox };
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
export interface InputProps
|
export interface InputProps
|
||||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||||
({ className, type, ...props }, ref) => {
|
({ className, type, ...props }, ref) => {
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
type={type}
|
type={type}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
Input.displayName = "Input"
|
Input.displayName = "Input";
|
||||||
|
|
||||||
export { Input }
|
export { Input };
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
function Skeleton({
|
function Skeleton({
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn("animate-pulse rounded-md bg-muted", className)}
|
className={cn("animate-pulse rounded-md bg-muted", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Skeleton }
|
export { Skeleton };
|
||||||
|
|||||||
@@ -1,114 +1,120 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
const Table = React.forwardRef<
|
const Table = React.forwardRef<
|
||||||
HTMLTableElement,
|
HTMLTableElement,
|
||||||
React.HTMLAttributes<HTMLTableElement>
|
React.HTMLAttributes<HTMLTableElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<div className="w-full overflow-auto">
|
<div className="w-full overflow-auto">
|
||||||
<table
|
<table
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("w-full caption-bottom text-sm", className)}
|
className={cn("w-full caption-bottom text-sm", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))
|
));
|
||||||
Table.displayName = "Table"
|
Table.displayName = "Table";
|
||||||
|
|
||||||
const TableHeader = React.forwardRef<
|
const TableHeader = React.forwardRef<
|
||||||
HTMLTableSectionElement,
|
HTMLTableSectionElement,
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
React.HTMLAttributes<HTMLTableSectionElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
||||||
))
|
));
|
||||||
TableHeader.displayName = "TableHeader"
|
TableHeader.displayName = "TableHeader";
|
||||||
|
|
||||||
const TableBody = React.forwardRef<
|
const TableBody = React.forwardRef<
|
||||||
HTMLTableSectionElement,
|
HTMLTableSectionElement,
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
React.HTMLAttributes<HTMLTableSectionElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<tbody
|
<tbody
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("[&_tr:last-child]:border-0", className)}
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
TableBody.displayName = "TableBody"
|
TableBody.displayName = "TableBody";
|
||||||
|
|
||||||
const TableFooter = React.forwardRef<
|
const TableFooter = React.forwardRef<
|
||||||
HTMLTableSectionElement,
|
HTMLTableSectionElement,
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
React.HTMLAttributes<HTMLTableSectionElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<tfoot
|
<tfoot
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("bg-primary font-medium text-primary-foreground", className)}
|
className={cn(
|
||||||
{...props}
|
"bg-primary font-medium text-primary-foreground",
|
||||||
/>
|
className,
|
||||||
))
|
)}
|
||||||
TableFooter.displayName = "TableFooter"
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableFooter.displayName = "TableFooter";
|
||||||
|
|
||||||
const TableRow = React.forwardRef<
|
const TableRow = React.forwardRef<
|
||||||
HTMLTableRowElement,
|
HTMLTableRowElement,
|
||||||
React.HTMLAttributes<HTMLTableRowElement>
|
React.HTMLAttributes<HTMLTableRowElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<tr
|
<tr
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
TableRow.displayName = "TableRow"
|
TableRow.displayName = "TableRow";
|
||||||
|
|
||||||
const TableHead = React.forwardRef<
|
const TableHead = React.forwardRef<
|
||||||
HTMLTableCellElement,
|
HTMLTableCellElement,
|
||||||
React.ThHTMLAttributes<HTMLTableCellElement>
|
React.ThHTMLAttributes<HTMLTableCellElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<th
|
<th
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
|
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
TableHead.displayName = "TableHead"
|
TableHead.displayName = "TableHead";
|
||||||
|
|
||||||
const TableCell = React.forwardRef<
|
const TableCell = React.forwardRef<
|
||||||
HTMLTableCellElement,
|
HTMLTableCellElement,
|
||||||
React.TdHTMLAttributes<HTMLTableCellElement>
|
React.TdHTMLAttributes<HTMLTableCellElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<td
|
<td
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
|
className={cn(
|
||||||
{...props}
|
"p-4 align-middle [&:has([role=checkbox])]:pr-0",
|
||||||
/>
|
className,
|
||||||
))
|
)}
|
||||||
TableCell.displayName = "TableCell"
|
{...props}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
TableCell.displayName = "TableCell";
|
||||||
|
|
||||||
const TableCaption = React.forwardRef<
|
const TableCaption = React.forwardRef<
|
||||||
HTMLTableCaptionElement,
|
HTMLTableCaptionElement,
|
||||||
React.HTMLAttributes<HTMLTableCaptionElement>
|
React.HTMLAttributes<HTMLTableCaptionElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<caption
|
<caption
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
TableCaption.displayName = "TableCaption"
|
TableCaption.displayName = "TableCaption";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Table,
|
Table,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableFooter,
|
TableFooter,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableRow,
|
TableRow,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableCaption,
|
TableCaption,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,127 +1,127 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as ToastPrimitives from "@radix-ui/react-toast"
|
import * as ToastPrimitives from "@radix-ui/react-toast";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
import { X } from "lucide-react"
|
import { X } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/basicComponents/lib/utils"
|
import { cn } from "@/basicComponents/lib/utils";
|
||||||
|
|
||||||
const ToastProvider = ToastPrimitives.Provider
|
const ToastProvider = ToastPrimitives.Provider;
|
||||||
|
|
||||||
const ToastViewport = React.forwardRef<
|
const ToastViewport = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Viewport
|
<ToastPrimitives.Viewport
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
|
||||||
|
|
||||||
const toastVariants = cva(
|
const toastVariants = cva(
|
||||||
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "border bg-background text-foreground",
|
default: "border bg-background text-foreground",
|
||||||
destructive:
|
destructive:
|
||||||
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
);
|
||||||
variant: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const Toast = React.forwardRef<
|
const Toast = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
||||||
VariantProps<typeof toastVariants>
|
VariantProps<typeof toastVariants>
|
||||||
>(({ className, variant, ...props }, ref) => {
|
>(({ className, variant, ...props }, ref) => {
|
||||||
return (
|
return (
|
||||||
<ToastPrimitives.Root
|
<ToastPrimitives.Root
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(toastVariants({ variant }), className)}
|
className={cn(toastVariants({ variant }), className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
Toast.displayName = ToastPrimitives.Root.displayName
|
Toast.displayName = ToastPrimitives.Root.displayName;
|
||||||
|
|
||||||
const ToastAction = React.forwardRef<
|
const ToastAction = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Action>,
|
React.ElementRef<typeof ToastPrimitives.Action>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Action
|
<ToastPrimitives.Action
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastAction.displayName = ToastPrimitives.Action.displayName
|
ToastAction.displayName = ToastPrimitives.Action.displayName;
|
||||||
|
|
||||||
const ToastClose = React.forwardRef<
|
const ToastClose = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Close>,
|
React.ElementRef<typeof ToastPrimitives.Close>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Close
|
<ToastPrimitives.Close
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
toast-close=""
|
toast-close=""
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4" />
|
<X className="h-4 w-4" />
|
||||||
</ToastPrimitives.Close>
|
</ToastPrimitives.Close>
|
||||||
))
|
));
|
||||||
ToastClose.displayName = ToastPrimitives.Close.displayName
|
ToastClose.displayName = ToastPrimitives.Close.displayName;
|
||||||
|
|
||||||
const ToastTitle = React.forwardRef<
|
const ToastTitle = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Title
|
<ToastPrimitives.Title
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("text-sm font-semibold", className)}
|
className={cn("text-sm font-semibold", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
||||||
|
|
||||||
const ToastDescription = React.forwardRef<
|
const ToastDescription = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Description>,
|
React.ElementRef<typeof ToastPrimitives.Description>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Description
|
<ToastPrimitives.Description
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("text-sm opacity-90", className)}
|
className={cn("text-sm opacity-90", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
))
|
));
|
||||||
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
ToastDescription.displayName = ToastPrimitives.Description.displayName;
|
||||||
|
|
||||||
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
|
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
|
||||||
|
|
||||||
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
type ToastActionElement = React.ReactElement<typeof ToastAction>;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
type ToastProps,
|
type ToastProps,
|
||||||
type ToastActionElement,
|
type ToastActionElement,
|
||||||
ToastProvider,
|
ToastProvider,
|
||||||
ToastViewport,
|
ToastViewport,
|
||||||
Toast,
|
Toast,
|
||||||
ToastTitle,
|
ToastTitle,
|
||||||
ToastDescription,
|
ToastDescription,
|
||||||
ToastClose,
|
ToastClose,
|
||||||
ToastAction,
|
ToastAction,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,33 +1,41 @@
|
|||||||
import {
|
import {
|
||||||
Toast,
|
Toast,
|
||||||
ToastClose,
|
ToastClose,
|
||||||
ToastDescription,
|
ToastDescription,
|
||||||
ToastProvider,
|
ToastProvider,
|
||||||
ToastTitle,
|
ToastTitle,
|
||||||
ToastViewport,
|
ToastViewport,
|
||||||
} from "@/basicComponents/ui/toast"
|
} from "@/basicComponents/ui/toast";
|
||||||
import { useToast } from "@/basicComponents/ui/use-toast"
|
import { useToast } from "@/basicComponents/ui/use-toast";
|
||||||
|
|
||||||
export function Toaster() {
|
export function Toaster() {
|
||||||
const { toasts } = useToast()
|
const { toasts } = useToast();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToastProvider>
|
<ToastProvider>
|
||||||
{toasts.map(function ({ id, title, description, action, ...props }) {
|
{toasts.map(function ({
|
||||||
return (
|
id,
|
||||||
<Toast key={id} {...props}>
|
title,
|
||||||
<div className="grid gap-1">
|
description,
|
||||||
{title && <ToastTitle>{title}</ToastTitle>}
|
action,
|
||||||
{description && (
|
...props
|
||||||
<ToastDescription>{description}</ToastDescription>
|
}) {
|
||||||
)}
|
return (
|
||||||
</div>
|
<Toast key={id} {...props}>
|
||||||
{action}
|
<div className="grid gap-1">
|
||||||
<ToastClose />
|
{title && <ToastTitle>{title}</ToastTitle>}
|
||||||
</Toast>
|
{description && (
|
||||||
)
|
<ToastDescription>
|
||||||
})}
|
{description}
|
||||||
<ToastViewport />
|
</ToastDescription>
|
||||||
</ToastProvider>
|
)}
|
||||||
)
|
</div>
|
||||||
|
{action}
|
||||||
|
<ToastClose />
|
||||||
|
</Toast>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<ToastViewport />
|
||||||
|
</ToastProvider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user