@object-ui/core 3.0.2 → 3.1.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 (79) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +6 -0
  3. package/dist/actions/ActionEngine.d.ts +98 -0
  4. package/dist/actions/ActionEngine.js +222 -0
  5. package/dist/actions/UndoManager.d.ts +80 -0
  6. package/dist/actions/UndoManager.js +193 -0
  7. package/dist/actions/index.d.ts +2 -0
  8. package/dist/actions/index.js +2 -0
  9. package/dist/adapters/ApiDataSource.d.ts +2 -1
  10. package/dist/adapters/ApiDataSource.js +25 -0
  11. package/dist/adapters/ValueDataSource.d.ts +2 -1
  12. package/dist/adapters/ValueDataSource.js +99 -3
  13. package/dist/data-scope/ViewDataProvider.d.ts +143 -0
  14. package/dist/data-scope/ViewDataProvider.js +153 -0
  15. package/dist/data-scope/index.d.ts +1 -0
  16. package/dist/data-scope/index.js +1 -0
  17. package/dist/evaluator/ExpressionEvaluator.d.ts +7 -0
  18. package/dist/evaluator/ExpressionEvaluator.js +19 -0
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.js +5 -0
  21. package/dist/protocols/DndProtocol.d.ts +84 -0
  22. package/dist/protocols/DndProtocol.js +113 -0
  23. package/dist/protocols/KeyboardProtocol.d.ts +93 -0
  24. package/dist/protocols/KeyboardProtocol.js +108 -0
  25. package/dist/protocols/NotificationProtocol.d.ts +71 -0
  26. package/dist/protocols/NotificationProtocol.js +99 -0
  27. package/dist/protocols/ResponsiveProtocol.d.ts +73 -0
  28. package/dist/protocols/ResponsiveProtocol.js +158 -0
  29. package/dist/protocols/SharingProtocol.d.ts +71 -0
  30. package/dist/protocols/SharingProtocol.js +124 -0
  31. package/dist/protocols/index.d.ts +12 -0
  32. package/dist/protocols/index.js +12 -0
  33. package/dist/utils/debug-collector.d.ts +59 -0
  34. package/dist/utils/debug-collector.js +73 -0
  35. package/dist/utils/debug.d.ts +37 -2
  36. package/dist/utils/debug.js +62 -3
  37. package/dist/utils/expand-fields.d.ts +40 -0
  38. package/dist/utils/expand-fields.js +68 -0
  39. package/dist/utils/extract-records.d.ts +16 -0
  40. package/dist/utils/extract-records.js +32 -0
  41. package/dist/utils/normalize-quick-filter.d.ts +29 -0
  42. package/dist/utils/normalize-quick-filter.js +66 -0
  43. package/package.json +3 -3
  44. package/src/__tests__/protocols/DndProtocol.test.ts +186 -0
  45. package/src/__tests__/protocols/KeyboardProtocol.test.ts +177 -0
  46. package/src/__tests__/protocols/NotificationProtocol.test.ts +142 -0
  47. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +176 -0
  48. package/src/__tests__/protocols/SharingProtocol.test.ts +188 -0
  49. package/src/actions/ActionEngine.ts +268 -0
  50. package/src/actions/UndoManager.ts +215 -0
  51. package/src/actions/__tests__/ActionEngine.test.ts +206 -0
  52. package/src/actions/__tests__/UndoManager.test.ts +320 -0
  53. package/src/actions/index.ts +2 -0
  54. package/src/adapters/ApiDataSource.ts +27 -0
  55. package/src/adapters/ValueDataSource.ts +109 -3
  56. package/src/adapters/__tests__/ValueDataSource.test.ts +147 -0
  57. package/src/data-scope/ViewDataProvider.ts +282 -0
  58. package/src/data-scope/__tests__/ViewDataProvider.test.ts +270 -0
  59. package/src/data-scope/index.ts +8 -0
  60. package/src/evaluator/ExpressionEvaluator.ts +22 -0
  61. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +31 -1
  62. package/src/index.ts +5 -0
  63. package/src/protocols/DndProtocol.ts +184 -0
  64. package/src/protocols/KeyboardProtocol.ts +185 -0
  65. package/src/protocols/NotificationProtocol.ts +159 -0
  66. package/src/protocols/ResponsiveProtocol.ts +210 -0
  67. package/src/protocols/SharingProtocol.ts +185 -0
  68. package/src/{index.test.ts → protocols/index.ts} +5 -7
  69. package/src/utils/__tests__/debug-collector.test.ts +102 -0
  70. package/src/utils/__tests__/debug.test.ts +52 -1
  71. package/src/utils/__tests__/expand-fields.test.ts +120 -0
  72. package/src/utils/__tests__/extract-records.test.ts +50 -0
  73. package/src/utils/__tests__/normalize-quick-filter.test.ts +123 -0
  74. package/src/utils/debug-collector.ts +100 -0
  75. package/src/utils/debug.ts +87 -6
  76. package/src/utils/expand-fields.ts +76 -0
  77. package/src/utils/extract-records.ts +33 -0
  78. package/src/utils/normalize-quick-filter.ts +78 -0
  79. package/tsconfig.tsbuildinfo +1 -1
@@ -1,4 +1,4 @@
1
1
 
2
- > @object-ui/core@3.0.2 build /home/runner/work/objectui/objectui/packages/core
2
+ > @object-ui/core@3.1.0 build /home/runner/work/objectui/objectui/packages/core
3
3
  > tsc
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @object-ui/core
2
2
 
3
+ ## 3.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - @object-ui/types@3.0.3
8
+
3
9
  ## 3.0.2
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,98 @@
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/core - Action Engine
10
+ *
11
+ * Declarative action dispatch engine. Manages action registration,
12
+ * event-to-action mapping, location-based filtering, keyboard shortcuts,
13
+ * and bulk operation support.
14
+ *
15
+ * Replaces callback-based patterns with a schema-driven pipeline:
16
+ * ActionSchema[] → ActionEngine → ActionRunner → ActionResult
17
+ */
18
+ import { ActionRunner, type ActionDef, type ActionContext, type ActionResult } from './ActionRunner';
19
+ /** Action location types (from @objectstack/spec) */
20
+ export type ActionLocation = 'list_toolbar' | 'list_item' | 'record_header' | 'record_more' | 'record_related' | 'global_nav';
21
+ /** Registered action with metadata */
22
+ export interface RegisteredAction {
23
+ action: ActionDef;
24
+ locations: ActionLocation[];
25
+ /** Keyboard shortcut (e.g., 'ctrl+s', 'meta+k') */
26
+ shortcut?: string;
27
+ /** Whether this action supports bulk operations */
28
+ bulkEnabled?: boolean;
29
+ /** Priority for ordering (lower = first) */
30
+ priority?: number;
31
+ }
32
+ /** Event-to-action mapping */
33
+ export interface ActionMapping {
34
+ /** Event name (e.g., 'row:click', 'toolbar:save', 'keyboard:ctrl+s') */
35
+ event: string;
36
+ /** Action name to execute */
37
+ actionName: string;
38
+ /** Optional condition expression */
39
+ condition?: string;
40
+ }
41
+ /** Keyboard shortcut handler */
42
+ export interface ShortcutBinding {
43
+ /** Key combination (e.g., 'ctrl+s', 'meta+k', 'shift+n') */
44
+ keys: string;
45
+ /** Action name to trigger */
46
+ actionName: string;
47
+ }
48
+ export declare class ActionEngine {
49
+ private actions;
50
+ private mappings;
51
+ private shortcuts;
52
+ private normalizedShortcutMap;
53
+ private runner;
54
+ constructor(context?: ActionContext);
55
+ /** Get the underlying ActionRunner for handler configuration */
56
+ getRunner(): ActionRunner;
57
+ /** Register a single action */
58
+ registerAction(action: ActionDef, options?: {
59
+ locations?: ActionLocation[];
60
+ shortcut?: string;
61
+ bulkEnabled?: boolean;
62
+ priority?: number;
63
+ }): void;
64
+ /** Register multiple actions from an ActionSchema array */
65
+ registerActions(actions: ActionDef[]): void;
66
+ /** Unregister an action by name */
67
+ unregisterAction(name: string): void;
68
+ /** Add an event-to-action mapping */
69
+ addMapping(mapping: ActionMapping): void;
70
+ /** Get actions available at a specific location, sorted by priority */
71
+ getActionsForLocation(location: ActionLocation): ActionDef[];
72
+ /** Get actions that support bulk operations */
73
+ getBulkActions(): ActionDef[];
74
+ /** Get all registered keyboard shortcuts */
75
+ getShortcuts(): ShortcutBinding[];
76
+ /** Get a registered action by name */
77
+ getAction(name: string): ActionDef | undefined;
78
+ /** Execute an action by name */
79
+ executeAction(name: string, contextOverride?: Partial<ActionContext>): Promise<ActionResult>;
80
+ /** Dispatch an event — finds mapped actions and executes them */
81
+ dispatch(event: string, contextOverride?: Partial<ActionContext>): Promise<ActionResult[]>;
82
+ /** Handle a keyboard shortcut event — returns true if handled */
83
+ handleShortcut(keys: string, contextOverride?: Partial<ActionContext>): Promise<ActionResult | null>;
84
+ /** Execute a bulk operation on multiple records */
85
+ executeBulk(actionName: string, records: Record<string, any>[], options?: {
86
+ parallel?: boolean;
87
+ continueOnError?: boolean;
88
+ }): Promise<{
89
+ total: number;
90
+ succeeded: number;
91
+ failed: number;
92
+ results: ActionResult[];
93
+ }>;
94
+ /** Update the action context */
95
+ updateContext(context: Partial<ActionContext>): void;
96
+ /** Clear all registered actions and mappings */
97
+ clear(): void;
98
+ }
@@ -0,0 +1,222 @@
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/core - Action Engine
10
+ *
11
+ * Declarative action dispatch engine. Manages action registration,
12
+ * event-to-action mapping, location-based filtering, keyboard shortcuts,
13
+ * and bulk operation support.
14
+ *
15
+ * Replaces callback-based patterns with a schema-driven pipeline:
16
+ * ActionSchema[] → ActionEngine → ActionRunner → ActionResult
17
+ */
18
+ import { ActionRunner } from './ActionRunner';
19
+ /** Normalize a shortcut string for comparison (lowercase, trimmed, sorted parts) */
20
+ function normalizeShortcut(keys) {
21
+ return keys.toLowerCase().split('+').map(k => k.trim()).sort().join('+');
22
+ }
23
+ export class ActionEngine {
24
+ constructor(context = {}) {
25
+ Object.defineProperty(this, "actions", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: new Map()
30
+ });
31
+ Object.defineProperty(this, "mappings", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: []
36
+ });
37
+ Object.defineProperty(this, "shortcuts", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: []
42
+ });
43
+ Object.defineProperty(this, "normalizedShortcutMap", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: new Map()
48
+ });
49
+ Object.defineProperty(this, "runner", {
50
+ enumerable: true,
51
+ configurable: true,
52
+ writable: true,
53
+ value: void 0
54
+ });
55
+ this.runner = new ActionRunner(context);
56
+ }
57
+ /** Get the underlying ActionRunner for handler configuration */
58
+ getRunner() {
59
+ return this.runner;
60
+ }
61
+ /** Register a single action */
62
+ registerAction(action, options) {
63
+ const name = action.name || action.type || '';
64
+ if (!name)
65
+ throw new Error('Action must have a name or type');
66
+ this.actions.set(name, {
67
+ action,
68
+ locations: options?.locations || [],
69
+ shortcut: options?.shortcut,
70
+ bulkEnabled: options?.bulkEnabled ?? false,
71
+ priority: options?.priority ?? 100,
72
+ });
73
+ // Auto-register keyboard shortcut
74
+ if (options?.shortcut) {
75
+ this.shortcuts.push({ keys: options.shortcut, actionName: name });
76
+ this.normalizedShortcutMap.set(normalizeShortcut(options.shortcut), name);
77
+ }
78
+ }
79
+ /** Register multiple actions from an ActionSchema array */
80
+ registerActions(actions) {
81
+ for (const action of actions) {
82
+ this.registerAction(action, {
83
+ locations: action.locations,
84
+ shortcut: action.shortcut,
85
+ bulkEnabled: action.bulkEnabled,
86
+ });
87
+ }
88
+ }
89
+ /** Unregister an action by name */
90
+ unregisterAction(name) {
91
+ const registered = this.actions.get(name);
92
+ if (registered?.shortcut) {
93
+ this.normalizedShortcutMap.delete(normalizeShortcut(registered.shortcut));
94
+ }
95
+ this.actions.delete(name);
96
+ this.shortcuts = this.shortcuts.filter(s => s.actionName !== name);
97
+ this.mappings = this.mappings.filter(m => m.actionName !== name);
98
+ }
99
+ /** Add an event-to-action mapping */
100
+ addMapping(mapping) {
101
+ this.mappings.push(mapping);
102
+ }
103
+ /** Get actions available at a specific location, sorted by priority */
104
+ getActionsForLocation(location) {
105
+ return Array.from(this.actions.values())
106
+ .filter(ra => ra.locations.includes(location))
107
+ .sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100))
108
+ .map(ra => ra.action);
109
+ }
110
+ /** Get actions that support bulk operations */
111
+ getBulkActions() {
112
+ return Array.from(this.actions.values())
113
+ .filter(ra => ra.bulkEnabled)
114
+ .sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100))
115
+ .map(ra => ra.action);
116
+ }
117
+ /** Get all registered keyboard shortcuts */
118
+ getShortcuts() {
119
+ return [...this.shortcuts];
120
+ }
121
+ /** Get a registered action by name */
122
+ getAction(name) {
123
+ return this.actions.get(name)?.action;
124
+ }
125
+ /** Execute an action by name */
126
+ async executeAction(name, contextOverride) {
127
+ const registered = this.actions.get(name);
128
+ if (!registered) {
129
+ return { success: false, error: `Action not found: ${name}` };
130
+ }
131
+ if (contextOverride) {
132
+ this.runner.updateContext(contextOverride);
133
+ }
134
+ return this.runner.execute(registered.action);
135
+ }
136
+ /** Dispatch an event — finds mapped actions and executes them */
137
+ async dispatch(event, contextOverride) {
138
+ const matchingMappings = this.mappings.filter(m => m.event === event);
139
+ if (matchingMappings.length === 0) {
140
+ return [];
141
+ }
142
+ const results = [];
143
+ for (const mapping of matchingMappings) {
144
+ // Check condition if present
145
+ if (mapping.condition) {
146
+ const evaluator = this.runner.getEvaluator();
147
+ const shouldRun = evaluator.evaluateCondition(mapping.condition);
148
+ if (!shouldRun)
149
+ continue;
150
+ }
151
+ const result = await this.executeAction(mapping.actionName, contextOverride);
152
+ results.push(result);
153
+ }
154
+ return results;
155
+ }
156
+ /** Handle a keyboard shortcut event — returns true if handled */
157
+ async handleShortcut(keys, contextOverride) {
158
+ const actionName = this.normalizedShortcutMap.get(normalizeShortcut(keys));
159
+ if (!actionName)
160
+ return null;
161
+ return this.executeAction(actionName, contextOverride);
162
+ }
163
+ /** Execute a bulk operation on multiple records */
164
+ async executeBulk(actionName, records, options) {
165
+ const registered = this.actions.get(actionName);
166
+ if (!registered) {
167
+ return { total: 0, succeeded: 0, failed: 0, results: [{ success: false, error: `Action not found: ${actionName}` }] };
168
+ }
169
+ if (!registered.bulkEnabled) {
170
+ return { total: 0, succeeded: 0, failed: 0, results: [{ success: false, error: `Action ${actionName} does not support bulk operations` }] };
171
+ }
172
+ const results = [];
173
+ let succeeded = 0;
174
+ let failed = 0;
175
+ if (options?.parallel) {
176
+ const promises = records.map(record => {
177
+ this.runner.updateContext({ record, selectedRecords: records });
178
+ return this.runner.execute(registered.action);
179
+ });
180
+ const settled = await Promise.allSettled(promises);
181
+ for (const r of settled) {
182
+ if (r.status === 'fulfilled') {
183
+ results.push(r.value);
184
+ if (r.value.success)
185
+ succeeded++;
186
+ else
187
+ failed++;
188
+ }
189
+ else {
190
+ results.push({ success: false, error: r.reason?.message || 'Unknown error' });
191
+ failed++;
192
+ }
193
+ }
194
+ }
195
+ else {
196
+ for (const record of records) {
197
+ this.runner.updateContext({ record, selectedRecords: records });
198
+ const result = await this.runner.execute(registered.action);
199
+ results.push(result);
200
+ if (result.success)
201
+ succeeded++;
202
+ else {
203
+ failed++;
204
+ if (!options?.continueOnError)
205
+ break;
206
+ }
207
+ }
208
+ }
209
+ return { total: records.length, succeeded, failed, results };
210
+ }
211
+ /** Update the action context */
212
+ updateContext(context) {
213
+ this.runner.updateContext(context);
214
+ }
215
+ /** Clear all registered actions and mappings */
216
+ clear() {
217
+ this.actions.clear();
218
+ this.mappings = [];
219
+ this.shortcuts = [];
220
+ this.normalizedShortcutMap.clear();
221
+ }
222
+ }
@@ -0,0 +1,80 @@
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/core - Undo Manager
10
+ *
11
+ * Global undo/redo system for CRUD operations. Class-based singleton
12
+ * pattern for use from ActionRunner, React hooks, and standalone contexts.
13
+ * Maintains bounded history stacks with subscriber notifications.
14
+ */
15
+ /** Represents a single undoable CRUD operation. */
16
+ export interface UndoableOperation {
17
+ id: string;
18
+ type: 'create' | 'update' | 'delete';
19
+ objectName: string;
20
+ recordId: string;
21
+ timestamp: number;
22
+ description: string;
23
+ /** Data needed to undo: for create=recordId, for update=previousData, for delete=fullRecord */
24
+ undoData: Record<string, unknown>;
25
+ /** Data needed to redo: for create=newData, for update=newData, for delete=recordId */
26
+ redoData: Record<string, unknown>;
27
+ }
28
+ export interface UndoManagerOptions {
29
+ /** Maximum number of operations to retain in history. @default 50 */
30
+ maxHistory?: number;
31
+ }
32
+ /**
33
+ * Manages undo/redo stacks for CRUD operations.
34
+ *
35
+ * Designed as a framework-agnostic class so it can be used from
36
+ * ActionRunner, React hooks, or any other consumer.
37
+ */
38
+ export declare class UndoManager {
39
+ private undoStack;
40
+ private redoStack;
41
+ private readonly maxHistory;
42
+ private listeners;
43
+ constructor(options?: UndoManagerOptions);
44
+ /** Record an undoable operation. Clears the redo stack. */
45
+ push(operation: UndoableOperation): void;
46
+ /** Peek at the next undoable operation without removing it. */
47
+ peekUndo(): UndoableOperation | undefined;
48
+ /** Peek at the next redoable operation without removing it. */
49
+ peekRedo(): UndoableOperation | undefined;
50
+ /** Pop the last operation from the undo stack and move it to redo. */
51
+ popUndo(): UndoableOperation | undefined;
52
+ /** Pop the last operation from the redo stack and move it to undo. */
53
+ popRedo(): UndoableOperation | undefined;
54
+ /** Clear all undo and redo history. */
55
+ clear(): void;
56
+ get canUndo(): boolean;
57
+ get canRedo(): boolean;
58
+ get undoCount(): number;
59
+ get redoCount(): number;
60
+ /** Subscribe to state changes. Returns an unsubscribe function. */
61
+ subscribe(listener: () => void): () => void;
62
+ /** Get a shallow copy of the undo history (for developer tools). */
63
+ getHistory(): UndoableOperation[];
64
+ /** Get a shallow copy of the redo history (for developer tools). */
65
+ getRedoHistory(): UndoableOperation[];
66
+ /** Push multiple operations as one atomic unit. Clears the redo stack. */
67
+ pushBatch(operations: UndoableOperation[]): void;
68
+ /** Pop `count` operations from the undo stack and move them to redo (LIFO order). */
69
+ popUndoBatch(count: number): UndoableOperation[];
70
+ /** Pop `count` operations from the redo stack and move them to undo (LIFO order). */
71
+ popRedoBatch(count: number): UndoableOperation[];
72
+ private static readonly STORAGE_KEY;
73
+ /** Persist the current undo/redo stacks to localStorage. */
74
+ saveToStorage(): void;
75
+ /** Restore undo/redo stacks from localStorage (no-op when unavailable). */
76
+ loadFromStorage(): void;
77
+ private notify;
78
+ }
79
+ /** Global singleton instance. */
80
+ export declare const globalUndoManager: UndoManager;
@@ -0,0 +1,193 @@
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
+ /** Type guard validating the required shape of a persisted UndoableOperation. */
9
+ function isValidOperation(op) {
10
+ if (typeof op !== 'object' || op === null)
11
+ return false;
12
+ const o = op;
13
+ return (typeof o.id === 'string' &&
14
+ typeof o.type === 'string' &&
15
+ typeof o.objectName === 'string' &&
16
+ typeof o.recordId === 'string' &&
17
+ typeof o.timestamp === 'number');
18
+ }
19
+ /**
20
+ * Manages undo/redo stacks for CRUD operations.
21
+ *
22
+ * Designed as a framework-agnostic class so it can be used from
23
+ * ActionRunner, React hooks, or any other consumer.
24
+ */
25
+ export class UndoManager {
26
+ constructor(options) {
27
+ Object.defineProperty(this, "undoStack", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: []
32
+ });
33
+ Object.defineProperty(this, "redoStack", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: []
38
+ });
39
+ Object.defineProperty(this, "maxHistory", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "listeners", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: new Set()
50
+ });
51
+ this.maxHistory = options?.maxHistory ?? 50;
52
+ }
53
+ /** Record an undoable operation. Clears the redo stack. */
54
+ push(operation) {
55
+ this.undoStack.push(operation);
56
+ if (this.undoStack.length > this.maxHistory) {
57
+ this.undoStack.shift();
58
+ }
59
+ this.redoStack = [];
60
+ this.notify();
61
+ }
62
+ /** Peek at the next undoable operation without removing it. */
63
+ peekUndo() {
64
+ return this.undoStack[this.undoStack.length - 1];
65
+ }
66
+ /** Peek at the next redoable operation without removing it. */
67
+ peekRedo() {
68
+ return this.redoStack[this.redoStack.length - 1];
69
+ }
70
+ /** Pop the last operation from the undo stack and move it to redo. */
71
+ popUndo() {
72
+ const op = this.undoStack.pop();
73
+ if (op) {
74
+ this.redoStack.push(op);
75
+ this.notify();
76
+ }
77
+ return op;
78
+ }
79
+ /** Pop the last operation from the redo stack and move it to undo. */
80
+ popRedo() {
81
+ const op = this.redoStack.pop();
82
+ if (op) {
83
+ this.undoStack.push(op);
84
+ this.notify();
85
+ }
86
+ return op;
87
+ }
88
+ /** Clear all undo and redo history. */
89
+ clear() {
90
+ this.undoStack = [];
91
+ this.redoStack = [];
92
+ this.notify();
93
+ }
94
+ get canUndo() { return this.undoStack.length > 0; }
95
+ get canRedo() { return this.redoStack.length > 0; }
96
+ get undoCount() { return this.undoStack.length; }
97
+ get redoCount() { return this.redoStack.length; }
98
+ /** Subscribe to state changes. Returns an unsubscribe function. */
99
+ subscribe(listener) {
100
+ this.listeners.add(listener);
101
+ return () => this.listeners.delete(listener);
102
+ }
103
+ /** Get a shallow copy of the undo history (for developer tools). */
104
+ getHistory() { return [...this.undoStack]; }
105
+ /** Get a shallow copy of the redo history (for developer tools). */
106
+ getRedoHistory() { return [...this.redoStack]; }
107
+ // ---------------------------------------------------------------------------
108
+ // Batch operations
109
+ // ---------------------------------------------------------------------------
110
+ /** Push multiple operations as one atomic unit. Clears the redo stack. */
111
+ pushBatch(operations) {
112
+ if (operations.length === 0)
113
+ return;
114
+ this.undoStack.push(...operations);
115
+ // Trim from the front if we exceed maxHistory
116
+ if (this.undoStack.length > this.maxHistory) {
117
+ this.undoStack.splice(0, this.undoStack.length - this.maxHistory);
118
+ }
119
+ this.redoStack = [];
120
+ this.notify();
121
+ }
122
+ /** Pop `count` operations from the undo stack and move them to redo (LIFO order). */
123
+ popUndoBatch(count) {
124
+ const actual = Math.min(count, this.undoStack.length);
125
+ if (actual === 0)
126
+ return [];
127
+ const ops = this.undoStack.splice(this.undoStack.length - actual, actual);
128
+ // Preserve LIFO order on the redo stack (last undone goes on top)
129
+ this.redoStack.push(...ops);
130
+ this.notify();
131
+ return ops;
132
+ }
133
+ /** Pop `count` operations from the redo stack and move them to undo (LIFO order). */
134
+ popRedoBatch(count) {
135
+ const actual = Math.min(count, this.redoStack.length);
136
+ if (actual === 0)
137
+ return [];
138
+ const ops = this.redoStack.splice(this.redoStack.length - actual, actual);
139
+ this.undoStack.push(...ops);
140
+ this.notify();
141
+ return ops;
142
+ }
143
+ /** Persist the current undo/redo stacks to localStorage. */
144
+ saveToStorage() {
145
+ try {
146
+ const payload = JSON.stringify({
147
+ undoStack: this.undoStack,
148
+ redoStack: this.redoStack,
149
+ });
150
+ localStorage.setItem(UndoManager.STORAGE_KEY, payload);
151
+ }
152
+ catch {
153
+ // localStorage may be unavailable (SSR, quota exceeded, etc.)
154
+ }
155
+ }
156
+ /** Restore undo/redo stacks from localStorage (no-op when unavailable). */
157
+ loadFromStorage() {
158
+ try {
159
+ if (typeof localStorage === 'undefined')
160
+ return;
161
+ const raw = localStorage.getItem(UndoManager.STORAGE_KEY);
162
+ if (!raw)
163
+ return;
164
+ const parsed = JSON.parse(raw);
165
+ if (Array.isArray(parsed.undoStack)) {
166
+ this.undoStack = parsed.undoStack.filter(isValidOperation);
167
+ }
168
+ if (Array.isArray(parsed.redoStack)) {
169
+ this.redoStack = parsed.redoStack.filter(isValidOperation);
170
+ }
171
+ // Enforce maxHistory in case persisted state used a different limit
172
+ if (this.undoStack.length > this.maxHistory) {
173
+ this.undoStack.splice(0, this.undoStack.length - this.maxHistory);
174
+ }
175
+ this.notify();
176
+ }
177
+ catch {
178
+ // Silently ignore parse errors or missing storage
179
+ }
180
+ }
181
+ notify() { this.listeners.forEach((fn) => fn()); }
182
+ }
183
+ // ---------------------------------------------------------------------------
184
+ // Persistence (localStorage)
185
+ // ---------------------------------------------------------------------------
186
+ Object.defineProperty(UndoManager, "STORAGE_KEY", {
187
+ enumerable: true,
188
+ configurable: true,
189
+ writable: true,
190
+ value: 'objectui:undo-history'
191
+ });
192
+ /** Global singleton instance. */
193
+ export const globalUndoManager = new UndoManager();
@@ -6,4 +6,6 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  export * from './ActionRunner.js';
9
+ export * from './ActionEngine.js';
9
10
  export * from './TransactionManager.js';
11
+ export * from './UndoManager.js';
@@ -6,4 +6,6 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  export * from './ActionRunner.js';
9
+ export * from './ActionEngine.js';
9
10
  export * from './TransactionManager.js';
11
+ export * from './UndoManager.js';
@@ -8,7 +8,7 @@
8
8
  * A DataSource adapter for the `provider: 'api'` ViewData mode.
9
9
  * Makes raw HTTP requests using the HttpRequest configs from ViewData.
10
10
  */
11
- import type { DataSource, QueryParams, QueryResult, HttpRequest } from '@object-ui/types';
11
+ import type { DataSource, QueryParams, QueryResult, HttpRequest, AggregateParams, AggregateResult } from '@object-ui/types';
12
12
  export interface ApiDataSourceConfig {
13
13
  /** HttpRequest config for read operations (find, findOne) */
14
14
  read?: HttpRequest;
@@ -53,6 +53,7 @@ export declare class ApiDataSource<T = any> implements DataSource<T> {
53
53
  getObjectSchema(_objectName: string): Promise<any>;
54
54
  getView(_objectName: string, _viewId: string): Promise<any | null>;
55
55
  getApp(_appId: string): Promise<any | null>;
56
+ aggregate(_resource: string, params: AggregateParams): Promise<AggregateResult[]>;
56
57
  /**
57
58
  * Normalize various API response shapes into a QueryResult.
58
59
  *
@@ -246,6 +246,31 @@ export class ApiDataSource {
246
246
  async getApp(_appId) {
247
247
  return null;
248
248
  }
249
+ async aggregate(_resource, params) {
250
+ const queryParams = {
251
+ field: params.field,
252
+ function: params.function,
253
+ groupBy: params.groupBy,
254
+ };
255
+ if (params.filter) {
256
+ queryParams.filter = typeof params.filter === 'string'
257
+ ? params.filter
258
+ : JSON.stringify(params.filter);
259
+ }
260
+ const raw = await this.request(this.readConfig, {
261
+ pathSuffix: 'aggregate',
262
+ method: 'GET',
263
+ queryParams,
264
+ });
265
+ // Normalize: the API might return an array or an object with data/results
266
+ if (Array.isArray(raw))
267
+ return raw;
268
+ if (raw?.data && Array.isArray(raw.data))
269
+ return raw.data;
270
+ if (raw?.results && Array.isArray(raw.results))
271
+ return raw.results;
272
+ return [];
273
+ }
249
274
  // -----------------------------------------------------------------------
250
275
  // Helpers
251
276
  // -----------------------------------------------------------------------