jazz-vue 0.8.50 → 0.9.0

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