@sincpro/web-ui 1.9.0 → 1.11.0
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/components/board/Board.d.ts +51 -0
- package/dist/components/board/Board.js +15 -0
- package/dist/components/board/index.d.ts +1 -0
- package/dist/components/board/index.js +2 -0
- package/dist/components/canvas/Canvas.d.ts +14 -0
- package/dist/components/canvas/Canvas.js +9 -0
- package/dist/components/canvas/canvas.css +19 -0
- package/dist/components/canvas/index.d.ts +1 -0
- package/dist/components/canvas/index.js +2 -0
- package/dist/components/chat/ChatComposer.d.ts +10 -0
- package/dist/components/chat/ChatComposer.js +29 -0
- package/dist/components/chat/ChatThread.d.ts +13 -0
- package/dist/components/chat/ChatThread.js +76 -0
- package/dist/components/chat/ConversationList.d.ts +22 -0
- package/dist/components/chat/ConversationList.js +22 -0
- package/dist/components/chat/index.d.ts +4 -0
- package/dist/components/chat/index.js +5 -0
- package/dist/components/chat/model.d.ts +30 -0
- package/dist/components/chat/model.js +53 -0
- package/dist/components/frame/Chart.d.ts +12 -7
- package/dist/components/frame/Chart.js +17 -17
- package/dist/components/frame/FrameView.d.ts +3 -3
- package/dist/components/frame/FrameView.js +79 -26
- package/dist/components/frame/model.d.ts +12 -3
- package/dist/components/frame/model.js +53 -19
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/listing/AxisLevels.d.ts +24 -0
- package/dist/components/listing/AxisLevels.js +58 -0
- package/dist/components/listing/ChartExplorer.d.ts +79 -0
- package/dist/components/listing/ChartExplorer.js +114 -0
- package/dist/components/listing/ColumnsMenu.d.ts +7 -1
- package/dist/components/listing/ColumnsMenu.js +16 -5
- package/dist/components/listing/GroupingLevels.d.ts +5 -1
- package/dist/components/listing/GroupingLevels.js +7 -4
- package/dist/components/listing/ListingBar.js +2 -2
- package/dist/components/listing/PivotExplorer.js +5 -36
- package/dist/components/listing/index.d.ts +2 -0
- package/dist/components/listing/index.js +2 -0
- package/dist/components/listing/set.d.ts +3 -1
- package/dist/components/preview/FilePreview.d.ts +19 -0
- package/dist/components/preview/FilePreview.js +112 -0
- package/dist/components/preview/PdfPreview.d.ts +7 -0
- package/dist/components/preview/PdfPreview.js +47 -0
- package/dist/components/preview/index.d.ts +1 -0
- package/dist/components/preview/index.js +2 -0
- package/dist/components/record/SmartButtons.js +1 -1
- package/dist/components/search/FieldPath.d.ts +54 -0
- package/dist/components/search/FieldPath.js +159 -0
- package/dist/components/search/FilterBuilder.d.ts +38 -5
- package/dist/components/search/FilterBuilder.js +129 -25
- package/dist/components/search/SearchBar.js +7 -2
- package/dist/components/search/criteria.d.ts +23 -1
- package/dist/components/search/index.d.ts +4 -2
- package/dist/components/search/index.js +4 -0
- package/dist/components/search/paths.d.ts +49 -0
- package/dist/components/search/paths.js +75 -0
- package/dist/components/shell/TopBar.js +1 -1
- package/dist/foundations/calendar.d.ts +15 -0
- package/dist/foundations/calendar.js +59 -1
- package/dist/foundations/chart.d.ts +126 -0
- package/dist/foundations/chart.js +297 -0
- package/dist/foundations/copy.d.ts +125 -0
- package/dist/foundations/copy.es.js +90 -0
- package/dist/foundations/copy.js +84 -0
- package/dist/foundations/index.d.ts +2 -1
- package/dist/foundations/index.js +4 -1
- package/dist/foundations/pivot.d.ts +9 -0
- package/dist/foundations/pivot.js +1 -0
- package/dist/primitives/chart/Chart.d.ts +39 -0
- package/dist/primitives/chart/Chart.js +235 -0
- package/dist/primitives/chart/index.d.ts +1 -0
- package/dist/primitives/chart/index.js +1 -0
- package/dist/primitives/field/Field.js +2 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/notice/Callout.d.ts +4 -1
- package/dist/primitives/notice/Callout.js +12 -2
- package/dist/primitives/notice/Notice.d.ts +26 -2
- package/dist/primitives/notice/Notice.js +64 -4
- package/dist/primitives/notice/Toast.js +10 -1
- package/dist/primitives/value/Markdown.d.ts +9 -0
- package/dist/primitives/value/Markdown.js +18 -0
- package/dist/primitives/value/Metric.d.ts +13 -2
- package/dist/primitives/value/Metric.js +25 -3
- package/dist/primitives/value/index.d.ts +1 -0
- package/dist/primitives/value/index.js +1 -0
- package/dist/tokens.css +73 -0
- package/dist/views/list/List.d.ts +2 -1
- package/dist/views/list/List.js +8 -1
- package/dist/views/list/ListView.d.ts +1 -1
- package/dist/views/list/ListView.js +37 -5
- package/dist/views/list/index.d.ts +1 -1
- package/dist/views/list/types.d.ts +34 -0
- package/package.json +5 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { fieldLabel, } from "./model.js";
|
|
4
|
+
import { createModelCache, isRelation, pathLabel, peekLabels, resolvePath, } from "./paths.js";
|
|
5
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
6
|
+
import { useSurface } from "../../foundations/surface.js";
|
|
7
|
+
import { Button, IconButton } from "../../primitives/button/Button.js";
|
|
8
|
+
import { SearchField } from "../../primitives/choice/SearchField.js";
|
|
9
|
+
import { listOptionStyles } from "../../primitives/field/aria.js";
|
|
10
|
+
import { Failed, Skeleton } from "../../primitives/notice/Notice.js";
|
|
11
|
+
import { Popover } from "../../primitives/overlay/Popover.js";
|
|
12
|
+
import { ChevronDown, ChevronLeft, ChevronRight } from "lucide-react";
|
|
13
|
+
import { useEffect, useMemo, useState } from "react";
|
|
14
|
+
import { Button as AriaButton, Dialog, DialogTrigger, ListBox, ListBoxItem, Pressable, } from "react-aria-components";
|
|
15
|
+
/** The cache a picker uses: the one it was given, or its own over its root. */
|
|
16
|
+
export function useModelCache(model, loadModel, models) {
|
|
17
|
+
return useMemo(() => models ?? createModelCache(model, loadModel), [models, model, loadModel]);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The steps of a path, once its models arrived: `undefined` while they come, `null` when the
|
|
21
|
+
* path does not exist in the model (or a model could not be loaded).
|
|
22
|
+
*
|
|
23
|
+
* The rows of a filter use it to learn the LAST field's operators and type: «Monto» reached
|
|
24
|
+
* through two relations compares like a number, not like the relation it came through.
|
|
25
|
+
*/
|
|
26
|
+
export function useFieldPathSteps(models, path) {
|
|
27
|
+
const copy = useUiCopy();
|
|
28
|
+
const at = path.join("\u0000");
|
|
29
|
+
const [steps, setSteps] = useState();
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
let alive = true;
|
|
32
|
+
const asked = at === "" ? [] : at.split("\u0000");
|
|
33
|
+
resolvePath(models, asked, copy.locale).then((found) => {
|
|
34
|
+
if (alive)
|
|
35
|
+
setSteps({ at, steps: found });
|
|
36
|
+
}, () => {
|
|
37
|
+
if (alive)
|
|
38
|
+
setSteps({ at, steps: null });
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
alive = false;
|
|
42
|
+
};
|
|
43
|
+
}, [models, at, copy.locale]);
|
|
44
|
+
return steps === undefined || steps.at !== at ? undefined : steps.steps;
|
|
45
|
+
}
|
|
46
|
+
function follows(rule, canLoad) {
|
|
47
|
+
if (!canLoad || rule === false)
|
|
48
|
+
return () => false;
|
|
49
|
+
if (rule === undefined || rule === true)
|
|
50
|
+
return (field) => isRelation(field);
|
|
51
|
+
return (field, name, at) => isRelation(field) && rule(field, name, at);
|
|
52
|
+
}
|
|
53
|
+
export function FieldPath({ model, loadModel, models: shared, value, onChange, filter, followRelations, label, placeholder, look = "select", icon, }) {
|
|
54
|
+
const copy = useUiCopy();
|
|
55
|
+
const surface = useSurface();
|
|
56
|
+
const models = useModelCache(model, loadModel, shared);
|
|
57
|
+
const [open, setOpen] = useState(false);
|
|
58
|
+
const steps = useFieldPathSteps(models, value);
|
|
59
|
+
const canFollow = follows(followRelations, models.canLoad);
|
|
60
|
+
const canChoose = filter ?? (() => true);
|
|
61
|
+
const shown = value.length === 0
|
|
62
|
+
? (placeholder ?? copy.fieldPath.choose)
|
|
63
|
+
: pathLabel(steps?.map((step) => step.label) ?? peekLabels(models, value, copy.locale));
|
|
64
|
+
const frame = surface === "chrome"
|
|
65
|
+
? "border-chrome-ink/20 bg-chrome text-chrome-ink"
|
|
66
|
+
: "border-ink/15 bg-surface text-ink";
|
|
67
|
+
return (_jsxs(DialogTrigger, { isOpen: open, onOpenChange: setOpen, children: [look === "button" ? (_jsx(Pressable, { children: _jsx(Button, { role: "secondary", size: "sm", expanded: open, haspopup: "dialog", ...(icon === undefined ? {} : { icon }), children: placeholder ?? copy.fieldPath.choose }) })) : (_jsxs(AriaButton, { "aria-label": value.length === 0 ? label : `${label}: ${shown}`, className: `flex min-w-0 flex-1 basis-40 items-center gap-2 rounded-control border px-2 py-1 text-left text-meta outline-0 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${frame}`, children: [_jsx("span", { className: `min-w-0 flex-1 truncate ${value.length === 0 ? "text-muted" : ""}`, children: shown }), _jsx(ChevronDown, { className: "size-(--size-icon-sm) shrink-0 text-muted", "aria-hidden": true })] })), _jsx(Popover, { placement: "bottom start", children: _jsx(Dialog, { "aria-label": label, className: "flex w-72 max-w-full flex-col gap-2 p-2 outline-0", children: ({ close }) => (_jsx(Levels, { models: models, start: value.slice(0, -1), canChoose: canChoose, canFollow: canFollow, onChoose: (path) => {
|
|
68
|
+
void resolvePath(models, path, copy.locale).then((found) => {
|
|
69
|
+
if (found !== null)
|
|
70
|
+
onChange(path, found);
|
|
71
|
+
});
|
|
72
|
+
close();
|
|
73
|
+
} })) }) })] }));
|
|
74
|
+
}
|
|
75
|
+
const SELF = "\u0000self";
|
|
76
|
+
function fold(text) {
|
|
77
|
+
return text
|
|
78
|
+
.normalize("NFD")
|
|
79
|
+
.replace(/\p{Diacritic}/gu, "")
|
|
80
|
+
.toLocaleLowerCase();
|
|
81
|
+
}
|
|
82
|
+
function Levels({ models, start, canChoose, canFollow, onChoose, }) {
|
|
83
|
+
const copy = useUiCopy();
|
|
84
|
+
const [at, setAt] = useState(start);
|
|
85
|
+
const [query, setQuery] = useState("");
|
|
86
|
+
const [level, setLevel] = useState({ status: "loading" });
|
|
87
|
+
const [attempt, setAttempt] = useState(0);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
let alive = true;
|
|
90
|
+
setLevel({ status: "loading" });
|
|
91
|
+
models.get(at).then((model) => {
|
|
92
|
+
if (alive)
|
|
93
|
+
setLevel({ status: "ready", model });
|
|
94
|
+
}, (error) => {
|
|
95
|
+
if (alive)
|
|
96
|
+
setLevel({
|
|
97
|
+
status: "failed",
|
|
98
|
+
error: error instanceof Error ? error.message : String(error),
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
return () => {
|
|
102
|
+
alive = false;
|
|
103
|
+
};
|
|
104
|
+
}, [models, at, attempt]);
|
|
105
|
+
function enter(name) {
|
|
106
|
+
setAt([...at, name]);
|
|
107
|
+
setQuery("");
|
|
108
|
+
}
|
|
109
|
+
function back() {
|
|
110
|
+
setAt(at.slice(0, -1));
|
|
111
|
+
setQuery("");
|
|
112
|
+
}
|
|
113
|
+
/* Backspace in an empty search goes up a level, the way it does in Odoo: the hand that
|
|
114
|
+
typed the search is already on the key. */
|
|
115
|
+
function onKeyDown(event) {
|
|
116
|
+
if (event.key === "Backspace" && query === "" && at.length > 0) {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
back();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const here = pathLabel(peekLabels(models, at, copy.locale));
|
|
122
|
+
/* The relation this level is inside, to offer choosing it as a whole. */
|
|
123
|
+
const parent = at.length === 0 ? undefined : models.peek(at.slice(0, -1));
|
|
124
|
+
const relationName = at[at.length - 1];
|
|
125
|
+
const relationField = relationName === undefined ? undefined : parent?.fields[relationName];
|
|
126
|
+
const offerSelf = relationField !== undefined &&
|
|
127
|
+
relationName !== undefined &&
|
|
128
|
+
canChoose(relationField, relationName, at.slice(0, -1));
|
|
129
|
+
const rows = level.status !== "ready"
|
|
130
|
+
? []
|
|
131
|
+
: Object.entries(level.model.fields)
|
|
132
|
+
.map(([name, field]) => ({
|
|
133
|
+
name,
|
|
134
|
+
field,
|
|
135
|
+
label: fieldLabel(level.model, name, copy.locale),
|
|
136
|
+
choose: canChoose(field, name, at),
|
|
137
|
+
follow: canFollow(field, name, at),
|
|
138
|
+
}))
|
|
139
|
+
.filter((row) => row.choose || row.follow)
|
|
140
|
+
.filter((row) => {
|
|
141
|
+
const q = fold(query.trim());
|
|
142
|
+
return q === "" || fold(row.label).includes(q) || fold(row.name).includes(q);
|
|
143
|
+
})
|
|
144
|
+
.sort((a, b) => a.label.localeCompare(b.label, copy.locale));
|
|
145
|
+
return (_jsxs("div", { onKeyDown: onKeyDown, className: "flex min-w-0 flex-col gap-2", children: [at.length === 0 ? null : (_jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [_jsx(IconButton, { icon: ChevronLeft, label: copy.fieldPath.back, onClick: back }), _jsx("p", { className: "min-w-0 flex-1 truncate text-meta font-medium text-ink", children: here })] })), _jsx(SearchField, { value: query, onChange: setQuery, "aria-label": copy.fieldPath.search, placeholder: copy.fieldPath.search }), level.status === "loading" ? (_jsx(Skeleton, { rows: 4, label: copy.fieldPath.loading })) : level.status === "failed" ? (_jsx(Failed, { heading: copy.fieldPath.failed, sentence: copy.fieldPath.failedHint, detail: `${at.join(".") || "/"} — ${level.error}`, action: _jsx(Button, { role: "secondary", size: "sm", onClick: () => setAttempt((n) => n + 1), children: copy.attachments.retry }) })) : rows.length === 0 && !offerSelf ? (_jsx("p", { className: "px-2 py-3 text-meta text-muted", children: copy.fieldPath.empty })) : (_jsxs(ListBox, { "aria-label": at.length === 0 ? copy.fieldPath.search : here, className: "max-h-72 min-w-0 overflow-auto outline-0", onAction: (key) => {
|
|
146
|
+
const name = String(key);
|
|
147
|
+
if (name === SELF)
|
|
148
|
+
return onChoose([...at]);
|
|
149
|
+
const row = rows.find((one) => one.name === name);
|
|
150
|
+
if (row === undefined)
|
|
151
|
+
return;
|
|
152
|
+
if (row.follow)
|
|
153
|
+
enter(name);
|
|
154
|
+
else if (row.choose)
|
|
155
|
+
onChoose([...at, name]);
|
|
156
|
+
}, children: [offerSelf && relationField !== undefined ? (_jsx(ListBoxItem, { id: SELF, textValue: fillCopy(copy.fieldPath.self, { label: here }), className: (state) => `${listOptionStyles(state)} border-b border-line font-medium`, children: fillCopy(copy.fieldPath.self, {
|
|
157
|
+
label: peekLabels(models, at, copy.locale).at(-1) ?? "",
|
|
158
|
+
}) })) : null, rows.map((row) => (_jsxs(ListBoxItem, { id: row.name, textValue: row.label, className: (state) => listOptionStyles(state), children: [_jsx("span", { className: "min-w-0 flex-1 truncate", children: row.label }), row.follow ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "sr-only", children: copy.fieldPath.opens }), _jsx(ChevronRight, { className: "size-(--size-icon-sm) shrink-0 text-muted", "aria-hidden": true })] })) : null] }, row.name)))] }))] }));
|
|
159
|
+
}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
import type { BuiltFilter, CriteriaJoin } from "./criteria.js";
|
|
1
|
+
import type { BuiltFilter, CriteriaJoin, ThroughMatch } from "./criteria.js";
|
|
2
2
|
import { type ModelDefinition } from "./model.js";
|
|
3
|
+
import { type LoadModel, type ModelCache } from "./paths.js";
|
|
3
4
|
/** Si esto es una de las formas que el filtro reconoce — condición, o grupo `all`/`any`/
|
|
4
5
|
* `negate`. Un JSON válido que no es ninguna de éstas —`{}`, `{"foo": 1}`, un array suelto—
|
|
5
6
|
* no es un filtro que este componente sepa dibujar, y se trata como error de forma en vez de
|
|
6
7
|
* intentar mostrar cualquier cosa. */
|
|
7
8
|
export declare function isRecognizedFilter(value: unknown): value is BuiltFilter;
|
|
9
|
+
/** One relation crossed on the way to a condition's field: «Líneas», and how many of the
|
|
10
|
+
* lines have to match. A to-one relation (`many: false`) reaches one record: no `match`. */
|
|
11
|
+
export interface TreeHop {
|
|
12
|
+
field: string;
|
|
13
|
+
many: boolean;
|
|
14
|
+
match: ThroughMatch;
|
|
15
|
+
}
|
|
8
16
|
export interface TreeCondition {
|
|
9
17
|
kind: "condition";
|
|
18
|
+
/** The relations crossed before `field`, in order: `Líneas > Impuestos` of «Líneas >
|
|
19
|
+
* Impuestos > Monto». Absent or empty = a field of the record itself. */
|
|
20
|
+
through?: TreeHop[];
|
|
21
|
+
/** The LAST field of the path: the one compared. Its operators and its type decide the
|
|
22
|
+
* rest of the row. */
|
|
10
23
|
field: string;
|
|
11
24
|
operator: string;
|
|
12
25
|
value: string;
|
|
@@ -78,19 +91,27 @@ export declare function treeFromFilter(filter: unknown): TreeNode | null;
|
|
|
78
91
|
* Un grupo anidado se encierra entre paréntesis, que es lo que evita que «a y (b o c)» se
|
|
79
92
|
* lea como «(a y b) o c». Para más de tres condiciones se corta: una ficha que no entra en
|
|
80
93
|
* la barra no dice nada — para eso está abrir el constructor y verlo entero. */
|
|
81
|
-
export declare function describeFilter(node: BuiltFilter, model?: ModelDefinition
|
|
94
|
+
export declare function describeFilter(node: BuiltFilter, model?: ModelDefinition,
|
|
95
|
+
/** The model at the end of a path of relations, when it already arrived: it names the
|
|
96
|
+
* fields of a `through`. Without it they keep their raw names. */
|
|
97
|
+
modelAt?: (path: readonly string[]) => ModelDefinition | undefined): string;
|
|
82
98
|
/** El filtro dibujado tal como es, recursivo: una condición es una línea, `all`/`any` son un
|
|
83
99
|
* grupo con su rótulo y sus hijos adentro, `negate` es «no» envolviendo al que niega.
|
|
84
100
|
*
|
|
85
101
|
* Es la mitad de sólo lectura de este archivo, y también sirve sola: mostrar qué dice un
|
|
86
102
|
* filtro que ya está puesto no necesita abrir el constructor. */
|
|
87
|
-
export declare function ExpressionView({ node, model, depth, }: {
|
|
103
|
+
export declare function ExpressionView({ node, model, depth, modelAt, at, }: {
|
|
88
104
|
node: BuiltFilter;
|
|
89
105
|
/** Quién sabe cómo se llama un campo. Sin él queda el nombre crudo. */
|
|
90
106
|
model?: ModelDefinition;
|
|
91
107
|
depth?: number;
|
|
108
|
+
/** El modelo al final de un camino de relaciones, si ya llegó: nombra los campos de un
|
|
109
|
+
* `through`. */
|
|
110
|
+
modelAt?: (path: readonly string[]) => ModelDefinition | undefined;
|
|
111
|
+
/** El camino hasta acá (por los `through` de afuera). */
|
|
112
|
+
at?: readonly string[];
|
|
92
113
|
}): import("react").JSX.Element;
|
|
93
|
-
export declare function WhereTree({ model, group, onChange, depth, focus, }: {
|
|
114
|
+
export declare function WhereTree({ model, group, onChange, depth, focus, loadModel, models: shared, }: {
|
|
94
115
|
model: ModelDefinition;
|
|
95
116
|
group: TreeGroup;
|
|
96
117
|
onChange: (next: TreeGroup) => void;
|
|
@@ -114,9 +135,21 @@ export declare function WhereTree({ model, group, onChange, depth, focus, }: {
|
|
|
114
135
|
* el otro.
|
|
115
136
|
*/
|
|
116
137
|
focus?: string;
|
|
138
|
+
/** El modelo al final de un camino de relaciones. Con esto, el campo de cada regla puede
|
|
139
|
+
* ser uno de un registro relacionado («Líneas > Impuestos > Monto»). */
|
|
140
|
+
loadModel?: LoadModel;
|
|
141
|
+
/** La caché de modelos que comparten las reglas. La arma el árbol de afuera. */
|
|
142
|
+
models?: ModelCache;
|
|
117
143
|
}): import("react").JSX.Element;
|
|
118
|
-
export declare function FilterBuilder({ model, initial, onApply, onCancel, }: {
|
|
144
|
+
export declare function FilterBuilder({ model, initial, onApply, onCancel, loadModel, models: shared, }: {
|
|
119
145
|
model: ModelDefinition;
|
|
146
|
+
/** El modelo al final de un camino de relaciones. Con esto, una regla puede preguntar por
|
|
147
|
+
* un campo de un registro relacionado: «alguna línea con algún impuesto con monto > 10».
|
|
148
|
+
* web-ui no pide nada: quien dibuja el constructor sabe de dónde salen los modelos. */
|
|
149
|
+
loadModel?: LoadModel;
|
|
150
|
+
/** Una caché de modelos compartida con quien dibuja el constructor —la misma que usa para
|
|
151
|
+
* describir el filtro aplicado con `describeFilter(…, modelAt)`—. Sin esto, una propia. */
|
|
152
|
+
models?: ModelCache;
|
|
120
153
|
/** El filtro que ya estaba puesto, si había uno. Reabrir el constructor con esto adentro
|
|
121
154
|
* tiene que seguir donde quedó, no empezar en blanco. */
|
|
122
155
|
initial?: BuiltFilter;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { FieldPath, useFieldPathSteps, useModelCache, } from "./FieldPath.js";
|
|
3
4
|
import { JoinWord } from "./JoinWord.js";
|
|
4
5
|
import { LazyJsonEditor } from "./LazyJsonEditor.js";
|
|
5
|
-
import { fieldLabel, filterableNames, } from "./model.js";
|
|
6
|
+
import { fieldLabel, filterableNames, isFilterable, } from "./model.js";
|
|
7
|
+
import { isToMany, } from "./paths.js";
|
|
6
8
|
import { opLabel, sayCondition } from "./query.js";
|
|
7
9
|
import { currentCopy, fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
8
10
|
import { useSurface } from "../../foundations/surface.js";
|
|
@@ -80,8 +82,19 @@ export function isRecognizedFilter(value) {
|
|
|
80
82
|
return true;
|
|
81
83
|
if ("negate" in record)
|
|
82
84
|
return true;
|
|
85
|
+
if (typeof record.through === "string" && "where" in record)
|
|
86
|
+
return true;
|
|
83
87
|
return false;
|
|
84
88
|
}
|
|
89
|
+
const MATCHES = ["any", "none", "all"];
|
|
90
|
+
function isThrough(value) {
|
|
91
|
+
if (typeof value !== "object" || value === null)
|
|
92
|
+
return false;
|
|
93
|
+
const record = value;
|
|
94
|
+
return (typeof record.through === "string" &&
|
|
95
|
+
"where" in record &&
|
|
96
|
+
(record.match === undefined || MATCHES.includes(record.match)));
|
|
97
|
+
}
|
|
85
98
|
export function blankCondition(model, first) {
|
|
86
99
|
const field = first ?? "";
|
|
87
100
|
return {
|
|
@@ -108,6 +121,20 @@ export function blankGroup(model, first) {
|
|
|
108
121
|
* haberlo anidado. */
|
|
109
122
|
export function treeToFilter(node) {
|
|
110
123
|
if (node.kind === "condition") {
|
|
124
|
+
const leaf = conditionToFilter(node);
|
|
125
|
+
return leaf === undefined ? undefined : wrapThrough(node.through ?? [], leaf);
|
|
126
|
+
}
|
|
127
|
+
return groupToFilter(node);
|
|
128
|
+
}
|
|
129
|
+
/** The relations of a path, as nested `through` nodes around the condition: the first hop
|
|
130
|
+
* outside, the last one next to the condition — the order the path reads in. */
|
|
131
|
+
function wrapThrough(hops, leaf) {
|
|
132
|
+
return hops.reduceRight((inner, hop) => hop.many
|
|
133
|
+
? { through: hop.field, match: hop.match, where: inner }
|
|
134
|
+
: { through: hop.field, where: inner }, leaf);
|
|
135
|
+
}
|
|
136
|
+
function conditionToFilter(node) {
|
|
137
|
+
{
|
|
111
138
|
if (node.field === "")
|
|
112
139
|
return undefined;
|
|
113
140
|
if (WITHOUT_VALUE.has(node.operator)) {
|
|
@@ -129,6 +156,8 @@ export function treeToFilter(node) {
|
|
|
129
156
|
return undefined;
|
|
130
157
|
return { field: node.field, operator: node.operator, value: node.value };
|
|
131
158
|
}
|
|
159
|
+
}
|
|
160
|
+
function groupToFilter(node) {
|
|
132
161
|
const kept = node.children
|
|
133
162
|
.map(treeToFilter)
|
|
134
163
|
.filter((one) => one !== undefined);
|
|
@@ -188,6 +217,24 @@ function conditionToTree(condition) {
|
|
|
188
217
|
export function treeFromFilter(filter) {
|
|
189
218
|
if (isCondition(filter))
|
|
190
219
|
return conditionToTree(filter);
|
|
220
|
+
/* A chain of relations ending in ONE condition is one row with its path. A chain that ends
|
|
221
|
+
in a group («alguna línea con impuesto > 10 Y cantidad > 2», both about the SAME line)
|
|
222
|
+
cannot be a row: the tree shows it read-only and the JSON stays the way to edit it. */
|
|
223
|
+
if (isThrough(filter)) {
|
|
224
|
+
const hops = [];
|
|
225
|
+
let node = filter;
|
|
226
|
+
while (isThrough(node)) {
|
|
227
|
+
hops.push({
|
|
228
|
+
field: node.through,
|
|
229
|
+
many: node.match !== undefined,
|
|
230
|
+
match: node.match ?? "any",
|
|
231
|
+
});
|
|
232
|
+
node = node.where;
|
|
233
|
+
}
|
|
234
|
+
if (!isCondition(node))
|
|
235
|
+
return null;
|
|
236
|
+
return { ...conditionToTree(node), through: hops };
|
|
237
|
+
}
|
|
191
238
|
if (typeof filter !== "object" || filter === null)
|
|
192
239
|
return null;
|
|
193
240
|
const record = filter;
|
|
@@ -265,23 +312,37 @@ function describeValue(value, operator) {
|
|
|
265
312
|
* Un grupo anidado se encierra entre paréntesis, que es lo que evita que «a y (b o c)» se
|
|
266
313
|
* lea como «(a y b) o c». Para más de tres condiciones se corta: una ficha que no entra en
|
|
267
314
|
* la barra no dice nada — para eso está abrir el constructor y verlo entero. */
|
|
268
|
-
export function describeFilter(node, model
|
|
269
|
-
|
|
315
|
+
export function describeFilter(node, model,
|
|
316
|
+
/** The model at the end of a path of relations, when it already arrived: it names the
|
|
317
|
+
* fields of a `through`. Without it they keep their raw names. */
|
|
318
|
+
modelAt) {
|
|
319
|
+
return say(node, model, 0, [], modelAt);
|
|
270
320
|
}
|
|
271
|
-
function say(node, model, depth) {
|
|
321
|
+
function say(node, model, depth, at, modelAt) {
|
|
272
322
|
const copy = currentCopy();
|
|
323
|
+
if ("through" in node) {
|
|
324
|
+
/* «alguno de Líneas con alguno de Impuestos con Monto mayor que 10». The quantifier
|
|
325
|
+
is a separate word and not «algún impuesto» because the model publishes the label,
|
|
326
|
+
not its gender or its singular: «algún Impuestos» would be worse than neutral. */
|
|
327
|
+
const relation = model === undefined ? node.through : fieldLabel(model, node.through, copy.locale);
|
|
328
|
+
const next = [...at, node.through];
|
|
329
|
+
const inner = say(node.where, modelAt?.(next), depth + 1, next, modelAt);
|
|
330
|
+
const template = node.match === undefined ? copy.fieldPath.say.one : copy.fieldPath.say[node.match];
|
|
331
|
+
return fillCopy(template, { relation, inner });
|
|
332
|
+
}
|
|
273
333
|
if ("all" in node || "any" in node) {
|
|
274
334
|
const items = "all" in node ? node.all : node.any;
|
|
275
335
|
const glue = "all" in node ? copy.search.and : copy.search.or;
|
|
276
|
-
const said = items.slice(0, 3).map((child) => say(child, model, depth + 1));
|
|
336
|
+
const said = items.slice(0, 3).map((child) => say(child, model, depth + 1, at, modelAt));
|
|
277
337
|
if (items.length > 3) {
|
|
278
338
|
said.push(fillCopy(copy.search.andMore, { count: items.length - 3 }));
|
|
279
339
|
}
|
|
280
340
|
const joined = said.join(` ${glue} `);
|
|
281
341
|
return depth === 0 || said.length === 1 ? joined : `(${joined})`;
|
|
282
342
|
}
|
|
283
|
-
if ("negate" in node)
|
|
284
|
-
return `${copy.search.notWord} ${say(node.negate, model, depth + 1)}`;
|
|
343
|
+
if ("negate" in node) {
|
|
344
|
+
return `${copy.search.notWord} ${say(node.negate, model, depth + 1, at, modelAt)}`;
|
|
345
|
+
}
|
|
285
346
|
const label = model === undefined ? node.field : fieldLabel(model, node.field, copy.locale);
|
|
286
347
|
return sayCondition(label, node.operator, describeValue(node.value, node.operator));
|
|
287
348
|
}
|
|
@@ -290,11 +351,19 @@ function say(node, model, depth) {
|
|
|
290
351
|
*
|
|
291
352
|
* Es la mitad de sólo lectura de este archivo, y también sirve sola: mostrar qué dice un
|
|
292
353
|
* filtro que ya está puesto no necesita abrir el constructor. */
|
|
293
|
-
export function ExpressionView({ node, model, depth = 0, }) {
|
|
354
|
+
export function ExpressionView({ node, model, depth = 0, modelAt, at = [], }) {
|
|
294
355
|
const surface = useSurface();
|
|
295
356
|
const copy = useUiCopy();
|
|
296
357
|
const box = surface === "chrome" ? "border-chrome-ink/20" : "border-ink/15";
|
|
297
358
|
const indent = depth === 0 ? "" : "ml-4";
|
|
359
|
+
if ("through" in node) {
|
|
360
|
+
const relation = model === undefined ? node.through : fieldLabel(model, node.through, copy.locale);
|
|
361
|
+
const next = [...at, node.through];
|
|
362
|
+
const inner = modelAt?.(next);
|
|
363
|
+
return (_jsxs("div", { className: `flex flex-col gap-1 border-l-2 pl-2 ${box} ${indent}`, children: [_jsx("p", { className: "text-micro text-muted", children: node.match === undefined
|
|
364
|
+
? relation
|
|
365
|
+
: `${copy.fieldPath.match[node.match]} · ${relation}` }), _jsx(ExpressionView, { node: node.where, ...(inner === undefined ? {} : { model: inner }), ...(modelAt === undefined ? {} : { modelAt }), at: next, depth: depth + 1 })] }));
|
|
366
|
+
}
|
|
298
367
|
if ("all" in node || "any" in node) {
|
|
299
368
|
/* LAS MISMAS TRES PALABRAS QUE LA BARRA. Un grupo que acá se llama «coincide
|
|
300
369
|
con alguna» y en la ficha «cualquiera» son dos vocabularios para una sola
|
|
@@ -312,10 +381,11 @@ export function ExpressionView({ node, model, depth = 0, }) {
|
|
|
312
381
|
/* ---------------------------------------------------------------------- *
|
|
313
382
|
* UN GRUPO, DIBUJADO — la pieza que se llama a sí misma para anidar.
|
|
314
383
|
* ---------------------------------------------------------------------- */
|
|
315
|
-
export function WhereTree({ model, group, onChange, depth = 0, focus, }) {
|
|
384
|
+
export function WhereTree({ model, group, onChange, depth = 0, focus, loadModel, models: shared, }) {
|
|
316
385
|
const names = filterableNames(model);
|
|
317
386
|
const copy = useUiCopy();
|
|
318
387
|
const surface = useSurface();
|
|
388
|
+
const models = useModelCache(model, loadModel, shared);
|
|
319
389
|
const box = surface === "chrome"
|
|
320
390
|
? "border-chrome-ink/20 bg-chrome text-chrome-ink"
|
|
321
391
|
: "border-ink/15 bg-surface text-ink";
|
|
@@ -348,23 +418,57 @@ export function WhereTree({ model, group, onChange, depth = 0, focus, }) {
|
|
|
348
418
|
function removeAt(index) {
|
|
349
419
|
onChange({ ...group, children: group.children.filter((_, at) => at !== index) });
|
|
350
420
|
}
|
|
351
|
-
return (_jsxs("div", { className: `flex min-w-0 flex-col gap-2 rounded-control border p-2 ${box}`, children: [_jsxs("p", { className: "flex flex-wrap items-baseline gap-1 text-meta", children: [copy.search.askJoin, _jsx(JoinWord, { join: group.join, onChange: (join) => onChange({ ...group, join }) })] }), group.children.map((child, index) => child.kind === "group" ? (_jsxs("div", { className: "flex min-w-0 items-start gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(WhereTree, { model: model, group: child, onChange: (next) => setChild(index, next), depth: depth + 1, ...(focus === undefined ? {} : { focus }) }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropGroup, disabled: group.children.length === 1, onClick: () => removeAt(index), className: "mt-2 text-muted disabled:opacity-30", children: _jsx(Trash2, { className: "size-4" }) })] }, index)) : (_jsxs("
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
421
|
+
return (_jsxs("div", { className: `flex min-w-0 flex-col gap-2 rounded-control border p-2 ${box}`, children: [_jsxs("p", { className: "flex flex-wrap items-baseline gap-1 text-meta", children: [copy.search.askJoin, _jsx(JoinWord, { join: group.join, onChange: (join) => onChange({ ...group, join }) })] }), group.children.map((child, index) => child.kind === "group" ? (_jsxs("div", { className: "flex min-w-0 items-start gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(WhereTree, { model: model, group: child, onChange: (next) => setChild(index, next), depth: depth + 1, models: models, ...(focus === undefined ? {} : { focus }) }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropGroup, disabled: group.children.length === 1, onClick: () => removeAt(index), className: "mt-2 text-muted disabled:opacity-30", children: _jsx(Trash2, { className: "size-4" }) })] }, index)) : (_jsx(ConditionRow, { model: model, models: models, child: child, box: box, focused: focus !== undefined && child.field === focus, onChange: (next) => setChild(index, next), actions: _jsxs("span", { className: "ml-auto flex shrink-0 items-center gap-2", children: [_jsx("button", { type: "button", "aria-label": copy.builder.addRule, onClick: () => addConditionAfter(index), className: "text-muted hover:text-ink", children: _jsx(Plus, { className: "size-4" }) }), _jsx("button", { type: "button", "aria-label": copy.builder.addNested, onClick: () => addGroupAfter(index), className: "text-muted hover:text-ink", children: _jsx(FolderTree, { className: "size-4" }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropRule, disabled: group.children.length === 1, onClick: () => removeAt(index), className: "text-muted disabled:opacity-30", children: _jsx(Trash2, { className: "size-4" }) })] }) }, index)))] }));
|
|
422
|
+
}
|
|
423
|
+
/* ---------------------------------------------------------------------- *
|
|
424
|
+
* UNA REGLA — el camino hasta el campo, cuántos de cada relación, el operador y el valor.
|
|
425
|
+
* ---------------------------------------------------------------------- */
|
|
426
|
+
function ConditionRow({ model, models, child, box, focused, onChange, actions, }) {
|
|
427
|
+
const copy = useUiCopy();
|
|
428
|
+
const hops = child.through ?? [];
|
|
429
|
+
const path = child.field === "" ? [] : [...hops.map((hop) => hop.field), child.field];
|
|
430
|
+
const steps = useFieldPathSteps(models, path);
|
|
431
|
+
/* El operador y el valor salen del ÚLTIMO campo del camino: «Monto», alcanzado por dos
|
|
432
|
+
relaciones, se compara como un número y no como la relación por la que se llegó. Una
|
|
433
|
+
regla de la raíz lo sabe sin esperar a nadie. */
|
|
434
|
+
const leaf = steps?.at(-1)?.field ?? (hops.length === 0 ? model.fields[child.field] : undefined);
|
|
435
|
+
const ops = leaf?.ops ?? [];
|
|
436
|
+
const type = leaf?.type ?? "text";
|
|
437
|
+
function choosePath(next, found) {
|
|
438
|
+
const last = found.at(-1);
|
|
439
|
+
if (last === undefined)
|
|
440
|
+
return;
|
|
441
|
+
const nextHops = found.slice(0, -1).map((step, at) => ({
|
|
442
|
+
field: step.name,
|
|
443
|
+
many: isToMany(step.field),
|
|
444
|
+
/* Cambiar el campo final no reinicia la ficha de una relación que sigue en el camino. */
|
|
445
|
+
match: hops[at]?.field === step.name ? hops[at].match : "any",
|
|
446
|
+
}));
|
|
447
|
+
onChange({
|
|
448
|
+
...child,
|
|
449
|
+
through: nextHops.length === 0 ? undefined : nextHops,
|
|
450
|
+
field: next[next.length - 1] ?? "",
|
|
451
|
+
operator: last.field.ops.includes(child.operator)
|
|
452
|
+
? child.operator
|
|
453
|
+
: (last.field.ops[0] ?? "="),
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function setMatch(at, match) {
|
|
457
|
+
onChange({
|
|
458
|
+
...child,
|
|
459
|
+
through: hops.map((hop, i) => (i === at ? { ...hop, match } : hop)),
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
return (_jsxs("div", {
|
|
463
|
+
/* La que se vino a ver se marca y se trae a la vista. El anillo y no
|
|
464
|
+
un fondo: el fondo compite con el `select` que hay que tocar. */
|
|
465
|
+
ref: focused ? (node) => node?.scrollIntoView({ block: "nearest" }) : undefined, className: `flex min-w-0 flex-wrap items-center gap-2 rounded-control ${focused ? "-m-1 p-1 ring-1 ring-primary/60" : ""}`, children: [_jsx(FieldPath, { model: model, models: models, value: path, label: copy.builder.ruleField, filter: (field) => isFilterable(field), onChange: choosePath }), hops.map((hop, at) => hop.many ? (_jsxs("label", { className: `flex min-w-0 shrink-0 items-center gap-1 rounded-control border px-2 py-0.5 text-micro ${box}`, children: [_jsx("span", { className: "max-w-32 truncate text-muted", children: steps?.[at]?.label ?? hop.field }), _jsx("select", { "aria-label": fillCopy(copy.fieldPath.match.label, {
|
|
466
|
+
relation: steps?.[at]?.label ?? hop.field,
|
|
467
|
+
}), value: hop.match, onChange: (event) => setMatch(at, event.target.value), className: "bg-transparent text-micro font-medium", children: MATCHES.map((match) => (_jsx("option", { value: match, children: copy.fieldPath.match[match] }, match))) })] }, `${hop.field}-${at}`)) : null), _jsx("select", { "aria-label": copy.builder.ruleOperator, value: child.operator, onChange: (event) => onChange({ ...child, operator: event.target.value }), className: `min-w-0 flex-1 basis-36 rounded-control border px-2 py-1 text-meta ${box}`, children: ops.map((operator) => (_jsx("option", { value: operator, children: opLabel(operator) }, operator))) }), WITHOUT_VALUE.has(child.operator) ? (_jsx("span", { className: "flex-1 text-meta text-muted", children: copy.builder.noValue })) : WITH_RANGE.has(child.operator) ? (_jsxs("span", { className: "flex min-w-0 flex-1 basis-40 items-center gap-1", children: [_jsx("input", { type: inputType(type), value: child.value, onChange: (event) => onChange({ ...child, value: event.target.value }), placeholder: copy.builder.from, className: `min-w-0 flex-1 rounded-control border px-2 py-1 text-meta ${box}` }), _jsx("span", { className: "shrink-0 text-micro text-muted", children: copy.search.and }), _jsx("input", { type: inputType(type), value: child.upper ?? "", onChange: (event) => onChange({ ...child, upper: event.target.value }), placeholder: copy.builder.to, className: `min-w-0 flex-1 rounded-control border px-2 py-1 text-meta ${box}` })] })) : (_jsx("input", { type: inputType(type), value: child.value, onChange: (event) => onChange({ ...child, value: event.target.value }), placeholder: copy.builder.value, className: `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}` })), actions] }));
|
|
365
468
|
}
|
|
366
|
-
export function FilterBuilder({ model, initial, onApply, onCancel, }) {
|
|
469
|
+
export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, models: shared, }) {
|
|
367
470
|
const names = filterableNames(model);
|
|
471
|
+
const models = useModelCache(model, loadModel, shared);
|
|
368
472
|
const copy = useUiCopy();
|
|
369
473
|
const decomposed = initial === undefined ? null : treeFromFilter(initial);
|
|
370
474
|
const [tree, setTree] = useState(() => decomposed !== null && decomposed.kind === "group"
|
|
@@ -417,5 +521,5 @@ export function FilterBuilder({ model, initial, onApply, onCancel, }) {
|
|
|
417
521
|
setLockedView(parsed);
|
|
418
522
|
}
|
|
419
523
|
}
|
|
420
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsx("div", { className: "max-h-80 min-w-0 overflow-auto", children: lockedView !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedView, model: model })] })) : (_jsx(WhereTree, { model: model, group: tree, onChange: updateTree })) }), _jsx(LazyJsonEditor, { value: rawText, onChange: updateRaw, error: rawError, label: copy.builder.jsonFilter }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { role: "primary", disabled: rawError !== null, onClick: () => onApply(rawText.trim() === "" ? undefined : JSON.parse(rawText)), children: copy.builder.add }), onCancel === undefined ? null : (_jsx(Button, { role: "ghost", onClick: onCancel, children: copy.builder.cancel }))] })] }));
|
|
524
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsx("div", { className: "max-h-80 min-w-0 overflow-auto", children: lockedView !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedView, model: model, modelAt: models.peek })] })) : (_jsx(WhereTree, { model: model, group: tree, onChange: updateTree, models: models })) }), _jsx(LazyJsonEditor, { value: rawText, onChange: updateRaw, error: rawError, label: copy.builder.jsonFilter }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { role: "primary", disabled: rawError !== null, onClick: () => onApply(rawText.trim() === "" ? undefined : JSON.parse(rawText)), children: copy.builder.add }), onCancel === undefined ? null : (_jsx(Button, { role: "ghost", onClick: onCancel, children: copy.builder.cancel }))] })] }));
|
|
421
525
|
}
|
|
@@ -241,14 +241,19 @@ export function SearchBar({ facets, model, criteria, onCriteriaChange, placehold
|
|
|
241
241
|
? one
|
|
242
242
|
: { ...node, of: [...node.of, one] };
|
|
243
243
|
}
|
|
244
|
-
return (_jsxs("div", { ref: box, onKeyDown: closePanelOnEscape,
|
|
244
|
+
return (_jsxs("div", { ref: box, onKeyDown: closePanelOnEscape,
|
|
245
|
+
/* `min-w-48`: placed in a flex row without a width, the bar used to collapse to its
|
|
246
|
+
narrowest and the input slid UNDER the filters button («bu⊞car»). 12rem is the
|
|
247
|
+
magnifier, a word of input and the buttons; a narrower container scrolls, it does
|
|
248
|
+
not stack controls on top of each other. */
|
|
249
|
+
className: "relative flex min-w-48 items-center gap-2", children: [_jsxs("div", { className: `@container/bar flex min-h-(--size-control-md) w-full min-w-0 items-start rounded-box border transition-colors duration-(--duration-instant) ${bySurface(sup, "border-line-strong bg-surface focus-within:border-primary/60",
|
|
245
250
|
/* Sobre el cromo lo que define al campo es el BORDE, no el relleno. El
|
|
246
251
|
azul ya es casi negro, así que hundirlo no da contraste (1,05:1) y
|
|
247
252
|
levantarlo da 1,21:1 — en los dos casos el campo no se lee como un
|
|
248
253
|
campo, que era «no llama la atención». La tinta al 45 % es el primer
|
|
249
254
|
borde que pasa 3:1 contra el relleno Y contra el cromo, que es lo que
|
|
250
255
|
1.4.11 le pide a un control. */
|
|
251
|
-
"border-chrome-ink/45 bg-chrome-ink/8 focus-within:border-chrome-link")}`, children: [_jsx("span", { className: "mt-0.75 flex h-7 shrink-0 items-center pr-1.5 pl-2.5", children: _jsx(Search, { className: "size-(--size-icon-md) shrink-0 text-muted", strokeWidth: 2, "aria-hidden": true }) }), _jsxs("div", { className: "flex min-w-
|
|
256
|
+
"border-chrome-ink/45 bg-chrome-ink/8 focus-within:border-chrome-link")}`, children: [_jsx("span", { className: "mt-0.75 flex h-7 shrink-0 items-center pr-1.5 pl-2.5", children: _jsx(Search, { className: "size-(--size-icon-md) shrink-0 text-muted", strokeWidth: 2, "aria-hidden": true }) }), _jsxs("div", { className: "flex min-w-24 flex-1 flex-wrap items-center gap-1 py-0.75", children: [_jsx(CriteriaChips, { criteria: criteria, surface: sup, ...(openGroup === null ? {} : { open: openGroup }), ...(onOpenBuilder === undefined ? {} : { onOpen: onOpenBuilder }), ...(collapseAfter === undefined ? {} : { collapseAfter }), onRemoveMany: (paths) => {
|
|
252
257
|
/* From the deepest index up, so each removal leaves the next path valid. */
|
|
253
258
|
const sorted = [...paths].sort((a, b) => (b[0] ?? 0) - (a[0] ?? 0));
|
|
254
259
|
onCriteriaChange(sorted.reduce((left, path) => removeAt(left, path), [...criteria]));
|
|
@@ -15,7 +15,29 @@ export type BuiltFilter = BuiltCondition | {
|
|
|
15
15
|
any: BuiltFilter[];
|
|
16
16
|
} | {
|
|
17
17
|
negate: BuiltFilter;
|
|
18
|
-
};
|
|
18
|
+
} | BuiltThrough;
|
|
19
|
+
/** How many of the records reached through a to-many relation have to match: «alguno»,
|
|
20
|
+
* «ninguno», «todos». A to-one relation reaches one record, so it carries none. */
|
|
21
|
+
export type ThroughMatch = "any" | "none" | "all";
|
|
22
|
+
/**
|
|
23
|
+
* A filter asked about the records at the other end of a relation.
|
|
24
|
+
*
|
|
25
|
+
* «alguna línea con algún impuesto con monto > 10»
|
|
26
|
+
* {through: "lines", match: "any",
|
|
27
|
+
* where: {through: "taxes", match: "any",
|
|
28
|
+
* where: {field: "amount", operator: ">", value: 10}}}
|
|
29
|
+
*
|
|
30
|
+
* «el cliente es de Bolivia» (to-one: no `match`)
|
|
31
|
+
* {through: "partner_id", where: {field: "country", operator: "=", value: "BO"}}
|
|
32
|
+
*
|
|
33
|
+
* One node per relation crossed, nested in the order of the path: the engine reads it from
|
|
34
|
+
* the outside in, the same way the path reads left to right.
|
|
35
|
+
*/
|
|
36
|
+
export interface BuiltThrough {
|
|
37
|
+
through: string;
|
|
38
|
+
match?: ThroughMatch;
|
|
39
|
+
where: BuiltFilter;
|
|
40
|
+
}
|
|
19
41
|
/** Cómo se juntan las instancias de un nodo. `not` niega lo que tiene adentro. */
|
|
20
42
|
export type CriteriaJoin = "all" | "any" | "not";
|
|
21
43
|
/**
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { type BuiltCondition, type BuiltFilter, } from "./criteria.js";
|
|
1
|
+
export { type BuiltCondition, type BuiltFilter, type BuiltThrough, type ThroughMatch, } from "./criteria.js";
|
|
2
2
|
export { type BuiltCriteria, type BuiltLevel, type BuiltSort, CriteriaBuilder, } from "./CriteriaBuilder.js";
|
|
3
|
-
export { blankGroup, describeFilter, FilterBuilder, type TreeCondition, treeFromFilter, type TreeGroup, type TreeNode, treeToFilter, } from "./FilterBuilder.js";
|
|
3
|
+
export { blankGroup, describeFilter, FilterBuilder, type TreeCondition, treeFromFilter, type TreeGroup, type TreeHop, type TreeNode, treeToFilter, } from "./FilterBuilder.js";
|
|
4
|
+
export { FieldPath, type FieldPathProps, type FieldPathRule, type PathPick, useFieldPathSteps, useModelCache, } from "./FieldPath.js";
|
|
4
5
|
export { formatJson, JsonEditor } from "./JsonEditor.js";
|
|
6
|
+
export { createModelCache, type FieldPathStep, type FieldPathValue, isRelation, isToMany, type LoadModel, type ModelCache, pathLabel, peekLabels, resolvePath, } from "./paths.js";
|
|
5
7
|
export { SearchBar, type SearchBarProps, type SearchFacet, } from "./SearchBar.js";
|
|
6
8
|
export { at, criteriaId, type CriteriaJoin, type CriteriaPath, filterCriteria, filtersOf, type GroupCriteria, groupCriteria, groupsOf, hasNamed, levelsOf, nextJoin, removeAt, replaceAt, type SearchCriteria, toggleNamed, whereOf, withLevels, } from "./criteria.js";
|
|
7
9
|
export { CriteriaChips, type CriteriaChipsProps, } from "./CriteriaChips.js";
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
export {} from "./criteria.js";
|
|
3
3
|
export { CriteriaBuilder, } from "./CriteriaBuilder.js";
|
|
4
4
|
export { blankGroup, describeFilter, FilterBuilder, treeFromFilter, treeToFilter, } from "./FilterBuilder.js";
|
|
5
|
+
/* Un campo alcanzado por relaciones: el selector (web-ui dibuja) y su modelo (quien lo usa
|
|
6
|
+
pasa `loadModel`). */
|
|
7
|
+
export { FieldPath, useFieldPathSteps, useModelCache, } from "./FieldPath.js";
|
|
5
8
|
export { formatJson, JsonEditor } from "./JsonEditor.js";
|
|
9
|
+
export { createModelCache, isRelation, isToMany, pathLabel, peekLabels, resolvePath, } from "./paths.js";
|
|
6
10
|
export { SearchBar, } from "./SearchBar.js";
|
|
7
11
|
/* LO QUE LA BARRA TIENE PUESTO: instancias. Una sola cosa para las dos clases
|
|
8
12
|
—grupo y filtro—, con sus metadatos de UI afuera y el objeto del motor
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type FieldDefinition, type ModelDefinition } from "./model.js";
|
|
2
|
+
export type FieldPathValue = readonly string[];
|
|
3
|
+
/** Answers the model at the end of a path of relation fields. The root is `[]`, and is
|
|
4
|
+
* never asked: the picker already has it. */
|
|
5
|
+
export type LoadModel = (path: FieldPathValue) => Promise<ModelDefinition>;
|
|
6
|
+
/** One step of a resolved path: the field, its definition and how it is called. */
|
|
7
|
+
export interface FieldPathStep {
|
|
8
|
+
name: string;
|
|
9
|
+
field: FieldDefinition;
|
|
10
|
+
label: string;
|
|
11
|
+
}
|
|
12
|
+
/** Whether a field points to another model: the picker can walk into it. */
|
|
13
|
+
export declare function isRelation(field: FieldDefinition): boolean;
|
|
14
|
+
/** Whether a relation reaches MANY records. A filter through it has to say how many of them
|
|
15
|
+
* must match: some, none or all. */
|
|
16
|
+
export declare function isToMany(field: FieldDefinition): boolean;
|
|
17
|
+
/** «Líneas > Impuestos > Monto»: how a path reads on a button or a chip. */
|
|
18
|
+
export declare function pathLabel(labels: readonly string[]): string;
|
|
19
|
+
/**
|
|
20
|
+
* The models along paths, asked once each.
|
|
21
|
+
*
|
|
22
|
+
* Context: a filter with five rules over the same relation would ask the same model five
|
|
23
|
+
* times, once per row, and the popover asks again each time it reopens. The cache keeps the
|
|
24
|
+
* PROMISE, so two rows asking at the same moment share one request, and a failed request is
|
|
25
|
+
* forgotten so the next attempt can succeed.
|
|
26
|
+
*/
|
|
27
|
+
export interface ModelCache {
|
|
28
|
+
root: ModelDefinition;
|
|
29
|
+
/** Whether relations can be followed at all: there is a `loadModel` behind it. */
|
|
30
|
+
canLoad: boolean;
|
|
31
|
+
/** The model at the end of a path of relations; `[]` is the root. */
|
|
32
|
+
get: (path: FieldPathValue) => Promise<ModelDefinition>;
|
|
33
|
+
/** The same, only if it already arrived — for code that cannot wait, like a label. */
|
|
34
|
+
peek: (path: FieldPathValue) => ModelDefinition | undefined;
|
|
35
|
+
}
|
|
36
|
+
export declare function createModelCache(root: ModelDefinition, loadModel?: LoadModel): ModelCache;
|
|
37
|
+
/**
|
|
38
|
+
* A path resolved into its steps: each field with its definition and its label.
|
|
39
|
+
*
|
|
40
|
+
* in ["lines", "taxes", "amount"], the invoice model
|
|
41
|
+
* out [Líneas (to-many), Impuestos (to-many), Monto (number)]
|
|
42
|
+
*
|
|
43
|
+
* A name the model does not have stops the walk: it answers `null`, because half a path is
|
|
44
|
+
* a different question, not a shorter one.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolvePath(models: ModelCache, path: FieldPathValue, locale: string): Promise<FieldPathStep[] | null>;
|
|
47
|
+
/** The labels of a path with what has already arrived; a model still on its way leaves the
|
|
48
|
+
* raw name, which is what there is to say until it arrives. */
|
|
49
|
+
export declare function peekLabels(models: ModelCache, path: FieldPathValue, locale: string): string[];
|