@nivaro/react 0.2.50 → 0.2.52

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 (121) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +204 -6
  4. package/dist/index.js +442 -439
  5. package/dist/layout-editor.d.ts +80 -0
  6. package/dist/layout-editor.js +11 -0
  7. package/dist/shared/components/ItemEditForm.js +4117 -3882
  8. package/dist/shared/components/RecordDrilldownSheet.js +114 -97
  9. package/dist/shared/components/RecordReadView.js +662 -596
  10. package/dist/shared/components/ai/ExplainButton.js +1 -1
  11. package/dist/shared/components/chat/ChatPanel.js +1053 -993
  12. package/dist/shared/components/import/DocumentAutofillButton.js +141 -129
  13. package/dist/shared/components/item-edit/GroupSection.js +489 -466
  14. package/dist/shared/components/item-edit/HeaderBand.js +47 -44
  15. package/dist/shared/components/item-edit/M2MStagingContext.js +3 -3
  16. package/dist/shared/components/item-edit/O2MStagingContext.js +1 -1
  17. package/dist/shared/components/item-edit/RecordGrantTools.js +206 -0
  18. package/dist/shared/components/item-edit/StepsBar.js +49 -43
  19. package/dist/shared/components/item-edit/SummaryPanel.js +2 -1
  20. package/dist/shared/components/item-edit/config-update.js +6 -0
  21. package/dist/shared/components/item-edit/layout-editing-quiet.js +25 -0
  22. package/dist/shared/components/layout-editor/AddPanel.js +301 -0
  23. package/dist/shared/components/layout-editor/DesignNode.js +173 -0
  24. package/dist/shared/components/layout-editor/EditorCanvas.js +52 -0
  25. package/dist/shared/components/layout-editor/EditorTopBar.js +241 -0
  26. package/dist/shared/components/layout-editor/HistoryPanel.js +179 -0
  27. package/dist/shared/components/layout-editor/LayoutEditor.js +393 -0
  28. package/dist/shared/components/layout-editor/LayoutsRail.js +89 -0
  29. package/dist/shared/components/layout-editor/add-target.js +103 -0
  30. package/dist/shared/components/layout-editor/bundle-to-active.js +86 -0
  31. package/dist/shared/components/layout-editor/canvases/PdfCanvas.js +90 -0
  32. package/dist/shared/components/layout-editor/canvases/TableColumnsCanvas.js +246 -0
  33. package/dist/shared/components/layout-editor/collection-meta.js +22 -0
  34. package/dist/shared/components/layout-editor/design-canvas.js +81 -0
  35. package/dist/shared/components/layout-editor/design-context.js +21 -0
  36. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +225 -0
  37. package/dist/shared/components/layout-editor/dnd/collision.js +107 -0
  38. package/dist/shared/components/layout-editor/dnd/node.js +164 -0
  39. package/dist/shared/components/layout-editor/dnd/order.js +122 -0
  40. package/dist/shared/components/layout-editor/editors/DefaultValuesEditor.js +223 -0
  41. package/dist/shared/components/layout-editor/editors/QuickPickerStepsEditor.js +129 -0
  42. package/dist/shared/components/layout-editor/editors/ReadPresentationEditor.js +134 -0
  43. package/dist/shared/components/layout-editor/editors/RecordConditionsEditor.js +249 -0
  44. package/dist/shared/components/layout-editor/editors/RolesPicker.js +77 -0
  45. package/dist/shared/components/layout-editor/editors/cascade-filters.js +556 -0
  46. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +150 -0
  47. package/dist/shared/components/layout-editor/editors/controls.js +73 -0
  48. package/dist/shared/components/layout-editor/editors/editor-api.js +21 -0
  49. package/dist/shared/components/layout-editor/editors/editor-queries.js +25 -0
  50. package/dist/shared/components/layout-editor/editors/field-default-value.js +131 -0
  51. package/dist/shared/components/layout-editor/editors/grid-presets.js +310 -0
  52. package/dist/shared/components/layout-editor/editors/inline-display.js +157 -0
  53. package/dist/shared/components/layout-editor/editors/layout-picker.js +80 -0
  54. package/dist/shared/components/layout-editor/editors/layout-rows.js +55 -0
  55. package/dist/shared/components/layout-editor/editors/lock-conditions.js +109 -0
  56. package/dist/shared/components/layout-editor/editors/o2m-agg-field.js +25 -0
  57. package/dist/shared/components/layout-editor/editors/pdf-field-config.js +107 -0
  58. package/dist/shared/components/layout-editor/editors/report-widget-config.js +94 -0
  59. package/dist/shared/components/layout-editor/editors/row-rule-check.js +225 -0
  60. package/dist/shared/components/layout-editor/editors/row-rule-row.js +1353 -0
  61. package/dist/shared/components/layout-editor/editors/swap-config.js +245 -0
  62. package/dist/shared/components/layout-editor/focus-buffer.js +32 -0
  63. package/dist/shared/components/layout-editor/host.js +15 -0
  64. package/dist/shared/components/layout-editor/inspector/AdvancedTab.js +296 -0
  65. package/dist/shared/components/layout-editor/inspector/GridTab.js +767 -0
  66. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +456 -0
  67. package/dist/shared/components/layout-editor/inspector/HeaderItemInspector.js +268 -0
  68. package/dist/shared/components/layout-editor/inspector/Inspector.js +332 -0
  69. package/dist/shared/components/layout-editor/inspector/LookTab.js +310 -0
  70. package/dist/shared/components/layout-editor/inspector/PickerTab.js +333 -0
  71. package/dist/shared/components/layout-editor/inspector/RulesTab.js +323 -0
  72. package/dist/shared/components/layout-editor/inspector/SlotInspector.js +179 -0
  73. package/dist/shared/components/layout-editor/inspector/SubtitleInspector.js +154 -0
  74. package/dist/shared/components/layout-editor/inspector/WidgetInspector.js +262 -0
  75. package/dist/shared/components/layout-editor/inspector/applies.js +27 -0
  76. package/dist/shared/components/layout-editor/inspector/field-context.js +134 -0
  77. package/dist/shared/components/layout-editor/inspector/interfaces.js +126 -0
  78. package/dist/shared/components/layout-editor/inspector/kit.js +595 -0
  79. package/dist/shared/components/layout-editor/inspector/model.js +307 -0
  80. package/dist/shared/components/layout-editor/overview/OverviewActions.js +15 -0
  81. package/dist/shared/components/layout-editor/overview/describe-conditions.js +121 -0
  82. package/dist/shared/components/layout-editor/overview/overview-api.js +141 -0
  83. package/dist/shared/components/layout-editor/overview/purpose.js +62 -0
  84. package/dist/shared/components/layout-editor/overview/record-count.js +65 -0
  85. package/dist/shared/components/layout-editor/panel-frame.js +99 -0
  86. package/dist/shared/components/layout-editor/panel-style.js +19 -0
  87. package/dist/shared/components/layout-editor/pickers/field-picker.js +230 -0
  88. package/dist/shared/components/layout-editor/pickers/icon-picker.js +233 -0
  89. package/dist/shared/components/layout-editor/pickers/relation-label.js +34 -0
  90. package/dist/shared/components/layout-editor/pickers/relation-picker.js +136 -0
  91. package/dist/shared/components/layout-editor/record-queries.js +15 -0
  92. package/dist/shared/components/layout-editor/settings/AddendumSection.js +52 -0
  93. package/dist/shared/components/layout-editor/settings/ButtonsSection.js +45 -0
  94. package/dist/shared/components/layout-editor/settings/DefaultsSection.js +67 -0
  95. package/dist/shared/components/layout-editor/settings/FormSettings.js +146 -0
  96. package/dist/shared/components/layout-editor/settings/InheritanceSection.js +37 -0
  97. package/dist/shared/components/layout-editor/settings/LayoutSection.js +70 -0
  98. package/dist/shared/components/layout-editor/settings/PdfSection.js +176 -0
  99. package/dist/shared/components/layout-editor/settings/ReadSection.js +79 -0
  100. package/dist/shared/components/layout-editor/settings/TextSetting.js +55 -0
  101. package/dist/shared/components/layout-editor/settings/ToggleSetting.js +33 -0
  102. package/dist/shared/components/layout-editor/settings/ToolsSection.js +179 -0
  103. package/dist/shared/components/layout-editor/settings/WhoSection.js +213 -0
  104. package/dist/shared/components/layout-editor/settings/controls.js +214 -0
  105. package/dist/shared/components/layout-editor/settings/section-props.js +17 -0
  106. package/dist/shared/components/layout-editor/settings/settings-api.js +151 -0
  107. package/dist/shared/components/layout-editor/settings/settings-registry.js +445 -0
  108. package/dist/shared/components/layout-editor/slot-names.js +20 -0
  109. package/dist/shared/components/layout-editor/summary-pref.js +21 -0
  110. package/dist/shared/components/layout-editor/useLayoutDraft.js +474 -0
  111. package/dist/shared/components/pipeline/relations.js +28 -23
  112. package/dist/shared/components/ui/dialog.js +11 -11
  113. package/dist/shared/components/ui/popover.js +17 -17
  114. package/dist/shared/components/ui/scroll-area.js +38 -0
  115. package/dist/shared/hooks/useRelationOptions.js +60 -0
  116. package/dist/shared/lib/layout-grants.js +9 -0
  117. package/dist/shared/lib/layout-ops.js +348 -0
  118. package/dist/shared/lib/layout-slots.js +11 -7
  119. package/dist/shared/lib/presence-state.js +43 -13
  120. package/dist/shared/lib/request-gate.js +1 -1
  121. package/package.json +5 -1
@@ -0,0 +1,176 @@
1
+ import { jsxs as k, Fragment as P, jsx as e } from "react/jsx-runtime";
2
+ import { ExternalLink as x } from "lucide-react";
3
+ import { useState as _ } from "react";
4
+ import { useApiFetchConfig as S } from "../../../context.js";
5
+ import { Setting as i, Toggle as C, Segmented as m, PickList as h, quietText as F, smallBtn as T } from "./controls.js";
6
+ import { flag as g, toggleLabel as O, changeLabel as u } from "./section-props.js";
7
+ import { useFieldSources as D, usePdfTemplates as N, fieldOptions as z, storedFieldNames as E } from "./settings-api.js";
8
+ import { TextSetting as v } from "./TextSetting.js";
9
+ import { ToggleSetting as b } from "./ToggleSetting.js";
10
+ const y = [
11
+ { value: "classic", label: "Classic" },
12
+ { value: "minimal", label: "Minimal" },
13
+ { value: "executive", label: "Executive" },
14
+ { value: "custom", label: "Custom" }
15
+ ];
16
+ function G(a) {
17
+ const { layout: l, collection: s } = a, { fields: c, columns: f, relations: d } = D(s), p = N(s, !0), o = y.some((t) => t.value === l.pdf_theme) ? l.pdf_theme : "classic", r = l.pdf_template_id == null ? null : String(l.pdf_template_id), n = l.pdf_cover_enabled == null ? !0 : g(l.pdf_cover_enabled), L = z(
18
+ c,
19
+ E(s, c, f, d)
20
+ ), w = g(l.is_active);
21
+ return /* @__PURE__ */ k(P, { children: [
22
+ /* @__PURE__ */ e(
23
+ i,
24
+ {
25
+ k: "layout.pdf_export_active",
26
+ control: /* @__PURE__ */ e(
27
+ C,
28
+ {
29
+ label: "PDF button on records",
30
+ checked: w,
31
+ onChange: (t) => a.set({ is_active: t }, O("layout.pdf_export_active", t))
32
+ }
33
+ )
34
+ }
35
+ ),
36
+ /* @__PURE__ */ e(
37
+ i,
38
+ {
39
+ k: "layout.pdf_theme",
40
+ control: /* @__PURE__ */ e(
41
+ m,
42
+ {
43
+ ariaLabel: "PDF theme",
44
+ value: o,
45
+ options: y,
46
+ onChange: (t) => a.set({ pdf_theme: t }, u("layout.pdf_theme"))
47
+ }
48
+ )
49
+ }
50
+ ),
51
+ /* @__PURE__ */ e(
52
+ i,
53
+ {
54
+ k: "layout.pdf_template_id",
55
+ control: /* @__PURE__ */ e(
56
+ h,
57
+ {
58
+ ariaLabel: "Custom template",
59
+ value: r,
60
+ options: p.map((t) => ({ value: String(t.id), label: t.name })),
61
+ clearLabel: "None",
62
+ emptyText: "No PDF templates for this collection",
63
+ onChange: (t) => a.set(
64
+ t ? { pdf_theme: "custom", pdf_template_id: Number(t) } : {
65
+ pdf_template_id: null,
66
+ ...o === "custom" ? { pdf_theme: "classic" } : {}
67
+ },
68
+ t ? "Use a custom PDF template" : "Stop using a custom PDF template"
69
+ )
70
+ }
71
+ ),
72
+ note: o === "custom" && !r ? "Pick a template: the Custom theme needs one, otherwise the PDF uses Classic." : null
73
+ }
74
+ ),
75
+ /* @__PURE__ */ e(b, { k: "layout.pdf_cover_enabled", props: a, defaultOn: !0 }),
76
+ /* @__PURE__ */ e(
77
+ i,
78
+ {
79
+ k: "layout.pdf_cover_title_field",
80
+ note: n ? null : "Turn on the cover page first.",
81
+ control: /* @__PURE__ */ e(
82
+ h,
83
+ {
84
+ ariaLabel: "Cover title field",
85
+ value: l.pdf_cover_title_field ? String(l.pdf_cover_title_field) : null,
86
+ options: L,
87
+ clearLabel: "The record's name",
88
+ disabled: !n,
89
+ onChange: (t) => a.set({ pdf_cover_title_field: t }, u("layout.pdf_cover_title_field"))
90
+ }
91
+ )
92
+ }
93
+ ),
94
+ /* @__PURE__ */ e(
95
+ v,
96
+ {
97
+ k: "layout.pdf_cover_subtitle",
98
+ props: a,
99
+ placeholder: "e.g. Procurement summary",
100
+ disabled: !n
101
+ }
102
+ ),
103
+ /* @__PURE__ */ e(v, { k: "layout.pdf_button_label", props: a, placeholder: "Download PDF" }),
104
+ /* @__PURE__ */ e(b, { k: "layout.pdf_show_logo", props: a, defaultOn: !0 }),
105
+ /* @__PURE__ */ e(
106
+ i,
107
+ {
108
+ k: "layout.pdf_page_size",
109
+ control: /* @__PURE__ */ e(
110
+ m,
111
+ {
112
+ ariaLabel: "Page size",
113
+ value: l.pdf_page_size === "Letter" ? "Letter" : "A4",
114
+ options: [
115
+ { value: "A4", label: "A4" },
116
+ { value: "Letter", label: "Letter" }
117
+ ],
118
+ onChange: (t) => a.set({ pdf_page_size: t }, u("layout.pdf_page_size"))
119
+ }
120
+ )
121
+ }
122
+ ),
123
+ /* @__PURE__ */ e(
124
+ i,
125
+ {
126
+ k: "layout.pdf_orientation",
127
+ control: /* @__PURE__ */ e(
128
+ m,
129
+ {
130
+ ariaLabel: "Orientation",
131
+ value: l.pdf_orientation === "landscape" ? "landscape" : "portrait",
132
+ options: [
133
+ { value: "portrait", label: "Portrait" },
134
+ { value: "landscape", label: "Landscape" }
135
+ ],
136
+ onChange: (t) => a.set({ pdf_orientation: t }, u("layout.pdf_orientation"))
137
+ }
138
+ )
139
+ }
140
+ ),
141
+ /* @__PURE__ */ e(U, { layoutId: Number(a.bundle.layout.id) })
142
+ ] });
143
+ }
144
+ function U({ layoutId: a }) {
145
+ const l = S(), [s, c] = _(!1), [f, d] = _(!1);
146
+ return /* @__PURE__ */ e(
147
+ i,
148
+ {
149
+ k: "layout.pdf_preview",
150
+ control: /* @__PURE__ */ k("button", { type: "button", className: T, disabled: s, onClick: async () => {
151
+ c(!0), d(!1);
152
+ const o = window.open("", "_blank");
153
+ try {
154
+ const r = await fetch(`${l.apiBase}/collection-layouts/${a}/preview-html`, {
155
+ headers: l.authHeaders,
156
+ credentials: l.credentials
157
+ });
158
+ if (!r.ok) throw new Error(String(r.status));
159
+ const n = URL.createObjectURL(new Blob([await r.text()], { type: "text/html" }));
160
+ o ? o.location.href = n : window.open(n, "_blank"), setTimeout(() => URL.revokeObjectURL(n), 6e4);
161
+ } catch {
162
+ o == null || o.close(), d(!0);
163
+ } finally {
164
+ c(!1);
165
+ }
166
+ }, children: [
167
+ /* @__PURE__ */ e(x, { className: "h-3.5 w-3.5" }),
168
+ s ? "Opening…" : "Preview PDF"
169
+ ] }),
170
+ note: f ? /* @__PURE__ */ e("span", { className: "text-[#9c2f47] dark:text-[#f08aa1]", children: "The preview could not be made. Saved changes are still saved." }) : /* @__PURE__ */ e("span", { className: F, children: "Shows the last saved settings." })
171
+ }
172
+ );
173
+ }
174
+ export {
175
+ G as PdfSection
176
+ };
@@ -0,0 +1,79 @@
1
+ import { jsxs as u, Fragment as h, jsx as a } from "react/jsx-runtime";
2
+ import { SheetWidthInput as y, HeaderFieldsPicker as f } from "../editors/ReadPresentationEditor.js";
3
+ import { Setting as r, Segmented as _ } from "./controls.js";
4
+ import { flag as c, changeLabel as d } from "./section-props.js";
5
+ import { useSettingsFields as g } from "./settings-api.js";
6
+ import { ToggleSetting as o } from "./ToggleSetting.js";
7
+ function w(t) {
8
+ let e = t;
9
+ if (typeof e == "string")
10
+ try {
11
+ e = JSON.parse(e);
12
+ } catch {
13
+ return [];
14
+ }
15
+ return Array.isArray(e) ? e.filter((l) => typeof l == "string") : [];
16
+ }
17
+ function x(t) {
18
+ const { layout: e, collection: l } = t, m = g(l), n = c(e.summary_enabled), s = e.sheet_width == null ? null : Number(e.sheet_width);
19
+ return /* @__PURE__ */ u(h, { children: [
20
+ /* @__PURE__ */ a(o, { k: "layout.summary_enabled", props: t }),
21
+ /* @__PURE__ */ a(
22
+ o,
23
+ {
24
+ k: "layout.summary_hide_empty",
25
+ props: t,
26
+ disabled: !n,
27
+ note: n ? void 0 : "Turn on the summary side panel first."
28
+ }
29
+ ),
30
+ /* @__PURE__ */ a(
31
+ r,
32
+ {
33
+ k: "layout.display_mode",
34
+ control: /* @__PURE__ */ a(
35
+ _,
36
+ {
37
+ ariaLabel: "Drill-down opens as",
38
+ value: e.display_mode === "read" ? "read" : "form",
39
+ options: [
40
+ { value: "form", label: "Form" },
41
+ { value: "read", label: "Read view" }
42
+ ],
43
+ onChange: (i) => t.set(
44
+ { display_mode: i === "read" ? "read" : null },
45
+ d("layout.display_mode")
46
+ )
47
+ }
48
+ )
49
+ }
50
+ ),
51
+ /* @__PURE__ */ a(
52
+ r,
53
+ {
54
+ k: "layout.sheet_width",
55
+ htmlFor: "setting-sheet_width",
56
+ control: /* @__PURE__ */ a(
57
+ y,
58
+ {
59
+ id: "setting-sheet_width",
60
+ value: Number.isFinite(s) ? s : null,
61
+ onChange: (i) => t.set({ sheet_width: i }, d("layout.sheet_width"))
62
+ }
63
+ )
64
+ }
65
+ ),
66
+ /* @__PURE__ */ a(r, { k: "layout.header_fields", children: /* @__PURE__ */ a(
67
+ f,
68
+ {
69
+ value: w(e.header_fields),
70
+ fields: m,
71
+ onChange: (i) => t.set({ header_fields: i }, d("layout.header_fields"))
72
+ }
73
+ ) }),
74
+ /* @__PURE__ */ a(o, { k: "layout.hide_empty", props: t })
75
+ ] });
76
+ }
77
+ export {
78
+ x as ReadSection
79
+ };
@@ -0,0 +1,55 @@
1
+ import { jsx as h, jsxs as B } from "react/jsx-runtime";
2
+ import { useState as C, useRef as a, useEffect as N } from "react";
3
+ import { cn as D } from "../../../lib/utils.js";
4
+ import { Setting as F, inputCls as K } from "./controls.js";
5
+ import { column as L, changeLabel as s } from "./section-props.js";
6
+ function H({
7
+ k: e,
8
+ props: n,
9
+ placeholder: p,
10
+ sanitize: m,
11
+ disabled: T,
12
+ mono: v,
13
+ extra: y,
14
+ note: S,
15
+ blurOnly: r = !1
16
+ }) {
17
+ const f = L(e), g = n.layout[f], c = g == null ? "" : String(g), d = `setting-${f}`, [E, R] = C(null), u = a(null), l = a(null), i = (t) => {
18
+ u.current = t, R(t);
19
+ }, o = (t) => ({ [f]: t === "" ? null : t }), b = (t) => {
20
+ l.current === null && (l.current = c), i(t), r || n.setText(o(t), s(e));
21
+ }, j = () => {
22
+ const t = u.current;
23
+ i(null), l.current = null, r && t !== null && t !== c && n.set(o(t), s(e)), n.flush();
24
+ }, x = a(() => {
25
+ });
26
+ x.current = () => {
27
+ const t = u.current;
28
+ r && t !== null && t !== c && n.set(o(t), s(e));
29
+ }, N(() => () => x.current(), []);
30
+ const w = () => {
31
+ const t = l.current;
32
+ !r && t !== null && u.current !== t && n.setText(o(t), s(e)), i(null);
33
+ };
34
+ return /* @__PURE__ */ h(F, { k: e, htmlFor: d, note: S, children: /* @__PURE__ */ B("div", { className: "flex items-center gap-1.5", children: [
35
+ /* @__PURE__ */ h(
36
+ "input",
37
+ {
38
+ id: d,
39
+ value: E ?? c,
40
+ disabled: T,
41
+ placeholder: p,
42
+ onChange: (t) => b(m ? m(t.target.value) : t.target.value),
43
+ onBlur: j,
44
+ onKeyDown: (t) => {
45
+ t.key === "Enter" ? t.currentTarget.blur() : t.key === "Escape" && (w(), t.currentTarget.blur());
46
+ },
47
+ className: D(K, v && "font-mono text-[12px]")
48
+ }
49
+ ),
50
+ y
51
+ ] }) });
52
+ }
53
+ export {
54
+ H as TextSetting
55
+ };
@@ -0,0 +1,33 @@
1
+ import { jsx as g } from "react/jsx-runtime";
2
+ import { Setting as i, Toggle as s } from "./controls.js";
3
+ import { column as u, toggleLabel as b, flag as p } from "./section-props.js";
4
+ import { settingDef as h } from "./settings-registry.js";
5
+ function w({
6
+ k: o,
7
+ props: t,
8
+ disabled: c,
9
+ note: m,
10
+ defaultOn: a = !1
11
+ }) {
12
+ var n;
13
+ const e = u(o), l = t.layout[e], f = l == null ? a : p(l);
14
+ return /* @__PURE__ */ g(
15
+ i,
16
+ {
17
+ k: o,
18
+ note: m,
19
+ control: /* @__PURE__ */ g(
20
+ s,
21
+ {
22
+ label: ((n = h(o)) == null ? void 0 : n.label) ?? o,
23
+ checked: f,
24
+ disabled: c,
25
+ onChange: (r) => t.set({ [e]: r }, b(o, r))
26
+ }
27
+ )
28
+ }
29
+ );
30
+ }
31
+ export {
32
+ w as ToggleSetting
33
+ };
@@ -0,0 +1,179 @@
1
+ import { jsxs as m, Fragment as b, jsx as e } from "react/jsx-runtime";
2
+ import { useQuery as C } from "@tanstack/react-query";
3
+ import { ExternalLink as I } from "lucide-react";
4
+ import { useState as x, useRef as R, useEffect as N } from "react";
5
+ import { useNivaroClient as P } from "../../../context.js";
6
+ import { get as A } from "../../../lib/commands.js";
7
+ import { cn as p } from "../../../lib/utils.js";
8
+ import { HistoryPanel as L } from "../HistoryPanel.js";
9
+ import { useLayoutEditorHost as _ } from "../host.js";
10
+ import { useRoleNames as T } from "../overview/overview-api.js";
11
+ import { tintCard as q, labelText as E } from "../panel-style.js";
12
+ import { RelationPicker as F } from "../pickers/relation-picker.js";
13
+ import { Setting as y, smallBtn as S, quietText as f, PickList as j, useSettingVisible as g } from "./controls.js";
14
+ import { useRolePreview as D } from "./settings-api.js";
15
+ import { settingDef as v } from "./settings-registry.js";
16
+ function le(t) {
17
+ const l = Number(t.layout.id);
18
+ return /* @__PURE__ */ m(b, { children: [
19
+ /* @__PURE__ */ e(H, { ...t }),
20
+ /* @__PURE__ */ e(B, { ...t }),
21
+ /* @__PURE__ */ e(k, { k: "tool.describe", layoutId: l }),
22
+ /* @__PURE__ */ e(k, { k: "tool.ai_review", layoutId: l }),
23
+ /* @__PURE__ */ e(K, { layoutId: l }),
24
+ /* @__PURE__ */ e(Q, { layoutId: l })
25
+ ] });
26
+ }
27
+ function H({ collection: t, layout: l }) {
28
+ const o = _(), [i, n] = x(null), r = l.slug ? String(l.slug) : null, c = i ? `${o.recordLink(t, i)}${r ? `?layout=${encodeURIComponent(r)}` : ""}` : null;
29
+ return /* @__PURE__ */ e(
30
+ y,
31
+ {
32
+ k: "tool.preview_record",
33
+ note: r ? `The record opens pinned to this layout (?layout=${r}).` : "Without a link name the record opens on whichever layout it resolves to.",
34
+ children: /* @__PURE__ */ m("div", { className: "flex flex-wrap items-center gap-1.5", children: [
35
+ /* @__PURE__ */ e("div", { className: "min-w-[180px] flex-1", children: /* @__PURE__ */ e(
36
+ F,
37
+ {
38
+ relatedCollection: t,
39
+ value: i,
40
+ onChange: (s) => n(s == null || s === "" ? null : String(s)),
41
+ placeholder: "Pick a record…"
42
+ }
43
+ ) }),
44
+ /* @__PURE__ */ m(
45
+ "a",
46
+ {
47
+ href: c ?? void 0,
48
+ target: "_blank",
49
+ rel: "noreferrer",
50
+ "aria-disabled": !c,
51
+ "data-layout-record-preview-open": !0,
52
+ className: p(S, !c && "pointer-events-none opacity-40"),
53
+ children: [
54
+ /* @__PURE__ */ e(I, { className: "h-3.5 w-3.5" }),
55
+ "Open in a new tab"
56
+ ]
57
+ }
58
+ )
59
+ ] })
60
+ }
61
+ );
62
+ }
63
+ function O(t, l) {
64
+ var r;
65
+ if (t.role.admin_access)
66
+ return `As ${t.role.name}: admin — default layout, every field.`;
67
+ if (!t.can_read) return `As ${t.role.name}: cannot read ${l} at all.`;
68
+ const o = [`gets “${((r = t.layout) == null ? void 0 : r.name) ?? "no layout"}”`], i = t.hidden_fields.length, n = t.readonly_fields.length;
69
+ return i && o.push(`${i} field${i === 1 ? "" : "s"} hidden`), n && o.push(`${n} read-only`), t.can_update || o.push("cannot edit"), `As ${t.role.name}: ${o.join(" · ")}`;
70
+ }
71
+ function B({
72
+ collection: t,
73
+ onPreviewRole: l,
74
+ previewRoleId: o,
75
+ onPreviewRoleChange: i
76
+ }) {
77
+ const { data: n = [] } = T(!0), [r, c] = x(null), s = i ? o ?? null : r, h = i ?? c, { data: a = null, isFetching: $ } = D(t, s), u = R(l);
78
+ return u.current = l, N(() => {
79
+ var d;
80
+ (d = u.current) == null || d.call(u, s ? a : null);
81
+ }, [s, a]), N(() => () => {
82
+ var d;
83
+ return (d = u.current) == null ? void 0 : d.call(u, null);
84
+ }, []), /* @__PURE__ */ e(
85
+ y,
86
+ {
87
+ k: "tool.preview_as_role",
88
+ control: /* @__PURE__ */ e(
89
+ j,
90
+ {
91
+ ariaLabel: "Preview as role",
92
+ value: s,
93
+ options: [...n].sort((d, w) => d.name.localeCompare(w.name)).map((d) => ({ value: d.id, label: d.name })),
94
+ clearLabel: "Nobody (off)",
95
+ onChange: h
96
+ }
97
+ ),
98
+ children: s && /* @__PURE__ */ e("div", { "data-role-preview": !0, className: p(q, "p-3 text-[12px]"), children: $ && !a ? /* @__PURE__ */ e("p", { className: f, children: "Checking…" }) : a ? /* @__PURE__ */ m(b, { children: [
99
+ /* @__PURE__ */ e(
100
+ "p",
101
+ {
102
+ className: p(
103
+ "text-slate-700 dark:text-foreground",
104
+ !a.can_read && "text-[#9c2f47] dark:text-[#f08aa1]"
105
+ ),
106
+ children: O(a, t)
107
+ }
108
+ ),
109
+ a.note && /* @__PURE__ */ e("p", { className: p("mt-1", f), children: a.note })
110
+ ] }) : /* @__PURE__ */ e("p", { className: f, children: "Could not preview this role." }) })
111
+ }
112
+ );
113
+ }
114
+ function k({ k: t, layoutId: l }) {
115
+ var n, r;
116
+ const o = _(), i = t === "tool.ai_review" ? (n = o.aiReviewSlot) == null ? void 0 : n.call(o, l) : (r = o.explainSlot) == null ? void 0 : r.call(o, {
117
+ kind: "config",
118
+ type: "layout",
119
+ id: l,
120
+ label: "Describe this layout"
121
+ });
122
+ return /* @__PURE__ */ e(y, { k: t, children: i ?? /* @__PURE__ */ e("p", { className: f, children: "Not offered in this app." }) });
123
+ }
124
+ function K({ layoutId: t }) {
125
+ var r, c;
126
+ const l = g("tool.version_history"), o = g("tool.version_diff"), i = g("tool.version_restore");
127
+ if (!l && !o && !i) return null;
128
+ const n = v("tool.version_history");
129
+ return /* @__PURE__ */ m("div", { "data-setting": "tool.version_history", className: "space-y-1.5", children: [
130
+ /* @__PURE__ */ e("p", { className: E, children: n == null ? void 0 : n.label }),
131
+ /* @__PURE__ */ e(L, { layoutId: t }),
132
+ /* @__PURE__ */ m("p", { className: f, children: [
133
+ n == null ? void 0 : n.effect,
134
+ " ",
135
+ (r = v("tool.version_diff")) == null ? void 0 : r.effect,
136
+ " ",
137
+ (c = v("tool.version_restore")) == null ? void 0 : c.effect
138
+ ] })
139
+ ] });
140
+ }
141
+ function Q({ layoutId: t }) {
142
+ const l = P(), [o, i] = x(!1), { data: n, isFetching: r, isError: c, refetch: s } = C({
143
+ queryKey: ["layout-editor", "drift"],
144
+ queryFn: () => l.request(A("/collection-layouts/drift")).then((a) => Array.isArray(a == null ? void 0 : a.data) ? a.data : []),
145
+ enabled: o,
146
+ staleTime: 0
147
+ }), h = n == null ? void 0 : n.find((a) => Number(a.layout_id) === t);
148
+ return /* @__PURE__ */ m(
149
+ y,
150
+ {
151
+ k: "tool.layout_drift",
152
+ control: /* @__PURE__ */ e(
153
+ "button",
154
+ {
155
+ type: "button",
156
+ className: S,
157
+ disabled: r,
158
+ onClick: () => o ? void s() : i(!0),
159
+ children: r ? "Checking…" : "Check now"
160
+ }
161
+ ),
162
+ children: [
163
+ o && !r && c && /* @__PURE__ */ e("p", { className: "text-[12px] text-[#9c2f47] dark:text-[#f08aa1]", children: "The check failed." }),
164
+ o && n && !r && /* @__PURE__ */ e("div", { "data-layout-drift": !0, className: "text-[12px]", children: h ? /* @__PURE__ */ e("ul", { className: "space-y-1", children: h.warnings.map((a) => /* @__PURE__ */ e(
165
+ "li",
166
+ {
167
+ className: "rounded bg-[#fae6eb] px-1.5 py-1 text-[#9c2f47] dark:bg-[#3d1621] dark:text-[#f08aa1]",
168
+ children: a
169
+ },
170
+ a
171
+ )) }) : /* @__PURE__ */ e("p", { className: f, children: "No drift: the layout matches its last saved version." }) })
172
+ ]
173
+ }
174
+ );
175
+ }
176
+ export {
177
+ le as ToolsSection,
178
+ O as rolePreviewSummary
179
+ };