@object-ui/components 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +21 -1
- package/dist/index.css +6339 -2
- package/dist/index.js +17600 -17481
- package/dist/index.umd.cjs +36 -36
- package/dist/packages/components/src/custom/empty.d.ts +12 -1
- package/dist/packages/components/src/renderers/action/action-bar.d.ts +12 -1
- package/dist/packages/components/src/ui/chart.d.ts +10 -29
- package/package.json +65 -44
- package/.turbo/turbo-build.log +0 -84
- package/README_SHADCN_SYNC.md +0 -281
- package/TESTING.md +0 -335
- package/docs/FilterBuilder.md +0 -268
- package/metadata/Chart.component.yml +0 -30
- package/metadata/FilterBuilder.component.yml +0 -39
- package/metadata/GridLayout.component.yml +0 -27
- package/metadata/Menu.component.yml +0 -31
- package/metadata/ObjectForm.component.yml +0 -34
- package/metadata/ObjectGrid.component.yml +0 -72
- package/metadata/Page.component.yml +0 -24
- package/postcss.config.js +0 -14
- package/shadcn-components.json +0 -440
- package/src/SchemaRenderer.tsx +0 -28
- package/src/__tests__/PageRendererRegions.test.tsx +0 -668
- package/src/__tests__/README.md +0 -124
- package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +0 -811
- package/src/__tests__/__snapshots__/snapshot.test.tsx.snap +0 -327
- package/src/__tests__/accessibility.test.tsx +0 -137
- package/src/__tests__/action-bar.test.tsx +0 -206
- package/src/__tests__/api-consistency.test.tsx +0 -596
- package/src/__tests__/basic-renderers.test.tsx +0 -255
- package/src/__tests__/color-contrast.test.tsx +0 -212
- package/src/__tests__/complex-disclosure-renderers.test.tsx +0 -302
- package/src/__tests__/compliance.test.tsx +0 -72
- package/src/__tests__/config-field-renderer.test.tsx +0 -307
- package/src/__tests__/config-panel-renderer.test.tsx +0 -580
- package/src/__tests__/config-primitives.test.tsx +0 -106
- package/src/__tests__/edge-cases.test.tsx +0 -285
- package/src/__tests__/feedback-overlay-renderers.test.tsx +0 -349
- package/src/__tests__/filter-builder.test.tsx +0 -409
- package/src/__tests__/form-renderers.test.tsx +0 -364
- package/src/__tests__/layout-data-renderers.test.tsx +0 -340
- package/src/__tests__/mobile-accessibility.test.tsx +0 -120
- package/src/__tests__/navigation-overlay.test.tsx +0 -370
- package/src/__tests__/snapshot-critical.test.tsx +0 -317
- package/src/__tests__/snapshot.test.tsx +0 -205
- package/src/__tests__/test-utils.tsx +0 -190
- package/src/__tests__/use-config-draft.test.tsx +0 -295
- package/src/__tests__/view-compliance.test.tsx +0 -153
- package/src/__tests__/wcag-audit.test.tsx +0 -493
- package/src/custom/action-param-dialog.tsx +0 -264
- package/src/custom/button-group.tsx +0 -91
- package/src/custom/combobox.tsx +0 -104
- package/src/custom/config-field-renderer.tsx +0 -276
- package/src/custom/config-panel-renderer.tsx +0 -306
- package/src/custom/config-row.tsx +0 -50
- package/src/custom/date-picker.tsx +0 -61
- package/src/custom/empty.tsx +0 -112
- package/src/custom/field.tsx +0 -81
- package/src/custom/filter-builder.tsx +0 -418
- package/src/custom/index.ts +0 -21
- package/src/custom/input-group.tsx +0 -53
- package/src/custom/item.tsx +0 -201
- package/src/custom/kbd.tsx +0 -36
- package/src/custom/mobile-dialog-content.tsx +0 -67
- package/src/custom/native-select.tsx +0 -33
- package/src/custom/navigation-overlay.tsx +0 -334
- package/src/custom/section-header.tsx +0 -68
- package/src/custom/sort-builder.tsx +0 -129
- package/src/custom/spinner.tsx +0 -26
- package/src/custom/view-skeleton.tsx +0 -243
- package/src/custom/view-states.tsx +0 -153
- package/src/debug/DebugPanel.tsx +0 -313
- package/src/debug/__tests__/DebugPanel.test.tsx +0 -134
- package/src/debug/index.ts +0 -10
- package/src/hooks/use-config-draft.ts +0 -127
- package/src/hooks/use-mobile.tsx +0 -27
- package/src/index.css +0 -245
- package/src/index.ts +0 -47
- package/src/lib/use-sync-external-store-shim.ts +0 -10
- package/src/lib/use-sync-external-store-with-selector-shim.ts +0 -90
- package/src/lib/utils.tsx +0 -35
- package/src/new-components.test.ts +0 -73
- package/src/renderers/action/action-bar.tsx +0 -221
- package/src/renderers/action/action-button.tsx +0 -158
- package/src/renderers/action/action-group.tsx +0 -270
- package/src/renderers/action/action-icon.tsx +0 -150
- package/src/renderers/action/action-menu.tsx +0 -203
- package/src/renderers/action/index.ts +0 -19
- package/src/renderers/action/resolve-icon.ts +0 -35
- package/src/renderers/basic/button-group.tsx +0 -79
- package/src/renderers/basic/div.tsx +0 -60
- package/src/renderers/basic/html.tsx +0 -43
- package/src/renderers/basic/icon.tsx +0 -89
- package/src/renderers/basic/image.tsx +0 -49
- package/src/renderers/basic/index.ts +0 -18
- package/src/renderers/basic/navigation-menu.tsx +0 -81
- package/src/renderers/basic/pagination.tsx +0 -109
- package/src/renderers/basic/separator.tsx +0 -57
- package/src/renderers/basic/span.tsx +0 -63
- package/src/renderers/basic/text.tsx +0 -52
- package/src/renderers/complex/README-KANBAN.md +0 -208
- package/src/renderers/complex/TIMELINE.md +0 -353
- package/src/renderers/complex/__tests__/data-table-airtable-ux.test.tsx +0 -239
- package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +0 -275
- package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +0 -120
- package/src/renderers/complex/__tests__/data-table-editing.test.tsx +0 -221
- package/src/renderers/complex/__tests__/data-table.test.ts +0 -76
- package/src/renderers/complex/carousel.tsx +0 -69
- package/src/renderers/complex/data-table.tsx +0 -1243
- package/src/renderers/complex/filter-builder.tsx +0 -77
- package/src/renderers/complex/index.ts +0 -16
- package/src/renderers/complex/resizable.tsx +0 -66
- package/src/renderers/complex/scroll-area.tsx +0 -58
- package/src/renderers/complex/table.tsx +0 -95
- package/src/renderers/data-display/alert.tsx +0 -46
- package/src/renderers/data-display/avatar.tsx +0 -38
- package/src/renderers/data-display/badge.tsx +0 -55
- package/src/renderers/data-display/breadcrumb.tsx +0 -61
- package/src/renderers/data-display/index.ts +0 -18
- package/src/renderers/data-display/kbd.tsx +0 -50
- package/src/renderers/data-display/list.tsx +0 -75
- package/src/renderers/data-display/statistic.tsx +0 -95
- package/src/renderers/data-display/table.tsx +0 -78
- package/src/renderers/data-display/tree-view.tsx +0 -176
- package/src/renderers/disclosure/accordion.tsx +0 -69
- package/src/renderers/disclosure/collapsible.tsx +0 -53
- package/src/renderers/disclosure/index.ts +0 -11
- package/src/renderers/disclosure/toggle-group.tsx +0 -79
- package/src/renderers/feedback/empty.tsx +0 -49
- package/src/renderers/feedback/index.ts +0 -16
- package/src/renderers/feedback/loading.tsx +0 -78
- package/src/renderers/feedback/progress.tsx +0 -29
- package/src/renderers/feedback/skeleton.tsx +0 -31
- package/src/renderers/feedback/sonner.tsx +0 -56
- package/src/renderers/feedback/spinner.tsx +0 -55
- package/src/renderers/feedback/toast.tsx +0 -59
- package/src/renderers/feedback/toaster.tsx +0 -23
- package/src/renderers/form/button.tsx +0 -103
- package/src/renderers/form/calendar.tsx +0 -34
- package/src/renderers/form/checkbox.tsx +0 -71
- package/src/renderers/form/combobox.tsx +0 -48
- package/src/renderers/form/command.tsx +0 -58
- package/src/renderers/form/date-picker.tsx +0 -84
- package/src/renderers/form/file-upload.tsx +0 -184
- package/src/renderers/form/form.tsx +0 -540
- package/src/renderers/form/index.ts +0 -26
- package/src/renderers/form/input-otp.tsx +0 -51
- package/src/renderers/form/input.tsx +0 -121
- package/src/renderers/form/label.tsx +0 -45
- package/src/renderers/form/radio-group.tsx +0 -63
- package/src/renderers/form/select.tsx +0 -94
- package/src/renderers/form/slider.tsx +0 -61
- package/src/renderers/form/switch.tsx +0 -48
- package/src/renderers/form/textarea.tsx +0 -76
- package/src/renderers/form/toggle.tsx +0 -42
- package/src/renderers/index.ts +0 -18
- package/src/renderers/layout/aspect-ratio.tsx +0 -51
- package/src/renderers/layout/card.tsx +0 -85
- package/src/renderers/layout/container.tsx +0 -122
- package/src/renderers/layout/flex.tsx +0 -132
- package/src/renderers/layout/grid.tsx +0 -178
- package/src/renderers/layout/index.ts +0 -19
- package/src/renderers/layout/page.tsx +0 -466
- package/src/renderers/layout/semantic.tsx +0 -48
- package/src/renderers/layout/stack.tsx +0 -132
- package/src/renderers/layout/tabs.tsx +0 -97
- package/src/renderers/navigation/header-bar.tsx +0 -118
- package/src/renderers/navigation/index.ts +0 -10
- package/src/renderers/navigation/sidebar.tsx +0 -208
- package/src/renderers/overlay/alert-dialog.tsx +0 -72
- package/src/renderers/overlay/context-menu.tsx +0 -100
- package/src/renderers/overlay/dialog.tsx +0 -77
- package/src/renderers/overlay/drawer.tsx +0 -77
- package/src/renderers/overlay/dropdown-menu.tsx +0 -99
- package/src/renderers/overlay/hover-card.tsx +0 -55
- package/src/renderers/overlay/index.ts +0 -18
- package/src/renderers/overlay/menubar.tsx +0 -76
- package/src/renderers/overlay/popover.tsx +0 -56
- package/src/renderers/overlay/sheet.tsx +0 -77
- package/src/renderers/overlay/tooltip.tsx +0 -67
- package/src/renderers/placeholders.tsx +0 -107
- package/src/stories/CRMApp.stories.tsx +0 -706
- package/src/stories/ConfigPanel.stories.tsx +0 -232
- package/src/stories/Guide.mdx +0 -55
- package/src/stories/MockedData.stories.tsx +0 -121
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -1
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +0 -1
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -1
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +0 -1
- package/src/stories/assets/youtube.svg +0 -1
- package/src/stories/button.css +0 -30
- package/src/stories/header.css +0 -32
- package/src/stories/page.css +0 -68
- package/src/stories-json/Accessibility.mdx +0 -297
- package/src/stories-json/EdgeCases.stories.tsx +0 -160
- package/src/stories-json/GettingStarted.mdx +0 -89
- package/src/stories-json/Introduction.mdx +0 -127
- package/src/stories-json/accordion.stories.tsx +0 -43
- package/src/stories-json/aggrid.stories.tsx +0 -103
- package/src/stories-json/alert.stories.tsx +0 -39
- package/src/stories-json/aspect-ratio.stories.tsx +0 -34
- package/src/stories-json/avatar.stories.tsx +0 -38
- package/src/stories-json/badge.stories.tsx +0 -53
- package/src/stories-json/breadcrumb.stories.tsx +0 -30
- package/src/stories-json/button-group.stories.tsx +0 -43
- package/src/stories-json/button.stories.tsx +0 -73
- package/src/stories-json/calendar.stories.tsx +0 -85
- package/src/stories-json/card.stories.tsx +0 -48
- package/src/stories-json/carousel.stories.tsx +0 -33
- package/src/stories-json/charts.stories.tsx +0 -195
- package/src/stories-json/chatbot.stories.tsx +0 -349
- package/src/stories-json/code-editor.stories.tsx +0 -92
- package/src/stories-json/collapsible.stories.tsx +0 -40
- package/src/stories-json/controls.stories.tsx +0 -36
- package/src/stories-json/crm-live-data.stories.tsx +0 -154
- package/src/stories-json/dashboard.stories.tsx +0 -318
- package/src/stories-json/data-table.stories.tsx +0 -136
- package/src/stories-json/data_display_extras.stories.tsx +0 -102
- package/src/stories-json/date-picker.stories.tsx +0 -28
- package/src/stories-json/detail-view.stories.tsx +0 -258
- package/src/stories-json/dialog.stories.tsx +0 -43
- package/src/stories-json/feedback_extras.stories.tsx +0 -40
- package/src/stories-json/feedback_others.stories.tsx +0 -46
- package/src/stories-json/form-variants.stories.tsx +0 -210
- package/src/stories-json/form_advanced.stories.tsx +0 -117
- package/src/stories-json/form_extras.stories.tsx +0 -123
- package/src/stories-json/grid.stories.tsx +0 -56
- package/src/stories-json/icon.stories.tsx +0 -36
- package/src/stories-json/input.stories.tsx +0 -52
- package/src/stories-json/kanban.stories.tsx +0 -295
- package/src/stories-json/layout_extended.stories.tsx +0 -76
- package/src/stories-json/layout_flex.stories.tsx +0 -107
- package/src/stories-json/list-view.stories.tsx +0 -97
- package/src/stories-json/markdown.stories.tsx +0 -129
- package/src/stories-json/menus.stories.tsx +0 -63
- package/src/stories-json/metric-card.stories.tsx +0 -143
- package/src/stories-json/navigation-menu.stories.tsx +0 -37
- package/src/stories-json/object-aggrid-advanced.stories.tsx +0 -389
- package/src/stories-json/object-aggrid.stories.tsx +0 -252
- package/src/stories-json/object-form.stories.tsx +0 -130
- package/src/stories-json/object-gantt.stories.tsx +0 -114
- package/src/stories-json/object-grid.stories.tsx +0 -315
- package/src/stories-json/object-map.stories.tsx +0 -116
- package/src/stories-json/object-view.stories.tsx +0 -118
- package/src/stories-json/overlay_extras.stories.tsx +0 -113
- package/src/stories-json/overlay_others.stories.tsx +0 -76
- package/src/stories-json/page.stories.tsx +0 -55
- package/src/stories-json/reports.stories.tsx +0 -163
- package/src/stories-json/resizable.stories.tsx +0 -44
- package/src/stories-json/select.stories.tsx +0 -34
- package/src/stories-json/separator.stories.tsx +0 -41
- package/src/stories-json/sidebar.stories.tsx +0 -147
- package/src/stories-json/statistic.stories.tsx +0 -44
- package/src/stories-json/tabs.stories.tsx +0 -51
- package/src/stories-json/timeline.stories.tsx +0 -188
- package/src/stories-json/typography.stories.tsx +0 -45
- package/src/types/config-panel.ts +0 -101
- package/src/ui/accordion.tsx +0 -66
- package/src/ui/alert-dialog.tsx +0 -149
- package/src/ui/alert.tsx +0 -67
- package/src/ui/aspect-ratio.tsx +0 -15
- package/src/ui/avatar.tsx +0 -58
- package/src/ui/badge.tsx +0 -44
- package/src/ui/breadcrumb.tsx +0 -123
- package/src/ui/button.tsx +0 -64
- package/src/ui/calendar.tsx +0 -221
- package/src/ui/card.tsx +0 -87
- package/src/ui/carousel.tsx +0 -270
- package/src/ui/chart.tsx +0 -377
- package/src/ui/checkbox.tsx +0 -38
- package/src/ui/collapsible.tsx +0 -19
- package/src/ui/command.tsx +0 -161
- package/src/ui/context-menu.tsx +0 -208
- package/src/ui/dialog.tsx +0 -130
- package/src/ui/drawer.tsx +0 -126
- package/src/ui/dropdown-menu.tsx +0 -208
- package/src/ui/form.tsx +0 -186
- package/src/ui/hover-card.tsx +0 -37
- package/src/ui/index.ts +0 -56
- package/src/ui/input-otp.tsx +0 -79
- package/src/ui/input.tsx +0 -30
- package/src/ui/label.tsx +0 -34
- package/src/ui/menubar.tsx +0 -264
- package/src/ui/navigation-menu.tsx +0 -136
- package/src/ui/pagination.tsx +0 -125
- package/src/ui/popover.tsx +0 -39
- package/src/ui/progress.tsx +0 -36
- package/src/ui/radio-group.tsx +0 -52
- package/src/ui/resizable.tsx +0 -53
- package/src/ui/scroll-area.tsx +0 -56
- package/src/ui/select.tsx +0 -168
- package/src/ui/separator.tsx +0 -39
- package/src/ui/sheet.tsx +0 -150
- package/src/ui/sidebar.tsx +0 -781
- package/src/ui/skeleton.tsx +0 -23
- package/src/ui/slider.tsx +0 -39
- package/src/ui/sonner.tsx +0 -53
- package/src/ui/switch.tsx +0 -37
- package/src/ui/table.tsx +0 -125
- package/src/ui/tabs.tsx +0 -63
- package/src/ui/textarea.tsx +0 -30
- package/src/ui/toast.tsx +0 -137
- package/src/ui/toggle-group.tsx +0 -69
- package/src/ui/toggle.tsx +0 -53
- package/src/ui/tooltip.tsx +0 -38
- package/src/ui/typography.tsx +0 -85
- package/tsconfig.json +0 -19
- package/vite.config.ts +0 -71
- package/vitest.config.ts +0 -5
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
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
|
-
});
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
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
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
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';
|
|
19
|
-
import './action-bar';
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { 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
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { ComponentRegistry } from '@object-ui/core';
|
|
10
|
-
import type { ButtonGroupSchema } from '@object-ui/types';
|
|
11
|
-
import { Button } from '../../ui';
|
|
12
|
-
import { cn } from '../../lib/utils';
|
|
13
|
-
|
|
14
|
-
ComponentRegistry.register('button-group',
|
|
15
|
-
({ schema, ...props }: { schema: ButtonGroupSchema; [key: string]: any }) => {
|
|
16
|
-
const {
|
|
17
|
-
'data-obj-id': dataObjId,
|
|
18
|
-
'data-obj-type': dataObjType,
|
|
19
|
-
style,
|
|
20
|
-
...buttonGroupProps
|
|
21
|
-
} = props;
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<div
|
|
25
|
-
className={cn('flex flex-wrap sm:inline-flex rounded-md shadow-sm', schema.className)}
|
|
26
|
-
role="group"
|
|
27
|
-
{...buttonGroupProps}
|
|
28
|
-
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
29
|
-
>
|
|
30
|
-
{schema.buttons?.map((button, idx) => (
|
|
31
|
-
<Button
|
|
32
|
-
key={idx}
|
|
33
|
-
variant={button.variant || schema.variant}
|
|
34
|
-
size={button.size || schema.size}
|
|
35
|
-
className={cn(
|
|
36
|
-
'rounded-none',
|
|
37
|
-
idx === 0 && 'rounded-l-md',
|
|
38
|
-
idx === (schema.buttons?.length || 0) - 1 && 'rounded-r-md',
|
|
39
|
-
idx > 0 && '-ml-px',
|
|
40
|
-
button.className
|
|
41
|
-
)}
|
|
42
|
-
>
|
|
43
|
-
{button.label}
|
|
44
|
-
</Button>
|
|
45
|
-
))}
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
namespace: 'ui',
|
|
51
|
-
label: 'Button Group',
|
|
52
|
-
inputs: [
|
|
53
|
-
{
|
|
54
|
-
name: 'variant',
|
|
55
|
-
type: 'enum',
|
|
56
|
-
enum: ['default', 'destructive', 'outline', 'secondary', 'ghost', 'link'],
|
|
57
|
-
defaultValue: 'default',
|
|
58
|
-
label: 'Variant'
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: 'size',
|
|
62
|
-
type: 'enum',
|
|
63
|
-
enum: ['default', 'sm', 'lg', 'icon'],
|
|
64
|
-
defaultValue: 'default',
|
|
65
|
-
label: 'Size'
|
|
66
|
-
},
|
|
67
|
-
{ name: 'className', type: 'string', label: 'CSS Class' }
|
|
68
|
-
],
|
|
69
|
-
defaultProps: {
|
|
70
|
-
variant: 'default',
|
|
71
|
-
size: 'default',
|
|
72
|
-
buttons: [
|
|
73
|
-
{ label: 'Left' },
|
|
74
|
-
{ label: 'Middle' },
|
|
75
|
-
{ label: 'Right' }
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { ComponentRegistry } from '@object-ui/core';
|
|
10
|
-
import type { DivSchema } from '@object-ui/types';
|
|
11
|
-
import { renderChildren } from '../../lib/utils';
|
|
12
|
-
import { forwardRef } from 'react';
|
|
13
|
-
|
|
14
|
-
const DivRenderer = forwardRef<HTMLDivElement, { schema: DivSchema; className?: string; [key: string]: any }>(
|
|
15
|
-
({ schema, className, ...props }, ref) => {
|
|
16
|
-
// Deprecation warning
|
|
17
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
18
|
-
console.warn(
|
|
19
|
-
'[ObjectUI] The "div" component is deprecated. Please use Shadcn components instead:\n' +
|
|
20
|
-
' - For containers: use "card", "flex", or semantic layout components\n' +
|
|
21
|
-
' - For simple wrappers: use layout components like "container", "stack", or "grid"\n' +
|
|
22
|
-
'See documentation at https://www.objectui.org/docs/components for alternatives.'
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Extract designer-related props
|
|
27
|
-
const {
|
|
28
|
-
'data-obj-id': dataObjId,
|
|
29
|
-
'data-obj-type': dataObjType,
|
|
30
|
-
style,
|
|
31
|
-
...divProps
|
|
32
|
-
} = props;
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<div
|
|
36
|
-
ref={ref}
|
|
37
|
-
className={className}
|
|
38
|
-
{...divProps}
|
|
39
|
-
// Apply designer props
|
|
40
|
-
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
41
|
-
>
|
|
42
|
-
{renderChildren(schema.children || schema.body)}
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
ComponentRegistry.register('div',
|
|
49
|
-
DivRenderer,
|
|
50
|
-
{
|
|
51
|
-
namespace: 'ui',
|
|
52
|
-
label: 'Container (Deprecated)',
|
|
53
|
-
inputs: [
|
|
54
|
-
{ name: 'className', type: 'string', label: 'CSS Class' }
|
|
55
|
-
],
|
|
56
|
-
defaultProps: {
|
|
57
|
-
className: 'p-2 sm:p-4 border border-dashed border-gray-300 rounded min-h-[100px]'
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
);
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import React from 'react';
|
|
10
|
-
import { ComponentRegistry } from '@object-ui/core';
|
|
11
|
-
import type { HtmlSchema } from '@object-ui/types';
|
|
12
|
-
import { cn } from '../../lib/utils';
|
|
13
|
-
|
|
14
|
-
ComponentRegistry.register('html',
|
|
15
|
-
({ schema, className, ...props }: { schema: HtmlSchema; className?: string; [key: string]: any }) => {
|
|
16
|
-
// Extract designer-related props
|
|
17
|
-
const {
|
|
18
|
-
'data-obj-id': dataObjId,
|
|
19
|
-
'data-obj-type': dataObjType,
|
|
20
|
-
style,
|
|
21
|
-
...htmlProps
|
|
22
|
-
} = props;
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<div
|
|
26
|
-
className={cn("prose prose-sm max-w-none dark:prose-invert", className)}
|
|
27
|
-
dangerouslySetInnerHTML={{ __html: schema.html }}
|
|
28
|
-
{...htmlProps}
|
|
29
|
-
// Apply designer props
|
|
30
|
-
data-obj-id={dataObjId}
|
|
31
|
-
data-obj-type={dataObjType}
|
|
32
|
-
style={style}
|
|
33
|
-
/>
|
|
34
|
-
);
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
namespace: 'ui',
|
|
38
|
-
label: 'HTML Content',
|
|
39
|
-
inputs: [
|
|
40
|
-
{ name: 'html', type: 'string', label: 'HTML', description: 'Raw HTML content' }
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
);
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { ComponentRegistry } from '@object-ui/core';
|
|
10
|
-
import type { IconSchema } from '@object-ui/types';
|
|
11
|
-
import { icons } from 'lucide-react';
|
|
12
|
-
import React, { forwardRef } from 'react';
|
|
13
|
-
import { cn } from '../../lib/utils';
|
|
14
|
-
|
|
15
|
-
// Convert kebab-case to PascalCase for Lucide icon names
|
|
16
|
-
// e.g., "arrow-right" -> "ArrowRight", "home" -> "Home"
|
|
17
|
-
function toPascalCase(str: string): string {
|
|
18
|
-
return str
|
|
19
|
-
.split('-')
|
|
20
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
21
|
-
.join('');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Map of renamed icons in lucide-react (from old name to new name)
|
|
25
|
-
const iconNameMap: Record<string, string> = {
|
|
26
|
-
'Home': 'House', // "Home" was renamed to "House" in lucide-react's icons object
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const IconRenderer = forwardRef<SVGSVGElement, { schema: IconSchema; className?: string; [key: string]: any }>(
|
|
30
|
-
({ schema, className, ...props }, ref) => {
|
|
31
|
-
// Extract designer-related props
|
|
32
|
-
const {
|
|
33
|
-
'data-obj-id': dataObjId,
|
|
34
|
-
'data-obj-type': dataObjType,
|
|
35
|
-
style,
|
|
36
|
-
...iconProps
|
|
37
|
-
} = props;
|
|
38
|
-
|
|
39
|
-
// Convert icon name to PascalCase for Lucide lookup
|
|
40
|
-
const iconName = toPascalCase(schema.name);
|
|
41
|
-
// Apply icon name mapping for renamed icons
|
|
42
|
-
const mappedIconName = iconNameMap[iconName] || iconName;
|
|
43
|
-
const Icon = (icons as any)[mappedIconName];
|
|
44
|
-
|
|
45
|
-
if (!Icon) {
|
|
46
|
-
console.warn(`Icon "${schema.name}" (lookup: "${iconName}"${mappedIconName !== iconName ? ` -> "${mappedIconName}"` : ''}) not found in lucide-react`);
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Build size style
|
|
51
|
-
const sizeStyle = schema.size ? { width: schema.size, height: schema.size } : undefined;
|
|
52
|
-
|
|
53
|
-
// Merge classNames: schema color, schema className, prop className
|
|
54
|
-
const mergedClassName = cn(
|
|
55
|
-
schema.color,
|
|
56
|
-
schema.className,
|
|
57
|
-
className
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<Icon
|
|
62
|
-
ref={ref}
|
|
63
|
-
className={mergedClassName}
|
|
64
|
-
style={{ ...sizeStyle, ...style }}
|
|
65
|
-
{...iconProps}
|
|
66
|
-
// Apply designer props
|
|
67
|
-
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType }}
|
|
68
|
-
/>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
IconRenderer.displayName = 'IconRenderer';
|
|
74
|
-
|
|
75
|
-
ComponentRegistry.register('icon',
|
|
76
|
-
IconRenderer,
|
|
77
|
-
{
|
|
78
|
-
namespace: 'ui',
|
|
79
|
-
label: 'Icon',
|
|
80
|
-
icon: 'smile',
|
|
81
|
-
category: 'basic',
|
|
82
|
-
inputs: [
|
|
83
|
-
{ name: 'name', type: 'string', label: 'Icon Name', defaultValue: 'smile' },
|
|
84
|
-
{ name: 'size', type: 'number', label: 'Size (px)' },
|
|
85
|
-
{ name: 'color', type: 'string', label: 'Color Class' },
|
|
86
|
-
{ name: 'className', type: 'string', label: 'CSS Class' }
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
);
|