@sincpro/web-ui 2.11.0 → 2.13.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 (207) hide show
  1. package/README.md +77 -20
  2. package/dist/components/activity/Messages.d.ts +3 -23
  3. package/dist/components/activity/Messages.js +3 -17
  4. package/dist/components/activity/index.d.ts +2 -1
  5. package/dist/components/activity/index.js +2 -1
  6. package/dist/components/activity/messageKind.d.ts +23 -0
  7. package/dist/components/activity/messageKind.js +17 -0
  8. package/dist/components/assist/assist.d.ts +1 -1
  9. package/dist/components/assist/assist.js +1 -1
  10. package/dist/components/frame/model.js +1 -1
  11. package/dist/components/guide/index.d.ts +2 -1
  12. package/dist/components/guide/index.js +2 -1
  13. package/dist/components/guide/selector.d.ts +25 -0
  14. package/dist/components/guide/selector.js +14 -0
  15. package/dist/components/guide/target.d.ts +3 -25
  16. package/dist/components/guide/target.js +2 -14
  17. package/dist/components/index.d.ts +1 -0
  18. package/dist/components/index.js +1 -0
  19. package/dist/components/listing/AxisLevels.d.ts +2 -5
  20. package/dist/components/listing/AxisLevels.js +5 -22
  21. package/dist/components/listing/BoardColumns.js +10 -6
  22. package/dist/components/listing/ColumnsMenu.d.ts +3 -7
  23. package/dist/components/listing/ColumnsMenu.js +4 -8
  24. package/dist/components/listing/Listing.js +3 -1
  25. package/dist/components/listing/ListingBar.d.ts +16 -94
  26. package/dist/components/listing/ListingBar.js +24 -2
  27. package/dist/components/listing/RecordCard.d.ts +41 -3
  28. package/dist/components/listing/RecordCard.js +63 -22
  29. package/dist/components/listing/Row.js +5 -2
  30. package/dist/components/listing/collapsed.d.ts +2 -0
  31. package/dist/components/listing/collapsed.js +8 -0
  32. package/dist/components/listing/columnSpecs.d.ts +34 -0
  33. package/dist/components/listing/columnSpecs.js +54 -0
  34. package/dist/components/listing/columns.d.ts +3 -21
  35. package/dist/components/listing/columns.js +2 -39
  36. package/dist/components/listing/index.d.ts +11 -7
  37. package/dist/components/listing/index.js +15 -8
  38. package/dist/components/listing/levels.d.ts +9 -0
  39. package/dist/components/listing/levels.js +27 -0
  40. package/dist/components/listing/pageSizes.d.ts +9 -0
  41. package/dist/components/listing/pageSizes.js +11 -0
  42. package/dist/components/listing/pages.d.ts +2 -9
  43. package/dist/components/listing/pages.js +5 -9
  44. package/dist/components/listing/set.d.ts +1 -1
  45. package/dist/components/listing/tree.d.ts +2 -1
  46. package/dist/components/listing/tree.js +4 -5
  47. package/dist/components/preview/FilePreview.d.ts +3 -3
  48. package/dist/components/preview/FilePreview.js +3 -15
  49. package/dist/components/preview/index.d.ts +2 -1
  50. package/dist/components/preview/index.js +2 -1
  51. package/dist/components/preview/previewKind.d.ts +3 -0
  52. package/dist/components/preview/previewKind.js +17 -0
  53. package/dist/components/receipt/Receipt.d.ts +51 -0
  54. package/dist/components/receipt/Receipt.js +23 -0
  55. package/dist/components/receipt/index.d.ts +1 -0
  56. package/dist/components/receipt/index.js +3 -0
  57. package/dist/components/search/CriteriaChips.js +5 -3
  58. package/dist/components/search/FilterBuilder.d.ts +5 -139
  59. package/dist/components/search/FilterBuilder.js +5 -579
  60. package/dist/components/search/JsonEditor.d.ts +2 -8
  61. package/dist/components/search/JsonEditor.js +5 -15
  62. package/dist/components/search/RuleValue.d.ts +2 -2
  63. package/dist/components/search/RuleValue.js +5 -4
  64. package/dist/components/search/datePeriods.js +1 -1
  65. package/dist/components/search/filterTree.d.ts +183 -0
  66. package/dist/components/search/filterTree.js +570 -0
  67. package/dist/components/search/formatJson.d.ts +8 -0
  68. package/dist/components/search/formatJson.js +17 -0
  69. package/dist/components/search/index.d.ts +5 -3
  70. package/dist/components/search/index.js +7 -3
  71. package/dist/components/search/query.js +1 -1
  72. package/dist/components/shell/KioskFrame.d.ts +35 -0
  73. package/dist/components/shell/KioskFrame.js +39 -0
  74. package/dist/components/shell/SearchEntry.js +1 -1
  75. package/dist/components/shell/index.d.ts +1 -0
  76. package/dist/components/shell/index.js +1 -0
  77. package/dist/foundations/calendar.js +1 -1
  78. package/dist/foundations/catalog.d.ts +7 -8
  79. package/dist/foundations/catalog.js +10 -35
  80. package/dist/foundations/chart.js +1 -1
  81. package/dist/foundations/clock.d.ts +3 -0
  82. package/dist/foundations/clock.js +41 -0
  83. package/dist/foundations/controlName.d.ts +12 -0
  84. package/dist/foundations/controlName.js +14 -0
  85. package/dist/foundations/copy.d.ts +3 -1130
  86. package/dist/foundations/copy.es.d.ts +1 -1
  87. package/dist/foundations/copy.es.js +26 -0
  88. package/dist/foundations/copy.js +13 -747
  89. package/dist/foundations/copyStore.d.ts +21 -0
  90. package/dist/foundations/copyStore.js +47 -0
  91. package/dist/foundations/density.d.ts +4 -8
  92. package/dist/foundations/density.js +2 -9
  93. package/dist/foundations/form.d.ts +2 -12
  94. package/dist/foundations/form.js +4 -14
  95. package/dist/foundations/idle.d.ts +1 -0
  96. package/dist/foundations/idle.js +34 -0
  97. package/dist/foundations/index.d.ts +21 -11
  98. package/dist/foundations/index.js +28 -11
  99. package/dist/foundations/keys.d.ts +8 -0
  100. package/dist/foundations/keys.js +6 -0
  101. package/dist/foundations/pickBy.d.ts +16 -0
  102. package/dist/foundations/pickBy.js +17 -0
  103. package/dist/foundations/pivotSheet.js +0 -0
  104. package/dist/foundations/pointer.d.ts +25 -0
  105. package/dist/foundations/pointer.js +28 -0
  106. package/dist/foundations/shortcut.d.ts +3 -9
  107. package/dist/foundations/shortcut.js +2 -7
  108. package/dist/foundations/sticky.d.ts +2 -6
  109. package/dist/foundations/sticky.js +5 -8
  110. package/dist/foundations/stickyStyle.d.ts +12 -0
  111. package/dist/foundations/stickyStyle.js +13 -0
  112. package/dist/foundations/surface.d.ts +2 -2
  113. package/dist/foundations/surface.js +4 -2
  114. package/dist/foundations/theme.d.ts +3 -13
  115. package/dist/foundations/theme.js +2 -15
  116. package/dist/foundations/themeChoice.d.ts +19 -0
  117. package/dist/foundations/themeChoice.js +22 -0
  118. package/dist/foundations/types.d.ts +3 -0
  119. package/dist/foundations/uiCopy.d.ts +1173 -0
  120. package/dist/foundations/uiCopy.js +775 -0
  121. package/dist/foundations/xlsx.d.ts +4 -10
  122. package/dist/foundations/xlsx.js +0 -0
  123. package/dist/foundations/xlsxDownload.d.ts +8 -0
  124. package/dist/foundations/xlsxDownload.js +28 -0
  125. package/dist/primitives/button/Button.d.ts +3 -15
  126. package/dist/primitives/button/Button.js +2 -65
  127. package/dist/primitives/button/classes.d.ts +21 -0
  128. package/dist/primitives/button/classes.js +65 -0
  129. package/dist/primitives/button/index.d.ts +2 -1
  130. package/dist/primitives/button/index.js +3 -1
  131. package/dist/primitives/choice/RadioGroup.d.ts +8 -1
  132. package/dist/primitives/choice/RadioGroup.js +9 -1
  133. package/dist/primitives/choice/options.d.ts +3 -0
  134. package/dist/primitives/field/Field.d.ts +2 -6
  135. package/dist/primitives/field/Field.js +4 -10
  136. package/dist/primitives/field/Keypad.d.ts +43 -0
  137. package/dist/primitives/field/Keypad.js +62 -0
  138. package/dist/primitives/field/Stepper.d.ts +28 -0
  139. package/dist/primitives/field/Stepper.js +52 -0
  140. package/dist/primitives/field/classes.d.ts +6 -0
  141. package/dist/primitives/field/classes.js +13 -0
  142. package/dist/primitives/field/clipboard.js +1 -1
  143. package/dist/primitives/field/index.d.ts +5 -1
  144. package/dist/primitives/field/index.js +9 -1
  145. package/dist/primitives/field/keypadKeys.d.ts +24 -0
  146. package/dist/primitives/field/keypadKeys.js +80 -0
  147. package/dist/primitives/hint/Hint.js +1 -1
  148. package/dist/primitives/menu/Menu.d.ts +2 -19
  149. package/dist/primitives/menu/Menu.js +4 -30
  150. package/dist/primitives/menu/classes.d.ts +18 -0
  151. package/dist/primitives/menu/classes.js +33 -0
  152. package/dist/primitives/menu/index.d.ts +2 -1
  153. package/dist/primitives/menu/index.js +3 -1
  154. package/dist/primitives/notice/Flag.js +1 -1
  155. package/dist/primitives/notice/Outcome.d.ts +28 -0
  156. package/dist/primitives/notice/Outcome.js +28 -0
  157. package/dist/primitives/notice/index.d.ts +1 -0
  158. package/dist/primitives/notice/index.js +2 -0
  159. package/dist/primitives/table/CellCopy.js +1 -1
  160. package/dist/primitives/table/EditableTable.d.ts +3 -37
  161. package/dist/primitives/table/EditableTable.js +2 -47
  162. package/dist/primitives/table/ReportTable.js +1 -1
  163. package/dist/primitives/table/RowActions.js +1 -1
  164. package/dist/primitives/table/Table.d.ts +2 -4
  165. package/dist/primitives/table/Table.js +13 -16
  166. package/dist/primitives/table/cellTone.d.ts +5 -0
  167. package/dist/primitives/table/cellTone.js +13 -0
  168. package/dist/primitives/table/editRules.d.ts +43 -0
  169. package/dist/primitives/table/editRules.js +53 -0
  170. package/dist/primitives/table/index.d.ts +4 -2
  171. package/dist/primitives/table/index.js +4 -2
  172. package/dist/primitives/tag/Count.d.ts +2 -3
  173. package/dist/primitives/tag/Count.js +4 -5
  174. package/dist/primitives/tag/Tags.d.ts +22 -1
  175. package/dist/primitives/tag/Tags.js +57 -14
  176. package/dist/primitives/tag/countText.d.ts +3 -0
  177. package/dist/primitives/tag/countText.js +7 -0
  178. package/dist/primitives/tag/index.d.ts +3 -2
  179. package/dist/primitives/tag/index.js +2 -1
  180. package/dist/primitives/value/DateValue.d.ts +2 -5
  181. package/dist/primitives/value/DateValue.js +6 -44
  182. package/dist/primitives/value/Elapsed.d.ts +16 -0
  183. package/dist/primitives/value/Elapsed.js +37 -0
  184. package/dist/primitives/value/Meter.d.ts +3 -8
  185. package/dist/primitives/value/Meter.js +2 -9
  186. package/dist/primitives/value/RichText.d.ts +2 -4
  187. package/dist/primitives/value/RichText.js +5 -20
  188. package/dist/primitives/value/Value.d.ts +10 -7
  189. package/dist/primitives/value/Value.js +7 -24
  190. package/dist/primitives/value/elapsedTime.d.ts +26 -0
  191. package/dist/primitives/value/elapsedTime.js +32 -0
  192. package/dist/primitives/value/format.d.ts +16 -0
  193. package/dist/primitives/value/format.js +81 -0
  194. package/dist/primitives/value/index.d.ts +9 -4
  195. package/dist/primitives/value/index.js +13 -4
  196. package/dist/primitives/value/meterLevel.d.ts +10 -0
  197. package/dist/primitives/value/meterLevel.js +12 -0
  198. package/dist/primitives/value/richTextPlain.d.ts +4 -0
  199. package/dist/primitives/value/richTextPlain.js +23 -0
  200. package/dist/tokens.css +87 -1
  201. package/dist/views/list/List.d.ts +11 -0
  202. package/dist/views/list/List.js +14 -3
  203. package/dist/views/list/ListView.d.ts +1 -1
  204. package/dist/views/list/ListView.js +26 -6
  205. package/dist/views/list/types.d.ts +7 -0
  206. package/dist/views/record/Record.js +1 -1
  207. package/package.json +1 -1
@@ -0,0 +1,570 @@
1
+ import { fieldLabel } from "./model.js";
2
+ import { isToMany } from "./paths.js";
3
+ import { sayCondition } from "./query.js";
4
+ import { recordsFilter, recordsOf, recordTarget, } from "./records.js";
5
+ import { currentCopy, fillCopy } from "../../foundations/uiCopy.js";
6
+ /* ====================================================================== *
7
+ * THE FILTER AS A TREE — the model `FilterBuilder` draws, without React.
8
+ *
9
+ * What the builder edits (`TreeNode`: groups of conditions, nested), how it goes to the
10
+ * engine's JSON and back (`treeToFilter`, `treeFromFilter`), which records a rule names
11
+ * (`liftRecords`, `namesOf`) and the filter said in one line (`describeFilter`).
12
+ *
13
+ * Context: it lived inside `FilterBuilder.tsx`, which carries `"use client"`, and a React
14
+ * Server Components bundler turns every export of a client module into a client reference:
15
+ * a server component could not say a saved filter in words. Here, without the directive, it
16
+ * is plain logic — the same functions the builder and the tests call. See the long note at
17
+ * the top of `FilterBuilder.tsx` for what the builder is.
18
+ * ====================================================================== */
19
+ /* What an operator is called for whoever reads it: `copy.ops`, which is the SAME table the
20
+ bar uses when building the question. Two tables means the same comparison is called two ways
21
+ on the same screen. */
22
+ /** Which operators take no value: asking whether something is empty needs nothing written. */
23
+ export const WITHOUT_VALUE = new Set(["is null", "is not null"]);
24
+ /** Which operators compare against TWO values. «Entre el 1 y el 31» is the question everybody
25
+ * asks about dates, and writing it as two loose rules is the way to
26
+ * get one of the two ends wrong. */
27
+ export const WITH_RANGE = new Set(["between"]);
28
+ /** The comparisons that take several values. */
29
+ export function takesMany(operator) {
30
+ return operator === "in" || operator === "not in";
31
+ }
32
+ /** What kind of input asks for a value, read from the field's type. */
33
+ export function inputType(type) {
34
+ if (type === "integer" || type === "number")
35
+ return "number";
36
+ if (type === "date")
37
+ return "date";
38
+ if (type === "datetime")
39
+ return "datetime-local";
40
+ return "text";
41
+ }
42
+ function isCondition(value) {
43
+ return (typeof value === "object" &&
44
+ value !== null &&
45
+ !Array.isArray(value) &&
46
+ typeof value.field === "string" &&
47
+ typeof value.operator === "string" &&
48
+ "value" in value);
49
+ }
50
+ /** Whether this is one of the shapes the filter recognises — condition, or `all`/`any`/
51
+ * `negate` group. A valid JSON that is none of these —`{}`, `{"foo": 1}`, a loose array—
52
+ * is not a filter this component knows how to draw, and is treated as a shape error instead of
53
+ * trying to show anything at all. */
54
+ export function isRecognizedFilter(value) {
55
+ if (isCondition(value))
56
+ return true;
57
+ if (typeof value !== "object" || value === null)
58
+ return false;
59
+ const record = value;
60
+ if (Array.isArray(record.all))
61
+ return true;
62
+ if (Array.isArray(record.any))
63
+ return true;
64
+ if ("negate" in record)
65
+ return true;
66
+ if (isThrough(record))
67
+ return true;
68
+ return false;
69
+ }
70
+ export const MATCHES = ["any", "none", "all"];
71
+ function isThrough(value) {
72
+ if (typeof value !== "object" || value === null)
73
+ return false;
74
+ const record = value;
75
+ return typeof record.through === "string" && "selection" in record;
76
+ }
77
+ function isNegate(value) {
78
+ return typeof value === "object" && value !== null && "negate" in value;
79
+ }
80
+ /**
81
+ * A relation crossed, read off criteria's shape: the quantifier is not a key, it is the
82
+ * sentence the `negate`s around the `through` make.
83
+ *
84
+ * {through, selection: s} «alguno» s
85
+ * {negate: {through, selection: s}} «ninguno» s
86
+ * {negate: {through, selection: {negate: s}}} «todos» s (none that does not)
87
+ *
88
+ * «Ninguno con no-s» and «todos con s» are the same filter; it reads as the second, the
89
+ * shorter sentence, and that is also how a path of two hops comes back: «ninguna línea con
90
+ * ningún impuesto» returns as «todas las líneas con algún impuesto», which filters the same.
91
+ * Anything else is not a relation crossed: `null`.
92
+ */
93
+ export function crossedOf(value) {
94
+ if (isThrough(value)) {
95
+ return { through: value.through, match: "any", selection: value.selection };
96
+ }
97
+ if (!isNegate(value) || !isThrough(value.negate))
98
+ return null;
99
+ const { through, selection } = value.negate;
100
+ return isNegate(selection)
101
+ ? { through, match: "all", selection: selection.negate }
102
+ : { through, match: "none", selection };
103
+ }
104
+ /** The other way: a relation and its quantifier, written the way criteria reads them. */
105
+ function crossing(through, match, inner) {
106
+ if (match === "none")
107
+ return { negate: { through, selection: inner } };
108
+ if (match === "all")
109
+ return { negate: { through, selection: { negate: inner } } };
110
+ return { through, selection: inner };
111
+ }
112
+ /** Whether a «some» crossing reaches ONE record: a to-one relation, as the model says. Then
113
+ * it is said as a path («Cliente > País»), since «alguno de» would be noise. Without the
114
+ * model it is said as what `{through, selection}` means — «alguno de» —, never wrong. */
115
+ export function reachesOne(model, crossed) {
116
+ const field = model?.fields[crossed.through];
117
+ return crossed.match === "any" && field !== undefined && !isToMany(field);
118
+ }
119
+ export function blankCondition(model, first) {
120
+ const field = first ?? "";
121
+ return {
122
+ kind: "condition",
123
+ field,
124
+ operator: model.fields[field]?.ops[0] ?? "=",
125
+ value: "",
126
+ };
127
+ }
128
+ export function blankGroup(model, first) {
129
+ return { kind: "group", join: "all", children: [blankCondition(model, first)] };
130
+ }
131
+ /** The tree as the filter that travels.
132
+ *
133
+ * in a lone condition
134
+ * out that condition, unwrapped
135
+ *
136
+ * in group with two children, join «any»
137
+ * out {any: [ … , … ]}
138
+ *
139
+ * A group with a single child is not wrapped —it is that child—, and a group with no children disappears: neither
140
+ * an empty «todas» nor «cualquiera» is a filter anybody asked for. The rule holds at any
141
+ * level, not only at the root, so nesting a single-condition group is the same as not
142
+ * having nested it. */
143
+ export function treeToFilter(node) {
144
+ if (node.kind === "condition") {
145
+ const leaf = conditionToFilter(node);
146
+ return leaf === undefined ? undefined : wrapThrough(node.through ?? [], leaf);
147
+ }
148
+ return groupToFilter(node);
149
+ }
150
+ /** The relations of a path, as nested `through` nodes around the condition: the first hop
151
+ * outside, the last one next to the condition — the order the path reads in. */
152
+ function wrapThrough(hops, leaf) {
153
+ return hops.reduceRight((inner, hop) => crossing(hop.field, hop.match, inner), leaf);
154
+ }
155
+ function conditionToFilter(node) {
156
+ if (node.field === "")
157
+ return undefined;
158
+ /* A rule about records: by key, the way the relation is compared — directly by its column
159
+ (a many2one) or crossing it (a to-many). «Está vacío» asks the column. */
160
+ if (node.target !== undefined) {
161
+ if (WITHOUT_VALUE.has(node.operator)) {
162
+ return node.target.column === undefined
163
+ ? undefined
164
+ : { field: node.target.column, operator: node.operator, value: true };
165
+ }
166
+ const keys = (node.values ?? []).map((one) => one.id);
167
+ if (keys.length === 0)
168
+ return undefined;
169
+ return recordsFilter(node.target, keys, node.operator === "!=" || node.operator === "not in");
170
+ }
171
+ if (WITHOUT_VALUE.has(node.operator)) {
172
+ return { field: node.field, operator: node.operator, value: true };
173
+ }
174
+ if (WITH_RANGE.has(node.operator)) {
175
+ /* A half-written range is not half a range: while one end is missing, the rule does not
176
+ travel. */
177
+ if (node.value === "" || (node.upper ?? "") === "")
178
+ return undefined;
179
+ return { field: node.field, operator: node.operator, value: [node.value, node.upper] };
180
+ }
181
+ /* Chosen values travel as what they are —a list for «está en», the one for «es»—, by key. */
182
+ if (node.values !== undefined && node.values.length > 0) {
183
+ const keys = node.values.map((one) => one.id);
184
+ return {
185
+ field: node.field,
186
+ operator: node.operator,
187
+ value: node.operator === "in" || node.operator === "not in" ? keys : keys[0],
188
+ };
189
+ }
190
+ if (node.raw !== undefined) {
191
+ return { field: node.field, operator: node.operator, value: node.raw };
192
+ }
193
+ /* **A rule with no value does not filter.** It used to travel with `value: ""`, and that is not «not
194
+ written anything yet»: against an `=` it is «the field is the empty string», which empties the list
195
+ while somebody is still typing, and against a `like` it is «contains nothing», which leaves it
196
+ the same. To ask for what is empty there is the «está vacío» operator, which the
197
+ model publishes on the fields that admit it — explicit, and not by omission. */
198
+ if (node.value === "")
199
+ return undefined;
200
+ return { field: node.field, operator: node.operator, value: node.value };
201
+ }
202
+ function groupToFilter(node) {
203
+ const kept = node.children
204
+ .map(treeToFilter)
205
+ .filter((one) => one !== undefined);
206
+ if (kept.length === 0)
207
+ return undefined;
208
+ /* «Ninguna» negates the WHOLE group and not each child on its own: «ni vencida ni
209
+ grande» is `not (vencida or grande)`. And a group of one is not dismantled
210
+ here either —dismantling it would lose the negation—, which is what the bar does. */
211
+ if (node.join === "not") {
212
+ return { negate: kept.length === 1 ? kept[0] : { any: kept } };
213
+ }
214
+ if (kept.length === 1)
215
+ return kept[0];
216
+ return node.join === "any" ? { any: kept } : { all: kept };
217
+ }
218
+ /** A condition back to an editable row: the value goes back to text, which is what an
219
+ * `<input>` shows — and stays as it came (`raw`), so the rule goes back out the same. A list
220
+ * —an `in`'s value— is written separated by commas, and kept as chosen values. */
221
+ function conditionToTree(condition) {
222
+ if (WITH_RANGE.has(condition.operator) && Array.isArray(condition.value)) {
223
+ const [from, to] = condition.value;
224
+ return {
225
+ kind: "condition",
226
+ field: condition.field,
227
+ operator: condition.operator,
228
+ value: String(from ?? ""),
229
+ upper: String(to ?? ""),
230
+ };
231
+ }
232
+ if (WITHOUT_VALUE.has(condition.operator)) {
233
+ return {
234
+ kind: "condition",
235
+ field: condition.field,
236
+ operator: condition.operator,
237
+ value: "",
238
+ };
239
+ }
240
+ const value = condition.value;
241
+ return {
242
+ kind: "condition",
243
+ field: condition.field,
244
+ operator: condition.operator,
245
+ value: Array.isArray(value) ? value.join(",") : String(value ?? ""),
246
+ ...(Array.isArray(value)
247
+ ? { values: value.map((id) => ({ id: id, name: "" })) }
248
+ : value === undefined
249
+ ? {}
250
+ : { raw: value }),
251
+ };
252
+ }
253
+ /** The filter read back into a tree.
254
+ *
255
+ * in {field: "name", operator: "=", value: "labs"}
256
+ * out TreeCondition
257
+ *
258
+ * in {any: [{all: [cond1, cond2]}, cond3]} group inside a group
259
+ * out TreeGroup(any) with a TreeGroup(all) and a condition as children
260
+ *
261
+ * in {negate: {any: [cond1, cond2]}}
262
+ * out TreeGroup(not) with the two conditions as children
263
+ *
264
+ * An `any`'s `negate` opens into the «ninguna» group and does not stay as a group
265
+ * inside another: it is what `treeToFilter` writes back, so there and
266
+ * back give the same. What can NOT be read —an object that is neither a
267
+ * condition nor any of the three shapes— returns `null`, and there the component
268
+ * shows it read-only while still letting you touch it as JSON.
269
+ */
270
+ export function treeFromFilter(filter) {
271
+ if (isCondition(filter))
272
+ return conditionToTree(filter);
273
+ /* A chain of relations ending in ONE condition is one row with its path. A chain that ends
274
+ in a group («alguna línea con impuesto > 10 Y cantidad > 2», both about the SAME line)
275
+ cannot be a row: the tree shows it read-only and the JSON stays the way to edit it.
276
+ Read before `negate`: «ninguna línea con…» is a `negate` around a `through`, and it is
277
+ one row with its quantifier, not a group. */
278
+ const hops = [];
279
+ let node = filter;
280
+ for (let crossed = crossedOf(node); crossed !== null; crossed = crossedOf(node)) {
281
+ hops.push({ field: crossed.through, match: crossed.match });
282
+ node = crossed.selection;
283
+ }
284
+ if (hops.length > 0) {
285
+ return isCondition(node) ? { ...conditionToTree(node), through: hops } : null;
286
+ }
287
+ if (typeof filter !== "object" || filter === null)
288
+ return null;
289
+ const record = filter;
290
+ if ("negate" in record) {
291
+ const inside = record.negate;
292
+ /* An `any`'s `negate` is the negated group's children; anything else
293
+ is a single child. */
294
+ const raws = typeof inside === "object" &&
295
+ inside !== null &&
296
+ Array.isArray(inside.any)
297
+ ? inside.any
298
+ : [inside];
299
+ const children = readChildren(raws);
300
+ return children === null ? null : { kind: "group", join: "not", children };
301
+ }
302
+ const join = Array.isArray(record.all)
303
+ ? "all"
304
+ : Array.isArray(record.any)
305
+ ? "any"
306
+ : null;
307
+ if (join === null)
308
+ return null;
309
+ const children = readChildren(record[join]);
310
+ return children === null ? null : { kind: "group", join, children };
311
+ }
312
+ /** A group's children, or `null` if any cannot be read: half a tree is
313
+ * worse than none, because it draws something that is not what filters. */
314
+ function readChildren(raws) {
315
+ const children = [];
316
+ for (const raw of raws) {
317
+ const child = treeFromFilter(raw);
318
+ if (child === null)
319
+ return null;
320
+ children.push(child);
321
+ }
322
+ return children;
323
+ }
324
+ /** The operators a rule about records offers: one record or several, in or out — and, through
325
+ * a column that admits it, «está vacío». A to-many relation is asked by some of its records
326
+ * or none of them. */
327
+ export function recordOps(target) {
328
+ if (target.many)
329
+ return ["in", "not in"];
330
+ const empty = ["is null", "is not null"].filter((op) => target.column !== undefined && target.ops.includes(op));
331
+ return ["=", "!=", "in", "not in", ...empty];
332
+ }
333
+ /** The keys of a list read back, as chosen values not named yet. */
334
+ function unnamed(keys) {
335
+ return keys.map((id) => ({ id, name: "" }));
336
+ }
337
+ /**
338
+ * The rules about RECORDS of a relation, recognised again in a tree read back.
339
+ *
340
+ * A filter carries keys, never which relation they were chosen from: `customer_id in [7, 9]`
341
+ * is, for the tree, a column compared to two numbers. The model says that `customer_id` is
342
+ * how «Cliente» is compared, so the row is drawn as «Cliente es alguno de [Andrés Pérez,
343
+ * Andrés Gutiérrez]» — the names asked of `searchRecords` by key. The same for a to-many
344
+ * crossed to its key: `{through: "tags", selection: {field: "id", operator: "in", …}}` is
345
+ * «Etiquetas es alguno de …».
346
+ *
347
+ * in {field: "customer_id", operator: "in", value: [7, 9]} (customer_id names Cliente)
348
+ * out {field: "customer", target: Cliente, operator: "in", values: [#7, #9]}
349
+ *
350
+ * Only on the record's own fields: a relation of a related record needs its model, and a row
351
+ * that stays a plain condition still filters the same.
352
+ */
353
+ export function liftRecords(node, model,
354
+ /** The model at the end of a path of relations, when it already arrived: with it, a rule
355
+ * about records past a relation —«Cliente > País es Bolivia»— is recognised too. */
356
+ modelAt) {
357
+ if (node.kind === "group") {
358
+ return {
359
+ ...node,
360
+ children: node.children.map((child) => liftRecords(child, model, modelAt)),
361
+ };
362
+ }
363
+ if (node.target !== undefined)
364
+ return node;
365
+ const hops = node.through ?? [];
366
+ const at = (path) => path.length === 0 ? model : modelAt?.(path.map((hop) => hop.field));
367
+ const keys = () => node.values !== undefined
368
+ ? node.values.map((one) => one.id)
369
+ : typeof node.raw === "string" || typeof node.raw === "number"
370
+ ? [node.raw]
371
+ : [];
372
+ /* A to-one relation compared by its column, in the model the rule's field lives in. */
373
+ const here = at(hops);
374
+ if (here !== undefined) {
375
+ for (const name of Object.keys(here.fields)) {
376
+ const target = recordTarget(here, name);
377
+ if (target === undefined || target.many || target.column !== node.field)
378
+ continue;
379
+ if (!recordOps(target).includes(node.operator))
380
+ return node;
381
+ return {
382
+ kind: "condition",
383
+ ...(hops.length === 0 ? {} : { through: hops }),
384
+ field: name,
385
+ operator: node.operator,
386
+ value: "",
387
+ target,
388
+ ...(WITHOUT_VALUE.has(node.operator) ? {} : { values: unnamed(keys()) }),
389
+ };
390
+ }
391
+ }
392
+ /* A to-many relation crossed to its key: the LAST hop is the relation. */
393
+ const last = hops.at(-1);
394
+ if (last === undefined || last.match === "all")
395
+ return node;
396
+ const before = hops.slice(0, -1);
397
+ const owner = at(before);
398
+ const target = owner === undefined ? undefined : recordTarget(owner, last.field);
399
+ if (target === undefined || !target.many || node.field !== target.key)
400
+ return node;
401
+ if (node.operator !== "in" && node.operator !== "=")
402
+ return node;
403
+ return {
404
+ kind: "condition",
405
+ ...(before.length === 0 ? {} : { through: before }),
406
+ field: last.field,
407
+ operator: last.match === "none" ? "not in" : "in",
408
+ value: "",
409
+ target,
410
+ values: unnamed(keys()),
411
+ };
412
+ }
413
+ /** The names of the records a tree has chosen, by relation and key: what says them in a
414
+ * sentence (`describeFilter`) once the tree is applied. */
415
+ export function namesOf(node) {
416
+ const known = new Map();
417
+ const walk = (one) => {
418
+ if (one.kind === "group")
419
+ return one.children.forEach(walk);
420
+ if (one.target === undefined)
421
+ return;
422
+ for (const value of one.values ?? []) {
423
+ if (value.name !== "")
424
+ known.set(`${one.target.name}\u0000${value.id}`, value.name);
425
+ }
426
+ };
427
+ walk(node);
428
+ return (relation, key) => known.get(`${relation}\u0000${key}`);
429
+ }
430
+ /** The tree with the names that were missing, where they are known. */
431
+ export function withNames(node, names) {
432
+ if (node.kind === "group") {
433
+ return { ...node, children: node.children.map((child) => withNames(child, names)) };
434
+ }
435
+ if (node.target === undefined || node.values === undefined)
436
+ return node;
437
+ const target = node.target;
438
+ return {
439
+ ...node,
440
+ values: node.values.map((one) => one.name !== ""
441
+ ? one
442
+ : { ...one, name: names.get(`${target.name}\u0000${one.id}`) ?? `#${one.id}` }),
443
+ };
444
+ }
445
+ /** The paths whose models a tree needs to recognise its rules about records past a relation:
446
+ * every prefix of the hops of a rule that is not one yet. */
447
+ export function pathsToLift(node) {
448
+ const out = new Map();
449
+ const walk = (one) => {
450
+ if (one.kind === "group")
451
+ return one.children.forEach(walk);
452
+ if (one.target !== undefined)
453
+ return;
454
+ const fields = (one.through ?? []).map((hop) => hop.field);
455
+ for (let end = 1; end <= fields.length; end++) {
456
+ const path = fields.slice(0, end);
457
+ out.set(path.join("."), path);
458
+ }
459
+ };
460
+ walk(node);
461
+ return [...out.values()];
462
+ }
463
+ export function stringifyFilter(filter) {
464
+ return filter === undefined ? "" : JSON.stringify(filter, null, 2);
465
+ }
466
+ /** A condition value, legible: a list is joined with commas, and what has nothing is
467
+ * said in words instead of showing a bare `true`/`undefined`. */
468
+ function describeValue(value, operator) {
469
+ const copy = currentCopy();
470
+ if (Array.isArray(value)) {
471
+ return operator !== undefined && WITH_RANGE.has(operator)
472
+ ? value.join(` ${copy.search.and} `)
473
+ : value.join(", ");
474
+ }
475
+ /* The same two words the table puts in a boolean cell: a `sí` that
476
+ is not the `sí` next door is a second way of saying the same thing. */
477
+ if (typeof value === "boolean")
478
+ return value ? copy.table.yes : copy.table.no;
479
+ return String(value ?? "");
480
+ }
481
+ /** The filter said in one line, for a chip or a label.
482
+ *
483
+ * in {field: "row_count", operator: ">", value: 1000}, with the model
484
+ * out 'filas mayor que 1000'
485
+ *
486
+ * in {all: [cond1, cond2]}
487
+ * out 'el nombre contiene labs y filas mayor que 1000'
488
+ *
489
+ * in {any: [cond1, cond2]}
490
+ * out 'el nombre es a o el nombre es b'
491
+ *
492
+ * Each condition is said by `sayCondition`, which is the same one the bar uses: without
493
+ * that, what is written in the bar and what is built in the dialog read differently even though
494
+ * they filter the same, and nobody knows which of the two phrases is the one in charge.
495
+ *
496
+ * **The model is the one that knows what a field is called.** Without it the raw
497
+ * name remains —`row_count`—, which is the best that can be said without asking
498
+ * anybody.
499
+ *
500
+ * A nested group is enclosed in parentheses, which is what keeps «a y (b o c)» from being
501
+ * read as «(a y b) o c». Past three conditions it is cut: a chip that does not fit in
502
+ * the bar says nothing — that is what opening the builder and seeing it whole is for. */
503
+ export function describeFilter(node, model,
504
+ /** The model at the end of a path of relations, when it already arrived: it names the
505
+ * fields of a `through`. Without it they keep their raw names. */
506
+ modelAt,
507
+ /** The names of the records a filter asks for, by relation and key: «Cliente es Andrés
508
+ * Pérez» instead of «customer_id es 7». The builder hands its own (`namesOf`). */
509
+ names) {
510
+ return say(node, model, 0, [], modelAt, names);
511
+ }
512
+ /** A filter that asks for RECORDS of one of the model's relations, said as such: «Cliente es
513
+ * alguno de Andrés Pérez, Andrés Gutiérrez». `null` when it is not one. */
514
+ function sayRecords(node, model, names) {
515
+ if (model === undefined)
516
+ return null;
517
+ for (const name of Object.keys(model.fields)) {
518
+ const target = recordTarget(model, name);
519
+ if (target === undefined)
520
+ continue;
521
+ const asked = recordsOf(target, node);
522
+ if (asked === null)
523
+ continue;
524
+ const one = asked.keys.length === 1 && !target.many;
525
+ const op = asked.negate ? (one ? "!=" : "not in") : one ? "=" : "in";
526
+ const said = asked.keys.map((key) => names?.(name, key) ?? String(key)).join(", ");
527
+ return sayCondition(fieldLabel(model, name, currentCopy().locale), op, said);
528
+ }
529
+ return null;
530
+ }
531
+ function say(node, model, depth, at, modelAt, names) {
532
+ const copy = currentCopy();
533
+ const records = sayRecords(node, model, names);
534
+ if (records !== null)
535
+ return records;
536
+ const crossed = crossedOf(node);
537
+ if (crossed !== null) {
538
+ /* «alguno de Líneas con alguno de Impuestos con Monto mayor que 10». The quantifier
539
+ is a separate word and not «algún impuesto» because the model publishes the label,
540
+ not its gender or its singular: «algún Impuestos» would be worse than neutral. */
541
+ const relation = model === undefined ? crossed.through : fieldLabel(model, crossed.through, copy.locale);
542
+ const next = [...at, crossed.through];
543
+ const inner = say(crossed.selection, modelAt?.(next), depth + 1, next, modelAt, names);
544
+ const template = reachesOne(model, crossed)
545
+ ? copy.fieldPath.say.one
546
+ : copy.fieldPath.say[crossed.match];
547
+ return fillCopy(template, { relation, inner });
548
+ }
549
+ if ("all" in node || "any" in node) {
550
+ const items = "all" in node ? node.all : node.any;
551
+ const glue = "all" in node ? copy.search.and : copy.search.or;
552
+ const said = items
553
+ .slice(0, 3)
554
+ .map((child) => say(child, model, depth + 1, at, modelAt, names));
555
+ if (items.length > 3) {
556
+ said.push(fillCopy(copy.search.andMore, { count: items.length - 3 }));
557
+ }
558
+ const joined = said.join(` ${glue} `);
559
+ return depth === 0 || said.length === 1 ? joined : `(${joined})`;
560
+ }
561
+ if ("negate" in node) {
562
+ return `${copy.search.notWord} ${say(node.negate, model, depth + 1, at, modelAt, names)}`;
563
+ }
564
+ /* Every `through` was said above; anything still not a condition is not a shape of the
565
+ grammar, and it is shown as it came rather than as a sentence it is not. */
566
+ if (!isCondition(node))
567
+ return JSON.stringify(node);
568
+ const label = model === undefined ? node.field : fieldLabel(model, node.field, copy.locale);
569
+ return sayCondition(label, node.operator, describeValue(node.value, node.operator));
570
+ }
@@ -0,0 +1,8 @@
1
+ /** A JSON laid out, or the same text if it cannot be read yet.
2
+ *
3
+ * in '{"all":[{"field":"a","operator":"=","value":1}]}'
4
+ * out the same, indented by two spaces and one field per line
5
+ *
6
+ * Separated from the editor so it can be tested without drawing anything: it is the only
7
+ * logic the editor has. */
8
+ export declare function formatJson(text: string): string;
@@ -0,0 +1,17 @@
1
+ /* Without `"use client"`, apart from `JsonEditor.tsx` (CodeMirror, in the browser): a server
2
+ component that shows a saved filter's JSON lays it out the same way. */
3
+ /** A JSON laid out, or the same text if it cannot be read yet.
4
+ *
5
+ * in '{"all":[{"field":"a","operator":"=","value":1}]}'
6
+ * out the same, indented by two spaces and one field per line
7
+ *
8
+ * Separated from the editor so it can be tested without drawing anything: it is the only
9
+ * logic the editor has. */
10
+ export function formatJson(text) {
11
+ try {
12
+ return JSON.stringify(JSON.parse(text), null, 2);
13
+ }
14
+ catch {
15
+ return text;
16
+ }
17
+ }
@@ -1,8 +1,10 @@
1
1
  export { type BuiltCondition, type BuiltFilter, type BuiltThrough, type ThroughMatch, } from "./criteria.js";
2
2
  export { type BuiltCriteria, type BuiltGrouping, type BuiltLevel, type BuiltMeasure, type BuiltSort, CriteriaBuilder, } from "./CriteriaBuilder.js";
3
- export { blankGroup, describeFilter, FilterBuilder, liftRecords, namesOf, type RecordNames, recordOps, SelectionTree, type TreeCondition, treeFromFilter, type TreeGroup, type TreeHop, type TreeNode, treeToFilter, } from "./FilterBuilder.js";
3
+ export { FilterBuilder, SelectionTree, } from "./FilterBuilder.js";
4
+ export { blankGroup, describeFilter, liftRecords, namesOf, type RecordNames, recordOps, takesMany, type TreeCondition, treeFromFilter, type TreeGroup, type TreeHop, type TreeNode, treeToFilter, } from "./filterTree.js";
4
5
  export { FieldPath, type FieldPathProps, type FieldPathRule, type PathPick, useFieldPathSteps, useModelCache, } from "./FieldPath.js";
5
- export { formatJson, JsonEditor } from "./JsonEditor.js";
6
+ export { formatJson } from "./formatJson.js";
7
+ export { JsonEditor } from "./JsonEditor.js";
6
8
  export { createModelCache, type FieldPathStep, type FieldPathValue, isRelation, isToMany, type LoadModel, type ModelCache, pathLabel, peekLabels, resolvePath, } from "./paths.js";
7
9
  export { SearchBar, type SearchBarProps, type SearchFacet, } from "./SearchBar.js";
8
10
  export { at, criteriaId, type CriteriaJoin, type CriteriaPath, filterCriteria, filtersOf, type GroupCriteria, groupCriteria, groupsOf, hasNamed, levelsOf, nextJoin, type RecordKey, type RecordOption, removeAt, replaceAt, type SearchCriteria, selectionOf, toggleNamed, withLevels, } from "./criteria.js";
@@ -11,5 +13,5 @@ export { choiceLabel, type FieldDefinition, fieldLabel, filterableNames, isFilte
11
13
  export { answers, choiceValues, conditionCriteria, defaultOp, describeCondition, fieldKey, globToLike, opLabel, type QueryDraft, type QueryField, queryField, queryFields, type QueryKind, type QuerySuggestion, readTyped, sayValues, suggest, type TypedValue, valueFor, valueLabel, valuesCriteria, type ValueShape, valuesSelection, withoutValue, withValue, } from "./query.js";
12
14
  export { SearchProvider, type SearchSettings, useSearchSettings, type ValueEditor, type ValueEditorProps, } from "./context.js";
13
15
  export { type BrowseRecords, type RecordBrowse, type RecordSearch, recordsFilter, recordsOf, type RecordTarget, recordTarget, sameKey, type SearchRecords, } from "./records.js";
14
- export { RuleValue, takesMany } from "./RuleValue.js";
16
+ export { RuleValue } from "./RuleValue.js";
15
17
  export { type DatePeriod, datePeriodGroup, datePeriodOptions, type DateRange, periodId, readPeriodId, recentMonths, recentYears, resolvePeriods, } from "./datePeriods.js";
@@ -1,11 +1,15 @@
1
1
  /* Search with facets, with the cuts built into the field. */
2
2
  export {} from "./criteria.js";
3
3
  export { CriteriaBuilder, } from "./CriteriaBuilder.js";
4
- export { blankGroup, describeFilter, FilterBuilder, liftRecords, namesOf, recordOps, SelectionTree, treeFromFilter, treeToFilter, } from "./FilterBuilder.js";
4
+ export { FilterBuilder, SelectionTree, } from "./FilterBuilder.js";
5
+ /* The builder's model — the tree, the JSON, the filter said in a line — without `"use client"`:
6
+ a server component reads it (`tests/serverBoundary.test.ts`). */
7
+ export { blankGroup, describeFilter, liftRecords, namesOf, recordOps, takesMany, treeFromFilter, treeToFilter, } from "./filterTree.js";
5
8
  /* A field reached through relations: the selector (web-ui draws) and its model (whoever uses it
6
9
  passes `loadModel`). */
7
10
  export { FieldPath, useFieldPathSteps, useModelCache, } from "./FieldPath.js";
8
- export { formatJson, JsonEditor } from "./JsonEditor.js";
11
+ export { formatJson } from "./formatJson.js";
12
+ export { JsonEditor } from "./JsonEditor.js";
9
13
  export { createModelCache, isRelation, isToMany, pathLabel, peekLabels, resolvePath, } from "./paths.js";
10
14
  export { SearchBar, } from "./SearchBar.js";
11
15
  /* WHAT THE BAR HAS SET: instances. A single thing for both kinds
@@ -25,7 +29,7 @@ export { answers, choiceValues, conditionCriteria, defaultOp, describeCondition,
25
29
  its own value controls (`valueEditor`) for the fields it draws its way. */
26
30
  export { SearchProvider, useSearchSettings, } from "./context.js";
27
31
  export { recordsFilter, recordsOf, recordTarget, sameKey, } from "./records.js";
28
- export { RuleValue, takesMany } from "./RuleValue.js";
32
+ export { RuleValue } from "./RuleValue.js";
29
33
  /* The date cut, the way Odoo does it: months, quarters and years that
30
34
  combine. The INTENT is saved and resolved on read. */
31
35
  export { datePeriodGroup, datePeriodOptions, periodId, readPeriodId, recentMonths, recentYears, resolvePeriods, } from "./datePeriods.js";
@@ -1,8 +1,8 @@
1
1
  import { filterCriteria, } from "./criteria.js";
2
2
  import { choiceLabel, fieldLabel, isFilterable, isNumericType, } from "./model.js";
3
3
  import { recordsFilter, recordTarget, sameKey, } from "./records.js";
4
- import { currentCopy, fillCopy } from "../../foundations/copy.js";
5
4
  import { matches as contains } from "../../foundations/match.js";
5
+ import { currentCopy, fillCopy } from "../../foundations/uiCopy.js";
6
6
  /** How a value of a field reads: an enum's word, or the value as it is. */
7
7
  export function valueLabel(field, value) {
8
8
  return field.choiceLabels?.[value] ?? value;