@object-ui/react 17.5.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.
- package/CHANGELOG.md +4100 -0
- package/README.md +303 -46
- package/dist/LazyPluginLoader.d.ts +14 -7
- package/dist/LazyPluginLoader.js +14 -7
- package/dist/SchemaRenderer.d.ts +38 -7
- package/dist/SchemaRenderer.js +1603 -60
- package/dist/context/ActionContext.js +40 -1
- package/dist/context/DiscussionContext.d.ts +12 -0
- package/dist/context/DiscussionContext.js +2 -0
- package/dist/context/DrillNavigationContext.d.ts +13 -0
- package/dist/context/HostNavigationContext.d.ts +82 -0
- package/dist/context/HostNavigationContext.js +65 -0
- package/dist/context/InlineEditContext.d.ts +81 -1
- package/dist/context/InlineEditContext.js +8 -2
- package/dist/context/RecordContext.d.ts +48 -5
- package/dist/context/RecordContext.js +10 -1
- package/dist/context/RelatedRecordActionsContext.d.ts +20 -1
- package/dist/context/SchemaRendererContext.d.ts +54 -2
- package/dist/context/SchemaRendererContext.js +38 -5
- package/dist/context/ThemeContext.js +1 -1
- package/dist/context/actionRunnerTranslator.d.ts +27 -0
- package/dist/context/actionRunnerTranslator.js +37 -0
- package/dist/context/index.d.ts +13 -12
- package/dist/context/index.js +13 -12
- package/dist/element-data-source/ElementDataSourceGate.d.ts +163 -3
- package/dist/element-data-source/ElementDataSourceGate.js +407 -15
- package/dist/hooks/index.d.ts +37 -35
- package/dist/hooks/index.js +44 -35
- package/dist/hooks/useActionEngine.js +47 -4
- package/dist/hooks/useActionRunner.js +4 -0
- package/dist/hooks/useActionTextLocalizer.d.ts +21 -8
- package/dist/hooks/useActionTextLocalizer.js +33 -8
- package/dist/hooks/useCapabilityGate.js +6 -5
- package/dist/hooks/useConfigBagEvaluator.d.ts +30 -0
- package/dist/hooks/useConfigBagEvaluator.js +39 -0
- package/dist/hooks/useCrudShortcuts.js +1 -1
- package/dist/hooks/useDatasetDimensionLabels.js +1 -1
- package/dist/hooks/useDensityMode.d.ts +6 -2
- package/dist/hooks/useDensityMode.js +6 -2
- package/dist/hooks/useDiscovery.d.ts +1 -10
- package/dist/hooks/useDiscovery.js +1 -1
- package/dist/hooks/useETagCache.js +25 -4
- package/dist/hooks/useElementDataSource.d.ts +15 -2
- package/dist/hooks/useElementDataSource.js +29 -9
- package/dist/hooks/useExpression.d.ts +52 -38
- package/dist/hooks/useExpression.js +62 -42
- package/dist/hooks/useFilterScope.d.ts +22 -2
- package/dist/hooks/useFilterScope.js +29 -4
- package/dist/hooks/useGlobalUndo.d.ts +10 -0
- package/dist/hooks/useGlobalUndo.js +112 -46
- package/dist/hooks/useNavigationOverlay.d.ts +77 -12
- package/dist/hooks/useNavigationOverlay.js +119 -9
- package/dist/hooks/useOffline.js +65 -11
- package/dist/hooks/usePageAssignment.d.ts +8 -5
- package/dist/hooks/usePageAssignment.js +38 -17
- package/dist/hooks/usePageTransition.js +1 -1
- package/dist/hooks/usePageVariableActionBridge.js +2 -2
- package/dist/hooks/useRecordSearch.d.ts +34 -1
- package/dist/hooks/useRecordSearch.js +42 -7
- package/dist/hooks/useResolvedFilter.d.ts +46 -0
- package/dist/hooks/useResolvedFilter.js +130 -0
- package/dist/hooks/useSchemaPersistence.d.ts +7 -0
- package/dist/hooks/useSchemaPersistence.js +144 -5
- package/dist/hooks/useSettledSchema.d.ts +123 -0
- package/dist/hooks/useSettledSchema.js +186 -0
- package/dist/hooks/useViewData.d.ts +7 -2
- package/dist/hooks/useViewData.js +1 -1
- package/dist/hooks/useViewTransition.js +1 -1
- package/dist/index.d.ts +18 -11
- package/dist/index.js +54 -10
- package/dist/schema-input.d.ts +55 -14
- package/dist/schema-input.js +55 -12
- package/dist/utils/configBag.d.ts +68 -0
- package/dist/utils/configBag.js +70 -0
- package/dist/utils/error-message.d.ts +59 -0
- package/dist/utils/error-message.js +116 -1
- package/dist/utils/inlineAria.d.ts +61 -0
- package/dist/utils/inlineAria.js +70 -0
- package/dist/utils/nonGridRowCeiling.d.ts +44 -0
- package/dist/utils/nonGridRowCeiling.js +78 -0
- package/dist/utils/paramsBag.d.ts +28 -0
- package/dist/utils/paramsBag.js +146 -0
- package/dist/utils/propsBagDiagnostic.d.ts +196 -0
- package/dist/utils/propsBagDiagnostic.js +421 -0
- package/dist/utils/refusedDataPropDiagnostic.d.ts +44 -0
- package/dist/utils/refusedDataPropDiagnostic.js +94 -0
- package/dist/utils/unevaluatedExpression.d.ts +110 -0
- package/dist/utils/unevaluatedExpression.js +257 -0
- package/dist/utils/visibilityDiagnostic.d.ts +371 -0
- package/dist/utils/visibilityDiagnostic.js +551 -0
- package/package.json +10 -10
- package/dist/hooks/useClientNotifications.d.ts +0 -47
- package/dist/hooks/useClientNotifications.js +0 -162
- package/dist/spec-bridge/SpecBridge.d.ts +0 -28
- package/dist/spec-bridge/SpecBridge.js +0 -56
- package/dist/spec-bridge/bridges/form-view.d.ts +0 -82
- package/dist/spec-bridge/bridges/form-view.js +0 -126
- package/dist/spec-bridge/bridges/list-view.d.ts +0 -20
- package/dist/spec-bridge/bridges/list-view.js +0 -241
- package/dist/spec-bridge/index.d.ts +0 -11
- package/dist/spec-bridge/index.js +0 -10
- package/dist/spec-bridge/types.d.ts +0 -55
- 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';
|
|
30
|
-
import { useNotifications } from '../context/NotificationContext';
|
|
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';
|
|
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';
|
|
9
|
-
import { bridgeFormView } from './bridges/form-view';
|
|
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,82 +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';
|
|
9
|
-
interface FormField {
|
|
10
|
-
field: string;
|
|
11
|
-
/** Field type (spec FormFieldSchema reuses Data.FieldType; auto-infers widget). */
|
|
12
|
-
type?: string;
|
|
13
|
-
/** Options for select/multiselect/radio/checkboxes fields. */
|
|
14
|
-
options?: any[];
|
|
15
|
-
/** Target object name for lookup/master_detail fields. */
|
|
16
|
-
reference?: string;
|
|
17
|
-
label?: string;
|
|
18
|
-
placeholder?: string;
|
|
19
|
-
helpText?: string;
|
|
20
|
-
readonly?: boolean;
|
|
21
|
-
required?: boolean;
|
|
22
|
-
hidden?: boolean;
|
|
23
|
-
colSpan?: number;
|
|
24
|
-
widget?: string;
|
|
25
|
-
dependsOn?: string[];
|
|
26
|
-
/** Canonical conditional-visibility predicate (ADR-0089). */
|
|
27
|
-
visibleWhen?: string;
|
|
28
|
-
/** @deprecated ADR-0089 → `visibleWhen`. */
|
|
29
|
-
visibleOn?: string;
|
|
30
|
-
}
|
|
31
|
-
interface FormSection {
|
|
32
|
-
/** Stable section identifier for i18n lookup (spec FormSectionSchema.name). */
|
|
33
|
-
name?: string;
|
|
34
|
-
label?: string;
|
|
35
|
-
description?: string;
|
|
36
|
-
collapsible?: boolean;
|
|
37
|
-
collapsed?: boolean;
|
|
38
|
-
columns?: number;
|
|
39
|
-
/** Section-level conditional-visibility predicate (ADR-0089). */
|
|
40
|
-
visibleWhen?: string;
|
|
41
|
-
fields?: FormField[];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* The subset of `@objectstack/spec` FormViewSchema the bridge consumes.
|
|
45
|
-
* Every serializable spec key is either mapped onto the `object-form` node
|
|
46
|
-
* or listed here with an explicit reason for being ignored — the bridge must
|
|
47
|
-
* never silently drop spec configuration (#2545).
|
|
48
|
-
*/
|
|
49
|
-
interface FormViewSpec {
|
|
50
|
-
type?: string;
|
|
51
|
-
layout?: string;
|
|
52
|
-
columns?: number;
|
|
53
|
-
title?: string;
|
|
54
|
-
description?: string;
|
|
55
|
-
defaultTab?: string;
|
|
56
|
-
tabPosition?: string;
|
|
57
|
-
allowSkip?: boolean;
|
|
58
|
-
showStepIndicator?: boolean;
|
|
59
|
-
splitDirection?: string;
|
|
60
|
-
splitSize?: number;
|
|
61
|
-
splitResizable?: boolean;
|
|
62
|
-
drawerSide?: string;
|
|
63
|
-
drawerWidth?: string;
|
|
64
|
-
modalSize?: string;
|
|
65
|
-
data?: any;
|
|
66
|
-
sections?: FormSection[];
|
|
67
|
-
/** Legacy alias of `sections` (spec: "Legacy support → alias to sections"). */
|
|
68
|
-
groups?: FormSection[];
|
|
69
|
-
/** Inline master-detail child collections. */
|
|
70
|
-
subforms?: any[];
|
|
71
|
-
defaultSort?: any;
|
|
72
|
-
sharing?: any;
|
|
73
|
-
aria?: {
|
|
74
|
-
ariaLabel?: string;
|
|
75
|
-
ariaDescribedBy?: string;
|
|
76
|
-
role?: string;
|
|
77
|
-
};
|
|
78
|
-
submitBehavior?: any;
|
|
79
|
-
}
|
|
80
|
-
/** Transforms a FormView spec into a Form SchemaNode */
|
|
81
|
-
export declare const bridgeFormView: BridgeFn<FormViewSpec>;
|
|
82
|
-
export {};
|
|
@@ -1,126 +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
|
-
function mapField(field) {
|
|
9
|
-
const mapped = {
|
|
10
|
-
name: field.field,
|
|
11
|
-
label: field.label ?? field.field,
|
|
12
|
-
};
|
|
13
|
-
if (field.type)
|
|
14
|
-
mapped.type = field.type;
|
|
15
|
-
if (field.options)
|
|
16
|
-
mapped.options = field.options;
|
|
17
|
-
if (field.reference)
|
|
18
|
-
mapped.reference = field.reference;
|
|
19
|
-
if (field.placeholder)
|
|
20
|
-
mapped.placeholder = field.placeholder;
|
|
21
|
-
if (field.helpText)
|
|
22
|
-
mapped.helpText = field.helpText;
|
|
23
|
-
if (field.readonly != null)
|
|
24
|
-
mapped.readonly = field.readonly;
|
|
25
|
-
if (field.required != null)
|
|
26
|
-
mapped.required = field.required;
|
|
27
|
-
if (field.hidden != null)
|
|
28
|
-
mapped.hidden = field.hidden;
|
|
29
|
-
if (field.colSpan != null)
|
|
30
|
-
mapped.colSpan = field.colSpan;
|
|
31
|
-
if (field.widget)
|
|
32
|
-
mapped.widget = field.widget;
|
|
33
|
-
if (field.dependsOn)
|
|
34
|
-
mapped.dependsOn = field.dependsOn;
|
|
35
|
-
// ADR-0089: `visibleWhen` is the canonical view-form-field visibility predicate
|
|
36
|
-
// (the spec folds the deprecated `visibleOn` into it at parse). Prefer it and
|
|
37
|
-
// fall back to `visibleOn` for raw / un-normalized metadata. The ObjectForm
|
|
38
|
-
// renderer reads this view-level predicate from the node's `visibleOn` slot.
|
|
39
|
-
const visiblePredicate = field.visibleWhen ?? field.visibleOn;
|
|
40
|
-
if (visiblePredicate)
|
|
41
|
-
mapped.visibleOn = visiblePredicate;
|
|
42
|
-
return mapped;
|
|
43
|
-
}
|
|
44
|
-
function mapSection(section) {
|
|
45
|
-
const mapped = {
|
|
46
|
-
fields: (section.fields ?? []).map(mapField),
|
|
47
|
-
};
|
|
48
|
-
if (section.name)
|
|
49
|
-
mapped.name = section.name;
|
|
50
|
-
if (section.label)
|
|
51
|
-
mapped.label = section.label;
|
|
52
|
-
if (section.description)
|
|
53
|
-
mapped.description = section.description;
|
|
54
|
-
if (section.collapsible != null)
|
|
55
|
-
mapped.collapsible = section.collapsible;
|
|
56
|
-
if (section.collapsed != null)
|
|
57
|
-
mapped.collapsed = section.collapsed;
|
|
58
|
-
if (section.columns != null)
|
|
59
|
-
mapped.columns = section.columns;
|
|
60
|
-
if (section.visibleWhen)
|
|
61
|
-
mapped.visibleWhen = section.visibleWhen;
|
|
62
|
-
return mapped;
|
|
63
|
-
}
|
|
64
|
-
/** Maps spec formType to ObjectUI formType */
|
|
65
|
-
function mapFormType(type) {
|
|
66
|
-
if (!type)
|
|
67
|
-
return undefined;
|
|
68
|
-
const validTypes = ['simple', 'tabbed', 'wizard', 'split', 'drawer', 'modal'];
|
|
69
|
-
return validTypes.includes(type) ? type : undefined;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Spec FormViewSchema keys carried onto the `object-form` node verbatim.
|
|
73
|
-
* All of them are declared with the same name (and semantics) on
|
|
74
|
-
* `ObjectFormSchema`, so no per-key mapping is needed — only presence checks.
|
|
75
|
-
*/
|
|
76
|
-
const PASSTHROUGH_KEYS = [
|
|
77
|
-
'layout',
|
|
78
|
-
'columns',
|
|
79
|
-
'title',
|
|
80
|
-
'description',
|
|
81
|
-
'defaultTab',
|
|
82
|
-
'tabPosition',
|
|
83
|
-
'allowSkip',
|
|
84
|
-
'showStepIndicator',
|
|
85
|
-
'splitDirection',
|
|
86
|
-
'splitSize',
|
|
87
|
-
'splitResizable',
|
|
88
|
-
'drawerSide',
|
|
89
|
-
'drawerWidth',
|
|
90
|
-
'modalSize',
|
|
91
|
-
'subforms',
|
|
92
|
-
];
|
|
93
|
-
/** Transforms a FormView spec into a Form SchemaNode */
|
|
94
|
-
export const bridgeFormView = (spec, _context) => {
|
|
95
|
-
// Spec defines `groups` as a legacy alias of `sections`; normalize here so
|
|
96
|
-
// downstream renderers only ever see `sections` (ObjectForm never reads a
|
|
97
|
-
// `groups` key — before this normalization a groups-only spec silently
|
|
98
|
-
// rendered no sections at all, #2545).
|
|
99
|
-
const sections = (spec.sections ?? spec.groups ?? []).map(mapSection);
|
|
100
|
-
const formType = mapFormType(spec.type);
|
|
101
|
-
const node = {
|
|
102
|
-
type: 'object-form',
|
|
103
|
-
id: `form-${spec.type ?? 'default'}`,
|
|
104
|
-
sections,
|
|
105
|
-
data: spec.data,
|
|
106
|
-
};
|
|
107
|
-
// P1.2 — formType mapping (tabbed, wizard, split, drawer, modal)
|
|
108
|
-
if (formType)
|
|
109
|
-
node.formType = formType;
|
|
110
|
-
// #2545 — same-name spec keys (layout, title, tab/wizard/split/drawer/modal
|
|
111
|
-
// options, subforms) pass straight through onto the node.
|
|
112
|
-
for (const key of PASSTHROUGH_KEYS) {
|
|
113
|
-
if (spec[key] != null)
|
|
114
|
-
node[key] = spec[key];
|
|
115
|
-
}
|
|
116
|
-
if (spec.defaultSort)
|
|
117
|
-
node.defaultSort = spec.defaultSort;
|
|
118
|
-
if (spec.submitBehavior)
|
|
119
|
-
node.submitBehavior = spec.submitBehavior;
|
|
120
|
-
// P1.6 — i18n & ARIA
|
|
121
|
-
if (spec.sharing)
|
|
122
|
-
node.sharing = spec.sharing;
|
|
123
|
-
if (spec.aria)
|
|
124
|
-
node.aria = spec.aria;
|
|
125
|
-
return node;
|
|
126
|
-
};
|
|
@@ -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';
|
|
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 {};
|