@rangka/client 0.1.1 → 0.1.3
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/dist/App.d.ts.map +1 -1
- package/dist/App.js +7 -1
- package/dist/App.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +20 -0
- package/dist/main.js.map +1 -1
- package/dist/shell/assets/index-63v1sBS3.css +1 -0
- package/dist/shell/assets/index-Dh7K40cQ.js +8634 -0
- package/dist/shell/assets/vendor-query-B2cydN5j.js +1 -0
- package/dist/shell/assets/vendor-radix-BJxYPxPb.js +69 -0
- package/dist/shell/assets/vendor-router-ET_myMt5.js +17 -0
- package/dist/shell/index.html +5 -2
- package/dist/theme.css +82 -0
- package/dist/widgets/components/lazy-manifest.d.ts +11 -0
- package/dist/widgets/components/lazy-manifest.d.ts.map +1 -0
- package/dist/widgets/components/lazy-manifest.js +32 -0
- package/dist/widgets/components/lazy-manifest.js.map +1 -0
- package/dist/widgets/components/register.js +12 -12
- package/dist/widgets/components/register.js.map +1 -1
- package/dist/widgets/loader.d.ts +3 -0
- package/dist/widgets/loader.d.ts.map +1 -0
- package/dist/widgets/loader.js +73 -0
- package/dist/widgets/loader.js.map +1 -0
- package/dist/widgets/renderer/LazyWidget.d.ts +8 -0
- package/dist/widgets/renderer/LazyWidget.d.ts.map +1 -0
- package/dist/widgets/renderer/LazyWidget.js +31 -0
- package/dist/widgets/renderer/LazyWidget.js.map +1 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.d.ts +17 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.d.ts.map +1 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.js +18 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.js.map +1 -0
- package/dist/widgets/renderer/WidgetRenderer.d.ts.map +1 -1
- package/dist/widgets/renderer/WidgetRenderer.js +8 -6
- package/dist/widgets/renderer/WidgetRenderer.js.map +1 -1
- package/package.json +7 -4
- package/.claude/skills/add-widget/SKILL.md +0 -101
- package/.turbo/turbo-build.log +0 -29
- package/CHANGELOG.md +0 -25
- package/CLAUDE.md +0 -236
- package/components.json +0 -25
- package/dist/components/ui/chart.d.ts +0 -45
- package/dist/components/ui/chart.d.ts.map +0 -1
- package/dist/components/ui/chart.js +0 -119
- package/dist/components/ui/chart.js.map +0 -1
- package/dist/shell/assets/index--35CAvcP.js +0 -8715
- package/dist/shell/assets/index-COLmoPYo.css +0 -1
- package/index.html +0 -12
- package/src/App.tsx +0 -44
- package/src/__tests__/setup.ts +0 -1
- package/src/api/auth.ts +0 -41
- package/src/api/boot.ts +0 -10
- package/src/api/client.ts +0 -26
- package/src/api/paths.ts +0 -3
- package/src/api/token.ts +0 -13
- package/src/auth/LoginForm.tsx +0 -67
- package/src/auth/SessionExpired.tsx +0 -24
- package/src/auth/SetupForm.tsx +0 -76
- package/src/boot/BootGate.tsx +0 -35
- package/src/boot/BootProvider.tsx +0 -28
- package/src/boot/types.ts +0 -9
- package/src/boot/useBoot.ts +0 -111
- package/src/components/Icon.tsx +0 -17
- package/src/components/ui/accordion.tsx +0 -82
- package/src/components/ui/alert-dialog.tsx +0 -180
- package/src/components/ui/alert.tsx +0 -76
- package/src/components/ui/aspect-ratio.tsx +0 -9
- package/src/components/ui/avatar.tsx +0 -94
- package/src/components/ui/badge.tsx +0 -45
- package/src/components/ui/breadcrumb.tsx +0 -104
- package/src/components/ui/button-group.tsx +0 -78
- package/src/components/ui/button.tsx +0 -65
- package/src/components/ui/calendar.tsx +0 -187
- package/src/components/ui/card.tsx +0 -85
- package/src/components/ui/carousel.tsx +0 -229
- package/src/components/ui/chart.tsx +0 -339
- package/src/components/ui/checkbox.tsx +0 -27
- package/src/components/ui/collapsible.tsx +0 -21
- package/src/components/ui/combobox.tsx +0 -275
- package/src/components/ui/command.tsx +0 -178
- package/src/components/ui/context-menu.tsx +0 -242
- package/src/components/ui/dialog.tsx +0 -146
- package/src/components/ui/direction.tsx +0 -20
- package/src/components/ui/drawer.tsx +0 -118
- package/src/components/ui/dropdown-menu.tsx +0 -247
- package/src/components/ui/empty.tsx +0 -94
- package/src/components/ui/field.tsx +0 -224
- package/src/components/ui/hover-card.tsx +0 -36
- package/src/components/ui/input-group.tsx +0 -142
- package/src/components/ui/input-otp.tsx +0 -86
- package/src/components/ui/input.tsx +0 -19
- package/src/components/ui/item.tsx +0 -182
- package/src/components/ui/kbd.tsx +0 -26
- package/src/components/ui/label.tsx +0 -19
- package/src/components/ui/menubar.tsx +0 -260
- package/src/components/ui/native-select.tsx +0 -55
- package/src/components/ui/navigation-menu.tsx +0 -160
- package/src/components/ui/pagination.tsx +0 -112
- package/src/components/ui/popover.tsx +0 -74
- package/src/components/ui/progress.tsx +0 -31
- package/src/components/ui/radio-group.tsx +0 -42
- package/src/components/ui/resizable.tsx +0 -42
- package/src/components/ui/scroll-area.tsx +0 -53
- package/src/components/ui/select.tsx +0 -185
- package/src/components/ui/separator.tsx +0 -26
- package/src/components/ui/sheet.tsx +0 -128
- package/src/components/ui/sidebar.tsx +0 -669
- package/src/components/ui/skeleton.tsx +0 -13
- package/src/components/ui/slider.tsx +0 -54
- package/src/components/ui/sonner.tsx +0 -43
- package/src/components/ui/spinner.tsx +0 -16
- package/src/components/ui/switch.tsx +0 -33
- package/src/components/ui/table.tsx +0 -87
- package/src/components/ui/tabs.tsx +0 -80
- package/src/components/ui/textarea.tsx +0 -18
- package/src/components/ui/toggle-group.tsx +0 -86
- package/src/components/ui/toggle.tsx +0 -44
- package/src/components/ui/tooltip.tsx +0 -53
- package/src/context/MetaContext.tsx +0 -22
- package/src/context/ModuleContext.tsx +0 -62
- package/src/context/PermissionsContext.tsx +0 -39
- package/src/context/ShellProviders.tsx +0 -33
- package/src/context/UserContext.tsx +0 -16
- package/src/data/QueryProvider.tsx +0 -7
- package/src/data/queryClient.ts +0 -18
- package/src/data/useModelMeta.ts +0 -17
- package/src/data/useMutation.ts +0 -60
- package/src/data/useRecord.ts +0 -29
- package/src/data/useSource.ts +0 -112
- package/src/hooks/use-mobile.ts +0 -19
- package/src/index.css +0 -260
- package/src/index.ts +0 -16
- package/src/lib/utils.ts +0 -6
- package/src/main.tsx +0 -17
- package/src/router/NotFound.tsx +0 -8
- package/src/router/RouterProvider.tsx +0 -7
- package/src/router/buildRouteTree.tsx +0 -63
- package/src/router/createShellRouter.ts +0 -9
- package/src/router/hooks.ts +0 -43
- package/src/shell/CommandPalette.tsx +0 -76
- package/src/shell/ConfirmDialog.tsx +0 -34
- package/src/shell/ConfirmProvider.tsx +0 -56
- package/src/shell/DrawerContext.tsx +0 -44
- package/src/shell/HeaderActions.tsx +0 -31
- package/src/shell/ModuleSelectorPage.tsx +0 -149
- package/src/shell/PageOutlet.tsx +0 -21
- package/src/shell/ShellContext.tsx +0 -45
- package/src/shell/ShellDevTools.tsx +0 -153
- package/src/shell/ShellLayout.tsx +0 -231
- package/src/shell/Toast.tsx +0 -58
- package/src/shell/ToastProvider.tsx +0 -60
- package/src/shell/app-sidebar/AppSidebar.tsx +0 -44
- package/src/shell/app-sidebar/ModuleSwitcher.tsx +0 -87
- package/src/shell/app-sidebar/NavMain.tsx +0 -64
- package/src/shell/app-sidebar/NavUser.tsx +0 -97
- package/src/shell/app-sidebar/SearchMenu.tsx +0 -22
- package/src/shell/app-sidebar/index.ts +0 -8
- package/src/shell/app-sidebar/types.ts +0 -38
- package/src/shell/types.ts +0 -6
- package/src/shell/useBreadcrumbs.ts +0 -42
- package/src/studio/bridge.ts +0 -125
- package/src/studio/index.ts +0 -3
- package/src/studio/overlay.ts +0 -47
- package/src/studio/types.ts +0 -32
- package/src/studio/walker.ts +0 -48
- package/src/vite-env.d.ts +0 -1
- package/src/widgets/__tests__/action-edge-cases.test.ts +0 -281
- package/src/widgets/__tests__/action.test.ts +0 -236
- package/src/widgets/__tests__/attachment-widget.test.tsx +0 -85
- package/src/widgets/__tests__/attachments-widget.test.tsx +0 -109
- package/src/widgets/__tests__/binding.test.ts +0 -76
- package/src/widgets/__tests__/button-widget.test.tsx +0 -145
- package/src/widgets/__tests__/checkbox-widget.test.tsx +0 -158
- package/src/widgets/__tests__/code-widget.test.tsx +0 -64
- package/src/widgets/__tests__/computed-widget.test.tsx +0 -62
- package/src/widgets/__tests__/condition-edge-cases.test.ts +0 -120
- package/src/widgets/__tests__/condition.test.ts +0 -221
- package/src/widgets/__tests__/context.test.ts +0 -99
- package/src/widgets/__tests__/data-widget.test.tsx +0 -204
- package/src/widgets/__tests__/datepicker-widget.test.tsx +0 -66
- package/src/widgets/__tests__/datetime-widget.test.tsx +0 -67
- package/src/widgets/__tests__/drawer-widget.test.tsx +0 -149
- package/src/widgets/__tests__/dynamic-link-widget.test.tsx +0 -52
- package/src/widgets/__tests__/edge-cases.test.ts +0 -232
- package/src/widgets/__tests__/evaluator.test.ts +0 -107
- package/src/widgets/__tests__/functions.test.ts +0 -147
- package/src/widgets/__tests__/grid-widget.test.tsx +0 -137
- package/src/widgets/__tests__/hooks.test.tsx +0 -249
- package/src/widgets/__tests__/icon-widget.test.tsx +0 -129
- package/src/widgets/__tests__/input-widget.test.tsx +0 -264
- package/src/widgets/__tests__/integration.test.ts +0 -116
- package/src/widgets/__tests__/json-widget.test.tsx +0 -70
- package/src/widgets/__tests__/link-widget.test.tsx +0 -92
- package/src/widgets/__tests__/many-to-many-widget.test.tsx +0 -93
- package/src/widgets/__tests__/modal-widget.test.tsx +0 -148
- package/src/widgets/__tests__/money-widget.test.tsx +0 -97
- package/src/widgets/__tests__/parser.test.ts +0 -171
- package/src/widgets/__tests__/reactive-variables.test.ts +0 -383
- package/src/widgets/__tests__/renderer.test.tsx +0 -300
- package/src/widgets/__tests__/repeat-widget.test.tsx +0 -229
- package/src/widgets/__tests__/select-widget.test.tsx +0 -231
- package/src/widgets/__tests__/sequence-widget.test.tsx +0 -58
- package/src/widgets/__tests__/shell-integration.test.tsx +0 -1343
- package/src/widgets/__tests__/split-widget.test.tsx +0 -133
- package/src/widgets/__tests__/state-edge-cases.test.ts +0 -118
- package/src/widgets/__tests__/state.test.ts +0 -106
- package/src/widgets/__tests__/table-data-binding.test.tsx +0 -482
- package/src/widgets/__tests__/table-filter-popover.test.tsx +0 -486
- package/src/widgets/__tests__/table-search.test.tsx +0 -305
- package/src/widgets/__tests__/table-widget.test.tsx +0 -509
- package/src/widgets/__tests__/textarea-widget.test.tsx +0 -105
- package/src/widgets/__tests__/tracker-validator-edge-cases.test.ts +0 -242
- package/src/widgets/__tests__/tracker.test.ts +0 -133
- package/src/widgets/__tests__/tree-widget.test.tsx +0 -97
- package/src/widgets/__tests__/use-model-source.test.ts +0 -67
- package/src/widgets/__tests__/validator.test.ts +0 -208
- package/src/widgets/action/dispatcher.ts +0 -334
- package/src/widgets/action/index.ts +0 -2
- package/src/widgets/binding/index.ts +0 -2
- package/src/widgets/binding/resolver.ts +0 -61
- package/src/widgets/components/AttachmentWidget.tsx +0 -111
- package/src/widgets/components/AttachmentsWidget.tsx +0 -121
- package/src/widgets/components/BadgeWidget.tsx +0 -35
- package/src/widgets/components/ButtonWidget.tsx +0 -43
- package/src/widgets/components/CardWidget.tsx +0 -68
- package/src/widgets/components/CheckboxWidget.tsx +0 -39
- package/src/widgets/components/CodeWidget.tsx +0 -44
- package/src/widgets/components/ColumnWidget.tsx +0 -22
- package/src/widgets/components/ComputedWidget.tsx +0 -49
- package/src/widgets/components/DataWidget.tsx +0 -189
- package/src/widgets/components/DatePickerWidget.tsx +0 -73
- package/src/widgets/components/DatetimeWidget.tsx +0 -160
- package/src/widgets/components/DividerWidget.tsx +0 -37
- package/src/widgets/components/DrawerWidget.tsx +0 -52
- package/src/widgets/components/DynamicLinkWidget.tsx +0 -130
- package/src/widgets/components/GridWidget.tsx +0 -134
- package/src/widgets/components/GroupWidget.tsx +0 -111
- package/src/widgets/components/IconWidget.tsx +0 -29
- package/src/widgets/components/ImageWidget.tsx +0 -28
- package/src/widgets/components/InputWidget.tsx +0 -70
- package/src/widgets/components/JsonWidget.tsx +0 -78
- package/src/widgets/components/LinkWidget.tsx +0 -99
- package/src/widgets/components/ManyToManyWidget.tsx +0 -125
- package/src/widgets/components/ModalWidget.tsx +0 -52
- package/src/widgets/components/MoneyWidget.tsx +0 -80
- package/src/widgets/components/RepeatWidget.tsx +0 -66
- package/src/widgets/components/ScrollAreaWidget.tsx +0 -40
- package/src/widgets/components/SectionWidget.tsx +0 -78
- package/src/widgets/components/SelectWidget.tsx +0 -63
- package/src/widgets/components/SequenceWidget.tsx +0 -32
- package/src/widgets/components/SpacerWidget.tsx +0 -29
- package/src/widgets/components/SplitWidget.tsx +0 -60
- package/src/widgets/components/StackWidget.tsx +0 -44
- package/src/widgets/components/TableWidget.tsx +0 -366
- package/src/widgets/components/TextWidget.tsx +0 -44
- package/src/widgets/components/TextareaWidget.tsx +0 -49
- package/src/widgets/components/TreeWidget.tsx +0 -109
- package/src/widgets/components/index.ts +0 -30
- package/src/widgets/components/register.ts +0 -93
- package/src/widgets/components/table/CellRenderers.tsx +0 -83
- package/src/widgets/components/table/TablePagination.tsx +0 -45
- package/src/widgets/components/table/TableToolbar.tsx +0 -285
- package/src/widgets/components/table/filter-operators.ts +0 -134
- package/src/widgets/components/table/index.ts +0 -11
- package/src/widgets/condition/evaluator.ts +0 -57
- package/src/widgets/condition/index.ts +0 -1
- package/src/widgets/context/builder.ts +0 -99
- package/src/widgets/context/index.ts +0 -8
- package/src/widgets/context/types.ts +0 -37
- package/src/widgets/data/index.ts +0 -5
- package/src/widgets/data/useModelQuery.ts +0 -116
- package/src/widgets/data/useModelRecord.ts +0 -37
- package/src/widgets/expression/evaluator.ts +0 -100
- package/src/widgets/expression/functions.ts +0 -131
- package/src/widgets/expression/index.ts +0 -13
- package/src/widgets/expression/parser.ts +0 -229
- package/src/widgets/expression/types.ts +0 -45
- package/src/widgets/form/FormContext.ts +0 -29
- package/src/widgets/form/FormProvider.tsx +0 -84
- package/src/widgets/form/FormWidget.tsx +0 -42
- package/src/widgets/form/index.ts +0 -4
- package/src/widgets/form/useFormState.ts +0 -127
- package/src/widgets/form/useFormSubmit.ts +0 -90
- package/src/widgets/form/useFormValidation.ts +0 -62
- package/src/widgets/hooks/index.ts +0 -8
- package/src/widgets/hooks/useAction.ts +0 -83
- package/src/widgets/hooks/useBind.ts +0 -34
- package/src/widgets/hooks/useCondition.ts +0 -21
- package/src/widgets/hooks/useDataQuery.ts +0 -48
- package/src/widgets/hooks/useExpression.ts +0 -14
- package/src/widgets/hooks/usePageState.ts +0 -21
- package/src/widgets/hooks/useSurfaceContext.ts +0 -11
- package/src/widgets/hooks/useWidgetContext.ts +0 -14
- package/src/widgets/index.ts +0 -80
- package/src/widgets/lib/layout-props.ts +0 -135
- package/src/widgets/reactivity/index.ts +0 -11
- package/src/widgets/reactivity/tracker.ts +0 -139
- package/src/widgets/reactivity/variables.ts +0 -213
- package/src/widgets/registry.ts +0 -41
- package/src/widgets/renderer/SlotRenderer.tsx +0 -47
- package/src/widgets/renderer/WidgetRenderer.tsx +0 -191
- package/src/widgets/renderer/index.ts +0 -4
- package/src/widgets/shell/WidgetSlotRenderer.tsx +0 -73
- package/src/widgets/shell/index.ts +0 -4
- package/src/widgets/shell/useActionHandlers.ts +0 -170
- package/src/widgets/state/index.ts +0 -2
- package/src/widgets/state/store.ts +0 -96
- package/src/widgets/types.ts +0 -28
- package/src/widgets/validation/index.ts +0 -2
- package/src/widgets/validation/validator.ts +0 -140
- package/tsconfig.json +0 -27
- package/tsconfig.tsbuildinfo +0 -1
- package/vite.config.ts +0 -21
- package/vitest.config.ts +0 -16
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { cn } from '@/lib/utils';
|
|
3
|
-
import type { SpacingToken } from '@rangka/shared';
|
|
4
|
-
import type { WidgetProps } from '../types.js';
|
|
5
|
-
|
|
6
|
-
const gapMap: Record<SpacingToken, string> = {
|
|
7
|
-
none: 'gap-0',
|
|
8
|
-
xs: 'gap-1',
|
|
9
|
-
sm: 'gap-2',
|
|
10
|
-
md: 'gap-4',
|
|
11
|
-
lg: 'gap-6',
|
|
12
|
-
xl: 'gap-8',
|
|
13
|
-
'2xl': 'gap-12',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const paddingMap: Record<SpacingToken, string> = {
|
|
17
|
-
none: 'p-0',
|
|
18
|
-
xs: 'p-1',
|
|
19
|
-
sm: 'p-2',
|
|
20
|
-
md: 'p-4',
|
|
21
|
-
lg: 'p-6',
|
|
22
|
-
xl: 'p-8',
|
|
23
|
-
'2xl': 'p-12',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const paddingXMap: Record<SpacingToken, string> = {
|
|
27
|
-
none: 'px-0',
|
|
28
|
-
xs: 'px-1',
|
|
29
|
-
sm: 'px-2',
|
|
30
|
-
md: 'px-4',
|
|
31
|
-
lg: 'px-6',
|
|
32
|
-
xl: 'px-8',
|
|
33
|
-
'2xl': 'px-12',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const paddingYMap: Record<SpacingToken, string> = {
|
|
37
|
-
none: 'py-0',
|
|
38
|
-
xs: 'py-1',
|
|
39
|
-
sm: 'py-2',
|
|
40
|
-
md: 'py-4',
|
|
41
|
-
lg: 'py-6',
|
|
42
|
-
xl: 'py-8',
|
|
43
|
-
'2xl': 'py-12',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const colsMap: Record<number, string> = {
|
|
47
|
-
1: 'grid-cols-1',
|
|
48
|
-
2: 'grid-cols-2',
|
|
49
|
-
3: 'grid-cols-3',
|
|
50
|
-
4: 'grid-cols-4',
|
|
51
|
-
5: 'grid-cols-5',
|
|
52
|
-
6: 'grid-cols-6',
|
|
53
|
-
7: 'grid-cols-7',
|
|
54
|
-
8: 'grid-cols-8',
|
|
55
|
-
9: 'grid-cols-9',
|
|
56
|
-
10: 'grid-cols-10',
|
|
57
|
-
11: 'grid-cols-11',
|
|
58
|
-
12: 'grid-cols-12',
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const autoFlowMap: Record<string, string> = {
|
|
62
|
-
row: 'grid-flow-row',
|
|
63
|
-
column: 'grid-flow-col',
|
|
64
|
-
dense: 'grid-flow-dense',
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export function GridWidget({ props, children }: WidgetProps) {
|
|
68
|
-
const columns = (props.columns as number) ?? 3;
|
|
69
|
-
const gap = (props.gap as SpacingToken) ?? 'md';
|
|
70
|
-
const rowGap = props.rowGap as SpacingToken | undefined;
|
|
71
|
-
const colGap = props.colGap as SpacingToken | undefined;
|
|
72
|
-
const autoFlow = props.autoFlow as string | undefined;
|
|
73
|
-
const padding = props.padding as SpacingToken | undefined;
|
|
74
|
-
const paddingX = props.paddingX as SpacingToken | undefined;
|
|
75
|
-
const paddingY = props.paddingY as SpacingToken | undefined;
|
|
76
|
-
const responsive = props.responsive as Record<string, number> | undefined;
|
|
77
|
-
|
|
78
|
-
const responsiveClasses: string[] = [];
|
|
79
|
-
if (responsive) {
|
|
80
|
-
if (responsive.sm) responsiveClasses.push(`max-sm:grid-cols-${responsive.sm}`);
|
|
81
|
-
if (responsive.md) responsiveClasses.push(`max-md:grid-cols-${responsive.md}`);
|
|
82
|
-
if (responsive.lg) responsiveClasses.push(`max-lg:grid-cols-${responsive.lg}`);
|
|
83
|
-
} else {
|
|
84
|
-
// Default responsive: collapse columns on smaller viewports
|
|
85
|
-
if (columns >= 3) {
|
|
86
|
-
responsiveClasses.push('max-md:grid-cols-2', 'max-sm:grid-cols-1');
|
|
87
|
-
} else if (columns === 2) {
|
|
88
|
-
responsiveClasses.push('max-sm:grid-cols-1');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<div
|
|
94
|
-
className={cn(
|
|
95
|
-
'grid',
|
|
96
|
-
colsMap[columns] ?? `grid-cols-[repeat(${columns},minmax(0,1fr))]`,
|
|
97
|
-
!rowGap && !colGap && gapMap[gap],
|
|
98
|
-
rowGap && `row-gap-${gapMap[rowGap]?.replace('gap-', '')}`,
|
|
99
|
-
colGap && `column-gap-${gapMap[colGap]?.replace('gap-', '')}`,
|
|
100
|
-
autoFlow && autoFlowMap[autoFlow],
|
|
101
|
-
padding && paddingMap[padding],
|
|
102
|
-
paddingX && paddingXMap[paddingX],
|
|
103
|
-
paddingY && paddingYMap[paddingY],
|
|
104
|
-
...responsiveClasses,
|
|
105
|
-
)}
|
|
106
|
-
>
|
|
107
|
-
{children}
|
|
108
|
-
</div>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
GridWidget.widgetMeta = {
|
|
113
|
-
name: 'grid',
|
|
114
|
-
label: 'Grid',
|
|
115
|
-
category: 'layout' as const,
|
|
116
|
-
schema: {
|
|
117
|
-
columns: { type: 'number' as const, default: 3 },
|
|
118
|
-
gap: {
|
|
119
|
-
type: 'enum' as const,
|
|
120
|
-
options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'],
|
|
121
|
-
default: 'md',
|
|
122
|
-
},
|
|
123
|
-
rowGap: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
124
|
-
colGap: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
125
|
-
autoFlow: { type: 'enum' as const, options: ['row', 'column', 'dense'], default: 'row' },
|
|
126
|
-
responsive: { type: 'object' as const },
|
|
127
|
-
padding: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
128
|
-
paddingX: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
129
|
-
paddingY: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
130
|
-
},
|
|
131
|
-
binding: 'none' as const,
|
|
132
|
-
triggers: [],
|
|
133
|
-
container: true,
|
|
134
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { cn } from '@/lib/utils';
|
|
3
|
-
import type { SpacingToken } from '@rangka/shared';
|
|
4
|
-
import type { WidgetProps } from '../types.js';
|
|
5
|
-
|
|
6
|
-
const gapMap: Record<SpacingToken, string> = {
|
|
7
|
-
none: 'gap-0',
|
|
8
|
-
xs: 'gap-1',
|
|
9
|
-
sm: 'gap-2',
|
|
10
|
-
md: 'gap-4',
|
|
11
|
-
lg: 'gap-6',
|
|
12
|
-
xl: 'gap-8',
|
|
13
|
-
'2xl': 'gap-12',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const paddingMap: Record<SpacingToken, string> = {
|
|
17
|
-
none: 'p-0',
|
|
18
|
-
xs: 'p-1',
|
|
19
|
-
sm: 'p-2',
|
|
20
|
-
md: 'p-4',
|
|
21
|
-
lg: 'p-6',
|
|
22
|
-
xl: 'p-8',
|
|
23
|
-
'2xl': 'p-12',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const paddingXMap: Record<SpacingToken, string> = {
|
|
27
|
-
none: 'px-0',
|
|
28
|
-
xs: 'px-1',
|
|
29
|
-
sm: 'px-2',
|
|
30
|
-
md: 'px-4',
|
|
31
|
-
lg: 'px-6',
|
|
32
|
-
xl: 'px-8',
|
|
33
|
-
'2xl': 'px-12',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const paddingYMap: Record<SpacingToken, string> = {
|
|
37
|
-
none: 'py-0',
|
|
38
|
-
xs: 'py-1',
|
|
39
|
-
sm: 'py-2',
|
|
40
|
-
md: 'py-4',
|
|
41
|
-
lg: 'py-6',
|
|
42
|
-
xl: 'py-8',
|
|
43
|
-
'2xl': 'py-12',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const alignMap: Record<string, string> = {
|
|
47
|
-
start: 'items-start',
|
|
48
|
-
center: 'items-center',
|
|
49
|
-
end: 'items-end',
|
|
50
|
-
stretch: 'items-stretch',
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const justifyMap: Record<string, string> = {
|
|
54
|
-
start: 'justify-start',
|
|
55
|
-
center: 'justify-center',
|
|
56
|
-
end: 'justify-end',
|
|
57
|
-
between: 'justify-between',
|
|
58
|
-
around: 'justify-around',
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export function GroupWidget({ props, children }: WidgetProps) {
|
|
62
|
-
const direction = (props.direction as 'row' | 'column') ?? 'column';
|
|
63
|
-
const gap = (props.gap as SpacingToken) ?? 'md';
|
|
64
|
-
const align = props.align as string | undefined;
|
|
65
|
-
const justify = props.justify as string | undefined;
|
|
66
|
-
const wrap = props.wrap as boolean | undefined;
|
|
67
|
-
const padding = props.padding as SpacingToken | undefined;
|
|
68
|
-
const paddingX = props.paddingX as SpacingToken | undefined;
|
|
69
|
-
const paddingY = props.paddingY as SpacingToken | undefined;
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<div
|
|
73
|
-
className={cn(
|
|
74
|
-
'flex',
|
|
75
|
-
direction === 'row' ? 'flex-row' : 'flex-col',
|
|
76
|
-
gapMap[gap],
|
|
77
|
-
align && alignMap[align],
|
|
78
|
-
justify && justifyMap[justify],
|
|
79
|
-
wrap && 'flex-wrap',
|
|
80
|
-
padding && paddingMap[padding],
|
|
81
|
-
paddingX && paddingXMap[paddingX],
|
|
82
|
-
paddingY && paddingYMap[paddingY],
|
|
83
|
-
)}
|
|
84
|
-
>
|
|
85
|
-
{children}
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
GroupWidget.widgetMeta = {
|
|
91
|
-
name: 'group',
|
|
92
|
-
label: 'Group',
|
|
93
|
-
category: 'layout' as const,
|
|
94
|
-
schema: {
|
|
95
|
-
direction: { type: 'enum' as const, options: ['row', 'column'], default: 'column' },
|
|
96
|
-
align: { type: 'enum' as const, options: ['start', 'center', 'end', 'stretch'] },
|
|
97
|
-
justify: { type: 'enum' as const, options: ['start', 'center', 'end', 'between', 'around'] },
|
|
98
|
-
gap: {
|
|
99
|
-
type: 'enum' as const,
|
|
100
|
-
options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'],
|
|
101
|
-
default: 'md',
|
|
102
|
-
},
|
|
103
|
-
wrap: { type: 'boolean' as const, default: false },
|
|
104
|
-
padding: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
105
|
-
paddingX: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
106
|
-
paddingY: { type: 'enum' as const, options: ['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'] },
|
|
107
|
-
},
|
|
108
|
-
binding: 'none' as const,
|
|
109
|
-
triggers: [],
|
|
110
|
-
container: true,
|
|
111
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Icon } from '@/components/Icon';
|
|
3
|
-
import type { WidgetProps } from '../types.js';
|
|
4
|
-
|
|
5
|
-
export function IconWidget({ props, on }: WidgetProps) {
|
|
6
|
-
const name = (props.name as string) ?? 'circle';
|
|
7
|
-
const size = props.size as number | undefined;
|
|
8
|
-
const color = props.color as string | undefined;
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<span onClick={on.click} className={on.click ? 'cursor-pointer' : undefined}>
|
|
12
|
-
<Icon name={name} size={size} color={color} />
|
|
13
|
-
</span>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
IconWidget.widgetMeta = {
|
|
18
|
-
name: 'icon',
|
|
19
|
-
label: 'Icon',
|
|
20
|
-
category: 'display' as const,
|
|
21
|
-
schema: {
|
|
22
|
-
name: { type: 'string' as const, required: true },
|
|
23
|
-
size: { type: 'number' as const, default: 14 },
|
|
24
|
-
color: { type: 'string' as const },
|
|
25
|
-
},
|
|
26
|
-
binding: 'none' as const,
|
|
27
|
-
triggers: ['click'],
|
|
28
|
-
container: false,
|
|
29
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { WidgetProps } from '../types.js';
|
|
3
|
-
|
|
4
|
-
export function ImageWidget({ props, bind }: WidgetProps) {
|
|
5
|
-
const src = (bind.value as string) ?? (props.src as string) ?? '';
|
|
6
|
-
const alt = (props.alt as string) ?? '';
|
|
7
|
-
const width = props.width as string | undefined;
|
|
8
|
-
const height = props.height as string | undefined;
|
|
9
|
-
|
|
10
|
-
if (!src) return null;
|
|
11
|
-
|
|
12
|
-
return <img src={src} alt={alt} style={{ width, height }} className="max-w-full rounded-sm" />;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
ImageWidget.widgetMeta = {
|
|
16
|
-
name: 'image',
|
|
17
|
-
label: 'Image',
|
|
18
|
-
category: 'display' as const,
|
|
19
|
-
schema: {
|
|
20
|
-
src: { type: 'string' as const },
|
|
21
|
-
alt: { type: 'string' as const },
|
|
22
|
-
width: { type: 'string' as const },
|
|
23
|
-
height: { type: 'string' as const },
|
|
24
|
-
},
|
|
25
|
-
binding: 'field' as const,
|
|
26
|
-
triggers: [],
|
|
27
|
-
container: false,
|
|
28
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Input } from '@/components/ui/input';
|
|
3
|
-
import { Field, FieldLabel } from '@/components/ui/field';
|
|
4
|
-
import type { WidgetProps } from '../types.js';
|
|
5
|
-
|
|
6
|
-
export function InputWidget({ props, bind, on }: WidgetProps) {
|
|
7
|
-
const fieldType = bind.meta?.type ?? 'string';
|
|
8
|
-
const label = (props.label as string) ?? bind.meta?.label ?? '';
|
|
9
|
-
const placeholder = (props.placeholder as string) ?? '';
|
|
10
|
-
const readOnly = (props.readOnly as boolean) ?? bind.meta?.readOnly ?? false;
|
|
11
|
-
const disabled = (props.disabled as boolean) ?? false;
|
|
12
|
-
const min = props.min as number | undefined;
|
|
13
|
-
const max = props.max as number | undefined;
|
|
14
|
-
const step = props.step as number | undefined;
|
|
15
|
-
const pattern = props.pattern as string | undefined;
|
|
16
|
-
const error = bind.error;
|
|
17
|
-
|
|
18
|
-
const inputType =
|
|
19
|
-
fieldType === 'int' || fieldType === 'decimal' || fieldType === 'money'
|
|
20
|
-
? 'number'
|
|
21
|
-
: fieldType === 'date'
|
|
22
|
-
? 'date'
|
|
23
|
-
: 'text';
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<Field>
|
|
27
|
-
{label && <FieldLabel>{label}</FieldLabel>}
|
|
28
|
-
<Input
|
|
29
|
-
type={inputType}
|
|
30
|
-
value={(bind.value as string) ?? ''}
|
|
31
|
-
onChange={(e) => {
|
|
32
|
-
bind.setValue?.(e.target.value);
|
|
33
|
-
on.change?.(e.target.value);
|
|
34
|
-
}}
|
|
35
|
-
onFocus={() => on.focus?.()}
|
|
36
|
-
onBlur={() => on.blur?.()}
|
|
37
|
-
placeholder={placeholder}
|
|
38
|
-
readOnly={readOnly}
|
|
39
|
-
disabled={disabled}
|
|
40
|
-
min={min}
|
|
41
|
-
max={max}
|
|
42
|
-
step={step}
|
|
43
|
-
pattern={pattern}
|
|
44
|
-
/>
|
|
45
|
-
{error && <p className="text-xs text-destructive mt-1">{error}</p>}
|
|
46
|
-
</Field>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
InputWidget.widgetMeta = {
|
|
51
|
-
name: 'input',
|
|
52
|
-
label: 'Input',
|
|
53
|
-
category: 'input' as const,
|
|
54
|
-
schema: {
|
|
55
|
-
label: { type: 'string' as const },
|
|
56
|
-
placeholder: { type: 'string' as const },
|
|
57
|
-
readOnly: { type: 'boolean' as const, default: false },
|
|
58
|
-
disabled: { type: 'boolean' as const, default: false },
|
|
59
|
-
error: { type: 'string' as const },
|
|
60
|
-
prefix: { type: 'string' as const },
|
|
61
|
-
suffix: { type: 'string' as const },
|
|
62
|
-
min: { type: 'number' as const },
|
|
63
|
-
max: { type: 'number' as const },
|
|
64
|
-
step: { type: 'number' as const },
|
|
65
|
-
pattern: { type: 'string' as const },
|
|
66
|
-
},
|
|
67
|
-
binding: 'field' as const,
|
|
68
|
-
triggers: ['change', 'focus', 'blur'],
|
|
69
|
-
container: false,
|
|
70
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { Textarea } from '@/components/ui/textarea';
|
|
3
|
-
import { Field, FieldLabel } from '@/components/ui/field';
|
|
4
|
-
import { cn } from '@/lib/utils';
|
|
5
|
-
import type { WidgetProps } from '../types.js';
|
|
6
|
-
|
|
7
|
-
export function JsonWidget({ props, bind, on }: WidgetProps) {
|
|
8
|
-
const label = (props.label as string) ?? bind.meta?.label ?? '';
|
|
9
|
-
const rows = (props.rows as number) ?? 6;
|
|
10
|
-
const disabled = (props.disabled as boolean) ?? bind.meta?.readOnly ?? false;
|
|
11
|
-
const [error, setError] = useState<string | null>(null);
|
|
12
|
-
|
|
13
|
-
const rawValue = bind.value;
|
|
14
|
-
const stringValue =
|
|
15
|
-
typeof rawValue === 'string'
|
|
16
|
-
? rawValue
|
|
17
|
-
: rawValue != null
|
|
18
|
-
? JSON.stringify(rawValue, null, 2)
|
|
19
|
-
: '';
|
|
20
|
-
const [localValue, setLocalValue] = useState(stringValue);
|
|
21
|
-
|
|
22
|
-
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
23
|
-
const text = e.target.value;
|
|
24
|
-
setLocalValue(text);
|
|
25
|
-
setError(null);
|
|
26
|
-
on.change?.(text);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const handleBlur = () => {
|
|
30
|
-
try {
|
|
31
|
-
const parsed = JSON.parse(localValue);
|
|
32
|
-
const formatted = JSON.stringify(parsed, null, 2);
|
|
33
|
-
setLocalValue(formatted);
|
|
34
|
-
bind.setValue?.(parsed);
|
|
35
|
-
setError(null);
|
|
36
|
-
} catch {
|
|
37
|
-
if (localValue.trim() !== '') {
|
|
38
|
-
setError('Invalid JSON');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
on.blur?.();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<Field>
|
|
46
|
-
{label && <FieldLabel>{label}</FieldLabel>}
|
|
47
|
-
<Textarea
|
|
48
|
-
value={localValue}
|
|
49
|
-
onChange={handleChange}
|
|
50
|
-
onFocus={() => on.focus?.()}
|
|
51
|
-
onBlur={handleBlur}
|
|
52
|
-
rows={rows}
|
|
53
|
-
disabled={disabled}
|
|
54
|
-
className={cn('font-mono text-xs', error && 'border-destructive')}
|
|
55
|
-
spellCheck={false}
|
|
56
|
-
/>
|
|
57
|
-
{error && (
|
|
58
|
-
<p className="text-xs text-destructive mt-1" role="alert">
|
|
59
|
-
{error}
|
|
60
|
-
</p>
|
|
61
|
-
)}
|
|
62
|
-
</Field>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
JsonWidget.widgetMeta = {
|
|
67
|
-
name: 'json',
|
|
68
|
-
label: 'JSON',
|
|
69
|
-
category: 'input' as const,
|
|
70
|
-
schema: {
|
|
71
|
-
label: { type: 'string' as const },
|
|
72
|
-
rows: { type: 'number' as const, default: 6 },
|
|
73
|
-
disabled: { type: 'boolean' as const, default: false },
|
|
74
|
-
},
|
|
75
|
-
binding: 'field' as const,
|
|
76
|
-
triggers: ['change', 'focus', 'blur'],
|
|
77
|
-
container: false,
|
|
78
|
-
};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover';
|
|
3
|
-
import {
|
|
4
|
-
Command,
|
|
5
|
-
CommandInput,
|
|
6
|
-
CommandList,
|
|
7
|
-
CommandEmpty,
|
|
8
|
-
CommandGroup,
|
|
9
|
-
CommandItem,
|
|
10
|
-
} from '@/components/ui/command';
|
|
11
|
-
import { Button } from '@/components/ui/button';
|
|
12
|
-
import { Field, FieldLabel } from '@/components/ui/field';
|
|
13
|
-
import { cn } from '@/lib/utils';
|
|
14
|
-
import type { WidgetProps } from '../types.js';
|
|
15
|
-
|
|
16
|
-
export function LinkWidget({ props, bind, on }: WidgetProps) {
|
|
17
|
-
const label = (props.label as string) ?? bind.meta?.label ?? '';
|
|
18
|
-
const placeholder = (props.placeholder as string) ?? 'Select...';
|
|
19
|
-
const disabled = (props.disabled as boolean) ?? bind.meta?.readOnly ?? false;
|
|
20
|
-
const [open, setOpen] = useState(false);
|
|
21
|
-
const [search, setSearch] = useState('');
|
|
22
|
-
|
|
23
|
-
const options = (bind.meta?.options ?? []) as { label: string; value: string }[];
|
|
24
|
-
const currentValue = bind.value as string | null | undefined;
|
|
25
|
-
const selectedOption = options.find((o) => o.value === currentValue);
|
|
26
|
-
|
|
27
|
-
const handleSelect = (value: string) => {
|
|
28
|
-
bind.setValue?.(value);
|
|
29
|
-
on.change?.(value);
|
|
30
|
-
setOpen(false);
|
|
31
|
-
setSearch('');
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const handleSearchChange = (value: string) => {
|
|
35
|
-
setSearch(value);
|
|
36
|
-
on.search?.(value);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<Field>
|
|
41
|
-
{label && <FieldLabel>{label}</FieldLabel>}
|
|
42
|
-
<Popover open={open} onOpenChange={setOpen}>
|
|
43
|
-
<PopoverTrigger asChild>
|
|
44
|
-
<Button
|
|
45
|
-
variant="outline"
|
|
46
|
-
role="combobox"
|
|
47
|
-
aria-expanded={open}
|
|
48
|
-
disabled={disabled}
|
|
49
|
-
className="w-full justify-between font-normal h-7 text-xs"
|
|
50
|
-
>
|
|
51
|
-
{selectedOption ? (
|
|
52
|
-
selectedOption.label
|
|
53
|
-
) : (
|
|
54
|
-
<span className="text-muted-foreground">{placeholder}</span>
|
|
55
|
-
)}
|
|
56
|
-
</Button>
|
|
57
|
-
</PopoverTrigger>
|
|
58
|
-
<PopoverContent className="w-[var(--radix-popover-trigger-width)] p-0" align="start">
|
|
59
|
-
<Command shouldFilter={false}>
|
|
60
|
-
<CommandInput
|
|
61
|
-
placeholder="Search..."
|
|
62
|
-
value={search}
|
|
63
|
-
onValueChange={handleSearchChange}
|
|
64
|
-
/>
|
|
65
|
-
<CommandList>
|
|
66
|
-
<CommandEmpty>No results found.</CommandEmpty>
|
|
67
|
-
<CommandGroup>
|
|
68
|
-
{options.map((opt) => (
|
|
69
|
-
<CommandItem
|
|
70
|
-
key={opt.value}
|
|
71
|
-
value={opt.value}
|
|
72
|
-
onSelect={() => handleSelect(opt.value)}
|
|
73
|
-
className={cn(opt.value === currentValue && 'bg-accent')}
|
|
74
|
-
>
|
|
75
|
-
{opt.label}
|
|
76
|
-
</CommandItem>
|
|
77
|
-
))}
|
|
78
|
-
</CommandGroup>
|
|
79
|
-
</CommandList>
|
|
80
|
-
</Command>
|
|
81
|
-
</PopoverContent>
|
|
82
|
-
</Popover>
|
|
83
|
-
</Field>
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
LinkWidget.widgetMeta = {
|
|
88
|
-
name: 'link',
|
|
89
|
-
label: 'Link',
|
|
90
|
-
category: 'input' as const,
|
|
91
|
-
schema: {
|
|
92
|
-
label: { type: 'string' as const },
|
|
93
|
-
placeholder: { type: 'string' as const },
|
|
94
|
-
disabled: { type: 'boolean' as const, default: false },
|
|
95
|
-
},
|
|
96
|
-
binding: 'field' as const,
|
|
97
|
-
triggers: ['change', 'search'],
|
|
98
|
-
container: false,
|
|
99
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover';
|
|
3
|
-
import {
|
|
4
|
-
Command,
|
|
5
|
-
CommandInput,
|
|
6
|
-
CommandList,
|
|
7
|
-
CommandEmpty,
|
|
8
|
-
CommandGroup,
|
|
9
|
-
CommandItem,
|
|
10
|
-
} from '@/components/ui/command';
|
|
11
|
-
import { Button } from '@/components/ui/button';
|
|
12
|
-
import { Badge } from '@/components/ui/badge';
|
|
13
|
-
import { Field, FieldLabel } from '@/components/ui/field';
|
|
14
|
-
import { cn } from '@/lib/utils';
|
|
15
|
-
import type { WidgetProps } from '../types.js';
|
|
16
|
-
|
|
17
|
-
export function ManyToManyWidget({ props, bind, on }: WidgetProps) {
|
|
18
|
-
const label = (props.label as string) ?? bind.meta?.label ?? '';
|
|
19
|
-
const placeholder = (props.placeholder as string) ?? 'Select...';
|
|
20
|
-
const disabled = (props.disabled as boolean) ?? bind.meta?.readOnly ?? false;
|
|
21
|
-
const [open, setOpen] = useState(false);
|
|
22
|
-
const [search, setSearch] = useState('');
|
|
23
|
-
|
|
24
|
-
const options = (bind.meta?.options ?? []) as { label: string; value: string }[];
|
|
25
|
-
const selected = (bind.value as string[] | null) ?? [];
|
|
26
|
-
|
|
27
|
-
const handleToggle = (value: string) => {
|
|
28
|
-
const next = selected.includes(value)
|
|
29
|
-
? selected.filter((v) => v !== value)
|
|
30
|
-
: [...selected, value];
|
|
31
|
-
bind.setValue?.(next);
|
|
32
|
-
on.change?.(next);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const handleRemove = (value: string) => {
|
|
36
|
-
const next = selected.filter((v) => v !== value);
|
|
37
|
-
bind.setValue?.(next);
|
|
38
|
-
on.change?.(next);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const handleSearchChange = (value: string) => {
|
|
42
|
-
setSearch(value);
|
|
43
|
-
on.search?.(value);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const selectedLabels = selected
|
|
47
|
-
.map((v) => options.find((o) => o.value === v))
|
|
48
|
-
.filter(Boolean) as { label: string; value: string }[];
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<Field>
|
|
52
|
-
{label && <FieldLabel>{label}</FieldLabel>}
|
|
53
|
-
<Popover open={open} onOpenChange={setOpen}>
|
|
54
|
-
<PopoverTrigger asChild>
|
|
55
|
-
<Button
|
|
56
|
-
variant="outline"
|
|
57
|
-
role="combobox"
|
|
58
|
-
aria-expanded={open}
|
|
59
|
-
disabled={disabled}
|
|
60
|
-
className="w-full justify-start font-normal h-auto min-h-7 text-xs flex-wrap gap-1 py-1"
|
|
61
|
-
>
|
|
62
|
-
{selectedLabels.length > 0 ? (
|
|
63
|
-
selectedLabels.map((opt) => (
|
|
64
|
-
<Badge key={opt.value} variant="secondary" className="text-xs">
|
|
65
|
-
{opt.label}
|
|
66
|
-
<button
|
|
67
|
-
type="button"
|
|
68
|
-
className="ml-1 rounded-full hover:bg-muted"
|
|
69
|
-
onClick={(e) => {
|
|
70
|
-
e.stopPropagation();
|
|
71
|
-
handleRemove(opt.value);
|
|
72
|
-
}}
|
|
73
|
-
aria-label={`Remove ${opt.label}`}
|
|
74
|
-
>
|
|
75
|
-
×
|
|
76
|
-
</button>
|
|
77
|
-
</Badge>
|
|
78
|
-
))
|
|
79
|
-
) : (
|
|
80
|
-
<span className="text-muted-foreground">{placeholder}</span>
|
|
81
|
-
)}
|
|
82
|
-
</Button>
|
|
83
|
-
</PopoverTrigger>
|
|
84
|
-
<PopoverContent className="w-[var(--radix-popover-trigger-width)] p-0" align="start">
|
|
85
|
-
<Command shouldFilter={false}>
|
|
86
|
-
<CommandInput
|
|
87
|
-
placeholder="Search..."
|
|
88
|
-
value={search}
|
|
89
|
-
onValueChange={handleSearchChange}
|
|
90
|
-
/>
|
|
91
|
-
<CommandList>
|
|
92
|
-
<CommandEmpty>No results found.</CommandEmpty>
|
|
93
|
-
<CommandGroup>
|
|
94
|
-
{options.map((opt) => (
|
|
95
|
-
<CommandItem
|
|
96
|
-
key={opt.value}
|
|
97
|
-
value={opt.value}
|
|
98
|
-
onSelect={() => handleToggle(opt.value)}
|
|
99
|
-
className={cn(selected.includes(opt.value) && 'bg-accent')}
|
|
100
|
-
>
|
|
101
|
-
{opt.label}
|
|
102
|
-
</CommandItem>
|
|
103
|
-
))}
|
|
104
|
-
</CommandGroup>
|
|
105
|
-
</CommandList>
|
|
106
|
-
</Command>
|
|
107
|
-
</PopoverContent>
|
|
108
|
-
</Popover>
|
|
109
|
-
</Field>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
ManyToManyWidget.widgetMeta = {
|
|
114
|
-
name: 'many-to-many',
|
|
115
|
-
label: 'Many to Many',
|
|
116
|
-
category: 'input' as const,
|
|
117
|
-
schema: {
|
|
118
|
-
label: { type: 'string' as const },
|
|
119
|
-
placeholder: { type: 'string' as const },
|
|
120
|
-
disabled: { type: 'boolean' as const, default: false },
|
|
121
|
-
},
|
|
122
|
-
binding: 'field' as const,
|
|
123
|
-
triggers: ['change', 'search'],
|
|
124
|
-
container: false,
|
|
125
|
-
};
|