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