@object-ui/react 3.3.0 → 3.3.1

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 (102) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +21 -1
  3. package/dist/context/AppShellContext.d.ts +26 -0
  4. package/dist/context/AppShellContext.js +67 -0
  5. package/dist/context/index.d.ts +1 -7
  6. package/dist/context/index.js +1 -7
  7. package/package.json +32 -9
  8. package/.turbo/turbo-build.log +0 -4
  9. package/src/LazyPluginLoader.tsx +0 -174
  10. package/src/SchemaRenderer.tsx +0 -266
  11. package/src/__tests__/LazyPluginLoader.test.tsx +0 -176
  12. package/src/__tests__/SchemaRenderer.aria.test.tsx +0 -118
  13. package/src/__tests__/SchemaRenderer.debug.test.tsx +0 -69
  14. package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +0 -114
  15. package/src/__tests__/SchemaRenderer.expressions.test.tsx +0 -131
  16. package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +0 -132
  17. package/src/__tests__/ThemeProvider.test.tsx +0 -451
  18. package/src/__tests__/useNavigationOverlay.test.ts +0 -578
  19. package/src/__tests__/useOffline.test.ts +0 -198
  20. package/src/__tests__/usePageTransition.test.ts +0 -214
  21. package/src/__tests__/usePageVariables.test.tsx +0 -334
  22. package/src/__tests__/usePerformance.test.ts +0 -137
  23. package/src/__tests__/useViewData.test.tsx +0 -422
  24. package/src/__tests__/view-switching.test.tsx +0 -456
  25. package/src/components/form/FieldFactory.tsx +0 -516
  26. package/src/components/form/FormRenderer.test.tsx +0 -744
  27. package/src/components/form/FormRenderer.tsx +0 -258
  28. package/src/components/form/README.md +0 -352
  29. package/src/components/form/index.ts +0 -12
  30. package/src/context/ActionContext.tsx +0 -213
  31. package/src/context/DndContext.tsx +0 -260
  32. package/src/context/NotificationContext.tsx +0 -280
  33. package/src/context/SchemaRendererContext.tsx +0 -48
  34. package/src/context/ThemeContext.tsx +0 -325
  35. package/src/context/__tests__/ActionContext.test.tsx +0 -174
  36. package/src/context/__tests__/DndContext.test.tsx +0 -150
  37. package/src/context/__tests__/NotificationContext.test.tsx +0 -176
  38. package/src/context/__tests__/useDataScope.test.tsx +0 -91
  39. package/src/context/index.ts +0 -13
  40. package/src/hooks/__tests__/useActionEngine.test.ts +0 -170
  41. package/src/hooks/__tests__/useActionRunner.test.ts +0 -153
  42. package/src/hooks/__tests__/useAnimation.test.ts +0 -82
  43. package/src/hooks/__tests__/useColumnSummary.test.ts +0 -93
  44. package/src/hooks/__tests__/useCrudShortcuts.test.ts +0 -85
  45. package/src/hooks/__tests__/useDataRefresh.test.ts +0 -115
  46. package/src/hooks/__tests__/useDebugMode.test.ts +0 -83
  47. package/src/hooks/__tests__/useDensityMode.test.ts +0 -81
  48. package/src/hooks/__tests__/useDiscovery.test.tsx +0 -247
  49. package/src/hooks/__tests__/useDynamicApp.test.ts +0 -161
  50. package/src/hooks/__tests__/useETagCache.test.ts +0 -153
  51. package/src/hooks/__tests__/useExpression.test.ts +0 -86
  52. package/src/hooks/__tests__/useFocusTrap.test.ts +0 -294
  53. package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +0 -144
  54. package/src/hooks/__tests__/usePageTransition.test.ts +0 -158
  55. package/src/hooks/__tests__/usePerformanceBudget.test.ts +0 -157
  56. package/src/hooks/__tests__/useReducedMotion.test.ts +0 -104
  57. package/src/hooks/__tests__/useSchemaPersistence.test.ts +0 -220
  58. package/src/hooks/__tests__/useViewSharing.test.ts +0 -121
  59. package/src/hooks/__tests__/useViewTransition.test.ts +0 -61
  60. package/src/hooks/index.ts +0 -36
  61. package/src/hooks/useActionEngine.ts +0 -84
  62. package/src/hooks/useActionRunner.ts +0 -119
  63. package/src/hooks/useAnimation.ts +0 -117
  64. package/src/hooks/useClientNotifications.ts +0 -251
  65. package/src/hooks/useColumnSummary.ts +0 -87
  66. package/src/hooks/useCrudShortcuts.ts +0 -126
  67. package/src/hooks/useDataRefresh.ts +0 -58
  68. package/src/hooks/useDebugMode.ts +0 -95
  69. package/src/hooks/useDensityMode.ts +0 -102
  70. package/src/hooks/useDiscovery.ts +0 -168
  71. package/src/hooks/useDynamicApp.ts +0 -142
  72. package/src/hooks/useETagCache.ts +0 -404
  73. package/src/hooks/useExpression.ts +0 -56
  74. package/src/hooks/useFocusManagement.ts +0 -248
  75. package/src/hooks/useFocusTrap.ts +0 -138
  76. package/src/hooks/useGlobalUndo.ts +0 -98
  77. package/src/hooks/useKeyboardShortcuts.ts +0 -119
  78. package/src/hooks/useNavigationOverlay.ts +0 -190
  79. package/src/hooks/useOffline.ts +0 -301
  80. package/src/hooks/usePageTransition.ts +0 -187
  81. package/src/hooks/usePageVariables.tsx +0 -157
  82. package/src/hooks/usePerformance.ts +0 -246
  83. package/src/hooks/usePerformanceBudget.ts +0 -313
  84. package/src/hooks/useReducedMotion.ts +0 -53
  85. package/src/hooks/useSchemaPersistence.ts +0 -222
  86. package/src/hooks/useViewData.ts +0 -201
  87. package/src/hooks/useViewSharing.ts +0 -140
  88. package/src/hooks/useViewTransition.ts +0 -144
  89. package/src/index.ts +0 -41
  90. package/src/spec-bridge/SpecBridge.ts +0 -64
  91. package/src/spec-bridge/__tests__/P1SpecBridge.test.ts +0 -855
  92. package/src/spec-bridge/__tests__/SpecBridge.test.ts +0 -550
  93. package/src/spec-bridge/bridges/dashboard.ts +0 -180
  94. package/src/spec-bridge/bridges/form-view.ts +0 -109
  95. package/src/spec-bridge/bridges/list-view.ts +0 -187
  96. package/src/spec-bridge/bridges/page.ts +0 -136
  97. package/src/spec-bridge/index.ts +0 -14
  98. package/src/spec-bridge/types.ts +0 -38
  99. package/src/utils/i18n.ts +0 -10
  100. package/tsconfig.json +0 -17
  101. package/tsconfig.tsbuildinfo +0 -1
  102. package/vitest.config.ts +0 -2
@@ -1,213 +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
- /**
10
- * @object-ui/react - Action Context
11
- *
12
- * Provides a shared ActionRunner instance and handlers to the component tree.
13
- * Components can consume actions without creating their own runner instances.
14
- */
15
-
16
- import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';
17
- import {
18
- ActionRunner,
19
- type ActionContext as ActionCtx,
20
- type ActionDef,
21
- type ActionResult,
22
- type ConfirmationHandler,
23
- type ToastHandler,
24
- type ModalHandler,
25
- type NavigationHandler,
26
- type ParamCollectionHandler,
27
- } from '@object-ui/core';
28
-
29
- export interface ActionProviderProps {
30
- children: React.ReactNode;
31
- /** Initial action context (record, user, data, etc.) */
32
- context?: ActionCtx;
33
- /** Custom confirmation handler (e.g., Shadcn AlertDialog) */
34
- onConfirm?: ConfirmationHandler;
35
- /** Custom toast handler (e.g., Sonner) */
36
- onToast?: ToastHandler;
37
- /** Custom modal handler — render modals in response to modal actions */
38
- onModal?: ModalHandler;
39
- /** Custom navigation handler — SPA-aware routing (e.g., React Router navigate) */
40
- onNavigate?: NavigationHandler;
41
- /** Custom param collection handler — show dialog to collect ActionParam values */
42
- onParamCollection?: ParamCollectionHandler;
43
- /** Pre-registered custom action handlers */
44
- handlers?: Record<string, (action: ActionDef, ctx: ActionCtx) => Promise<ActionResult>>;
45
- }
46
-
47
- interface ActionContextValue {
48
- /** Execute an action */
49
- execute: (action: ActionDef) => Promise<ActionResult>;
50
- /** Execute multiple actions in chain */
51
- executeChain: (actions: ActionDef[], mode?: 'sequential' | 'parallel') => Promise<ActionResult>;
52
- /** Whether an action is currently being executed */
53
- loading: boolean;
54
- /** Last error message */
55
- error: string | null;
56
- /** Last action result */
57
- result: ActionResult | null;
58
- /** The underlying ActionRunner instance */
59
- runner: ActionRunner;
60
- /** Update context data */
61
- updateContext: (ctx: Partial<ActionCtx>) => void;
62
- }
63
-
64
- const ActionCtxReact = createContext<ActionContextValue | null>(null);
65
-
66
- /**
67
- * ActionProvider — Provides a shared ActionRunner to the tree.
68
- *
69
- * @example
70
- * ```tsx
71
- * <ActionProvider
72
- * context={{ record: currentRecord, user }}
73
- * onToast={(msg, opts) => toast[opts?.type ?? 'info'](msg)}
74
- * onConfirm={async (msg) => showConfirmDialog(msg)}
75
- * onNavigate={(url) => router.push(url)}
76
- * >
77
- * <SchemaRenderer schema={pageSchema} />
78
- * </ActionProvider>
79
- * ```
80
- */
81
- export const ActionProvider: React.FC<ActionProviderProps> = ({
82
- children,
83
- context = {},
84
- onConfirm,
85
- onToast,
86
- onModal,
87
- onNavigate,
88
- onParamCollection,
89
- handlers,
90
- }) => {
91
- const [loading, setLoading] = useState(false);
92
- const [error, setError] = useState<string | null>(null);
93
- const [result, setResult] = useState<ActionResult | null>(null);
94
-
95
- const runner = useMemo(() => {
96
- const r = new ActionRunner(context);
97
- if (onConfirm) r.setConfirmHandler(onConfirm);
98
- if (onToast) r.setToastHandler(onToast);
99
- if (onModal) r.setModalHandler(onModal);
100
- if (onNavigate) r.setNavigationHandler(onNavigate);
101
- if (onParamCollection) r.setParamCollectionHandler(onParamCollection);
102
- if (handlers) {
103
- Object.entries(handlers).forEach(([name, handler]) => {
104
- r.registerHandler(name, handler);
105
- });
106
- }
107
- return r;
108
- // eslint-disable-next-line react-hooks/exhaustive-deps
109
- }, [JSON.stringify(context)]);
110
-
111
- const execute = useCallback(
112
- async (action: ActionDef): Promise<ActionResult> => {
113
- setLoading(true);
114
- setError(null);
115
- setResult(null);
116
-
117
- try {
118
- const actionResult = await runner.execute(action);
119
- setResult(actionResult);
120
- if (!actionResult.success) {
121
- setError(actionResult.error || 'Action failed');
122
- }
123
- return actionResult;
124
- } catch (err) {
125
- const errorMessage = (err as Error).message;
126
- setError(errorMessage);
127
- const failureResult: ActionResult = { success: false, error: errorMessage };
128
- setResult(failureResult);
129
- return failureResult;
130
- } finally {
131
- setLoading(false);
132
- }
133
- },
134
- [runner],
135
- );
136
-
137
- const executeChain = useCallback(
138
- async (actions: ActionDef[], mode?: 'sequential' | 'parallel'): Promise<ActionResult> => {
139
- setLoading(true);
140
- setError(null);
141
- setResult(null);
142
-
143
- try {
144
- const actionResult = await runner.executeChain(actions, mode);
145
- setResult(actionResult);
146
- if (!actionResult.success) {
147
- setError(actionResult.error || 'Chain failed');
148
- }
149
- return actionResult;
150
- } catch (err) {
151
- const errorMessage = (err as Error).message;
152
- setError(errorMessage);
153
- const failureResult: ActionResult = { success: false, error: errorMessage };
154
- setResult(failureResult);
155
- return failureResult;
156
- } finally {
157
- setLoading(false);
158
- }
159
- },
160
- [runner],
161
- );
162
-
163
- const updateContext = useCallback(
164
- (newContext: Partial<ActionCtx>) => {
165
- runner.updateContext(newContext);
166
- },
167
- [runner],
168
- );
169
-
170
- const value = useMemo<ActionContextValue>(
171
- () => ({ execute, executeChain, loading, error, result, runner, updateContext }),
172
- [execute, executeChain, loading, error, result, runner, updateContext],
173
- );
174
-
175
- return (
176
- <ActionCtxReact.Provider value={value}>{children}</ActionCtxReact.Provider>
177
- );
178
- };
179
-
180
- ActionProvider.displayName = 'ActionProvider';
181
-
182
- /**
183
- * Hook to consume the ActionProvider context.
184
- * Returns the shared ActionRunner execute function, loading state, and more.
185
- *
186
- * Falls back to a local ActionRunner if no ActionProvider is present.
187
- */
188
- export function useAction(): ActionContextValue {
189
- const ctx = useContext(ActionCtxReact);
190
- if (!ctx) {
191
- // Graceful fallback: create a local runner
192
- // This allows action components to work even without an ActionProvider
193
- const runner = new ActionRunner();
194
- return {
195
- execute: (action: ActionDef) => runner.execute(action),
196
- executeChain: (actions: ActionDef[], mode?: 'sequential' | 'parallel') =>
197
- runner.executeChain(actions, mode),
198
- loading: false,
199
- error: null,
200
- result: null,
201
- runner,
202
- updateContext: (ctx: Partial<ActionCtx>) => runner.updateContext(ctx),
203
- };
204
- }
205
- return ctx;
206
- }
207
-
208
- /**
209
- * Hook to check if an ActionProvider is available.
210
- */
211
- export function useHasActionProvider(): boolean {
212
- return useContext(ActionCtxReact) !== null;
213
- }
@@ -1,260 +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
- /**
10
- * @object-ui/react - Drag and Drop Context
11
- *
12
- * Provides a unified DnD configuration system to the component tree.
13
- * Implements DndConfigSchema, DragItemSchema, DropZoneSchema,
14
- * DragConstraintSchema, and DropEffectSchema from @objectstack/spec v2.0.7.
15
- */
16
-
17
- import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';
18
-
19
- /** Drop effect types aligned with DropEffectSchema */
20
- export type DropEffectType = 'move' | 'copy' | 'link' | 'none';
21
-
22
- /** Drag constraint axis aligned with DragConstraintSchema */
23
- export type DragAxis = 'x' | 'y' | 'both';
24
-
25
- /** Drag item metadata */
26
- export interface DragItemData {
27
- /** Unique identifier for the dragged item */
28
- id: string;
29
- /** Type of the dragged item (for drop zone filtering) */
30
- type: string;
31
- /** Arbitrary data associated with the drag */
32
- data?: Record<string, unknown>;
33
- /** Source container/zone identifier */
34
- sourceId?: string;
35
- }
36
-
37
- /** Drop zone configuration */
38
- export interface DropZoneConfig {
39
- /** Unique identifier for the drop zone */
40
- id: string;
41
- /** Accepted drag item types */
42
- acceptTypes: string[];
43
- /** Drop effect to apply */
44
- effect?: DropEffectType;
45
- /** Whether the zone is currently disabled */
46
- disabled?: boolean;
47
- /** Maximum number of items this zone can hold */
48
- maxItems?: number;
49
- }
50
-
51
- /** Drag constraints configuration */
52
- export interface DragConstraintConfig {
53
- /** Constrain movement to an axis */
54
- axis?: DragAxis;
55
- /** Minimum distance before drag starts (in pixels) */
56
- activationDistance?: number;
57
- /** Whether to show a drag handle */
58
- showHandle?: boolean;
59
- /** Container bounds (CSS selector) */
60
- containerId?: string;
61
- }
62
-
63
- /** Overall DnD configuration aligned with DndConfigSchema */
64
- export interface DndSystemConfig {
65
- /** Whether DnD is enabled */
66
- enabled?: boolean;
67
- /** Default drag constraints */
68
- defaultConstraints?: DragConstraintConfig;
69
- /** Whether to show drag overlay/preview */
70
- showPreview?: boolean;
71
- /** Auto-scroll when dragging near edges */
72
- autoScroll?: boolean;
73
- }
74
-
75
- /** Drag event information */
76
- export interface DragEvent {
77
- /** The dragged item */
78
- item: DragItemData;
79
- /** Target drop zone (null if not over a zone) */
80
- targetZoneId: string | null;
81
- /** The applied drop effect */
82
- effect: DropEffectType;
83
- }
84
-
85
- export interface DndProviderProps {
86
- children: React.ReactNode;
87
- /** System-wide DnD configuration */
88
- config?: DndSystemConfig;
89
- /** Called when a drag starts */
90
- onDragStart?: (event: DragEvent) => void;
91
- /** Called when an item is dropped */
92
- onDrop?: (event: DragEvent) => void;
93
- /** Called when a drag is cancelled */
94
- onDragCancel?: (event: DragEvent) => void;
95
- }
96
-
97
- interface DndContextValue {
98
- /** System-wide DnD configuration */
99
- config: DndSystemConfig;
100
- /** Whether DnD is enabled */
101
- enabled: boolean;
102
- /** Currently dragging item (null if not dragging) */
103
- activeItem: DragItemData | null;
104
- /** Registered drop zones */
105
- dropZones: Map<string, DropZoneConfig>;
106
- /** Start a drag operation */
107
- startDrag: (item: DragItemData) => void;
108
- /** End the current drag operation */
109
- endDrag: (targetZoneId?: string) => void;
110
- /** Cancel the current drag */
111
- cancelDrag: () => void;
112
- /** Register a drop zone */
113
- registerDropZone: (zone: DropZoneConfig) => void;
114
- /** Unregister a drop zone */
115
- unregisterDropZone: (zoneId: string) => void;
116
- /** Check if a drop zone accepts a drag item type */
117
- canDrop: (zoneId: string, itemType: string) => boolean;
118
- }
119
-
120
- const DndCtx = createContext<DndContextValue | null>(null);
121
-
122
- /**
123
- * DndProvider — Provides a unified DnD system aligned with @objectstack/spec v2.0.7.
124
- *
125
- * This is a coordination layer; actual drag mechanics are delegated to
126
- * libraries like @dnd-kit/core or react-grid-layout in individual plugins.
127
- *
128
- * @example
129
- * ```tsx
130
- * <DndProvider
131
- * config={{ enabled: true, showPreview: true, autoScroll: true }}
132
- * onDrop={(event) => handleDrop(event.item, event.targetZoneId)}
133
- * >
134
- * <KanbanBoard />
135
- * </DndProvider>
136
- * ```
137
- */
138
- export const DndProvider: React.FC<DndProviderProps> = ({
139
- children,
140
- config: userConfig = {},
141
- onDragStart,
142
- onDrop,
143
- onDragCancel,
144
- }) => {
145
- const config = useMemo<DndSystemConfig>(
146
- () => ({
147
- enabled: true,
148
- showPreview: true,
149
- autoScroll: true,
150
- ...userConfig,
151
- }),
152
- // eslint-disable-next-line react-hooks/exhaustive-deps
153
- [JSON.stringify(userConfig)],
154
- );
155
-
156
- const [activeItem, setActiveItem] = useState<DragItemData | null>(null);
157
- const [dropZones] = useState<Map<string, DropZoneConfig>>(() => new Map());
158
-
159
- const startDrag = useCallback(
160
- (item: DragItemData) => {
161
- if (!config.enabled) return;
162
- setActiveItem(item);
163
- onDragStart?.({ item, targetZoneId: null, effect: 'move' });
164
- },
165
- [config.enabled, onDragStart],
166
- );
167
-
168
- const endDrag = useCallback(
169
- (targetZoneId?: string) => {
170
- if (!activeItem) return;
171
- const zone = targetZoneId ? dropZones.get(targetZoneId) : undefined;
172
- const effect: DropEffectType = zone?.effect ?? 'move';
173
- onDrop?.({ item: activeItem, targetZoneId: targetZoneId ?? null, effect });
174
- setActiveItem(null);
175
- },
176
- [activeItem, dropZones, onDrop],
177
- );
178
-
179
- const cancelDrag = useCallback(() => {
180
- if (!activeItem) return;
181
- onDragCancel?.({ item: activeItem, targetZoneId: null, effect: 'none' });
182
- setActiveItem(null);
183
- }, [activeItem, onDragCancel]);
184
-
185
- const registerDropZone = useCallback(
186
- (zone: DropZoneConfig) => {
187
- dropZones.set(zone.id, zone);
188
- },
189
- [dropZones],
190
- );
191
-
192
- const unregisterDropZone = useCallback(
193
- (zoneId: string) => {
194
- dropZones.delete(zoneId);
195
- },
196
- [dropZones],
197
- );
198
-
199
- const canDrop = useCallback(
200
- (zoneId: string, itemType: string): boolean => {
201
- const zone = dropZones.get(zoneId);
202
- if (!zone || zone.disabled) return false;
203
- return zone.acceptTypes.includes(itemType);
204
- },
205
- [dropZones],
206
- );
207
-
208
- const value = useMemo<DndContextValue>(
209
- () => ({
210
- config,
211
- enabled: config.enabled ?? true,
212
- activeItem,
213
- dropZones,
214
- startDrag,
215
- endDrag,
216
- cancelDrag,
217
- registerDropZone,
218
- unregisterDropZone,
219
- canDrop,
220
- }),
221
- [
222
- config,
223
- activeItem,
224
- dropZones,
225
- startDrag,
226
- endDrag,
227
- cancelDrag,
228
- registerDropZone,
229
- unregisterDropZone,
230
- canDrop,
231
- ],
232
- );
233
-
234
- return <DndCtx.Provider value={value}>{children}</DndCtx.Provider>;
235
- };
236
-
237
- DndProvider.displayName = 'DndProvider';
238
-
239
- /**
240
- * Hook to consume the DnD context.
241
- *
242
- * @throws Error if used outside a DndProvider
243
- */
244
- export function useDnd(): DndContextValue {
245
- const ctx = useContext(DndCtx);
246
- if (!ctx) {
247
- throw new Error(
248
- 'useDnd must be used within a <DndProvider>. ' +
249
- 'Wrap your app with <DndProvider> to use the drag and drop system.',
250
- );
251
- }
252
- return ctx;
253
- }
254
-
255
- /**
256
- * Hook to check if a DndProvider is available.
257
- */
258
- export function useHasDndProvider(): boolean {
259
- return useContext(DndCtx) !== null;
260
- }