@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
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { fieldLabel, isFilterable, isNumericType, } from "./model.js";
|
|
2
2
|
import { currentCopy, fillCopy } from "../../foundations/copy.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The words that, after the hash sign, open a GROUP instead of naming an
|
|
5
|
+
* attribute.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* They are written as they are thought —`#and`, `#or`, `#not`— and also as they are read in
|
|
8
|
+
* the bar —`#todas`, `#cualquiera`, `#ninguna`—, because they are the same thing said
|
|
9
|
+
* in two ways and forcing only one is forcing people to learn it.
|
|
10
10
|
*/
|
|
11
11
|
const OPENS = {
|
|
12
12
|
and: "all",
|
|
@@ -19,55 +19,55 @@ const OPENS = {
|
|
|
19
19
|
none: "not",
|
|
20
20
|
ninguna: "not",
|
|
21
21
|
};
|
|
22
|
-
/*
|
|
23
|
-
|
|
22
|
+
/* The operators that can be written in front of the value, from longest to
|
|
23
|
+
shortest: if `<` were tried before `<=`, «<=100» would be read as «< =100». */
|
|
24
24
|
const WRITTEN_OPS = ["<=", ">=", "!=", "<", ">", "="];
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* Those that ORDER. Only something that has an order can answer them —a number, a
|
|
27
|
+
* date—, and not because the field does not publish the operator: «mayor que» on a
|
|
28
|
+
* text is an alphabetical comparison nobody ever asked for and that gives results
|
|
29
|
+
* that cannot be explained.
|
|
30
30
|
*/
|
|
31
31
|
const ORDERING = new Set([">", ">=", "<", "<="]);
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* Those that only compare EQUALITY. These do not discriminate by type: anything can be
|
|
34
|
+
* compared against itself, so writing `=` opens the whole list instead of
|
|
35
|
+
* guessing what kind of thing has not been written yet.
|
|
36
36
|
*/
|
|
37
37
|
const EQUALITY = new Set(["=", "!="]);
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
38
|
+
/** Which kinds have an order. An enum does not: its values are words even if
|
|
39
|
+
* they are written with numbers. */
|
|
40
40
|
const ORDERED = new Set(["number", "date"]);
|
|
41
41
|
const NUMBER = /^-?\d+([.,]\d+)?$/;
|
|
42
42
|
const DATE = /^\d{4}-\d{2}(-\d{2})?$/;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* Reads what somebody wrote: the operator it brings in front, the value, and what
|
|
45
|
+
* shape it is.
|
|
46
46
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
47
|
+
* A pattern —`*.csv`, `ventas_*`— is different from a text: it is searched with `like` and
|
|
48
|
+
* the `*` is translated to the engine's wildcard. A loose text is NOT an implicit
|
|
49
|
+
* pattern: whoever writes `test` is asking for what contains «test», and whoever
|
|
50
|
+
* writes `*.csv` is asking for what ENDS in «.csv», which is another question.
|
|
51
51
|
*/
|
|
52
52
|
export function readTyped(text) {
|
|
53
53
|
const clean = text.trim();
|
|
54
54
|
if (clean === "")
|
|
55
55
|
return { value: "", shape: "empty" };
|
|
56
|
-
/* `#`
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
/* `#` is «choose the attribute»: what follows is not a value, it is the name of the
|
|
57
|
+
field to be asked about. It exists because the two intentions are
|
|
58
|
+
written with the same letters —«nombre» can be the field or the text being
|
|
59
|
+
searched— and until now you had to trust the bar to guess which. With
|
|
60
|
+
the hash sign there is nothing to guess. */
|
|
61
61
|
if (clean.startsWith("#")) {
|
|
62
62
|
const rest = clean.slice(1).trim();
|
|
63
63
|
const opens = OPENS[rest.toLowerCase()];
|
|
64
|
-
/* `#and`
|
|
65
|
-
|
|
66
|
-
`and`,
|
|
67
|
-
—
|
|
68
|
-
/*
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
/* `#and` is not an attribute called «and»: it is the order to open a
|
|
65
|
+
group. It is looked at first because a model could have a field called
|
|
66
|
+
`and`, and between the two readings the one somebody wrote on purpose wins
|
|
67
|
+
—nobody types the hash sign to search for the word «or». */
|
|
68
|
+
/* A bare `#` is «choose the attribute» without having started to name it: the shape
|
|
69
|
+
is «empty», as anywhere else. Saying «text» of an empty string is
|
|
70
|
+
lying about what is written. */
|
|
71
71
|
const shape = rest === "" ? "empty" : "text";
|
|
72
72
|
if (opens !== undefined)
|
|
73
73
|
return { value: rest, shape, attribute: true, opens };
|
|
@@ -92,12 +92,12 @@ export function readTyped(text) {
|
|
|
92
92
|
: "text";
|
|
93
93
|
return { ...(written === undefined ? {} : { op: written }), value, shape };
|
|
94
94
|
}
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
95
|
+
/** The pattern, with the wildcard the engine understands. `*` is what people
|
|
96
|
+
* write —and what a terminal writes— and `%` is what a `like` understands. */
|
|
97
97
|
export function globToLike(value) {
|
|
98
98
|
return value.replace(/\*/g, "%");
|
|
99
99
|
}
|
|
100
|
-
/**
|
|
100
|
+
/** What kind of value a field is, read from the type the model publishes. */
|
|
101
101
|
function kindOf(definition) {
|
|
102
102
|
if (definition.kind === "relation")
|
|
103
103
|
return "relation";
|
|
@@ -115,18 +115,18 @@ function kindOf(definition) {
|
|
|
115
115
|
return "text";
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
|
-
*
|
|
118
|
+
* The fields the bar can ask about, taken from the model.
|
|
119
119
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
120
|
+
* A relational enters through the column that IDENTIFIES it and with the relation's
|
|
121
|
+
* label: asking «el cliente se llama Ferretería» is a question about the
|
|
122
|
+
* customer even if inside it compares its name. A relational without `identifiedBy`
|
|
123
|
+
* does not enter: there is nothing to compare against, and offering it would be offering a
|
|
124
|
+
* question that cannot be answered.
|
|
125
125
|
*/
|
|
126
126
|
export function queryFields(model, locale) {
|
|
127
|
-
/*
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
/* The columns that already name a relation are not offered on their own: they are
|
|
128
|
+
the same question with two labels —«proyecto» and «nombre del proyecto»— and the
|
|
129
|
+
one that is understood is the relation's. */
|
|
130
130
|
const naming = new Set(Object.values(model.fields)
|
|
131
131
|
.filter((one) => one.kind === "relation")
|
|
132
132
|
.map((one) => one.identifiedBy)
|
|
@@ -165,25 +165,25 @@ export function queryFields(model, locale) {
|
|
|
165
165
|
return out;
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
|
-
*
|
|
168
|
+
* Whether a field can answer what was written.
|
|
169
169
|
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
170
|
+
* The OPERATOR rules when one was written, because it is what says what kind of
|
|
171
|
+
* question it is:
|
|
172
172
|
*
|
|
173
|
-
* = / !=
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* > >= < <=
|
|
177
|
-
*
|
|
173
|
+
* = / != everything. Anything is compared against itself, so
|
|
174
|
+
* writing `=` opens the whole list instead of guessing what
|
|
175
|
+
* kind a value that has not been written yet is.
|
|
176
|
+
* > >= < <= only what is ORDERED —a number, a date—. «Mayor que» on
|
|
177
|
+
* a text is an alphabetical comparison nobody asked for.
|
|
178
178
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* `*.csv`
|
|
179
|
+
* With no operator written the value's SHAPE rules: `*.csv` is a pattern and only
|
|
180
|
+
* something with letters answers it; `100` only something with numbers. Offering «filas» for
|
|
181
|
+
* `*.csv` is offering a question that gives zero.
|
|
182
182
|
*/
|
|
183
183
|
export function answers(field, typed) {
|
|
184
|
-
/*
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
/* The operator is looked at BEFORE the value, and not after: writing `>` already
|
|
185
|
+
discards the texts even though what to compare against has not been written yet. The other way round,
|
|
186
|
+
the bar offered the five columns until the first digit was typed. */
|
|
187
187
|
if (typed.op !== undefined) {
|
|
188
188
|
if (!field.ops.includes(typed.op))
|
|
189
189
|
return false;
|
|
@@ -202,18 +202,18 @@ export function answers(field, typed) {
|
|
|
202
202
|
case "glob":
|
|
203
203
|
return field.kind === "text" || field.kind === "relation";
|
|
204
204
|
default:
|
|
205
|
-
/*
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
/* A text is answered by what has letters inside, and also an enum: its
|
|
206
|
+
values are words. A number does not —«test» is not a number— and a date
|
|
207
|
+
neither. */
|
|
208
208
|
return field.kind === "text" || field.kind === "relation" || field.kind === "choice";
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
/**
|
|
212
|
-
*
|
|
212
|
+
* Which operator to ask with, when nobody chose one.
|
|
213
213
|
*
|
|
214
|
-
*
|
|
215
|
-
* `like`,
|
|
216
|
-
*
|
|
214
|
+
* The one written wins. Otherwise, the one the shape asks for: a pattern is asked with
|
|
215
|
+
* `like`, a text with `like` if the field accepts it —«contiene» is what whoever
|
|
216
|
+
* writes half a word wants— and everything else with `=`.
|
|
217
217
|
*/
|
|
218
218
|
export function defaultOp(field, typed) {
|
|
219
219
|
if (typed.op !== undefined && field.ops.includes(typed.op))
|
|
@@ -224,29 +224,29 @@ export function defaultOp(field, typed) {
|
|
|
224
224
|
return "like";
|
|
225
225
|
return field.ops.includes("=") ? "=" : (field.ops[0] ?? "=");
|
|
226
226
|
}
|
|
227
|
-
/**
|
|
228
|
-
*
|
|
227
|
+
/** The value as it travels: a pattern is translated to the engine's wildcard, and the rest
|
|
228
|
+
* goes as it was written. */
|
|
229
229
|
export function valueFor(op, typed) {
|
|
230
230
|
return op === "like" && typed.shape === "glob" ? globToLike(typed.value) : typed.value;
|
|
231
231
|
}
|
|
232
|
-
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
232
|
+
/** What an operator is called for whoever reads it. It comes from the copy, so an
|
|
233
|
+
* operator the server adds appears with its symbol until somebody gives it
|
|
234
|
+
* a word — and does not disappear. */
|
|
235
235
|
export function opLabel(op) {
|
|
236
236
|
return currentCopy().ops[op] ?? op;
|
|
237
237
|
}
|
|
238
|
-
/**
|
|
239
|
-
*
|
|
238
|
+
/** Whether the operator takes no value: asking whether something is empty needs nothing
|
|
239
|
+
* to be written. */
|
|
240
240
|
export function withoutValue(op) {
|
|
241
241
|
return op === "is null" || op === "is not null";
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
|
-
*
|
|
244
|
+
* Whether the operator compares against TWO values.
|
|
245
245
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
246
|
+
* The bar writes ONE —it is a line, not a form— so these are not
|
|
247
|
+
* offered here: choosing «está entre» and writing a number builds half a range, which
|
|
248
|
+
* is not a laxer question but one the engine cannot answer. They are
|
|
249
|
+
* asked in the builder, which has both fields.
|
|
250
250
|
*/
|
|
251
251
|
export function withTwoValues(op) {
|
|
252
252
|
return op === "between";
|
|
@@ -258,14 +258,14 @@ function matches(field, text) {
|
|
|
258
258
|
return (field.label.toLowerCase().includes(needle) || field.field.toLowerCase().includes(needle));
|
|
259
259
|
}
|
|
260
260
|
/**
|
|
261
|
-
*
|
|
261
|
+
* What is offered right now.
|
|
262
262
|
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
263
|
+
* It is a single list and not three screens: in the first step the fields
|
|
264
|
+
* named like what was typed coexist —«nombr» → «nombre»— with the whole questions
|
|
265
|
+
* that what was typed already allows building —«test» en el nombre—. Whoever writes a field's
|
|
266
|
+
* name wants to continue that way; whoever writes a value wants to ask it
|
|
267
|
+
* right away. The two intentions are written the same, so both are offered, with the
|
|
268
|
+
* fields first: it is the step that has not decided anything yet.
|
|
269
269
|
*/
|
|
270
270
|
/**
|
|
271
271
|
* Whether the MODEL reads what was typed as a question of its own: an operator written in
|
|
@@ -286,13 +286,13 @@ export function suggest(draft, fields,
|
|
|
286
286
|
/** The set has a literal search (`SearchBar literal`): offer it for free text. */
|
|
287
287
|
options = {}) {
|
|
288
288
|
const typed = readTyped(draft.text);
|
|
289
|
-
/*
|
|
289
|
+
/* Step 3 — the field and the operator are already there: the value is missing. */
|
|
290
290
|
if (draft.field !== undefined && draft.op !== undefined) {
|
|
291
291
|
const field = draft.field;
|
|
292
|
-
/*
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
292
|
+
/* Writing a pattern CHANGES the comparison: «igual a ventas_*» searches for a
|
|
293
|
+
name that ends in an asterisk, which does not exist and nobody meant to ask for.
|
|
294
|
+
It only overrides equality —whoever chose «mayor que» and wrote a `*` is
|
|
295
|
+
writing something else entirely— and only if the field publishes `like`. */
|
|
296
296
|
const op = typed.shape === "glob" && EQUALITY.has(draft.op) && field.ops.includes("like")
|
|
297
297
|
? "like"
|
|
298
298
|
: draft.op;
|
|
@@ -321,17 +321,17 @@ options = {}) {
|
|
|
321
321
|
}
|
|
322
322
|
return ready;
|
|
323
323
|
}
|
|
324
|
-
/*
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
/* Step 2 — the field is already there: ITS operators are offered. The one the shape of what was
|
|
325
|
+
typed asks for goes first, because writing «100» after choosing «filas» is
|
|
326
|
+
almost always «igual a 100». */
|
|
327
327
|
if (draft.field !== undefined) {
|
|
328
328
|
const field = draft.field;
|
|
329
329
|
const first = defaultOp(field, typed);
|
|
330
330
|
const ops = [first, ...field.ops.filter((one) => one !== first)].filter((op) => !withTwoValues(op));
|
|
331
331
|
return ops.map((op) =>
|
|
332
|
-
/*
|
|
333
|
-
|
|
334
|
-
|
|
332
|
+
/* The one that takes NO value is a whole question as soon as it is chosen: sending it
|
|
333
|
+
to the value step left whoever chose «está vacío» typing something that
|
|
334
|
+
means nothing, with an empty list below and Enter doing nothing. */
|
|
335
335
|
withoutValue(op)
|
|
336
336
|
? {
|
|
337
337
|
kind: "condition",
|
|
@@ -344,8 +344,8 @@ options = {}) {
|
|
|
344
344
|
}
|
|
345
345
|
: { kind: "op", id: `op:${op}`, label: opLabel(op), op });
|
|
346
346
|
}
|
|
347
|
-
/* `#and`, `#or`, `#not`:
|
|
348
|
-
|
|
347
|
+
/* `#and`, `#or`, `#not`: what was asked for is to open a group, not to choose a
|
|
348
|
+
field. ONLY THAT is offered — whoever wrote it already knows what they want. */
|
|
349
349
|
if (typed.opens !== undefined) {
|
|
350
350
|
const join = typed.opens;
|
|
351
351
|
return [
|
|
@@ -357,9 +357,9 @@ options = {}) {
|
|
|
357
357
|
},
|
|
358
358
|
];
|
|
359
359
|
}
|
|
360
|
-
/*
|
|
361
|
-
—
|
|
362
|
-
|
|
360
|
+
/* With a bare `#` the ATTRIBUTE is being chosen, so the fields are offered
|
|
361
|
+
—and the three group openers, because they are also asked for with the hash sign and
|
|
362
|
+
hiding them would be having a notation nobody discovers. */
|
|
363
363
|
if (typed.attribute === true) {
|
|
364
364
|
const opening = typed.value === ""
|
|
365
365
|
? ["all", "any", "not"].map((join) => ({
|
|
@@ -382,7 +382,7 @@ options = {}) {
|
|
|
382
382
|
})),
|
|
383
383
|
];
|
|
384
384
|
}
|
|
385
|
-
/*
|
|
385
|
+
/* Step 1 — nothing has been chosen yet. */
|
|
386
386
|
const byName = typed.shape === "empty"
|
|
387
387
|
? []
|
|
388
388
|
: fields
|
|
@@ -408,10 +408,10 @@ options = {}) {
|
|
|
408
408
|
value: valueFor(op, typed),
|
|
409
409
|
};
|
|
410
410
|
});
|
|
411
|
-
/*
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
411
|
+
/* Without a VALUE there is no question to build yet —a question without a value
|
|
412
|
+
is not a question— so fields are offered. But if the operator was already written,
|
|
413
|
+
that alone narrows: `>` keeps those that have an order and drops the texts
|
|
414
|
+
before the first digit is written. */
|
|
415
415
|
if (typed.shape === "empty") {
|
|
416
416
|
return fields
|
|
417
417
|
.filter((field) => answers(field, typed))
|
|
@@ -423,10 +423,10 @@ options = {}) {
|
|
|
423
423
|
field,
|
|
424
424
|
}));
|
|
425
425
|
}
|
|
426
|
-
/*
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
/* A field named like what was typed is not offered twice: if «nombre»
|
|
427
|
+
appears above to continue by it, below it is no longer needed as a
|
|
428
|
+
question already made — unless what was typed is also a reasonable value, which is
|
|
429
|
+
precisely the case of «test». */
|
|
430
430
|
const named = new Set(byName.map((one) => (one.kind === "field" ? one.field.field : "")));
|
|
431
431
|
const byModel = [
|
|
432
432
|
...byName,
|
|
@@ -447,22 +447,22 @@ options = {}) {
|
|
|
447
447
|
return readByModel(typed, byName, fields) ? [...byModel, literal] : [literal, ...byModel];
|
|
448
448
|
}
|
|
449
449
|
/**
|
|
450
|
-
*
|
|
450
|
+
* HOW A CONDITION IS READ, in one place.
|
|
451
451
|
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
452
|
+
* It is used by the bar —for the chip of what somebody just asked— and the
|
|
453
|
+
* builder —for the chip and for the tree of what is already built—. Only
|
|
454
|
+
* one, because the same condition written two ways reads differently on two
|
|
455
|
+
* screens and nobody knows which of the two is the one that filters.
|
|
456
456
|
*
|
|
457
|
-
*
|
|
458
|
-
* `row_count`
|
|
457
|
+
* It takes the label ALREADY resolved and not the field: who knows what
|
|
458
|
+
* `row_count` is called is the model, and this only knows how to build the sentence.
|
|
459
459
|
*/
|
|
460
460
|
export function sayCondition(label, op, value) {
|
|
461
461
|
return withoutValue(op)
|
|
462
462
|
? `${label} ${opLabel(op)}`
|
|
463
463
|
: fillCopy(currentCopy().search.condition, { field: label, op: opLabel(op), value });
|
|
464
464
|
}
|
|
465
|
-
/**
|
|
465
|
+
/** How an already-made question reads, for the chip: «el nombre contiene test». */
|
|
466
466
|
export function describeCondition(field, op, value) {
|
|
467
467
|
return sayCondition(field.label, op, value);
|
|
468
468
|
}
|
|
@@ -5,10 +5,17 @@ menu,
|
|
|
5
5
|
/** The band at the bottom. It goes AFTER the content, not pinned to the
|
|
6
6
|
* floor of the window — pinning left a hole between it and a short view. */
|
|
7
7
|
status,
|
|
8
|
-
/** The module's navigation, on the left of the view: a `NavigationTree
|
|
9
|
-
sidebar
|
|
8
|
+
/** The module's navigation, on the left of the view: a `NavigationTree`, or a `Sidebar`
|
|
9
|
+
* around one when there is no `menu` and the sidebar is the application's chrome. On a
|
|
10
|
+
* phone it opens as a drawer. */
|
|
11
|
+
sidebar,
|
|
12
|
+
/** With a `sidebar` and no `menu`: the bar on top on a PHONE only, where the sidebar is a
|
|
13
|
+
* drawer and something has to open it — a `TopBar` with the product's name, which draws
|
|
14
|
+
* the button first. A bare `TopBar` by default. */
|
|
15
|
+
narrowMenu, children, }: {
|
|
10
16
|
menu?: ReactNode;
|
|
11
17
|
status?: ReactNode;
|
|
12
18
|
sidebar?: ReactNode;
|
|
19
|
+
narrowMenu?: ReactNode;
|
|
13
20
|
children: ReactNode;
|
|
14
21
|
}): import("react").JSX.Element;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { HeaderSlotContext } from "./headerSlot.js";
|
|
4
|
+
import { SidebarDrawerContext } from "./sidebarDrawer.js";
|
|
5
|
+
import { TopBar } from "./TopBar.js";
|
|
6
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
7
|
+
import { HANDHELD_WIDTH } from "../../foundations/layout.js";
|
|
4
8
|
import { stickyTop, useStickyLayer } from "../../foundations/sticky.js";
|
|
5
|
-
import {
|
|
9
|
+
import { IconButton } from "../../primitives/button/Button.js";
|
|
10
|
+
import { X } from "lucide-react";
|
|
11
|
+
import { useEffect, useId, useMemo, useState } from "react";
|
|
12
|
+
import { Dialog as AriaDialog, Modal, ModalOverlay } from "react-aria-components";
|
|
6
13
|
/* ==================================================================== *
|
|
7
14
|
* THE APPLICATION FRAME — the three bands, and nothing between them.
|
|
8
15
|
*
|
|
@@ -52,29 +59,110 @@ import { useState } from "react";
|
|
|
52
59
|
* is left of the window and scrolls on its own, so a long module never takes
|
|
53
60
|
* the page with it. The page still scrolls as a whole — only the view moves.
|
|
54
61
|
* Without a `sidebar` the frame is exactly what it was.
|
|
62
|
+
*
|
|
63
|
+
* ── The sidebar AS the chrome: no `menu` ────────────────────────────
|
|
64
|
+
*
|
|
65
|
+
* ┌──────────┬────────────────────────────────────────────┐
|
|
66
|
+
* │ brand │ view │
|
|
67
|
+
* │ user │ …its own header sticks at the top… │
|
|
68
|
+
* │ sections │ │
|
|
69
|
+
* │ ──────── │ │
|
|
70
|
+
* │ sign out │ │
|
|
71
|
+
* └──────────┴────────────────────────────────────────────┘
|
|
72
|
+
*
|
|
73
|
+
* A back office whose navigation is all in the sidebar has no bar on top: the
|
|
74
|
+
* sidebar is as tall as the window and holds the brand and the user itself
|
|
75
|
+
* (`Sidebar`). A view's header then stays in the view's column — there is no
|
|
76
|
+
* bar for it to hang under, and spanning above the sidebar it would push the
|
|
77
|
+
* brand down from the top-left, which is the brand's place.
|
|
78
|
+
*
|
|
79
|
+
* ── On a phone the sidebar is a drawer ──────────────────────────────
|
|
80
|
+
*
|
|
81
|
+
* Below `sm` a 15 rem column is two thirds of the screen. The sidebar is hidden
|
|
82
|
+
* and the SAME content opens as a drawer from the start edge: from a button the
|
|
83
|
+
* `TopBar` draws first, or — with no `menu` — from the bar the frame draws for
|
|
84
|
+
* the phone alone (`narrowMenu`, a bare `TopBar` by default). Following a link
|
|
85
|
+
* in it closes it: the person went where they were going.
|
|
55
86
|
* ==================================================================== */
|
|
87
|
+
/* Following a link closes the drawer. On the CAPTURE phase: React Aria's links stop the
|
|
88
|
+
click from bubbling, and a keyboard Enter on one reaches here as the click it dispatches. */
|
|
89
|
+
function closeOnLink(close) {
|
|
90
|
+
return (event) => {
|
|
91
|
+
if (event.target.closest("a[href]") !== null)
|
|
92
|
+
close();
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** The sidebar as a drawer, for a phone: modal (the page behind is inert and dimmed, the
|
|
96
|
+
* focus is kept inside and returns to the button), dismissed by the scrim, Escape, its ×
|
|
97
|
+
* or a link followed. */
|
|
98
|
+
function SidebarDrawerPanel({ id, open, onClose, children, }) {
|
|
99
|
+
const copy = useUiCopy();
|
|
100
|
+
return (_jsx(ModalOverlay, { isOpen: open, onOpenChange: (next) => {
|
|
101
|
+
if (!next)
|
|
102
|
+
onClose();
|
|
103
|
+
}, isDismissable: true, className: ({ isEntering, isExiting }) => `fixed inset-0 z-50 bg-scrim/40 transition-opacity duration-(--duration-quick) ease-(--ease-out) sm:hidden ${isEntering || isExiting ? "opacity-0" : ""}`, children: _jsx(Modal, { className: ({ isEntering, isExiting }) => `fixed inset-y-0 start-0 flex w-(--container-drawer) flex-col border-e border-line-strong bg-ground shadow-window outline-0 transition-[translate] duration-(--duration-panel) ease-(--ease-out) ${isEntering || isExiting ? "-translate-x-full rtl:translate-x-full" : ""}`, children: _jsxs(AriaDialog, { id: id, "aria-label": copy.shell.navigation, className: "flex min-h-0 flex-1 flex-col outline-0", children: [_jsx("div", { className: "flex shrink-0 justify-end px-2 pt-2", children: _jsx(IconButton, { icon: X, label: copy.shell.close, onClick: onClose }) }), _jsx("div", { className: "flex min-h-0 flex-1 flex-col overflow-y-auto", onClickCapture: closeOnLink(onClose), children: children })] }) }) }));
|
|
104
|
+
}
|
|
56
105
|
export function AppFrame({
|
|
57
106
|
/** The bar at the top. It stays in view while scrolling. */
|
|
58
107
|
menu,
|
|
59
108
|
/** The band at the bottom. It goes AFTER the content, not pinned to the
|
|
60
109
|
* floor of the window — pinning left a hole between it and a short view. */
|
|
61
110
|
status,
|
|
62
|
-
/** The module's navigation, on the left of the view: a `NavigationTree
|
|
63
|
-
sidebar
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
111
|
+
/** The module's navigation, on the left of the view: a `NavigationTree`, or a `Sidebar`
|
|
112
|
+
* around one when there is no `menu` and the sidebar is the application's chrome. On a
|
|
113
|
+
* phone it opens as a drawer. */
|
|
114
|
+
sidebar,
|
|
115
|
+
/** With a `sidebar` and no `menu`: the bar on top on a PHONE only, where the sidebar is a
|
|
116
|
+
* drawer and something has to open it — a `TopBar` with the product's name, which draws
|
|
117
|
+
* the button first. A bare `TopBar` by default. */
|
|
118
|
+
narrowMenu, children, }) {
|
|
119
|
+
/* The top bar MEASURES what it takes and passes it to what is below: a list's
|
|
120
|
+
bar sticks beneath it, and a table's header beneath the other two. None of the
|
|
121
|
+
three has a fixed height — see `system/sticky.tsx`. */
|
|
67
122
|
const bar = useStickyLayer();
|
|
68
123
|
/* The slot for a view's header (see `headerSlot.ts`): full width, stuck under the
|
|
69
124
|
application bar, and it pushes the stack down for the sidebar and the table header. */
|
|
70
125
|
const [slot, setSlot] = useState(null);
|
|
71
126
|
const head = useStickyLayer();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
127
|
+
const hasSidebar = sidebar !== undefined;
|
|
128
|
+
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
129
|
+
const drawerId = useId();
|
|
130
|
+
const drawer = useMemo(() => hasSidebar
|
|
131
|
+
? {
|
|
132
|
+
isOpen: drawerOpen,
|
|
133
|
+
open: () => setDrawerOpen(true),
|
|
134
|
+
close: () => setDrawerOpen(false),
|
|
135
|
+
id: drawerId,
|
|
136
|
+
}
|
|
137
|
+
: null, [hasSidebar, drawerOpen, drawerId]);
|
|
138
|
+
/* A window widened past the phone while the drawer was open (a tablet turned): the
|
|
139
|
+
sidebar is back beside the view, and a modal drawer left open would keep the page inert
|
|
140
|
+
behind a panel CSS has already hidden. */
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!drawerOpen)
|
|
143
|
+
return;
|
|
144
|
+
const wide = window.matchMedia(`(min-width: ${HANDHELD_WIDTH}px)`);
|
|
145
|
+
const close = () => {
|
|
146
|
+
if (wide.matches)
|
|
147
|
+
setDrawerOpen(false);
|
|
148
|
+
};
|
|
149
|
+
close();
|
|
150
|
+
wide.addEventListener("change", close);
|
|
151
|
+
return () => wide.removeEventListener("change", close);
|
|
152
|
+
}, [drawerOpen]);
|
|
153
|
+
/* With no `menu` the sidebar is the chrome: on a wide screen nothing is on top of it, and
|
|
154
|
+
on a phone a bar appears to open it. */
|
|
155
|
+
const sidebarIsChrome = hasSidebar && menu === undefined;
|
|
156
|
+
const top = sidebarIsChrome ? (narrowMenu ?? _jsx(TopBar, {})) : menu;
|
|
157
|
+
/* The sidebar sits on the ground tone, the content on the paper (surface): the same white
|
|
158
|
+
for both made the navigation read as part of the list bar. On a phone it is hidden: the
|
|
159
|
+
drawer shows it. */
|
|
160
|
+
const aside = sidebar === undefined ? null : (_jsx("aside", { className: "sticky w-(--container-sidebar) shrink-0 self-start overflow-y-auto overscroll-contain border-r border-line bg-ground max-sm:hidden", style: { ...stickyTop, height: "calc(100dvh - var(--sticky-top, 0px))" }, children: sidebar }));
|
|
161
|
+
return (_jsx(SidebarDrawerContext, { value: drawer, children: _jsxs("div", { className: "relative flex min-h-dvh min-w-0 flex-col bg-ground", children: [top === undefined ? null : (
|
|
162
|
+
/* Hidden on a wide screen when it is only the phone's bar: it measures 0 there, so
|
|
163
|
+
nothing below is pushed down by it. */
|
|
164
|
+
_jsx("div", { ref: bar.ref, className: `sticky top-0 z-40 ${sidebarIsChrome ? "sm:hidden" : ""}`, children: top })), sidebar === undefined ? (_jsx("main", { className: "flex min-w-0 flex-1 flex-col", style: bar.below, children: children })) : sidebarIsChrome ? (_jsxs("div", { className: "flex min-w-0 flex-1 items-start", style: bar.below, children: [aside, _jsx("main", { className: "flex min-w-0 flex-1 flex-col self-stretch", children: children })] })) : (_jsx(HeaderSlotContext, { value: slot, children: _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", style: bar.below, children: [_jsx("div", { ref: (node) => {
|
|
165
|
+
head.ref.current = node;
|
|
166
|
+
setSlot(node);
|
|
167
|
+
}, className: "sticky z-30 min-w-0", style: head.self }), _jsxs("div", { className: "flex min-w-0 flex-1 items-start", style: head.below, children: [aside, _jsx("main", { className: "flex min-w-0 flex-1 flex-col self-stretch", children: children })] })] }) })), status, sidebar === undefined ? null : (_jsx(SidebarDrawerPanel, { id: drawerId, open: drawerOpen, onClose: () => setDrawerOpen(false), children: sidebar }))] }) }));
|
|
80
168
|
}
|