@kayr/umbika-web-renderer 0.0.0-stage → 0.1.0

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -2
  3. package/THIRD_PARTY_LICENSES.txt +20 -0
  4. package/dist/browser/umbika.min.css +23 -0
  5. package/dist/browser/umbika.min.d.mts +437 -0
  6. package/dist/browser/umbika.min.d.ts +437 -0
  7. package/dist/browser/umbika.min.js +60 -0
  8. package/dist/browser/umbika.min.mjs +60 -0
  9. package/dist/casconda.d.ts +2 -0
  10. package/dist/casconda.d.ts.map +1 -0
  11. package/dist/contracts.d.ts +165 -0
  12. package/dist/contracts.d.ts.map +1 -0
  13. package/dist/dom-identity.d.ts +17 -0
  14. package/dist/dom-identity.d.ts.map +1 -0
  15. package/dist/field-presentation.d.ts +26 -0
  16. package/dist/field-presentation.d.ts.map +1 -0
  17. package/dist/index.d.ts +16 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/layout.d.ts +25 -0
  20. package/dist/layout.d.ts.map +1 -0
  21. package/dist/mount.d.ts +14 -0
  22. package/dist/mount.d.ts.map +1 -0
  23. package/dist/render-nodes.d.ts +18 -0
  24. package/dist/render-nodes.d.ts.map +1 -0
  25. package/dist/renderers/multi-select.d.ts +18 -0
  26. package/dist/renderers/multi-select.d.ts.map +1 -0
  27. package/dist/renderers/object.d.ts +6 -0
  28. package/dist/renderers/object.d.ts.map +1 -0
  29. package/dist/renderers/output.d.ts +6 -0
  30. package/dist/renderers/output.d.ts.map +1 -0
  31. package/dist/renderers/select.d.ts +6 -0
  32. package/dist/renderers/select.d.ts.map +1 -0
  33. package/dist/renderers/table.d.ts +6 -0
  34. package/dist/renderers/table.d.ts.map +1 -0
  35. package/dist/renderers/text.d.ts +8 -0
  36. package/dist/renderers/text.d.ts.map +1 -0
  37. package/dist/row-details.d.ts +89 -0
  38. package/dist/row-details.d.ts.map +1 -0
  39. package/dist/standalone/contracts.d.ts +77 -0
  40. package/dist/standalone/contracts.d.ts.map +1 -0
  41. package/dist/standalone/index.d.ts +7 -0
  42. package/dist/standalone/index.d.ts.map +1 -0
  43. package/dist/standalone/mount.d.ts +9 -0
  44. package/dist/standalone/mount.d.ts.map +1 -0
  45. package/dist/summary.d.ts +29 -0
  46. package/dist/summary.d.ts.map +1 -0
  47. package/dist/tags.d.ts +32 -0
  48. package/dist/tags.d.ts.map +1 -0
  49. package/package.json +78 -4
  50. package/src/casconda.js +10 -0
  51. package/src/contracts.js +79 -0
  52. package/src/dom-identity.js +31 -0
  53. package/src/field-presentation.js +71 -0
  54. package/src/index.js +9 -0
  55. package/src/layout.js +176 -0
  56. package/src/mount.js +569 -0
  57. package/src/render-nodes.js +77 -0
  58. package/src/renderers/multi-select.js +211 -0
  59. package/src/renderers/object.js +43 -0
  60. package/src/renderers/output.js +87 -0
  61. package/src/renderers/select.js +104 -0
  62. package/src/renderers/table.js +344 -0
  63. package/src/renderers/text.js +82 -0
  64. package/src/row-details.js +305 -0
  65. package/src/standalone/contracts.js +22 -0
  66. package/src/standalone/index.js +5 -0
  67. package/src/standalone/mount.js +128 -0
  68. package/src/summary.js +135 -0
  69. package/src/tags.js +69 -0
  70. package/styles/base.css +432 -0
  71. package/styles/standalone.css +2 -0
  72. package/styles/themes/default.css +99 -0
  73. package/vendor/LICENSE +21 -0
  74. package/vendor/README.md +33 -0
  75. package/vendor/casconda.min.d.mts +340 -0
  76. package/vendor/casconda.min.d.ts +340 -0
  77. package/vendor/casconda.min.mjs +1 -0
@@ -0,0 +1,305 @@
1
+ import { computed } from "./casconda.js";
2
+ import { _structuralDomId } from "./dom-identity.js";
3
+ import { _tableLayoutAt } from "./layout.js";
4
+ import { _primarySummaryValue, _summaryColumns } from "./summary.js";
5
+ import { button, dialog, div, foreach, h3, p } from "./tags.js";
6
+
7
+ /**
8
+ * @typedef {Readonly<{
9
+ * row: import("@kayr/umbika-core").ActiveTableRow;
10
+ * definitionPath: readonly string[];
11
+ * parentRowPath: import("@kayr/umbika-core").FieldPath | undefined;
12
+ * table: import("@kayr/umbika-core").ActiveTableField;
13
+ * tableName: string;
14
+ * }>} ResolvedRowDetail
15
+ */
16
+ /** @typedef {Readonly<{detail: ResolvedRowDetail, frame: import("./contracts.js").WorkspaceFrame, depth: number}>} WorkspaceDetail */
17
+
18
+ /**
19
+ * @param {readonly import("@kayr/umbika-core").ActiveFieldNode[]} nodes
20
+ * @param {readonly string[]} rowPath
21
+ * @returns {ResolvedRowDetail | undefined}
22
+ */
23
+ export function _resolveRowDetail(nodes, rowPath) {
24
+ return _findRow(nodes, rowPath, [], []);
25
+ }
26
+
27
+ /**
28
+ * @param {readonly import("@kayr/umbika-core").ActiveFieldNode[]} nodes
29
+ * @param {import("./contracts.js").WorkspaceState | null} workspace
30
+ */
31
+ export function _reconcileWorkspace(nodes, workspace) {
32
+ if (!workspace) return null;
33
+ const frames = [];
34
+ for (const frame of workspace.frames) {
35
+ if (!_resolveRowDetail(nodes, frame.rowPath)) break;
36
+ frames.push(frame);
37
+ }
38
+ return frames.length > 0
39
+ ? Object.freeze({ frames: Object.freeze(frames) })
40
+ : null;
41
+ }
42
+
43
+ /**
44
+ * Derive workspace language from the current active tree. Frames remain paths
45
+ * and origins only, so refresh always observes current labels and summaries.
46
+ *
47
+ * @param {readonly import("@kayr/umbika-core").ActiveFieldNode[]} nodes
48
+ * @param {import("./contracts.js").WorkspaceState | null} workspace
49
+ * @param {import("./contracts.js").OwnedWebFormLayout} layout
50
+ */
51
+ export function _workspacePresentation(nodes, workspace, layout) {
52
+ if (!workspace?.frames.length) return null;
53
+ const entries = [];
54
+ for (const frame of workspace.frames) {
55
+ const detail = _resolveRowDetail(nodes, frame.rowPath);
56
+ if (!detail) break;
57
+ const columns = _summaryColumns(
58
+ [detail.row],
59
+ _tableLayoutAt(layout, detail.definitionPath)?.columns,
60
+ );
61
+ const primary = _primarySummaryValue(detail.row, columns);
62
+ entries.push({ detail, frame, primary });
63
+ }
64
+ const current = entries.at(-1);
65
+ if (!current) return null;
66
+ const fallback = `${current.detail.tableName} row`;
67
+ const currentName = current.primary.available
68
+ ? current.primary.display
69
+ : fallback;
70
+ const isNew = current.frame.origin === "new";
71
+ return Object.freeze({
72
+ current: Object.freeze({ ...current, name: currentName }),
73
+ depth: entries.length,
74
+ title: isNew
75
+ ? `Add row to ${current.detail.tableName}`
76
+ : `Edit ${currentName}`,
77
+ trail: Object.freeze(
78
+ entries.flatMap((entry) => [
79
+ entry.detail.tableName,
80
+ entry.primary.available
81
+ ? entry.primary.display
82
+ : `${entry.detail.tableName} row`,
83
+ ]),
84
+ ),
85
+ secondary: isNew ? "cancel" : entries.length > 1 ? "back" : "close",
86
+ });
87
+ }
88
+
89
+ /**
90
+ * @param {ReturnType<typeof import("./casconda.js").ref>} workspace
91
+ * @param {ReturnType<typeof import("./casconda.js").ref>} activeFields
92
+ * @param {import("./contracts.js").NodeRendererContext} context
93
+ * @param {Readonly<{close: () => void, back: () => void, add: () => void, cancel: () => void, remove: () => void, escape: () => void}>} actions
94
+ */
95
+ export function _renderRowDetails(workspace, activeFields, context, actions) {
96
+ const titleId = _structuralDomId(context.instanceId, "workspace-title", [
97
+ "active-row",
98
+ ]);
99
+ const locationId = _structuralDomId(
100
+ context.instanceId,
101
+ "workspace-location",
102
+ ["active-row"],
103
+ );
104
+ const presentations = computed(
105
+ () => {
106
+ const current =
107
+ /** @type {import("./contracts.js").WorkspaceState | null} */ (
108
+ workspace.get()
109
+ );
110
+ const presentation = _workspacePresentation(
111
+ activeFields.get(),
112
+ current,
113
+ context.layout,
114
+ );
115
+ return presentation ? [presentation] : [];
116
+ },
117
+ workspace,
118
+ activeFields,
119
+ );
120
+
121
+ return dialog(
122
+ {
123
+ class: "umbika-workspace",
124
+ "aria-labelledby": titleId,
125
+ "aria-describedby": locationId,
126
+ oncancel: (/** @type {Event} */ event) => {
127
+ event.preventDefault();
128
+ actions.escape();
129
+ },
130
+ },
131
+ div(
132
+ { class: "umbika-workspace__contents" },
133
+ foreach(
134
+ {
135
+ id: (/** @type {any} */ entry) =>
136
+ _detailKey(entry.current.frame.rowPath),
137
+ resource: true,
138
+ },
139
+ presentations,
140
+ (
141
+ /** @type {ReturnType<typeof _workspacePresentation> & {}} */ initial,
142
+ /** @type {number} */ _index,
143
+ /** @type {import("./contracts.js").KeyedItemResource<any>} */ detailResource,
144
+ ) => {
145
+ const fields = computed(
146
+ () => detailResource.get()?.current.detail.row.children ?? [],
147
+ detailResource,
148
+ );
149
+ const current = initial.current;
150
+ return div(
151
+ {
152
+ class:
153
+ current.frame.origin === "new"
154
+ ? "umbika-workspace__panel umbika-workspace__panel--new"
155
+ : "umbika-workspace__panel",
156
+ "data-umbika-workspace-depth": String(initial.depth),
157
+ },
158
+ div(
159
+ { class: "umbika-workspace__header" },
160
+ h3(
161
+ {
162
+ id: titleId,
163
+ class: "umbika-workspace__title",
164
+ tabindex: "-1",
165
+ },
166
+ initial.title,
167
+ ),
168
+ p(
169
+ {
170
+ id: locationId,
171
+ class: "umbika-workspace__hierarchy",
172
+ "aria-label": "Workspace hierarchy",
173
+ },
174
+ initial.trail.join(" / "),
175
+ ),
176
+ current.frame.origin === "existing"
177
+ ? div(
178
+ {
179
+ class:
180
+ "umbika-workspace__actions umbika-workspace__navigation",
181
+ },
182
+ initial.depth > 1
183
+ ? button(
184
+ {
185
+ type: "button",
186
+ class: "umbika-workspace__back",
187
+ onclick: actions.back,
188
+ },
189
+ "Back",
190
+ )
191
+ : "",
192
+ button(
193
+ {
194
+ type: "button",
195
+ class: "umbika-workspace__done",
196
+ onclick: actions.close,
197
+ },
198
+ "Close",
199
+ ),
200
+ )
201
+ : "",
202
+ ),
203
+ div(
204
+ { class: "umbika-workspace__fields" },
205
+ context.renderNodes(fields, current.detail.definitionPath),
206
+ ),
207
+ current.frame.origin === "new"
208
+ ? div(
209
+ { class: "umbika-workspace__confirmation-footer" },
210
+ button(
211
+ {
212
+ type: "button",
213
+ class: "umbika-workspace__discard",
214
+ onpointerdown: (/** @type {PointerEvent} */ event) =>
215
+ event.preventDefault(),
216
+ onclick: actions.cancel,
217
+ },
218
+ "Cancel",
219
+ ),
220
+ button(
221
+ {
222
+ type: "button",
223
+ class: "umbika-workspace__keep",
224
+ onclick: actions.add,
225
+ },
226
+ `Add row to ${current.detail.tableName}`,
227
+ ),
228
+ )
229
+ : div(
230
+ { class: "umbika-workspace__danger-area" },
231
+ button(
232
+ {
233
+ type: "button",
234
+ class: "umbika-workspace__remove",
235
+ "aria-label": `Remove ${current.name} from ${current.detail.tableName}`,
236
+ onpointerdown: (/** @type {PointerEvent} */ event) =>
237
+ event.preventDefault(),
238
+ onclick: actions.remove,
239
+ },
240
+ "Remove row",
241
+ ),
242
+ ),
243
+ );
244
+ },
245
+ ),
246
+ ),
247
+ );
248
+ }
249
+
250
+ /** @param {readonly string[]} path */
251
+ function _detailKey(path) {
252
+ return path.map((segment) => `${segment.length}:${segment}`).join("|");
253
+ }
254
+
255
+ /**
256
+ * @param {readonly import("@kayr/umbika-core").ActiveFieldNode[]} nodes
257
+ * @param {readonly string[]} wantedPath
258
+ * @param {readonly string[]} definitionParent
259
+ * @param {readonly import("@kayr/umbika-core").FieldPath[]} rowAncestors
260
+ * @returns {ResolvedRowDetail | undefined}
261
+ */
262
+ function _findRow(nodes, wantedPath, definitionParent, rowAncestors) {
263
+ for (const node of nodes) {
264
+ const definitionPath = [...definitionParent, node.id];
265
+ if (node.type === "object") {
266
+ const found = _findRow(
267
+ node.children,
268
+ wantedPath,
269
+ definitionPath,
270
+ rowAncestors,
271
+ );
272
+ if (found) return found;
273
+ continue;
274
+ }
275
+ if (node.type !== "table") continue;
276
+ for (const row of node.rows) {
277
+ const ancestors = [...rowAncestors, row.path];
278
+ if (_pathsEqual(row.path, wantedPath)) {
279
+ return Object.freeze({
280
+ row,
281
+ definitionPath: Object.freeze(definitionPath),
282
+ parentRowPath: rowAncestors.at(-1),
283
+ table: node,
284
+ tableName: node.label ?? node.id,
285
+ });
286
+ }
287
+ const found = _findRow(
288
+ row.children,
289
+ wantedPath,
290
+ definitionPath,
291
+ ancestors,
292
+ );
293
+ if (found) return found;
294
+ }
295
+ }
296
+ return undefined;
297
+ }
298
+
299
+ /** @param {readonly string[]} left @param {readonly string[]} right */
300
+ function _pathsEqual(left, right) {
301
+ return (
302
+ left.length === right.length &&
303
+ left.every((segment, index) => segment === right[index])
304
+ );
305
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @typedef {object} StandaloneMountOptions
3
+ * @property {string} source Authored version-1 form source.
4
+ * @property {import("@kayr/umbika-core").FormVars} [vars] Immutable supporting values.
5
+ * @property {import("@kayr/umbika-core").FormValues} [data] Initial answer data.
6
+ * @property {string} [instanceId] Host-supplied renderer identity prefix.
7
+ * @property {import("../index.js").WebFormLayout} [layout] Renderer-owned repeat presentation.
8
+ * @property {string} [theme] Renderer-owned root theme name.
9
+ * @property {(submission: Record<string, unknown>) => void} [onSubmit] Receives valid projected submission data.
10
+ * @property {string} [submitLabel] Non-empty native submit-button label.
11
+ */
12
+
13
+ /**
14
+ * @typedef {object} MountedStandaloneWebForm
15
+ * @property {import("@kayr/umbika-core").Form} form Ordinary form-engine instance.
16
+ * @property {HTMLFormElement} root Renderer-owned form root.
17
+ * @property {() => void} refresh Publish current engine state to the renderer.
18
+ * @property {(path: import("@kayr/umbika-core").FieldPath) => boolean} focus Focus an active editable field.
19
+ * @property {() => void} dispose Release presentation resources. Repeated calls do nothing.
20
+ */
21
+
22
+ export {};
@@ -0,0 +1,5 @@
1
+ export { FormLanguageError } from "@kayr/umbika-core/language";
2
+ export { mount } from "./mount.js";
3
+
4
+ /** @typedef {import("./contracts.js").MountedStandaloneWebForm} MountedStandaloneWebForm */
5
+ /** @typedef {import("./contracts.js").StandaloneMountOptions} StandaloneMountOptions */
@@ -0,0 +1,128 @@
1
+ import { mountWebForm } from "../index.js";
2
+ import { createLanguageForm } from "@kayr/umbika-core/language";
3
+
4
+ /**
5
+ * Compile authored source and mount the complete browser form.
6
+ *
7
+ * @param {string | HTMLElement} target
8
+ * @param {import("./contracts.js").StandaloneMountOptions} options
9
+ * @returns {import("./contracts.js").MountedStandaloneWebForm}
10
+ */
11
+ export function mount(target, options) {
12
+ const host = resolveTarget(target);
13
+ const validated = validateOptions(options);
14
+ const form = createLanguageForm({
15
+ source: validated.source,
16
+ ...(validated.vars === undefined ? {} : { vars: validated.vars }),
17
+ ...(validated.data === undefined ? {} : { data: validated.data }),
18
+ });
19
+ const onSubmit = validated.onSubmit;
20
+ const submitButton = createSubmitButton(onSubmit, validated.submitLabel);
21
+ const renderer = mountWebForm(host, {
22
+ form,
23
+ ...(validated.instanceId === undefined
24
+ ? {}
25
+ : { instanceId: validated.instanceId }),
26
+ ...(validated.layout === undefined ? {} : { layout: validated.layout }),
27
+ ...(validated.theme === undefined ? {} : { theme: validated.theme }),
28
+ ...(onSubmit === undefined
29
+ ? {}
30
+ : {
31
+ onSubmit: ({ validation }) => {
32
+ if (validation.valid) {
33
+ onSubmit(form.getSubmissionData());
34
+ }
35
+ },
36
+ }),
37
+ });
38
+
39
+ try {
40
+ if (submitButton) renderer.root.append(submitButton);
41
+ } catch (cause) {
42
+ disposeSubmitButton(submitButton);
43
+ renderer.dispose();
44
+ throw cause;
45
+ }
46
+
47
+ return {
48
+ form,
49
+ root: renderer.root,
50
+ refresh: () => renderer.refresh(),
51
+ focus: (path) => renderer.focus(path),
52
+ dispose() {
53
+ disposeSubmitButton(submitButton);
54
+ renderer.dispose();
55
+ },
56
+ };
57
+ }
58
+
59
+ /** @param {string | HTMLElement} target */
60
+ function resolveTarget(target) {
61
+ const candidate =
62
+ typeof target === "string" ? document.querySelector(target) : target;
63
+ if (!(candidate instanceof HTMLElement)) {
64
+ throw new TypeError("target must resolve to an HTMLElement");
65
+ }
66
+ return candidate;
67
+ }
68
+
69
+ /** @param {unknown} options */
70
+ function validateOptions(options) {
71
+ if (!isRecord(options)) throw new TypeError("options must be an object");
72
+ if (typeof options.source !== "string") {
73
+ throw new TypeError("options.source must be a string");
74
+ }
75
+ if (options.vars !== undefined && !isRecord(options.vars)) {
76
+ throw new TypeError("options.vars must be an object");
77
+ }
78
+ if (options.data !== undefined && !isRecord(options.data)) {
79
+ throw new TypeError("options.data must be an object");
80
+ }
81
+ if (
82
+ options.onSubmit !== undefined &&
83
+ typeof options.onSubmit !== "function"
84
+ ) {
85
+ throw new TypeError("options.onSubmit must be a function");
86
+ }
87
+ if (
88
+ options.submitLabel !== undefined &&
89
+ (typeof options.submitLabel !== "string" ||
90
+ options.submitLabel.trim() === "")
91
+ ) {
92
+ throw new TypeError("options.submitLabel must be a non-empty string");
93
+ }
94
+ return /** @type {import("./contracts.js").StandaloneMountOptions} */ (
95
+ options
96
+ );
97
+ }
98
+
99
+ /**
100
+ * @param {((submission: Record<string, unknown>) => void) | undefined} onSubmit
101
+ * @param {string | undefined} submitLabel
102
+ */
103
+ function createSubmitButton(onSubmit, submitLabel) {
104
+ if (!onSubmit) return undefined;
105
+ const button = document.createElement("button");
106
+ button.type = "submit";
107
+ button.className = "umbika-action umbika-standalone-submit";
108
+ button.textContent = submitLabel ?? "Submit";
109
+ button.addEventListener("mousedown", preserveFocusedDraft);
110
+ return button;
111
+ }
112
+
113
+ /** @param {Event} event */
114
+ function preserveFocusedDraft(event) {
115
+ event.preventDefault();
116
+ }
117
+
118
+ /** @param {HTMLButtonElement | undefined} button */
119
+ function disposeSubmitButton(button) {
120
+ if (!button) return;
121
+ button.removeEventListener("mousedown", preserveFocusedDraft);
122
+ button.remove();
123
+ }
124
+
125
+ /** @param {unknown} value @returns {value is Record<string, any>} */
126
+ function isRecord(value) {
127
+ return typeof value === "object" && value !== null && !Array.isArray(value);
128
+ }
package/src/summary.js ADDED
@@ -0,0 +1,135 @@
1
+ import { _displayValue } from "./field-presentation.js";
2
+
3
+ /** @param {readonly import("@kayr/umbika-core").ActiveFieldNode[]} nodes */
4
+ export function _visibleErrorCount(nodes) {
5
+ let count = 0;
6
+ for (const node of nodes) {
7
+ count += node.errors.length;
8
+ if (node.type === "object") {
9
+ count += _visibleErrorCount(node.children);
10
+ } else if (node.type === "table") {
11
+ for (const row of node.rows) count += _visibleErrorCount(row.children);
12
+ }
13
+ }
14
+ return count;
15
+ }
16
+
17
+ /**
18
+ * @param {readonly import("@kayr/umbika-core").ActiveTableRow[]} rows
19
+ * @param {readonly import("./contracts.js").OwnedWebTableColumnLayout[] | undefined} configured
20
+ */
21
+ export function _summaryColumns(rows, configured) {
22
+ if (configured) return configured;
23
+
24
+ /** @type {import("./contracts.js").OwnedWebTableColumnLayout[]} */
25
+ const columns = [];
26
+ const seen = new Set();
27
+ for (const row of rows) {
28
+ _appendColumns(row.children, [], columns, seen);
29
+ if (columns.length === 4) break;
30
+ }
31
+ return columns;
32
+ }
33
+
34
+ /**
35
+ * @param {import("@kayr/umbika-core").ActiveTableRow} row
36
+ * @param {readonly string[]} relativePath
37
+ */
38
+ export function _summaryValueAt(row, relativePath) {
39
+ const field = _leafAt(row.children, relativePath);
40
+ if (!field) return { available: false, display: "—" };
41
+
42
+ const value = _summaryFieldValue(field);
43
+ return { available: true, display: _displayValue(value) };
44
+ }
45
+
46
+ /**
47
+ * @param {import("@kayr/umbika-core").ActiveTableRow} row
48
+ * @param {readonly import("./contracts.js").OwnedWebTableColumnLayout[]} columns
49
+ */
50
+ export function _primarySummaryValue(row, columns) {
51
+ for (const column of columns) {
52
+ const value = _summaryValueAt(row, column.path);
53
+ if (value.available) return value;
54
+ }
55
+ return { available: false, display: "row" };
56
+ }
57
+
58
+ /**
59
+ * @param {readonly import("@kayr/umbika-core").ActiveFieldNode[]} nodes
60
+ * @param {readonly string[]} parentPath
61
+ * @param {import("./contracts.js").OwnedWebTableColumnLayout[]} columns
62
+ * @param {Set<string>} seen
63
+ */
64
+ function _appendColumns(nodes, parentPath, columns, seen) {
65
+ for (const node of nodes) {
66
+ if (columns.length === 4) return;
67
+ const path = [...parentPath, node.id];
68
+ if (node.type === "object") {
69
+ _appendColumns(node.children, path, columns, seen);
70
+ continue;
71
+ }
72
+ if (node.type === "table") continue;
73
+
74
+ const key = _columnKey(path);
75
+ if (seen.has(key)) continue;
76
+ seen.add(key);
77
+ columns.push(
78
+ Object.freeze({
79
+ key,
80
+ path: Object.freeze(path),
81
+ label: node.label,
82
+ align: "start",
83
+ }),
84
+ );
85
+ }
86
+ }
87
+
88
+ /**
89
+ * @param {readonly import("@kayr/umbika-core").ActiveFieldNode[]} nodes
90
+ * @param {readonly string[]} path
91
+ * @returns {import("@kayr/umbika-core").ActiveField | undefined}
92
+ */
93
+ function _leafAt(nodes, path) {
94
+ const [id, ...remaining] = path;
95
+ if (id === undefined) return undefined;
96
+ const node = nodes.find((candidate) => candidate.id === id);
97
+ if (!node) return undefined;
98
+ if (remaining.length > 0) {
99
+ return node.type === "object"
100
+ ? _leafAt(node.children, remaining)
101
+ : undefined;
102
+ }
103
+ return node.type === "text" ||
104
+ node.type === "select" ||
105
+ node.type === "multi-select" ||
106
+ node.type === "calculated"
107
+ ? node
108
+ : undefined;
109
+ }
110
+
111
+ /** @param {import("@kayr/umbika-core").ActiveField} field */
112
+ function _summaryFieldValue(field) {
113
+ if (field.type === "select") {
114
+ return (
115
+ field.options.find((option) => option.value === field.value)?.label ??
116
+ field.value
117
+ );
118
+ }
119
+ if (field.type !== "multi-select" || !Array.isArray(field.value)) {
120
+ return field.value;
121
+ }
122
+ return field.value
123
+ .map((value) =>
124
+ typeof value === "string"
125
+ ? (field.options.find((option) => option.value === value)?.label ??
126
+ `${value} (unavailable)`)
127
+ : String(value),
128
+ )
129
+ .join(", ");
130
+ }
131
+
132
+ /** @param {readonly string[]} path */
133
+ function _columnKey(path) {
134
+ return path.map((segment) => `${segment.length}:${segment}`).join("|");
135
+ }
package/src/tags.js ADDED
@@ -0,0 +1,69 @@
1
+ import { tags } from "./casconda.js";
2
+
3
+ /** @typedef {(...children: any[]) => any[]} TagFactory */
4
+
5
+ /**
6
+ * Keep the vendor declaration's dynamic proxy cast at one private boundary.
7
+ *
8
+ * @typedef {object} DirectRendererTags
9
+ * @property {TagFactory} article
10
+ * @property {TagFactory} button
11
+ * @property {TagFactory} caption
12
+ * @property {TagFactory} dialog
13
+ * @property {TagFactory} div
14
+ * @property {TagFactory} fieldset
15
+ * @property {TagFactory} foreach
16
+ * @property {TagFactory} form
17
+ * @property {TagFactory} frag
18
+ * @property {TagFactory} h2
19
+ * @property {TagFactory} h3
20
+ * @property {TagFactory} input
21
+ * @property {TagFactory} label
22
+ * @property {TagFactory} legend
23
+ * @property {TagFactory} li
24
+ * @property {TagFactory} option
25
+ * @property {TagFactory} output
26
+ * @property {TagFactory} p
27
+ * @property {TagFactory} section
28
+ * @property {TagFactory} select
29
+ * @property {TagFactory} ul
30
+ * @property {TagFactory} table
31
+ * @property {TagFactory} tbody
32
+ * @property {TagFactory} td
33
+ * @property {TagFactory} th
34
+ * @property {TagFactory} thead
35
+ * @property {TagFactory} tr
36
+ */
37
+
38
+ /** @type {DirectRendererTags} */
39
+ const _tags = /** @type {DirectRendererTags} */ (tags);
40
+
41
+ export const {
42
+ article,
43
+ button,
44
+ caption,
45
+ dialog,
46
+ div,
47
+ fieldset,
48
+ foreach,
49
+ form,
50
+ frag,
51
+ h2,
52
+ h3,
53
+ input,
54
+ label,
55
+ legend,
56
+ li,
57
+ option,
58
+ output,
59
+ p,
60
+ section,
61
+ select,
62
+ ul,
63
+ table,
64
+ tbody,
65
+ td,
66
+ th,
67
+ thead,
68
+ tr,
69
+ } = _tags;