@viewkitjs/views 0.4.0 → 0.5.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/CHANGELOG.md +148 -0
- package/README.md +3 -3
- package/dist/atoms/DrillRows.d.ts +3 -0
- package/dist/atoms/DrillRows.js +25 -0
- package/dist/atoms/PanelRows.d.ts +5 -0
- package/dist/atoms/PanelRows.js +40 -0
- package/dist/atoms/PanelSearch.d.ts +2 -0
- package/dist/atoms/PanelSearch.js +21 -0
- package/dist/atoms/SelectionSheet.d.ts +3 -0
- package/dist/atoms/SelectionSheet.js +30 -0
- package/dist/atoms/defaults.js +12 -0
- package/dist/atoms/types.d.ts +117 -1
- package/dist/contract.d.ts +170 -9
- package/dist/contract.js +179 -2
- package/dist/figures.d.ts +5 -48
- package/dist/figures.js +1 -63
- package/dist/grid/chrome/GridColumnMenu.d.ts +3 -3
- package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
- package/dist/grid/chrome/GridGroupMenu.d.ts +2 -2
- package/dist/grid/chrome/GridTable.js +1 -1
- package/dist/grid/useGridTablePrefs.d.ts +1 -1
- package/dist/grouping/sort-groups.d.ts +6 -7
- package/dist/model/aggregates.d.ts +3 -3
- package/dist/model/aggregates.js +17 -71
- package/dist/model/column-order.d.ts +2 -2
- package/dist/model/column-schema.d.ts +6 -7
- package/dist/model/column-state.d.ts +3 -20
- package/dist/model/column-state.js +1 -4
- package/dist/model/column-types.d.ts +1 -15
- package/dist/model/column-types.js +1 -1
- package/dist/model/part-columns.d.ts +1 -6
- package/dist/model/part-columns.js +1 -1
- package/dist/model/part-rows.d.ts +2 -9
- package/dist/model/part-rows.js +1 -10
- package/dist/model/preferences.d.ts +3 -23
- package/dist/model/preferences.js +1 -17
- package/dist/model/prefs-buckets.d.ts +0 -27
- package/dist/model/prefs-buckets.js +1 -1
- package/dist/model/relation-filters.d.ts +0 -1
- package/dist/model/relation-filters.js +1 -1
- package/dist/model/row-icon.d.ts +5 -9
- package/dist/model/view-rules.d.ts +32 -6
- package/dist/model/view-rules.js +94 -22
- package/dist/provider/ViewsProvider.d.ts +6 -2
- package/dist/provider/ViewsProvider.js +3 -2
- package/dist/provider/components.d.ts +16 -0
- package/dist/provider/context.d.ts +3 -1
- package/dist/provider/desktop.d.ts +3 -0
- package/dist/provider/desktop.js +7 -4
- package/dist/react.d.ts +2 -2
- package/dist/selection/SelectionBar.d.ts +18 -0
- package/dist/selection/SelectionBar.js +92 -0
- package/dist/selection/SelectionBarPhone.d.ts +3 -0
- package/dist/selection/SelectionBarPhone.js +14 -0
- package/dist/selection/bar-overflow.d.ts +12 -0
- package/dist/selection/bar-overflow.js +42 -0
- package/dist/selection/bar-parts.d.ts +15 -0
- package/dist/selection/bar-parts.js +17 -0
- package/dist/selection/index.d.ts +2 -0
- package/dist/selection/index.js +1 -0
- package/dist/selection/types.d.ts +3 -2
- package/dist/selection/verbs.d.ts +34 -0
- package/dist/selection/verbs.js +1 -0
- package/docs/contract.md +62 -8
- package/docs/getting-started.md +1 -1
- package/docs/guides/atoms.md +2 -1
- package/docs/guides/selection.md +32 -20
- package/docs/guides/the-grid.md +3 -2
- package/docs/guides/the-provider.md +4 -2
- package/docs/index.md +2 -0
- package/docs/install.md +4 -1
- package/docs/reference/grid.md +2 -2
- package/docs/reference/react.md +13 -3
- package/docs/reference/selection.md +10 -2
- package/docs/reference/views.md +25 -27
- package/package.json +22 -3
- package/skills/views/SKILL.md +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FieldType } from "@viewkitjs/fields";
|
|
2
|
-
import { type FilterRelationRule, type FilterRule, type FilterTree, type ViewFieldReader } from "@viewkitjs/fields/query";
|
|
2
|
+
import { type FilterNode, type FilterRelationRule, type FilterRule, type FilterTree, type ViewFieldReader } from "@viewkitjs/fields/query";
|
|
3
3
|
import type { ListColumn } from "./column-schema.js";
|
|
4
4
|
import type { ListFilterRule, ListFilterRuleState } from "./preferences.js";
|
|
5
5
|
/** THE KEY A COLUMN IS KNOWN BY OFF THE GRID — its FIELD, when it has one, and
|
|
@@ -29,15 +29,41 @@ opts?: {
|
|
|
29
29
|
export declare function rootRulesByColumn<Row>(tree: FilterTree, columns: ListColumn<Row>[], opts?: {
|
|
30
30
|
parts?: boolean;
|
|
31
31
|
}): ListFilterRuleState;
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/** A filter tree as a panel edits it. */
|
|
33
|
+
export type FilterPanelState = {
|
|
34
|
+
/** How the root's items combine. */
|
|
35
|
+
op: FilterTree["op"];
|
|
36
|
+
/** One rule per row: a column's whole value under its id; with `parts`, a part row's under its part key. */
|
|
37
|
+
rules: ListFilterRuleState;
|
|
38
|
+
/** Every root item no row draws, whole and in its order: and/or/not groups, relation rules, a second rule on a row
|
|
39
|
+
* already drawn, and a rule no row can show (an operator its editor doesn't write, a field no column carries). */
|
|
40
|
+
rest: readonly FilterNode[];
|
|
41
|
+
};
|
|
42
|
+
/** A quick-filter panel's picks, by field key: an option's codes, a yes/no field's "true" or "false". */
|
|
43
|
+
export type QuickValues = Readonly<Record<string, readonly string[]>>;
|
|
44
|
+
/** A field a quick-filter panel offers: its key and the type its value is read as, one whose rule picks options. */
|
|
45
|
+
export type QuickValueField = {
|
|
46
|
+
key: string;
|
|
47
|
+
type: FieldType;
|
|
48
|
+
};
|
|
49
|
+
/** The tree as the panel draws it: a rule per column (and, with `parts`, per part row), and the rest kept whole. */
|
|
50
|
+
export declare function filterPanelFromTree<Row>(tree: FilterTree, columns: ListColumn<Row>[], opts?: {
|
|
51
|
+
parts?: boolean;
|
|
52
|
+
}): FilterPanelState;
|
|
53
|
+
/** The tree the panel's state says: the rows' rules in column order, then the rest as it was kept. A key no row
|
|
54
|
+
* names writes nothing. `treeFromFilterPanel(filterPanelFromTree(tree))` holds every rule `tree` held. */
|
|
55
|
+
export declare function treeFromFilterPanel<Row>(panel: FilterPanelState, columns: ListColumn<Row>[], opts?: {
|
|
36
56
|
parts?: boolean;
|
|
37
57
|
}): FilterTree;
|
|
58
|
+
/** The picks a quick-filter panel draws: each offered field's root rule that picks options, as its values. */
|
|
59
|
+
export declare function quickValuesFromTree(tree: FilterTree, fields: readonly QuickValueField[]): QuickValues;
|
|
60
|
+
/** The tree with the offered fields' picks written as ordinary root rules (a field with none picked has none);
|
|
61
|
+
* every other item kept, a rule on an offered field the panel can't show (an `is_none_of`) among them. */
|
|
62
|
+
export declare function withQuickValues(tree: FilterTree, fields: readonly QuickValueField[], values: QuickValues): FilterTree;
|
|
38
63
|
/** The root relation rules, by relation field key — the Filter panel's Related records rows (POR-704). */
|
|
39
64
|
export declare function rootRelationRules(tree: FilterTree): Record<string, FilterRelationRule>;
|
|
40
|
-
/** The tree with its root relation rules replaced by `rules`; every other rule and group untouched
|
|
65
|
+
/** The tree with its root relation rules replaced by `rules`; every other rule and group untouched, and a set-aside
|
|
66
|
+
* relation rule kept, since no row shows it. */
|
|
41
67
|
export declare function withRootRelationRules(tree: FilterTree, rules: Readonly<Record<string, FilterRelationRule>>): FilterTree;
|
|
42
68
|
/** Replace (or drop, on null) the root rule for one column, or with `part` its rule on that part of the value; groups
|
|
43
69
|
* untouched. */
|
package/dist/model/view-rules.js
CHANGED
|
@@ -6,16 +6,25 @@ export function fieldKeyOf(col) {
|
|
|
6
6
|
return col.field?.key ?? col.id;
|
|
7
7
|
}
|
|
8
8
|
export function fromListFilterRule(fieldKey, type, rule, part) {
|
|
9
|
-
const
|
|
9
|
+
const read = wholeFromListFilterRule(fieldKey, type, rule);
|
|
10
|
+
const whole = read && VALUELESS.has(read.operator) ? { ...read, value: null } : read;
|
|
10
11
|
return whole && part !== undefined ? { ...whole, part } : whole;
|
|
11
12
|
}
|
|
13
|
+
const VALUELESS = new Set(["is_empty", "is_not_empty"]);
|
|
14
|
+
function numberEnds(value) {
|
|
15
|
+
return {
|
|
16
|
+
value: value[0] == null ? null : Number(value[0]),
|
|
17
|
+
value2: value[1] == null ? null : Number(value[1]),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
12
20
|
function wholeFromListFilterRule(fieldKey, type, rule) {
|
|
13
21
|
switch (rule.editor) {
|
|
14
22
|
case "text":
|
|
15
23
|
return { fieldKey, operator: rule.operator, value: rule.query };
|
|
16
24
|
case "number":
|
|
17
25
|
return rule.operator === "between"
|
|
18
|
-
?
|
|
26
|
+
?
|
|
27
|
+
{ fieldKey, operator: "between", value: [rule.value ?? null, rule.value2 ?? null] }
|
|
19
28
|
: { fieldKey, operator: rule.operator, value: rule.value };
|
|
20
29
|
case "date":
|
|
21
30
|
if (rule.operator === "is_relative")
|
|
@@ -59,12 +68,7 @@ export function toListFilterRule(type, rule, opts) {
|
|
|
59
68
|
case "percent":
|
|
60
69
|
case "currency":
|
|
61
70
|
if (Array.isArray(rule.value))
|
|
62
|
-
return {
|
|
63
|
-
editor: "number",
|
|
64
|
-
operator: "between",
|
|
65
|
-
value: Number(rule.value[0]),
|
|
66
|
-
value2: Number(rule.value[1]),
|
|
67
|
-
};
|
|
71
|
+
return { editor: "number", operator: "between", ...numberEnds(rule.value) };
|
|
68
72
|
return {
|
|
69
73
|
editor: "number",
|
|
70
74
|
operator: rule.operator,
|
|
@@ -131,7 +135,7 @@ function partListFilterRule(type, rule, part) {
|
|
|
131
135
|
return null;
|
|
132
136
|
if (type === "range")
|
|
133
137
|
return Array.isArray(rule.value)
|
|
134
|
-
? { editor: "number", operator: "between",
|
|
138
|
+
? { editor: "number", operator: "between", ...numberEnds(rule.value) }
|
|
135
139
|
: {
|
|
136
140
|
editor: "number",
|
|
137
141
|
operator: rule.operator,
|
|
@@ -150,7 +154,7 @@ function partListFilterRule(type, rule, part) {
|
|
|
150
154
|
export function rootRulesByColumn(tree, columns, opts) {
|
|
151
155
|
const out = {};
|
|
152
156
|
for (const item of tree.items) {
|
|
153
|
-
if (isFilterGroup(item) || isRelationRule(item))
|
|
157
|
+
if (isFilterGroup(item) || isRelationRule(item) || item.setAside)
|
|
154
158
|
continue;
|
|
155
159
|
const col = columns.find((c) => fieldKeyOf(c) === item.fieldKey);
|
|
156
160
|
if (!col?.field)
|
|
@@ -161,31 +165,98 @@ export function rootRulesByColumn(tree, columns, opts) {
|
|
|
161
165
|
}
|
|
162
166
|
return out;
|
|
163
167
|
}
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
let next = tree;
|
|
168
|
+
function columnRows(columns, opts) {
|
|
169
|
+
const rows = [];
|
|
167
170
|
for (const col of columns) {
|
|
168
171
|
if (!col.field)
|
|
169
172
|
continue;
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
const type = valueTypeOf(col.field);
|
|
174
|
+
const fieldKey = fieldKeyOf(col);
|
|
175
|
+
rows.push({ key: col.id, fieldKey, type });
|
|
176
|
+
if (opts?.parts)
|
|
177
|
+
for (const part of FILTER_PART_ROWS[type] ?? [])
|
|
178
|
+
rows.push({ key: partKey(col.id, part), fieldKey, type, part });
|
|
179
|
+
}
|
|
180
|
+
return rows;
|
|
181
|
+
}
|
|
182
|
+
const quickRows = (fields) => fields.map((f) => ({ key: f.key, fieldKey: f.key, type: f.type }));
|
|
183
|
+
function sameValue(a, b) {
|
|
184
|
+
if (a === b)
|
|
185
|
+
return true;
|
|
186
|
+
if (Array.isArray(a) || Array.isArray(b))
|
|
187
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((x, i) => sameValue(x, b[i]));
|
|
188
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
189
|
+
const keys = Object.keys(a);
|
|
190
|
+
return (keys.length === Object.keys(b).length &&
|
|
191
|
+
keys.every((k) => sameValue(a[k], b[k])));
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
function sameRule(a, b) {
|
|
196
|
+
if (a.fieldKey !== b.fieldKey || a.part !== b.part || a.operator !== b.operator)
|
|
197
|
+
return false;
|
|
198
|
+
return VALUELESS.has(a.operator) || sameValue(a.value, b.value);
|
|
199
|
+
}
|
|
200
|
+
function readRows(tree, rows) {
|
|
201
|
+
const rules = {};
|
|
202
|
+
const rest = [];
|
|
203
|
+
for (const item of tree.items) {
|
|
204
|
+
if (isFilterGroup(item) || isRelationRule(item) || item.setAside) {
|
|
205
|
+
rest.push(item);
|
|
206
|
+
continue;
|
|
176
207
|
}
|
|
208
|
+
const row = rows.find((r) => !(r.key in rules) && r.fieldKey === item.fieldKey && r.part === item.part);
|
|
209
|
+
const rule = row ? toListFilterRule(row.type, item, { parts: true }) : null;
|
|
210
|
+
const back = row && rule ? fromListFilterRule(row.fieldKey, row.type, rule, row.part) : null;
|
|
211
|
+
if (row && rule && back && sameRule(back, item))
|
|
212
|
+
rules[row.key] = rule;
|
|
213
|
+
else
|
|
214
|
+
rest.push(item);
|
|
215
|
+
}
|
|
216
|
+
return { rules, rest };
|
|
217
|
+
}
|
|
218
|
+
function writeRows(op, rows, rules, rest) {
|
|
219
|
+
const items = [];
|
|
220
|
+
for (const row of rows) {
|
|
221
|
+
const rule = rules[row.key];
|
|
222
|
+
const next = rule ? fromListFilterRule(row.fieldKey, row.type, rule, row.part) : null;
|
|
223
|
+
if (next)
|
|
224
|
+
items.push(next);
|
|
225
|
+
}
|
|
226
|
+
return { op, items: [...items, ...rest] };
|
|
227
|
+
}
|
|
228
|
+
export function filterPanelFromTree(tree, columns, opts) {
|
|
229
|
+
return { op: tree.op, ...readRows(tree, columnRows(columns, opts)) };
|
|
230
|
+
}
|
|
231
|
+
export function treeFromFilterPanel(panel, columns, opts) {
|
|
232
|
+
return writeRows(panel.op, columnRows(columns, opts), panel.rules, panel.rest);
|
|
233
|
+
}
|
|
234
|
+
export function quickValuesFromTree(tree, fields) {
|
|
235
|
+
const out = {};
|
|
236
|
+
for (const [key, rule] of Object.entries(readRows(tree, quickRows(fields)).rules))
|
|
237
|
+
if (rule.editor === "options")
|
|
238
|
+
out[key] = rule.values;
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
export function withQuickValues(tree, fields, values) {
|
|
242
|
+
const rows = quickRows(fields);
|
|
243
|
+
const rules = {};
|
|
244
|
+
for (const f of fields) {
|
|
245
|
+
const picked = values[f.key];
|
|
246
|
+
if (picked?.length)
|
|
247
|
+
rules[f.key] = { editor: "options", values: [...picked] };
|
|
177
248
|
}
|
|
178
|
-
return
|
|
249
|
+
return writeRows(tree.op, rows, rules, readRows(tree, rows).rest);
|
|
179
250
|
}
|
|
180
251
|
export function rootRelationRules(tree) {
|
|
181
252
|
const out = {};
|
|
182
253
|
for (const item of tree.items)
|
|
183
|
-
if (isRelationRule(item))
|
|
254
|
+
if (isRelationRule(item) && !item.setAside)
|
|
184
255
|
out[item.fieldKey] = item;
|
|
185
256
|
return out;
|
|
186
257
|
}
|
|
187
258
|
export function withRootRelationRules(tree, rules) {
|
|
188
|
-
const kept = tree.items.filter((item) => !isRelationRule(item));
|
|
259
|
+
const kept = tree.items.filter((item) => !isRelationRule(item) || item.setAside);
|
|
189
260
|
return { op: tree.op, items: [...kept, ...Object.values(rules)] };
|
|
190
261
|
}
|
|
191
262
|
export function withRootRule(tree, col, rule, part) {
|
|
@@ -193,6 +264,7 @@ export function withRootRule(tree, col, rule, part) {
|
|
|
193
264
|
const type = col.field ? valueTypeOf(col.field) : undefined;
|
|
194
265
|
const kept = tree.items.filter((item) => isFilterGroup(item) ||
|
|
195
266
|
isRelationRule(item) ||
|
|
267
|
+
item.setAside ||
|
|
196
268
|
item.fieldKey !== key ||
|
|
197
269
|
item.part !== part ||
|
|
198
270
|
(part !== undefined && (!type || !toListFilterRule(type, item, { parts: true }))));
|
|
@@ -3,7 +3,7 @@ import type { FieldConventions } from "@viewkitjs/fields";
|
|
|
3
3
|
import { type ViewsMessageResolver } from "../contract.js";
|
|
4
4
|
import type { ViewsAtoms } from "../atoms/types.js";
|
|
5
5
|
import type { FieldPresentation } from "../display/options.js";
|
|
6
|
-
import type { ViewsComponents, ViewsMenuRoute, ViewsSheetActionsPlace } from "./components.js";
|
|
6
|
+
import type { ViewsComponents, ViewsMenuRoute, ViewsSelectionBarSettings, ViewsSheetActionsPlace } from "./components.js";
|
|
7
7
|
import type { ViewsIcons } from "./icons.js";
|
|
8
8
|
import type { ViewsEscapeRules } from "../editors/escape-rule.js";
|
|
9
9
|
import { type ViewsPorts } from "./ports.js";
|
|
@@ -41,6 +41,10 @@ export type ViewsProviderProps = {
|
|
|
41
41
|
* your `Menu`, handed its rows as data, with the three hints a row may carry (`beside`, `keepOpen`,
|
|
42
42
|
* `detail`). */
|
|
43
43
|
menus?: ViewsMenuRoute;
|
|
44
|
+
/** Where the selection bar sits: its bottom, its layer and its classes on the desktop and on the phone,
|
|
45
|
+
* and the media query that makes it the phone's pill. Pass a module-level object. Default: 1rem above
|
|
46
|
+
* the screen's foot, layer 50, the pill wherever `desktopQuery` does not match. */
|
|
47
|
+
selectionBar?: ViewsSelectionBarSettings;
|
|
44
48
|
children: ReactNode;
|
|
45
49
|
};
|
|
46
|
-
export declare function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages, presentation, desktopQuery, sheetActions, escape, sayRefusals, menus, }: ViewsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
export declare function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages, presentation, desktopQuery, sheetActions, escape, sayRefusals, menus, selectionBar, }: ViewsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,7 +12,7 @@ import { browserConfirm } from "./ports.js";
|
|
|
12
12
|
export { useViews } from "./context.js";
|
|
13
13
|
const MISSING_COMMAND_PARTS = missingParts("Command");
|
|
14
14
|
const MISSING_CALENDAR_COMPONENT = missingComponent("Calendar");
|
|
15
|
-
export function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages = resolveViewsMessage, presentation, desktopQuery = DEFAULT_DESKTOP_QUERY, sheetActions = "bar", escape, sayRefusals = false, menus = "popover", }) {
|
|
15
|
+
export function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages = resolveViewsMessage, presentation, desktopQuery = DEFAULT_DESKTOP_QUERY, sheetActions = "bar", escape, sayRefusals = false, menus = "popover", selectionBar, }) {
|
|
16
16
|
const merged = useMemo(() => ({ ...DEFAULT_VIEWS_ATOMS, ...atoms }), [atoms]);
|
|
17
17
|
const settled = useMemo(() => ({
|
|
18
18
|
...components,
|
|
@@ -35,6 +35,7 @@ export function ViewsProvider({ children, components, conventions, icons, ports,
|
|
|
35
35
|
escape,
|
|
36
36
|
sayRefusals,
|
|
37
37
|
menus,
|
|
38
|
-
|
|
38
|
+
selectionBar,
|
|
39
|
+
}), [settled, merged, conventions, icons, resolved, messages, presentation, desktopQuery, sheetActions, escape, sayRefusals, menus, selectionBar]);
|
|
39
40
|
return _jsx(ViewsContext.Provider, { value: value, children: children });
|
|
40
41
|
}
|
|
@@ -349,6 +349,22 @@ export type ViewsSheetActionsPlace = "bar" | "head";
|
|
|
349
349
|
* `popover`, ViewKit's rows in your `Popover`; `menu`, your `Menu`, handed rows as data. The row menu and
|
|
350
350
|
* a command cell's menu always go through your `Menu`. */
|
|
351
351
|
export type ViewsMenuRoute = "popover" | "menu";
|
|
352
|
+
/** Where the selection bar's fixed box sits on one form. `bottom` is a CSS length (default
|
|
353
|
+
* `calc(1rem + env(safe-area-inset-bottom))`), `zIndex` its layer (default 50), and `className` the app's
|
|
354
|
+
* own classes on the box (a hook its CSS reads, a rule that hides the bar). */
|
|
355
|
+
export type ViewsBarPlacement = {
|
|
356
|
+
bottom?: string;
|
|
357
|
+
zIndex?: number;
|
|
358
|
+
className?: string;
|
|
359
|
+
};
|
|
360
|
+
/** The selection bar, as the app places it: on the desktop an island, on the phone a pill whose Actions
|
|
361
|
+
* open a sheet. `phoneQuery`, when handed, is the media query under which the bar is the phone's pill;
|
|
362
|
+
* without it the bar is the pill wherever the provider's `desktopQuery` does not match. */
|
|
363
|
+
export type ViewsSelectionBarSettings = {
|
|
364
|
+
phoneQuery?: string;
|
|
365
|
+
desktop?: ViewsBarPlacement;
|
|
366
|
+
phone?: ViewsBarPlacement;
|
|
367
|
+
};
|
|
352
368
|
/** A phone sheet. `snap` is a hint: an app whose sheet has no snap points ignores it. */
|
|
353
369
|
export type ViewsSheetProps = {
|
|
354
370
|
open: boolean;
|
|
@@ -2,7 +2,7 @@ import type { FieldConventions } from "@viewkitjs/fields";
|
|
|
2
2
|
import type { ViewsMessageResolver } from "../contract.js";
|
|
3
3
|
import type { ViewsAtoms } from "../atoms/types.js";
|
|
4
4
|
import type { FieldPresentation } from "../display/options.js";
|
|
5
|
-
import type { ViewsMenuRoute, ViewsResolvedComponents, ViewsSheetActionsPlace } from "./components.js";
|
|
5
|
+
import type { ViewsMenuRoute, ViewsResolvedComponents, ViewsSelectionBarSettings, ViewsSheetActionsPlace } from "./components.js";
|
|
6
6
|
import type { ViewsIcons } from "./icons.js";
|
|
7
7
|
import type { ViewsResolvedPorts } from "./ports.js";
|
|
8
8
|
import type { ViewsEscapeRules } from "../editors/escape-rule.js";
|
|
@@ -27,6 +27,8 @@ export type ViewsContextValue = {
|
|
|
27
27
|
sayRefusals?: boolean;
|
|
28
28
|
/** How the grid opens its own menus (`ViewsProvider`'s `menus`). Absent means `popover`. */
|
|
29
29
|
menus?: ViewsMenuRoute;
|
|
30
|
+
/** Where the selection bar sits (`ViewsProvider`'s `selectionBar`); absent, the package's defaults. */
|
|
31
|
+
selectionBar?: ViewsSelectionBarSettings;
|
|
30
32
|
};
|
|
31
33
|
export declare const ViewsContext: import("react").Context<ViewsContextValue | null>;
|
|
32
34
|
export declare function useViews(): ViewsContextValue;
|
|
@@ -7,3 +7,6 @@ export declare function isDesktopNow(query: string): boolean;
|
|
|
7
7
|
/** Whether the screen is a desktop, by the provider's `desktopQuery`: true where there is no
|
|
8
8
|
* `matchMedia`. It follows the query's changes. The package's own: no entry point exports it. */
|
|
9
9
|
export declare function useDesktop(): boolean;
|
|
10
|
+
/** Whether `query` matches the screen, following its changes. `fallback` is the answer where the screen
|
|
11
|
+
* can't be asked (a server render, no `matchMedia`). The package's own: no entry point exports it. */
|
|
12
|
+
export declare function useMediaQuery(query: string, fallback: boolean): boolean;
|
package/dist/provider/desktop.js
CHANGED
|
@@ -10,13 +10,16 @@ export function isDesktopNow(query) {
|
|
|
10
10
|
}
|
|
11
11
|
export function useDesktop() {
|
|
12
12
|
const { desktopQuery } = useViews();
|
|
13
|
+
return useMediaQuery(desktopQuery, true);
|
|
14
|
+
}
|
|
15
|
+
export function useMediaQuery(query, fallback) {
|
|
13
16
|
const subscribe = useCallback((onChange) => {
|
|
14
17
|
if (!canAsk())
|
|
15
18
|
return () => { };
|
|
16
|
-
const list = window.matchMedia(
|
|
19
|
+
const list = window.matchMedia(query);
|
|
17
20
|
list.addEventListener("change", onChange);
|
|
18
21
|
return () => list.removeEventListener("change", onChange);
|
|
19
|
-
}, [
|
|
20
|
-
const read = () =>
|
|
21
|
-
return useSyncExternalStore(subscribe, read, () =>
|
|
22
|
+
}, [query]);
|
|
23
|
+
const read = () => (canAsk() ? window.matchMedia(query).matches : fallback);
|
|
24
|
+
return useSyncExternalStore(subscribe, read, () => fallback);
|
|
22
25
|
}
|
package/dist/react.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ export { ViewsProvider, useViews } from "./provider/ViewsProvider.js";
|
|
|
2
2
|
export type { ViewsContextValue, ViewsProviderProps } from "./provider/ViewsProvider.js";
|
|
3
3
|
export type { EditEscape, ViewsEscapeRules } from "./editors/escape-rule.js";
|
|
4
4
|
export { DEFAULT_DESKTOP_QUERY } from "./provider/desktop.js";
|
|
5
|
-
export type { ViewsAlign, ViewsAnchor, ViewsButtonProps, ViewsCalendarProps, ViewsCheckboxProps, ViewsCloseReason, ViewsCollapseProps, ViewsCommandParts, ViewsComponents, ViewsDateBodyProps, ViewsDatePick, ViewsInputProps, ViewsMenuItem, ViewsMenuProps, ViewsMenuRoute, ViewsOpenChange, ViewsPickerAction, ViewsPickerItem, ViewsPickerProps, ViewsPopoverProps, ViewsResolvedComponents, ViewsSheetAction, ViewsSheetActions, ViewsSheetActionsPlace, ViewsSheetProps, ViewsSide, ViewsTooltipProps, } from "./provider/components.js";
|
|
5
|
+
export type { ViewsAlign, ViewsAnchor, ViewsBarPlacement, ViewsButtonProps, ViewsCalendarProps, ViewsCheckboxProps, ViewsCloseReason, ViewsCollapseProps, ViewsCommandParts, ViewsComponents, ViewsDateBodyProps, ViewsDatePick, ViewsInputProps, ViewsMenuItem, ViewsMenuProps, ViewsMenuRoute, ViewsOpenChange, ViewsPickerAction, ViewsPickerItem, ViewsPickerProps, ViewsPopoverProps, ViewsResolvedComponents, ViewsSelectionBarSettings, ViewsSheetAction, ViewsSheetActions, ViewsSheetActionsPlace, ViewsSheetProps, ViewsSide, ViewsTooltipProps, } from "./provider/components.js";
|
|
6
6
|
export type { ViewsIconProps, ViewsIcons } from "./provider/icons.js";
|
|
7
7
|
export { NOOP_PORTS } from "./provider/ports.js";
|
|
8
8
|
export type { ViewsClipboardPort, ViewsConfirmPort, ViewsConfirmRequest, ViewsHapticsPort, ViewsPorts, ViewsPrefsPort, ViewsResolvedPorts, ViewsToastPort, } from "./provider/ports.js";
|
|
9
9
|
export { DEFAULT_VIEWS_ATOMS } from "./atoms/defaults.js";
|
|
10
|
-
export type { ViewsAtoms, ViewsCommandMenuProps, ViewsRowMenuItem, ViewsRowMenuProps, ViewsListProps, ViewsRelationLinkProps, ViewsRelationRolesProps, ViewsLoadingProps, ViewsLoadMoreProps, ViewsPlatformMarkProps, ViewsRowContentProps, ViewsRowProps, ViewsStatusBadgeProps, ViewsStatusMarkerProps, ViewsTagProps, ViewsTickBoxProps, } from "./atoms/types.js";
|
|
10
|
+
export type { ViewsAtoms, ViewsCommandMenuProps, ViewsRowMenuItem, ViewsRowMenuProps, ViewsListProps, ViewsRelationLinkProps, ViewsRelationRolesProps, ViewsLoadingProps, ViewsLoadMoreProps, ViewsPlatformMarkProps, ViewsRowContentProps, ViewsRowProps, ViewsSelectionSheetProps, ViewsStatusBadgeProps, ViewsStatusMarkerProps, ViewsTagProps, ViewsTickBoxProps, ViewsChoiceRowProps, ViewsCheckRowProps, ViewsRadioRowProps, ViewsDirectionButtonProps, ViewsMenuRowProps, ViewsToggleRowProps, ViewsPanelSearchProps, } from "./atoms/types.js";
|
|
11
11
|
export type { ComponentName, PortName, ViewsIconName, ViewsMessage, ViewsMessageResolver } from "./contract.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { SelectionVerb } from "./verbs.js";
|
|
3
|
+
export type SelectionBarProps = {
|
|
4
|
+
/** How many rows are selected. The bar draws nothing at zero. */
|
|
5
|
+
count: number;
|
|
6
|
+
/** Clears the selection: the count chip, the phone's ✕. */
|
|
7
|
+
onClear: () => void;
|
|
8
|
+
/** What the selection lets a person do, in order: the first four on the bar, the rest in More. */
|
|
9
|
+
verbs: readonly SelectionVerb[];
|
|
10
|
+
/** A batch is running: every control is disabled until it ends. */
|
|
11
|
+
busy?: boolean;
|
|
12
|
+
/** Deletes the selection. The bar's own verb, drawn as the trailing trash in the same place on every list;
|
|
13
|
+
* never a verb in `verbs`. A list with no bulk delete leaves it out. */
|
|
14
|
+
onDelete?: () => void;
|
|
15
|
+
/** The trash's accessible name and tooltip. Default: the `views.selection.delete` message. */
|
|
16
|
+
deleteLabel?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function SelectionBar(props: SelectionBarProps): ReactNode;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { cx } from "../internal/cx.js";
|
|
6
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
7
|
+
import { useViews } from "../provider/context.js";
|
|
8
|
+
import { useDesktop, useMediaQuery } from "../provider/desktop.js";
|
|
9
|
+
import { overflowItems, splitVerbs } from "./bar-overflow.js";
|
|
10
|
+
import { CountWords, DIVIDER_CLASS, OptionLabel, PILL_CLASS } from "./bar-parts.js";
|
|
11
|
+
import { SelectionBarPhone } from "./SelectionBarPhone.js";
|
|
12
|
+
const DEFAULT_BOTTOM = "calc(1rem + env(safe-area-inset-bottom))";
|
|
13
|
+
const DEFAULT_LAYER = 50;
|
|
14
|
+
export function SelectionBar(props) {
|
|
15
|
+
const { selectionBar } = useViews();
|
|
16
|
+
const desktop = useDesktop();
|
|
17
|
+
const phoneQuery = selectionBar?.phoneQuery;
|
|
18
|
+
const phoneByQuery = useMediaQuery(phoneQuery ?? "not all", false);
|
|
19
|
+
const phone = phoneQuery ? phoneByQuery : !desktop;
|
|
20
|
+
if (props.count === 0 || typeof document === "undefined")
|
|
21
|
+
return null;
|
|
22
|
+
const placement = phone ? selectionBar?.phone : selectionBar?.desktop;
|
|
23
|
+
return createPortal(_jsx("div", { "data-slot": "vk-selection-bar", className: cx("fixed left-1/2 -translate-x-1/2", placement?.className), style: { bottom: placement?.bottom ?? DEFAULT_BOTTOM, zIndex: placement?.zIndex ?? DEFAULT_LAYER }, children: phone ? _jsx(SelectionBarPhone, { ...props }) : _jsx(DesktopBar, { ...props }) }), document.body);
|
|
24
|
+
}
|
|
25
|
+
function DesktopBar({ count, onClear, verbs, busy = false, onDelete, deleteLabel }) {
|
|
26
|
+
const { components, icons, messages } = useViews();
|
|
27
|
+
const { Button, Tooltip } = components;
|
|
28
|
+
const { inline, overflow } = splitVerbs(verbs);
|
|
29
|
+
const Close = icons.close;
|
|
30
|
+
const Trash = icons.delete;
|
|
31
|
+
const trashLabel = deleteLabel ?? messages({ key: "views.selection.delete" });
|
|
32
|
+
const deselect = messages({ key: "views.selection.deselect-all" });
|
|
33
|
+
return (_jsxs("div", { "data-slot": "vk-selection-pill", className: cx(PILL_CLASS, "pl-1.5"), children: [_jsx(Tooltip, { side: "top", delayMs: 300, className: "flex items-center gap-2", content: _jsxs(_Fragment, { children: [deselect, _jsx("span", { className: "rounded-sm border border-solid border-(color:--vk-border) px-1 py-px text-[10px] font-medium text-(color:--vk-fg-subtle)", children: messages({ key: "views.selection.escape" }) })] }), children: _jsxs("button", { type: "button", "data-slot": "vk-selection-chip", onClick: onClear, disabled: busy, "aria-label": deselect, className: cx(ELEMENT_RESET, "group/selchip flex h-8 cursor-pointer items-center gap-1.5 rounded-full bg-(color:--vk-neutral) pl-3 pr-2.5 transition-colors hover:bg-(color:--vk-neutral-hovered) disabled:cursor-default disabled:opacity-50"), children: [_jsx(CountWords, { count: count }), _jsx(Close, { className: "h-3 w-3 text-(color:--vk-fg-subtle) transition-colors group-hover/selchip:text-(color:--vk-fg)" })] }) }), _jsxs("div", { className: "flex items-center gap-1 pl-4", children: [inline.map((verb, index) => (_jsx(InlineVerb, { verb: verb, busy: busy }, index))), onDelete ? (_jsx(Button, { size: "icon", variant: "ghost", className: "h-8 w-8 rounded-full text-(color:--vk-danger) hover:bg-(color:--vk-danger-subtlest) hover:text-(color:--vk-danger)", disabled: busy, onClick: onDelete, "aria-label": trashLabel, title: trashLabel, children: _jsx(Trash, { className: "h-4 w-4" }) })) : null] }), _jsx("span", { className: DIVIDER_CLASS }), _jsx(MoreVerbs, { overflow: overflow, busy: busy })] }));
|
|
34
|
+
}
|
|
35
|
+
function InlineVerb({ verb, busy }) {
|
|
36
|
+
const { Button } = useViews().components;
|
|
37
|
+
if (verb.kind === "options")
|
|
38
|
+
return _jsx(OptionsVerb, { verb: verb, busy: busy });
|
|
39
|
+
if (verb.kind === "group")
|
|
40
|
+
return _jsx(GroupVerb, { verb: verb, busy: busy });
|
|
41
|
+
return (_jsxs(Button, { size: "sm", variant: "ghost", className: cx("rounded-full", verb.destructive && "text-(color:--vk-danger) hover:text-(color:--vk-danger)"), disabled: busy || verb.disabled, onClick: verb.onClick, children: [verb.icon, verb.label] }));
|
|
42
|
+
}
|
|
43
|
+
function useAnchoredOpen(disabled) {
|
|
44
|
+
const [open, setOpen] = useState(false);
|
|
45
|
+
const anchor = useRef(null);
|
|
46
|
+
const openAtPress = useRef(null);
|
|
47
|
+
const trigger = {
|
|
48
|
+
ref: anchor,
|
|
49
|
+
className: "inline-flex",
|
|
50
|
+
onPointerDownCapture: () => {
|
|
51
|
+
openAtPress.current = open;
|
|
52
|
+
},
|
|
53
|
+
onClick: () => {
|
|
54
|
+
const wasOpen = openAtPress.current ?? open;
|
|
55
|
+
openAtPress.current = null;
|
|
56
|
+
if (!disabled)
|
|
57
|
+
setOpen(!wasOpen);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
return { open, setOpen, anchor, trigger };
|
|
61
|
+
}
|
|
62
|
+
function GroupVerb({ verb, busy }) {
|
|
63
|
+
const { Button, Menu } = useViews().components;
|
|
64
|
+
const disabled = Boolean(busy || verb.disabled);
|
|
65
|
+
const { open, setOpen, anchor, trigger } = useAnchoredOpen(disabled);
|
|
66
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ...trigger, children: _jsxs(Button, { size: "sm", variant: "ghost", className: "rounded-full", disabled: disabled, "aria-label": verb.label, children: [verb.icon, verb.label] }) }), _jsx(Menu, { open: open, onOpenChange: (next) => setOpen(next), anchor: anchor, side: "top", align: "center", label: verb.label, items: verb.items.map((item, index) => ({
|
|
67
|
+
key: String(index),
|
|
68
|
+
label: item.label,
|
|
69
|
+
icon: item.icon,
|
|
70
|
+
onSelect: item.onClick,
|
|
71
|
+
disabled: item.disabled,
|
|
72
|
+
destructive: item.destructive,
|
|
73
|
+
})) })] }));
|
|
74
|
+
}
|
|
75
|
+
function OptionsVerb({ verb, busy }) {
|
|
76
|
+
const { components, atoms } = useViews();
|
|
77
|
+
const { Button, Popover } = components;
|
|
78
|
+
const { List, Row } = atoms;
|
|
79
|
+
const disabled = Boolean(busy || verb.disabled);
|
|
80
|
+
const { open, setOpen, anchor, trigger } = useAnchoredOpen(disabled);
|
|
81
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ...trigger, children: _jsxs(Button, { size: "sm", variant: "ghost", className: "rounded-full", disabled: disabled, "aria-label": verb.label, children: [verb.icon, verb.label] }) }), _jsx(Popover, { open: open, onOpenChange: (next) => setOpen(next), anchor: anchor, side: "top", align: "center", sideOffset: 8, onOutsidePress: (event) => (anchor.current?.contains(event.target) ? false : undefined), chrome: "menu", className: "w-48", children: _jsx(List, { className: "max-h-72 overflow-y-auto overscroll-contain scrollbar-overlay", children: verb.options.map((option) => (_jsx(Row, { size: "compact", label: _jsx(OptionLabel, { option: option }), onClick: () => {
|
|
82
|
+
setOpen(false);
|
|
83
|
+
verb.onSelect(option.value);
|
|
84
|
+
} }, option.value))) }) })] }));
|
|
85
|
+
}
|
|
86
|
+
function MoreVerbs({ overflow, busy }) {
|
|
87
|
+
const { components, icons, messages } = useViews();
|
|
88
|
+
const { Button, Menu } = components;
|
|
89
|
+
const { open, setOpen, anchor, trigger } = useAnchoredOpen(busy);
|
|
90
|
+
const More = icons.more;
|
|
91
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ...trigger, children: _jsxs(Button, { size: "sm", variant: "ghost", className: "rounded-full text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)", disabled: busy, "aria-label": messages({ key: "views.selection.more-label" }), children: [_jsx(More, { className: "h-4 w-4" }), messages({ key: "views.selection.more" })] }) }), _jsx(Menu, { open: open, onOpenChange: (next) => setOpen(next), anchor: anchor, side: "top", label: messages({ key: "views.selection.more" }), items: overflowItems(overflow) })] }));
|
|
92
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { cx } from "../internal/cx.js";
|
|
5
|
+
import { useViews } from "../provider/context.js";
|
|
6
|
+
import { CountWords, DIVIDER_CLASS, PILL_CLASS } from "./bar-parts.js";
|
|
7
|
+
export function SelectionBarPhone({ count, onClear, verbs, busy = false, onDelete, deleteLabel }) {
|
|
8
|
+
const { components, atoms, icons, messages } = useViews();
|
|
9
|
+
const { Button } = components;
|
|
10
|
+
const { SelectionSheet } = atoms;
|
|
11
|
+
const [open, setOpen] = useState(false);
|
|
12
|
+
const Close = icons.close;
|
|
13
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { "data-slot": "vk-selection-pill", className: cx(PILL_CLASS, "pl-4"), children: [_jsx(CountWords, { count: count }), _jsx("span", { className: DIVIDER_CLASS }), _jsx(Button, { size: "sm", variant: "ghost", className: "rounded-full", disabled: busy, onClick: () => setOpen(true), children: messages({ key: "views.selection.actions" }) }), _jsx(Button, { size: "icon", variant: "ghost", className: "h-8 w-8 rounded-full text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)", onClick: onClear, disabled: busy, "aria-label": messages({ key: "views.selection.clear" }), children: _jsx(Close, { className: "h-4 w-4" }) })] }), _jsx(SelectionSheet, { open: open, onOpenChange: (next) => setOpen(next), title: messages({ key: "views.selection.count", values: { count } }), verbs: verbs, onDelete: onDelete, deleteLabel: deleteLabel ?? messages({ key: "views.selection.delete" }), busy: busy })] }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ViewsMenuItem } from "../provider/components.js";
|
|
2
|
+
import type { SelectionVerb } from "./verbs.js";
|
|
3
|
+
/** How many verbs stay on the bar before the rest fold into More. */
|
|
4
|
+
export declare const INLINE_VERBS = 4;
|
|
5
|
+
export declare function splitVerbs(verbs: readonly SelectionVerb[]): {
|
|
6
|
+
inline: SelectionVerb[];
|
|
7
|
+
overflow: SelectionVerb[];
|
|
8
|
+
};
|
|
9
|
+
/** The spilled verbs as More's rows. A group or an options verb keeps its shape, opening its rows beside
|
|
10
|
+
* the menu: its rows only mean something under their own heading ("Set tag → warming / ready"). A menu row
|
|
11
|
+
* is words, so an options verb's values read as their labels here. */
|
|
12
|
+
export declare function overflowItems(overflow: readonly SelectionVerb[]): ViewsMenuItem[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const INLINE_VERBS = 4;
|
|
2
|
+
export function splitVerbs(verbs) {
|
|
3
|
+
return { inline: verbs.slice(0, INLINE_VERBS), overflow: verbs.slice(INLINE_VERBS) };
|
|
4
|
+
}
|
|
5
|
+
export function overflowItems(overflow) {
|
|
6
|
+
return overflow.map((verb, index) => {
|
|
7
|
+
const key = `verb-${index}`;
|
|
8
|
+
if (verb.kind === "action") {
|
|
9
|
+
return { key, label: verb.label, icon: verb.icon, onSelect: verb.onClick, disabled: verb.disabled, destructive: verb.destructive };
|
|
10
|
+
}
|
|
11
|
+
if (verb.kind === "group") {
|
|
12
|
+
return {
|
|
13
|
+
key,
|
|
14
|
+
label: verb.label,
|
|
15
|
+
icon: verb.icon,
|
|
16
|
+
disabled: verb.disabled,
|
|
17
|
+
beside: true,
|
|
18
|
+
children: verb.items.map((item, at) => ({
|
|
19
|
+
key: `${key}-${at}`,
|
|
20
|
+
label: item.label,
|
|
21
|
+
icon: item.icon,
|
|
22
|
+
onSelect: item.onClick,
|
|
23
|
+
disabled: verb.disabled || item.disabled,
|
|
24
|
+
destructive: item.destructive,
|
|
25
|
+
})),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
key,
|
|
30
|
+
label: verb.label,
|
|
31
|
+
icon: verb.icon,
|
|
32
|
+
disabled: verb.disabled,
|
|
33
|
+
beside: true,
|
|
34
|
+
children: verb.options.map((option) => ({
|
|
35
|
+
key: `${key}-${option.value}`,
|
|
36
|
+
label: option.label,
|
|
37
|
+
disabled: verb.disabled,
|
|
38
|
+
onSelect: () => verb.onSelect(option.value),
|
|
39
|
+
})),
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { PickerOption } from "../editors/SelectEditor.js";
|
|
3
|
+
/** The pill the bar floats in: the overlay ground, the hairline and the floating drop. */
|
|
4
|
+
export declare const PILL_CLASS = "flex items-center gap-2 rounded-full border border-solid border-(color:--vk-border) bg-(color:--vk-overlay) py-1.5 pr-1.5 text-(color:--vk-fg) shadow-[var(--vk-float-shadow,0_8px_24px_rgb(0_0_0/0.12))]";
|
|
5
|
+
/** The vertical hairline between the bar's regions. */
|
|
6
|
+
export declare const DIVIDER_CLASS = "h-5 w-px bg-(color:--vk-border)";
|
|
7
|
+
/** "3 selected": the number in weight, the word quieter. */
|
|
8
|
+
export declare function CountWords({ count }: {
|
|
9
|
+
count: number;
|
|
10
|
+
}): ReactNode;
|
|
11
|
+
/** A value of an options verb as its badge: a status by its slot, a category by its colour, else its words.
|
|
12
|
+
* The same badges a cell shows, so setting status on the bar reads as setting it in a cell. */
|
|
13
|
+
export declare function OptionLabel({ option }: {
|
|
14
|
+
option: PickerOption;
|
|
15
|
+
}): ReactNode;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useViews } from "../provider/context.js";
|
|
4
|
+
export const PILL_CLASS = "flex items-center gap-2 rounded-full border border-solid border-(color:--vk-border) bg-(color:--vk-overlay) py-1.5 pr-1.5 text-(color:--vk-fg) shadow-[var(--vk-float-shadow,0_8px_24px_rgb(0_0_0/0.12))]";
|
|
5
|
+
export const DIVIDER_CLASS = "h-5 w-px bg-(color:--vk-border)";
|
|
6
|
+
export function CountWords({ count }) {
|
|
7
|
+
const { messages } = useViews();
|
|
8
|
+
return (_jsxs("span", { className: "text-sm whitespace-nowrap", children: [_jsx("span", { className: "font-semibold tabular-nums", children: count }), _jsxs("span", { className: "text-(color:--vk-fg-subtle)", children: [" ", messages({ key: "views.selection.selected" })] })] }));
|
|
9
|
+
}
|
|
10
|
+
export function OptionLabel({ option }) {
|
|
11
|
+
const { atoms } = useViews();
|
|
12
|
+
if (option.slot)
|
|
13
|
+
return _jsx(atoms.StatusBadge, { slot: option.slot, label: option.label });
|
|
14
|
+
if (option.color)
|
|
15
|
+
return _jsx(atoms.Tag, { label: option.label, color: option.color });
|
|
16
|
+
return option.label;
|
|
17
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type { ListBatchApi, ListSelectionConfig } from "./types.js";
|
|
2
|
+
export { SelectionBar, type SelectionBarProps } from "./SelectionBar.js";
|
|
3
|
+
export type { SelectionOptionsVerb, SelectionVerb, SelectionVerbItem } from "./verbs.js";
|
|
2
4
|
export { SelectCheckbox } from "./SelectCheckbox.js";
|
|
3
5
|
export { useCheckDragSelect, ROW_CHECK_ATTR } from "./useCheckDragSelect.js";
|
|
4
6
|
export { preventShiftTextSelect, selectFromClick, ROW_INTERACTIVE_SELECTOR, ROW_NO_TEXT_SELECT, ROW_OPEN_STOP_SELECTOR, } from "./row-click.js";
|
package/dist/selection/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { SelectionBar } from "./SelectionBar.js";
|
|
1
2
|
export { SelectCheckbox } from "./SelectCheckbox.js";
|
|
2
3
|
export { useCheckDragSelect, ROW_CHECK_ATTR } from "./useCheckDragSelect.js";
|
|
3
4
|
export { preventShiftTextSelect, selectFromClick, ROW_INTERACTIVE_SELECTOR, ROW_NO_TEXT_SELECT, ROW_OPEN_STOP_SELECTOR, } from "./row-click.js";
|
|
@@ -12,6 +12,7 @@ export type ListSelectionConfig = {
|
|
|
12
12
|
retention?: SelectionRetention;
|
|
13
13
|
/** Selection clears whenever this view/filter identity changes. */
|
|
14
14
|
resetKey: string;
|
|
15
|
-
/** Render the floating bar, optionally with the active renderer's
|
|
16
|
-
|
|
15
|
+
/** Render the floating bar (`SelectionBar`, with the app's verbs), optionally with the active renderer's
|
|
16
|
+
* batch API. The renderer calls it on every render, empty selection included. Absent: no bar. */
|
|
17
|
+
renderBar?: (sel: UseListSelectionResult, batch?: ListBatchApi) => ReactNode;
|
|
17
18
|
};
|