@object-ui/react 0.5.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +32 -0
  3. package/dist/LazyPluginLoader.d.ts +44 -0
  4. package/dist/LazyPluginLoader.js +92 -3
  5. package/dist/SchemaRenderer.d.ts +20 -1
  6. package/dist/SchemaRenderer.js +76 -13
  7. package/dist/components/form/FieldFactory.js +44 -40
  8. package/dist/components/form/FormRenderer.js +45 -3
  9. package/dist/context/ActionContext.d.ts +76 -0
  10. package/dist/context/ActionContext.js +139 -0
  11. package/dist/context/DndContext.d.ts +135 -0
  12. package/dist/context/DndContext.js +120 -0
  13. package/dist/context/NotificationContext.d.ts +113 -0
  14. package/dist/context/NotificationContext.js +130 -0
  15. package/dist/context/ThemeContext.d.ts +94 -0
  16. package/dist/context/ThemeContext.js +215 -0
  17. package/dist/context/index.d.ts +4 -0
  18. package/dist/context/index.js +4 -0
  19. package/dist/hooks/index.d.ts +22 -0
  20. package/dist/hooks/index.js +22 -0
  21. package/dist/hooks/useActionRunner.d.ts +21 -7
  22. package/dist/hooks/useActionRunner.js +27 -7
  23. package/dist/hooks/useAnimation.d.ts +46 -0
  24. package/dist/hooks/useAnimation.js +59 -0
  25. package/dist/hooks/useClientNotifications.d.ts +53 -0
  26. package/dist/hooks/useClientNotifications.js +190 -0
  27. package/dist/hooks/useColumnSummary.d.ts +38 -0
  28. package/dist/hooks/useColumnSummary.js +54 -0
  29. package/dist/hooks/useCrudShortcuts.d.ts +39 -0
  30. package/dist/hooks/useCrudShortcuts.js +96 -0
  31. package/dist/hooks/useDensityMode.d.ts +48 -0
  32. package/dist/hooks/useDensityMode.js +60 -0
  33. package/dist/hooks/useDiscovery.d.ts +78 -0
  34. package/dist/hooks/useDiscovery.js +96 -0
  35. package/dist/hooks/useDynamicApp.d.ts +70 -0
  36. package/dist/hooks/useDynamicApp.js +92 -0
  37. package/dist/hooks/useETagCache.d.ts +75 -0
  38. package/dist/hooks/useETagCache.js +306 -0
  39. package/dist/hooks/useFocusManagement.d.ts +89 -0
  40. package/dist/hooks/useFocusManagement.js +188 -0
  41. package/dist/hooks/useFocusTrap.d.ts +41 -0
  42. package/dist/hooks/useFocusTrap.js +103 -0
  43. package/dist/hooks/useKeyboardShortcuts.d.ts +49 -0
  44. package/dist/hooks/useKeyboardShortcuts.js +86 -0
  45. package/dist/hooks/useNavigationOverlay.d.ts +78 -0
  46. package/dist/hooks/useNavigationOverlay.js +112 -0
  47. package/dist/hooks/useOffline.d.ts +96 -0
  48. package/dist/hooks/useOffline.js +185 -0
  49. package/dist/hooks/usePageTransition.d.ts +60 -0
  50. package/dist/hooks/usePageTransition.js +111 -0
  51. package/dist/hooks/usePageVariables.d.ts +67 -0
  52. package/dist/hooks/usePageVariables.js +109 -0
  53. package/dist/hooks/usePerformance.d.ts +87 -0
  54. package/dist/hooks/usePerformance.js +165 -0
  55. package/dist/hooks/usePerformanceBudget.d.ts +78 -0
  56. package/dist/hooks/usePerformanceBudget.js +209 -0
  57. package/dist/hooks/useReducedMotion.d.ts +28 -0
  58. package/dist/hooks/useReducedMotion.js +48 -0
  59. package/dist/hooks/useSchemaPersistence.d.ts +87 -0
  60. package/dist/hooks/useSchemaPersistence.js +173 -0
  61. package/dist/hooks/useViewData.d.ts +73 -0
  62. package/dist/hooks/useViewData.js +135 -0
  63. package/dist/hooks/useViewSharing.d.ts +57 -0
  64. package/dist/hooks/useViewSharing.js +74 -0
  65. package/dist/hooks/useViewTransition.d.ts +54 -0
  66. package/dist/hooks/useViewTransition.js +83 -0
  67. package/dist/index.d.ts +1 -0
  68. package/dist/index.js +2 -0
  69. package/dist/utils/i18n.d.ts +10 -0
  70. package/dist/utils/i18n.js +12 -0
  71. package/package.json +7 -5
  72. package/src/LazyPluginLoader.tsx +129 -7
  73. package/src/SchemaRenderer.tsx +122 -13
  74. package/src/__tests__/LazyPluginLoader.test.tsx +97 -1
  75. package/src/__tests__/SchemaRenderer.aria.test.tsx +118 -0
  76. package/src/__tests__/SchemaRenderer.errorBoundary.test.tsx +114 -0
  77. package/src/__tests__/SchemaRendererProvider.smoke.test.tsx +132 -0
  78. package/src/__tests__/ThemeProvider.test.tsx +451 -0
  79. package/src/__tests__/useNavigationOverlay.test.ts +416 -0
  80. package/src/__tests__/useOffline.test.ts +198 -0
  81. package/src/__tests__/usePageTransition.test.ts +214 -0
  82. package/src/__tests__/usePageVariables.test.tsx +334 -0
  83. package/src/__tests__/usePerformance.test.ts +137 -0
  84. package/src/__tests__/useViewData.test.tsx +422 -0
  85. package/src/__tests__/view-switching.test.tsx +456 -0
  86. package/src/components/form/FieldFactory.tsx +51 -46
  87. package/src/components/form/FormRenderer.test.tsx +145 -0
  88. package/src/components/form/FormRenderer.tsx +52 -3
  89. package/src/context/ActionContext.tsx +213 -0
  90. package/src/context/DndContext.tsx +260 -0
  91. package/src/context/NotificationContext.tsx +280 -0
  92. package/src/context/ThemeContext.tsx +325 -0
  93. package/src/context/__tests__/ActionContext.test.tsx +174 -0
  94. package/src/context/__tests__/DndContext.test.tsx +150 -0
  95. package/src/context/__tests__/NotificationContext.test.tsx +176 -0
  96. package/src/context/index.ts +4 -0
  97. package/src/hooks/__tests__/useActionRunner.test.ts +153 -0
  98. package/src/hooks/__tests__/useAnimation.test.ts +82 -0
  99. package/src/hooks/__tests__/useColumnSummary.test.ts +93 -0
  100. package/src/hooks/__tests__/useDensityMode.test.ts +81 -0
  101. package/src/hooks/__tests__/useDiscovery.test.tsx +149 -0
  102. package/src/hooks/__tests__/useDynamicApp.test.ts +161 -0
  103. package/src/hooks/__tests__/useETagCache.test.ts +153 -0
  104. package/src/hooks/__tests__/useExpression.test.ts +86 -0
  105. package/src/hooks/__tests__/useFocusTrap.test.ts +47 -0
  106. package/src/hooks/__tests__/useKeyboardShortcuts.test.ts +144 -0
  107. package/src/hooks/__tests__/usePerformanceBudget.test.ts +157 -0
  108. package/src/hooks/__tests__/useSchemaPersistence.test.ts +220 -0
  109. package/src/hooks/__tests__/useViewSharing.test.ts +121 -0
  110. package/src/hooks/__tests__/useViewTransition.test.ts +61 -0
  111. package/src/hooks/index.ts +22 -1
  112. package/src/hooks/useActionRunner.ts +49 -11
  113. package/src/hooks/useAnimation.ts +117 -0
  114. package/src/hooks/useClientNotifications.ts +251 -0
  115. package/src/hooks/useColumnSummary.ts +87 -0
  116. package/src/hooks/useCrudShortcuts.ts +126 -0
  117. package/src/hooks/useDensityMode.ts +102 -0
  118. package/src/hooks/useDiscovery.ts +141 -0
  119. package/src/hooks/useDynamicApp.ts +142 -0
  120. package/src/hooks/useETagCache.ts +404 -0
  121. package/src/hooks/useFocusManagement.ts +248 -0
  122. package/src/hooks/useFocusTrap.ts +138 -0
  123. package/src/hooks/useKeyboardShortcuts.ts +119 -0
  124. package/src/hooks/useNavigationOverlay.ts +180 -0
  125. package/src/hooks/useOffline.ts +301 -0
  126. package/src/hooks/usePageTransition.ts +187 -0
  127. package/src/hooks/usePageVariables.tsx +157 -0
  128. package/src/hooks/usePerformance.ts +246 -0
  129. package/src/hooks/usePerformanceBudget.ts +313 -0
  130. package/src/hooks/useReducedMotion.ts +53 -0
  131. package/src/hooks/useSchemaPersistence.ts +222 -0
  132. package/src/hooks/useViewData.ts +201 -0
  133. package/src/hooks/useViewSharing.ts +140 -0
  134. package/src/hooks/useViewTransition.ts +144 -0
  135. package/src/index.ts +21 -0
  136. package/src/utils/i18n.ts +10 -0
  137. package/tsconfig.json +1 -0
  138. package/tsconfig.tsbuildinfo +1 -1
  139. package/dist/__tests__/LazyPluginLoader.test.d.ts +0 -8
  140. package/dist/__tests__/LazyPluginLoader.test.js +0 -49
  141. package/dist/components/form/FormRenderer.test.d.ts +0 -8
  142. package/dist/components/form/FormRenderer.test.js +0 -534
  143. package/dist/index.test.d.ts +0 -8
  144. package/dist/index.test.js +0 -13
@@ -0,0 +1,130 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * ObjectUI
4
+ * Copyright (c) 2024-present ObjectStack Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ /**
10
+ * @object-ui/react - Notification Context
11
+ *
12
+ * Provides a spec-driven notification system to the component tree.
13
+ * Implements NotificationSchema, NotificationConfigSchema, and
14
+ * NotificationActionSchema from @objectstack/spec v2.0.7.
15
+ */
16
+ import { createContext, useCallback, useContext, useMemo, useState } from 'react';
17
+ let notificationCounter = 0;
18
+ const NotificationCtx = createContext(null);
19
+ /**
20
+ * NotificationProvider — Provides a spec-driven notification system.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * <NotificationProvider
25
+ * config={{ position: 'top-right', defaultDuration: 5000, maxVisible: 5 }}
26
+ * onToast={(n) => toast[n.severity](n.title, { description: n.message })}
27
+ * >
28
+ * <App />
29
+ * </NotificationProvider>
30
+ * ```
31
+ */
32
+ export const NotificationProvider = ({ children, config: userConfig = {}, onToast, }) => {
33
+ const config = useMemo(() => ({
34
+ position: 'top-right',
35
+ defaultDuration: 5000,
36
+ maxVisible: 5,
37
+ stacking: true,
38
+ ...userConfig,
39
+ }),
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ [JSON.stringify(userConfig)]);
42
+ const [notifications, setNotifications] = useState([]);
43
+ const notify = useCallback((input) => {
44
+ const id = `notification-${++notificationCounter}`;
45
+ const notification = {
46
+ ...input,
47
+ id,
48
+ createdAt: new Date(),
49
+ read: false,
50
+ };
51
+ setNotifications((prev) => [notification, ...prev]);
52
+ // Delegate to external toast handler if provided
53
+ if (onToast) {
54
+ onToast(notification);
55
+ }
56
+ // Auto-dismiss non-persistent notifications
57
+ const duration = input.duration ?? config.defaultDuration ?? 5000;
58
+ if (duration > 0) {
59
+ setTimeout(() => {
60
+ setNotifications((prev) => prev.filter((n) => n.id !== id));
61
+ }, duration);
62
+ }
63
+ return id;
64
+ }, [config.defaultDuration, onToast]);
65
+ const info = useCallback((title, message) => notify({ title, message, severity: 'info' }), [notify]);
66
+ const success = useCallback((title, message) => notify({ title, message, severity: 'success' }), [notify]);
67
+ const warning = useCallback((title, message) => notify({ title, message, severity: 'warning' }), [notify]);
68
+ const error = useCallback((title, message) => notify({ title, message, severity: 'error' }), [notify]);
69
+ const markAsRead = useCallback((id) => {
70
+ setNotifications((prev) => prev.map((n) => (n.id === id ? { ...n, read: true } : n)));
71
+ }, []);
72
+ const markAllAsRead = useCallback(() => {
73
+ setNotifications((prev) => prev.map((n) => ({ ...n, read: true })));
74
+ }, []);
75
+ const dismiss = useCallback((id) => {
76
+ setNotifications((prev) => prev.filter((n) => n.id !== id));
77
+ }, []);
78
+ const clearAll = useCallback(() => {
79
+ setNotifications([]);
80
+ }, []);
81
+ const unreadCount = useMemo(() => notifications.filter((n) => !n.read).length, [notifications]);
82
+ const value = useMemo(() => ({
83
+ notifications,
84
+ unreadCount,
85
+ notify,
86
+ info,
87
+ success,
88
+ warning,
89
+ error,
90
+ markAsRead,
91
+ markAllAsRead,
92
+ dismiss,
93
+ clearAll,
94
+ config,
95
+ }), [
96
+ notifications,
97
+ unreadCount,
98
+ notify,
99
+ info,
100
+ success,
101
+ warning,
102
+ error,
103
+ markAsRead,
104
+ markAllAsRead,
105
+ dismiss,
106
+ clearAll,
107
+ config,
108
+ ]);
109
+ return (_jsx(NotificationCtx.Provider, { value: value, children: children }));
110
+ };
111
+ NotificationProvider.displayName = 'NotificationProvider';
112
+ /**
113
+ * Hook to consume the NotificationProvider context.
114
+ *
115
+ * @throws Error if used outside a NotificationProvider
116
+ */
117
+ export function useNotifications() {
118
+ const ctx = useContext(NotificationCtx);
119
+ if (!ctx) {
120
+ throw new Error('useNotifications must be used within a <NotificationProvider>. ' +
121
+ 'Wrap your app with <NotificationProvider> to use the notification system.');
122
+ }
123
+ return ctx;
124
+ }
125
+ /**
126
+ * Hook to check if a NotificationProvider is available.
127
+ */
128
+ export function useHasNotificationProvider() {
129
+ return useContext(NotificationCtx) !== null;
130
+ }
@@ -0,0 +1,94 @@
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 - ThemeContext
10
+ *
11
+ * React context + provider for the Theme System.
12
+ * Converts a spec-aligned Theme JSON into CSS custom properties
13
+ * and manages mode switching, theme registration, and persistence.
14
+ *
15
+ * @module context/ThemeContext
16
+ * @packageDocumentation
17
+ */
18
+ import React from 'react';
19
+ import type { Theme, ThemeMode } from '@object-ui/types';
20
+ /**
21
+ * The public API surface of the theme system, available via useTheme().
22
+ */
23
+ export interface ThemeContextValue {
24
+ /** The fully resolved active theme (after inheritance) */
25
+ theme: Theme | null;
26
+ /** The effective mode: 'light' or 'dark' (resolved from 'auto') */
27
+ resolvedMode: 'light' | 'dark';
28
+ /** The raw mode setting (may be 'auto') */
29
+ mode: ThemeMode;
30
+ /** Name of the active theme */
31
+ activeTheme: string | null;
32
+ /** List of available themes */
33
+ themes: Theme[];
34
+ /** Switch to a different theme by name */
35
+ setTheme: (name: string) => void;
36
+ /** Switch mode (light / dark / auto) */
37
+ setMode: (mode: ThemeMode) => void;
38
+ /** The generated CSS custom property map */
39
+ cssVars: Record<string, string>;
40
+ }
41
+ /**
42
+ * Props for the ThemeProvider component.
43
+ */
44
+ export interface ThemeProviderProps {
45
+ /** Available theme definitions */
46
+ themes?: Theme[];
47
+ /** Initial active theme name (default: first theme) */
48
+ defaultTheme?: string;
49
+ /** Initial mode (default: 'auto') */
50
+ defaultMode?: ThemeMode;
51
+ /** Persist theme/mode to localStorage */
52
+ persist?: boolean;
53
+ /** localStorage key prefix */
54
+ storageKey?: string;
55
+ /** Target element for CSS variable injection (default: document.documentElement) */
56
+ target?: HTMLElement | null;
57
+ /** Children */
58
+ children: React.ReactNode;
59
+ }
60
+ /**
61
+ * ThemeProvider
62
+ *
63
+ * Wraps a subtree with theme context. It:
64
+ * 1. Maintains theme + mode state
65
+ * 2. Resolves theme inheritance (extends)
66
+ * 3. Converts the active theme → CSS custom properties
67
+ * 4. Injects those CSS variables into the DOM
68
+ * 5. Applies 'dark' / 'light' class to the target element
69
+ * 6. Optionally persists user preference to localStorage
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * <ThemeProvider themes={[myTheme]} defaultTheme="my-theme" defaultMode="auto">
74
+ * <App />
75
+ * </ThemeProvider>
76
+ * ```
77
+ */
78
+ export declare function ThemeProvider({ themes: themesInput, defaultTheme, defaultMode, persist, storageKey, target, children, }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
79
+ /**
80
+ * useTheme — access the current theme context.
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * const { theme, resolvedMode, setMode, setTheme } = useTheme();
85
+ * ```
86
+ *
87
+ * @throws Error if used outside a ThemeProvider
88
+ */
89
+ export declare function useTheme(): ThemeContextValue;
90
+ /**
91
+ * useOptionalTheme — like useTheme() but returns null outside a provider.
92
+ * Useful for components that should work with or without a theme.
93
+ */
94
+ export declare function useOptionalTheme(): ThemeContextValue | null;
@@ -0,0 +1,215 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * ObjectUI
4
+ * Copyright (c) 2024-present ObjectStack Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ /**
10
+ * @object-ui/react - ThemeContext
11
+ *
12
+ * React context + provider for the Theme System.
13
+ * Converts a spec-aligned Theme JSON into CSS custom properties
14
+ * and manages mode switching, theme registration, and persistence.
15
+ *
16
+ * @module context/ThemeContext
17
+ * @packageDocumentation
18
+ */
19
+ import { createContext, useContext, useState, useEffect, useMemo, useCallback, } from 'react';
20
+ import { generateThemeVars, resolveThemeInheritance, resolveMode, } from '@object-ui/core';
21
+ // ============================================================================
22
+ // Context
23
+ // ============================================================================
24
+ const ThemeContext = createContext(null);
25
+ /**
26
+ * Default storage keys
27
+ */
28
+ const DEFAULT_STORAGE_KEY = 'objectui-theme';
29
+ // ============================================================================
30
+ // Provider
31
+ // ============================================================================
32
+ /**
33
+ * ThemeProvider
34
+ *
35
+ * Wraps a subtree with theme context. It:
36
+ * 1. Maintains theme + mode state
37
+ * 2. Resolves theme inheritance (extends)
38
+ * 3. Converts the active theme → CSS custom properties
39
+ * 4. Injects those CSS variables into the DOM
40
+ * 5. Applies 'dark' / 'light' class to the target element
41
+ * 6. Optionally persists user preference to localStorage
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * <ThemeProvider themes={[myTheme]} defaultTheme="my-theme" defaultMode="auto">
46
+ * <App />
47
+ * </ThemeProvider>
48
+ * ```
49
+ */
50
+ export function ThemeProvider({ themes: themesInput = [], defaultTheme, defaultMode = 'auto', persist = false, storageKey = DEFAULT_STORAGE_KEY, target, children, }) {
51
+ // ---- Build theme registry ----
52
+ const registry = useMemo(() => {
53
+ const map = new Map();
54
+ for (const t of themesInput) {
55
+ map.set(t.name, t);
56
+ }
57
+ return map;
58
+ }, [themesInput]);
59
+ // ---- Load persisted state ----
60
+ const loadPersistedTheme = useCallback(() => {
61
+ if (!persist)
62
+ return undefined;
63
+ try {
64
+ if (typeof window !== 'undefined') {
65
+ return localStorage.getItem(`${storageKey}-name`) ?? undefined;
66
+ }
67
+ }
68
+ catch { /* ignore */ }
69
+ return undefined;
70
+ }, [persist, storageKey]);
71
+ const loadPersistedMode = useCallback(() => {
72
+ if (!persist)
73
+ return undefined;
74
+ try {
75
+ if (typeof window !== 'undefined') {
76
+ const stored = localStorage.getItem(`${storageKey}-mode`);
77
+ if (stored === 'light' || stored === 'dark' || stored === 'auto') {
78
+ return stored;
79
+ }
80
+ }
81
+ }
82
+ catch { /* ignore */ }
83
+ return undefined;
84
+ }, [persist, storageKey]);
85
+ // ---- State ----
86
+ const [activeThemeName, setActiveThemeName] = useState(() => loadPersistedTheme() ?? defaultTheme ?? themesInput[0]?.name ?? null);
87
+ const [mode, setModeState] = useState(() => loadPersistedMode() ?? defaultMode);
88
+ // ---- Resolve theme ----
89
+ const resolvedTheme = useMemo(() => {
90
+ if (!activeThemeName)
91
+ return null;
92
+ const base = registry.get(activeThemeName);
93
+ if (!base)
94
+ return null;
95
+ return resolveThemeInheritance(base, registry);
96
+ }, [activeThemeName, registry]);
97
+ // ---- Resolve mode ----
98
+ const [systemDark, setSystemDark] = useState(() => {
99
+ if (typeof window !== 'undefined' && window.matchMedia) {
100
+ return window.matchMedia('(prefers-color-scheme: dark)').matches;
101
+ }
102
+ return false;
103
+ });
104
+ // Listen to system preference changes
105
+ useEffect(() => {
106
+ if (typeof window === 'undefined' || !window.matchMedia)
107
+ return;
108
+ const mq = window.matchMedia('(prefers-color-scheme: dark)');
109
+ const handler = (e) => setSystemDark(e.matches);
110
+ mq.addEventListener('change', handler);
111
+ return () => mq.removeEventListener('change', handler);
112
+ }, []);
113
+ const resolvedMode = useMemo(() => resolveMode(mode, systemDark), [mode, systemDark]);
114
+ // ---- Generate CSS variables ----
115
+ const cssVars = useMemo(() => {
116
+ if (!resolvedTheme)
117
+ return {};
118
+ return generateThemeVars(resolvedTheme);
119
+ }, [resolvedTheme]);
120
+ // ---- Inject CSS variables into the DOM ----
121
+ useEffect(() => {
122
+ const el = target ?? (typeof document !== 'undefined' ? document.documentElement : null);
123
+ if (!el)
124
+ return;
125
+ // Apply CSS variables
126
+ const previousValues = {};
127
+ for (const [prop, value] of Object.entries(cssVars)) {
128
+ previousValues[prop] = el.style.getPropertyValue(prop);
129
+ el.style.setProperty(prop, value);
130
+ }
131
+ // Apply mode class
132
+ el.classList.remove('light', 'dark');
133
+ el.classList.add(resolvedMode);
134
+ // Apply logo / favicon
135
+ if (resolvedTheme?.logo?.favicon && typeof document !== 'undefined') {
136
+ const link = document.querySelector('link[rel="icon"]')
137
+ ?? document.querySelector('#favicon');
138
+ if (link) {
139
+ link.href = resolvedTheme.logo.favicon;
140
+ }
141
+ }
142
+ return () => {
143
+ // Cleanup: remove injected vars
144
+ for (const prop of Object.keys(cssVars)) {
145
+ if (previousValues[prop]) {
146
+ el.style.setProperty(prop, previousValues[prop]);
147
+ }
148
+ else {
149
+ el.style.removeProperty(prop);
150
+ }
151
+ }
152
+ el.classList.remove(resolvedMode);
153
+ };
154
+ }, [cssVars, resolvedMode, resolvedTheme, target]);
155
+ // ---- Persistence ----
156
+ useEffect(() => {
157
+ if (!persist)
158
+ return;
159
+ try {
160
+ if (activeThemeName) {
161
+ localStorage.setItem(`${storageKey}-name`, activeThemeName);
162
+ }
163
+ localStorage.setItem(`${storageKey}-mode`, mode);
164
+ }
165
+ catch { /* ignore */ }
166
+ }, [persist, storageKey, activeThemeName, mode]);
167
+ // ---- Actions ----
168
+ const setTheme = useCallback((name) => {
169
+ if (registry.has(name)) {
170
+ setActiveThemeName(name);
171
+ }
172
+ }, [registry]);
173
+ const setMode = useCallback((newMode) => {
174
+ setModeState(newMode);
175
+ }, []);
176
+ // ---- Context value ----
177
+ const value = useMemo(() => ({
178
+ theme: resolvedTheme,
179
+ resolvedMode,
180
+ mode,
181
+ activeTheme: activeThemeName,
182
+ themes: themesInput,
183
+ setTheme,
184
+ setMode,
185
+ cssVars,
186
+ }), [resolvedTheme, resolvedMode, mode, activeThemeName, themesInput, setTheme, setMode, cssVars]);
187
+ return (_jsx(ThemeContext.Provider, { value: value, children: children }));
188
+ }
189
+ // ============================================================================
190
+ // Hook
191
+ // ============================================================================
192
+ /**
193
+ * useTheme — access the current theme context.
194
+ *
195
+ * @example
196
+ * ```tsx
197
+ * const { theme, resolvedMode, setMode, setTheme } = useTheme();
198
+ * ```
199
+ *
200
+ * @throws Error if used outside a ThemeProvider
201
+ */
202
+ export function useTheme() {
203
+ const ctx = useContext(ThemeContext);
204
+ if (!ctx) {
205
+ throw new Error('useTheme must be used within a <ThemeProvider>');
206
+ }
207
+ return ctx;
208
+ }
209
+ /**
210
+ * useOptionalTheme — like useTheme() but returns null outside a provider.
211
+ * Useful for components that should work with or without a theme.
212
+ */
213
+ export function useOptionalTheme() {
214
+ return useContext(ThemeContext);
215
+ }
@@ -6,3 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  export * from './SchemaRendererContext';
9
+ export * from './ActionContext';
10
+ export * from './ThemeContext';
11
+ export * from './NotificationContext';
12
+ export * from './DndContext';
@@ -6,3 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  export * from './SchemaRendererContext';
9
+ export * from './ActionContext';
10
+ export * from './ThemeContext';
11
+ export * from './NotificationContext';
12
+ export * from './DndContext';
@@ -7,3 +7,25 @@
7
7
  */
8
8
  export * from './useExpression';
9
9
  export * from './useActionRunner';
10
+ export * from './useNavigationOverlay';
11
+ export * from './usePageVariables';
12
+ export * from './useViewData';
13
+ export * from './useDynamicApp';
14
+ export * from './useDiscovery';
15
+ export * from './useFocusTrap';
16
+ export * from './useFocusManagement';
17
+ export * from './useKeyboardShortcuts';
18
+ export * from './useCrudShortcuts';
19
+ export * from './useReducedMotion';
20
+ export * from './useAnimation';
21
+ export * from './useColumnSummary';
22
+ export * from './useDensityMode';
23
+ export * from './useViewSharing';
24
+ export * from './useClientNotifications';
25
+ export * from './useOffline';
26
+ export * from './usePerformance';
27
+ export * from './usePerformanceBudget';
28
+ export * from './usePageTransition';
29
+ export * from './useViewTransition';
30
+ export * from './useETagCache';
31
+ export * from './useSchemaPersistence';
@@ -7,3 +7,25 @@
7
7
  */
8
8
  export * from './useExpression';
9
9
  export * from './useActionRunner';
10
+ export * from './useNavigationOverlay';
11
+ export * from './usePageVariables';
12
+ export * from './useViewData';
13
+ export * from './useDynamicApp';
14
+ export * from './useDiscovery';
15
+ export * from './useFocusTrap';
16
+ export * from './useFocusManagement';
17
+ export * from './useKeyboardShortcuts';
18
+ export * from './useCrudShortcuts';
19
+ export * from './useReducedMotion';
20
+ export * from './useAnimation';
21
+ export * from './useColumnSummary';
22
+ export * from './useDensityMode';
23
+ export * from './useViewSharing';
24
+ export * from './useClientNotifications';
25
+ export * from './useOffline';
26
+ export * from './usePerformance';
27
+ export * from './usePerformanceBudget';
28
+ export * from './usePageTransition';
29
+ export * from './useViewTransition';
30
+ export * from './useETagCache';
31
+ export * from './useSchemaPersistence';
@@ -5,25 +5,39 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- import { ActionRunner, type ActionContext, type ActionResult } from '@object-ui/core';
8
+ import { ActionRunner, type ActionContext, type ActionDef, type ActionResult, type ConfirmationHandler, type ToastHandler, type ModalHandler, type NavigationHandler } from '@object-ui/core';
9
+ export interface UseActionRunnerOptions {
10
+ context?: ActionContext;
11
+ /** Custom confirmation handler — wire to Shadcn AlertDialog or similar */
12
+ onConfirm?: ConfirmationHandler;
13
+ /** Custom toast handler — wire to Sonner or similar */
14
+ onToast?: ToastHandler;
15
+ /** Custom modal handler — render modals in response to modal actions */
16
+ onModal?: ModalHandler;
17
+ /** Custom navigation handler — SPA-aware routing */
18
+ onNavigate?: NavigationHandler;
19
+ }
9
20
  /**
10
- * Hook for executing actions with loading state
21
+ * Hook for executing actions with loading state, typed with ActionDef.
11
22
  *
12
23
  * @example
13
24
  * ```tsx
14
- * const { execute, loading, error, result } = useActionRunner({ data: formData });
25
+ * const { execute, loading, error, result } = useActionRunner({
26
+ * context: { data: formData },
27
+ * onToast: (msg, opts) => toast[opts?.type || 'info'](msg),
28
+ * });
15
29
  *
16
30
  * const handleClick = () => {
17
31
  * execute({
18
- * type: 'action',
32
+ * type: 'api',
19
33
  * api: '/api/save',
20
- * successMessage: 'Saved successfully!'
34
+ * successMessage: 'Saved successfully!',
21
35
  * });
22
36
  * };
23
37
  * ```
24
38
  */
25
- export declare function useActionRunner(context?: ActionContext): {
26
- execute: (action: any) => Promise<ActionResult>;
39
+ export declare function useActionRunner(optionsOrContext?: UseActionRunnerOptions | ActionContext): {
40
+ execute: (action: ActionDef) => Promise<ActionResult>;
27
41
  loading: boolean;
28
42
  error: string | null;
29
43
  result: ActionResult | null;
@@ -6,28 +6,48 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  import { useState, useCallback, useMemo } from 'react';
9
- import { ActionRunner } from '@object-ui/core';
9
+ import { ActionRunner, } from '@object-ui/core';
10
10
  /**
11
- * Hook for executing actions with loading state
11
+ * Hook for executing actions with loading state, typed with ActionDef.
12
12
  *
13
13
  * @example
14
14
  * ```tsx
15
- * const { execute, loading, error, result } = useActionRunner({ data: formData });
15
+ * const { execute, loading, error, result } = useActionRunner({
16
+ * context: { data: formData },
17
+ * onToast: (msg, opts) => toast[opts?.type || 'info'](msg),
18
+ * });
16
19
  *
17
20
  * const handleClick = () => {
18
21
  * execute({
19
- * type: 'action',
22
+ * type: 'api',
20
23
  * api: '/api/save',
21
- * successMessage: 'Saved successfully!'
24
+ * successMessage: 'Saved successfully!',
22
25
  * });
23
26
  * };
24
27
  * ```
25
28
  */
26
- export function useActionRunner(context = {}) {
29
+ export function useActionRunner(optionsOrContext = {}) {
30
+ // Backwards compat: if no 'context' key, treat entire object as context
31
+ const options = 'context' in optionsOrContext
32
+ ? optionsOrContext
33
+ : { context: optionsOrContext };
34
+ const { context = {}, onConfirm, onToast, onModal, onNavigate } = options;
27
35
  const [loading, setLoading] = useState(false);
28
36
  const [error, setError] = useState(null);
29
37
  const [result, setResult] = useState(null);
30
- const runner = useMemo(() => new ActionRunner(context), [JSON.stringify(context)]);
38
+ const runner = useMemo(() => {
39
+ const r = new ActionRunner(context);
40
+ if (onConfirm)
41
+ r.setConfirmHandler(onConfirm);
42
+ if (onToast)
43
+ r.setToastHandler(onToast);
44
+ if (onModal)
45
+ r.setModalHandler(onModal);
46
+ if (onNavigate)
47
+ r.setNavigationHandler(onNavigate);
48
+ return r;
49
+ // eslint-disable-next-line react-hooks/exhaustive-deps
50
+ }, [JSON.stringify(context)]);
31
51
  const execute = useCallback(async (action) => {
32
52
  setLoading(true);
33
53
  setError(null);
@@ -0,0 +1,46 @@
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
+ /** Animation trigger type */
9
+ export type AnimationTriggerType = 'enter' | 'exit' | 'hover' | 'focus' | 'click';
10
+ /** Easing presets aligned with EasingFunctionSchema */
11
+ export type EasingPreset = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring';
12
+ /** Transition preset aligned with TransitionPresetSchema */
13
+ export type TransitionPresetType = 'fade' | 'slide-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'scale' | 'scale-fade' | 'none';
14
+ export interface AnimationConfig {
15
+ /** The animation/transition preset */
16
+ preset?: TransitionPresetType;
17
+ /** Duration in milliseconds */
18
+ duration?: number;
19
+ /** Delay in milliseconds */
20
+ delay?: number;
21
+ /** Easing function */
22
+ easing?: EasingPreset;
23
+ /** Whether animation is enabled */
24
+ enabled?: boolean;
25
+ }
26
+ /** Resolved CSS classes and styles for animation */
27
+ export interface AnimationResult {
28
+ /** Tailwind CSS classes for the animation */
29
+ className: string;
30
+ /** Inline style for custom durations/delays (only when needed) */
31
+ style: React.CSSProperties;
32
+ }
33
+ /**
34
+ * Hook for applying spec-driven animations to components.
35
+ * Implements ComponentAnimationSchema and TransitionPresetSchema
36
+ * from @objectstack/spec v2.0.7.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * function Card() {
41
+ * const animation = useAnimation({ preset: 'fade', duration: 200, easing: 'ease-out' });
42
+ * return <div className={animation.className} style={animation.style}>...</div>;
43
+ * }
44
+ * ```
45
+ */
46
+ export declare function useAnimation(config?: AnimationConfig): AnimationResult;