jazz-vue 0.8.10 → 0.8.12
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +18 -0
- package/dist/createJazzVueApp.d.ts +2 -2
- package/dist/index.js +159 -151
- package/package.json +4 -4
- package/src/createJazzVueApp.ts +20 -11
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# jazz-react
|
2
2
|
|
3
|
+
## 0.8.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- a734530: fix useCoState reactivity
|
8
|
+
- Updated dependencies [f6bc8af]
|
9
|
+
- jazz-browser@0.8.22
|
10
|
+
|
11
|
+
## 0.8.11
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- Updated dependencies [0f30eea]
|
16
|
+
- Updated dependencies [149ca97]
|
17
|
+
- cojson@0.8.21
|
18
|
+
- jazz-tools@0.8.21
|
19
|
+
- jazz-browser@0.8.21
|
20
|
+
|
3
21
|
## 0.8.10
|
4
22
|
|
5
23
|
### Patch Changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Account, AnonymousJazzAgent, CoValue, CoValueClass, DeeplyLoaded, DepthsIn, ID } from 'jazz-tools';
|
2
|
-
import { Component, ComputedRef, Ref } from 'vue';
|
2
|
+
import { Component, ComputedRef, MaybeRef, Ref } from 'vue';
|
3
3
|
export declare const logoutHandler: Ref<(() => void) | undefined, (() => void) | undefined>;
|
4
4
|
export interface JazzVueApp<Acc extends Account> {
|
5
5
|
JazzProvider: Component;
|
@@ -17,7 +17,7 @@ export interface JazzVueApp<Acc extends Account> {
|
|
17
17
|
useAccountOrGuest<D extends DepthsIn<Acc>>(depth: D): {
|
18
18
|
me: ComputedRef<DeeplyLoaded<Acc, D> | undefined | AnonymousJazzAgent>;
|
19
19
|
};
|
20
|
-
useCoState<V extends CoValue, D>(Schema: CoValueClass<V>, id: ID<V> | undefined
|
20
|
+
useCoState<V extends CoValue, D>(Schema: CoValueClass<V>, id: MaybeRef<ID<V> | undefined>, depth?: D & DepthsIn<V>): Ref<DeeplyLoaded<V, D> | undefined>;
|
21
21
|
useAcceptInvite<V extends CoValue>(args: {
|
22
22
|
invitedObjectSchema: CoValueClass<V>;
|
23
23
|
onAccept: (projectID: ID<V>) => void;
|
package/dist/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { createJazzBrowserContext as D, consumeInviteLinkFromWindowLocation as
|
2
|
-
import { Account as
|
3
|
-
import { ref as
|
4
|
-
const
|
1
|
+
import { createJazzBrowserContext as D, consumeInviteLinkFromWindowLocation as M, BrowserDemoAuth as _ } from "jazz-browser";
|
2
|
+
import { Account as B, subscribeToCoValue as V } from "jazz-tools";
|
3
|
+
import { ref as z, defineComponent as R, provide as j, onMounted as P, watch as I, onUnmounted as k, computed as v, toRaw as w, shallowRef as T, unref as S, inject as N, reactive as $, openBlock as g, createElementBlock as f, normalizeStyle as y, Fragment as C, createElementVNode as x, toDisplayString as J, renderList as E, withModifiers as F, withDirectives as G, vModelText as W, createCommentVNode as L, toRef as q, renderSlot as H } from "vue";
|
4
|
+
const A = z(), O = Symbol("JazzContext");
|
5
5
|
function te({
|
6
|
-
AccountSchema: p =
|
6
|
+
AccountSchema: p = B
|
7
7
|
} = {}) {
|
8
|
-
const
|
8
|
+
const u = R({
|
9
9
|
name: "JazzProvider",
|
10
10
|
props: {
|
11
11
|
auth: {
|
@@ -21,28 +21,28 @@ function te({
|
|
21
21
|
default: void 0
|
22
22
|
}
|
23
23
|
},
|
24
|
-
setup(
|
25
|
-
const
|
24
|
+
setup(t, { slots: o }) {
|
25
|
+
const r = z(
|
26
26
|
void 0
|
27
|
-
),
|
28
|
-
|
29
|
-
const
|
30
|
-
var e,
|
31
|
-
|
27
|
+
), a = z(0);
|
28
|
+
j(O, r);
|
29
|
+
const n = async () => {
|
30
|
+
var e, s;
|
31
|
+
r.value && ((s = (e = r.value).done) == null || s.call(e), r.value = void 0);
|
32
32
|
try {
|
33
33
|
const m = await D(
|
34
|
-
|
34
|
+
t.auth === "guest" ? { peer: t.peer, storage: t.storage } : {
|
35
35
|
AccountSchema: p,
|
36
|
-
auth:
|
37
|
-
peer:
|
38
|
-
storage:
|
36
|
+
auth: t.auth,
|
37
|
+
peer: t.peer,
|
38
|
+
storage: t.storage
|
39
39
|
}
|
40
40
|
);
|
41
|
-
|
41
|
+
r.value = {
|
42
42
|
...m,
|
43
43
|
logOut: () => {
|
44
|
-
var
|
45
|
-
(
|
44
|
+
var b;
|
45
|
+
(b = A.value) == null || b.call(A), a.value += 1;
|
46
46
|
}
|
47
47
|
};
|
48
48
|
} catch (m) {
|
@@ -50,28 +50,29 @@ function te({
|
|
50
50
|
}
|
51
51
|
};
|
52
52
|
return P(() => {
|
53
|
-
|
54
|
-
}),
|
55
|
-
() =>
|
53
|
+
n();
|
54
|
+
}), I(
|
55
|
+
() => a.value,
|
56
56
|
async () => {
|
57
|
-
await
|
57
|
+
await n();
|
58
58
|
}
|
59
|
-
),
|
60
|
-
var e,
|
61
|
-
|
59
|
+
), k(() => {
|
60
|
+
var e, s;
|
61
|
+
r.value && ((s = (e = r.value).done) == null || s.call(e));
|
62
62
|
}), () => {
|
63
63
|
var e;
|
64
|
-
return
|
64
|
+
return r.value ? (e = o.default) == null ? void 0 : e.call(o) : null;
|
65
65
|
};
|
66
66
|
}
|
67
67
|
});
|
68
68
|
function l() {
|
69
|
-
const
|
70
|
-
if (!
|
69
|
+
const t = N(O);
|
70
|
+
if (!t)
|
71
71
|
throw new Error("useJazzContext must be used within a JazzProvider");
|
72
|
-
return
|
72
|
+
return t;
|
73
73
|
}
|
74
|
-
function
|
74
|
+
function i(t) {
|
75
|
+
var n, e;
|
75
76
|
const o = l();
|
76
77
|
if (!o.value)
|
77
78
|
throw new Error("useAccount must be used within a JazzProvider");
|
@@ -79,136 +80,143 @@ function te({
|
|
79
80
|
throw new Error(
|
80
81
|
"useAccount can't be used in a JazzProvider with auth === 'guest' - consider using useAccountOrGuest()"
|
81
82
|
);
|
82
|
-
const
|
83
|
-
o.value.me
|
84
|
-
|
85
|
-
r
|
83
|
+
const r = v(
|
84
|
+
() => "me" in o.value ? o.value.me : void 0
|
85
|
+
), a = d(
|
86
|
+
(n = r.value) == null ? void 0 : n.constructor,
|
87
|
+
(e = r.value) == null ? void 0 : e.id,
|
88
|
+
t
|
86
89
|
);
|
87
90
|
return {
|
88
91
|
me: v(() => {
|
89
|
-
const
|
90
|
-
return
|
92
|
+
const s = t === void 0 ? a.value || w(o.value.me) : a.value;
|
93
|
+
return s && w(s);
|
91
94
|
}),
|
92
95
|
logOut: o.value.logOut
|
93
96
|
};
|
94
97
|
}
|
95
|
-
function c(
|
98
|
+
function c(t) {
|
99
|
+
var n, e;
|
96
100
|
const o = l();
|
97
101
|
if (!o.value)
|
98
102
|
throw new Error("useAccountOrGuest must be used within a JazzProvider");
|
99
|
-
const
|
100
|
-
|
101
|
-
|
102
|
-
r
|
103
|
+
const r = v(
|
104
|
+
() => "me" in o.value ? o.value.me : void 0
|
105
|
+
), a = d(
|
106
|
+
(n = r.value) == null ? void 0 : n.constructor,
|
107
|
+
(e = r.value) == null ? void 0 : e.id,
|
108
|
+
t
|
103
109
|
);
|
104
110
|
return "me" in o.value ? {
|
105
111
|
me: v(
|
106
|
-
() =>
|
112
|
+
() => t === void 0 ? a.value || w(o.value.me) : a.value
|
107
113
|
)
|
108
114
|
} : {
|
109
|
-
me: v(() =>
|
115
|
+
me: v(() => w(o.value.guest))
|
110
116
|
};
|
111
117
|
}
|
112
|
-
function d(
|
113
|
-
const
|
114
|
-
if (!
|
118
|
+
function d(t, o, r = []) {
|
119
|
+
const a = T(void 0), n = l();
|
120
|
+
if (!n.value)
|
115
121
|
throw new Error("useCoState must be used within a JazzProvider");
|
116
122
|
let e;
|
117
|
-
return
|
118
|
-
[() => o, () =>
|
123
|
+
return I(
|
124
|
+
[() => S(o), () => n, () => t, () => r],
|
119
125
|
() => {
|
120
|
-
e && e()
|
121
|
-
|
122
|
-
|
123
|
-
"me" in s.value ? b(s.value.me) : b(s.value.guest),
|
126
|
+
e && e();
|
127
|
+
const m = S(o);
|
128
|
+
m && (e = V(
|
124
129
|
t,
|
125
|
-
|
126
|
-
|
130
|
+
m,
|
131
|
+
"me" in n.value ? w(n.value.me) : w(n.value.guest),
|
132
|
+
r,
|
133
|
+
(b) => {
|
134
|
+
a.value = b;
|
127
135
|
}
|
128
136
|
));
|
129
137
|
},
|
130
|
-
{ immediate: !0 }
|
131
|
-
),
|
138
|
+
{ deep: !0, immediate: !0 }
|
139
|
+
), k(() => {
|
132
140
|
e && e();
|
133
|
-
}), v(() =>
|
141
|
+
}), v(() => a.value);
|
134
142
|
}
|
135
143
|
function h({
|
136
|
-
invitedObjectSchema:
|
144
|
+
invitedObjectSchema: t,
|
137
145
|
onAccept: o,
|
138
|
-
forValueHint:
|
146
|
+
forValueHint: r
|
139
147
|
}) {
|
140
|
-
const
|
141
|
-
if (!
|
148
|
+
const a = l();
|
149
|
+
if (!a.value)
|
142
150
|
throw new Error("useAcceptInvite must be used within a JazzProvider");
|
143
|
-
if (!("me" in
|
151
|
+
if (!("me" in a.value))
|
144
152
|
throw new Error(
|
145
153
|
"useAcceptInvite can't be used in a JazzProvider with auth === 'guest'."
|
146
154
|
);
|
147
|
-
const
|
148
|
-
|
149
|
-
as:
|
150
|
-
invitedObjectSchema:
|
151
|
-
forValueHint:
|
152
|
-
}).then((
|
153
|
-
console.error("Failed to accept invite",
|
155
|
+
const n = () => {
|
156
|
+
M({
|
157
|
+
as: w(a.value.me),
|
158
|
+
invitedObjectSchema: t,
|
159
|
+
forValueHint: r
|
160
|
+
}).then((s) => s && o(s.valueID)).catch((s) => {
|
161
|
+
console.error("Failed to accept invite", s);
|
154
162
|
});
|
155
163
|
};
|
156
164
|
P(() => {
|
157
|
-
|
158
|
-
}),
|
165
|
+
n();
|
166
|
+
}), I(
|
159
167
|
() => o,
|
160
|
-
(e,
|
161
|
-
e !==
|
168
|
+
(e, s) => {
|
169
|
+
e !== s && n();
|
162
170
|
}
|
163
171
|
);
|
164
172
|
}
|
165
173
|
return {
|
166
|
-
JazzProvider:
|
167
|
-
useAccount:
|
174
|
+
JazzProvider: u,
|
175
|
+
useAccount: i,
|
168
176
|
useAccountOrGuest: c,
|
169
177
|
useCoState: d,
|
170
178
|
useAcceptInvite: h
|
171
179
|
};
|
172
180
|
}
|
173
|
-
function
|
181
|
+
function oe({
|
174
182
|
seedAccounts: p
|
175
183
|
} = {}) {
|
176
|
-
const
|
184
|
+
const u = $({
|
177
185
|
state: "loading",
|
178
186
|
errors: []
|
179
|
-
}), l =
|
180
|
-
new
|
187
|
+
}), l = z(
|
188
|
+
new _(
|
181
189
|
{
|
182
|
-
onReady: ({ signUp:
|
183
|
-
|
190
|
+
onReady: ({ signUp: i, existingUsers: c, logInAs: d }) => {
|
191
|
+
u.state = "ready", u.signUp = i, u.existingUsers = c, u.logInAs = d, u.errors = [];
|
184
192
|
},
|
185
|
-
onSignedIn: ({ logOut:
|
186
|
-
|
187
|
-
|
188
|
-
},
|
193
|
+
onSignedIn: ({ logOut: i }) => {
|
194
|
+
u.state = "signedIn", u.logOut = () => {
|
195
|
+
i(), u.state = "ready", u.errors = [];
|
196
|
+
}, u.errors = [], A.value = u.logOut;
|
189
197
|
},
|
190
|
-
onError: (
|
191
|
-
|
198
|
+
onError: (i) => {
|
199
|
+
u.errors.push(i.toString());
|
192
200
|
}
|
193
201
|
},
|
194
202
|
p
|
195
203
|
)
|
196
204
|
);
|
197
|
-
return
|
198
|
-
|
199
|
-
}), { authMethod: l, state:
|
205
|
+
return k(() => {
|
206
|
+
u.state === "signedIn" && (A.value = void 0);
|
207
|
+
}), { authMethod: l, state: u };
|
200
208
|
}
|
201
209
|
const K = { key: 0 }, Q = {
|
202
210
|
key: 0,
|
203
211
|
style: { display: "flex", "flex-direction": "column", gap: "0.5rem" }
|
204
|
-
}, X = ["onClick", "aria-label"],
|
212
|
+
}, X = ["onClick", "aria-label"], re = /* @__PURE__ */ R({
|
205
213
|
__name: "DemoAuthBasicUI",
|
206
214
|
props: {
|
207
215
|
appName: {},
|
208
216
|
state: {}
|
209
217
|
},
|
210
218
|
setup(p) {
|
211
|
-
const
|
219
|
+
const u = p, l = z(""), i = v(
|
212
220
|
() => window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches
|
213
221
|
), c = v(() => ({
|
214
222
|
minHeight: "100vh",
|
@@ -221,77 +229,77 @@ const K = { key: 0 }, Q = {
|
|
221
229
|
maxWidth: "100vw",
|
222
230
|
gap: "2rem",
|
223
231
|
margin: "0",
|
224
|
-
...
|
232
|
+
...i.value ? { background: "#000" } : {}
|
225
233
|
})), d = v(() => ({
|
226
|
-
border:
|
234
|
+
border: i.value ? "2px solid #444" : "2px solid #ddd",
|
227
235
|
padding: "11px 8px",
|
228
236
|
borderRadius: "6px",
|
229
|
-
background:
|
230
|
-
color:
|
237
|
+
background: i.value ? "#000" : "#fff",
|
238
|
+
color: i.value ? "#fff" : "#000"
|
231
239
|
})), h = v(() => ({
|
232
240
|
padding: "13px 5px",
|
233
241
|
border: "none",
|
234
242
|
borderRadius: "6px",
|
235
243
|
cursor: "pointer",
|
236
|
-
background:
|
237
|
-
color:
|
238
|
-
})),
|
239
|
-
background:
|
240
|
-
color:
|
244
|
+
background: i.value ? "#444" : "#ddd",
|
245
|
+
color: i.value ? "#fff" : "#000"
|
246
|
+
})), t = v(() => ({
|
247
|
+
background: i.value ? "#0d0d0d" : "#eee",
|
248
|
+
color: i.value ? "#fff" : "#000",
|
241
249
|
padding: "0.5rem",
|
242
250
|
border: "none",
|
243
251
|
borderRadius: "6px"
|
244
252
|
})), o = () => {
|
245
|
-
|
246
|
-
},
|
247
|
-
|
253
|
+
u.state.signUp(l.value), l.value = "";
|
254
|
+
}, r = (a) => {
|
255
|
+
u.state.logInAs(a);
|
248
256
|
};
|
249
|
-
return (
|
250
|
-
style:
|
257
|
+
return (a, n) => (g(), f("div", {
|
258
|
+
style: y(c.value)
|
251
259
|
}, [
|
252
|
-
|
260
|
+
a.state.state === "loading" ? (g(), f("div", K, "Loading...")) : a.state.state === "ready" ? (g(), f(C, { key: 1 }, [
|
253
261
|
x("h1", {
|
254
|
-
style:
|
255
|
-
},
|
256
|
-
(g(!0), f(
|
262
|
+
style: y({ color: i.value ? "#fff" : "#000", textAlign: "center" })
|
263
|
+
}, J(a.appName), 5),
|
264
|
+
(g(!0), f(C, null, E(a.state.errors, (e) => (g(), f("div", {
|
257
265
|
key: e,
|
258
266
|
style: { color: "red" }
|
259
|
-
},
|
267
|
+
}, J(e), 1))), 128)),
|
260
268
|
x("form", {
|
261
269
|
onSubmit: F(o, ["prevent"]),
|
262
270
|
style: { display: "flex", "flex-direction": "column", gap: "0.5rem" }
|
263
271
|
}, [
|
264
272
|
G(x("input", {
|
265
|
-
"onUpdate:modelValue":
|
273
|
+
"onUpdate:modelValue": n[0] || (n[0] = (e) => l.value = e),
|
266
274
|
placeholder: "Display name",
|
267
275
|
autoComplete: "webauthn",
|
268
|
-
style:
|
276
|
+
style: y(d.value)
|
269
277
|
}, null, 4), [
|
270
278
|
[W, l.value]
|
271
279
|
]),
|
272
280
|
x("input", {
|
273
281
|
type: "submit",
|
274
282
|
value: "Sign up",
|
275
|
-
style:
|
283
|
+
style: y(h.value)
|
276
284
|
}, null, 4)
|
277
285
|
], 32),
|
278
|
-
|
286
|
+
a.state.existingUsers.length > 0 ? (g(), f("div", Q, [
|
279
287
|
x("p", {
|
280
|
-
style:
|
281
|
-
color:
|
288
|
+
style: y({
|
289
|
+
color: i.value ? "#e2e2e2" : "#000",
|
282
290
|
textAlign: "center",
|
283
291
|
paddingTop: "0.5rem",
|
284
292
|
borderTop: "1px solid",
|
285
|
-
borderColor:
|
293
|
+
borderColor: i.value ? "#111" : "#e2e2e2"
|
286
294
|
})
|
287
295
|
}, " Log in as ", 4),
|
288
|
-
(g(!0), f(
|
296
|
+
(g(!0), f(C, null, E(a.state.existingUsers, (e) => (g(), f("button", {
|
289
297
|
key: e,
|
290
|
-
onClick: (
|
298
|
+
onClick: (s) => r(e),
|
291
299
|
type: "button",
|
292
300
|
"aria-label": `Log in as ${e}`,
|
293
|
-
style:
|
294
|
-
},
|
301
|
+
style: y(t.value)
|
302
|
+
}, J(e), 13, X))), 128))
|
295
303
|
])) : L("", !0)
|
296
304
|
], 64)) : L("", !0)
|
297
305
|
], 4));
|
@@ -303,59 +311,59 @@ const K = { key: 0 }, Q = {
|
|
303
311
|
maxWidth: {}
|
304
312
|
},
|
305
313
|
setup(p) {
|
306
|
-
function
|
307
|
-
const h =
|
308
|
-
let
|
309
|
-
const o =
|
314
|
+
function u(c, d) {
|
315
|
+
const h = z({});
|
316
|
+
let t;
|
317
|
+
const o = I(
|
310
318
|
() => {
|
311
|
-
var
|
312
|
-
return [(
|
319
|
+
var r;
|
320
|
+
return [(r = c.value) == null ? void 0 : r.id, d];
|
313
321
|
},
|
314
322
|
() => {
|
315
|
-
let
|
316
|
-
return c.value ? c.value.subscribe({}, (
|
317
|
-
var
|
318
|
-
const e =
|
323
|
+
let r;
|
324
|
+
return c.value ? c.value.subscribe({}, (n) => {
|
325
|
+
var s, m;
|
326
|
+
const e = n == null ? void 0 : n.highestResAvailable({ maxWidth: d });
|
319
327
|
if (e) {
|
320
|
-
if (e.res !==
|
321
|
-
|
322
|
-
const
|
323
|
-
if (
|
324
|
-
const U = URL.createObjectURL(
|
328
|
+
if (e.res !== r) {
|
329
|
+
r = e.res;
|
330
|
+
const b = e.stream.toBlob();
|
331
|
+
if (b) {
|
332
|
+
const U = URL.createObjectURL(b);
|
325
333
|
h.value = {
|
326
334
|
src: U,
|
327
335
|
res: e.res,
|
328
|
-
originalSize: (
|
329
|
-
},
|
336
|
+
originalSize: (s = c.value) == null ? void 0 : s.originalSize
|
337
|
+
}, t && t(), t = () => {
|
330
338
|
setTimeout(() => URL.revokeObjectURL(U), 200);
|
331
339
|
};
|
332
340
|
}
|
333
341
|
}
|
334
342
|
} else
|
335
343
|
h.value = {
|
336
|
-
src:
|
344
|
+
src: n == null ? void 0 : n.placeholderDataURL,
|
337
345
|
res: "placeholder",
|
338
346
|
originalSize: (m = c.value) == null ? void 0 : m.originalSize
|
339
347
|
};
|
340
348
|
}) : void 0;
|
341
349
|
}
|
342
350
|
);
|
343
|
-
return
|
344
|
-
o(),
|
351
|
+
return k(() => {
|
352
|
+
o(), t && t();
|
345
353
|
}), h;
|
346
354
|
}
|
347
|
-
const l = p,
|
355
|
+
const l = p, i = u(q(l, "image"), l.maxWidth);
|
348
356
|
return (c, d) => H(c.$slots, "default", {
|
349
|
-
src:
|
350
|
-
res:
|
351
|
-
originalSize:
|
357
|
+
src: S(i).src,
|
358
|
+
res: S(i).res,
|
359
|
+
originalSize: S(i).originalSize
|
352
360
|
});
|
353
361
|
}
|
354
362
|
});
|
355
363
|
export {
|
356
|
-
|
364
|
+
re as DemoAuthBasicUI,
|
357
365
|
ne as ProgressiveImg,
|
358
366
|
te as createJazzVueApp,
|
359
|
-
|
360
|
-
|
367
|
+
A as logoutHandler,
|
368
|
+
oe as useDemoAuth
|
361
369
|
};
|
package/package.json
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-vue",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.12",
|
4
4
|
"type": "module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "src/index.ts",
|
7
7
|
"license": "MIT",
|
8
8
|
"dependencies": {
|
9
9
|
"@scure/bip39": "^1.3.0",
|
10
|
-
"cojson": "0.8.
|
11
|
-
"jazz-browser": "0.8.
|
12
|
-
"jazz-tools": "0.8.
|
10
|
+
"cojson": "0.8.21",
|
11
|
+
"jazz-browser": "0.8.22",
|
12
|
+
"jazz-tools": "0.8.21"
|
13
13
|
},
|
14
14
|
"devDependencies": {
|
15
15
|
"@vitejs/plugin-vue": "^5.1.4",
|
package/src/createJazzVueApp.ts
CHANGED
@@ -19,6 +19,7 @@ import {
|
|
19
19
|
import {
|
20
20
|
Component,
|
21
21
|
ComputedRef,
|
22
|
+
MaybeRef,
|
22
23
|
PropType,
|
23
24
|
Ref,
|
24
25
|
ShallowRef,
|
@@ -31,6 +32,7 @@ import {
|
|
31
32
|
ref,
|
32
33
|
shallowRef,
|
33
34
|
toRaw,
|
35
|
+
unref,
|
34
36
|
watch,
|
35
37
|
} from "vue";
|
36
38
|
|
@@ -56,7 +58,7 @@ export interface JazzVueApp<Acc extends Account> {
|
|
56
58
|
|
57
59
|
useCoState<V extends CoValue, D>(
|
58
60
|
Schema: CoValueClass<V>,
|
59
|
-
id: ID<V> | undefined
|
61
|
+
id: MaybeRef<ID<V> | undefined>,
|
60
62
|
depth?: D & DepthsIn<V>,
|
61
63
|
): Ref<DeeplyLoaded<V, D> | undefined>;
|
62
64
|
|
@@ -181,9 +183,13 @@ export function createJazzVueApp<Acc extends Account>({
|
|
181
183
|
);
|
182
184
|
}
|
183
185
|
|
186
|
+
const contextMe = computed(() =>
|
187
|
+
"me" in context.value ? context.value.me : undefined,
|
188
|
+
);
|
189
|
+
|
184
190
|
const me = useCoState<Acc, D>(
|
185
|
-
|
186
|
-
|
191
|
+
contextMe.value?.constructor as CoValueClass<Acc>,
|
192
|
+
contextMe.value?.id,
|
187
193
|
depth,
|
188
194
|
);
|
189
195
|
|
@@ -219,11 +225,13 @@ export function createJazzVueApp<Acc extends Account>({
|
|
219
225
|
throw new Error("useAccountOrGuest must be used within a JazzProvider");
|
220
226
|
}
|
221
227
|
|
222
|
-
const contextMe =
|
228
|
+
const contextMe = computed(() =>
|
229
|
+
"me" in context.value ? context.value.me : undefined,
|
230
|
+
);
|
223
231
|
|
224
232
|
const me = useCoState<Acc, D>(
|
225
|
-
contextMe?.constructor as CoValueClass<Acc>,
|
226
|
-
contextMe?.id,
|
233
|
+
contextMe.value?.constructor as CoValueClass<Acc>,
|
234
|
+
contextMe.value?.id,
|
227
235
|
depth,
|
228
236
|
);
|
229
237
|
|
@@ -244,7 +252,7 @@ export function createJazzVueApp<Acc extends Account>({
|
|
244
252
|
|
245
253
|
function useCoState<V extends CoValue, D>(
|
246
254
|
Schema: CoValueClass<V>,
|
247
|
-
id: ID<V> | undefined
|
255
|
+
id: MaybeRef<ID<V> | undefined>,
|
248
256
|
depth: D & DepthsIn<V> = [] as D & DepthsIn<V>,
|
249
257
|
): Ref<DeeplyLoaded<V, D> | undefined> {
|
250
258
|
const state: ShallowRef<DeeplyLoaded<V, D> | undefined> =
|
@@ -258,15 +266,16 @@ export function createJazzVueApp<Acc extends Account>({
|
|
258
266
|
let unsubscribe: (() => void) | undefined;
|
259
267
|
|
260
268
|
watch(
|
261
|
-
[() => id, () => context, () => Schema, () => depth],
|
269
|
+
[() => unref(id), () => context, () => Schema, () => depth],
|
262
270
|
() => {
|
263
271
|
if (unsubscribe) unsubscribe();
|
264
272
|
|
265
|
-
|
273
|
+
const idValue = unref(id);
|
274
|
+
if (!idValue) return;
|
266
275
|
|
267
276
|
unsubscribe = subscribeToCoValue(
|
268
277
|
Schema,
|
269
|
-
|
278
|
+
idValue,
|
270
279
|
"me" in context.value
|
271
280
|
? toRaw(context.value.me)
|
272
281
|
: toRaw(context.value.guest),
|
@@ -276,7 +285,7 @@ export function createJazzVueApp<Acc extends Account>({
|
|
276
285
|
},
|
277
286
|
);
|
278
287
|
},
|
279
|
-
{ immediate: true },
|
288
|
+
{ deep: true, immediate: true },
|
280
289
|
);
|
281
290
|
|
282
291
|
onUnmounted(() => {
|