@mdbase-dev/ui 0.2.1 → 0.2.2
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 +119 -0
- package/css/controls.css +37 -0
- package/css/date-picker.css +176 -0
- package/css/filter-builder.css +336 -0
- package/css/properties.css +398 -0
- package/dist/AnchoredPopover.d.ts +20 -0
- package/dist/AnchoredPopover.js +100 -0
- package/dist/Combo.d.ts +41 -0
- package/dist/Combo.js +82 -0
- package/dist/DatePicker.d.ts +69 -0
- package/dist/DatePicker.js +317 -0
- package/dist/Menu.d.ts +3 -1
- package/dist/Menu.js +3 -2
- package/dist/QuickCreate.js +1 -16
- package/dist/date-picker-model.d.ts +31 -0
- package/dist/date-picker-model.js +97 -0
- package/dist/filter-builder/AddFilter.d.ts +13 -0
- package/dist/filter-builder/AddFilter.js +295 -0
- package/dist/filter-builder/FilterBuilder.d.ts +36 -0
- package/dist/filter-builder/FilterBuilder.js +225 -0
- package/dist/filter-builder/FilterPill.d.ts +17 -0
- package/dist/filter-builder/FilterPill.js +494 -0
- package/dist/filter-builder/context.d.ts +40 -0
- package/dist/filter-builder/context.js +67 -0
- package/dist/filter-builder/editors.d.ts +31 -0
- package/dist/filter-builder/editors.js +294 -0
- package/dist/filter-builder/filter-ast.d.ts +13 -0
- package/dist/filter-builder/filter-ast.js +382 -0
- package/dist/filter-builder/labels.d.ts +99 -0
- package/dist/filter-builder/labels.js +555 -0
- package/dist/filter-builder/menu.d.ts +21 -0
- package/dist/filter-builder/menu.js +60 -0
- package/dist/filter-builder/operators.d.ts +30 -0
- package/dist/filter-builder/operators.js +192 -0
- package/dist/filter-builder/tree.d.ts +12 -0
- package/dist/filter-builder/tree.js +61 -0
- package/dist/filter-builder/types.d.ts +69 -0
- package/dist/filter-builder/types.js +48 -0
- package/dist/filter-builder.d.ts +13 -0
- package/dist/filter-builder.js +10 -0
- package/dist/glyphs.d.ts +32 -0
- package/dist/glyphs.js +143 -0
- package/dist/locales/de/messages.json +1 -1
- package/dist/locales/en/messages.json +1 -1
- package/dist/locales/es/messages.json +1 -1
- package/dist/locales/fr/messages.json +1 -1
- package/dist/locales/it/messages.json +1 -1
- package/dist/locales/ja/messages.json +1 -1
- package/dist/locales/ko/messages.json +1 -1
- package/dist/locales/pt/messages.json +1 -1
- package/dist/locales/ru/messages.json +1 -1
- package/dist/locales/zh/messages.json +1 -1
- package/dist/popover.d.ts +5 -0
- package/dist/popover.js +15 -0
- package/dist/properties/PropertyList.d.ts +31 -0
- package/dist/properties/PropertyList.js +233 -0
- package/dist/properties/PropertyValue.d.ts +42 -0
- package/dist/properties/PropertyValue.js +304 -0
- package/dist/properties/fields.d.ts +20 -0
- package/dist/properties/fields.js +81 -0
- package/dist/properties/labels.d.ts +29 -0
- package/dist/properties/labels.js +127 -0
- package/dist/properties/model.d.ts +52 -0
- package/dist/properties/model.js +195 -0
- package/dist/properties.d.ts +13 -0
- package/dist/properties.js +9 -0
- package/package.json +25 -2
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { AnchoredPopover } from "../AnchoredPopover.js";
|
|
4
|
+
import { Glyph } from "../glyphs.js";
|
|
5
|
+
import { AddFilter } from "./AddFilter.js";
|
|
6
|
+
import { combinatorHint, describeRule, fieldOf, FX, KIND_ICONS, openPart, useBar, valueText } from "./context.js";
|
|
7
|
+
import { ExprEditor, ValuePanel } from "./editors.js";
|
|
8
|
+
import { isComplete, ruleToExpression, tryExpressionToRule } from "./filter-ast.js";
|
|
9
|
+
import { changeOperator, labelOf, operatorLabel, operatorMenu } from "./operators.js";
|
|
10
|
+
import { FilterMenu } from "./menu.js";
|
|
11
|
+
import { newId, replaceNode } from "./tree.js";
|
|
12
|
+
function SharedTag() {
|
|
13
|
+
const {
|
|
14
|
+
labels
|
|
15
|
+
} = useBar();
|
|
16
|
+
return _jsx("span", {
|
|
17
|
+
className: "mdbase-filter-shared",
|
|
18
|
+
title: labels.sharedHint,
|
|
19
|
+
children: labels.shared
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** Edits shared by every pill: replace, remove, and the options menu (field click or right-click). */
|
|
23
|
+
function actions(bar, tier, node, depth) {
|
|
24
|
+
const {
|
|
25
|
+
labels
|
|
26
|
+
} = bar;
|
|
27
|
+
const key = `${tier}:${node.id}`;
|
|
28
|
+
const name = text => tier === "shared" ? labels.sharedName(text) : text;
|
|
29
|
+
const replace = next => bar.edit(tier, tree => replaceNode(tree, node.id, next));
|
|
30
|
+
const remove = () => {
|
|
31
|
+
replace(null);
|
|
32
|
+
bar.setOpenKey(null);
|
|
33
|
+
bar.focusAdd();
|
|
34
|
+
};
|
|
35
|
+
const locked = node.kind === "rule" && bar.locked.has(node.field);
|
|
36
|
+
const menu = [];
|
|
37
|
+
if (node.kind === "rule" && !locked) {
|
|
38
|
+
menu.push({
|
|
39
|
+
label: labels.editAsExpression,
|
|
40
|
+
icon: FX,
|
|
41
|
+
onSelect: () => {
|
|
42
|
+
replace({
|
|
43
|
+
kind: "expr",
|
|
44
|
+
id: node.id,
|
|
45
|
+
expression: ruleToExpression(node)
|
|
46
|
+
});
|
|
47
|
+
bar.setOpenKey(`${key}:expr`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (node.kind === "expr") {
|
|
52
|
+
const rule = tryExpressionToRule(node.expression, node.id);
|
|
53
|
+
if (rule) menu.push({
|
|
54
|
+
label: labels.convertToPill,
|
|
55
|
+
icon: _jsx(Glyph, {
|
|
56
|
+
name: "convert"
|
|
57
|
+
}),
|
|
58
|
+
onSelect: () => {
|
|
59
|
+
replace(rule);
|
|
60
|
+
bar.setOpenKey(null);
|
|
61
|
+
bar.focusNode(tier, node.id);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (node.kind !== "group" && !locked) {
|
|
66
|
+
menu.push({
|
|
67
|
+
label: labels.wrapInOrGroup,
|
|
68
|
+
icon: _jsx(Glyph, {
|
|
69
|
+
name: "group"
|
|
70
|
+
}),
|
|
71
|
+
onSelect: () => {
|
|
72
|
+
const group = {
|
|
73
|
+
kind: "group",
|
|
74
|
+
id: newId(),
|
|
75
|
+
combinator: "any",
|
|
76
|
+
children: [node]
|
|
77
|
+
};
|
|
78
|
+
replace(group);
|
|
79
|
+
bar.setOpenKey(`${tier}:${group.id}:add`);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (bar.tiered && depth === 0 && !locked) {
|
|
84
|
+
menu.push({
|
|
85
|
+
label: tier === "view" ? labels.moveToShared : labels.moveToView,
|
|
86
|
+
hint: tier === "view" ? labels.moveToSharedHint : undefined,
|
|
87
|
+
icon: _jsx(Glyph, {
|
|
88
|
+
name: "swap"
|
|
89
|
+
}),
|
|
90
|
+
onSelect: () => {
|
|
91
|
+
bar.setOpenKey(null);
|
|
92
|
+
bar.move(tier, node.id);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (!locked) menu.push(...(menu.length ? ["separator"] : []), {
|
|
97
|
+
label: node.kind === "group" ? labels.removeGroup : labels.remove,
|
|
98
|
+
icon: _jsx(Glyph, {
|
|
99
|
+
name: "remove"
|
|
100
|
+
}),
|
|
101
|
+
danger: true,
|
|
102
|
+
onSelect: remove
|
|
103
|
+
});
|
|
104
|
+
const openMenu = event => {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
event.stopPropagation();
|
|
107
|
+
if (menu.length) bar.setOpenKey(`${key}:menu`);
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
key,
|
|
111
|
+
name,
|
|
112
|
+
replace,
|
|
113
|
+
remove,
|
|
114
|
+
locked,
|
|
115
|
+
menu,
|
|
116
|
+
openMenu
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function OptionsMenu({
|
|
120
|
+
open,
|
|
121
|
+
anchor,
|
|
122
|
+
items,
|
|
123
|
+
onClose
|
|
124
|
+
}) {
|
|
125
|
+
const {
|
|
126
|
+
labels
|
|
127
|
+
} = useBar();
|
|
128
|
+
return _jsx(FilterMenu, {
|
|
129
|
+
open: open,
|
|
130
|
+
anchor: anchor,
|
|
131
|
+
label: labels.filterOptions,
|
|
132
|
+
items: items,
|
|
133
|
+
onClose: onClose
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export function RulePill({
|
|
137
|
+
node: rule,
|
|
138
|
+
tier,
|
|
139
|
+
depth
|
|
140
|
+
}) {
|
|
141
|
+
const bar = useBar();
|
|
142
|
+
const {
|
|
143
|
+
labels
|
|
144
|
+
} = bar;
|
|
145
|
+
const {
|
|
146
|
+
key,
|
|
147
|
+
name,
|
|
148
|
+
replace,
|
|
149
|
+
remove,
|
|
150
|
+
locked,
|
|
151
|
+
menu,
|
|
152
|
+
openMenu
|
|
153
|
+
} = actions(bar, tier, rule, depth);
|
|
154
|
+
const part = openPart(bar, key);
|
|
155
|
+
const fieldRef = useRef(null);
|
|
156
|
+
const opRef = useRef(null);
|
|
157
|
+
const valueRef = useRef(null);
|
|
158
|
+
const field = fieldOf(bar.fields, rule);
|
|
159
|
+
const text = valueText(labels, rule);
|
|
160
|
+
const complete = isComplete(rule);
|
|
161
|
+
const toggle = name => bar.setOpenKey(part === name ? null : `${key}:${name}`);
|
|
162
|
+
const close = () => bar.setOpenKey(null);
|
|
163
|
+
const after = ref => {
|
|
164
|
+
ref.current?.focus();
|
|
165
|
+
close();
|
|
166
|
+
};
|
|
167
|
+
const context = rule.valueKind === "context" ? bar.contextVars.find(item => item.expr === rule.value) : undefined;
|
|
168
|
+
return _jsxs("div", {
|
|
169
|
+
className: "mdbase-filter-pill",
|
|
170
|
+
role: "group",
|
|
171
|
+
"aria-label": name(describeRule(labels, rule, bar.fields)),
|
|
172
|
+
"data-key": key,
|
|
173
|
+
"data-shared": tier === "shared" || undefined,
|
|
174
|
+
"data-draft": !complete || undefined,
|
|
175
|
+
onContextMenu: openMenu,
|
|
176
|
+
children: [tier === "shared" && _jsx(SharedTag, {}), _jsxs("span", {
|
|
177
|
+
className: "mdbase-filter-anchor",
|
|
178
|
+
children: [locked ? _jsxs("span", {
|
|
179
|
+
className: "mdbase-filter-seg mdbase-filter-seg-field",
|
|
180
|
+
"data-locked": true,
|
|
181
|
+
title: labels.lockedField(labelOf(field)),
|
|
182
|
+
children: [KIND_ICONS[field.kind], _jsx("span", {
|
|
183
|
+
className: "mdbase-filter-seg-text",
|
|
184
|
+
children: labelOf(field)
|
|
185
|
+
})]
|
|
186
|
+
}) : _jsxs("button", {
|
|
187
|
+
ref: fieldRef,
|
|
188
|
+
type: "button",
|
|
189
|
+
className: "mdbase-filter-seg mdbase-filter-seg-field",
|
|
190
|
+
"aria-haspopup": "menu",
|
|
191
|
+
"aria-expanded": part === "menu",
|
|
192
|
+
title: labels.filterOptions,
|
|
193
|
+
onClick: () => toggle("menu"),
|
|
194
|
+
children: [KIND_ICONS[field.kind], _jsx("span", {
|
|
195
|
+
className: "mdbase-filter-seg-text",
|
|
196
|
+
children: labelOf(field)
|
|
197
|
+
})]
|
|
198
|
+
}), _jsx(OptionsMenu, {
|
|
199
|
+
open: part === "menu",
|
|
200
|
+
anchor: fieldRef,
|
|
201
|
+
items: menu,
|
|
202
|
+
onClose: close
|
|
203
|
+
})]
|
|
204
|
+
}), _jsxs("span", {
|
|
205
|
+
className: "mdbase-filter-anchor",
|
|
206
|
+
children: [_jsx("button", {
|
|
207
|
+
ref: opRef,
|
|
208
|
+
type: "button",
|
|
209
|
+
className: "mdbase-filter-seg mdbase-filter-seg-op",
|
|
210
|
+
"aria-haspopup": "menu",
|
|
211
|
+
"aria-expanded": part === "op",
|
|
212
|
+
title: labels.changeOperator,
|
|
213
|
+
onClick: () => toggle("op"),
|
|
214
|
+
children: operatorLabel(labels, field.kind, rule.op)
|
|
215
|
+
}), _jsx(FilterMenu, {
|
|
216
|
+
open: part === "op",
|
|
217
|
+
anchor: opRef,
|
|
218
|
+
label: labels.operator,
|
|
219
|
+
onClose: close,
|
|
220
|
+
items: operatorMenu(labels, field.kind, rule).map(item => ({
|
|
221
|
+
label: item.label,
|
|
222
|
+
checked: item.op === rule.op,
|
|
223
|
+
onSelect: () => {
|
|
224
|
+
const next = changeOperator(rule, field, item.op);
|
|
225
|
+
replace(next);
|
|
226
|
+
if (isComplete(next)) after(opRef);else bar.setOpenKey(`${key}:value`);
|
|
227
|
+
}
|
|
228
|
+
}))
|
|
229
|
+
})]
|
|
230
|
+
}), text !== null && _jsxs("span", {
|
|
231
|
+
className: "mdbase-filter-anchor",
|
|
232
|
+
children: [_jsx("button", {
|
|
233
|
+
ref: valueRef,
|
|
234
|
+
type: "button",
|
|
235
|
+
className: "mdbase-filter-seg mdbase-filter-seg-value",
|
|
236
|
+
"aria-haspopup": "dialog",
|
|
237
|
+
"aria-expanded": part === "value",
|
|
238
|
+
"aria-label": complete ? undefined : labels.chooseValue,
|
|
239
|
+
"data-context": context || rule.valueKind === "context" ? true : undefined,
|
|
240
|
+
title: context ? `${context.expr}${context.preview !== undefined ? ` · ${context.preview}` : ""}` : describeRule(labels, rule, bar.fields),
|
|
241
|
+
onClick: () => toggle("value"),
|
|
242
|
+
children: _jsx("span", {
|
|
243
|
+
className: "mdbase-filter-seg-text",
|
|
244
|
+
children: text
|
|
245
|
+
})
|
|
246
|
+
}), part === "value" && _jsx(AnchoredPopover, {
|
|
247
|
+
anchor: valueRef,
|
|
248
|
+
label: labels.editValue,
|
|
249
|
+
className: "mdbase-filter-popover mdbase-filter-value-popover",
|
|
250
|
+
onClose: close,
|
|
251
|
+
children: _jsx(ValuePanel, {
|
|
252
|
+
rule: rule,
|
|
253
|
+
field: field,
|
|
254
|
+
contextVars: bar.contextVars,
|
|
255
|
+
commitOnBlur: true,
|
|
256
|
+
action: labels.done,
|
|
257
|
+
onChange: replace,
|
|
258
|
+
onDone: () => after(valueRef)
|
|
259
|
+
})
|
|
260
|
+
})]
|
|
261
|
+
}), !locked && _jsx("button", {
|
|
262
|
+
type: "button",
|
|
263
|
+
className: "mdbase-filter-seg mdbase-filter-seg-remove",
|
|
264
|
+
"aria-label": labels.removeFilter,
|
|
265
|
+
title: labels.removeFilter,
|
|
266
|
+
onClick: remove,
|
|
267
|
+
children: _jsx(Glyph, {
|
|
268
|
+
name: "close",
|
|
269
|
+
size: 12
|
|
270
|
+
})
|
|
271
|
+
})]
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
export function ExprPill({
|
|
275
|
+
node,
|
|
276
|
+
tier,
|
|
277
|
+
depth
|
|
278
|
+
}) {
|
|
279
|
+
const bar = useBar();
|
|
280
|
+
const {
|
|
281
|
+
labels
|
|
282
|
+
} = bar;
|
|
283
|
+
const {
|
|
284
|
+
key,
|
|
285
|
+
name,
|
|
286
|
+
replace,
|
|
287
|
+
remove,
|
|
288
|
+
menu,
|
|
289
|
+
openMenu
|
|
290
|
+
} = actions(bar, tier, node, depth);
|
|
291
|
+
const part = openPart(bar, key);
|
|
292
|
+
const codeRef = useRef(null);
|
|
293
|
+
const close = () => bar.setOpenKey(null);
|
|
294
|
+
const expression = node.expression.trim();
|
|
295
|
+
return _jsxs("div", {
|
|
296
|
+
className: "mdbase-filter-pill is-expression",
|
|
297
|
+
role: "group",
|
|
298
|
+
"aria-label": name(labels.expressionName(expression)),
|
|
299
|
+
"data-key": key,
|
|
300
|
+
"data-shared": tier === "shared" || undefined,
|
|
301
|
+
"data-draft": !expression || undefined,
|
|
302
|
+
onContextMenu: openMenu,
|
|
303
|
+
children: [tier === "shared" && _jsx(SharedTag, {}), _jsxs("span", {
|
|
304
|
+
className: "mdbase-filter-anchor",
|
|
305
|
+
children: [_jsxs("button", {
|
|
306
|
+
ref: codeRef,
|
|
307
|
+
type: "button",
|
|
308
|
+
className: "mdbase-filter-seg mdbase-filter-seg-code",
|
|
309
|
+
"aria-haspopup": "dialog",
|
|
310
|
+
"aria-expanded": part === "expr",
|
|
311
|
+
title: expression || labels.editExpression,
|
|
312
|
+
onClick: () => bar.setOpenKey(part === "expr" ? null : `${key}:expr`),
|
|
313
|
+
children: [FX, _jsx("code", {
|
|
314
|
+
children: expression || labels.expression
|
|
315
|
+
})]
|
|
316
|
+
}), part === "expr" && _jsx(AnchoredPopover, {
|
|
317
|
+
anchor: codeRef,
|
|
318
|
+
label: labels.editExpression,
|
|
319
|
+
className: "mdbase-filter-popover mdbase-filter-expression-popover",
|
|
320
|
+
onClose: close,
|
|
321
|
+
children: _jsx(ExprEditor, {
|
|
322
|
+
expression: node.expression,
|
|
323
|
+
id: node.id,
|
|
324
|
+
commitOnBlur: true,
|
|
325
|
+
onApply: text => {
|
|
326
|
+
replace({
|
|
327
|
+
...node,
|
|
328
|
+
expression: text
|
|
329
|
+
});
|
|
330
|
+
codeRef.current?.focus();
|
|
331
|
+
close();
|
|
332
|
+
},
|
|
333
|
+
onConvert: rule => {
|
|
334
|
+
replace(rule);
|
|
335
|
+
close();
|
|
336
|
+
bar.focusNode(tier, node.id);
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
}), _jsx(OptionsMenu, {
|
|
340
|
+
open: part === "menu",
|
|
341
|
+
anchor: codeRef,
|
|
342
|
+
items: menu,
|
|
343
|
+
onClose: close
|
|
344
|
+
})]
|
|
345
|
+
}), _jsx("button", {
|
|
346
|
+
type: "button",
|
|
347
|
+
className: "mdbase-filter-seg mdbase-filter-seg-remove",
|
|
348
|
+
"aria-label": labels.removeFilter,
|
|
349
|
+
title: labels.removeFilter,
|
|
350
|
+
onClick: remove,
|
|
351
|
+
children: _jsx(Glyph, {
|
|
352
|
+
name: "close",
|
|
353
|
+
size: 12
|
|
354
|
+
})
|
|
355
|
+
})]
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
/** A nested group on the bar: a shaded cluster with its combinator, its own pills, and `+`. */
|
|
359
|
+
export function GroupCluster({
|
|
360
|
+
node: group,
|
|
361
|
+
tier,
|
|
362
|
+
depth,
|
|
363
|
+
root = false
|
|
364
|
+
}) {
|
|
365
|
+
const bar = useBar();
|
|
366
|
+
const {
|
|
367
|
+
labels
|
|
368
|
+
} = bar;
|
|
369
|
+
const {
|
|
370
|
+
key,
|
|
371
|
+
name: tiered,
|
|
372
|
+
replace,
|
|
373
|
+
remove,
|
|
374
|
+
menu,
|
|
375
|
+
openMenu
|
|
376
|
+
} = actions(bar, tier, group, root ? 1 : depth);
|
|
377
|
+
const part = openPart(bar, key);
|
|
378
|
+
const chipRef = useRef(null);
|
|
379
|
+
const addRef = useRef(null);
|
|
380
|
+
const close = () => bar.setOpenKey(null);
|
|
381
|
+
const name = labels[group.combinator];
|
|
382
|
+
return _jsxs("div", {
|
|
383
|
+
className: "mdbase-filter-group",
|
|
384
|
+
role: "group",
|
|
385
|
+
"aria-label": tiered(labels.group(name)),
|
|
386
|
+
"data-key": key,
|
|
387
|
+
"data-depth": depth,
|
|
388
|
+
"data-shared": tier === "shared" || undefined,
|
|
389
|
+
onContextMenu: openMenu,
|
|
390
|
+
children: [tier === "shared" && _jsx(SharedTag, {}), _jsxs("span", {
|
|
391
|
+
className: "mdbase-filter-anchor",
|
|
392
|
+
children: [_jsxs("button", {
|
|
393
|
+
ref: chipRef,
|
|
394
|
+
type: "button",
|
|
395
|
+
className: "mdbase-filter-group-chip",
|
|
396
|
+
"aria-haspopup": "menu",
|
|
397
|
+
"aria-expanded": part === "combinator",
|
|
398
|
+
title: labels.howTheseCombine,
|
|
399
|
+
onClick: () => bar.setOpenKey(part === "combinator" ? null : `${key}:combinator`),
|
|
400
|
+
children: [name, _jsx(Glyph, {
|
|
401
|
+
name: "down",
|
|
402
|
+
size: 11
|
|
403
|
+
})]
|
|
404
|
+
}), _jsx(FilterMenu, {
|
|
405
|
+
open: part === "combinator",
|
|
406
|
+
anchor: chipRef,
|
|
407
|
+
label: labels.match,
|
|
408
|
+
onClose: close,
|
|
409
|
+
items: ["any", "all", "none"].map(combinator => ({
|
|
410
|
+
label: labels[combinator],
|
|
411
|
+
hint: combinatorHint(labels, combinator),
|
|
412
|
+
checked: group.combinator === combinator,
|
|
413
|
+
onSelect: () => {
|
|
414
|
+
replace({
|
|
415
|
+
...group,
|
|
416
|
+
combinator
|
|
417
|
+
});
|
|
418
|
+
chipRef.current?.focus();
|
|
419
|
+
close();
|
|
420
|
+
}
|
|
421
|
+
}))
|
|
422
|
+
}), _jsx(OptionsMenu, {
|
|
423
|
+
open: part === "menu",
|
|
424
|
+
anchor: chipRef,
|
|
425
|
+
items: menu,
|
|
426
|
+
onClose: close
|
|
427
|
+
})]
|
|
428
|
+
}), group.children.map(child => _jsx(FilterNodeView, {
|
|
429
|
+
node: child,
|
|
430
|
+
tier: tier,
|
|
431
|
+
depth: depth + 1
|
|
432
|
+
}, child.id)), _jsxs("span", {
|
|
433
|
+
className: "mdbase-filter-anchor",
|
|
434
|
+
children: [_jsx("button", {
|
|
435
|
+
ref: addRef,
|
|
436
|
+
type: "button",
|
|
437
|
+
className: "mdbase-filter-group-button",
|
|
438
|
+
"aria-label": labels.addFilterToGroup,
|
|
439
|
+
title: labels.addFilterToGroupHint,
|
|
440
|
+
"aria-haspopup": "dialog",
|
|
441
|
+
"aria-expanded": part === "add",
|
|
442
|
+
onClick: () => bar.setOpenKey(part === "add" ? null : `${key}:add`),
|
|
443
|
+
children: _jsx(Glyph, {
|
|
444
|
+
name: "plus",
|
|
445
|
+
size: 12
|
|
446
|
+
})
|
|
447
|
+
}), part === "add" && _jsx(AnchoredPopover, {
|
|
448
|
+
anchor: addRef,
|
|
449
|
+
label: labels.addFilter,
|
|
450
|
+
className: "mdbase-filter-popover mdbase-filter-command",
|
|
451
|
+
onClose: close,
|
|
452
|
+
children: _jsx(AddFilter, {
|
|
453
|
+
tier: tier,
|
|
454
|
+
groupId: group.id,
|
|
455
|
+
onClose: restore => {
|
|
456
|
+
if (restore) addRef.current?.focus();
|
|
457
|
+
close();
|
|
458
|
+
}
|
|
459
|
+
})
|
|
460
|
+
})]
|
|
461
|
+
}), _jsx("button", {
|
|
462
|
+
type: "button",
|
|
463
|
+
className: "mdbase-filter-group-button",
|
|
464
|
+
"aria-label": labels.removeGroup,
|
|
465
|
+
title: labels.removeGroup,
|
|
466
|
+
onClick: remove,
|
|
467
|
+
children: _jsx(Glyph, {
|
|
468
|
+
name: "close",
|
|
469
|
+
size: 12
|
|
470
|
+
})
|
|
471
|
+
})]
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
export function FilterNodeView({
|
|
475
|
+
node,
|
|
476
|
+
tier,
|
|
477
|
+
depth
|
|
478
|
+
}) {
|
|
479
|
+
if (node.kind === "rule") return _jsx(RulePill, {
|
|
480
|
+
node: node,
|
|
481
|
+
tier: tier,
|
|
482
|
+
depth: depth
|
|
483
|
+
});
|
|
484
|
+
if (node.kind === "expr") return _jsx(ExprPill, {
|
|
485
|
+
node: node,
|
|
486
|
+
tier: tier,
|
|
487
|
+
depth: depth
|
|
488
|
+
});
|
|
489
|
+
return _jsx(GroupCluster, {
|
|
490
|
+
node: node,
|
|
491
|
+
tier: tier,
|
|
492
|
+
depth: depth
|
|
493
|
+
});
|
|
494
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { FilterLabels } from "./labels.js";
|
|
3
|
+
import type { FilterCombinator, FilterContextVar, FilterFieldKind, FilterFieldSpec, FilterGroup, FilterRule } from "./types.js";
|
|
4
|
+
export declare const EXPRESSION_EXAMPLE = "amount * 1.1 > 500";
|
|
5
|
+
export declare const FX: import("react").JSX.Element;
|
|
6
|
+
/** `shared` is the `query.where` every view of a file applies; `view` is this view's own `where`. */
|
|
7
|
+
export type Tier = "shared" | "view";
|
|
8
|
+
/** What every pill reads from the bar it sits on. */
|
|
9
|
+
export interface BarContext {
|
|
10
|
+
labels: FilterLabels;
|
|
11
|
+
fields: FilterFieldSpec[];
|
|
12
|
+
contextVars: FilterContextVar[];
|
|
13
|
+
/** Fields the host owns: their rules stay editable but cannot be removed or rewritten, and are not offered for new rules. */
|
|
14
|
+
locked: ReadonlySet<string>;
|
|
15
|
+
/** Whether the shared tier exists, so filters can move between tiers. */
|
|
16
|
+
tiered: boolean;
|
|
17
|
+
trees: Record<Tier, FilterGroup>;
|
|
18
|
+
edit: (tier: Tier, change: (tree: FilterGroup) => FilterGroup) => void;
|
|
19
|
+
/** Moves a top-level node to the other tier. */
|
|
20
|
+
move: (from: Tier, id: string) => void;
|
|
21
|
+
/** The one open popover, as `tier:nodeId:part`. */
|
|
22
|
+
openKey: string | null;
|
|
23
|
+
setOpenKey: (key: string | null) => void;
|
|
24
|
+
/** Returns focus to the bar's add button, after the focused pill went away. */
|
|
25
|
+
focusAdd: () => void;
|
|
26
|
+
/** Focuses the pill for node `id` once it renders (after it was rebuilt under the same id). */
|
|
27
|
+
focusNode: (tier: Tier, id: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare const Bar: import("react").Context<BarContext | null>;
|
|
30
|
+
export declare function useBar(): BarContext;
|
|
31
|
+
/** The part of `key`'s node whose popover is open, if any. */
|
|
32
|
+
export declare function openPart(bar: BarContext, key: string): string | null;
|
|
33
|
+
export declare const KIND_ICONS: Record<FilterFieldKind, ReactNode>;
|
|
34
|
+
export declare const fieldOf: (fields: FilterFieldSpec[], rule: FilterRule) => FilterFieldSpec;
|
|
35
|
+
/** The value segment's text: `Software, Travel` for two values, `3 selected` beyond that. */
|
|
36
|
+
export declare function valueText(labels: FilterLabels, rule: FilterRule): string | null;
|
|
37
|
+
/** A one-line reading of a rule, naming every value. */
|
|
38
|
+
export declare function describeRule(labels: FilterLabels, rule: FilterRule, fields: FilterFieldSpec[]): string;
|
|
39
|
+
/** What each combinator keeps, as a menu hint. */
|
|
40
|
+
export declare const combinatorHint: (labels: FilterLabels, combinator: FilterCombinator) => string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { Glyph } from "../glyphs.js";
|
|
4
|
+
import { inferField, labelOf, MULTI, operatorLabel, UNARY } from "./operators.js";
|
|
5
|
+
// The mark of an expression and an expression to start from: CEL, the same in every language.
|
|
6
|
+
const fx = "fx";
|
|
7
|
+
export const EXPRESSION_EXAMPLE = "amount * 1.1 > 500";
|
|
8
|
+
export const FX = _jsx("span", {
|
|
9
|
+
className: "mdbase-filter-fx",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
children: fx
|
|
12
|
+
});
|
|
13
|
+
export const Bar = createContext(null);
|
|
14
|
+
export function useBar() {
|
|
15
|
+
const bar = useContext(Bar);
|
|
16
|
+
if (!bar) throw new Error("Filter pills must render inside a FilterBuilder");
|
|
17
|
+
return bar;
|
|
18
|
+
}
|
|
19
|
+
/** The part of `key`'s node whose popover is open, if any. */
|
|
20
|
+
export function openPart(bar, key) {
|
|
21
|
+
return bar.openKey?.startsWith(`${key}:`) ? bar.openKey.slice(key.length + 1) : null;
|
|
22
|
+
}
|
|
23
|
+
export const KIND_ICONS = {
|
|
24
|
+
string: _jsx(Glyph, {
|
|
25
|
+
name: "text"
|
|
26
|
+
}),
|
|
27
|
+
number: _jsx(Glyph, {
|
|
28
|
+
name: "number"
|
|
29
|
+
}),
|
|
30
|
+
date: _jsx(Glyph, {
|
|
31
|
+
name: "date"
|
|
32
|
+
}),
|
|
33
|
+
boolean: _jsx(Glyph, {
|
|
34
|
+
name: "boolean"
|
|
35
|
+
}),
|
|
36
|
+
enum: _jsx(Glyph, {
|
|
37
|
+
name: "choice"
|
|
38
|
+
}),
|
|
39
|
+
formula: _jsx(Glyph, {
|
|
40
|
+
name: "formula"
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
export const fieldOf = (fields, rule) => fields.find(field => field.key === rule.field) ?? inferField(rule);
|
|
44
|
+
const show = value => value === "" ? '""' : String(value);
|
|
45
|
+
/** The value segment's text: `Software, Travel` for two values, `3 selected` beyond that. */
|
|
46
|
+
export function valueText(labels, rule) {
|
|
47
|
+
if (UNARY.has(rule.op)) return null;
|
|
48
|
+
if (MULTI.has(rule.op)) {
|
|
49
|
+
const values = rule.values ?? [];
|
|
50
|
+
return values.length > 2 ? labels.selected(values.length) : values.length ? values.map(show).join(", ") : "…";
|
|
51
|
+
}
|
|
52
|
+
return rule.value === undefined ? "…" : show(rule.value);
|
|
53
|
+
}
|
|
54
|
+
/** A one-line reading of a rule, naming every value. */
|
|
55
|
+
export function describeRule(labels, rule, fields) {
|
|
56
|
+
const field = fieldOf(fields, rule);
|
|
57
|
+
const head = `${labelOf(field)} ${operatorLabel(labels, field.kind, rule.op)}`;
|
|
58
|
+
if (UNARY.has(rule.op)) return head;
|
|
59
|
+
const value = MULTI.has(rule.op) ? (rule.values ?? []).map(show).join(", ") || "…" : valueText(labels, rule);
|
|
60
|
+
return `${head} ${value}`;
|
|
61
|
+
}
|
|
62
|
+
/** What each combinator keeps, as a menu hint. */
|
|
63
|
+
export const combinatorHint = (labels, combinator) => ({
|
|
64
|
+
all: labels.everyFilter,
|
|
65
|
+
any: labels.atLeastOne,
|
|
66
|
+
none: labels.noFilter
|
|
67
|
+
})[combinator];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type JSX } from "react";
|
|
2
|
+
import type { FilterContextVar, FilterFieldSpec, FilterRule } from "./types.js";
|
|
3
|
+
export interface ValuePanelProps {
|
|
4
|
+
rule: FilterRule;
|
|
5
|
+
field: FilterFieldSpec;
|
|
6
|
+
contextVars: FilterContextVar[];
|
|
7
|
+
/** Commit a typed value when focus leaves it (editing a pill), rather than only on Enter (adding one). */
|
|
8
|
+
commitOnBlur: boolean;
|
|
9
|
+
onChange: (rule: FilterRule) => void;
|
|
10
|
+
/** The value is chosen: close. */
|
|
11
|
+
onDone: () => void;
|
|
12
|
+
/** What the button that takes a typed value says: "Add filter" when adding one, "Done" when changing one. */
|
|
13
|
+
action: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Picks a rule's value: a checklist for enums and `in` rules (one value is
|
|
17
|
+
* `eq`, several are `in`), True/False for booleans, otherwise a typed literal,
|
|
18
|
+
* plus one-click `this.*` bindings.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ValuePanel({ rule, field, contextVars, commitOnBlur, onChange, onDone, action }: ValuePanelProps): JSX.Element;
|
|
21
|
+
export interface ExprEditorProps {
|
|
22
|
+
expression: string;
|
|
23
|
+
id: string;
|
|
24
|
+
onApply: (expression: string) => void;
|
|
25
|
+
/** Replaces the expression with the visual rule it spells. */
|
|
26
|
+
onConvert: (rule: FilterRule) => void;
|
|
27
|
+
/** Commit the text when focus leaves the editor (editing a pill), rather than only on Apply (adding one). */
|
|
28
|
+
commitOnBlur: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** A CEL editor: Enter applies, Shift+Enter breaks the line. */
|
|
31
|
+
export declare function ExprEditor({ expression, id, onApply, onConvert, commitOnBlur }: ExprEditorProps): JSX.Element;
|