viewkitjs 0.26.0 → 0.28.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 +95 -0
- package/MIGRATION.md +122 -7
- package/package.json +1 -1
- package/views/dist/cells/cell-format.d.ts +3 -1
- package/views/dist/cells/cell-format.js +2 -2
- package/views/dist/cells/use-cell-format.d.ts +8 -1
- package/views/dist/cells/use-cell-format.js +13 -2
- package/views/dist/contract.d.ts +240 -3
- package/views/dist/contract.js +238 -0
- package/views/dist/controls/alert/alert.d.ts +46 -0
- package/views/dist/controls/alert/alert.js +11 -0
- package/views/dist/controls/alert/looks.d.ts +4 -0
- package/views/dist/controls/alert/looks.js +19 -0
- package/views/dist/controls/alert/tokens.d.ts +92 -0
- package/views/dist/controls/alert/tokens.js +25 -0
- package/views/dist/controls/alert-dialog/alert-dialog.d.ts +50 -0
- package/views/dist/controls/alert-dialog/alert-dialog.js +67 -0
- package/views/dist/controls/alert-dialog/confirm.d.ts +13 -0
- package/views/dist/controls/alert-dialog/confirm.js +11 -0
- package/views/dist/controls/alert-dialog/looks.d.ts +4 -0
- package/views/dist/controls/alert-dialog/looks.js +17 -0
- package/views/dist/controls/alert-dialog/tokens.d.ts +119 -0
- package/views/dist/controls/alert-dialog/tokens.js +32 -0
- package/views/dist/controls/alert-dialog.css +95 -0
- package/views/dist/controls/alert.css +51 -0
- package/views/dist/controls/collapsible/collapsible.d.ts +39 -0
- package/views/dist/controls/collapsible/collapsible.js +18 -0
- package/views/dist/controls/collapsible/looks.d.ts +4 -0
- package/views/dist/controls/collapsible/looks.js +5 -0
- package/views/dist/controls/collapsible/map-collapse.d.ts +2 -0
- package/views/dist/controls/collapsible/map-collapse.js +6 -0
- package/views/dist/controls/collapsible/tokens.d.ts +68 -0
- package/views/dist/controls/collapsible/tokens.js +19 -0
- package/views/dist/controls/collapsible.css +83 -0
- package/views/dist/controls/compound-editor/map-parts-body.js +2 -1
- package/views/dist/controls/compound-editor/name-parts.js +10 -2
- package/views/dist/controls/compound-editor/place-parts.js +5 -1
- package/views/dist/controls/compound-editor/place.d.ts +2 -1
- package/views/dist/controls/compound-editor/place.js +2 -0
- package/views/dist/controls/controls.d.ts +17 -0
- package/views/dist/controls/controls.js +17 -0
- package/views/dist/controls/date-editor/date-editor.d.ts +2 -1
- package/views/dist/controls/date-editor/map-calendar.js +3 -1
- package/views/dist/controls/filter-editor/filter-editor.d.ts +56 -0
- package/views/dist/controls/filter-editor/filter-editor.js +208 -0
- package/views/dist/controls/filter-editor/how.d.ts +23 -0
- package/views/dist/controls/filter-editor/how.js +13 -0
- package/views/dist/controls/filter-editor/map-filter-body.d.ts +18 -0
- package/views/dist/controls/filter-editor/map-filter-body.js +164 -0
- package/views/dist/controls/filter-editor/map-rules.d.ts +85 -0
- package/views/dist/controls/filter-editor/map-rules.js +273 -0
- package/views/dist/controls/filter-editor/parts.d.ts +46 -0
- package/views/dist/controls/filter-editor/parts.js +75 -0
- package/views/dist/controls/filter-editor/rules.d.ts +104 -0
- package/views/dist/controls/filter-editor/rules.js +148 -0
- package/views/dist/controls/filter-editor/tokens.d.ts +83 -0
- package/views/dist/controls/filter-editor/tokens.js +23 -0
- package/views/dist/controls/filter-editor/words.d.ts +59 -0
- package/views/dist/controls/filter-editor/words.js +40 -0
- package/views/dist/controls/filter-editor.css +124 -0
- package/views/dist/controls/group-editor/group-editor.d.ts +56 -0
- package/views/dist/controls/group-editor/group-editor.js +126 -0
- package/views/dist/controls/group-editor/map-group-body.d.ts +19 -0
- package/views/dist/controls/group-editor/map-group-body.js +106 -0
- package/views/dist/controls/group-editor/rules.d.ts +48 -0
- package/views/dist/controls/group-editor/rules.js +41 -0
- package/views/dist/controls/group-editor/tokens.d.ts +15 -0
- package/views/dist/controls/group-editor/tokens.js +6 -0
- package/views/dist/controls/group-editor/words.d.ts +39 -0
- package/views/dist/controls/group-editor/words.js +21 -0
- package/views/dist/controls/group-editor.css +20 -0
- package/views/dist/controls/index.d.ts +35 -1
- package/views/dist/controls/index.js +35 -1
- package/views/dist/controls/internal/editor-parts.d.ts +47 -0
- package/views/dist/controls/internal/editor-parts.js +48 -0
- package/views/dist/controls/internal/step-return.d.ts +9 -0
- package/views/dist/controls/internal/step-return.js +27 -0
- package/views/dist/controls/links-editor/links-editor.d.ts +80 -0
- package/views/dist/controls/links-editor/links-editor.js +329 -0
- package/views/dist/controls/links-editor/links.d.ts +62 -0
- package/views/dist/controls/links-editor/links.js +50 -0
- package/views/dist/controls/links-editor/map-links-body.d.ts +10 -0
- package/views/dist/controls/links-editor/map-links-body.js +74 -0
- package/views/dist/controls/links-editor/tokens.d.ts +71 -0
- package/views/dist/controls/links-editor/tokens.js +20 -0
- package/views/dist/controls/links-editor/words.d.ts +56 -0
- package/views/dist/controls/links-editor/words.js +33 -0
- package/views/dist/controls/links-editor.css +132 -0
- package/views/dist/controls/menu-list/menu-list.d.ts +17 -2
- package/views/dist/controls/menu-list/menu-list.js +25 -16
- package/views/dist/controls/modal/looks.d.ts +4 -0
- package/views/dist/controls/modal/looks.js +25 -0
- package/views/dist/controls/modal/modal.d.ts +69 -0
- package/views/dist/controls/modal/modal.js +62 -0
- package/views/dist/controls/modal/tokens.d.ts +192 -0
- package/views/dist/controls/modal/tokens.js +50 -0
- package/views/dist/controls/modal.css +130 -0
- package/views/dist/controls/notice/notice.d.ts +49 -0
- package/views/dist/controls/notice/notice.js +35 -0
- package/views/dist/controls/notice/tokens.d.ts +99 -0
- package/views/dist/controls/notice/tokens.js +27 -0
- package/views/dist/controls/notice.css +100 -0
- package/views/dist/controls/number-editor/format.d.ts +31 -0
- package/views/dist/controls/number-editor/format.js +79 -0
- package/views/dist/controls/number-editor/looks.d.ts +14 -0
- package/views/dist/controls/number-editor/looks.js +17 -0
- package/views/dist/controls/number-editor/map-number-body.d.ts +16 -0
- package/views/dist/controls/number-editor/map-number-body.js +57 -0
- package/views/dist/controls/number-editor/number-editor.d.ts +72 -0
- package/views/dist/controls/number-editor/number-editor.js +202 -0
- package/views/dist/controls/number-editor/tokens.d.ts +28 -0
- package/views/dist/controls/number-editor/tokens.js +9 -0
- package/views/dist/controls/number-editor/words.d.ts +23 -0
- package/views/dist/controls/number-editor/words.js +13 -0
- package/views/dist/controls/number-editor.css +37 -0
- package/views/dist/controls/number-field/number-field.js +57 -5
- package/views/dist/controls/pane/looks.d.ts +4 -0
- package/views/dist/controls/pane/looks.js +11 -0
- package/views/dist/controls/pane/pane.d.ts +63 -0
- package/views/dist/controls/pane/pane.js +98 -0
- package/views/dist/controls/pane/state.d.ts +14 -0
- package/views/dist/controls/pane/state.js +7 -0
- package/views/dist/controls/pane/tokens.d.ts +79 -0
- package/views/dist/controls/pane/tokens.js +22 -0
- package/views/dist/controls/pane.css +104 -0
- package/views/dist/controls/picker/rows.d.ts +4 -2
- package/views/dist/controls/picker/rows.js +4 -3
- package/views/dist/controls/radio/radio.d.ts +33 -0
- package/views/dist/controls/radio/radio.js +19 -0
- package/views/dist/controls/radio/tokens.d.ts +127 -0
- package/views/dist/controls/radio/tokens.js +34 -0
- package/views/dist/controls/radio.css +104 -0
- package/views/dist/controls/sort-editor/map-sort-body.d.ts +9 -0
- package/views/dist/controls/sort-editor/map-sort-body.js +81 -0
- package/views/dist/controls/sort-editor/rules.d.ts +48 -0
- package/views/dist/controls/sort-editor/rules.js +24 -0
- package/views/dist/controls/sort-editor/sort-editor.d.ts +58 -0
- package/views/dist/controls/sort-editor/sort-editor.js +180 -0
- package/views/dist/controls/sort-editor/tokens.d.ts +79 -0
- package/views/dist/controls/sort-editor/tokens.js +22 -0
- package/views/dist/controls/sort-editor/words.d.ts +48 -0
- package/views/dist/controls/sort-editor/words.js +25 -0
- package/views/dist/controls/sort-editor.css +96 -0
- package/views/dist/controls/text-editor/phone-number.d.ts +4 -0
- package/views/dist/controls/text-editor/phone-number.js +20 -0
- package/views/dist/controls/text-editor/text-editor.js +2 -19
- package/views/dist/controls/toast/toast.d.ts +75 -0
- package/views/dist/controls/toast/toast.js +99 -0
- package/views/dist/controls/toast/tokens.d.ts +100 -0
- package/views/dist/controls/toast/tokens.js +27 -0
- package/views/dist/controls/toast.css +93 -0
- package/views/dist/controls/tokens.js +30 -0
- package/views/dist/controls/values-editor/looks.d.ts +16 -0
- package/views/dist/controls/values-editor/looks.js +19 -0
- package/views/dist/controls/values-editor/map-values-body.d.ts +12 -0
- package/views/dist/controls/values-editor/map-values-body.js +71 -0
- package/views/dist/controls/values-editor/tokens.d.ts +132 -0
- package/views/dist/controls/values-editor/tokens.js +35 -0
- package/views/dist/controls/values-editor/values-editor.d.ts +62 -0
- package/views/dist/controls/values-editor/values-editor.js +441 -0
- package/views/dist/controls/values-editor/values.d.ts +71 -0
- package/views/dist/controls/values-editor/values.js +59 -0
- package/views/dist/controls/values-editor/words.d.ts +50 -0
- package/views/dist/controls/values-editor/words.js +29 -0
- package/views/dist/controls/values-editor.css +207 -0
- package/views/dist/controls/views-list/looks.d.ts +13 -0
- package/views/dist/controls/views-list/looks.js +12 -0
- package/views/dist/controls/views-list/map-views-list-body.d.ts +19 -0
- package/views/dist/controls/views-list/map-views-list-body.js +65 -0
- package/views/dist/controls/views-list/rules.d.ts +72 -0
- package/views/dist/controls/views-list/rules.js +4 -0
- package/views/dist/controls/views-list/tokens.d.ts +11 -0
- package/views/dist/controls/views-list/tokens.js +5 -0
- package/views/dist/controls/views-list/views-list.d.ts +44 -0
- package/views/dist/controls/views-list/views-list.js +57 -0
- package/views/dist/controls/views-list/words.d.ts +22 -0
- package/views/dist/controls/views-list/words.js +3 -0
- package/views/dist/controls/views-list.css +8 -0
- package/views/dist/display/date.js +2 -2
- package/views/dist/display/format.js +10 -2
- package/views/dist/display/options.d.ts +3 -1
- package/views/dist/display/use-display-options.d.ts +3 -0
- package/views/dist/display/use-display-options.js +10 -2
- package/views/dist/display/viewer.d.ts +1 -1
- package/views/dist/display/viewer.js +1 -1
- package/views/dist/editors/DateEditor.js +11 -9
- package/views/dist/editors/NumberEditor.js +3 -1
- package/views/dist/editors/relation-panel.js +7 -1
- package/views/dist/editors/relation-picker.d.ts +2 -1
- package/views/dist/editors/relation-picker.js +4 -3
- package/views/dist/editors/relation-source.d.ts +4 -1
- package/views/dist/editors/relation-source.js +5 -2
- package/views/dist/field-row/editors/RowNumberEditor.js +2 -2
- package/views/dist/fields/number-edit.d.ts +6 -0
- package/views/dist/fields/number-edit.js +8 -1
- package/views/dist/grid/chrome/GridCellEditors.js +3 -3
- package/views/dist/grid/chrome/GridColumnDateSection.d.ts +4 -3
- package/views/dist/grid/chrome/GridColumnDateSection.js +4 -4
- package/views/dist/grid/chrome/GridColumnDurationSection.js +2 -2
- package/views/dist/grid/chrome/GridColumnMenu.js +6 -4
- package/views/dist/grid/chrome/GridDateEditor.d.ts +3 -1
- package/views/dist/grid/chrome/GridDateEditor.js +2 -1
- package/views/dist/grid/chrome/GridFooter.js +2 -2
- package/views/dist/grid/chrome/grid-column-menu-items.js +4 -2
- package/views/dist/grid/chrome/useGridBandFigures.js +2 -2
- package/views/dist/grid/chrome/useGridFittedWidths.d.ts +3 -0
- package/views/dist/grid/chrome/useGridFittedWidths.js +9 -3
- package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -1
- package/views/dist/grid/chrome/useGridKeyboard.js +5 -2
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +2 -1
- package/views/dist/grid/core/commit-model.d.ts +7 -0
- package/views/dist/grid/core/commit-model.js +5 -1
- package/views/dist/grid/core/editing-controller.js +10 -2
- package/views/dist/grid/core/editing-model.js +3 -7
- package/views/dist/grid/core/undo-owner.d.ts +6 -0
- package/views/dist/grid/core/undo-owner.js +13 -0
- package/views/dist/grid/core/useGridEditing.d.ts +2 -0
- package/views/dist/grid/core/useGridEditing.js +4 -0
- package/views/dist/looks/index.d.ts +8 -0
- package/views/dist/looks/index.js +8 -0
- package/views/dist/looks/pieces.js +16 -0
- package/views/dist/panels/model.d.ts +6 -1
- package/views/dist/panels/react/customize-body.d.ts +4 -2
- package/views/dist/panels/react/customize-body.js +3 -3
- package/views/dist/panels/react/customize.js +4 -2
- package/views/dist/panels/react/filter/FilterEditor.js +2 -2
- package/views/dist/panels/react/filter/PhoneFilterEditor.d.ts +8 -2
- package/views/dist/panels/react/filter/PhoneFilterEditor.js +9 -6
- package/views/dist/panels/react/filter/filter-body.d.ts +8 -5
- package/views/dist/panels/react/filter/filter-body.js +17 -6
- package/views/dist/panels/react/filter/filter-part-body.d.ts +4 -1
- package/views/dist/panels/react/filter/filter-part-body.js +3 -1
- package/views/dist/panels/react/panel-sheet.d.ts +5 -1
- package/views/dist/panels/react/panel-sheet.js +6 -2
- package/views/dist/panels/react/panel-step.d.ts +12 -0
- package/views/dist/panels/react/panel-step.js +26 -0
- package/views/dist/panels/react/sort/SortEditor.d.ts +4 -0
- package/views/dist/panels/react/sort/SortEditor.js +5 -2
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +8 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +84 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.d.ts +16 -0
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +49 -0
- package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +3 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.d.ts +4 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +36 -21
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +4 -1
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarSortPill.d.ts +5 -0
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +15 -6
- package/views/dist/panels/react/toolbar/panel-part.d.ts +5 -1
- package/views/dist/panels/react/toolbar/panel-part.js +2 -2
- package/views/dist/panels/react/toolbar/use-filter-add.d.ts +16 -0
- package/views/dist/panels/react/toolbar/use-filter-add.js +32 -0
- package/views/dist/panels/react.d.ts +1 -0
- package/views/dist/panels/react.js +1 -0
- package/views/dist/panels/settings/filter-groups.js +35 -1
- package/views/dist/panels/settings/group-buckets.js +1 -0
- package/views/dist/provider/ViewsProvider.d.ts +7 -1
- package/views/dist/provider/ViewsProvider.js +23 -3
- package/views/dist/provider/components.d.ts +34 -4
- package/views/dist/provider/moment.d.ts +6 -0
- package/views/dist/provider/moment.js +10 -0
- package/views/dist/styles.css +1276 -51
- package/views/dist/styles.unlayered.css +1277 -51
- package/views/docs/contract.md +23 -15
- package/views/docs/controls/alert-dialog.md +37 -0
- package/views/docs/controls/alert.md +30 -0
- package/views/docs/controls/collapsible.md +22 -0
- package/views/docs/controls/filter-editor.md +28 -0
- package/views/docs/controls/group-editor.md +11 -0
- package/views/docs/controls/links-editor.md +25 -0
- package/views/docs/controls/modal.md +55 -0
- package/views/docs/controls/notice.md +32 -0
- package/views/docs/controls/number-editor.md +12 -0
- package/views/docs/controls/pane.md +25 -0
- package/views/docs/controls/radio.md +39 -0
- package/views/docs/controls/sort-editor.md +27 -0
- package/views/docs/controls/toast.md +32 -0
- package/views/docs/controls/values-editor.md +40 -0
- package/views/docs/controls/views-list.md +8 -0
- package/views/docs/guides/cells.md +1 -1
- package/views/docs/guides/display.md +1 -1
- package/views/docs/guides/the-grid.md +1 -1
- package/views/docs/guides/the-provider.md +19 -0
- package/views/docs/reference/cells.md +2 -2
- package/views/docs/reference/controls.md +326 -8
- package/views/docs/reference/display.md +2 -2
- package/views/docs/reference/editors-relation.md +1 -1
- package/views/docs/reference/looks.md +20 -3
- package/views/docs/reference/panels-react.md +7 -6
- package/views/docs/reference/panels.md +1 -1
- package/views/docs/reference/react.md +8 -8
- package/views/docs/reference/views.md +1 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { resolveViewsMessage } from "../../contract.js";
|
|
5
|
+
import { ViewsContext } from "../../provider/context.js";
|
|
6
|
+
import { glyph, TICK, X } from "../internal/editor-parts.js";
|
|
7
|
+
import { useToldStep } from "../internal/told-step.js";
|
|
8
|
+
import { pickerWordsOf } from "../picker/map-picker.js";
|
|
9
|
+
import { HeaderBar } from "../phone-header/header-bar.js";
|
|
10
|
+
import { SheetButton } from "../sheet/bottom-sheet.js";
|
|
11
|
+
import { useSortEditor } from "./sort-editor.js";
|
|
12
|
+
const KIT = { asc: "ascending", desc: "descending" };
|
|
13
|
+
const VIEWKIT = { ascending: "asc", descending: "desc" };
|
|
14
|
+
const BACK = ["M5 12l14 0", "M5 12l6 6", "M5 12l6 -6"];
|
|
15
|
+
function BodyHead({ title, left, right }) {
|
|
16
|
+
return (_jsx("div", { className: "o-sheet-head", "data-slot": "vk-sort-head", children: _jsx(HeaderBar, { className: "o-sheet-row", "data-sides": "", left: left, title: _jsx("h2", { className: "o-sheet-title", children: title }), right: right }) }));
|
|
17
|
+
}
|
|
18
|
+
const placeOf = (value) => (value.includes("::") ? value.slice(0, value.lastIndexOf("::")) : value);
|
|
19
|
+
export function sortEditorWordsOf(say) {
|
|
20
|
+
return {
|
|
21
|
+
field: say({ key: "views.panels.sort-field" }),
|
|
22
|
+
direction: say({ key: "views.panels.sort-direction" }),
|
|
23
|
+
ascending: say({ key: "views.panels.sort-ascending" }),
|
|
24
|
+
descending: say({ key: "views.panels.sort-descending" }),
|
|
25
|
+
sorted: say({ key: "views.panels.sort-sorted" }),
|
|
26
|
+
max: (max) => say({ key: "views.panels.sort-max", values: { max } }),
|
|
27
|
+
add: say({ key: "views.panels.sort-add" }),
|
|
28
|
+
clearAllSorts: say({ key: "views.panels.sort-clear-all-sorts" }),
|
|
29
|
+
clearAll: say({ key: "views.panels.sort-clear-all" }),
|
|
30
|
+
delete: say({ key: "views.panels.sort-delete" }),
|
|
31
|
+
move: (label) => say({ key: "views.panels.sort-move", values: { label } }),
|
|
32
|
+
remove: (label) => say({ key: "views.panels.sort-remove", values: { label } }),
|
|
33
|
+
sortBy: (label) => say({ key: "views.panels.sort-by-named", values: { label } }),
|
|
34
|
+
actionsFor: (label) => say({ key: "views.panels.sort-actions", values: { label } }),
|
|
35
|
+
none: say({ key: "views.panels.sort-empty" }),
|
|
36
|
+
noneLine: say({ key: "views.panels.sort-empty-line" }),
|
|
37
|
+
search: say({ key: "views.panels.sort-search" }),
|
|
38
|
+
back: say({ key: "views.panels.back" }),
|
|
39
|
+
close: say({ key: "views.panels.close" }),
|
|
40
|
+
save: say({ key: "views.panels.sort-done" }),
|
|
41
|
+
putBack: say({ key: "views.panels.put-back" }),
|
|
42
|
+
fieldNamed: (label) => say({ key: "views.panels.sort-field-named", values: { label } }),
|
|
43
|
+
picker: pickerWordsOf(say),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function asideOf(rule, say) {
|
|
47
|
+
const why = rule.reason === "missing-field" && rule.value !== null
|
|
48
|
+
? say({ key: "views.panels.sort-set-aside-back" })
|
|
49
|
+
: say({ key: "views.panels.sort-set-aside-why", values: { reason: rule.reason } });
|
|
50
|
+
return { key: rule.fieldKey, label: rule.label, direction: KIT[rule.dir], why, back: rule.value };
|
|
51
|
+
}
|
|
52
|
+
export function sortEditorPropsOf(p, words, say = resolveViewsMessage) {
|
|
53
|
+
const held = p.setAside;
|
|
54
|
+
return {
|
|
55
|
+
label: p.label,
|
|
56
|
+
fields: p.options.map((o) => ({ value: o.value, label: o.label, ...(o.glyph ? { as: { mark: o.glyph } } : {}) })),
|
|
57
|
+
rules: p.rules.map((r) => ({ field: r.value, direction: KIT[r.dir] })),
|
|
58
|
+
aside: held.map((r) => asideOf(r, say)),
|
|
59
|
+
max: p.max,
|
|
60
|
+
form: p.form,
|
|
61
|
+
addSort: p.addSort,
|
|
62
|
+
fieldOf: placeOf,
|
|
63
|
+
onDone: p.onDone,
|
|
64
|
+
words,
|
|
65
|
+
onRulesChange: (rules, aside) => p.onRulesChange(rules.map((r) => ({ value: r.field, dir: VIEWKIT[r.direction] })), ...(aside ? [aside.map((a) => held.find((h) => h.fieldKey === a.key)).filter((h) => !!h)] : [])),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function MapSortBody(props) {
|
|
69
|
+
const views = React.useContext(ViewsContext);
|
|
70
|
+
const messages = views?.messages ?? resolveViewsMessage;
|
|
71
|
+
const words = React.useMemo(() => sortEditorWordsOf(messages), [messages]);
|
|
72
|
+
const parts = useSortEditor(sortEditorPropsOf(props, words, messages));
|
|
73
|
+
useToldStep(parts, props.onStepChange);
|
|
74
|
+
const { actions } = props;
|
|
75
|
+
if (!actions)
|
|
76
|
+
return _jsx(_Fragment, { children: parts.body });
|
|
77
|
+
const done = actions.done && _jsx(SheetButton, { kind: "primary", "aria-label": actions.done.label, icon: glyph(TICK), onClick: actions.done.onPress });
|
|
78
|
+
return (_jsxs(_Fragment, { children: [parts.title !== undefined
|
|
79
|
+
? _jsx(BodyHead, { title: parts.title, left: _jsx(SheetButton, { "aria-label": words.back, className: "o-sheet-back", icon: glyph(BACK), onClick: parts.head.onBack }), right: done || _jsx("span", {}) })
|
|
80
|
+
: _jsx(BodyHead, { title: props.label, left: _jsx(SheetButton, { "aria-label": actions.close.label, icon: glyph(X), onClick: actions.close.onPress }), right: done || _jsx("span", {}) }), parts.body] }));
|
|
81
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type PickerItem } from "../picker/rows.js";
|
|
2
|
+
export type SortDirection = "ascending" | "descending";
|
|
3
|
+
/** One rule: the field it sorts by (one level in, its value: company.region) and its direction. */
|
|
4
|
+
export interface SortRule {
|
|
5
|
+
field: string;
|
|
6
|
+
direction: SortDirection;
|
|
7
|
+
}
|
|
8
|
+
/** The field a sort key sorts: a place's part key sorts its place. Each key its own field unless handed. */
|
|
9
|
+
export type FieldOf = (field: string) => string;
|
|
10
|
+
/** A sort set aside: its stored field key, its words, its direction, why it was set aside in words, and the sort key it sorts by
|
|
11
|
+
* once put back, null while it doesn't fit. */
|
|
12
|
+
export interface SortAside {
|
|
13
|
+
key: string;
|
|
14
|
+
label: string;
|
|
15
|
+
direction: SortDirection;
|
|
16
|
+
why: string;
|
|
17
|
+
back: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** How many rules a view sorts by, at most. */
|
|
20
|
+
export declare const SORT_MAX = 3;
|
|
21
|
+
/** The rules with one more at their end, sorting by `field`, ascending. */
|
|
22
|
+
export declare const addSort: (rules: SortRule[], field: string) => SortRule[];
|
|
23
|
+
/** Whether another rule can be added: fewer than `max`. */
|
|
24
|
+
export declare const canAddSort: (rules: SortRule[], max?: number) => boolean;
|
|
25
|
+
/** The fields the rules sort by already, each as `fieldOf` names it. */
|
|
26
|
+
export declare const sortedFields: (rules: SortRule[], fieldOf?: FieldOf) => Set<string>;
|
|
27
|
+
/** Whether another rule than the one on `own` already sorts `value`'s field. */
|
|
28
|
+
export declare const takenBy: (rules: SortRule[], value: string, own?: string, fieldOf?: FieldOf) => boolean;
|
|
29
|
+
/** The sort as the filter bar names it: its first rule's field, by its path, and how many rules follow; none, nothing. */
|
|
30
|
+
export declare function sortLabel(rules: SortRule[], fields: PickerItem[]): {
|
|
31
|
+
first: string;
|
|
32
|
+
more: number;
|
|
33
|
+
} | null;
|
|
34
|
+
/** How many rules fit: `max` less the sorts set aside, each holding one of the places. */
|
|
35
|
+
export declare const openPlaces: (max: number, aside: readonly SortAside[]) => number;
|
|
36
|
+
/** The sorts set aside without the one on `key`. */
|
|
37
|
+
export declare const dropAside: (aside: SortAside[], key: string) => SortAside[];
|
|
38
|
+
/** A sort set aside pointed at `field`: a rule on it, in the set-aside sort's direction, at the rules' end, and the sort out of the
|
|
39
|
+
* set-aside ones; null where another rule sorts that field already. */
|
|
40
|
+
export declare function repoint(rules: SortRule[], aside: SortAside[], key: string, field: string, fieldOf?: FieldOf): {
|
|
41
|
+
rules: SortRule[];
|
|
42
|
+
aside: SortAside[];
|
|
43
|
+
} | null;
|
|
44
|
+
/** A sort set aside put back on its own field; null while it doesn't fit (`back` null) or another rule sorts it. */
|
|
45
|
+
export declare function putBack(rules: SortRule[], aside: SortAside[], key: string, fieldOf?: FieldOf): {
|
|
46
|
+
rules: SortRule[];
|
|
47
|
+
aside: SortAside[];
|
|
48
|
+
} | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { itemLabel } from "../picker/rows.js";
|
|
2
|
+
const itself = (f) => f;
|
|
3
|
+
export const SORT_MAX = 3;
|
|
4
|
+
export const addSort = (rules, field) => [...rules, { field, direction: "ascending" }];
|
|
5
|
+
export const canAddSort = (rules, max = SORT_MAX) => rules.length < max;
|
|
6
|
+
export const sortedFields = (rules, fieldOf = itself) => new Set(rules.map((r) => fieldOf(r.field)));
|
|
7
|
+
export const takenBy = (rules, value, own, fieldOf = itself) => rules.some((r) => r.field !== own && fieldOf(r.field) === fieldOf(value));
|
|
8
|
+
export function sortLabel(rules, fields) {
|
|
9
|
+
if (!rules.length)
|
|
10
|
+
return null;
|
|
11
|
+
return { first: itemLabel(fields, rules[0].field), more: rules.length - 1 };
|
|
12
|
+
}
|
|
13
|
+
export const openPlaces = (max, aside) => Math.max(max - aside.length, 0);
|
|
14
|
+
export const dropAside = (aside, key) => aside.filter((a) => a.key !== key);
|
|
15
|
+
export function repoint(rules, aside, key, field, fieldOf = itself) {
|
|
16
|
+
const held = aside.find((a) => a.key === key);
|
|
17
|
+
if (!held || takenBy(rules, field, undefined, fieldOf))
|
|
18
|
+
return null;
|
|
19
|
+
return { rules: [...rules, { field, direction: held.direction }], aside: dropAside(aside, key) };
|
|
20
|
+
}
|
|
21
|
+
export function putBack(rules, aside, key, fieldOf = itself) {
|
|
22
|
+
const back = aside.find((a) => a.key === key)?.back;
|
|
23
|
+
return back == null ? null : repoint(rules, aside, key, back, fieldOf);
|
|
24
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type PickerItem } from "../picker/picker.js";
|
|
3
|
+
import type { SheetHeadProps } from "../sheet/bottom-sheet.js";
|
|
4
|
+
import { type FieldOf, type SortAside, type SortRule } from "./rules.js";
|
|
5
|
+
import { type SortEditorWords } from "./words.js";
|
|
6
|
+
export type { SortAside, SortDirection, SortRule } from "./rules.js";
|
|
7
|
+
/** What a page shows standing open: a rule's field or direction, by its place (on a phone the direction's step). */
|
|
8
|
+
export type SortEditorOpens = {
|
|
9
|
+
list: "field" | "direction";
|
|
10
|
+
rule: number;
|
|
11
|
+
};
|
|
12
|
+
export interface SortEditorProps {
|
|
13
|
+
/** What it sorts, as its shell names it ("Sort"): the Sheet's title on a phone, and the rules' name to a screen reader. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** The fields a list sorts by, each with its type's mark; one leading one level in (a deal's Company) holds its own. */
|
|
16
|
+
fields: PickerItem[];
|
|
17
|
+
/** The view's rules, the first sorting first. */
|
|
18
|
+
rules: SortRule[];
|
|
19
|
+
/** Each change, as it is made: a rule added, moved, changed or taken away; and, when a sort set aside is pointed at a field, put
|
|
20
|
+
* back or deleted, the set-aside sorts left. */
|
|
21
|
+
onRulesChange: (rules: SortRule[], aside?: SortAside[]) => void;
|
|
22
|
+
/** The sorts set aside, after the rules: each holds one of the places until it is pointed at a field, put back or deleted. */
|
|
23
|
+
aside?: readonly SortAside[];
|
|
24
|
+
/** How many rules at most; three unless said. */
|
|
25
|
+
max?: number;
|
|
26
|
+
/** Which form; by default the phone's in a phone's window or in a PhoneHost screen, else the computer's. `narrow`, on a computer
|
|
27
|
+
* in a narrow place (Customize's Sort, in the Pane): the phone's structure at a computer's sizes. */
|
|
28
|
+
form?: "computer" | "phone" | "narrow";
|
|
29
|
+
/** The job is done and what holds it closes: ✓, or ✕ once the rules are back, on a phone. */
|
|
30
|
+
onDone?: () => void;
|
|
31
|
+
/** What the fields' search says before anything is typed ("Search deal fields"); the words' `search` unless said. */
|
|
32
|
+
search?: string;
|
|
33
|
+
/** For a page that shows a state, standing still: a rule held by its grip (its place); a list standing open, with a level open in
|
|
34
|
+
* the fields (its row's value). Nothing takes the focus. */
|
|
35
|
+
lifted?: number;
|
|
36
|
+
opens?: SortEditorOpens;
|
|
37
|
+
level?: string;
|
|
38
|
+
/** The field a sort key sorts, so a place sorts once, by one of its parts; each key its own field unless handed. */
|
|
39
|
+
fieldOf?: FieldOf;
|
|
40
|
+
/** On a computer, Add sort at the foot: what holds it has no + of its own to add a rule with. True unless said. */
|
|
41
|
+
addSort?: boolean;
|
|
42
|
+
/** Its words; English unless handed. */
|
|
43
|
+
words?: Partial<SortEditorWords>;
|
|
44
|
+
}
|
|
45
|
+
export interface SortEditorParts {
|
|
46
|
+
body: React.ReactNode;
|
|
47
|
+
/** On a phone, the Sheet head's ✕ and ✓, or on a step its Back (`onBack`) alone; {} on a computer and in the narrow form. */
|
|
48
|
+
head: Pick<SheetHeadProps, "close" | "left" | "right" | "onBack">;
|
|
49
|
+
/** On a phone's step, its title: Add sort, or the rule's field's name; absent off a step. */
|
|
50
|
+
title?: string;
|
|
51
|
+
}
|
|
52
|
+
/** The fields as a list's Sort offers them to add a rule: those the rules sort by already greyed with "Sorted", one level in too
|
|
53
|
+
* (what Sort on the row's right, and on the filter bar the empty Sort, open on a computer, KIT-623). */
|
|
54
|
+
export declare const sortableFields: (fields: PickerItem[], rules: SortRule[], fieldOf?: FieldOf, sorted?: string) => PickerItem[];
|
|
55
|
+
/** The sort editor's state and the parts a shell pours in. */
|
|
56
|
+
export declare function useSortEditor(props: SortEditorProps): SortEditorParts;
|
|
57
|
+
/** The body alone, for a shell that holds only a body (the Popover). */
|
|
58
|
+
export declare function SortEditor(props: SortEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Button } from "../button/button.js";
|
|
5
|
+
import { FieldRows, FieldRowsRow as FieldRow } from "../field/field.js";
|
|
6
|
+
import { Grip } from "../grip/grip.js";
|
|
7
|
+
import { asSelect, DOTS, DOTS_LOOK, DOTS_UP, glyph, MORE_LOOK, PLUS, TRASH, useDecide, useStandingRoom, X } from "../internal/editor-parts.js";
|
|
8
|
+
import { PhoneHost, phoneMark, usePhone } from "../internal/phone.js";
|
|
9
|
+
import { moved, useReorder } from "../internal/reorder.js";
|
|
10
|
+
import { useStepReturn } from "../internal/step-return.js";
|
|
11
|
+
import { Menu } from "../menu/menu.js";
|
|
12
|
+
import { Picker, usePicker } from "../picker/picker.js";
|
|
13
|
+
import { findItem, itemLabel } from "../picker/rows.js";
|
|
14
|
+
import { Popover } from "../popover/popover.js";
|
|
15
|
+
import { Select } from "../select/select.js";
|
|
16
|
+
import { Tooltip } from "../tooltip/tooltip.js";
|
|
17
|
+
import { addSort, canAddSort, dropAside, openPlaces, putBack, repoint, SORT_MAX, takenBy } from "./rules.js";
|
|
18
|
+
import { sortWords } from "./words.js";
|
|
19
|
+
const ASCENDING = ["M4 6l7 0", "M4 12l7 0", "M4 18l9 0", "M15 9l3 -3l3 3", "M18 6l0 12"];
|
|
20
|
+
const DESCENDING = ["M4 6l9 0", "M4 12l7 0", "M4 18l7 0", "M15 15l3 3l3 -3", "M18 6l0 12"];
|
|
21
|
+
const markOf = (paths) => _jsx("span", { className: "o-sort-editor-mark", children: glyph(paths) });
|
|
22
|
+
const directionsOf = (w) => [
|
|
23
|
+
{ value: "ascending", label: w.ascending, as: { mark: markOf(ASCENDING) } },
|
|
24
|
+
{ value: "descending", label: w.descending, as: { mark: markOf(DESCENDING) } },
|
|
25
|
+
];
|
|
26
|
+
const isDirection = (v) => v === "ascending" || v === "descending";
|
|
27
|
+
const X_LOOK = { radius: "sm", corner: "round", edge: "none", words: "inherit", colour: "faint", icon: "16" };
|
|
28
|
+
const ROWS = { cards: "one", edge: "on", height: "56", label: "none", lines: "words" };
|
|
29
|
+
function fieldsFor(fields, rules, sorted, own, fieldOf) {
|
|
30
|
+
return fields.map((f) => (f.level ? { ...f, level: fieldsFor(f.level, rules, sorted, own, fieldOf) }
|
|
31
|
+
: f.value !== own && takenBy(rules, f.value, own, fieldOf) ? { ...f, disabled: true, line: sorted } : f));
|
|
32
|
+
}
|
|
33
|
+
export const sortableFields = (fields, rules, fieldOf, sorted = sortWords().sorted) => fieldsFor(fields, rules, sorted, undefined, fieldOf);
|
|
34
|
+
export function useSortEditor(props) {
|
|
35
|
+
const { label, fields, rules, onRulesChange, max = SORT_MAX, onDone, opens, fieldOf, addSort: adds = true } = props;
|
|
36
|
+
const aside = React.useMemo(() => props.aside ?? [], [props.aside]);
|
|
37
|
+
const w = sortWords(props.words), search = props.search ?? w.search, DIRECTIONS = directionsOf(w);
|
|
38
|
+
const words = w.picker ? { words: w.picker } : {};
|
|
39
|
+
const screen = React.useContext(PhoneHost), small = usePhone(), way = props.form ?? (screen || small ? "phone" : "computer");
|
|
40
|
+
const phone = way === "phone", narrow = way === "narrow";
|
|
41
|
+
const now = React.useRef(rules), asideNow = React.useRef(aside);
|
|
42
|
+
React.useLayoutEffect(() => { now.current = rules; asideNow.current = aside; });
|
|
43
|
+
const change = (next) => { now.current = next; onRulesChange(next); };
|
|
44
|
+
const write = (out) => { if (!out)
|
|
45
|
+
return; now.current = out.rules; asideNow.current = out.aside; onRulesChange(out.rules, out.aside); };
|
|
46
|
+
const repointed = React.useRef(null);
|
|
47
|
+
const pointAt = (key) => (v) => { if (typeof v === "string") {
|
|
48
|
+
repointed.current = v;
|
|
49
|
+
write(repoint(now.current, [...asideNow.current], key, v, fieldOf));
|
|
50
|
+
} };
|
|
51
|
+
const backOn = (key) => write(putBack(now.current, [...asideNow.current], key, fieldOf));
|
|
52
|
+
const drop = (key) => { const left = dropAside([...asideNow.current], key); asideNow.current = left; onRulesChange(now.current, left); };
|
|
53
|
+
const can = canAddSort(rules, openPlaces(max, aside));
|
|
54
|
+
const nameOf = (field) => itemLabel(fields, field);
|
|
55
|
+
const markFor = (field) => { const as = findItem(fields, field)?.item.as; return as && "mark" in as ? as.mark : null; };
|
|
56
|
+
const pickable = (own) => fieldsFor(fields, rules, w.sorted, own, fieldOf);
|
|
57
|
+
const free = (v) => !takenBy(now.current, v, undefined, fieldOf);
|
|
58
|
+
const dragged = React.useRef(false), [moving, setMoving] = React.useState(false);
|
|
59
|
+
const { gripProps, lift, dragging } = useReorder({ count: rules.length, grip: phone || narrow ? ".o-sort-editor-press" : ".o-sort-editor-grip",
|
|
60
|
+
onMove: (from, to) => { dragged.current = true; setMoving(true); change(moved(now.current, from, to)); } });
|
|
61
|
+
const liftedAt = (i) => ((dragging === i && (!narrow || moving)) || props.lifted === i ? "" : undefined);
|
|
62
|
+
const [root, setRoot] = React.useState(null);
|
|
63
|
+
const [refocus, setRefocus] = React.useState(null);
|
|
64
|
+
React.useLayoutEffect(() => {
|
|
65
|
+
if (refocus == null || !root)
|
|
66
|
+
return;
|
|
67
|
+
setRefocus(null);
|
|
68
|
+
const xs = root.querySelectorAll(".o-sort-editor-remove");
|
|
69
|
+
(xs[refocus] ?? xs[xs.length - 1])?.focus({ preventScroll: true });
|
|
70
|
+
}, [refocus, root]);
|
|
71
|
+
const remove = (i) => { root?.focus({ preventScroll: true }); change(now.current.filter((_, k) => k !== i)); setRefocus(i); };
|
|
72
|
+
const held = React.useMemo(() => ({ get current() { return { rules: now.current, aside: asideNow.current }; } }), []);
|
|
73
|
+
const restore = (was) => {
|
|
74
|
+
now.current = was.rules;
|
|
75
|
+
asideNow.current = was.aside;
|
|
76
|
+
if (props.aside)
|
|
77
|
+
onRulesChange(was.rules, [...was.aside]);
|
|
78
|
+
else
|
|
79
|
+
onRulesChange(was.rules);
|
|
80
|
+
};
|
|
81
|
+
const decide = useDecide(held, restore, onDone, { close: w.close, save: w.save }), placed = decide.place;
|
|
82
|
+
const placeRoot = React.useCallback((el) => { setRoot(el); placed(el); }, [placed]);
|
|
83
|
+
const room = useStandingRoom(root, "[data-sort-shown]", phone, [opens]);
|
|
84
|
+
const [pop, setPop] = React.useState(null);
|
|
85
|
+
const shownList = (items, value, name, searched) => (_jsx("div", { className: "o-sort-editor-shown o-list o-smooth o-smooth-ease", "data-sort-shown": "list", ...phoneMark(small), children: _jsx(Picker, { label: name, items: items, value: value, onValueChange: () => { }, search: searched ? search : undefined, searchShown: searched, form: "computer", standing: true, defaultLevel: props.level, ...words }) }));
|
|
86
|
+
const addField = (v) => { if (typeof v === "string" && free(v))
|
|
87
|
+
change(addSort(now.current, v)); };
|
|
88
|
+
const turn = (i) => (v) => { if (isDirection(v) && now.current[i] && now.current[i].direction !== v)
|
|
89
|
+
change(now.current.map((x, k) => (k === i ? { ...x, direction: v } : x))); };
|
|
90
|
+
const [step, setStep] = React.useState(() => (phone && opens?.list === "direction" ? { list: "direction", rule: opens.rule } : null));
|
|
91
|
+
const back = () => setStep(null);
|
|
92
|
+
const asideAt = (key) => `[data-aside-key="${CSS.escape(key)}"] .o-sort-editor-press`;
|
|
93
|
+
useStepReturn(root, !phone || !step ? [] : [step.list === "add" ? ".o-sort-editor-add"
|
|
94
|
+
: step.list === "direction" ? `.o-sort-editor-rule[data-row="${step.rule}"] .o-sort-editor-press`
|
|
95
|
+
: ((key) => (r) => {
|
|
96
|
+
const at = repointed.current == null ? -1 : now.current.findIndex((x) => x.field === repointed.current);
|
|
97
|
+
return (at >= 0 ? r.querySelector(`.o-sort-editor-rule[data-row="${at}"] .o-sort-editor-press`) : null)
|
|
98
|
+
?? r.querySelector(asideAt(key)) ?? r.querySelector(".o-sort-editor-add");
|
|
99
|
+
})(step.key)]);
|
|
100
|
+
const stepRule = step?.list === "direction" ? rules[step.rule] : undefined;
|
|
101
|
+
const stepAside = step?.list === "repoint" ? aside.find((a) => a.key === step.key) : undefined;
|
|
102
|
+
const stepList = usePicker(step?.list === "direction" && stepRule
|
|
103
|
+
? { label: nameOf(stepRule.field), items: DIRECTIONS, value: stepRule.direction, searchShown: false, form: "phone", onDone: back,
|
|
104
|
+
onValueChange: (v) => { turn(step.rule)(v); back(); }, ...words }
|
|
105
|
+
: { label: stepAside ? w.fieldNamed(stepAside.label) : w.add, items: pickable(), value: null, search, searchShown: true, defaultLevel: props.level, form: "phone", onDone: back,
|
|
106
|
+
onValueChange: (v) => { if (stepAside)
|
|
107
|
+
pointAt(stepAside.key)(v);
|
|
108
|
+
else
|
|
109
|
+
addField(v); back(); }, ...words });
|
|
110
|
+
React.useEffect(() => { if (step && step.list !== "add" && !stepRule && !(step.list === "repoint" && aside.some((a) => a.key === step.key)))
|
|
111
|
+
setStep(null); }, [step, stepRule, aside]);
|
|
112
|
+
const stepTitle = phone && step ? (stepRule ? nameOf(stepRule.field) : stepAside ? w.fieldNamed(stepAside.label) : step.list === "add" ? w.add : undefined) : undefined;
|
|
113
|
+
const addButton = (size) => (_jsx(Tooltip, { label: w.max(max), reason: true, side: "top", disabled: can, children: _jsx(Button, { kind: "outline", size: size, icon: glyph(PLUS), className: "o-sort-editor-add", disabled: !can, focusableWhenDisabled: true, "aria-haspopup": phone ? undefined : "dialog", "aria-expanded": phone ? undefined : pop?.list === "add", onClick: (e) => { const at = e.currentTarget; if (phone)
|
|
114
|
+
setStep({ list: "add" });
|
|
115
|
+
else
|
|
116
|
+
setPop((p) => (p?.list === "add" ? null : { list: "add", rule: -1, at })); }, children: w.add }) }));
|
|
117
|
+
const closePop = () => setPop(null);
|
|
118
|
+
const addPicker = _jsx(Picker, { label: w.add, items: pickable(), value: null, search: search, searchShown: true, form: "computer", defaultLevel: props.level, onDone: closePop, onValueChange: (v) => { addField(v); }, ...words });
|
|
119
|
+
const asideEntries = (a) => [
|
|
120
|
+
{ icon: null, label: a.why, disabled: a.why },
|
|
121
|
+
...(a.back != null ? [{ icon: null, label: w.putBack, onSelect: () => backOn(a.key) }] : []),
|
|
122
|
+
{ icon: glyph(TRASH), label: w.delete, danger: true, onSelect: () => drop(a.key) },
|
|
123
|
+
];
|
|
124
|
+
if (phone || narrow) {
|
|
125
|
+
const size = phone ? "44" : "sm";
|
|
126
|
+
const more = (name) => (phone
|
|
127
|
+
? _jsx(Button, { kind: "quiet", shape: "icon", size: "40x44", look: DOTS_LOOK, className: "o-sort-editor-more", "aria-label": w.actionsFor(name), icon: glyph(DOTS) })
|
|
128
|
+
: _jsx(Button, { kind: "quiet", shape: "icon", size: "xs", look: MORE_LOOK, className: "o-sort-editor-more", "aria-label": w.actionsFor(name), icon: glyph(DOTS_UP) }));
|
|
129
|
+
const ruleRow = (r, i) => {
|
|
130
|
+
const name = nameOf(r.field), mark = markFor(r.field), g = gripProps(i), standing = narrow && opens?.list === "direction" && opens.rule === i;
|
|
131
|
+
const inner = _jsxs(_Fragment, { children: [_jsxs("button", { type: "button", className: "o-sort-editor-press", ...g, onPointerDown: (e) => { dragged.current = false; setMoving(false); g.onPointerDown(e); }, "aria-haspopup": narrow ? "dialog" : undefined, "aria-expanded": narrow ? pop?.list === "direction" && pop.rule === i : undefined, onClick: (e) => {
|
|
132
|
+
if (dragged.current) {
|
|
133
|
+
dragged.current = false;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const at = e.currentTarget;
|
|
137
|
+
if (narrow)
|
|
138
|
+
setPop((p) => (p?.list === "direction" && p.rule === i ? null : { list: "direction", rule: i, at }));
|
|
139
|
+
else
|
|
140
|
+
setStep({ list: "direction", rule: i });
|
|
141
|
+
}, children: [mark, _jsxs("span", { className: "o-sort-editor-words", children: [_jsx("span", { className: "o-sort-editor-name", children: name }), _jsx("span", { className: "o-sort-editor-way", children: r.direction === "ascending" ? w.ascending : w.descending })] })] }), _jsx(Menu, { label: w.sortBy(name), align: "end", entries: [{ icon: glyph(TRASH), label: w.delete, danger: true, onSelect: () => change(now.current.filter((_, k) => k !== i)) }], trigger: more(name) }), standing && shownList(DIRECTIONS, r.direction, w.direction, false)] });
|
|
142
|
+
return phone
|
|
143
|
+
? _jsx(FieldRow, { as: "div", role: "listitem", className: "o-sort-editor-rule", "data-row": i, "data-lifted": liftedAt(i), style: lift(i), children: inner }, r.field)
|
|
144
|
+
: _jsx("div", { role: "listitem", className: "o-sort-editor-rule", "data-row": i, "data-lifted": liftedAt(i), style: lift(i), children: inner }, r.field);
|
|
145
|
+
};
|
|
146
|
+
const asideRow = (a) => {
|
|
147
|
+
const inner = _jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "o-sort-editor-press", "aria-haspopup": narrow ? "dialog" : undefined, "aria-expanded": narrow ? pop?.list === "repoint" && pop.key === a.key : undefined, onClick: (e) => { const at = e.currentTarget; if (narrow)
|
|
148
|
+
setPop((p) => (p?.list === "repoint" && p.key === a.key ? null : { list: "repoint", rule: -1, key: a.key, at }));
|
|
149
|
+
else {
|
|
150
|
+
repointed.current = null;
|
|
151
|
+
setStep({ list: "repoint", key: a.key });
|
|
152
|
+
} }, children: _jsxs("span", { className: "o-sort-editor-words", children: [_jsx("span", { className: "o-sort-editor-name", children: a.label }), _jsx("span", { className: "o-sort-editor-way", children: a.why })] }) }), _jsx(Menu, { label: w.sortBy(a.label), align: "end", entries: asideEntries(a), trigger: more(a.label) })] });
|
|
153
|
+
return phone
|
|
154
|
+
? _jsx(FieldRow, { as: "div", role: "listitem", className: "o-sort-editor-rule o-sort-editor-aside", "data-aside": "", "data-aside-key": a.key, children: inner }, `aside-${a.key}`)
|
|
155
|
+
: _jsx("div", { role: "listitem", className: "o-sort-editor-rule o-sort-editor-aside", "data-aside": "", "data-aside-key": a.key, children: inner }, `aside-${a.key}`);
|
|
156
|
+
};
|
|
157
|
+
const popRule = pop?.list === "direction" ? rules[pop.rule] : undefined;
|
|
158
|
+
const popAside = pop?.list === "repoint" ? aside.find((a) => a.key === pop.key) : undefined;
|
|
159
|
+
const body = (_jsxs("div", { ref: placeRoot, className: "o-sort-editor", "data-kit": "sort-editor", "data-sort-form": way, role: narrow ? "group" : undefined, "aria-label": narrow ? label : undefined, tabIndex: -1, style: room ? { paddingBottom: room } : undefined, ...phoneMark(!!screen || small), "data-sort-step": stepTitle !== undefined ? step?.list : undefined, children: [stepTitle !== undefined ? stepList.body : _jsxs(_Fragment, { children: [rules.length || aside.length ? (phone
|
|
160
|
+
? _jsxs(FieldRows, { look: ROWS, className: "o-sort-editor-card", role: "list", "aria-label": label, children: [rules.map(ruleRow), aside.map(asideRow)] })
|
|
161
|
+
: _jsxs("div", { className: "o-sort-editor-rules", role: "list", "aria-label": label, children: [rules.map(ruleRow), aside.map(asideRow)] })) : (_jsxs("div", { className: "o-sort-editor-none", children: [_jsx("p", { className: "o-sort-editor-none-head", children: w.none }), _jsx("p", { className: "o-sort-editor-none-line", children: w.noneLine })] })), _jsxs("div", { className: "o-sort-editor-acts", children: [addButton(size), rules.length > 0 && _jsx(Button, { kind: "quiet", size: size, className: "o-sort-editor-clear", onClick: () => change([]), children: w.clearAll })] })] }), narrow && (_jsx(Popover, { open: !!pop && (pop.list === "add" || !!popRule || !!popAside), onOpenChange: (o) => { if (!o)
|
|
162
|
+
closePop(); }, anchor: pop?.at, className: "o-sort-editor-pop", "aria-label": pop?.list === "add" ? w.add : popAside ? w.fieldNamed(popAside.label) : popRule ? nameOf(popRule.field) : label, children: pop?.list === "add"
|
|
163
|
+
? addPicker
|
|
164
|
+
: popAside ? _jsx(Picker, { label: w.fieldNamed(popAside.label), items: pickable(), value: null, search: search, searchShown: true, form: "computer", defaultLevel: props.level, onDone: closePop, onValueChange: (v) => { pointAt(popAside.key)(v); closePop(); }, ...words })
|
|
165
|
+
: popRule && _jsx(Picker, { label: nameOf(popRule.field), items: DIRECTIONS, value: popRule.direction, searchShown: false, form: "computer", fromHeld: true, onDone: closePop, onValueChange: turn(pop?.rule ?? -1), ...words }) }))] }));
|
|
166
|
+
return { body, head: !phone ? {} : stepTitle !== undefined ? { onBack: back } : decide.head, ...(stepTitle !== undefined ? { title: stepTitle } : {}) };
|
|
167
|
+
}
|
|
168
|
+
const body = (_jsx("div", { ref: placeRoot, className: "o-sort-editor", "data-kit": "sort-editor", "data-sort-form": "computer", role: "group", "aria-label": label, tabIndex: -1, style: room ? { paddingBottom: room } : undefined, ...phoneMark(!!screen || small), children: (rules.length > 0 || aside.length > 0) && _jsxs(_Fragment, { children: [_jsxs("div", { className: "o-sort-editor-rules", role: "list", "aria-label": label, children: [rules.map((r, i) => {
|
|
169
|
+
const name = nameOf(r.field), g = gripProps(i), open = opens?.rule === i ? opens.list : null;
|
|
170
|
+
const items = pickable(r.field);
|
|
171
|
+
return (_jsxs("div", { role: "listitem", className: "o-sort-editor-rule", "data-row": i, "data-lifted": liftedAt(i), style: lift(i), children: [_jsx(Grip, { label: w.move(name), className: "o-sort-editor-grip", ...g }), _jsxs("div", { className: "o-sort-editor-field", children: [_jsx(Select, { size: "xs", listWidth: "rows", "aria-label": w.field, items: asSelect(items), value: r.field, search: search, "data-force": open === "field" ? "focus" : undefined, onValueChange: (v) => { if (typeof v === "string" && v !== r.field && !takenBy(now.current, v, r.field, fieldOf))
|
|
172
|
+
change(now.current.map((x, k) => (k === i ? { ...x, field: v } : x))); } }), open === "field" && shownList(items, r.field, w.field, true)] }), _jsxs("div", { className: "o-sort-editor-direction", children: [_jsx(Select, { size: "xs", listWidth: "rows", "aria-label": w.direction, items: asSelect(DIRECTIONS), value: r.direction, "data-force": open === "direction" ? "focus" : undefined, onValueChange: turn(i) }), open === "direction" && shownList(DIRECTIONS, r.direction, w.direction, false)] }), _jsx(Button, { kind: "quiet", shape: "icon", size: "2xs", look: X_LOOK, className: "o-sort-editor-remove", "aria-label": w.remove(name), icon: glyph(X), onClick: () => remove(i) })] }, r.field));
|
|
173
|
+
}), aside.map((a) => (_jsxs("div", { role: "listitem", className: "o-sort-editor-rule o-sort-editor-aside", "data-aside": "", "data-aside-key": a.key, children: [_jsx("span", { className: "o-sort-editor-grip-place", "aria-hidden": "true" }), _jsx("div", { className: "o-sort-editor-field", children: _jsx(Tooltip, { label: a.why, side: "bottom", children: _jsx("span", { className: "o-sort-editor-why", children: _jsx(Select, { size: "xs", listWidth: "rows", "aria-label": w.fieldNamed(a.label), items: asSelect(pickable()), value: null, placeholder: a.label, search: search, onValueChange: pointAt(a.key) }) }) }) }), _jsx("div", { className: "o-sort-editor-direction", children: _jsx(Tooltip, { label: a.why, side: "bottom", children: _jsx("span", { className: "o-sort-editor-why", children: _jsx(Select, { size: "xs", listWidth: "rows", "aria-label": w.direction, items: asSelect(DIRECTIONS), value: a.direction, disabled: true, onValueChange: () => { } }) }) }) }), _jsx(Menu, { label: w.sortBy(a.label), align: "end", entries: asideEntries(a), trigger: _jsx(Button, { kind: "quiet", shape: "icon", size: "2xs", look: X_LOOK, className: "o-sort-editor-more", "aria-label": w.actionsFor(a.label), icon: glyph(DOTS) }) })] }, `aside-${a.key}`)))] }), (adds || rules.length > 0) && _jsxs("div", { className: "o-sort-editor-foot", children: [adds && addButton("sm"), rules.length > 0 && _jsx(Button, { kind: "quiet", size: "sm", className: "o-sort-editor-clear", onClick: () => { closePop(); change([]); if (!asideNow.current.length)
|
|
174
|
+
onDone?.(); }, children: w.clearAllSorts })] }), _jsx(Popover, { open: pop?.list === "add", onOpenChange: (o) => { if (!o)
|
|
175
|
+
closePop(); }, anchor: pop?.at, className: "o-sort-editor-pop", "aria-label": w.add, children: pop?.list === "add" && addPicker })] }) }));
|
|
176
|
+
return { body, head: {} };
|
|
177
|
+
}
|
|
178
|
+
export function SortEditor(props) {
|
|
179
|
+
return _jsx(_Fragment, { children: useSortEditor(props).body });
|
|
180
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare const SORT_EDITOR_TOKENS: readonly [{
|
|
2
|
+
readonly name: "--vk-border-brand";
|
|
3
|
+
readonly kind: "colour";
|
|
4
|
+
readonly outright: "--border-focused";
|
|
5
|
+
}, {
|
|
6
|
+
readonly name: "--vk-border-warning";
|
|
7
|
+
readonly kind: "colour";
|
|
8
|
+
readonly outright: "--border-warning";
|
|
9
|
+
}, {
|
|
10
|
+
readonly name: "--vk-border-width";
|
|
11
|
+
readonly kind: "size";
|
|
12
|
+
readonly outright: "--border-width";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "--vk-fg";
|
|
15
|
+
readonly kind: "colour";
|
|
16
|
+
readonly outright: "--text";
|
|
17
|
+
}, {
|
|
18
|
+
readonly name: "--vk-fg-subtle";
|
|
19
|
+
readonly kind: "colour";
|
|
20
|
+
readonly outright: "--text-subtle";
|
|
21
|
+
}, {
|
|
22
|
+
readonly name: "--vk-font-size-base";
|
|
23
|
+
readonly kind: "size";
|
|
24
|
+
readonly outright: "--text-base";
|
|
25
|
+
}, {
|
|
26
|
+
readonly name: "--vk-font-size-sm";
|
|
27
|
+
readonly kind: "size";
|
|
28
|
+
readonly outright: "--text-sm";
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "--vk-font-size-xs";
|
|
31
|
+
readonly kind: "size";
|
|
32
|
+
readonly outright: "--text-xs";
|
|
33
|
+
}, {
|
|
34
|
+
readonly name: "--vk-font-weight-medium";
|
|
35
|
+
readonly kind: "size";
|
|
36
|
+
readonly outright: "--font-weight-medium";
|
|
37
|
+
}, {
|
|
38
|
+
readonly name: "--vk-layer-popup";
|
|
39
|
+
readonly kind: "size";
|
|
40
|
+
readonly outright: "--layer-popup";
|
|
41
|
+
}, {
|
|
42
|
+
readonly name: "--vk-line-height-base";
|
|
43
|
+
readonly kind: "size";
|
|
44
|
+
readonly outright: "--text-base--line-height";
|
|
45
|
+
}, {
|
|
46
|
+
readonly name: "--vk-line-height-sm";
|
|
47
|
+
readonly kind: "size";
|
|
48
|
+
readonly outright: "--text-sm--line-height";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "--vk-line-height-xs";
|
|
51
|
+
readonly kind: "size";
|
|
52
|
+
readonly outright: "--text-xs--line-height";
|
|
53
|
+
}, {
|
|
54
|
+
readonly name: "--vk-overlay";
|
|
55
|
+
readonly kind: "colour";
|
|
56
|
+
readonly outright: "--surface-overlay";
|
|
57
|
+
}, {
|
|
58
|
+
readonly name: "--vk-overlay-hovered";
|
|
59
|
+
readonly kind: "colour";
|
|
60
|
+
readonly outright: "--surface-overlay-hovered";
|
|
61
|
+
}, {
|
|
62
|
+
readonly name: "--vk-radius-md";
|
|
63
|
+
readonly kind: "size";
|
|
64
|
+
readonly outright: "--radius-md";
|
|
65
|
+
}, {
|
|
66
|
+
readonly name: "--vk-shadow-lg";
|
|
67
|
+
readonly kind: "shadow";
|
|
68
|
+
readonly outright: "--shadow-lg";
|
|
69
|
+
}, {
|
|
70
|
+
readonly name: "--vk-spacing";
|
|
71
|
+
readonly kind: "size";
|
|
72
|
+
readonly outright: "--spacing";
|
|
73
|
+
}, {
|
|
74
|
+
readonly name: "--vk-warning";
|
|
75
|
+
readonly kind: "colour";
|
|
76
|
+
readonly outright: "--text-warning";
|
|
77
|
+
}];
|
|
78
|
+
/** The prefixes of the sort editor's own machinery, set and read by it alone: none. */
|
|
79
|
+
export declare const SORT_EDITOR_PRIVATE: readonly [];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const SORT_EDITOR_TOKENS = [
|
|
2
|
+
{ name: "--vk-border-brand", kind: "colour", outright: "--border-focused" },
|
|
3
|
+
{ name: "--vk-border-warning", kind: "colour", outright: "--border-warning" },
|
|
4
|
+
{ name: "--vk-border-width", kind: "size", outright: "--border-width" },
|
|
5
|
+
{ name: "--vk-fg", kind: "colour", outright: "--text" },
|
|
6
|
+
{ name: "--vk-fg-subtle", kind: "colour", outright: "--text-subtle" },
|
|
7
|
+
{ name: "--vk-font-size-base", kind: "size", outright: "--text-base" },
|
|
8
|
+
{ name: "--vk-font-size-sm", kind: "size", outright: "--text-sm" },
|
|
9
|
+
{ name: "--vk-font-size-xs", kind: "size", outright: "--text-xs" },
|
|
10
|
+
{ name: "--vk-font-weight-medium", kind: "size", outright: "--font-weight-medium" },
|
|
11
|
+
{ name: "--vk-layer-popup", kind: "size", outright: "--layer-popup" },
|
|
12
|
+
{ name: "--vk-line-height-base", kind: "size", outright: "--text-base--line-height" },
|
|
13
|
+
{ name: "--vk-line-height-sm", kind: "size", outright: "--text-sm--line-height" },
|
|
14
|
+
{ name: "--vk-line-height-xs", kind: "size", outright: "--text-xs--line-height" },
|
|
15
|
+
{ name: "--vk-overlay", kind: "colour", outright: "--surface-overlay" },
|
|
16
|
+
{ name: "--vk-overlay-hovered", kind: "colour", outright: "--surface-overlay-hovered" },
|
|
17
|
+
{ name: "--vk-radius-md", kind: "size", outright: "--radius-md" },
|
|
18
|
+
{ name: "--vk-shadow-lg", kind: "shadow", outright: "--shadow-lg" },
|
|
19
|
+
{ name: "--vk-spacing", kind: "size", outright: "--spacing" },
|
|
20
|
+
{ name: "--vk-warning", kind: "colour", outright: "--text-warning" },
|
|
21
|
+
];
|
|
22
|
+
export const SORT_EDITOR_PRIVATE = [];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PickerWords } from "../picker/picker.js";
|
|
2
|
+
export interface SortEditorWords {
|
|
3
|
+
/** A rule's field box, to a screen reader. */
|
|
4
|
+
field: string;
|
|
5
|
+
/** A rule's direction box, to a screen reader, and its list's name. */
|
|
6
|
+
direction: string;
|
|
7
|
+
ascending: string;
|
|
8
|
+
descending: string;
|
|
9
|
+
/** The line on a field another rule sorts already. */
|
|
10
|
+
sorted: string;
|
|
11
|
+
/** Why Add sort can't be used, at `max` rules. */
|
|
12
|
+
max: (max: number) => string;
|
|
13
|
+
/** Add sort, and its list's name. */
|
|
14
|
+
add: string;
|
|
15
|
+
/** A computer's Clear all, at the foot's end. */
|
|
16
|
+
clearAllSorts: string;
|
|
17
|
+
/** A phone's and the narrow form's Clear all. */
|
|
18
|
+
clearAll: string;
|
|
19
|
+
/** A rule's menu row taking it away. */
|
|
20
|
+
delete: string;
|
|
21
|
+
/** A rule's grip. */
|
|
22
|
+
move: (name: string) => string;
|
|
23
|
+
/** A rule's ×. */
|
|
24
|
+
remove: (name: string) => string;
|
|
25
|
+
/** The menu a rule's ⋯ opens, by its field. */
|
|
26
|
+
sortBy: (name: string) => string;
|
|
27
|
+
/** A rule's ⋯. */
|
|
28
|
+
actionsFor: (name: string) => string;
|
|
29
|
+
/** What the body says with nothing sorted, and its line under it. */
|
|
30
|
+
none: string;
|
|
31
|
+
noneLine: string;
|
|
32
|
+
/** The fields' search, before anything is typed. */
|
|
33
|
+
search: string;
|
|
34
|
+
/** A step's ‹, back to the rules. */
|
|
35
|
+
back: string;
|
|
36
|
+
/** The phone's ✕ and ✓, round an editor whose holder draws no head of its own (useDecide). */
|
|
37
|
+
close: string;
|
|
38
|
+
save: string;
|
|
39
|
+
/** A set-aside sort's menu row putting it back on its own field. */
|
|
40
|
+
putBack: string;
|
|
41
|
+
/** A set-aside sort's field box, and its step's title on a phone, by its words. */
|
|
42
|
+
fieldNamed: (label: string) => string;
|
|
43
|
+
/** The lists' own words (the Picker's). */
|
|
44
|
+
picker?: Partial<PickerWords>;
|
|
45
|
+
}
|
|
46
|
+
export declare const SORT_EDITOR_WORDS: SortEditorWords;
|
|
47
|
+
/** The sort editor's words: the handed ones over the English. */
|
|
48
|
+
export declare const sortWords: (given?: Partial<SortEditorWords>) => SortEditorWords;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const SORT_EDITOR_WORDS = {
|
|
2
|
+
field: "Field",
|
|
3
|
+
direction: "Direction",
|
|
4
|
+
ascending: "Ascending",
|
|
5
|
+
descending: "Descending",
|
|
6
|
+
sorted: "Sorted",
|
|
7
|
+
max: (max) => (max === 3 ? "Three at most" : `${max} at most`),
|
|
8
|
+
add: "Add sort",
|
|
9
|
+
clearAllSorts: "Clear all sorts",
|
|
10
|
+
clearAll: "Clear all",
|
|
11
|
+
delete: "Delete",
|
|
12
|
+
move: (name) => `Move ${name}`,
|
|
13
|
+
remove: (name) => `Remove the sort by ${name}`,
|
|
14
|
+
sortBy: (name) => `the sort by ${name}`,
|
|
15
|
+
actionsFor: (name) => `Actions for the sort by ${name}`,
|
|
16
|
+
none: "No sorting set up yet",
|
|
17
|
+
noneLine: "Choose a field to sort by",
|
|
18
|
+
search: "Search fields",
|
|
19
|
+
back: "Back",
|
|
20
|
+
close: "Close",
|
|
21
|
+
save: "Save",
|
|
22
|
+
putBack: "Put back",
|
|
23
|
+
fieldNamed: (label) => `Field: ${label}`,
|
|
24
|
+
};
|
|
25
|
+
export const sortWords = (given) => (given ? { ...SORT_EDITOR_WORDS, ...given } : SORT_EDITOR_WORDS);
|