@graffiti-garden/wrapper-vue 0.7.1 → 1.0.3

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 +999 -941
  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 -331
  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 -343
  69. package/src/pollers.ts +0 -119
  70. package/src/reducers.ts +0 -124
@@ -1,296 +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 p = (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 ne(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
- p(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 oe(e, i, n, a = !1) {
45
+ const l = H(), t = /* @__PURE__ */ new Map(), o = 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
- p(this, "iterator");
52
- p(this, "continue");
53
- p(this, "poll", async (t) => {
54
- if (!this.iterator)
55
- if (this.continue)
62
+ return P(
63
+ () => ({
64
+ args: [b(e), b(i), b(n)],
65
+ refresh: j.value
66
+ }),
67
+ ({ args: d }, x, z) => {
68
+ t.clear(), o.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
+ $ && (o.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
- o.value && (this.iterator = void 0, 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
- p(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
- p(this, "results", G([]));
121
- p(this, "resultsRaw", /* @__PURE__ */ new Map());
122
- p(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: o,
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, a;
156
- const l = async () => {
157
- if (f || !a) return;
158
- const c = a;
159
- f = !0;
160
- try {
161
- await c();
162
- } finally {
163
- if (c !== a) return;
164
- f = !1, d(n) && l();
165
- }
166
- }, h = G(!1);
167
- return k(
168
- o,
169
- async (c, m) => {
170
- if (JSON.stringify(c) === JSON.stringify(m))
171
- return;
172
- i == null || i.return(null), e.clear(), t.clear(), s(), a = () => t.poll(e.onEntry.bind(e));
173
- const y = a;
174
- f = !1, h.value = !0;
127
+ function J(e, i) {
128
+ const n = w(void 0);
129
+ return P(
130
+ () => b(e),
131
+ async (a, l, t) => {
132
+ let o = !0;
133
+ t(() => {
134
+ o = !1;
135
+ }), n.value = void 0;
175
136
  try {
176
- await l();
177
- } finally {
178
- if (y !== a) return;
179
- h.value = !1;
137
+ const f = await i(a);
138
+ o && (n.value = f);
139
+ } catch (f) {
140
+ if (!o) return;
141
+ f instanceof D ? n.value = null : console.error(f);
180
142
  }
181
143
  },
182
- {
183
- immediate: !0
184
- }
185
- ), A(() => {
186
- i == null || i.return(null), e.clear(), t.clear(), a = void 0;
187
- }), { poll: l, isInitialPolling: h };
188
- }
189
- function $(e, t) {
190
- return () => {
191
- const r = d(t);
192
- return r === void 0 ? e == null ? void 0 : e.value : r;
144
+ { immediate: !0 }
145
+ ), {
146
+ output: n
193
147
  };
194
148
  }
195
- function v(e) {
196
- return e.map((t) => t());
149
+ function K(e) {
150
+ return e === void 0 ? "Loading..." : e === null ? "Not found" : e;
197
151
  }
198
- function x(e, t, r, o = !1) {
199
- const n = w(), i = F(), s = () => d(e), f = () => d(t), a = $(i, r), l = [s, f, a], h = () => n.synchronizeDiscover(...v(l)), c = () => n.discover(...v(l)), m = new T(n), y = new O(c), { poll: P, isInitialPolling: j } = E(
200
- m,
201
- y,
202
- h,
203
- l,
204
- o
152
+ function re(e) {
153
+ const i = W(), { output: n } = J(
154
+ e,
155
+ i.actorToHandle.bind(i)
205
156
  );
206
- return {
207
- /**
208
- * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
209
- * an array of Graffiti objects.
210
- */
211
- objects: m.results,
212
- /**
213
- * A method to poll for new results.
214
- */
215
- poll: P,
216
- /**
217
- * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
218
- * that indicates if the *first* poll is currently running.
219
- * Useful to show a loading spinner or disable a button.
220
- *
221
- * This also tracks new polls when the arguments have changed,
222
- * but it does not track ongoing polls from either calling
223
- * {@link poll} or using the `autopoll` argument.
224
- */
225
- isInitialPolling: j
226
- };
227
- }
228
- function W(e, t, r, o = !1) {
229
- const n = w(), i = F(), s = () => d(e), f = () => d(t), a = $(i, r), l = [
230
- s,
231
- f,
232
- a
233
- ], h = () => n.synchronizeGet(...v(l)), c = new V(), m = () => n.get(...v(l)), y = new U(m), { poll: P, isInitialPolling: j } = E(
234
- c,
235
- y,
236
- h,
237
- l,
238
- o
239
- );
240
- return {
241
- /**
242
- * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
243
- * the retrieved Graffiti object, if it exists. If the object has been deleted,
244
- * the result is `null`. If the object is still being fetched, the result is `undefined`.
245
- */
246
- object: c.result,
247
- /**
248
- * A method to poll for new results.
249
- */
250
- poll: P,
251
- /**
252
- * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
253
- * that indicates if the *first* poll is currently running.
254
- * Useful to show a loading spinner or disable a button.
255
- *
256
- * This also tracks new polls when the arguments have changed,
257
- * but it does not track ongoing polls from either calling
258
- * {@link poll} or using the `autopoll` argument.
259
- */
260
- isInitialPolling: j
261
- };
262
- }
263
- function q(e, t, r = !1) {
264
- const o = w(), s = [() => d(e), () => d(t)], f = () => o.synchronizeRecoverOrphans(...v(s)), a = new T(o), l = () => o.recoverOrphans(...v(s)), h = new O(l), { poll: c, isInitialPolling: m } = E(
265
- a,
266
- h,
267
- f,
268
- s,
269
- r
270
- );
271
- return {
272
- /**
273
- * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
274
- * an array of Graffiti objects.
275
- */
276
- objects: a.results,
277
- /**
278
- * A method to poll for new results.
279
- */
280
- poll: c,
281
- /**
282
- * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
283
- * that indicates if the *first* poll is currently running.
284
- * Useful to show a loading spinner or disable a button.
285
- *
286
- * This also tracks new polls when the arguments have changed,
287
- * but it does not track ongoing polls from either calling
288
- * {@link poll} or using the `autopoll` argument.
289
- */
290
- isInitialPolling: m
291
- };
157
+ return { handle: n };
292
158
  }
293
- const D = /* @__PURE__ */ S({
159
+ const O = /* @__PURE__ */ A({
160
+ __name: "ActorToHandle",
161
+ props: {
162
+ actor: {}
163
+ },
164
+ setup(e) {
165
+ const n = h(e, "actor"), { handle: a } = re(n);
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(), n = w(!1);
177
+ async function a(l, t) {
178
+ n.value = !0, await new Promise((o) => setTimeout(o, 0)), confirm(
179
+ "Are you sure you want to delete this object? It cannot be undone."
180
+ ) && await i.delete(l, t), n.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, (o) => (c(), u("li", { key: o }, [
218
+ r("dl", null, [
219
+ t[8] || (t[8] = r("dt", null, "Actor", -1)),
220
+ r("dd", null, [
221
+ r("code", null, G(o), 1)
222
+ ]),
223
+ t[9] || (t[9] = r("dt", null, "Handle", -1)),
224
+ r("dd", null, [
225
+ T(O, { actor: o }, 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, (o) => (c(), u("li", { key: o }, [
235
+ r("code", null, G(o), 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: n.value,
247
+ onClick: t[0] || (t[0] = (o) => a(e.object, l.$graffitiSession.value))
248
+ }, G(n.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({
294
270
  __name: "Discover",
295
271
  props: {
296
272
  channels: {},
@@ -299,94 +275,255 @@ const D = /* @__PURE__ */ S({
299
275
  autopoll: { type: Boolean }
300
276
  },
301
277
  setup(e) {
302
- const t = e, { objects: r, poll: o, isInitialPolling: n } = x(
303
- u(t, "channels"),
304
- u(t, "schema"),
305
- u(t, "session"),
306
- u(t, "autopoll")
278
+ const i = e, { objects: n, poll: a, isFirstPoll: l } = oe(
279
+ h(i, "channels"),
280
+ h(i, "schema"),
281
+ h(i, "session"),
282
+ h(i, "autopoll")
307
283
  );
308
- return (i, s) => R(i.$slots, "default", {
309
- objects: g(r),
310
- poll: g(o),
311
- isInitialPolling: g(n)
312
- });
284
+ return (t, o) => L(t.$slots, "default", {
285
+ objects: s(n),
286
+ poll: s(a),
287
+ isFirstPoll: s(l)
288
+ }, () => [
289
+ s(l) ? (c(), u("p", ye, [...o[0] || (o[0] = [
290
+ r("em", null, " Loading... ", -1)
291
+ ])])) : (c(), u("ul", ve, [
292
+ (c(!0), u(C, null, F(s(n), (f) => (c(), u("li", {
293
+ key: f.url
294
+ }, [
295
+ T(R, { object: f }, null, 8, ["object"])
296
+ ]))), 128))
297
+ ]))
298
+ ]);
313
299
  }
314
- }), I = /* @__PURE__ */ S({
300
+ });
301
+ function pe(e, i, n) {
302
+ const a = H(), l = w(void 0);
303
+ let t = async () => {
304
+ };
305
+ const o = async () => t();
306
+ let f;
307
+ return _(() => {
308
+ f?.return(null);
309
+ }), P(
310
+ () => [b(e), b(i), b(n)],
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
+ }, o();
336
+ },
337
+ { immediate: !0 }
338
+ ), {
339
+ object: l,
340
+ poll: o
341
+ };
342
+ }
343
+ const X = /* @__PURE__ */ A({
315
344
  __name: "Get",
316
345
  props: {
317
346
  url: {},
318
347
  schema: {},
319
- session: {},
320
- autopoll: { type: Boolean }
348
+ session: {}
321
349
  },
322
350
  setup(e) {
323
- const t = e, { object: r, poll: o, isInitialPolling: n } = W(
324
- u(t, "url"),
325
- u(t, "schema"),
326
- u(t, "session"),
327
- u(t, "autopoll")
351
+ const i = e, { object: n, poll: a } = pe(
352
+ h(i, "url"),
353
+ h(i, "schema"),
354
+ h(i, "session")
328
355
  );
329
- return (i, s) => R(i.$slots, "default", {
330
- object: g(r),
331
- poll: g(o),
332
- isInitialPolling: g(n)
333
- });
356
+ return (l, t) => L(l.$slots, "default", {
357
+ object: s(n),
358
+ poll: s(a)
359
+ }, () => [
360
+ T(R, { object: s(n) }, null, 8, ["object"])
361
+ ]);
334
362
  }
335
- }), N = /* @__PURE__ */ S({
336
- __name: "RecoverOrphans",
363
+ });
364
+ function be(e, i, n) {
365
+ const a = H(), l = w(
366
+ void 0
367
+ ), t = w(0);
368
+ let o = null, f = () => {
369
+ };
370
+ function p() {
371
+ return o || (t.value++, o = new Promise((m) => {
372
+ f = () => {
373
+ o = null, m();
374
+ };
375
+ }), o);
376
+ }
377
+ return P(
378
+ () => ({
379
+ args: [b(e), b(i), b(n)],
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",
337
415
  props: {
338
- schema: {},
339
- session: {},
340
- autopoll: { type: Boolean }
416
+ url: {},
417
+ requirements: {},
418
+ session: {}
341
419
  },
342
420
  setup(e) {
343
- const t = e, { objects: r, poll: o, isInitialPolling: n } = q(
344
- u(t, "schema"),
345
- u(t, "session"),
346
- u(t, "autopoll")
421
+ const i = e, { media: n, poll: a } = be(
422
+ h(i, "url"),
423
+ h(i, "requirements"),
424
+ h(i, "session")
347
425
  );
348
- return (i, s) => R(i.$slots, "default", {
349
- objects: g(r),
350
- poll: g(o),
351
- isInitialPolling: g(n)
352
- });
426
+ function l() {
427
+ n.value && (window.location.href = n.value.dataUrl);
428
+ }
429
+ return (t, o) => L(t.$slots, "default", {
430
+ media: s(n),
431
+ poll: s(a)
432
+ }, () => [
433
+ s(n)?.data.type.startsWith("image/") ? (c(), u("img", {
434
+ key: 0,
435
+ src: s(n).dataUrl,
436
+ alt: `An image by ${s(n).actor}`
437
+ }, null, 8, he)) : s(n)?.data.type.startsWith("video/") ? (c(), u("video", {
438
+ key: 1,
439
+ controls: "",
440
+ src: s(n).dataUrl,
441
+ alt: `A video by ${s(n).actor}`
442
+ }, null, 8, ge)) : s(n)?.data.type.startsWith("audio/") ? (c(), u("audio", {
443
+ key: 2,
444
+ controls: "",
445
+ src: s(n).dataUrl,
446
+ alt: `Audio by ${s(n).actor}`
447
+ }, null, 8, je)) : s(n)?.data.type === "text/html" ? (c(), u("iframe", {
448
+ key: 3,
449
+ src: s(n).dataUrl,
450
+ alt: `HTML by ${s(n).actor}`,
451
+ sandbox: ""
452
+ }, null, 8, we)) : s(n)?.data.type.startsWith("application/pdf") ? (c(), u("object", {
453
+ key: 4,
454
+ data: s(n).dataUrl,
455
+ type: "application/pdf",
456
+ alt: `PDF by ${s(n).actor}`
457
+ }, null, 8, Ge)) : s(n) ? (c(), u("button", {
458
+ key: 5,
459
+ onClick: l
460
+ }, "Download")) : s(n) === null ? (c(), u("p", $e, [...o[0] || (o[0] = [
461
+ r("em", null, "Media not found", -1)
462
+ ])])) : (c(), u("p", ke, [...o[1] || (o[1] = [
463
+ r("em", null, " Loading... ", -1)
464
+ ])]))
465
+ ]);
466
+ }
467
+ });
468
+ function Ae(e) {
469
+ const i = W(), { output: n } = J(
470
+ e,
471
+ i.handleToActor.bind(i)
472
+ );
473
+ return { actor: n };
474
+ }
475
+ const Z = /* @__PURE__ */ A({
476
+ __name: "HandleToActor",
477
+ props: {
478
+ handle: {}
479
+ },
480
+ setup(e) {
481
+ const n = h(e, "handle"), { actor: a } = Ae(n);
482
+ return (l, t) => L(l.$slots, "default", { actor: s(a) }, () => [
483
+ r("span", null, G(s(K)(s(a))), 1)
484
+ ]);
353
485
  }
354
- }), Y = {
355
- install(e, t) {
356
- const r = t.graffiti, o = new C(r), n = G(void 0);
357
- o.sessionEvents.addEventListener("initialized", async (i) => {
358
- const s = i.detail;
359
- if (s && s.error && console.error(s.error), s && s.href) {
486
+ }), Le = {
487
+ install(e, i) {
488
+ const n = i.graffiti, a = new ee(n), l = w(void 0);
489
+ a.sessionEvents.addEventListener("initialized", async (t) => {
490
+ const o = t.detail;
491
+ if (o && o.error && console.error(o.error), o && o.href) {
360
492
  const f = e.config.globalProperties.$router;
361
493
  if (f) {
362
- const a = f.options.history.base, l = new URL(s.href);
363
- l.pathname.startsWith(a) && (l.pathname = l.pathname.slice(a.length)), await f.replace(l.pathname + l.search + l.hash);
494
+ const p = f.options.history.base, m = new URL(o.href);
495
+ m.pathname.startsWith(p) && (m.pathname = m.pathname.slice(p.length)), await f.replace(m.pathname + m.search + m.hash);
364
496
  }
365
497
  }
366
- n.value || (n.value = null);
367
- }), o.sessionEvents.addEventListener("login", (i) => {
368
- const s = i.detail;
369
- if (s.error) {
370
- console.error("Error logging in:"), console.error(s.error);
498
+ l.value || (l.value = null);
499
+ }), a.sessionEvents.addEventListener("login", (t) => {
500
+ const o = t.detail;
501
+ if (o.error) {
502
+ console.error("Error logging in:"), console.error(o.error);
371
503
  return;
372
504
  } else
373
- n.value = s.session;
374
- }), o.sessionEvents.addEventListener("logout", (i) => {
375
- const s = i.detail;
376
- s.error ? (console.error("Error logging out:"), console.error(s.error)) : n.value = null;
377
- }), 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 = o.session;
506
+ }), a.sessionEvents.addEventListener("logout", (t) => {
507
+ const o = t.detail;
508
+ o.error ? (console.error("Error logging out:"), console.error(o.error)) : l.value = null;
509
+ }), ne(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;
378
510
  }
379
- }, Z = D, tt = I, et = N;
511
+ }, Ee = Q, Te = X, Oe = Y, De = O, He = Z, Re = R;
380
512
  export {
381
- Z as GraffitiDiscover,
382
- tt as GraffitiGet,
383
- Y as GraffitiPlugin,
384
- et as GraffitiRecoverOrphans,
385
- X as useGraffiti,
386
- x as useGraffitiDiscover,
387
- W as useGraffitiGet,
388
- q as useGraffitiRecoverOrphans,
389
- F as useGraffitiSession,
390
- 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
+ oe as useGraffitiDiscover,
523
+ pe as useGraffitiGet,
524
+ be as useGraffitiGetMedia,
525
+ Ae as useGraffitiHandleToActor,
526
+ Pe as useGraffitiSession,
527
+ H as useGraffitiSynchronize
391
528
  };
392
529
  //# sourceMappingURL=plugin.mjs.map