@seedprotocol/react 0.4.20 → 0.4.22

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