@declarion/react 0.12.4 → 0.19.0
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-lib/ActionRunner-F1HBBKyQ.js +8344 -0
- package/dist-lib/{DraggableChildrenTable-CcogMLSZ.js → DraggableChildrenTable-D7kzLdIg.js} +55 -54
- package/dist-lib/{Grid-Cwxca9aO.js → Grid-Cz_2olTR.js} +120 -120
- package/dist-lib/{MarkdownRenderer-Dbl3AFDQ.js → MarkdownRenderer-Cm-nbv6g.js} +1 -1
- package/dist-lib/api/data.d.ts +28 -0
- package/dist-lib/api/entities.d.ts +13 -7
- package/dist-lib/dataTableStyles-vwD1mVOP.js +22 -0
- package/dist-lib/declarion-react.css +1 -1
- package/dist-lib/hooks/useCursorEntityData.d.ts +57 -0
- package/dist-lib/hooks/useEntityData.d.ts +2 -2
- package/dist-lib/hooks/useSSE.d.ts +1 -0
- package/dist-lib/index.js +5285 -7322
- package/dist-lib/lib/actions.d.ts +23 -18
- package/dist-lib/testing.d.ts +66 -0
- package/dist-lib/testing.js +147 -0
- package/dist-lib/types/api.d.ts +24 -0
- package/dist-lib/types/schema.d.ts +20 -0
- package/package.json +14 -3
- package/dist-lib/dataTableStyles-EMyLDQRB.js +0 -5342
- package/dist-lib/rich-text-CJpzFOG5.js +0 -46
- package/dist-lib/value-CrpaObP_.js +0 -774
|
@@ -1,774 +0,0 @@
|
|
|
1
|
-
import { createContext as e, useCallback as t, useContext as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
|
|
2
|
-
import { jsx as s } from "react/jsx-runtime";
|
|
3
|
-
//#region src/types/api.ts
|
|
4
|
-
var c = class extends Error {
|
|
5
|
-
status;
|
|
6
|
-
code;
|
|
7
|
-
index;
|
|
8
|
-
raw;
|
|
9
|
-
constructor(e, t, n, r, i) {
|
|
10
|
-
super(t), this.name = "ApiError", this.status = e, this.code = n, this.index = r, this.raw = i;
|
|
11
|
-
}
|
|
12
|
-
}, l = "cursor_semantics_mismatch", u = "cursor_locale_changed";
|
|
13
|
-
function d(e) {
|
|
14
|
-
return e instanceof c && (e.code === "cursor_semantics_mismatch" || e.code === "cursor_locale_changed");
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/api/auth-redirect.ts
|
|
18
|
-
var f = "/", p = "/login", m = "/signup", h = "https://declarion.local";
|
|
19
|
-
function ee(e) {
|
|
20
|
-
let t = e.split(/[?#]/, 1)[0];
|
|
21
|
-
return t === p || t.startsWith(`${p}/`) || t === m || t.startsWith(`${m}/`);
|
|
22
|
-
}
|
|
23
|
-
function te(e) {
|
|
24
|
-
if (!e) return f;
|
|
25
|
-
let t = e.toLowerCase();
|
|
26
|
-
if (!e.startsWith("/") || e.startsWith("//") || e.includes("\\") || t.includes("%5c")) return f;
|
|
27
|
-
try {
|
|
28
|
-
let t = new URL(e, h);
|
|
29
|
-
if (t.origin !== h) return f;
|
|
30
|
-
let n = `${t.pathname}${t.search}${t.hash}`;
|
|
31
|
-
return !n.startsWith("/") || n.startsWith("//") || n.includes("\\") ? f : n || f;
|
|
32
|
-
} catch {
|
|
33
|
-
return f;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function ne(e) {
|
|
37
|
-
let t = te(e);
|
|
38
|
-
return t === f || ee(t) ? p : `${p}?next=${encodeURIComponent(t)}`;
|
|
39
|
-
}
|
|
40
|
-
function re() {
|
|
41
|
-
if (typeof window > "u") return p;
|
|
42
|
-
let { pathname: e, search: t, hash: n } = window.location;
|
|
43
|
-
return ne(`${e}${t}${n}`);
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/embed/protocol.ts
|
|
47
|
-
var g = "declarion-embed", _ = {
|
|
48
|
-
ready: "ready",
|
|
49
|
-
setToken: "set-token",
|
|
50
|
-
tokenExpired: "token-expired",
|
|
51
|
-
reloadRequired: "reload-required",
|
|
52
|
-
resized: "resized",
|
|
53
|
-
navigated: "navigated",
|
|
54
|
-
navigationRequested: "navigation-requested",
|
|
55
|
-
dirtyChanged: "dirty-changed",
|
|
56
|
-
navigationFailed: "navigation-failed",
|
|
57
|
-
navigate: "navigate",
|
|
58
|
-
setTheme: "set-theme"
|
|
59
|
-
};
|
|
60
|
-
function v(e, t, n) {
|
|
61
|
-
if (!e || typeof window > "u" || window.parent === window) return !1;
|
|
62
|
-
let r = {
|
|
63
|
-
source: g,
|
|
64
|
-
protocol: 1,
|
|
65
|
-
type: t,
|
|
66
|
-
payload: n
|
|
67
|
-
};
|
|
68
|
-
return window.parent.postMessage(r, e), !0;
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/embed/token.ts
|
|
72
|
-
var ie = 15e3, ae = 5e3, y = {
|
|
73
|
-
active: !1,
|
|
74
|
-
parentOrigin: null,
|
|
75
|
-
current: null,
|
|
76
|
-
pending: null
|
|
77
|
-
};
|
|
78
|
-
function oe(e) {
|
|
79
|
-
y.active = !0, y.parentOrigin = e;
|
|
80
|
-
}
|
|
81
|
-
function b() {
|
|
82
|
-
return y.active;
|
|
83
|
-
}
|
|
84
|
-
function se() {
|
|
85
|
-
return y.current?.token ?? null;
|
|
86
|
-
}
|
|
87
|
-
function ce() {
|
|
88
|
-
return y.parentOrigin;
|
|
89
|
-
}
|
|
90
|
-
function le() {
|
|
91
|
-
return y.current ? Date.now() >= y.current.expiresAt - ae : !0;
|
|
92
|
-
}
|
|
93
|
-
function ue(e) {
|
|
94
|
-
if (!e.token || typeof e.token != "string") return;
|
|
95
|
-
let t = Date.parse(e.expires_at);
|
|
96
|
-
if (!Number.isNaN(t) && (y.current = {
|
|
97
|
-
token: e.token,
|
|
98
|
-
expiresAt: t
|
|
99
|
-
}, y.pending)) {
|
|
100
|
-
let t = y.pending;
|
|
101
|
-
y.pending = null, clearTimeout(t.timer), t.resolve(e.token);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function x() {
|
|
105
|
-
y.current = null;
|
|
106
|
-
}
|
|
107
|
-
function S() {
|
|
108
|
-
if (!le() && y.current) return Promise.resolve(y.current.token);
|
|
109
|
-
if (y.pending) return y.pending.promise;
|
|
110
|
-
let e, t, n = new Promise((n, r) => {
|
|
111
|
-
e = n, t = r;
|
|
112
|
-
}), r = setTimeout(() => {
|
|
113
|
-
y.pending && y.pending.promise === n && (y.pending = null), t(/* @__PURE__ */ Error(`embed token wait timed out after ${ie}ms`));
|
|
114
|
-
}, ie);
|
|
115
|
-
return y.pending = {
|
|
116
|
-
promise: n,
|
|
117
|
-
resolve: e,
|
|
118
|
-
reject: t,
|
|
119
|
-
timer: r
|
|
120
|
-
}, v(y.parentOrigin, _.tokenExpired, {}), n;
|
|
121
|
-
}
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/lib/versionTracker.ts
|
|
124
|
-
var de = "X-Declarion-Version", fe = "declarion-version";
|
|
125
|
-
function pe() {
|
|
126
|
-
if (typeof BroadcastChannel > "u") return null;
|
|
127
|
-
try {
|
|
128
|
-
return new BroadcastChannel(fe);
|
|
129
|
-
} catch {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
var C = {
|
|
134
|
-
firstSeen: null,
|
|
135
|
-
firstComponents: null,
|
|
136
|
-
hasReportedDrift: !1,
|
|
137
|
-
listeners: /* @__PURE__ */ new Set(),
|
|
138
|
-
channel: null
|
|
139
|
-
};
|
|
140
|
-
function w() {
|
|
141
|
-
C.channel || typeof BroadcastChannel > "u" || (C.channel = pe(), C.channel && C.channel.addEventListener("message", (e) => {
|
|
142
|
-
let t = e.data;
|
|
143
|
-
if (!(!t || t.type !== "drift" || !t.delta) && !C.hasReportedDrift) {
|
|
144
|
-
C.hasReportedDrift = !0;
|
|
145
|
-
for (let e of C.listeners) e(t.delta);
|
|
146
|
-
}
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
function me(e) {
|
|
150
|
-
if (w(), !e) return;
|
|
151
|
-
let t = e.get(de);
|
|
152
|
-
if (t) {
|
|
153
|
-
if (!C.firstSeen) {
|
|
154
|
-
C.firstSeen = t;
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
t !== C.firstSeen && (C.hasReportedDrift || T().catch(() => {
|
|
158
|
-
E({
|
|
159
|
-
kind: "unknown",
|
|
160
|
-
observed: t
|
|
161
|
-
});
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async function T() {
|
|
166
|
-
w();
|
|
167
|
-
let e;
|
|
168
|
-
try {
|
|
169
|
-
let t = {};
|
|
170
|
-
C.firstSeen && (t["If-None-Match"] = `"${C.firstSeen}"`), e = await fetch("/api/version", {
|
|
171
|
-
method: "GET",
|
|
172
|
-
credentials: b() ? "omit" : "include",
|
|
173
|
-
headers: t
|
|
174
|
-
});
|
|
175
|
-
} catch {
|
|
176
|
-
throw Error("version probe network error");
|
|
177
|
-
}
|
|
178
|
-
if (e.status === 304) return;
|
|
179
|
-
if (!e.ok) throw Error(`version probe ${e.status}`);
|
|
180
|
-
let t;
|
|
181
|
-
try {
|
|
182
|
-
t = await e.json();
|
|
183
|
-
} catch {
|
|
184
|
-
throw Error("version probe malformed body");
|
|
185
|
-
}
|
|
186
|
-
let n = t.fingerprint;
|
|
187
|
-
if (typeof n != "string" || n === "") throw Error("version probe missing fingerprint");
|
|
188
|
-
let r = typeof t.schema_fingerprint == "string" && typeof t.asset_fingerprint == "string" && typeof t.binary_fingerprint == "string" ? {
|
|
189
|
-
schema: t.schema_fingerprint,
|
|
190
|
-
asset: t.asset_fingerprint,
|
|
191
|
-
binary: t.binary_fingerprint
|
|
192
|
-
} : void 0;
|
|
193
|
-
C.firstSeen ||= n, !C.firstComponents && r && n === C.firstSeen && (C.firstComponents = r), n !== C.firstSeen && E({
|
|
194
|
-
kind: he(C.firstComponents, r),
|
|
195
|
-
observed: n,
|
|
196
|
-
components: r
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
function he(e, t) {
|
|
200
|
-
if (!e || !t) return "unknown";
|
|
201
|
-
let n = e.schema !== t.schema, r = e.asset !== t.asset, i = e.binary !== t.binary;
|
|
202
|
-
return n && !r && !i ? "schema-only" : r || i ? "asset-or-binary" : "unknown";
|
|
203
|
-
}
|
|
204
|
-
function E(e) {
|
|
205
|
-
if (!C.hasReportedDrift) {
|
|
206
|
-
C.hasReportedDrift = !0;
|
|
207
|
-
for (let t of C.listeners) t(e);
|
|
208
|
-
if (C.channel) try {
|
|
209
|
-
C.channel.postMessage({
|
|
210
|
-
type: "drift",
|
|
211
|
-
delta: e
|
|
212
|
-
});
|
|
213
|
-
} catch {}
|
|
214
|
-
b() && e.kind !== "schema-only" && v(ce(), _.reloadRequired, { reason: `version drift: ${e.kind}` });
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function ge(e) {
|
|
218
|
-
return C.listeners.add(e), () => {
|
|
219
|
-
C.listeners.delete(e);
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/api/client.ts
|
|
224
|
-
var _e = (e) => JSON.stringify(e ?? {}), D = null, O = class extends Error {
|
|
225
|
-
status;
|
|
226
|
-
constructor(e) {
|
|
227
|
-
super(`refresh failed terminally (${e})`), this.status = e, this.name = "RefreshDeadError";
|
|
228
|
-
}
|
|
229
|
-
}, k = null, A = null, j = 3e4, ve = 5e3;
|
|
230
|
-
function M() {
|
|
231
|
-
F().catch((e) => {
|
|
232
|
-
e instanceof O && I();
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
function N(e) {
|
|
236
|
-
if (k &&= (clearTimeout(k), null), A = null, !e || typeof window > "u") return;
|
|
237
|
-
let t = Date.parse(e);
|
|
238
|
-
if (Number.isNaN(t)) return;
|
|
239
|
-
A = t;
|
|
240
|
-
let n = Math.max(t - Date.now() - j, ve);
|
|
241
|
-
k = setTimeout(() => {
|
|
242
|
-
k = null, M();
|
|
243
|
-
}, n);
|
|
244
|
-
}
|
|
245
|
-
function ye() {
|
|
246
|
-
k &&= (clearTimeout(k), null), A = null;
|
|
247
|
-
}
|
|
248
|
-
typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
249
|
-
document.visibilityState === "visible" && A !== null && Date.now() >= A - j && M();
|
|
250
|
-
});
|
|
251
|
-
async function P(e) {
|
|
252
|
-
try {
|
|
253
|
-
let t = await e.json();
|
|
254
|
-
N(t?.result?.expires_at ?? t?.expires_at);
|
|
255
|
-
} catch {}
|
|
256
|
-
}
|
|
257
|
-
async function be() {
|
|
258
|
-
let e = {
|
|
259
|
-
method: "POST",
|
|
260
|
-
credentials: "include",
|
|
261
|
-
headers: { "Content-Type": "application/json" },
|
|
262
|
-
body: _e({})
|
|
263
|
-
}, t = await fetch("/api/actions/auth.refresh", e);
|
|
264
|
-
if (t.status === 429) {
|
|
265
|
-
let n = parseInt(t.headers.get("Retry-After") || "1", 10);
|
|
266
|
-
await new Promise((e) => setTimeout(e, n * 1e3));
|
|
267
|
-
let r = await fetch("/api/actions/auth.refresh", e);
|
|
268
|
-
if (!r.ok) throw new O(r.status);
|
|
269
|
-
await P(r);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (!t.ok) throw new O(t.status);
|
|
273
|
-
await P(t);
|
|
274
|
-
}
|
|
275
|
-
async function F() {
|
|
276
|
-
return D || (D = be().finally(() => {
|
|
277
|
-
D = null;
|
|
278
|
-
}), D);
|
|
279
|
-
}
|
|
280
|
-
var I = () => {
|
|
281
|
-
if (typeof window > "u") return;
|
|
282
|
-
let { pathname: e } = window.location;
|
|
283
|
-
e.startsWith("/login") || e.startsWith("/signup") || e === "/reset" || e === "/forgot" || (window.location.href = re());
|
|
284
|
-
};
|
|
285
|
-
function xe(e) {
|
|
286
|
-
let t = I;
|
|
287
|
-
return I = e, t;
|
|
288
|
-
}
|
|
289
|
-
function L() {
|
|
290
|
-
return I;
|
|
291
|
-
}
|
|
292
|
-
var Se = ({ status: e, code: t, message: n }) => {
|
|
293
|
-
console.error(`[API ${e}] ${t}: ${n}`);
|
|
294
|
-
};
|
|
295
|
-
function R(e, t, n, r) {
|
|
296
|
-
let i = new Headers(e);
|
|
297
|
-
return !i.has("Content-Type") && t && i.set("Content-Type", "application/json"), n.setAccept && !i.has("Accept") && i.set("Accept", "*/*"), r && i.set("Authorization", `Bearer ${r}`), i;
|
|
298
|
-
}
|
|
299
|
-
async function z(e, t, n, r) {
|
|
300
|
-
let i = b(), a = i ? "omit" : "include", o = R(t.headers, !!t.body, n, i ? se() : null), s = await fetch(e, {
|
|
301
|
-
...t,
|
|
302
|
-
headers: o,
|
|
303
|
-
credentials: a
|
|
304
|
-
});
|
|
305
|
-
if (me(s.headers), !s.ok) {
|
|
306
|
-
let o = "Request failed", l = "UNKNOWN", u, d;
|
|
307
|
-
try {
|
|
308
|
-
d = await s.json();
|
|
309
|
-
let e = d;
|
|
310
|
-
e && e.error && (o = e.error.message, l = e.error.code, e.index != null && (u = e.index));
|
|
311
|
-
} catch {}
|
|
312
|
-
if (s.status === 401 && (l === "TOKEN_REFRESH_NEEDED" || l === "UNAUTHORIZED")) try {
|
|
313
|
-
let o = null;
|
|
314
|
-
i ? (x(), o = await S()) : await F();
|
|
315
|
-
let s = R(t.headers, !!t.body, n, o), l = await fetch(e, {
|
|
316
|
-
...t,
|
|
317
|
-
headers: s,
|
|
318
|
-
credentials: a
|
|
319
|
-
});
|
|
320
|
-
if (!l.ok) {
|
|
321
|
-
I();
|
|
322
|
-
let e = await l.json().catch(() => ({ error: {
|
|
323
|
-
message: "Request failed",
|
|
324
|
-
code: "UNKNOWN"
|
|
325
|
-
} }));
|
|
326
|
-
throw new c(l.status, e.error.message, e.error.code, e.index);
|
|
327
|
-
}
|
|
328
|
-
return r(l);
|
|
329
|
-
} catch (e) {
|
|
330
|
-
throw e instanceof c ? e : (I(), new c(401, o, l, u));
|
|
331
|
-
}
|
|
332
|
-
throw s.status === 401 && I(), Se({
|
|
333
|
-
status: s.status,
|
|
334
|
-
code: l,
|
|
335
|
-
message: o
|
|
336
|
-
}), new c(s.status, o, l, u, d);
|
|
337
|
-
}
|
|
338
|
-
return r(s);
|
|
339
|
-
}
|
|
340
|
-
function Ce(e) {
|
|
341
|
-
return e.status === 204 ? Promise.resolve(void 0) : e.json();
|
|
342
|
-
}
|
|
343
|
-
async function B(e, t = {}) {
|
|
344
|
-
return z(e, t, { setAccept: !1 }, Ce);
|
|
345
|
-
}
|
|
346
|
-
async function we(e) {
|
|
347
|
-
return {
|
|
348
|
-
blob: await e.blob(),
|
|
349
|
-
filename: Ee(e.headers),
|
|
350
|
-
headers: e.headers
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
async function Te(e, t = {}) {
|
|
354
|
-
return z(e, t, { setAccept: !0 }, we);
|
|
355
|
-
}
|
|
356
|
-
function Ee(e) {
|
|
357
|
-
let t = e.get("Content-Disposition");
|
|
358
|
-
if (!t) return "";
|
|
359
|
-
let n = t.match(/filename\*\s*=\s*([^']*)'([^']*)'([^;]+)/i);
|
|
360
|
-
if (n) try {
|
|
361
|
-
return decodeURIComponent(n[3].trim());
|
|
362
|
-
} catch {}
|
|
363
|
-
let r = t.match(/filename\s*=\s*("([^"]+)"|([^;]+))/i);
|
|
364
|
-
return r ? (r[2] ?? r[3] ?? "").trim() : "";
|
|
365
|
-
}
|
|
366
|
-
async function V(e, t = {}) {
|
|
367
|
-
return (await B(`/api/actions/${encodeURIComponent(e)}`, {
|
|
368
|
-
method: "POST",
|
|
369
|
-
body: _e(t)
|
|
370
|
-
})).result;
|
|
371
|
-
}
|
|
372
|
-
//#endregion
|
|
373
|
-
//#region src/embed/file-src.ts
|
|
374
|
-
var H = "/api/files";
|
|
375
|
-
function De(e) {
|
|
376
|
-
if (typeof e != "object" || !e) return !1;
|
|
377
|
-
let t = e;
|
|
378
|
-
return typeof t.url == "string" && typeof t.proxy == "boolean";
|
|
379
|
-
}
|
|
380
|
-
function Oe(e, t) {
|
|
381
|
-
let n = encodeURIComponent(e);
|
|
382
|
-
return typeof t == "object" ? `${H}/${n}/derived/${encodeURIComponent(t.derivation)}/url` : `${H}/${n}/url`;
|
|
383
|
-
}
|
|
384
|
-
var U = class extends Error {
|
|
385
|
-
fileId;
|
|
386
|
-
key;
|
|
387
|
-
constructor(e, t) {
|
|
388
|
-
super(`derivation "${t}" of file ${e} is still generating`), this.fileId = e, this.key = t, this.name = "DerivationPendingError";
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
function W(e, t) {
|
|
392
|
-
return {
|
|
393
|
-
method: "GET",
|
|
394
|
-
credentials: "omit",
|
|
395
|
-
headers: { Authorization: `Bearer ${e}` },
|
|
396
|
-
signal: t
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
function ke(e) {
|
|
400
|
-
return `${e}${e.includes("?") ? "&" : "?"}disposition=attachment`;
|
|
401
|
-
}
|
|
402
|
-
async function G(e, t) {
|
|
403
|
-
let n = await S(), r = await fetch(e, W(n, t));
|
|
404
|
-
if (r.status !== 401) return r;
|
|
405
|
-
x();
|
|
406
|
-
let i = await S();
|
|
407
|
-
return fetch(e, W(i, t));
|
|
408
|
-
}
|
|
409
|
-
async function K(e, t, n) {
|
|
410
|
-
if (!b()) throw Error("resolveEmbedFileSrc called outside embed token mode");
|
|
411
|
-
let r = await G(Oe(e, t), n);
|
|
412
|
-
if (r.status === 202 && typeof t == "object") throw new U(e, t.derivation);
|
|
413
|
-
if (!r.ok) throw Error(`embed file url request failed: ${r.status} ${r.statusText}`);
|
|
414
|
-
let i = await r.json();
|
|
415
|
-
if (!De(i)) throw Error("embed file url response is malformed");
|
|
416
|
-
if (!i.proxy) return {
|
|
417
|
-
url: i.url,
|
|
418
|
-
kind: "direct"
|
|
419
|
-
};
|
|
420
|
-
if (!i.url.startsWith("/api/files/")) throw Error(`embed file proxy: refusing non-files-route URL ${JSON.stringify(i.url)}`);
|
|
421
|
-
let a = await G(t === "download" ? ke(i.url) : i.url, n);
|
|
422
|
-
if (!a.ok) throw Error(`embed file proxy fetch failed: ${a.status} ${a.statusText}`);
|
|
423
|
-
let o = await a.blob();
|
|
424
|
-
return {
|
|
425
|
-
url: URL.createObjectURL(o),
|
|
426
|
-
kind: "blob"
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
//#endregion
|
|
430
|
-
//#region src/components/file-widgets/upload.ts
|
|
431
|
-
var q = class extends Error {
|
|
432
|
-
code;
|
|
433
|
-
status;
|
|
434
|
-
constructor(e, t, n) {
|
|
435
|
-
super(n), this.code = t, this.status = e;
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
async function Ae(e) {
|
|
439
|
-
let t = b();
|
|
440
|
-
try {
|
|
441
|
-
return await J(e, t ? await S() : null);
|
|
442
|
-
} catch (n) {
|
|
443
|
-
if (!(n instanceof q && n.status === 401 && (n.code === "TOKEN_REFRESH_NEEDED" || n.code === "UNAUTHORIZED"))) throw n;
|
|
444
|
-
let r = null;
|
|
445
|
-
try {
|
|
446
|
-
t ? (x(), r = await S()) : await F();
|
|
447
|
-
} catch {
|
|
448
|
-
throw L()(), n;
|
|
449
|
-
}
|
|
450
|
-
try {
|
|
451
|
-
return await J(e, r);
|
|
452
|
-
} catch (e) {
|
|
453
|
-
throw e instanceof q && e.status === 401 && L()(), e;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
function J(e, t) {
|
|
458
|
-
let { file: n, entityCode: r, fieldCode: i, slotCode: a, onProgress: o, signal: s } = e;
|
|
459
|
-
return new Promise((e, c) => {
|
|
460
|
-
let l = new XMLHttpRequest();
|
|
461
|
-
if (l.open("POST", je(r, i, a)), l.withCredentials = t === null, t && l.setRequestHeader("Authorization", `Bearer ${t}`), l.upload.onprogress = (e) => {
|
|
462
|
-
if (!o) return;
|
|
463
|
-
let t = e.lengthComputable ? e.total : n.size, r = t > 0 ? Math.min(100, Math.round(e.loaded / t * 100)) : 0;
|
|
464
|
-
o({
|
|
465
|
-
loaded: e.loaded,
|
|
466
|
-
total: t,
|
|
467
|
-
pct: r
|
|
468
|
-
});
|
|
469
|
-
}, l.onload = () => {
|
|
470
|
-
let t = l.responseText || "", n = null;
|
|
471
|
-
try {
|
|
472
|
-
n = t ? JSON.parse(t) : null;
|
|
473
|
-
} catch {}
|
|
474
|
-
if (l.status >= 200 && l.status < 300) {
|
|
475
|
-
let t = Y(n);
|
|
476
|
-
if (!t || !t.id) {
|
|
477
|
-
c(new q(l.status, "BAD_RESPONSE", "Upload returned no file id"));
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
e(t);
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
let r = n, i = r?.error?.code ?? "UPLOAD_FAILED", a = r?.error?.message ?? `Upload failed (${l.status})`;
|
|
484
|
-
c(new q(l.status, i, a));
|
|
485
|
-
}, l.onerror = () => {
|
|
486
|
-
c(new q(0, "NETWORK_ERROR", "Network error during upload"));
|
|
487
|
-
}, l.onabort = () => {
|
|
488
|
-
c(new q(0, "ABORTED", "Upload aborted"));
|
|
489
|
-
}, s) {
|
|
490
|
-
if (s.aborted) {
|
|
491
|
-
l.abort(), c(new q(0, "ABORTED", "Upload aborted"));
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
s.addEventListener("abort", () => l.abort(), { once: !0 });
|
|
495
|
-
}
|
|
496
|
-
let u = new FormData();
|
|
497
|
-
u.append("file", n, n.name), l.send(u);
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
function je(e, t, n) {
|
|
501
|
-
let r = new URLSearchParams();
|
|
502
|
-
e && t && (r.set("entity_code", e), r.set("field_code", t), n && r.set("slot_code", n));
|
|
503
|
-
let i = r.toString();
|
|
504
|
-
return i ? `/api/files/upload?${i}` : "/api/files/upload";
|
|
505
|
-
}
|
|
506
|
-
function Y(e) {
|
|
507
|
-
return X(e) ? X(e.result) ? Y(e.result) : X(e.file) ? Me(e.file) : typeof e.id == "string" ? e : null : null;
|
|
508
|
-
}
|
|
509
|
-
function Me(e) {
|
|
510
|
-
let t = Z(e.file_id);
|
|
511
|
-
return t ? {
|
|
512
|
-
id: t,
|
|
513
|
-
filename: Z(e.filename_original) ?? Z(e.filename_normalized) ?? t,
|
|
514
|
-
content_type: Z(e.content_type) ?? "application/octet-stream",
|
|
515
|
-
size_bytes: Ne(e.size_bytes) ?? 0,
|
|
516
|
-
sha256: Z(e.sha256) ?? "",
|
|
517
|
-
dedup: Pe(e.dedup)
|
|
518
|
-
} : null;
|
|
519
|
-
}
|
|
520
|
-
function X(e) {
|
|
521
|
-
return typeof e == "object" && !!e;
|
|
522
|
-
}
|
|
523
|
-
function Z(e) {
|
|
524
|
-
return typeof e == "string" ? e : void 0;
|
|
525
|
-
}
|
|
526
|
-
function Ne(e) {
|
|
527
|
-
return typeof e == "number" ? e : void 0;
|
|
528
|
-
}
|
|
529
|
-
function Pe(e) {
|
|
530
|
-
return typeof e == "boolean" ? e : void 0;
|
|
531
|
-
}
|
|
532
|
-
async function Fe(e) {
|
|
533
|
-
await V("files.discard", { file_id: e });
|
|
534
|
-
}
|
|
535
|
-
function Ie(e, t, n) {
|
|
536
|
-
if (n && e.size > n) return {
|
|
537
|
-
code: "FILE_TOO_LARGE",
|
|
538
|
-
message: `File is ${Q(e.size)}, max ${Q(n)}`
|
|
539
|
-
};
|
|
540
|
-
if (t && t.length > 0) {
|
|
541
|
-
let n = e.type || "application/octet-stream";
|
|
542
|
-
if (!t.some((e) => Le(e, n))) return {
|
|
543
|
-
code: "MIME_NOT_ACCEPTED",
|
|
544
|
-
message: `File type ${n} is not accepted`
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
return null;
|
|
548
|
-
}
|
|
549
|
-
function Le(e, t) {
|
|
550
|
-
if (e === "*/*" || e === "*") return !0;
|
|
551
|
-
if (e.endsWith("/*")) {
|
|
552
|
-
let n = e.slice(0, e.length - 1);
|
|
553
|
-
return t.startsWith(n);
|
|
554
|
-
}
|
|
555
|
-
return e === t;
|
|
556
|
-
}
|
|
557
|
-
function Q(e) {
|
|
558
|
-
if (e < 1024) return `${e} B`;
|
|
559
|
-
let t = [
|
|
560
|
-
"KB",
|
|
561
|
-
"MB",
|
|
562
|
-
"GB"
|
|
563
|
-
], n = e / 1024, r = 0;
|
|
564
|
-
for (; n >= 1024 && r < t.length - 1;) n /= 1024, r++;
|
|
565
|
-
return `${n.toFixed(n >= 10 ? 0 : 1)} ${t[r]}`;
|
|
566
|
-
}
|
|
567
|
-
//#endregion
|
|
568
|
-
//#region src/components/file-widgets/helpers.ts
|
|
569
|
-
var Re = ["thumb_200", "thumb_300"];
|
|
570
|
-
function ze() {
|
|
571
|
-
return typeof navigator > "u" ? ["en"] : (navigator.languages?.length ? navigator.languages : [navigator.language]).filter((e) => typeof e == "string" && e.length > 0);
|
|
572
|
-
}
|
|
573
|
-
function Be(e, t) {
|
|
574
|
-
for (let n of t) {
|
|
575
|
-
if (e[n]) return e[n];
|
|
576
|
-
let t = n.split("-")[0];
|
|
577
|
-
if (t && e[t]) return e[t];
|
|
578
|
-
}
|
|
579
|
-
for (let t of Object.values(e)) if (typeof t == "string" && t.length > 0) return t;
|
|
580
|
-
}
|
|
581
|
-
function Ve(e, t, n) {
|
|
582
|
-
if (t) return t;
|
|
583
|
-
let r = e?.metadata?.alt_text;
|
|
584
|
-
if (typeof r == "string" && r.length > 0) return r;
|
|
585
|
-
if (r && typeof r == "object" && !Array.isArray(r)) {
|
|
586
|
-
let e = Be(Object.fromEntries(Object.entries(r).filter((e) => e[0].length > 0 && typeof e[1] == "string")), ze());
|
|
587
|
-
if (e) return e;
|
|
588
|
-
}
|
|
589
|
-
return n;
|
|
590
|
-
}
|
|
591
|
-
var He = new Set([
|
|
592
|
-
"image/png",
|
|
593
|
-
"image/jpeg",
|
|
594
|
-
"image/webp",
|
|
595
|
-
"image/gif",
|
|
596
|
-
"image/avif",
|
|
597
|
-
"application/pdf"
|
|
598
|
-
]);
|
|
599
|
-
function Ue(e) {
|
|
600
|
-
let t = e.content_type?.toLowerCase().split(";")[0]?.trim() ?? "";
|
|
601
|
-
return He.has(t);
|
|
602
|
-
}
|
|
603
|
-
function We(e) {
|
|
604
|
-
return e.url ?? e.presigned_url;
|
|
605
|
-
}
|
|
606
|
-
function Ge(e) {
|
|
607
|
-
return e.url ? Je(e.url, "attachment") : e.presigned_url;
|
|
608
|
-
}
|
|
609
|
-
function Ke(e, t) {
|
|
610
|
-
if (!e) return;
|
|
611
|
-
let n = e.derivations ?? {};
|
|
612
|
-
if (t && n[t]) return n[t];
|
|
613
|
-
for (let e of Re) if (n[e]) return n[e];
|
|
614
|
-
return e.url ?? e.presigned_url;
|
|
615
|
-
}
|
|
616
|
-
function qe(e, t) {
|
|
617
|
-
let n = e?.derivations ?? {};
|
|
618
|
-
if (t && n[t]) return { derivation: t };
|
|
619
|
-
for (let e of Re) if (n[e]) return { derivation: e };
|
|
620
|
-
return "preview";
|
|
621
|
-
}
|
|
622
|
-
function Je(e, t) {
|
|
623
|
-
try {
|
|
624
|
-
let n = new URL(e, typeof window < "u" ? window.location.origin : "http://localhost");
|
|
625
|
-
return n.searchParams.set("disposition", t), /^https?:\/\//i.test(e) ? n.toString() : `${n.pathname}${n.search}${n.hash}`;
|
|
626
|
-
} catch {
|
|
627
|
-
return `${e}${e.includes("?") ? "&" : "?"}disposition=${t}`;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
function Ye(e) {
|
|
631
|
-
let t = e?.metadata?.focal_point;
|
|
632
|
-
if (!t || typeof t != "object" || Array.isArray(t)) return null;
|
|
633
|
-
let n = t, r = typeof n.x == "number" ? n.x : NaN, i = typeof n.y == "number" ? n.y : NaN;
|
|
634
|
-
return !Number.isFinite(r) || !Number.isFinite(i) || r < 0 || r > 1 || i < 0 || i > 1 ? null : {
|
|
635
|
-
x: r,
|
|
636
|
-
y: i
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
function Xe(e) {
|
|
640
|
-
if (e) return `${e.x * 100}% ${e.y * 100}%`;
|
|
641
|
-
}
|
|
642
|
-
function Ze(e, t) {
|
|
643
|
-
return {
|
|
644
|
-
...e,
|
|
645
|
-
metadata: {
|
|
646
|
-
...e.metadata ?? {},
|
|
647
|
-
focal_point: t
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
//#endregion
|
|
652
|
-
//#region src/components/file-widgets/draft-scope.tsx
|
|
653
|
-
var Qe = e({
|
|
654
|
-
registerDraft() {},
|
|
655
|
-
unregisterDraft() {},
|
|
656
|
-
hasDraft() {
|
|
657
|
-
return !1;
|
|
658
|
-
},
|
|
659
|
-
flushAllDrafts: async () => {},
|
|
660
|
-
markCommitted() {}
|
|
661
|
-
});
|
|
662
|
-
function $e({ children: e }) {
|
|
663
|
-
let t = a(/* @__PURE__ */ new Map()), n = i(() => ({
|
|
664
|
-
registerDraft(e) {
|
|
665
|
-
t.current.set(e.fileId, e);
|
|
666
|
-
},
|
|
667
|
-
unregisterDraft(e) {
|
|
668
|
-
t.current.delete(e);
|
|
669
|
-
},
|
|
670
|
-
hasDraft(e) {
|
|
671
|
-
return t.current.has(e);
|
|
672
|
-
},
|
|
673
|
-
markCommitted(e) {
|
|
674
|
-
t.current.delete(e);
|
|
675
|
-
},
|
|
676
|
-
async flushAllDrafts() {
|
|
677
|
-
let e = Array.from(t.current.values());
|
|
678
|
-
t.current.clear(), await Promise.allSettled(e.map((e) => Promise.resolve(e.discard())));
|
|
679
|
-
}
|
|
680
|
-
}), []);
|
|
681
|
-
return /* @__PURE__ */ s(Qe.Provider, {
|
|
682
|
-
value: n,
|
|
683
|
-
children: e
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
function et() {
|
|
687
|
-
return n(Qe);
|
|
688
|
-
}
|
|
689
|
-
function tt() {
|
|
690
|
-
let e = et();
|
|
691
|
-
return {
|
|
692
|
-
register: t((t, n) => {
|
|
693
|
-
e.registerDraft({
|
|
694
|
-
fileId: t,
|
|
695
|
-
discard: n
|
|
696
|
-
});
|
|
697
|
-
}, [e]),
|
|
698
|
-
unregister: t((t) => {
|
|
699
|
-
e.unregisterDraft(t);
|
|
700
|
-
}, [e]),
|
|
701
|
-
markCommitted: t((t) => {
|
|
702
|
-
e.markCommitted(t);
|
|
703
|
-
}, [e]),
|
|
704
|
-
isDraft: t((t) => e.hasDraft(t), [e])
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
//#endregion
|
|
708
|
-
//#region src/components/file-widgets/useEmbedFileSrc.ts
|
|
709
|
-
function nt(e) {
|
|
710
|
-
return typeof e == "object" ? `derivation:${e.derivation}` : e;
|
|
711
|
-
}
|
|
712
|
-
function rt(e) {
|
|
713
|
-
return e.startsWith("derivation:") ? { derivation: e.slice(11) } : e === "download" ? "download" : "preview";
|
|
714
|
-
}
|
|
715
|
-
function it(e, t, n) {
|
|
716
|
-
let i = nt(t), [a, s] = o(() => b() ? void 0 : n);
|
|
717
|
-
return r(() => {
|
|
718
|
-
b() || s(n);
|
|
719
|
-
}, [n]), r(() => {
|
|
720
|
-
if (!b()) return;
|
|
721
|
-
if (!e) {
|
|
722
|
-
s(void 0);
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
let t = null, n = !1, r = new AbortController();
|
|
726
|
-
return s(void 0), K(e, rt(i), r.signal).then((e) => {
|
|
727
|
-
if (n) {
|
|
728
|
-
e.kind === "blob" && URL.revokeObjectURL(e.url);
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
e.kind === "blob" && (t = e.url), s(e.url);
|
|
732
|
-
}).catch((e) => {
|
|
733
|
-
if (!n) {
|
|
734
|
-
if (e instanceof U) {
|
|
735
|
-
s(void 0);
|
|
736
|
-
return;
|
|
737
|
-
}
|
|
738
|
-
e instanceof DOMException && e.name === "AbortError" || (console.error("[declarion-embed] file src resolution failed:", e), s(void 0));
|
|
739
|
-
}
|
|
740
|
-
}), () => {
|
|
741
|
-
n = !0, r.abort(), t && URL.revokeObjectURL(t);
|
|
742
|
-
};
|
|
743
|
-
}, [e, i]), a;
|
|
744
|
-
}
|
|
745
|
-
function at() {
|
|
746
|
-
let e = a([]);
|
|
747
|
-
return r(() => () => {
|
|
748
|
-
for (let t of e.current) URL.revokeObjectURL(t);
|
|
749
|
-
e.current = [];
|
|
750
|
-
}, []), { open: t((t, n, r) => {
|
|
751
|
-
if (!b()) {
|
|
752
|
-
r && window.open(r, "_blank", "noopener");
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
t && K(t, n).then((t) => {
|
|
756
|
-
t.kind === "blob" && e.current.push(t.url), window.open(t.url, "_blank", "noopener");
|
|
757
|
-
}).catch((e) => {
|
|
758
|
-
e instanceof U || console.error("[declarion-embed] file open failed:", e);
|
|
759
|
-
});
|
|
760
|
-
}, []) };
|
|
761
|
-
}
|
|
762
|
-
//#endregion
|
|
763
|
-
//#region src/components/file-widgets/value.ts
|
|
764
|
-
function $(e) {
|
|
765
|
-
return typeof e == "object" && !!e && typeof e.id == "string";
|
|
766
|
-
}
|
|
767
|
-
function ot(e) {
|
|
768
|
-
return e ? Array.isArray(e) ? e.find($) ?? null : $(e) ? e : null : null;
|
|
769
|
-
}
|
|
770
|
-
function st(e) {
|
|
771
|
-
return e ? Array.isArray(e) ? e.filter($) : $(e) ? [e] : [] : [];
|
|
772
|
-
}
|
|
773
|
-
//#endregion
|
|
774
|
-
export { xe as A, _ as B, B as C, F as D, ye as E, se as F, u as G, ne as H, oe as I, l as K, b as L, ge as M, S as N, L as O, x as P, ue as R, O as S, V as T, te as U, v as V, c as W, q as _, $e as a, Ae as b, Ue as c, Ke as d, qe as f, Ze as g, Ve as h, it as i, T as j, N as k, Ge as l, Ye as m, ot as n, tt as o, We as p, d as q, at as r, et as s, st as t, Xe as u, Fe as v, Te as w, Ie as x, Q as y, g as z };
|