@graffiti-garden/wrapper-vue 0.7.2 → 1.0.4

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.
Files changed (70) hide show
  1. package/README.md +2 -3
  2. package/dist/browser/ajv-D_HICdxS.mjs +4447 -0
  3. package/dist/browser/ajv-D_HICdxS.mjs.map +1 -0
  4. package/dist/browser/plugin.mjs +1003 -943
  5. package/dist/browser/plugin.mjs.map +1 -1
  6. package/dist/node/components/ActorToHandle.vue.d.ts +23 -0
  7. package/dist/node/components/ActorToHandle.vue.d.ts.map +1 -0
  8. package/dist/node/{Discover.vue.d.ts → components/Discover.vue.d.ts} +4 -4
  9. package/dist/node/components/Discover.vue.d.ts.map +1 -0
  10. package/dist/node/{Get.vue.d.ts → components/Get.vue.d.ts} +2 -5
  11. package/dist/node/components/Get.vue.d.ts.map +1 -0
  12. package/dist/node/components/GetMedia.vue.d.ts +36 -0
  13. package/dist/node/components/GetMedia.vue.d.ts.map +1 -0
  14. package/dist/node/components/HandleToActor.vue.d.ts +23 -0
  15. package/dist/node/components/HandleToActor.vue.d.ts.map +1 -0
  16. package/dist/node/components/ObjectInfo.vue.d.ts +7 -0
  17. package/dist/node/components/ObjectInfo.vue.d.ts.map +1 -0
  18. package/dist/node/composables/actor-to-handle.d.ts +25 -0
  19. package/dist/node/composables/actor-to-handle.d.ts.map +1 -0
  20. package/dist/node/composables/discover.d.ts +38 -0
  21. package/dist/node/composables/discover.d.ts.map +1 -0
  22. package/dist/node/composables/get-media.d.ts +31 -0
  23. package/dist/node/composables/get-media.d.ts.map +1 -0
  24. package/dist/node/composables/get.d.ts +28 -0
  25. package/dist/node/composables/get.d.ts.map +1 -0
  26. package/dist/node/composables/handle-to-actor.d.ts +25 -0
  27. package/dist/node/composables/handle-to-actor.d.ts.map +1 -0
  28. package/dist/node/composables/resolve-string.d.ts +6 -0
  29. package/dist/node/composables/resolve-string.d.ts.map +1 -0
  30. package/dist/node/globals.d.ts +3 -5
  31. package/dist/node/globals.d.ts.map +1 -1
  32. package/dist/node/plugin.d.ts +174 -75
  33. package/dist/node/plugin.d.ts.map +1 -1
  34. package/dist/node/plugin.js +1 -1
  35. package/dist/node/plugin.js.map +1 -1
  36. package/dist/node/plugin.mjs +468 -333
  37. package/dist/node/plugin.mjs.map +1 -1
  38. package/package.json +15 -14
  39. package/src/components/ActorToHandle.vue +16 -0
  40. package/src/{Discover.vue → components/Discover.vue} +15 -9
  41. package/src/{Get.vue → components/Get.vue} +7 -11
  42. package/src/components/GetMedia.vue +75 -0
  43. package/src/components/HandleToActor.vue +16 -0
  44. package/src/components/ObjectInfo.vue +127 -0
  45. package/src/composables/actor-to-handle.ts +32 -0
  46. package/src/composables/discover.ts +202 -0
  47. package/src/composables/get-media.ts +116 -0
  48. package/src/composables/get.ts +109 -0
  49. package/src/composables/handle-to-actor.ts +32 -0
  50. package/src/composables/resolve-string.ts +46 -0
  51. package/src/globals.ts +24 -2
  52. package/src/plugin.ts +84 -29
  53. package/dist/browser/ajv-C30pimY5.mjs +0 -4400
  54. package/dist/browser/ajv-C30pimY5.mjs.map +0 -1
  55. package/dist/browser/index-CWfNKdDL.mjs +0 -424
  56. package/dist/browser/index-CWfNKdDL.mjs.map +0 -1
  57. package/dist/node/Discover.vue.d.ts.map +0 -1
  58. package/dist/node/Get.vue.d.ts.map +0 -1
  59. package/dist/node/RecoverOrphans.vue.d.ts +0 -31
  60. package/dist/node/RecoverOrphans.vue.d.ts.map +0 -1
  61. package/dist/node/composables.d.ts +0 -75
  62. package/dist/node/composables.d.ts.map +0 -1
  63. package/dist/node/pollers.d.ts +0 -28
  64. package/dist/node/pollers.d.ts.map +0 -1
  65. package/dist/node/reducers.d.ts +0 -37
  66. package/dist/node/reducers.d.ts.map +0 -1
  67. package/src/RecoverOrphans.vue +0 -37
  68. package/src/composables.ts +0 -347
  69. package/src/pollers.ts +0 -119
  70. package/src/reducers.ts +0 -124
@@ -1,298 +1,272 @@
1
- var M = Object.defineProperty;
2
- var B = (e, t, r) => t in e ? M(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var m = (e, t, r) => B(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { ref as G, computed as L, watch as k, onScopeDispose as A, toValue as d, defineComponent as S, toRef as u, renderSlot as R, unref as g } from "vue";
5
- import { GraffitiSynchronize as C } from "@graffiti-garden/wrapper-synchronize";
6
- const b = {};
7
- function w() {
8
- const e = b.graffitiSynchronize;
1
+ import { ref as w, onScopeDispose as _, watch as P, toValue as b, defineComponent as A, toRef as h, renderSlot as L, unref as s, createElementVNode as r, toDisplayString as G, createElementBlock as u, openBlock as c, createVNode as T, createCommentVNode as V, Fragment as C, renderList as F } from "vue";
2
+ import { GraffitiSynchronize as ee } from "@graffiti-garden/wrapper-synchronize";
3
+ var D = class q extends Error {
4
+ constructor(i) {
5
+ super(i), this.name = "GraffitiErrorNotFound", Object.setPrototypeOf(this, q.prototype);
6
+ }
7
+ };
8
+ const k = {};
9
+ function te(e) {
10
+ if (!k.graffitiSession)
11
+ k.graffitiSession = e;
12
+ else
13
+ throw new Error(
14
+ "Graffiti session already set - plugin installed multiple times?"
15
+ );
16
+ }
17
+ function oe(e) {
18
+ if (!k.graffitiSynchronize)
19
+ k.graffitiSynchronize = e;
20
+ else
21
+ throw new Error(
22
+ "Graffiti synchronize already set - plugin installed multiple times?"
23
+ );
24
+ }
25
+ function H() {
26
+ const e = k.graffitiSynchronize;
9
27
  if (!e)
10
28
  throw new Error(
11
29
  "No Graffiti instance provided, did you forget to install the plugin?"
12
30
  );
13
31
  return e;
14
32
  }
15
- function X() {
16
- return w();
33
+ function W() {
34
+ return H();
17
35
  }
18
- function F() {
19
- const e = b.graffitiSession;
36
+ function Pe() {
37
+ const e = k.graffitiSession;
20
38
  if (!e)
21
39
  throw new Error(
22
40
  "No Graffiti session provided, did you forget to install the plugin?"
23
41
  );
24
42
  return e;
25
43
  }
26
- var J = class _ extends Error {
27
- constructor(t) {
28
- super(t), this.name = "GraffitiErrorNotFound", Object.setPrototypeOf(this, _.prototype);
29
- }
30
- };
31
- class U {
32
- constructor(t) {
33
- m(this, "poll", async (t) => {
34
- let r;
35
- const o = this.getter;
36
- try {
37
- r = await o();
38
- } catch {
39
- this.getter === o && t(null);
40
- return;
41
- }
42
- this.getter === o && t({ object: r });
44
+ function ne(e, i, o, a = !1) {
45
+ const l = H(), t = /* @__PURE__ */ new Map(), n = w([]);
46
+ let f = async () => {
47
+ };
48
+ const p = async () => f(), m = w(!0);
49
+ let S, g;
50
+ _(() => {
51
+ S?.return(null), g?.return({
52
+ continue: () => g,
53
+ cursor: ""
43
54
  });
44
- this.getter = t;
45
- }
46
- clear() {
55
+ });
56
+ const j = w(0);
57
+ function v(d = 0) {
58
+ setTimeout(() => {
59
+ j.value++;
60
+ }, d);
47
61
  }
48
- }
49
- class O {
50
- constructor(t) {
51
- m(this, "iterator");
52
- m(this, "continue");
53
- m(this, "poll", async (t) => {
54
- if (!this.iterator)
55
- if (this.continue)
62
+ return P(
63
+ () => ({
64
+ args: [b(e), b(i), b(o)],
65
+ refresh: j.value
66
+ }),
67
+ ({ args: d }, x, z) => {
68
+ t.clear(), n.value = [], m.value = !0;
69
+ const I = l.synchronizeDiscover(...d);
70
+ S = I;
71
+ let E, $ = !0;
72
+ z(() => {
73
+ $ = !1, I.return(null), E?.return({
74
+ continue: () => g,
75
+ cursor: ""
76
+ });
77
+ });
78
+ let U;
79
+ (async () => {
80
+ for await (const y of I) {
81
+ if (!$) break;
82
+ y.tombstone ? t.delete(y.object.url) : t.set(y.object.url, y.object), U || (U = new Promise((N) => {
83
+ setTimeout(() => {
84
+ $ && (n.value = Array.from(t.values())), U = void 0, N();
85
+ }, 50);
86
+ }));
87
+ }
88
+ })();
89
+ let M = !1, B = () => l.discover(...d);
90
+ f = async () => {
91
+ if (!(M || !$)) {
92
+ M = !0;
56
93
  try {
57
- this.iterator = this.continue();
58
- } catch (r) {
59
- if (r instanceof J)
60
- t("clear"), this.iterator = this.streamFactory();
61
- else
62
- throw r;
63
- }
64
- else
65
- this.iterator = this.streamFactory();
66
- for (; this.iterator; ) {
67
- const r = this.iterator, o = await r.next();
68
- if (r === this.iterator) {
69
- if (o.done) {
70
- this.iterator = void 0, o.value && (this.continue = o.value.continue);
71
- break;
94
+ E = B(d[2]);
95
+ } catch {
96
+ return v(5e3);
72
97
  }
73
- if (o.value.error) {
74
- console.error(o.value.error);
75
- continue;
98
+ if ($) {
99
+ for (g = E; ; ) {
100
+ let y;
101
+ try {
102
+ y = await E.next();
103
+ } catch (N) {
104
+ return N instanceof D ? v() : v(5e3);
105
+ }
106
+ if (!$) return;
107
+ if (y.done) {
108
+ B = y.value.continue;
109
+ break;
110
+ } else y.value.error && console.error(y.value.error);
111
+ }
112
+ await new Promise((y) => setTimeout(y, 0)), U && await U, $ && (M = !1, m.value = !1, b(a) && p());
76
113
  }
77
- t(o.value);
78
114
  }
79
- }
80
- });
81
- this.streamFactory = t;
82
- }
83
- clear() {
84
- if (this.iterator) {
85
- const t = this.iterator;
86
- this.iterator.return({
87
- continue: () => t,
88
- cursor: ""
89
- });
90
- }
91
- this.iterator = void 0, this.continue = void 0;
92
- }
93
- }
94
- function z(e, t) {
95
- return !t || e.object.lastModified > t.object.lastModified || e.object.lastModified === t.object.lastModified && !e.tombstone && !!t.tombstone;
96
- }
97
- class V {
98
- constructor() {
99
- m(this, "entry", G());
100
- }
101
- get result() {
102
- return L(() => {
103
- const t = this.entry.value;
104
- return t && (t.tombstone ? null : t.object);
105
- });
106
- }
107
- clear() {
108
- this.entry.value = void 0;
109
- }
110
- onEntry(t) {
111
- if (t === "clear") {
112
- this.clear();
113
- return;
114
- }
115
- (!t || z(t, this.entry.value)) && (this.entry.value = t);
116
- }
117
- }
118
- class T {
119
- constructor(t) {
120
- m(this, "results", G([]));
121
- m(this, "resultsRaw", /* @__PURE__ */ new Map());
122
- m(this, "batchFlattenTimer");
123
- this.graffiti = t;
124
- }
125
- clear() {
126
- this.resultsRaw.clear(), this.results.value = [], clearTimeout(this.batchFlattenTimer), this.batchFlattenTimer = void 0;
127
- }
128
- flattenResults() {
129
- this.results.value = Array.from(this.resultsRaw.values()).reduce((t, r) => (r.tombstone || t.push(r.object), t), []);
130
- }
131
- onEntry(t) {
132
- if (!t) return;
133
- if (t === "clear") {
134
- this.clear();
135
- return;
136
- }
137
- const r = this.resultsRaw.get(t.object.url);
138
- z(t, r) && (this.resultsRaw.set(t.object.url, t), this.batchFlattenTimer || (this.batchFlattenTimer = setTimeout(() => {
139
- this.flattenResults(), this.batchFlattenTimer = void 0;
140
- }, 0)));
141
- }
115
+ }, p();
116
+ },
117
+ { immediate: !0 }
118
+ ), P(
119
+ () => b(a),
120
+ (d) => d && p()
121
+ ), {
122
+ objects: n,
123
+ poll: p,
124
+ isFirstPoll: m
125
+ };
142
126
  }
143
- function E(e, t, r, o, n) {
144
- let i;
145
- async function s() {
146
- i = r();
147
- for await (const c of i) {
148
- if (c.error) {
149
- console.error(c.error);
150
- continue;
151
- }
152
- e.onEntry(c);
153
- }
154
- }
155
- let f = !1, l;
156
- const a = async () => {
157
- if (f || !l) return;
158
- const c = l;
159
- f = !0;
160
- try {
161
- await c();
162
- } catch {
163
- await new Promise((v) => setTimeout(v, 2e3));
164
- } finally {
165
- if (c !== l) return;
166
- f = !1, d(n) && a();
167
- }
168
- }, h = G(!1);
169
- return k(
170
- o,
171
- async (c, p) => {
172
- if (JSON.stringify(c) === JSON.stringify(p))
173
- return;
174
- i == null || i.return(null), e.clear(), t.clear(), s(), l = () => t.poll(e.onEntry.bind(e));
175
- const v = l;
176
- f = !1, h.value = !0;
127
+ function J(e, i) {
128
+ const o = w(void 0);
129
+ return P(
130
+ () => b(e),
131
+ async (a, l, t) => {
132
+ let n = !0;
133
+ t(() => {
134
+ n = !1;
135
+ }), o.value = void 0;
177
136
  try {
178
- await a();
179
- } finally {
180
- if (v !== l) return;
181
- h.value = !1;
137
+ const f = await i(a);
138
+ n && (o.value = f);
139
+ } catch (f) {
140
+ if (!n) return;
141
+ f instanceof D ? o.value = null : console.error(f);
182
142
  }
183
143
  },
184
- {
185
- immediate: !0
186
- }
187
- ), A(() => {
188
- i == null || i.return(null), e.clear(), t.clear(), l = void 0;
189
- }), { poll: a, isInitialPolling: h };
190
- }
191
- function $(e, t) {
192
- return () => {
193
- const r = d(t);
194
- return r === void 0 ? e == null ? void 0 : e.value : r;
144
+ { immediate: !0 }
145
+ ), {
146
+ output: o
195
147
  };
196
148
  }
197
- function y(e) {
198
- return e.map((t) => t());
149
+ function K(e) {
150
+ return e === void 0 ? "Loading..." : e === null ? "Not found" : e;
199
151
  }
200
- function x(e, t, r, o = !1) {
201
- const n = w(), i = F(), s = () => d(e), f = () => d(t), l = $(i, r), a = [s, f, l], h = () => n.synchronizeDiscover(...y(a)), c = () => n.discover(...y(a)), p = new T(n), v = new O(c), { poll: P, isInitialPolling: j } = E(
202
- p,
203
- v,
204
- h,
205
- a,
206
- o
152
+ function re(e) {
153
+ const i = W(), { output: o } = J(
154
+ e,
155
+ i.actorToHandle.bind(i)
207
156
  );
208
- return {
209
- /**
210
- * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
211
- * an array of Graffiti objects.
212
- */
213
- objects: p.results,
214
- /**
215
- * A method to poll for new results.
216
- */
217
- poll: P,
218
- /**
219
- * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
220
- * that indicates if the *first* poll is currently running.
221
- * Useful to show a loading spinner or disable a button.
222
- *
223
- * This also tracks new polls when the arguments have changed,
224
- * but it does not track ongoing polls from either calling
225
- * {@link poll} or using the `autopoll` argument.
226
- */
227
- isInitialPolling: j
228
- };
229
- }
230
- function W(e, t, r, o = !1) {
231
- const n = w(), i = F(), s = () => d(e), f = () => d(t), l = $(i, r), a = [
232
- s,
233
- f,
234
- l
235
- ], h = () => n.synchronizeGet(...y(a)), c = new V(), p = () => n.get(...y(a)), v = new U(p), { poll: P, isInitialPolling: j } = E(
236
- c,
237
- v,
238
- h,
239
- a,
240
- o
241
- );
242
- return {
243
- /**
244
- * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
245
- * the retrieved Graffiti object, if it exists. If the object has been deleted,
246
- * the result is `null`. If the object is still being fetched, the result is `undefined`.
247
- */
248
- object: c.result,
249
- /**
250
- * A method to poll for new results.
251
- */
252
- poll: P,
253
- /**
254
- * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
255
- * that indicates if the *first* poll is currently running.
256
- * Useful to show a loading spinner or disable a button.
257
- *
258
- * This also tracks new polls when the arguments have changed,
259
- * but it does not track ongoing polls from either calling
260
- * {@link poll} or using the `autopoll` argument.
261
- */
262
- isInitialPolling: j
263
- };
264
- }
265
- function q(e, t, r = !1) {
266
- const o = w(), s = [() => d(e), () => d(t)], f = () => o.synchronizeRecoverOrphans(...y(s)), l = new T(o), a = () => o.recoverOrphans(...y(s)), h = new O(a), { poll: c, isInitialPolling: p } = E(
267
- l,
268
- h,
269
- f,
270
- s,
271
- r
272
- );
273
- return {
274
- /**
275
- * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
276
- * an array of Graffiti objects.
277
- */
278
- objects: l.results,
279
- /**
280
- * A method to poll for new results.
281
- */
282
- poll: c,
283
- /**
284
- * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
285
- * that indicates if the *first* poll is currently running.
286
- * Useful to show a loading spinner or disable a button.
287
- *
288
- * This also tracks new polls when the arguments have changed,
289
- * but it does not track ongoing polls from either calling
290
- * {@link poll} or using the `autopoll` argument.
291
- */
292
- isInitialPolling: p
293
- };
157
+ return { handle: o };
294
158
  }
295
- const D = /* @__PURE__ */ S({
159
+ const O = /* @__PURE__ */ A({
160
+ __name: "ActorToHandle",
161
+ props: {
162
+ actor: {}
163
+ },
164
+ setup(e) {
165
+ const o = h(e, "actor"), { handle: a } = re(o);
166
+ return (l, t) => L(l.$slots, "default", { handle: s(a) }, () => [
167
+ r("span", null, G(s(K)(s(a))), 1)
168
+ ]);
169
+ }
170
+ }), le = ["data-url"], ie = { key: 0 }, se = { key: 1 }, ae = { key: 0 }, ue = { key: 1 }, ce = { key: 0 }, fe = ["disabled"], de = { key: 1 }, me = { key: 2 }, R = /* @__PURE__ */ A({
171
+ __name: "ObjectInfo",
172
+ props: {
173
+ object: {}
174
+ },
175
+ setup(e) {
176
+ const i = W(), o = w(!1);
177
+ async function a(l, t) {
178
+ o.value = !0, await new Promise((n) => setTimeout(n, 0)), confirm(
179
+ "Are you sure you want to delete this object? It cannot be undone."
180
+ ) && await i.delete(l, t), o.value = !1;
181
+ }
182
+ return (l, t) => e.object ? (c(), u("article", {
183
+ key: 0,
184
+ "data-url": e.object.url
185
+ }, [
186
+ r("header", null, [
187
+ t[4] || (t[4] = r("h2", null, "Graffiti Object", -1)),
188
+ r("dl", null, [
189
+ t[1] || (t[1] = r("dt", null, "Object URL", -1)),
190
+ r("dd", null, [
191
+ r("code", null, G(e.object.url), 1)
192
+ ]),
193
+ t[2] || (t[2] = r("dt", null, "Actor", -1)),
194
+ r("dd", null, [
195
+ r("code", null, G(e.object.actor), 1)
196
+ ]),
197
+ t[3] || (t[3] = r("dt", null, "Handle", -1)),
198
+ r("dd", null, [
199
+ T(O, {
200
+ actor: e.object.actor
201
+ }, null, 8, ["actor"])
202
+ ])
203
+ ])
204
+ ]),
205
+ r("section", null, [
206
+ t[5] || (t[5] = r("h3", null, "Content", -1)),
207
+ r("pre", null, G(e.object.value), 1)
208
+ ]),
209
+ r("section", null, [
210
+ t[10] || (t[10] = r("h3", null, "Allowed Actors", -1)),
211
+ Array.isArray(e.object.allowed) ? e.object.allowed.length === 0 ? (c(), u("p", se, [...t[7] || (t[7] = [
212
+ r("em", null, "Noone", -1)
213
+ ])])) : V("", !0) : (c(), u("p", ie, [...t[6] || (t[6] = [
214
+ r("em", null, "Public", -1)
215
+ ])])),
216
+ r("ul", null, [
217
+ (c(!0), u(C, null, F(e.object.allowed, (n) => (c(), u("li", { key: n }, [
218
+ r("dl", null, [
219
+ t[8] || (t[8] = r("dt", null, "Actor", -1)),
220
+ r("dd", null, [
221
+ r("code", null, G(n), 1)
222
+ ]),
223
+ t[9] || (t[9] = r("dt", null, "Handle", -1)),
224
+ r("dd", null, [
225
+ T(O, { actor: n }, null, 8, ["actor"])
226
+ ])
227
+ ])
228
+ ]))), 128))
229
+ ])
230
+ ]),
231
+ r("section", null, [
232
+ t[12] || (t[12] = r("h3", null, "Channels", -1)),
233
+ e.object.channels?.length ? (c(), u("ul", ae, [
234
+ (c(!0), u(C, null, F(e.object.channels, (n) => (c(), u("li", { key: n }, [
235
+ r("code", null, G(n), 1)
236
+ ]))), 128))
237
+ ])) : (c(), u("p", ue, [...t[11] || (t[11] = [
238
+ r("em", null, "No channels", -1)
239
+ ])]))
240
+ ]),
241
+ r("footer", null, [
242
+ r("nav", null, [
243
+ r("ul", null, [
244
+ l.$graffitiSession.value?.actor === e.object.actor ? (c(), u("li", ce, [
245
+ r("button", {
246
+ disabled: o.value,
247
+ onClick: t[0] || (t[0] = (n) => a(e.object, l.$graffitiSession.value))
248
+ }, G(o.value ? "Deleting..." : "Delete"), 9, fe)
249
+ ])) : V("", !0)
250
+ ])
251
+ ])
252
+ ])
253
+ ], 8, le)) : e.object === null ? (c(), u("article", de, [...t[13] || (t[13] = [
254
+ r("header", null, [
255
+ r("h2", null, "Graffiti Object")
256
+ ], -1),
257
+ r("p", null, [
258
+ r("em", null, "Object not found")
259
+ ], -1)
260
+ ])])) : (c(), u("article", me, [...t[14] || (t[14] = [
261
+ r("header", null, [
262
+ r("h2", null, "Graffiti Object")
263
+ ], -1),
264
+ r("p", null, [
265
+ r("em", null, "Loading...")
266
+ ], -1)
267
+ ])]));
268
+ }
269
+ }), ve = { key: 0 }, ye = { key: 1 }, Q = /* @__PURE__ */ A({
296
270
  __name: "Discover",
297
271
  props: {
298
272
  channels: {},
@@ -301,94 +275,255 @@ const D = /* @__PURE__ */ S({
301
275
  autopoll: { type: Boolean }
302
276
  },
303
277
  setup(e) {
304
- const t = e, { objects: r, poll: o, isInitialPolling: n } = x(
305
- u(t, "channels"),
306
- u(t, "schema"),
307
- u(t, "session"),
308
- u(t, "autopoll")
278
+ const i = e, { objects: o, poll: a, isFirstPoll: l } = ne(
279
+ h(i, "channels"),
280
+ h(i, "schema"),
281
+ h(i, "session"),
282
+ h(i, "autopoll")
309
283
  );
310
- return (i, s) => R(i.$slots, "default", {
311
- objects: g(r),
312
- poll: g(o),
313
- isInitialPolling: g(n)
314
- });
284
+ return (t, n) => L(t.$slots, "default", {
285
+ objects: s(o),
286
+ poll: s(a),
287
+ isFirstPoll: s(l)
288
+ }, () => [
289
+ s(l) ? (c(), u("p", ye, [...n[0] || (n[0] = [
290
+ r("em", null, " Loading... ", -1)
291
+ ])])) : (c(), u("ul", ve, [
292
+ (c(!0), u(C, null, F(s(o), (f) => (c(), u("li", {
293
+ key: f.url
294
+ }, [
295
+ T(R, { object: f }, null, 8, ["object"])
296
+ ]))), 128))
297
+ ]))
298
+ ]);
315
299
  }
316
- }), I = /* @__PURE__ */ S({
300
+ });
301
+ function pe(e, i, o) {
302
+ const a = H(), l = w(void 0);
303
+ let t = async () => {
304
+ };
305
+ const n = async () => t();
306
+ let f;
307
+ return _(() => {
308
+ f?.return(null);
309
+ }), P(
310
+ () => [b(e), b(i), b(o)],
311
+ (p, m, S) => {
312
+ l.value = void 0;
313
+ const g = a.synchronizeGet(...p);
314
+ f = g;
315
+ let j = !0;
316
+ S(() => {
317
+ j = !1, g.return(null);
318
+ }), (async () => {
319
+ for await (const d of g) {
320
+ if (!j) return;
321
+ d.tombstone ? l.value = null : l.value = d.object;
322
+ }
323
+ })();
324
+ let v = !1;
325
+ t = async () => {
326
+ if (!(v || !j)) {
327
+ v = !0;
328
+ try {
329
+ await a.get(...p);
330
+ } catch (d) {
331
+ d instanceof D || console.error(d);
332
+ }
333
+ await new Promise((d) => setTimeout(d, 0)), v = !1;
334
+ }
335
+ }, n();
336
+ },
337
+ { immediate: !0 }
338
+ ), {
339
+ object: l,
340
+ poll: n
341
+ };
342
+ }
343
+ const X = /* @__PURE__ */ A({
317
344
  __name: "Get",
318
345
  props: {
319
346
  url: {},
320
347
  schema: {},
321
- session: {},
322
- autopoll: { type: Boolean }
348
+ session: {}
323
349
  },
324
350
  setup(e) {
325
- const t = e, { object: r, poll: o, isInitialPolling: n } = W(
326
- u(t, "url"),
327
- u(t, "schema"),
328
- u(t, "session"),
329
- u(t, "autopoll")
351
+ const i = e, { object: o, poll: a } = pe(
352
+ h(i, "url"),
353
+ h(i, "schema"),
354
+ h(i, "session")
330
355
  );
331
- return (i, s) => R(i.$slots, "default", {
332
- object: g(r),
333
- poll: g(o),
334
- isInitialPolling: g(n)
335
- });
356
+ return (l, t) => L(l.$slots, "default", {
357
+ object: s(o),
358
+ poll: s(a)
359
+ }, () => [
360
+ T(R, { object: s(o) }, null, 8, ["object"])
361
+ ]);
336
362
  }
337
- }), N = /* @__PURE__ */ S({
338
- __name: "RecoverOrphans",
363
+ });
364
+ function be(e, i, o) {
365
+ const a = H(), l = w(
366
+ void 0
367
+ ), t = w(0);
368
+ let n = null, f = () => {
369
+ };
370
+ function p() {
371
+ return n || (t.value++, n = new Promise((m) => {
372
+ f = () => {
373
+ n = null, m();
374
+ };
375
+ }), n);
376
+ }
377
+ return P(
378
+ () => ({
379
+ args: [b(e), b(i), b(o)],
380
+ pollCounter: t.value
381
+ }),
382
+ async ({ args: m }, S, g) => {
383
+ l.value?.dataUrl && URL.revokeObjectURL(l.value.dataUrl), l.value = void 0;
384
+ let j = !0;
385
+ g(() => {
386
+ j = !1;
387
+ });
388
+ try {
389
+ const { data: v, actor: d, allowed: x } = await a.getMedia(...m);
390
+ if (!j) return;
391
+ const z = URL.createObjectURL(v);
392
+ l.value = {
393
+ data: v,
394
+ dataUrl: z,
395
+ actor: d,
396
+ allowed: x
397
+ };
398
+ } catch (v) {
399
+ if (!j) return;
400
+ v instanceof D ? l.value = null : console.error(v);
401
+ } finally {
402
+ f();
403
+ }
404
+ },
405
+ { immediate: !0 }
406
+ ), _(() => {
407
+ f(), l.value?.dataUrl && URL.revokeObjectURL(l.value.dataUrl);
408
+ }), {
409
+ media: l,
410
+ poll: p
411
+ };
412
+ }
413
+ const he = ["src", "alt"], ge = ["src", "alt"], je = ["src", "alt"], we = ["src", "alt"], Ge = ["data", "alt"], $e = { key: 6 }, ke = { key: 7 }, Y = /* @__PURE__ */ A({
414
+ __name: "GetMedia",
339
415
  props: {
340
- schema: {},
341
- session: {},
342
- autopoll: { type: Boolean }
416
+ url: {},
417
+ accept: {},
418
+ session: {}
343
419
  },
344
420
  setup(e) {
345
- const t = e, { objects: r, poll: o, isInitialPolling: n } = q(
346
- u(t, "schema"),
347
- u(t, "session"),
348
- u(t, "autopoll")
421
+ const i = e, { media: o, poll: a } = be(
422
+ h(i, "url"),
423
+ h(i, "accept"),
424
+ h(i, "session")
349
425
  );
350
- return (i, s) => R(i.$slots, "default", {
351
- objects: g(r),
352
- poll: g(o),
353
- isInitialPolling: g(n)
354
- });
426
+ function l() {
427
+ o.value && (window.location.href = o.value.dataUrl);
428
+ }
429
+ return (t, n) => L(t.$slots, "default", {
430
+ media: s(o),
431
+ poll: s(a)
432
+ }, () => [
433
+ s(o)?.data.type.startsWith("image/") ? (c(), u("img", {
434
+ key: 0,
435
+ src: s(o).dataUrl,
436
+ alt: `An image by ${s(o).actor}`
437
+ }, null, 8, he)) : s(o)?.data.type.startsWith("video/") ? (c(), u("video", {
438
+ key: 1,
439
+ controls: "",
440
+ src: s(o).dataUrl,
441
+ alt: `A video by ${s(o).actor}`
442
+ }, null, 8, ge)) : s(o)?.data.type.startsWith("audio/") ? (c(), u("audio", {
443
+ key: 2,
444
+ controls: "",
445
+ src: s(o).dataUrl,
446
+ alt: `Audio by ${s(o).actor}`
447
+ }, null, 8, je)) : s(o)?.data.type === "text/html" ? (c(), u("iframe", {
448
+ key: 3,
449
+ src: s(o).dataUrl,
450
+ alt: `HTML by ${s(o).actor}`,
451
+ sandbox: ""
452
+ }, null, 8, we)) : s(o)?.data.type.startsWith("application/pdf") ? (c(), u("object", {
453
+ key: 4,
454
+ data: s(o).dataUrl,
455
+ type: "application/pdf",
456
+ alt: `PDF by ${s(o).actor}`
457
+ }, null, 8, Ge)) : s(o) ? (c(), u("button", {
458
+ key: 5,
459
+ onClick: l
460
+ }, "Download")) : s(o) === null ? (c(), u("p", $e, [...n[0] || (n[0] = [
461
+ r("em", null, "Media not found", -1)
462
+ ])])) : (c(), u("p", ke, [...n[1] || (n[1] = [
463
+ r("em", null, " Loading... ", -1)
464
+ ])]))
465
+ ]);
466
+ }
467
+ });
468
+ function Ae(e) {
469
+ const i = W(), { output: o } = J(
470
+ e,
471
+ i.handleToActor.bind(i)
472
+ );
473
+ return { actor: o };
474
+ }
475
+ const Z = /* @__PURE__ */ A({
476
+ __name: "HandleToActor",
477
+ props: {
478
+ handle: {}
479
+ },
480
+ setup(e) {
481
+ const o = h(e, "handle"), { actor: a } = Ae(o);
482
+ return (l, t) => L(l.$slots, "default", { actor: s(a) }, () => [
483
+ r("span", null, G(s(K)(s(a))), 1)
484
+ ]);
355
485
  }
356
- }), Y = {
357
- install(e, t) {
358
- const r = t.graffiti, o = new C(r), n = G(void 0);
359
- o.sessionEvents.addEventListener("initialized", async (i) => {
360
- const s = i.detail;
361
- if (s && s.error && console.error(s.error), s && s.href) {
486
+ }), Le = {
487
+ install(e, i) {
488
+ const o = i.graffiti, a = new ee(o), l = w(void 0);
489
+ a.sessionEvents.addEventListener("initialized", async (t) => {
490
+ const n = t.detail;
491
+ if (n && n.error && console.error(n.error), n && n.href) {
362
492
  const f = e.config.globalProperties.$router;
363
493
  if (f) {
364
- const l = f.options.history.base, a = new URL(s.href);
365
- a.pathname.startsWith(l) && (a.pathname = a.pathname.slice(l.length)), await f.replace(a.pathname + a.search + a.hash);
494
+ const p = f.options.history.base, m = new URL(n.href);
495
+ m.pathname.startsWith(p) && (m.pathname = m.pathname.slice(p.length)), await f.replace(m.pathname + m.search + m.hash);
366
496
  }
367
497
  }
368
- n.value || (n.value = null);
369
- }), o.sessionEvents.addEventListener("login", (i) => {
370
- const s = i.detail;
371
- if (s.error) {
372
- console.error("Error logging in:"), console.error(s.error);
498
+ l.value || (l.value = null);
499
+ }), a.sessionEvents.addEventListener("login", (t) => {
500
+ const n = t.detail;
501
+ if (n.error) {
502
+ console.error("Error logging in:"), console.error(n.error);
373
503
  return;
374
504
  } else
375
- n.value = s.session;
376
- }), o.sessionEvents.addEventListener("logout", (i) => {
377
- const s = i.detail;
378
- s.error ? (console.error("Error logging out:"), console.error(s.error)) : n.value = null;
379
- }), b.graffitiSynchronize = o, b.graffitiSession = n, e.component("GraffitiDiscover", D), e.component("GraffitiGet", I), e.component("GraffitiRecoverOrphans", N), e.config.globalProperties.$graffiti = o, e.config.globalProperties.$graffitiSession = n;
505
+ l.value = n.session;
506
+ }), a.sessionEvents.addEventListener("logout", (t) => {
507
+ const n = t.detail;
508
+ n.error ? (console.error("Error logging out:"), console.error(n.error)) : l.value = null;
509
+ }), oe(a), te(l), e.component("GraffitiDiscover", Q), e.component("GraffitiGet", X), e.component("GraffitiGetMedia", Y), e.component("GraffitiActorToHandle", O), e.component("GraffitiHandleToActor", Z), e.component("GraffitiObjectInfo", R), e.config.globalProperties.$graffiti = a, e.config.globalProperties.$graffitiSession = l;
380
510
  }
381
- }, Z = D, tt = I, et = N;
511
+ }, Ee = Q, Te = X, Oe = Y, De = O, He = Z, Re = R;
382
512
  export {
383
- Z as GraffitiDiscover,
384
- tt as GraffitiGet,
385
- Y as GraffitiPlugin,
386
- et as GraffitiRecoverOrphans,
387
- X as useGraffiti,
388
- x as useGraffitiDiscover,
389
- W as useGraffitiGet,
390
- q as useGraffitiRecoverOrphans,
391
- F as useGraffitiSession,
392
- w as useGraffitiSynchronize
513
+ De as GraffitiActorToHandle,
514
+ Ee as GraffitiDiscover,
515
+ Te as GraffitiGet,
516
+ Oe as GraffitiGetMedia,
517
+ He as GraffitiHandleToActor,
518
+ Re as GraffitiObjectInfo,
519
+ Le as GraffitiPlugin,
520
+ W as useGraffiti,
521
+ re as useGraffitiActorToHandle,
522
+ ne as useGraffitiDiscover,
523
+ pe as useGraffitiGet,
524
+ be as useGraffitiGetMedia,
525
+ Ae as useGraffitiHandleToActor,
526
+ Pe as useGraffitiSession,
527
+ H as useGraffitiSynchronize
393
528
  };
394
529
  //# sourceMappingURL=plugin.mjs.map