@nivaro/react 0.2.54 → 0.2.56

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 (151) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +99 -98
  3. package/dist/index.d.ts +367 -2
  4. package/dist/index.js +645 -616
  5. package/dist/layout-editor.d.ts +4 -0
  6. package/dist/shared/components/BackgroundRunOffer.js +117 -0
  7. package/dist/shared/components/BroadcastView.js +214 -213
  8. package/dist/shared/components/CollectionBrowserView.js +2592 -2695
  9. package/dist/shared/components/ItemEditForm.js +4066 -3832
  10. package/dist/shared/components/JobsTray.js +100 -55
  11. package/dist/shared/components/MyWorkView.js +91 -89
  12. package/dist/shared/components/NotificationBell.js +80 -79
  13. package/dist/shared/components/ProfileView.js +568 -520
  14. package/dist/shared/components/RecordCompare.js +254 -0
  15. package/dist/shared/components/RecordReadView.js +599 -552
  16. package/dist/shared/components/ReportView.js +578 -543
  17. package/dist/shared/components/RowPresence.js +91 -0
  18. package/dist/shared/components/WidgetSlot.js +474 -458
  19. package/dist/shared/components/ai/AiAnalyticsView.js +16 -6
  20. package/dist/shared/components/ai/AskPanel.js +139 -119
  21. package/dist/shared/components/ai/FirstWeekCard.js +126 -0
  22. package/dist/shared/components/bulk/BulkFieldUpdate.js +289 -0
  23. package/dist/shared/components/bulk/bulk-field-options.js +45 -0
  24. package/dist/shared/components/charts/CumulativeFlowChart.js +176 -0
  25. package/dist/shared/components/chat/ChannelArchive.js +326 -0
  26. package/dist/shared/components/chat/ChannelExtras.js +141 -121
  27. package/dist/shared/components/chat/ChatAnalyticsView.js +112 -110
  28. package/dist/shared/components/chat/ChatPanel.js +1695 -1733
  29. package/dist/shared/components/chat/Composer.js +357 -303
  30. package/dist/shared/components/chat/MessageActions.js +92 -0
  31. package/dist/shared/components/chat/MessageFormat.js +290 -264
  32. package/dist/shared/components/chat/OutboxBubbles.js +146 -0
  33. package/dist/shared/components/chat/RequestIdCard.js +135 -0
  34. package/dist/shared/components/chat/RoomHeaderMenu.js +202 -0
  35. package/dist/shared/components/chat/RoomParts.js +213 -274
  36. package/dist/shared/components/chat/ScreenClip.js +184 -0
  37. package/dist/shared/components/chat/chat-core.js +402 -483
  38. package/dist/shared/components/chat/chat-drafts.js +59 -0
  39. package/dist/shared/components/chat/chat-emoji.js +348 -0
  40. package/dist/shared/components/chat/chat-local-time.js +41 -0
  41. package/dist/shared/components/chat/chat-outbox.js +303 -0
  42. package/dist/shared/components/chat/chat-window.js +163 -0
  43. package/dist/shared/components/chat/huddle/HuddleControls.js +143 -0
  44. package/dist/shared/components/chat/huddle/HuddleStage.js +164 -0
  45. package/dist/shared/components/chat/huddle/huddle-store.js +342 -0
  46. package/dist/shared/components/chat/huddle/useHuddle.js +58 -0
  47. package/dist/shared/components/help-videos/api.js +76 -73
  48. package/dist/shared/components/item-edit/CatalogPickerField.js +113 -112
  49. package/dist/shared/components/item-edit/ChangeReasonDialog.js +13 -13
  50. package/dist/shared/components/item-edit/FieldAffordances.js +2 -2
  51. package/dist/shared/components/item-edit/FieldRenderer.js +248 -245
  52. package/dist/shared/components/item-edit/FieldRow.js +292 -279
  53. package/dist/shared/components/item-edit/GroupSection.js +698 -574
  54. package/dist/shared/components/item-edit/InlineTableField.js +3 -1
  55. package/dist/shared/components/item-edit/RelationCombobox.js +186 -176
  56. package/dist/shared/components/item-edit/entry/EntryStrip.js +54 -0
  57. package/dist/shared/components/item-edit/entry/entry-keys.js +27 -0
  58. package/dist/shared/components/item-edit/entry/useEntryKeyboard.js +70 -0
  59. package/dist/shared/components/item-edit/entry/useEntryMode.js +59 -0
  60. package/dist/shared/components/item-edit/form-structure-ui.js +105 -0
  61. package/dist/shared/components/item-edit/lazy-sections.js +36 -0
  62. package/dist/shared/components/item-edit/lock-why.js +39 -32
  63. package/dist/shared/components/item-edit/picker-miss.js +26 -0
  64. package/dist/shared/components/item-edit/placement-behaviour.js +196 -0
  65. package/dist/shared/components/item-edit/useFormUsageBeacon.js +51 -45
  66. package/dist/shared/components/layout-editor/AddPanel.js +134 -117
  67. package/dist/shared/components/layout-editor/ChangeNote.js +25 -24
  68. package/dist/shared/components/layout-editor/CollabParts.js +80 -75
  69. package/dist/shared/components/layout-editor/DesignNode.js +126 -120
  70. package/dist/shared/components/layout-editor/EditorCanvas.js +30 -27
  71. package/dist/shared/components/layout-editor/EditorTopBar.js +203 -192
  72. package/dist/shared/components/layout-editor/HistoryPanel.js +120 -104
  73. package/dist/shared/components/layout-editor/LayoutEditor.js +768 -671
  74. package/dist/shared/components/layout-editor/RestorePiece.js +143 -0
  75. package/dist/shared/components/layout-editor/StagedChip.js +22 -0
  76. package/dist/shared/components/layout-editor/StructureMenu.js +237 -186
  77. package/dist/shared/components/layout-editor/collab/FormFollowShare.js +149 -103
  78. package/dist/shared/components/layout-editor/collab/collab-api.js +29 -26
  79. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +81 -80
  80. package/dist/shared/components/layout-editor/dnd/node.js +69 -57
  81. package/dist/shared/components/layout-editor/draft-recovery.js +113 -43
  82. package/dist/shared/components/layout-editor/entry/PlacementPresets.js +149 -0
  83. package/dist/shared/components/layout-editor/entry/entry-editor-context.js +10 -0
  84. package/dist/shared/components/layout-editor/entry/presets.js +71 -0
  85. package/dist/shared/components/layout-editor/entry/tab-order.js +110 -0
  86. package/dist/shared/components/layout-editor/entry/theme-preview.js +37 -0
  87. package/dist/shared/components/layout-editor/grid-guides.js +142 -0
  88. package/dist/shared/components/layout-editor/inspector/BehaviourSettings.js +402 -0
  89. package/dist/shared/components/layout-editor/inspector/BulkInspector.js +61 -57
  90. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +247 -151
  91. package/dist/shared/components/layout-editor/inspector/Inspector.js +176 -155
  92. package/dist/shared/components/layout-editor/inspector/LookTab.js +167 -116
  93. package/dist/shared/components/layout-editor/inspector/PickerMisses.js +129 -0
  94. package/dist/shared/components/layout-editor/inspector/PickerTab.js +84 -82
  95. package/dist/shared/components/layout-editor/inspector/RulesTab.js +66 -62
  96. package/dist/shared/components/layout-editor/inspector/kit.js +69 -68
  97. package/dist/shared/components/layout-editor/outputs/OutputsButton.js +254 -0
  98. package/dist/shared/components/layout-editor/outputs/help-sheet.js +154 -0
  99. package/dist/shared/components/layout-editor/outputs/output-api.js +61 -0
  100. package/dist/shared/components/layout-editor/overview/describe-conditions.js +6 -0
  101. package/dist/shared/components/layout-editor/overview/purpose.js +15 -13
  102. package/dist/shared/components/layout-editor/parity-keys.json.js +1 -1
  103. package/dist/shared/components/layout-editor/restore-piece.js +192 -0
  104. package/dist/shared/components/layout-editor/section-structure.js +241 -0
  105. package/dist/shared/components/layout-editor/settings/EntrySection.js +296 -0
  106. package/dist/shared/components/layout-editor/settings/FormSettings.js +41 -39
  107. package/dist/shared/components/layout-editor/settings/ResolveSettings.js +255 -0
  108. package/dist/shared/components/layout-editor/settings/ToolsSection.js +147 -111
  109. package/dist/shared/components/layout-editor/settings/WhoSection.js +29 -26
  110. package/dist/shared/components/layout-editor/settings/settings-registry.js +114 -17
  111. package/dist/shared/components/layout-editor/staged-api.js +64 -0
  112. package/dist/shared/components/layout-editor/structure-ops.js +81 -77
  113. package/dist/shared/components/layout-editor/testing/TestingPanels.js +65 -60
  114. package/dist/shared/components/layout-editor/testing/testing-model.js +198 -185
  115. package/dist/shared/components/layout-editor/toolbar-kit.js +11 -11
  116. package/dist/shared/components/layout-editor/usage/AbTestSection.js +355 -0
  117. package/dist/shared/components/layout-editor/usage/UsagePanel.js +144 -70
  118. package/dist/shared/components/layout-editor/usage/ab-api.js +86 -0
  119. package/dist/shared/components/layout-editor/usage/suggest-collapse.js +32 -0
  120. package/dist/shared/components/layout-editor/useLayoutDraft.js +25 -24
  121. package/dist/shared/components/notifications/NotificationAnalyticsView.js +148 -77
  122. package/dist/shared/components/panels/ErpFailureBanner.js +18 -17
  123. package/dist/shared/components/panels/ExternalRequestsChip.js +63 -62
  124. package/dist/shared/components/pipeline/PipelineEditorView.js +106 -104
  125. package/dist/shared/components/profile/AgentsPanel.js +479 -0
  126. package/dist/shared/components/queue/QueueWorklist.js +1026 -1040
  127. package/dist/shared/components/support/SupportAnalytics.js +171 -0
  128. package/dist/shared/components/support/SupportView.js +75 -73
  129. package/dist/shared/lib/background-runs.js +150 -0
  130. package/dist/shared/lib/delivery-ack.js +9 -0
  131. package/dist/shared/lib/entry-badge-style.js +13 -0
  132. package/dist/shared/lib/entry-config.js +71 -0
  133. package/dist/shared/lib/form-sections.js +64 -0
  134. package/dist/shared/lib/form-structure.js +99 -0
  135. package/dist/shared/lib/form-usage-beacon.js +101 -52
  136. package/dist/shared/lib/jobs-tray.js +25 -23
  137. package/dist/shared/lib/keyset-pager.js +37 -0
  138. package/dist/shared/lib/layout-ops.js +84 -82
  139. package/dist/shared/lib/layout-resolve.js +113 -0
  140. package/dist/shared/lib/placement-behaviour.js +144 -0
  141. package/dist/shared/lib/prefetch.js +149 -0
  142. package/dist/shared/lib/presence-hooks.js +199 -0
  143. package/dist/shared/lib/record-outbox.js +82 -81
  144. package/dist/shared/lib/replay-socket.js +93 -0
  145. package/dist/shared/lib/request-gate.js +51 -50
  146. package/dist/shared/lib/room-gaps.js +96 -0
  147. package/dist/shared/lib/search-log.js +27 -0
  148. package/dist/shared/lib/socket-realtime.js +101 -80
  149. package/dist/shared/lib/stale-chunk.js +60 -0
  150. package/dist/shared/lib/worker-socket.js +200 -0
  151. package/package.json +1 -1
@@ -0,0 +1,150 @@
1
+ import { useQueryClient as p } from "@tanstack/react-query";
2
+ import { useRef as A, useState as h, useEffect as f, useCallback as O, useMemo as D } from "react";
3
+ import { useOptionalNivaroClient as L } from "../context.js";
4
+ import { get as $, post as N } from "./commands.js";
5
+ import { useLiveEvent as Q } from "./live.js";
6
+ const P = 2500, T = 8e3, x = 4e3, K = "nvr:bgrun:";
7
+ function W(e) {
8
+ return `${e.method} ${e.url} ${e.body === void 0 ? "" : JSON.stringify(e.body)}`;
9
+ }
10
+ function M(e) {
11
+ let t = 5381;
12
+ for (let d = 0; d < e.length; d++) t = (t << 5) + t + e.charCodeAt(d) | 0;
13
+ return `${K}${(t >>> 0).toString(36)}:${e.length}`;
14
+ }
15
+ function Y(e) {
16
+ try {
17
+ return sessionStorage.getItem(M(e));
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+ function R(e, t) {
23
+ try {
24
+ t ? sessionStorage.setItem(M(e), t) : sessionStorage.removeItem(M(e));
25
+ } catch {
26
+ }
27
+ }
28
+ function j(e, t) {
29
+ return e >= T ? !0 : e >= P && !!(t != null && t.slow);
30
+ }
31
+ function U(e, t) {
32
+ return !t || t <= 0 ? null : Math.max(0, Math.min(0.95, e / t));
33
+ }
34
+ function V(e) {
35
+ const t = Math.max(0, Math.round(e / 1e3));
36
+ return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, "0")}`;
37
+ }
38
+ function Z(e) {
39
+ const t = L(), d = p(), r = e.request ? W(e.request) : null, S = A(e);
40
+ S.current = e;
41
+ const [m, w] = h(0), [g, k] = h(
42
+ null
43
+ ), [u, y] = h(null), [a, i] = h("idle"), [F, b] = h(null), E = A(null);
44
+ f(() => {
45
+ w(0), k(null), y(null), b(null), i("idle"), E.current = null;
46
+ }, [r]), f(() => {
47
+ if (!e.pending || !r || u) return;
48
+ const n = Date.now(), o = setInterval(() => w(Date.now() - n), 500);
49
+ return () => {
50
+ clearInterval(o), w(0);
51
+ };
52
+ }, [e.pending, r, u]), f(() => {
53
+ !t || !r || !e.request || m < P || E.current === r || (E.current = r, t.request(
54
+ $("/background-runs/estimate", {
55
+ method: e.request.method,
56
+ url: e.request.url
57
+ })
58
+ ).then((n) => k(n.data)).catch(() => k({ slow: !1, typical_ms: null })));
59
+ }, [t, r, m, e.request]), f(() => {
60
+ a !== "idle" || u || !e.pending || j(m, g) && i("offer");
61
+ }, [a, u, e.pending, m, g]), f(() => {
62
+ !e.pending && a === "offer" && i("idle");
63
+ }, [e.pending, a]);
64
+ const q = O(
65
+ async (n) => {
66
+ if (!t || !r) return;
67
+ if (R(r, null), n.status === "error") {
68
+ b(n.error ?? "The run failed"), i("error");
69
+ return;
70
+ }
71
+ const { queryKey: o, select: c, onResult: s, onGone: I } = S.current;
72
+ try {
73
+ const _ = await t.request($(`/background-runs/${n.id}/result`));
74
+ o && d.setQueryData(o, c ? c(_) : _), s == null || s(_);
75
+ } catch {
76
+ o && d.invalidateQueries({ queryKey: o }), I == null || I();
77
+ }
78
+ i("done");
79
+ },
80
+ [t, r, d]
81
+ );
82
+ f(() => {
83
+ if (!t || !r) return;
84
+ const n = Y(r);
85
+ if (!n) return;
86
+ let o = !1;
87
+ return t.request($(`/background-runs/${n}`)).then((c) => {
88
+ o || (y(c.data), c.data.status === "running" ? i("running") : q(c.data));
89
+ }).catch(() => R(r, null)), () => {
90
+ o = !0;
91
+ };
92
+ }, [t, r, q]);
93
+ const C = O(() => {
94
+ const { request: n, label: o } = S.current;
95
+ if (!t || !n || !r) return;
96
+ i("starting"), b(null);
97
+ const c = typeof window < "u" ? `${window.location.pathname}${window.location.search}` : null;
98
+ t.request(
99
+ N("/background-runs", {
100
+ method: n.method,
101
+ url: n.url,
102
+ ...n.body !== void 0 ? { body: n.body } : {},
103
+ label: o,
104
+ href: c
105
+ })
106
+ ).then((s) => {
107
+ R(r, s.data.id), y(s.data), i("running");
108
+ }).catch((s) => {
109
+ b((s == null ? void 0 : s.message) || "Could not start the run"), i("error");
110
+ });
111
+ }, [t, r]), l = (u == null ? void 0 : u.id) ?? null, v = O(async () => {
112
+ if (!(!t || !l))
113
+ try {
114
+ const n = await t.request($(`/background-runs/${l}`));
115
+ y(n.data), n.data.status !== "running" && await q(n.data);
116
+ } catch {
117
+ }
118
+ }, [t, l, q]);
119
+ return Q(
120
+ "job:progress",
121
+ (n) => {
122
+ !l || (n == null ? void 0 : n.key) !== `bgrun:${l}` || (n.status === "completed" || n.status === "error") && v();
123
+ },
124
+ { includeOwn: !0, enabled: !!l && a === "running" }
125
+ ), f(() => {
126
+ if (!l || a !== "running") return;
127
+ v();
128
+ const n = setInterval(() => void v(), x);
129
+ return () => clearInterval(n);
130
+ }, [l, a, v]), D(
131
+ () => ({
132
+ phase: a,
133
+ typicalMs: (u == null ? void 0 : u.expected_ms) ?? (g == null ? void 0 : g.typical_ms) ?? null,
134
+ run: u,
135
+ error: F,
136
+ start: C
137
+ }),
138
+ [a, u, g, F, C]
139
+ );
140
+ }
141
+ export {
142
+ P as OFFER_AFTER_MS,
143
+ T as OFFER_ANYWAY_MS,
144
+ V as clock,
145
+ W as requestSignature,
146
+ U as runProgress,
147
+ j as shouldOffer,
148
+ M as signatureKey,
149
+ Z as useBackgroundRun
150
+ };
@@ -0,0 +1,9 @@
1
+ import { serverNow as t } from "./server-clock.js";
2
+ function o(r) {
3
+ if (!r || typeof r != "object") return null;
4
+ const e = r;
5
+ return typeof e._seq != "number" || typeof e._st != "number" ? null : { seq: e._seq, st: e._st, rx: t() };
6
+ }
7
+ export {
8
+ o as deliveryAckFor
9
+ };
@@ -0,0 +1,13 @@
1
+ const r = {
2
+ slate: "border border-slate-300 bg-slate-100 text-slate-700 dark:border-slate-600 dark:bg-slate-700/40 dark:text-slate-200",
3
+ blue: "border border-blue-300 bg-blue-100 text-blue-800 dark:border-blue-500/50 dark:bg-blue-500/20 dark:text-blue-200",
4
+ cyan: "border border-cyan-300 bg-cyan-100 text-cyan-800 dark:border-cyan-500/50 dark:bg-cyan-500/20 dark:text-cyan-200",
5
+ emerald: "border border-emerald-300 bg-emerald-100 text-emerald-800 dark:border-emerald-500/50 dark:bg-emerald-500/20 dark:text-emerald-200",
6
+ amber: "border border-amber-300 bg-amber-100 text-amber-900 dark:border-amber-500/50 dark:bg-amber-500/20 dark:text-amber-200",
7
+ orange: "border border-orange-300 bg-orange-100 text-orange-800 dark:border-orange-500/50 dark:bg-orange-500/20 dark:text-orange-200",
8
+ rose: "border border-rose-300 bg-rose-100 text-rose-800 dark:border-rose-500/50 dark:bg-rose-500/20 dark:text-rose-200",
9
+ violet: "border border-violet-300 bg-violet-100 text-violet-800 dark:border-violet-500/50 dark:bg-violet-500/20 dark:text-violet-200"
10
+ }, a = (e) => r[e] ?? r.slate;
11
+ export {
12
+ a as badgeClasses
13
+ };
@@ -0,0 +1,71 @@
1
+ const p = 3, u = 50, E = 16, A = 20, g = 200, l = [
2
+ "slate",
3
+ "blue",
4
+ "cyan",
5
+ "emerald",
6
+ "amber",
7
+ "orange",
8
+ "rose",
9
+ "violet"
10
+ ], a = ["width", "required", "help", "placeholder", "input", "lock"], o = (e) => !!e && typeof e == "object" && !Array.isArray(e), _ = /^[A-Za-z_][A-Za-z0-9_.]*$/;
11
+ function f(e) {
12
+ if (!o(e)) return null;
13
+ const t = typeof e.name == "string" ? e.name.replace(/\s+/g, " ").trim().slice(0, 60) : "", s = typeof e.id == "string" ? e.id.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 40) : "";
14
+ if (!t || !s) return null;
15
+ const r = (Array.isArray(e.parts) ? e.parts : []).filter(
16
+ (c) => a.includes(c)
17
+ ), n = { id: s, name: t, parts: [...new Set(r)] };
18
+ return (e.col_span === null || typeof e.col_span == "number") && (n.col_span = e.col_span === null ? null : Math.min(12, Math.max(1, Math.round(e.col_span)))), o(e.overrides) && (n.overrides = e.overrides), (e.lock_conditions === null || typeof e.lock_conditions == "string") && (n.lock_conditions = e.lock_conditions), n;
19
+ }
20
+ function d(e) {
21
+ let t = e;
22
+ if (typeof t == "string")
23
+ try {
24
+ t = JSON.parse(t);
25
+ } catch {
26
+ return null;
27
+ }
28
+ if (!o(t)) return null;
29
+ const s = {};
30
+ if (t.focus_first === !0 && (s.focus_first = !0), t.enter_next === !0 && (s.enter_next = !0), t.adaptive === !0 && (s.adaptive = !0), t.glossary === !1 && (s.glossary = !1), typeof t.adaptive_threshold == "number" && Number.isFinite(t.adaptive_threshold)) {
31
+ const r = Math.min(50, Math.max(1, Math.round(t.adaptive_threshold)));
32
+ r !== 3 && (s.adaptive_threshold = r);
33
+ }
34
+ if (Array.isArray(t.tab_order)) {
35
+ const r = [
36
+ ...new Set(t.tab_order.filter((n) => typeof n == "string" && _.test(n)))
37
+ ].slice(0, 200);
38
+ r.length && (s.tab_order = r);
39
+ }
40
+ if (o(t.badge)) {
41
+ const r = typeof t.badge.tag == "string" ? t.badge.tag.replace(/\s+/g, " ").trim().slice(0, 16) : "", n = l.includes(t.badge.color) ? t.badge.color : "slate";
42
+ r && (s.badge = { tag: r, color: n });
43
+ }
44
+ if (Array.isArray(t.presets)) {
45
+ const r = /* @__PURE__ */ new Set(), n = [];
46
+ for (const c of t.presets) {
47
+ const i = f(c);
48
+ if (i && !r.has(i.id) && (r.add(i.id), n.push(i)), n.length >= 20) break;
49
+ }
50
+ n.length && (s.presets = n);
51
+ }
52
+ return Object.keys(s).length ? s : null;
53
+ }
54
+ function T(e) {
55
+ return d(e == null ? void 0 : e.entry_config) ?? {};
56
+ }
57
+ function h(e, t) {
58
+ return e < (t.adaptive_threshold ?? 3);
59
+ }
60
+ export {
61
+ l as BADGE_COLORS,
62
+ E as ENTRY_BADGE_TAG_MAX,
63
+ A as ENTRY_PRESETS_MAX,
64
+ g as ENTRY_TAB_ORDER_MAX,
65
+ p as ENTRY_THRESHOLD_DEFAULT,
66
+ u as ENTRY_THRESHOLD_MAX,
67
+ a as PRESET_PARTS,
68
+ T as entryConfigOf,
69
+ h as isBeginner,
70
+ d as sanitizeEntryConfig
71
+ };
@@ -0,0 +1,64 @@
1
+ const p = "__header__", N = "__general__", E = "__ungrouped__", w = /* @__PURE__ */ new Set(["content", "metadata"]), a = (l) => Number.isFinite(Number(l)) ? Number(l) : 0;
2
+ function v(l, c, s = {}) {
3
+ const u = c.filter((e) => e.is_visible == null || !!e.is_visible).filter((e) => !e.field.startsWith("__")).sort((e, n) => a(e.sort) - a(n.sort)), d = /* @__PURE__ */ new Map();
4
+ for (const e of l) e.id != null && d.set(Number(e.id), e);
5
+ const t = /* @__PURE__ */ new Map();
6
+ for (const e of l) {
7
+ const n = e.container_id == null ? null : Number(e.container_id);
8
+ if (n != null && !d.has(n)) continue;
9
+ const f = t.get(n) ?? [];
10
+ f.push(e), t.set(n, f);
11
+ }
12
+ for (const e of t.values()) e.sort((n, f) => a(n.sort) - a(f.sort));
13
+ const r = (e) => u.filter((n) => n.group_key === e).map((n) => ({ field: n.field, label: n.label_override || null })), i = [], o = r(p);
14
+ o.length && i.push({ key: p, label: "Header", fields: o });
15
+ const y = {
16
+ key: N,
17
+ label: s.generalLabel ?? "General",
18
+ fields: u.filter((e) => e.group_key == null || e.group_key === E).map((e) => ({ field: e.field, label: e.label_override || null }))
19
+ };
20
+ let b = !1;
21
+ const h = () => {
22
+ b || (b = !0, y.fields.length && i.push(y));
23
+ };
24
+ s.ungroupedSort == null && h();
25
+ const g = /* @__PURE__ */ new Set(), m = (e, n) => {
26
+ var S;
27
+ if (g.has(e.key)) return;
28
+ g.add(e.key);
29
+ const f = ((S = e.label) == null ? void 0 : S.trim()) || "", k = f ? [...n, f] : n;
30
+ if (!w.has(String(e.type ?? ""))) {
31
+ const _ = r(e.key);
32
+ _.length && i.push({ key: e.key, label: k.join(" › ") || O(e.key), fields: _ });
33
+ }
34
+ if (e.id != null) for (const _ of t.get(Number(e.id)) ?? []) m(_, k);
35
+ };
36
+ for (const e of t.get(null) ?? [])
37
+ e.key !== p && (!b && s.ungroupedSort != null && a(e.sort) > s.ungroupedSort && h(), m(e, []));
38
+ return h(), i;
39
+ }
40
+ function O(l) {
41
+ return l.replace(/[_-]+/g, " ").replace(/^\w/, (c) => c.toUpperCase());
42
+ }
43
+ function G(l) {
44
+ const c = [], s = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set();
45
+ for (const d of l)
46
+ for (const t of d) {
47
+ const r = t.fields.filter((o) => !u.has(o.field));
48
+ if (r.length === 0) continue;
49
+ for (const o of r) u.add(o.field);
50
+ const i = s.get(t.label);
51
+ if (i) i.fields.push(...r);
52
+ else {
53
+ const o = { ...t, fields: [...r] };
54
+ s.set(t.label, o), c.push(o);
55
+ }
56
+ }
57
+ return c;
58
+ }
59
+ export {
60
+ N as GENERAL_SECTION_KEY,
61
+ p as HEADER_SECTION_KEY,
62
+ v as formSections,
63
+ G as mergeFormSections
64
+ };
@@ -0,0 +1,99 @@
1
+ const g = "sticky", y = "empty_text", m = "row_groups", k = "fold", b = 200, O = 120;
2
+ function a(n) {
3
+ if (n && typeof n == "object" && !Array.isArray(n)) return n;
4
+ if (typeof n != "string" || !n.trim()) return {};
5
+ try {
6
+ const e = JSON.parse(n);
7
+ return e && typeof e == "object" && !Array.isArray(e) ? e : {};
8
+ } catch {
9
+ return {};
10
+ }
11
+ }
12
+ function E(n) {
13
+ if (!Array.isArray(n)) return [];
14
+ const e = [], r = /* @__PURE__ */ new Set();
15
+ for (const s of n) {
16
+ if (!s || typeof s != "object") continue;
17
+ const { key: t, label: i, fields: l } = s;
18
+ if (typeof t != "string" || !t || r.has(t) || !Array.isArray(l)) continue;
19
+ const u = l.filter(
20
+ (c) => typeof c == "string" && !!c && !e.some((d) => d.fields.includes(c))
21
+ );
22
+ r.add(t), e.push({ key: t, label: typeof i == "string" ? i : "", fields: [...new Set(u)] });
23
+ }
24
+ return e;
25
+ }
26
+ function T(n) {
27
+ const e = a(n), r = typeof e[y] == "string" ? e[y].trim() : "";
28
+ return {
29
+ sticky: e[g] === !0,
30
+ emptyText: r || null,
31
+ rows: E(e[m])
32
+ };
33
+ }
34
+ function S(n, e) {
35
+ const r = { ...a(n) }, s = (t, i) => {
36
+ i === void 0 ? delete r[t] : r[t] = i;
37
+ };
38
+ if ("sticky" in e && s(g, e.sticky ? !0 : void 0), "emptyText" in e) {
39
+ const t = (e.emptyText ?? "").trim().slice(0, 200);
40
+ s(y, t || void 0);
41
+ }
42
+ if ("rows" in e) {
43
+ const t = (e.rows ?? []).map((i) => ({ ...i, label: i.label.slice(0, 120) })).filter((i) => i.fields.length > 0);
44
+ s(m, t.length ? t : void 0);
45
+ }
46
+ return Object.keys(r).length ? JSON.stringify(r) : null;
47
+ }
48
+ function h(n, e) {
49
+ return n.find((r) => r.fields.includes(e)) ?? null;
50
+ }
51
+ function Y(n) {
52
+ return a(n)[k] === !0;
53
+ }
54
+ function M(n) {
55
+ return n == null || n === "" || Array.isArray(n) && n.length === 0;
56
+ }
57
+ function R(n) {
58
+ for (const e of n)
59
+ if ((e.type ?? "section") === "section" && T(e.swap_config).sticky)
60
+ return e.key;
61
+ return null;
62
+ }
63
+ function X(n, e = {}) {
64
+ var w, _, A;
65
+ const r = e.rows ?? [], s = new Set(n.map((o) => o.field)), t = r.filter((o) => o.fields.filter((f) => s.has(f)).length >= 2), i = (o) => t.find((f) => f.fields.includes(o)) ?? null, l = [], u = [];
66
+ let c = !1;
67
+ const d = /* @__PURE__ */ new Set();
68
+ for (const o of n) {
69
+ const f = i(o.field);
70
+ if (f) {
71
+ if (d.has(f.key)) continue;
72
+ d.add(f.key), l.push({ kind: "row", row: f, members: n.filter((p) => f.fields.includes(p.field)) });
73
+ continue;
74
+ }
75
+ if ((w = e.folded) != null && w.call(e, o) && !((_ = e.keep) != null && _.call(e, o))) {
76
+ u.push(o), (A = e.filled) != null && A.call(e, o) && (c = !0);
77
+ continue;
78
+ }
79
+ l.push({ kind: "field", field: o });
80
+ }
81
+ return { units: l, folded: u, forcedOpen: c };
82
+ }
83
+ const x = (n) => `Show ${n} more`;
84
+ export {
85
+ y as EMPTY_TEXT_KEY,
86
+ b as EMPTY_TEXT_MAX,
87
+ k as FOLD_KEY,
88
+ m as ROW_GROUPS_KEY,
89
+ O as ROW_LABEL_MAX,
90
+ g as STICKY_KEY,
91
+ x as foldLabel,
92
+ M as isEmptyValue,
93
+ Y as isFolded,
94
+ X as planFieldGrid,
95
+ T as readGroupStructure,
96
+ h as rowOf,
97
+ R as stickyGroupKey,
98
+ S as withGroupStructure
99
+ };
@@ -1,21 +1,21 @@
1
- var p = Object.defineProperty;
2
- var d = (e, t, n) => t in e ? p(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var r = (e, t, n) => d(e, typeof t != "symbol" ? t + "" : t, n);
4
- const s = [];
5
- let u = null, l = null, a = !1;
6
- const h = 20, f = 15e3;
7
- function c() {
8
- if (l && (clearTimeout(l), l = null), !u || s.length === 0) return;
9
- const { apiBase: e, authHeaders: t, credentials: n } = u;
10
- for (; s.length; ) {
11
- const i = JSON.stringify({ events: s.splice(0, h) });
1
+ var S = Object.defineProperty;
2
+ var w = (t, e, n) => e in t ? S(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var i = (t, e, n) => w(t, typeof e != "symbol" ? e + "" : e, n);
4
+ const r = [];
5
+ let h = null, a = null, d = !1;
6
+ const p = 20, v = 15e3;
7
+ function l() {
8
+ if (a && (clearTimeout(a), a = null), !h || r.length === 0) return;
9
+ const { apiBase: t, authHeaders: e, credentials: n } = h;
10
+ for (; r.length; ) {
11
+ const s = JSON.stringify({ events: r.splice(0, p) });
12
12
  try {
13
- const o = `${e}/layout-usage/beacon`;
14
- !(Object.keys(t).length > 0) && typeof navigator < "u" && typeof navigator.sendBeacon == "function" && navigator.sendBeacon(o, new Blob([i], { type: "application/json" })) || fetch(o, {
13
+ const o = `${t}/layout-usage/beacon`;
14
+ !(Object.keys(e).length > 0) && typeof navigator < "u" && typeof navigator.sendBeacon == "function" && navigator.sendBeacon(o, new Blob([s], { type: "application/json" })) || fetch(o, {
15
15
  method: "POST",
16
16
  credentials: n,
17
- headers: { "Content-Type": "application/json", ...t },
18
- body: i,
17
+ headers: { "Content-Type": "application/json", ...e },
18
+ body: s,
19
19
  keepalive: !0
20
20
  }).catch(() => {
21
21
  });
@@ -23,62 +23,111 @@ function c() {
23
23
  }
24
24
  }
25
25
  }
26
- function v() {
27
- a || typeof window > "u" || (a = !0, window.addEventListener("pagehide", c), document.addEventListener("visibilitychange", () => {
28
- document.visibilityState === "hidden" && c();
26
+ function g() {
27
+ d || typeof window > "u" || (d = !0, window.addEventListener("pagehide", l), document.addEventListener("visibilitychange", () => {
28
+ document.visibilityState === "hidden" && l();
29
29
  }));
30
30
  }
31
- function _(e, t) {
32
- u = t, s.push(e), v(), s.length >= h ? c() : l || (l = setTimeout(c, f));
31
+ function _(t, e) {
32
+ h = e, r.push(t), g(), r.length >= p ? l() : a || (a = setTimeout(l, v));
33
33
  }
34
- class M {
35
- constructor(t, n, i = !0) {
36
- r(this, "steps", {});
37
- r(this, "current");
38
- r(this, "since");
39
- this.current = t, this.since = i ? n : null;
34
+ class k {
35
+ constructor(e, n, s = !0) {
36
+ i(this, "steps", {});
37
+ i(this, "current");
38
+ i(this, "since");
39
+ this.current = e, this.since = s ? n : null;
40
40
  }
41
- settle(t) {
41
+ settle(e) {
42
42
  if (this.since == null) return;
43
- const n = Math.max(0, t - this.since);
44
- n > 0 && (this.steps[this.current] = (this.steps[this.current] ?? 0) + n), this.since = t;
43
+ const n = Math.max(0, e - this.since);
44
+ n > 0 && (this.steps[this.current] = (this.steps[this.current] ?? 0) + n), this.since = e;
45
45
  }
46
- step(t, n) {
47
- t !== this.current && (this.settle(n), this.current = t);
46
+ step(e, n) {
47
+ e !== this.current && (this.settle(n), this.current = e);
48
48
  }
49
- pause(t) {
50
- this.settle(t), this.since = null;
49
+ pause(e) {
50
+ this.settle(e), this.since = null;
51
51
  }
52
- resume(t) {
53
- this.since == null && (this.since = t);
52
+ resume(e) {
53
+ this.since == null && (this.since = e);
54
54
  }
55
55
  get currentStep() {
56
56
  return this.current;
57
57
  }
58
+ /** The time so far in this chunk, without starting afresh. */
59
+ peek(e) {
60
+ const n = this.since == null ? 0 : Math.max(0, e - this.since);
61
+ return Object.values(this.steps).reduce((s, o) => s + o, 0) + n;
62
+ }
58
63
  /** The time so far, and start counting afresh (the clock keeps running). */
59
- take(t) {
60
- this.settle(t);
64
+ take(e) {
65
+ this.settle(e);
61
66
  const n = this.steps;
62
- return this.steps = {}, { steps: n, total: Object.values(n).reduce((i, o) => i + o, 0) };
67
+ return this.steps = {}, { steps: n, total: Object.values(n).reduce((s, o) => s + o, 0) };
63
68
  }
64
69
  }
65
- const g = 400, S = 3e3;
66
- function B(e) {
67
- return !e.saved && !e.openSent && e.elapsed < g || !e.saved && e.openSent && e.total <= 0 ? null : {
68
- layout_id: e.layoutId,
69
- collection: e.collection,
70
- item: e.item,
71
- open: !e.openSent,
72
- saved: e.saved,
73
- abandoned_step: e.final && e.item == null && !e.saved && e.elapsed >= S ? e.step : null,
74
- steps: e.steps
70
+ const m = 400, y = 3e3;
71
+ function B(t) {
72
+ if (!t.saved && !t.openSent && t.elapsed < m || !t.saved && t.openSent && t.total <= 0) return null;
73
+ const e = {
74
+ layout_id: t.layoutId,
75
+ collection: t.collection,
76
+ item: t.item,
77
+ open: !t.openSent,
78
+ saved: t.saved,
79
+ abandoned_step: t.final && t.item == null && !t.saved && t.elapsed >= y ? t.step : null,
80
+ steps: t.steps
81
+ };
82
+ return t.sections && (t.sections.shown.length || t.sections.opened.length) && (e.sections = t.sections), t.saved && t.saveMs != null && t.saveMs > 0 && (e.save_ms = Math.round(t.saveMs)), e;
83
+ }
84
+ const u = /* @__PURE__ */ new Set(), c = [], f = 5e3;
85
+ function N(t) {
86
+ const e = Date.now();
87
+ for (c.push({ ...t, at: e }); c.length > 200 || c[0] && e - c[0].at > f; )
88
+ c.shift();
89
+ for (const n of u)
90
+ try {
91
+ n(t);
92
+ } catch {
93
+ }
94
+ }
95
+ function T(t) {
96
+ const e = Date.now();
97
+ for (const n of c) n.kind === "shown" && e - n.at <= f && t(n);
98
+ return u.add(t), () => {
99
+ u.delete(t);
75
100
  };
76
101
  }
102
+ class j {
103
+ constructor() {
104
+ i(this, "shown", /* @__PURE__ */ new Set());
105
+ i(this, "opened", /* @__PURE__ */ new Set());
106
+ i(this, "sentShown", /* @__PURE__ */ new Set());
107
+ i(this, "sentOpened", /* @__PURE__ */ new Set());
108
+ }
109
+ note(e, n) {
110
+ e === "opened" ? (this.shown.add(n), this.opened.add(n)) : this.shown.add(n);
111
+ }
112
+ pending() {
113
+ return {
114
+ shown: [...this.shown].filter((e) => !this.sentShown.has(e)),
115
+ opened: [...this.opened].filter((e) => !this.sentOpened.has(e))
116
+ };
117
+ }
118
+ markSent(e) {
119
+ for (const n of e.shown) this.sentShown.add(n);
120
+ for (const n of e.opened) this.sentOpened.add(n);
121
+ }
122
+ }
77
123
  export {
78
- S as MIN_ABANDON_MS,
79
- g as MIN_SESSION_MS,
80
- M as StepClock,
81
- c as flushFormUsage,
124
+ y as MIN_ABANDON_MS,
125
+ m as MIN_SESSION_MS,
126
+ j as SectionTally,
127
+ k as StepClock,
128
+ l as flushFormUsage,
129
+ T as onSectionUse,
82
130
  _ as queueFormUsage,
131
+ N as reportSectionUse,
83
132
  B as sessionEvent
84
133
  };