@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.
Files changed (317) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/App.js +7 -1
  3. package/dist/App.js.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/main.d.ts.map +1 -1
  9. package/dist/main.js +20 -0
  10. package/dist/main.js.map +1 -1
  11. package/dist/shell/assets/index-63v1sBS3.css +1 -0
  12. package/dist/shell/assets/index-Dh7K40cQ.js +8634 -0
  13. package/dist/shell/assets/vendor-query-B2cydN5j.js +1 -0
  14. package/dist/shell/assets/vendor-radix-BJxYPxPb.js +69 -0
  15. package/dist/shell/assets/vendor-router-ET_myMt5.js +17 -0
  16. package/dist/shell/index.html +5 -2
  17. package/dist/theme.css +82 -0
  18. package/dist/widgets/components/lazy-manifest.d.ts +11 -0
  19. package/dist/widgets/components/lazy-manifest.d.ts.map +1 -0
  20. package/dist/widgets/components/lazy-manifest.js +32 -0
  21. package/dist/widgets/components/lazy-manifest.js.map +1 -0
  22. package/dist/widgets/components/register.js +12 -12
  23. package/dist/widgets/components/register.js.map +1 -1
  24. package/dist/widgets/loader.d.ts +3 -0
  25. package/dist/widgets/loader.d.ts.map +1 -0
  26. package/dist/widgets/loader.js +73 -0
  27. package/dist/widgets/loader.js.map +1 -0
  28. package/dist/widgets/renderer/LazyWidget.d.ts +8 -0
  29. package/dist/widgets/renderer/LazyWidget.d.ts.map +1 -0
  30. package/dist/widgets/renderer/LazyWidget.js +31 -0
  31. package/dist/widgets/renderer/LazyWidget.js.map +1 -0
  32. package/dist/widgets/renderer/WidgetErrorBoundary.d.ts +17 -0
  33. package/dist/widgets/renderer/WidgetErrorBoundary.d.ts.map +1 -0
  34. package/dist/widgets/renderer/WidgetErrorBoundary.js +18 -0
  35. package/dist/widgets/renderer/WidgetErrorBoundary.js.map +1 -0
  36. package/dist/widgets/renderer/WidgetRenderer.d.ts.map +1 -1
  37. package/dist/widgets/renderer/WidgetRenderer.js +8 -6
  38. package/dist/widgets/renderer/WidgetRenderer.js.map +1 -1
  39. package/package.json +7 -4
  40. package/.claude/skills/add-widget/SKILL.md +0 -101
  41. package/.turbo/turbo-build.log +0 -29
  42. package/CHANGELOG.md +0 -25
  43. package/CLAUDE.md +0 -236
  44. package/components.json +0 -25
  45. package/dist/components/ui/chart.d.ts +0 -45
  46. package/dist/components/ui/chart.d.ts.map +0 -1
  47. package/dist/components/ui/chart.js +0 -119
  48. package/dist/components/ui/chart.js.map +0 -1
  49. package/dist/shell/assets/index--35CAvcP.js +0 -8715
  50. package/dist/shell/assets/index-COLmoPYo.css +0 -1
  51. package/index.html +0 -12
  52. package/src/App.tsx +0 -44
  53. package/src/__tests__/setup.ts +0 -1
  54. package/src/api/auth.ts +0 -41
  55. package/src/api/boot.ts +0 -10
  56. package/src/api/client.ts +0 -26
  57. package/src/api/paths.ts +0 -3
  58. package/src/api/token.ts +0 -13
  59. package/src/auth/LoginForm.tsx +0 -67
  60. package/src/auth/SessionExpired.tsx +0 -24
  61. package/src/auth/SetupForm.tsx +0 -76
  62. package/src/boot/BootGate.tsx +0 -35
  63. package/src/boot/BootProvider.tsx +0 -28
  64. package/src/boot/types.ts +0 -9
  65. package/src/boot/useBoot.ts +0 -111
  66. package/src/components/Icon.tsx +0 -17
  67. package/src/components/ui/accordion.tsx +0 -82
  68. package/src/components/ui/alert-dialog.tsx +0 -180
  69. package/src/components/ui/alert.tsx +0 -76
  70. package/src/components/ui/aspect-ratio.tsx +0 -9
  71. package/src/components/ui/avatar.tsx +0 -94
  72. package/src/components/ui/badge.tsx +0 -45
  73. package/src/components/ui/breadcrumb.tsx +0 -104
  74. package/src/components/ui/button-group.tsx +0 -78
  75. package/src/components/ui/button.tsx +0 -65
  76. package/src/components/ui/calendar.tsx +0 -187
  77. package/src/components/ui/card.tsx +0 -85
  78. package/src/components/ui/carousel.tsx +0 -229
  79. package/src/components/ui/chart.tsx +0 -339
  80. package/src/components/ui/checkbox.tsx +0 -27
  81. package/src/components/ui/collapsible.tsx +0 -21
  82. package/src/components/ui/combobox.tsx +0 -275
  83. package/src/components/ui/command.tsx +0 -178
  84. package/src/components/ui/context-menu.tsx +0 -242
  85. package/src/components/ui/dialog.tsx +0 -146
  86. package/src/components/ui/direction.tsx +0 -20
  87. package/src/components/ui/drawer.tsx +0 -118
  88. package/src/components/ui/dropdown-menu.tsx +0 -247
  89. package/src/components/ui/empty.tsx +0 -94
  90. package/src/components/ui/field.tsx +0 -224
  91. package/src/components/ui/hover-card.tsx +0 -36
  92. package/src/components/ui/input-group.tsx +0 -142
  93. package/src/components/ui/input-otp.tsx +0 -86
  94. package/src/components/ui/input.tsx +0 -19
  95. package/src/components/ui/item.tsx +0 -182
  96. package/src/components/ui/kbd.tsx +0 -26
  97. package/src/components/ui/label.tsx +0 -19
  98. package/src/components/ui/menubar.tsx +0 -260
  99. package/src/components/ui/native-select.tsx +0 -55
  100. package/src/components/ui/navigation-menu.tsx +0 -160
  101. package/src/components/ui/pagination.tsx +0 -112
  102. package/src/components/ui/popover.tsx +0 -74
  103. package/src/components/ui/progress.tsx +0 -31
  104. package/src/components/ui/radio-group.tsx +0 -42
  105. package/src/components/ui/resizable.tsx +0 -42
  106. package/src/components/ui/scroll-area.tsx +0 -53
  107. package/src/components/ui/select.tsx +0 -185
  108. package/src/components/ui/separator.tsx +0 -26
  109. package/src/components/ui/sheet.tsx +0 -128
  110. package/src/components/ui/sidebar.tsx +0 -669
  111. package/src/components/ui/skeleton.tsx +0 -13
  112. package/src/components/ui/slider.tsx +0 -54
  113. package/src/components/ui/sonner.tsx +0 -43
  114. package/src/components/ui/spinner.tsx +0 -16
  115. package/src/components/ui/switch.tsx +0 -33
  116. package/src/components/ui/table.tsx +0 -87
  117. package/src/components/ui/tabs.tsx +0 -80
  118. package/src/components/ui/textarea.tsx +0 -18
  119. package/src/components/ui/toggle-group.tsx +0 -86
  120. package/src/components/ui/toggle.tsx +0 -44
  121. package/src/components/ui/tooltip.tsx +0 -53
  122. package/src/context/MetaContext.tsx +0 -22
  123. package/src/context/ModuleContext.tsx +0 -62
  124. package/src/context/PermissionsContext.tsx +0 -39
  125. package/src/context/ShellProviders.tsx +0 -33
  126. package/src/context/UserContext.tsx +0 -16
  127. package/src/data/QueryProvider.tsx +0 -7
  128. package/src/data/queryClient.ts +0 -18
  129. package/src/data/useModelMeta.ts +0 -17
  130. package/src/data/useMutation.ts +0 -60
  131. package/src/data/useRecord.ts +0 -29
  132. package/src/data/useSource.ts +0 -112
  133. package/src/hooks/use-mobile.ts +0 -19
  134. package/src/index.css +0 -260
  135. package/src/index.ts +0 -16
  136. package/src/lib/utils.ts +0 -6
  137. package/src/main.tsx +0 -17
  138. package/src/router/NotFound.tsx +0 -8
  139. package/src/router/RouterProvider.tsx +0 -7
  140. package/src/router/buildRouteTree.tsx +0 -63
  141. package/src/router/createShellRouter.ts +0 -9
  142. package/src/router/hooks.ts +0 -43
  143. package/src/shell/CommandPalette.tsx +0 -76
  144. package/src/shell/ConfirmDialog.tsx +0 -34
  145. package/src/shell/ConfirmProvider.tsx +0 -56
  146. package/src/shell/DrawerContext.tsx +0 -44
  147. package/src/shell/HeaderActions.tsx +0 -31
  148. package/src/shell/ModuleSelectorPage.tsx +0 -149
  149. package/src/shell/PageOutlet.tsx +0 -21
  150. package/src/shell/ShellContext.tsx +0 -45
  151. package/src/shell/ShellDevTools.tsx +0 -153
  152. package/src/shell/ShellLayout.tsx +0 -231
  153. package/src/shell/Toast.tsx +0 -58
  154. package/src/shell/ToastProvider.tsx +0 -60
  155. package/src/shell/app-sidebar/AppSidebar.tsx +0 -44
  156. package/src/shell/app-sidebar/ModuleSwitcher.tsx +0 -87
  157. package/src/shell/app-sidebar/NavMain.tsx +0 -64
  158. package/src/shell/app-sidebar/NavUser.tsx +0 -97
  159. package/src/shell/app-sidebar/SearchMenu.tsx +0 -22
  160. package/src/shell/app-sidebar/index.ts +0 -8
  161. package/src/shell/app-sidebar/types.ts +0 -38
  162. package/src/shell/types.ts +0 -6
  163. package/src/shell/useBreadcrumbs.ts +0 -42
  164. package/src/studio/bridge.ts +0 -125
  165. package/src/studio/index.ts +0 -3
  166. package/src/studio/overlay.ts +0 -47
  167. package/src/studio/types.ts +0 -32
  168. package/src/studio/walker.ts +0 -48
  169. package/src/vite-env.d.ts +0 -1
  170. package/src/widgets/__tests__/action-edge-cases.test.ts +0 -281
  171. package/src/widgets/__tests__/action.test.ts +0 -236
  172. package/src/widgets/__tests__/attachment-widget.test.tsx +0 -85
  173. package/src/widgets/__tests__/attachments-widget.test.tsx +0 -109
  174. package/src/widgets/__tests__/binding.test.ts +0 -76
  175. package/src/widgets/__tests__/button-widget.test.tsx +0 -145
  176. package/src/widgets/__tests__/checkbox-widget.test.tsx +0 -158
  177. package/src/widgets/__tests__/code-widget.test.tsx +0 -64
  178. package/src/widgets/__tests__/computed-widget.test.tsx +0 -62
  179. package/src/widgets/__tests__/condition-edge-cases.test.ts +0 -120
  180. package/src/widgets/__tests__/condition.test.ts +0 -221
  181. package/src/widgets/__tests__/context.test.ts +0 -99
  182. package/src/widgets/__tests__/data-widget.test.tsx +0 -204
  183. package/src/widgets/__tests__/datepicker-widget.test.tsx +0 -66
  184. package/src/widgets/__tests__/datetime-widget.test.tsx +0 -67
  185. package/src/widgets/__tests__/drawer-widget.test.tsx +0 -149
  186. package/src/widgets/__tests__/dynamic-link-widget.test.tsx +0 -52
  187. package/src/widgets/__tests__/edge-cases.test.ts +0 -232
  188. package/src/widgets/__tests__/evaluator.test.ts +0 -107
  189. package/src/widgets/__tests__/functions.test.ts +0 -147
  190. package/src/widgets/__tests__/grid-widget.test.tsx +0 -137
  191. package/src/widgets/__tests__/hooks.test.tsx +0 -249
  192. package/src/widgets/__tests__/icon-widget.test.tsx +0 -129
  193. package/src/widgets/__tests__/input-widget.test.tsx +0 -264
  194. package/src/widgets/__tests__/integration.test.ts +0 -116
  195. package/src/widgets/__tests__/json-widget.test.tsx +0 -70
  196. package/src/widgets/__tests__/link-widget.test.tsx +0 -92
  197. package/src/widgets/__tests__/many-to-many-widget.test.tsx +0 -93
  198. package/src/widgets/__tests__/modal-widget.test.tsx +0 -148
  199. package/src/widgets/__tests__/money-widget.test.tsx +0 -97
  200. package/src/widgets/__tests__/parser.test.ts +0 -171
  201. package/src/widgets/__tests__/reactive-variables.test.ts +0 -383
  202. package/src/widgets/__tests__/renderer.test.tsx +0 -300
  203. package/src/widgets/__tests__/repeat-widget.test.tsx +0 -229
  204. package/src/widgets/__tests__/select-widget.test.tsx +0 -231
  205. package/src/widgets/__tests__/sequence-widget.test.tsx +0 -58
  206. package/src/widgets/__tests__/shell-integration.test.tsx +0 -1343
  207. package/src/widgets/__tests__/split-widget.test.tsx +0 -133
  208. package/src/widgets/__tests__/state-edge-cases.test.ts +0 -118
  209. package/src/widgets/__tests__/state.test.ts +0 -106
  210. package/src/widgets/__tests__/table-data-binding.test.tsx +0 -482
  211. package/src/widgets/__tests__/table-filter-popover.test.tsx +0 -486
  212. package/src/widgets/__tests__/table-search.test.tsx +0 -305
  213. package/src/widgets/__tests__/table-widget.test.tsx +0 -509
  214. package/src/widgets/__tests__/textarea-widget.test.tsx +0 -105
  215. package/src/widgets/__tests__/tracker-validator-edge-cases.test.ts +0 -242
  216. package/src/widgets/__tests__/tracker.test.ts +0 -133
  217. package/src/widgets/__tests__/tree-widget.test.tsx +0 -97
  218. package/src/widgets/__tests__/use-model-source.test.ts +0 -67
  219. package/src/widgets/__tests__/validator.test.ts +0 -208
  220. package/src/widgets/action/dispatcher.ts +0 -334
  221. package/src/widgets/action/index.ts +0 -2
  222. package/src/widgets/binding/index.ts +0 -2
  223. package/src/widgets/binding/resolver.ts +0 -61
  224. package/src/widgets/components/AttachmentWidget.tsx +0 -111
  225. package/src/widgets/components/AttachmentsWidget.tsx +0 -121
  226. package/src/widgets/components/BadgeWidget.tsx +0 -35
  227. package/src/widgets/components/ButtonWidget.tsx +0 -43
  228. package/src/widgets/components/CardWidget.tsx +0 -68
  229. package/src/widgets/components/CheckboxWidget.tsx +0 -39
  230. package/src/widgets/components/CodeWidget.tsx +0 -44
  231. package/src/widgets/components/ColumnWidget.tsx +0 -22
  232. package/src/widgets/components/ComputedWidget.tsx +0 -49
  233. package/src/widgets/components/DataWidget.tsx +0 -189
  234. package/src/widgets/components/DatePickerWidget.tsx +0 -73
  235. package/src/widgets/components/DatetimeWidget.tsx +0 -160
  236. package/src/widgets/components/DividerWidget.tsx +0 -37
  237. package/src/widgets/components/DrawerWidget.tsx +0 -52
  238. package/src/widgets/components/DynamicLinkWidget.tsx +0 -130
  239. package/src/widgets/components/GridWidget.tsx +0 -134
  240. package/src/widgets/components/GroupWidget.tsx +0 -111
  241. package/src/widgets/components/IconWidget.tsx +0 -29
  242. package/src/widgets/components/ImageWidget.tsx +0 -28
  243. package/src/widgets/components/InputWidget.tsx +0 -70
  244. package/src/widgets/components/JsonWidget.tsx +0 -78
  245. package/src/widgets/components/LinkWidget.tsx +0 -99
  246. package/src/widgets/components/ManyToManyWidget.tsx +0 -125
  247. package/src/widgets/components/ModalWidget.tsx +0 -52
  248. package/src/widgets/components/MoneyWidget.tsx +0 -80
  249. package/src/widgets/components/RepeatWidget.tsx +0 -66
  250. package/src/widgets/components/ScrollAreaWidget.tsx +0 -40
  251. package/src/widgets/components/SectionWidget.tsx +0 -78
  252. package/src/widgets/components/SelectWidget.tsx +0 -63
  253. package/src/widgets/components/SequenceWidget.tsx +0 -32
  254. package/src/widgets/components/SpacerWidget.tsx +0 -29
  255. package/src/widgets/components/SplitWidget.tsx +0 -60
  256. package/src/widgets/components/StackWidget.tsx +0 -44
  257. package/src/widgets/components/TableWidget.tsx +0 -366
  258. package/src/widgets/components/TextWidget.tsx +0 -44
  259. package/src/widgets/components/TextareaWidget.tsx +0 -49
  260. package/src/widgets/components/TreeWidget.tsx +0 -109
  261. package/src/widgets/components/index.ts +0 -30
  262. package/src/widgets/components/register.ts +0 -93
  263. package/src/widgets/components/table/CellRenderers.tsx +0 -83
  264. package/src/widgets/components/table/TablePagination.tsx +0 -45
  265. package/src/widgets/components/table/TableToolbar.tsx +0 -285
  266. package/src/widgets/components/table/filter-operators.ts +0 -134
  267. package/src/widgets/components/table/index.ts +0 -11
  268. package/src/widgets/condition/evaluator.ts +0 -57
  269. package/src/widgets/condition/index.ts +0 -1
  270. package/src/widgets/context/builder.ts +0 -99
  271. package/src/widgets/context/index.ts +0 -8
  272. package/src/widgets/context/types.ts +0 -37
  273. package/src/widgets/data/index.ts +0 -5
  274. package/src/widgets/data/useModelQuery.ts +0 -116
  275. package/src/widgets/data/useModelRecord.ts +0 -37
  276. package/src/widgets/expression/evaluator.ts +0 -100
  277. package/src/widgets/expression/functions.ts +0 -131
  278. package/src/widgets/expression/index.ts +0 -13
  279. package/src/widgets/expression/parser.ts +0 -229
  280. package/src/widgets/expression/types.ts +0 -45
  281. package/src/widgets/form/FormContext.ts +0 -29
  282. package/src/widgets/form/FormProvider.tsx +0 -84
  283. package/src/widgets/form/FormWidget.tsx +0 -42
  284. package/src/widgets/form/index.ts +0 -4
  285. package/src/widgets/form/useFormState.ts +0 -127
  286. package/src/widgets/form/useFormSubmit.ts +0 -90
  287. package/src/widgets/form/useFormValidation.ts +0 -62
  288. package/src/widgets/hooks/index.ts +0 -8
  289. package/src/widgets/hooks/useAction.ts +0 -83
  290. package/src/widgets/hooks/useBind.ts +0 -34
  291. package/src/widgets/hooks/useCondition.ts +0 -21
  292. package/src/widgets/hooks/useDataQuery.ts +0 -48
  293. package/src/widgets/hooks/useExpression.ts +0 -14
  294. package/src/widgets/hooks/usePageState.ts +0 -21
  295. package/src/widgets/hooks/useSurfaceContext.ts +0 -11
  296. package/src/widgets/hooks/useWidgetContext.ts +0 -14
  297. package/src/widgets/index.ts +0 -80
  298. package/src/widgets/lib/layout-props.ts +0 -135
  299. package/src/widgets/reactivity/index.ts +0 -11
  300. package/src/widgets/reactivity/tracker.ts +0 -139
  301. package/src/widgets/reactivity/variables.ts +0 -213
  302. package/src/widgets/registry.ts +0 -41
  303. package/src/widgets/renderer/SlotRenderer.tsx +0 -47
  304. package/src/widgets/renderer/WidgetRenderer.tsx +0 -191
  305. package/src/widgets/renderer/index.ts +0 -4
  306. package/src/widgets/shell/WidgetSlotRenderer.tsx +0 -73
  307. package/src/widgets/shell/index.ts +0 -4
  308. package/src/widgets/shell/useActionHandlers.ts +0 -170
  309. package/src/widgets/state/index.ts +0 -2
  310. package/src/widgets/state/store.ts +0 -96
  311. package/src/widgets/types.ts +0 -28
  312. package/src/widgets/validation/index.ts +0 -2
  313. package/src/widgets/validation/validator.ts +0 -140
  314. package/tsconfig.json +0 -27
  315. package/tsconfig.tsbuildinfo +0 -1
  316. package/vite.config.ts +0 -21
  317. package/vitest.config.ts +0 -16
@@ -1,111 +0,0 @@
1
- import React, { useRef } from 'react';
2
- import { Button } from '@/components/ui/button';
3
- import { Field, FieldLabel } from '@/components/ui/field';
4
- import { cn } from '@/lib/utils';
5
- import type { WidgetProps } from '../types.js';
6
-
7
- interface FileValue {
8
- name: string;
9
- url?: string;
10
- size?: number;
11
- }
12
-
13
- export function AttachmentWidget({ props, bind, on }: WidgetProps) {
14
- const label = (props.label as string) ?? bind.meta?.label ?? '';
15
- const accept = (props.accept as string) ?? '';
16
- const disabled = (props.disabled as boolean) ?? bind.meta?.readOnly ?? false;
17
- const inputRef = useRef<HTMLInputElement>(null);
18
-
19
- const fileValue = bind.value as FileValue | null | undefined;
20
-
21
- const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
22
- const file = e.target.files?.[0];
23
- if (file) {
24
- const value = { name: file.name, size: file.size };
25
- bind.setValue?.(value);
26
- on.change?.(value);
27
- }
28
- };
29
-
30
- const handleDrop = (e: React.DragEvent) => {
31
- e.preventDefault();
32
- if (disabled) return;
33
- const file = e.dataTransfer.files?.[0];
34
- if (file) {
35
- const value = { name: file.name, size: file.size };
36
- bind.setValue?.(value);
37
- on.change?.(value);
38
- }
39
- };
40
-
41
- const handleRemove = () => {
42
- bind.setValue?.(null);
43
- on.remove?.();
44
- if (inputRef.current) inputRef.current.value = '';
45
- };
46
-
47
- return (
48
- <Field>
49
- {label && <FieldLabel>{label}</FieldLabel>}
50
- {fileValue ? (
51
- <div className="flex items-center gap-2 rounded-md border border-input px-3 py-2">
52
- <span className="flex-1 truncate text-sm">{fileValue.name}</span>
53
- {fileValue.size && (
54
- <span className="text-xs text-muted-foreground">
55
- {(fileValue.size / 1024).toFixed(1)} KB
56
- </span>
57
- )}
58
- {!disabled && (
59
- <Button
60
- variant="ghost"
61
- size="sm"
62
- onClick={handleRemove}
63
- className="h-5 px-1"
64
- aria-label="Remove file"
65
- >
66
- ×
67
- </Button>
68
- )}
69
- </div>
70
- ) : (
71
- <div
72
- className={cn(
73
- 'flex flex-col items-center justify-center rounded-md border-2 border-dashed border-input p-4 text-center transition-colors',
74
- !disabled && 'cursor-pointer hover:border-primary/50 hover:bg-accent/50',
75
- disabled && 'opacity-50 cursor-not-allowed',
76
- )}
77
- onClick={() => !disabled && inputRef.current?.click()}
78
- onDrop={handleDrop}
79
- onDragOver={(e) => e.preventDefault()}
80
- role="button"
81
- aria-label="Upload file"
82
- >
83
- <p className="text-xs text-muted-foreground">Drop a file here or click to browse</p>
84
- </div>
85
- )}
86
- <input
87
- ref={inputRef}
88
- type="file"
89
- accept={accept}
90
- onChange={handleFileChange}
91
- className="hidden"
92
- disabled={disabled}
93
- />
94
- </Field>
95
- );
96
- }
97
-
98
- AttachmentWidget.widgetMeta = {
99
- name: 'attachment',
100
- label: 'Attachment',
101
- category: 'input' as const,
102
- schema: {
103
- label: { type: 'string' as const },
104
- accept: { type: 'string' as const },
105
- maxSize: { type: 'string' as const },
106
- disabled: { type: 'boolean' as const, default: false },
107
- },
108
- binding: 'field' as const,
109
- triggers: ['change', 'remove'],
110
- container: false,
111
- };
@@ -1,121 +0,0 @@
1
- import React, { useRef } from 'react';
2
- import { Button } from '@/components/ui/button';
3
- import { Field, FieldLabel } from '@/components/ui/field';
4
- import { cn } from '@/lib/utils';
5
- import type { WidgetProps } from '../types.js';
6
-
7
- interface FileValue {
8
- name: string;
9
- url?: string;
10
- size?: number;
11
- }
12
-
13
- export function AttachmentsWidget({ props, bind, on }: WidgetProps) {
14
- const label = (props.label as string) ?? bind.meta?.label ?? '';
15
- const accept = (props.accept as string) ?? '';
16
- const maxCount = (props.maxCount as number) ?? 10;
17
- const disabled = (props.disabled as boolean) ?? bind.meta?.readOnly ?? false;
18
- const inputRef = useRef<HTMLInputElement>(null);
19
-
20
- const files = (bind.value as FileValue[] | null) ?? [];
21
-
22
- const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
23
- const newFiles = Array.from(e.target.files ?? []).map((f) => ({ name: f.name, size: f.size }));
24
- const next = [...files, ...newFiles].slice(0, maxCount);
25
- bind.setValue?.(next);
26
- on.change?.(next);
27
- if (inputRef.current) inputRef.current.value = '';
28
- };
29
-
30
- const handleDrop = (e: React.DragEvent) => {
31
- e.preventDefault();
32
- if (disabled) return;
33
- const newFiles = Array.from(e.dataTransfer.files).map((f) => ({ name: f.name, size: f.size }));
34
- const next = [...files, ...newFiles].slice(0, maxCount);
35
- bind.setValue?.(next);
36
- on.change?.(next);
37
- };
38
-
39
- const handleRemove = (index: number) => {
40
- const next = files.filter((_, i) => i !== index);
41
- bind.setValue?.(next);
42
- on.remove?.(index);
43
- };
44
-
45
- return (
46
- <Field>
47
- {label && <FieldLabel>{label}</FieldLabel>}
48
- {files.length > 0 && (
49
- <ul className="mb-2 space-y-1" role="list">
50
- {files.map((file, i) => (
51
- <li
52
- key={`${file.name}-${i}`}
53
- className="flex items-center gap-2 rounded-md border border-input px-3 py-1.5"
54
- >
55
- <span className="flex-1 truncate text-sm">{file.name}</span>
56
- {file.size && (
57
- <span className="text-xs text-muted-foreground">
58
- {(file.size / 1024).toFixed(1)} KB
59
- </span>
60
- )}
61
- {!disabled && (
62
- <Button
63
- variant="ghost"
64
- size="sm"
65
- onClick={() => handleRemove(i)}
66
- className="h-5 px-1"
67
- aria-label={`Remove ${file.name}`}
68
- >
69
- ×
70
- </Button>
71
- )}
72
- </li>
73
- ))}
74
- </ul>
75
- )}
76
- {files.length < maxCount && (
77
- <div
78
- className={cn(
79
- 'flex flex-col items-center justify-center rounded-md border-2 border-dashed border-input p-4 text-center transition-colors',
80
- !disabled && 'cursor-pointer hover:border-primary/50 hover:bg-accent/50',
81
- disabled && 'opacity-50 cursor-not-allowed',
82
- )}
83
- onClick={() => !disabled && inputRef.current?.click()}
84
- onDrop={handleDrop}
85
- onDragOver={(e) => e.preventDefault()}
86
- role="button"
87
- aria-label="Upload files"
88
- >
89
- <p className="text-xs text-muted-foreground">
90
- Drop files here or click to browse ({files.length}/{maxCount})
91
- </p>
92
- </div>
93
- )}
94
- <input
95
- ref={inputRef}
96
- type="file"
97
- accept={accept}
98
- multiple
99
- onChange={handleFileChange}
100
- className="hidden"
101
- disabled={disabled}
102
- />
103
- </Field>
104
- );
105
- }
106
-
107
- AttachmentsWidget.widgetMeta = {
108
- name: 'attachments',
109
- label: 'Attachments',
110
- category: 'input' as const,
111
- schema: {
112
- label: { type: 'string' as const },
113
- accept: { type: 'string' as const },
114
- maxSize: { type: 'string' as const },
115
- maxCount: { type: 'number' as const, default: 10 },
116
- disabled: { type: 'boolean' as const, default: false },
117
- },
118
- binding: 'field' as const,
119
- triggers: ['change', 'remove'],
120
- container: false,
121
- };
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
- import { Badge } from '@/components/ui/badge';
3
- import type { WidgetProps } from '../types.js';
4
-
5
- const variantMap: Record<string, 'default' | 'secondary' | 'outline' | 'destructive'> = {
6
- solid: 'default',
7
- outline: 'outline',
8
- subtle: 'secondary',
9
- };
10
-
11
- export function BadgeWidget({ props, bind }: WidgetProps) {
12
- const label = props.label as string | undefined;
13
- const value = (bind.value as string) ?? '';
14
- const variant = variantMap[(props.variant as string) ?? 'subtle'] ?? 'secondary';
15
-
16
- return <Badge variant={variant}>{label || value}</Badge>;
17
- }
18
-
19
- BadgeWidget.widgetMeta = {
20
- name: 'badge',
21
- label: 'Badge',
22
- category: 'display' as const,
23
- schema: {
24
- variant: { type: 'enum' as const, options: ['solid', 'outline', 'subtle'], default: 'subtle' },
25
- color: {
26
- type: 'enum' as const,
27
- options: ['default', 'success', 'warning', 'error', 'info'],
28
- default: 'default',
29
- },
30
- colorMap: { type: 'object' as const },
31
- },
32
- binding: 'field' as const,
33
- triggers: [],
34
- container: false,
35
- };
@@ -1,43 +0,0 @@
1
- import React from 'react';
2
- import { Button as UIButton } from '@/components/ui/button';
3
- import type { WidgetProps } from '../types.js';
4
-
5
- export function ButtonWidget({ props, on }: WidgetProps) {
6
- const variant = props.variant as string | undefined;
7
- const size = props.size as string | undefined;
8
-
9
- return (
10
- <UIButton
11
- variant={
12
- variant === 'primary'
13
- ? 'default'
14
- : (variant as 'default' | 'secondary' | 'ghost' | 'destructive' | undefined)
15
- }
16
- size={size === 'md' ? 'default' : (size as 'sm' | 'default' | 'lg' | undefined)}
17
- disabled={props.disabled as boolean | undefined}
18
- onClick={on.click}
19
- >
20
- {props.label as string}
21
- </UIButton>
22
- );
23
- }
24
-
25
- ButtonWidget.widgetMeta = {
26
- name: 'button',
27
- label: 'Button',
28
- category: 'action' as const,
29
- schema: {
30
- label: { type: 'string' as const, required: true },
31
- variant: {
32
- type: 'enum' as const,
33
- options: ['primary', 'secondary', 'ghost', 'destructive'],
34
- default: 'secondary',
35
- },
36
- size: { type: 'enum' as const, options: ['sm', 'md', 'lg'], default: 'md' },
37
- disabled: { type: 'boolean' as const, default: false },
38
- loading: { type: 'boolean' as const, default: false },
39
- },
40
- binding: 'none' as const,
41
- triggers: ['click'],
42
- container: false,
43
- };
@@ -1,68 +0,0 @@
1
- import React from 'react';
2
- import {
3
- Card,
4
- CardHeader,
5
- CardTitle,
6
- CardDescription,
7
- CardAction,
8
- CardContent,
9
- CardFooter,
10
- } from '@/components/ui/card';
11
- import { WidgetRenderer } from '../renderer/WidgetRenderer.js';
12
- import { SurfaceProvider } from '../hooks/useSurfaceContext.js';
13
- import type { WidgetNode } from '@rangka/shared';
14
- import type { WidgetProps } from '../types.js';
15
-
16
- export function CardWidget({ props, children }: WidgetProps) {
17
- const title = props.title as string | undefined;
18
- const description = props.description as string | undefined;
19
- const size = (props.size as 'default' | 'sm') ?? 'default';
20
- const actions = props.actions as WidgetNode[] | undefined;
21
- const footer = props.footer as WidgetNode[] | undefined;
22
-
23
- return (
24
- <Card size={size}>
25
- {(title || description || actions) && (
26
- <CardHeader>
27
- {title && <CardTitle>{title}</CardTitle>}
28
- {description && <CardDescription>{description}</CardDescription>}
29
- {actions && actions.length > 0 && (
30
- <CardAction>
31
- <div className="flex items-center gap-2">
32
- {actions.map((node, i) => (
33
- <WidgetRenderer key={node.id ?? i} node={node} />
34
- ))}
35
- </div>
36
- </CardAction>
37
- )}
38
- </CardHeader>
39
- )}
40
- <CardContent>
41
- <SurfaceProvider value="card">{children}</SurfaceProvider>
42
- </CardContent>
43
- {footer && footer.length > 0 && (
44
- <CardFooter>
45
- {footer.map((node, i) => (
46
- <WidgetRenderer key={node.id ?? i} node={node} />
47
- ))}
48
- </CardFooter>
49
- )}
50
- </Card>
51
- );
52
- }
53
-
54
- CardWidget.widgetMeta = {
55
- name: 'card',
56
- label: 'Card',
57
- category: 'layout' as const,
58
- schema: {
59
- title: { type: 'string' as const },
60
- description: { type: 'string' as const },
61
- size: { type: 'enum' as const, options: ['default', 'sm'], default: 'default' },
62
- actions: { type: 'array' as const },
63
- footer: { type: 'array' as const },
64
- },
65
- binding: 'none' as const,
66
- triggers: [],
67
- container: true,
68
- };
@@ -1,39 +0,0 @@
1
- import React from 'react';
2
- import { Checkbox } from '@/components/ui/checkbox';
3
- import type { WidgetProps } from '../types.js';
4
-
5
- export function CheckboxWidget({ props, bind, on }: WidgetProps) {
6
- const label = (props.label as string) ?? bind.meta?.label ?? '';
7
- const disabled = (props.disabled as boolean) ?? bind.meta?.readOnly ?? false;
8
- const error = bind.error;
9
-
10
- return (
11
- <div className="flex flex-col gap-1">
12
- <div className="flex items-center gap-2">
13
- <Checkbox
14
- checked={(bind.value as boolean) ?? false}
15
- onCheckedChange={(checked) => {
16
- bind.setValue?.(checked);
17
- on.change?.(checked);
18
- }}
19
- disabled={disabled}
20
- />
21
- {label && <span className="text-sm text-foreground">{label}</span>}
22
- </div>
23
- {error && <p className="text-xs text-destructive">{error}</p>}
24
- </div>
25
- );
26
- }
27
-
28
- CheckboxWidget.widgetMeta = {
29
- name: 'checkbox',
30
- label: 'Checkbox',
31
- category: 'input' as const,
32
- schema: {
33
- label: { type: 'string' as const },
34
- disabled: { type: 'boolean' as const, default: false },
35
- },
36
- binding: 'field' as const,
37
- triggers: ['change'],
38
- container: false,
39
- };
@@ -1,44 +0,0 @@
1
- import React from 'react';
2
- import { Textarea } from '@/components/ui/textarea';
3
- import { Field, FieldLabel } from '@/components/ui/field';
4
- import type { WidgetProps } from '../types.js';
5
-
6
- export function CodeWidget({ props, bind, on }: WidgetProps) {
7
- const label = (props.label as string) ?? bind.meta?.label ?? '';
8
- const rows = (props.rows as number) ?? 6;
9
- const disabled = (props.disabled as boolean) ?? bind.meta?.readOnly ?? false;
10
-
11
- return (
12
- <Field>
13
- {label && <FieldLabel>{label}</FieldLabel>}
14
- <Textarea
15
- value={(bind.value as string) ?? ''}
16
- onChange={(e) => {
17
- bind.setValue?.(e.target.value);
18
- on.change?.(e.target.value);
19
- }}
20
- onFocus={() => on.focus?.()}
21
- onBlur={() => on.blur?.()}
22
- rows={rows}
23
- disabled={disabled}
24
- className="font-mono text-xs"
25
- spellCheck={false}
26
- />
27
- </Field>
28
- );
29
- }
30
-
31
- CodeWidget.widgetMeta = {
32
- name: 'code',
33
- label: 'Code',
34
- category: 'input' as const,
35
- schema: {
36
- label: { type: 'string' as const },
37
- language: { type: 'string' as const },
38
- rows: { type: 'number' as const, default: 6 },
39
- disabled: { type: 'boolean' as const, default: false },
40
- },
41
- binding: 'field' as const,
42
- triggers: ['change', 'focus', 'blur'],
43
- container: false,
44
- };
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
- import type { WidgetProps } from '../types.js';
3
-
4
- export function ColumnWidget({ children }: WidgetProps) {
5
- return <>{children}</>;
6
- }
7
-
8
- ColumnWidget.widgetMeta = {
9
- name: 'column',
10
- label: 'Column',
11
- category: 'layout' as const,
12
- schema: {
13
- label: { type: 'string' as const, required: true },
14
- width: { type: 'string' as const },
15
- align: { type: 'enum' as const, options: ['left', 'center', 'right'], default: 'left' },
16
- sortable: { type: 'boolean' as const },
17
- filterable: { type: 'boolean' as const },
18
- },
19
- binding: 'none' as const,
20
- triggers: [],
21
- container: true,
22
- };
@@ -1,49 +0,0 @@
1
- import React from 'react';
2
- import { Field, FieldLabel } from '@/components/ui/field';
3
- import type { WidgetProps } from '../types.js';
4
-
5
- export function ComputedWidget({ props, bind }: WidgetProps) {
6
- const label = (props.label as string) ?? bind.meta?.label ?? '';
7
- const format = (props.format as string) ?? 'text';
8
- const value = bind.value;
9
-
10
- const formatValue = (val: unknown): string => {
11
- if (val == null) return '—';
12
- if (format === 'number' && typeof val === 'number') {
13
- return val.toLocaleString();
14
- }
15
- if (format === 'currency' && typeof val === 'number') {
16
- return val.toFixed(2);
17
- }
18
- if (format === 'date' && typeof val === 'string') {
19
- return new Date(val).toLocaleDateString();
20
- }
21
- return String(val);
22
- };
23
-
24
- return (
25
- <Field>
26
- {label && <FieldLabel>{label}</FieldLabel>}
27
- <div className="flex items-center h-7 text-sm" data-testid="computed-value">
28
- {formatValue(value)}
29
- </div>
30
- </Field>
31
- );
32
- }
33
-
34
- ComputedWidget.widgetMeta = {
35
- name: 'computed',
36
- label: 'Computed',
37
- category: 'display' as const,
38
- schema: {
39
- label: { type: 'string' as const },
40
- format: {
41
- type: 'enum' as const,
42
- options: ['text', 'number', 'currency', 'date'],
43
- default: 'text',
44
- },
45
- },
46
- binding: 'field' as const,
47
- triggers: [],
48
- container: false,
49
- };