@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,139 +0,0 @@
|
|
|
1
|
-
import type { WidgetNode, Condition } from '@rangka/shared';
|
|
2
|
-
import { parse } from '../expression/parser.js';
|
|
3
|
-
import type { AstNode } from '../expression/types.js';
|
|
4
|
-
|
|
5
|
-
export interface DependencyMap {
|
|
6
|
-
fields: Map<string, Set<string>>;
|
|
7
|
-
state: Map<string, Set<string>>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function buildDependencyMap(nodes: WidgetNode[], parentPath: string = ''): DependencyMap {
|
|
11
|
-
const fields = new Map<string, Set<string>>();
|
|
12
|
-
const state = new Map<string, Set<string>>();
|
|
13
|
-
|
|
14
|
-
function addDep(map: Map<string, Set<string>>, key: string, widgetId: string): void {
|
|
15
|
-
let set = map.get(key);
|
|
16
|
-
if (!set) {
|
|
17
|
-
set = new Set();
|
|
18
|
-
map.set(key, set);
|
|
19
|
-
}
|
|
20
|
-
set.add(widgetId);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function walkNodes(nodes: WidgetNode[], path: string): void {
|
|
24
|
-
nodes.forEach((node, index) => {
|
|
25
|
-
const widgetId = node.id ?? `${path}[${index}]`;
|
|
26
|
-
|
|
27
|
-
if (node.bind?.field) {
|
|
28
|
-
addDep(fields, node.bind.field, widgetId);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (node.bind?.expression) {
|
|
32
|
-
const deps = extractDepsFromExpression(node.bind.expression);
|
|
33
|
-
for (const dep of deps.fields) addDep(fields, dep, widgetId);
|
|
34
|
-
for (const dep of deps.state) addDep(state, dep, widgetId);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (node.visible) {
|
|
38
|
-
const conditions = Array.isArray(node.visible) ? node.visible : [node.visible];
|
|
39
|
-
for (const condition of conditions) {
|
|
40
|
-
const deps = extractDepsFromCondition(condition);
|
|
41
|
-
for (const dep of deps.fields) addDep(fields, dep, widgetId);
|
|
42
|
-
for (const dep of deps.state) addDep(state, dep, widgetId);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (node.props) {
|
|
47
|
-
for (const value of Object.values(node.props)) {
|
|
48
|
-
if (typeof value === 'string' && value.includes('{{')) {
|
|
49
|
-
const deps = extractDepsFromExpression(value);
|
|
50
|
-
for (const dep of deps.fields) addDep(fields, dep, widgetId);
|
|
51
|
-
for (const dep of deps.state) addDep(state, dep, widgetId);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (node.children) {
|
|
57
|
-
walkNodes(node.children, `${widgetId}.children`);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
walkNodes(nodes, parentPath);
|
|
63
|
-
return { fields, state };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function getAffectedWidgets(
|
|
67
|
-
depMap: DependencyMap,
|
|
68
|
-
key: string,
|
|
69
|
-
isState: boolean,
|
|
70
|
-
): Set<string> {
|
|
71
|
-
const map = isState ? depMap.state : depMap.fields;
|
|
72
|
-
return map.get(key) ?? new Set();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
interface ExtractedDeps {
|
|
76
|
-
fields: string[];
|
|
77
|
-
state: string[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function extractDepsFromExpression(expr: string): ExtractedDeps {
|
|
81
|
-
const fields: string[] = [];
|
|
82
|
-
const state: string[] = [];
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
const ast = parse(expr);
|
|
86
|
-
walkAst(ast, fields, state);
|
|
87
|
-
} catch {
|
|
88
|
-
// skip unparseable expressions
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return { fields, state };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function extractDepsFromCondition(condition: Condition): ExtractedDeps {
|
|
95
|
-
const fields: string[] = [];
|
|
96
|
-
const state: string[] = [];
|
|
97
|
-
|
|
98
|
-
const field = condition.field;
|
|
99
|
-
if (field.startsWith('$state.')) {
|
|
100
|
-
state.push(field.slice(7));
|
|
101
|
-
} else if (!field.startsWith('$')) {
|
|
102
|
-
fields.push(field.split('.')[0]);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (typeof condition.value === 'string' && condition.value.includes('{{')) {
|
|
106
|
-
const deps = extractDepsFromExpression(condition.value);
|
|
107
|
-
fields.push(...deps.fields);
|
|
108
|
-
state.push(...deps.state);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return { fields, state };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function walkAst(node: AstNode, fields: string[], state: string[]): void {
|
|
115
|
-
switch (node.type) {
|
|
116
|
-
case 'field': {
|
|
117
|
-
if (node.path[0] === '$state' && node.path.length > 1) {
|
|
118
|
-
state.push(node.path[1]);
|
|
119
|
-
} else if (!node.path[0].startsWith('$')) {
|
|
120
|
-
fields.push(node.path[0]);
|
|
121
|
-
}
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
case 'binary':
|
|
125
|
-
walkAst(node.left, fields, state);
|
|
126
|
-
walkAst(node.right, fields, state);
|
|
127
|
-
break;
|
|
128
|
-
case 'unary':
|
|
129
|
-
walkAst(node.operand, fields, state);
|
|
130
|
-
break;
|
|
131
|
-
case 'call':
|
|
132
|
-
for (const arg of node.args) {
|
|
133
|
-
walkAst(arg, fields, state);
|
|
134
|
-
}
|
|
135
|
-
break;
|
|
136
|
-
case 'literal':
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reactive variable parsing helpers for $filter, $sort, $page namespaces.
|
|
3
|
-
*
|
|
4
|
-
* These variables are stored in the same flat StateStore as $state keys.
|
|
5
|
-
* The store keys use the full prefix (e.g. "$filter.sales.order.status__gt").
|
|
6
|
-
* These helpers parse those keys into structured query parameters.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export type FilterOperator =
|
|
10
|
-
| 'eq'
|
|
11
|
-
| 'in'
|
|
12
|
-
| 'gt'
|
|
13
|
-
| 'gte'
|
|
14
|
-
| 'lt'
|
|
15
|
-
| 'lte'
|
|
16
|
-
| 'like'
|
|
17
|
-
| 'empty'
|
|
18
|
-
| 'not_empty';
|
|
19
|
-
|
|
20
|
-
export interface ParsedFilterKey {
|
|
21
|
-
model: string;
|
|
22
|
-
field: string;
|
|
23
|
-
operator: FilterOperator;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface ParsedFilter {
|
|
27
|
-
model: string;
|
|
28
|
-
field: string;
|
|
29
|
-
operator: FilterOperator;
|
|
30
|
-
value: unknown;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface SortEntry {
|
|
34
|
-
field: string;
|
|
35
|
-
direction: 'asc' | 'desc';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const OPERATOR_SUFFIXES: Record<string, FilterOperator> = {
|
|
39
|
-
__gt: 'gt',
|
|
40
|
-
__gte: 'gte',
|
|
41
|
-
__lt: 'lt',
|
|
42
|
-
__lte: 'lte',
|
|
43
|
-
__like: 'like',
|
|
44
|
-
__empty: 'empty',
|
|
45
|
-
__not_empty: 'not_empty',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const FILTER_PREFIX = '$filter.';
|
|
49
|
-
const SORT_PREFIX = '$sort.';
|
|
50
|
-
const PAGE_PREFIX = '$page.';
|
|
51
|
-
const SEARCH_PREFIX = '$search.';
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Parse a $filter key into its model, field, and operator components.
|
|
55
|
-
*
|
|
56
|
-
* Key format: $filter.{module}.{model}.{field}[__{op}]
|
|
57
|
-
* The model is the first two dot-separated segments after $filter (module.model).
|
|
58
|
-
* The field is the remaining segment, optionally with an operator suffix.
|
|
59
|
-
*
|
|
60
|
-
* Examples:
|
|
61
|
-
* "$filter.sales.order.status" -> { model: "sales.order", field: "status", operator: "eq" }
|
|
62
|
-
* "$filter.sales.order.total__gt" -> { model: "sales.order", field: "total", operator: "gt" }
|
|
63
|
-
* "$filter.sales.order.deleted_at__empty" -> { model: "sales.order", field: "deleted_at", operator: "empty" }
|
|
64
|
-
*/
|
|
65
|
-
export function parseFilterKey(key: string): ParsedFilterKey | null {
|
|
66
|
-
if (!key.startsWith(FILTER_PREFIX)) return null;
|
|
67
|
-
|
|
68
|
-
const rest = key.slice(FILTER_PREFIX.length);
|
|
69
|
-
// Need at least module.model.field = 3 dot-separated segments
|
|
70
|
-
const parts = rest.split('.');
|
|
71
|
-
if (parts.length < 3) return null;
|
|
72
|
-
|
|
73
|
-
// Model is first two segments (module.model)
|
|
74
|
-
const model = `${parts[0]}.${parts[1]}`;
|
|
75
|
-
|
|
76
|
-
// Field is the remaining segments joined (supports dotted field names, though unusual)
|
|
77
|
-
let fieldPart = parts.slice(2).join('.');
|
|
78
|
-
|
|
79
|
-
// Check for operator suffix (longest match first)
|
|
80
|
-
let operator: FilterOperator = 'eq';
|
|
81
|
-
for (const [suffix, op] of Object.entries(OPERATOR_SUFFIXES)) {
|
|
82
|
-
if (fieldPart.endsWith(suffix)) {
|
|
83
|
-
operator = op;
|
|
84
|
-
fieldPart = fieldPart.slice(0, -suffix.length);
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!fieldPart) return null;
|
|
90
|
-
|
|
91
|
-
return { model, field: fieldPart, operator };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Get all active filters for a given model from the state store.
|
|
96
|
-
* Reads all keys starting with $filter.{model}. and parses them.
|
|
97
|
-
*/
|
|
98
|
-
export function getFiltersForModel(state: Map<string, unknown>, model: string): ParsedFilter[] {
|
|
99
|
-
const prefix = `${FILTER_PREFIX}${model}.`;
|
|
100
|
-
const filters: ParsedFilter[] = [];
|
|
101
|
-
|
|
102
|
-
for (const [key, value] of state) {
|
|
103
|
-
if (!key.startsWith(prefix)) continue;
|
|
104
|
-
// Skip null/undefined values (cleared filters)
|
|
105
|
-
if (value === null || value === undefined) continue;
|
|
106
|
-
|
|
107
|
-
const parsed = parseFilterKey(key);
|
|
108
|
-
if (!parsed) continue;
|
|
109
|
-
|
|
110
|
-
// Determine operator: if no suffix but value is an array, use 'in'
|
|
111
|
-
let operator = parsed.operator;
|
|
112
|
-
if (operator === 'eq' && Array.isArray(value)) {
|
|
113
|
-
operator = 'in';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
filters.push({
|
|
117
|
-
model: parsed.model,
|
|
118
|
-
field: parsed.field,
|
|
119
|
-
operator,
|
|
120
|
-
value,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return filters;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Get the sort configuration for a model.
|
|
129
|
-
* The sort value is a comma-separated string. Prefix '-' means descending.
|
|
130
|
-
*
|
|
131
|
-
* Examples:
|
|
132
|
-
* "-date" -> [{ field: "date", direction: "desc" }]
|
|
133
|
-
* "-date,name" -> [{ field: "date", direction: "desc" }, { field: "name", direction: "asc" }]
|
|
134
|
-
* null -> null (use model default)
|
|
135
|
-
*/
|
|
136
|
-
export function getSortForModel(state: Map<string, unknown>, model: string): SortEntry[] | null {
|
|
137
|
-
const key = `${SORT_PREFIX}${model}`;
|
|
138
|
-
const value = state.get(key);
|
|
139
|
-
|
|
140
|
-
if (value === null || value === undefined) return null;
|
|
141
|
-
if (typeof value !== 'string' || value.trim() === '') return null;
|
|
142
|
-
|
|
143
|
-
const entries: SortEntry[] = [];
|
|
144
|
-
const parts = value.split(',');
|
|
145
|
-
|
|
146
|
-
for (const part of parts) {
|
|
147
|
-
const trimmed = part.trim();
|
|
148
|
-
if (!trimmed) continue;
|
|
149
|
-
|
|
150
|
-
if (trimmed.startsWith('-')) {
|
|
151
|
-
entries.push({ field: trimmed.slice(1), direction: 'desc' });
|
|
152
|
-
} else {
|
|
153
|
-
entries.push({ field: trimmed, direction: 'asc' });
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return entries.length > 0 ? entries : null;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Get the current page number for a model.
|
|
162
|
-
* Returns null if not set (use default page 1).
|
|
163
|
-
*/
|
|
164
|
-
export function getPageForModel(state: Map<string, unknown>, model: string): number | null {
|
|
165
|
-
const key = `${PAGE_PREFIX}${model}`;
|
|
166
|
-
const value = state.get(key);
|
|
167
|
-
|
|
168
|
-
if (value === null || value === undefined) return null;
|
|
169
|
-
const num = Number(value);
|
|
170
|
-
return Number.isFinite(num) && num >= 1 ? Math.floor(num) : null;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Get the current search term for a model.
|
|
175
|
-
* Returns null if not set.
|
|
176
|
-
*/
|
|
177
|
-
export function getSearchForModel(state: Map<string, unknown>, model: string): string | null {
|
|
178
|
-
const key = `${SEARCH_PREFIX}${model}`;
|
|
179
|
-
const value = state.get(key);
|
|
180
|
-
if (value === null || value === undefined) return null;
|
|
181
|
-
const str = String(value).trim();
|
|
182
|
-
return str.length > 0 ? str : null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Check whether a store key belongs to one of the reactive variable namespaces.
|
|
187
|
-
*/
|
|
188
|
-
export function isReactiveVariableKey(key: string): 'filter' | 'sort' | 'page' | 'state' | null {
|
|
189
|
-
if (key.startsWith(FILTER_PREFIX)) return 'filter';
|
|
190
|
-
if (key.startsWith(SORT_PREFIX)) return 'sort';
|
|
191
|
-
if (key.startsWith(PAGE_PREFIX)) return 'page';
|
|
192
|
-
if (key.startsWith('$state.')) return 'state';
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Extract the model name from a $filter, $sort, or $page key.
|
|
198
|
-
* Returns null for $state or unrecognized keys.
|
|
199
|
-
*/
|
|
200
|
-
export function getModelFromKey(key: string): string | null {
|
|
201
|
-
if (key.startsWith(FILTER_PREFIX)) {
|
|
202
|
-
const rest = key.slice(FILTER_PREFIX.length);
|
|
203
|
-
const parts = rest.split('.');
|
|
204
|
-
return parts.length >= 2 ? `${parts[0]}.${parts[1]}` : null;
|
|
205
|
-
}
|
|
206
|
-
if (key.startsWith(SORT_PREFIX)) {
|
|
207
|
-
return key.slice(SORT_PREFIX.length) || null;
|
|
208
|
-
}
|
|
209
|
-
if (key.startsWith(PAGE_PREFIX)) {
|
|
210
|
-
return key.slice(PAGE_PREFIX.length) || null;
|
|
211
|
-
}
|
|
212
|
-
return null;
|
|
213
|
-
}
|
package/src/widgets/registry.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { WidgetDefinitionMeta } from '@rangka/shared';
|
|
2
|
-
import type { ComponentType } from 'react';
|
|
3
|
-
import type { WidgetProps } from './types.js';
|
|
4
|
-
|
|
5
|
-
export interface WidgetRegistryEntry {
|
|
6
|
-
meta: WidgetDefinitionMeta;
|
|
7
|
-
component: ComponentType<WidgetProps>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const widgets = new Map<string, WidgetRegistryEntry>();
|
|
11
|
-
|
|
12
|
-
export function registerWidget(
|
|
13
|
-
meta: WidgetDefinitionMeta,
|
|
14
|
-
component: ComponentType<WidgetProps>,
|
|
15
|
-
): void {
|
|
16
|
-
widgets.set(meta.name, { meta, component });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getWidget(name: string): WidgetRegistryEntry | undefined {
|
|
20
|
-
return widgets.get(name);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function getWidgetMeta(name: string): WidgetDefinitionMeta | undefined {
|
|
24
|
-
return widgets.get(name)?.meta;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getAllWidgetMeta(): WidgetDefinitionMeta[] {
|
|
28
|
-
return [...widgets.values()].map((e) => e.meta);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function getWidgetRegistry(): Map<string, WidgetDefinitionMeta> {
|
|
32
|
-
const map = new Map<string, WidgetDefinitionMeta>();
|
|
33
|
-
for (const [name, entry] of widgets) {
|
|
34
|
-
map.set(name, entry.meta);
|
|
35
|
-
}
|
|
36
|
-
return map;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function clearWidgetRegistry(): void {
|
|
40
|
-
widgets.clear();
|
|
41
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
import type { WidgetNode } from '@rangka/shared';
|
|
3
|
-
import type { ActionHandlers } from '../action/dispatcher.js';
|
|
4
|
-
import { WidgetContextProvider } from '../hooks/useWidgetContext.js';
|
|
5
|
-
import { PageStateProvider } from '../hooks/usePageState.js';
|
|
6
|
-
import { StateStore } from '../state/store.js';
|
|
7
|
-
import type { WidgetContext } from '../context/types.js';
|
|
8
|
-
import { createRootContext } from '../context/builder.js';
|
|
9
|
-
import { WidgetRenderer } from './WidgetRenderer.js';
|
|
10
|
-
import type { FieldMeta } from '../binding/resolver.js';
|
|
11
|
-
|
|
12
|
-
export interface SlotRendererProps {
|
|
13
|
-
nodes: WidgetNode[];
|
|
14
|
-
context?: WidgetContext;
|
|
15
|
-
state?: StateStore;
|
|
16
|
-
handlers?: ActionHandlers;
|
|
17
|
-
fieldMeta?: Record<string, FieldMeta>;
|
|
18
|
-
setValue?: (field: string, val: unknown) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function SlotRenderer({
|
|
22
|
-
nodes,
|
|
23
|
-
context,
|
|
24
|
-
state,
|
|
25
|
-
handlers = {},
|
|
26
|
-
fieldMeta,
|
|
27
|
-
setValue,
|
|
28
|
-
}: SlotRendererProps) {
|
|
29
|
-
const ctx = context ?? createRootContext({}, '', 'view');
|
|
30
|
-
const store = useMemo(() => state ?? new StateStore(), [state]);
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<PageStateProvider value={store}>
|
|
34
|
-
<WidgetContextProvider value={ctx}>
|
|
35
|
-
{nodes.map((node, index) => (
|
|
36
|
-
<WidgetRenderer
|
|
37
|
-
key={node.id ?? index}
|
|
38
|
-
node={node}
|
|
39
|
-
handlers={handlers}
|
|
40
|
-
fieldMeta={fieldMeta}
|
|
41
|
-
setValue={setValue}
|
|
42
|
-
/>
|
|
43
|
-
))}
|
|
44
|
-
</WidgetContextProvider>
|
|
45
|
-
</PageStateProvider>
|
|
46
|
-
);
|
|
47
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
import type { WidgetNode } from '@rangka/shared';
|
|
3
|
-
import type { ActionHandlers } from '../action/dispatcher.js';
|
|
4
|
-
import { getWidget } from '../registry.js';
|
|
5
|
-
import { useCondition } from '../hooks/useCondition.js';
|
|
6
|
-
import { useBind } from '../hooks/useBind.js';
|
|
7
|
-
import { useTriggerHandlers } from '../hooks/useAction.js';
|
|
8
|
-
import { useWidgetContext } from '../hooks/useWidgetContext.js';
|
|
9
|
-
import { WidgetContextProvider } from '../hooks/useWidgetContext.js';
|
|
10
|
-
import { buildContext } from '../context/builder.js';
|
|
11
|
-
import { flattenContext } from '../context/types.js';
|
|
12
|
-
import { parse, evaluate } from '../expression/index.js';
|
|
13
|
-
import { extractLayoutProps, hasLayoutProps, resolveLayoutClasses } from '../lib/layout-props.js';
|
|
14
|
-
import { useParams } from '../../router/hooks.js';
|
|
15
|
-
import type { FieldMeta } from '../binding/resolver.js';
|
|
16
|
-
import type { WidgetProps } from '../types.js';
|
|
17
|
-
|
|
18
|
-
function useRouteParams(): Record<string, string> {
|
|
19
|
-
try {
|
|
20
|
-
return useParams();
|
|
21
|
-
} catch {
|
|
22
|
-
return {};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface WidgetRendererProps {
|
|
27
|
-
node: WidgetNode;
|
|
28
|
-
handlers?: ActionHandlers;
|
|
29
|
-
fieldMeta?: Record<string, FieldMeta>;
|
|
30
|
-
setValue?: (field: string, val: unknown) => void;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function WidgetRenderer({ node, handlers = {}, fieldMeta, setValue }: WidgetRendererProps) {
|
|
34
|
-
const visible = useCondition(node.visible);
|
|
35
|
-
const parentCtx = useWidgetContext();
|
|
36
|
-
const routeParams = useRouteParams();
|
|
37
|
-
const binding = useBind(node.bind, fieldMeta, setValue);
|
|
38
|
-
const triggerHandlers = useTriggerHandlers(node.on, handlers, node.bind?.field);
|
|
39
|
-
|
|
40
|
-
const resolvedProps = useResolvedProps(node.props);
|
|
41
|
-
|
|
42
|
-
const propsWithVisibleField = useMemo(() => {
|
|
43
|
-
if (node.visible && !Array.isArray(node.visible) && node.visible.field) {
|
|
44
|
-
return { ...resolvedProps, _visibleField: node.visible.field };
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(node.visible) && node.visible.length === 1 && node.visible[0].field) {
|
|
47
|
-
return { ...resolvedProps, _visibleField: node.visible[0].field };
|
|
48
|
-
}
|
|
49
|
-
return resolvedProps;
|
|
50
|
-
}, [resolvedProps, node.visible]);
|
|
51
|
-
|
|
52
|
-
const childContext = useMemo(() => buildContext(node, parentCtx), [node, parentCtx]);
|
|
53
|
-
|
|
54
|
-
const { layoutProps, widgetProps: extractedWidgetProps } = useMemo(
|
|
55
|
-
() => extractLayoutProps(propsWithVisibleField),
|
|
56
|
-
[propsWithVisibleField],
|
|
57
|
-
);
|
|
58
|
-
const layoutClassName = useMemo(
|
|
59
|
-
() => (hasLayoutProps(propsWithVisibleField) ? resolveLayoutClasses(layoutProps) : ''),
|
|
60
|
-
[propsWithVisibleField, layoutProps],
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
if (!visible) return null;
|
|
64
|
-
|
|
65
|
-
const widgetEntry = getWidget(node.type);
|
|
66
|
-
|
|
67
|
-
if (!widgetEntry) {
|
|
68
|
-
return <div data-widget-error={`Unknown widget: ${node.type}`} />;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const Component = widgetEntry.component;
|
|
72
|
-
|
|
73
|
-
const widgetProps: WidgetProps = {
|
|
74
|
-
props: extractedWidgetProps,
|
|
75
|
-
bind: {
|
|
76
|
-
value: binding?.value ?? null,
|
|
77
|
-
setValue: binding?.setValue,
|
|
78
|
-
meta: binding?.meta,
|
|
79
|
-
error: binding?.error,
|
|
80
|
-
id: resolveBindId(node.bind?.id, parentCtx, routeParams),
|
|
81
|
-
},
|
|
82
|
-
on: triggerHandlers,
|
|
83
|
-
context: {
|
|
84
|
-
record: parentCtx.record,
|
|
85
|
-
model: parentCtx.model,
|
|
86
|
-
mode: parentCtx.mode,
|
|
87
|
-
index: parentCtx.index,
|
|
88
|
-
},
|
|
89
|
-
childNodes: node.children,
|
|
90
|
-
children: node.children ? (
|
|
91
|
-
<WidgetContextProvider value={childContext}>
|
|
92
|
-
{node.children.map((child, i) => (
|
|
93
|
-
<WidgetRenderer
|
|
94
|
-
key={child.id ?? i}
|
|
95
|
-
node={child}
|
|
96
|
-
handlers={handlers}
|
|
97
|
-
fieldMeta={fieldMeta}
|
|
98
|
-
setValue={setValue}
|
|
99
|
-
/>
|
|
100
|
-
))}
|
|
101
|
-
</WidgetContextProvider>
|
|
102
|
-
) : undefined,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const dataAttrs: Record<string, string | undefined> = {
|
|
106
|
-
'data-rangka-widget': node.type,
|
|
107
|
-
'data-rangka-id': node.id ?? undefined,
|
|
108
|
-
'data-rangka-model': parentCtx.model || undefined,
|
|
109
|
-
'data-rangka-field': node.bind?.field ?? undefined,
|
|
110
|
-
'data-rangka-mode': parentCtx.mode,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
let rendered: React.ReactNode;
|
|
114
|
-
|
|
115
|
-
if (node.bind?.model || node.source) {
|
|
116
|
-
rendered = (
|
|
117
|
-
<WidgetContextProvider value={childContext}>
|
|
118
|
-
<Component {...widgetProps} />
|
|
119
|
-
</WidgetContextProvider>
|
|
120
|
-
);
|
|
121
|
-
} else {
|
|
122
|
-
rendered = <Component {...widgetProps} />;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (layoutClassName) {
|
|
126
|
-
return (
|
|
127
|
-
<div className={layoutClassName} {...dataAttrs}>
|
|
128
|
-
{rendered}
|
|
129
|
-
</div>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div className="contents" {...dataAttrs}>
|
|
135
|
-
{rendered}
|
|
136
|
-
</div>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function useResolvedProps(props: Record<string, unknown> | undefined): Record<string, unknown> {
|
|
141
|
-
const ctx = useWidgetContext();
|
|
142
|
-
const routeParams = useRouteParams();
|
|
143
|
-
return useMemo(() => {
|
|
144
|
-
if (!props) return {};
|
|
145
|
-
const resolved: Record<string, unknown> = {};
|
|
146
|
-
const flat = flattenContext(ctx);
|
|
147
|
-
const merged: Record<string, unknown> = { ...flat, $route: routeParams };
|
|
148
|
-
for (const [key, value] of Object.entries(props)) {
|
|
149
|
-
if (typeof value === 'string' && value.includes('{{')) {
|
|
150
|
-
const trimmed = value.trim();
|
|
151
|
-
if (
|
|
152
|
-
trimmed.startsWith('{{') &&
|
|
153
|
-
trimmed.endsWith('}}') &&
|
|
154
|
-
!trimmed.slice(2, -2).includes('{{')
|
|
155
|
-
) {
|
|
156
|
-
const ast = parse(trimmed);
|
|
157
|
-
resolved[key] = evaluate(ast, merged);
|
|
158
|
-
} else {
|
|
159
|
-
resolved[key] = value.replace(/\{\{(.+?)\}\}/g, (_m, expr: string) => {
|
|
160
|
-
const ast = parse(expr.trim());
|
|
161
|
-
return String(evaluate(ast, merged) ?? '');
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
} else {
|
|
165
|
-
resolved[key] = value;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return resolved;
|
|
169
|
-
}, [props, ctx, routeParams]);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function resolveBindId(
|
|
173
|
-
id: string | undefined,
|
|
174
|
-
ctx: import('../context/types.js').WidgetContext,
|
|
175
|
-
routeParams: Record<string, string>,
|
|
176
|
-
): string | undefined {
|
|
177
|
-
if (!id) return undefined;
|
|
178
|
-
if (!id.includes('{{')) return id;
|
|
179
|
-
const flat = flattenContext(ctx);
|
|
180
|
-
const merged: Record<string, unknown> = { ...flat, $route: routeParams };
|
|
181
|
-
const trimmed = id.trim();
|
|
182
|
-
if (trimmed.startsWith('{{') && trimmed.endsWith('}}') && !trimmed.slice(2, -2).includes('{{')) {
|
|
183
|
-
const ast = parse(trimmed);
|
|
184
|
-
const result = evaluate(ast, merged);
|
|
185
|
-
return result != null ? String(result) : undefined;
|
|
186
|
-
}
|
|
187
|
-
return id.replace(/\{\{(.+?)\}\}/g, (_m, expr: string) => {
|
|
188
|
-
const ast = parse(expr.trim());
|
|
189
|
-
return String(evaluate(ast, merged) ?? '');
|
|
190
|
-
});
|
|
191
|
-
}
|