@object-ui/components 0.5.0 → 2.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 (96) hide show
  1. package/.turbo/turbo-build.log +12 -25
  2. package/CHANGELOG.md +13 -0
  3. package/dist/index.css +1 -1
  4. package/dist/index.js +23366 -22221
  5. package/dist/index.umd.cjs +30 -30
  6. package/dist/src/custom/action-param-dialog.d.ts +21 -0
  7. package/dist/src/custom/index.d.ts +2 -0
  8. package/dist/src/custom/navigation-overlay.d.ts +50 -0
  9. package/dist/src/index.d.ts +1 -0
  10. package/dist/src/renderers/action/action-button.d.ts +11 -0
  11. package/dist/src/renderers/action/action-group.d.ts +25 -0
  12. package/dist/src/renderers/action/action-icon.d.ts +10 -0
  13. package/dist/src/renderers/action/action-menu.d.ts +19 -0
  14. package/dist/src/renderers/action/index.d.ts +0 -0
  15. package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
  16. package/package.json +9 -8
  17. package/src/__tests__/PageRendererRegions.test.tsx +664 -55
  18. package/src/__tests__/compliance.test.tsx +72 -0
  19. package/src/__tests__/navigation-overlay.test.tsx +273 -0
  20. package/src/__tests__/view-compliance.test.tsx +153 -0
  21. package/src/custom/action-param-dialog.tsx +264 -0
  22. package/src/custom/index.ts +2 -0
  23. package/src/custom/navigation-overlay.tsx +296 -0
  24. package/src/index.ts +1 -0
  25. package/src/renderers/action/action-button.tsx +147 -0
  26. package/src/renderers/action/action-group.tsx +270 -0
  27. package/src/renderers/action/action-icon.tsx +150 -0
  28. package/src/renderers/action/action-menu.tsx +203 -0
  29. package/src/renderers/action/index.ts +18 -0
  30. package/src/renderers/action/resolve-icon.ts +35 -0
  31. package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
  32. package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
  33. package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
  34. package/src/renderers/complex/data-table.tsx +242 -21
  35. package/src/renderers/form/form.tsx +23 -4
  36. package/src/renderers/index.ts +1 -0
  37. package/src/renderers/layout/page.tsx +416 -52
  38. package/src/renderers/navigation/sidebar.tsx +6 -0
  39. package/src/renderers/placeholders.tsx +2 -2
  40. package/src/stories/Introduction.mdx +54 -27
  41. package/src/stories/MockedData.stories.tsx +87 -37
  42. package/src/stories-json/accordion.stories.tsx +1 -1
  43. package/src/stories-json/aggrid.stories.tsx +1 -1
  44. package/src/stories-json/alert.stories.tsx +1 -1
  45. package/src/stories-json/aspect-ratio.stories.tsx +1 -1
  46. package/src/stories-json/avatar.stories.tsx +1 -1
  47. package/src/stories-json/badge.stories.tsx +1 -1
  48. package/src/stories-json/breadcrumb.stories.tsx +1 -1
  49. package/src/stories-json/button-group.stories.tsx +1 -1
  50. package/src/stories-json/button.stories.tsx +1 -1
  51. package/src/stories-json/calendar.stories.tsx +1 -1
  52. package/src/stories-json/card.stories.tsx +1 -1
  53. package/src/stories-json/carousel.stories.tsx +1 -1
  54. package/src/stories-json/charts.stories.tsx +1 -1
  55. package/src/stories-json/chatbot.stories.tsx +1 -1
  56. package/src/stories-json/code-editor.stories.tsx +1 -1
  57. package/src/stories-json/collapsible.stories.tsx +1 -1
  58. package/src/stories-json/controls.stories.tsx +1 -1
  59. package/src/stories-json/crm-live-data.stories.tsx +154 -0
  60. package/src/stories-json/data-table.stories.tsx +80 -4
  61. package/src/stories-json/data_display_extras.stories.tsx +1 -1
  62. package/src/stories-json/date-picker.stories.tsx +1 -1
  63. package/src/stories-json/detail-view.stories.tsx +1 -1
  64. package/src/stories-json/dialog.stories.tsx +1 -1
  65. package/src/stories-json/feedback_extras.stories.tsx +1 -1
  66. package/src/stories-json/feedback_others.stories.tsx +1 -1
  67. package/src/stories-json/form-variants.stories.tsx +210 -0
  68. package/src/stories-json/form_advanced.stories.tsx +1 -1
  69. package/src/stories-json/form_extras.stories.tsx +1 -1
  70. package/src/stories-json/grid.stories.tsx +1 -1
  71. package/src/stories-json/icon.stories.tsx +1 -1
  72. package/src/stories-json/input.stories.tsx +1 -1
  73. package/src/stories-json/kanban.stories.tsx +1 -1
  74. package/src/stories-json/layout_extended.stories.tsx +1 -1
  75. package/src/stories-json/layout_flex.stories.tsx +1 -1
  76. package/src/stories-json/list-view.stories.tsx +1 -1
  77. package/src/stories-json/markdown.stories.tsx +1 -1
  78. package/src/stories-json/menus.stories.tsx +1 -1
  79. package/src/stories-json/metric-card.stories.tsx +1 -1
  80. package/src/stories-json/navigation-menu.stories.tsx +1 -1
  81. package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
  82. package/src/stories-json/object-aggrid.stories.tsx +1 -1
  83. package/src/stories-json/object-form.stories.tsx +1 -1
  84. package/src/stories-json/object-gantt.stories.tsx +1 -1
  85. package/src/stories-json/object-grid.stories.tsx +159 -1
  86. package/src/stories-json/object-map.stories.tsx +1 -1
  87. package/src/stories-json/object-view.stories.tsx +1 -1
  88. package/src/stories-json/overlay_extras.stories.tsx +1 -1
  89. package/src/stories-json/overlay_others.stories.tsx +1 -1
  90. package/src/stories-json/resizable.stories.tsx +1 -1
  91. package/src/stories-json/select.stories.tsx +1 -1
  92. package/src/stories-json/separator.stories.tsx +1 -1
  93. package/src/stories-json/statistic.stories.tsx +1 -1
  94. package/src/stories-json/tabs.stories.tsx +1 -1
  95. package/src/stories-json/timeline.stories.tsx +1 -1
  96. package/src/stories-json/typography.stories.tsx +1 -1
@@ -0,0 +1,203 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * action:menu — Dropdown menu for overflow actions.
11
+ *
12
+ * Renders a Shadcn DropdownMenu populated from ActionSchema[].
13
+ * Each menu item triggers the corresponding action via ActionRunner.
14
+ */
15
+
16
+ import React, { forwardRef, useCallback, useMemo, useState } from 'react';
17
+ import { ComponentRegistry } from '@object-ui/core';
18
+ import type { ActionSchema } from '@object-ui/types';
19
+ import { useAction } from '@object-ui/react';
20
+ import { useCondition } from '@object-ui/react';
21
+ import { Button } from '../../ui';
22
+ import {
23
+ DropdownMenu,
24
+ DropdownMenuContent,
25
+ DropdownMenuItem,
26
+ DropdownMenuSeparator,
27
+ DropdownMenuTrigger,
28
+ } from '../../ui';
29
+ import { cn } from '../../lib/utils';
30
+ import { Loader2, MoreHorizontal } from 'lucide-react';
31
+ import { resolveIcon } from './resolve-icon';
32
+
33
+ export interface ActionMenuSchema {
34
+ type: 'action:menu';
35
+ /** Menu trigger label (defaults to icon-only) */
36
+ label?: string;
37
+ /** Menu trigger icon (defaults to more-horizontal) */
38
+ icon?: string;
39
+ /** Actions to render as menu items */
40
+ actions?: ActionSchema[];
41
+ /** Trigger variant */
42
+ variant?: string;
43
+ /** Trigger size */
44
+ size?: string;
45
+ /** Visibility condition */
46
+ visible?: string;
47
+ /** Custom CSS class */
48
+ className?: string;
49
+ [key: string]: any;
50
+ }
51
+
52
+ const ActionMenuItem: React.FC<{
53
+ action: ActionSchema;
54
+ onExecute: (action: ActionSchema) => Promise<void>;
55
+ }> = ({ action, onExecute }) => {
56
+ const isVisible = useCondition(action.visible ? `\${${action.visible}}` : undefined);
57
+ const isEnabled = useCondition(action.enabled ? `\${${action.enabled}}` : undefined);
58
+
59
+ const iconElement = useMemo(() => {
60
+ const Icon = resolveIcon(action.icon);
61
+ // eslint-disable-next-line react-hooks/static-components -- Icon is resolved from a stable icon registry
62
+ return Icon ? <Icon className="mr-2 h-4 w-4" /> : null;
63
+ }, [action.icon]);
64
+
65
+ if (action.visible && !isVisible) return null;
66
+
67
+ return (
68
+ <DropdownMenuItem
69
+ disabled={action.enabled ? !isEnabled : false}
70
+ onSelect={(e) => {
71
+ e.preventDefault();
72
+ onExecute(action);
73
+ }}
74
+ className={cn(
75
+ (action.variant as string) === 'destructive' && 'text-destructive focus:text-destructive',
76
+ action.className,
77
+ )}
78
+ >
79
+ {iconElement}
80
+ <span>{action.label || action.name}</span>
81
+ </DropdownMenuItem>
82
+ );
83
+ };
84
+
85
+ ActionMenuItem.displayName = 'ActionMenuItem';
86
+
87
+ const ActionMenuRenderer = forwardRef<HTMLButtonElement, { schema: ActionMenuSchema; [key: string]: any }>(
88
+ ({ schema, className, ...props }, ref) => {
89
+ const {
90
+ 'data-obj-id': dataObjId,
91
+ 'data-obj-type': dataObjType,
92
+ style,
93
+ ...rest
94
+ } = props;
95
+
96
+ const { execute } = useAction();
97
+ const [loading, setLoading] = useState(false);
98
+
99
+ const isVisible = useCondition(schema.visible ? `\${${schema.visible}}` : undefined);
100
+
101
+ const TriggerIcon = resolveIcon(schema.icon) || MoreHorizontal;
102
+ const variant = schema.variant || 'ghost';
103
+ const size = schema.size || 'icon';
104
+
105
+ const handleExecute = useCallback(
106
+ async (action: ActionSchema) => {
107
+ setLoading(true);
108
+ try {
109
+ await execute({
110
+ type: action.type,
111
+ name: action.name,
112
+ target: action.target,
113
+ execute: action.execute,
114
+ endpoint: action.endpoint,
115
+ method: action.method,
116
+ params: action.params as Record<string, any> | undefined,
117
+ confirmText: action.confirmText,
118
+ successMessage: action.successMessage,
119
+ errorMessage: action.errorMessage,
120
+ refreshAfter: action.refreshAfter,
121
+ toast: action.toast,
122
+ });
123
+ } finally {
124
+ setLoading(false);
125
+ }
126
+ },
127
+ [execute],
128
+ );
129
+
130
+ if (schema.visible && !isVisible) return null;
131
+
132
+ const actions = schema.actions || [];
133
+ if (actions.length === 0) return null;
134
+
135
+ return (
136
+ <DropdownMenu>
137
+ <DropdownMenuTrigger asChild>
138
+ <Button
139
+ ref={ref}
140
+ type="button"
141
+ variant={variant as any}
142
+ size={size as any}
143
+ className={cn(
144
+ size === 'icon' && 'h-8 w-8',
145
+ schema.className,
146
+ className,
147
+ )}
148
+ disabled={loading}
149
+ aria-label={schema.label || 'More actions'}
150
+ {...rest}
151
+ {...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
152
+ >
153
+ {loading ? (
154
+ <Loader2 className="h-4 w-4 animate-spin" />
155
+ ) : (
156
+ <>
157
+ <TriggerIcon className={cn('h-4 w-4', schema.label && 'mr-2')} />
158
+ {schema.label && <span>{schema.label}</span>}
159
+ </>
160
+ )}
161
+ </Button>
162
+ </DropdownMenuTrigger>
163
+
164
+ <DropdownMenuContent align="end">
165
+ {actions.map((action, index) => {
166
+ // Render separator for actions tagged with 'separator-before'
167
+ const showSeparator = action.tags?.includes('separator-before') && index > 0;
168
+ return (
169
+ <React.Fragment key={action.name || index}>
170
+ {showSeparator && <DropdownMenuSeparator />}
171
+ <ActionMenuItem action={action} onExecute={handleExecute} />
172
+ </React.Fragment>
173
+ );
174
+ })}
175
+ </DropdownMenuContent>
176
+ </DropdownMenu>
177
+ );
178
+ },
179
+ );
180
+
181
+ ActionMenuRenderer.displayName = 'ActionMenuRenderer';
182
+
183
+ ComponentRegistry.register('action:menu', ActionMenuRenderer, {
184
+ namespace: 'action',
185
+ label: 'Action Menu',
186
+ inputs: [
187
+ { name: 'label', type: 'string', label: 'Trigger Label' },
188
+ { name: 'icon', type: 'string', label: 'Trigger Icon' },
189
+ { name: 'actions', type: 'object', label: 'Actions' },
190
+ {
191
+ name: 'variant',
192
+ type: 'enum',
193
+ label: 'Trigger Variant',
194
+ enum: ['default', 'secondary', 'outline', 'ghost'],
195
+ defaultValue: 'ghost',
196
+ },
197
+ { name: 'className', type: 'string', label: 'CSS Class', advanced: true },
198
+ ],
199
+ defaultProps: {
200
+ variant: 'ghost',
201
+ actions: [],
202
+ },
203
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * Action renderers — Smart action components driven by ActionSchema.
11
+ *
12
+ * Registers: action:button, action:icon, action:menu, action:group
13
+ */
14
+
15
+ import './action-button';
16
+ import './action-icon';
17
+ import './action-menu';
18
+ import './action-group';
@@ -0,0 +1,35 @@
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 { icons, type LucideIcon } from 'lucide-react';
10
+
11
+ /**
12
+ * Convert a kebab-case icon name to PascalCase (e.g., "arrow-right" -> "ArrowRight").
13
+ */
14
+ function toPascalCase(str: string): string {
15
+ return str
16
+ .split('-')
17
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
18
+ .join('');
19
+ }
20
+
21
+ /** Map of renamed icons in lucide-react */
22
+ const iconNameMap: Record<string, string> = {
23
+ Home: 'House',
24
+ };
25
+
26
+ /**
27
+ * Resolve a Lucide icon by its kebab-case name.
28
+ * Returns null if not found.
29
+ */
30
+ export function resolveIcon(name: string | undefined): LucideIcon | null {
31
+ if (!name) return null;
32
+ const pascalName = toPascalCase(name);
33
+ const mapped = iconNameMap[pascalName] || pascalName;
34
+ return (icons as Record<string, LucideIcon>)[mapped] ?? null;
35
+ }
@@ -0,0 +1,275 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { describe, it, expect, vi } from 'vitest';
10
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
11
+ import React from 'react';
12
+ import type { DataTableSchema } from '@object-ui/types';
13
+
14
+ // Import the component
15
+ import '../data-table';
16
+ import { ComponentRegistry } from '@object-ui/core';
17
+
18
+ describe('Data Table - Batch Editing', () => {
19
+ const mockData = [
20
+ { id: 1, name: 'John Doe', email: 'john@example.com', age: 30 },
21
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com', age: 25 },
22
+ { id: 3, name: 'Bob Johnson', email: 'bob@example.com', age: 35 },
23
+ ];
24
+
25
+ const mockColumns = [
26
+ { header: 'ID', accessorKey: 'id', editable: false },
27
+ { header: 'Name', accessorKey: 'name' },
28
+ { header: 'Email', accessorKey: 'email' },
29
+ { header: 'Age', accessorKey: 'age' },
30
+ ];
31
+
32
+ it('should track pending changes across multiple cells', async () => {
33
+ const onRowSave = vi.fn();
34
+
35
+ const schema: DataTableSchema = {
36
+ type: 'data-table',
37
+ columns: mockColumns,
38
+ data: mockData,
39
+ editable: true,
40
+ pagination: false,
41
+ searchable: false,
42
+ rowActions: true,
43
+ onRowSave,
44
+ };
45
+
46
+ const DataTableRenderer = ComponentRegistry.get('data-table');
47
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
48
+
49
+ const { container } = render(<DataTableRenderer schema={schema} />);
50
+
51
+ // Edit first cell in row
52
+ const nameCell = screen.getByText('John Doe').closest('td');
53
+ if (nameCell) {
54
+ fireEvent.doubleClick(nameCell);
55
+
56
+ await waitFor(() => {
57
+ const input = nameCell.querySelector('input');
58
+ expect(input).toBeInTheDocument();
59
+ });
60
+
61
+ const input = nameCell.querySelector('input');
62
+ if (input) {
63
+ fireEvent.change(input, { target: { value: 'John Smith' } });
64
+ fireEvent.keyDown(input, { key: 'Enter' });
65
+ }
66
+ }
67
+
68
+ // Wait for the edit to be saved to pending changes
69
+ await waitFor(() => {
70
+ const modifiedIndicator = screen.getByText(/1 row modified/i);
71
+ expect(modifiedIndicator).toBeInTheDocument();
72
+ });
73
+
74
+ // Edit second cell in same row - find by searching through all cells
75
+ const emailCell = Array.from(container.querySelectorAll('td')).find(el =>
76
+ el.textContent?.includes('john@example.com')
77
+ );
78
+
79
+ expect(emailCell).toBeInTheDocument();
80
+ if (emailCell) {
81
+ fireEvent.doubleClick(emailCell);
82
+
83
+ await waitFor(() => {
84
+ const input = emailCell.querySelector('input');
85
+ expect(input).toBeInTheDocument();
86
+ });
87
+
88
+ const input = emailCell.querySelector('input');
89
+ if (input) {
90
+ fireEvent.change(input, { target: { value: 'johnsmith@example.com' } });
91
+ fireEvent.keyDown(input, { key: 'Enter' });
92
+ }
93
+ }
94
+
95
+ // Row should still show as modified (still just 1 row)
96
+ await waitFor(() => {
97
+ const modifiedIndicator = screen.getByText(/1 row modified/i);
98
+ expect(modifiedIndicator).toBeInTheDocument();
99
+ });
100
+ });
101
+
102
+ it('should save a single row with multiple changes', async () => {
103
+ const onRowSave = vi.fn().mockResolvedValue(undefined);
104
+
105
+ const schema: DataTableSchema = {
106
+ type: 'data-table',
107
+ columns: mockColumns,
108
+ data: mockData,
109
+ editable: true,
110
+ pagination: false,
111
+ searchable: false,
112
+ rowActions: true,
113
+ onRowSave,
114
+ };
115
+
116
+ const DataTableRenderer = ComponentRegistry.get('data-table');
117
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
118
+
119
+ render(<DataTableRenderer schema={schema} />);
120
+
121
+ // Edit name
122
+ const nameCell = screen.getByText('John Doe').closest('td');
123
+ if (nameCell) {
124
+ fireEvent.doubleClick(nameCell);
125
+ await waitFor(() => {
126
+ const input = nameCell.querySelector('input');
127
+ expect(input).toBeInTheDocument();
128
+ });
129
+
130
+ const input = nameCell.querySelector('input');
131
+ if (input) {
132
+ fireEvent.change(input, { target: { value: 'John Smith' } });
133
+ fireEvent.keyDown(input, { key: 'Enter' });
134
+ }
135
+ }
136
+
137
+ // Find and click save button for row
138
+ await waitFor(() => {
139
+ const saveButtons = screen.getAllByTitle('Save row');
140
+ expect(saveButtons.length).toBeGreaterThan(0);
141
+ fireEvent.click(saveButtons[0]);
142
+ });
143
+
144
+ // Verify callback was called with correct data
145
+ await waitFor(() => {
146
+ expect(onRowSave).toHaveBeenCalledWith(
147
+ 0,
148
+ { name: 'John Smith' },
149
+ mockData[0]
150
+ );
151
+ });
152
+ });
153
+
154
+ it('should save all modified rows with batch save', async () => {
155
+ const onBatchSave = vi.fn().mockResolvedValue(undefined);
156
+
157
+ const schema: DataTableSchema = {
158
+ type: 'data-table',
159
+ columns: mockColumns,
160
+ data: mockData,
161
+ editable: true,
162
+ pagination: false,
163
+ searchable: false,
164
+ onBatchSave,
165
+ };
166
+
167
+ const DataTableRenderer = ComponentRegistry.get('data-table');
168
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
169
+
170
+ render(<DataTableRenderer schema={schema} />);
171
+
172
+ // Edit row 1
173
+ const nameCell1 = screen.getByText('John Doe').closest('td');
174
+ if (nameCell1) {
175
+ fireEvent.doubleClick(nameCell1);
176
+ await waitFor(() => {
177
+ const input = nameCell1.querySelector('input');
178
+ expect(input).toBeInTheDocument();
179
+ });
180
+
181
+ const input = nameCell1.querySelector('input');
182
+ if (input) {
183
+ fireEvent.change(input, { target: { value: 'John Smith' } });
184
+ fireEvent.keyDown(input, { key: 'Enter' });
185
+ }
186
+ }
187
+
188
+ // Edit row 2
189
+ await waitFor(() => {
190
+ const nameCell2 = screen.getByText('Jane Smith').closest('td');
191
+ expect(nameCell2).toBeInTheDocument();
192
+ });
193
+
194
+ const nameCell2 = screen.getByText('Jane Smith').closest('td');
195
+ if (nameCell2) {
196
+ fireEvent.doubleClick(nameCell2);
197
+ await waitFor(() => {
198
+ const input = nameCell2.querySelector('input');
199
+ expect(input).toBeInTheDocument();
200
+ });
201
+
202
+ const input = nameCell2.querySelector('input');
203
+ if (input) {
204
+ fireEvent.change(input, { target: { value: 'Jane Doe' } });
205
+ fireEvent.keyDown(input, { key: 'Enter' });
206
+ }
207
+ }
208
+
209
+ // Click save all button
210
+ await waitFor(() => {
211
+ const saveAllButton = screen.getByText(/Save All \(2\)/i);
212
+ expect(saveAllButton).toBeInTheDocument();
213
+ fireEvent.click(saveAllButton);
214
+ });
215
+
216
+ // Verify callback was called
217
+ await waitFor(() => {
218
+ expect(onBatchSave).toHaveBeenCalledWith([
219
+ { rowIndex: 0, changes: { name: 'John Smith' }, row: mockData[0] },
220
+ { rowIndex: 1, changes: { name: 'Jane Doe' }, row: mockData[1] },
221
+ ]);
222
+ });
223
+ });
224
+
225
+ it('should cancel all changes', async () => {
226
+ const onBatchSave = vi.fn();
227
+
228
+ const schema: DataTableSchema = {
229
+ type: 'data-table',
230
+ columns: mockColumns,
231
+ data: mockData,
232
+ editable: true,
233
+ pagination: false,
234
+ searchable: false,
235
+ onBatchSave,
236
+ };
237
+
238
+ const DataTableRenderer = ComponentRegistry.get('data-table');
239
+ if (!DataTableRenderer) throw new Error('DataTableRenderer not found');
240
+
241
+ render(<DataTableRenderer schema={schema} />);
242
+
243
+ // Edit a cell
244
+ const nameCell = screen.getByText('John Doe').closest('td');
245
+ if (nameCell) {
246
+ fireEvent.doubleClick(nameCell);
247
+ await waitFor(() => {
248
+ const input = nameCell.querySelector('input');
249
+ expect(input).toBeInTheDocument();
250
+ });
251
+
252
+ const input = nameCell.querySelector('input');
253
+ if (input) {
254
+ fireEvent.change(input, { target: { value: 'John Smith' } });
255
+ fireEvent.keyDown(input, { key: 'Enter' });
256
+ }
257
+ }
258
+
259
+ // Click cancel all button
260
+ await waitFor(() => {
261
+ const cancelButton = screen.getByText(/Cancel All/i);
262
+ expect(cancelButton).toBeInTheDocument();
263
+ fireEvent.click(cancelButton);
264
+ });
265
+
266
+ // Verify changes indicator is gone
267
+ await waitFor(() => {
268
+ const modifiedIndicator = screen.queryByText(/row modified/i);
269
+ expect(modifiedIndicator).not.toBeInTheDocument();
270
+ });
271
+
272
+ // Original value should be restored
273
+ expect(screen.getByText('John Doe')).toBeInTheDocument();
274
+ });
275
+ });
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Data Table - Custom Cell Renderer Tests
3
+ *
4
+ * Tests that data-table respects col.cell() function for custom cell rendering.
5
+ */
6
+ import { describe, it, expect, vi } from 'vitest';
7
+ import { render, screen, waitFor } from '@testing-library/react';
8
+ import '@testing-library/jest-dom';
9
+ import React from 'react';
10
+ import { SchemaRenderer } from '@object-ui/react';
11
+
12
+ // Import data-table to ensure it's registered
13
+ import '../data-table';
14
+
15
+ describe('Data Table: col.cell() custom renderer', () => {
16
+ it('should invoke col.cell function to render cell content', async () => {
17
+ const cellFn = vi.fn((value: any, _row: any) => (
18
+ <span data-testid="custom-cell">{`Custom: ${value}`}</span>
19
+ ));
20
+
21
+ const schema = {
22
+ type: 'data-table',
23
+ columns: [
24
+ { header: 'Name', accessorKey: 'name', cell: cellFn },
25
+ { header: 'Email', accessorKey: 'email' },
26
+ ],
27
+ data: [
28
+ { name: 'Alice', email: 'alice@test.com' },
29
+ { name: 'Bob', email: 'bob@test.com' },
30
+ ],
31
+ pagination: false,
32
+ searchable: false,
33
+ };
34
+
35
+ render(<SchemaRenderer schema={schema} />);
36
+
37
+ await waitFor(() => {
38
+ expect(screen.getByText('Custom: Alice')).toBeInTheDocument();
39
+ });
40
+
41
+ expect(screen.getByText('Custom: Bob')).toBeInTheDocument();
42
+ expect(cellFn).toHaveBeenCalledTimes(2);
43
+
44
+ // Non-custom cell should render value directly
45
+ expect(screen.getByText('alice@test.com')).toBeInTheDocument();
46
+ });
47
+
48
+ it('should pass both value and row to cell function', async () => {
49
+ const cellFn = vi.fn((value: any, row: any) => (
50
+ <span data-testid="combo-cell">{`${value} (${row.email})`}</span>
51
+ ));
52
+
53
+ const schema = {
54
+ type: 'data-table',
55
+ columns: [
56
+ { header: 'Name', accessorKey: 'name', cell: cellFn },
57
+ ],
58
+ data: [
59
+ { name: 'Alice', email: 'alice@test.com' },
60
+ ],
61
+ pagination: false,
62
+ searchable: false,
63
+ };
64
+
65
+ render(<SchemaRenderer schema={schema} />);
66
+
67
+ await waitFor(() => {
68
+ expect(screen.getByText('Alice (alice@test.com)')).toBeInTheDocument();
69
+ });
70
+
71
+ expect(cellFn).toHaveBeenCalledWith('Alice', expect.objectContaining({ name: 'Alice', email: 'alice@test.com' }));
72
+ });
73
+
74
+ it('should render raw value when no cell function is provided', async () => {
75
+ const schema = {
76
+ type: 'data-table',
77
+ columns: [
78
+ { header: 'Name', accessorKey: 'name' },
79
+ ],
80
+ data: [
81
+ { name: 'Alice' },
82
+ ],
83
+ pagination: false,
84
+ searchable: false,
85
+ };
86
+
87
+ render(<SchemaRenderer schema={schema} />);
88
+
89
+ await waitFor(() => {
90
+ expect(screen.getByText('Alice')).toBeInTheDocument();
91
+ });
92
+ });
93
+
94
+ it('should prefer editing state over cell function when in edit mode', async () => {
95
+ // The editing state should take precedence over custom cell renderer
96
+ // This test verifies the rendering priority: editing > cell > raw value
97
+ const cellFn = vi.fn((value: any) => (
98
+ <span>{`Custom: ${value}`}</span>
99
+ ));
100
+
101
+ const schema = {
102
+ type: 'data-table',
103
+ columns: [
104
+ { header: 'Name', accessorKey: 'name', cell: cellFn },
105
+ ],
106
+ data: [
107
+ { name: 'Alice' },
108
+ ],
109
+ pagination: false,
110
+ searchable: false,
111
+ editable: false,
112
+ };
113
+
114
+ render(<SchemaRenderer schema={schema} />);
115
+
116
+ await waitFor(() => {
117
+ expect(screen.getByText('Custom: Alice')).toBeInTheDocument();
118
+ });
119
+ });
120
+ });