@declarion/react 0.1.84 → 0.1.86

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