@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,83 +0,0 @@
|
|
|
1
|
-
import type { WidgetNode } from '@rangka/shared';
|
|
2
|
-
import type { WidgetContext } from '../../context/types.js';
|
|
3
|
-
import { getWidget } from '../../registry.js';
|
|
4
|
-
import { flattenContext } from '../../context/types.js';
|
|
5
|
-
import { parse, evaluate } from '../../expression/index.js';
|
|
6
|
-
|
|
7
|
-
export function ColumnChildRenderer({ node, rowCtx }: { node: WidgetNode; rowCtx: WidgetContext }) {
|
|
8
|
-
const entry = getWidget(node.type);
|
|
9
|
-
if (!entry) return <span data-widget-error={`Unknown: ${node.type}`} />;
|
|
10
|
-
|
|
11
|
-
const Component = entry.component;
|
|
12
|
-
const flat = flattenContext(rowCtx);
|
|
13
|
-
const resolvedProps = resolveProps(node.props, flat);
|
|
14
|
-
const bindResult = resolveBindValue(node, rowCtx);
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<Component
|
|
18
|
-
props={resolvedProps}
|
|
19
|
-
bind={{ value: bindResult, setValue: undefined, meta: undefined }}
|
|
20
|
-
on={{}}
|
|
21
|
-
context={{
|
|
22
|
-
record: rowCtx.record,
|
|
23
|
-
model: rowCtx.model,
|
|
24
|
-
mode: rowCtx.mode,
|
|
25
|
-
index: rowCtx.index,
|
|
26
|
-
}}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function CellValue({ col, row }: { col: WidgetNode; row: Record<string, unknown> }) {
|
|
32
|
-
const field = col.bind?.field;
|
|
33
|
-
if (!field) return null;
|
|
34
|
-
const value = row[field];
|
|
35
|
-
return <>{value != null ? String(value) : ''}</>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function resolveProps(
|
|
39
|
-
props: Record<string, unknown> | undefined,
|
|
40
|
-
flat: Record<string, unknown>,
|
|
41
|
-
): Record<string, unknown> {
|
|
42
|
-
if (!props) return {};
|
|
43
|
-
const resolved: Record<string, unknown> = {};
|
|
44
|
-
for (const [key, value] of Object.entries(props)) {
|
|
45
|
-
if (typeof value === 'string' && value.includes('{{')) {
|
|
46
|
-
const trimmed = value.trim();
|
|
47
|
-
if (
|
|
48
|
-
trimmed.startsWith('{{') &&
|
|
49
|
-
trimmed.endsWith('}}') &&
|
|
50
|
-
!trimmed.slice(2, -2).includes('{{')
|
|
51
|
-
) {
|
|
52
|
-
const ast = parse(trimmed);
|
|
53
|
-
resolved[key] = evaluate(ast, flat);
|
|
54
|
-
} else {
|
|
55
|
-
resolved[key] = value.replace(/\{\{(.+?)\}\}/g, (_m, expr: string) => {
|
|
56
|
-
const ast = parse(expr.trim());
|
|
57
|
-
return String(evaluate(ast, flat) ?? '');
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
resolved[key] = value;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return resolved;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function resolveBindValue(node: WidgetNode, ctx: WidgetContext): unknown {
|
|
68
|
-
if (!node.bind) return null;
|
|
69
|
-
if (node.bind.field) {
|
|
70
|
-
return ctx.record[node.bind.field] ?? null;
|
|
71
|
-
}
|
|
72
|
-
if (node.bind.expression) {
|
|
73
|
-
const flat = flattenContext(ctx);
|
|
74
|
-
const expr = node.bind.expression;
|
|
75
|
-
const trimmed = expr.trim();
|
|
76
|
-
if (trimmed.startsWith('{{') && trimmed.endsWith('}}')) {
|
|
77
|
-
const ast = parse(trimmed);
|
|
78
|
-
return evaluate(ast, flat);
|
|
79
|
-
}
|
|
80
|
-
return expr;
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
|
|
2
|
-
import { Button } from '../../../components/ui/button.js';
|
|
3
|
-
|
|
4
|
-
interface TablePaginationProps {
|
|
5
|
-
page: number;
|
|
6
|
-
pageSize: number;
|
|
7
|
-
total: number | undefined;
|
|
8
|
-
recordCount: number;
|
|
9
|
-
onPageChange: (page: number) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function TablePagination({ page, pageSize, total, recordCount, onPageChange }: TablePaginationProps) {
|
|
13
|
-
const start = (page - 1) * pageSize + 1;
|
|
14
|
-
const end = total != null ? Math.min(page * pageSize, total) : start + recordCount - 1;
|
|
15
|
-
const hasPrev = page > 1;
|
|
16
|
-
const hasNext = total != null ? end < total : recordCount >= pageSize;
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div className="flex items-center justify-between border-t border-border px-5 py-2.5 text-sm">
|
|
20
|
-
<span className="text-muted-foreground tabular-nums">
|
|
21
|
-
{total != null ? `Showing ${start}\u2013${end} of ${total}` : `Page ${page}`}
|
|
22
|
-
</span>
|
|
23
|
-
<div className="flex items-center gap-1">
|
|
24
|
-
<Button
|
|
25
|
-
variant="outline"
|
|
26
|
-
size="icon-sm"
|
|
27
|
-
disabled={!hasPrev}
|
|
28
|
-
onClick={() => onPageChange(page - 1)}
|
|
29
|
-
aria-label="Previous page"
|
|
30
|
-
>
|
|
31
|
-
<ChevronLeftIcon className="h-4 w-4" />
|
|
32
|
-
</Button>
|
|
33
|
-
<Button
|
|
34
|
-
variant="outline"
|
|
35
|
-
size="icon-sm"
|
|
36
|
-
disabled={!hasNext}
|
|
37
|
-
onClick={() => onPageChange(page + 1)}
|
|
38
|
-
aria-label="Next page"
|
|
39
|
-
>
|
|
40
|
-
<ChevronRightIcon className="h-3.5 w-3.5" />
|
|
41
|
-
</Button>
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import React, { useState, useCallback, useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
FilterIcon,
|
|
4
|
-
XIcon,
|
|
5
|
-
SearchIcon,
|
|
6
|
-
} from 'lucide-react';
|
|
7
|
-
import type { WidgetNode } from '@rangka/shared';
|
|
8
|
-
import { Badge } from '../../../components/ui/badge.js';
|
|
9
|
-
import { Button } from '../../../components/ui/button.js';
|
|
10
|
-
import { Input } from '../../../components/ui/input.js';
|
|
11
|
-
import { Popover, PopoverTrigger, PopoverContent } from '../../../components/ui/popover.js';
|
|
12
|
-
import { useModelMeta } from '../../../data/useModelMeta.js';
|
|
13
|
-
import {
|
|
14
|
-
getOperatorsForType,
|
|
15
|
-
getDefaultOperator,
|
|
16
|
-
getOperatorSymbol,
|
|
17
|
-
getActiveFilters,
|
|
18
|
-
getLabelForField,
|
|
19
|
-
} from './filter-operators.js';
|
|
20
|
-
|
|
21
|
-
interface PageStore {
|
|
22
|
-
get(key: string): unknown;
|
|
23
|
-
set(key: string, value: unknown): void;
|
|
24
|
-
keys(): Iterable<string>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface TableToolbarProps {
|
|
28
|
-
model: string;
|
|
29
|
-
store: PageStore;
|
|
30
|
-
columns: WidgetNode[];
|
|
31
|
-
hasSearch: boolean;
|
|
32
|
-
hasFilters: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function TableToolbar({ model, store, columns, hasSearch, hasFilters }: TableToolbarProps) {
|
|
36
|
-
const [searchInput, setSearchInput] = useState(() => {
|
|
37
|
-
const val = store.get(`$search.${model}`);
|
|
38
|
-
return val ? String(val) : '';
|
|
39
|
-
});
|
|
40
|
-
const debounceRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
41
|
-
|
|
42
|
-
const handleSearchChange = useCallback(
|
|
43
|
-
(value: string) => {
|
|
44
|
-
setSearchInput(value);
|
|
45
|
-
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
46
|
-
debounceRef.current = setTimeout(() => {
|
|
47
|
-
store.set(`$search.${model}`, value || null);
|
|
48
|
-
store.set(`$page.${model}`, 1);
|
|
49
|
-
}, 300);
|
|
50
|
-
},
|
|
51
|
-
[model, store],
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const activeFilters = getActiveFilters(store, model, columns);
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<div className="flex flex-col border-b border-border/50">
|
|
58
|
-
<div className="flex items-center gap-2 px-5 py-2">
|
|
59
|
-
{hasSearch && (
|
|
60
|
-
<div className="flex flex-1 items-center gap-2">
|
|
61
|
-
<SearchIcon className="h-3.5 w-3.5 text-muted-foreground shrink-0" />
|
|
62
|
-
<input
|
|
63
|
-
type="text"
|
|
64
|
-
value={searchInput}
|
|
65
|
-
onChange={(e) => handleSearchChange(e.target.value)}
|
|
66
|
-
placeholder="Search..."
|
|
67
|
-
className="flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground"
|
|
68
|
-
/>
|
|
69
|
-
{searchInput && (
|
|
70
|
-
<button
|
|
71
|
-
className="rounded-sm p-0.5 hover:bg-muted"
|
|
72
|
-
onClick={() => handleSearchChange('')}
|
|
73
|
-
aria-label="Clear search"
|
|
74
|
-
>
|
|
75
|
-
<XIcon className="h-3 w-3 text-muted-foreground" />
|
|
76
|
-
</button>
|
|
77
|
-
)}
|
|
78
|
-
</div>
|
|
79
|
-
)}
|
|
80
|
-
{hasFilters && <TableFilterPopover columns={columns} model={model} store={store} />}
|
|
81
|
-
</div>
|
|
82
|
-
{activeFilters.length > 0 && (
|
|
83
|
-
<div className="flex flex-wrap items-center gap-2 px-5 pb-2">
|
|
84
|
-
{activeFilters.map((f) => (
|
|
85
|
-
<Badge key={f.key} variant="secondary" className="gap-1 pr-1">
|
|
86
|
-
<span className="text-xs">
|
|
87
|
-
{f.label} {getOperatorSymbol(f.operator)} {f.displayValue}
|
|
88
|
-
</span>
|
|
89
|
-
<button
|
|
90
|
-
className="ml-1 rounded-sm p-0.5 hover:bg-muted"
|
|
91
|
-
onClick={() => {
|
|
92
|
-
store.set(f.key, null);
|
|
93
|
-
store.set(`$page.${model}`, 1);
|
|
94
|
-
}}
|
|
95
|
-
aria-label={`Remove ${f.label} filter`}
|
|
96
|
-
>
|
|
97
|
-
<XIcon className="h-3 w-3" />
|
|
98
|
-
</button>
|
|
99
|
-
</Badge>
|
|
100
|
-
))}
|
|
101
|
-
</div>
|
|
102
|
-
)}
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// --- Filter Popover ---
|
|
108
|
-
|
|
109
|
-
interface FilterPopoverProps {
|
|
110
|
-
columns: WidgetNode[];
|
|
111
|
-
model: string;
|
|
112
|
-
store: PageStore;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function TableFilterPopover({ columns, model, store }: FilterPopoverProps) {
|
|
116
|
-
const [adding, setAdding] = useState(false);
|
|
117
|
-
const [selectedField, setSelectedField] = useState<string | null>(null);
|
|
118
|
-
const [selectedOperator, setSelectedOperator] = useState<string>('');
|
|
119
|
-
const [filterValue, setFilterValue] = useState('');
|
|
120
|
-
const [search, setSearch] = useState('');
|
|
121
|
-
|
|
122
|
-
const { modelMeta } = useModelMeta(model);
|
|
123
|
-
|
|
124
|
-
const getFieldType = useCallback(
|
|
125
|
-
(field: string): string => {
|
|
126
|
-
const meta = modelMeta?.fields.find((f) => f.name === field);
|
|
127
|
-
return meta?.type ?? 'string';
|
|
128
|
-
},
|
|
129
|
-
[modelMeta],
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const filteredColumns = useMemo(() => {
|
|
133
|
-
if (!search) return columns.filter((col) => col.bind?.field);
|
|
134
|
-
const q = search.toLowerCase();
|
|
135
|
-
return columns.filter((col) => {
|
|
136
|
-
if (!col.bind?.field) return false;
|
|
137
|
-
const label = String(col.props?.label ?? col.bind.field).toLowerCase();
|
|
138
|
-
return label.includes(q);
|
|
139
|
-
});
|
|
140
|
-
}, [columns, search]);
|
|
141
|
-
|
|
142
|
-
const handleFieldSelect = (field: string) => {
|
|
143
|
-
setSelectedField(field);
|
|
144
|
-
setSelectedOperator(getDefaultOperator(getFieldType(field)));
|
|
145
|
-
setFilterValue('');
|
|
146
|
-
setSearch('');
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const handleApply = () => {
|
|
150
|
-
if (!selectedField) return;
|
|
151
|
-
const operators = getOperatorsForType(getFieldType(selectedField));
|
|
152
|
-
const op = operators.find((o) => o.value === selectedOperator);
|
|
153
|
-
if (!op) return;
|
|
154
|
-
if (op.needsValue && !filterValue) return;
|
|
155
|
-
|
|
156
|
-
const suffix = selectedOperator === 'eq' ? '' : `__${selectedOperator}`;
|
|
157
|
-
const key = `$filter.${model}.${selectedField}${suffix}`;
|
|
158
|
-
|
|
159
|
-
let value: unknown = filterValue;
|
|
160
|
-
if (selectedOperator === 'empty') value = 'true';
|
|
161
|
-
else if (selectedOperator === 'not_empty') value = 'true';
|
|
162
|
-
else if (selectedOperator === 'eq' && getFieldType(selectedField) === 'boolean') value = 'true';
|
|
163
|
-
else if (selectedOperator === 'neq' && getFieldType(selectedField) === 'boolean')
|
|
164
|
-
value = 'false';
|
|
165
|
-
|
|
166
|
-
store.set(key, value);
|
|
167
|
-
store.set(`$page.${model}`, 1);
|
|
168
|
-
setAdding(false);
|
|
169
|
-
setSelectedField(null);
|
|
170
|
-
setSelectedOperator('');
|
|
171
|
-
setFilterValue('');
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const handleBack = () => {
|
|
175
|
-
setSelectedField(null);
|
|
176
|
-
setSelectedOperator('');
|
|
177
|
-
setFilterValue('');
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const handleOpenChange = (open: boolean) => {
|
|
181
|
-
setAdding(open);
|
|
182
|
-
if (!open) {
|
|
183
|
-
setSelectedField(null);
|
|
184
|
-
setSelectedOperator('');
|
|
185
|
-
setFilterValue('');
|
|
186
|
-
setSearch('');
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const currentOperators = selectedField ? getOperatorsForType(getFieldType(selectedField)) : [];
|
|
191
|
-
const currentOp = currentOperators.find((o) => o.value === selectedOperator);
|
|
192
|
-
|
|
193
|
-
return (
|
|
194
|
-
<Popover open={adding} onOpenChange={handleOpenChange}>
|
|
195
|
-
<PopoverTrigger asChild>
|
|
196
|
-
<Button variant="ghost" size="sm" className="h-7 gap-1 text-xs shrink-0">
|
|
197
|
-
<FilterIcon className="h-3.5 w-3.5" />
|
|
198
|
-
Filter
|
|
199
|
-
</Button>
|
|
200
|
-
</PopoverTrigger>
|
|
201
|
-
<PopoverContent className="w-56 p-0" align="end">
|
|
202
|
-
{!selectedField ? (
|
|
203
|
-
<div className="flex flex-col">
|
|
204
|
-
<div className="flex items-center gap-2 border-b border-border/50 px-2.5 py-2">
|
|
205
|
-
<SearchIcon className="h-3.5 w-3.5 text-muted-foreground shrink-0" />
|
|
206
|
-
<input
|
|
207
|
-
type="text"
|
|
208
|
-
value={search}
|
|
209
|
-
onChange={(e) => setSearch(e.target.value)}
|
|
210
|
-
placeholder="Search fields..."
|
|
211
|
-
className="flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground"
|
|
212
|
-
autoFocus
|
|
213
|
-
/>
|
|
214
|
-
</div>
|
|
215
|
-
<div className="flex flex-col py-1 max-h-48 overflow-auto">
|
|
216
|
-
{filteredColumns.map((col) => {
|
|
217
|
-
const field = col.bind?.field;
|
|
218
|
-
if (!field) return null;
|
|
219
|
-
return (
|
|
220
|
-
<button
|
|
221
|
-
key={field}
|
|
222
|
-
className="px-2.5 py-1.5 text-left text-xs hover:bg-muted transition-colors"
|
|
223
|
-
onClick={() => handleFieldSelect(field)}
|
|
224
|
-
>
|
|
225
|
-
{String(col.props?.label ?? field)}
|
|
226
|
-
</button>
|
|
227
|
-
);
|
|
228
|
-
})}
|
|
229
|
-
{filteredColumns.length === 0 && (
|
|
230
|
-
<p className="px-2.5 py-1.5 text-xs text-muted-foreground">No fields found</p>
|
|
231
|
-
)}
|
|
232
|
-
</div>
|
|
233
|
-
</div>
|
|
234
|
-
) : (
|
|
235
|
-
<div className="flex flex-col">
|
|
236
|
-
<div className="px-2.5 pt-2.5 pb-2">
|
|
237
|
-
<p className="text-xs font-semibold">{getLabelForField(columns, selectedField)}</p>
|
|
238
|
-
</div>
|
|
239
|
-
<div className="flex flex-col gap-2 px-2.5 pb-2.5">
|
|
240
|
-
<select
|
|
241
|
-
value={selectedOperator}
|
|
242
|
-
onChange={(e) => {
|
|
243
|
-
setSelectedOperator(e.target.value);
|
|
244
|
-
setFilterValue('');
|
|
245
|
-
}}
|
|
246
|
-
className="h-7 w-full rounded-none border border-border bg-transparent px-2 text-xs outline-none focus:border-ring"
|
|
247
|
-
>
|
|
248
|
-
{currentOperators.map((op) => (
|
|
249
|
-
<option key={op.value} value={op.value}>
|
|
250
|
-
{op.label}
|
|
251
|
-
</option>
|
|
252
|
-
))}
|
|
253
|
-
</select>
|
|
254
|
-
{currentOp?.needsValue && (
|
|
255
|
-
<Input
|
|
256
|
-
value={filterValue}
|
|
257
|
-
onChange={(e) => setFilterValue(e.target.value)}
|
|
258
|
-
placeholder="Value..."
|
|
259
|
-
className="h-7 text-xs"
|
|
260
|
-
onKeyDown={(e) => {
|
|
261
|
-
if (e.key === 'Enter') handleApply();
|
|
262
|
-
}}
|
|
263
|
-
autoFocus
|
|
264
|
-
/>
|
|
265
|
-
)}
|
|
266
|
-
</div>
|
|
267
|
-
<div className="flex items-center justify-between border-t border-border/50 px-2.5 py-2">
|
|
268
|
-
<Button variant="ghost" size="xs" onClick={handleBack}>
|
|
269
|
-
Back
|
|
270
|
-
</Button>
|
|
271
|
-
<Button
|
|
272
|
-
variant="default"
|
|
273
|
-
size="xs"
|
|
274
|
-
onClick={handleApply}
|
|
275
|
-
disabled={currentOp?.needsValue ? !filterValue : false}
|
|
276
|
-
>
|
|
277
|
-
Apply
|
|
278
|
-
</Button>
|
|
279
|
-
</div>
|
|
280
|
-
</div>
|
|
281
|
-
)}
|
|
282
|
-
</PopoverContent>
|
|
283
|
-
</Popover>
|
|
284
|
-
);
|
|
285
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { WidgetNode } from '@rangka/shared';
|
|
2
|
-
|
|
3
|
-
export interface OperatorOption {
|
|
4
|
-
value: string;
|
|
5
|
-
label: string;
|
|
6
|
-
needsValue: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const STRING_OPERATORS: OperatorOption[] = [
|
|
10
|
-
{ value: 'like', label: 'Contains', needsValue: true },
|
|
11
|
-
{ value: 'eq', label: 'Equals', needsValue: true },
|
|
12
|
-
{ value: 'neq', label: 'Not equals', needsValue: true },
|
|
13
|
-
{ value: 'empty', label: 'Empty', needsValue: false },
|
|
14
|
-
{ value: 'not_empty', label: 'Not empty', needsValue: false },
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
export const NUMERIC_OPERATORS: OperatorOption[] = [
|
|
18
|
-
{ value: 'eq', label: 'Equals', needsValue: true },
|
|
19
|
-
{ value: 'neq', label: 'Not equals', needsValue: true },
|
|
20
|
-
{ value: 'gt', label: 'Greater than', needsValue: true },
|
|
21
|
-
{ value: 'gte', label: 'Greater or equal', needsValue: true },
|
|
22
|
-
{ value: 'lt', label: 'Less than', needsValue: true },
|
|
23
|
-
{ value: 'lte', label: 'Less or equal', needsValue: true },
|
|
24
|
-
{ value: 'empty', label: 'Empty', needsValue: false },
|
|
25
|
-
{ value: 'not_empty', label: 'Not empty', needsValue: false },
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
export const DATE_OPERATORS: OperatorOption[] = [
|
|
29
|
-
{ value: 'eq', label: 'Equals', needsValue: true },
|
|
30
|
-
{ value: 'gt', label: 'After', needsValue: true },
|
|
31
|
-
{ value: 'gte', label: 'On or after', needsValue: true },
|
|
32
|
-
{ value: 'lt', label: 'Before', needsValue: true },
|
|
33
|
-
{ value: 'lte', label: 'On or before', needsValue: true },
|
|
34
|
-
{ value: 'empty', label: 'Empty', needsValue: false },
|
|
35
|
-
{ value: 'not_empty', label: 'Not empty', needsValue: false },
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
export const BOOLEAN_OPERATORS: OperatorOption[] = [
|
|
39
|
-
{ value: 'eq', label: 'Is true', needsValue: false },
|
|
40
|
-
{ value: 'neq', label: 'Is false', needsValue: false },
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
export const ENUM_OPERATORS: OperatorOption[] = [
|
|
44
|
-
{ value: 'eq', label: 'Equals', needsValue: true },
|
|
45
|
-
{ value: 'neq', label: 'Not equals', needsValue: true },
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
export function getOperatorsForType(fieldType: string): OperatorOption[] {
|
|
49
|
-
switch (fieldType) {
|
|
50
|
-
case 'string':
|
|
51
|
-
case 'text':
|
|
52
|
-
return STRING_OPERATORS;
|
|
53
|
-
case 'int':
|
|
54
|
-
case 'decimal':
|
|
55
|
-
case 'money':
|
|
56
|
-
return NUMERIC_OPERATORS;
|
|
57
|
-
case 'date':
|
|
58
|
-
case 'datetime':
|
|
59
|
-
return DATE_OPERATORS;
|
|
60
|
-
case 'boolean':
|
|
61
|
-
return BOOLEAN_OPERATORS;
|
|
62
|
-
case 'enum':
|
|
63
|
-
return ENUM_OPERATORS;
|
|
64
|
-
default:
|
|
65
|
-
return STRING_OPERATORS;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function getDefaultOperator(fieldType: string): string {
|
|
70
|
-
if (fieldType === 'string' || fieldType === 'text') return 'like';
|
|
71
|
-
return 'eq';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getOperatorSymbol(operator: string): string {
|
|
75
|
-
switch (operator) {
|
|
76
|
-
case 'eq':
|
|
77
|
-
return '=';
|
|
78
|
-
case 'neq':
|
|
79
|
-
return '\u2260';
|
|
80
|
-
case 'gt':
|
|
81
|
-
return '>';
|
|
82
|
-
case 'gte':
|
|
83
|
-
return '\u2265';
|
|
84
|
-
case 'lt':
|
|
85
|
-
return '<';
|
|
86
|
-
case 'lte':
|
|
87
|
-
return '\u2264';
|
|
88
|
-
case 'like':
|
|
89
|
-
return '\u2248';
|
|
90
|
-
case 'empty':
|
|
91
|
-
return 'is empty';
|
|
92
|
-
case 'not_empty':
|
|
93
|
-
return 'is not empty';
|
|
94
|
-
default:
|
|
95
|
-
return '=';
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function getActiveFilters(
|
|
100
|
-
store: { get(key: string): unknown; keys(): Iterable<string> },
|
|
101
|
-
model: string,
|
|
102
|
-
columns: WidgetNode[],
|
|
103
|
-
): { key: string; field: string; operator: string; label: string; displayValue: string }[] {
|
|
104
|
-
const prefix = `$filter.${model}.`;
|
|
105
|
-
const results: {
|
|
106
|
-
key: string;
|
|
107
|
-
field: string;
|
|
108
|
-
operator: string;
|
|
109
|
-
label: string;
|
|
110
|
-
displayValue: string;
|
|
111
|
-
}[] = [];
|
|
112
|
-
for (const key of store.keys()) {
|
|
113
|
-
if (!key.startsWith(prefix)) continue;
|
|
114
|
-
const value = store.get(key);
|
|
115
|
-
if (value === null || value === undefined) continue;
|
|
116
|
-
const fieldPart = key.slice(prefix.length);
|
|
117
|
-
let operator = 'eq';
|
|
118
|
-
let field = fieldPart;
|
|
119
|
-
const suffixMatch = fieldPart.match(/__(\w+)$/);
|
|
120
|
-
if (suffixMatch) {
|
|
121
|
-
operator = suffixMatch[1];
|
|
122
|
-
field = fieldPart.slice(0, -suffixMatch[0].length);
|
|
123
|
-
}
|
|
124
|
-
const label = getLabelForField(columns, field);
|
|
125
|
-
const displayValue = operator === 'empty' || operator === 'not_empty' ? '' : String(value);
|
|
126
|
-
results.push({ key, field, operator, label, displayValue });
|
|
127
|
-
}
|
|
128
|
-
return results;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function getLabelForField(columns: WidgetNode[], field: string): string {
|
|
132
|
-
const col = columns.find((c) => c.bind?.field === field);
|
|
133
|
-
return String(col?.props?.label ?? field);
|
|
134
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { TableToolbar } from './TableToolbar.js';
|
|
2
|
-
export { TablePagination } from './TablePagination.js';
|
|
3
|
-
export { ColumnChildRenderer, CellValue } from './CellRenderers.js';
|
|
4
|
-
export {
|
|
5
|
-
getOperatorsForType,
|
|
6
|
-
getDefaultOperator,
|
|
7
|
-
getOperatorSymbol,
|
|
8
|
-
getActiveFilters,
|
|
9
|
-
getLabelForField,
|
|
10
|
-
} from './filter-operators.js';
|
|
11
|
-
export type { OperatorOption } from './filter-operators.js';
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { Condition } from '@rangka/shared';
|
|
2
|
-
import { parse, evaluate } from '../expression/index.js';
|
|
3
|
-
import type { EvalContext } from '../expression/index.js';
|
|
4
|
-
|
|
5
|
-
export function evaluateCondition(condition: Condition, context: EvalContext): boolean {
|
|
6
|
-
const fieldValue = resolveFieldValue(condition.field, context);
|
|
7
|
-
const compareValue = resolveValue(condition.value, context);
|
|
8
|
-
|
|
9
|
-
switch (condition.operator) {
|
|
10
|
-
case 'eq':
|
|
11
|
-
return fieldValue == compareValue;
|
|
12
|
-
case 'neq':
|
|
13
|
-
return fieldValue != compareValue;
|
|
14
|
-
case 'in':
|
|
15
|
-
return Array.isArray(compareValue) && compareValue.includes(fieldValue);
|
|
16
|
-
case 'notIn':
|
|
17
|
-
return Array.isArray(compareValue) && !compareValue.includes(fieldValue);
|
|
18
|
-
case 'empty':
|
|
19
|
-
return fieldValue == null || fieldValue === '';
|
|
20
|
-
case 'notEmpty':
|
|
21
|
-
return fieldValue != null && fieldValue !== '';
|
|
22
|
-
case 'gt':
|
|
23
|
-
return Number(fieldValue) > Number(compareValue);
|
|
24
|
-
case 'lt':
|
|
25
|
-
return Number(fieldValue) < Number(compareValue);
|
|
26
|
-
case 'gte':
|
|
27
|
-
return Number(fieldValue) >= Number(compareValue);
|
|
28
|
-
case 'lte':
|
|
29
|
-
return Number(fieldValue) <= Number(compareValue);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function evaluateConditions(
|
|
34
|
-
conditions: Condition | Condition[],
|
|
35
|
-
context: EvalContext,
|
|
36
|
-
): boolean {
|
|
37
|
-
const list = Array.isArray(conditions) ? conditions : [conditions];
|
|
38
|
-
return list.every((c) => evaluateCondition(c, context));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function resolveFieldValue(field: string, context: EvalContext): unknown {
|
|
42
|
-
const parts = field.split('.');
|
|
43
|
-
let current: unknown = context;
|
|
44
|
-
for (const part of parts) {
|
|
45
|
-
if (current == null || typeof current !== 'object') return undefined;
|
|
46
|
-
current = (current as Record<string, unknown>)[part];
|
|
47
|
-
}
|
|
48
|
-
return current;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function resolveValue(value: unknown, context: EvalContext): unknown {
|
|
52
|
-
if (typeof value === 'string' && value.includes('{{')) {
|
|
53
|
-
const ast = parse(value);
|
|
54
|
-
return evaluate(ast, context);
|
|
55
|
-
}
|
|
56
|
-
return value;
|
|
57
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { evaluateCondition, evaluateConditions } from './evaluator.js';
|