@sincpro/web-ui 1.11.1 → 2.1.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 (120) hide show
  1. package/dist/components/activity/Activity.d.ts +13 -14
  2. package/dist/components/activity/Activity.js +1 -1
  3. package/dist/components/activity/Messages.d.ts +5 -5
  4. package/dist/components/activity/Messages.js +8 -8
  5. package/dist/components/form/Form.js +6 -6
  6. package/dist/components/form/index.js +2 -2
  7. package/dist/components/frame/FrameView.d.ts +5 -5
  8. package/dist/components/frame/FrameView.js +4 -4
  9. package/dist/components/listing/GroupingLevels.d.ts +22 -22
  10. package/dist/components/listing/GroupingLevels.js +9 -9
  11. package/dist/components/listing/Listing.d.ts +11 -11
  12. package/dist/components/listing/Listing.js +11 -11
  13. package/dist/components/listing/ListingBar.js +11 -11
  14. package/dist/components/listing/Row.d.ts +19 -19
  15. package/dist/components/listing/Row.js +25 -25
  16. package/dist/components/listing/SortMenu.d.ts +36 -36
  17. package/dist/components/listing/SortMenu.js +6 -6
  18. package/dist/components/listing/grouping.d.ts +16 -16
  19. package/dist/components/listing/grouping.js +6 -6
  20. package/dist/components/listing/index.js +1 -1
  21. package/dist/components/listing/modelColumns.d.ts +25 -25
  22. package/dist/components/listing/modelColumns.js +24 -24
  23. package/dist/components/listing/pages.js +4 -4
  24. package/dist/components/listing/set.d.ts +18 -18
  25. package/dist/components/navigation/index.js +2 -2
  26. package/dist/components/record/RecordSkeleton.js +7 -7
  27. package/dist/components/search/CriteriaBuilder.d.ts +35 -22
  28. package/dist/components/search/CriteriaBuilder.js +95 -85
  29. package/dist/components/search/CriteriaChips.d.ts +9 -9
  30. package/dist/components/search/CriteriaChips.js +13 -13
  31. package/dist/components/search/FilterBuilder.d.ts +72 -71
  32. package/dist/components/search/FilterBuilder.js +190 -145
  33. package/dist/components/search/JoinWord.d.ts +1 -1
  34. package/dist/components/search/JoinWord.js +14 -14
  35. package/dist/components/search/JsonEditor.d.ts +8 -8
  36. package/dist/components/search/JsonEditor.js +21 -18
  37. package/dist/components/search/SearchBar.d.ts +34 -34
  38. package/dist/components/search/SearchBar.js +113 -113
  39. package/dist/components/search/criteria.d.ts +86 -74
  40. package/dist/components/search/criteria.js +44 -43
  41. package/dist/components/search/datePeriods.d.ts +47 -48
  42. package/dist/components/search/datePeriods.js +29 -29
  43. package/dist/components/search/dateRanges.d.ts +27 -27
  44. package/dist/components/search/dateRanges.js +16 -16
  45. package/dist/components/search/index.d.ts +2 -2
  46. package/dist/components/search/index.js +14 -14
  47. package/dist/components/search/model.d.ts +28 -28
  48. package/dist/components/search/model.js +21 -21
  49. package/dist/components/search/query.d.ts +71 -71
  50. package/dist/components/search/query.js +119 -119
  51. package/dist/components/shell/AppFrame.js +3 -3
  52. package/dist/components/shell/index.js +1 -1
  53. package/dist/foundations/calendar.d.ts +27 -27
  54. package/dist/foundations/calendar.js +72 -72
  55. package/dist/foundations/chart.d.ts +57 -57
  56. package/dist/foundations/chart.js +27 -27
  57. package/dist/foundations/copy.d.ts +104 -94
  58. package/dist/foundations/copy.es.js +6 -1
  59. package/dist/foundations/copy.js +6 -1
  60. package/dist/foundations/grouping.d.ts +175 -175
  61. package/dist/foundations/grouping.js +0 -0
  62. package/dist/foundations/index.d.ts +1 -1
  63. package/dist/foundations/index.js +21 -21
  64. package/dist/foundations/pivot.d.ts +133 -131
  65. package/dist/foundations/pivot.js +54 -54
  66. package/dist/foundations/pivotSheet.d.ts +36 -36
  67. package/dist/foundations/pivotSheet.js +0 -0
  68. package/dist/foundations/slots.d.ts +38 -38
  69. package/dist/foundations/slots.js +18 -18
  70. package/dist/foundations/sticky.d.ts +28 -28
  71. package/dist/foundations/sticky.js +59 -59
  72. package/dist/foundations/xlsx.d.ts +47 -47
  73. package/dist/foundations/xlsx.js +0 -0
  74. package/dist/primitives/block/Line.d.ts +4 -4
  75. package/dist/primitives/block/Line.js +28 -28
  76. package/dist/primitives/block/index.js +2 -2
  77. package/dist/primitives/cell/index.js +2 -2
  78. package/dist/primitives/choice/index.js +3 -3
  79. package/dist/primitives/date/Calendar.d.ts +7 -1
  80. package/dist/primitives/date/Calendar.js +13 -3
  81. package/dist/primitives/date/DatePicker.d.ts +4 -1
  82. package/dist/primitives/date/DatePicker.js +2 -2
  83. package/dist/primitives/date/index.js +3 -3
  84. package/dist/primitives/disclosure/index.js +1 -1
  85. package/dist/primitives/menu/Menu.d.ts +3 -3
  86. package/dist/primitives/notice/Callout.d.ts +30 -30
  87. package/dist/primitives/notice/Callout.js +6 -6
  88. package/dist/primitives/overlay/index.js +3 -3
  89. package/dist/primitives/picker/Picker.d.ts +6 -0
  90. package/dist/primitives/picker/Picker.js +27 -4
  91. package/dist/primitives/picker/index.js +2 -2
  92. package/dist/primitives/table/DataTable.d.ts +32 -32
  93. package/dist/primitives/table/DataTable.js +24 -24
  94. package/dist/primitives/table/EditableTable.d.ts +10 -10
  95. package/dist/primitives/table/EditableTable.js +9 -9
  96. package/dist/primitives/table/ReportTable.js +7 -7
  97. package/dist/primitives/table/SheetTable.d.ts +13 -13
  98. package/dist/primitives/table/SheetTable.js +14 -14
  99. package/dist/primitives/table/Table.js +8 -8
  100. package/dist/primitives/tabs/Tabs.d.ts +46 -46
  101. package/dist/primitives/tabs/Tabs.js +7 -7
  102. package/dist/primitives/tag/index.js +2 -2
  103. package/dist/primitives/toolbar/index.js +1 -1
  104. package/dist/primitives/value/Copyable.d.ts +22 -22
  105. package/dist/primitives/value/Copyable.js +9 -9
  106. package/dist/tokens.css +17 -17
  107. package/dist/views/list/List.d.ts +36 -36
  108. package/dist/views/list/List.js +19 -19
  109. package/dist/views/list/ListView.js +74 -74
  110. package/dist/views/list/columns.d.ts +10 -10
  111. package/dist/views/list/columns.js +10 -10
  112. package/dist/views/list/derive.d.ts +30 -30
  113. package/dist/views/list/derive.js +49 -49
  114. package/dist/views/list/index.js +2 -2
  115. package/dist/views/list/presentations.js +3 -3
  116. package/dist/views/list/types.d.ts +109 -109
  117. package/dist/views/record/Record.d.ts +14 -14
  118. package/dist/views/record/Record.js +24 -24
  119. package/dist/views/record/index.js +1 -1
  120. package/package.json +1 -1
@@ -4,53 +4,66 @@ export interface BuiltSort {
4
4
  field: string;
5
5
  descending?: boolean;
6
6
  }
7
+ /** A grouping level, like criteria's `Level`: the field and, if it is a date, the grain. */
7
8
  export interface BuiltLevel {
8
9
  field: string;
9
10
  grain?: string | null;
10
11
  }
11
- /** Un número plegado de las filas de un montón: `["sum", "row_count"]`. */
12
- export type BuiltFold = [string, string];
13
- /** Desde dónde empieza una página de montones — la misma forma que la paginación de filas. */
12
+ /**
13
+ * A number that each heap answers, like criteria's `Measure`:
14
+ * `{ function: "sum", field: "row_count" }`. Named parts and not a pair, just as a
15
+ * condition travels as `{field, operator, value}`.
16
+ */
17
+ export interface BuiltMeasure {
18
+ function: string;
19
+ field: string;
20
+ /** What the function needs besides the field. Only `percentile`: the cut's fraction. */
21
+ argument?: number;
22
+ }
23
+ /** From where a page of heaps starts — the same shape as the rows' pagination. */
14
24
  export type BuiltPageStrategy = {
15
- token?: string | null;
25
+ token: string | null;
16
26
  } | {
17
- rows?: number;
27
+ rows: number;
18
28
  };
19
29
  export interface BuiltGroupPagination {
20
30
  limit?: number;
21
31
  strategy?: BuiltPageStrategy;
22
32
  }
33
+ /** The grouping as `@sincpro/criteria` 2.0 declares it, key by key. */
23
34
  export interface BuiltGrouping {
24
- by?: BuiltLevel[];
25
- totals?: Record<string, BuiltFold>;
26
- /** Un filtro sobre lo que los montones plegaron: `count > 10`. Los nombres que admite son
27
- * los de `totals`, más `"count"`. */
28
- having?: BuiltFilter;
29
- /** En qué orden vuelven los montones: por el propio campo del nivel, por un nombre de
30
- * `totals`, o por `count`. */
35
+ /** The levels, in order: they are not added, they nest. */
36
+ group_by?: BuiltLevel[];
37
+ /** The numbers each heap answers, each under a chosen name. */
38
+ measures?: Record<string, BuiltMeasure>;
39
+ /** A filter on what the heaps measured, not on the rows: `count > 10`. The
40
+ * names it admits are those of `measures`, plus `"count"`. */
41
+ where_measures?: BuiltFilter;
42
+ /** In what order the heaps come back: by the level's own field, by a name from
43
+ * `measures`, or by `count`. */
31
44
  order?: BuiltSort[];
32
- /** Cuántos montones del primer nivel vuelven, y desde dónde. Ausente es todos. */
45
+ /** How many heaps of the first level come back, and from where. Absent is all of them. */
33
46
  pagination?: BuiltGroupPagination;
34
47
  }
35
- /** La criteria tal como la declara el motor. Es lo que este componente arma y devuelve, y lo
36
- * que el editor de código muestra. */
48
+ /** The criteria as the engine declares it. It is what this component builds and returns, and what
49
+ * the code editor shows. */
37
50
  export interface BuiltCriteria {
38
- where?: BuiltFilter;
51
+ selection?: BuiltFilter;
39
52
  order?: BuiltSort[];
40
53
  grouping?: BuiltGrouping;
41
54
  specification?: Record<string, Record<string, never>>;
42
55
  }
43
56
  export declare function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }: {
44
57
  model: ModelDefinition;
45
- /** La criteria que ya estaba puesta. Reabrir tiene que seguir donde quedó. */
58
+ /** The criteria that was already set. Reopening has to continue where it was left. */
46
59
  initial?: BuiltCriteria;
47
60
  /**
48
- * El campo de la condición que hay que mostrar primero: la ficha que alguien
49
- * tocó en la barra.
61
+ * The condition's field to show first: the chip somebody
62
+ * touched in the bar.
50
63
  *
51
- * Sin esto, tocar un recorte abría el constructor en la regla uno y había que
52
- * buscar entre doce la que uno venía mirando — que es la manera más rápida de
53
- * editar la equivocada.
64
+ * Without this, touching a cut opened the builder on rule one and you had to
65
+ * search among twelve for the one you were looking at — which is the quickest way to
66
+ * edit the wrong one.
54
67
  */
55
68
  focus?: string;
56
69
  onApply: (criteria: BuiltCriteria | undefined) => void;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { blankGroup, ExpressionView, treeFromFilter, treeToFilter, WhereTree, } from "./FilterBuilder.js";
3
+ import { blankGroup, ExpressionView, SelectionTree, treeFromFilter, treeToFilter, } from "./FilterBuilder.js";
4
4
  import { LazyJsonEditor } from "./LazyJsonEditor.js";
5
5
  import { filterableNames, } from "./model.js";
6
6
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
@@ -12,37 +12,45 @@ import { Tags } from "../../primitives/tag/Tags.js";
12
12
  import { Plus, Trash2 } from "lucide-react";
13
13
  import { Fragment, useMemo, useState } from "react";
14
14
  /**
15
- * Los cortes de una fecha, de GRUESO a fino, con `null` adelante: sin corte, un
16
- * campo de fecha parte por instante y cada fila termina en su propio montón.
15
+ * A date's cuts, from COARSE to fine, with `null` first: with no cut, a
16
+ * date field splits by instant and every row ends up in its own heap.
17
17
  *
18
- * El orden no es una preferencia — un día entero vive adentro de un solo mes— y
19
- * es el mismo que `GRAIN_ORDER` publica para la barra: una sola dirección para
20
- * las dos pantallas. La ficha de un nivel rota por esta lista.
18
+ * The order is not a preference — a whole day lives inside a single month— and
19
+ * it is the same one `GRAIN_ORDER` publishes for the bar: a single direction for
20
+ * both screens. A level's chip rotates through this list.
21
21
  */
22
22
  const GRAINS = [null, ...GRAIN_ORDER];
23
- /** Qué tipos admiten un grano: recortar un texto por mes no significa nada. */
23
+ /** Which types admit a grain: cutting a text by month means nothing. */
24
24
  const DATE_TYPES = new Set(["date", "datetime"]);
25
- /** Los operadores que un plegado —siempre un número— o `count` admiten en un `having`: los
26
- * mismos que la definición del modelo publica para un campo numérico, `is null` aparte, que
27
- * no significa nada sobre un número que el propio motor calculó. */
25
+ /** The operators that a measure —always a number— or `count` admit in a
26
+ * `where_measures`: the same ones the model definition publishes for a numeric field,
27
+ * `is null` aside, which means nothing on a number the engine itself computed. */
28
28
  const COMPARABLE = ["=", "!=", ">", ">=", "<", "<=", "between"];
29
- /** Las funciones que un plegado puede pedir, cerradas del lado del servidor porque el nombre
30
- * llega a SQL. */
31
- const FOLD_FUNCTIONS = ["sum", "avg", "min", "max", "count"];
29
+ /** The functions a measure can ask for here, closed on the server side because the
30
+ * name reaches SQL. */
31
+ const MEASURE_FUNCTIONS = ["sum", "avg", "min", "max", "count"];
32
32
  function isEmpty(criteria) {
33
- return (criteria.where === undefined &&
33
+ return (criteria.selection === undefined &&
34
34
  (criteria.order ?? []).length === 0 &&
35
- (criteria.grouping?.by ?? []).length === 0 &&
36
- Object.keys(criteria.grouping?.totals ?? {}).length === 0 &&
35
+ (criteria.grouping?.group_by ?? []).length === 0 &&
36
+ Object.keys(criteria.grouping?.measures ?? {}).length === 0 &&
37
37
  Object.keys(criteria.specification ?? {}).length === 0);
38
38
  }
39
+ /** The `where_measures` editor's tree: what was read, wrapped in a group if it is a single
40
+ * condition, or a blank one over `count` if there is nothing to read. */
41
+ function measuresTreeOf(filter, model) {
42
+ const node = filter === undefined ? null : treeFromFilter(filter);
43
+ if (node === null)
44
+ return blankGroup(model, "count");
45
+ return node.kind === "group" ? node : { kind: "group", join: "all", children: [node] };
46
+ }
39
47
  /**
40
- * LA FICHA QUE AGREGA: un «+» que abre la lista de lo que se puede elegir.
48
+ * THE CHIP THAT ADDS: a «+» that opens the list of what can be chosen.
41
49
  *
42
- * Es lo mismo que hace el numeral en la barra, y por la misma razón: elegir
43
- * entre veinte campos es elegir de una LISTA, no desplegar un `<select>` que ya
44
- * viene con uno puesto y que hay que cambiar. Con el `<select>`, agregar un
45
- * nivel ponía el primer campo del modelo aunque nadie lo hubiera pedido.
50
+ * It is the same as what the hash sign does in the bar, and for the same reason: choosing
51
+ * among twenty fields is choosing from a LIST, not unfolding a `<select>` that already
52
+ * comes with one set and has to be changed. With the `<select>`, adding a
53
+ * level put the model's first field even though nobody had asked for it.
46
54
  */
47
55
  function AddTag({ label, options, onPick, }) {
48
56
  const [open, setOpen] = useState(false);
@@ -57,7 +65,7 @@ function AddTag({ label, options, onPick, }) {
57
65
  },
58
66
  })) }) })) : null] }));
59
67
  }
60
- /** El corte siguiente, y vuelta a empezar. */
68
+ /** The next cut, and back to the start. */
61
69
  function nextGrain(grain) {
62
70
  const at = GRAINS.indexOf(grain ?? null);
63
71
  return GRAINS[(at + 1) % GRAINS.length] ?? null;
@@ -65,70 +73,66 @@ function nextGrain(grain) {
65
73
  export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
66
74
  const surface = useSurface();
67
75
  const names = Object.keys(model.fields).sort();
68
- /* Nunca un relacional ni un valor-objeto: ninguno de los dos tiene una comparación propia
69
- (`ops` vacío), así que ninguno sirve de blanco para un filtro, un orden o un nivel. */
76
+ /* Never a relational nor a value-object: neither has a comparison of its own
77
+ (empty `ops`), so neither serves as a target for a filter, an order or a level. */
70
78
  const scalarNames = filterableNames(model);
71
79
  const sortable = names.filter((name) => model.fields[name]?.sortable === true);
72
- const decomposed = initial?.where === undefined ? null : treeFromFilter(initial.where);
80
+ const decomposed = initial?.selection === undefined ? null : treeFromFilter(initial.selection);
73
81
  const [tree, setTree] = useState(() => decomposed !== null && decomposed.kind === "group"
74
82
  ? decomposed
75
83
  : decomposed !== null
76
84
  ? { kind: "group", join: "all", children: [decomposed] }
77
85
  : blankGroup(model, scalarNames[0]));
78
86
  const copy = useUiCopy();
79
- const [lockedWhere, setLockedWhere] = useState(initial?.where !== undefined && decomposed === null ? initial.where : null);
87
+ const [lockedSelection, setLockedSelection] = useState(initial?.selection !== undefined && decomposed === null ? initial.selection : null);
80
88
  const [order, setOrder] = useState(initial?.order ?? []);
81
- const [levels, setLevels] = useState(initial?.grouping?.by ?? []);
82
- const [totals, setTotals] = useState(initial?.grouping?.totals ?? {});
89
+ const [levels, setLevels] = useState(initial?.grouping?.group_by ?? []);
90
+ const [measures, setMeasures] = useState(initial?.grouping?.measures ?? {});
83
91
  const [groupOrder, setGroupOrder] = useState(initial?.grouping?.order ?? []);
84
92
  const [groupLimit, setGroupLimit] = useState(initial?.grouping?.pagination?.limit);
85
- /* `having` es un filtro como cualquier otro, sobre un modelo sintético cuyos únicos campos
86
- son los nombres que admite: los de `totals`, más `count`. Reutilizar `WhereTree` sobre ese
87
- modelo es más simple y más correcto que armar un editor de condiciones aparte. */
88
- const havingModel = useMemo(() => ({
89
- aggregate: "having",
93
+ /* `where_measures` is a filter like any other, over a synthetic model whose only
94
+ fields are the names it admits: those of `measures`, plus `count`. Reusing
95
+ `SelectionTree` over that model is simpler and more correct than building a separate
96
+ conditions editor. */
97
+ const measuresModel = useMemo(() => ({
98
+ aggregate: "where_measures",
90
99
  identity: "count",
91
100
  fields: Object.fromEntries([
92
101
  ["count", { type: "integer", nullable: false, sortable: false, ops: COMPARABLE }],
93
- ...Object.keys(totals).map((name) => [
102
+ ...Object.keys(measures).map((name) => [
94
103
  name,
95
104
  { type: "number", nullable: false, sortable: false, ops: COMPARABLE },
96
105
  ]),
97
106
  ]),
98
- }), [totals]);
99
- const havingDecomposed = initial?.grouping?.having === undefined ? null : treeFromFilter(initial.grouping.having);
100
- const [havingTree, setHavingTree] = useState(() => havingDecomposed !== null && havingDecomposed.kind === "group"
101
- ? havingDecomposed
102
- : havingDecomposed !== null
103
- ? { kind: "group", join: "all", children: [havingDecomposed] }
104
- : blankGroup(havingModel, "count"));
107
+ }), [measures]);
108
+ const [measuresTree, setMeasuresTree] = useState(() => measuresTreeOf(initial?.grouping?.where_measures, measuresModel));
105
109
  const [fields, setFields] = useState(Object.keys(initial?.specification ?? {}));
106
110
  const [rawText, setRawText] = useState(() => initial === undefined ? "" : JSON.stringify(initial, null, 2));
107
111
  const [rawError, setRawError] = useState(null);
108
- /** Lo que los controles dicen, junto: es lo que se aplica y lo que el JSON muestra. */
112
+ /** What the controls say, together: it is what is applied and what the JSON shows. */
109
113
  function assemble(next) {
110
- const where = next.locked ?? lockedWhere ?? treeToFilter(next.tree ?? tree);
114
+ const selection = next.locked ?? lockedSelection ?? treeToFilter(next.tree ?? tree);
111
115
  const sorts = next.order ?? order;
112
- const by = next.levels ?? levels;
113
- const folds = next.totals ?? totals;
114
- const having = treeToFilter(next.havingTree ?? havingTree);
116
+ const groupBy = next.levels ?? levels;
117
+ const measured = next.measures ?? measures;
118
+ const whereMeasures = treeToFilter(next.measuresTree ?? measuresTree);
115
119
  const groupSorts = next.groupOrder ?? groupOrder;
116
120
  const limit = "groupLimit" in next ? next.groupLimit : groupLimit;
117
121
  const chosen = next.fields ?? fields;
118
- /* Sin niveles no hay qué plegar, qué filtrar entre montones ni en qué orden o página
119
- volverían — un total, un `having` o una página puestos y luego vaciados de niveles no
120
- tienen que sobrevivir sueltos en la criteria que se manda. */
121
- const grouping = by.length === 0
122
+ /* Without levels there is nothing to measure, nothing to filter between heaps, nor in what order or page
123
+ they would come back — a measure, a `where_measures` or a page set and then emptied of
124
+ levels must not survive loose in the criteria that is sent. */
125
+ const grouping = groupBy.length === 0
122
126
  ? {}
123
127
  : {
124
- by,
125
- ...(Object.keys(folds).length === 0 ? {} : { totals: folds }),
126
- ...(having === undefined ? {} : { having }),
128
+ group_by: groupBy,
129
+ ...(Object.keys(measured).length === 0 ? {} : { measures: measured }),
130
+ ...(whereMeasures === undefined ? {} : { where_measures: whereMeasures }),
127
131
  ...(groupSorts.length === 0 ? {} : { order: groupSorts }),
128
132
  ...(limit === undefined ? {} : { pagination: { limit } }),
129
133
  };
130
134
  return {
131
- ...(where === undefined ? {} : { where }),
135
+ ...(selection === undefined ? {} : { selection }),
132
136
  ...(sorts.length === 0 ? {} : { order: sorts }),
133
137
  ...(Object.keys(grouping).length === 0 ? {} : { grouping }),
134
138
  ...(chosen.length === 0
@@ -138,20 +142,20 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
138
142
  }),
139
143
  };
140
144
  }
141
- /* Tocar cualquier control reescribe el JSON entero: las dos vistas son la misma criteria. */
145
+ /* Touching any control rewrites the whole JSON: the two views are the same criteria. */
142
146
  function push(next) {
143
147
  if (next.tree !== undefined)
144
148
  setTree(next.tree);
145
149
  if (next.locked !== undefined)
146
- setLockedWhere(next.locked);
150
+ setLockedSelection(next.locked);
147
151
  if (next.order !== undefined)
148
152
  setOrder(next.order);
149
153
  if (next.levels !== undefined)
150
154
  setLevels(next.levels);
151
- if (next.totals !== undefined)
152
- setTotals(next.totals);
153
- if (next.havingTree !== undefined)
154
- setHavingTree(next.havingTree);
155
+ if (next.measures !== undefined)
156
+ setMeasures(next.measures);
157
+ if (next.measuresTree !== undefined)
158
+ setMeasuresTree(next.measuresTree);
155
159
  if (next.groupOrder !== undefined)
156
160
  setGroupOrder(next.groupOrder);
157
161
  if ("groupLimit" in next)
@@ -162,7 +166,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
162
166
  setRawText(isEmpty(built) ? "" : JSON.stringify(built, null, 2));
163
167
  setRawError(null);
164
168
  }
165
- /* Escribir el JSON rehace los controles, mientras lo escrito sea una criteria. */
169
+ /* Writing the JSON rebuilds the controls, as long as what was written is a criteria. */
166
170
  function updateRaw(text) {
167
171
  setRawText(text);
168
172
  if (text.trim() === "") {
@@ -182,36 +186,31 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
182
186
  return;
183
187
  }
184
188
  setRawError(null);
185
- const node = parsed.where === undefined ? null : treeFromFilter(parsed.where);
189
+ const node = parsed.selection === undefined ? null : treeFromFilter(parsed.selection);
186
190
  if (node !== null) {
187
191
  setTree(node.kind === "group" ? node : { kind: "group", join: "all", children: [node] });
188
- setLockedWhere(null);
192
+ setLockedSelection(null);
189
193
  }
190
- else if (parsed.where !== undefined) {
191
- setLockedWhere(parsed.where);
194
+ else if (parsed.selection !== undefined) {
195
+ setLockedSelection(parsed.selection);
192
196
  }
193
197
  else {
194
198
  setTree(blankGroup(model, scalarNames[0]));
195
- setLockedWhere(null);
199
+ setLockedSelection(null);
196
200
  }
197
201
  setOrder(parsed.order ?? []);
198
- setLevels(parsed.grouping?.by ?? []);
199
- setTotals(parsed.grouping?.totals ?? {});
202
+ setLevels(parsed.grouping?.group_by ?? []);
203
+ setMeasures(parsed.grouping?.measures ?? {});
200
204
  setGroupOrder(parsed.grouping?.order ?? []);
201
205
  setGroupLimit(parsed.grouping?.pagination?.limit);
202
- const havingNode = parsed.grouping?.having === undefined ? null : treeFromFilter(parsed.grouping.having);
203
- setHavingTree(havingNode !== null && havingNode.kind === "group"
204
- ? havingNode
205
- : havingNode !== null
206
- ? { kind: "group", join: "all", children: [havingNode] }
207
- : blankGroup(havingModel, "count"));
206
+ setMeasuresTree(measuresTreeOf(parsed.grouping?.where_measures, measuresModel));
208
207
  setFields(Object.keys(parsed.specification ?? {}));
209
208
  }
210
209
  const box = surface === "chrome"
211
210
  ? "border-chrome-ink/20 bg-chrome text-chrome-ink"
212
211
  : "border-ink/15 bg-surface text-ink";
213
212
  const select = `min-w-0 flex-1 basis-40 rounded-control border px-2 py-1 text-meta ${box}`;
214
- return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filter }), _jsx("div", { className: "max-h-72 min-w-0 overflow-auto", children: lockedWhere !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "mb-2 text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedWhere, model: model })] })) : (_jsx(WhereTree, { model: model, group: tree, onChange: (next) => push({ tree: next }), ...(focus === undefined ? {} : { focus }) })) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.order }), _jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1", children: [_jsx(Tags, { items: order.map((sort, index) => ({
213
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3 p-3", children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filter }), _jsx("div", { className: "max-h-72 min-w-0 overflow-auto", children: lockedSelection !== null ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "mb-2 text-meta text-muted", children: copy.search.unreadable }), _jsx(ExpressionView, { node: lockedSelection, model: model })] })) : (_jsx(SelectionTree, { model: model, group: tree, onChange: (next) => push({ tree: next }), ...(focus === undefined ? {} : { focus }) })) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.order }), _jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1", children: [_jsx(Tags, { items: order.map((sort, index) => ({
215
214
  id: `${sort.field}-${index}`,
216
215
  label: sort.field,
217
216
  note: sort.descending === true ? "↓" : "↑",
@@ -239,26 +238,37 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
239
238
  onRemove: () => push({ levels: levels.filter((_, at) => at !== index) }),
240
239
  removeLabel: fillCopy(copy.builder.dropLevel, { field: level.field }),
241
240
  },
242
- ] })] }, `${level.field}-${index}`))), _jsx(AddTag, { label: copy.builder.addGroup, options: scalarNames.filter((name) => !levels.some((one) => one.field === name)), onPick: (name) => push({ levels: [...levels, { field: name }] }) })] }), levels.length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noGrouping })) : null] }), levels.length > 0 ? (_jsxs(_Fragment, { children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.totals }), Object.keys(totals).length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noTotals })) : null, Object.entries(totals).map(([name, [fn, field]]) => (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsx("select", { value: fn, onChange: (event) => push({
243
- totals: { ...totals, [name]: [event.target.value, field] },
244
- }), className: `min-w-0 flex-1 basis-28 rounded-control border px-2 py-1 text-meta ${box}`, children: FOLD_FUNCTIONS.map((one) => (_jsx("option", { value: one, children: one }, one))) }), _jsx("select", { value: field, onChange: (event) => push({ totals: { ...totals, [name]: [fn, event.target.value] } }), className: select, children: scalarNames.map((one) => (_jsx("option", { value: one, children: one }, one))) }), _jsx("span", { className: "shrink-0 text-micro text-muted", children: fillCopy(copy.builder.totalAs, { name }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropTotal, onClick: () => {
245
- const { [name]: _dropped, ...rest } = totals;
246
- push({ totals: rest });
241
+ ] })] }, `${level.field}-${index}`))), _jsx(AddTag, { label: copy.builder.addGroup, options: scalarNames.filter((name) => !levels.some((one) => one.field === name)), onPick: (name) => push({ levels: [...levels, { field: name }] }) })] }), levels.length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noGrouping })) : null] }), levels.length > 0 ? (_jsxs(_Fragment, { children: [_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.totals }), Object.keys(measures).length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noTotals })) : null, Object.entries(measures).map(([name, measure]) => (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsx("select", { "aria-label": fillCopy(copy.builder.totalFunction, { name }), value: measure.function, onChange: (event) => push({
242
+ measures: {
243
+ ...measures,
244
+ [name]: { function: event.target.value, field: measure.field },
245
+ },
246
+ }), className: `min-w-0 flex-1 basis-28 rounded-control border px-2 py-1 text-meta ${box}`, children: MEASURE_FUNCTIONS.map((one) => (_jsx("option", { value: one, children: one }, one))) }), _jsx("select", { "aria-label": fillCopy(copy.builder.totalField, { name }), value: measure.field, onChange: (event) => push({
247
+ measures: {
248
+ ...measures,
249
+ [name]: { ...measure, field: event.target.value },
250
+ },
251
+ }), className: select, children: scalarNames.map((one) => (_jsx("option", { value: one, children: one }, one))) }), _jsx("span", { className: "shrink-0 text-micro text-muted", children: fillCopy(copy.builder.totalAs, { name }) }), _jsx("button", { type: "button", "aria-label": copy.builder.dropTotal, onClick: () => {
252
+ const { [name]: _dropped, ...rest } = measures;
253
+ push({ measures: rest });
247
254
  }, className: "ml-auto shrink-0 text-muted", children: _jsx(Trash2, { className: "size-4" }) })] }, name))), _jsx("div", { children: _jsxs(Button, { role: "ghost", disabled: scalarNames.length === 0, onClick: () => {
248
255
  let name = "total";
249
256
  let index = 2;
250
- while (name in totals)
257
+ while (name in measures)
251
258
  name = `total_${index++}`;
252
259
  push({
253
- totals: { ...totals, [name]: ["sum", scalarNames[0] ?? ""] },
260
+ measures: {
261
+ ...measures,
262
+ [name]: { function: "sum", field: scalarNames[0] ?? "" },
263
+ },
254
264
  });
255
- }, children: [_jsx(Plus, { className: "size-4" }), " ", copy.builder.addTotal] }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filterPiles }), _jsx("p", { className: "text-meta text-muted", children: copy.builder.pilesNote }), _jsx(WhereTree, { model: havingModel, group: havingTree, onChange: (next) => push({ havingTree: next }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.pileOrder }), groupOrder.length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noPileOrder })) : null, groupOrder.map((sort, index) => (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsx("select", { value: sort.field, onChange: (event) => push({
265
+ }, children: [_jsx(Plus, { className: "size-4" }), " ", copy.builder.addTotal] }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.filterPiles }), _jsx("p", { className: "text-meta text-muted", children: copy.builder.pilesNote }), _jsx(SelectionTree, { model: measuresModel, group: measuresTree, onChange: (next) => push({ measuresTree: next }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(Rule, { label: copy.builder.pileOrder }), groupOrder.length === 0 ? (_jsx("p", { className: "text-meta text-muted", children: copy.builder.noPileOrder })) : null, groupOrder.map((sort, index) => (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsx("select", { "aria-label": copy.builder.pileOrderField, value: sort.field, onChange: (event) => push({
256
266
  groupOrder: groupOrder.map((one, at) => at === index ? { ...one, field: event.target.value } : one),
257
267
  }), className: select, children: [
258
268
  ...levels.map((level) => level.field),
259
- ...Object.keys(totals),
269
+ ...Object.keys(measures),
260
270
  "count",
261
- ].map((name) => (_jsx("option", { value: name, children: name }, name))) }), _jsxs("select", { value: sort.descending === true ? "desc" : "asc", onChange: (event) => push({
271
+ ].map((name) => (_jsx("option", { value: name, children: name }, name))) }), _jsxs("select", { "aria-label": copy.builder.pileOrderDirection, value: sort.descending === true ? "desc" : "asc", onChange: (event) => push({
262
272
  groupOrder: groupOrder.map((one, at) => at === index
263
273
  ? { ...one, descending: event.target.value === "desc" }
264
274
  : one),
@@ -1,22 +1,22 @@
1
1
  import { type CriteriaJoin, type CriteriaPath, type SearchCriteria } from "./criteria.js";
2
2
  import type { Surface } from "../../foundations/types.js";
3
3
  export type CriteriaChipsProps = {
4
- /** Lo que la barra tiene puesto. Grupos y filtros mezclados: acá se separan. */
4
+ /** What the bar has set. Groups and filters mixed: here they are separated. */
5
5
  criteria: readonly SearchCriteria[];
6
- /** Abrir el constructor sobre una instancia. */
6
+ /** Open the builder on an instance. */
7
7
  onOpen?: (path: CriteriaPath) => void;
8
- /** Cambiar cómo se juntan los de un nodo. */
8
+ /** Change how a node's ones are joined. */
9
9
  onJoin?: (path: CriteriaPath, join: CriteriaJoin) => void;
10
- /** Sacar una instancia, o una rama entera. */
10
+ /** Remove an instance, or a whole branch. */
11
11
  onRemove?: (path: CriteriaPath) => void;
12
- /** Sacar varias de una vez: the × of the grouping chain drops every level. */
12
+ /** Remove several at once: the × of the grouping chain drops every level. */
13
13
  onRemoveMany?: (paths: readonly CriteriaPath[]) => void;
14
14
  /**
15
- * Cuál nodo está ABIERTO: dónde va a caer lo próximo que se escriba.
15
+ * Which node is OPEN: where the next thing written will land.
16
16
  *
17
- * Se marca porque si no, escribir `#and` y después una condición la mete en un
18
- * lugar que nadie eligió mirando: el grupo existe, la condición entra, y el
19
- * único que sabía dónde era el que la escribió.
17
+ * It is marked because otherwise, writing `#and` and then a condition puts it in a
18
+ * place nobody chose by looking: the group exists, the condition goes in, and the
19
+ * only one who knew where it was is the one who wrote it.
20
20
  */
21
21
  open?: CriteriaPath;
22
22
  /** How many facets show before the rest fold into «+N» (the grouping chain counts as one).
@@ -12,9 +12,9 @@ export function CriteriaChips({ criteria, onOpen, onJoin, onRemove, onRemoveMany
12
12
  const [expanded, setExpanded] = useState(false);
13
13
  const groups = groupsOf(criteria);
14
14
  const filters = filtersOf(criteria);
15
- /* La ruta se cuenta sobre la lista ENTERA y no sobre la mitad dibujada: es la
16
- identidad de la instancia, y una identidad que cambia según de qué lado se
17
- la mire no identifica nada. */
15
+ /* The path is counted over the WHOLE list and not over the drawn half: it is the
16
+ instance's identity, and an identity that changes depending on which side
17
+ you look at it from identifies nothing. */
18
18
  const pathOf = (one) => [
19
19
  criteria.findIndex((each) => each.id === one.id),
20
20
  ];
@@ -81,26 +81,26 @@ function GroupChain({ groups, onOpen, onRemoveMany, surface, }) {
81
81
  function Node({ node, path, onOpen, onJoin, onRemove, open, surface, }) {
82
82
  const copy = useUiCopy();
83
83
  if (node.kind !== "join") {
84
- /* Una instancia que no lleva expresión no tiene qué editar: el constructor
85
- edita lo que VIAJA, y ésta la contesta quien la declaró. Se ve y se saca
86
- como cualquiera; lo que no hace es prometer una puerta que da a nada. */
87
- const editable = node.kind === "group" || node.where !== undefined;
84
+ /* An instance that carries no expression has nothing to edit: the builder
85
+ edits what TRAVELS, and this one is answered by whoever declared it. It is seen and removed
86
+ like any other; what it does not do is promise a door that opens onto nothing. */
87
+ const editable = node.kind === "group" || node.selection !== undefined;
88
88
  return (_jsx(Chip, { label: node.label, path: path, ...(onOpen === undefined || !editable ? {} : { onOpen }), ...(onRemove === undefined ? {} : { onRemove }), surface: surface }));
89
89
  }
90
- /* El nodo abierto se marca: es donde va a caer lo próximo. Un anillo y no un
91
- fondo, porque adentro hay fichas que ya tienen el suyo. */
90
+ /* The open node is marked: it is where the next thing will land. A ring and not a
91
+ background, because inside there are chips that already have their own. */
92
92
  const isOpen = open !== undefined && open.join(".") === path.join(".");
93
93
  return (_jsxs("span", { className: `inline-flex min-w-0 flex-wrap items-center gap-1 rounded-control border px-1.5 py-0.5 ${bySurface(surface, "border-line bg-ink/4", "border-chrome-ink/25 bg-chrome-ink/8")} ${isOpen ? "ring-1 ring-primary/60" : ""}`, children: [_jsx(JoinWord, { join: node.join, ...(onJoin === undefined ? {} : { onChange: (next) => onJoin(path, next) }), surface: surface }), node.of.length === 0 ? (
94
- /* Un nodo recién abierto no tiene nada adentro, y un corchete vacío se
95
- lee como un error. Dice que está esperando. */
94
+ /* A newly opened node has nothing inside, and an empty bracket reads
95
+ as an error. It says it is waiting. */
96
96
  _jsx("span", { className: `shrink-0 text-micro italic ${bySurface(surface, "text-muted", "text-chrome-muted")}`, children: copy.search.landsHere })) : null, node.of.map((child, at) => (_jsx(Node, { node: child, path: [...path, at], ...(onOpen === undefined ? {} : { onOpen }), ...(onJoin === undefined ? {} : { onJoin }), ...(onRemove === undefined ? {} : { onRemove }), ...(open === undefined ? {} : { open }), surface: surface }, child.id)))] }));
97
97
  }
98
98
  function Chip({ label, path, onOpen, onRemove, surface, }) {
99
99
  const copy = useUiCopy();
100
100
  const shell = `inline-flex min-w-0 max-w-(--container-facet) items-center gap-1 rounded-pill border py-0.5 text-micro ${bySurface(surface, "border-accent/40 bg-accent/18 text-ink", "border-chrome-link/35 bg-chrome-link/18 text-chrome-link")} ${onRemove === undefined ? "px-2" : "pr-0.5 pl-2"}`;
101
101
  const remove = onRemove === undefined ? null : (_jsx("button", { type: "button", onClick: (event) => {
102
- /* Sin esto, sacarla también la abre: el click llega acá y después
103
- sube. */
102
+ /* Without this, removing it also opens it: the click arrives here and then
103
+ bubbles up. */
104
104
  event.stopPropagation();
105
105
  onRemove(path);
106
106
  }, "aria-label": copy.search.removeFilter.replace("{label}", label), className: `inline-flex size-4 shrink-0 items-center justify-center rounded-pill transition-colors duration-(--duration-instant) ${bySurface(surface, "hover:bg-primary/20", "hover:bg-chrome-link/25")}`, children: _jsx(X, { className: "size-3", strokeWidth: 2.5 }) }));