@sincpro/web-ui 1.9.0 → 1.10.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.
Files changed (55) hide show
  1. package/dist/components/canvas/Canvas.d.ts +14 -0
  2. package/dist/components/canvas/Canvas.js +9 -0
  3. package/dist/components/canvas/canvas.css +19 -0
  4. package/dist/components/canvas/index.d.ts +1 -0
  5. package/dist/components/canvas/index.js +2 -0
  6. package/dist/components/chat/ChatComposer.d.ts +10 -0
  7. package/dist/components/chat/ChatComposer.js +29 -0
  8. package/dist/components/chat/ChatThread.d.ts +13 -0
  9. package/dist/components/chat/ChatThread.js +76 -0
  10. package/dist/components/chat/ConversationList.d.ts +22 -0
  11. package/dist/components/chat/ConversationList.js +22 -0
  12. package/dist/components/chat/index.d.ts +4 -0
  13. package/dist/components/chat/index.js +5 -0
  14. package/dist/components/chat/model.d.ts +30 -0
  15. package/dist/components/chat/model.js +53 -0
  16. package/dist/components/index.d.ts +3 -0
  17. package/dist/components/index.js +3 -0
  18. package/dist/components/listing/ColumnsMenu.d.ts +7 -1
  19. package/dist/components/listing/ColumnsMenu.js +16 -5
  20. package/dist/components/listing/GroupingLevels.d.ts +5 -1
  21. package/dist/components/listing/GroupingLevels.js +7 -4
  22. package/dist/components/listing/ListingBar.js +2 -2
  23. package/dist/components/preview/FilePreview.d.ts +19 -0
  24. package/dist/components/preview/FilePreview.js +112 -0
  25. package/dist/components/preview/PdfPreview.d.ts +7 -0
  26. package/dist/components/preview/PdfPreview.js +47 -0
  27. package/dist/components/preview/index.d.ts +1 -0
  28. package/dist/components/preview/index.js +2 -0
  29. package/dist/components/record/SmartButtons.js +1 -1
  30. package/dist/components/search/FieldPath.d.ts +54 -0
  31. package/dist/components/search/FieldPath.js +159 -0
  32. package/dist/components/search/FilterBuilder.d.ts +38 -5
  33. package/dist/components/search/FilterBuilder.js +129 -25
  34. package/dist/components/search/SearchBar.js +7 -2
  35. package/dist/components/search/criteria.d.ts +23 -1
  36. package/dist/components/search/index.d.ts +4 -2
  37. package/dist/components/search/index.js +4 -0
  38. package/dist/components/search/paths.d.ts +49 -0
  39. package/dist/components/search/paths.js +75 -0
  40. package/dist/components/shell/TopBar.js +1 -1
  41. package/dist/foundations/copy.d.ts +86 -0
  42. package/dist/foundations/copy.es.js +63 -0
  43. package/dist/foundations/copy.js +57 -0
  44. package/dist/primitives/field/Field.js +2 -1
  45. package/dist/primitives/notice/Callout.d.ts +4 -1
  46. package/dist/primitives/notice/Callout.js +12 -2
  47. package/dist/primitives/notice/Notice.d.ts +26 -2
  48. package/dist/primitives/notice/Notice.js +64 -4
  49. package/dist/primitives/notice/Toast.js +10 -1
  50. package/dist/primitives/value/Markdown.d.ts +9 -0
  51. package/dist/primitives/value/Markdown.js +18 -0
  52. package/dist/primitives/value/index.d.ts +1 -0
  53. package/dist/primitives/value/index.js +1 -0
  54. package/dist/tokens.css +28 -0
  55. package/package.json +4 -1
@@ -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
- return say(node, model, 0);
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("div", {
352
- /* La que se vino a ver se marca y se trae a la vista. El anillo y no
353
- un fondo: el fondo compite con el `select` que hay que tocar. */
354
- ref: focus !== undefined && child.field === focus
355
- ? (node) => node?.scrollIntoView({ block: "nearest" })
356
- : undefined, className: `flex min-w-0 flex-wrap items-center gap-2 rounded-control ${focus !== undefined && child.field === focus
357
- ? "-m-1 p-1 ring-1 ring-primary/60"
358
- : ""}`, children: [_jsx("select", { "aria-label": copy.builder.ruleField, value: child.field, onChange: (event) => setChild(index, {
359
- ...child,
360
- field: event.target.value,
361
- operator: model.fields[event.target.value]?.ops.includes(child.operator)
362
- ? child.operator
363
- : (model.fields[event.target.value]?.ops[0] ?? "="),
364
- }), className: `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}`, children: names.map((name) => (_jsx("option", { value: name, children: name }, name))) }), _jsx("select", { "aria-label": copy.builder.ruleOperator, value: child.operator, onChange: (event) => setChild(index, { ...child, operator: event.target.value }), className: `min-w-0 flex-1 basis-36 rounded-control border px-2 py-1 text-meta ${box}`, children: (model.fields[child.field]?.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(model.fields[child.field]?.type ?? "text"), value: child.value, onChange: (event) => setChild(index, { ...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(model.fields[child.field]?.type ?? "text"), value: child.upper ?? "", onChange: (event) => setChild(index, { ...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(model.fields[child.field]?.type ?? "text"), value: child.value, onChange: (event) => setChild(index, { ...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}` })), _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)))] }));
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, className: "relative flex min-w-0 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",
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-0 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) => {
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[];
@@ -0,0 +1,75 @@
1
+ import { fieldLabel, } from "./model.js";
2
+ /** Whether a field points to another model: the picker can walk into it. */
3
+ export function isRelation(field) {
4
+ return (field.kind === "relation" || (field.relation !== undefined && field.relation !== null));
5
+ }
6
+ /** Whether a relation reaches MANY records. A filter through it has to say how many of them
7
+ * must match: some, none or all. */
8
+ export function isToMany(field) {
9
+ return isRelation(field) && field.many === true;
10
+ }
11
+ /** «Líneas > Impuestos > Monto»: how a path reads on a button or a chip. */
12
+ export function pathLabel(labels) {
13
+ return labels.join(" > ");
14
+ }
15
+ const key = (path) => path.join("\u0000");
16
+ export function createModelCache(root, loadModel) {
17
+ const pending = new Map();
18
+ const arrived = new Map([[key([]), root]]);
19
+ return {
20
+ root,
21
+ canLoad: loadModel !== undefined,
22
+ peek: (path) => arrived.get(key(path)),
23
+ get(path) {
24
+ const at = key(path);
25
+ const known = arrived.get(at);
26
+ if (known !== undefined)
27
+ return Promise.resolve(known);
28
+ const asked = pending.get(at);
29
+ if (asked !== undefined)
30
+ return asked;
31
+ if (loadModel === undefined) {
32
+ return Promise.reject(new Error(`No loadModel to follow «${path.join(".")}»`));
33
+ }
34
+ const request = loadModel(path).then((model) => {
35
+ arrived.set(at, model);
36
+ pending.delete(at);
37
+ return model;
38
+ }, (error) => {
39
+ pending.delete(at);
40
+ throw error;
41
+ });
42
+ pending.set(at, request);
43
+ return request;
44
+ },
45
+ };
46
+ }
47
+ /**
48
+ * A path resolved into its steps: each field with its definition and its label.
49
+ *
50
+ * in ["lines", "taxes", "amount"], the invoice model
51
+ * out [Líneas (to-many), Impuestos (to-many), Monto (number)]
52
+ *
53
+ * A name the model does not have stops the walk: it answers `null`, because half a path is
54
+ * a different question, not a shorter one.
55
+ */
56
+ export async function resolvePath(models, path, locale) {
57
+ const steps = [];
58
+ for (let at = 0; at < path.length; at++) {
59
+ const model = await models.get(path.slice(0, at));
60
+ const name = path[at];
61
+ const field = model.fields[name];
62
+ if (field === undefined)
63
+ return null;
64
+ steps.push({ name, field, label: fieldLabel(model, name, locale) });
65
+ }
66
+ return steps;
67
+ }
68
+ /** The labels of a path with what has already arrived; a model still on its way leaves the
69
+ * raw name, which is what there is to say until it arrives. */
70
+ export function peekLabels(models, path, locale) {
71
+ return path.map((name, at) => {
72
+ const model = models.peek(path.slice(0, at));
73
+ return model === undefined ? name : fieldLabel(model, name, locale);
74
+ });
75
+ }
@@ -10,7 +10,7 @@ export function TopBar({ app, apps, currentApp, onAppSelect, menus, onMenuSelect
10
10
  const copy = useUiCopy();
11
11
  const actual = apps?.find((a) => a.id === currentApp);
12
12
  const brand = app ?? actual;
13
- return (_jsx(SurfaceProvider, { value: "chrome", children: _jsxs("header", { className: "flex h-(--size-appbar) min-w-0 items-center gap-1 border-b border-chrome-edge bg-chrome px-2", children: [apps === undefined || apps.length === 0 ? null : (_jsx(AppSwitcher, { apps: apps, current: currentApp, ...(onAppSelect === undefined ? {} : { onSelect: onAppSelect }) })), brand === undefined ? null : (_jsxs("span", { className: "flex shrink-0 items-center gap-2 pr-2 pl-1", children: [brand.icon === undefined ? null : (_jsx(brand.icon, { className: "size-(--size-icon-md) text-chrome-link", strokeWidth: 2, "aria-hidden": true })), _jsx("span", { className: "text-lead font-medium text-chrome-ink", children: brand.label })] })), menus === undefined ? null : (_jsx("nav", { className: "flex min-w-0 items-center gap-0.5 overflow-hidden", "aria-label": copy.shell.menus, children: menus.map((m) => (_jsx(Menu, { label: m.label, groups: m.groups, surface: "chrome", variant: "text", chevron: false, onSelect: (id) => onMenuSelect?.(m.id, id) }, m.id))) })), _jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1 pl-2", children: [systray, user === undefined ? null : (_jsx(UserMenu, { name: user.name, ...(user.detail === undefined ? {} : { detail: user.detail }), groups: userGroups ?? [], ...(onUserSelect === undefined ? {} : { onSelect: onUserSelect }) }))] })] }) }));
13
+ return (_jsx(SurfaceProvider, { value: "chrome", children: _jsxs("header", { className: "flex h-(--size-appbar) min-w-0 items-center gap-1 border-b border-chrome-edge bg-chrome px-2", children: [apps === undefined || apps.length === 0 ? null : (_jsx(AppSwitcher, { apps: apps, current: currentApp, ...(onAppSelect === undefined ? {} : { onSelect: onAppSelect }) })), brand === undefined ? null : (_jsxs("span", { className: "flex shrink-0 items-center gap-2 pr-2 pl-1", children: [brand.icon === undefined ? null : (_jsx(brand.icon, { className: "size-(--size-icon-md) text-chrome-link", strokeWidth: 2, "aria-hidden": true })), _jsx("span", { className: "text-lead font-medium text-chrome-ink", children: brand.label })] })), menus === undefined ? null : (_jsx("nav", { className: "scroll-quiet flex min-w-0 items-center gap-0.5", "aria-label": copy.shell.menus, children: menus.map((m) => (_jsx(Menu, { label: m.label, groups: m.groups, surface: "chrome", variant: "text", chevron: false, onSelect: (id) => onMenuSelect?.(m.id, id) }, m.id))) })), _jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1 pl-2", children: [systray, user === undefined ? null : (_jsx(UserMenu, { name: user.name, ...(user.detail === undefined ? {} : { detail: user.detail }), groups: userGroups ?? [], ...(onUserSelect === undefined ? {} : { onSelect: onUserSelect }) }))] })] }) }));
14
14
  }
15
15
  /** The app switcher: a grid, not a list.
16
16
  *
@@ -359,6 +359,8 @@ export type UiCopy = {
359
359
  field: string;
360
360
  /** A field with nothing in it: said, not a silent success. */
361
361
  empty: string;
362
+ /** On an error: copies the whole report (what it said, the detail, when, where). */
363
+ report: string;
362
364
  };
363
365
  /** The rich-text editor: its toolbar, its link form, its list of people to mention. */
364
366
  richText: {
@@ -804,6 +806,90 @@ export type UiCopy = {
804
806
  failed: string;
805
807
  retry: string;
806
808
  };
809
+ /** The field picker that walks relations: «Líneas > Impuestos > Monto». */
810
+ fieldPath: {
811
+ /** The trigger with nothing chosen. */
812
+ choose: string;
813
+ search: string;
814
+ back: string;
815
+ loading: string;
816
+ failed: string;
817
+ failedHint: string;
818
+ empty: string;
819
+ /** The first option inside a relation: choosing the relation itself. `{label}`. */
820
+ self: string;
821
+ /** Said after a relation's name: pressing it shows its fields. */
822
+ opens: string;
823
+ /** Add a column or a grouping level from a related field. */
824
+ addColumn: string;
825
+ addLevel: string;
826
+ /** How many of the records reached through a to-many relation must match. */
827
+ match: {
828
+ label: string;
829
+ any: string;
830
+ none: string;
831
+ all: string;
832
+ };
833
+ /** A filter through a relation said in words. `{relation}` and `{inner}`. */
834
+ say: {
835
+ any: string;
836
+ none: string;
837
+ all: string;
838
+ one: string;
839
+ };
840
+ };
841
+ /** The file preview a person opens from a file: the kind decides the renderer. */
842
+ preview: {
843
+ label: string;
844
+ download: string;
845
+ /** No renderer for this kind: said, with the download still there. */
846
+ unsupported: string;
847
+ loading: string;
848
+ /** The renderer failed. The technical text goes in the error report. */
849
+ failed: string;
850
+ /** `{page}` and `{total}`. */
851
+ page: string;
852
+ previousPage: string;
853
+ nextPage: string;
854
+ fit: string;
855
+ actualSize: string;
856
+ /** `{size}` is the file size, already written for the locale. */
857
+ kind: {
858
+ image: string;
859
+ pdf: string;
860
+ text: string;
861
+ markdown: string;
862
+ other: string;
863
+ };
864
+ };
865
+ /** A conversation: the thread of messages and the composer under it. */
866
+ chat: {
867
+ thread: string;
868
+ empty: string;
869
+ loadOlder: string;
870
+ loadingOlder: string;
871
+ jumpLatest: string;
872
+ today: string;
873
+ yesterday: string;
874
+ /** The composer's accessible name and its placeholder. */
875
+ composer: string;
876
+ placeholder: string;
877
+ send: string;
878
+ /** `{count}` is the number of unread messages. */
879
+ unread: string;
880
+ conversations: string;
881
+ newMessages: string;
882
+ /** A message that is written but not yet confirmed by the server. */
883
+ sending: string;
884
+ };
885
+ /** A canvas of nodes and connections (a diagram, a flow). */
886
+ canvas: {
887
+ label: string;
888
+ zoomIn: string;
889
+ zoomOut: string;
890
+ fit: string;
891
+ readOnly: string;
892
+ };
807
893
  /** The theme switch: the three choices an app offers for the palette. */
808
894
  theme: {
809
895
  /** The name of the control — what a screen reader says for the group. */