@seedprotocol/react 0.4.30 → 0.4.31

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.js CHANGED
@@ -1,2266 +1,2350 @@
1
- import qe, { createContext as rt, useContext as nt, useState as S, useCallback as x, useEffect as w, useRef as C, useMemo as N, useLayoutEffect as st } from "react";
2
- import { flushSync as ue } from "react-dom";
3
- import { getClient as ge, ClientManagerState as P, eventEmitter as z, BaseDb as j, Item as Ce, EAS_SEED_DATA_SYNCED_TO_DB_EVENT as ne, getAddressesForItemsFilter as ot, seeds as D, getVersionData as it, createNewItem as at, ItemProperty as ie, metadata as k, appState as fe, Schema as be, schemas as X, loadAllSchemasFromDb as ct, SEED_PROTOCOL_SCHEMA_NAME as lt, Model as ae, models as ce, modelSchemas as ve, ModelProperty as ye, properties as te, getPropertySchema as ze, getSchemaNameFromId as dt, BaseFileManager as W, easSyncProcesses as pe, client as ut, resolveMediaRef as ft, normalizeFeedItemFields as yt } from "@seedprotocol/sdk";
4
- import { orderBy as pt, debounce as He, startCase as Pe } from "lodash-es";
5
- import G from "debug";
6
- import { useSelector as Le } from "@xstate/react";
7
- import { jsx as g, jsxs as U, Fragment as Se } from "react/jsx-runtime";
8
- import { or as re, isNull as le, eq as q, inArray as Te, sql as mt, isNotNull as Ae, and as xe, gt as ht, like as Qe, desc as Ve } from "drizzle-orm";
9
- import { toSnakeCase as gt } from "drizzle-orm/casing";
10
- import { useQueryClient as Z, useQuery as ee, QueryClient as bt, QueryClientProvider as St } from "@tanstack/react-query";
11
- import vt from "pluralize";
12
- const Q = () => {
13
- const t = ge().getService();
14
- return Le(t, (n) => n.value === P.IDLE);
15
- }, Me = "addresses.persisted", Ke = rt(0);
16
- function je() {
17
- return nt(Ke);
1
+ import e, { createContext as t, useCallback as n, useContext as r, useEffect as i, useLayoutEffect as a, useMemo as o, useRef as s, useState as c } from "react";
2
+ import { flushSync as l } from "react-dom";
3
+ import { BaseDb as u, BaseFileManager as d, ClientManagerState as f, EAS_SEED_DATA_SYNCED_TO_DB_EVENT as p, Item as m, ItemProperty as h, Model as g, ModelProperty as _, SEED_PROTOCOL_SCHEMA_NAME as v, Schema as y, appState as b, client as x, createNewItem as S, easSyncProcesses as C, eventEmitter as w, getAddressesForItemsFilter as T, getClient as E, getPropertySchema as D, getSchemaNameFromId as ee, getVersionData as te, loadAllSchemasFromDb as ne, metadata as O, modelSchemas as k, models as A, normalizeFeedItemFields as re, properties as j, resolveMediaRef as ie, schemas as M, seeds as N } from "@seedprotocol/sdk";
4
+ import { debounce as ae, orderBy as oe, startCase as se } from "lodash-es";
5
+ import P from "debug";
6
+ import { useSelector as ce } from "@xstate/react";
7
+ import { Fragment as F, jsx as I, jsxs as L } from "react/jsx-runtime";
8
+ import { and as le, desc as ue, eq as R, gt as de, inArray as fe, isNotNull as pe, isNull as z, like as me, or as B, sql as he } from "drizzle-orm";
9
+ import { toSnakeCase as ge } from "drizzle-orm/casing";
10
+ import { QueryClient as _e, QueryClientProvider as ve, useQuery as V, useQueryClient as H } from "@tanstack/react-query";
11
+ import ye from "pluralize";
12
+ //#region src/client.ts
13
+ var U = () => ce(E().getService(), (e) => e.value === f.IDLE), W = "addresses.persisted", be = t(0);
14
+ function G() {
15
+ return r(be);
18
16
  }
19
- function wt({
20
- queryClient: e,
21
- children: t
22
- }) {
23
- const [r, n] = S(0), o = x(() => {
24
- e.invalidateQueries({ queryKey: ["seed", "items"], exact: !1 }), n((a) => a + 1);
25
- }, [e]);
26
- return w(() => (z.on(Me, o), () => {
27
- z.off(Me, o);
28
- }), [o]), /* @__PURE__ */ g(Ke.Provider, { value: r, children: t });
17
+ function xe({ queryClient: e, children: t }) {
18
+ let [r, a] = c(0), o = n(() => {
19
+ e.invalidateQueries({
20
+ queryKey: ["seed", "items"],
21
+ exact: !1
22
+ }), a((e) => e + 1);
23
+ }, [e]);
24
+ return i(() => (w.on(W, o), () => {
25
+ w.off(W, o);
26
+ }), [o]), /* @__PURE__ */ I(be.Provider, {
27
+ value: r,
28
+ children: t
29
+ });
29
30
  }
30
- function Y(e) {
31
- const [t, r] = S(void 0), n = C(null), o = Q(), a = N(() => {
32
- if (!o || !e)
33
- return null;
34
- try {
35
- return j.liveQuery(e);
36
- } catch (s) {
37
- return console.error("[useLiveQuery] Failed to create live query:", s), null;
38
- }
39
- }, [e, o]);
40
- return w(() => {
41
- if (n.current && (n.current.unsubscribe(), n.current = null), !a)
42
- return;
43
- const s = a.subscribe({
44
- next: (c) => {
45
- r(c !== void 0 ? [...c] : void 0);
46
- },
47
- error: (c) => {
48
- console.error("[useLiveQuery] Error:", c);
49
- }
50
- });
51
- return n.current = s, () => {
52
- n.current && (n.current.unsubscribe(), n.current = null);
53
- };
54
- }, [a]), t;
31
+ //#endregion
32
+ //#region src/liveQuery.ts
33
+ function K(e) {
34
+ let [t, n] = c(void 0), r = s(null), a = U(), l = o(() => {
35
+ if (!a || !e) return null;
36
+ try {
37
+ return u.liveQuery(e);
38
+ } catch (e) {
39
+ return console.error("[useLiveQuery] Failed to create live query:", e), null;
40
+ }
41
+ }, [e, a]);
42
+ return i(() => {
43
+ if (r.current && (r.current.unsubscribe(), r.current = null), l) return r.current = l.subscribe({
44
+ next: (e) => {
45
+ n(e === void 0 ? void 0 : [...e]);
46
+ },
47
+ error: (e) => {
48
+ console.error("[useLiveQuery] Error:", e);
49
+ }
50
+ }), () => {
51
+ r.current && (r.current.unsubscribe(), r.current = null);
52
+ };
53
+ }, [l]), t;
55
54
  }
56
- const me = G("seedSdk:react:item"), pr = ({ modelName: e, seedLocalId: t, seedUid: r }) => {
57
- const [n, o] = S(), [, a] = S(0), [s, c] = S(!!(t || r)), [l, i] = S(null), d = C(void 0), u = C(!1), f = Q(), b = je(), v = C(e), h = C(t), y = C(r), p = N(() => f ? !!(h.current || y.current) : !1, [f, t, r]), E = x(async () => {
58
- if (!!!(f && (h.current || y.current))) {
59
- o(void 0), c(!1), i(null);
60
- return;
61
- }
62
- try {
63
- i(null);
64
- const _ = await Ce.find({
65
- modelName: v.current,
66
- seedLocalId: h.current,
67
- seedUid: y.current
68
- });
69
- if (!_) {
70
- me("[useItem] [loadItem] no item found", v.current, h.current), o((R) => R && (R.seedLocalId && R.seedLocalId === h.current || R.seedUid && R.seedUid === y.current) ? R : void 0), c(!1), i(null);
71
- return;
72
- }
73
- o(_), c(!1), i(null);
74
- } catch (_) {
75
- me("[useItem] Error loading item:", _), o(void 0), c(!1), i(_);
76
- }
77
- }, [f]), I = C(E);
78
- return w(() => {
79
- I.current = E;
80
- }, [E]), w(() => {
81
- v.current = e, h.current = t, y.current = r;
82
- }, [e, t, r]), w(() => {
83
- const m = () => {
84
- a((_) => _ + 1), I.current();
85
- };
86
- return z.on(ne, m), () => {
87
- z.off(ne, m);
88
- };
89
- }, []), w(() => {
90
- if (!p) {
91
- !t && !r && (o(void 0), c(!1), i(null));
92
- return;
93
- }
94
- E();
95
- }, [p, E, t, r, b]), w(() => {
96
- if (!n) {
97
- d.current?.unsubscribe(), d.current = void 0, u.current = !1;
98
- return;
99
- }
100
- d.current?.unsubscribe(), u.current = !1;
101
- const _ = n.getService().subscribe((R) => {
102
- R && typeof R == "object" && "value" in R && (R.value === "idle" ? (u.current = !0, c(!1), i(null)) : R.value === "error" ? (i(new Error("Item service error")), c(!1)) : u.current && c(!0));
103
- });
104
- return d.current = _, () => {
105
- d.current?.unsubscribe(), d.current = void 0;
106
- };
107
- }, [n]), {
108
- item: n,
109
- isLoading: s,
110
- error: l
111
- };
112
- }, It = (e, t, r, n, o) => [
113
- "seed",
114
- "items",
115
- e ?? null,
116
- t ?? !1,
117
- r ?? !1,
118
- n ?? null,
119
- o ?? 0
120
- ], mr = ({
121
- modelName: e,
122
- deleted: t = !1,
123
- includeEas: r = !1,
124
- addressFilter: n
125
- }) => {
126
- const o = Q(), a = je(), s = Z();
127
- w(() => {
128
- const I = () => {
129
- s.invalidateQueries({ queryKey: ["seed", "items"] });
130
- };
131
- return z.on(ne, I), () => {
132
- z.off(ne, I);
133
- };
134
- }, [s]);
135
- const c = C([]), l = C(/* @__PURE__ */ new Set()), i = C(!1), [d, u] = S(null);
136
- w(() => {
137
- if (n !== "owned" && n !== "watched") {
138
- u(null);
139
- return;
140
- }
141
- let I = !1;
142
- return ot(n).then((m) => {
143
- I || u(m);
144
- }), () => {
145
- I = !0;
146
- };
147
- }, [n, a]);
148
- const f = N(
149
- () => It(e, t, r, n, a),
150
- [e, t, r, n, a]
151
- );
152
- w(() => {
153
- i.current = !1;
154
- }, [f]);
155
- const {
156
- data: b = [],
157
- isLoading: v,
158
- error: h
159
- } = ee({
160
- queryKey: f,
161
- queryFn: async () => await Ce.all(e, t, {
162
- waitForReady: !0,
163
- includeEas: r,
164
- addressFilter: n
165
- }),
166
- enabled: o,
167
- // Local SQLite + live invalidation drive freshness; Seed’s default staleTime would keep a
168
- // mistaken initial [] “fresh” and block refetch when another subscriber mounts.
169
- staleTime: 0
170
- });
171
- c.current = b;
172
- const y = o ? j.getAppDb() : null, p = N(() => {
173
- if (!y || (n === "owned" || n === "watched") && d === null)
174
- return null;
175
- const I = [];
176
- r || I.push(re(le(D.uid), q(D.uid, ""))), e && I.push(q(D.type, gt(e))), n === "owned" ? d && d.length > 0 && I.push(
177
- re(
178
- Te(D.publisher, d),
179
- le(D.publisher)
180
- )
181
- ) : n === "watched" && (d && d.length > 0 ? I.push(Te(D.publisher, d)) : I.push(mt`1=0`)), t ? I.push(
182
- re(
183
- Ae(D._markedForDeletion),
184
- q(D._markedForDeletion, 1)
185
- )
186
- ) : (I.push(
187
- re(
188
- le(D._markedForDeletion),
189
- q(D._markedForDeletion, 0)
190
- )
191
- ), I.push(
192
- re(le(D.revokedAt), q(D.revokedAt, 0))
193
- ));
194
- const m = it();
195
- return y.with(m).select({
196
- localId: D.localId,
197
- uid: D.uid,
198
- type: D.type,
199
- schemaUid: D.schemaUid,
200
- createdAt: D.createdAt,
201
- attestationCreatedAt: D.attestationCreatedAt,
202
- _markedForDeletion: D._markedForDeletion
203
- }).from(D).leftJoin(m, q(D.localId, m.seedLocalId)).where(xe(ht(m.versionsCount, 0), ...I)).groupBy(D.localId);
204
- }, [y, o, e, t, r, n, d]), E = Y(p);
205
- return w(() => {
206
- if (!o || !E) return;
207
- const I = /* @__PURE__ */ new Set();
208
- for (const A of E) {
209
- const B = A.localId || A.uid;
210
- B && I.add(B);
211
- }
212
- const m = /* @__PURE__ */ new Set();
213
- for (const A of c.current) {
214
- const B = A.seedLocalId || A.seedUid;
215
- B && m.add(B);
216
- }
217
- if (I.size === 0 && m.size > 0)
218
- return;
219
- if (!i.current && (i.current = !0, I.size > 0 && m.size === 0)) {
220
- l.current = new Set(I), s.invalidateQueries({ queryKey: f });
221
- return;
222
- }
223
- const _ = l.current;
224
- if (_.size === I.size && [..._].every((A) => I.has(A)))
225
- return;
226
- if (m.size === I.size && [...m].every((A) => I.has(A))) {
227
- l.current = new Set(I);
228
- return;
229
- }
230
- l.current = new Set(I), s.invalidateQueries({ queryKey: f });
231
- }, [o, E, s, f]), {
232
- items: pt(
233
- b,
234
- [
235
- (I) => I.lastVersionPublishedAt || I.attestationCreatedAt || I.createdAt
236
- ],
237
- ["desc"]
238
- ),
239
- isLoading: v,
240
- error: h
241
- };
242
- }, hr = () => {
243
- const [e, t] = S(!1), [r, n] = S(null), o = x(() => n(null), []);
244
- return {
245
- createItem: x(
246
- async (s, c) => {
247
- if (e) {
248
- me("[useCreateItem] [createItem] already creating item, skipping");
249
- return;
250
- }
251
- n(null), ue(() => t(!0));
252
- try {
253
- const l = c ?? {}, { seedLocalId: i } = await at({ modelName: s, ...l });
254
- return await Ce.find({ modelName: s, seedLocalId: i }) ?? void 0;
255
- } catch (l) {
256
- me("[useCreateItem] Error creating item:", l), n(l instanceof Error ? l : new Error(String(l)));
257
- return;
258
- } finally {
259
- queueMicrotask(() => t(!1));
260
- }
261
- },
262
- [e]
263
- ),
264
- isLoading: e,
265
- error: r,
266
- resetError: o
267
- };
268
- }, gr = () => {
269
- const [e, t] = S(null), [r, n] = S(!1), [o, a] = S(null), s = C(void 0), c = x(() => a(null), []), l = x((i) => {
270
- i && (t(i), a(null), i.publish().catch(() => {
271
- }));
272
- }, []);
273
- return w(() => {
274
- if (!e) {
275
- s.current?.unsubscribe(), s.current = void 0, n(!1);
276
- return;
277
- }
278
- s.current?.unsubscribe();
279
- const i = e.getService(), d = i.subscribe((v) => {
280
- const h = v?.value, y = v?.context;
281
- n(h === "publishing");
282
- const p = y?._publishError;
283
- a(p ? new Error(p.message) : null);
284
- });
285
- s.current = d;
286
- const u = i.getSnapshot();
287
- n(u?.value === "publishing");
288
- const b = u?.context?._publishError;
289
- return a(b ? new Error(b.message) : null), () => {
290
- s.current?.unsubscribe(), s.current = void 0;
291
- };
292
- }, [e]), {
293
- publishItem: l,
294
- isLoading: r,
295
- error: o,
296
- resetError: c
297
- };
298
- }, he = G("seedSdk:react:property"), oe = G("seedSdk:react:itemProperties");
299
- function We(e, t) {
300
- const r = Q(), [n, o] = S(void 0), [a, s] = S(!1), [c, l] = S(null), i = C(void 0), [, d] = S(0), f = typeof e == "object" && e != null ? e : null, b = f?.itemId, v = f?.seedLocalId, h = f?.seedUid, y = f?.propertyName, p = typeof e == "string" ? e : b !== void 0 && b !== "" ? b : void 0, I = y ?? (typeof e == "string" ? t : void 0), m = N(() => {
301
- const A = p !== void 0 && p !== "" ? p : v, B = p !== void 0 && p !== "" ? void 0 : h;
302
- return (A != null || B != null) && I != null && I !== "" ? {
303
- type: "identifiers",
304
- seedLocalId: A ?? void 0,
305
- seedUid: B,
306
- propertyName: I
307
- } : null;
308
- }, [p, I, v, h]);
309
- N(() => m ? !!((m.seedLocalId || m.seedUid) && m.propertyName) : !1, [m]);
310
- const _ = N(() => !r || !m ? !1 : !!((m.seedLocalId || m.seedUid) && m.propertyName), [r, m]);
311
- st(() => {
312
- _ && s(!0);
313
- }, [_]);
314
- const R = x(async () => {
315
- if (!r || !m) {
316
- o(void 0), s(!1), l(null);
317
- return;
318
- }
319
- try {
320
- s(!0), l(null);
321
- const A = m.seedLocalId, B = m.seedUid;
322
- if (!A && !B) {
323
- o(void 0), s(!1), l(null);
324
- return;
325
- }
326
- const V = await ie.find({
327
- propertyName: m.propertyName,
328
- seedLocalId: A,
329
- seedUid: B
330
- });
331
- if (!V) {
332
- he(
333
- `[useItemProperty] [updateItemProperty] no property found for Item.${A || B}.${m.propertyName}`
334
- ), o(void 0), s(!1), l(null);
335
- return;
336
- }
337
- o(V), s(!1), l(null);
338
- } catch (A) {
339
- he("[useItemProperty] Error updating item property:", A), o(void 0), s(!1), l(A);
340
- }
341
- }, [r, m]);
342
- return w(() => {
343
- if (!_) {
344
- o(void 0), s(!1), l(null);
345
- return;
346
- }
347
- n && m && n.propertyName === m.propertyName && (m.seedLocalId != null && n.seedLocalId === m.seedLocalId || m.seedUid != null && n.seedUid === m.seedUid) || R();
348
- }, [_, R, n, m]), w(() => {
349
- if (!n) {
350
- i.current?.unsubscribe(), i.current = void 0;
351
- return;
352
- }
353
- i.current?.unsubscribe();
354
- let A = 0, B = !1, V;
355
- const L = 50, $ = n.getService().subscribe((F) => {
356
- if (F && typeof F == "object" && "value" in F && F.value === "idle") {
357
- s(!1), l(null);
358
- const M = F.context, J = JSON.stringify([M.renderValue, M.propertyValue]);
359
- (!B || J !== V) && (B = !0, V = J, d((se) => se + 1));
360
- return;
361
- }
362
- B = !1, V = void 0;
363
- const K = Date.now();
364
- K - A >= L && (A = K, d((M) => M + 1));
365
- });
366
- return i.current = $, () => {
367
- i.current?.unsubscribe(), i.current = void 0;
368
- };
369
- }, [n]), {
370
- property: n,
371
- isLoading: a,
372
- error: c
373
- };
55
+ //#endregion
56
+ //#region src/item.ts
57
+ var q = P("seedSdk:react:item"), Se = ({ modelName: e, seedLocalId: t, seedUid: r }) => {
58
+ let [a, l] = c(), [, u] = c(0), [d, f] = c(!!(t || r)), [h, g] = c(null), _ = s(void 0), v = s(!1), y = U(), b = G(), x = s(e), S = s(t), C = s(r), T = o(() => y ? !!(S.current || C.current) : !1, [
59
+ y,
60
+ t,
61
+ r
62
+ ]), E = n(async () => {
63
+ if (!(y && (S.current || C.current))) {
64
+ l(void 0), f(!1), g(null);
65
+ return;
66
+ }
67
+ try {
68
+ g(null);
69
+ let e = await m.find({
70
+ modelName: x.current,
71
+ seedLocalId: S.current,
72
+ seedUid: C.current
73
+ });
74
+ if (!e) {
75
+ q("[useItem] [loadItem] no item found", x.current, S.current), l((e) => {
76
+ if (e) return e.seedLocalId && e.seedLocalId === S.current || e.seedUid && e.seedUid === C.current ? e : void 0;
77
+ }), f(!1), g(null);
78
+ return;
79
+ }
80
+ l(e), f(!1), g(null);
81
+ } catch (e) {
82
+ q("[useItem] Error loading item:", e), l(void 0), f(!1), g(e);
83
+ }
84
+ }, [y]), D = s(E);
85
+ return i(() => {
86
+ D.current = E;
87
+ }, [E]), i(() => {
88
+ x.current = e, S.current = t, C.current = r;
89
+ }, [
90
+ e,
91
+ t,
92
+ r
93
+ ]), i(() => {
94
+ let e = () => {
95
+ u((e) => e + 1), D.current();
96
+ };
97
+ return w.on(p, e), () => {
98
+ w.off(p, e);
99
+ };
100
+ }, []), i(() => {
101
+ if (!T) {
102
+ !t && !r && (l(void 0), f(!1), g(null));
103
+ return;
104
+ }
105
+ E();
106
+ }, [
107
+ T,
108
+ E,
109
+ t,
110
+ r,
111
+ b
112
+ ]), i(() => {
113
+ if (!a) {
114
+ _.current?.unsubscribe(), _.current = void 0, v.current = !1;
115
+ return;
116
+ }
117
+ return _.current?.unsubscribe(), v.current = !1, _.current = a.getService().subscribe((e) => {
118
+ e && typeof e == "object" && "value" in e && (e.value === "idle" ? (v.current = !0, f(!1), g(null)) : e.value === "error" ? (g(/* @__PURE__ */ Error("Item service error")), f(!1)) : v.current && f(!0));
119
+ }), () => {
120
+ _.current?.unsubscribe(), _.current = void 0;
121
+ };
122
+ }, [a]), {
123
+ item: a,
124
+ isLoading: d,
125
+ error: h
126
+ };
127
+ }, Ce = (e, t, n, r, i) => [
128
+ "seed",
129
+ "items",
130
+ e ?? null,
131
+ t ?? !1,
132
+ n ?? !1,
133
+ r ?? null,
134
+ i ?? 0
135
+ ], we = ({ modelName: e, deleted: t = !1, includeEas: n = !1, addressFilter: r }) => {
136
+ let a = U(), l = G(), d = H();
137
+ i(() => {
138
+ let e = () => {
139
+ d.invalidateQueries({ queryKey: ["seed", "items"] });
140
+ };
141
+ return w.on(p, e), () => {
142
+ w.off(p, e);
143
+ };
144
+ }, [d]);
145
+ let f = s([]), h = s(/* @__PURE__ */ new Set()), g = s(!1), [_, v] = c(null);
146
+ i(() => {
147
+ if (r !== "owned" && r !== "watched") {
148
+ v(null);
149
+ return;
150
+ }
151
+ let e = !1;
152
+ return T(r).then((t) => {
153
+ e || v(t);
154
+ }), () => {
155
+ e = !0;
156
+ };
157
+ }, [r, l]);
158
+ let y = o(() => Ce(e, t, n, r, l), [
159
+ e,
160
+ t,
161
+ n,
162
+ r,
163
+ l
164
+ ]);
165
+ i(() => {
166
+ g.current = !1;
167
+ }, [y]);
168
+ let { data: b = [], isLoading: x, error: S } = V({
169
+ queryKey: y,
170
+ queryFn: async () => await m.all(e, t, {
171
+ waitForReady: !0,
172
+ includeEas: n,
173
+ addressFilter: r
174
+ }),
175
+ enabled: a,
176
+ staleTime: 0
177
+ });
178
+ f.current = b;
179
+ let C = a ? u.getAppDb() : null, E = K(o(() => {
180
+ if (!C || (r === "owned" || r === "watched") && _ === null) return null;
181
+ let i = [];
182
+ n || i.push(B(z(N.uid), R(N.uid, ""))), e && i.push(R(N.type, ge(e))), r === "owned" ? _ && _.length > 0 && i.push(B(fe(N.publisher, _), z(N.publisher))) : r === "watched" && (_ && _.length > 0 ? i.push(fe(N.publisher, _)) : i.push(he`1=0`)), t ? i.push(B(pe(N._markedForDeletion), R(N._markedForDeletion, 1))) : (i.push(B(z(N._markedForDeletion), R(N._markedForDeletion, 0))), i.push(B(z(N.revokedAt), R(N.revokedAt, 0))));
183
+ let a = te();
184
+ return C.with(a).select({
185
+ localId: N.localId,
186
+ uid: N.uid,
187
+ type: N.type,
188
+ schemaUid: N.schemaUid,
189
+ createdAt: N.createdAt,
190
+ attestationCreatedAt: N.attestationCreatedAt,
191
+ _markedForDeletion: N._markedForDeletion
192
+ }).from(N).leftJoin(a, R(N.localId, a.seedLocalId)).where(le(de(a.versionsCount, 0), ...i)).groupBy(N.localId);
193
+ }, [
194
+ C,
195
+ a,
196
+ e,
197
+ t,
198
+ n,
199
+ r,
200
+ _
201
+ ]));
202
+ return i(() => {
203
+ if (!a || !E) return;
204
+ let e = /* @__PURE__ */ new Set();
205
+ for (let t of E) {
206
+ let n = t.localId || t.uid;
207
+ n && e.add(n);
208
+ }
209
+ let t = /* @__PURE__ */ new Set();
210
+ for (let e of f.current) {
211
+ let n = e.seedLocalId || e.seedUid;
212
+ n && t.add(n);
213
+ }
214
+ if (e.size === 0 && t.size > 0) return;
215
+ if (!g.current && (g.current = !0, e.size > 0 && t.size === 0)) {
216
+ h.current = new Set(e), d.invalidateQueries({ queryKey: y });
217
+ return;
218
+ }
219
+ let n = h.current;
220
+ if (!(n.size === e.size && [...n].every((t) => e.has(t)))) {
221
+ if (t.size === e.size && [...t].every((t) => e.has(t))) {
222
+ h.current = new Set(e);
223
+ return;
224
+ }
225
+ h.current = new Set(e), d.invalidateQueries({ queryKey: y });
226
+ }
227
+ }, [
228
+ a,
229
+ E,
230
+ d,
231
+ y
232
+ ]), {
233
+ items: oe(b, [(e) => e.lastVersionPublishedAt || e.attestationCreatedAt || e.createdAt], ["desc"]),
234
+ isLoading: x,
235
+ error: S
236
+ };
237
+ }, Te = () => {
238
+ let [e, t] = c(!1), [r, i] = c(null), a = n(() => i(null), []);
239
+ return {
240
+ createItem: n(async (n, r) => {
241
+ if (e) {
242
+ q("[useCreateItem] [createItem] already creating item, skipping");
243
+ return;
244
+ }
245
+ i(null), l(() => t(!0));
246
+ try {
247
+ let { seedLocalId: e } = await S({
248
+ modelName: n,
249
+ ...r ?? {}
250
+ });
251
+ return await m.find({
252
+ modelName: n,
253
+ seedLocalId: e
254
+ }) ?? void 0;
255
+ } catch (e) {
256
+ q("[useCreateItem] Error creating item:", e), i(e instanceof Error ? e : Error(String(e)));
257
+ return;
258
+ } finally {
259
+ queueMicrotask(() => t(!1));
260
+ }
261
+ }, [e]),
262
+ isLoading: e,
263
+ error: r,
264
+ resetError: a
265
+ };
266
+ }, Ee = () => {
267
+ let [e, t] = c(null), [r, a] = c(!1), [o, l] = c(null), u = s(void 0), d = n(() => l(null), []), f = n((e) => {
268
+ e && (t(e), l(null), e.publish().catch(() => {}));
269
+ }, []);
270
+ return i(() => {
271
+ if (!e) {
272
+ u.current?.unsubscribe(), u.current = void 0, a(!1);
273
+ return;
274
+ }
275
+ u.current?.unsubscribe();
276
+ let t = e.getService();
277
+ u.current = t.subscribe((e) => {
278
+ let t = e?.value, n = e?.context;
279
+ a(t === "publishing");
280
+ let r = n?._publishError;
281
+ l(r ? Error(r.message) : null);
282
+ });
283
+ let n = t.getSnapshot();
284
+ a(n?.value === "publishing");
285
+ let r = n?.context?._publishError;
286
+ return l(r ? Error(r.message) : null), () => {
287
+ u.current?.unsubscribe(), u.current = void 0;
288
+ };
289
+ }, [e]), {
290
+ publishItem: f,
291
+ isLoading: r,
292
+ error: o,
293
+ resetError: d
294
+ };
295
+ }, J = P("seedSdk:react:property"), Y = P("seedSdk:react:itemProperties");
296
+ function De(e, t) {
297
+ let r = U(), [l, u] = c(void 0), [d, f] = c(!1), [p, m] = c(null), g = s(void 0), [, _] = c(0), v = typeof e == "object" && e ? e : null, y = v?.itemId, b = v?.seedLocalId, x = v?.seedUid, S = v?.propertyName, C = typeof e == "string" ? e : y !== void 0 && y !== "" ? y : void 0, w = S ?? (typeof e == "string" ? t : void 0), T = o(() => {
298
+ let e = C !== void 0 && C !== "" ? C : b, t = C !== void 0 && C !== "" ? void 0 : x;
299
+ return (e != null || t != null) && w != null && w !== "" ? {
300
+ type: "identifiers",
301
+ seedLocalId: e ?? void 0,
302
+ seedUid: t,
303
+ propertyName: w
304
+ } : null;
305
+ }, [
306
+ C,
307
+ w,
308
+ b,
309
+ x
310
+ ]);
311
+ o(() => T ? !!((T.seedLocalId || T.seedUid) && T.propertyName) : !1, [T]);
312
+ let E = o(() => !r || !T ? !1 : !!((T.seedLocalId || T.seedUid) && T.propertyName), [r, T]);
313
+ a(() => {
314
+ E && f(!0);
315
+ }, [E]);
316
+ let D = n(async () => {
317
+ if (!r || !T) {
318
+ u(void 0), f(!1), m(null);
319
+ return;
320
+ }
321
+ try {
322
+ f(!0), m(null);
323
+ let e = T.seedLocalId, t = T.seedUid;
324
+ if (!e && !t) {
325
+ u(void 0), f(!1), m(null);
326
+ return;
327
+ }
328
+ let n = await h.find({
329
+ propertyName: T.propertyName,
330
+ seedLocalId: e,
331
+ seedUid: t
332
+ });
333
+ if (!n) {
334
+ J(`[useItemProperty] [updateItemProperty] no property found for Item.${e || t}.${T.propertyName}`), u(void 0), f(!1), m(null);
335
+ return;
336
+ }
337
+ u(n), f(!1), m(null);
338
+ } catch (e) {
339
+ J("[useItemProperty] Error updating item property:", e), u(void 0), f(!1), m(e);
340
+ }
341
+ }, [r, T]);
342
+ return i(() => {
343
+ if (!E) {
344
+ u(void 0), f(!1), m(null);
345
+ return;
346
+ }
347
+ l && T && l.propertyName === T.propertyName && (T.seedLocalId != null && l.seedLocalId === T.seedLocalId || T.seedUid != null && l.seedUid === T.seedUid) || D();
348
+ }, [
349
+ E,
350
+ D,
351
+ l,
352
+ T
353
+ ]), i(() => {
354
+ if (!l) {
355
+ g.current?.unsubscribe(), g.current = void 0;
356
+ return;
357
+ }
358
+ g.current?.unsubscribe();
359
+ let e = 0, t = !1, n;
360
+ return g.current = l.getService().subscribe((r) => {
361
+ if (r && typeof r == "object" && "value" in r && r.value === "idle") {
362
+ f(!1), m(null);
363
+ let e = r.context, i = JSON.stringify([e.renderValue, e.propertyValue]);
364
+ (!t || i !== n) && (t = !0, n = i, _((e) => e + 1));
365
+ return;
366
+ }
367
+ t = !1, n = void 0;
368
+ let i = Date.now();
369
+ i - e >= 50 && (e = i, _((e) => e + 1));
370
+ }), () => {
371
+ g.current?.unsubscribe(), g.current = void 0;
372
+ };
373
+ }, [l]), {
374
+ property: l,
375
+ isLoading: d,
376
+ error: p
377
+ };
374
378
  }
375
- function br(e, t = 300) {
376
- const r = "itemId" in e ? e.itemId : void 0, n = "seedLocalId" in e ? e.seedLocalId : void 0, o = "seedUid" in e ? e.seedUid : void 0, a = e.propertyName, s = N(() => r ? { seedLocalId: r, propertyName: a } : { seedLocalId: n, seedUid: o, propertyName: a }, [r, n, o, a]), { property: c, isLoading: l, error: i } = We(s), d = C(""), u = N(
377
- () => He((b) => {
378
- b.getService().send({
379
- type: "save",
380
- newValue: d.current
381
- });
382
- }, t),
383
- [t]
384
- );
385
- w(() => () => u.cancel(), [u]);
386
- const f = x(
387
- (b) => {
388
- c && (d.current = b, c.getService().send({
389
- type: "updateContext",
390
- propertyValue: b,
391
- renderValue: b
392
- }), u(c));
393
- },
394
- [c, u]
395
- );
396
- return {
397
- property: c,
398
- setValue: f,
399
- isLoading: l,
400
- error: i
401
- };
379
+ function Oe(e, t = 300) {
380
+ let r = "itemId" in e ? e.itemId : void 0, a = "seedLocalId" in e ? e.seedLocalId : void 0, c = "seedUid" in e ? e.seedUid : void 0, l = e.propertyName, { property: u, isLoading: d, error: f } = De(o(() => r ? {
381
+ seedLocalId: r,
382
+ propertyName: l
383
+ } : {
384
+ seedLocalId: a,
385
+ seedUid: c,
386
+ propertyName: l
387
+ }, [
388
+ r,
389
+ a,
390
+ c,
391
+ l
392
+ ])), p = s(""), m = o(() => ae((e) => {
393
+ e.getService().send({
394
+ type: "save",
395
+ newValue: p.current
396
+ });
397
+ }, t), [t]);
398
+ return i(() => () => m.cancel(), [m]), {
399
+ property: u,
400
+ setValue: n((e) => {
401
+ u && (p.current = e, u.getService().send({
402
+ type: "updateContext",
403
+ propertyValue: e,
404
+ renderValue: e
405
+ }), m(u));
406
+ }, [u, m]),
407
+ isLoading: d,
408
+ error: f
409
+ };
402
410
  }
403
- async function Et(e, t) {
404
- if (!e && !t) return [];
405
- const r = j.getAppDb();
406
- if (!r) return [];
407
- const n = await ie.all(
408
- { seedLocalId: e ?? void 0, seedUid: t ?? void 0 },
409
- { waitForReady: !0 }
410
- ), o = [...n], a = /* @__PURE__ */ new Set();
411
- for (const l of n)
412
- l.propertyName && a.add(l.propertyName);
413
- let s;
414
- if (n.length > 0) {
415
- const l = n[0];
416
- s = l.modelName ?? l.modelType, s && typeof s == "string" && (s = Pe(s));
417
- }
418
- if (!s) {
419
- const l = await r.select({ type: D.type }).from(D).where(t ? q(D.uid, t) : q(D.localId, e)).limit(1);
420
- l.length > 0 && l[0].type && (s = Pe(l[0].type));
421
- }
422
- const c = [];
423
- if (s)
424
- try {
425
- const { Model: l } = await import("@seedprotocol/sdk"), i = await l.getByNameAsync(s);
426
- if (i?.properties)
427
- for (const d of i.properties)
428
- d.name && c.push(d.name);
429
- } catch (l) {
430
- oe(`[useItemProperties] Error getting ModelProperties for ${s}:`, l);
431
- }
432
- if (s && c.length > 0) {
433
- const l = n.length > 0 ? n[0].seedLocalId ?? e : e, i = n.length > 0 ? n[0].seedUid ?? t : t;
434
- for (const d of c)
435
- if (!a.has(d))
436
- try {
437
- const u = ie.create(
438
- {
439
- propertyName: d,
440
- modelName: s,
441
- seedLocalId: l || void 0,
442
- seedUid: i || void 0,
443
- propertyValue: null
444
- },
445
- { waitForReady: !1 }
446
- );
447
- u && o.push(u);
448
- } catch (u) {
449
- he(`[useItemProperties] Error creating ItemProperty for missing property ${d}:`, u);
450
- }
451
- }
452
- if (e || t) {
453
- const l = await r.select({ createdAt: D.createdAt }).from(D).where(t ? q(D.uid, t) : q(D.localId, e)).limit(1);
454
- if (l.length > 0 && l[0].createdAt) {
455
- const i = "createdAt";
456
- if (!o.some((u) => u.propertyName === i) && s)
457
- try {
458
- const u = n.length > 0 ? n[0].seedLocalId ?? e : e, f = n.length > 0 ? n[0].seedUid ?? t : t, b = ie.create(
459
- {
460
- propertyName: i,
461
- modelName: s,
462
- seedLocalId: u || void 0,
463
- seedUid: f || void 0,
464
- propertyValue: l[0].createdAt.toString()
465
- },
466
- { waitForReady: !1 }
467
- );
468
- b && o.push(b);
469
- } catch (u) {
470
- he("[useItemProperties] Error creating createdAt ItemProperty:", u);
471
- }
472
- }
473
- }
474
- return o;
411
+ async function ke(e, t) {
412
+ if (!e && !t) return [];
413
+ let n = u.getAppDb();
414
+ if (!n) return [];
415
+ let r = await h.all({
416
+ seedLocalId: e ?? void 0,
417
+ seedUid: t ?? void 0
418
+ }, { waitForReady: !0 }), i = [...r], a = /* @__PURE__ */ new Set();
419
+ for (let e of r) e.propertyName && a.add(e.propertyName);
420
+ let o;
421
+ if (r.length > 0) {
422
+ let e = r[0];
423
+ o = e.modelName ?? e.modelType, o && typeof o == "string" && (o = se(o));
424
+ }
425
+ if (!o) {
426
+ let r = await n.select({ type: N.type }).from(N).where(t ? R(N.uid, t) : R(N.localId, e)).limit(1);
427
+ r.length > 0 && r[0].type && (o = se(r[0].type));
428
+ }
429
+ let s = [];
430
+ if (o) try {
431
+ let { Model: e } = await import("@seedprotocol/sdk"), t = await e.getByNameAsync(o);
432
+ if (t?.properties) for (let e of t.properties) e.name && s.push(e.name);
433
+ } catch (e) {
434
+ Y(`[useItemProperties] Error getting ModelProperties for ${o}:`, e);
435
+ }
436
+ if (o && s.length > 0) {
437
+ let n = r.length > 0 ? r[0].seedLocalId ?? e : e, c = r.length > 0 ? r[0].seedUid ?? t : t;
438
+ for (let e of s) if (!a.has(e)) try {
439
+ let t = h.create({
440
+ propertyName: e,
441
+ modelName: o,
442
+ seedLocalId: n || void 0,
443
+ seedUid: c || void 0,
444
+ propertyValue: null
445
+ }, { waitForReady: !1 });
446
+ t && i.push(t);
447
+ } catch (t) {
448
+ J(`[useItemProperties] Error creating ItemProperty for missing property ${e}:`, t);
449
+ }
450
+ }
451
+ if (e || t) {
452
+ let a = await n.select({ createdAt: N.createdAt }).from(N).where(t ? R(N.uid, t) : R(N.localId, e)).limit(1);
453
+ if (a.length > 0 && a[0].createdAt) {
454
+ let n = "createdAt";
455
+ if (!i.some((e) => e.propertyName === n) && o) try {
456
+ let s = r.length > 0 ? r[0].seedLocalId ?? e : e, c = r.length > 0 ? r[0].seedUid ?? t : t, l = h.create({
457
+ propertyName: n,
458
+ modelName: o,
459
+ seedLocalId: s || void 0,
460
+ seedUid: c || void 0,
461
+ propertyValue: a[0].createdAt.toString()
462
+ }, { waitForReady: !1 });
463
+ l && i.push(l);
464
+ } catch (e) {
465
+ J("[useItemProperties] Error creating createdAt ItemProperty:", e);
466
+ }
467
+ }
468
+ }
469
+ return i;
475
470
  }
476
- function Sr(e) {
477
- const t = Q(), r = Z(), n = C(void 0), o = N(() => typeof e == "string" ? { type: "itemId", itemId: e } : typeof e == "object" ? {
478
- type: "identifiers",
479
- seedLocalId: e.seedLocalId,
480
- seedUid: e.seedUid
481
- } : null, [e]), a = N(() => {
482
- if (o)
483
- return o.type === "itemId" ? o.itemId : o.seedLocalId;
484
- }, [o]), s = N(() => {
485
- if (!(!o || o.type === "itemId"))
486
- return o.seedUid;
487
- }, [o]), c = a ?? s ?? "", l = N(
488
- () => ["seed", "itemProperties", c],
489
- [c]
490
- ), {
491
- data: i = [],
492
- isLoading: d,
493
- error: u
494
- } = ee({
495
- queryKey: l,
496
- queryFn: () => Et(a, s),
497
- enabled: t && !!c
498
- }), f = N(() => {
499
- if (!t || !a && !s)
500
- return oe("[useItemProperties] Query: returning null (not ready or no identifiers)"), null;
501
- const h = j.getAppDb();
502
- if (!h)
503
- return oe("[useItemProperties] Query: returning null (no db)"), null;
504
- oe(`[useItemProperties] Query: creating query for seedLocalId=${a}, seedUid=${s}`);
505
- const y = s ? h.select({
506
- propertyName: k.propertyName,
507
- propertyValue: k.propertyValue,
508
- seedLocalId: k.seedLocalId,
509
- seedUid: k.seedUid,
510
- modelType: k.modelType,
511
- schemaUid: k.schemaUid,
512
- createdAt: k.createdAt,
513
- attestationCreatedAt: k.attestationCreatedAt
514
- }).from(k).where(
515
- xe(
516
- q(k.seedUid, s),
517
- Ae(k.propertyName)
518
- )
519
- ) : a ? h.select({
520
- propertyName: k.propertyName,
521
- propertyValue: k.propertyValue,
522
- seedLocalId: k.seedLocalId,
523
- seedUid: k.seedUid,
524
- modelType: k.modelType,
525
- schemaUid: k.schemaUid,
526
- createdAt: k.createdAt,
527
- attestationCreatedAt: k.attestationCreatedAt
528
- }).from(k).where(
529
- xe(
530
- q(k.seedLocalId, a),
531
- Ae(k.propertyName)
532
- )
533
- ) : null;
534
- return oe("[useItemProperties] Query: created query object", { queryType: s ? "seedUid" : "seedLocalId" }), y;
535
- }, [t, a, s]), b = Y(f), v = N(() => {
536
- if (!b || b.length === 0)
537
- return [];
538
- const h = /* @__PURE__ */ new Map();
539
- for (const y of b) {
540
- if (!y.propertyName) continue;
541
- const p = h.get(y.propertyName);
542
- if (!p)
543
- h.set(y.propertyName, y);
544
- else {
545
- const E = p.attestationCreatedAt || p.createdAt || 0;
546
- (y.attestationCreatedAt || y.createdAt || 0) > E && h.set(y.propertyName, y);
547
- }
548
- }
549
- return Array.from(h.values());
550
- }, [b]);
551
- return w(() => {
552
- if (!t || !a && !s || v === void 0) return;
553
- const h = JSON.stringify(
554
- v.map((y) => ({
555
- propertyName: y.propertyName,
556
- propertyValue: y.propertyValue,
557
- seedLocalId: y.seedLocalId,
558
- seedUid: y.seedUid
559
- })).sort((y, p) => (y.propertyName || "").localeCompare(p.propertyName || ""))
560
- );
561
- n.current !== h && (n.current = h, v.length > 0 && r.invalidateQueries({ queryKey: l }));
562
- }, [t, v, i, a, s, r, l]), w(() => {
563
- n.current = void 0;
564
- }, [a, s]), {
565
- properties: i,
566
- isLoading: d,
567
- error: u
568
- };
471
+ function Ae(e) {
472
+ let t = U(), n = H(), r = s(void 0), a = o(() => typeof e == "string" ? {
473
+ type: "itemId",
474
+ itemId: e
475
+ } : typeof e == "object" ? {
476
+ type: "identifiers",
477
+ seedLocalId: e.seedLocalId,
478
+ seedUid: e.seedUid
479
+ } : null, [e]), c = o(() => {
480
+ if (a) return a.type === "itemId" ? a.itemId : a.seedLocalId;
481
+ }, [a]), l = o(() => {
482
+ if (!(!a || a.type === "itemId")) return a.seedUid;
483
+ }, [a]), d = c ?? l ?? "", f = o(() => [
484
+ "seed",
485
+ "itemProperties",
486
+ d
487
+ ], [d]), { data: p = [], isLoading: m, error: h } = V({
488
+ queryKey: f,
489
+ queryFn: () => ke(c, l),
490
+ enabled: t && !!d
491
+ }), g = K(o(() => {
492
+ if (!t || !c && !l) return Y("[useItemProperties] Query: returning null (not ready or no identifiers)"), null;
493
+ let e = u.getAppDb();
494
+ if (!e) return Y("[useItemProperties] Query: returning null (no db)"), null;
495
+ Y(`[useItemProperties] Query: creating query for seedLocalId=${c}, seedUid=${l}`);
496
+ let n = l ? e.select({
497
+ propertyName: O.propertyName,
498
+ propertyValue: O.propertyValue,
499
+ seedLocalId: O.seedLocalId,
500
+ seedUid: O.seedUid,
501
+ modelType: O.modelType,
502
+ schemaUid: O.schemaUid,
503
+ createdAt: O.createdAt,
504
+ attestationCreatedAt: O.attestationCreatedAt
505
+ }).from(O).where(le(R(O.seedUid, l), pe(O.propertyName))) : c ? e.select({
506
+ propertyName: O.propertyName,
507
+ propertyValue: O.propertyValue,
508
+ seedLocalId: O.seedLocalId,
509
+ seedUid: O.seedUid,
510
+ modelType: O.modelType,
511
+ schemaUid: O.schemaUid,
512
+ createdAt: O.createdAt,
513
+ attestationCreatedAt: O.attestationCreatedAt
514
+ }).from(O).where(le(R(O.seedLocalId, c), pe(O.propertyName))) : null;
515
+ return Y("[useItemProperties] Query: created query object", { queryType: l ? "seedUid" : "seedLocalId" }), n;
516
+ }, [
517
+ t,
518
+ c,
519
+ l
520
+ ])), _ = o(() => {
521
+ if (!g || g.length === 0) return [];
522
+ let e = /* @__PURE__ */ new Map();
523
+ for (let t of g) {
524
+ if (!t.propertyName) continue;
525
+ let n = e.get(t.propertyName);
526
+ if (!n) e.set(t.propertyName, t);
527
+ else {
528
+ let r = n.attestationCreatedAt || n.createdAt || 0;
529
+ (t.attestationCreatedAt || t.createdAt || 0) > r && e.set(t.propertyName, t);
530
+ }
531
+ }
532
+ return Array.from(e.values());
533
+ }, [g]);
534
+ return i(() => {
535
+ if (!t || !c && !l || _ === void 0) return;
536
+ let e = JSON.stringify(_.map((e) => ({
537
+ propertyName: e.propertyName,
538
+ propertyValue: e.propertyValue,
539
+ seedLocalId: e.seedLocalId,
540
+ seedUid: e.seedUid
541
+ })).sort((e, t) => (e.propertyName || "").localeCompare(t.propertyName || "")));
542
+ r.current !== e && (r.current = e, _.length > 0 && n.invalidateQueries({ queryKey: f }));
543
+ }, [
544
+ t,
545
+ _,
546
+ p,
547
+ c,
548
+ l,
549
+ n,
550
+ f
551
+ ]), i(() => {
552
+ r.current = void 0;
553
+ }, [c, l]), {
554
+ properties: p,
555
+ isLoading: m,
556
+ error: h
557
+ };
569
558
  }
570
- const vr = () => {
571
- const e = C(void 0), [t, r] = S(!1), [n, o] = S(null), a = x(() => o(null), []), s = x((c) => {
572
- if (!c.propertyName || !c.seedLocalId && !c.seedUid || !c.modelName) {
573
- const d = new Error("seedLocalId or seedUid, propertyName, and modelName are required");
574
- o(d);
575
- return;
576
- }
577
- o(null), r(!0), e.current?.unsubscribe(), e.current = void 0;
578
- const l = ie.create(c, { waitForReady: !1 });
579
- if (!l) {
580
- o(new Error("Failed to create item property")), r(!1);
581
- return;
582
- }
583
- const i = l.getService().subscribe((d) => {
584
- if (d?.value === "error") {
585
- const u = d.context?._loadingError?.error ?? new Error("Failed to create item property");
586
- o(u instanceof Error ? u : new Error(String(u))), r(!1);
587
- }
588
- d?.value === "idle" && (o(null), r(!1));
589
- });
590
- return e.current = i, l;
591
- }, []);
592
- return w(() => () => {
593
- e.current?.unsubscribe(), e.current = void 0;
594
- }, []), {
595
- create: s,
596
- isLoading: t,
597
- error: n,
598
- resetError: a
599
- };
600
- }, wr = () => {
601
- const [e, t] = S(null), [r, n] = S({
602
- isLoading: !1,
603
- error: null
604
- });
605
- w(() => {
606
- if (!e) {
607
- n({ isLoading: !1, error: null });
608
- return;
609
- }
610
- const s = e.getService(), c = () => {
611
- const d = s.getSnapshot().context;
612
- n({
613
- isLoading: !!d._destroyInProgress,
614
- error: d._destroyError ? new Error(d._destroyError.message) : null
615
- });
616
- };
617
- c();
618
- const l = s.subscribe(c);
619
- return () => l.unsubscribe();
620
- }, [e]);
621
- const o = x(async (s) => {
622
- s && (t(s), await s.destroy());
623
- }, []), a = x(() => {
624
- e && e.getService().send({ type: "clearDestroyError" });
625
- }, [e]);
626
- return {
627
- destroy: o,
628
- isLoading: r.isLoading,
629
- error: r.error,
630
- resetError: a
631
- };
632
- }, Ne = G("seedSdk:react:services"), Lt = ["idle", "ready", "done", "success", "initialized"], Je = (e) => {
633
- let t = "actor";
634
- const r = e;
635
- return e && r.uniqueKey && (t = r.uniqueKey), e && !r.uniqueKey && r.logic && r.logic.config && (t = Re(e)), t;
636
- }, ke = (e) => {
637
- let t;
638
- return e && e.getSnapshot() && e.getSnapshot().value && (t = e.getSnapshot().value), Je(e) === "global" && t && typeof t == "object" && Object.keys(t).length > 0 && Object.keys(t)[0] === "initialized" && (t = "ready"), t && typeof t == "object" && (t = JSON.stringify(t)), t;
639
- }, Re = (e) => {
640
- const t = e;
641
- if (!e || !t.logic || !t.logic.config || !t._snapshot)
642
- return;
643
- const r = t.logic.config;
644
- if (!r.id)
645
- return;
646
- let n = r.id;
647
- r.id.includes("@seedSdk/") && (n = r.id.match(/^.*@seedSdk\/(\w+)[\.\w]*/)[1]);
648
- let o;
649
- try {
650
- o = e.getSnapshot();
651
- } catch (a) {
652
- return Ne("Error:", a), n;
653
- }
654
- if (o) {
655
- const a = o.context;
656
- a && a.dbName && (n = a.dbName), a && a.modelNamePlural && (n = a.modelNamePlural), a && a.modelName && (n = vt(a.modelName.toLowerCase()));
657
- }
658
- return n;
659
- }, Ir = (e) => {
660
- const [t, r] = S(0), n = (s) => {
661
- let c = 0;
662
- const l = s;
663
- if (l.logic?.states) {
664
- const i = [], d = [];
665
- for (const [b, v] of Object.entries(l.logic.states))
666
- v.tags?.includes("loading") && (i.push(b), d.push(v));
667
- const u = d.length, f = ke(s);
668
- if (f && Lt.includes(f))
669
- return 0;
670
- f && (c = i.indexOf(f) / u * 100);
671
- }
672
- return c;
673
- }, o = x(
674
- (s) => {
675
- e.getSnapshot().context;
676
- const c = e.getSnapshot().value;
677
- if (c === "done" || c === "success" || c === "idle" || c === "ready") {
678
- clearInterval(s);
679
- return;
680
- }
681
- r((l) => l + 1);
682
- },
683
- [e]
684
- ), a = x(() => {
685
- const s = setInterval(() => {
686
- o(s);
687
- }, 1e3);
688
- return s;
689
- }, [o, e]);
690
- return w(() => {
691
- const s = a();
692
- return () => clearInterval(s);
693
- }, []), {
694
- name: Je(e),
695
- timeElapsed: t,
696
- value: ke(e),
697
- percentComplete: n(e),
698
- uniqueKey: Re(e)
699
- };
700
- }, At = () => {
701
- const [e, t] = S(!1), { internalStatus: r } = _t();
702
- return w(() => {
703
- r === "ready" && t(!0);
704
- }, [r]), w(() => {
705
- r === "ready" && t(!0);
706
- }, []), e;
707
- }, Er = () => {
708
- const [e, t] = S(!1), r = xt(), { services: n, percentComplete: o } = Nt(), a = x(async () => {
709
- for (const c of n) {
710
- const l = Re(c);
711
- Ne(
712
- `would save to db with snapshot__${l}:`,
713
- JSON.stringify(c.getPersistedSnapshot())
714
- );
715
- }
716
- }, [n]), s = x(async () => {
717
- const c = j.getAppDb();
718
- return c ? await c.select().from(fe).where(Qe(fe.key, "snapshot__%")) : [];
719
- }, []);
720
- w(() => !r || e ? void 0 : ((async () => {
721
- const l = await s();
722
- Ne("persistedSnapshots:", l), t(!0);
723
- })(), () => {
724
- a();
725
- }), [r, e]);
726
- }, xt = () => {
727
- const [e, t] = S(!1), r = At();
728
- return w(() => {
729
- r && (async () => {
730
- const a = await j.getAppDb().select().from(fe).where(Qe(fe.key, "snapshot__%"));
731
- a && a.length > 0 && t(!0);
732
- })();
733
- }, [r]), e;
734
- }, Nt = () => {
735
- const [e, t] = S([]), [r, n] = S(5);
736
- return w(() => {
737
- const a = ge().getService(), s = a;
738
- s.uniqueKey = "clientManager", t([s]);
739
- const c = a.subscribe((l) => {
740
- const i = l.value;
741
- let d = 0;
742
- i === P.IDLE ? d = 100 : i === P.ADD_MODELS_TO_DB ? d = 90 : i === P.ADD_MODELS_TO_STORE ? d = 80 : i === P.PROCESS_SCHEMA_FILES ? d = 70 : i === P.SAVE_CONFIG ? d = 60 : i === P.DB_INIT ? d = 50 : i === P.FILE_SYSTEM_INIT ? d = 30 : i === P.PLATFORM_CLASSES_INIT && (d = 10), n(d);
743
- });
744
- return () => {
745
- c.unsubscribe();
746
- };
747
- }, []), {
748
- services: e,
749
- percentComplete: r
750
- };
751
- }, _t = () => {
752
- const t = ge().getService(), r = Le(t, (o) => o.value), n = Le(t, (o) => {
753
- const a = o.value;
754
- return a === P.DB_INIT || a === P.SAVE_CONFIG || a === P.PROCESS_SCHEMA_FILES || a === P.ADD_MODELS_TO_STORE || a === P.ADD_MODELS_TO_DB || a === P.IDLE ? "ready" : a;
755
- });
756
- return {
757
- status: r,
758
- internalStatus: n
759
- };
559
+ var je = () => {
560
+ let e = s(void 0), [t, r] = c(!1), [a, o] = c(null), l = n(() => o(null), []), u = n((t) => {
561
+ if (!t.propertyName || !t.seedLocalId && !t.seedUid || !t.modelName) {
562
+ o(/* @__PURE__ */ Error("seedLocalId or seedUid, propertyName, and modelName are required"));
563
+ return;
564
+ }
565
+ o(null), r(!0), e.current?.unsubscribe(), e.current = void 0;
566
+ let n = h.create(t, { waitForReady: !1 });
567
+ if (!n) {
568
+ o(/* @__PURE__ */ Error("Failed to create item property")), r(!1);
569
+ return;
570
+ }
571
+ return e.current = n.getService().subscribe((e) => {
572
+ if (e?.value === "error") {
573
+ let t = e.context?._loadingError?.error ?? /* @__PURE__ */ Error("Failed to create item property");
574
+ o(t instanceof Error ? t : Error(String(t))), r(!1);
575
+ }
576
+ e?.value === "idle" && (o(null), r(!1));
577
+ }), n;
578
+ }, []);
579
+ return i(() => () => {
580
+ e.current?.unsubscribe(), e.current = void 0;
581
+ }, []), {
582
+ create: u,
583
+ isLoading: t,
584
+ error: a,
585
+ resetError: l
586
+ };
587
+ }, Me = () => {
588
+ let [e, t] = c(null), [r, a] = c({
589
+ isLoading: !1,
590
+ error: null
591
+ });
592
+ i(() => {
593
+ if (!e) {
594
+ a({
595
+ isLoading: !1,
596
+ error: null
597
+ });
598
+ return;
599
+ }
600
+ let t = e.getService(), n = () => {
601
+ let e = t.getSnapshot().context;
602
+ a({
603
+ isLoading: !!e._destroyInProgress,
604
+ error: e._destroyError ? Error(e._destroyError.message) : null
605
+ });
606
+ };
607
+ n();
608
+ let r = t.subscribe(n);
609
+ return () => r.unsubscribe();
610
+ }, [e]);
611
+ let o = n(async (e) => {
612
+ e && (t(e), await e.destroy());
613
+ }, []), s = n(() => {
614
+ e && e.getService().send({ type: "clearDestroyError" });
615
+ }, [e]);
616
+ return {
617
+ destroy: o,
618
+ isLoading: r.isLoading,
619
+ error: r.error,
620
+ resetError: s
621
+ };
622
+ }, Ne = P("seedSdk:react:services"), Pe = [
623
+ "idle",
624
+ "ready",
625
+ "done",
626
+ "success",
627
+ "initialized"
628
+ ], Fe = (e) => {
629
+ let t = "actor", n = e;
630
+ return e && n.uniqueKey && (t = n.uniqueKey), e && !n.uniqueKey && n.logic && n.logic.config && (t = X(e)), t;
631
+ }, Ie = (e) => {
632
+ let t;
633
+ return e && e.getSnapshot() && e.getSnapshot().value && (t = e.getSnapshot().value), Fe(e) === "global" && t && typeof t == "object" && Object.keys(t).length > 0 && Object.keys(t)[0] === "initialized" && (t = "ready"), t && typeof t == "object" && (t = JSON.stringify(t)), t;
634
+ }, X = (e) => {
635
+ let t = e;
636
+ if (!e || !t.logic || !t.logic.config || !t._snapshot) return;
637
+ let n = t.logic.config;
638
+ if (!n.id) return;
639
+ let r = n.id;
640
+ n.id.includes("@seedSdk/") && (r = n.id.match(/^.*@seedSdk\/(\w+)[\.\w]*/)[1]);
641
+ let i;
642
+ try {
643
+ i = e.getSnapshot();
644
+ } catch (e) {
645
+ return Ne("Error:", e), r;
646
+ }
647
+ if (i) {
648
+ let e = i.context;
649
+ e && e.dbName && (r = e.dbName), e && e.modelNamePlural && (r = e.modelNamePlural), e && e.modelName && (r = ye(e.modelName.toLowerCase()));
650
+ }
651
+ return r;
652
+ }, Le = (e) => {
653
+ let [t, r] = c(0), a = (e) => {
654
+ let t = 0, n = e;
655
+ if (n.logic?.states) {
656
+ let r = [], i = [];
657
+ for (let [e, t] of Object.entries(n.logic.states)) t.tags?.includes("loading") && (r.push(e), i.push(t));
658
+ let a = i.length, o = Ie(e);
659
+ if (o && Pe.includes(o)) return 0;
660
+ o && (t = r.indexOf(o) / a * 100);
661
+ }
662
+ return t;
663
+ }, o = n((t) => {
664
+ e.getSnapshot().context;
665
+ let n = e.getSnapshot().value;
666
+ if (n === "done" || n === "success" || n === "idle" || n === "ready") {
667
+ clearInterval(t);
668
+ return;
669
+ }
670
+ r((e) => e + 1);
671
+ }, [e]), s = n(() => {
672
+ let e = setInterval(() => {
673
+ o(e);
674
+ }, 1e3);
675
+ return e;
676
+ }, [o, e]);
677
+ return i(() => {
678
+ let e = s();
679
+ return () => clearInterval(e);
680
+ }, []), {
681
+ name: Fe(e),
682
+ timeElapsed: t,
683
+ value: Ie(e),
684
+ percentComplete: a(e),
685
+ uniqueKey: X(e)
686
+ };
687
+ }, Re = () => {
688
+ let [e, t] = c(!1), { internalStatus: n } = He();
689
+ return i(() => {
690
+ n === "ready" && t(!0);
691
+ }, [n]), i(() => {
692
+ n === "ready" && t(!0);
693
+ }, []), e;
694
+ }, ze = () => {
695
+ let [e, t] = c(!1), r = Be(), { services: a, percentComplete: o } = Ve(), s = n(async () => {
696
+ for (let e of a) Ne(`would save to db with snapshot__${X(e)}:`, JSON.stringify(e.getPersistedSnapshot()));
697
+ }, [a]), l = n(async () => {
698
+ let e = u.getAppDb();
699
+ return e ? await e.select().from(b).where(me(b.key, "snapshot__%")) : [];
700
+ }, []);
701
+ i(() => !r || e ? void 0 : ((async () => {
702
+ Ne("persistedSnapshots:", await l()), t(!0);
703
+ })(), () => {
704
+ s();
705
+ }), [r, e]);
706
+ }, Be = () => {
707
+ let [e, t] = c(!1), n = Re();
708
+ return i(() => {
709
+ n && (async () => {
710
+ let e = await u.getAppDb().select().from(b).where(me(b.key, "snapshot__%"));
711
+ e && e.length > 0 && t(!0);
712
+ })();
713
+ }, [n]), e;
714
+ }, Ve = () => {
715
+ let [e, t] = c([]), [n, r] = c(5);
716
+ return i(() => {
717
+ let e = E().getService(), n = e;
718
+ n.uniqueKey = "clientManager", t([n]);
719
+ let i = e.subscribe((e) => {
720
+ let t = e.value, n = 0;
721
+ t === f.IDLE ? n = 100 : t === f.ADD_MODELS_TO_DB ? n = 90 : t === f.ADD_MODELS_TO_STORE ? n = 80 : t === f.PROCESS_SCHEMA_FILES ? n = 70 : t === f.SAVE_CONFIG ? n = 60 : t === f.DB_INIT ? n = 50 : t === f.FILE_SYSTEM_INIT ? n = 30 : t === f.PLATFORM_CLASSES_INIT && (n = 10), r(n);
722
+ });
723
+ return () => {
724
+ i.unsubscribe();
725
+ };
726
+ }, []), {
727
+ services: e,
728
+ percentComplete: n
729
+ };
730
+ }, He = () => {
731
+ let e = E().getService();
732
+ return {
733
+ status: ce(e, (e) => e.value),
734
+ internalStatus: ce(e, (e) => {
735
+ let t = e.value;
736
+ return t === f.DB_INIT || t === f.SAVE_CONFIG || t === f.PROCESS_SCHEMA_FILES || t === f.ADD_MODELS_TO_STORE || t === f.ADD_MODELS_TO_DB || t === f.IDLE ? "ready" : t;
737
+ })
738
+ };
760
739
  };
761
- G("seedSdk:react:db");
762
- const Lr = () => {
763
- const [e, t] = S(!1), r = x(() => {
764
- e || t(!0);
765
- }, []);
766
- return w(() => {
767
- let n;
768
- return (async () => {
769
- const s = ge().getService(), c = s.getSnapshot().value;
770
- if (c === P.DB_INIT || c === P.SAVE_CONFIG || c === P.PROCESS_SCHEMA_FILES || c === P.ADD_MODELS_TO_STORE || c === P.ADD_MODELS_TO_DB || c === P.IDLE) {
771
- r();
772
- return;
773
- }
774
- n = s.subscribe((l) => {
775
- const i = l.value;
776
- (i === P.DB_INIT || i === P.SAVE_CONFIG || i === P.PROCESS_SCHEMA_FILES || i === P.ADD_MODELS_TO_STORE || i === P.ADD_MODELS_TO_DB || i === P.IDLE) && (r(), n?.unsubscribe());
777
- });
778
- })(), () => {
779
- n && n.unsubscribe();
780
- };
781
- }, []), {
782
- dbsAreReady: e
783
- };
784
- }, Ge = G("seedSdk:react:schema"), Dt = (e) => {
785
- const [t, r] = S(null), [n, o] = S(!!e), [a, s] = S(null), c = C(null), l = Q(), i = x((d) => {
786
- o(!0), s(null);
787
- try {
788
- const u = be.create(d, {
789
- waitForReady: !1
790
- });
791
- r(u);
792
- const f = u.getService();
793
- f.getSnapshot().value === "idle" ? (ue(() => o(!1)), s(null)) : o(!0), c.current = f.subscribe((h) => {
794
- h.value === "idle" ? (ue(() => o(!1)), s(null)) : o(!0);
795
- });
796
- } catch (u) {
797
- return Ge("[useSchema] Error creating schema:", u), s(u), r(null), o(!1), null;
798
- }
799
- }, []);
800
- return w(() => {
801
- if (c.current && (c.current.unsubscribe(), c.current = null), !l) {
802
- r(null), s(null), o(!1);
803
- return;
804
- }
805
- if (!e) {
806
- r(null), s(null), o(!1);
807
- return;
808
- }
809
- return i(e), () => {
810
- c.current && (c.current.unsubscribe(), c.current = null);
811
- };
812
- }, [e, l, i]), {
813
- schema: t,
814
- isLoading: n,
815
- error: a
816
- };
817
- }, we = ["seed", "schemas"], Ar = () => {
818
- const e = Q(), t = Z(), r = C(void 0), n = C([]), {
819
- data: o = [],
820
- isLoading: a,
821
- error: s
822
- } = ee({
823
- queryKey: we,
824
- queryFn: () => be.all({ waitForReady: !0 }),
825
- enabled: e
826
- });
827
- n.current = o;
828
- const c = e ? j.getAppDb() : null, l = N(() => c ? c.select().from(X).orderBy(X.name, Ve(X.version)) : null, [c, e]), i = Y(l);
829
- return w(() => {
830
- if (typeof BroadcastChannel > "u") return;
831
- const d = new BroadcastChannel("seed-schemas-invalidate"), u = () => {
832
- t.invalidateQueries({ queryKey: we });
833
- };
834
- return d.addEventListener("message", u), () => {
835
- d.removeEventListener("message", u), d.close();
836
- };
837
- }, [t]), w(() => {
838
- if (!e || !i)
839
- return;
840
- const d = r.current, u = d ? JSON.stringify(d) : "undefined", f = i ? JSON.stringify(i) : "undefined";
841
- if (u === f && d !== void 0)
842
- return;
843
- r.current = i;
844
- const b = /* @__PURE__ */ new Set();
845
- for (const p of n.current) {
846
- const E = p.id || p.schemaFileId;
847
- if (E)
848
- b.add(E);
849
- else {
850
- const I = p.metadata?.name, m = p.version;
851
- I && m !== void 0 && b.add(`${I}:${m}`);
852
- }
853
- }
854
- const v = /* @__PURE__ */ new Set();
855
- for (const p of i)
856
- p.name !== "Seed Protocol" && (p.schemaFileId ? v.add(p.schemaFileId) : p.name != null && p.version !== void 0 && v.add(`${p.name}:${p.version}`));
857
- const h = b.size === v.size && [...b].every((p) => v.has(p)), y = b.size > 0 && v.size > 0 && [...v].some((p) => !b.has(p));
858
- !h && y && t.invalidateQueries({ queryKey: we });
859
- }, [e, i, t]), {
860
- schemas: o,
861
- isLoading: a,
862
- error: s
863
- };
864
- }, xr = () => {
865
- const e = C(null), [t, r] = S(!1), [n, o] = S(null), a = x(() => o(null), []), s = x((c) => {
866
- o(null), r(!0), e.current?.unsubscribe(), e.current = null;
867
- const l = be.create(c, {
868
- waitForReady: !1
869
- }), i = l.getService().subscribe((d) => {
870
- if (d.value === "error") {
871
- const u = d.context._loadingError?.error;
872
- o(u instanceof Error ? u : new Error("Failed to create schema")), r(!1);
873
- }
874
- d.value === "idle" && (o(null), r(!1));
875
- });
876
- return e.current = i, l;
877
- }, []);
878
- return w(() => () => {
879
- e.current?.unsubscribe(), e.current = null;
880
- }, []), {
881
- createSchema: s,
882
- isLoading: t,
883
- error: n,
884
- resetError: a
885
- };
886
- }, Nr = () => {
887
- const [e, t] = S(null), [r, n] = S({
888
- isLoading: !1,
889
- error: null
890
- });
891
- w(() => {
892
- if (!e) {
893
- n({ isLoading: !1, error: null });
894
- return;
895
- }
896
- const s = e.getService(), c = () => {
897
- const d = s.getSnapshot().context;
898
- n({
899
- isLoading: !!d._destroyInProgress,
900
- error: d._destroyError ? new Error(d._destroyError.message) : null
901
- });
902
- };
903
- c();
904
- const l = s.subscribe(c);
905
- return () => l.unsubscribe();
906
- }, [e]);
907
- const o = x(async (s) => {
908
- s && (t(s), await s.destroy());
909
- }, []), a = x(() => {
910
- e && e.getService().send({ type: "clearDestroyError" });
911
- }, [e]);
912
- return {
913
- destroy: o,
914
- isLoading: r.isLoading,
915
- error: r.error,
916
- resetError: a
917
- };
918
- }, _r = () => {
919
- const [e, t] = S(), r = C(/* @__PURE__ */ new Map()), n = Q(), o = x(async () => {
920
- if (n)
921
- try {
922
- const a = await ct(), s = /* @__PURE__ */ new Set();
923
- for (const l of a) {
924
- const i = l.schema.metadata?.name;
925
- i && s.add(i);
926
- }
927
- const c = /* @__PURE__ */ new Map();
928
- for (const l of s)
929
- if (r.current.has(l)) {
930
- const i = r.current.get(l);
931
- c.set(l, i);
932
- } else {
933
- const i = be.create(l, {
934
- waitForReady: !1
935
- });
936
- c.set(l, i);
937
- }
938
- for (const [l, i] of r.current.entries())
939
- s.has(l) || i.unload();
940
- r.current = c, t(Array.from(c.values()));
941
- } catch (a) {
942
- Ge("Error fetching all schema versions from database:", a), t(null);
943
- }
944
- }, [n]);
945
- return w(() => {
946
- n && o();
947
- }, [n, o]), w(() => () => {
948
- r.current.forEach((a) => {
949
- a.unload();
950
- }), r.current.clear();
951
- }, []), e;
952
- }, Dr = () => Dt(lt), Ft = (e) => ["seed", "models", e], $e = /* @__PURE__ */ new Map(), Ct = (e) => {
953
- const t = Q(), r = Z(), n = C([]), o = N(() => Ft(e), [e]), {
954
- data: a = [],
955
- isLoading: s,
956
- error: c
957
- } = ee({
958
- queryKey: o,
959
- queryFn: async () => {
960
- const y = r.getQueryData(o), p = await ae.all(e, { waitForReady: !1 });
961
- if (Array.isArray(y) && y.length > 0 && Array.isArray(p) && p.length === 0)
962
- return [...y];
963
- if (Array.isArray(p) && p.length === 0) {
964
- const E = r.getQueryData(o);
965
- if (Array.isArray(E) && E.length > 0)
966
- return [...E];
967
- }
968
- return p;
969
- },
970
- enabled: t && !!e
971
- }), l = e && typeof e == "string" ? e : "";
972
- a.length > 0 && $e.set(l, a);
973
- const i = n.current.length > 0 ? n.current : $e.get(l), d = e ? a.length > 0 ? a : i?.length ? i : a : a;
974
- n.current = d, w(() => {
975
- if (!e || typeof BroadcastChannel > "u") return;
976
- const y = new BroadcastChannel("seed-models-invalidate"), p = (E) => {
977
- const { schemaName: I, schemaFileId: m } = E.data || {};
978
- (e === I || e === m) && (r.invalidateQueries({ queryKey: o }), r.refetchQueries({ queryKey: o }));
979
- };
980
- return y.addEventListener("message", p), () => {
981
- y.removeEventListener("message", p), y.close();
982
- };
983
- }, [e, r, o]);
984
- const u = C(null), f = C(null);
985
- function b() {
986
- const y = j.getAppDb();
987
- return !y || !e ? null : y.select({
988
- modelFileId: ce.schemaFileId,
989
- modelName: ce.name
990
- }).from(X).innerJoin(ve, q(X.id, ve.schemaId)).innerJoin(ce, q(ve.modelId, ce.id)).where(
991
- re(
992
- q(X.schemaFileId, e),
993
- q(X.name, e)
994
- )
995
- );
996
- }
997
- const v = N(() => {
998
- if (!e || !t) return null;
999
- const y = { schemaId: e, ready: t }, p = u.current;
1000
- if (p && p.schemaId === y.schemaId && p.ready === y.ready && f.current !== null)
1001
- return f.current;
1002
- const E = b();
1003
- return E ? (u.current = y, f.current = E, E) : null;
1004
- }, [e, t]), h = Y(v);
1005
- return w(() => {
1006
- if (!t || !h || !e) return;
1007
- const y = /* @__PURE__ */ new Set();
1008
- for (const m of n.current) {
1009
- const _ = m.id || m.modelFileId;
1010
- _ ? y.add(_) : m.modelName && y.add(m.modelName);
1011
- }
1012
- const p = /* @__PURE__ */ new Set();
1013
- for (const m of h)
1014
- m.modelFileId ? p.add(m.modelFileId) : m.modelName && p.add(m.modelName);
1015
- const E = y.size === p.size && [...y].every((m) => p.has(m)), I = p.size > 0 && [...p].some((m) => !y.has(m));
1016
- !E && I && r.invalidateQueries({ queryKey: o });
1017
- }, [t, h, e, r, o]), {
1018
- models: d,
1019
- isLoading: s,
1020
- error: c
1021
- };
1022
- }, Rt = (e, t) => {
1023
- const r = Q(), [n, o] = S(void 0), [a, s] = S(!1), [c, l] = S(null), i = C(void 0), [, d] = S(0), u = t == null;
1024
- if (N(() => r ? u ? !!e : !!(e && t) : !1, [r, u, e, t]), w(() => {
1025
- if (!r || !u || !e) {
1026
- o(void 0), s(!1), l(null);
1027
- return;
1028
- }
1029
- (async () => {
1030
- try {
1031
- s(!0), l(null);
1032
- const p = await ae.createById(e);
1033
- o(p || void 0), s(!1), l(null);
1034
- } catch (p) {
1035
- console.error("[useModel] Error looking up model by ID:", p), o(void 0), s(!1), l(p);
1036
- }
1037
- })();
1038
- }, [r, u, e]), w(() => {
1039
- if (!u || !n) {
1040
- i.current?.unsubscribe(), i.current = void 0;
1041
- return;
1042
- }
1043
- i.current?.unsubscribe();
1044
- const y = n.getService().subscribe((p) => {
1045
- d((E) => E + 1);
1046
- });
1047
- return i.current = y, () => {
1048
- i.current?.unsubscribe(), i.current = void 0;
1049
- };
1050
- }, [u, n]), u)
1051
- return {
1052
- model: n,
1053
- isLoading: a,
1054
- error: c
1055
- };
1056
- const { models: f, isLoading: b, error: v } = Ct(e), h = N(() => {
1057
- if (t)
1058
- return f.find((y) => (y.modelName ?? y.name) === t);
1059
- }, [f, t]);
1060
- return w(() => {
1061
- if (u || !h) {
1062
- i.current?.unsubscribe(), i.current = void 0;
1063
- return;
1064
- }
1065
- i.current?.unsubscribe();
1066
- const y = h.getService().subscribe((p) => {
1067
- d((E) => E + 1);
1068
- });
1069
- return i.current = y, () => {
1070
- i.current?.unsubscribe(), i.current = void 0;
1071
- };
1072
- }, [u, h]), {
1073
- model: h,
1074
- isLoading: b,
1075
- error: v
1076
- };
1077
- }, Fr = () => {
1078
- const e = C(void 0), [t, r] = S(!1), [n, o] = S(null), a = x(() => o(null), []), s = x(
1079
- (c, l, i) => {
1080
- o(null), r(!0), e.current?.unsubscribe(), e.current = void 0;
1081
- const d = ae.create(l, c, {
1082
- ...i,
1083
- waitForReady: !1
1084
- }), u = d.getService().subscribe((f) => {
1085
- f.value === "error" && (o(
1086
- f.context._loadingError?.error ?? new Error("Failed to create model")
1087
- ), r(!1)), f.value === "idle" && (o(null), r(!1));
1088
- });
1089
- return e.current = u, d;
1090
- },
1091
- []
1092
- );
1093
- return w(() => () => {
1094
- e.current?.unsubscribe(), e.current = void 0;
1095
- }, []), {
1096
- create: s,
1097
- isLoading: t,
1098
- error: n,
1099
- resetError: a
1100
- };
1101
- }, Cr = () => {
1102
- const [e, t] = S(null), [r, n] = S({
1103
- isLoading: !1,
1104
- error: null
1105
- });
1106
- w(() => {
1107
- if (!e) {
1108
- n({ isLoading: !1, error: null });
1109
- return;
1110
- }
1111
- const s = e.getService(), c = () => {
1112
- const d = s.getSnapshot().context;
1113
- n({
1114
- isLoading: !!d._destroyInProgress,
1115
- error: d._destroyError ? new Error(d._destroyError.message) : null
1116
- });
1117
- };
1118
- c();
1119
- const l = s.subscribe(c);
1120
- return () => l.unsubscribe();
1121
- }, [e]);
1122
- const o = x(async (s) => {
1123
- s && (t(s), await s.destroy());
1124
- }, []), a = x(() => {
1125
- e && e.getService().send({ type: "clearDestroyError" });
1126
- }, [e]);
1127
- return {
1128
- destroy: o,
1129
- isLoading: r.isLoading,
1130
- error: r.error,
1131
- resetError: a
1132
- };
740
+ //#endregion
741
+ //#region src/db.ts
742
+ P("seedSdk:react:db");
743
+ var Ue = () => {
744
+ let [e, t] = c(!1), r = n(() => {
745
+ e || t(!0);
746
+ }, []);
747
+ return i(() => {
748
+ let e;
749
+ return (async () => {
750
+ let t = E().getService(), n = t.getSnapshot().value;
751
+ if (n === f.DB_INIT || n === f.SAVE_CONFIG || n === f.PROCESS_SCHEMA_FILES || n === f.ADD_MODELS_TO_STORE || n === f.ADD_MODELS_TO_DB || n === f.IDLE) {
752
+ r();
753
+ return;
754
+ }
755
+ e = t.subscribe((t) => {
756
+ let n = t.value;
757
+ (n === f.DB_INIT || n === f.SAVE_CONFIG || n === f.PROCESS_SCHEMA_FILES || n === f.ADD_MODELS_TO_STORE || n === f.ADD_MODELS_TO_DB || n === f.IDLE) && (r(), e?.unsubscribe());
758
+ });
759
+ })(), () => {
760
+ e && e.unsubscribe();
761
+ };
762
+ }, []), { dbsAreReady: e };
763
+ }, We = P("seedSdk:react:schema"), Ge = (e) => {
764
+ let [t, r] = c(null), [a, o] = c(!!e), [u, d] = c(null), f = s(null), p = U(), m = n((e) => {
765
+ o(!0), d(null);
766
+ try {
767
+ let t = y.create(e, { waitForReady: !1 });
768
+ r(t);
769
+ let n = t.getService();
770
+ n.getSnapshot().value === "idle" ? (l(() => o(!1)), d(null)) : o(!0), f.current = n.subscribe((e) => {
771
+ e.value === "idle" ? (l(() => o(!1)), d(null)) : o(!0);
772
+ });
773
+ } catch (e) {
774
+ return We("[useSchema] Error creating schema:", e), d(e), r(null), o(!1), null;
775
+ }
776
+ }, []);
777
+ return i(() => {
778
+ if (f.current && (f.current.unsubscribe(), f.current = null), !p) {
779
+ r(null), d(null), o(!1);
780
+ return;
781
+ }
782
+ if (!e) {
783
+ r(null), d(null), o(!1);
784
+ return;
785
+ }
786
+ return m(e), () => {
787
+ f.current && (f.current.unsubscribe(), f.current = null);
788
+ };
789
+ }, [
790
+ e,
791
+ p,
792
+ m
793
+ ]), {
794
+ schema: t,
795
+ isLoading: a,
796
+ error: u
797
+ };
798
+ }, Ke = ["seed", "schemas"], qe = () => {
799
+ let e = U(), t = H(), n = s(void 0), r = s([]), { data: a = [], isLoading: c, error: l } = V({
800
+ queryKey: Ke,
801
+ queryFn: () => y.all({ waitForReady: !0 }),
802
+ enabled: e
803
+ });
804
+ r.current = a;
805
+ let d = e ? u.getAppDb() : null, f = K(o(() => d ? d.select().from(M).orderBy(M.name, ue(M.version)) : null, [d, e]));
806
+ return i(() => {
807
+ if (typeof BroadcastChannel > "u") return;
808
+ let e = new BroadcastChannel("seed-schemas-invalidate"), n = () => {
809
+ t.invalidateQueries({ queryKey: Ke });
810
+ };
811
+ return e.addEventListener("message", n), () => {
812
+ e.removeEventListener("message", n), e.close();
813
+ };
814
+ }, [t]), i(() => {
815
+ if (!e || !f) return;
816
+ let i = n.current;
817
+ if ((i ? JSON.stringify(i) : "undefined") === (f ? JSON.stringify(f) : "undefined") && i !== void 0) return;
818
+ n.current = f;
819
+ let a = /* @__PURE__ */ new Set();
820
+ for (let e of r.current) {
821
+ let t = e.id || e.schemaFileId;
822
+ if (t) a.add(t);
823
+ else {
824
+ let t = e.metadata?.name, n = e.version;
825
+ t && n !== void 0 && a.add(`${t}:${n}`);
826
+ }
827
+ }
828
+ let o = /* @__PURE__ */ new Set();
829
+ for (let e of f) e.name !== "Seed Protocol" && (e.schemaFileId ? o.add(e.schemaFileId) : e.name != null && e.version !== void 0 && o.add(`${e.name}:${e.version}`));
830
+ let s = a.size === o.size && [...a].every((e) => o.has(e)), c = a.size > 0 && o.size > 0 && [...o].some((e) => !a.has(e));
831
+ !s && c && t.invalidateQueries({ queryKey: Ke });
832
+ }, [
833
+ e,
834
+ f,
835
+ t
836
+ ]), {
837
+ schemas: a,
838
+ isLoading: c,
839
+ error: l
840
+ };
841
+ }, Je = () => {
842
+ let e = s(null), [t, r] = c(!1), [a, o] = c(null), l = n(() => o(null), []), u = n((t) => {
843
+ o(null), r(!0), e.current?.unsubscribe(), e.current = null;
844
+ let n = y.create(t, { waitForReady: !1 });
845
+ return e.current = n.getService().subscribe((e) => {
846
+ if (e.value === "error") {
847
+ let t = e.context._loadingError?.error;
848
+ o(t instanceof Error ? t : /* @__PURE__ */ Error("Failed to create schema")), r(!1);
849
+ }
850
+ e.value === "idle" && (o(null), r(!1));
851
+ }), n;
852
+ }, []);
853
+ return i(() => () => {
854
+ e.current?.unsubscribe(), e.current = null;
855
+ }, []), {
856
+ createSchema: u,
857
+ isLoading: t,
858
+ error: a,
859
+ resetError: l
860
+ };
861
+ }, Ye = () => {
862
+ let [e, t] = c(null), [r, a] = c({
863
+ isLoading: !1,
864
+ error: null
865
+ });
866
+ i(() => {
867
+ if (!e) {
868
+ a({
869
+ isLoading: !1,
870
+ error: null
871
+ });
872
+ return;
873
+ }
874
+ let t = e.getService(), n = () => {
875
+ let e = t.getSnapshot().context;
876
+ a({
877
+ isLoading: !!e._destroyInProgress,
878
+ error: e._destroyError ? Error(e._destroyError.message) : null
879
+ });
880
+ };
881
+ n();
882
+ let r = t.subscribe(n);
883
+ return () => r.unsubscribe();
884
+ }, [e]);
885
+ let o = n(async (e) => {
886
+ e && (t(e), await e.destroy());
887
+ }, []), s = n(() => {
888
+ e && e.getService().send({ type: "clearDestroyError" });
889
+ }, [e]);
890
+ return {
891
+ destroy: o,
892
+ isLoading: r.isLoading,
893
+ error: r.error,
894
+ resetError: s
895
+ };
896
+ }, Xe = () => {
897
+ let [e, t] = c(), r = s(/* @__PURE__ */ new Map()), a = U(), o = n(async () => {
898
+ if (a) try {
899
+ let e = await ne(), n = /* @__PURE__ */ new Set();
900
+ for (let t of e) {
901
+ let e = t.schema.metadata?.name;
902
+ e && n.add(e);
903
+ }
904
+ let i = /* @__PURE__ */ new Map();
905
+ for (let e of n) if (r.current.has(e)) {
906
+ let t = r.current.get(e);
907
+ i.set(e, t);
908
+ } else {
909
+ let t = y.create(e, { waitForReady: !1 });
910
+ i.set(e, t);
911
+ }
912
+ for (let [e, t] of r.current.entries()) n.has(e) || t.unload();
913
+ r.current = i, t(Array.from(i.values()));
914
+ } catch (e) {
915
+ We("Error fetching all schema versions from database:", e), t(null);
916
+ }
917
+ }, [a]);
918
+ return i(() => {
919
+ a && o();
920
+ }, [a, o]), i(() => () => {
921
+ r.current.forEach((e) => {
922
+ e.unload();
923
+ }), r.current.clear();
924
+ }, []), e;
925
+ }, Ze = () => Ge(v), Qe = (e) => [
926
+ "seed",
927
+ "models",
928
+ e
929
+ ], $e = /* @__PURE__ */ new Map(), et = (e) => {
930
+ let t = U(), n = H(), r = s([]), a = o(() => Qe(e), [e]), { data: c = [], isLoading: l, error: d } = V({
931
+ queryKey: a,
932
+ queryFn: async () => {
933
+ let t = n.getQueryData(a), r = await g.all(e, { waitForReady: !1 });
934
+ if (Array.isArray(t) && t.length > 0 && Array.isArray(r) && r.length === 0) return [...t];
935
+ if (Array.isArray(r) && r.length === 0) {
936
+ let e = n.getQueryData(a);
937
+ if (Array.isArray(e) && e.length > 0) return [...e];
938
+ }
939
+ return r;
940
+ },
941
+ enabled: t && !!e
942
+ }), f = e && typeof e == "string" ? e : "";
943
+ c.length > 0 && $e.set(f, c);
944
+ let p = r.current.length > 0 ? r.current : $e.get(f), m = e ? c.length > 0 ? c : p?.length ? p : c : c;
945
+ r.current = m, i(() => {
946
+ if (!e || typeof BroadcastChannel > "u") return;
947
+ let t = new BroadcastChannel("seed-models-invalidate"), r = (t) => {
948
+ let { schemaName: r, schemaFileId: i } = t.data || {};
949
+ (e === r || e === i) && (n.invalidateQueries({ queryKey: a }), n.refetchQueries({ queryKey: a }));
950
+ };
951
+ return t.addEventListener("message", r), () => {
952
+ t.removeEventListener("message", r), t.close();
953
+ };
954
+ }, [
955
+ e,
956
+ n,
957
+ a
958
+ ]);
959
+ let h = s(null), _ = s(null);
960
+ function v() {
961
+ let t = u.getAppDb();
962
+ return !t || !e ? null : t.select({
963
+ modelFileId: A.schemaFileId,
964
+ modelName: A.name
965
+ }).from(M).innerJoin(k, R(M.id, k.schemaId)).innerJoin(A, R(k.modelId, A.id)).where(B(R(M.schemaFileId, e), R(M.name, e)));
966
+ }
967
+ let y = K(o(() => {
968
+ if (!e || !t) return null;
969
+ let n = {
970
+ schemaId: e,
971
+ ready: t
972
+ }, r = h.current;
973
+ if (r && r.schemaId === n.schemaId && r.ready === n.ready && _.current !== null) return _.current;
974
+ let i = v();
975
+ return i ? (h.current = n, _.current = i, i) : null;
976
+ }, [e, t]));
977
+ return i(() => {
978
+ if (!t || !y || !e) return;
979
+ let i = /* @__PURE__ */ new Set();
980
+ for (let e of r.current) {
981
+ let t = e.id || e.modelFileId;
982
+ t ? i.add(t) : e.modelName && i.add(e.modelName);
983
+ }
984
+ let o = /* @__PURE__ */ new Set();
985
+ for (let e of y) e.modelFileId ? o.add(e.modelFileId) : e.modelName && o.add(e.modelName);
986
+ let s = i.size === o.size && [...i].every((e) => o.has(e)), c = o.size > 0 && [...o].some((e) => !i.has(e));
987
+ !s && c && n.invalidateQueries({ queryKey: a });
988
+ }, [
989
+ t,
990
+ y,
991
+ e,
992
+ n,
993
+ a
994
+ ]), {
995
+ models: m,
996
+ isLoading: l,
997
+ error: d
998
+ };
999
+ }, tt = (e, t) => {
1000
+ let n = U(), [r, a] = c(void 0), [l, u] = c(!1), [d, f] = c(null), p = s(void 0), [, m] = c(0), h = t == null;
1001
+ if (o(() => n ? h ? !!e : !!(e && t) : !1, [
1002
+ n,
1003
+ h,
1004
+ e,
1005
+ t
1006
+ ]), i(() => {
1007
+ if (!n || !h || !e) {
1008
+ a(void 0), u(!1), f(null);
1009
+ return;
1010
+ }
1011
+ (async () => {
1012
+ try {
1013
+ u(!0), f(null), a(await g.createById(e) || void 0), u(!1), f(null);
1014
+ } catch (e) {
1015
+ console.error("[useModel] Error looking up model by ID:", e), a(void 0), u(!1), f(e);
1016
+ }
1017
+ })();
1018
+ }, [
1019
+ n,
1020
+ h,
1021
+ e
1022
+ ]), i(() => {
1023
+ if (!h || !r) {
1024
+ p.current?.unsubscribe(), p.current = void 0;
1025
+ return;
1026
+ }
1027
+ return p.current?.unsubscribe(), p.current = r.getService().subscribe((e) => {
1028
+ m((e) => e + 1);
1029
+ }), () => {
1030
+ p.current?.unsubscribe(), p.current = void 0;
1031
+ };
1032
+ }, [h, r]), h) return {
1033
+ model: r,
1034
+ isLoading: l,
1035
+ error: d
1036
+ };
1037
+ let { models: _, isLoading: v, error: y } = et(e), b = o(() => {
1038
+ if (t) return _.find((e) => (e.modelName ?? e.name) === t);
1039
+ }, [_, t]);
1040
+ return i(() => {
1041
+ if (h || !b) {
1042
+ p.current?.unsubscribe(), p.current = void 0;
1043
+ return;
1044
+ }
1045
+ return p.current?.unsubscribe(), p.current = b.getService().subscribe((e) => {
1046
+ m((e) => e + 1);
1047
+ }), () => {
1048
+ p.current?.unsubscribe(), p.current = void 0;
1049
+ };
1050
+ }, [h, b]), {
1051
+ model: b,
1052
+ isLoading: v,
1053
+ error: y
1054
+ };
1055
+ }, nt = () => {
1056
+ let e = s(void 0), [t, r] = c(!1), [a, o] = c(null), l = n(() => o(null), []), u = n((t, n, i) => {
1057
+ o(null), r(!0), e.current?.unsubscribe(), e.current = void 0;
1058
+ let a = g.create(n, t, {
1059
+ ...i,
1060
+ waitForReady: !1
1061
+ });
1062
+ return e.current = a.getService().subscribe((e) => {
1063
+ e.value === "error" && (o(e.context._loadingError?.error ?? /* @__PURE__ */ Error("Failed to create model")), r(!1)), e.value === "idle" && (o(null), r(!1));
1064
+ }), a;
1065
+ }, []);
1066
+ return i(() => () => {
1067
+ e.current?.unsubscribe(), e.current = void 0;
1068
+ }, []), {
1069
+ create: u,
1070
+ isLoading: t,
1071
+ error: a,
1072
+ resetError: l
1073
+ };
1074
+ }, rt = () => {
1075
+ let [e, t] = c(null), [r, a] = c({
1076
+ isLoading: !1,
1077
+ error: null
1078
+ });
1079
+ i(() => {
1080
+ if (!e) {
1081
+ a({
1082
+ isLoading: !1,
1083
+ error: null
1084
+ });
1085
+ return;
1086
+ }
1087
+ let t = e.getService(), n = () => {
1088
+ let e = t.getSnapshot().context;
1089
+ a({
1090
+ isLoading: !!e._destroyInProgress,
1091
+ error: e._destroyError ? Error(e._destroyError.message) : null
1092
+ });
1093
+ };
1094
+ n();
1095
+ let r = t.subscribe(n);
1096
+ return () => r.unsubscribe();
1097
+ }, [e]);
1098
+ let o = n(async (e) => {
1099
+ e && (t(e), await e.destroy());
1100
+ }, []), s = n(() => {
1101
+ e && e.getService().send({ type: "clearDestroyError" });
1102
+ }, [e]);
1103
+ return {
1104
+ destroy: o,
1105
+ isLoading: r.isLoading,
1106
+ error: r.error,
1107
+ resetError: s
1108
+ };
1133
1109
  };
1134
- G("seedSdk:browser:react:modelProperty");
1135
- const Rr = (e, t) => {
1136
- const { model: r } = Rt(e, t);
1137
- N(() => {
1138
- if (r)
1139
- try {
1140
- return r.modelName ?? r.name;
1141
- } catch {
1142
- return;
1143
- }
1144
- }, [r]);
1145
- const n = Q(), o = Z(), a = N(() => {
1146
- if (!r) return null;
1147
- try {
1148
- return r._getSnapshotContext()._dbId;
1149
- } catch {
1150
- return null;
1151
- }
1152
- }, [r]), s = r?.id, c = N(
1153
- () => ["seed", "modelProperties", s ?? ""],
1154
- [s]
1155
- ), {
1156
- data: l = [],
1157
- isLoading: i,
1158
- error: d
1159
- } = ee({
1160
- queryKey: c,
1161
- queryFn: () => ye.all(s, { waitForReady: !0 }),
1162
- enabled: n && !!s
1163
- }), u = n ? j.getAppDb() : null, f = N(() => !u || !a ? null : u.select({
1164
- id: te.id,
1165
- name: te.name,
1166
- dataType: te.dataType,
1167
- schemaFileId: te.schemaFileId
1168
- }).from(te).where(q(te.modelId, a)), [u, n, a]), b = Y(f), v = C([]);
1169
- v.current = l, w(() => {
1170
- if (!s || l.length > 0 || !o || !c) return;
1171
- const p = [400, 1200, 2500].map(
1172
- (E) => setTimeout(() => {
1173
- o.invalidateQueries({ queryKey: c });
1174
- }, E)
1175
- );
1176
- return () => p.forEach((E) => clearTimeout(E));
1177
- }, [s, l.length, o, c]), w(() => {
1178
- if (!n || !r?.id || !b || !c) return;
1179
- const y = /* @__PURE__ */ new Set();
1180
- for (const m of v.current) {
1181
- const R = m._getSnapshotContext()?.id;
1182
- R ? y.add(R) : m.name && y.add(m.name);
1183
- }
1184
- const p = /* @__PURE__ */ new Set();
1185
- for (const m of b)
1186
- m.schemaFileId ? p.add(m.schemaFileId) : m.name && p.add(m.name);
1187
- !(y.size === p.size && (y.size === 0 || [...y].every((m) => p.has(m)))) && (y.size > 0 || p.size > 0) && o.invalidateQueries({ queryKey: c });
1188
- }, [n, b, r?.id, o, c]);
1189
- const h = i && l.length === 0;
1190
- return {
1191
- modelProperties: l,
1192
- isLoading: h,
1193
- error: d
1194
- };
1195
- }, Pt = async (e, t) => {
1196
- const r = await ae.createById(e);
1197
- if (!r)
1198
- return;
1199
- const n = r.modelName ?? r.name;
1200
- if (n)
1201
- return ze(n, t);
1110
+ //#endregion
1111
+ //#region src/modelProperty.ts
1112
+ P("seedSdk:browser:react:modelProperty");
1113
+ var it = (e, t) => {
1114
+ let { model: n } = tt(e, t);
1115
+ o(() => {
1116
+ if (n) try {
1117
+ return n.modelName ?? n.name;
1118
+ } catch {
1119
+ return;
1120
+ }
1121
+ }, [n]);
1122
+ let r = U(), a = H(), c = o(() => {
1123
+ if (!n) return null;
1124
+ try {
1125
+ return n._getSnapshotContext()._dbId;
1126
+ } catch {
1127
+ return null;
1128
+ }
1129
+ }, [n]), l = n?.id, d = o(() => [
1130
+ "seed",
1131
+ "modelProperties",
1132
+ l ?? ""
1133
+ ], [l]), { data: f = [], isLoading: p, error: m } = V({
1134
+ queryKey: d,
1135
+ queryFn: () => _.all(l, { waitForReady: !0 }),
1136
+ enabled: r && !!l
1137
+ }), h = r ? u.getAppDb() : null, g = K(o(() => !h || !c ? null : h.select({
1138
+ id: j.id,
1139
+ name: j.name,
1140
+ dataType: j.dataType,
1141
+ schemaFileId: j.schemaFileId
1142
+ }).from(j).where(R(j.modelId, c)), [
1143
+ h,
1144
+ r,
1145
+ c
1146
+ ])), v = s([]);
1147
+ return v.current = f, i(() => {
1148
+ if (!l || f.length > 0 || !a || !d) return;
1149
+ let e = [
1150
+ 400,
1151
+ 1200,
1152
+ 2500
1153
+ ].map((e) => setTimeout(() => {
1154
+ a.invalidateQueries({ queryKey: d });
1155
+ }, e));
1156
+ return () => e.forEach((e) => clearTimeout(e));
1157
+ }, [
1158
+ l,
1159
+ f.length,
1160
+ a,
1161
+ d
1162
+ ]), i(() => {
1163
+ if (!r || !n?.id || !g || !d) return;
1164
+ let e = /* @__PURE__ */ new Set();
1165
+ for (let t of v.current) {
1166
+ let n = t._getSnapshotContext()?.id;
1167
+ n ? e.add(n) : t.name && e.add(t.name);
1168
+ }
1169
+ let t = /* @__PURE__ */ new Set();
1170
+ for (let e of g) e.schemaFileId ? t.add(e.schemaFileId) : e.name && t.add(e.name);
1171
+ !(e.size === t.size && (e.size === 0 || [...e].every((e) => t.has(e)))) && (e.size > 0 || t.size > 0) && a.invalidateQueries({ queryKey: d });
1172
+ }, [
1173
+ r,
1174
+ g,
1175
+ n?.id,
1176
+ a,
1177
+ d
1178
+ ]), {
1179
+ modelProperties: f,
1180
+ isLoading: p && f.length === 0,
1181
+ error: m
1182
+ };
1183
+ }, at = async (e, t) => {
1184
+ let n = await g.createById(e);
1185
+ if (!n) return;
1186
+ let r = n.modelName ?? n.name;
1187
+ if (r) return D(r, t);
1202
1188
  };
1203
- function Pr(e, t, r) {
1204
- const n = N(() => r != null ? !!(e && t && r) : t != null ? !!(e && t) : !!e, [e, t, r]), [o, a] = S(void 0), [s, c] = S(n), [l, i] = S(null), d = C(void 0), u = Q(), f = N(() => r != null ? { type: "schemaId", schemaId: e, modelName: t, propertyName: r } : t != null ? { type: "modelFileId", modelFileId: e, propertyName: t } : { type: "propertyFileId", propertyFileId: e }, [e, t, r]), b = N(() => u ? f.type === "propertyFileId" ? !!f.propertyFileId : f.type === "modelFileId" ? !!(f.modelFileId && f.propertyName) : !!(f.schemaId && f.modelName && f.propertyName) : !1, [u, f]), v = x(async () => {
1205
- if (!u) {
1206
- a(void 0), c(!1), i(null);
1207
- return;
1208
- }
1209
- let y, p;
1210
- try {
1211
- if (c(!0), i(null), f.type === "propertyFileId") {
1212
- if (!f.propertyFileId) {
1213
- a(void 0), c(!1), i(null);
1214
- return;
1215
- }
1216
- const E = await ye.createById(f.propertyFileId);
1217
- E ? (a(E), c(!1), i(null)) : (a(void 0), c(!1), i(null));
1218
- return;
1219
- } else if (f.type === "modelFileId") {
1220
- if (!f.modelFileId || !f.propertyName) {
1221
- a(void 0), c(!1), i(null);
1222
- return;
1223
- }
1224
- y = await Pt(f.modelFileId, f.propertyName);
1225
- const E = await ae.createById(f.modelFileId);
1226
- p = E?.modelName ?? E?.name;
1227
- } else {
1228
- if (!f.schemaId || !f.modelName || !f.propertyName) {
1229
- a(void 0), c(!1), i(null);
1230
- return;
1231
- }
1232
- y = await ze(f.modelName, f.propertyName), p = f.modelName;
1233
- }
1234
- if (y && p) {
1235
- const E = ye.create(
1236
- { ...y, modelName: p },
1237
- { waitForReady: !1 }
1238
- ), I = E instanceof Promise ? await E : E;
1239
- ue(() => {
1240
- a(I), c(!1), i(null);
1241
- });
1242
- } else
1243
- a(void 0), c(!1), i(null);
1244
- } catch (E) {
1245
- console.error("[useModelProperty] Error updating model property:", E), a(void 0), c(!1), i(E);
1246
- }
1247
- }, [u, f.type, f.propertyFileId, f.modelFileId, f.propertyName, f.schemaId, f.modelName]);
1248
- w(() => {
1249
- if (!b) {
1250
- a(void 0), c(!1), i(null);
1251
- return;
1252
- }
1253
- v();
1254
- }, [b, v]);
1255
- const h = f.type === "propertyFileId";
1256
- return w(() => {
1257
- if (!o || !h)
1258
- return;
1259
- d.current?.unsubscribe();
1260
- const y = He(v, 100), p = o.getService().subscribe(() => {
1261
- y();
1262
- });
1263
- return d.current = p, () => {
1264
- y.cancel(), d.current?.unsubscribe(), d.current = void 0;
1265
- };
1266
- }, [o, v, h]), {
1267
- modelProperty: o,
1268
- isLoading: s,
1269
- error: l
1270
- };
1189
+ function ot(e, t, r) {
1190
+ let a = o(() => r == null ? t == null ? !!e : !!(e && t) : !!(e && t && r), [
1191
+ e,
1192
+ t,
1193
+ r
1194
+ ]), [u, d] = c(void 0), [f, p] = c(a), [m, h] = c(null), v = s(void 0), y = U(), b = o(() => r == null ? t == null ? {
1195
+ type: "propertyFileId",
1196
+ propertyFileId: e
1197
+ } : {
1198
+ type: "modelFileId",
1199
+ modelFileId: e,
1200
+ propertyName: t
1201
+ } : {
1202
+ type: "schemaId",
1203
+ schemaId: e,
1204
+ modelName: t,
1205
+ propertyName: r
1206
+ }, [
1207
+ e,
1208
+ t,
1209
+ r
1210
+ ]), x = o(() => y ? b.type === "propertyFileId" ? !!b.propertyFileId : b.type === "modelFileId" ? !!(b.modelFileId && b.propertyName) : !!(b.schemaId && b.modelName && b.propertyName) : !1, [y, b]), S = n(async () => {
1211
+ if (!y) {
1212
+ d(void 0), p(!1), h(null);
1213
+ return;
1214
+ }
1215
+ let e, t;
1216
+ try {
1217
+ if (p(!0), h(null), b.type === "propertyFileId") {
1218
+ if (!b.propertyFileId) {
1219
+ d(void 0), p(!1), h(null);
1220
+ return;
1221
+ }
1222
+ let e = await _.createById(b.propertyFileId);
1223
+ e ? (d(e), p(!1), h(null)) : (d(void 0), p(!1), h(null));
1224
+ return;
1225
+ } else if (b.type === "modelFileId") {
1226
+ if (!b.modelFileId || !b.propertyName) {
1227
+ d(void 0), p(!1), h(null);
1228
+ return;
1229
+ }
1230
+ e = await at(b.modelFileId, b.propertyName);
1231
+ let n = await g.createById(b.modelFileId);
1232
+ t = n?.modelName ?? n?.name;
1233
+ } else {
1234
+ if (!b.schemaId || !b.modelName || !b.propertyName) {
1235
+ d(void 0), p(!1), h(null);
1236
+ return;
1237
+ }
1238
+ e = await D(b.modelName, b.propertyName), t = b.modelName;
1239
+ }
1240
+ if (e && t) {
1241
+ let n = _.create({
1242
+ ...e,
1243
+ modelName: t
1244
+ }, { waitForReady: !1 }), r = n instanceof Promise ? await n : n;
1245
+ l(() => {
1246
+ d(r), p(!1), h(null);
1247
+ });
1248
+ } else d(void 0), p(!1), h(null);
1249
+ } catch (e) {
1250
+ console.error("[useModelProperty] Error updating model property:", e), d(void 0), p(!1), h(e);
1251
+ }
1252
+ }, [
1253
+ y,
1254
+ b.type,
1255
+ b.propertyFileId,
1256
+ b.modelFileId,
1257
+ b.propertyName,
1258
+ b.schemaId,
1259
+ b.modelName
1260
+ ]);
1261
+ i(() => {
1262
+ if (!x) {
1263
+ d(void 0), p(!1), h(null);
1264
+ return;
1265
+ }
1266
+ S();
1267
+ }, [x, S]);
1268
+ let C = b.type === "propertyFileId";
1269
+ return i(() => {
1270
+ if (!u || !C) return;
1271
+ v.current?.unsubscribe();
1272
+ let e = ae(S, 100);
1273
+ return v.current = u.getService().subscribe(() => {
1274
+ e();
1275
+ }), () => {
1276
+ e.cancel(), v.current?.unsubscribe(), v.current = void 0;
1277
+ };
1278
+ }, [
1279
+ u,
1280
+ S,
1281
+ C
1282
+ ]), {
1283
+ modelProperty: u,
1284
+ isLoading: f,
1285
+ error: m
1286
+ };
1271
1287
  }
1272
- const Tr = () => {
1273
- const e = C(void 0), [t, r] = S(!1), [n, o] = S(null), a = x(() => o(null), []), s = x(
1274
- (c, l, i) => {
1275
- if (o(null), r(!0), e.current?.unsubscribe(), e.current = void 0, !l || !i.name || !i.dataType) {
1276
- const b = new Error("modelName, property name and dataType are required");
1277
- throw o(b), r(!1), b;
1278
- }
1279
- const d = dt(c) ?? c, u = ye.create(
1280
- { ...i, modelName: l },
1281
- { waitForReady: !1, schemaName: d }
1282
- ), f = u.getService().subscribe((b) => {
1283
- if (b.value === "error") {
1284
- const v = b.context._loadingError?.error ?? new Error("Failed to create model property");
1285
- o(v instanceof Error ? v : new Error(String(v))), r(!1);
1286
- }
1287
- b.value === "idle" && (o(null), r(!1));
1288
- });
1289
- return e.current = f, u;
1290
- },
1291
- []
1292
- );
1293
- return w(() => () => {
1294
- e.current?.unsubscribe(), e.current = void 0;
1295
- }, []), {
1296
- create: s,
1297
- isLoading: t,
1298
- error: n,
1299
- resetError: a
1300
- };
1301
- }, Mr = () => {
1302
- const [e, t] = S(null), [r, n] = S({
1303
- isLoading: !1,
1304
- error: null
1305
- });
1306
- w(() => {
1307
- if (!e) {
1308
- n({ isLoading: !1, error: null });
1309
- return;
1310
- }
1311
- const s = e.getService(), c = () => {
1312
- const d = s.getSnapshot().context;
1313
- n({
1314
- isLoading: !!d._destroyInProgress,
1315
- error: d._destroyError ? new Error(d._destroyError.message) : null
1316
- });
1317
- };
1318
- c();
1319
- const l = s.subscribe(c);
1320
- return () => l.unsubscribe();
1321
- }, [e]);
1322
- const o = x(async (s) => {
1323
- s && (t(s), await s.destroy());
1324
- }, []), a = x(() => {
1325
- e && e.getService().send({ type: "clearDestroyError" });
1326
- }, [e]);
1327
- return {
1328
- destroy: o,
1329
- isLoading: r.isLoading,
1330
- error: r.error,
1331
- resetError: a
1332
- };
1333
- }, kr = () => {
1334
- const [e, t] = S(null), [r, n] = S({
1335
- isLoading: !1,
1336
- error: null
1337
- });
1338
- w(() => {
1339
- if (!e) {
1340
- n({ isLoading: !1, error: null });
1341
- return;
1342
- }
1343
- const s = e.getService(), c = () => {
1344
- const d = s.getSnapshot().context;
1345
- n({
1346
- isLoading: !!d._destroyInProgress,
1347
- error: d._destroyError ? new Error(d._destroyError.message) : null
1348
- });
1349
- };
1350
- c();
1351
- const l = s.subscribe(c);
1352
- return () => l.unsubscribe();
1353
- }, [e]);
1354
- const o = x(async (s) => {
1355
- s && (t(s), await s.destroy());
1356
- }, []), a = x(() => {
1357
- e && e.getService().send({ type: "clearDestroyError" });
1358
- }, [e]);
1359
- return {
1360
- deleteItem: o,
1361
- isLoading: r.isLoading,
1362
- error: r.error,
1363
- resetError: a
1364
- };
1365
- }, Ie = ["seed", "imageFiles"];
1366
- function $r() {
1367
- const e = Q(), t = Z(), {
1368
- data: r = [],
1369
- isLoading: n,
1370
- error: o,
1371
- refetch: a
1372
- } = ee({
1373
- queryKey: Ie,
1374
- queryFn: () => W.listImageFiles(),
1375
- enabled: e
1376
- });
1377
- return w(() => {
1378
- const s = (l) => {
1379
- l.includes("/images/") && t.invalidateQueries({ queryKey: Ie });
1380
- }, c = () => {
1381
- t.invalidateQueries({ queryKey: Ie });
1382
- };
1383
- return z.on("file-saved", s), z.on("fs.downloadAll.success", c), () => {
1384
- z.off("file-saved", s), z.off("fs.downloadAll.success", c);
1385
- };
1386
- }, [t]), {
1387
- imageFiles: r,
1388
- isLoading: n,
1389
- error: o instanceof Error ? o : null,
1390
- refetch: a
1391
- };
1288
+ var st = () => {
1289
+ let e = s(void 0), [t, r] = c(!1), [a, o] = c(null), l = n(() => o(null), []), u = n((t, n, i) => {
1290
+ if (o(null), r(!0), e.current?.unsubscribe(), e.current = void 0, !n || !i.name || !i.dataType) {
1291
+ let e = /* @__PURE__ */ Error("modelName, property name and dataType are required");
1292
+ throw o(e), r(!1), e;
1293
+ }
1294
+ let a = ee(t) ?? t, s = _.create({
1295
+ ...i,
1296
+ modelName: n
1297
+ }, {
1298
+ waitForReady: !1,
1299
+ schemaName: a
1300
+ });
1301
+ return e.current = s.getService().subscribe((e) => {
1302
+ if (e.value === "error") {
1303
+ let t = e.context._loadingError?.error ?? /* @__PURE__ */ Error("Failed to create model property");
1304
+ o(t instanceof Error ? t : Error(String(t))), r(!1);
1305
+ }
1306
+ e.value === "idle" && (o(null), r(!1));
1307
+ }), s;
1308
+ }, []);
1309
+ return i(() => () => {
1310
+ e.current?.unsubscribe(), e.current = void 0;
1311
+ }, []), {
1312
+ create: u,
1313
+ isLoading: t,
1314
+ error: a,
1315
+ resetError: l
1316
+ };
1317
+ }, ct = () => {
1318
+ let [e, t] = c(null), [r, a] = c({
1319
+ isLoading: !1,
1320
+ error: null
1321
+ });
1322
+ i(() => {
1323
+ if (!e) {
1324
+ a({
1325
+ isLoading: !1,
1326
+ error: null
1327
+ });
1328
+ return;
1329
+ }
1330
+ let t = e.getService(), n = () => {
1331
+ let e = t.getSnapshot().context;
1332
+ a({
1333
+ isLoading: !!e._destroyInProgress,
1334
+ error: e._destroyError ? Error(e._destroyError.message) : null
1335
+ });
1336
+ };
1337
+ n();
1338
+ let r = t.subscribe(n);
1339
+ return () => r.unsubscribe();
1340
+ }, [e]);
1341
+ let o = n(async (e) => {
1342
+ e && (t(e), await e.destroy());
1343
+ }, []), s = n(() => {
1344
+ e && e.getService().send({ type: "clearDestroyError" });
1345
+ }, [e]);
1346
+ return {
1347
+ destroy: o,
1348
+ isLoading: r.isLoading,
1349
+ error: r.error,
1350
+ resetError: s
1351
+ };
1352
+ }, lt = () => {
1353
+ let [e, t] = c(null), [r, a] = c({
1354
+ isLoading: !1,
1355
+ error: null
1356
+ });
1357
+ i(() => {
1358
+ if (!e) {
1359
+ a({
1360
+ isLoading: !1,
1361
+ error: null
1362
+ });
1363
+ return;
1364
+ }
1365
+ let t = e.getService(), n = () => {
1366
+ let e = t.getSnapshot().context;
1367
+ a({
1368
+ isLoading: !!e._destroyInProgress,
1369
+ error: e._destroyError ? Error(e._destroyError.message) : null
1370
+ });
1371
+ };
1372
+ n();
1373
+ let r = t.subscribe(n);
1374
+ return () => r.unsubscribe();
1375
+ }, [e]);
1376
+ let o = n(async (e) => {
1377
+ e && (t(e), await e.destroy());
1378
+ }, []), s = n(() => {
1379
+ e && e.getService().send({ type: "clearDestroyError" });
1380
+ }, [e]);
1381
+ return {
1382
+ deleteItem: o,
1383
+ isLoading: r.isLoading,
1384
+ error: r.error,
1385
+ resetError: s
1386
+ };
1387
+ }, ut = ["seed", "imageFiles"];
1388
+ function dt() {
1389
+ let e = U(), t = H(), { data: n = [], isLoading: r, error: a, refetch: o } = V({
1390
+ queryKey: ut,
1391
+ queryFn: () => d.listImageFiles(),
1392
+ enabled: e
1393
+ });
1394
+ return i(() => {
1395
+ let e = (e) => {
1396
+ e.includes("/images/") && t.invalidateQueries({ queryKey: ut });
1397
+ }, n = () => {
1398
+ t.invalidateQueries({ queryKey: ut });
1399
+ };
1400
+ return w.on("file-saved", e), w.on("fs.downloadAll.success", n), () => {
1401
+ w.off("file-saved", e), w.off("fs.downloadAll.success", n);
1402
+ };
1403
+ }, [t]), {
1404
+ imageFiles: n,
1405
+ isLoading: r,
1406
+ error: a instanceof Error ? a : null,
1407
+ refetch: o
1408
+ };
1392
1409
  }
1393
- const Tt = ["seed", "files"];
1394
- function Br(e = "files") {
1395
- const t = Q(), r = Z(), n = N(() => [...Tt, e], [e]), {
1396
- data: o = [],
1397
- isLoading: a,
1398
- error: s,
1399
- refetch: c
1400
- } = ee({
1401
- queryKey: n,
1402
- queryFn: () => W.listFiles(e),
1403
- enabled: t
1404
- });
1405
- return w(() => {
1406
- const l = (d) => {
1407
- d.includes(`/${e}/`) && r.invalidateQueries({ queryKey: n });
1408
- }, i = () => {
1409
- r.invalidateQueries({ queryKey: n });
1410
- };
1411
- return z.on("file-saved", l), z.on("fs.downloadAll.success", i), () => {
1412
- z.off("file-saved", l), z.off("fs.downloadAll.success", i);
1413
- };
1414
- }, [r, e, n]), {
1415
- files: o,
1416
- isLoading: a,
1417
- error: s instanceof Error ? s : null,
1418
- refetch: c
1419
- };
1410
+ //#endregion
1411
+ //#region src/useFiles.ts
1412
+ var ft = ["seed", "files"];
1413
+ function pt(e = "files") {
1414
+ let t = U(), n = H(), r = o(() => [...ft, e], [e]), { data: a = [], isLoading: s, error: c, refetch: l } = V({
1415
+ queryKey: r,
1416
+ queryFn: () => d.listFiles(e),
1417
+ enabled: t
1418
+ });
1419
+ return i(() => {
1420
+ let t = (t) => {
1421
+ t.includes(`/${e}/`) && n.invalidateQueries({ queryKey: r });
1422
+ }, i = () => {
1423
+ n.invalidateQueries({ queryKey: r });
1424
+ };
1425
+ return w.on("file-saved", t), w.on("fs.downloadAll.success", i), () => {
1426
+ w.off("file-saved", t), w.off("fs.downloadAll.success", i);
1427
+ };
1428
+ }, [
1429
+ n,
1430
+ e,
1431
+ r
1432
+ ]), {
1433
+ files: a,
1434
+ isLoading: s,
1435
+ error: c instanceof Error ? c : null,
1436
+ refetch: l
1437
+ };
1420
1438
  }
1421
- function Ye() {
1422
- const e = j.getAppDb();
1423
- return N(
1424
- () => e ? e.select().from(pe).orderBy(Ve(pe.startedAt)) : null,
1425
- [e]
1426
- );
1439
+ //#endregion
1440
+ //#region src/useEasSyncProcesses.ts
1441
+ function mt() {
1442
+ let e = u.getAppDb();
1443
+ return o(() => e ? e.select().from(C).orderBy(ue(C.startedAt)) : null, [e]);
1427
1444
  }
1428
- function Mt() {
1429
- const e = Ye(), t = Y(e), r = N(
1430
- () => t === void 0 ? void 0 : t.filter((n) => n.status !== "in_progress").length,
1431
- [t]
1432
- );
1433
- return { records: t, nonActiveCount: r };
1445
+ function ht() {
1446
+ let e = K(mt());
1447
+ return {
1448
+ records: e,
1449
+ nonActiveCount: o(() => e === void 0 ? void 0 : e.filter((e) => e.status !== "in_progress").length, [e])
1450
+ };
1434
1451
  }
1435
- function Or() {
1436
- const e = Ye();
1437
- return Y(e);
1452
+ function gt() {
1453
+ return K(mt());
1438
1454
  }
1439
- function Ur() {
1440
- return Mt().nonActiveCount;
1455
+ function _t() {
1456
+ return ht().nonActiveCount;
1441
1457
  }
1442
- function qr(e) {
1443
- const t = j.getAppDb(), r = N(
1444
- () => e != null && t ? t.select().from(pe).where(q(pe.id, e)).limit(1) : null,
1445
- [t, e]
1446
- ), n = Y(r), o = n === void 0;
1447
- return { record: n && n.length > 0 ? n[0] : null, isLoading: o };
1458
+ function vt(e) {
1459
+ let t = u.getAppDb(), n = K(o(() => e != null && t ? t.select().from(C).where(R(C.id, e)).limit(1) : null, [t, e])), r = n === void 0;
1460
+ return {
1461
+ record: n && n.length > 0 ? n[0] : null,
1462
+ isLoading: r
1463
+ };
1448
1464
  }
1449
- const kt = {
1450
- queries: {
1451
- networkMode: "offlineFirst",
1452
- gcTime: 1e3 * 60 * 60 * 24,
1453
- // 24 hours
1454
- staleTime: 1e3 * 60
1455
- // 1 minute - list data can be slightly stale
1456
- }
1457
- };
1458
- function Xe() {
1459
- return { ...kt };
1465
+ //#endregion
1466
+ //#region src/queryClient.ts
1467
+ var yt = { queries: {
1468
+ networkMode: "offlineFirst",
1469
+ gcTime: 1e3 * 60 * 60 * 24,
1470
+ staleTime: 1e3 * 60
1471
+ } };
1472
+ function bt() {
1473
+ return { ...yt };
1460
1474
  }
1461
- function $t(e) {
1462
- const t = Xe();
1463
- return e ? {
1464
- queries: {
1465
- ...t.queries,
1466
- ...e.queries ?? {}
1467
- },
1468
- mutations: {
1469
- ...t.mutations ?? {},
1470
- ...e.mutations ?? {}
1471
- }
1472
- } : t;
1475
+ function xt(e) {
1476
+ let t = bt();
1477
+ return e ? {
1478
+ queries: {
1479
+ ...t.queries,
1480
+ ...e.queries ?? {}
1481
+ },
1482
+ mutations: {
1483
+ ...t.mutations ?? {},
1484
+ ...e.mutations ?? {}
1485
+ }
1486
+ } : t;
1473
1487
  }
1474
- function Bt(e) {
1475
- const t = Xe(), { defaultOptions: r, ...n } = e ?? {};
1476
- return new bt({
1477
- ...n,
1478
- defaultOptions: r ? $t(r) : t
1479
- });
1488
+ function St(e) {
1489
+ let t = bt(), { defaultOptions: n, ...r } = e ?? {};
1490
+ return new _e({
1491
+ ...r,
1492
+ defaultOptions: n ? xt(n) : t
1493
+ });
1480
1494
  }
1481
- let _e = null;
1482
- function zr(e) {
1483
- const t = _e?.(e);
1484
- return typeof window < "u" && window.__SEED_INVALIDATE_ITEM_PROPERTIES__ && window.__SEED_INVALIDATE_ITEM_PROPERTIES__(e), Promise.resolve(t).then(() => {
1485
- });
1495
+ //#endregion
1496
+ //#region src/SeedProvider.tsx
1497
+ var Ct = null;
1498
+ function wt(e) {
1499
+ let t = Ct?.(e);
1500
+ return typeof window < "u" && window.__SEED_INVALIDATE_ITEM_PROPERTIES__ && window.__SEED_INVALIDATE_ITEM_PROPERTIES__(e), Promise.resolve(t).then(() => {});
1486
1501
  }
1487
- function Ot({ queryClient: e }) {
1488
- return w(() => {
1489
- const t = (o) => {
1490
- const a = ["seed", "itemProperties", o];
1491
- return e.invalidateQueries({ queryKey: a }), e.refetchQueries({ queryKey: a });
1492
- };
1493
- _e = t, typeof window < "u" && (window.__SEED_INVALIDATE_ITEM_PROPERTIES__ = t);
1494
- const r = (o) => {
1495
- const a = o?.seedLocalId ?? o?.seedUid;
1496
- a && t(a);
1497
- }, n = () => {
1498
- e.invalidateQueries({ queryKey: ["seed", "items"], exact: !1 });
1499
- };
1500
- return z.on("itemProperty.saved", r), z.on(ne, n), () => {
1501
- z.off("itemProperty.saved", r), z.off(ne, n), _e = null, typeof window < "u" && (window.__SEED_INVALIDATE_ITEM_PROPERTIES__ = null);
1502
- };
1503
- }, [e]), null;
1502
+ function Tt({ queryClient: e }) {
1503
+ return i(() => {
1504
+ let t = (t) => {
1505
+ let n = [
1506
+ "seed",
1507
+ "itemProperties",
1508
+ t
1509
+ ];
1510
+ return e.invalidateQueries({ queryKey: n }), e.refetchQueries({ queryKey: n });
1511
+ };
1512
+ Ct = t, typeof window < "u" && (window.__SEED_INVALIDATE_ITEM_PROPERTIES__ = t);
1513
+ let n = (e) => {
1514
+ let n = e?.seedLocalId ?? e?.seedUid;
1515
+ n && t(n);
1516
+ }, r = () => {
1517
+ e.invalidateQueries({
1518
+ queryKey: ["seed", "items"],
1519
+ exact: !1
1520
+ });
1521
+ };
1522
+ return w.on("itemProperty.saved", n), w.on(p, r), () => {
1523
+ w.off("itemProperty.saved", n), w.off(p, r), Ct = null, typeof window < "u" && (window.__SEED_INVALIDATE_ITEM_PROPERTIES__ = null);
1524
+ };
1525
+ }, [e]), null;
1504
1526
  }
1505
- function Hr({ children: e, queryClient: t, queryClientRef: r }) {
1506
- const n = N(
1507
- () => t ?? Bt(),
1508
- [t]
1509
- );
1510
- if (r && (r.current = n, typeof window < "u")) {
1511
- const o = window;
1512
- o.__TEST_SEED_QUERY_CLIENT__ = n;
1513
- try {
1514
- window.parent && window.parent !== window && (window.parent.__TEST_SEED_QUERY_CLIENT__ = n);
1515
- } catch {
1516
- }
1517
- }
1518
- return /* @__PURE__ */ g(St, { client: n, children: /* @__PURE__ */ U(wt, { queryClient: n, children: [
1519
- /* @__PURE__ */ g(Ot, { queryClient: n }),
1520
- e
1521
- ] }) });
1527
+ function Et({ children: e, queryClient: t, queryClientRef: n }) {
1528
+ let r = o(() => t ?? St(), [t]);
1529
+ if (n && (n.current = r, typeof window < "u")) {
1530
+ let e = window;
1531
+ e.__TEST_SEED_QUERY_CLIENT__ = r;
1532
+ try {
1533
+ window.parent && window.parent !== window && (window.parent.__TEST_SEED_QUERY_CLIENT__ = r);
1534
+ } catch {}
1535
+ }
1536
+ return /* @__PURE__ */ I(ve, {
1537
+ client: r,
1538
+ children: /* @__PURE__ */ L(xe, {
1539
+ queryClient: r,
1540
+ children: [/* @__PURE__ */ I(Tt, { queryClient: r }), e]
1541
+ })
1542
+ });
1522
1543
  }
1523
- function Ut() {
1524
- return /* @__PURE__ */ g(
1525
- "div",
1526
- {
1527
- style: {
1528
- display: "flex",
1529
- alignItems: "center",
1530
- justifyContent: "center",
1531
- height: "100%",
1532
- width: "100%"
1533
- },
1534
- children: "Loading..."
1535
- }
1536
- );
1544
+ //#endregion
1545
+ //#region src/SeedClientGate.tsx
1546
+ function Dt() {
1547
+ return /* @__PURE__ */ I("div", {
1548
+ style: {
1549
+ display: "flex",
1550
+ alignItems: "center",
1551
+ justifyContent: "center",
1552
+ height: "100%",
1553
+ width: "100%"
1554
+ },
1555
+ children: "Loading..."
1556
+ });
1537
1557
  }
1538
- function Qr({
1539
- initConfig: e,
1540
- schema: t,
1541
- loadingComponent: r,
1542
- wrapperClassName: n,
1543
- loadingClassName: o,
1544
- children: a
1545
- }) {
1546
- const s = Q();
1547
- w(() => {
1548
- const u = t ? {
1549
- ...e,
1550
- config: {
1551
- ...e.config,
1552
- schema: t
1553
- }
1554
- } : e;
1555
- ut.init(u);
1556
- }, [e, t]);
1557
- const c = r ?? /* @__PURE__ */ g(Ut, {}), l = n ? void 0 : { position: "relative", display: "flex", height: "100vh", width: "100vw" }, i = {
1558
- display: s ? "none" : "flex",
1559
- ...!o && {
1560
- position: "absolute",
1561
- inset: 0,
1562
- zIndex: 50,
1563
- alignItems: "center",
1564
- justifyContent: "center"
1565
- }
1566
- };
1567
- return /* @__PURE__ */ U("div", { className: n, style: l, children: [
1568
- /* @__PURE__ */ g(
1569
- "div",
1570
- {
1571
- className: o,
1572
- style: i,
1573
- "aria-hidden": s,
1574
- children: c
1575
- }
1576
- ),
1577
- /* @__PURE__ */ g("div", { style: {
1578
- flex: 1,
1579
- display: s ? "flex" : "none",
1580
- flexDirection: "column"
1581
- }, children: a })
1582
- ] });
1558
+ function Ot({ initConfig: e, schema: t, loadingComponent: n, wrapperClassName: r, loadingClassName: a, children: o }) {
1559
+ let s = U();
1560
+ i(() => {
1561
+ let n = t ? {
1562
+ ...e,
1563
+ config: {
1564
+ ...e.config,
1565
+ schema: t
1566
+ }
1567
+ } : e;
1568
+ x.init(n);
1569
+ }, [e, t]);
1570
+ let c = n ?? /* @__PURE__ */ I(Dt, {});
1571
+ return /* @__PURE__ */ L("div", {
1572
+ className: r,
1573
+ style: r ? void 0 : {
1574
+ position: "relative",
1575
+ display: "flex",
1576
+ height: "100vh",
1577
+ width: "100vw"
1578
+ },
1579
+ children: [/* @__PURE__ */ I("div", {
1580
+ className: a,
1581
+ style: {
1582
+ display: s ? "none" : "flex",
1583
+ ...!a && {
1584
+ position: "absolute",
1585
+ inset: 0,
1586
+ zIndex: 50,
1587
+ alignItems: "center",
1588
+ justifyContent: "center"
1589
+ }
1590
+ },
1591
+ "aria-hidden": s,
1592
+ children: c
1593
+ }), /* @__PURE__ */ I("div", {
1594
+ style: {
1595
+ flex: 1,
1596
+ display: s ? "flex" : "none",
1597
+ flexDirection: "column"
1598
+ },
1599
+ children: o
1600
+ })]
1601
+ });
1583
1602
  }
1584
- async function Ze(e, t = "") {
1585
- const r = [];
1586
- try {
1587
- for await (const [n, o] of e.entries()) {
1588
- const a = t ? `${t}/${n}` : n;
1589
- if (o.kind === "file")
1590
- try {
1591
- const s = await o.getFile();
1592
- r.push({
1593
- name: n,
1594
- path: a,
1595
- size: s.size,
1596
- type: s.type || "application/octet-stream",
1597
- lastModified: s.lastModified
1598
- });
1599
- } catch (s) {
1600
- console.warn(`Failed to read file ${a}:`, s);
1601
- }
1602
- else if (o.kind === "directory") {
1603
- const s = await Ze(o, a);
1604
- r.push(...s);
1605
- }
1606
- }
1607
- } catch (n) {
1608
- console.warn(`Failed to scan directory ${t}:`, n);
1609
- }
1610
- return r;
1603
+ //#endregion
1604
+ //#region src/useOPFSFiles.ts
1605
+ async function kt(e, t = "") {
1606
+ let n = [];
1607
+ try {
1608
+ for await (let [r, i] of e.entries()) {
1609
+ let e = t ? `${t}/${r}` : r;
1610
+ if (i.kind === "file") try {
1611
+ let t = await i.getFile();
1612
+ n.push({
1613
+ name: r,
1614
+ path: e,
1615
+ size: t.size,
1616
+ type: t.type || "application/octet-stream",
1617
+ lastModified: t.lastModified
1618
+ });
1619
+ } catch (t) {
1620
+ console.warn(`Failed to read file ${e}:`, t);
1621
+ }
1622
+ else if (i.kind === "directory") {
1623
+ let t = await kt(i, e);
1624
+ n.push(...t);
1625
+ }
1626
+ }
1627
+ } catch (e) {
1628
+ console.warn(`Failed to scan directory ${t}:`, e);
1629
+ }
1630
+ return n;
1611
1631
  }
1612
- function qt(e = {}) {
1613
- const { rootPath: t } = e, [r, n] = S([]), [o, a] = S(!0), [s, c] = S(null), l = x(async () => {
1614
- a(!0), c(null);
1615
- try {
1616
- let d = await navigator.storage.getDirectory();
1617
- if (t) {
1618
- const f = t.split("/").filter(Boolean);
1619
- for (const b of f)
1620
- d = await d.getDirectoryHandle(b);
1621
- }
1622
- const u = await Ze(d, t || "");
1623
- n(u.sort((f, b) => f.path.localeCompare(b.path)));
1624
- } catch (i) {
1625
- c(
1626
- "Failed to access OPFS: " + (i instanceof Error ? i.message : String(i))
1627
- ), console.error("OPFS access error:", i);
1628
- } finally {
1629
- a(!1);
1630
- }
1631
- }, [t]);
1632
- return w(() => {
1633
- l();
1634
- }, [l]), { files: r, isLoading: o, error: s, refetch: l };
1632
+ function At(e = {}) {
1633
+ let { rootPath: t } = e, [r, a] = c([]), [o, s] = c(!0), [l, u] = c(null), d = n(async () => {
1634
+ s(!0), u(null);
1635
+ try {
1636
+ let e = await navigator.storage.getDirectory();
1637
+ if (t) {
1638
+ let n = t.split("/").filter(Boolean);
1639
+ for (let t of n) e = await e.getDirectoryHandle(t);
1640
+ }
1641
+ a((await kt(e, t || "")).sort((e, t) => e.path.localeCompare(t.path)));
1642
+ } catch (e) {
1643
+ u("Failed to access OPFS: " + (e instanceof Error ? e.message : String(e))), console.error("OPFS access error:", e);
1644
+ } finally {
1645
+ s(!1);
1646
+ }
1647
+ }, [t]);
1648
+ return i(() => {
1649
+ d();
1650
+ }, [d]), {
1651
+ files: r,
1652
+ isLoading: o,
1653
+ error: l,
1654
+ refetch: d
1655
+ };
1635
1656
  }
1636
- const Be = () => /* @__PURE__ */ g("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", style: { width: 20, height: 20 }, children: /* @__PURE__ */ g("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" }) }), zt = () => /* @__PURE__ */ g("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", style: { width: 48, height: 48 }, children: /* @__PURE__ */ g("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M2.25 12.75V12a2.25 2.25 0 012.25-2.25h15A2.25 2.25 0 0121.75 12v.75m-8.69-6.44l-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25h-5.379a1.5 1.5 0 01-1.06-.44z" }) }), Ht = () => /* @__PURE__ */ g("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", style: { width: 20, height: 20 }, children: /* @__PURE__ */ g("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" }) }), Oe = () => /* @__PURE__ */ g("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", style: { width: 20, height: 20 }, children: /* @__PURE__ */ g("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" }) }), Qt = () => /* @__PURE__ */ U(
1637
- "svg",
1638
- {
1639
- xmlns: "http://www.w3.org/2000/svg",
1640
- fill: "none",
1641
- viewBox: "0 0 24 24",
1642
- style: { width: 32, height: 32 },
1643
- "aria-hidden": !0,
1644
- children: [
1645
- /* @__PURE__ */ g(
1646
- "circle",
1647
- {
1648
- style: { opacity: 0.25 },
1649
- cx: "12",
1650
- cy: "12",
1651
- r: "10",
1652
- stroke: "currentColor",
1653
- strokeWidth: "4"
1654
- }
1655
- ),
1656
- /* @__PURE__ */ g(
1657
- "path",
1658
- {
1659
- style: { opacity: 0.75 },
1660
- fill: "currentColor",
1661
- d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
1662
- }
1663
- )
1664
- ]
1665
- }
1666
- );
1667
- function Vt(e) {
1668
- if (e === 0) return "0 Bytes";
1669
- const t = 1024, r = ["Bytes", "KB", "MB", "GB"], n = Math.floor(Math.log(e) / Math.log(t));
1670
- return Math.round(e / Math.pow(t, n) * 100) / 100 + " " + r[n];
1657
+ //#endregion
1658
+ //#region src/OPFSFilesManager.tsx
1659
+ var jt = () => /* @__PURE__ */ I("svg", {
1660
+ xmlns: "http://www.w3.org/2000/svg",
1661
+ fill: "none",
1662
+ viewBox: "0 0 24 24",
1663
+ strokeWidth: 1.5,
1664
+ stroke: "currentColor",
1665
+ style: {
1666
+ width: 20,
1667
+ height: 20
1668
+ },
1669
+ children: /* @__PURE__ */ I("path", {
1670
+ strokeLinecap: "round",
1671
+ strokeLinejoin: "round",
1672
+ d: "M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3"
1673
+ })
1674
+ }), Mt = () => /* @__PURE__ */ I("svg", {
1675
+ xmlns: "http://www.w3.org/2000/svg",
1676
+ fill: "none",
1677
+ viewBox: "0 0 24 24",
1678
+ strokeWidth: 1.5,
1679
+ stroke: "currentColor",
1680
+ style: {
1681
+ width: 48,
1682
+ height: 48
1683
+ },
1684
+ children: /* @__PURE__ */ I("path", {
1685
+ strokeLinecap: "round",
1686
+ strokeLinejoin: "round",
1687
+ d: "M2.25 12.75V12a2.25 2.25 0 012.25-2.25h15A2.25 2.25 0 0121.75 12v.75m-8.69-6.44l-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25h-5.379a1.5 1.5 0 01-1.06-.44z"
1688
+ })
1689
+ }), Nt = () => /* @__PURE__ */ I("svg", {
1690
+ xmlns: "http://www.w3.org/2000/svg",
1691
+ fill: "none",
1692
+ viewBox: "0 0 24 24",
1693
+ strokeWidth: 1.5,
1694
+ stroke: "currentColor",
1695
+ style: {
1696
+ width: 20,
1697
+ height: 20
1698
+ },
1699
+ children: /* @__PURE__ */ I("path", {
1700
+ strokeLinecap: "round",
1701
+ strokeLinejoin: "round",
1702
+ d: "M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"
1703
+ })
1704
+ }), Pt = () => /* @__PURE__ */ I("svg", {
1705
+ xmlns: "http://www.w3.org/2000/svg",
1706
+ fill: "none",
1707
+ viewBox: "0 0 24 24",
1708
+ strokeWidth: 1.5,
1709
+ stroke: "currentColor",
1710
+ style: {
1711
+ width: 20,
1712
+ height: 20
1713
+ },
1714
+ children: /* @__PURE__ */ I("path", {
1715
+ strokeLinecap: "round",
1716
+ strokeLinejoin: "round",
1717
+ d: "M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
1718
+ })
1719
+ }), Ft = () => /* @__PURE__ */ L("svg", {
1720
+ xmlns: "http://www.w3.org/2000/svg",
1721
+ fill: "none",
1722
+ viewBox: "0 0 24 24",
1723
+ style: {
1724
+ width: 32,
1725
+ height: 32
1726
+ },
1727
+ "aria-hidden": !0,
1728
+ children: [/* @__PURE__ */ I("circle", {
1729
+ style: { opacity: .25 },
1730
+ cx: "12",
1731
+ cy: "12",
1732
+ r: "10",
1733
+ stroke: "currentColor",
1734
+ strokeWidth: "4"
1735
+ }), /* @__PURE__ */ I("path", {
1736
+ style: { opacity: .75 },
1737
+ fill: "currentColor",
1738
+ d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
1739
+ })]
1740
+ });
1741
+ function It(e) {
1742
+ if (e === 0) return "0 Bytes";
1743
+ let t = 1024, n = [
1744
+ "Bytes",
1745
+ "KB",
1746
+ "MB",
1747
+ "GB"
1748
+ ], r = Math.floor(Math.log(e) / Math.log(t));
1749
+ return Math.round(e / t ** r * 100) / 100 + " " + n[r];
1671
1750
  }
1672
- function Kt(e) {
1673
- return new Date(e).toLocaleString();
1751
+ function Lt(e) {
1752
+ return new Date(e).toLocaleString();
1674
1753
  }
1675
- async function jt(e, t) {
1676
- const r = e.path.split("/").filter(Boolean);
1677
- if (r.length === 0) throw new Error("Invalid file path");
1678
- let n = t;
1679
- for (let c = 0; c < r.length - 1; c++)
1680
- n = await n.getDirectoryHandle(r[c]);
1681
- const o = r[r.length - 1];
1682
- return await (await n.getFileHandle(o)).getFile();
1754
+ async function Rt(e, t) {
1755
+ let n = e.path.split("/").filter(Boolean);
1756
+ if (n.length === 0) throw Error("Invalid file path");
1757
+ let r = t;
1758
+ for (let e = 0; e < n.length - 1; e++) r = await r.getDirectoryHandle(n[e]);
1759
+ let i = n[n.length - 1];
1760
+ return await (await r.getFileHandle(i)).getFile();
1683
1761
  }
1684
- async function Ue(e, t) {
1685
- const r = e.split("/").filter(Boolean);
1686
- if (r.length === 0) throw new Error("Invalid file path");
1687
- let n = t;
1688
- for (let a = 0; a < r.length - 1; a++)
1689
- n = await n.getDirectoryHandle(r[a]);
1690
- const o = r[r.length - 1];
1691
- await n.removeEntry(o);
1762
+ async function zt(e, t) {
1763
+ let n = e.split("/").filter(Boolean);
1764
+ if (n.length === 0) throw Error("Invalid file path");
1765
+ let r = t;
1766
+ for (let e = 0; e < n.length - 1; e++) r = await r.getDirectoryHandle(n[e]);
1767
+ let i = n[n.length - 1];
1768
+ await r.removeEntry(i);
1692
1769
  }
1693
- const Wt = {
1694
- light: {
1695
- title: "text-gray-900",
1696
- description: "text-gray-500",
1697
- batchBar: "bg-gray-100 border-gray-200",
1698
- batchText: "text-gray-900",
1699
- clearButton: "text-gray-500 hover:text-gray-900",
1700
- loadingText: "text-gray-500",
1701
- errorBox: "bg-red-50 border-red-200",
1702
- errorTitle: "text-red-800",
1703
- errorText: "text-red-700",
1704
- emptyIcon: "text-gray-400",
1705
- emptyTitle: "text-gray-900",
1706
- emptyText: "text-gray-500",
1707
- tableHeader: "bg-gray-100 text-gray-900",
1708
- tableRow: "bg-white",
1709
- tableBorder: "border-gray-200 divide-gray-200",
1710
- tableCell: "text-gray-900",
1711
- tableCellMuted: "text-gray-500",
1712
- codeBlock: "bg-gray-100 border-gray-200 text-gray-800",
1713
- actionButton: "text-gray-500 hover:text-gray-700",
1714
- deleteButton: "text-gray-500 hover:text-red-600"
1715
- },
1716
- dark: {
1717
- title: "text-white",
1718
- description: "text-gray-400",
1719
- batchBar: "bg-gray-800 border-gray-700",
1720
- batchText: "text-white",
1721
- clearButton: "text-gray-400 hover:text-white",
1722
- loadingText: "text-gray-400",
1723
- errorBox: "bg-red-900/50 border-red-800",
1724
- errorTitle: "text-red-200",
1725
- errorText: "text-red-300",
1726
- emptyIcon: "text-gray-500",
1727
- emptyTitle: "text-white",
1728
- emptyText: "text-gray-400",
1729
- tableHeader: "bg-gray-900 text-white",
1730
- tableRow: "bg-gray-900",
1731
- tableBorder: "border-gray-800 divide-gray-800",
1732
- tableCell: "text-white",
1733
- tableCellMuted: "text-gray-400",
1734
- codeBlock: "bg-gray-800 border-gray-700 text-gray-300",
1735
- actionButton: "text-gray-400 hover:text-indigo-400",
1736
- deleteButton: "text-gray-400 hover:text-red-500"
1737
- }
1738
- }, T = {
1739
- container: { padding: "2rem 0" },
1740
- header: {
1741
- display: "flex",
1742
- flexWrap: "wrap",
1743
- alignItems: "center",
1744
- gap: "1rem",
1745
- marginBottom: "1rem"
1746
- },
1747
- title: { fontSize: "1.5rem", fontWeight: 600, margin: 0 },
1748
- description: { fontSize: "0.875rem", margin: "0.5rem 0 0 0" },
1749
- button: "rounded-md px-3 py-2 text-sm font-semibold border-0 cursor-pointer bg-indigo-600 text-white hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600",
1750
- buttonDanger: "rounded-md px-3 py-2 text-sm font-semibold border-0 cursor-pointer bg-red-600 text-white hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600",
1751
- table: "min-w-full divide-y",
1752
- tableHeader: "py-3.5 pl-4 pr-3 text-left text-sm font-semibold sm:pl-6",
1753
- tableCell: "whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6",
1754
- errorBox: "rounded-md border p-4 mt-4",
1755
- emptyState: "text-center py-12"
1770
+ var Bt = {
1771
+ light: {
1772
+ title: "text-gray-900",
1773
+ description: "text-gray-500",
1774
+ batchBar: "bg-gray-100 border-gray-200",
1775
+ batchText: "text-gray-900",
1776
+ clearButton: "text-gray-500 hover:text-gray-900",
1777
+ loadingText: "text-gray-500",
1778
+ errorBox: "bg-red-50 border-red-200",
1779
+ errorTitle: "text-red-800",
1780
+ errorText: "text-red-700",
1781
+ emptyIcon: "text-gray-400",
1782
+ emptyTitle: "text-gray-900",
1783
+ emptyText: "text-gray-500",
1784
+ tableHeader: "bg-gray-100 text-gray-900",
1785
+ tableRow: "bg-white",
1786
+ tableBorder: "border-gray-200 divide-gray-200",
1787
+ tableCell: "text-gray-900",
1788
+ tableCellMuted: "text-gray-500",
1789
+ codeBlock: "bg-gray-100 border-gray-200 text-gray-800",
1790
+ actionButton: "text-gray-500 hover:text-gray-700",
1791
+ deleteButton: "text-gray-500 hover:text-red-600"
1792
+ },
1793
+ dark: {
1794
+ title: "text-white",
1795
+ description: "text-gray-400",
1796
+ batchBar: "bg-gray-800 border-gray-700",
1797
+ batchText: "text-white",
1798
+ clearButton: "text-gray-400 hover:text-white",
1799
+ loadingText: "text-gray-400",
1800
+ errorBox: "bg-red-900/50 border-red-800",
1801
+ errorTitle: "text-red-200",
1802
+ errorText: "text-red-300",
1803
+ emptyIcon: "text-gray-500",
1804
+ emptyTitle: "text-white",
1805
+ emptyText: "text-gray-400",
1806
+ tableHeader: "bg-gray-900 text-white",
1807
+ tableRow: "bg-gray-900",
1808
+ tableBorder: "border-gray-800 divide-gray-800",
1809
+ tableCell: "text-white",
1810
+ tableCellMuted: "text-gray-400",
1811
+ codeBlock: "bg-gray-800 border-gray-700 text-gray-300",
1812
+ actionButton: "text-gray-400 hover:text-indigo-400",
1813
+ deleteButton: "text-gray-400 hover:text-red-500"
1814
+ }
1815
+ }, Z = {
1816
+ container: { padding: "2rem 0" },
1817
+ header: {
1818
+ display: "flex",
1819
+ flexWrap: "wrap",
1820
+ alignItems: "center",
1821
+ gap: "1rem",
1822
+ marginBottom: "1rem"
1823
+ },
1824
+ title: {
1825
+ fontSize: "1.5rem",
1826
+ fontWeight: 600,
1827
+ margin: 0
1828
+ },
1829
+ description: {
1830
+ fontSize: "0.875rem",
1831
+ margin: "0.5rem 0 0 0"
1832
+ },
1833
+ button: "rounded-md px-3 py-2 text-sm font-semibold border-0 cursor-pointer bg-indigo-600 text-white hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600",
1834
+ buttonDanger: "rounded-md px-3 py-2 text-sm font-semibold border-0 cursor-pointer bg-red-600 text-white hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600",
1835
+ table: "min-w-full divide-y",
1836
+ tableHeader: "py-3.5 pl-4 pr-3 text-left text-sm font-semibold sm:pl-6",
1837
+ tableCell: "whitespace-nowrap py-4 pl-4 pr-3 text-sm sm:pl-6",
1838
+ errorBox: "rounded-md border p-4 mt-4",
1839
+ emptyState: "text-center py-12"
1756
1840
  };
1757
- function Vr({
1758
- rootPath: e,
1759
- filter: t,
1760
- onBeforeDelete: r,
1761
- onAfterDelete: n,
1762
- onDownload: o,
1763
- title: a = "Files",
1764
- description: s = "Browse and download all files stored in the Origin Private File System (OPFS).",
1765
- theme: c = "dark",
1766
- className: l
1767
- }) {
1768
- const i = Wt[c], { files: d, isLoading: u, error: f, refetch: b } = qt({ rootPath: e }), v = t ? d.filter(t) : d, [h, y] = S(/* @__PURE__ */ new Set()), p = C(null), E = v.length > 0 && h.size === v.length, I = h.size > 0 && h.size < v.length, m = (L) => {
1769
- y(($) => {
1770
- const F = new Set($);
1771
- return F.has(L) ? F.delete(L) : F.add(L), F;
1772
- });
1773
- }, _ = () => {
1774
- y(
1775
- h.size === v.length ? /* @__PURE__ */ new Set() : new Set(v.map((L) => L.path))
1776
- );
1777
- };
1778
- w(() => {
1779
- y(/* @__PURE__ */ new Set());
1780
- }, [v.length]), w(() => {
1781
- p.current && (p.current.indeterminate = I);
1782
- }, [I]);
1783
- const R = async (L, $ = !1) => {
1784
- try {
1785
- const F = await navigator.storage.getDirectory(), H = await jt(L, F);
1786
- if (o)
1787
- await o(L, H);
1788
- else {
1789
- const K = URL.createObjectURL(H), M = document.createElement("a");
1790
- M.href = K, M.download = L.name, document.body.appendChild(M), M.click(), document.body.removeChild(M), URL.revokeObjectURL(K);
1791
- }
1792
- } catch (F) {
1793
- const H = "Failed to download file: " + (F instanceof Error ? F.message : String(F));
1794
- throw $ || alert(H), F;
1795
- }
1796
- }, A = async (L) => {
1797
- if (!(r && !await r(L)) && confirm(`Are you sure you want to delete "${L.name}"? This action cannot be undone.`))
1798
- try {
1799
- const $ = await navigator.storage.getDirectory();
1800
- await Ue(L.path, $), await b(), await n?.([L.path]);
1801
- } catch ($) {
1802
- alert("Failed to delete file: " + ($ instanceof Error ? $.message : String($)));
1803
- }
1804
- }, B = async () => {
1805
- if (h.size === 0) return;
1806
- const L = v.filter((F) => h.has(F.path)), $ = [];
1807
- for (const F of L)
1808
- try {
1809
- await R(F, !0), await new Promise((H) => setTimeout(H, 100));
1810
- } catch (H) {
1811
- $.push(`${F.name}: ${H instanceof Error ? H.message : String(H)}`);
1812
- }
1813
- $.length > 0 && alert(`Some downloads failed:
1814
- ${$.join(`
1815
- `)}`);
1816
- }, V = async () => {
1817
- if (h.size === 0) return;
1818
- const L = v.filter((M) => h.has(M.path)), $ = L.map((M) => M.name).join(", ");
1819
- if (!confirm(
1820
- `Are you sure you want to delete ${h.size} file(s)?
1821
-
1822
- Files: ${$}
1823
-
1824
- This action cannot be undone.`
1825
- ))
1826
- return;
1827
- const F = await navigator.storage.getDirectory(), H = [], K = [];
1828
- for (const M of L)
1829
- if (!(r && !await r(M)))
1830
- try {
1831
- await Ue(M.path, F), H.push(M.path);
1832
- } catch (J) {
1833
- K.push(`${M.name}: ${J instanceof Error ? J.message : String(J)}`);
1834
- }
1835
- y(/* @__PURE__ */ new Set()), await b(), H.length > 0 && await n?.(H), K.length > 0 && alert(`Some deletions failed:
1836
- ${K.join(`
1837
- `)}`);
1838
- };
1839
- return /* @__PURE__ */ U("div", { className: l, style: T.container, children: [
1840
- /* @__PURE__ */ g("style", { children: "@keyframes opfs-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}" }),
1841
- /* @__PURE__ */ U("div", { style: T.header, children: [
1842
- /* @__PURE__ */ U("div", { style: { flex: 1, minWidth: 0 }, children: [
1843
- /* @__PURE__ */ g("h1", { style: T.title, className: i.title, children: a }),
1844
- /* @__PURE__ */ g("p", { style: T.description, className: i.description, children: s })
1845
- ] }),
1846
- /* @__PURE__ */ g("button", { type: "button", onClick: b, className: T.button, children: "Refresh" })
1847
- ] }),
1848
- h.size > 0 && /* @__PURE__ */ U(
1849
- "div",
1850
- {
1851
- className: `mt-4 flex items-center justify-between rounded-lg border px-4 py-3 ${i.batchBar}`,
1852
- children: [
1853
- /* @__PURE__ */ U("span", { className: `text-sm font-medium ${i.batchText}`, children: [
1854
- h.size,
1855
- " file",
1856
- h.size === 1 ? "" : "s",
1857
- " selected"
1858
- ] }),
1859
- /* @__PURE__ */ U("div", { className: "flex items-center gap-3", children: [
1860
- /* @__PURE__ */ g("button", { onClick: B, className: T.button, children: /* @__PURE__ */ U("span", { className: "inline-flex items-center gap-2", children: [
1861
- /* @__PURE__ */ g(Be, {}),
1862
- " Download All"
1863
- ] }) }),
1864
- /* @__PURE__ */ g("button", { onClick: V, className: T.buttonDanger, children: /* @__PURE__ */ U("span", { className: "inline-flex items-center gap-2", children: [
1865
- /* @__PURE__ */ g(Oe, {}),
1866
- " Delete All"
1867
- ] }) }),
1868
- /* @__PURE__ */ g(
1869
- "button",
1870
- {
1871
- onClick: () => y(/* @__PURE__ */ new Set()),
1872
- className: `text-sm cursor-pointer bg-transparent border-0 ${i.clearButton}`,
1873
- children: "Clear selection"
1874
- }
1875
- )
1876
- ] })
1877
- ]
1878
- }
1879
- ),
1880
- /* @__PURE__ */ g("div", { className: "mt-8", children: u ? /* @__PURE__ */ U("div", { className: "flex justify-center items-center py-12 gap-3", children: [
1881
- /* @__PURE__ */ g("span", { style: { animation: "opfs-spin 1s linear infinite" }, children: /* @__PURE__ */ g(Qt, {}) }),
1882
- /* @__PURE__ */ g("span", { className: i.loadingText, children: "Loading files..." })
1883
- ] }) : f ? /* @__PURE__ */ U("div", { className: `${T.errorBox} ${i.errorBox}`, children: [
1884
- /* @__PURE__ */ g("h3", { className: `m-0 text-sm font-medium ${i.errorTitle}`, children: "Error" }),
1885
- /* @__PURE__ */ g("div", { className: `mt-2 text-sm ${i.errorText}`, children: f })
1886
- ] }) : v.length === 0 ? /* @__PURE__ */ U("div", { className: T.emptyState, children: [
1887
- /* @__PURE__ */ g("span", { className: i.emptyIcon, children: /* @__PURE__ */ g(zt, {}) }),
1888
- /* @__PURE__ */ g("h3", { className: `mt-2 text-sm font-semibold ${i.emptyTitle}`, children: "No files" }),
1889
- /* @__PURE__ */ g("p", { className: `mt-1 text-sm ${i.emptyText}`, children: "No files found in OPFS." })
1890
- ] }) : /* @__PURE__ */ g("div", { className: "overflow-x-auto", children: /* @__PURE__ */ U("table", { className: T.table, children: [
1891
- /* @__PURE__ */ g("thead", { children: /* @__PURE__ */ U("tr", { className: i.tableBorder, children: [
1892
- /* @__PURE__ */ g("th", { className: `${T.tableHeader} w-10 ${i.tableHeader}`, children: /* @__PURE__ */ g(
1893
- "input",
1894
- {
1895
- ref: p,
1896
- type: "checkbox",
1897
- checked: E,
1898
- onChange: _,
1899
- "aria-label": "Select all"
1900
- }
1901
- ) }),
1902
- /* @__PURE__ */ g("th", { className: `${T.tableHeader} ${i.tableHeader}`, children: "Name" }),
1903
- /* @__PURE__ */ g("th", { className: `${T.tableHeader} ${i.tableHeader}`, children: "Path" }),
1904
- /* @__PURE__ */ g("th", { className: `${T.tableHeader} ${i.tableHeader}`, children: "Size" }),
1905
- /* @__PURE__ */ g("th", { className: `${T.tableHeader} ${i.tableHeader}`, children: "Type" }),
1906
- /* @__PURE__ */ g("th", { className: `${T.tableHeader} ${i.tableHeader}`, children: "Modified" }),
1907
- /* @__PURE__ */ g(
1908
- "th",
1909
- {
1910
- className: `${T.tableHeader} w-24 ${i.tableHeader}`,
1911
- "aria-label": "Actions"
1912
- }
1913
- )
1914
- ] }) }),
1915
- /* @__PURE__ */ g("tbody", { className: `divide-y ${i.tableBorder}`, children: v.map((L) => /* @__PURE__ */ U("tr", { className: i.tableRow, children: [
1916
- /* @__PURE__ */ g("td", { className: `${T.tableCell} ${i.tableCell}`, children: /* @__PURE__ */ g(
1917
- "input",
1918
- {
1919
- type: "checkbox",
1920
- checked: h.has(L.path),
1921
- onChange: () => m(L.path),
1922
- "aria-label": `Select ${L.name}`
1923
- }
1924
- ) }),
1925
- /* @__PURE__ */ g("td", { className: `${T.tableCell} ${i.tableCell}`, children: /* @__PURE__ */ U("span", { className: "flex items-center gap-2", children: [
1926
- /* @__PURE__ */ g(Ht, {}),
1927
- L.name
1928
- ] }) }),
1929
- /* @__PURE__ */ g("td", { className: `${T.tableCell} ${i.tableCellMuted}`, children: /* @__PURE__ */ g("code", { className: `text-xs px-2 py-1 rounded border ${i.codeBlock}`, children: L.path }) }),
1930
- /* @__PURE__ */ g("td", { className: `${T.tableCell} ${i.tableCellMuted}`, children: Vt(L.size) }),
1931
- /* @__PURE__ */ g("td", { className: `${T.tableCell} ${i.tableCellMuted}`, children: L.type }),
1932
- /* @__PURE__ */ g("td", { className: `${T.tableCell} ${i.tableCellMuted}`, children: Kt(L.lastModified) }),
1933
- /* @__PURE__ */ g("td", { className: T.tableCell, children: /* @__PURE__ */ U("div", { className: "flex gap-2 justify-end", children: [
1934
- /* @__PURE__ */ g(
1935
- "button",
1936
- {
1937
- type: "button",
1938
- onClick: () => R(L),
1939
- title: "Download",
1940
- className: `p-1.5 rounded cursor-pointer bg-transparent border-0 transition-colors ${i.actionButton}`,
1941
- children: /* @__PURE__ */ g(Be, {})
1942
- }
1943
- ),
1944
- /* @__PURE__ */ g(
1945
- "button",
1946
- {
1947
- type: "button",
1948
- onClick: () => A(L),
1949
- title: "Delete",
1950
- className: `p-1.5 rounded cursor-pointer bg-transparent border-0 transition-colors ${i.deleteButton}`,
1951
- children: /* @__PURE__ */ g(Oe, {})
1952
- }
1953
- )
1954
- ] }) })
1955
- ] }, L.path)) })
1956
- ] }) }) })
1957
- ] });
1841
+ function Vt({ rootPath: e, filter: t, onBeforeDelete: n, onAfterDelete: r, onDownload: a, title: o = "Files", description: l = "Browse and download all files stored in the Origin Private File System (OPFS).", theme: u = "dark", className: d }) {
1842
+ let f = Bt[u], { files: p, isLoading: m, error: h, refetch: g } = At({ rootPath: e }), _ = t ? p.filter(t) : p, [v, y] = c(/* @__PURE__ */ new Set()), b = s(null), x = _.length > 0 && v.size === _.length, S = v.size > 0 && v.size < _.length, C = (e) => {
1843
+ y((t) => {
1844
+ let n = new Set(t);
1845
+ return n.has(e) ? n.delete(e) : n.add(e), n;
1846
+ });
1847
+ }, w = () => {
1848
+ y(v.size === _.length ? /* @__PURE__ */ new Set() : new Set(_.map((e) => e.path)));
1849
+ };
1850
+ i(() => {
1851
+ y(/* @__PURE__ */ new Set());
1852
+ }, [_.length]), i(() => {
1853
+ b.current && (b.current.indeterminate = S);
1854
+ }, [S]);
1855
+ let T = async (e, t = !1) => {
1856
+ try {
1857
+ let t = await Rt(e, await navigator.storage.getDirectory());
1858
+ if (a) await a(e, t);
1859
+ else {
1860
+ let n = URL.createObjectURL(t), r = document.createElement("a");
1861
+ r.href = n, r.download = e.name, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(n);
1862
+ }
1863
+ } catch (e) {
1864
+ let n = "Failed to download file: " + (e instanceof Error ? e.message : String(e));
1865
+ throw t || alert(n), e;
1866
+ }
1867
+ }, E = async (e) => {
1868
+ if (!(n && !await n(e)) && confirm(`Are you sure you want to delete "${e.name}"? This action cannot be undone.`)) try {
1869
+ let t = await navigator.storage.getDirectory();
1870
+ await zt(e.path, t), await g(), await r?.([e.path]);
1871
+ } catch (e) {
1872
+ alert("Failed to delete file: " + (e instanceof Error ? e.message : String(e)));
1873
+ }
1874
+ };
1875
+ return /* @__PURE__ */ L("div", {
1876
+ className: d,
1877
+ style: Z.container,
1878
+ children: [
1879
+ /* @__PURE__ */ I("style", { children: "@keyframes opfs-spin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}" }),
1880
+ /* @__PURE__ */ L("div", {
1881
+ style: Z.header,
1882
+ children: [/* @__PURE__ */ L("div", {
1883
+ style: {
1884
+ flex: 1,
1885
+ minWidth: 0
1886
+ },
1887
+ children: [/* @__PURE__ */ I("h1", {
1888
+ style: Z.title,
1889
+ className: f.title,
1890
+ children: o
1891
+ }), /* @__PURE__ */ I("p", {
1892
+ style: Z.description,
1893
+ className: f.description,
1894
+ children: l
1895
+ })]
1896
+ }), /* @__PURE__ */ I("button", {
1897
+ type: "button",
1898
+ onClick: g,
1899
+ className: Z.button,
1900
+ children: "Refresh"
1901
+ })]
1902
+ }),
1903
+ v.size > 0 && /* @__PURE__ */ L("div", {
1904
+ className: `mt-4 flex items-center justify-between rounded-lg border px-4 py-3 ${f.batchBar}`,
1905
+ children: [/* @__PURE__ */ L("span", {
1906
+ className: `text-sm font-medium ${f.batchText}`,
1907
+ children: [
1908
+ v.size,
1909
+ " file",
1910
+ v.size === 1 ? "" : "s",
1911
+ " selected"
1912
+ ]
1913
+ }), /* @__PURE__ */ L("div", {
1914
+ className: "flex items-center gap-3",
1915
+ children: [
1916
+ /* @__PURE__ */ I("button", {
1917
+ onClick: async () => {
1918
+ if (v.size === 0) return;
1919
+ let e = _.filter((e) => v.has(e.path)), t = [];
1920
+ for (let n of e) try {
1921
+ await T(n, !0), await new Promise((e) => setTimeout(e, 100));
1922
+ } catch (e) {
1923
+ t.push(`${n.name}: ${e instanceof Error ? e.message : String(e)}`);
1924
+ }
1925
+ t.length > 0 && alert(`Some downloads failed:\n${t.join("\n")}`);
1926
+ },
1927
+ className: Z.button,
1928
+ children: /* @__PURE__ */ L("span", {
1929
+ className: "inline-flex items-center gap-2",
1930
+ children: [/* @__PURE__ */ I(jt, {}), " Download All"]
1931
+ })
1932
+ }),
1933
+ /* @__PURE__ */ I("button", {
1934
+ onClick: async () => {
1935
+ if (v.size === 0) return;
1936
+ let e = _.filter((e) => v.has(e.path)), t = e.map((e) => e.name).join(", ");
1937
+ if (!confirm(`Are you sure you want to delete ${v.size} file(s)?\n\nFiles: ${t}\n\nThis action cannot be undone.`)) return;
1938
+ let i = await navigator.storage.getDirectory(), a = [], o = [];
1939
+ for (let t of e) if (!(n && !await n(t))) try {
1940
+ await zt(t.path, i), a.push(t.path);
1941
+ } catch (e) {
1942
+ o.push(`${t.name}: ${e instanceof Error ? e.message : String(e)}`);
1943
+ }
1944
+ y(/* @__PURE__ */ new Set()), await g(), a.length > 0 && await r?.(a), o.length > 0 && alert(`Some deletions failed:\n${o.join("\n")}`);
1945
+ },
1946
+ className: Z.buttonDanger,
1947
+ children: /* @__PURE__ */ L("span", {
1948
+ className: "inline-flex items-center gap-2",
1949
+ children: [/* @__PURE__ */ I(Pt, {}), " Delete All"]
1950
+ })
1951
+ }),
1952
+ /* @__PURE__ */ I("button", {
1953
+ onClick: () => y(/* @__PURE__ */ new Set()),
1954
+ className: `text-sm cursor-pointer bg-transparent border-0 ${f.clearButton}`,
1955
+ children: "Clear selection"
1956
+ })
1957
+ ]
1958
+ })]
1959
+ }),
1960
+ /* @__PURE__ */ I("div", {
1961
+ className: "mt-8",
1962
+ children: m ? /* @__PURE__ */ L("div", {
1963
+ className: "flex justify-center items-center py-12 gap-3",
1964
+ children: [/* @__PURE__ */ I("span", {
1965
+ style: { animation: "opfs-spin 1s linear infinite" },
1966
+ children: /* @__PURE__ */ I(Ft, {})
1967
+ }), /* @__PURE__ */ I("span", {
1968
+ className: f.loadingText,
1969
+ children: "Loading files..."
1970
+ })]
1971
+ }) : h ? /* @__PURE__ */ L("div", {
1972
+ className: `${Z.errorBox} ${f.errorBox}`,
1973
+ children: [/* @__PURE__ */ I("h3", {
1974
+ className: `m-0 text-sm font-medium ${f.errorTitle}`,
1975
+ children: "Error"
1976
+ }), /* @__PURE__ */ I("div", {
1977
+ className: `mt-2 text-sm ${f.errorText}`,
1978
+ children: h
1979
+ })]
1980
+ }) : _.length === 0 ? /* @__PURE__ */ L("div", {
1981
+ className: Z.emptyState,
1982
+ children: [
1983
+ /* @__PURE__ */ I("span", {
1984
+ className: f.emptyIcon,
1985
+ children: /* @__PURE__ */ I(Mt, {})
1986
+ }),
1987
+ /* @__PURE__ */ I("h3", {
1988
+ className: `mt-2 text-sm font-semibold ${f.emptyTitle}`,
1989
+ children: "No files"
1990
+ }),
1991
+ /* @__PURE__ */ I("p", {
1992
+ className: `mt-1 text-sm ${f.emptyText}`,
1993
+ children: "No files found in OPFS."
1994
+ })
1995
+ ]
1996
+ }) : /* @__PURE__ */ I("div", {
1997
+ className: "overflow-x-auto",
1998
+ children: /* @__PURE__ */ L("table", {
1999
+ className: Z.table,
2000
+ children: [/* @__PURE__ */ I("thead", { children: /* @__PURE__ */ L("tr", {
2001
+ className: f.tableBorder,
2002
+ children: [
2003
+ /* @__PURE__ */ I("th", {
2004
+ className: `${Z.tableHeader} w-10 ${f.tableHeader}`,
2005
+ children: /* @__PURE__ */ I("input", {
2006
+ ref: b,
2007
+ type: "checkbox",
2008
+ checked: x,
2009
+ onChange: w,
2010
+ "aria-label": "Select all"
2011
+ })
2012
+ }),
2013
+ /* @__PURE__ */ I("th", {
2014
+ className: `${Z.tableHeader} ${f.tableHeader}`,
2015
+ children: "Name"
2016
+ }),
2017
+ /* @__PURE__ */ I("th", {
2018
+ className: `${Z.tableHeader} ${f.tableHeader}`,
2019
+ children: "Path"
2020
+ }),
2021
+ /* @__PURE__ */ I("th", {
2022
+ className: `${Z.tableHeader} ${f.tableHeader}`,
2023
+ children: "Size"
2024
+ }),
2025
+ /* @__PURE__ */ I("th", {
2026
+ className: `${Z.tableHeader} ${f.tableHeader}`,
2027
+ children: "Type"
2028
+ }),
2029
+ /* @__PURE__ */ I("th", {
2030
+ className: `${Z.tableHeader} ${f.tableHeader}`,
2031
+ children: "Modified"
2032
+ }),
2033
+ /* @__PURE__ */ I("th", {
2034
+ className: `${Z.tableHeader} w-24 ${f.tableHeader}`,
2035
+ "aria-label": "Actions"
2036
+ })
2037
+ ]
2038
+ }) }), /* @__PURE__ */ I("tbody", {
2039
+ className: `divide-y ${f.tableBorder}`,
2040
+ children: _.map((e) => /* @__PURE__ */ L("tr", {
2041
+ className: f.tableRow,
2042
+ children: [
2043
+ /* @__PURE__ */ I("td", {
2044
+ className: `${Z.tableCell} ${f.tableCell}`,
2045
+ children: /* @__PURE__ */ I("input", {
2046
+ type: "checkbox",
2047
+ checked: v.has(e.path),
2048
+ onChange: () => C(e.path),
2049
+ "aria-label": `Select ${e.name}`
2050
+ })
2051
+ }),
2052
+ /* @__PURE__ */ I("td", {
2053
+ className: `${Z.tableCell} ${f.tableCell}`,
2054
+ children: /* @__PURE__ */ L("span", {
2055
+ className: "flex items-center gap-2",
2056
+ children: [/* @__PURE__ */ I(Nt, {}), e.name]
2057
+ })
2058
+ }),
2059
+ /* @__PURE__ */ I("td", {
2060
+ className: `${Z.tableCell} ${f.tableCellMuted}`,
2061
+ children: /* @__PURE__ */ I("code", {
2062
+ className: `text-xs px-2 py-1 rounded border ${f.codeBlock}`,
2063
+ children: e.path
2064
+ })
2065
+ }),
2066
+ /* @__PURE__ */ I("td", {
2067
+ className: `${Z.tableCell} ${f.tableCellMuted}`,
2068
+ children: It(e.size)
2069
+ }),
2070
+ /* @__PURE__ */ I("td", {
2071
+ className: `${Z.tableCell} ${f.tableCellMuted}`,
2072
+ children: e.type
2073
+ }),
2074
+ /* @__PURE__ */ I("td", {
2075
+ className: `${Z.tableCell} ${f.tableCellMuted}`,
2076
+ children: Lt(e.lastModified)
2077
+ }),
2078
+ /* @__PURE__ */ I("td", {
2079
+ className: Z.tableCell,
2080
+ children: /* @__PURE__ */ L("div", {
2081
+ className: "flex gap-2 justify-end",
2082
+ children: [/* @__PURE__ */ I("button", {
2083
+ type: "button",
2084
+ onClick: () => T(e),
2085
+ title: "Download",
2086
+ className: `p-1.5 rounded cursor-pointer bg-transparent border-0 transition-colors ${f.actionButton}`,
2087
+ children: /* @__PURE__ */ I(jt, {})
2088
+ }), /* @__PURE__ */ I("button", {
2089
+ type: "button",
2090
+ onClick: () => E(e),
2091
+ title: "Delete",
2092
+ className: `p-1.5 rounded cursor-pointer bg-transparent border-0 transition-colors ${f.deleteButton}`,
2093
+ children: /* @__PURE__ */ I(Pt, {})
2094
+ })]
2095
+ })
2096
+ })
2097
+ ]
2098
+ }, e.path))
2099
+ })]
2100
+ })
2101
+ })
2102
+ })
2103
+ ]
2104
+ });
1958
2105
  }
1959
- const Ee = G("seedSdk:react:SeedImage"), de = /* @__PURE__ */ new Map(), et = (e) => {
1960
- const t = /^(.*[\/\\])?([^\/\\]+?)(\.[^.\/\\]*)?$/, r = e.match(t);
1961
- return r && r[2] ? r[2] : e;
2106
+ //#endregion
2107
+ //#region src/SeedImage.tsx
2108
+ var Q = P("seedSdk:react:SeedImage"), $ = /* @__PURE__ */ new Map(), Ht = (e) => {
2109
+ let t = e.match(/^(.*[\/\\])?([^\/\\]+?)(\.[^.\/\\]*)?$/);
2110
+ return t && t[2] ? t[2] : e;
1962
2111
  };
1963
- function Jt(e) {
1964
- return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2112
+ function Ut(e) {
2113
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1965
2114
  }
1966
- function Gt(e, t) {
1967
- const r = new RegExp(`^${Jt(t)}$`), n = et(e);
1968
- return r.test(n);
2115
+ function Wt(e, t) {
2116
+ let n = RegExp(`^${Ut(t)}$`), r = Ht(e);
2117
+ return n.test(r);
1969
2118
  }
1970
- const Yt = ({ imageProperty: e, width: t, filename: r, ...n }) => {
1971
- const [o, a] = S(), [s, c] = S(), { property: l } = We({
1972
- propertyName: e.propertyName,
1973
- seedLocalId: e.seedLocalId,
1974
- seedUid: e.seedUid
1975
- }), i = e ?? l, d = r ?? i?.refResolvedValue ?? i?.value, u = i?.value, f = typeof u == "string" ? u : d, b = u != null && (u instanceof File || u instanceof Blob), [v, h] = S(null), y = qe.useRef(null);
1976
- w(() => {
1977
- if (b && (u instanceof File || u instanceof Blob))
1978
- return y.current || (y.current = URL.createObjectURL(u), h(y.current)), () => {
1979
- y.current && (URL.revokeObjectURL(y.current), y.current = null), h(null);
1980
- };
1981
- y.current = null, h(null);
1982
- }, [b, u]), w(() => {
1983
- if (!d || u && ((A) => typeof A == "string" && A.startsWith("blob:"))(u) || v) return;
1984
- let _ = !1;
1985
- return (async () => {
1986
- try {
1987
- const A = i?.localStoragePath ? i.localStoragePath : `${W.getFilesPath("images")}/${d}`;
1988
- if (await W.pathExists(A)) {
1989
- const V = await W.getContentUrlFromPath(A);
1990
- !_ && V && c(V);
1991
- }
1992
- } catch (A) {
1993
- Ee("_getOriginalContentUrl error", A);
1994
- }
1995
- })(), () => {
1996
- _ = !0;
1997
- };
1998
- }, [d, u, v, i?.localStoragePath]), w(() => {
1999
- if (!t || !d)
2000
- return;
2001
- (async () => {
2002
- try {
2003
- const _ = await W.getFs(), R = i?.localStoragePath ? i.localStoragePath.split("/").slice(0, -1).join("/") : W.getFilesPath("images"), V = _.readdirSync(R, { withFileTypes: !0 }).filter((O) => O.isDirectory()).map((O) => parseInt(O.name)), L = V.reduce((O, se) => Math.abs(se - t) < Math.abs(O - t) ? se : O, V[0]), $ = et(d), F = `${$}-${L}`;
2004
- if (de.has(F))
2005
- try {
2006
- const O = de.get(F);
2007
- if (O && (await fetch(O)).ok) {
2008
- a(O);
2009
- return;
2010
- }
2011
- } catch (O) {
2012
- Ee("error", O), de.delete(F);
2013
- }
2014
- const K = _.readdirSync(`${R}/${L}`, { withFileTypes: !0 }).find((O) => O.name ? Gt(O.name, $) : !1);
2015
- if (!K)
2016
- return;
2017
- const M = `${R}/${L}/${K?.name}`;
2018
- if (await W.pathExists(M)) {
2019
- const O = await W.getContentUrlFromPath(M);
2020
- O && (de.set(F, O), a(O));
2021
- }
2022
- } catch (_) {
2023
- Ee("_getSizedContentUrl error", _);
2024
- }
2025
- })();
2026
- }, [i, t, f, d]);
2027
- const p = (m) => typeof m == "string" && m.startsWith("blob:");
2028
- if (!(!!o || !!s || !!v || !!f && p(f)) && !d)
2029
- return null;
2030
- const I = o || s || v || (p(f) ? f : void 0) || "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
2031
- return /* @__PURE__ */ g("img", { src: I, alt: n.alt || e.propertyName || "Image", ...n });
2032
- }, Kr = qe.memo(
2033
- Yt,
2034
- (e, t) => e.imageProperty === t.imageProperty && e.width === t.width && e.filename === t.filename
2035
- );
2036
- function tt(e) {
2037
- const { value: t, enabled: r = !0, treatAs: n } = e, [o, a] = S(0), [s, c] = S(null), [l, i] = S(null), [d, u] = S("idle");
2038
- w(() => {
2039
- let h = !1;
2040
- return (async () => {
2041
- if (!r || t == null || String(t).trim() === "") {
2042
- h || (c(null), i(null), u("idle"));
2043
- return;
2044
- }
2045
- h || (u("loading"), i(null));
2046
- try {
2047
- const p = await ft(String(t), { treatAs: n });
2048
- if (h) return;
2049
- c(p), p.status === "empty" ? u("empty") : p.status === "ready" ? u("ready") : u("unresolved");
2050
- } catch (p) {
2051
- if (h) return;
2052
- i(p instanceof Error ? p : new Error(String(p))), c(null), u("error");
2053
- }
2054
- })(), () => {
2055
- h = !0;
2056
- };
2057
- }, [r, t, n, o]);
2058
- const f = x(() => {
2059
- a((h) => h + 1);
2060
- }, []), b = s && s.status === "ready" ? s.href : void 0, v = s && s.status === "ready" ? s.source : void 0;
2061
- return {
2062
- href: b,
2063
- status: d,
2064
- source: v,
2065
- error: l,
2066
- result: s,
2067
- refetch: f
2068
- };
2119
+ var Gt = e.memo(({ imageProperty: t, width: n, filename: r, ...a }) => {
2120
+ let [o, s] = c(), [l, u] = c(), { property: f } = De({
2121
+ propertyName: t.propertyName,
2122
+ seedLocalId: t.seedLocalId,
2123
+ seedUid: t.seedUid
2124
+ }), p = t ?? f, m = r ?? p?.refResolvedValue ?? p?.value, h = p?.value, g = typeof h == "string" ? h : m, _ = h != null && (h instanceof File || h instanceof Blob), [v, y] = c(null), b = e.useRef(null);
2125
+ i(() => {
2126
+ if (_ && (h instanceof File || h instanceof Blob)) return b.current || (b.current = URL.createObjectURL(h), y(b.current)), () => {
2127
+ b.current && (URL.revokeObjectURL(b.current), b.current = null), y(null);
2128
+ };
2129
+ b.current = null, y(null);
2130
+ }, [_, h]), i(() => {
2131
+ if (!m || h && ((e) => typeof e == "string" && e.startsWith("blob:"))(h) || v) return;
2132
+ let e = !1;
2133
+ return (async () => {
2134
+ try {
2135
+ let t = p?.localStoragePath ? p.localStoragePath : `${d.getFilesPath("images")}/${m}`;
2136
+ if (await d.pathExists(t)) {
2137
+ let n = await d.getContentUrlFromPath(t);
2138
+ !e && n && u(n);
2139
+ }
2140
+ } catch (e) {
2141
+ Q("_getOriginalContentUrl error", e);
2142
+ }
2143
+ })(), () => {
2144
+ e = !0;
2145
+ };
2146
+ }, [
2147
+ m,
2148
+ h,
2149
+ v,
2150
+ p?.localStoragePath
2151
+ ]), i(() => {
2152
+ !n || !m || (async () => {
2153
+ try {
2154
+ let e = await d.getFs(), t = p?.localStoragePath ? p.localStoragePath.split("/").slice(0, -1).join("/") : d.getFilesPath("images"), r = e.readdirSync(t, { withFileTypes: !0 }).filter((e) => e.isDirectory()).map((e) => parseInt(e.name)), i = r.reduce((e, t) => Math.abs(t - n) < Math.abs(e - n) ? t : e, r[0]), a = Ht(m), o = `${a}-${i}`;
2155
+ if ($.has(o)) try {
2156
+ let e = $.get(o);
2157
+ if (e && (await fetch(e)).ok) {
2158
+ s(e);
2159
+ return;
2160
+ }
2161
+ } catch (e) {
2162
+ Q("error", e), $.delete(o);
2163
+ }
2164
+ let c = e.readdirSync(`${t}/${i}`, { withFileTypes: !0 }).find((e) => e.name ? Wt(e.name, a) : !1);
2165
+ if (!c) return;
2166
+ let l = `${t}/${i}/${c?.name}`;
2167
+ if (await d.pathExists(l)) {
2168
+ let e = await d.getContentUrlFromPath(l);
2169
+ e && ($.set(o, e), s(e));
2170
+ }
2171
+ } catch (e) {
2172
+ Q("_getSizedContentUrl error", e);
2173
+ }
2174
+ })();
2175
+ }, [
2176
+ p,
2177
+ n,
2178
+ g,
2179
+ m
2180
+ ]);
2181
+ let x = (e) => typeof e == "string" && e.startsWith("blob:");
2182
+ return !(o || l || v || g && x(g)) && !m ? null : /* @__PURE__ */ I("img", {
2183
+ src: o || l || v || (x(g) ? g : void 0) || "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
2184
+ alt: a.alt || t.propertyName || "Image",
2185
+ ...a
2186
+ });
2187
+ }, (e, t) => e.imageProperty === t.imageProperty && e.width === t.width && e.filename === t.filename);
2188
+ //#endregion
2189
+ //#region src/useResolvedMediaRef.ts
2190
+ function Kt(e) {
2191
+ let { value: t, enabled: r = !0, treatAs: a } = e, [o, s] = c(0), [l, u] = c(null), [d, f] = c(null), [p, m] = c("idle");
2192
+ i(() => {
2193
+ let e = !1;
2194
+ return (async () => {
2195
+ if (!r || t == null || String(t).trim() === "") {
2196
+ e || (u(null), f(null), m("idle"));
2197
+ return;
2198
+ }
2199
+ e || (m("loading"), f(null));
2200
+ try {
2201
+ let n = await ie(String(t), { treatAs: a });
2202
+ if (e) return;
2203
+ u(n), n.status === "empty" ? m("empty") : n.status === "ready" ? m("ready") : m("unresolved");
2204
+ } catch (t) {
2205
+ if (e) return;
2206
+ f(t instanceof Error ? t : Error(String(t))), u(null), m("error");
2207
+ }
2208
+ })(), () => {
2209
+ e = !0;
2210
+ };
2211
+ }, [
2212
+ r,
2213
+ t,
2214
+ a,
2215
+ o
2216
+ ]);
2217
+ let h = n(() => {
2218
+ s((e) => e + 1);
2219
+ }, []);
2220
+ return {
2221
+ href: l && l.status === "ready" ? l.href : void 0,
2222
+ status: p,
2223
+ source: l && l.status === "ready" ? l.source : void 0,
2224
+ error: d,
2225
+ result: l,
2226
+ refetch: h
2227
+ };
2069
2228
  }
2070
- function jr({
2071
- value: e,
2072
- enabled: t,
2073
- treatAs: r,
2074
- render: n,
2075
- alt: o,
2076
- ...a
2077
- }) {
2078
- const { href: s } = tt({ value: e, enabled: t, treatAs: r });
2079
- if (!s)
2080
- return null;
2081
- const c = { ...a, src: s, alt: o ?? "" };
2082
- return n ? /* @__PURE__ */ g(Se, { children: n(c) }) : /* @__PURE__ */ g("img", { ...c });
2229
+ //#endregion
2230
+ //#region src/SeedMediaImage.tsx
2231
+ function qt({ value: e, enabled: t, treatAs: n, render: r, alt: i, ...a }) {
2232
+ let { href: o } = Kt({
2233
+ value: e,
2234
+ enabled: t,
2235
+ treatAs: n
2236
+ });
2237
+ if (!o) return null;
2238
+ let s = {
2239
+ ...a,
2240
+ src: o,
2241
+ alt: i ?? ""
2242
+ };
2243
+ return r ? /* @__PURE__ */ I(F, { children: r(s) }) : /* @__PURE__ */ I("img", { ...s });
2083
2244
  }
2084
- function Xt(e) {
2085
- try {
2086
- return new URL(e).pathname.split("/").filter(Boolean).pop() || "Open";
2087
- } catch {
2088
- return "Open";
2089
- }
2245
+ //#endregion
2246
+ //#region src/SeedMediaFile.tsx
2247
+ function Jt(e) {
2248
+ try {
2249
+ return new URL(e).pathname.split("/").filter(Boolean).pop() || "Open";
2250
+ } catch {
2251
+ return "Open";
2252
+ }
2090
2253
  }
2091
- function Zt(e) {
2092
- try {
2093
- const t = new URL(e).protocol;
2094
- return t === "http:" || t === "https:";
2095
- } catch {
2096
- return !1;
2097
- }
2254
+ function Yt(e) {
2255
+ try {
2256
+ let t = new URL(e).protocol;
2257
+ return t === "http:" || t === "https:";
2258
+ } catch {
2259
+ return !1;
2260
+ }
2098
2261
  }
2099
- function Wr({
2100
- value: e,
2101
- enabled: t,
2102
- treatAs: r,
2103
- download: n,
2104
- render: o,
2105
- children: a,
2106
- target: s,
2107
- rel: c,
2108
- ...l
2109
- }) {
2110
- const { href: i } = tt({ value: e, enabled: t, treatAs: r });
2111
- if (!i)
2112
- return null;
2113
- const d = Zt(i), u = s !== void 0 ? s : d ? "_blank" : void 0, f = {
2114
- ...l,
2115
- href: i,
2116
- download: n,
2117
- target: u,
2118
- rel: c ?? (d && u === "_blank" ? "noopener noreferrer" : void 0),
2119
- children: a ?? Xt(i)
2120
- };
2121
- return o ? /* @__PURE__ */ g(Se, { children: o(f) }) : /* @__PURE__ */ g("a", { ...f });
2262
+ function Xt({ value: e, enabled: t, treatAs: n, download: r, render: i, children: a, target: o, rel: s, ...c }) {
2263
+ let { href: l } = Kt({
2264
+ value: e,
2265
+ enabled: t,
2266
+ treatAs: n
2267
+ });
2268
+ if (!l) return null;
2269
+ let u = Yt(l), d = o === void 0 ? u ? "_blank" : void 0 : o, f = {
2270
+ ...c,
2271
+ href: l,
2272
+ download: r,
2273
+ target: d,
2274
+ rel: s ?? (u && d === "_blank" ? "noopener noreferrer" : void 0),
2275
+ children: a ?? Jt(l)
2276
+ };
2277
+ return i ? /* @__PURE__ */ I(F, { children: i(f) }) : /* @__PURE__ */ I("a", { ...f });
2122
2278
  }
2123
- function er(e) {
2124
- return typeof e == "string" && e.trim().length > 0;
2279
+ //#endregion
2280
+ //#region src/SeedHtml.tsx
2281
+ function Zt(e) {
2282
+ return typeof e == "string" && e.trim().length > 0;
2125
2283
  }
2126
- function Jr({
2127
- html: e,
2128
- sanitize: t,
2129
- render: r,
2130
- ...n
2131
- }) {
2132
- if (!er(e))
2133
- return null;
2134
- const o = t(e);
2135
- return r ? /* @__PURE__ */ g(Se, { children: r({ html: o }) }) : /* @__PURE__ */ g("div", { ...n, dangerouslySetInnerHTML: { __html: o } });
2284
+ function Qt({ html: e, sanitize: t, render: n, ...r }) {
2285
+ if (!Zt(e)) return null;
2286
+ let i = t(e);
2287
+ return n ? /* @__PURE__ */ I(F, { children: n({ html: i }) }) : /* @__PURE__ */ I("div", {
2288
+ ...r,
2289
+ dangerouslySetInnerHTML: { __html: i }
2290
+ });
2136
2291
  }
2137
- function De(e, t) {
2138
- return e.length <= t ? e : `${e.slice(0, t)}…`;
2292
+ //#endregion
2293
+ //#region src/formatSeedJson.ts
2294
+ function $t(e, t) {
2295
+ return e.length <= t ? e : `${e.slice(0, t)}…`;
2139
2296
  }
2140
- function tr(e) {
2141
- const t = e.trim();
2142
- return t.startsWith("{") && t.endsWith("}") || t.startsWith("[") && t.endsWith("]");
2297
+ function en(e) {
2298
+ let t = e.trim();
2299
+ return t.startsWith("{") && t.endsWith("}") || t.startsWith("[") && t.endsWith("]");
2143
2300
  }
2144
- function Fe(e, t, r, n, o) {
2145
- if (typeof e == "bigint")
2146
- return String(e);
2147
- if (typeof e == "symbol")
2148
- return e.toString();
2149
- if (typeof e == "function")
2150
- return "[Function]";
2151
- if (e instanceof Date)
2152
- return e.toISOString();
2153
- if (typeof e == "string")
2154
- return De(e, r);
2155
- if (e === null || typeof e != "object")
2156
- return e;
2157
- if (o.has(e))
2158
- return "[Circular]";
2159
- if (n >= t)
2160
- return "[Max depth]";
2161
- if (o.add(e), Array.isArray(e))
2162
- return e.map((s) => Fe(s, t, r, n + 1, o));
2163
- const a = {};
2164
- for (const [s, c] of Object.entries(e))
2165
- a[s] = Fe(c, t, r, n + 1, o);
2166
- return a;
2301
+ function tn(e, t, n, r, i) {
2302
+ if (typeof e == "bigint") return String(e);
2303
+ if (typeof e == "symbol") return e.toString();
2304
+ if (typeof e == "function") return "[Function]";
2305
+ if (e instanceof Date) return e.toISOString();
2306
+ if (typeof e == "string") return $t(e, n);
2307
+ if (typeof e != "object" || !e) return e;
2308
+ if (i.has(e)) return "[Circular]";
2309
+ if (r >= t) return "[Max depth]";
2310
+ if (i.add(e), Array.isArray(e)) return e.map((e) => tn(e, t, n, r + 1, i));
2311
+ let a = {};
2312
+ for (let [o, s] of Object.entries(e)) a[o] = tn(s, t, n, r + 1, i);
2313
+ return a;
2167
2314
  }
2168
- function rr(e, t) {
2169
- const r = t?.maxDepth ?? 6, n = t?.maxStringLength ?? 5e4, o = t?.space ?? 2;
2170
- if (e === void 0)
2171
- return "undefined";
2172
- if (e === null)
2173
- return "null";
2174
- let a = e;
2175
- if (typeof e == "string")
2176
- if (tr(e))
2177
- try {
2178
- a = JSON.parse(e);
2179
- } catch {
2180
- return De(e, n);
2181
- }
2182
- else
2183
- return De(e, n);
2184
- const s = Fe(a, r, n, 0, /* @__PURE__ */ new WeakSet());
2185
- try {
2186
- return JSON.stringify(s, null, o);
2187
- } catch {
2188
- return "[Unserializable JSON]";
2189
- }
2315
+ function nn(e, t) {
2316
+ let n = t?.maxDepth ?? 6, r = t?.maxStringLength ?? 5e4, i = t?.space ?? 2;
2317
+ if (e === void 0) return "undefined";
2318
+ if (e === null) return "null";
2319
+ let a = e;
2320
+ if (typeof e == "string") if (en(e)) try {
2321
+ a = JSON.parse(e);
2322
+ } catch {
2323
+ return $t(e, r);
2324
+ }
2325
+ else return $t(e, r);
2326
+ let o = tn(a, n, r, 0, /* @__PURE__ */ new WeakSet());
2327
+ try {
2328
+ return JSON.stringify(o, null, i);
2329
+ } catch {
2330
+ return "[Unserializable JSON]";
2331
+ }
2190
2332
  }
2191
- function Gr({
2192
- value: e,
2193
- format: t,
2194
- formatOptions: r,
2195
- render: n,
2196
- ...o
2197
- }) {
2198
- const a = t ? t(e) : rr(e, r);
2199
- return n ? /* @__PURE__ */ g(Se, { children: n({ text: a }) }) : /* @__PURE__ */ g("pre", { ...o, children: a });
2333
+ //#endregion
2334
+ //#region src/SeedJson.tsx
2335
+ function rn({ value: e, format: t, formatOptions: n, render: r, ...i }) {
2336
+ let a = t ? t(e) : nn(e, n);
2337
+ return r ? /* @__PURE__ */ I(F, { children: r({ text: a }) }) : /* @__PURE__ */ I("pre", {
2338
+ ...i,
2339
+ children: a
2340
+ });
2200
2341
  }
2201
- function Yr(e, t) {
2202
- return N(() => e ? yt(e, t) : {}, [e, t]);
2342
+ //#endregion
2343
+ //#region src/useNormalizedFeedItemFields.ts
2344
+ function an(e, t) {
2345
+ return o(() => e ? re(e, t) : {}, [e, t]);
2203
2346
  }
2204
- export {
2205
- Me as ADDRESSES_PERSISTED_EVENT,
2206
- Tt as FILES_QUERY_KEY_PREFIX,
2207
- Vr as OPFSFilesManager,
2208
- Qr as SeedClientGate,
2209
- Jr as SeedHtml,
2210
- Kr as SeedImage,
2211
- Gr as SeedJson,
2212
- Wr as SeedMediaFile,
2213
- jr as SeedMediaImage,
2214
- Hr as SeedProvider,
2215
- Bt as createSeedQueryClient,
2216
- rr as formatSeedJson,
2217
- Xe as getSeedQueryDefaultOptions,
2218
- Je as getServiceName,
2219
- Re as getServiceUniqueKey,
2220
- ke as getServiceValue,
2221
- zr as invalidateItemPropertiesForItem,
2222
- $t as mergeSeedQueryDefaults,
2223
- _r as useAllSchemaVersions,
2224
- hr as useCreateItem,
2225
- vr as useCreateItemProperty,
2226
- Fr as useCreateModel,
2227
- Tr as useCreateModelProperty,
2228
- xr as useCreateSchema,
2229
- Lr as useDbsAreReady,
2230
- br as useDebouncedItemProperty,
2231
- kr as useDeleteItem,
2232
- wr as useDestroyItemProperty,
2233
- Cr as useDestroyModel,
2234
- Mr as useDestroyModelProperty,
2235
- Nr as useDestroySchema,
2236
- qr as useEasSyncProcessById,
2237
- Or as useEasSyncProcesses,
2238
- Ur as useEasSyncProcessesNonActiveCount,
2239
- Mt as useEasSyncProcessesState,
2240
- Br as useFiles,
2241
- _t as useGlobalServiceStatus,
2242
- xt as useHasSavedSnapshots,
2243
- $r as useImageFiles,
2244
- At as useIsDbReady,
2245
- pr as useItem,
2246
- Sr as useItemProperties,
2247
- We as useItemProperty,
2248
- mr as useItems,
2249
- Y as useLiveQuery,
2250
- Rt as useModel,
2251
- Rr as useModelProperties,
2252
- Pr as useModelProperty,
2253
- Ct as useModels,
2254
- Yr as useNormalizedFeedItemFields,
2255
- qt as useOPFSFiles,
2256
- Er as usePersistedSnapshots,
2257
- gr as usePublishItem,
2258
- tt as useResolvedMediaRef,
2259
- Dt as useSchema,
2260
- Ar as useSchemas,
2261
- je as useSeedAddressRevision,
2262
- Dr as useSeedProtocolSchema,
2263
- Ir as useService,
2264
- Nt as useServices
2265
- };
2266
- //# sourceMappingURL=index.js.map
2347
+ //#endregion
2348
+ export { W as ADDRESSES_PERSISTED_EVENT, ft as FILES_QUERY_KEY_PREFIX, Vt as OPFSFilesManager, Ot as SeedClientGate, Qt as SeedHtml, Gt as SeedImage, rn as SeedJson, Xt as SeedMediaFile, qt as SeedMediaImage, Et as SeedProvider, St as createSeedQueryClient, nn as formatSeedJson, bt as getSeedQueryDefaultOptions, Fe as getServiceName, X as getServiceUniqueKey, Ie as getServiceValue, wt as invalidateItemPropertiesForItem, xt as mergeSeedQueryDefaults, Xe as useAllSchemaVersions, Te as useCreateItem, je as useCreateItemProperty, nt as useCreateModel, st as useCreateModelProperty, Je as useCreateSchema, Ue as useDbsAreReady, Oe as useDebouncedItemProperty, lt as useDeleteItem, Me as useDestroyItemProperty, rt as useDestroyModel, ct as useDestroyModelProperty, Ye as useDestroySchema, vt as useEasSyncProcessById, gt as useEasSyncProcesses, _t as useEasSyncProcessesNonActiveCount, ht as useEasSyncProcessesState, pt as useFiles, He as useGlobalServiceStatus, Be as useHasSavedSnapshots, dt as useImageFiles, Re as useIsDbReady, Se as useItem, Ae as useItemProperties, De as useItemProperty, we as useItems, K as useLiveQuery, tt as useModel, it as useModelProperties, ot as useModelProperty, et as useModels, an as useNormalizedFeedItemFields, At as useOPFSFiles, ze as usePersistedSnapshots, Ee as usePublishItem, Kt as useResolvedMediaRef, Ge as useSchema, qe as useSchemas, G as useSeedAddressRevision, Ze as useSeedProtocolSchema, Le as useService, Ve as useServices };
2349
+
2350
+ //# sourceMappingURL=index.js.map