@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,334 +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
- import { describe, it, expect } from 'vitest';
10
- import { renderHook, act } from '@testing-library/react';
11
- import React from 'react';
12
- import {
13
- PageVariablesProvider,
14
- usePageVariables,
15
- useHasPageVariables,
16
- } from '../hooks/usePageVariables';
17
- import type { PageVariable } from '@object-ui/types';
18
-
19
- // ---------------------------------------------------------------------------
20
- // Helper: wrap hook in PageVariablesProvider
21
- // ---------------------------------------------------------------------------
22
-
23
- function createWrapper(definitions?: PageVariable[]) {
24
- return ({ children }: { children: React.ReactNode }) => (
25
- <PageVariablesProvider definitions={definitions}>
26
- {children}
27
- </PageVariablesProvider>
28
- );
29
- }
30
-
31
- // ---------------------------------------------------------------------------
32
- // useHasPageVariables
33
- // ---------------------------------------------------------------------------
34
-
35
- describe('useHasPageVariables', () => {
36
- it('should return false when outside provider', () => {
37
- const { result } = renderHook(() => useHasPageVariables());
38
- expect(result.current).toBe(false);
39
- });
40
-
41
- it('should return true when inside provider', () => {
42
- const { result } = renderHook(() => useHasPageVariables(), {
43
- wrapper: createWrapper([]),
44
- });
45
- expect(result.current).toBe(true);
46
- });
47
- });
48
-
49
- // ---------------------------------------------------------------------------
50
- // usePageVariables — outside provider (graceful fallback)
51
- // ---------------------------------------------------------------------------
52
-
53
- describe('usePageVariables — outside provider', () => {
54
- it('should return empty variables', () => {
55
- const { result } = renderHook(() => usePageVariables());
56
- expect(result.current.variables).toEqual({});
57
- });
58
-
59
- it('should provide no-op setVariable', () => {
60
- const { result } = renderHook(() => usePageVariables());
61
- // Should not throw
62
- act(() => {
63
- result.current.setVariable('x', 1);
64
- });
65
- expect(result.current.variables).toEqual({});
66
- });
67
-
68
- it('should provide no-op setVariables', () => {
69
- const { result } = renderHook(() => usePageVariables());
70
- act(() => {
71
- result.current.setVariables({ a: 1, b: 2 });
72
- });
73
- expect(result.current.variables).toEqual({});
74
- });
75
-
76
- it('should provide no-op resetVariables', () => {
77
- const { result } = renderHook(() => usePageVariables());
78
- act(() => {
79
- result.current.resetVariables();
80
- });
81
- expect(result.current.variables).toEqual({});
82
- });
83
- });
84
-
85
- // ---------------------------------------------------------------------------
86
- // Initialization from definitions
87
- // ---------------------------------------------------------------------------
88
-
89
- describe('usePageVariables — initialization', () => {
90
- it('should initialize string variable with default', () => {
91
- const defs: PageVariable[] = [
92
- { name: 'query', type: 'string', defaultValue: 'hello' },
93
- ];
94
- const { result } = renderHook(() => usePageVariables(), {
95
- wrapper: createWrapper(defs),
96
- });
97
- expect(result.current.variables.query).toBe('hello');
98
- });
99
-
100
- it('should initialize number variable with default', () => {
101
- const defs: PageVariable[] = [
102
- { name: 'count', type: 'number', defaultValue: 42 },
103
- ];
104
- const { result } = renderHook(() => usePageVariables(), {
105
- wrapper: createWrapper(defs),
106
- });
107
- expect(result.current.variables.count).toBe(42);
108
- });
109
-
110
- it('should initialize boolean variable with default', () => {
111
- const defs: PageVariable[] = [
112
- { name: 'isOpen', type: 'boolean', defaultValue: true },
113
- ];
114
- const { result } = renderHook(() => usePageVariables(), {
115
- wrapper: createWrapper(defs),
116
- });
117
- expect(result.current.variables.isOpen).toBe(true);
118
- });
119
-
120
- it('should initialize object variable with default', () => {
121
- const defs: PageVariable[] = [
122
- { name: 'filter', type: 'object', defaultValue: { status: 'active' } },
123
- ];
124
- const { result } = renderHook(() => usePageVariables(), {
125
- wrapper: createWrapper(defs),
126
- });
127
- expect(result.current.variables.filter).toEqual({ status: 'active' });
128
- });
129
-
130
- it('should initialize array variable with default', () => {
131
- const defs: PageVariable[] = [
132
- { name: 'tags', type: 'array', defaultValue: ['a', 'b'] },
133
- ];
134
- const { result } = renderHook(() => usePageVariables(), {
135
- wrapper: createWrapper(defs),
136
- });
137
- expect(result.current.variables.tags).toEqual(['a', 'b']);
138
- });
139
-
140
- it('should use type-appropriate defaults when no defaultValue', () => {
141
- const defs: PageVariable[] = [
142
- { name: 'str', type: 'string' },
143
- { name: 'num', type: 'number' },
144
- { name: 'bool', type: 'boolean' },
145
- { name: 'obj', type: 'object' },
146
- { name: 'arr', type: 'array' },
147
- ];
148
- const { result } = renderHook(() => usePageVariables(), {
149
- wrapper: createWrapper(defs),
150
- });
151
- expect(result.current.variables.str).toBe('');
152
- expect(result.current.variables.num).toBe(0);
153
- expect(result.current.variables.bool).toBe(false);
154
- expect(result.current.variables.obj).toEqual({});
155
- expect(result.current.variables.arr).toEqual([]);
156
- });
157
-
158
- it('should default to empty string when type is undefined', () => {
159
- const defs: PageVariable[] = [{ name: 'unknown' }];
160
- const { result } = renderHook(() => usePageVariables(), {
161
- wrapper: createWrapper(defs),
162
- });
163
- expect(result.current.variables.unknown).toBe('');
164
- });
165
-
166
- it('should initialize multiple variables', () => {
167
- const defs: PageVariable[] = [
168
- { name: 'name', type: 'string', defaultValue: 'Alice' },
169
- { name: 'age', type: 'number', defaultValue: 30 },
170
- { name: 'active', type: 'boolean', defaultValue: true },
171
- ];
172
- const { result } = renderHook(() => usePageVariables(), {
173
- wrapper: createWrapper(defs),
174
- });
175
- expect(result.current.variables).toEqual({
176
- name: 'Alice',
177
- age: 30,
178
- active: true,
179
- });
180
- });
181
-
182
- it('should return empty variables when definitions is empty array', () => {
183
- const { result } = renderHook(() => usePageVariables(), {
184
- wrapper: createWrapper([]),
185
- });
186
- expect(result.current.variables).toEqual({});
187
- });
188
-
189
- it('should return empty variables when definitions is undefined', () => {
190
- const { result } = renderHook(() => usePageVariables(), {
191
- wrapper: createWrapper(undefined),
192
- });
193
- expect(result.current.variables).toEqual({});
194
- });
195
- });
196
-
197
- // ---------------------------------------------------------------------------
198
- // setVariable
199
- // ---------------------------------------------------------------------------
200
-
201
- describe('usePageVariables — setVariable', () => {
202
- it('should update a single variable', () => {
203
- const defs: PageVariable[] = [
204
- { name: 'selected', type: 'string', defaultValue: '' },
205
- ];
206
- const { result } = renderHook(() => usePageVariables(), {
207
- wrapper: createWrapper(defs),
208
- });
209
-
210
- act(() => {
211
- result.current.setVariable('selected', 'item-1');
212
- });
213
- expect(result.current.variables.selected).toBe('item-1');
214
- });
215
-
216
- it('should not overwrite other variables', () => {
217
- const defs: PageVariable[] = [
218
- { name: 'a', type: 'string', defaultValue: 'alpha' },
219
- { name: 'b', type: 'string', defaultValue: 'beta' },
220
- ];
221
- const { result } = renderHook(() => usePageVariables(), {
222
- wrapper: createWrapper(defs),
223
- });
224
-
225
- act(() => {
226
- result.current.setVariable('a', 'updated');
227
- });
228
- expect(result.current.variables.a).toBe('updated');
229
- expect(result.current.variables.b).toBe('beta');
230
- });
231
-
232
- it('should allow setting a new key not in definitions', () => {
233
- const defs: PageVariable[] = [
234
- { name: 'known', type: 'string', defaultValue: 'x' },
235
- ];
236
- const { result } = renderHook(() => usePageVariables(), {
237
- wrapper: createWrapper(defs),
238
- });
239
-
240
- act(() => {
241
- result.current.setVariable('dynamic', 'value');
242
- });
243
- expect(result.current.variables.dynamic).toBe('value');
244
- expect(result.current.variables.known).toBe('x');
245
- });
246
- });
247
-
248
- // ---------------------------------------------------------------------------
249
- // setVariables (batch)
250
- // ---------------------------------------------------------------------------
251
-
252
- describe('usePageVariables — setVariables', () => {
253
- it('should update multiple variables at once', () => {
254
- const defs: PageVariable[] = [
255
- { name: 'x', type: 'number', defaultValue: 0 },
256
- { name: 'y', type: 'number', defaultValue: 0 },
257
- { name: 'z', type: 'number', defaultValue: 0 },
258
- ];
259
- const { result } = renderHook(() => usePageVariables(), {
260
- wrapper: createWrapper(defs),
261
- });
262
-
263
- act(() => {
264
- result.current.setVariables({ x: 10, y: 20 });
265
- });
266
- expect(result.current.variables).toEqual({ x: 10, y: 20, z: 0 });
267
- });
268
-
269
- it('should merge with existing variables', () => {
270
- const defs: PageVariable[] = [
271
- { name: 'name', type: 'string', defaultValue: 'Alice' },
272
- { name: 'age', type: 'number', defaultValue: 25 },
273
- ];
274
- const { result } = renderHook(() => usePageVariables(), {
275
- wrapper: createWrapper(defs),
276
- });
277
-
278
- act(() => {
279
- result.current.setVariable('name', 'Bob');
280
- });
281
- act(() => {
282
- result.current.setVariables({ age: 30 });
283
- });
284
- expect(result.current.variables).toEqual({ name: 'Bob', age: 30 });
285
- });
286
- });
287
-
288
- // ---------------------------------------------------------------------------
289
- // resetVariables
290
- // ---------------------------------------------------------------------------
291
-
292
- describe('usePageVariables — resetVariables', () => {
293
- it('should reset all variables to defaults', () => {
294
- const defs: PageVariable[] = [
295
- { name: 'a', type: 'string', defaultValue: 'original' },
296
- { name: 'b', type: 'number', defaultValue: 5 },
297
- ];
298
- const { result } = renderHook(() => usePageVariables(), {
299
- wrapper: createWrapper(defs),
300
- });
301
-
302
- // Mutate
303
- act(() => {
304
- result.current.setVariables({ a: 'changed', b: 99 });
305
- });
306
- expect(result.current.variables).toEqual({ a: 'changed', b: 99 });
307
-
308
- // Reset
309
- act(() => {
310
- result.current.resetVariables();
311
- });
312
- expect(result.current.variables).toEqual({ a: 'original', b: 5 });
313
- });
314
-
315
- it('should reset dynamically added variables', () => {
316
- const defs: PageVariable[] = [
317
- { name: 'x', type: 'number', defaultValue: 1 },
318
- ];
319
- const { result } = renderHook(() => usePageVariables(), {
320
- wrapper: createWrapper(defs),
321
- });
322
-
323
- act(() => {
324
- result.current.setVariable('extra', 'gone');
325
- });
326
- expect(result.current.variables.extra).toBe('gone');
327
-
328
- act(() => {
329
- result.current.resetVariables();
330
- });
331
- // 'extra' was not in definitions, so it's removed on reset
332
- expect(result.current.variables).toEqual({ x: 1 });
333
- });
334
- });
@@ -1,137 +0,0 @@
1
- /**
2
- * ObjectUI — usePerformance Tests
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
- import { describe, it, expect, vi, afterEach } from 'vitest';
10
- import { renderHook, act } from '@testing-library/react';
11
- import { usePerformance } from '../hooks/usePerformance';
12
-
13
- describe('usePerformance', () => {
14
- afterEach(() => {
15
- vi.restoreAllMocks();
16
- });
17
-
18
- it('should return default config values', () => {
19
- const { result } = renderHook(() => usePerformance());
20
-
21
- expect(result.current.config).toEqual({
22
- lazyLoad: true,
23
- cacheStrategy: 'stale-while-revalidate',
24
- prefetch: false,
25
- pageSize: 50,
26
- debounceMs: 300,
27
- virtualScroll: {
28
- enabled: false,
29
- itemHeight: 40,
30
- overscan: 5,
31
- },
32
- });
33
- });
34
-
35
- it('should merge user config with defaults', () => {
36
- const { result } = renderHook(() =>
37
- usePerformance({
38
- lazyLoad: false,
39
- pageSize: 100,
40
- virtualScroll: { enabled: true, itemHeight: 60 },
41
- }),
42
- );
43
-
44
- expect(result.current.config.lazyLoad).toBe(false);
45
- expect(result.current.config.pageSize).toBe(100);
46
- expect(result.current.config.virtualScroll.enabled).toBe(true);
47
- expect(result.current.config.virtualScroll.itemHeight).toBe(60);
48
- // Default overscan preserved
49
- expect(result.current.config.virtualScroll.overscan).toBe(5);
50
- });
51
-
52
- it('should accept all cache strategy values', () => {
53
- for (const strategy of [
54
- 'none',
55
- 'cache-first',
56
- 'network-first',
57
- 'stale-while-revalidate',
58
- ] as const) {
59
- const { result } = renderHook(() =>
60
- usePerformance({ cacheStrategy: strategy }),
61
- );
62
- expect(result.current.config.cacheStrategy).toBe(strategy);
63
- }
64
- });
65
-
66
- it('should track render count via markRenderStart', () => {
67
- const { result } = renderHook(() => usePerformance());
68
-
69
- // Initial render count should be 0 (only increments when markRenderStart stop is called)
70
- expect(result.current.metrics.renderCount).toBe(0);
71
-
72
- // After calling markRenderStart and its stop function, count should increment
73
- act(() => {
74
- const stop = result.current.markRenderStart();
75
- stop();
76
- });
77
- expect(result.current.metrics.renderCount).toBeGreaterThanOrEqual(1);
78
- });
79
-
80
- it('should provide markRenderStart that returns stop function', () => {
81
- const { result } = renderHook(() => usePerformance());
82
-
83
- let stop: () => void;
84
- act(() => {
85
- stop = result.current.markRenderStart();
86
- });
87
-
88
- // stop should be a function
89
- expect(typeof stop!).toBe('function');
90
-
91
- act(() => {
92
- stop();
93
- });
94
-
95
- // After calling stop, lastRenderDuration should be a number
96
- expect(result.current.metrics.lastRenderDuration).toBeTypeOf('number');
97
- expect(result.current.metrics.lastRenderDuration!).toBeGreaterThanOrEqual(0);
98
- });
99
-
100
- it('should create a debounced function', async () => {
101
- const { result } = renderHook(() => usePerformance({ debounceMs: 100 }));
102
-
103
- const callback = vi.fn();
104
- let debounced: typeof callback;
105
-
106
- act(() => {
107
- debounced = result.current.debounce(callback);
108
- });
109
-
110
- // Call the debounced function multiple times in quick succession
111
- act(() => {
112
- debounced!('arg1');
113
- });
114
-
115
- // Callback not called immediately
116
- expect(callback).not.toHaveBeenCalled();
117
-
118
- // Wait for debounce to fire
119
- await act(async () => {
120
- await new Promise((resolve) => setTimeout(resolve, 150));
121
- });
122
-
123
- // Called once with the last arguments
124
- expect(callback).toHaveBeenCalledTimes(1);
125
- expect(callback).toHaveBeenCalledWith('arg1');
126
- });
127
-
128
- it('should provide initial metrics with null values', () => {
129
- const { result } = renderHook(() => usePerformance());
130
-
131
- // FCP and LCP may be null in test environment
132
- expect(result.current.metrics.lcp).toBeNull();
133
- expect(result.current.metrics.fcp).toBeNull();
134
- expect(result.current.metrics.tti).toBeNull();
135
- expect(result.current.metrics.lastRenderDuration).toBeNull();
136
- });
137
- });