@object-ui/components 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.
- package/.turbo/turbo-build.log +12 -25
- package/CHANGELOG.md +32 -0
- package/dist/index.css +1 -1
- package/dist/index.js +23987 -22576
- package/dist/index.umd.cjs +30 -30
- package/dist/src/custom/action-param-dialog.d.ts +21 -0
- package/dist/src/custom/index.d.ts +4 -0
- package/dist/src/custom/navigation-overlay.d.ts +50 -0
- package/dist/src/custom/view-skeleton.d.ts +37 -0
- package/dist/src/custom/view-states.d.ts +33 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/renderers/action/action-button.d.ts +11 -0
- package/dist/src/renderers/action/action-group.d.ts +25 -0
- package/dist/src/renderers/action/action-icon.d.ts +10 -0
- package/dist/src/renderers/action/action-menu.d.ts +19 -0
- package/dist/src/renderers/action/index.d.ts +0 -0
- package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
- package/package.json +20 -19
- package/src/__tests__/PageRendererRegions.test.tsx +664 -55
- package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +811 -0
- package/src/__tests__/__snapshots__/snapshot.test.tsx.snap +327 -0
- package/src/__tests__/accessibility.test.tsx +137 -0
- package/src/__tests__/api-consistency.test.tsx +596 -0
- package/src/__tests__/color-contrast.test.tsx +212 -0
- package/src/__tests__/compliance.test.tsx +72 -0
- package/src/__tests__/edge-cases.test.tsx +285 -0
- package/src/__tests__/navigation-overlay.test.tsx +273 -0
- package/src/__tests__/snapshot-critical.test.tsx +317 -0
- package/src/__tests__/snapshot.test.tsx +205 -0
- package/src/__tests__/view-compliance.test.tsx +153 -0
- package/src/__tests__/wcag-audit.test.tsx +493 -0
- package/src/custom/action-param-dialog.tsx +264 -0
- package/src/custom/index.ts +4 -0
- package/src/custom/navigation-overlay.tsx +296 -0
- package/src/custom/view-skeleton.tsx +243 -0
- package/src/custom/view-states.tsx +153 -0
- package/src/index.ts +1 -0
- package/src/renderers/action/action-button.tsx +147 -0
- package/src/renderers/action/action-group.tsx +270 -0
- package/src/renderers/action/action-icon.tsx +150 -0
- package/src/renderers/action/action-menu.tsx +203 -0
- package/src/renderers/action/index.ts +18 -0
- package/src/renderers/action/resolve-icon.ts +35 -0
- package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
- package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
- package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
- package/src/renderers/complex/data-table.tsx +269 -33
- package/src/renderers/complex/resizable.tsx +20 -17
- package/src/renderers/data-display/list.tsx +1 -1
- package/src/renderers/data-display/table.tsx +1 -1
- package/src/renderers/data-display/tree-view.tsx +2 -1
- package/src/renderers/form/form.tsx +33 -10
- package/src/renderers/index.ts +1 -0
- package/src/renderers/layout/aspect-ratio.tsx +1 -1
- package/src/renderers/layout/page.tsx +416 -52
- package/src/renderers/navigation/sidebar.tsx +6 -0
- package/src/renderers/placeholders.tsx +2 -2
- package/src/stories/MockedData.stories.tsx +87 -37
- package/src/stories-json/Accessibility.mdx +297 -0
- package/src/stories-json/EdgeCases.stories.tsx +160 -0
- package/src/stories-json/GettingStarted.mdx +89 -0
- package/src/stories-json/Introduction.mdx +127 -0
- package/src/stories-json/accordion.stories.tsx +1 -1
- package/src/stories-json/aggrid.stories.tsx +1 -1
- package/src/stories-json/alert.stories.tsx +1 -1
- package/src/stories-json/aspect-ratio.stories.tsx +1 -1
- package/src/stories-json/avatar.stories.tsx +1 -1
- package/src/stories-json/badge.stories.tsx +1 -1
- package/src/stories-json/breadcrumb.stories.tsx +1 -1
- package/src/stories-json/button-group.stories.tsx +1 -1
- package/src/stories-json/button.stories.tsx +1 -1
- package/src/stories-json/calendar.stories.tsx +1 -1
- package/src/stories-json/card.stories.tsx +1 -1
- package/src/stories-json/carousel.stories.tsx +1 -1
- package/src/stories-json/charts.stories.tsx +1 -1
- package/src/stories-json/chatbot.stories.tsx +1 -1
- package/src/stories-json/code-editor.stories.tsx +1 -1
- package/src/stories-json/collapsible.stories.tsx +1 -1
- package/src/stories-json/controls.stories.tsx +1 -1
- package/src/stories-json/crm-live-data.stories.tsx +154 -0
- package/src/stories-json/data-table.stories.tsx +80 -4
- package/src/stories-json/data_display_extras.stories.tsx +1 -1
- package/src/stories-json/date-picker.stories.tsx +1 -1
- package/src/stories-json/detail-view.stories.tsx +1 -1
- package/src/stories-json/dialog.stories.tsx +1 -1
- package/src/stories-json/feedback_extras.stories.tsx +1 -1
- package/src/stories-json/feedback_others.stories.tsx +1 -1
- package/src/stories-json/form-variants.stories.tsx +210 -0
- package/src/stories-json/form_advanced.stories.tsx +1 -1
- package/src/stories-json/form_extras.stories.tsx +1 -1
- package/src/stories-json/grid.stories.tsx +1 -1
- package/src/stories-json/icon.stories.tsx +1 -1
- package/src/stories-json/input.stories.tsx +1 -1
- package/src/stories-json/kanban.stories.tsx +1 -1
- package/src/stories-json/layout_extended.stories.tsx +1 -1
- package/src/stories-json/layout_flex.stories.tsx +1 -1
- package/src/stories-json/list-view.stories.tsx +1 -1
- package/src/stories-json/markdown.stories.tsx +1 -1
- package/src/stories-json/menus.stories.tsx +1 -1
- package/src/stories-json/metric-card.stories.tsx +1 -1
- package/src/stories-json/navigation-menu.stories.tsx +1 -1
- package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
- package/src/stories-json/object-aggrid.stories.tsx +1 -1
- package/src/stories-json/object-form.stories.tsx +1 -1
- package/src/stories-json/object-gantt.stories.tsx +1 -1
- package/src/stories-json/object-grid.stories.tsx +159 -1
- package/src/stories-json/object-map.stories.tsx +1 -1
- package/src/stories-json/object-view.stories.tsx +1 -1
- package/src/stories-json/overlay_extras.stories.tsx +1 -1
- package/src/stories-json/overlay_others.stories.tsx +1 -1
- package/src/stories-json/resizable.stories.tsx +1 -1
- package/src/stories-json/select.stories.tsx +1 -1
- package/src/stories-json/separator.stories.tsx +1 -1
- package/src/stories-json/statistic.stories.tsx +1 -1
- package/src/stories-json/tabs.stories.tsx +1 -1
- package/src/stories-json/timeline.stories.tsx +1 -1
- package/src/stories-json/typography.stories.tsx +1 -1
- package/src/ui/slider.tsx +6 -2
- package/src/stories/Introduction.mdx +0 -34
|
@@ -0,0 +1,270 @@
|
|
|
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:group — Toolbar or button group for organizing related actions.
|
|
11
|
+
*
|
|
12
|
+
* Supports two display modes:
|
|
13
|
+
* - 'inline': Renders all actions as a horizontal button row
|
|
14
|
+
* - 'dropdown': Renders a primary button + dropdown for overflow
|
|
15
|
+
*
|
|
16
|
+
* Filters actions by location when `location` prop is provided.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React, { forwardRef, useCallback, useState } from 'react';
|
|
20
|
+
import { ComponentRegistry } from '@object-ui/core';
|
|
21
|
+
import type { ActionSchema, ActionGroup, ActionLocation } from '@object-ui/types';
|
|
22
|
+
import { useAction } from '@object-ui/react';
|
|
23
|
+
import { useCondition } from '@object-ui/react';
|
|
24
|
+
import { Button } from '../../ui';
|
|
25
|
+
import {
|
|
26
|
+
DropdownMenu,
|
|
27
|
+
DropdownMenuContent,
|
|
28
|
+
DropdownMenuItem,
|
|
29
|
+
DropdownMenuSeparator,
|
|
30
|
+
DropdownMenuTrigger,
|
|
31
|
+
} from '../../ui';
|
|
32
|
+
import { cn } from '../../lib/utils';
|
|
33
|
+
import { Loader2, ChevronDown } from 'lucide-react';
|
|
34
|
+
import { resolveIcon } from './resolve-icon';
|
|
35
|
+
|
|
36
|
+
export interface ActionGroupSchema {
|
|
37
|
+
type: 'action:group';
|
|
38
|
+
/** Group name */
|
|
39
|
+
name?: string;
|
|
40
|
+
/** Group label */
|
|
41
|
+
label?: string;
|
|
42
|
+
/** Group icon */
|
|
43
|
+
icon?: string;
|
|
44
|
+
/** Actions in this group */
|
|
45
|
+
actions?: ActionSchema[];
|
|
46
|
+
/** Display mode: inline button row or dropdown */
|
|
47
|
+
display?: 'dropdown' | 'inline';
|
|
48
|
+
/** Filter actions by location */
|
|
49
|
+
location?: ActionLocation;
|
|
50
|
+
/** Group visibility condition */
|
|
51
|
+
visible?: string;
|
|
52
|
+
/** Button variant for inline actions */
|
|
53
|
+
variant?: string;
|
|
54
|
+
/** Button size for inline actions */
|
|
55
|
+
size?: string;
|
|
56
|
+
/** Custom CSS class */
|
|
57
|
+
className?: string;
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Inline action button within a group.
|
|
63
|
+
*/
|
|
64
|
+
const InlineActionButton: React.FC<{
|
|
65
|
+
action: ActionSchema;
|
|
66
|
+
variant?: string;
|
|
67
|
+
size?: string;
|
|
68
|
+
onExecute: (action: ActionSchema) => Promise<void>;
|
|
69
|
+
}> = ({ action, variant, size, onExecute }) => {
|
|
70
|
+
const [loading, setLoading] = useState(false);
|
|
71
|
+
const isVisible = useCondition(action.visible ? `\${${action.visible}}` : undefined);
|
|
72
|
+
const isEnabled = useCondition(action.enabled ? `\${${action.enabled}}` : undefined);
|
|
73
|
+
|
|
74
|
+
const Icon = resolveIcon(action.icon);
|
|
75
|
+
const btnVariant = (action.variant as string) === 'primary' ? 'default' : (action.variant || variant || 'outline');
|
|
76
|
+
const btnSize = action.size === 'md' ? 'default' : (action.size || size || 'sm');
|
|
77
|
+
|
|
78
|
+
const handleClick = useCallback(async () => {
|
|
79
|
+
if (loading) return;
|
|
80
|
+
setLoading(true);
|
|
81
|
+
try {
|
|
82
|
+
await onExecute(action);
|
|
83
|
+
} finally {
|
|
84
|
+
setLoading(false);
|
|
85
|
+
}
|
|
86
|
+
}, [action, onExecute, loading]);
|
|
87
|
+
|
|
88
|
+
if (action.visible && !isVisible) return null;
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Button
|
|
92
|
+
type="button"
|
|
93
|
+
variant={btnVariant as any}
|
|
94
|
+
size={btnSize as any}
|
|
95
|
+
className={action.className}
|
|
96
|
+
disabled={(action.enabled ? !isEnabled : false) || loading}
|
|
97
|
+
onClick={handleClick}
|
|
98
|
+
>
|
|
99
|
+
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
100
|
+
{!loading && Icon && <Icon className={cn('h-4 w-4', action.label && 'mr-2')} />}
|
|
101
|
+
{action.label}
|
|
102
|
+
</Button>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
InlineActionButton.displayName = 'InlineActionButton';
|
|
107
|
+
|
|
108
|
+
const ActionGroupRenderer = forwardRef<HTMLDivElement, { schema: ActionGroupSchema; [key: string]: any }>(
|
|
109
|
+
({ schema, className, ...props }, ref) => {
|
|
110
|
+
const {
|
|
111
|
+
'data-obj-id': dataObjId,
|
|
112
|
+
'data-obj-type': dataObjType,
|
|
113
|
+
style,
|
|
114
|
+
...rest
|
|
115
|
+
} = props;
|
|
116
|
+
|
|
117
|
+
const { execute } = useAction();
|
|
118
|
+
const [dropdownLoading, setDropdownLoading] = useState(false);
|
|
119
|
+
|
|
120
|
+
const isVisible = useCondition(schema.visible ? `\${${schema.visible}}` : undefined);
|
|
121
|
+
|
|
122
|
+
// Filter actions by location if specified
|
|
123
|
+
let actions = schema.actions || [];
|
|
124
|
+
if (schema.location) {
|
|
125
|
+
actions = actions.filter(
|
|
126
|
+
a => !a.locations || a.locations.includes(schema.location!),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const handleExecute = useCallback(
|
|
131
|
+
async (action: ActionSchema) => {
|
|
132
|
+
await execute({
|
|
133
|
+
type: action.type,
|
|
134
|
+
name: action.name,
|
|
135
|
+
target: action.target,
|
|
136
|
+
execute: action.execute,
|
|
137
|
+
endpoint: action.endpoint,
|
|
138
|
+
method: action.method,
|
|
139
|
+
params: action.params as Record<string, any> | undefined,
|
|
140
|
+
confirmText: action.confirmText,
|
|
141
|
+
successMessage: action.successMessage,
|
|
142
|
+
errorMessage: action.errorMessage,
|
|
143
|
+
refreshAfter: action.refreshAfter,
|
|
144
|
+
toast: action.toast,
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
[execute],
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (schema.visible && !isVisible) return null;
|
|
151
|
+
if (actions.length === 0) return null;
|
|
152
|
+
|
|
153
|
+
const display = schema.display || 'inline';
|
|
154
|
+
|
|
155
|
+
// --- DROPDOWN MODE ---
|
|
156
|
+
if (display === 'dropdown') {
|
|
157
|
+
const TriggerIcon = resolveIcon(schema.icon);
|
|
158
|
+
return (
|
|
159
|
+
<DropdownMenu>
|
|
160
|
+
<DropdownMenuTrigger asChild>
|
|
161
|
+
<Button
|
|
162
|
+
type="button"
|
|
163
|
+
variant={(schema.variant || 'outline') as any}
|
|
164
|
+
size={(schema.size === 'md' ? 'default' : (schema.size || 'default')) as any}
|
|
165
|
+
className={cn(schema.className, className)}
|
|
166
|
+
disabled={dropdownLoading}
|
|
167
|
+
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
168
|
+
>
|
|
169
|
+
{dropdownLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
170
|
+
{!dropdownLoading && TriggerIcon && <TriggerIcon className="mr-2 h-4 w-4" />}
|
|
171
|
+
{schema.label || 'Actions'}
|
|
172
|
+
<ChevronDown className="ml-2 h-3 w-3 opacity-50" />
|
|
173
|
+
</Button>
|
|
174
|
+
</DropdownMenuTrigger>
|
|
175
|
+
|
|
176
|
+
<DropdownMenuContent align="end">
|
|
177
|
+
{actions.map((action, index) => {
|
|
178
|
+
const Icon = resolveIcon(action.icon);
|
|
179
|
+
const showSeparator = action.tags?.includes('separator-before') && index > 0;
|
|
180
|
+
return (
|
|
181
|
+
<React.Fragment key={action.name || index}>
|
|
182
|
+
{showSeparator && <DropdownMenuSeparator />}
|
|
183
|
+
<DropdownMenuItem
|
|
184
|
+
onSelect={async (e) => {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
setDropdownLoading(true);
|
|
187
|
+
try {
|
|
188
|
+
await handleExecute(action);
|
|
189
|
+
} finally {
|
|
190
|
+
setDropdownLoading(false);
|
|
191
|
+
}
|
|
192
|
+
}}
|
|
193
|
+
className={cn(
|
|
194
|
+
action.variant === 'destructive' && 'text-destructive focus:text-destructive',
|
|
195
|
+
action.className,
|
|
196
|
+
)}
|
|
197
|
+
>
|
|
198
|
+
{Icon && <Icon className="mr-2 h-4 w-4" />}
|
|
199
|
+
<span>{action.label || action.name}</span>
|
|
200
|
+
</DropdownMenuItem>
|
|
201
|
+
</React.Fragment>
|
|
202
|
+
);
|
|
203
|
+
})}
|
|
204
|
+
</DropdownMenuContent>
|
|
205
|
+
</DropdownMenu>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// --- INLINE MODE (default) ---
|
|
210
|
+
return (
|
|
211
|
+
<div
|
|
212
|
+
ref={ref}
|
|
213
|
+
className={cn('flex items-center gap-2', schema.className, className)}
|
|
214
|
+
{...rest}
|
|
215
|
+
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
216
|
+
>
|
|
217
|
+
{actions.map((action) => (
|
|
218
|
+
<InlineActionButton
|
|
219
|
+
key={action.name}
|
|
220
|
+
action={action}
|
|
221
|
+
variant={schema.variant}
|
|
222
|
+
size={schema.size}
|
|
223
|
+
onExecute={handleExecute}
|
|
224
|
+
/>
|
|
225
|
+
))}
|
|
226
|
+
</div>
|
|
227
|
+
);
|
|
228
|
+
},
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
ActionGroupRenderer.displayName = 'ActionGroupRenderer';
|
|
232
|
+
|
|
233
|
+
ComponentRegistry.register('action:group', ActionGroupRenderer, {
|
|
234
|
+
namespace: 'action',
|
|
235
|
+
label: 'Action Group',
|
|
236
|
+
inputs: [
|
|
237
|
+
{ name: 'name', type: 'string', label: 'Group Name' },
|
|
238
|
+
{ name: 'label', type: 'string', label: 'Label' },
|
|
239
|
+
{ name: 'icon', type: 'string', label: 'Icon' },
|
|
240
|
+
{ name: 'actions', type: 'object', label: 'Actions' },
|
|
241
|
+
{
|
|
242
|
+
name: 'display',
|
|
243
|
+
type: 'enum',
|
|
244
|
+
label: 'Display Mode',
|
|
245
|
+
enum: ['inline', 'dropdown'],
|
|
246
|
+
defaultValue: 'inline',
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: 'variant',
|
|
250
|
+
type: 'enum',
|
|
251
|
+
label: 'Variant',
|
|
252
|
+
enum: ['default', 'secondary', 'outline', 'ghost'],
|
|
253
|
+
defaultValue: 'outline',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: 'size',
|
|
257
|
+
type: 'enum',
|
|
258
|
+
label: 'Size',
|
|
259
|
+
enum: ['sm', 'md', 'lg'],
|
|
260
|
+
defaultValue: 'sm',
|
|
261
|
+
},
|
|
262
|
+
{ name: 'className', type: 'string', label: 'CSS Class', advanced: true },
|
|
263
|
+
],
|
|
264
|
+
defaultProps: {
|
|
265
|
+
display: 'inline',
|
|
266
|
+
variant: 'outline',
|
|
267
|
+
size: 'sm',
|
|
268
|
+
actions: [],
|
|
269
|
+
},
|
|
270
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
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:icon — Icon-only action button for dense layouts.
|
|
11
|
+
*
|
|
12
|
+
* Renders a Shadcn Button (size="icon") with tooltip and ActionRunner integration.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import React, { forwardRef, useCallback, useState } from 'react';
|
|
16
|
+
import { ComponentRegistry } from '@object-ui/core';
|
|
17
|
+
import type { ActionSchema } from '@object-ui/types';
|
|
18
|
+
import { useAction } from '@object-ui/react';
|
|
19
|
+
import { useCondition } from '@object-ui/react';
|
|
20
|
+
import { Button } from '../../ui';
|
|
21
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui';
|
|
22
|
+
import { cn } from '../../lib/utils';
|
|
23
|
+
import { Loader2 } from 'lucide-react';
|
|
24
|
+
import { resolveIcon } from './resolve-icon';
|
|
25
|
+
|
|
26
|
+
export interface ActionIconProps {
|
|
27
|
+
schema: ActionSchema & { type: string; className?: string };
|
|
28
|
+
className?: string;
|
|
29
|
+
context?: Record<string, any>;
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ActionIconRenderer = forwardRef<HTMLButtonElement, ActionIconProps>(
|
|
34
|
+
({ schema, className, context: localContext, ...props }, ref) => {
|
|
35
|
+
const {
|
|
36
|
+
'data-obj-id': dataObjId,
|
|
37
|
+
'data-obj-type': dataObjType,
|
|
38
|
+
style,
|
|
39
|
+
...rest
|
|
40
|
+
} = props;
|
|
41
|
+
|
|
42
|
+
const { execute } = useAction();
|
|
43
|
+
const [loading, setLoading] = useState(false);
|
|
44
|
+
|
|
45
|
+
const isVisible = useCondition(schema.visible ? `\${${schema.visible}}` : undefined);
|
|
46
|
+
const isEnabled = useCondition(schema.enabled ? `\${${schema.enabled}}` : undefined);
|
|
47
|
+
|
|
48
|
+
const Icon = resolveIcon(schema.icon);
|
|
49
|
+
const variant = schema.variant === 'primary' ? 'default' : (schema.variant || 'ghost');
|
|
50
|
+
const size = 'icon';
|
|
51
|
+
|
|
52
|
+
const handleClick = useCallback(async () => {
|
|
53
|
+
if (loading) return;
|
|
54
|
+
setLoading(true);
|
|
55
|
+
try {
|
|
56
|
+
await execute({
|
|
57
|
+
type: schema.type,
|
|
58
|
+
name: schema.name,
|
|
59
|
+
target: schema.target,
|
|
60
|
+
execute: schema.execute,
|
|
61
|
+
endpoint: schema.endpoint,
|
|
62
|
+
method: schema.method,
|
|
63
|
+
params: schema.params as Record<string, any> | undefined,
|
|
64
|
+
confirmText: schema.confirmText,
|
|
65
|
+
successMessage: schema.successMessage,
|
|
66
|
+
errorMessage: schema.errorMessage,
|
|
67
|
+
refreshAfter: schema.refreshAfter,
|
|
68
|
+
toast: schema.toast,
|
|
69
|
+
...localContext,
|
|
70
|
+
});
|
|
71
|
+
} finally {
|
|
72
|
+
setLoading(false);
|
|
73
|
+
}
|
|
74
|
+
}, [schema, execute, loading, localContext]);
|
|
75
|
+
|
|
76
|
+
if (schema.visible && !isVisible) return null;
|
|
77
|
+
|
|
78
|
+
const button = (
|
|
79
|
+
<Button
|
|
80
|
+
ref={ref}
|
|
81
|
+
type="button"
|
|
82
|
+
variant={variant as any}
|
|
83
|
+
size={size}
|
|
84
|
+
className={cn('h-8 w-8', schema.className, className)}
|
|
85
|
+
disabled={(schema.enabled ? !isEnabled : false) || loading}
|
|
86
|
+
onClick={handleClick}
|
|
87
|
+
aria-label={schema.label || schema.name}
|
|
88
|
+
{...rest}
|
|
89
|
+
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
90
|
+
>
|
|
91
|
+
{loading ? (
|
|
92
|
+
<Loader2 className="h-4 w-4 animate-spin" />
|
|
93
|
+
) : Icon ? (
|
|
94
|
+
<Icon className="h-4 w-4" />
|
|
95
|
+
) : (
|
|
96
|
+
<span className="text-xs">{schema.label?.charAt(0) || '?'}</span>
|
|
97
|
+
)}
|
|
98
|
+
</Button>
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// Wrap with tooltip if label is provided
|
|
102
|
+
if (schema.label || schema.description) {
|
|
103
|
+
return (
|
|
104
|
+
<TooltipProvider delayDuration={300}>
|
|
105
|
+
<Tooltip>
|
|
106
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
107
|
+
<TooltipContent>
|
|
108
|
+
<p>{schema.label || schema.description}</p>
|
|
109
|
+
</TooltipContent>
|
|
110
|
+
</Tooltip>
|
|
111
|
+
</TooltipProvider>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return button;
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
ActionIconRenderer.displayName = 'ActionIconRenderer';
|
|
120
|
+
|
|
121
|
+
ComponentRegistry.register('action:icon', ActionIconRenderer, {
|
|
122
|
+
namespace: 'action',
|
|
123
|
+
label: 'Action Icon',
|
|
124
|
+
inputs: [
|
|
125
|
+
{ name: 'name', type: 'string', label: 'Action Name' },
|
|
126
|
+
{ name: 'label', type: 'string', label: 'Tooltip Label' },
|
|
127
|
+
{ name: 'icon', type: 'string', label: 'Icon' },
|
|
128
|
+
{
|
|
129
|
+
name: 'type',
|
|
130
|
+
type: 'enum',
|
|
131
|
+
label: 'Action Type',
|
|
132
|
+
enum: ['script', 'url', 'modal', 'flow', 'api'],
|
|
133
|
+
defaultValue: 'script',
|
|
134
|
+
},
|
|
135
|
+
{ name: 'target', type: 'string', label: 'Target' },
|
|
136
|
+
{
|
|
137
|
+
name: 'variant',
|
|
138
|
+
type: 'enum',
|
|
139
|
+
label: 'Variant',
|
|
140
|
+
enum: ['default', 'secondary', 'destructive', 'outline', 'ghost'],
|
|
141
|
+
defaultValue: 'ghost',
|
|
142
|
+
},
|
|
143
|
+
{ name: 'className', type: 'string', label: 'CSS Class', advanced: true },
|
|
144
|
+
],
|
|
145
|
+
defaultProps: {
|
|
146
|
+
icon: 'play',
|
|
147
|
+
type: 'script',
|
|
148
|
+
variant: 'ghost',
|
|
149
|
+
},
|
|
150
|
+
});
|
|
@@ -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
|
+
}
|