@declarion/react 0.1.85 → 0.1.88

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.
@@ -10,11 +10,11 @@ var o = class extends Error {
10
10
  super(t), this.name = "ApiError", this.status = e, this.code = n, this.index = r, this.raw = i;
11
11
  }
12
12
  }, s = "/", c = "/login", l = "/signup", u = "https://declarion.local";
13
- function d(e) {
13
+ function ee(e) {
14
14
  let t = e.split(/[?#]/, 1)[0];
15
15
  return t === c || t.startsWith(`${c}/`) || t === l || t.startsWith(`${l}/`);
16
16
  }
17
- function f(e) {
17
+ function d(e) {
18
18
  if (!e) return s;
19
19
  let t = e.toLowerCase();
20
20
  if (!e.startsWith("/") || e.startsWith("//") || e.includes("\\") || t.includes("%5c")) return s;
@@ -27,22 +27,22 @@ function f(e) {
27
27
  return s;
28
28
  }
29
29
  }
30
- function p(e) {
31
- let t = f(e);
32
- return t === s || d(t) ? c : `${c}?next=${encodeURIComponent(t)}`;
30
+ function f(e) {
31
+ let t = d(e);
32
+ return t === s || ee(t) ? c : `${c}?next=${encodeURIComponent(t)}`;
33
33
  }
34
- function m() {
34
+ function p() {
35
35
  if (typeof window > "u") return c;
36
36
  let { pathname: e, search: t, hash: n } = window.location;
37
- return p(`${e}${t}${n}`);
37
+ return f(`${e}${t}${n}`);
38
38
  }
39
39
  //#endregion
40
40
  //#region src/lib/versionTracker.ts
41
- var h = "X-Declarion-Version", ee = "declarion-version";
41
+ var m = "X-Declarion-Version", h = "declarion-version";
42
42
  function g() {
43
43
  if (typeof BroadcastChannel > "u") return null;
44
44
  try {
45
- return new BroadcastChannel(ee);
45
+ return new BroadcastChannel(h);
46
46
  } catch {
47
47
  return null;
48
48
  }
@@ -65,14 +65,14 @@ function v() {
65
65
  }
66
66
  function y(e) {
67
67
  if (v(), !e) return;
68
- let t = e.get(h);
68
+ let t = e.get(m);
69
69
  if (t) {
70
70
  if (!_.firstSeen) {
71
71
  _.firstSeen = t;
72
72
  return;
73
73
  }
74
74
  t !== _.firstSeen && (_.hasReportedDrift || b().catch(() => {
75
- x({
75
+ S({
76
76
  kind: "unknown",
77
77
  observed: t
78
78
  });
@@ -107,18 +107,18 @@ async function b() {
107
107
  asset: t.asset_fingerprint,
108
108
  binary: t.binary_fingerprint
109
109
  } : void 0;
110
- _.firstSeen ||= n, !_.firstComponents && r && n === _.firstSeen && (_.firstComponents = r), n !== _.firstSeen && x({
111
- kind: te(_.firstComponents, r),
110
+ _.firstSeen ||= n, !_.firstComponents && r && n === _.firstSeen && (_.firstComponents = r), n !== _.firstSeen && S({
111
+ kind: x(_.firstComponents, r),
112
112
  observed: n,
113
113
  components: r
114
114
  });
115
115
  }
116
- function te(e, t) {
116
+ function x(e, t) {
117
117
  if (!e || !t) return "unknown";
118
118
  let n = e.schema !== t.schema, r = e.asset !== t.asset, i = e.binary !== t.binary;
119
119
  return n && !r && !i ? "schema-only" : r || i ? "asset-or-binary" : "unknown";
120
120
  }
121
- function x(e) {
121
+ function S(e) {
122
122
  if (!_.hasReportedDrift) {
123
123
  _.hasReportedDrift = !0;
124
124
  for (let t of _.listeners) t(e);
@@ -130,83 +130,77 @@ function x(e) {
130
130
  } catch {}
131
131
  }
132
132
  }
133
- function ne(e) {
133
+ function C(e) {
134
134
  return _.listeners.add(e), () => {
135
135
  _.listeners.delete(e);
136
136
  };
137
137
  }
138
138
  //#endregion
139
139
  //#region src/api/client.ts
140
- var S = (e) => JSON.stringify(e ?? {}), C = null, w = class extends Error {
140
+ var w = (e) => JSON.stringify(e ?? {}), T = null, E = class extends Error {
141
+ status;
141
142
  constructor(e) {
142
143
  super(`refresh failed terminally (${e})`), this.status = e, this.name = "RefreshDeadError";
143
144
  }
144
145
  };
145
- async function T() {
146
+ async function te() {
146
147
  let e = {
147
148
  method: "POST",
148
149
  credentials: "include",
149
150
  headers: { "Content-Type": "application/json" },
150
- body: S({})
151
+ body: w({})
151
152
  }, t = await fetch("/api/actions/auth.refresh", e);
152
153
  if (t.status === 429) {
153
154
  let n = parseInt(t.headers.get("Retry-After") || "1", 10);
154
155
  await new Promise((e) => setTimeout(e, n * 1e3));
155
156
  let r = await fetch("/api/actions/auth.refresh", e);
156
- if (!r.ok) throw new w(r.status);
157
+ if (!r.ok) throw new E(r.status);
157
158
  return;
158
159
  }
159
- if (!t.ok) throw new w(t.status);
160
+ if (!t.ok) throw new E(t.status);
160
161
  }
161
- async function E() {
162
- return C || (C = T().finally(() => {
163
- C = null;
164
- }), C);
162
+ async function D() {
163
+ return T || (T = te().finally(() => {
164
+ T = null;
165
+ }), T);
165
166
  }
166
- var D = () => {
167
+ var O = () => {
167
168
  if (typeof window > "u") return;
168
169
  let { pathname: e } = window.location;
169
- e.startsWith("/login") || e.startsWith("/signup") || e === "/reset" || e === "/forgot" || (window.location.href = m());
170
+ e.startsWith("/login") || e.startsWith("/signup") || e === "/reset" || e === "/forgot" || (window.location.href = p());
170
171
  };
171
- function O() {
172
- return D;
172
+ function k() {
173
+ return O;
173
174
  }
174
- var re = ({ status: e, code: t, message: n }) => {
175
+ var A = ({ status: e, code: t, message: n }) => {
175
176
  console.error(`[API ${e}] ${t}: ${n}`);
176
- }, k = 3e4;
177
- function A(e, t, n) {
177
+ };
178
+ function j(e, t, n) {
178
179
  let r = new Headers(e);
179
180
  return !r.has("Content-Type") && t && r.set("Content-Type", "application/json"), n.setAccept && !r.has("Accept") && r.set("Accept", "*/*"), r;
180
181
  }
181
- async function j(e, t, n, r) {
182
- let i = A(t.headers, !!t.body, n), a = AbortSignal.timeout(k), s = t.signal ? AbortSignal.any([t.signal, a]) : a, c;
183
- try {
184
- c = await fetch(e, {
185
- ...t,
186
- headers: i,
187
- credentials: "include",
188
- signal: s
189
- });
190
- } catch (t) {
191
- throw t instanceof DOMException && t.name === "TimeoutError" ? new o(0, `Request to ${e} timed out after ${k / 1e3}s. If you have many tabs open to the dev server, the HTTP/1.1 6-connection cap may be queueing requests in the browser. See docs/gotchas.md.`, "REQUEST_TIMEOUT") : t;
192
- }
193
- if (y(c.headers), !c.ok) {
194
- let i = "Request failed", a = "UNKNOWN", l, u;
182
+ async function M(e, t, n, r) {
183
+ let i = j(t.headers, !!t.body, n), a = await fetch(e, {
184
+ ...t,
185
+ headers: i,
186
+ credentials: "include"
187
+ });
188
+ if (y(a.headers), !a.ok) {
189
+ let i = "Request failed", s = "UNKNOWN", c, l;
195
190
  try {
196
- u = await c.json();
197
- let e = u;
198
- e && e.error && (i = e.error.message, a = e.error.code, e.index != null && (l = e.index));
191
+ l = await a.json();
192
+ let e = l;
193
+ e && e.error && (i = e.error.message, s = e.error.code, e.index != null && (c = e.index));
199
194
  } catch {}
200
- if (c.status === 401 && (a === "TOKEN_REFRESH_NEEDED" || a === "UNAUTHORIZED")) try {
201
- await E();
202
- let i = A(t.headers, !!t.body, n), a = await fetch(e, {
195
+ if (a.status === 401 && (s === "TOKEN_REFRESH_NEEDED" || s === "UNAUTHORIZED")) try {
196
+ await D();
197
+ let i = j(t.headers, !!t.body, n), a = await fetch(e, {
203
198
  ...t,
204
199
  headers: i,
205
- credentials: "include",
206
- signal: s
200
+ credentials: "include"
207
201
  });
208
202
  if (!a.ok) {
209
- D();
203
+ O();
210
204
  let e = await a.json().catch(() => ({ error: {
211
205
  message: "Request failed",
212
206
  code: "UNKNOWN"
@@ -215,21 +209,21 @@ async function j(e, t, n, r) {
215
209
  }
216
210
  return r(a);
217
211
  } catch (e) {
218
- throw e instanceof o ? e : (D(), new o(401, i, a, l));
212
+ throw e instanceof o ? e : (O(), new o(401, i, s, c));
219
213
  }
220
- throw c.status === 401 && D(), re({
221
- status: c.status,
222
- code: a,
214
+ throw a.status === 401 && O(), A({
215
+ status: a.status,
216
+ code: s,
223
217
  message: i
224
- }), new o(c.status, i, a, l, u);
218
+ }), new o(a.status, i, s, c, l);
225
219
  }
226
- return r(c);
220
+ return r(a);
227
221
  }
228
- function M(e) {
222
+ function ne(e) {
229
223
  return e.status === 204 ? Promise.resolve(void 0) : e.json();
230
224
  }
231
225
  async function N(e, t = {}) {
232
- return j(e, t, { setAccept: !1 }, M);
226
+ return M(e, t, { setAccept: !1 }, ne);
233
227
  }
234
228
  async function P(e) {
235
229
  return {
@@ -239,7 +233,7 @@ async function P(e) {
239
233
  };
240
234
  }
241
235
  async function F(e, t = {}) {
242
- return j(e, t, { setAccept: !0 }, P);
236
+ return M(e, t, { setAccept: !0 }, P);
243
237
  }
244
238
  function I(e) {
245
239
  let t = e.get("Content-Disposition");
@@ -254,7 +248,7 @@ function I(e) {
254
248
  async function L(e, t = {}) {
255
249
  return (await N(`/api/actions/${encodeURIComponent(e)}`, {
256
250
  method: "POST",
257
- body: S(t)
251
+ body: w(t)
258
252
  })).result;
259
253
  }
260
254
  //#endregion
@@ -266,11 +260,28 @@ var R = class extends Error {
266
260
  super(n), this.code = t, this.status = e;
267
261
  }
268
262
  };
269
- function z(e) {
263
+ async function z(e) {
264
+ try {
265
+ return await B(e);
266
+ } catch (t) {
267
+ if (!(t instanceof R && t.status === 401 && (t.code === "TOKEN_REFRESH_NEEDED" || t.code === "UNAUTHORIZED"))) throw t;
268
+ try {
269
+ await D();
270
+ } catch {
271
+ throw k()(), t;
272
+ }
273
+ try {
274
+ return await B(e);
275
+ } catch (e) {
276
+ throw e instanceof R && e.status === 401 && k()(), e;
277
+ }
278
+ }
279
+ }
280
+ function B(e) {
270
281
  let { file: t, entityCode: n, fieldCode: r, slotCode: i, onProgress: a, signal: o } = e;
271
282
  return new Promise((e, s) => {
272
283
  let c = new XMLHttpRequest();
273
- if (c.open("POST", B(n, r, i)), c.withCredentials = !0, c.upload.onprogress = (e) => {
284
+ if (c.open("POST", V(n, r, i)), c.withCredentials = !0, c.upload.onprogress = (e) => {
274
285
  if (!a) return;
275
286
  let n = e.lengthComputable ? e.total : t.size, r = n > 0 ? Math.min(100, Math.round(e.loaded / n * 100)) : 0;
276
287
  a({
@@ -284,7 +295,7 @@ function z(e) {
284
295
  n = t ? JSON.parse(t) : null;
285
296
  } catch {}
286
297
  if (c.status >= 200 && c.status < 300) {
287
- let t = V(n);
298
+ let t = H(n);
288
299
  if (!t || !t.id) {
289
300
  s(new R(c.status, "BAD_RESPONSE", "Upload returned no file id"));
290
301
  return;
@@ -309,56 +320,56 @@ function z(e) {
309
320
  l.append("file", t, t.name), c.send(l);
310
321
  });
311
322
  }
312
- function B(e, t, n) {
323
+ function V(e, t, n) {
313
324
  let r = new URLSearchParams();
314
325
  e && t && (r.set("entity_code", e), r.set("field_code", t), n && r.set("slot_code", n));
315
326
  let i = r.toString();
316
327
  return i ? `/api/files/upload?${i}` : "/api/files/upload";
317
328
  }
318
- function V(e) {
319
- return U(e) ? U(e.result) ? V(e.result) : U(e.file) ? H(e.file) : typeof e.id == "string" ? e : null : null;
320
- }
321
329
  function H(e) {
322
- let t = W(e.file_id);
330
+ return W(e) ? W(e.result) ? H(e.result) : W(e.file) ? U(e.file) : typeof e.id == "string" ? e : null : null;
331
+ }
332
+ function U(e) {
333
+ let t = G(e.file_id);
323
334
  return t ? {
324
335
  id: t,
325
- filename: W(e.filename_original) ?? W(e.filename_normalized) ?? t,
326
- content_type: W(e.content_type) ?? "application/octet-stream",
327
- size_bytes: G(e.size_bytes) ?? 0,
328
- sha256: W(e.sha256) ?? "",
329
- dedup: K(e.dedup)
336
+ filename: G(e.filename_original) ?? G(e.filename_normalized) ?? t,
337
+ content_type: G(e.content_type) ?? "application/octet-stream",
338
+ size_bytes: K(e.size_bytes) ?? 0,
339
+ sha256: G(e.sha256) ?? "",
340
+ dedup: q(e.dedup)
330
341
  } : null;
331
342
  }
332
- function U(e) {
343
+ function W(e) {
333
344
  return typeof e == "object" && !!e;
334
345
  }
335
- function W(e) {
346
+ function G(e) {
336
347
  return typeof e == "string" ? e : void 0;
337
348
  }
338
- function G(e) {
349
+ function K(e) {
339
350
  return typeof e == "number" ? e : void 0;
340
351
  }
341
- function K(e) {
352
+ function q(e) {
342
353
  return typeof e == "boolean" ? e : void 0;
343
354
  }
344
- async function q(e) {
355
+ async function J(e) {
345
356
  await L("files.discard", { file_id: e });
346
357
  }
347
- function ie(e, t, n) {
358
+ function Y(e, t, n) {
348
359
  if (n && e.size > n) return {
349
360
  code: "FILE_TOO_LARGE",
350
- message: `File is ${Y(e.size)}, max ${Y(n)}`
361
+ message: `File is ${X(e.size)}, max ${X(n)}`
351
362
  };
352
363
  if (t && t.length > 0) {
353
364
  let n = e.type || "application/octet-stream";
354
- if (!t.some((e) => J(e, n))) return {
365
+ if (!t.some((e) => re(e, n))) return {
355
366
  code: "MIME_NOT_ACCEPTED",
356
367
  message: `File type ${n} is not accepted`
357
368
  };
358
369
  }
359
370
  return null;
360
371
  }
361
- function J(e, t) {
372
+ function re(e, t) {
362
373
  if (e === "*/*" || e === "*") return !0;
363
374
  if (e.endsWith("/*")) {
364
375
  let n = e.slice(0, e.length - 1);
@@ -366,7 +377,7 @@ function J(e, t) {
366
377
  }
367
378
  return e === t;
368
379
  }
369
- function Y(e) {
380
+ function X(e) {
370
381
  if (e < 1024) return `${e} B`;
371
382
  let t = [
372
383
  "KB",
@@ -378,10 +389,10 @@ function Y(e) {
378
389
  }
379
390
  //#endregion
380
391
  //#region src/components/file-widgets/helpers.ts
381
- function ae() {
392
+ function ie() {
382
393
  return typeof navigator > "u" ? ["en"] : (navigator.languages?.length ? navigator.languages : [navigator.language]).filter((e) => typeof e == "string" && e.length > 0);
383
394
  }
384
- function oe(e, t) {
395
+ function ae(e, t) {
385
396
  for (let n of t) {
386
397
  if (e[n]) return e[n];
387
398
  let t = n.split("-")[0];
@@ -389,17 +400,17 @@ function oe(e, t) {
389
400
  }
390
401
  for (let t of Object.values(e)) if (typeof t == "string" && t.length > 0) return t;
391
402
  }
392
- function se(e, t, n) {
403
+ function oe(e, t, n) {
393
404
  if (t) return t;
394
405
  let r = e?.metadata?.alt_text;
395
406
  if (typeof r == "string" && r.length > 0) return r;
396
407
  if (r && typeof r == "object" && !Array.isArray(r)) {
397
- let e = oe(Object.fromEntries(Object.entries(r).filter((e) => e[0].length > 0 && typeof e[1] == "string")), ae());
408
+ let e = ae(Object.fromEntries(Object.entries(r).filter((e) => e[0].length > 0 && typeof e[1] == "string")), ie());
398
409
  if (e) return e;
399
410
  }
400
411
  return n;
401
412
  }
402
- var ce = new Set([
413
+ var se = new Set([
403
414
  "image/png",
404
415
  "image/jpeg",
405
416
  "image/webp",
@@ -407,22 +418,22 @@ var ce = new Set([
407
418
  "image/avif",
408
419
  "application/pdf"
409
420
  ]);
410
- function le(e) {
421
+ function ce(e) {
411
422
  let t = e.content_type?.toLowerCase().split(";")[0]?.trim() ?? "";
412
- return ce.has(t);
423
+ return se.has(t);
413
424
  }
414
- function ue(e) {
425
+ function le(e) {
415
426
  return e.url ?? e.presigned_url;
416
427
  }
417
- function de(e) {
418
- return e.url ? pe(e.url, "attachment") : e.presigned_url;
428
+ function ue(e) {
429
+ return e.url ? fe(e.url, "attachment") : e.presigned_url;
419
430
  }
420
- function fe(e, t) {
431
+ function de(e, t) {
421
432
  if (!e) return;
422
433
  let n = e.derivations ?? {};
423
434
  return t && n[t] ? n[t] : n.thumb_200 ?? n.thumb_300 ?? e.url ?? e.presigned_url;
424
435
  }
425
- function pe(e, t) {
436
+ function fe(e, t) {
426
437
  try {
427
438
  let n = new URL(e, typeof window < "u" ? window.location.origin : "http://localhost");
428
439
  return n.searchParams.set("disposition", t), /^https?:\/\//i.test(e) ? n.toString() : `${n.pathname}${n.search}${n.hash}`;
@@ -430,7 +441,7 @@ function pe(e, t) {
430
441
  return `${e}${e.includes("?") ? "&" : "?"}disposition=${t}`;
431
442
  }
432
443
  }
433
- function me(e) {
444
+ function pe(e) {
434
445
  let t = e?.metadata?.focal_point;
435
446
  if (!t || typeof t != "object" || Array.isArray(t)) return null;
436
447
  let n = t, r = typeof n.x == "number" ? n.x : NaN, i = typeof n.y == "number" ? n.y : NaN;
@@ -439,10 +450,10 @@ function me(e) {
439
450
  y: i
440
451
  };
441
452
  }
442
- function he(e) {
453
+ function me(e) {
443
454
  if (e) return `${e.x * 100}% ${e.y * 100}%`;
444
455
  }
445
- function ge(e, t) {
456
+ function he(e, t) {
446
457
  return {
447
458
  ...e,
448
459
  metadata: {
@@ -453,7 +464,7 @@ function ge(e, t) {
453
464
  }
454
465
  //#endregion
455
466
  //#region src/components/file-widgets/draft-scope.tsx
456
- var X = e({
467
+ var Z = e({
457
468
  registerDraft() {},
458
469
  unregisterDraft() {},
459
470
  hasDraft() {
@@ -462,7 +473,7 @@ var X = e({
462
473
  flushAllDrafts: async () => {},
463
474
  markCommitted() {}
464
475
  });
465
- function _e({ children: e }) {
476
+ function ge({ children: e }) {
466
477
  let t = i(/* @__PURE__ */ new Map()), n = r(() => ({
467
478
  registerDraft(e) {
468
479
  t.current.set(e.fileId, e);
@@ -481,16 +492,16 @@ function _e({ children: e }) {
481
492
  t.current.clear(), await Promise.allSettled(e.map((e) => Promise.resolve(e.discard())));
482
493
  }
483
494
  }), []);
484
- return /* @__PURE__ */ a(X.Provider, {
495
+ return /* @__PURE__ */ a(Z.Provider, {
485
496
  value: n,
486
497
  children: e
487
498
  });
488
499
  }
489
- function Z() {
490
- return n(X);
491
- }
492
500
  function Q() {
493
- let e = Z();
501
+ return n(Z);
502
+ }
503
+ function _e() {
504
+ let e = Q();
494
505
  return {
495
506
  register: t((t, n) => {
496
507
  e.registerDraft({
@@ -519,6 +530,6 @@ function ye(e) {
519
530
  return e ? Array.isArray(e) ? e.filter($) : $(e) ? [e] : [] : [];
520
531
  }
521
532
  //#endregion
522
- export { E as C, p as D, ne as E, f as O, L as S, b as T, z as _, Z as a, N as b, he as c, me as d, se as f, Y as g, q as h, Q as i, o as k, fe as l, R as m, ve as n, le as o, ge as p, _e as r, de as s, ye as t, ue as u, ie as v, O as w, F as x, w as y };
533
+ export { D as C, f as D, C as E, d as O, L as S, b as T, z as _, Q as a, N as b, me as c, pe as d, oe as f, X as g, J as h, _e as i, o as k, de as l, R as m, ve as n, ce as o, he as p, ge as r, ue as s, ye as t, le as u, Y as v, k as w, F as x, E as y };
523
534
 
524
- //# sourceMappingURL=value-DgzPSFZM.js.map
535
+ //# sourceMappingURL=value-Bhy_PJo2.js.map