@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,73 +0,0 @@
1
- import React, { useState, useCallback, useMemo, useRef } from 'react';
2
- import type { WidgetNode } from '@rangka/shared';
3
- import { SlotRenderer } from '../renderer/SlotRenderer.js';
4
- import { StateStore } from '../state/store.js';
5
- import { createRootContext } from '../context/builder.js';
6
- import { useActionHandlers } from './useActionHandlers.js';
7
- import type { UseActionHandlersOptions } from './useActionHandlers.js';
8
- import type { FieldMeta } from '../binding/resolver.js';
9
-
10
- export interface WidgetSlotRendererProps {
11
- nodes: WidgetNode[];
12
- record?: Record<string, unknown>;
13
- model?: string;
14
- mode?: 'view' | 'edit';
15
- fieldMeta?: Record<string, FieldMeta>;
16
- sourceQueryKey?: unknown[];
17
- onRecordChange?: (record: Record<string, unknown>) => void;
18
- }
19
-
20
- export function WidgetSlotRenderer({
21
- nodes,
22
- record: initialRecord,
23
- model,
24
- mode = 'view',
25
- fieldMeta,
26
- sourceQueryKey,
27
- onRecordChange,
28
- }: WidgetSlotRendererProps) {
29
- const [record, setRecord] = useState<Record<string, unknown>>(initialRecord ?? {});
30
- const recordRef = useRef(record);
31
- recordRef.current = record;
32
- const state = useMemo(() => new StateStore(), []);
33
-
34
- const handlerOptions: UseActionHandlersOptions = useMemo(
35
- () => ({ model, sourceQueryKey }),
36
- [model, sourceQueryKey],
37
- );
38
- const actionHandlers = useActionHandlers(handlerOptions);
39
-
40
- const setValue = useCallback(
41
- (field: string, value: unknown) => {
42
- const next = { ...recordRef.current, [field]: value };
43
- recordRef.current = next;
44
- setRecord(next);
45
- onRecordChange?.(next);
46
- },
47
- [onRecordChange],
48
- );
49
-
50
- const handlersWithRecord = useMemo(
51
- () => ({
52
- ...actionHandlers,
53
- setRecordValue: setValue,
54
- }),
55
- [actionHandlers, setValue],
56
- );
57
-
58
- const context = useMemo(
59
- () => createRootContext(record, model ?? '', mode),
60
- [record, model, mode],
61
- );
62
-
63
- return (
64
- <SlotRenderer
65
- nodes={nodes}
66
- context={context}
67
- state={state}
68
- handlers={handlersWithRecord}
69
- fieldMeta={fieldMeta}
70
- setValue={setValue}
71
- />
72
- );
73
- }
@@ -1,4 +0,0 @@
1
- export { WidgetSlotRenderer } from './WidgetSlotRenderer.js';
2
- export { useActionHandlers } from './useActionHandlers.js';
3
- export type { UseActionHandlersOptions } from './useActionHandlers.js';
4
- export type { WidgetSlotRendererProps } from './WidgetSlotRenderer.js';
@@ -1,170 +0,0 @@
1
- import { useCallback, useMemo } from 'react';
2
- import { useQueryClient } from '@tanstack/react-query';
3
- import { apiClient } from '../../api/client.js';
4
- import { modelToPath } from '../../api/paths.js';
5
- import { useNavigate } from '../../router/hooks.js';
6
- import type { ActionHandlers } from '../action/dispatcher.js';
7
-
8
- export interface UseActionHandlersOptions {
9
- model?: string;
10
- sourceQueryKey?: unknown[];
11
- }
12
-
13
- export function useActionHandlers(options: UseActionHandlersOptions = {}): ActionHandlers {
14
- const navigate = useNavigate();
15
- const queryClient = useQueryClient();
16
-
17
- const handleNavigate = useCallback(
18
- (path: string) => {
19
- navigate(path);
20
- },
21
- [navigate],
22
- );
23
-
24
- const handleService = useCallback(
25
- async (name: string, params: Record<string, unknown>): Promise<Record<string, unknown>> => {
26
- const response = await apiClient(`/api/services/${name}`, {
27
- method: 'POST',
28
- body: JSON.stringify(params),
29
- });
30
- if (!response.ok) {
31
- const err = await response.json().catch(() => ({ message: 'Service call failed' }));
32
- throw new Error(err.message ?? 'Service call failed');
33
- }
34
- return response.json();
35
- },
36
- [],
37
- );
38
-
39
- const handleRefreshSource = useCallback(() => {
40
- if (options.sourceQueryKey) {
41
- queryClient.invalidateQueries({ queryKey: options.sourceQueryKey });
42
- } else if (options.model) {
43
- queryClient.invalidateQueries({ queryKey: ['model', options.model] });
44
- }
45
- }, [queryClient, options.sourceQueryKey, options.model]);
46
-
47
- const handleFocus = useCallback((field: string) => {
48
- const el = document.querySelector(`[data-field="${field}"]`) as HTMLElement | null;
49
- el?.focus();
50
- }, []);
51
-
52
- const handleValidate = useCallback(async (_fields?: string[]): Promise<boolean> => {
53
- return true;
54
- }, []);
55
-
56
- const handleModelCreate = useCallback(
57
- async (model: string, data: Record<string, unknown>): Promise<Record<string, unknown>> => {
58
- const path = modelToPath(model);
59
- const response = await apiClient(path, {
60
- method: 'POST',
61
- body: JSON.stringify(data),
62
- });
63
- if (!response.ok) {
64
- const err = await response.json().catch(() => ({ message: 'Create failed' }));
65
- throw new Error(err.message ?? 'Create failed');
66
- }
67
- const result = await response.json();
68
- queryClient.invalidateQueries({ queryKey: ['model', model] });
69
- return result;
70
- },
71
- [queryClient],
72
- );
73
-
74
- const handleModelUpdate = useCallback(
75
- async (
76
- model: string,
77
- id: string,
78
- data: Record<string, unknown>,
79
- ): Promise<Record<string, unknown>> => {
80
- const path = `${modelToPath(model)}/${id}`;
81
- const response = await apiClient(path, {
82
- method: 'PUT',
83
- body: JSON.stringify(data),
84
- });
85
- if (!response.ok) {
86
- const err = await response.json().catch(() => ({ message: 'Update failed' }));
87
- throw new Error(err.message ?? 'Update failed');
88
- }
89
- const result = await response.json();
90
- queryClient.invalidateQueries({ queryKey: ['model', model] });
91
- return result;
92
- },
93
- [queryClient],
94
- );
95
-
96
- const handleModelDelete = useCallback(
97
- async (model: string, id: string): Promise<void> => {
98
- const path = `${modelToPath(model)}/${id}`;
99
- const response = await apiClient(path, { method: 'DELETE' });
100
- if (!response.ok) {
101
- const err = await response.json().catch(() => ({ message: 'Delete failed' }));
102
- throw new Error(err.message ?? 'Delete failed');
103
- }
104
- queryClient.invalidateQueries({ queryKey: ['model', model] });
105
- },
106
- [queryClient],
107
- );
108
-
109
- const handleModelFetch = useCallback(
110
- async (model: string, id: string): Promise<Record<string, unknown>> => {
111
- const path = `${modelToPath(model)}/${id}`;
112
- const response = await apiClient(path);
113
- if (!response.ok) {
114
- const err = await response.json().catch(() => ({ message: 'Fetch failed' }));
115
- throw new Error(err.message ?? 'Fetch failed');
116
- }
117
- return response.json();
118
- },
119
- [],
120
- );
121
-
122
- const handleModelList = useCallback(
123
- async (
124
- model: string,
125
- filters?: Record<string, unknown>,
126
- ): Promise<Record<string, unknown>[]> => {
127
- const url = new URL(modelToPath(model), window.location.origin);
128
- if (filters) {
129
- for (const [key, value] of Object.entries(filters)) {
130
- url.searchParams.set(`filter[${key}]`, String(value));
131
- }
132
- }
133
- const response = await apiClient(url.pathname + url.search);
134
- if (!response.ok) {
135
- const err = await response.json().catch(() => ({ message: 'List failed' }));
136
- throw new Error(err.message ?? 'List failed');
137
- }
138
- const result = await response.json();
139
- return Array.isArray(result) ? result : (result.data ?? []);
140
- },
141
- [],
142
- );
143
-
144
- return useMemo(
145
- () => ({
146
- navigate: handleNavigate,
147
- service: handleService,
148
- refreshSource: handleRefreshSource,
149
- focus: handleFocus,
150
- validate: handleValidate,
151
- modelCreate: handleModelCreate,
152
- modelUpdate: handleModelUpdate,
153
- modelDelete: handleModelDelete,
154
- modelFetch: handleModelFetch,
155
- modelList: handleModelList,
156
- }),
157
- [
158
- handleNavigate,
159
- handleService,
160
- handleRefreshSource,
161
- handleFocus,
162
- handleValidate,
163
- handleModelCreate,
164
- handleModelUpdate,
165
- handleModelDelete,
166
- handleModelFetch,
167
- handleModelList,
168
- ],
169
- );
170
- }
@@ -1,2 +0,0 @@
1
- export { StateStore } from './store.js';
2
- export type { Subscriber } from './store.js';
@@ -1,96 +0,0 @@
1
- export type Subscriber = (value: unknown) => void;
2
- export type StoreListener = () => void;
3
-
4
- export class StateStore {
5
- private state: Map<string, unknown> = new Map();
6
- private subscribers: Map<string, Set<Subscriber>> = new Map();
7
- private listeners: Set<StoreListener> = new Set();
8
- private version = 0;
9
-
10
- get(key: string): unknown {
11
- return this.state.get(key);
12
- }
13
-
14
- set(key: string, value: unknown): void {
15
- const prev = this.state.get(key);
16
- if (prev === value) return;
17
- this.state.set(key, value);
18
- this.version++;
19
- this.notify(key, value);
20
- this.notifyListeners();
21
- }
22
-
23
- setMany(entries: Record<string, unknown>): void {
24
- const changed: [string, unknown][] = [];
25
- for (const [key, value] of Object.entries(entries)) {
26
- const prev = this.state.get(key);
27
- if (prev !== value) {
28
- this.state.set(key, value);
29
- changed.push([key, value]);
30
- }
31
- }
32
- if (changed.length > 0) {
33
- this.version++;
34
- for (const [key, value] of changed) {
35
- this.notify(key, value);
36
- }
37
- this.notifyListeners();
38
- }
39
- }
40
-
41
- subscribe(key: string, fn: Subscriber): () => void {
42
- let subs = this.subscribers.get(key);
43
- if (!subs) {
44
- subs = new Set();
45
- this.subscribers.set(key, subs);
46
- }
47
- subs.add(fn);
48
- return () => {
49
- subs!.delete(fn);
50
- if (subs!.size === 0) {
51
- this.subscribers.delete(key);
52
- }
53
- };
54
- }
55
-
56
- onchange(fn: StoreListener): () => void {
57
- this.listeners.add(fn);
58
- return () => {
59
- this.listeners.delete(fn);
60
- };
61
- }
62
-
63
- getVersion(): number {
64
- return this.version;
65
- }
66
-
67
- clear(): void {
68
- this.state.clear();
69
- this.subscribers.clear();
70
- this.listeners.clear();
71
- this.version = 0;
72
- }
73
-
74
- keys(): string[] {
75
- return [...this.state.keys()];
76
- }
77
-
78
- snapshot(): Record<string, unknown> {
79
- return Object.fromEntries(this.state);
80
- }
81
-
82
- private notify(key: string, value: unknown): void {
83
- const subs = this.subscribers.get(key);
84
- if (subs) {
85
- for (const fn of subs) {
86
- fn(value);
87
- }
88
- }
89
- }
90
-
91
- private notifyListeners(): void {
92
- for (const fn of this.listeners) {
93
- fn();
94
- }
95
- }
96
- }
@@ -1,28 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { WidgetNode } from '@rangka/shared';
3
-
4
- export interface WidgetProps {
5
- props: Record<string, unknown>;
6
- bind: {
7
- value: unknown;
8
- setValue?: (val: unknown) => void;
9
- meta?: {
10
- type: string;
11
- label: string;
12
- required: boolean;
13
- options?: unknown[];
14
- readOnly: boolean;
15
- };
16
- error?: string;
17
- id?: string;
18
- };
19
- on: Record<string, (...args: unknown[]) => void>;
20
- context: {
21
- record: Record<string, unknown>;
22
- model: string;
23
- mode: 'view' | 'edit';
24
- index?: number;
25
- };
26
- childNodes?: WidgetNode[];
27
- children?: ReactNode;
28
- }
@@ -1,2 +0,0 @@
1
- export { validateWidgetTree } from './validator.js';
2
- export type { ValidationError } from './validator.js';
@@ -1,140 +0,0 @@
1
- import type { WidgetNode, WidgetDefinitionMeta } from '@rangka/shared';
2
-
3
- export interface ValidationError {
4
- path: string;
5
- message: string;
6
- }
7
-
8
- export function validateWidgetTree(
9
- nodes: WidgetNode[],
10
- registry: Map<string, WidgetDefinitionMeta>,
11
- parentPath: string = '',
12
- ): ValidationError[] {
13
- const errors: ValidationError[] = [];
14
-
15
- nodes.forEach((node, index) => {
16
- const path = parentPath ? `${parentPath}[${index}]` : `[${index}]`;
17
- const def = registry.get(node.type);
18
-
19
- if (!def) {
20
- errors.push({ path, message: `Unknown widget type: '${node.type}'` });
21
- return;
22
- }
23
-
24
- if (node.children && node.children.length > 0) {
25
- if (!def.container) {
26
- errors.push({ path, message: `Widget '${node.type}' is not a container but has children` });
27
- } else if (def.accepts) {
28
- for (let i = 0; i < node.children.length; i++) {
29
- const child = node.children[i];
30
- if (!def.accepts.includes(child.type)) {
31
- errors.push({
32
- path: `${path}.children[${i}]`,
33
- message: `Widget '${node.type}' does not accept child type '${child.type}'. Allowed: ${def.accepts.join(', ')}`,
34
- });
35
- }
36
- }
37
- }
38
- }
39
-
40
- if (node.props) {
41
- for (const [key, value] of Object.entries(node.props)) {
42
- const propDef = def.schema[key];
43
- if (!propDef) {
44
- errors.push({
45
- path: `${path}.props.${key}`,
46
- message: `Unknown prop '${key}' on widget '${node.type}'`,
47
- });
48
- continue;
49
- }
50
- if (typeof value === 'string' && value.includes('{{')) {
51
- continue;
52
- }
53
- if (!validatePropType(value, propDef.type, propDef.options)) {
54
- errors.push({
55
- path: `${path}.props.${key}`,
56
- message: `Invalid value for prop '${key}': expected ${propDef.type}${propDef.options ? ` (${propDef.options.join(' | ')})` : ''}`,
57
- });
58
- }
59
- }
60
-
61
- for (const [key, propDef] of Object.entries(def.schema)) {
62
- if (propDef.required && !(key in node.props) && propDef.default === undefined) {
63
- errors.push({
64
- path: `${path}.props`,
65
- message: `Missing required prop '${key}' on widget '${node.type}'`,
66
- });
67
- }
68
- }
69
- } else {
70
- for (const [key, propDef] of Object.entries(def.schema)) {
71
- if (propDef.required && propDef.default === undefined) {
72
- errors.push({
73
- path: `${path}.props`,
74
- message: `Missing required prop '${key}' on widget '${node.type}'`,
75
- });
76
- }
77
- }
78
- }
79
-
80
- if (node.on) {
81
- for (const trigger of Object.keys(node.on)) {
82
- if (!def.triggers.includes(trigger)) {
83
- errors.push({
84
- path: `${path}.on.${trigger}`,
85
- message: `Unknown trigger '${trigger}' on widget '${node.type}'. Available: ${def.triggers.join(', ') || 'none'}`,
86
- });
87
- }
88
- }
89
- }
90
-
91
- if (node.bind) {
92
- const bindMode = getBindMode(node.bind);
93
- if (bindMode !== def.binding && def.binding !== 'none') {
94
- if (bindMode !== def.binding) {
95
- errors.push({
96
- path: `${path}.bind`,
97
- message: `Widget '${node.type}' expects binding mode '${def.binding}' but got '${bindMode}'`,
98
- });
99
- }
100
- } else if (def.binding === 'none' && bindMode !== 'none') {
101
- errors.push({
102
- path: `${path}.bind`,
103
- message: `Widget '${node.type}' does not support data binding`,
104
- });
105
- }
106
- }
107
-
108
- if (node.children) {
109
- errors.push(...validateWidgetTree(node.children, registry, `${path}.children`));
110
- }
111
- });
112
-
113
- return errors;
114
- }
115
-
116
- function getBindMode(bind: { field?: string; expression?: string; model?: unknown }): string {
117
- if (bind.field) return 'field';
118
- if (bind.expression) return 'expression';
119
- if (bind.model) return 'model';
120
- return 'none';
121
- }
122
-
123
- function validatePropType(value: unknown, type: string, options?: string[]): boolean {
124
- switch (type) {
125
- case 'string':
126
- return typeof value === 'string';
127
- case 'number':
128
- return typeof value === 'number';
129
- case 'boolean':
130
- return typeof value === 'boolean';
131
- case 'enum':
132
- return typeof value === 'string' && (options ? options.includes(value) : true);
133
- case 'object':
134
- return typeof value === 'object' && value !== null;
135
- case 'array':
136
- return Array.isArray(value);
137
- default:
138
- return true;
139
- }
140
- }
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "resolveJsonModule": true,
12
- "isolatedModules": true,
13
- "declaration": true,
14
- "declarationMap": true,
15
- "sourceMap": true,
16
- "composite": true,
17
- "outDir": "dist",
18
- "rootDir": "src",
19
- "jsx": "react-jsx",
20
- "paths": {
21
- "@/*": ["./src/*"]
22
- }
23
- },
24
- "include": ["src"],
25
- "exclude": ["src/__tests__", "src/**/__tests__"],
26
- "references": [{ "path": "../shared" }]
27
- }