@sincpro/web-ui 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/components/activity/Activity.d.ts +13 -14
- package/dist/components/activity/Activity.js +1 -1
- package/dist/components/activity/Messages.d.ts +5 -5
- package/dist/components/activity/Messages.js +8 -8
- package/dist/components/attachments/Attachments.d.ts +7 -1
- package/dist/components/attachments/Attachments.js +8 -2
- package/dist/components/board/Board.d.ts +32 -2
- package/dist/components/board/Board.js +27 -4
- package/dist/components/board/index.d.ts +1 -1
- package/dist/components/board/index.js +2 -1
- package/dist/components/form/Form.js +6 -6
- package/dist/components/form/index.js +2 -2
- package/dist/components/frame/FrameView.d.ts +5 -5
- package/dist/components/frame/FrameView.js +4 -4
- package/dist/components/listing/GroupingLevels.d.ts +22 -22
- package/dist/components/listing/GroupingLevels.js +9 -9
- package/dist/components/listing/Listing.d.ts +11 -11
- package/dist/components/listing/Listing.js +11 -11
- package/dist/components/listing/ListingBar.js +11 -11
- package/dist/components/listing/Row.d.ts +19 -19
- package/dist/components/listing/Row.js +27 -27
- package/dist/components/listing/SortMenu.d.ts +36 -36
- package/dist/components/listing/SortMenu.js +6 -6
- package/dist/components/listing/grouping.d.ts +16 -16
- package/dist/components/listing/grouping.js +6 -6
- package/dist/components/listing/index.js +1 -1
- package/dist/components/listing/modelColumns.d.ts +25 -25
- package/dist/components/listing/modelColumns.js +24 -24
- package/dist/components/listing/pages.js +4 -4
- package/dist/components/listing/set.d.ts +18 -18
- package/dist/components/navigation/NavigationTree.js +2 -2
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/record/RecordSkeleton.js +7 -7
- package/dist/components/search/CriteriaBuilder.d.ts +22 -22
- package/dist/components/search/CriteriaBuilder.js +31 -31
- package/dist/components/search/CriteriaChips.d.ts +9 -9
- package/dist/components/search/CriteriaChips.js +12 -12
- package/dist/components/search/FilterBuilder.d.ts +67 -67
- package/dist/components/search/FilterBuilder.js +104 -104
- package/dist/components/search/JoinWord.d.ts +1 -1
- package/dist/components/search/JoinWord.js +14 -14
- package/dist/components/search/JsonEditor.d.ts +8 -8
- package/dist/components/search/JsonEditor.js +16 -16
- package/dist/components/search/SearchBar.d.ts +34 -34
- package/dist/components/search/SearchBar.js +140 -117
- package/dist/components/search/criteria.d.ts +61 -61
- package/dist/components/search/criteria.js +39 -39
- package/dist/components/search/datePeriods.d.ts +47 -48
- package/dist/components/search/datePeriods.js +29 -29
- package/dist/components/search/dateRanges.d.ts +27 -27
- package/dist/components/search/dateRanges.js +16 -16
- package/dist/components/search/index.js +13 -13
- package/dist/components/search/model.d.ts +28 -28
- package/dist/components/search/model.js +21 -21
- package/dist/components/search/query.d.ts +71 -71
- package/dist/components/search/query.js +119 -119
- package/dist/components/shell/AppFrame.d.ts +9 -2
- package/dist/components/shell/AppFrame.js +102 -14
- package/dist/components/shell/Sidebar.d.ts +34 -0
- package/dist/components/shell/Sidebar.js +32 -0
- package/dist/components/shell/TopBar.d.ts +2 -0
- package/dist/components/shell/TopBar.js +13 -9
- package/dist/components/shell/index.d.ts +2 -0
- package/dist/components/shell/index.js +5 -1
- package/dist/components/shell/sidebarDrawer.d.ts +26 -0
- package/dist/components/shell/sidebarDrawer.js +22 -0
- package/dist/foundations/calendar.d.ts +27 -27
- package/dist/foundations/calendar.js +72 -72
- package/dist/foundations/chart.d.ts +57 -57
- package/dist/foundations/chart.js +27 -27
- package/dist/foundations/copy.d.ts +109 -94
- package/dist/foundations/copy.es.js +10 -2
- package/dist/foundations/copy.js +10 -2
- package/dist/foundations/grouping.d.ts +175 -175
- package/dist/foundations/grouping.js +0 -0
- package/dist/foundations/index.d.ts +1 -1
- package/dist/foundations/index.js +21 -21
- package/dist/foundations/pivot.d.ts +133 -131
- package/dist/foundations/pivot.js +54 -54
- package/dist/foundations/pivotSheet.d.ts +36 -36
- package/dist/foundations/pivotSheet.js +0 -0
- package/dist/foundations/slots.d.ts +38 -38
- package/dist/foundations/slots.js +18 -18
- package/dist/foundations/sticky.d.ts +28 -28
- package/dist/foundations/sticky.js +59 -59
- package/dist/foundations/xlsx.d.ts +47 -47
- package/dist/foundations/xlsx.js +0 -0
- package/dist/primitives/block/Line.d.ts +4 -4
- package/dist/primitives/block/Line.js +28 -28
- package/dist/primitives/block/index.js +2 -2
- package/dist/primitives/cell/index.js +2 -2
- package/dist/primitives/choice/index.js +3 -3
- package/dist/primitives/date/Calendar.d.ts +7 -1
- package/dist/primitives/date/Calendar.js +13 -3
- package/dist/primitives/date/DatePicker.d.ts +4 -1
- package/dist/primitives/date/DatePicker.js +2 -2
- package/dist/primitives/date/index.js +3 -3
- package/dist/primitives/disclosure/index.js +1 -1
- package/dist/primitives/field/DropZone.d.ts +22 -3
- package/dist/primitives/field/DropZone.js +33 -12
- package/dist/primitives/menu/Menu.d.ts +10 -6
- package/dist/primitives/menu/Menu.js +4 -3
- package/dist/primitives/notice/Callout.d.ts +30 -30
- package/dist/primitives/notice/Callout.js +6 -6
- package/dist/primitives/overlay/index.js +3 -3
- package/dist/primitives/picker/Picker.d.ts +6 -0
- package/dist/primitives/picker/Picker.js +27 -4
- package/dist/primitives/picker/index.js +2 -2
- package/dist/primitives/table/DataTable.d.ts +32 -32
- package/dist/primitives/table/DataTable.js +24 -24
- package/dist/primitives/table/EditableTable.d.ts +10 -10
- package/dist/primitives/table/EditableTable.js +9 -9
- package/dist/primitives/table/ReportTable.js +7 -7
- package/dist/primitives/table/SheetTable.d.ts +13 -13
- package/dist/primitives/table/SheetTable.js +14 -14
- package/dist/primitives/table/Table.js +8 -8
- package/dist/primitives/tabs/Tabs.d.ts +46 -46
- package/dist/primitives/tabs/Tabs.js +4 -30
- package/dist/primitives/tag/Count.d.ts +23 -0
- package/dist/primitives/tag/Count.js +59 -0
- package/dist/primitives/tag/index.d.ts +1 -0
- package/dist/primitives/tag/index.js +5 -2
- package/dist/primitives/toolbar/index.js +1 -1
- package/dist/primitives/value/Copyable.d.ts +22 -22
- package/dist/primitives/value/Copyable.js +9 -9
- package/dist/primitives/value/Metric.d.ts +7 -2
- package/dist/primitives/value/Metric.js +12 -4
- package/dist/tokens.css +164 -57
- package/dist/views/list/List.d.ts +36 -36
- package/dist/views/list/List.js +19 -19
- package/dist/views/list/ListView.js +74 -74
- package/dist/views/list/columns.d.ts +10 -10
- package/dist/views/list/columns.js +10 -10
- package/dist/views/list/derive.d.ts +30 -30
- package/dist/views/list/derive.js +49 -49
- package/dist/views/list/index.js +2 -2
- package/dist/views/list/presentations.js +3 -3
- package/dist/views/list/types.d.ts +109 -109
- package/dist/views/record/Record.d.ts +14 -14
- package/dist/views/record/Record.js +24 -24
- package/dist/views/record/index.js +1 -1
- 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
|
-
*
|
|
15
|
+
* A FILTER SOMEBODY BUILDS, FROM WHAT THE MODEL SAYS IT ACCEPTS.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* JSON
|
|
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
|
-
* **
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
-
* **
|
|
30
|
-
* «todas / cualquiera»
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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
|
-
* **
|
|
35
|
-
*
|
|
36
|
-
* criteria,
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
|
-
/*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/**
|
|
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
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
70
|
-
* `negate
|
|
71
|
-
*
|
|
72
|
-
*
|
|
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;
|
|
@@ -147,18 +147,18 @@ export function blankCondition(model, first) {
|
|
|
147
147
|
export function blankGroup(model, first) {
|
|
148
148
|
return { kind: "group", join: "all", children: [blankCondition(model, first)] };
|
|
149
149
|
}
|
|
150
|
-
/**
|
|
150
|
+
/** The tree as the filter that travels.
|
|
151
151
|
*
|
|
152
|
-
* in
|
|
153
|
-
* out
|
|
152
|
+
* in a lone condition
|
|
153
|
+
* out that condition, unwrapped
|
|
154
154
|
*
|
|
155
|
-
* in
|
|
155
|
+
* in group with two children, join «any»
|
|
156
156
|
* out {any: [ … , … ]}
|
|
157
157
|
*
|
|
158
|
-
*
|
|
159
|
-
* «todas»
|
|
160
|
-
*
|
|
161
|
-
*
|
|
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. */
|
|
162
162
|
export function treeToFilter(node) {
|
|
163
163
|
if (node.kind === "condition") {
|
|
164
164
|
const leaf = conditionToFilter(node);
|
|
@@ -179,17 +179,17 @@ function conditionToFilter(node) {
|
|
|
179
179
|
return { field: node.field, operator: node.operator, value: true };
|
|
180
180
|
}
|
|
181
181
|
if (WITH_RANGE.has(node.operator)) {
|
|
182
|
-
/*
|
|
183
|
-
|
|
182
|
+
/* A half-written range is not half a range: while one end is missing, the rule does not
|
|
183
|
+
travel. */
|
|
184
184
|
if (node.value === "" || (node.upper ?? "") === "")
|
|
185
185
|
return undefined;
|
|
186
186
|
return { field: node.field, operator: node.operator, value: [node.value, node.upper] };
|
|
187
187
|
}
|
|
188
|
-
/* **
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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. */
|
|
193
193
|
if (node.value === "")
|
|
194
194
|
return undefined;
|
|
195
195
|
return { field: node.field, operator: node.operator, value: node.value };
|
|
@@ -201,9 +201,9 @@ function groupToFilter(node) {
|
|
|
201
201
|
.filter((one) => one !== undefined);
|
|
202
202
|
if (kept.length === 0)
|
|
203
203
|
return undefined;
|
|
204
|
-
/* «Ninguna»
|
|
205
|
-
grande»
|
|
206
|
-
|
|
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. */
|
|
207
207
|
if (node.join === "not") {
|
|
208
208
|
return { negate: kept.length === 1 ? kept[0] : { any: kept } };
|
|
209
209
|
}
|
|
@@ -211,8 +211,8 @@ function groupToFilter(node) {
|
|
|
211
211
|
return kept[0];
|
|
212
212
|
return node.join === "any" ? { any: kept } : { all: kept };
|
|
213
213
|
}
|
|
214
|
-
/**
|
|
215
|
-
*
|
|
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. */
|
|
216
216
|
function conditionToTree(condition) {
|
|
217
217
|
if (WITH_RANGE.has(condition.operator) && Array.isArray(condition.value)) {
|
|
218
218
|
const [from, to] = condition.value;
|
|
@@ -235,22 +235,22 @@ function conditionToTree(condition) {
|
|
|
235
235
|
: String(condition.value ?? ""),
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
|
-
/**
|
|
238
|
+
/** The filter read back into a tree.
|
|
239
239
|
*
|
|
240
240
|
* in {field: "name", operator: "=", value: "labs"}
|
|
241
241
|
* out TreeCondition
|
|
242
242
|
*
|
|
243
|
-
* in {any: [{all: [cond1, cond2]}, cond3]}
|
|
244
|
-
* out TreeGroup(any)
|
|
243
|
+
* in {any: [{all: [cond1, cond2]}, cond3]} group inside a group
|
|
244
|
+
* out TreeGroup(any) with a TreeGroup(all) and a condition as children
|
|
245
245
|
*
|
|
246
246
|
* in {negate: {any: [cond1, cond2]}}
|
|
247
|
-
* out TreeGroup(not)
|
|
247
|
+
* out TreeGroup(not) with the two conditions as children
|
|
248
248
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
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.
|
|
254
254
|
*/
|
|
255
255
|
export function treeFromFilter(filter) {
|
|
256
256
|
if (isCondition(filter))
|
|
@@ -274,8 +274,8 @@ export function treeFromFilter(filter) {
|
|
|
274
274
|
const record = filter;
|
|
275
275
|
if ("negate" in record) {
|
|
276
276
|
const inside = record.negate;
|
|
277
|
-
/*
|
|
278
|
-
|
|
277
|
+
/* An `any`'s `negate` is the negated group's children; anything else
|
|
278
|
+
is a single child. */
|
|
279
279
|
const raws = typeof inside === "object" &&
|
|
280
280
|
inside !== null &&
|
|
281
281
|
Array.isArray(inside.any)
|
|
@@ -294,8 +294,8 @@ export function treeFromFilter(filter) {
|
|
|
294
294
|
const children = readChildren(record[join]);
|
|
295
295
|
return children === null ? null : { kind: "group", join, children };
|
|
296
296
|
}
|
|
297
|
-
/**
|
|
298
|
-
*
|
|
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. */
|
|
299
299
|
function readChildren(raws) {
|
|
300
300
|
const children = [];
|
|
301
301
|
for (const raw of raws) {
|
|
@@ -309,8 +309,8 @@ function readChildren(raws) {
|
|
|
309
309
|
function stringifyFilter(filter) {
|
|
310
310
|
return filter === undefined ? "" : JSON.stringify(filter, null, 2);
|
|
311
311
|
}
|
|
312
|
-
/**
|
|
313
|
-
*
|
|
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`. */
|
|
314
314
|
function describeValue(value, operator) {
|
|
315
315
|
const copy = currentCopy();
|
|
316
316
|
if (Array.isArray(value)) {
|
|
@@ -318,15 +318,15 @@ function describeValue(value, operator) {
|
|
|
318
318
|
? value.join(` ${copy.search.and} `)
|
|
319
319
|
: value.join(", ");
|
|
320
320
|
}
|
|
321
|
-
/*
|
|
322
|
-
|
|
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. */
|
|
323
323
|
if (typeof value === "boolean")
|
|
324
324
|
return value ? copy.table.yes : copy.table.no;
|
|
325
325
|
return String(value ?? "");
|
|
326
326
|
}
|
|
327
|
-
/**
|
|
327
|
+
/** The filter said in one line, for a chip or a label.
|
|
328
328
|
*
|
|
329
|
-
* in {field: "row_count", operator: ">", value: 1000},
|
|
329
|
+
* in {field: "row_count", operator: ">", value: 1000}, with the model
|
|
330
330
|
* out 'filas mayor que 1000'
|
|
331
331
|
*
|
|
332
332
|
* in {all: [cond1, cond2]}
|
|
@@ -335,17 +335,17 @@ function describeValue(value, operator) {
|
|
|
335
335
|
* in {any: [cond1, cond2]}
|
|
336
336
|
* out 'el nombre es a o el nombre es b'
|
|
337
337
|
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
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.
|
|
341
341
|
*
|
|
342
|
-
* **
|
|
343
|
-
*
|
|
344
|
-
*
|
|
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.
|
|
345
345
|
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
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. */
|
|
349
349
|
export function describeFilter(node, model,
|
|
350
350
|
/** The model at the end of a path of relations, when it already arrived: it names the
|
|
351
351
|
* fields of a `through`. Without it they keep their raw names. */
|
|
@@ -387,11 +387,11 @@ function say(node, model, depth, at, modelAt) {
|
|
|
387
387
|
const label = model === undefined ? node.field : fieldLabel(model, node.field, copy.locale);
|
|
388
388
|
return sayCondition(label, node.operator, describeValue(node.value, node.operator));
|
|
389
389
|
}
|
|
390
|
-
/**
|
|
391
|
-
*
|
|
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.
|
|
392
392
|
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
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. */
|
|
395
395
|
export function ExpressionView({ node, model, depth = 0, modelAt, at = [], }) {
|
|
396
396
|
const surface = useSurface();
|
|
397
397
|
const copy = useUiCopy();
|
|
@@ -407,9 +407,9 @@ export function ExpressionView({ node, model, depth = 0, modelAt, at = [], }) {
|
|
|
407
407
|
: `${copy.fieldPath.match[crossed.match]} · ${relation}` }), _jsx(ExpressionView, { node: crossed.selection, ...(inner === undefined ? {} : { model: inner }), ...(modelAt === undefined ? {} : { modelAt }), at: next, depth: depth + 1 })] }));
|
|
408
408
|
}
|
|
409
409
|
if ("all" in node || "any" in node) {
|
|
410
|
-
/*
|
|
411
|
-
con alguna»
|
|
412
|
-
|
|
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. */
|
|
413
413
|
const label = "all" in node ? copy.search.joins.all : copy.search.joins.any;
|
|
414
414
|
const items = "all" in node ? node.all : node.any;
|
|
415
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)))] }));
|
|
@@ -417,11 +417,11 @@ export function ExpressionView({ node, model, depth = 0, modelAt, at = [], }) {
|
|
|
417
417
|
if ("negate" in node) {
|
|
418
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 })] }));
|
|
419
419
|
}
|
|
420
|
-
/*
|
|
420
|
+
/* And the same phrase as the chip: a condition reads the same wherever it is. */
|
|
421
421
|
return _jsx("p", { className: `text-meta ${indent}`, children: describeFilter(node, model) });
|
|
422
422
|
}
|
|
423
423
|
/* ---------------------------------------------------------------------- *
|
|
424
|
-
*
|
|
424
|
+
* A GROUP, DRAWN — the piece that calls itself to nest.
|
|
425
425
|
* ---------------------------------------------------------------------- */
|
|
426
426
|
export function SelectionTree({ model, group, onChange, depth = 0, focus, loadModel, models: shared, }) {
|
|
427
427
|
const names = filterableNames(model);
|
|
@@ -463,16 +463,16 @@ export function SelectionTree({ model, group, onChange, depth = 0, focus, loadMo
|
|
|
463
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)))] }));
|
|
464
464
|
}
|
|
465
465
|
/* ---------------------------------------------------------------------- *
|
|
466
|
-
*
|
|
466
|
+
* A RULE — the path to the field, how many of each relation, the operator and the value.
|
|
467
467
|
* ---------------------------------------------------------------------- */
|
|
468
468
|
function ConditionRow({ model, models, child, box, focused, onChange, actions, }) {
|
|
469
469
|
const copy = useUiCopy();
|
|
470
470
|
const hops = child.through ?? [];
|
|
471
471
|
const path = child.field === "" ? [] : [...hops.map((hop) => hop.field), child.field];
|
|
472
472
|
const steps = useFieldPathSteps(models, path);
|
|
473
|
-
/*
|
|
474
|
-
|
|
475
|
-
|
|
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. */
|
|
476
476
|
const leaf = steps?.at(-1)?.field ?? (hops.length === 0 ? model.fields[child.field] : undefined);
|
|
477
477
|
const ops = leaf?.ops ?? [];
|
|
478
478
|
const type = leaf?.type ?? "text";
|
|
@@ -482,7 +482,7 @@ function ConditionRow({ model, models, child, box, focused, onChange, actions, }
|
|
|
482
482
|
return;
|
|
483
483
|
const nextHops = found.slice(0, -1).map((step, at) => ({
|
|
484
484
|
field: step.name,
|
|
485
|
-
/*
|
|
485
|
+
/* Changing the final field does not reset the chip of a relation that remains in the path. */
|
|
486
486
|
match: hops[at]?.field === step.name ? hops[at].match : "any",
|
|
487
487
|
}));
|
|
488
488
|
onChange({
|
|
@@ -501,8 +501,8 @@ function ConditionRow({ model, models, child, box, focused, onChange, actions, }
|
|
|
501
501
|
});
|
|
502
502
|
}
|
|
503
503
|
return (_jsxs("div", {
|
|
504
|
-
/*
|
|
505
|
-
|
|
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
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
507
|
const step = steps?.[at];
|
|
508
508
|
const many = step !== undefined && isToMany(step.field);
|
|
@@ -524,18 +524,18 @@ export function FilterBuilder({ model, initial, onApply, onCancel, loadModel, mo
|
|
|
524
524
|
const [lockedView, setLockedView] = useState(initial !== undefined && decomposed === null ? initial : null);
|
|
525
525
|
const [rawText, setRawText] = useState(() => stringifyFilter(initial ?? treeToFilter(tree)));
|
|
526
526
|
const [rawError, setRawError] = useState(null);
|
|
527
|
-
/*
|
|
528
|
-
|
|
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. */
|
|
529
529
|
function updateTree(next) {
|
|
530
530
|
setTree(next);
|
|
531
531
|
setLockedView(null);
|
|
532
532
|
setRawText(stringifyFilter(treeToFilter(next)));
|
|
533
533
|
setRawError(null);
|
|
534
534
|
}
|
|
535
|
-
/*
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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. */
|
|
539
539
|
function updateRaw(text) {
|
|
540
540
|
setRawText(text);
|
|
541
541
|
if (text.trim() === "") {
|
|
@@ -2,7 +2,7 @@ import type { CriteriaJoin } from "./criteria.js";
|
|
|
2
2
|
import type { Surface } from "../../foundations/types.js";
|
|
3
3
|
export declare function JoinWord({ join, onChange, surface, }: {
|
|
4
4
|
join: CriteriaJoin;
|
|
5
|
-
/**
|
|
5
|
+
/** Without this the word is a value: it says how it joins, and is not touched. */
|
|
6
6
|
onChange?: (next: CriteriaJoin) => void;
|
|
7
7
|
surface?: Surface;
|
|
8
8
|
}): import("react").JSX.Element;
|
|
@@ -5,26 +5,26 @@ import { bySurface, useSurface } from "../../foundations/surface.js";
|
|
|
5
5
|
import { Tags } from "../../primitives/tag/Tags.js";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
/* ==================================================================== *
|
|
8
|
-
*
|
|
8
|
+
* HOW A NODE IS JOINED, in a word you touch.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* All, any, none. They are three and not two: without «ninguna», negating something
|
|
11
|
+
* could only be written in the JSON, and a question the editor does not know how to
|
|
12
|
+
* build is a question most people will not ask.
|
|
13
13
|
*
|
|
14
|
-
* ──
|
|
14
|
+
* ── A word, not a symbol ────────────────────────────────────────────
|
|
15
15
|
*
|
|
16
|
-
* «Y»
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* «Y» and «O» belong to whoever writes queries; «todas» and «cualquiera» belong to whoever
|
|
17
|
+
* searches. And they are the copy's, so changing them changes them on both sides
|
|
18
|
+
* at once.
|
|
19
19
|
*
|
|
20
|
-
* ──
|
|
20
|
+
* ── It opens into its options, it does not rotate ──────────────────────
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* With three, a toggling button says neither which there are nor which is set: you
|
|
23
|
+
* have to press it to find out, and finding out changes what it filters.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
* `<select>`
|
|
27
|
-
*
|
|
25
|
+
* It lives here and not inside the bar because the builder asks the same. A
|
|
26
|
+
* `<select>` there and a list here are two controls for one decision, and whoever
|
|
27
|
+
* learned one does not recognise the other.
|
|
28
28
|
* ==================================================================== */
|
|
29
29
|
const OPTIONS = ["all", "any", "not"];
|
|
30
30
|
export function JoinWord({ join, onChange, surface, }) {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** A JSON laid out, or the same text if it cannot be read yet.
|
|
2
2
|
*
|
|
3
3
|
* in '{"all":[{"field":"a","operator":"=","value":1}]}'
|
|
4
|
-
* out
|
|
4
|
+
* out the same, indented by two spaces and one field per line
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Separated from the component so it can be tested without drawing anything, which is the only thing
|
|
7
|
+
* with logic in here. */
|
|
8
8
|
export declare function formatJson(text: string): string;
|
|
9
9
|
export declare function JsonEditor({ value, onChange, error, height, label, }: {
|
|
10
10
|
value: string;
|
|
11
11
|
onChange: (next: string) => void;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
12
|
+
/** What is wrong with what was written beyond the syntax — that it is valid JSON but not a
|
|
13
|
+
* filter, for example. Syntax errors are marked by the editor, at their exact place. */
|
|
14
14
|
error?: string | null;
|
|
15
15
|
height?: string;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
16
|
+
/** What this editor is called. Without this it says only that it is a code editor,
|
|
17
|
+
* which is the only thing that can be said without knowing what is written inside. */
|
|
18
18
|
label?: string;
|
|
19
19
|
}): import("react").JSX.Element;
|
|
@@ -10,26 +10,26 @@ import CodeMirror, { EditorView, Prec } from "@uiw/react-codemirror";
|
|
|
10
10
|
import { Wand2 } from "lucide-react";
|
|
11
11
|
import { useId } from "react";
|
|
12
12
|
/* ====================================================================== *
|
|
13
|
-
*
|
|
13
|
+
* A JSON WRITTEN BY HAND, IN A REAL EDITOR.
|
|
14
14
|
*
|
|
15
|
-
* CodeMirror
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* CodeMirror and not a `<textarea>` with colours on top: the latter got as far
|
|
16
|
+
* as fifty lines go —painting the quotes— and fell short on
|
|
17
|
+
* everything else, which is what makes writing a filter by hand usable:
|
|
18
|
+
* line numbers to know where the error is, folding so you do not get lost
|
|
19
|
+
* in an `all` of six conditions, and the underline on the exact character
|
|
20
|
+
* where the JSON breaks instead of a sign saying something is wrong.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* The `linter` below is the JSON package's own: it marks the error
|
|
23
|
+
* as you type. The outer notice —`error`— still exists because it
|
|
24
|
+
* says something else: that the JSON is well written but is not a filter.
|
|
25
25
|
* ====================================================================== */
|
|
26
|
-
/**
|
|
26
|
+
/** A JSON laid out, or the same text if it cannot be read yet.
|
|
27
27
|
*
|
|
28
28
|
* in '{"all":[{"field":"a","operator":"=","value":1}]}'
|
|
29
|
-
* out
|
|
29
|
+
* out the same, indented by two spaces and one field per line
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Separated from the component so it can be tested without drawing anything, which is the only thing
|
|
32
|
+
* with logic in here. */
|
|
33
33
|
export function formatJson(text) {
|
|
34
34
|
try {
|
|
35
35
|
return JSON.stringify(JSON.parse(text), null, 2);
|
|
@@ -77,8 +77,8 @@ export function JsonEditor({ value, onChange, error, height = "16rem", label, })
|
|
|
77
77
|
foldGutter: true,
|
|
78
78
|
highlightActiveLine: true,
|
|
79
79
|
autocompletion: false,
|
|
80
|
-
/*
|
|
81
|
-
|
|
80
|
+
/* Highlighting the pair of braces is what makes a nested filter legible: without it,
|
|
81
|
+
in an `any` inside an `all` you have to count brackets with your finger. */
|
|
82
82
|
bracketMatching: true,
|
|
83
83
|
closeBrackets: true,
|
|
84
84
|
} }) }), error == null ? null : _jsx("p", { className: "text-micro text-danger", children: error })] }));
|