@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
@@ -12,43 +12,43 @@ import { Button } from "../../primitives/button/index.js";
12
12
  import { FolderTree, Plus, Trash2 } from "lucide-react";
13
13
  import { useState } from "react";
14
14
  /* ====================================================================== *
15
- * UN FILTRO QUE ALGUIEN ARMA, DE LO QUE EL MODELO DICE QUE ACEPTA.
15
+ * A FILTER SOMEBODY BUILDS, FROM WHAT THE MODEL SAYS IT ACCEPTS.
16
16
  *
17
- * Los recortes con nombre de al lado —«vencidas», «con entregas pendientes»— son las
18
- * preguntas que alguien ya pensó. Esto es para las demás: elegir un campo, un
19
- * operador, escribir un valor — agruparlos con Y o con O, anidar un grupo
20
- * adentro de otro tantas veces como haga falta, o escribir directamente el
21
- * JSON para copiar o pegar una criteria entera.
17
+ * The named cuts alongside —«vencidas», «con entregas pendientes»— are the
18
+ * questions somebody already thought of. This is for the rest: choose a field, an
19
+ * operator, write a value — group them with AND or with OR, nest a group
20
+ * inside another as many times as needed, or write the
21
+ * JSON directly to copy or paste a whole criteria.
22
22
  *
23
- * **Nada acá está escrito a mano.** Los campos salen de la definición del
24
- * modelo que manda el servidor, y también los operadores de cada uno: un
25
- * campo de texto ofrece «contiene», uno numérico ofrece «>», uno que admite
26
- * vacío ofrece «está vacío». Agregar una columna la hace aparecer acá, con
27
- * sus operadores correctos, sin tocar este archivo.
23
+ * **Nothing here is written by hand.** The fields come from the model
24
+ * definition the server sends, and so do each one's operators: a
25
+ * text field offers «contiene», a numeric one offers «>», one that admits
26
+ * empty offers «está vacío». Adding a column makes it appear here, with
27
+ * its correct operators, without touching this file.
28
28
  *
29
- * **Un árbol, no una lista.** Cada grupo —la raíz incluida— tiene su propio
30
- * «todas / cualquiera» y sus propios hijos: una condición, o otro grupo
31
- * anidado adentro. El ícono del árbol agrega un grupo nuevo al lado de la
32
- * fila que se tocó; el `+` agrega otra condición.
29
+ * **A tree, not a list.** Each group —the root included— has its own
30
+ * «todas / cualquiera» and its own children: a condition, or another group
31
+ * nested inside. The tree icon adds a new group beside the
32
+ * row that was touched; the `+` adds another condition.
33
33
  *
34
- * **Un solo componente renderiza y construye — y siempre hay un JSON al
35
- * lado.** El árbol y el editor de código son dos vistas de la MISMA
36
- * criteria, sincronizadas en las dos direcciones: tocar el árbol reescribe
37
- * el JSON, y escribir un JSON reconocible rehace el árbol. Lo único que el
38
- * árbol no sabe construir ni mostrar es un NOT: si el filtro trae uno en
39
- * cualquier nivel, se dibuja de sólo lectura con `ExpressionView` en su
40
- * lugar, y el JSON sigue siendo la manera de tocarlo.
34
+ * **One component renders and builds — and there is always a JSON
35
+ * beside it.** The tree and the code editor are two views of the SAME
36
+ * criteria, synchronised in both directions: touching the tree rewrites
37
+ * the JSON, and writing a recognisable JSON rebuilds the tree. The only thing the
38
+ * tree does not know how to build or show is a NOT: if the filter brings one at
39
+ * any level, it is drawn read-only with `ExpressionView` in its
40
+ * place, and the JSON remains the way to touch it.
41
41
  * ====================================================================== */
42
- /* Cómo se llama un operador para quien lo lee: `copy.ops`, que es la MISMA tabla que usa la
43
- barra al armar la pregunta. Dos tablas es que la misma comparación se llame de dos maneras
44
- en la misma pantalla. */
45
- /** Qué operadores no llevan valor: preguntar si algo está vacío no necesita escribir nada. */
42
+ /* What an operator is called for whoever reads it: `copy.ops`, which is the SAME table the
43
+ bar uses when building the question. Two tables means the same comparison is called two ways
44
+ on the same screen. */
45
+ /** Which operators take no value: asking whether something is empty needs nothing written. */
46
46
  const WITHOUT_VALUE = new Set(["is null"]);
47
- /** Qué operadores comparan contra DOS valores. «Entre el 1 y el 31» es la pregunta que todo
48
- * el mundo hace sobre fechas, y escribirla como dos reglas sueltas es la forma de
49
- * equivocarse con uno de los dos extremos. */
47
+ /** Which operators compare against TWO values. «Entre el 1 y el 31» is the question everybody
48
+ * asks about dates, and writing it as two loose rules is the way to
49
+ * get one of the two ends wrong. */
50
50
  const WITH_RANGE = new Set(["between"]);
51
- /** Qué clase de input pide un valor, leído del tipo del campo. */
51
+ /** What kind of input asks for a value, read from the field's type. */
52
52
  function inputType(type) {
53
53
  if (type === "integer" || type === "number")
54
54
  return "number";
@@ -66,10 +66,10 @@ function isCondition(value) {
66
66
  typeof value.operator === "string" &&
67
67
  "value" in value);
68
68
  }
69
- /** Si esto es una de las formas que el filtro reconoce — condición, o grupo `all`/`any`/
70
- * `negate`. Un JSON válido que no es ninguna de éstas —`{}`, `{"foo": 1}`, un array suelto—
71
- * no es un filtro que este componente sepa dibujar, y se trata como error de forma en vez de
72
- * intentar mostrar cualquier cosa. */
69
+ /** Whether this is one of the shapes the filter recognises — condition, or `all`/`any`/
70
+ * `negate` group. A valid JSON that is none of these —`{}`, `{"foo": 1}`, a loose array—
71
+ * is not a filter this component knows how to draw, and is treated as a shape error instead of
72
+ * trying to show anything at all. */
73
73
  export function isRecognizedFilter(value) {
74
74
  if (isCondition(value))
75
75
  return true;
@@ -82,7 +82,7 @@ export function isRecognizedFilter(value) {
82
82
  return true;
83
83
  if ("negate" in record)
84
84
  return true;
85
- if (typeof record.through === "string" && "where" in record)
85
+ if (isThrough(record))
86
86
  return true;
87
87
  return false;
88
88
  }
@@ -91,9 +91,49 @@ function isThrough(value) {
91
91
  if (typeof value !== "object" || value === null)
92
92
  return false;
93
93
  const record = value;
94
- return (typeof record.through === "string" &&
95
- "where" in record &&
96
- (record.match === undefined || MATCHES.includes(record.match)));
94
+ return typeof record.through === "string" && "selection" in record;
95
+ }
96
+ function isNegate(value) {
97
+ return typeof value === "object" && value !== null && "negate" in value;
98
+ }
99
+ /**
100
+ * A relation crossed, read off criteria's shape: the quantifier is not a key, it is the
101
+ * sentence the `negate`s around the `through` make.
102
+ *
103
+ * {through, selection: s} «alguno» s
104
+ * {negate: {through, selection: s}} «ninguno» s
105
+ * {negate: {through, selection: {negate: s}}} «todos» s (none that does not)
106
+ *
107
+ * «Ninguno con no-s» and «todos con s» are the same filter; it reads as the second, the
108
+ * shorter sentence, and that is also how a path of two hops comes back: «ninguna línea con
109
+ * ningún impuesto» returns as «todas las líneas con algún impuesto», which filters the same.
110
+ * Anything else is not a relation crossed: `null`.
111
+ */
112
+ function crossedOf(value) {
113
+ if (isThrough(value)) {
114
+ return { through: value.through, match: "any", selection: value.selection };
115
+ }
116
+ if (!isNegate(value) || !isThrough(value.negate))
117
+ return null;
118
+ const { through, selection } = value.negate;
119
+ return isNegate(selection)
120
+ ? { through, match: "all", selection: selection.negate }
121
+ : { through, match: "none", selection };
122
+ }
123
+ /** The other way: a relation and its quantifier, written the way criteria reads them. */
124
+ function crossing(through, match, inner) {
125
+ if (match === "none")
126
+ return { negate: { through, selection: inner } };
127
+ if (match === "all")
128
+ return { negate: { through, selection: { negate: inner } } };
129
+ return { through, selection: inner };
130
+ }
131
+ /** Whether a «some» crossing reaches ONE record: a to-one relation, as the model says. Then
132
+ * it is said as a path («Cliente > País»), since «alguno de» would be noise. Without the
133
+ * model it is said as what `{through, selection}` means — «alguno de» —, never wrong. */
134
+ function reachesOne(model, crossed) {
135
+ const field = model?.fields[crossed.through];
136
+ return crossed.match === "any" && field !== undefined && !isToMany(field);
97
137
  }
98
138
  export function blankCondition(model, first) {
99
139
  const field = first ?? "";
@@ -107,18 +147,18 @@ export function blankCondition(model, first) {
107
147
  export function blankGroup(model, first) {
108
148
  return { kind: "group", join: "all", children: [blankCondition(model, first)] };
109
149
  }
110
- /** El árbol como el filtro que viaja.
150
+ /** The tree as the filter that travels.
111
151
  *
112
- * in condición sola
113
- * out esa condición, sin envolver
152
+ * in a lone condition
153
+ * out that condition, unwrapped
114
154
  *
115
- * in grupo con dos hijos, join «any»
155
+ * in group with two children, join «any»
116
156
  * out {any: [ … , … ]}
117
157
  *
118
- * Un grupo de un solo hijo no se envuelve —es ese hijo—, y un grupo sin hijos desaparece: ni
119
- * «todas» ni «cualquiera» vacío es un filtro que alguien pidió. La regla vale en cualquier
120
- * nivel, no sólo en la raíz, así que anidar un grupo de una condición sola es lo mismo que no
121
- * haberlo anidado. */
158
+ * A group with a single child is not wrapped —it is that child—, and a group with no children disappears: neither
159
+ * an empty «todas» nor «cualquiera» is a filter anybody asked for. The rule holds at any
160
+ * level, not only at the root, so nesting a single-condition group is the same as not
161
+ * having nested it. */
122
162
  export function treeToFilter(node) {
123
163
  if (node.kind === "condition") {
124
164
  const leaf = conditionToFilter(node);
@@ -129,9 +169,7 @@ export function treeToFilter(node) {
129
169
  /** The relations of a path, as nested `through` nodes around the condition: the first hop
130
170
  * outside, the last one next to the condition — the order the path reads in. */
131
171
  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);
172
+ return hops.reduceRight((inner, hop) => crossing(hop.field, hop.match, inner), leaf);
135
173
  }
136
174
  function conditionToFilter(node) {
137
175
  {
@@ -141,17 +179,17 @@ function conditionToFilter(node) {
141
179
  return { field: node.field, operator: node.operator, value: true };
142
180
  }
143
181
  if (WITH_RANGE.has(node.operator)) {
144
- /* Un rango a medio escribir no es medio rango: mientras falte un extremo, la regla no
145
- viaja. */
182
+ /* A half-written range is not half a range: while one end is missing, the rule does not
183
+ travel. */
146
184
  if (node.value === "" || (node.upper ?? "") === "")
147
185
  return undefined;
148
186
  return { field: node.field, operator: node.operator, value: [node.value, node.upper] };
149
187
  }
150
- /* **Una regla sin valor no filtra.** Viajaba con `value: ""`, y eso no es «todavía no
151
- escribí nada»: contra un `=` es «el campo es la cadena vacía», que vacía la lista
152
- mientras alguien sigue tipeando, y contra un `like` es «contiene nada», que la deja
153
- igual. Para preguntar por lo que está vacío está el operador «está vacío», que el
154
- modelo publica en los campos que lo admiten — explícito, y no por omisión. */
188
+ /* **A rule with no value does not filter.** It used to travel with `value: ""`, and that is not «not
189
+ written anything yet»: against an `=` it is «the field is the empty string», which empties the list
190
+ while somebody is still typing, and against a `like` it is «contains nothing», which leaves it
191
+ the same. To ask for what is empty there is the «está vacío» operator, which the
192
+ model publishes on the fields that admit it — explicit, and not by omission. */
155
193
  if (node.value === "")
156
194
  return undefined;
157
195
  return { field: node.field, operator: node.operator, value: node.value };
@@ -163,9 +201,9 @@ function groupToFilter(node) {
163
201
  .filter((one) => one !== undefined);
164
202
  if (kept.length === 0)
165
203
  return undefined;
166
- /* «Ninguna» niega el grupo ENTERO y no cada hijo por su cuenta: «ni vencida ni
167
- grande» es `no (vencida o grande)`. Y un grupo de uno tampoco se desarma
168
- acá —desarmarlo perdería la negación—, que es lo mismo que hace la barra. */
204
+ /* «Ninguna» negates the WHOLE group and not each child on its own: «ni vencida ni
205
+ grande» is `not (vencida or grande)`. And a group of one is not dismantled
206
+ here either —dismantling it would lose the negation—, which is what the bar does. */
169
207
  if (node.join === "not") {
170
208
  return { negate: kept.length === 1 ? kept[0] : { any: kept } };
171
209
  }
@@ -173,8 +211,8 @@ function groupToFilter(node) {
173
211
  return kept[0];
174
212
  return node.join === "any" ? { any: kept } : { all: kept };
175
213
  }
176
- /** Una condición de vuelta a una fila editable: el valor vuelve a texto, que es lo único que
177
- * un `<input>` sabe mostrar. Una lista —el valor de un `in`— se escribe separada por comas. */
214
+ /** A condition back to an editable row: the value goes back to text, which is the only thing
215
+ * an `<input>` knows how to show. A list —an `in`'s value— is written separated by commas. */
178
216
  function conditionToTree(condition) {
179
217
  if (WITH_RANGE.has(condition.operator) && Array.isArray(condition.value)) {
180
218
  const [from, to] = condition.value;
@@ -197,51 +235,47 @@ function conditionToTree(condition) {
197
235
  : String(condition.value ?? ""),
198
236
  };
199
237
  }
200
- /** El filtro leído de vuelta a un árbol.
238
+ /** The filter read back into a tree.
201
239
  *
202
240
  * in {field: "name", operator: "=", value: "labs"}
203
241
  * out TreeCondition
204
242
  *
205
- * in {any: [{all: [cond1, cond2]}, cond3]} grupo adentro de grupo
206
- * out TreeGroup(any) con un TreeGroup(all) y una condición como hijos
243
+ * in {any: [{all: [cond1, cond2]}, cond3]} group inside a group
244
+ * out TreeGroup(any) with a TreeGroup(all) and a condition as children
207
245
  *
208
246
  * in {negate: {any: [cond1, cond2]}}
209
- * out TreeGroup(not) con las dos condiciones como hijos
247
+ * out TreeGroup(not) with the two conditions as children
210
248
  *
211
- * El `negate` de un `any` se abre en el grupo «ninguna» y no queda como un grupo
212
- * adentro de otro: es lo que `treeToFilter` vuelve a escribir, así que ida y
213
- * vuelta dan lo mismo. Lo que NO se puede leer —un objeto que no es ni una
214
- * condición ni ninguna de las tres formas— devuelve `null`, y ahí el componente
215
- * lo muestra de sólo lectura sin dejar de poder tocarlo como JSON.
249
+ * An `any`'s `negate` opens into the «ninguna» group and does not stay as a group
250
+ * inside another: it is what `treeToFilter` writes back, so there and
251
+ * back give the same. What can NOT be read —an object that is neither a
252
+ * condition nor any of the three shapes— returns `null`, and there the component
253
+ * shows it read-only while still letting you touch it as JSON.
216
254
  */
217
255
  export function treeFromFilter(filter) {
218
256
  if (isCondition(filter))
219
257
  return conditionToTree(filter);
220
258
  /* A chain of relations ending in ONE condition is one row with its path. A chain that ends
221
259
  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 };
260
+ cannot be a row: the tree shows it read-only and the JSON stays the way to edit it.
261
+ Read before `negate`: «ninguna línea con…» is a `negate` around a `through`, and it is
262
+ one row with its quantifier, not a group. */
263
+ const hops = [];
264
+ let node = filter;
265
+ for (let crossed = crossedOf(node); crossed !== null; crossed = crossedOf(node)) {
266
+ hops.push({ field: crossed.through, match: crossed.match });
267
+ node = crossed.selection;
268
+ }
269
+ if (hops.length > 0) {
270
+ return isCondition(node) ? { ...conditionToTree(node), through: hops } : null;
237
271
  }
238
272
  if (typeof filter !== "object" || filter === null)
239
273
  return null;
240
274
  const record = filter;
241
275
  if ("negate" in record) {
242
276
  const inside = record.negate;
243
- /* Un `negate` de un `any` son los hijos del grupo negado; cualquier otra cosa
244
- es un solo hijo. */
277
+ /* An `any`'s `negate` is the negated group's children; anything else
278
+ is a single child. */
245
279
  const raws = typeof inside === "object" &&
246
280
  inside !== null &&
247
281
  Array.isArray(inside.any)
@@ -260,8 +294,8 @@ export function treeFromFilter(filter) {
260
294
  const children = readChildren(record[join]);
261
295
  return children === null ? null : { kind: "group", join, children };
262
296
  }
263
- /** Los hijos de un grupo, o `null` si alguno no se puede leer: medio árbol es
264
- * peor que ninguno, porque dibuja algo que no es lo que filtra. */
297
+ /** A group's children, or `null` if any cannot be read: half a tree is
298
+ * worse than none, because it draws something that is not what filters. */
265
299
  function readChildren(raws) {
266
300
  const children = [];
267
301
  for (const raw of raws) {
@@ -275,8 +309,8 @@ function readChildren(raws) {
275
309
  function stringifyFilter(filter) {
276
310
  return filter === undefined ? "" : JSON.stringify(filter, null, 2);
277
311
  }
278
- /** Un valor de condición, legible: una lista se junta con comas, y lo que no tiene nada se
279
- * dice en palabras en vez de mostrar `true`/`undefined` sueltos. */
312
+ /** A condition value, legible: a list is joined with commas, and what has nothing is
313
+ * said in words instead of showing a bare `true`/`undefined`. */
280
314
  function describeValue(value, operator) {
281
315
  const copy = currentCopy();
282
316
  if (Array.isArray(value)) {
@@ -284,15 +318,15 @@ function describeValue(value, operator) {
284
318
  ? value.join(` ${copy.search.and} `)
285
319
  : value.join(", ");
286
320
  }
287
- /* Las mismas dos palabras que la tabla pone en una celda booleana: un `sí` que
288
- no es el `sí` de al lado es una segunda manera de decir lo mismo. */
321
+ /* The same two words the table puts in a boolean cell: a `sí` that
322
+ is not the `sí` next door is a second way of saying the same thing. */
289
323
  if (typeof value === "boolean")
290
324
  return value ? copy.table.yes : copy.table.no;
291
325
  return String(value ?? "");
292
326
  }
293
- /** El filtro dicho en una línea, para una ficha o un rótulo.
327
+ /** The filter said in one line, for a chip or a label.
294
328
  *
295
- * in {field: "row_count", operator: ">", value: 1000}, con el modelo
329
+ * in {field: "row_count", operator: ">", value: 1000}, with the model
296
330
  * out 'filas mayor que 1000'
297
331
  *
298
332
  * in {all: [cond1, cond2]}
@@ -301,17 +335,17 @@ function describeValue(value, operator) {
301
335
  * in {any: [cond1, cond2]}
302
336
  * out 'el nombre es a o el nombre es b'
303
337
  *
304
- * Cada condición la dice `sayCondition`, que es la misma que usa la barra: sin
305
- * eso, lo escrito en la barra y lo armado en el diálogo se leen distinto aunque
306
- * filtren igual, y nadie sabe cuál de las dos frases es la que manda.
338
+ * Each condition is said by `sayCondition`, which is the same one the bar uses: without
339
+ * that, what is written in the bar and what is built in the dialog read differently even though
340
+ * they filter the same, and nobody knows which of the two phrases is the one in charge.
307
341
  *
308
- * **El modelo es el que sabe cómo se llama un campo.** Sin él queda el nombre
309
- * crudo —`row_count`—, que es lo mejor que se puede decir sin preguntarle a
310
- * nadie.
342
+ * **The model is the one that knows what a field is called.** Without it the raw
343
+ * name remains —`row_count`—, which is the best that can be said without asking
344
+ * anybody.
311
345
  *
312
- * Un grupo anidado se encierra entre paréntesis, que es lo que evita que «a y (b o c)» se
313
- * lea como «(a y b) o c». Para más de tres condiciones se corta: una ficha que no entra en
314
- * la barra no dice nada — para eso está abrir el constructor y verlo entero. */
346
+ * A nested group is enclosed in parentheses, which is what keeps «a y (b o c)» from being
347
+ * read as «(a y b) o c». Past three conditions it is cut: a chip that does not fit in
348
+ * the bar says nothing — that is what opening the builder and seeing it whole is for. */
315
349
  export function describeFilter(node, model,
316
350
  /** The model at the end of a path of relations, when it already arrived: it names the
317
351
  * fields of a `through`. Without it they keep their raw names. */
@@ -320,14 +354,17 @@ modelAt) {
320
354
  }
321
355
  function say(node, model, depth, at, modelAt) {
322
356
  const copy = currentCopy();
323
- if ("through" in node) {
357
+ const crossed = crossedOf(node);
358
+ if (crossed !== null) {
324
359
  /* «alguno de Líneas con alguno de Impuestos con Monto mayor que 10». The quantifier
325
360
  is a separate word and not «algún impuesto» because the model publishes the label,
326
361
  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];
362
+ const relation = model === undefined ? crossed.through : fieldLabel(model, crossed.through, copy.locale);
363
+ const next = [...at, crossed.through];
364
+ const inner = say(crossed.selection, modelAt?.(next), depth + 1, next, modelAt);
365
+ const template = reachesOne(model, crossed)
366
+ ? copy.fieldPath.say.one
367
+ : copy.fieldPath.say[crossed.match];
331
368
  return fillCopy(template, { relation, inner });
332
369
  }
333
370
  if ("all" in node || "any" in node) {
@@ -343,45 +380,50 @@ function say(node, model, depth, at, modelAt) {
343
380
  if ("negate" in node) {
344
381
  return `${copy.search.notWord} ${say(node.negate, model, depth + 1, at, modelAt)}`;
345
382
  }
383
+ /* Every `through` was said above; anything still not a condition is not a shape of the
384
+ grammar, and it is shown as it came rather than as a sentence it is not. */
385
+ if (!isCondition(node))
386
+ return JSON.stringify(node);
346
387
  const label = model === undefined ? node.field : fieldLabel(model, node.field, copy.locale);
347
388
  return sayCondition(label, node.operator, describeValue(node.value, node.operator));
348
389
  }
349
- /** El filtro dibujado tal como es, recursivo: una condición es una línea, `all`/`any` son un
350
- * grupo con su rótulo y sus hijos adentro, `negate` es «no» envolviendo al que niega.
390
+ /** The filter drawn as it is, recursive: a condition is a line, `all`/`any` are a
391
+ * group with its label and its children inside, `negate` is «no» wrapping the one it negates.
351
392
  *
352
- * Es la mitad de sólo lectura de este archivo, y también sirve sola: mostrar qué dice un
353
- * filtro que ya está puesto no necesita abrir el constructor. */
393
+ * It is the read-only half of this file, and it also works alone: showing what a
394
+ * filter that is already set says does not need opening the builder. */
354
395
  export function ExpressionView({ node, model, depth = 0, modelAt, at = [], }) {
355
396
  const surface = useSurface();
356
397
  const copy = useUiCopy();
357
398
  const box = surface === "chrome" ? "border-chrome-ink/20" : "border-ink/15";
358
399
  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];
400
+ const crossed = crossedOf(node);
401
+ if (crossed !== null) {
402
+ const relation = model === undefined ? crossed.through : fieldLabel(model, crossed.through, copy.locale);
403
+ const next = [...at, crossed.through];
362
404
  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
405
+ 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: reachesOne(model, crossed)
364
406
  ? 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 })] }));
407
+ : `${copy.fieldPath.match[crossed.match]} · ${relation}` }), _jsx(ExpressionView, { node: crossed.selection, ...(inner === undefined ? {} : { model: inner }), ...(modelAt === undefined ? {} : { modelAt }), at: next, depth: depth + 1 })] }));
366
408
  }
367
409
  if ("all" in node || "any" in node) {
368
- /* LAS MISMAS TRES PALABRAS QUE LA BARRA. Un grupo que acá se llama «coincide
369
- con alguna» y en la ficha «cualquiera» son dos vocabularios para una sola
370
- cosa, y el que los lee tiene que aprender los dos. */
410
+ /* THE SAME THREE WORDS AS THE BAR. A group that is called «coincide
411
+ con alguna» here and «cualquiera» on the chip is two vocabularies for one
412
+ thing, and whoever reads them has to learn both. */
371
413
  const label = "all" in node ? copy.search.joins.all : copy.search.joins.any;
372
414
  const items = "all" in node ? node.all : node.any;
373
- 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: label }), items.map((child, index) => (_jsx(ExpressionView, { node: child, ...(model === undefined ? {} : { model }), depth: depth + 1 }, index)))] }));
415
+ 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: label }), items.map((child, index) => (_jsx(ExpressionView, { node: child, ...(model === undefined ? {} : { model }), ...(modelAt === undefined ? {} : { modelAt }), at: at, depth: depth + 1 }, index)))] }));
374
416
  }
375
417
  if ("negate" in node) {
376
- 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: copy.search.joins.none }), _jsx(ExpressionView, { node: node.negate, ...(model === undefined ? {} : { model }), depth: depth + 1 })] }));
418
+ 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: copy.search.joins.none }), _jsx(ExpressionView, { node: node.negate, ...(model === undefined ? {} : { model }), ...(modelAt === undefined ? {} : { modelAt }), at: at, depth: depth + 1 })] }));
377
419
  }
378
- /* Y la misma frase que la ficha: una condición se lee igual esté donde esté. */
420
+ /* And the same phrase as the chip: a condition reads the same wherever it is. */
379
421
  return _jsx("p", { className: `text-meta ${indent}`, children: describeFilter(node, model) });
380
422
  }
381
423
  /* ---------------------------------------------------------------------- *
382
- * UN GRUPO, DIBUJADO — la pieza que se llama a sí misma para anidar.
424
+ * A GROUP, DRAWN — the piece that calls itself to nest.
383
425
  * ---------------------------------------------------------------------- */
384
- export function WhereTree({ model, group, onChange, depth = 0, focus, loadModel, models: shared, }) {
426
+ export function SelectionTree({ model, group, onChange, depth = 0, focus, loadModel, models: shared, }) {
385
427
  const names = filterableNames(model);
386
428
  const copy = useUiCopy();
387
429
  const surface = useSurface();
@@ -418,19 +460,19 @@ export function WhereTree({ model, group, onChange, depth = 0, focus, loadModel,
418
460
  function removeAt(index) {
419
461
  onChange({ ...group, children: group.children.filter((_, at) => at !== index) });
420
462
  }
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)))] }));
463
+ 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(SelectionTree, { 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
464
  }
423
465
  /* ---------------------------------------------------------------------- *
424
- * UNA REGLA — el camino hasta el campo, cuántos de cada relación, el operador y el valor.
466
+ * A RULE — the path to the field, how many of each relation, the operator and the value.
425
467
  * ---------------------------------------------------------------------- */
426
468
  function ConditionRow({ model, models, child, box, focused, onChange, actions, }) {
427
469
  const copy = useUiCopy();
428
470
  const hops = child.through ?? [];
429
471
  const path = child.field === "" ? [] : [...hops.map((hop) => hop.field), child.field];
430
472
  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. */
473
+ /* The operator and the value come from the path's LAST field: «Monto», reached through two
474
+ relations, is compared as a number and not as the relation it was reached through. A
475
+ root rule knows it without waiting for anybody. */
434
476
  const leaf = steps?.at(-1)?.field ?? (hops.length === 0 ? model.fields[child.field] : undefined);
435
477
  const ops = leaf?.ops ?? [];
436
478
  const type = leaf?.type ?? "text";
@@ -440,8 +482,7 @@ function ConditionRow({ model, models, child, box, focused, onChange, actions, }
440
482
  return;
441
483
  const nextHops = found.slice(0, -1).map((step, at) => ({
442
484
  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. */
485
+ /* Changing the final field does not reset the chip of a relation that remains in the path. */
445
486
  match: hops[at]?.field === step.name ? hops[at].match : "any",
446
487
  }));
447
488
  onChange({
@@ -460,11 +501,15 @@ function ConditionRow({ model, models, child, box, focused, onChange, actions, }
460
501
  });
461
502
  }
462
503
  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] }));
504
+ /* The one that was come to see is marked and brought into view. A ring and not
505
+ a background: the background competes with the `select` that has to be touched. */
506
+ 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) => {
507
+ const step = steps?.[at];
508
+ const many = step !== undefined && isToMany(step.field);
509
+ return hop.match !== "any" || 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: step?.label ?? hop.field }), _jsx("select", { "aria-label": fillCopy(copy.fieldPath.match.label, {
510
+ relation: step?.label ?? hop.field,
511
+ }), 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;
512
+ }), _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] }));
468
513
  }
469
514
  export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, models: shared, }) {
470
515
  const names = filterableNames(model);
@@ -479,18 +524,18 @@ export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, mo
479
524
  const [lockedView, setLockedView] = useState(initial !== undefined && decomposed === null ? initial : null);
480
525
  const [rawText, setRawText] = useState(() => stringifyFilter(initial ?? treeToFilter(tree)));
481
526
  const [rawError, setRawError] = useState(null);
482
- /* Tocar el árbol reescribe el JSON para que muestre exactamente lo que el árbol ahora dice,
483
- y suelta cualquier vista de sólo lectura que hubiera quedado. */
527
+ /* Touching the tree rewrites the JSON so it shows exactly what the tree now says,
528
+ and drops any read-only view that may have been left. */
484
529
  function updateTree(next) {
485
530
  setTree(next);
486
531
  setLockedView(null);
487
532
  setRawText(stringifyFilter(treeToFilter(next)));
488
533
  setRawError(null);
489
534
  }
490
- /* Escribir en el JSON intenta lo mismo al revés: si lo tipeado no trae un `negate` en
491
- ningún nivel, el árbol se rehace para mostrarlo — Y y O, a cualquier profundidad. Si trae
492
- uno, se dibuja de sólo lectura, pero el JSON sigue siendo lo que se va a aplicar. Si no
493
- es ninguna de las dos —a medio escribir, o no es un filtro— no se toca lo que ya había. */
535
+ /* Writing in the JSON tries the same the other way round: if what was typed brings no `negate` at
536
+ any level, the tree is rebuilt to show it — AND and OR, at any depth. If it brings
537
+ one, it is drawn read-only, but the JSON remains what will be applied. If it is
538
+ neither —half-written, or not a filter— what was there is not touched. */
494
539
  function updateRaw(text) {
495
540
  setRawText(text);
496
541
  if (text.trim() === "") {
@@ -521,5 +566,5 @@ export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, mo
521
566
  setLockedView(parsed);
522
567
  }
523
568
  }
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 }))] })] }));
569
+ 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(SelectionTree, { 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 }))] })] }));
525
570
  }