@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/SeedHtml.d.ts +18 -0
- package/dist/SeedHtml.d.ts.map +1 -0
- package/dist/SeedJson.d.ts +19 -0
- package/dist/SeedJson.d.ts.map +1 -0
- package/dist/SeedMediaFile.d.ts +20 -0
- package/dist/SeedMediaFile.d.ts.map +1 -0
- package/dist/SeedMediaImage.d.ts +18 -0
- package/dist/SeedMediaImage.d.ts.map +1 -0
- package/dist/SeedProvider.d.ts.map +1 -1
- package/dist/SeedSessionContext.d.ts +13 -0
- package/dist/SeedSessionContext.d.ts.map +1 -0
- package/dist/addressesPersistedEventName.d.ts +6 -0
- package/dist/addressesPersistedEventName.d.ts.map +1 -0
- package/dist/formatSeedJson.d.ts +14 -0
- package/dist/formatSeedJson.d.ts.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1188 -978
- package/dist/index.js.map +1 -1
- package/dist/item.d.ts +10 -0
- package/dist/item.d.ts.map +1 -1
- package/dist/useNormalizedFeedItemFields.d.ts +7 -0
- package/dist/useNormalizedFeedItemFields.d.ts.map +1 -0
- package/dist/useResolvedMediaRef.d.ts +19 -0
- package/dist/useResolvedMediaRef.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,147 +1,176 @@
|
|
|
1
|
-
import
|
|
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
|
|
4
|
-
import { orderBy as
|
|
5
|
-
import
|
|
6
|
-
import { useSelector as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
return
|
|
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 [
|
|
18
|
-
if (!
|
|
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 (
|
|
23
|
-
return console.error("[useLiveQuery] Failed to create live query:",
|
|
36
|
+
} catch (s) {
|
|
37
|
+
return console.error("[useLiveQuery] Failed to create live query:", s), null;
|
|
24
38
|
}
|
|
25
|
-
}, [e,
|
|
39
|
+
}, [e, o]);
|
|
26
40
|
return I(() => {
|
|
27
41
|
if (n.current && (n.current.unsubscribe(), n.current = null), !a)
|
|
28
42
|
return;
|
|
29
|
-
const
|
|
43
|
+
const s = a.subscribe({
|
|
30
44
|
next: (l) => {
|
|
31
|
-
|
|
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 =
|
|
51
|
+
return n.current = s, () => {
|
|
38
52
|
n.current && (n.current.unsubscribe(), n.current = null);
|
|
39
53
|
};
|
|
40
|
-
}, [a]),
|
|
54
|
+
}, [a]), t;
|
|
41
55
|
}
|
|
42
|
-
const pe =
|
|
43
|
-
const [n,
|
|
44
|
-
if (!!!(u && (
|
|
45
|
-
|
|
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
|
|
51
|
-
modelName:
|
|
52
|
-
seedLocalId:
|
|
64
|
+
const w = await _e.find({
|
|
65
|
+
modelName: g.current,
|
|
66
|
+
seedLocalId: v.current,
|
|
53
67
|
seedUid: b.current
|
|
54
68
|
});
|
|
55
|
-
if (!
|
|
56
|
-
pe("[useItem] [loadItem] no item found",
|
|
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
|
-
|
|
60
|
-
} catch (
|
|
61
|
-
pe("[useItem] Error loading item:",
|
|
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
|
-
|
|
66
|
-
}, [e,
|
|
67
|
-
if (!
|
|
68
|
-
!
|
|
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
|
-
}, [
|
|
86
|
+
}, [y, p, t, r, f]), I(() => {
|
|
73
87
|
if (!n) {
|
|
74
|
-
|
|
88
|
+
i.current?.unsubscribe(), i.current = void 0, d.current = !1;
|
|
75
89
|
return;
|
|
76
90
|
}
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
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
|
|
82
|
-
|
|
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
|
-
},
|
|
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:
|
|
92
|
-
includeEas:
|
|
113
|
+
deleted: t = !1,
|
|
114
|
+
includeEas: r = !1,
|
|
93
115
|
addressFilter: n
|
|
94
116
|
}) => {
|
|
95
|
-
const
|
|
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
|
-
|
|
120
|
+
u(null);
|
|
99
121
|
return;
|
|
100
122
|
}
|
|
101
|
-
let
|
|
102
|
-
return
|
|
103
|
-
|
|
123
|
+
let w = !1;
|
|
124
|
+
return tt(n).then((m) => {
|
|
125
|
+
w || u(m);
|
|
104
126
|
}), () => {
|
|
105
|
-
|
|
127
|
+
w = !0;
|
|
106
128
|
};
|
|
107
|
-
}, [n]);
|
|
108
|
-
const
|
|
109
|
-
() =>
|
|
110
|
-
[e, r,
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
|
|
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:
|
|
117
|
-
queryFn: () =>
|
|
118
|
-
enabled:
|
|
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 =
|
|
121
|
-
const
|
|
122
|
-
if (!
|
|
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
|
|
125
|
-
|
|
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
|
-
|
|
156
|
+
Re(A.publisher, d),
|
|
128
157
|
le(A.publisher)
|
|
129
158
|
)
|
|
130
|
-
) : n === "watched" && (
|
|
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
|
-
|
|
133
|
-
|
|
161
|
+
Ee(A._markedForDeletion),
|
|
162
|
+
U(A._markedForDeletion, 1)
|
|
134
163
|
)
|
|
135
|
-
) : (
|
|
164
|
+
) : (w.push(
|
|
136
165
|
te(
|
|
137
166
|
le(A._markedForDeletion),
|
|
138
|
-
|
|
167
|
+
U(A._markedForDeletion, 0)
|
|
139
168
|
)
|
|
140
|
-
),
|
|
141
|
-
te(le(A.revokedAt),
|
|
169
|
+
), w.push(
|
|
170
|
+
te(le(A.revokedAt), U(A.revokedAt, 0))
|
|
142
171
|
));
|
|
143
|
-
const
|
|
144
|
-
return
|
|
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(
|
|
153
|
-
}, [
|
|
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 (!
|
|
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
|
|
158
|
-
const
|
|
159
|
-
|
|
191
|
+
for (const N of l.current) {
|
|
192
|
+
const $ = N.seedLocalId || N.seedUid;
|
|
193
|
+
$ && m.add($);
|
|
160
194
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
167
|
-
|
|
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 (
|
|
171
|
-
c.current = new Set(
|
|
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(
|
|
175
|
-
}, [
|
|
176
|
-
items:
|
|
177
|
-
|
|
207
|
+
c.current = new Set(w), s.invalidateQueries({ queryKey: f });
|
|
208
|
+
}, [o, E, s, f]), {
|
|
209
|
+
items: dt(
|
|
210
|
+
g,
|
|
178
211
|
[
|
|
179
|
-
(
|
|
212
|
+
(w) => w.lastVersionPublishedAt || w.attestationCreatedAt || w.createdAt
|
|
180
213
|
],
|
|
181
214
|
["desc"]
|
|
182
215
|
),
|
|
183
|
-
isLoading:
|
|
216
|
+
isLoading: v,
|
|
184
217
|
error: b
|
|
185
218
|
};
|
|
186
|
-
},
|
|
187
|
-
const [e,
|
|
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 (
|
|
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(() =>
|
|
228
|
+
n(null), de(() => t(!0));
|
|
196
229
|
try {
|
|
197
|
-
const c = l ?? {}, { seedLocalId:
|
|
198
|
-
return await
|
|
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(() =>
|
|
236
|
+
queueMicrotask(() => t(!1));
|
|
204
237
|
}
|
|
205
238
|
},
|
|
206
239
|
[e]
|
|
207
240
|
),
|
|
208
241
|
isLoading: e,
|
|
209
|
-
error:
|
|
210
|
-
resetError:
|
|
242
|
+
error: r,
|
|
243
|
+
resetError: o
|
|
211
244
|
};
|
|
212
|
-
},
|
|
213
|
-
const [e,
|
|
214
|
-
|
|
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
|
-
|
|
252
|
+
s.current?.unsubscribe(), s.current = void 0, n(!1);
|
|
220
253
|
return;
|
|
221
254
|
}
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
n(
|
|
226
|
-
const
|
|
227
|
-
a(
|
|
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
|
-
|
|
230
|
-
const u =
|
|
262
|
+
s.current = d;
|
|
263
|
+
const u = i.getSnapshot();
|
|
231
264
|
n(u?.value === "publishing");
|
|
232
|
-
const
|
|
233
|
-
return a(
|
|
234
|
-
|
|
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:
|
|
239
|
-
error:
|
|
271
|
+
isLoading: r,
|
|
272
|
+
error: o,
|
|
240
273
|
resetError: l
|
|
241
274
|
};
|
|
242
|
-
}, ye =
|
|
243
|
-
function
|
|
244
|
-
const
|
|
245
|
-
const N =
|
|
246
|
-
return (N != null ||
|
|
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:
|
|
250
|
-
propertyName:
|
|
282
|
+
seedUid: $,
|
|
283
|
+
propertyName: w
|
|
251
284
|
} : null;
|
|
252
|
-
}, [
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}, [
|
|
258
|
-
const
|
|
259
|
-
if (!
|
|
260
|
-
|
|
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
|
-
|
|
265
|
-
const N =
|
|
266
|
-
if (!N &&
|
|
267
|
-
|
|
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:
|
|
304
|
+
propertyName: m.propertyName,
|
|
272
305
|
seedLocalId: N,
|
|
273
|
-
seedUid:
|
|
306
|
+
seedUid: $
|
|
274
307
|
});
|
|
275
308
|
if (!Q) {
|
|
276
309
|
ye(
|
|
277
|
-
`[useItemProperty] [updateItemProperty] no property found for Item.${N ||
|
|
278
|
-
),
|
|
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
|
-
|
|
314
|
+
o(Q), s(!1), c(null);
|
|
282
315
|
} catch (N) {
|
|
283
|
-
ye("[useItemProperty] Error updating item property:", N),
|
|
316
|
+
ye("[useItemProperty] Error updating item property:", N), o(void 0), s(!1), c(N);
|
|
284
317
|
}
|
|
285
|
-
}, [
|
|
318
|
+
}, [r, m]);
|
|
286
319
|
return I(() => {
|
|
287
|
-
if (!
|
|
288
|
-
|
|
320
|
+
if (!P) {
|
|
321
|
+
o(void 0), s(!1), c(null);
|
|
289
322
|
return;
|
|
290
323
|
}
|
|
291
|
-
n &&
|
|
292
|
-
}, [
|
|
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
|
-
|
|
327
|
+
i.current?.unsubscribe(), i.current = void 0;
|
|
295
328
|
return;
|
|
296
329
|
}
|
|
297
|
-
|
|
298
|
-
let N = 0,
|
|
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
|
-
|
|
302
|
-
const M = _.context,
|
|
303
|
-
(
|
|
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
|
-
|
|
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
|
|
311
|
-
|
|
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
|
|
320
|
-
const
|
|
321
|
-
() =>
|
|
322
|
-
|
|
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
|
-
},
|
|
327
|
-
[
|
|
359
|
+
}, t),
|
|
360
|
+
[t]
|
|
328
361
|
);
|
|
329
362
|
I(() => () => u.cancel(), [u]);
|
|
330
363
|
const f = x(
|
|
331
|
-
(
|
|
332
|
-
l && (d.current =
|
|
364
|
+
(g) => {
|
|
365
|
+
l && (d.current = g, l.getService().send({
|
|
333
366
|
type: "updateContext",
|
|
334
|
-
propertyValue:
|
|
335
|
-
renderValue:
|
|
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:
|
|
377
|
+
error: i
|
|
345
378
|
};
|
|
346
379
|
}
|
|
347
|
-
async function
|
|
348
|
-
if (!e && !
|
|
349
|
-
const
|
|
350
|
-
if (!
|
|
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:
|
|
385
|
+
{ seedLocalId: e ?? void 0, seedUid: t ?? void 0 },
|
|
353
386
|
{ waitForReady: !0 }
|
|
354
|
-
),
|
|
387
|
+
), o = [...n], a = /* @__PURE__ */ new Set();
|
|
355
388
|
for (const c of n)
|
|
356
389
|
c.propertyName && a.add(c.propertyName);
|
|
357
|
-
let
|
|
390
|
+
let s;
|
|
358
391
|
if (n.length > 0) {
|
|
359
392
|
const c = n[0];
|
|
360
|
-
|
|
393
|
+
s = c.modelName ?? c.modelType, s && typeof s == "string" && (s = Ce(s));
|
|
361
394
|
}
|
|
362
|
-
if (!
|
|
363
|
-
const c = await
|
|
364
|
-
c.length > 0 && 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 (
|
|
400
|
+
if (s)
|
|
368
401
|
try {
|
|
369
|
-
const { Model: c } = await import("@seedprotocol/sdk"),
|
|
370
|
-
if (
|
|
371
|
-
for (const d of
|
|
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 ${
|
|
407
|
+
ne(`[useItemProperties] Error getting ModelProperties for ${s}:`, c);
|
|
375
408
|
}
|
|
376
|
-
if (
|
|
377
|
-
const c = n.length > 0 ? n[0].seedLocalId ?? e : e,
|
|
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:
|
|
417
|
+
modelName: s,
|
|
385
418
|
seedLocalId: c || void 0,
|
|
386
|
-
seedUid:
|
|
419
|
+
seedUid: i || void 0,
|
|
387
420
|
propertyValue: null
|
|
388
421
|
},
|
|
389
422
|
{ waitForReady: !1 }
|
|
390
423
|
);
|
|
391
|
-
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 ||
|
|
397
|
-
const c = await
|
|
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
|
|
400
|
-
if (!
|
|
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 ??
|
|
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:
|
|
405
|
-
modelName:
|
|
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
|
-
|
|
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
|
|
451
|
+
return o;
|
|
419
452
|
}
|
|
420
|
-
function
|
|
421
|
-
const
|
|
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 =
|
|
426
|
-
if (
|
|
427
|
-
return
|
|
428
|
-
}, [
|
|
429
|
-
if (!(!
|
|
430
|
-
return
|
|
431
|
-
}, [
|
|
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:
|
|
468
|
+
data: i = [],
|
|
436
469
|
isLoading: d,
|
|
437
470
|
error: u
|
|
438
471
|
} = Z({
|
|
439
472
|
queryKey: c,
|
|
440
|
-
queryFn: () =>
|
|
441
|
-
enabled:
|
|
442
|
-
}), f =
|
|
443
|
-
if (!
|
|
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
|
|
446
|
-
if (!
|
|
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=${
|
|
449
|
-
const
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
492
|
+
Le(
|
|
493
|
+
U(T.seedUid, s),
|
|
494
|
+
Ee(T.propertyName)
|
|
462
495
|
)
|
|
463
|
-
) : a ?
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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:
|
|
479
|
-
}, [
|
|
480
|
-
if (!
|
|
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
|
|
483
|
-
for (const
|
|
484
|
-
if (!
|
|
485
|
-
const
|
|
486
|
-
if (!
|
|
487
|
-
|
|
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
|
|
490
|
-
(
|
|
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(
|
|
494
|
-
}, [
|
|
526
|
+
return Array.from(b.values());
|
|
527
|
+
}, [g]);
|
|
495
528
|
return I(() => {
|
|
496
|
-
if (!
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
propertyName:
|
|
500
|
-
propertyValue:
|
|
501
|
-
seedLocalId:
|
|
502
|
-
seedUid:
|
|
503
|
-
})).sort((
|
|
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 !==
|
|
506
|
-
}, [
|
|
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,
|
|
509
|
-
properties:
|
|
541
|
+
}, [a, s]), {
|
|
542
|
+
properties: i,
|
|
510
543
|
isLoading: d,
|
|
511
544
|
error: u
|
|
512
545
|
};
|
|
513
546
|
}
|
|
514
|
-
const
|
|
515
|
-
const e =
|
|
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
|
-
|
|
551
|
+
o(d);
|
|
519
552
|
return;
|
|
520
553
|
}
|
|
521
|
-
|
|
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
|
-
|
|
557
|
+
o(new Error("Failed to create item property")), r(!1);
|
|
525
558
|
return;
|
|
526
559
|
}
|
|
527
|
-
const
|
|
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
|
-
|
|
563
|
+
o(u instanceof Error ? u : new Error(String(u))), r(!1);
|
|
531
564
|
}
|
|
532
|
-
d?.value === "idle" && (
|
|
565
|
+
d?.value === "idle" && (o(null), r(!1));
|
|
533
566
|
});
|
|
534
|
-
return e.current =
|
|
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:
|
|
540
|
-
isLoading:
|
|
572
|
+
create: s,
|
|
573
|
+
isLoading: t,
|
|
541
574
|
error: n,
|
|
542
575
|
resetError: a
|
|
543
576
|
};
|
|
544
|
-
},
|
|
545
|
-
const [e,
|
|
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
|
|
555
|
-
const d =
|
|
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 =
|
|
595
|
+
const c = s.subscribe(l);
|
|
563
596
|
return () => c.unsubscribe();
|
|
564
597
|
}, [e]);
|
|
565
|
-
const
|
|
566
|
-
|
|
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:
|
|
572
|
-
isLoading:
|
|
573
|
-
error:
|
|
604
|
+
destroy: o,
|
|
605
|
+
isLoading: r.isLoading,
|
|
606
|
+
error: r.error,
|
|
574
607
|
resetError: a
|
|
575
608
|
};
|
|
576
|
-
},
|
|
577
|
-
let
|
|
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
|
-
|
|
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
|
|
588
|
-
if (!
|
|
620
|
+
const r = t.logic.config;
|
|
621
|
+
if (!r.id)
|
|
589
622
|
return;
|
|
590
|
-
let n =
|
|
591
|
-
|
|
592
|
-
let
|
|
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
|
-
|
|
627
|
+
o = e.getSnapshot();
|
|
595
628
|
} catch (a) {
|
|
596
|
-
return
|
|
629
|
+
return xe("Error:", a), n;
|
|
597
630
|
}
|
|
598
|
-
if (
|
|
599
|
-
const a =
|
|
600
|
-
a && a.dbName && (n = a.dbName), a && a.modelNamePlural && (n = a.modelNamePlural), a && a.modelName && (n =
|
|
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
|
-
},
|
|
604
|
-
const [
|
|
636
|
+
}, br = (e) => {
|
|
637
|
+
const [t, r] = S(0), n = (s) => {
|
|
605
638
|
let l = 0;
|
|
606
|
-
const c =
|
|
639
|
+
const c = s;
|
|
607
640
|
if (c.logic?.states) {
|
|
608
|
-
const
|
|
609
|
-
for (const [
|
|
610
|
-
|
|
611
|
-
const u = d.length, f =
|
|
612
|
-
if (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 =
|
|
647
|
+
f && (l = i.indexOf(f) / u * 100);
|
|
615
648
|
}
|
|
616
649
|
return l;
|
|
617
|
-
},
|
|
618
|
-
(
|
|
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(
|
|
655
|
+
clearInterval(s);
|
|
623
656
|
return;
|
|
624
657
|
}
|
|
625
|
-
|
|
658
|
+
r((c) => c + 1);
|
|
626
659
|
},
|
|
627
660
|
[e]
|
|
628
661
|
), a = x(() => {
|
|
629
|
-
const
|
|
630
|
-
|
|
662
|
+
const s = setInterval(() => {
|
|
663
|
+
o(s);
|
|
631
664
|
}, 1e3);
|
|
632
|
-
return
|
|
633
|
-
}, [
|
|
665
|
+
return s;
|
|
666
|
+
}, [o, e]);
|
|
634
667
|
return I(() => {
|
|
635
|
-
const
|
|
636
|
-
return () => clearInterval(
|
|
668
|
+
const s = a();
|
|
669
|
+
return () => clearInterval(s);
|
|
637
670
|
}, []), {
|
|
638
|
-
name:
|
|
639
|
-
timeElapsed:
|
|
640
|
-
value:
|
|
671
|
+
name: Ke(e),
|
|
672
|
+
timeElapsed: t,
|
|
673
|
+
value: Me(e),
|
|
641
674
|
percentComplete: n(e),
|
|
642
|
-
uniqueKey:
|
|
675
|
+
uniqueKey: De(e)
|
|
643
676
|
};
|
|
644
|
-
},
|
|
645
|
-
const [e,
|
|
677
|
+
}, It = () => {
|
|
678
|
+
const [e, t] = S(!1), { internalStatus: r } = xt();
|
|
646
679
|
return I(() => {
|
|
647
|
-
|
|
648
|
-
}, [
|
|
649
|
-
|
|
680
|
+
r === "ready" && t(!0);
|
|
681
|
+
}, [r]), I(() => {
|
|
682
|
+
r === "ready" && t(!0);
|
|
650
683
|
}, []), e;
|
|
651
|
-
},
|
|
652
|
-
const [e,
|
|
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 =
|
|
655
|
-
|
|
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]),
|
|
693
|
+
}, [n]), s = x(async () => {
|
|
661
694
|
const l = W.getAppDb();
|
|
662
|
-
return l ? await l.select().from(ue).where(
|
|
695
|
+
return l ? await l.select().from(ue).where(qe(ue.key, "snapshot__%")) : [];
|
|
663
696
|
}, []);
|
|
664
|
-
I(() => !
|
|
665
|
-
const c = await
|
|
666
|
-
|
|
697
|
+
I(() => !r || e ? void 0 : ((async () => {
|
|
698
|
+
const c = await s();
|
|
699
|
+
xe("persistedSnapshots:", c), t(!0);
|
|
667
700
|
})(), () => {
|
|
668
701
|
a();
|
|
669
|
-
}), [
|
|
670
|
-
},
|
|
671
|
-
const [e,
|
|
702
|
+
}), [r, e]);
|
|
703
|
+
}, Et = () => {
|
|
704
|
+
const [e, t] = S(!1), r = It();
|
|
672
705
|
return I(() => {
|
|
673
|
-
|
|
674
|
-
const a = await W.getAppDb().select().from(ue).where(
|
|
675
|
-
a && a.length > 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
|
-
}, [
|
|
678
|
-
},
|
|
679
|
-
const [e,
|
|
710
|
+
}, [r]), e;
|
|
711
|
+
}, Lt = () => {
|
|
712
|
+
const [e, t] = S([]), [r, n] = S(5);
|
|
680
713
|
return I(() => {
|
|
681
|
-
const a = me().getService(),
|
|
682
|
-
|
|
714
|
+
const a = me().getService(), s = a;
|
|
715
|
+
s.uniqueKey = "clientManager", t([s]);
|
|
683
716
|
const l = a.subscribe((c) => {
|
|
684
|
-
const
|
|
717
|
+
const i = c.value;
|
|
685
718
|
let d = 0;
|
|
686
|
-
|
|
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:
|
|
726
|
+
percentComplete: r
|
|
694
727
|
};
|
|
695
|
-
},
|
|
696
|
-
const
|
|
697
|
-
const a =
|
|
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:
|
|
734
|
+
status: r,
|
|
702
735
|
internalStatus: n
|
|
703
736
|
};
|
|
704
737
|
};
|
|
705
|
-
|
|
706
|
-
const
|
|
707
|
-
const [e,
|
|
708
|
-
e ||
|
|
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
|
|
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
|
-
|
|
748
|
+
r();
|
|
716
749
|
return;
|
|
717
750
|
}
|
|
718
|
-
n =
|
|
719
|
-
const
|
|
720
|
-
(
|
|
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
|
-
},
|
|
729
|
-
const [
|
|
730
|
-
|
|
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
|
-
|
|
768
|
+
r(u);
|
|
736
769
|
const f = u.getService();
|
|
737
|
-
f.getSnapshot().value === "idle" ? (de(() =>
|
|
738
|
-
|
|
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
|
|
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
|
-
|
|
779
|
+
r(null), s(null), o(!1);
|
|
747
780
|
return;
|
|
748
781
|
}
|
|
749
782
|
if (!e) {
|
|
750
|
-
|
|
783
|
+
r(null), s(null), o(!1);
|
|
751
784
|
return;
|
|
752
785
|
}
|
|
753
|
-
return
|
|
786
|
+
return i(e), () => {
|
|
754
787
|
l.current && (l.current.unsubscribe(), l.current = null);
|
|
755
788
|
};
|
|
756
|
-
}, [e, c,
|
|
757
|
-
schema:
|
|
789
|
+
}, [e, c, i]), {
|
|
790
|
+
schema: t,
|
|
758
791
|
isLoading: n,
|
|
759
792
|
error: a
|
|
760
793
|
};
|
|
761
|
-
},
|
|
762
|
-
const e =
|
|
763
|
-
data:
|
|
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:
|
|
798
|
+
error: s
|
|
766
799
|
} = Z({
|
|
767
|
-
queryKey:
|
|
800
|
+
queryKey: ve,
|
|
768
801
|
queryFn: () => he.all({ waitForReady: !0 }),
|
|
769
802
|
enabled: e
|
|
770
803
|
});
|
|
771
|
-
n.current =
|
|
772
|
-
const l = e ? W.getAppDb() : null, 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
|
-
|
|
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
|
-
}, [
|
|
782
|
-
if (!e || !
|
|
814
|
+
}, [t]), I(() => {
|
|
815
|
+
if (!e || !i)
|
|
783
816
|
return;
|
|
784
|
-
const d =
|
|
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
|
-
|
|
788
|
-
const
|
|
789
|
-
for (const
|
|
790
|
-
const
|
|
791
|
-
if (
|
|
792
|
-
|
|
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
|
|
795
|
-
|
|
827
|
+
const w = p.metadata?.name, m = p.version;
|
|
828
|
+
w && m !== void 0 && g.add(`${w}:${m}`);
|
|
796
829
|
}
|
|
797
830
|
}
|
|
798
|
-
const
|
|
799
|
-
for (const
|
|
800
|
-
|
|
801
|
-
const
|
|
802
|
-
!
|
|
803
|
-
}, [e,
|
|
804
|
-
schemas:
|
|
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:
|
|
839
|
+
error: s
|
|
807
840
|
};
|
|
808
|
-
},
|
|
809
|
-
const e =
|
|
810
|
-
|
|
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
|
-
}),
|
|
846
|
+
}), i = c.getService().subscribe((d) => {
|
|
814
847
|
if (d.value === "error") {
|
|
815
848
|
const u = d.context._loadingError?.error;
|
|
816
|
-
|
|
849
|
+
o(u instanceof Error ? u : new Error("Failed to create schema")), r(!1);
|
|
817
850
|
}
|
|
818
|
-
d.value === "idle" && (
|
|
851
|
+
d.value === "idle" && (o(null), r(!1));
|
|
819
852
|
});
|
|
820
|
-
return e.current =
|
|
853
|
+
return e.current = i, c;
|
|
821
854
|
}, []);
|
|
822
855
|
return I(() => () => {
|
|
823
856
|
e.current?.unsubscribe(), e.current = null;
|
|
824
857
|
}, []), {
|
|
825
|
-
createSchema:
|
|
826
|
-
isLoading:
|
|
858
|
+
createSchema: s,
|
|
859
|
+
isLoading: t,
|
|
827
860
|
error: n,
|
|
828
861
|
resetError: a
|
|
829
862
|
};
|
|
830
|
-
},
|
|
831
|
-
const [e,
|
|
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
|
|
841
|
-
const d =
|
|
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 =
|
|
881
|
+
const c = s.subscribe(l);
|
|
849
882
|
return () => c.unsubscribe();
|
|
850
883
|
}, [e]);
|
|
851
|
-
const
|
|
852
|
-
|
|
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:
|
|
858
|
-
isLoading:
|
|
859
|
-
error:
|
|
890
|
+
destroy: o,
|
|
891
|
+
isLoading: r.isLoading,
|
|
892
|
+
error: r.error,
|
|
860
893
|
resetError: a
|
|
861
894
|
};
|
|
862
|
-
},
|
|
863
|
-
const [e,
|
|
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
|
|
899
|
+
const a = await st(), s = /* @__PURE__ */ new Set();
|
|
867
900
|
for (const c of a) {
|
|
868
|
-
const
|
|
869
|
-
|
|
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
|
|
873
|
-
if (
|
|
874
|
-
const
|
|
875
|
-
l.set(c,
|
|
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
|
|
910
|
+
const i = he.create(c, {
|
|
878
911
|
waitForReady: !1
|
|
879
912
|
});
|
|
880
|
-
l.set(c,
|
|
913
|
+
l.set(c, i);
|
|
881
914
|
}
|
|
882
|
-
for (const [c,
|
|
883
|
-
|
|
884
|
-
|
|
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
|
-
|
|
919
|
+
je("Error fetching all schema versions from database:", a), t(null);
|
|
887
920
|
}
|
|
888
921
|
}, [n]);
|
|
889
922
|
return I(() => {
|
|
890
|
-
n &&
|
|
891
|
-
}, [n,
|
|
892
|
-
|
|
923
|
+
n && o();
|
|
924
|
+
}, [n, o]), I(() => () => {
|
|
925
|
+
r.current.forEach((a) => {
|
|
893
926
|
a.unload();
|
|
894
|
-
}),
|
|
927
|
+
}), r.current.clear();
|
|
895
928
|
}, []), e;
|
|
896
|
-
},
|
|
897
|
-
const
|
|
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:
|
|
932
|
+
isLoading: s,
|
|
900
933
|
error: l
|
|
901
934
|
} = Z({
|
|
902
|
-
queryKey:
|
|
935
|
+
queryKey: o,
|
|
903
936
|
queryFn: async () => {
|
|
904
|
-
const
|
|
905
|
-
if (Array.isArray(
|
|
906
|
-
return [...
|
|
907
|
-
if (Array.isArray(
|
|
908
|
-
const
|
|
909
|
-
if (Array.isArray(
|
|
910
|
-
return [...
|
|
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
|
|
945
|
+
return p;
|
|
913
946
|
},
|
|
914
|
-
enabled:
|
|
947
|
+
enabled: t && !!e
|
|
915
948
|
}), c = e && typeof e == "string" ? e : "";
|
|
916
|
-
a.length > 0 &&
|
|
917
|
-
const
|
|
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
|
|
921
|
-
const { schemaName:
|
|
922
|
-
(e ===
|
|
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
|
|
925
|
-
|
|
957
|
+
return y.addEventListener("message", p), () => {
|
|
958
|
+
y.removeEventListener("message", p), y.close();
|
|
926
959
|
};
|
|
927
|
-
}, [e,
|
|
928
|
-
const u =
|
|
929
|
-
function
|
|
930
|
-
const
|
|
931
|
-
return !
|
|
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(
|
|
967
|
+
}).from(Y).innerJoin(be, U(Y.id, be.schemaId)).innerJoin(ae, U(be.modelId, ae.id)).where(
|
|
935
968
|
te(
|
|
936
|
-
|
|
937
|
-
|
|
969
|
+
U(Y.schemaFileId, e),
|
|
970
|
+
U(Y.name, e)
|
|
938
971
|
)
|
|
939
972
|
);
|
|
940
973
|
}
|
|
941
|
-
const
|
|
942
|
-
if (!e || !
|
|
943
|
-
const
|
|
944
|
-
if (
|
|
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
|
|
947
|
-
return
|
|
948
|
-
}, [e,
|
|
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 (!
|
|
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
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
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:
|
|
996
|
+
isLoading: s,
|
|
964
997
|
error: l
|
|
965
998
|
};
|
|
966
|
-
},
|
|
967
|
-
const
|
|
968
|
-
if (
|
|
969
|
-
if (!
|
|
970
|
-
|
|
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
|
-
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
} catch (
|
|
979
|
-
console.error("[useModel] Error looking up model by ID:",
|
|
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
|
-
}, [
|
|
1015
|
+
}, [r, u, e]), I(() => {
|
|
983
1016
|
if (!u || !n) {
|
|
984
|
-
|
|
1017
|
+
i.current?.unsubscribe(), i.current = void 0;
|
|
985
1018
|
return;
|
|
986
1019
|
}
|
|
987
|
-
|
|
988
|
-
const
|
|
989
|
-
d((
|
|
1020
|
+
i.current?.unsubscribe();
|
|
1021
|
+
const y = n.getService().subscribe((p) => {
|
|
1022
|
+
d((E) => E + 1);
|
|
990
1023
|
});
|
|
991
|
-
return
|
|
992
|
-
|
|
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:
|
|
1001
|
-
if (
|
|
1002
|
-
return f.find((
|
|
1003
|
-
}, [f,
|
|
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 || !
|
|
1006
|
-
|
|
1038
|
+
if (u || !b) {
|
|
1039
|
+
i.current?.unsubscribe(), i.current = void 0;
|
|
1007
1040
|
return;
|
|
1008
1041
|
}
|
|
1009
|
-
|
|
1010
|
-
const
|
|
1011
|
-
d((
|
|
1042
|
+
i.current?.unsubscribe();
|
|
1043
|
+
const y = b.getService().subscribe((p) => {
|
|
1044
|
+
d((E) => E + 1);
|
|
1012
1045
|
});
|
|
1013
|
-
return
|
|
1014
|
-
|
|
1046
|
+
return i.current = y, () => {
|
|
1047
|
+
i.current?.unsubscribe(), i.current = void 0;
|
|
1015
1048
|
};
|
|
1016
|
-
}, [u,
|
|
1017
|
-
model:
|
|
1018
|
-
isLoading:
|
|
1019
|
-
error:
|
|
1049
|
+
}, [u, b]), {
|
|
1050
|
+
model: b,
|
|
1051
|
+
isLoading: g,
|
|
1052
|
+
error: v
|
|
1020
1053
|
};
|
|
1021
|
-
},
|
|
1022
|
-
const e =
|
|
1023
|
-
(l, c,
|
|
1024
|
-
|
|
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
|
-
...
|
|
1059
|
+
...i,
|
|
1027
1060
|
waitForReady: !1
|
|
1028
1061
|
}), u = d.getService().subscribe((f) => {
|
|
1029
|
-
f.value === "error" && (
|
|
1062
|
+
f.value === "error" && (o(
|
|
1030
1063
|
f.context._loadingError?.error ?? new Error("Failed to create model")
|
|
1031
|
-
),
|
|
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:
|
|
1041
|
-
isLoading:
|
|
1073
|
+
create: s,
|
|
1074
|
+
isLoading: t,
|
|
1042
1075
|
error: n,
|
|
1043
1076
|
resetError: a
|
|
1044
1077
|
};
|
|
1045
|
-
},
|
|
1046
|
-
const [e,
|
|
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
|
|
1056
|
-
const d =
|
|
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 =
|
|
1096
|
+
const c = s.subscribe(l);
|
|
1064
1097
|
return () => c.unsubscribe();
|
|
1065
1098
|
}, [e]);
|
|
1066
|
-
const
|
|
1067
|
-
|
|
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:
|
|
1073
|
-
isLoading:
|
|
1074
|
-
error:
|
|
1105
|
+
destroy: o,
|
|
1106
|
+
isLoading: r.isLoading,
|
|
1107
|
+
error: r.error,
|
|
1075
1108
|
resetError: a
|
|
1076
1109
|
};
|
|
1077
1110
|
};
|
|
1078
|
-
|
|
1079
|
-
const
|
|
1080
|
-
const { model:
|
|
1081
|
-
|
|
1082
|
-
if (
|
|
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
|
|
1117
|
+
return r.modelName ?? r.name;
|
|
1085
1118
|
} catch {
|
|
1086
1119
|
return;
|
|
1087
1120
|
}
|
|
1088
|
-
}, [
|
|
1089
|
-
const n =
|
|
1090
|
-
if (!
|
|
1121
|
+
}, [r]);
|
|
1122
|
+
const n = q(), o = X(), a = F(() => {
|
|
1123
|
+
if (!r) return null;
|
|
1091
1124
|
try {
|
|
1092
|
-
return
|
|
1125
|
+
return r._getSnapshotContext()._dbId;
|
|
1093
1126
|
} catch {
|
|
1094
1127
|
return null;
|
|
1095
1128
|
}
|
|
1096
|
-
}, [
|
|
1097
|
-
() => ["seed", "modelProperties",
|
|
1098
|
-
[
|
|
1129
|
+
}, [r]), s = r?.id, l = F(
|
|
1130
|
+
() => ["seed", "modelProperties", s ?? ""],
|
|
1131
|
+
[s]
|
|
1099
1132
|
), {
|
|
1100
1133
|
data: c = [],
|
|
1101
|
-
isLoading:
|
|
1134
|
+
isLoading: i,
|
|
1102
1135
|
error: d
|
|
1103
1136
|
} = Z({
|
|
1104
1137
|
queryKey: l,
|
|
1105
|
-
queryFn: () => fe.all(
|
|
1106
|
-
enabled: n && !!
|
|
1107
|
-
}), u = n ? W.getAppDb() : null, f =
|
|
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(
|
|
1113
|
-
|
|
1114
|
-
if (!
|
|
1115
|
-
const
|
|
1116
|
-
(
|
|
1117
|
-
|
|
1118
|
-
},
|
|
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 () =>
|
|
1121
|
-
}, [
|
|
1122
|
-
if (!n || !
|
|
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
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
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:
|
|
1169
|
+
isLoading: b,
|
|
1137
1170
|
error: d
|
|
1138
1171
|
};
|
|
1139
|
-
},
|
|
1140
|
-
const
|
|
1141
|
-
if (!
|
|
1172
|
+
}, Dt = async (e, t) => {
|
|
1173
|
+
const r = await oe.createById(e);
|
|
1174
|
+
if (!r)
|
|
1142
1175
|
return;
|
|
1143
|
-
const n =
|
|
1176
|
+
const n = r.modelName ?? r.name;
|
|
1144
1177
|
if (n)
|
|
1145
|
-
return
|
|
1178
|
+
return Ue(n, t);
|
|
1146
1179
|
};
|
|
1147
|
-
function
|
|
1148
|
-
const n =
|
|
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),
|
|
1183
|
+
a(void 0), l(!1), i(null);
|
|
1151
1184
|
return;
|
|
1152
1185
|
}
|
|
1153
|
-
let
|
|
1186
|
+
let y, p;
|
|
1154
1187
|
try {
|
|
1155
|
-
if (l(!0),
|
|
1188
|
+
if (l(!0), i(null), f.type === "propertyFileId") {
|
|
1156
1189
|
if (!f.propertyFileId) {
|
|
1157
|
-
a(void 0), l(!1),
|
|
1190
|
+
a(void 0), l(!1), i(null);
|
|
1158
1191
|
return;
|
|
1159
1192
|
}
|
|
1160
|
-
const
|
|
1161
|
-
|
|
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),
|
|
1198
|
+
a(void 0), l(!1), i(null);
|
|
1166
1199
|
return;
|
|
1167
1200
|
}
|
|
1168
|
-
|
|
1169
|
-
const
|
|
1170
|
-
|
|
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),
|
|
1206
|
+
a(void 0), l(!1), i(null);
|
|
1174
1207
|
return;
|
|
1175
1208
|
}
|
|
1176
|
-
|
|
1209
|
+
y = await Ue(f.modelName, f.propertyName), p = f.modelName;
|
|
1177
1210
|
}
|
|
1178
|
-
if (
|
|
1179
|
-
const
|
|
1180
|
-
{ ...
|
|
1211
|
+
if (y && p) {
|
|
1212
|
+
const E = fe.create(
|
|
1213
|
+
{ ...y, modelName: p },
|
|
1181
1214
|
{ waitForReady: !1 }
|
|
1182
|
-
),
|
|
1215
|
+
), w = E instanceof Promise ? await E : E;
|
|
1183
1216
|
de(() => {
|
|
1184
|
-
a(
|
|
1217
|
+
a(w), l(!1), i(null);
|
|
1185
1218
|
});
|
|
1186
1219
|
} else
|
|
1187
|
-
a(void 0), l(!1),
|
|
1188
|
-
} catch (
|
|
1189
|
-
console.error("[useModelProperty] Error updating model property:",
|
|
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 (!
|
|
1194
|
-
a(void 0), l(!1),
|
|
1226
|
+
if (!g) {
|
|
1227
|
+
a(void 0), l(!1), i(null);
|
|
1195
1228
|
return;
|
|
1196
1229
|
}
|
|
1197
|
-
|
|
1198
|
-
}, [
|
|
1199
|
-
const
|
|
1230
|
+
v();
|
|
1231
|
+
}, [g, v]);
|
|
1232
|
+
const b = f.type === "propertyFileId";
|
|
1200
1233
|
return I(() => {
|
|
1201
|
-
if (!
|
|
1234
|
+
if (!o || !b)
|
|
1202
1235
|
return;
|
|
1203
1236
|
d.current?.unsubscribe();
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1237
|
+
const y = ze(v, 100), p = o.getService().subscribe(() => {
|
|
1238
|
+
y();
|
|
1206
1239
|
});
|
|
1207
|
-
return d.current =
|
|
1208
|
-
|
|
1240
|
+
return d.current = p, () => {
|
|
1241
|
+
y.cancel(), d.current?.unsubscribe(), d.current = void 0;
|
|
1209
1242
|
};
|
|
1210
|
-
}, [
|
|
1211
|
-
modelProperty:
|
|
1212
|
-
isLoading:
|
|
1243
|
+
}, [o, v, b]), {
|
|
1244
|
+
modelProperty: o,
|
|
1245
|
+
isLoading: s,
|
|
1213
1246
|
error: c
|
|
1214
1247
|
};
|
|
1215
1248
|
}
|
|
1216
|
-
const
|
|
1217
|
-
const e =
|
|
1218
|
-
(l, c,
|
|
1219
|
-
if (
|
|
1220
|
-
const
|
|
1221
|
-
throw
|
|
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 =
|
|
1224
|
-
{ ...
|
|
1256
|
+
const d = it(l) ?? l, u = fe.create(
|
|
1257
|
+
{ ...i, modelName: c },
|
|
1225
1258
|
{ waitForReady: !1, schemaName: d }
|
|
1226
|
-
), f = u.getService().subscribe((
|
|
1227
|
-
if (
|
|
1228
|
-
const
|
|
1229
|
-
|
|
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
|
-
|
|
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:
|
|
1241
|
-
isLoading:
|
|
1273
|
+
create: s,
|
|
1274
|
+
isLoading: t,
|
|
1242
1275
|
error: n,
|
|
1243
1276
|
resetError: a
|
|
1244
1277
|
};
|
|
1245
|
-
},
|
|
1246
|
-
const [e,
|
|
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
|
|
1256
|
-
const d =
|
|
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 =
|
|
1296
|
+
const c = s.subscribe(l);
|
|
1264
1297
|
return () => c.unsubscribe();
|
|
1265
1298
|
}, [e]);
|
|
1266
|
-
const
|
|
1267
|
-
|
|
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:
|
|
1273
|
-
isLoading:
|
|
1274
|
-
error:
|
|
1305
|
+
destroy: o,
|
|
1306
|
+
isLoading: r.isLoading,
|
|
1307
|
+
error: r.error,
|
|
1275
1308
|
resetError: a
|
|
1276
1309
|
};
|
|
1277
|
-
},
|
|
1278
|
-
const [e,
|
|
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
|
|
1288
|
-
const d =
|
|
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 =
|
|
1328
|
+
const c = s.subscribe(l);
|
|
1296
1329
|
return () => c.unsubscribe();
|
|
1297
1330
|
}, [e]);
|
|
1298
|
-
const
|
|
1299
|
-
|
|
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:
|
|
1305
|
-
isLoading:
|
|
1306
|
-
error:
|
|
1337
|
+
deleteItem: o,
|
|
1338
|
+
isLoading: r.isLoading,
|
|
1339
|
+
error: r.error,
|
|
1307
1340
|
resetError: a
|
|
1308
1341
|
};
|
|
1309
|
-
},
|
|
1310
|
-
function
|
|
1311
|
-
const e =
|
|
1312
|
-
data:
|
|
1342
|
+
}, Se = ["seed", "imageFiles"];
|
|
1343
|
+
function Pr() {
|
|
1344
|
+
const e = q(), t = X(), {
|
|
1345
|
+
data: r = [],
|
|
1313
1346
|
isLoading: n,
|
|
1314
|
-
error:
|
|
1347
|
+
error: o,
|
|
1315
1348
|
refetch: a
|
|
1316
1349
|
} = Z({
|
|
1317
|
-
queryKey:
|
|
1350
|
+
queryKey: Se,
|
|
1318
1351
|
queryFn: () => j.listImageFiles(),
|
|
1319
1352
|
enabled: e
|
|
1320
1353
|
});
|
|
1321
1354
|
return I(() => {
|
|
1322
|
-
const
|
|
1323
|
-
c.includes("/images/") &&
|
|
1355
|
+
const s = (c) => {
|
|
1356
|
+
c.includes("/images/") && t.invalidateQueries({ queryKey: Se });
|
|
1324
1357
|
}, l = () => {
|
|
1325
|
-
|
|
1358
|
+
t.invalidateQueries({ queryKey: Se });
|
|
1326
1359
|
};
|
|
1327
|
-
return K.on("file-saved",
|
|
1328
|
-
K.off("file-saved",
|
|
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
|
-
}, [
|
|
1331
|
-
imageFiles:
|
|
1363
|
+
}, [t]), {
|
|
1364
|
+
imageFiles: r,
|
|
1332
1365
|
isLoading: n,
|
|
1333
|
-
error:
|
|
1366
|
+
error: o instanceof Error ? o : null,
|
|
1334
1367
|
refetch: a
|
|
1335
1368
|
};
|
|
1336
1369
|
}
|
|
1337
|
-
const
|
|
1338
|
-
function
|
|
1339
|
-
const
|
|
1340
|
-
data:
|
|
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:
|
|
1375
|
+
error: s,
|
|
1343
1376
|
refetch: l
|
|
1344
1377
|
} = Z({
|
|
1345
1378
|
queryKey: n,
|
|
1346
1379
|
queryFn: () => j.listFiles(e),
|
|
1347
|
-
enabled:
|
|
1380
|
+
enabled: t
|
|
1348
1381
|
});
|
|
1349
1382
|
return I(() => {
|
|
1350
1383
|
const c = (d) => {
|
|
1351
|
-
d.includes(`/${e}/`) &&
|
|
1352
|
-
},
|
|
1353
|
-
|
|
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",
|
|
1356
|
-
K.off("file-saved", c), K.off("fs.downloadAll.success",
|
|
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
|
-
}, [
|
|
1359
|
-
files:
|
|
1391
|
+
}, [r, e, n]), {
|
|
1392
|
+
files: o,
|
|
1360
1393
|
isLoading: a,
|
|
1361
|
-
error:
|
|
1394
|
+
error: s instanceof Error ? s : null,
|
|
1362
1395
|
refetch: l
|
|
1363
1396
|
};
|
|
1364
1397
|
}
|
|
1365
|
-
const
|
|
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
|
|
1375
|
-
return { ...
|
|
1407
|
+
function We() {
|
|
1408
|
+
return { ...Rt };
|
|
1376
1409
|
}
|
|
1377
|
-
function
|
|
1378
|
-
const
|
|
1410
|
+
function Pt(e) {
|
|
1411
|
+
const t = We();
|
|
1379
1412
|
return e ? {
|
|
1380
1413
|
queries: {
|
|
1381
|
-
...
|
|
1414
|
+
...t.queries,
|
|
1382
1415
|
...e.queries ?? {}
|
|
1383
1416
|
},
|
|
1384
1417
|
mutations: {
|
|
1385
|
-
...
|
|
1418
|
+
...t.mutations ?? {},
|
|
1386
1419
|
...e.mutations ?? {}
|
|
1387
1420
|
}
|
|
1388
|
-
} :
|
|
1421
|
+
} : t;
|
|
1389
1422
|
}
|
|
1390
|
-
function
|
|
1391
|
-
const
|
|
1392
|
-
return new
|
|
1423
|
+
function Mt(e) {
|
|
1424
|
+
const t = We(), { defaultOptions: r, ...n } = e ?? {};
|
|
1425
|
+
return new mt({
|
|
1393
1426
|
...n,
|
|
1394
|
-
defaultOptions:
|
|
1427
|
+
defaultOptions: r ? Pt(r) : t
|
|
1395
1428
|
});
|
|
1396
1429
|
}
|
|
1397
|
-
let
|
|
1398
|
-
function
|
|
1399
|
-
const
|
|
1400
|
-
return typeof window < "u" && window.__SEED_INVALIDATE_ITEM_PROPERTIES__ && window.__SEED_INVALIDATE_ITEM_PROPERTIES__(e), Promise.resolve(
|
|
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
|
|
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
|
|
1412
|
-
|
|
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",
|
|
1415
|
-
K.off("itemProperty.saved",
|
|
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
|
|
1420
|
-
const n =
|
|
1421
|
-
() =>
|
|
1422
|
-
[
|
|
1452
|
+
function kr({ children: e, queryClient: t, queryClientRef: r }) {
|
|
1453
|
+
const n = F(
|
|
1454
|
+
() => t ?? Mt(),
|
|
1455
|
+
[t]
|
|
1423
1456
|
);
|
|
1424
|
-
if (
|
|
1425
|
-
const
|
|
1426
|
-
|
|
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__ */
|
|
1433
|
-
/* @__PURE__ */
|
|
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
|
|
1438
|
-
return /* @__PURE__ */
|
|
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
|
|
1485
|
+
function $r({
|
|
1453
1486
|
initConfig: e,
|
|
1454
|
-
schema:
|
|
1455
|
-
loadingComponent:
|
|
1487
|
+
schema: t,
|
|
1488
|
+
loadingComponent: r,
|
|
1456
1489
|
wrapperClassName: n,
|
|
1457
|
-
loadingClassName:
|
|
1490
|
+
loadingClassName: o,
|
|
1458
1491
|
children: a
|
|
1459
1492
|
}) {
|
|
1460
|
-
const
|
|
1493
|
+
const s = q();
|
|
1461
1494
|
I(() => {
|
|
1462
|
-
const u =
|
|
1495
|
+
const u = t ? {
|
|
1463
1496
|
...e,
|
|
1464
1497
|
config: {
|
|
1465
1498
|
...e.config,
|
|
1466
|
-
schema:
|
|
1499
|
+
schema: t
|
|
1467
1500
|
}
|
|
1468
1501
|
} : e;
|
|
1469
|
-
|
|
1470
|
-
}, [e,
|
|
1471
|
-
const l =
|
|
1472
|
-
display:
|
|
1473
|
-
...!
|
|
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__ */
|
|
1482
|
-
/* @__PURE__ */
|
|
1514
|
+
return /* @__PURE__ */ O("div", { className: n, style: c, children: [
|
|
1515
|
+
/* @__PURE__ */ h(
|
|
1483
1516
|
"div",
|
|
1484
1517
|
{
|
|
1485
|
-
className:
|
|
1486
|
-
style:
|
|
1487
|
-
"aria-hidden":
|
|
1518
|
+
className: o,
|
|
1519
|
+
style: i,
|
|
1520
|
+
"aria-hidden": s,
|
|
1488
1521
|
children: l
|
|
1489
1522
|
}
|
|
1490
1523
|
),
|
|
1491
|
-
/* @__PURE__ */
|
|
1524
|
+
/* @__PURE__ */ h("div", { style: {
|
|
1492
1525
|
flex: 1,
|
|
1493
|
-
display:
|
|
1526
|
+
display: s ? "flex" : "none",
|
|
1494
1527
|
flexDirection: "column"
|
|
1495
1528
|
}, children: a })
|
|
1496
1529
|
] });
|
|
1497
1530
|
}
|
|
1498
|
-
async function
|
|
1499
|
-
const
|
|
1531
|
+
async function Je(e, t = "") {
|
|
1532
|
+
const r = [];
|
|
1500
1533
|
try {
|
|
1501
|
-
for await (const [n,
|
|
1502
|
-
const a =
|
|
1503
|
-
if (
|
|
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
|
|
1506
|
-
|
|
1538
|
+
const s = await o.getFile();
|
|
1539
|
+
r.push({
|
|
1507
1540
|
name: n,
|
|
1508
1541
|
path: a,
|
|
1509
|
-
size:
|
|
1510
|
-
type:
|
|
1511
|
-
lastModified:
|
|
1542
|
+
size: s.size,
|
|
1543
|
+
type: s.type || "application/octet-stream",
|
|
1544
|
+
lastModified: s.lastModified
|
|
1512
1545
|
});
|
|
1513
|
-
} catch (
|
|
1514
|
-
console.warn(`Failed to read file ${a}:`,
|
|
1546
|
+
} catch (s) {
|
|
1547
|
+
console.warn(`Failed to read file ${a}:`, s);
|
|
1515
1548
|
}
|
|
1516
|
-
else if (
|
|
1517
|
-
const
|
|
1518
|
-
|
|
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 ${
|
|
1555
|
+
console.warn(`Failed to scan directory ${t}:`, n);
|
|
1523
1556
|
}
|
|
1524
|
-
return
|
|
1557
|
+
return r;
|
|
1525
1558
|
}
|
|
1526
|
-
function
|
|
1527
|
-
const { rootPath:
|
|
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 (
|
|
1532
|
-
const f =
|
|
1533
|
-
for (const
|
|
1534
|
-
d = await d.getDirectoryHandle(
|
|
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
|
|
1537
|
-
n(u.sort((f,
|
|
1538
|
-
} catch (
|
|
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: " + (
|
|
1541
|
-
), console.error("OPFS access error:",
|
|
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
|
-
}, [
|
|
1578
|
+
}, [t]);
|
|
1546
1579
|
return I(() => {
|
|
1547
1580
|
c();
|
|
1548
|
-
}, [c]), { files:
|
|
1581
|
+
}, [c]), { files: r, isLoading: o, error: s, refetch: c };
|
|
1549
1582
|
}
|
|
1550
|
-
const
|
|
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__ */
|
|
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__ */
|
|
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
|
|
1614
|
+
function zt(e) {
|
|
1582
1615
|
if (e === 0) return "0 Bytes";
|
|
1583
|
-
const
|
|
1584
|
-
return Math.round(e / Math.pow(
|
|
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
|
|
1619
|
+
function qt(e) {
|
|
1587
1620
|
return new Date(e).toLocaleString();
|
|
1588
1621
|
}
|
|
1589
|
-
async function
|
|
1590
|
-
const
|
|
1591
|
-
if (
|
|
1592
|
-
let n =
|
|
1593
|
-
for (let l = 0; l <
|
|
1594
|
-
n = await n.getDirectoryHandle(
|
|
1595
|
-
const
|
|
1596
|
-
return await (await n.getFileHandle(
|
|
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
|
|
1599
|
-
const
|
|
1600
|
-
if (
|
|
1601
|
-
let n =
|
|
1602
|
-
for (let a = 0; a <
|
|
1603
|
-
n = await n.getDirectoryHandle(
|
|
1604
|
-
const
|
|
1605
|
-
await n.removeEntry(
|
|
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
|
|
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
|
-
},
|
|
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
|
|
1704
|
+
function Br({
|
|
1672
1705
|
rootPath: e,
|
|
1673
|
-
filter:
|
|
1674
|
-
onBeforeDelete:
|
|
1706
|
+
filter: t,
|
|
1707
|
+
onBeforeDelete: r,
|
|
1675
1708
|
onAfterDelete: n,
|
|
1676
|
-
onDownload:
|
|
1709
|
+
onDownload: o,
|
|
1677
1710
|
title: a = "Files",
|
|
1678
|
-
description:
|
|
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
|
|
1683
|
-
|
|
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
|
-
},
|
|
1688
|
-
|
|
1689
|
-
|
|
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
|
-
|
|
1694
|
-
}, [
|
|
1695
|
-
|
|
1696
|
-
}, [
|
|
1697
|
-
const
|
|
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(),
|
|
1700
|
-
if (
|
|
1701
|
-
await
|
|
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(
|
|
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
|
|
1708
|
-
throw k || alert(
|
|
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 (!(
|
|
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
|
|
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
|
-
},
|
|
1719
|
-
if (
|
|
1720
|
-
const L =
|
|
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
|
|
1724
|
-
} catch (
|
|
1725
|
-
k.push(`${_.name}: ${
|
|
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 (
|
|
1732
|
-
const L =
|
|
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 ${
|
|
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(),
|
|
1774
|
+
const _ = await navigator.storage.getDirectory(), z = [], V = [];
|
|
1742
1775
|
for (const M of L)
|
|
1743
|
-
if (!(
|
|
1776
|
+
if (!(r && !await r(M)))
|
|
1744
1777
|
try {
|
|
1745
|
-
await
|
|
1746
|
-
} catch (
|
|
1747
|
-
V.push(`${M.name}: ${
|
|
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
|
-
|
|
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__ */
|
|
1754
|
-
/* @__PURE__ */
|
|
1755
|
-
/* @__PURE__ */
|
|
1756
|
-
/* @__PURE__ */
|
|
1757
|
-
/* @__PURE__ */
|
|
1758
|
-
/* @__PURE__ */
|
|
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__ */
|
|
1793
|
+
/* @__PURE__ */ h("button", { type: "button", onClick: g, className: R.button, children: "Refresh" })
|
|
1761
1794
|
] }),
|
|
1762
|
-
|
|
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 ${
|
|
1798
|
+
className: `mt-4 flex items-center justify-between rounded-lg border px-4 py-3 ${i.batchBar}`,
|
|
1766
1799
|
children: [
|
|
1767
|
-
/* @__PURE__ */
|
|
1768
|
-
|
|
1800
|
+
/* @__PURE__ */ O("span", { className: `text-sm font-medium ${i.batchText}`, children: [
|
|
1801
|
+
b.size,
|
|
1769
1802
|
" file",
|
|
1770
|
-
|
|
1803
|
+
b.size === 1 ? "" : "s",
|
|
1771
1804
|
" selected"
|
|
1772
1805
|
] }),
|
|
1773
|
-
/* @__PURE__ */
|
|
1774
|
-
/* @__PURE__ */
|
|
1775
|
-
/* @__PURE__ */
|
|
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__ */
|
|
1779
|
-
/* @__PURE__ */
|
|
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__ */
|
|
1815
|
+
/* @__PURE__ */ h(
|
|
1783
1816
|
"button",
|
|
1784
1817
|
{
|
|
1785
|
-
onClick: () =>
|
|
1786
|
-
className: `text-sm cursor-pointer bg-transparent border-0 ${
|
|
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__ */
|
|
1795
|
-
/* @__PURE__ */
|
|
1796
|
-
/* @__PURE__ */
|
|
1797
|
-
] }) : f ? /* @__PURE__ */
|
|
1798
|
-
/* @__PURE__ */
|
|
1799
|
-
/* @__PURE__ */
|
|
1800
|
-
] }) :
|
|
1801
|
-
/* @__PURE__ */
|
|
1802
|
-
/* @__PURE__ */
|
|
1803
|
-
/* @__PURE__ */
|
|
1804
|
-
] }) : /* @__PURE__ */
|
|
1805
|
-
/* @__PURE__ */
|
|
1806
|
-
/* @__PURE__ */
|
|
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:
|
|
1842
|
+
ref: p,
|
|
1810
1843
|
type: "checkbox",
|
|
1811
|
-
checked:
|
|
1812
|
-
onChange:
|
|
1844
|
+
checked: E,
|
|
1845
|
+
onChange: P,
|
|
1813
1846
|
"aria-label": "Select all"
|
|
1814
1847
|
}
|
|
1815
1848
|
) }),
|
|
1816
|
-
/* @__PURE__ */
|
|
1817
|
-
/* @__PURE__ */
|
|
1818
|
-
/* @__PURE__ */
|
|
1819
|
-
/* @__PURE__ */
|
|
1820
|
-
/* @__PURE__ */
|
|
1821
|
-
/* @__PURE__ */
|
|
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: `${
|
|
1857
|
+
className: `${R.tableHeader} w-24 ${i.tableHeader}`,
|
|
1825
1858
|
"aria-label": "Actions"
|
|
1826
1859
|
}
|
|
1827
1860
|
)
|
|
1828
1861
|
] }) }),
|
|
1829
|
-
/* @__PURE__ */
|
|
1830
|
-
/* @__PURE__ */
|
|
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:
|
|
1835
|
-
onChange: () =>
|
|
1867
|
+
checked: b.has(L.path),
|
|
1868
|
+
onChange: () => m(L.path),
|
|
1836
1869
|
"aria-label": `Select ${L.name}`
|
|
1837
1870
|
}
|
|
1838
1871
|
) }),
|
|
1839
|
-
/* @__PURE__ */
|
|
1840
|
-
/* @__PURE__ */
|
|
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__ */
|
|
1844
|
-
/* @__PURE__ */
|
|
1845
|
-
/* @__PURE__ */
|
|
1846
|
-
/* @__PURE__ */
|
|
1847
|
-
/* @__PURE__ */
|
|
1848
|
-
/* @__PURE__ */
|
|
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: () =>
|
|
1885
|
+
onClick: () => H(L),
|
|
1853
1886
|
title: "Download",
|
|
1854
|
-
className: `p-1.5 rounded cursor-pointer bg-transparent border-0 transition-colors ${
|
|
1855
|
-
children: /* @__PURE__ */
|
|
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__ */
|
|
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 ${
|
|
1865
|
-
children: /* @__PURE__ */
|
|
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
|
|
1874
|
-
const
|
|
1875
|
-
return
|
|
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
|
|
1910
|
+
function Vt(e) {
|
|
1878
1911
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1879
1912
|
}
|
|
1880
|
-
function
|
|
1881
|
-
const
|
|
1882
|
-
return
|
|
1913
|
+
function Kt(e, t) {
|
|
1914
|
+
const r = new RegExp(`^${Vt(t)}$`), n = Ge(e);
|
|
1915
|
+
return r.test(n);
|
|
1883
1916
|
}
|
|
1884
|
-
const
|
|
1885
|
-
const [
|
|
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
|
-
}),
|
|
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 (
|
|
1892
|
-
return
|
|
1893
|
-
|
|
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
|
-
|
|
1896
|
-
}, [
|
|
1897
|
-
if (!d || u && ((N) => typeof N == "string" && N.startsWith("blob:"))(u) ||
|
|
1898
|
-
let
|
|
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 =
|
|
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
|
-
!
|
|
1937
|
+
!P && Q && l(Q);
|
|
1905
1938
|
}
|
|
1906
1939
|
} catch (N) {
|
|
1907
|
-
|
|
1940
|
+
we("_getOriginalContentUrl error", N);
|
|
1908
1941
|
}
|
|
1909
1942
|
})(), () => {
|
|
1910
|
-
|
|
1943
|
+
P = !0;
|
|
1911
1944
|
};
|
|
1912
|
-
}, [d, u,
|
|
1913
|
-
if (!
|
|
1945
|
+
}, [d, u, v, i?.localStoragePath]), I(() => {
|
|
1946
|
+
if (!t || !d)
|
|
1914
1947
|
return;
|
|
1915
1948
|
(async () => {
|
|
1916
1949
|
try {
|
|
1917
|
-
const
|
|
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
|
|
1921
|
-
if (
|
|
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
|
-
|
|
1958
|
+
} catch (B) {
|
|
1959
|
+
we("error", B), ce.delete(_);
|
|
1927
1960
|
}
|
|
1928
|
-
const V =
|
|
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 = `${
|
|
1964
|
+
const M = `${H}/${L}/${V?.name}`;
|
|
1932
1965
|
if (await j.pathExists(M)) {
|
|
1933
|
-
const
|
|
1934
|
-
|
|
1966
|
+
const B = await j.getContentUrlFromPath(M);
|
|
1967
|
+
B && (ce.set(_, B), a(B));
|
|
1935
1968
|
}
|
|
1936
|
-
} catch (
|
|
1937
|
-
|
|
1969
|
+
} catch (P) {
|
|
1970
|
+
we("_getSizedContentUrl error", P);
|
|
1938
1971
|
}
|
|
1939
1972
|
})();
|
|
1940
|
-
}, [
|
|
1941
|
-
const
|
|
1942
|
-
if (!(!!
|
|
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
|
|
1945
|
-
return /* @__PURE__ */
|
|
1946
|
-
},
|
|
1947
|
-
|
|
1948
|
-
(e,
|
|
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
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
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
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
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
|