@object-ui/react 17.6.0 → 17.7.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 (89) hide show
  1. package/CHANGELOG.md +3766 -0
  2. package/README.md +294 -38
  3. package/dist/SchemaRenderer.d.ts +38 -7
  4. package/dist/SchemaRenderer.js +1218 -87
  5. package/dist/context/ActionContext.js +40 -1
  6. package/dist/context/DiscussionContext.d.ts +12 -0
  7. package/dist/context/DiscussionContext.js +2 -0
  8. package/dist/context/DrillNavigationContext.d.ts +13 -0
  9. package/dist/context/InlineEditContext.d.ts +81 -1
  10. package/dist/context/InlineEditContext.js +8 -2
  11. package/dist/context/RecordContext.d.ts +48 -5
  12. package/dist/context/RecordContext.js +10 -1
  13. package/dist/context/RelatedRecordActionsContext.d.ts +5 -1
  14. package/dist/context/SchemaRendererContext.d.ts +54 -2
  15. package/dist/context/SchemaRendererContext.js +38 -5
  16. package/dist/context/ThemeContext.js +1 -1
  17. package/dist/context/actionRunnerTranslator.d.ts +27 -0
  18. package/dist/context/actionRunnerTranslator.js +37 -0
  19. package/dist/element-data-source/ElementDataSourceGate.d.ts +88 -1
  20. package/dist/element-data-source/ElementDataSourceGate.js +326 -13
  21. package/dist/hooks/index.d.ts +3 -1
  22. package/dist/hooks/index.js +10 -1
  23. package/dist/hooks/useActionEngine.js +46 -3
  24. package/dist/hooks/useActionRunner.js +4 -0
  25. package/dist/hooks/useActionTextLocalizer.d.ts +21 -8
  26. package/dist/hooks/useActionTextLocalizer.js +33 -8
  27. package/dist/hooks/useConfigBagEvaluator.d.ts +30 -0
  28. package/dist/hooks/useConfigBagEvaluator.js +39 -0
  29. package/dist/hooks/useDensityMode.d.ts +6 -2
  30. package/dist/hooks/useDensityMode.js +6 -2
  31. package/dist/hooks/useDiscovery.d.ts +1 -10
  32. package/dist/hooks/useETagCache.js +25 -4
  33. package/dist/hooks/useElementDataSource.d.ts +15 -2
  34. package/dist/hooks/useElementDataSource.js +24 -7
  35. package/dist/hooks/useExpression.d.ts +52 -59
  36. package/dist/hooks/useExpression.js +58 -90
  37. package/dist/hooks/useFilterScope.d.ts +22 -2
  38. package/dist/hooks/useFilterScope.js +29 -4
  39. package/dist/hooks/useGlobalUndo.d.ts +10 -0
  40. package/dist/hooks/useGlobalUndo.js +112 -46
  41. package/dist/hooks/useNavigationOverlay.d.ts +76 -11
  42. package/dist/hooks/useNavigationOverlay.js +119 -9
  43. package/dist/hooks/useOffline.js +65 -11
  44. package/dist/hooks/usePageAssignment.d.ts +8 -5
  45. package/dist/hooks/usePageAssignment.js +37 -16
  46. package/dist/hooks/useRecordSearch.d.ts +34 -1
  47. package/dist/hooks/useRecordSearch.js +42 -7
  48. package/dist/hooks/useResolvedFilter.d.ts +46 -0
  49. package/dist/hooks/useResolvedFilter.js +130 -0
  50. package/dist/hooks/useSchemaPersistence.d.ts +7 -0
  51. package/dist/hooks/useSchemaPersistence.js +144 -5
  52. package/dist/hooks/useSettledSchema.d.ts +123 -0
  53. package/dist/hooks/useSettledSchema.js +186 -0
  54. package/dist/hooks/useViewData.d.ts +7 -2
  55. package/dist/index.d.ts +8 -1
  56. package/dist/index.js +45 -1
  57. package/dist/schema-input.d.ts +38 -8
  58. package/dist/schema-input.js +39 -7
  59. package/dist/utils/configBag.d.ts +68 -0
  60. package/dist/utils/configBag.js +70 -0
  61. package/dist/utils/error-message.d.ts +1 -1
  62. package/dist/utils/error-message.js +1 -1
  63. package/dist/utils/inlineAria.d.ts +61 -0
  64. package/dist/utils/inlineAria.js +70 -0
  65. package/dist/utils/nonGridRowCeiling.d.ts +44 -0
  66. package/dist/utils/nonGridRowCeiling.js +78 -0
  67. package/dist/utils/paramsBag.d.ts +28 -0
  68. package/dist/utils/paramsBag.js +146 -0
  69. package/dist/utils/propsBagDiagnostic.d.ts +196 -0
  70. package/dist/utils/propsBagDiagnostic.js +421 -0
  71. package/dist/utils/refusedDataPropDiagnostic.d.ts +44 -0
  72. package/dist/utils/refusedDataPropDiagnostic.js +94 -0
  73. package/dist/utils/unevaluatedExpression.d.ts +42 -1
  74. package/dist/utils/unevaluatedExpression.js +74 -11
  75. package/dist/utils/visibilityDiagnostic.d.ts +271 -19
  76. package/dist/utils/visibilityDiagnostic.js +311 -44
  77. package/package.json +10 -10
  78. package/dist/hooks/useClientNotifications.d.ts +0 -47
  79. package/dist/hooks/useClientNotifications.js +0 -162
  80. package/dist/spec-bridge/SpecBridge.d.ts +0 -28
  81. package/dist/spec-bridge/SpecBridge.js +0 -56
  82. package/dist/spec-bridge/bridges/form-view.d.ts +0 -158
  83. package/dist/spec-bridge/bridges/form-view.js +0 -170
  84. package/dist/spec-bridge/bridges/list-view.d.ts +0 -20
  85. package/dist/spec-bridge/bridges/list-view.js +0 -268
  86. package/dist/spec-bridge/index.d.ts +0 -11
  87. package/dist/spec-bridge/index.js +0 -10
  88. package/dist/spec-bridge/types.d.ts +0 -55
  89. package/dist/spec-bridge/types.js +0 -8
@@ -1,162 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * @object-ui/react - useClientNotifications
10
- *
11
- * Bridge hook between the @objectstack/client notifications API
12
- * and the local NotificationContext state. Fetches server-side
13
- * notifications and surfaces them through the existing provider.
14
- *
15
- * ADR-0030 (Notification Convergence): the `client.notifications.*` helpers
16
- * are the stable transport contract — the server routes them to the L5
17
- * `sys_inbox_message` materialization and the `sys_notification_receipt`
18
- * read-state spine (the re-modeled `sys_notification` L2 event carries no
19
- * recipient/read columns). This hook only needs to call the SDK with its
20
- * current signatures: `list(options)`, `markRead(ids[])`, `markAllRead()`.
21
- *
22
- * The former registerDevice/getPreferences/updatePreferences delegates were
23
- * removed (objectstack#3612): the SDK deleted those methods because the
24
- * /notifications/devices and /notifications/preferences server routes were
25
- * never built — every call was a guaranteed error. They return when the
26
- * server side exists.
27
- */
28
- import { useCallback, useContext, useEffect, useRef, useState } from 'react';
29
- import { SchemaRendererContext } from '../context/SchemaRendererContext.js';
30
- import { useNotifications } from '../context/NotificationContext.js';
31
- /* ------------------------------------------------------------------ */
32
- /* Helpers */
33
- /* ------------------------------------------------------------------ */
34
- /** Normalise severity coming from the server into a valid local level. */
35
- function toSeverity(value) {
36
- const valid = ['info', 'success', 'warning', 'error'];
37
- if (typeof value === 'string' && valid.includes(value)) {
38
- return value;
39
- }
40
- return 'info';
41
- }
42
- /**
43
- * Resolve the ObjectStack client from explicit option or SchemaRendererContext.
44
- *
45
- * The dataSource stored in context is typically an ObjectStackAdapter which
46
- * exposes `getClient()`. When the caller passes a client directly we use
47
- * that instead.
48
- */
49
- function useResolvedClient(explicit) {
50
- const rendererCtx = useContext(SchemaRendererContext);
51
- if (explicit)
52
- return explicit;
53
- const dataSource = rendererCtx?.dataSource;
54
- if (dataSource && typeof dataSource.getClient === 'function') {
55
- return dataSource.getClient();
56
- }
57
- return null;
58
- }
59
- /* ------------------------------------------------------------------ */
60
- /* Hook */
61
- /* ------------------------------------------------------------------ */
62
- /**
63
- * Bridge between the `@objectstack/client` notifications API and the
64
- * local {@link NotificationContext}.
65
- *
66
- * The hook resolves the ObjectStack client either from the explicit
67
- * `client` option or from the `SchemaRendererContext` dataSource, then
68
- * delegates to `client.notifications.*` methods. Fetched notifications
69
- * are fed into the local provider via `useNotifications().notify()`.
70
- *
71
- * @example
72
- * ```tsx
73
- * function NotificationBell() {
74
- * const { fetchNotifications, loading } = useClientNotifications({
75
- * autoFetch: true,
76
- * pollInterval: 30_000,
77
- * });
78
- *
79
- * return <Button onClick={fetchNotifications} disabled={loading}>🔔</Button>;
80
- * }
81
- * ```
82
- */
83
- export function useClientNotifications(options = {}) {
84
- const { client: explicitClient, autoFetch = false, pollInterval = 0 } = options;
85
- const client = useResolvedClient(explicitClient);
86
- const { notify, markAsRead: localMarkAsRead } = useNotifications();
87
- const [loading, setLoading] = useState(false);
88
- const [error, setError] = useState(null);
89
- // Track IDs that have already been pushed into the local context so we
90
- // don't add duplicates on subsequent fetches / polls.
91
- const seenIdsRef = useRef(new Set());
92
- /* ---- fetchNotifications ---- */
93
- const fetchNotifications = useCallback(async () => {
94
- if (!client?.notifications)
95
- return;
96
- setLoading(true);
97
- setError(null);
98
- try {
99
- const result = await client.notifications.list({});
100
- const items = Array.isArray(result) ? result : result?.data ?? result?.items ?? [];
101
- for (const item of items) {
102
- const id = String(item.id ?? '');
103
- if (!id || seenIdsRef.current.has(id))
104
- continue;
105
- seenIdsRef.current.add(id);
106
- notify({
107
- title: item.title ?? 'Notification',
108
- message: item.message ?? item.body,
109
- severity: toSeverity(item.severity ?? item.level),
110
- duration: 0, // server-driven notifications are persistent
111
- });
112
- }
113
- }
114
- catch (err) {
115
- setError(err instanceof Error ? err : new Error('Failed to fetch notifications'));
116
- }
117
- finally {
118
- setLoading(false);
119
- }
120
- }, [client, notify]);
121
- /* ---- markAsRead (server + local) ---- */
122
- const markAsRead = useCallback(async (id) => {
123
- // Optimistically mark locally first
124
- localMarkAsRead(id);
125
- if (!client?.notifications)
126
- return;
127
- setError(null);
128
- try {
129
- // ADR-0030 / @objectstack/client v7+: the SDK exposes `markRead(ids[])`
130
- // (batch) — there is no single-id `markAsRead`. Server-side this writes
131
- // the `read` state to the `sys_notification_receipt` spine. We keep the
132
- // friendly single-id hook API and adapt to the batch call.
133
- await client.notifications.markRead([id]);
134
- }
135
- catch (err) {
136
- const wrapped = err instanceof Error ? err : new Error('Failed to mark as read');
137
- setError(wrapped);
138
- throw wrapped;
139
- }
140
- }, [client, localMarkAsRead]);
141
- /* ---- auto-fetch on mount ---- */
142
- useEffect(() => {
143
- if (autoFetch && client?.notifications) {
144
- fetchNotifications();
145
- }
146
- }, [autoFetch, client, fetchNotifications]);
147
- /* ---- polling ---- */
148
- useEffect(() => {
149
- if (!pollInterval || pollInterval <= 0 || !client?.notifications)
150
- return;
151
- const id = setInterval(() => {
152
- fetchNotifications();
153
- }, pollInterval);
154
- return () => clearInterval(id);
155
- }, [pollInterval, client, fetchNotifications]);
156
- return {
157
- fetchNotifications,
158
- markAsRead,
159
- loading,
160
- error,
161
- };
162
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- import type { BaseSchema } from '@object-ui/types';
9
- import type { BridgeContext, BridgeFn } from './types.js';
10
- export declare class SpecBridge {
11
- private bridges;
12
- private context;
13
- constructor(context?: BridgeContext);
14
- register(specType: string, bridge: BridgeFn): void;
15
- /**
16
- * Transform a spec schema into a schema node tree.
17
- *
18
- * Returns `BaseSchema` rather than `SchemaNode` — see {@link BridgeFn} for
19
- * the ruling (objectui#4580 Q4-B) and the measurement behind it. A registered
20
- * bridge always produces an object; the union only made callers narrow.
21
- */
22
- transform(specType: string, spec: any): BaseSchema;
23
- /** Transform a ListView spec */
24
- transformListView(spec: any): BaseSchema;
25
- /** Transform a FormView spec */
26
- transformFormView(spec: any): BaseSchema;
27
- updateContext(ctx: Partial<BridgeContext>): void;
28
- }
@@ -1,56 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- import { bridgeListView } from './bridges/list-view.js';
9
- import { bridgeFormView } from './bridges/form-view.js';
10
- export class SpecBridge {
11
- constructor(context = {}) {
12
- Object.defineProperty(this, "bridges", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: new Map()
17
- });
18
- Object.defineProperty(this, "context", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: void 0
23
- });
24
- this.context = context;
25
- this.register('list', bridgeListView);
26
- this.register('form', bridgeFormView);
27
- }
28
- register(specType, bridge) {
29
- this.bridges.set(specType, bridge);
30
- }
31
- /**
32
- * Transform a spec schema into a schema node tree.
33
- *
34
- * Returns `BaseSchema` rather than `SchemaNode` — see {@link BridgeFn} for
35
- * the ruling (objectui#4580 Q4-B) and the measurement behind it. A registered
36
- * bridge always produces an object; the union only made callers narrow.
37
- */
38
- transform(specType, spec) {
39
- const bridge = this.bridges.get(specType);
40
- if (!bridge) {
41
- throw new Error(`No bridge registered for spec type: ${specType}`);
42
- }
43
- return bridge(spec, this.context);
44
- }
45
- /** Transform a ListView spec */
46
- transformListView(spec) {
47
- return this.transform('list', spec);
48
- }
49
- /** Transform a FormView spec */
50
- transformFormView(spec) {
51
- return this.transform('form', spec);
52
- }
53
- updateContext(ctx) {
54
- this.context = { ...this.context, ...ctx };
55
- }
56
- }
@@ -1,158 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * Form-view bridge input — the documented SUBSET of `@objectstack/spec`'s
10
- * FormViewSchema this bridge consumes, with every drift-prone key's TYPE bound
11
- * to the contract instead of restated (objectui#5652).
12
- *
13
- * The subset stays hand-listed on purpose: this declaration is load-bearing
14
- * documentation, and its NON-declarations are a retirement ledger
15
- * (`defaultSort` / `aria`, objectui#3901 / #3974) that a blanket
16
- * `Omit<FormView, ...>` would erase. What was never deliberate is the TYPE each
17
- * declared key was given. Three of them had drifted from what the contract
18
- * accepts, and nothing ever compared the two descriptions — the mirror shape
19
- * `scripts/check-spec-symbol-derivation.mjs` exists to catch. The sibling
20
- * bridge in this directory (`list-view.ts`) was converted the same way and for
21
- * the same reason (objectui#2231): the shape derives, so it cannot drift.
22
- *
23
- * ## What the contract actually answers
24
- *
25
- * Measured with `safeParse` against the installed `@objectstack/spec` while
26
- * fixing this, NOT copied from the finding — two of its three rows were wrong,
27
- * in ways that change the repair:
28
- *
29
- * FormSection.columns `1 | 2 | 3 | 4 | '1' | '2' | '3' | '4'`. The string
30
- * arm IS admitted, and the section schema's own pipe
31
- * folds it to a number. The bridge declared `number`
32
- * and refused it.
33
- * FormView.columns `number`, with NO string arm: `FormViewSchema`
34
- * rejects `columns: '3'` at the FORM level while
35
- * `FormSectionSchema` accepts it at the SECTION level.
36
- * The bridge's `number` was already right here — it is
37
- * bound to the contract so the asymmetry cannot rot,
38
- * and the two answers are pinned side by side.
39
- * FormField.dependsOn a BARE parent-field name. The array arm is rejected
40
- * by the contract outright. The bridge declared
41
- * `string[]`, so it admitted only the arm the contract
42
- * refuses and refused the only arm it admits — the one
43
- * configuration that makes `field-selector` and
44
- * `dynamic-config` work (objectui#5040).
45
- * *.visibleWhen `string | { dialect, source?, ast?, meta? }`, with
46
- * `dialect` REQUIRED and enum-typed. `{ dialect?,
47
- * source }` is a DIFFERENT layer's type — the
48
- * evaluator's `FieldRulePredicate` (`@object-ui/core`,
49
- * ADR-0089) — and the contract does not accept it: an
50
- * object arm without `dialect` is refused. The bridge
51
- * declared `string` and refused the object arm
52
- * entirely.
53
- *
54
- * ## Declaring an arm is not consuming it
55
- *
56
- * A key that is declarable but dropped on the way out is the same defect one
57
- * layer over (objectui#5542 / #5594), so each widened arm is followed all the
58
- * way onto the `object-form` node by `FormViewWidenedArms.test.ts`, and the one
59
- * arm that needs a translation to get there gets it — see `normalizeColumns`.
60
- */
61
- import type { DependsOnInput } from '@object-ui/types';
62
- import type { FormFieldInput, FormSection, FormView } from '@objectstack/spec/ui';
63
- import type { BridgeFn } from '../types.js';
64
- /**
65
- * A form field as authored. Exported so the derivation pins in
66
- * `__tests__/FormViewWidenedArms.test.ts` can name the declared types; NOT
67
- * re-exported by `spec-bridge/index.ts`, so the package surface is unchanged.
68
- */
69
- export interface FormFieldSpec {
70
- field: string;
71
- /** Field type (spec FormFieldSchema reuses Data.FieldType; auto-infers widget). */
72
- type?: string;
73
- /** Options for select/multiselect/radio/checkboxes fields. */
74
- options?: any[];
75
- /** Target object name for lookup/master_detail fields. */
76
- reference?: string;
77
- label?: string;
78
- placeholder?: string;
79
- helpText?: string;
80
- readonly?: boolean;
81
- required?: boolean;
82
- hidden?: boolean;
83
- colSpan?: number;
84
- widget?: string;
85
- /**
86
- * Sibling field name whose value this field's widget reads (objectui#5040).
87
- *
88
- * The contract admits a BARE NAME and refuses an array. This is the wider
89
- * {@link DependsOnInput} rather than the contract's `string` alone because
90
- * the value is FORWARDED, unread, into the node slot that is declared with
91
- * exactly this type (`FormField.dependsOn`, `@object-ui/types`) and read by
92
- * `resolveCascadingOptions` / `resolveDependsOnFields` (`@object-ui/core`),
93
- * whose parameter is also exactly this type (framework#4074). Narrowing to
94
- * the contract's `string` would refuse array-authored layouts that the
95
- * runtime has always honoured, on the same never-parsed inputs `groups` and
96
- * `visibleOn` below are still read for. The contract's arm is a subset of
97
- * this one, which is what the derivation pin asserts — so a spec that widens
98
- * `dependsOn` fails the pin instead of silently outgrowing the declaration.
99
- */
100
- dependsOn?: DependsOnInput;
101
- /** Canonical conditional-visibility predicate (ADR-0089), bound to the contract. */
102
- visibleWhen?: FormFieldInput['visibleWhen'];
103
- /** @deprecated ADR-0089 -> `visibleWhen`. */
104
- visibleOn?: FormFieldInput['visibleOn'];
105
- }
106
- /** One section of a form layout, as authored. */
107
- export interface FormSectionSpec {
108
- /** Stable section identifier for i18n lookup (spec FormSectionSchema.name). */
109
- name?: string;
110
- label?: string;
111
- description?: string;
112
- collapsible?: boolean;
113
- collapsed?: boolean;
114
- /** Bound to the contract: the string spelling of a column count is admitted. */
115
- columns?: FormSection['columns'];
116
- /** Section-level conditional-visibility predicate (ADR-0089), bound to the contract. */
117
- visibleWhen?: FormSection['visibleWhen'];
118
- /**
119
- * The authored field list. A bare string is the spec's shorthand for "this
120
- * object's own field, rendered with its defaults" — the same shorthand
121
- * `mapColumn` already honours on the list bridge.
122
- */
123
- fields?: Array<string | FormFieldSpec>;
124
- }
125
- /**
126
- * The subset of `@objectstack/spec` FormViewSchema the bridge consumes.
127
- * Every serializable spec key is either mapped onto the `object-form` node
128
- * or listed here with an explicit reason for being ignored — the bridge must
129
- * never silently drop spec configuration (#2545).
130
- */
131
- export interface FormViewSpec {
132
- type?: string;
133
- layout?: string;
134
- /** Bound to the contract, which admits NO string arm here — unlike a section. */
135
- columns?: FormView['columns'];
136
- title?: string;
137
- description?: string;
138
- defaultTab?: string;
139
- tabPosition?: string;
140
- allowSkip?: boolean;
141
- showStepIndicator?: boolean;
142
- splitDirection?: string;
143
- splitSize?: number;
144
- splitResizable?: boolean;
145
- drawerSide?: string;
146
- drawerWidth?: string;
147
- modalSize?: string;
148
- data?: any;
149
- sections?: FormSectionSpec[];
150
- /** Legacy alias of `sections` (spec: "Legacy support → alias to sections"). */
151
- groups?: FormSectionSpec[];
152
- /** Inline master-detail child collections. */
153
- subforms?: any[];
154
- sharing?: any;
155
- submitBehavior?: any;
156
- }
157
- /** Transforms a FormView spec into a Form SchemaNode */
158
- export declare const bridgeFormView: BridgeFn<FormViewSpec>;
@@ -1,170 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * Fold the contract's string spelling of a column count onto the number the
10
- * node carries.
11
- *
12
- * `FormSectionSchema` accepts `'2'` and `2` and normalises the string away in
13
- * its own pipe; the `object-form` node's section declares `columns?: 1|2|3|4`
14
- * and `FormSectionContainer` indexes its grid-class map by that number. Its
15
- * header states where the fold belongs: "The normalisation belongs at the seam
16
- * that parses authored metadata, not in the container's props." This bridge is
17
- * that seam. Forwarding `'2'` verbatim hands every downstream renderer a value
18
- * outside the type it declares.
19
- */
20
- function normalizeColumns(columns) {
21
- return typeof columns === 'string' ? Number(columns) : columns;
22
- }
23
- function mapField(field) {
24
- const mapped = {
25
- name: field.field,
26
- label: field.label ?? field.field,
27
- };
28
- if (field.type)
29
- mapped.type = field.type;
30
- if (field.options)
31
- mapped.options = field.options;
32
- if (field.reference)
33
- mapped.reference = field.reference;
34
- if (field.placeholder)
35
- mapped.placeholder = field.placeholder;
36
- if (field.helpText)
37
- mapped.helpText = field.helpText;
38
- if (field.readonly != null)
39
- mapped.readonly = field.readonly;
40
- if (field.required != null)
41
- mapped.required = field.required;
42
- if (field.hidden != null)
43
- mapped.hidden = field.hidden;
44
- if (field.colSpan != null)
45
- mapped.colSpan = field.colSpan;
46
- if (field.widget)
47
- mapped.widget = field.widget;
48
- // Forwarded unread into the node's `dependsOn`, which is declared with the
49
- // same type and read by `@object-ui/core`'s cascading-option resolver.
50
- if (field.dependsOn)
51
- mapped.dependsOn = field.dependsOn;
52
- // ADR-0089: `visibleWhen` is the canonical view-form-field visibility predicate
53
- // (the spec folds the deprecated `visibleOn` into it at parse). Prefer it and
54
- // fall back to `visibleOn` for raw / un-normalized metadata. The ObjectForm
55
- // renderer reads this view-level predicate from the node's `visibleOn` slot.
56
- //
57
- // Both contract arms travel whole: the bare CEL string, and the expression
58
- // object. `evalFieldPredicate` reads `{ dialect, source }` back out of the
59
- // object arm, which is how a spec-authored `{ dialect: 'cel', source: ... }`
60
- // now drives visibility instead of being refused by this declaration. An
61
- // `ast`-only expression (legal metadata: the contract requires `dialect` plus
62
- // one of `source` / `ast`) is forwarded whole rather than dropped, but no
63
- // evaluator in this repo reads an `ast` today — that gap is the evaluator's,
64
- // and the bridge must not hide it by discarding the key.
65
- const visiblePredicate = field.visibleWhen ?? field.visibleOn;
66
- if (visiblePredicate)
67
- mapped.visibleOn = visiblePredicate;
68
- return mapped;
69
- }
70
- function mapSection(section) {
71
- const mapped = {
72
- // A bare field name is the spec's shorthand and is forwarded verbatim: the
73
- // node's `fields` slot admits it and `normalizeSectionField`
74
- // (@object-ui/plugin-form) resolves it against the object schema. Running
75
- // it through `mapField` instead produced `{ name: undefined }` — a field
76
- // with no identity — for the most ordinary section a form can declare.
77
- fields: (section.fields ?? []).map((field) => typeof field === 'string' ? field : mapField(field)),
78
- };
79
- if (section.name)
80
- mapped.name = section.name;
81
- if (section.label)
82
- mapped.label = section.label;
83
- if (section.description)
84
- mapped.description = section.description;
85
- if (section.collapsible != null)
86
- mapped.collapsible = section.collapsible;
87
- if (section.collapsed != null)
88
- mapped.collapsed = section.collapsed;
89
- if (section.columns != null)
90
- mapped.columns = normalizeColumns(section.columns);
91
- // Whole, both arms — same predicate contract as the field above.
92
- if (section.visibleWhen)
93
- mapped.visibleWhen = section.visibleWhen;
94
- return mapped;
95
- }
96
- /** Maps spec formType to ObjectUI formType */
97
- function mapFormType(type) {
98
- if (!type)
99
- return undefined;
100
- const validTypes = ['simple', 'tabbed', 'wizard', 'split', 'drawer', 'modal'];
101
- return validTypes.includes(type) ? type : undefined;
102
- }
103
- /**
104
- * Spec FormViewSchema keys carried onto the `object-form` node verbatim.
105
- * All of them are declared with the same name (and semantics) on
106
- * `ObjectFormSchema`, so no per-key mapping is needed — only presence checks.
107
- */
108
- const PASSTHROUGH_KEYS = [
109
- 'layout',
110
- 'columns',
111
- 'title',
112
- 'description',
113
- 'defaultTab',
114
- 'tabPosition',
115
- 'allowSkip',
116
- 'showStepIndicator',
117
- 'splitDirection',
118
- 'splitSize',
119
- 'splitResizable',
120
- 'drawerSide',
121
- 'drawerWidth',
122
- 'modalSize',
123
- 'subforms',
124
- ];
125
- /** Transforms a FormView spec into a Form SchemaNode */
126
- export const bridgeFormView = (spec, _context) => {
127
- // Spec defines `groups` as a legacy alias of `sections`; normalize here so
128
- // downstream renderers only ever see `sections` (ObjectForm never reads a
129
- // `groups` key — before this normalization a groups-only spec silently
130
- // rendered no sections at all, #2545).
131
- const sections = (spec.sections ?? spec.groups ?? []).map(mapSection);
132
- const formType = mapFormType(spec.type);
133
- const node = {
134
- type: 'object-form',
135
- id: `form-${spec.type ?? 'default'}`,
136
- sections,
137
- data: spec.data,
138
- };
139
- // P1.2 — formType mapping (tabbed, wizard, split, drawer, modal)
140
- if (formType)
141
- node.formType = formType;
142
- // #2545 — same-name spec keys (layout, title, tab/wizard/split/drawer/modal
143
- // options, subforms) pass straight through onto the node.
144
- for (const key of PASSTHROUGH_KEYS) {
145
- if (spec[key] != null)
146
- node[key] = spec[key];
147
- }
148
- if (spec.submitBehavior)
149
- node.submitBehavior = spec.submitBehavior;
150
- // P1.6 — sharing
151
- if (spec.sharing)
152
- node.sharing = spec.sharing;
153
- // `defaultSort` (#3974) and `aria` (#3901) USED to be copied here. Both are
154
- // `retiredKey()` tombstones on spec 17's FormViewSchema, so a FormView that
155
- // parsed can never carry either — the guards were unreachable, and their
156
- // shape invited the next reader to copy a dead pattern. Removed under the
157
- // maintainer's 2026-08-11 enforce-or-remove ruling; measured dormant at BOTH
158
- // ends before removal:
159
- // - producer: `FormViewSchema.safeParse` rejects both keys by name
160
- // (`form.defaultSort` / `form.aria` removed in the #3896 close-out).
161
- // - consumer: no form renderer reads either off the node — plugin-form
162
- // reads neither, and `SchemaRenderer`'s generic ARIA injection resolves
163
- // FLAT `ariaLabel`/`ariaDescribedBy`/`role` (SchemaRenderer.tsx:109-119),
164
- // never a nested `aria` object.
165
- // The nested `aria` copy is still correct on the LIST bridge
166
- // (`list-view.ts:214`), whose carrier stayed live and IS consumed at
167
- // `plugin-list/src/ListView.tsx:2389-2392` — do not "align" the two.
168
- // Pinned by `__tests__/FormViewRetiredKeys.test.ts`.
169
- return node;
170
- };
@@ -1,20 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- import type { BridgeFn } from '../types.js';
9
- import type { ListView } from '@objectstack/spec/ui';
10
- /**
11
- * Bridge input: the spec-canonical ListView (#2231 — the former hand-written
12
- * `ListViewSpec`/`ListColumn` mirrors are retired; the shape now derives from
13
- * `@objectstack/spec/ui` and can no longer drift). Relaxed to `Partial` because
14
- * hosts routinely hand the bridge fragmentary view-configs (every field was
15
- * optional in the old mirror too, including spec-required `columns`).
16
- */
17
- type ListViewSpec = Partial<ListView>;
18
- /** Transforms a ListView spec into a DataTable SchemaNode */
19
- export declare const bridgeListView: BridgeFn<ListViewSpec>;
20
- export {};