@seedprotocol/react 0.4.20 → 0.4.21

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