@object-ui/react 3.1.5 → 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 (109) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +28 -3
  3. package/dist/SchemaRenderer.js +2 -2
  4. package/dist/components/form/FieldFactory.js +5 -2
  5. package/dist/context/AppShellContext.d.ts +26 -0
  6. package/dist/context/AppShellContext.js +67 -0
  7. package/dist/context/index.d.ts +1 -7
  8. package/dist/context/index.js +1 -7
  9. package/dist/hooks/index.d.ts +1 -0
  10. package/dist/hooks/index.js +1 -0
  11. package/dist/hooks/useDataRefresh.d.ts +36 -0
  12. package/dist/hooks/useDataRefresh.js +50 -0
  13. package/dist/hooks/useDiscovery.d.ts +12 -0
  14. package/dist/hooks/useDiscovery.js +6 -0
  15. package/dist/hooks/usePerformanceBudget.js +1 -1
  16. package/package.json +32 -9
  17. package/.turbo/turbo-build.log +0 -4
  18. package/src/LazyPluginLoader.tsx +0 -174
  19. package/src/SchemaRenderer.tsx +0 -266
  20. package/src/__tests__/LazyPluginLoader.test.tsx +0 -176
  21. package/src/__tests__/SchemaRenderer.aria.test.tsx +0 -118
  22. package/src/__tests__/SchemaRenderer.debug.test.tsx +0 -69
  23. package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +0 -114
  24. package/src/__tests__/SchemaRenderer.expressions.test.tsx +0 -131
  25. package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +0 -132
  26. package/src/__tests__/ThemeProvider.test.tsx +0 -451
  27. package/src/__tests__/useNavigationOverlay.test.ts +0 -578
  28. package/src/__tests__/useOffline.test.ts +0 -198
  29. package/src/__tests__/usePageTransition.test.ts +0 -214
  30. package/src/__tests__/usePageVariables.test.tsx +0 -334
  31. package/src/__tests__/usePerformance.test.ts +0 -137
  32. package/src/__tests__/useViewData.test.tsx +0 -422
  33. package/src/__tests__/view-switching.test.tsx +0 -456
  34. package/src/components/form/FieldFactory.tsx +0 -509
  35. package/src/components/form/FormRenderer.test.tsx +0 -744
  36. package/src/components/form/FormRenderer.tsx +0 -258
  37. package/src/components/form/README.md +0 -352
  38. package/src/components/form/index.ts +0 -12
  39. package/src/context/ActionContext.tsx +0 -213
  40. package/src/context/DndContext.tsx +0 -260
  41. package/src/context/NotificationContext.tsx +0 -280
  42. package/src/context/SchemaRendererContext.tsx +0 -48
  43. package/src/context/ThemeContext.tsx +0 -325
  44. package/src/context/__tests__/ActionContext.test.tsx +0 -174
  45. package/src/context/__tests__/DndContext.test.tsx +0 -150
  46. package/src/context/__tests__/NotificationContext.test.tsx +0 -176
  47. package/src/context/__tests__/useDataScope.test.tsx +0 -91
  48. package/src/context/index.ts +0 -13
  49. package/src/hooks/__tests__/useActionEngine.test.ts +0 -170
  50. package/src/hooks/__tests__/useActionRunner.test.ts +0 -153
  51. package/src/hooks/__tests__/useAnimation.test.ts +0 -82
  52. package/src/hooks/__tests__/useColumnSummary.test.ts +0 -93
  53. package/src/hooks/__tests__/useCrudShortcuts.test.ts +0 -85
  54. package/src/hooks/__tests__/useDebugMode.test.ts +0 -83
  55. package/src/hooks/__tests__/useDensityMode.test.ts +0 -81
  56. package/src/hooks/__tests__/useDiscovery.test.tsx +0 -149
  57. package/src/hooks/__tests__/useDynamicApp.test.ts +0 -161
  58. package/src/hooks/__tests__/useETagCache.test.ts +0 -153
  59. package/src/hooks/__tests__/useExpression.test.ts +0 -86
  60. package/src/hooks/__tests__/useFocusTrap.test.ts +0 -294
  61. package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +0 -144
  62. package/src/hooks/__tests__/usePageTransition.test.ts +0 -158
  63. package/src/hooks/__tests__/usePerformanceBudget.test.ts +0 -157
  64. package/src/hooks/__tests__/useReducedMotion.test.ts +0 -104
  65. package/src/hooks/__tests__/useSchemaPersistence.test.ts +0 -220
  66. package/src/hooks/__tests__/useViewSharing.test.ts +0 -121
  67. package/src/hooks/__tests__/useViewTransition.test.ts +0 -61
  68. package/src/hooks/index.ts +0 -35
  69. package/src/hooks/useActionEngine.ts +0 -84
  70. package/src/hooks/useActionRunner.ts +0 -119
  71. package/src/hooks/useAnimation.ts +0 -117
  72. package/src/hooks/useClientNotifications.ts +0 -251
  73. package/src/hooks/useColumnSummary.ts +0 -87
  74. package/src/hooks/useCrudShortcuts.ts +0 -126
  75. package/src/hooks/useDebugMode.ts +0 -95
  76. package/src/hooks/useDensityMode.ts +0 -102
  77. package/src/hooks/useDiscovery.ts +0 -154
  78. package/src/hooks/useDynamicApp.ts +0 -142
  79. package/src/hooks/useETagCache.ts +0 -404
  80. package/src/hooks/useExpression.ts +0 -56
  81. package/src/hooks/useFocusManagement.ts +0 -248
  82. package/src/hooks/useFocusTrap.ts +0 -138
  83. package/src/hooks/useGlobalUndo.ts +0 -98
  84. package/src/hooks/useKeyboardShortcuts.ts +0 -119
  85. package/src/hooks/useNavigationOverlay.ts +0 -190
  86. package/src/hooks/useOffline.ts +0 -301
  87. package/src/hooks/usePageTransition.ts +0 -187
  88. package/src/hooks/usePageVariables.tsx +0 -157
  89. package/src/hooks/usePerformance.ts +0 -246
  90. package/src/hooks/usePerformanceBudget.ts +0 -313
  91. package/src/hooks/useReducedMotion.ts +0 -53
  92. package/src/hooks/useSchemaPersistence.ts +0 -222
  93. package/src/hooks/useViewData.ts +0 -201
  94. package/src/hooks/useViewSharing.ts +0 -140
  95. package/src/hooks/useViewTransition.ts +0 -144
  96. package/src/index.ts +0 -41
  97. package/src/spec-bridge/SpecBridge.ts +0 -64
  98. package/src/spec-bridge/__tests__/P1SpecBridge.test.ts +0 -855
  99. package/src/spec-bridge/__tests__/SpecBridge.test.ts +0 -550
  100. package/src/spec-bridge/bridges/dashboard.ts +0 -180
  101. package/src/spec-bridge/bridges/form-view.ts +0 -109
  102. package/src/spec-bridge/bridges/list-view.ts +0 -187
  103. package/src/spec-bridge/bridges/page.ts +0 -136
  104. package/src/spec-bridge/index.ts +0 -14
  105. package/src/spec-bridge/types.ts +0 -38
  106. package/src/utils/i18n.ts +0 -10
  107. package/tsconfig.json +0 -17
  108. package/tsconfig.tsbuildinfo +0 -1
  109. package/vitest.config.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @object-ui/react
2
2
 
3
+ ## 3.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @object-ui/types@3.3.1
8
+ - @object-ui/core@3.3.1
9
+ - @object-ui/i18n@3.3.1
10
+ - @object-ui/data-objectstack@3.3.1
11
+
12
+ ## 3.3.0
13
+
14
+ ### Patch Changes
15
+
16
+ - @object-ui/types@3.3.0
17
+ - @object-ui/core@3.3.0
18
+ - @object-ui/i18n@3.3.0
19
+
20
+ ## 3.2.0
21
+
22
+ ### Patch Changes
23
+
24
+ - @object-ui/types@3.2.0
25
+ - @object-ui/core@3.2.0
26
+ - @object-ui/i18n@3.2.0
27
+
3
28
  ## 3.1.5
4
29
 
5
30
  ### Patch Changes
package/README.md CHANGED
@@ -120,13 +120,18 @@ Access server discovery information including preview mode detection:
120
120
  import { useDiscovery } from '@object-ui/react'
121
121
 
122
122
  function MyComponent() {
123
- const { discovery, isLoading, isAuthEnabled } = useDiscovery()
123
+ const { discovery, isLoading, isAuthEnabled, isAiEnabled } = useDiscovery()
124
124
 
125
125
  // Check if the server is in preview mode
126
126
  if (discovery?.mode === 'preview') {
127
127
  console.log('Preview mode active:', discovery.previewMode)
128
128
  }
129
129
 
130
+ // Check if AI service is available
131
+ if (isAiEnabled) {
132
+ console.log('AI service route:', discovery?.services?.ai?.route)
133
+ }
134
+
130
135
  return <div>Server: {discovery?.name}</div>
131
136
  }
132
137
  ```
@@ -139,7 +144,7 @@ function MyComponent() {
139
144
  | `version` | `string` | Server version |
140
145
  | `mode` | `string` | Runtime mode (e.g. `'development'`, `'production'`, `'preview'`) |
141
146
  | `previewMode` | `object` | Preview mode configuration (present when mode is `'preview'`) |
142
- | `services` | `object` | Service availability status (auth, data, metadata) |
147
+ | `services` | `object` | Service availability status (auth, data, metadata, ai) |
143
148
  | `capabilities` | `string[]` | API capabilities |
144
149
 
145
150
  The `previewMode` object contains:
@@ -157,6 +162,26 @@ The `previewMode` object contains:
157
162
 
158
163
  See [full documentation](https://objectui.org/api/react) for detailed API reference.
159
164
 
165
+ <!-- release-metadata:v3.3.0 -->
166
+
167
+ ## Compatibility
168
+
169
+ - **React:** 18.x or 19.x
170
+ - **Node.js:** ≥ 18
171
+ - **TypeScript:** ≥ 5.0 (strict mode)
172
+ - **`@objectstack/spec`:** ^3.3.0
173
+ - **`@objectstack/client`:** ^3.3.0
174
+ - **Tailwind CSS:** ≥ 3.4 (for packages with UI)
175
+
176
+ ## Links
177
+
178
+ - 📚 [Documentation](https://www.objectui.org/docs/packages/react)
179
+ - 📦 [npm package](https://www.npmjs.com/package/@object-ui/react)
180
+ - 📝 [Changelog](./CHANGELOG.md)
181
+ - 🐛 [Report an issue](https://github.com/objectstack-ai/objectui/issues)
182
+ - 🤝 [Contributing Guide](https://github.com/objectstack-ai/objectui/blob/main/CONTRIBUTING.md)
183
+ - 🗺️ [Roadmap](https://github.com/objectstack-ai/objectui/blob/main/ROADMAP.md)
184
+
160
185
  ## License
161
186
 
162
- MIT
187
+ MIT — see [LICENSE](./LICENSE).
@@ -56,7 +56,7 @@ export class SchemaErrorBoundary extends Component {
56
56
  render() {
57
57
  if (this.state.hasError && this.state.error) {
58
58
  const error = this.state.error;
59
- const isDev = process.env.NODE_ENV !== 'production';
59
+ const isDev = globalThis.process?.env?.NODE_ENV !== 'production';
60
60
  const objuiError = isObjectUIError(error) ? error : null;
61
61
  return (_jsxs("div", { className: "p-4 border border-orange-400 rounded bg-orange-50 text-orange-700 my-2", role: "alert", children: [_jsxs("p", { className: "font-medium", children: ["Component", this.props.componentType ? ` "${this.props.componentType}"` : '', " failed to render"] }), _jsx("p", { className: "text-sm mt-1", children: error.message }), isDev && objuiError?.code && (_jsxs("p", { className: "text-xs mt-1 text-orange-500", children: ["Error code: ", objuiError.code, objuiError.details?.suggestion ? (_jsxs("span", { className: "block mt-0.5", children: ["\uD83D\uDCA1 ", String(objuiError.details.suggestion)] })) : null] })), _jsx("button", { onClick: this.handleRetry, className: "mt-2 text-sm underline hover:no-underline", children: "Retry" })] }));
62
62
  }
@@ -137,7 +137,7 @@ export const SchemaRenderer = forwardRef(({ schema, ...props }, _ref) => {
137
137
  if (!Component) {
138
138
  debugLog('schema', 'Component not found in registry', { type: evaluatedSchema.type });
139
139
  const errorInfo = ERROR_CODES['OBJUI-001'];
140
- return (_jsxs("div", { className: "p-4 border border-red-500 rounded text-red-500 bg-red-50 my-2", role: "alert", children: [_jsxs("p", { className: "font-medium", children: ["Unknown component type: ", _jsx("strong", { children: evaluatedSchema.type })] }), process.env.NODE_ENV !== 'production' && (_jsxs("p", { className: "text-xs mt-1", children: ["\uD83D\uDCA1 ", errorInfo.suggestion, " (OBJUI-001)"] })), _jsx("pre", { className: "text-xs mt-2 overflow-auto", children: JSON.stringify(evaluatedSchema, null, 2) })] }));
140
+ return (_jsxs("div", { className: "p-4 border border-red-500 rounded text-red-500 bg-red-50 my-2", role: "alert", children: [_jsxs("p", { className: "font-medium", children: ["Unknown component type: ", _jsx("strong", { children: evaluatedSchema.type })] }), globalThis.process?.env?.NODE_ENV !== 'production' && (_jsxs("p", { className: "text-xs mt-1", children: ["\uD83D\uDCA1 ", errorInfo.suggestion, " (OBJUI-001)"] })), _jsx("pre", { className: "text-xs mt-2 overflow-auto", children: JSON.stringify(evaluatedSchema, null, 2) })] }));
141
141
  }
142
142
  // Note: We don't forward the ref to the Component because components in the registry
143
143
  // may not support refs. The SchemaRenderer itself can still receive refs for its own use.
@@ -1,11 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { resolveI18nLabel } from '../../utils/i18n';
3
+ import { createSafeTranslation } from '@object-ui/i18n';
4
+ const useSafeTranslation = createSafeTranslation({ 'common.selectOption': 'Select an option' }, 'common.selectOption');
3
5
  /**
4
6
  * FieldFactory component that renders different input types based on
5
7
  * the widget property or field type
6
8
  */
7
9
  export const FieldFactory = ({ field, methods, disabled = false, }) => {
8
10
  const { register, formState: { errors } } = methods;
11
+ const { t } = useSafeTranslation();
9
12
  // Cast to extended field for properties not in base schema
10
13
  const extendedField = field;
11
14
  // Determine the widget type
@@ -61,7 +64,7 @@ export const FieldFactory = ({ field, methods, disabled = false, }) => {
61
64
  return renderField(_jsxs("select", { id: fieldName, disabled: disabled, multiple: extendedField.multiple, className: "w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed", ...register(fieldName, {
62
65
  required: field.required ? `${fieldLabel || fieldName} is required` : false,
63
66
  setValueAs: handleMultipleSelectValue,
64
- }), children: [!extendedField.multiple && _jsx("option", { value: "", children: fieldPlaceholder || 'Select an option' }), extendedField.options?.map((option) => (_jsx("option", { value: option.value, disabled: option.disabled, children: option.label }, option.value)))] }));
67
+ }), children: [!extendedField.multiple && _jsx("option", { value: "", children: fieldPlaceholder || t('common.selectOption') }), extendedField.options?.map((option) => (_jsx("option", { value: option.value, disabled: option.disabled, children: option.label }, option.value)))] }));
65
68
  case 'date':
66
69
  return renderField(_jsx("input", { id: fieldName, type: "date", placeholder: fieldPlaceholder, disabled: disabled, className: "w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed", ...register(fieldName, {
67
70
  required: field.required ? `${fieldLabel || fieldName} is required` : false,
@@ -118,7 +121,7 @@ export const FieldFactory = ({ field, methods, disabled = false, }) => {
118
121
  return renderField(_jsxs("select", { id: fieldName, disabled: disabled, multiple: extendedField.multiple, className: "w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed", ...register(fieldName, {
119
122
  required: field.required ? `${fieldLabel || fieldName} is required` : false,
120
123
  setValueAs: handleMultipleSelectValue,
121
- }), children: [!extendedField.multiple && _jsx("option", { value: "", children: fieldPlaceholder || 'Select an option' }), extendedField.options?.map((option) => (_jsx("option", { value: option.value, disabled: option.disabled, children: option.label }, option.value)))] }));
124
+ }), children: [!extendedField.multiple && _jsx("option", { value: "", children: fieldPlaceholder || t('common.selectOption') }), extendedField.options?.map((option) => (_jsx("option", { value: option.value, disabled: option.disabled, children: option.label }, option.value)))] }));
122
125
  case 'user':
123
126
  case 'owner':
124
127
  return renderField(_jsxs("select", { id: fieldName, disabled: disabled, multiple: extendedField.multiple, className: "w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed", ...register(fieldName, {
@@ -0,0 +1,26 @@
1
+ import type { ObjectStackAdapter } from '@object-ui/data-objectstack';
2
+ export declare const AdapterCtx: import("react").Context<ObjectStackAdapter<unknown> | null>;
3
+ export declare function useAdapter(): ObjectStackAdapter | null;
4
+ export interface MetadataState {
5
+ apps: any[];
6
+ objects: any[];
7
+ dashboards: any[];
8
+ reports: any[];
9
+ pages: any[];
10
+ loading: boolean;
11
+ error: Error | null;
12
+ }
13
+ export interface MetadataContextValue extends MetadataState {
14
+ refresh: (type?: string) => Promise<void>;
15
+ invalidate: (type: string, name?: string) => void;
16
+ ensureType: (type: string) => Promise<any[]>;
17
+ getItem: (type: string, name: string) => Promise<any | null>;
18
+ getItemsByType: (type: string) => any[];
19
+ }
20
+ export declare const MetadataCtx: import("react").Context<MetadataContextValue | null>;
21
+ export declare function useMetadata(): MetadataContextValue;
22
+ export declare function useMetadataItem(type: string, name: string | undefined | null): {
23
+ item: any | null;
24
+ loading: boolean;
25
+ error: Error | null;
26
+ };
@@ -0,0 +1,67 @@
1
+ import { createContext, useContext, useEffect, useState } from 'react';
2
+ // ---------------------------------------------------------------------------
3
+ // AdapterContext
4
+ // ---------------------------------------------------------------------------
5
+ export const AdapterCtx = createContext(null);
6
+ export function useAdapter() {
7
+ return useContext(AdapterCtx);
8
+ }
9
+ export const MetadataCtx = createContext(null);
10
+ export function useMetadata() {
11
+ const ctx = useContext(MetadataCtx);
12
+ if (!ctx) {
13
+ // Graceful fallback: when a consumer is rendered outside a MetadataProvider
14
+ // (common in unit tests that only need to assert on rendering), return an
15
+ // empty no-op implementation rather than crash. Production code paths
16
+ // should always wrap in <MetadataProvider>.
17
+ return {
18
+ apps: [],
19
+ objects: [],
20
+ dashboards: [],
21
+ reports: [],
22
+ pages: [],
23
+ loading: false,
24
+ error: null,
25
+ refresh: async () => { },
26
+ invalidate: () => { },
27
+ ensureType: async () => [],
28
+ getItem: async () => null,
29
+ getItemsByType: () => [],
30
+ };
31
+ }
32
+ return ctx;
33
+ }
34
+ export function useMetadataItem(type, name) {
35
+ const { getItem } = useMetadata();
36
+ const [state, setState] = useState({
37
+ item: null,
38
+ loading: !!name,
39
+ error: null,
40
+ });
41
+ useEffect(() => {
42
+ if (!name) {
43
+ setState({ item: null, loading: false, error: null });
44
+ return;
45
+ }
46
+ let cancelled = false;
47
+ setState(s => ({ ...s, loading: true, error: null }));
48
+ getItem(type, name)
49
+ .then(item => {
50
+ if (!cancelled)
51
+ setState({ item, loading: false, error: null });
52
+ })
53
+ .catch(err => {
54
+ if (!cancelled) {
55
+ setState({
56
+ item: null,
57
+ loading: false,
58
+ error: err instanceof Error ? err : new Error(String(err)),
59
+ });
60
+ }
61
+ });
62
+ return () => {
63
+ cancelled = true;
64
+ };
65
+ }, [type, name, getItem]);
66
+ return state;
67
+ }
@@ -1,12 +1,6 @@
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
1
  export * from './SchemaRendererContext';
9
2
  export * from './ActionContext';
10
3
  export * from './ThemeContext';
11
4
  export * from './NotificationContext';
12
5
  export * from './DndContext';
6
+ export * from './AppShellContext';
@@ -1,12 +1,6 @@
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
1
  export * from './SchemaRendererContext';
9
2
  export * from './ActionContext';
10
3
  export * from './ThemeContext';
11
4
  export * from './NotificationContext';
12
5
  export * from './DndContext';
6
+ export * from './AppShellContext';
@@ -32,3 +32,4 @@ export * from './useSchemaPersistence';
32
32
  export * from './useGlobalUndo';
33
33
  export * from './useDebugMode';
34
34
  export * from './useActionEngine';
35
+ export * from './useDataRefresh';
@@ -32,3 +32,4 @@ export * from './useSchemaPersistence';
32
32
  export * from './useGlobalUndo';
33
33
  export * from './useDebugMode';
34
34
  export * from './useActionEngine';
35
+ export * from './useDataRefresh';
@@ -0,0 +1,36 @@
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 { DataSource } from '@object-ui/types';
9
+ /**
10
+ * Reusable hook that encapsulates the data-refresh pattern:
11
+ * 1. A numeric `refreshKey` that triggers React effect re-runs when incremented.
12
+ * 2. An imperative `refresh()` function to trigger a re-fetch on demand.
13
+ * 3. Auto-subscription to `DataSource.onMutation()` — if the DataSource
14
+ * implements the optional mutation event bus, the hook auto-refreshes
15
+ * whenever a mutation occurs on the matching `objectName`.
16
+ *
17
+ * @param dataSource - The DataSource instance (may be undefined during initial render)
18
+ * @param objectName - The resource/object name to watch for mutations
19
+ * @returns `{ refreshKey, refresh }` — include `refreshKey` in your effect deps
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { refreshKey, refresh } = useDataRefresh(dataSource, schema.objectName);
24
+ *
25
+ * useEffect(() => {
26
+ * dataSource.find(objectName, params).then(setData);
27
+ * }, [objectName, refreshKey]);
28
+ *
29
+ * // Or trigger manually:
30
+ * <button onClick={refresh}>Refresh</button>
31
+ * ```
32
+ */
33
+ export declare function useDataRefresh(dataSource: DataSource | undefined, objectName: string | undefined): {
34
+ refreshKey: number;
35
+ refresh: () => void;
36
+ };
@@ -0,0 +1,50 @@
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 { useState, useCallback, useEffect } from 'react';
9
+ /**
10
+ * Reusable hook that encapsulates the data-refresh pattern:
11
+ * 1. A numeric `refreshKey` that triggers React effect re-runs when incremented.
12
+ * 2. An imperative `refresh()` function to trigger a re-fetch on demand.
13
+ * 3. Auto-subscription to `DataSource.onMutation()` — if the DataSource
14
+ * implements the optional mutation event bus, the hook auto-refreshes
15
+ * whenever a mutation occurs on the matching `objectName`.
16
+ *
17
+ * @param dataSource - The DataSource instance (may be undefined during initial render)
18
+ * @param objectName - The resource/object name to watch for mutations
19
+ * @returns `{ refreshKey, refresh }` — include `refreshKey` in your effect deps
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { refreshKey, refresh } = useDataRefresh(dataSource, schema.objectName);
24
+ *
25
+ * useEffect(() => {
26
+ * dataSource.find(objectName, params).then(setData);
27
+ * }, [objectName, refreshKey]);
28
+ *
29
+ * // Or trigger manually:
30
+ * <button onClick={refresh}>Refresh</button>
31
+ * ```
32
+ */
33
+ export function useDataRefresh(dataSource, objectName) {
34
+ const [refreshKey, setRefreshKey] = useState(0);
35
+ const refresh = useCallback(() => {
36
+ setRefreshKey(k => k + 1);
37
+ }, []);
38
+ // Auto-subscribe to DataSource mutation events
39
+ useEffect(() => {
40
+ if (!dataSource?.onMutation || !objectName)
41
+ return;
42
+ const unsub = dataSource.onMutation((event) => {
43
+ if (event.resource === objectName) {
44
+ setRefreshKey(k => k + 1);
45
+ }
46
+ });
47
+ return unsub;
48
+ }, [dataSource, objectName]);
49
+ return { refreshKey, refresh };
50
+ }
@@ -42,6 +42,13 @@ export interface DiscoveryInfo {
42
42
  enabled: boolean;
43
43
  status?: 'available' | 'unavailable';
44
44
  };
45
+ /** AI service configuration */
46
+ ai?: {
47
+ enabled: boolean;
48
+ status?: 'available' | 'unavailable';
49
+ /** AI service endpoint route (e.g. '/api/v1/ai') */
50
+ route?: string;
51
+ };
45
52
  [key: string]: any;
46
53
  };
47
54
  /** API capabilities */
@@ -86,4 +93,9 @@ export declare function useDiscovery(): {
86
93
  * Defaults to true if discovery data is not available.
87
94
  */
88
95
  isAuthEnabled: boolean;
96
+ /**
97
+ * Check if AI service is enabled and available on the server.
98
+ * Defaults to false if discovery data is not available.
99
+ */
100
+ isAiEnabled: boolean;
89
101
  };
@@ -92,5 +92,11 @@ export function useDiscovery() {
92
92
  * Defaults to true if discovery data is not available.
93
93
  */
94
94
  isAuthEnabled: discovery?.services?.auth?.enabled ?? true,
95
+ /**
96
+ * Check if AI service is enabled and available on the server.
97
+ * Defaults to false if discovery data is not available.
98
+ */
99
+ isAiEnabled: discovery?.services?.ai?.enabled === true &&
100
+ discovery?.services?.ai?.status === 'available',
95
101
  };
96
102
  }
@@ -122,7 +122,7 @@ export function usePerformanceBudget(userBudget = {}) {
122
122
  timestamp: Date.now(),
123
123
  };
124
124
  setViolations((prev) => [...prev, violation]);
125
- if (budget.warnOnViolation && process.env.NODE_ENV !== 'production') {
125
+ if (budget.warnOnViolation && globalThis.process?.env?.NODE_ENV !== 'production') {
126
126
  console.warn(`[ObjectUI] Performance budget violated: ${metric} = ${violation.actual} (budget: ${budgetValue})`);
127
127
  }
128
128
  onViolationRef.current?.(violation);
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@object-ui/react",
3
- "version": "3.1.5",
3
+ "version": "3.3.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "React bindings and SchemaRenderer component for Object UI",
7
- "homepage": "https://www.objectui.org",
7
+ "homepage": "https://www.objectui.org/docs/packages/react",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/objectstack-ai/objectui.git",
10
+ "url": "git+https://github.com/objectstack-ai/objectui.git",
11
11
  "directory": "packages/react"
12
12
  },
13
13
  "bugs": {
@@ -24,11 +24,12 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@objectstack/spec": "^3.3.0",
28
- "react-hook-form": "^7.72.0",
29
- "@object-ui/core": "3.1.5",
30
- "@object-ui/i18n": "3.1.5",
31
- "@object-ui/types": "3.1.5"
27
+ "@objectstack/spec": "^4.0.4",
28
+ "react-hook-form": "^7.75.0",
29
+ "@object-ui/core": "3.3.1",
30
+ "@object-ui/data-objectstack": "3.3.1",
31
+ "@object-ui/i18n": "3.3.1",
32
+ "@object-ui/types": "3.3.1"
32
33
  },
33
34
  "peerDependencies": {
34
35
  "react": "^18.0.0 || ^19.0.0",
@@ -37,8 +38,30 @@
37
38
  "devDependencies": {
38
39
  "@types/react": "19.2.14",
39
40
  "@types/react-dom": "19.2.3",
40
- "typescript": "^5.9.3"
41
+ "typescript": "^6.0.3"
41
42
  },
43
+ "keywords": [
44
+ "objectui",
45
+ "sdui",
46
+ "schema-driven-ui",
47
+ "react",
48
+ "tailwind",
49
+ "shadcn",
50
+ "objectstack",
51
+ "renderer",
52
+ "schema-renderer",
53
+ "hooks"
54
+ ],
55
+ "author": "ObjectStack Team <team@objectstack.ai>",
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "files": [
60
+ "dist",
61
+ "README.md",
62
+ "CHANGELOG.md",
63
+ "LICENSE"
64
+ ],
42
65
  "scripts": {
43
66
  "build": "tsc",
44
67
  "test": "vitest run",
@@ -1,4 +0,0 @@
1
-
2
- > @object-ui/react@3.1.5 build /home/runner/work/objectui/objectui/packages/react
3
- > tsc
4
-
@@ -1,174 +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 React, { lazy, Suspense, Component } from 'react';
10
-
11
- export interface LazyPluginOptions {
12
- /**
13
- * Fallback component to show while loading
14
- */
15
- fallback?: React.ReactNode;
16
- /**
17
- * Number of retry attempts on load failure (default: 2)
18
- */
19
- retries?: number;
20
- /**
21
- * Delay in ms between retries (default: 1000)
22
- */
23
- retryDelay?: number;
24
- /**
25
- * Custom error fallback component
26
- */
27
- errorFallback?: React.ComponentType<{ error: Error; retry: () => void }>;
28
- }
29
-
30
- /**
31
- * Error boundary for lazy-loaded plugins
32
- */
33
- interface ErrorBoundaryState {
34
- hasError: boolean;
35
- error: Error | null;
36
- }
37
-
38
- class PluginErrorBoundary extends Component<
39
- { fallback?: React.ComponentType<{ error: Error; retry: () => void }>; children: React.ReactNode },
40
- ErrorBoundaryState
41
- > {
42
- state: ErrorBoundaryState = { hasError: false, error: null };
43
-
44
- static getDerivedStateFromError(error: Error): ErrorBoundaryState {
45
- return { hasError: true, error };
46
- }
47
-
48
- handleRetry = () => {
49
- this.setState({ hasError: false, error: null });
50
- };
51
-
52
- render() {
53
- if (this.state.hasError && this.state.error) {
54
- const FallbackComponent = this.props.fallback;
55
- if (FallbackComponent) {
56
- return <FallbackComponent error={this.state.error} retry={this.handleRetry} />;
57
- }
58
- return null;
59
- }
60
- return this.props.children;
61
- }
62
- }
63
-
64
- /**
65
- * Create a lazy-loaded import function with retry support
66
- */
67
- function createRetryImport<P extends object>(
68
- importFn: () => Promise<{ default: React.ComponentType<P> }>,
69
- retries: number,
70
- retryDelay: number,
71
- ): () => Promise<{ default: React.ComponentType<P> }> {
72
- return () => {
73
- let attempt = 0;
74
- const tryImport = (): Promise<{ default: React.ComponentType<P> }> =>
75
- importFn().catch((err) => {
76
- attempt++;
77
- if (attempt <= retries) {
78
- return new Promise((resolve) =>
79
- setTimeout(() => resolve(tryImport()), retryDelay),
80
- );
81
- }
82
- throw err;
83
- });
84
- return tryImport();
85
- };
86
- }
87
-
88
- /**
89
- * Create a lazy-loaded plugin component with Suspense wrapper
90
- *
91
- * @param importFn - Dynamic import function that returns a module with default export
92
- * @param options - Configuration options for the lazy plugin
93
- * @returns A component that lazy loads the plugin
94
- *
95
- * @example
96
- * ```tsx
97
- * // Basic usage
98
- * const ObjectGrid = createLazyPlugin(
99
- * () => import('@object-ui/plugin-grid')
100
- * );
101
- *
102
- * // With custom fallback
103
- * const ObjectGrid = createLazyPlugin(
104
- * () => import('@object-ui/plugin-grid'),
105
- * { fallback: <div>Loading grid...</div> }
106
- * );
107
- *
108
- * // With retry and error handling
109
- * const ObjectGrid = createLazyPlugin(
110
- * () => import('@object-ui/plugin-grid'),
111
- * {
112
- * retries: 3,
113
- * errorFallback: ({ error, retry }) => (
114
- * <div>
115
- * <p>Failed to load: {error.message}</p>
116
- * <button onClick={retry}>Retry</button>
117
- * </div>
118
- * ),
119
- * }
120
- * );
121
- * ```
122
- */
123
- export function createLazyPlugin<P extends object = any>(
124
- importFn: () => Promise<{ default: React.ComponentType<P> }>,
125
- options?: LazyPluginOptions
126
- ): React.ComponentType<P> {
127
- const { retries = 2, retryDelay = 1000, errorFallback } = options || {};
128
-
129
- const retryImport = retries > 0
130
- ? createRetryImport(importFn, retries, retryDelay)
131
- : importFn;
132
-
133
- const LazyComponent = lazy(retryImport);
134
-
135
- const PluginWrapper: React.FC<P> = (props) => {
136
- const content = (
137
- <Suspense fallback={options?.fallback || null}>
138
- <LazyComponent {...props} />
139
- </Suspense>
140
- );
141
-
142
- if (errorFallback) {
143
- return (
144
- <PluginErrorBoundary fallback={errorFallback}>
145
- {content}
146
- </PluginErrorBoundary>
147
- );
148
- }
149
-
150
- return content;
151
- };
152
-
153
- return PluginWrapper;
154
- }
155
-
156
- /**
157
- * Preload a plugin module without rendering it.
158
- * Useful for preloading plugins that will be needed soon.
159
- *
160
- * @param importFn - Dynamic import function
161
- * @returns Promise that resolves when the module is loaded
162
- *
163
- * @example
164
- * ```tsx
165
- * // Preload on hover
166
- * const loadGrid = () => import('@object-ui/plugin-grid');
167
- * <button onMouseEnter={() => preloadPlugin(loadGrid)}>Show Grid</button>
168
- * ```
169
- */
170
- export function preloadPlugin<T = unknown>(
171
- importFn: () => Promise<T>,
172
- ): Promise<T> {
173
- return importFn();
174
- }