@nivaro/react 0.3.9 → 0.3.11

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.
Files changed (80) hide show
  1. package/dist/components/fields/FileField.js +20 -19
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useNivaroForm.js +129 -126
  4. package/dist/hooks/useSessionRecorder.js +1 -1
  5. package/dist/index.d.ts +103 -4
  6. package/dist/index.js +512 -501
  7. package/dist/shared/components/CollectionBrowserView.js +1632 -1564
  8. package/dist/shared/components/ConformanceView.js +36 -35
  9. package/dist/shared/components/ForceReloadBanner.js +58 -34
  10. package/dist/shared/components/ItemEditForm.js +4386 -4142
  11. package/dist/shared/components/JsonMapEditor.js +18 -17
  12. package/dist/shared/components/MatrixEditor.js +8 -7
  13. package/dist/shared/components/MyWorkView.js +32 -31
  14. package/dist/shared/components/PageRenderer.js +527 -479
  15. package/dist/shared/components/QueryStatStrip.js +74 -70
  16. package/dist/shared/components/RecordGridEditor.js +76 -75
  17. package/dist/shared/components/ReportView.js +818 -827
  18. package/dist/shared/components/SheetHeaderBody.js +16 -14
  19. package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
  20. package/dist/shared/components/ai/AskPanel.js +55 -54
  21. package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
  22. package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
  23. package/dist/shared/components/chat/SlashCommands.js +30 -29
  24. package/dist/shared/components/chat/chat-outbox.js +76 -75
  25. package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
  26. package/dist/shared/components/integrations/console/SignalCard.js +124 -123
  27. package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
  28. package/dist/shared/components/item-edit/CatalogPickerField.js +1029 -933
  29. package/dist/shared/components/item-edit/CloneDialog.js +85 -78
  30. package/dist/shared/components/item-edit/FieldRenderer.js +161 -156
  31. package/dist/shared/components/item-edit/FieldRow.js +20 -19
  32. package/dist/shared/components/item-edit/FilePickerField.js +52 -40
  33. package/dist/shared/components/item-edit/GroupSection.js +221 -221
  34. package/dist/shared/components/item-edit/InlineGridField.js +41 -41
  35. package/dist/shared/components/item-edit/InlineTableField.js +2287 -2275
  36. package/dist/shared/components/item-edit/M2MCombobox.js +46 -44
  37. package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
  38. package/dist/shared/components/item-edit/NestedRelationEditor.js +11 -11
  39. package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
  40. package/dist/shared/components/item-edit/QuickPicker.js +263 -216
  41. package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
  42. package/dist/shared/components/item-edit/RelationCombobox.js +285 -245
  43. package/dist/shared/components/item-edit/RichTextEditorImpl.js +42 -32
  44. package/dist/shared/components/item-edit/RowHistorySheet.js +130 -134
  45. package/dist/shared/components/item-edit/SummaryPanel.js +305 -279
  46. package/dist/shared/components/item-edit/helpers.js +133 -134
  47. package/dist/shared/components/item-edit/line-qty.js +57 -0
  48. package/dist/shared/components/item-edit/option-disambiguate.js +53 -0
  49. package/dist/shared/components/item-edit/staged-links.js +86 -0
  50. package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
  51. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
  52. package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
  53. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
  54. package/dist/shared/components/panels/AddendumLinesDiff.js +87 -90
  55. package/dist/shared/components/panels/CommentPanel.js +350 -315
  56. package/dist/shared/components/panels/ItemLockBanner.js +297 -230
  57. package/dist/shared/components/panels/PipelinePanel.js +719 -701
  58. package/dist/shared/components/profile/AiMemoryCard.js +15 -14
  59. package/dist/shared/components/profile/PersonAdminTools.js +70 -67
  60. package/dist/shared/components/queue/QueueItemSheet.js +36 -35
  61. package/dist/shared/components/queue/QueueQuickFilters.js +43 -41
  62. package/dist/shared/components/queue/QueueWorklist.js +1026 -957
  63. package/dist/shared/components/widgets/ReviewListWidget.js +99 -93
  64. package/dist/shared/lib/client-version.js +63 -0
  65. package/dist/shared/lib/force-reload.js +36 -0
  66. package/dist/shared/lib/load-error.js +11 -10
  67. package/dist/shared/lib/obligation-banner.js +14 -13
  68. package/dist/shared/lib/obligation-reason-text.js +13 -0
  69. package/dist/shared/lib/presence-live.js +54 -35
  70. package/dist/shared/lib/query-filter-seed.js +34 -11
  71. package/dist/shared/lib/record-outbox.js +76 -75
  72. package/dist/shared/lib/safe-error.js +39 -0
  73. package/dist/shared/lib/sanitize-html.js +24 -15
  74. package/dist/shared/lib/server-clock.js +11 -7
  75. package/dist/shared/lib/sheet-def.js +38 -22
  76. package/dist/shared/lib/unique-options.js +10 -0
  77. package/dist/shared/lib/unsaved-work.js +62 -0
  78. package/dist/shared/lib/utils.js +57 -43
  79. package/dist/shared/lib/validation-rules.js +58 -34
  80. package/package.json +1 -1
@@ -1,17 +1,30 @@
1
- import { useQueryClient as d } from "@tanstack/react-query";
2
- import { useEffect as E } from "react";
3
- import { LIVE_WINDOW_EVENT as c } from "./live.js";
4
- import { useLiveRefetchInterval as p } from "./live-queries.js";
5
- import { useOptionalRealtime as w } from "./realtime.js";
6
- const L = ["presence-online"], _ = 1e3, v = 6e4, f = /* @__PURE__ */ new WeakMap();
7
- function a(n, t) {
8
- t.timer || (t.timer = setTimeout(() => {
9
- t.timer = null, n.invalidateQueries({ queryKey: [...L] }, { cancelRefetch: !1 });
10
- }, _));
1
+ import { useQueryClient as _ } from "@tanstack/react-query";
2
+ import { useEffect as w } from "react";
3
+ import { useItemEditAuth as S } from "../context.js";
4
+ import { LIVE_WINDOW_EVENT as m } from "./live.js";
5
+ import { useLiveRefetchInterval as I } from "./live-queries.js";
6
+ import { presenceChangeTouches as P } from "./presence-state.js";
7
+ import { useOptionalRealtime as N } from "./realtime.js";
8
+ const v = ["presence-online"], A = 1e3, E = 1e4, C = 2e3, L = 6e4, s = /* @__PURE__ */ new WeakMap(), l = { now: () => Date.now(), random: () => Math.random() };
9
+ function d(n, e) {
10
+ e.timer && clearTimeout(e.timer), e.timer = null, e.lastRefreshAt = l.now(), n.invalidateQueries({ queryKey: [...v] }, { cancelRefetch: !1 });
11
11
  }
12
- function P(n, t) {
13
- var u;
14
- let r = f.get(n);
12
+ function M(n, e = l.random()) {
13
+ return n >= E ? A : E - Math.max(0, n) + e * C;
14
+ }
15
+ function p(n, e, o) {
16
+ const r = o;
17
+ if (e.selfId && (r == null ? void 0 : r.many) !== !0 && P(o, e.selfId)) {
18
+ d(n, e);
19
+ return;
20
+ }
21
+ if (e.timer) return;
22
+ const t = l.now() - e.lastRefreshAt;
23
+ e.timer = setTimeout(() => d(n, e), M(t));
24
+ }
25
+ function W(n, e, o) {
26
+ var a;
27
+ let r = s.get(n);
15
28
  if (!r) {
16
29
  const i = {
17
30
  refs: 0,
@@ -19,36 +32,42 @@ function P(n, t) {
19
32
  offAdapter: null,
20
33
  offWindow: () => {
21
34
  },
22
- timer: null
23
- }, l = (m) => {
24
- const o = m.detail;
25
- (o == null ? void 0 : o.event) === "presence:changed" && a(n, i);
35
+ timer: null,
36
+ lastRefreshAt: 0,
37
+ selfId: null
38
+ }, u = (R) => {
39
+ const f = R.detail;
40
+ (f == null ? void 0 : f.event) === "presence:changed" && p(n, i, f.payload);
26
41
  };
27
- typeof window < "u" && (window.addEventListener(c, l), i.offWindow = () => window.removeEventListener(c, l)), r = i, f.set(n, r);
42
+ typeof window < "u" && (window.addEventListener(m, u), i.offWindow = () => window.removeEventListener(m, u)), r = i, s.set(n, r);
28
43
  }
29
- const e = r;
30
- e.refs++, t && e.adapter !== t && ((u = e.offAdapter) == null || u.call(e), e.adapter = t, e.offAdapter = t.on("presence:changed", () => a(n, e)));
31
- let s = !1;
44
+ const t = r;
45
+ t.refs++, o && (t.selfId = String(o)), e && t.adapter !== e && ((a = t.offAdapter) == null || a.call(t), t.adapter = e, t.offAdapter = e.on("presence:changed", (i) => p(n, t, i)));
46
+ let c = !1;
32
47
  return () => {
33
48
  var i;
34
- s || (s = !0, e.refs--, !(e.refs > 0) && ((i = e.offAdapter) == null || i.call(e), e.offWindow(), e.timer && clearTimeout(e.timer), f.delete(n)));
49
+ c || (c = !0, t.refs--, !(t.refs > 0) && ((i = t.offAdapter) == null || i.call(t), t.offWindow(), t.timer && clearTimeout(t.timer), s.delete(n)));
35
50
  };
36
51
  }
37
- function N(n = !0) {
38
- const t = d(), r = w();
39
- E(() => {
52
+ function O(n = !0) {
53
+ const e = _(), o = N(), { userId: r } = S();
54
+ w(() => {
40
55
  if (n)
41
- return P(t, r);
42
- }, [t, r, n]);
56
+ return W(e, o, r || null);
57
+ }, [e, o, n, r]);
43
58
  }
44
- function S(n, t = !0) {
45
- return N(t), p(t ? n : !1, { safetyMs: v });
59
+ function K(n, e = !0) {
60
+ return O(e), I(e ? n : !1, { safetyMs: L });
46
61
  }
47
62
  export {
48
- L as PRESENCE_ONLINE_KEY,
49
- v as PRESENCE_POLL_BACKSTOP_MS,
50
- _ as PRESENCE_REFETCH_DELAY_MS,
51
- P as acquirePresenceListener,
52
- N as usePresenceOnlineLive,
53
- S as usePresenceOnlinePoll
63
+ E as PRESENCE_MIN_REFRESH_GAP_MS,
64
+ v as PRESENCE_ONLINE_KEY,
65
+ L as PRESENCE_POLL_BACKSTOP_MS,
66
+ C as PRESENCE_REFRESH_JITTER_MS,
67
+ A as PRESENCE_REFRESH_WINDOW_MS,
68
+ W as acquirePresenceListener,
69
+ l as presenceLiveClock,
70
+ M as presenceRefreshDelay,
71
+ O as usePresenceOnlineLive,
72
+ K as usePresenceOnlinePoll
54
73
  };
@@ -1,18 +1,41 @@
1
- function c(o, i, u = /* @__PURE__ */ new Date()) {
2
- var l;
3
- const t = {}, f = new URLSearchParams(i);
4
- for (const a of o ?? []) {
5
- const r = a.value_field ?? "id", n = a.url_param ? f.getAll(a.url_param).flatMap((e) => e.split(",")).map((e) => e.trim()).filter(Boolean) : [];
6
- if (n.length) {
7
- t[a.param] = n.map((e) => ({ [r]: e }));
1
+ function f(n, l) {
2
+ return n.getAll(l).flatMap((e) => e.split(",")).map((e) => e.trim()).filter(Boolean);
3
+ }
4
+ function p(n, l) {
5
+ const e = new URLSearchParams(l), t = /* @__PURE__ */ new Set();
6
+ for (const r of n ?? [])
7
+ r.url_param && e.has(r.url_param) && f(e, r.url_param).length === 0 && t.add(r.param);
8
+ return t;
9
+ }
10
+ function _(n, l, e) {
11
+ const t = new URLSearchParams(e);
12
+ for (const o of n ?? []) {
13
+ if (!o.url_param) continue;
14
+ const u = o.value_field ?? "id", a = (l[o.param] ?? []).map((i) => String(i[u] ?? "")).filter(Boolean);
15
+ t.set(o.url_param, a.join(","));
16
+ }
17
+ const r = t.toString();
18
+ return r ? `?${r}` : "";
19
+ }
20
+ function d(n, l, e = /* @__PURE__ */ new Date()) {
21
+ var u;
22
+ const t = {}, r = new URLSearchParams(l), o = p(n, l);
23
+ for (const a of n ?? []) {
24
+ const i = a.value_field ?? "id", s = a.url_param ? f(r, a.url_param) : [];
25
+ if (s.length) {
26
+ t[a.param] = (a.single ? s.slice(0, 1) : s).map((c) => ({ [i]: c }));
8
27
  continue;
9
28
  }
10
- (l = a.default_values) != null && l.length && (t[a.param] = a.default_values.map((e) => ({
11
- [r]: e === "$current_year" ? u.getFullYear() : e
12
- })));
29
+ if (o.has(a.param) || !((u = a.default_values) != null && u.length)) continue;
30
+ const m = a.single ? a.default_values.slice(0, 1) : a.default_values;
31
+ t[a.param] = m.map((c) => ({
32
+ [i]: c === "$current_year" ? e.getFullYear() : c
33
+ }));
13
34
  }
14
35
  return t;
15
36
  }
16
37
  export {
17
- c as initialFilterSelection
38
+ p as explicitAllUrlParams,
39
+ _ as filterSelectionToSearch,
40
+ d as initialFilterSelection
18
41
  };
@@ -1,22 +1,23 @@
1
1
  import { clearChatOutbox as z } from "../components/chat/chat-outbox.js";
2
2
  import { get as C, patch as G } from "./commands.js";
3
- const H = "nivaro-record-outbox", k = "entries", Z = 1, Q = 10080 * 60 * 1e3, P = 8e3;
4
- function tt(t) {
3
+ import { userErrorMessage as H } from "./safe-error.js";
4
+ const Z = "nivaro-record-outbox", k = "entries", Q = 1, tt = 10080 * 60 * 1e3, P = 8e3;
5
+ function et(t) {
5
6
  return t ? `${typeof location < "u" ? location.host : ""}|${t}` : null;
6
7
  }
7
- function et(t) {
8
+ function nt(t) {
8
9
  return t.slice(t.lastIndexOf("|") + 1);
9
10
  }
10
11
  function p(t, e, n) {
11
12
  return `${t}|${e}|${String(n)}`;
12
13
  }
13
- let nt = !1;
14
+ let ot = !1;
14
15
  const O = /* @__PURE__ */ new Map();
15
- function ot() {
16
+ function rt() {
16
17
  return new Promise((t) => {
17
18
  try {
18
- if (nt || typeof indexedDB > "u") return t(null);
19
- const e = indexedDB.open(H, Z);
19
+ if (ot || typeof indexedDB > "u") return t(null);
20
+ const e = indexedDB.open(Z, Q);
20
21
  e.onupgradeneeded = () => {
21
22
  const n = e.result;
22
23
  n.objectStoreNames.contains(k) || n.createObjectStore(k, { keyPath: "id" });
@@ -27,7 +28,7 @@ function ot() {
27
28
  });
28
29
  }
29
30
  async function g(t, e) {
30
- const n = await ot();
31
+ const n = await rt();
31
32
  return n ? new Promise((r) => {
32
33
  try {
33
34
  const o = n.transaction(k, t), i = e(o.objectStore(k));
@@ -49,16 +50,16 @@ async function x(t) {
49
50
  const e = await g("readonly", (n) => n.get(t));
50
51
  return e.ok ? e.value ?? null : O.get(t) ?? null;
51
52
  }
52
- async function B() {
53
+ async function M() {
53
54
  const t = await g("readonly", (e) => e.getAll());
54
55
  return t.ok ? t.value ?? [] : [...O.values()];
55
56
  }
56
57
  function W(t) {
57
58
  return JSON.parse(JSON.stringify(t ?? null));
58
59
  }
59
- let l = null, rt = !1, j = null, w = null, a = [];
60
+ let l = null, it = !1, j = null, w = null, a = [];
60
61
  const D = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ new Set();
61
- let S = null, A = !1, h = null;
62
+ let S = null, A = !1, m = null;
62
63
  function d() {
63
64
  for (const t of D) t();
64
65
  }
@@ -71,37 +72,37 @@ function R(t) {
71
72
  }
72
73
  function y() {
73
74
  try {
74
- h == null || h.postMessage({ type: "changed" });
75
+ m == null || m.postMessage({ type: "changed" });
75
76
  } catch {
76
77
  }
77
78
  }
78
79
  function K(t, e) {
79
80
  const n = new Date(t.created_at).getTime();
80
- return !Number.isFinite(n) || e - n > Q;
81
+ return !Number.isFinite(n) || e - n > tt;
81
82
  }
82
- async function it(t) {
83
- const e = M();
83
+ async function st(t) {
84
+ const e = B();
84
85
  if (!e) return t();
85
86
  await e.request("nvr-record-outbox:sweep", {}, t).catch(() => {
86
87
  });
87
88
  }
88
89
  async function V() {
89
90
  const t = l;
90
- t && await it(async () => {
91
+ t && await st(async () => {
91
92
  const e = Date.now();
92
- for (const n of await B()) {
93
+ for (const n of await M()) {
93
94
  if (!n || n.owner !== t || !K(n, e)) continue;
94
95
  const r = await x(n.id);
95
96
  r && (await v(n.id), a = a.filter((o) => o.id !== n.id), d(), y(), l === t && R({ type: "expired", entry: r }));
96
97
  }
97
98
  });
98
99
  }
99
- async function st(t) {
100
- for (const e of await B()) e && e.owner !== t && await v(e.id);
100
+ async function at(t) {
101
+ for (const e of await M()) e && e.owner !== t && await v(e.id);
101
102
  }
102
103
  async function $() {
103
104
  if (!l) return;
104
- const t = l, e = await B(), n = Date.now(), r = [];
105
+ const t = l, e = await M(), n = Date.now(), r = [];
105
106
  let o = !1;
106
107
  for (const i of e)
107
108
  if (!(!i || i.owner !== t)) {
@@ -113,31 +114,31 @@ async function $() {
113
114
  }
114
115
  l === t && (a = r, d(), o && await V());
115
116
  }
116
- function ht(t, e, n) {
117
+ function bt(t, e, n) {
117
118
  j = t, n && (w = n);
118
- const r = tt(e);
119
+ const r = et(e);
119
120
  if (!(!r || r === l)) {
120
- if (l = r, a = [], d(), typeof BroadcastChannel < "u" && !h)
121
+ if (l = r, a = [], d(), typeof BroadcastChannel < "u" && !m)
121
122
  try {
122
- h = new BroadcastChannel("nvr-record-outbox"), h.onmessage = () => void $();
123
+ m = new BroadcastChannel("nvr-record-outbox"), m.onmessage = () => void $();
123
124
  } catch {
124
- h = null;
125
+ m = null;
125
126
  }
126
- !A && typeof window < "u" && (A = !0, window.addEventListener("online", () => b(0))), st(r).then(() => (y(), $())).then(() => {
127
+ !A && typeof window < "u" && (A = !0, window.addEventListener("online", () => b(0))), at(r).then(() => (y(), $())).then(() => {
127
128
  a.some((o) => o.status === "queued") && b(1e3);
128
129
  });
129
130
  }
130
131
  }
131
- function mt() {
132
+ function pt() {
132
133
  return a;
133
134
  }
134
- function bt(t) {
135
+ function Ot(t) {
135
136
  return D.add(t), () => D.delete(t);
136
137
  }
137
- function pt(t) {
138
+ function gt(t) {
138
139
  return I.add(t), () => I.delete(t);
139
140
  }
140
- function Ot(t) {
141
+ function vt(t) {
141
142
  return N.add(t), () => N.delete(t);
142
143
  }
143
144
  function F(t) {
@@ -145,7 +146,7 @@ function F(t) {
145
146
  const e = t, n = (e == null ? void 0 : e.status) ?? ((r = e == null ? void 0 : e.response) == null ? void 0 : r.status);
146
147
  return n == null ? !(e != null && e.response) : n === 0 || n === 502 || n === 503 || n === 504;
147
148
  }
148
- function at(t) {
149
+ function ct(t) {
149
150
  const e = t == null ? void 0 : t.response, n = (e == null ? void 0 : e.data) ?? e;
150
151
  return (n == null ? void 0 : n.code) !== "MIDAIR_COLLISION" || !Array.isArray(n.conflicts) ? null : { conflicts: n.conflicts, latest: Number(n.latest_revision) || 0 };
151
152
  }
@@ -158,9 +159,9 @@ function L(t, e) {
158
159
  return !1;
159
160
  }
160
161
  }
161
- async function gt(t) {
162
+ async function xt(t) {
162
163
  const e = l;
163
- if (!e || rt) return null;
164
+ if (!e || it) return null;
164
165
  const n = {};
165
166
  for (const [f, Y] of Object.entries(t.payload)) f.startsWith("_") || (n[f] = Y);
166
167
  if (Object.keys(n).length === 0) return null;
@@ -185,7 +186,7 @@ async function gt(t) {
185
186
  });
186
187
  return l !== e ? null : (a = [...a.filter((f) => f.id !== r), q], d(), await T(q), y(), b(P), q);
187
188
  }
188
- async function vt(t, e, n) {
189
+ async function St(t, e, n) {
189
190
  if (!l) return;
190
191
  const r = p(l, t, e), o = a.find((s) => s.id === r) ?? await x(r);
191
192
  if (!o || o.owner !== l) return;
@@ -204,26 +205,26 @@ async function vt(t, e, n) {
204
205
  }
205
206
  y();
206
207
  }
207
- async function xt(t, e) {
208
+ async function kt(t, e) {
208
209
  if (!l) return;
209
210
  const n = p(l, t, e);
210
211
  a = a.filter((r) => r.id !== n), d(), await v(n), y();
211
212
  }
212
- async function St() {
213
+ async function _t() {
213
214
  z(), a = [], O.clear(), d(), await g("readwrite", (t) => t.clear()), y();
214
215
  }
215
- async function m(t, e) {
216
+ async function h(t, e) {
216
217
  const n = a.find((o) => o.id === t) ?? await x(t);
217
218
  if (!n) return null;
218
219
  const r = { ...n, ...e };
219
220
  return a = a.some((o) => o.id === t) ? a.map((o) => o.id === t ? r : o) : a, d(), await T(r), y(), r;
220
221
  }
221
- function M() {
222
+ function B() {
222
223
  const t = globalThis.navigator;
223
224
  return (t == null ? void 0 : t.locks) ?? null;
224
225
  }
225
226
  const _ = /* @__PURE__ */ new Set();
226
- function kt(t, e) {
227
+ function Rt(t, e) {
227
228
  if (!l) return () => {
228
229
  };
229
230
  const n = p(l, t, e);
@@ -232,15 +233,15 @@ function kt(t, e) {
232
233
  };
233
234
  const o = new Promise((c) => {
234
235
  r = c;
235
- }), i = M();
236
+ }), i = B();
236
237
  return i && i.request(`nvr-record-outbox:${n}`, {}, () => o).catch(() => {
237
238
  }), () => {
238
239
  _.delete(n), r();
239
240
  };
240
241
  }
241
- async function ct(t, e) {
242
+ async function lt(t, e) {
242
243
  if (_.has(t)) return;
243
- const n = M();
244
+ const n = B();
244
245
  if (!n) return e();
245
246
  await n.request(`nvr-record-outbox:${t}`, { ifAvailable: !0 }, async (r) => {
246
247
  r && await e();
@@ -250,25 +251,25 @@ async function ct(t, e) {
250
251
  let E = !1;
251
252
  function b(t) {
252
253
  S && clearTimeout(S), S = setTimeout(() => {
253
- S = null, ut();
254
+ S = null, ft();
254
255
  }, t);
255
256
  }
256
- async function lt(t, e) {
257
+ async function ut(t, e) {
257
258
  var n;
258
259
  try {
259
260
  const r = await t.request(C("/auth/me")), o = (n = r == null ? void 0 : r.data) == null ? void 0 : n.id;
260
- return !!o && String(o).toLowerCase() === et(e).toLowerCase();
261
+ return !!o && String(o).toLowerCase() === nt(e).toLowerCase();
261
262
  } catch (r) {
262
263
  return F(r) ? null : !1;
263
264
  }
264
265
  }
265
- async function ut() {
266
+ async function ft() {
266
267
  if (E || !j || !l || (await V(), !a.some((r) => r.status === "queued"))) return;
267
268
  E = !0;
268
269
  const t = j, e = l;
269
270
  let n = !1;
270
271
  try {
271
- const r = await lt(t, e);
272
+ const r = await ut(t, e);
272
273
  if (r === null) {
273
274
  n = !0;
274
275
  return;
@@ -278,20 +279,20 @@ async function ut() {
278
279
  const o = a.filter((i) => i.status === "queued" && !_.has(i.id));
279
280
  for (const i of o) {
280
281
  if (l !== e) return;
281
- if (await ct(i.id, async () => {
282
+ if (await lt(i.id, async () => {
282
283
  const c = await x(i.id);
283
284
  if (!c || c.owner !== e || c.status !== "queued") {
284
285
  await $();
285
286
  return;
286
287
  }
287
- await dt(t, c) === "offline" && (n = !0);
288
+ await yt(t, c) === "offline" && (n = !0);
288
289
  }), n) break;
289
290
  }
290
291
  } finally {
291
292
  E = !1, n && b(P);
292
293
  }
293
294
  }
294
- async function ft(t, e) {
295
+ async function dt(t, e) {
295
296
  const n = Object.keys(e.payload), r = await t.request(
296
297
  C(`/items/${e.collection}/${encodeURIComponent(e.item)}`, { fields: n.join(",") })
297
298
  ), o = (r == null ? void 0 : r.data) ?? {}, i = [];
@@ -307,13 +308,13 @@ async function ft(t, e) {
307
308
  });
308
309
  return { conflicts: i, latest: c == null ? null : Number(c) || null };
309
310
  }
310
- async function dt(t, e) {
311
+ async function yt(t, e) {
311
312
  var n, r;
312
- await m(e.id, { status: "sending" });
313
+ await h(e.id, { status: "sending" });
313
314
  try {
314
315
  let o = e.base_revision;
315
316
  if (o == null) {
316
- const c = await ft(t, e);
317
+ const c = await dt(t, e);
317
318
  if (c.conflicts.length > 0) return J(e, c.conflicts, c.latest ?? 0);
318
319
  o = c.latest;
319
320
  }
@@ -321,11 +322,11 @@ async function dt(t, e) {
321
322
  return o != null && (i._base_revision = o), e.change_reason && (i._change_reason = e.change_reason), await t.request(G(`/items/${e.collection}/${encodeURIComponent(e.item)}`, i)), U(e);
322
323
  } catch (o) {
323
324
  if (F(o))
324
- return await m(e.id, { status: "queued", error: "Waiting for a connection" }), "offline";
325
- const i = at(o);
325
+ return await h(e.id, { status: "queued", error: "Waiting for a connection" }), "offline";
326
+ const i = ct(o);
326
327
  if (i)
327
328
  return i.conflicts.every((u) => L(u.current_value, e.payload[u.field])) ? U(e) : J(e, i.conflicts, i.latest);
328
- const c = ((n = o == null ? void 0 : o.response) == null ? void 0 : n.message) ?? ((r = o == null ? void 0 : o.response) == null ? void 0 : r.error) ?? (o instanceof Error ? o.message : "Could not save"), s = await m(e.id, { status: "failed", error: c });
329
+ const c = ((n = o == null ? void 0 : o.response) == null ? void 0 : n.message) ?? ((r = o == null ? void 0 : o.response) == null ? void 0 : r.error) ?? H(o, "Could not save"), s = await h(e.id, { status: "failed", error: c });
329
330
  return s && R({ type: "failed", entry: s }), "failed";
330
331
  }
331
332
  }
@@ -333,7 +334,7 @@ async function U(t) {
333
334
  return a = a.filter((e) => e.id !== t.id), d(), await v(t.id), y(), R({ type: "replayed", entry: t }), w == null || w.invalidateQueries({ queryKey: ["item", t.collection] }), w == null || w.invalidateQueries({ queryKey: ["collision-base", t.collection] }), "done";
334
335
  }
335
336
  async function J(t, e, n) {
336
- const r = await m(t.id, {
337
+ const r = await h(t.id, {
337
338
  status: "conflict",
338
339
  conflicts: W(e),
339
340
  latest_revision: n,
@@ -341,32 +342,32 @@ async function J(t, e, n) {
341
342
  });
342
343
  return r && R({ type: "conflict", entry: r }), "conflict";
343
344
  }
344
- async function _t(t, e) {
345
- l && (await m(p(l, t, e), {
345
+ async function qt(t, e) {
346
+ l && (await h(p(l, t, e), {
346
347
  status: "queued",
347
348
  error: null,
348
349
  conflicts: null
349
350
  }), b(0));
350
351
  }
351
352
  export {
352
- Q as RECORD_OUTBOX_TTL_MS,
353
- ht as bindRecordOutbox,
354
- ft as checkUnknownBase,
355
- kt as claimRecordOutbox,
356
- St as clearRecordOutbox,
357
- xt as discardRecordOutbox,
358
- gt as enqueueRecordSave,
359
- mt as getRecordOutbox,
353
+ tt as RECORD_OUTBOX_TTL_MS,
354
+ bt as bindRecordOutbox,
355
+ dt as checkUnknownBase,
356
+ Rt as claimRecordOutbox,
357
+ _t as clearRecordOutbox,
358
+ kt as discardRecordOutbox,
359
+ xt as enqueueRecordSave,
360
+ pt as getRecordOutbox,
360
361
  F as isOfflineSaveError,
361
- at as midairCollisionOf,
362
- pt as onRecordOutboxEvent,
363
- Ot as onRecordOutboxRetry,
362
+ ct as midairCollisionOf,
363
+ gt as onRecordOutboxEvent,
364
+ vt as onRecordOutboxRetry,
364
365
  p as outboxEntryId,
365
- tt as outboxOwner,
366
- ut as replayRecordOutbox,
367
- _t as retryRecordOutbox,
366
+ et as outboxOwner,
367
+ ft as replayRecordOutbox,
368
+ qt as retryRecordOutbox,
368
369
  b as scheduleReplay,
369
- vt as settleRecordOutbox,
370
- bt as subscribeRecordOutbox,
370
+ St as settleRecordOutbox,
371
+ Ot as subscribeRecordOutbox,
371
372
  V as sweepExpiredRecordOutbox
372
373
  };
@@ -0,0 +1,39 @@
1
+ import { reportClientCrash as a } from "./client-crash.js";
2
+ const u = "Something went wrong — it’s been reported", c = /failed to fetch|load failed|networkerror|network request failed|network error/i;
3
+ function l(t) {
4
+ var s;
5
+ const r = t, e = (r == null ? void 0 : r.status) ?? ((s = r == null ? void 0 : r.response) == null ? void 0 : s.status);
6
+ return typeof e == "number" ? e : null;
7
+ }
8
+ function f(t) {
9
+ return !(t instanceof Error) || l(t) != null || t.response != null || c.test(t.message) ? !1 : t instanceof TypeError || t instanceof ReferenceError || t instanceof RangeError;
10
+ }
11
+ const d = /^(bad request|unauthorized|forbidden|not found|conflict|unprocessable entity|too many requests|internal server error|bad gateway|service unavailable|gateway timeout)$/i;
12
+ function m(t) {
13
+ var s;
14
+ const r = t, e = [(s = r == null ? void 0 : r.response) == null ? void 0 : s.data, r == null ? void 0 : r.response];
15
+ for (const o of e) {
16
+ const n = o == null ? void 0 : o.error;
17
+ if (typeof n == "string" && n.trim() && !d.test(n.trim())) return n.trim();
18
+ }
19
+ for (const o of e) {
20
+ const n = o == null ? void 0 : o.message;
21
+ if (typeof n == "string" && n.trim()) return n.trim();
22
+ }
23
+ return null;
24
+ }
25
+ function g(t, r = "Failed") {
26
+ const e = m(t);
27
+ return e || (f(t) ? u : t instanceof Error ? t.message || r : typeof t == "string" && t.trim() ? t : r);
28
+ }
29
+ const i = /* @__PURE__ */ new WeakSet();
30
+ function E(t, r) {
31
+ !t || !f(r) || i.has(r) || (i.add(r), a(t, r, null).catch(() => {
32
+ }));
33
+ }
34
+ export {
35
+ u as SOMETHING_WENT_WRONG,
36
+ f as isCodeError,
37
+ E as reportCodeError,
38
+ g as userErrorMessage
39
+ };
@@ -38,7 +38,7 @@ const l = /* @__PURE__ */ new Set([
38
38
  "th",
39
39
  "td",
40
40
  "caption"
41
- ]), f = /* @__PURE__ */ new Set([
41
+ ]), c = /* @__PURE__ */ new Set([
42
42
  "script",
43
43
  "style",
44
44
  "iframe",
@@ -52,37 +52,46 @@ const l = /* @__PURE__ */ new Set([
52
52
  "template",
53
53
  "base",
54
54
  "noscript"
55
- ]), c = /* @__PURE__ */ new Set(["href", "title", "colspan", "rowspan", "start", "type"]), h = /^(https?:|mailto:|tel:)/i, u = (n) => {
55
+ ]), f = /* @__PURE__ */ new Set(["href", "title", "colspan", "rowspan", "start", "type"]), p = /^(https?:|mailto:|tel:)/i, u = (n) => {
56
56
  let e = "";
57
- for (const o of n) o.charCodeAt(0) > 32 && (e += o);
58
- return e = e.toLowerCase(), !e || h.test(e) ? !0 : !/^[a-z][a-z0-9+.-]*:/.test(e);
57
+ for (const r of n) r.charCodeAt(0) > 32 && (e += r);
58
+ return e = e.toLowerCase(), !e || p.test(e) ? !0 : !/^[a-z][a-z0-9+.-]*:/.test(e);
59
59
  };
60
+ function h(n) {
61
+ if (typeof DOMParser < "u") {
62
+ const e = new DOMParser().parseFromString(n, "text/html");
63
+ for (const r of e.body.querySelectorAll("script,style,template,noscript")) r.remove();
64
+ return (e.body.textContent || "").replace(/\s+/g, " ");
65
+ }
66
+ return n.replace(/<(script|style|template|noscript)\b[\s\S]*?<\/\1>/gi, " ").replace(/<[^>]+>/g, " ").replace(/&nbsp;/g, " ").replace(/\s+/g, " ");
67
+ }
60
68
  function m(n) {
61
69
  if (typeof DOMParser > "u") return "";
62
- const e = new DOMParser().parseFromString(n, "text/html"), o = (i) => {
70
+ const e = new DOMParser().parseFromString(n, "text/html"), r = (i) => {
63
71
  for (const t of [...i.children]) {
64
72
  const s = t.tagName.toLowerCase();
65
73
  if (!l.has(s)) {
66
- if (f.has(s)) {
74
+ if (c.has(s)) {
67
75
  t.remove();
68
76
  continue;
69
77
  }
70
- const r = t.parentNode;
71
- if (r) {
72
- for (; t.firstChild; ) r.insertBefore(t.firstChild, t);
73
- r.removeChild(t);
78
+ const o = t.parentNode;
79
+ if (o) {
80
+ for (; t.firstChild; ) o.insertBefore(t.firstChild, t);
81
+ o.removeChild(t);
74
82
  }
75
83
  continue;
76
84
  }
77
- for (const r of [...t.attributes]) {
78
- const a = r.name.toLowerCase();
79
- (!c.has(a) || a === "href" && !u(r.value)) && t.removeAttribute(r.name);
85
+ for (const o of [...t.attributes]) {
86
+ const a = o.name.toLowerCase();
87
+ (!f.has(a) || a === "href" && !u(o.value)) && t.removeAttribute(o.name);
80
88
  }
81
- s === "a" && (t.setAttribute("rel", "noopener noreferrer"), t.setAttribute("target", "_blank")), o(t);
89
+ s === "a" && (t.setAttribute("rel", "noopener noreferrer"), t.setAttribute("target", "_blank")), r(t);
82
90
  }
83
91
  };
84
- return o(e.body), e.body.innerHTML;
92
+ return r(e.body), e.body.innerHTML;
85
93
  }
86
94
  export {
95
+ h as htmlToText,
87
96
  m as sanitizeHtml
88
97
  };