viewkitjs 0.32.0 → 0.33.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 +69 -0
- package/fields/dist/index.d.ts +1 -1
- package/fields/dist/index.js +1 -1
- package/fields/dist/query/evaluate.d.ts +7 -0
- package/fields/dist/query/exact-number.d.ts +8 -2
- package/fields/dist/query/exact-number.js +14 -1
- package/fields/dist/query/sort.js +13 -10
- package/fields/dist/registry.js +5 -1
- package/fields/dist/types.d.ts +4 -1
- package/fields/dist/zod.d.ts +5 -0
- package/fields/dist/zod.js +10 -1
- package/fields/docs/guides/contact-values.md +12 -0
- package/fields/docs/guides/field-types.md +1 -1
- package/fields/docs/guides/queries.md +3 -1
- package/fields/docs/reference/fields.md +1 -0
- package/package.json +1 -1
- package/postgres/dist/check.js +4 -1
- package/postgres/dist/definitions/formula-forms.js +3 -1
- package/postgres/dist/definitions/money.js +2 -1
- package/postgres/dist/page.js +6 -3
- package/postgres/dist/rules.d.ts +15 -1
- package/postgres/dist/rules.js +16 -0
- package/postgres/dist/sort.js +7 -2
- package/postgres/docs/guides/definitions.md +1 -1
- package/postgres/docs/guides/field-map.md +1 -1
- package/postgres/docs/reference/definitions.md +1 -1
- package/postgres/docs/reference/postgres.md +1 -1
- package/views/dist/atoms/ToolbarButton.d.ts +1 -1
- package/views/dist/atoms/ToolbarButton.js +4 -3
- package/views/dist/atoms/frame-parts.d.ts +6 -0
- package/views/dist/atoms/frame-parts.js +15 -0
- package/views/dist/atoms/types.d.ts +16 -7
- package/views/dist/cells/cell-title.d.ts +3 -1
- package/views/dist/cells/cell-title.js +2 -2
- package/views/dist/cells/cell-values.js +2 -2
- package/views/dist/contract.d.ts +31 -6
- package/views/dist/contract.js +123 -0
- package/views/dist/controls/button/map-button.js +2 -0
- package/views/dist/controls/checkbox/checkbox.d.ts +3 -2
- package/views/dist/controls/checkbox/checkbox.js +2 -2
- package/views/dist/controls/compound-editor/compound-editor.d.ts +1 -1
- package/views/dist/controls/compound-editor/name-parts.js +4 -4
- package/views/dist/controls/compound-editor/place-parts.js +19 -19
- package/views/dist/controls/compound-editor/range-parts.js +14 -14
- package/views/dist/controls/compound-editor/row.d.ts +3 -1
- package/views/dist/controls/compound-editor/row.js +2 -2
- package/views/dist/controls/controls.d.ts +2 -0
- package/views/dist/controls/controls.js +2 -0
- package/views/dist/controls/customize/customize.js +37 -35
- package/views/dist/controls/customize/map-customize-body.d.ts +2 -0
- package/views/dist/controls/customize/map-customize-body.js +4 -0
- package/views/dist/controls/date-editor/date-days.js +2 -2
- package/views/dist/controls/date-editor/date-editor.js +18 -18
- package/views/dist/controls/date-editor/date-parts.js +6 -6
- package/views/dist/controls/date-editor/map-calendar.js +1 -1
- package/views/dist/controls/date-editor.css +2 -2
- package/views/dist/controls/field/field.d.ts +3 -0
- package/views/dist/controls/field/field.js +6 -6
- package/views/dist/controls/filter-editor/block.d.ts +2 -2
- package/views/dist/controls/filter-editor/block.js +5 -5
- package/views/dist/controls/filter-editor/filter-editor.js +31 -33
- package/views/dist/controls/filter-editor/how.d.ts +3 -1
- package/views/dist/controls/filter-editor/map-filter-body.d.ts +1 -0
- package/views/dist/controls/filter-editor/map-filter-body.js +7 -3
- package/views/dist/controls/filter-editor/map-rules.js +1 -1
- package/views/dist/controls/filter-editor/parts.js +2 -1
- package/views/dist/controls/group-editor/group-editor.js +15 -13
- package/views/dist/controls/index.d.ts +2 -0
- package/views/dist/controls/index.js +1 -0
- package/views/dist/controls/input/input.js +2 -2
- package/views/dist/controls/input/map-input.js +2 -0
- package/views/dist/controls/internal/editor-parts.js +1 -1
- package/views/dist/controls/internal/map-panel-controls.d.ts +8 -0
- package/views/dist/controls/internal/map-panel-controls.js +20 -0
- package/views/dist/controls/internal/panel-controls.d.ts +50 -0
- package/views/dist/controls/internal/panel-controls.js +197 -0
- package/views/dist/controls/internal/part-slot.d.ts +12 -0
- package/views/dist/controls/internal/part-slot.js +5 -0
- package/views/dist/controls/links-editor/links-editor.d.ts +1 -1
- package/views/dist/controls/links-editor/links-editor.js +27 -27
- package/views/dist/controls/menu/map-menu.d.ts +2 -2
- package/views/dist/controls/menu/map-menu.js +15 -12
- package/views/dist/controls/menu/menu.d.ts +2 -0
- package/views/dist/controls/menu/menu.js +3 -3
- package/views/dist/controls/menu-list/menu-list.d.ts +14 -4
- package/views/dist/controls/menu-list/menu-list.js +23 -22
- package/views/dist/controls/notice/notice.d.ts +3 -1
- package/views/dist/controls/notice/notice.js +2 -2
- package/views/dist/controls/number-editor/number-editor.d.ts +1 -1
- package/views/dist/controls/number-editor/number-editor.js +13 -13
- package/views/dist/controls/number-field/number-field.js +5 -3
- package/views/dist/controls/pane/pane.d.ts +4 -2
- package/views/dist/controls/pane/pane.js +4 -4
- package/views/dist/controls/picker/picker.d.ts +2 -0
- package/views/dist/controls/picker/picker.js +37 -36
- package/views/dist/controls/picker/rows.d.ts +4 -0
- package/views/dist/controls/popover/map-popover.d.ts +1 -1
- package/views/dist/controls/popover/map-popover.js +4 -2
- package/views/dist/controls/quick-filters/quick-filters.js +4 -4
- package/views/dist/controls/radio/radio.d.ts +3 -0
- package/views/dist/controls/radio/radio.js +4 -3
- package/views/dist/controls/select/map-select.d.ts +3 -0
- package/views/dist/controls/select/map-select.js +8 -0
- package/views/dist/controls/select/select.d.ts +3 -0
- package/views/dist/controls/select/select.js +3 -3
- package/views/dist/controls/sheet/bottom-sheet.d.ts +5 -1
- package/views/dist/controls/sheet/bottom-sheet.js +2 -2
- package/views/dist/controls/sheet/map-sheet.js +1 -1
- package/views/dist/controls/sort-editor/map-sort-body.d.ts +1 -0
- package/views/dist/controls/sort-editor/map-sort-body.js +7 -3
- package/views/dist/controls/sort-editor/sort-editor.js +24 -26
- package/views/dist/controls/sort-editor.css +5 -0
- package/views/dist/controls/text-editor/text-editor.d.ts +1 -1
- package/views/dist/controls/text-editor/text-editor.js +8 -8
- package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +3 -3
- package/views/dist/controls/toolbar-button/atom-toolbar-button.js +7 -6
- package/views/dist/controls/values-editor/values-editor.d.ts +1 -1
- package/views/dist/controls/values-editor/values-editor.js +22 -22
- package/views/dist/controls/views-list/map-view-menu.js +1 -1
- package/views/dist/controls/views-list/view-menu.js +6 -6
- package/views/dist/controls/views-list/views-list.js +4 -4
- package/views/dist/editors/EditorPanel.js +1 -1
- package/views/dist/field-row/FieldRow.js +13 -0
- package/views/dist/fields/money.d.ts +5 -2
- package/views/dist/fields/money.js +14 -2
- package/views/dist/grid/chrome/GridTable.js +4 -1
- package/views/dist/grid/chrome/cell-clipboard.d.ts +4 -2
- package/views/dist/grid/chrome/cell-clipboard.js +2 -2
- package/views/dist/grid/chrome/cells.js +3 -1
- package/views/dist/grid/chrome/grid-row-menu-items.js +1 -1
- package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -1
- package/views/dist/grid/chrome/useGridKeyboard.js +29 -6
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +9 -2
- package/views/dist/grid/core/clipboard-model.d.ts +3 -1
- package/views/dist/grid/core/clipboard-model.js +9 -8
- package/views/dist/grid/core/editing-controller.d.ts +3 -0
- package/views/dist/grid/core/editing-controller.js +6 -0
- package/views/dist/grid/core/edits-sink.d.ts +19 -0
- package/views/dist/grid/core/edits-sink.js +2 -0
- package/views/dist/grid/core/spreadsheet-operations.js +1 -1
- package/views/dist/grid/core/useGridEditing.d.ts +5 -0
- package/views/dist/grid/core/useGridEditing.js +6 -0
- package/views/dist/list/answer.d.ts +40 -0
- package/views/dist/list/answer.js +43 -0
- package/views/dist/list/bulk-bar.d.ts +7 -0
- package/views/dist/list/bulk-bar.js +10 -0
- package/views/dist/list/columns.d.ts +24 -0
- package/views/dist/list/columns.js +27 -0
- package/views/dist/list/edits.d.ts +19 -0
- package/views/dist/list/edits.js +56 -0
- package/views/dist/list/grid.d.ts +11 -0
- package/views/dist/list/grid.js +76 -0
- package/views/dist/list/index.d.ts +14 -1
- package/views/dist/list/index.js +4 -1
- package/views/dist/list/link.d.ts +8 -0
- package/views/dist/list/link.js +78 -0
- package/views/dist/list/list.d.ts +70 -0
- package/views/dist/list/list.js +14 -0
- package/views/dist/list/parts.js +10 -3
- package/views/dist/list/root-base.d.ts +46 -0
- package/views/dist/list/root-base.js +137 -0
- package/views/dist/list/root.d.ts +35 -34
- package/views/dist/list/root.js +153 -113
- package/views/dist/list/source-answers.d.ts +39 -0
- package/views/dist/list/source-answers.js +225 -0
- package/views/dist/list/store.d.ts +37 -5
- package/views/dist/list/store.js +31 -0
- package/views/dist/list/toolbar.d.ts +3 -2
- package/views/dist/list/toolbar.js +14 -2
- package/views/dist/list/views-axis.js +4 -2
- package/views/dist/list/views.d.ts +7 -2
- package/views/dist/list/views.js +16 -5
- package/views/dist/model/column-capabilities.d.ts +13 -0
- package/views/dist/model/column-capabilities.js +23 -2
- package/views/dist/model/column-schema.d.ts +11 -1
- package/views/dist/model/view-rules.js +1 -0
- package/views/dist/panels/model.d.ts +2 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +8 -2
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +2 -2
- package/views/dist/panels/react/toolbar/Toolbar.d.ts +8 -1
- package/views/dist/panels/react/toolbar/Toolbar.js +12 -3
- package/views/dist/panels/react/toolbar/ToolbarAdvancedFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarAsideFilter.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +4 -4
- package/views/dist/panels/react/toolbar/ToolbarButton.js +4 -1
- package/views/dist/panels/react/toolbar/ToolbarFilter.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarNew.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarOptions.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSort.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +6 -4
- package/views/dist/panels/react/toolbar/context.d.ts +10 -1
- package/views/dist/panels/react/toolbar/panel-part.d.ts +4 -1
- package/views/dist/panels/react/toolbar/panel-part.js +5 -3
- package/views/dist/panels/settings/filter-groups.js +6 -1
- package/views/dist/provider/ViewsProvider.d.ts +6 -2
- package/views/dist/provider/ViewsProvider.js +18 -1
- package/views/dist/provider/components.d.ts +59 -0
- package/views/dist/provider/components.js +1 -1
- package/views/dist/provider/context.d.ts +4 -1
- package/views/dist/provider/own-control.d.ts +4 -0
- package/views/dist/provider/own-control.js +7 -0
- package/views/dist/provider/select-items.d.ts +3 -0
- package/views/dist/provider/select-items.js +6 -0
- package/views/dist/react.d.ts +4 -2
- package/views/dist/react.js +2 -0
- package/views/dist/styles.css +86 -78
- package/views/dist/styles.unlayered.css +86 -78
- package/views/docs/contract.md +252 -5
- package/views/docs/controls/compound-editor.md +4 -0
- package/views/docs/controls/customize.md +6 -0
- package/views/docs/controls/date-editor.md +4 -0
- package/views/docs/controls/field.md +4 -0
- package/views/docs/controls/filter-editor.md +8 -0
- package/views/docs/controls/group-editor.md +6 -0
- package/views/docs/controls/input.md +4 -0
- package/views/docs/controls/links-editor.md +4 -0
- package/views/docs/controls/menu-list.md +8 -0
- package/views/docs/controls/menu.md +4 -0
- package/views/docs/controls/notice.md +4 -0
- package/views/docs/controls/number-editor.md +4 -0
- package/views/docs/controls/pane.md +4 -0
- package/views/docs/controls/picker.md +8 -0
- package/views/docs/controls/quick-filters.md +6 -0
- package/views/docs/controls/radio.md +4 -0
- package/views/docs/controls/select.md +8 -0
- package/views/docs/controls/sheet.md +4 -0
- package/views/docs/controls/sort-editor.md +8 -0
- package/views/docs/controls/text-editor.md +4 -0
- package/views/docs/controls/values-editor.md +4 -0
- package/views/docs/controls/views-list.md +6 -0
- package/views/docs/guides/the-grid.md +2 -2
- package/views/docs/guides/the-provider.md +19 -2
- package/views/docs/reference/controls.md +7 -5
- package/views/docs/reference/field-row.md +1 -1
- package/views/docs/reference/grid.md +1 -1
- package/views/docs/reference/list.md +141 -11
- package/views/docs/reference/panels-react.md +2 -2
- package/views/docs/reference/react.md +15 -9
- package/views/docs/reference/views.md +8 -4
- package/views/docs/reshaping.md +6 -1
|
@@ -151,22 +151,22 @@ export function useViewMenu(props) {
|
|
|
151
151
|
];
|
|
152
152
|
return props.reshape ? props.reshape(all, id) : all;
|
|
153
153
|
};
|
|
154
|
-
const entries = (id) => menuEntries(items(id));
|
|
154
|
+
const entries = (id) => menuEntries(items(id), undefined, "vk-view-menu-row");
|
|
155
155
|
const where = props.container ?? undefined, standing = props.standing;
|
|
156
156
|
const target = asked && (asked.what === "rename" || asked.what === "delete" || asked.what === "menu") ? viewOf(asked.id) : undefined;
|
|
157
157
|
const asking = shown;
|
|
158
|
-
const nameField = (run) => (_jsx(Field, { label: w.name, children: _jsx(Input, { ref: box, value: name, onValueChange: (v) => setName(v), onKeyDown: enter(run), autoComplete: "off" }) }));
|
|
158
|
+
const nameField = (run) => (_jsx(Field, { label: w.name, children: _jsx(Input, { ref: box, "data-slot": "vk-view-menu-name", value: name, onValueChange: (v) => setName(v), onKeyDown: enter(run), autoComplete: "off" }) }));
|
|
159
159
|
const columnsField = chosen?.columns && columns && (phone
|
|
160
|
-
? _jsx("div", { style: { display: "contents" }, ...MENU_LIST_CARD_FRAME, children: _jsx(MenuList, { label: w.columns(chosen.name), entries: [{ kind: "choices", icon: null, label: w.columns(chosen.name), value: column, choices: columns.fields.map((f) => ({ value: f.value, label: f.label })) }], onOpen: () => (stepping ? ask({ what: "columns" }) : setPicking({ open: true })) }) })
|
|
161
|
-
: _jsx(Field, { label: w.columns(chosen.name), nativeLabel: false, children: _jsx(Select, { "aria-label": w.columns(chosen.name), items: asSelect(columns.fields), value: column, onValueChange: (v) => { if (typeof v === "string")
|
|
160
|
+
? _jsx("div", { style: { display: "contents" }, ...MENU_LIST_CARD_FRAME, children: _jsx(MenuList, { label: w.columns(chosen.name), entries: [{ kind: "choices", icon: null, label: w.columns(chosen.name), value: column, slot: { slot: "vk-view-menu-columns" }, choices: columns.fields.map((f) => ({ value: f.value, label: f.label })) }], onOpen: () => (stepping ? ask({ what: "columns" }) : setPicking({ open: true })) }) })
|
|
161
|
+
: _jsx(Field, { label: w.columns(chosen.name), nativeLabel: false, children: _jsx(Select, { "aria-label": w.columns(chosen.name), "data-slot": "vk-view-menu-columns", items: asSelect(columns.fields), value: column, onValueChange: (v) => { if (typeof v === "string")
|
|
162
162
|
setColumn(v); } }) }));
|
|
163
163
|
const newForm = (_jsxs("div", { className: "o-views-list-form", children: [_jsx(RadioGroup, { row: true, label: w.layout, value: layout, onValueChange: (v) => { if (typeof v === "string")
|
|
164
|
-
setLayout(v); }, children: layouts.map((l) => _jsx(Radio, { value: l.id, mark: l.mark, label: l.name, note: l.line }, l.id)) }), nameField(create), columnsField] }));
|
|
164
|
+
setLayout(v); }, children: layouts.map((l) => _jsx(Radio, { value: l.id, mark: l.mark, label: l.name, note: l.line, "data-slot": "vk-view-menu-layout", "data-key": l.id }, l.id)) }), nameField(create), columnsField] }));
|
|
165
165
|
const modalWords = { close: w.close };
|
|
166
166
|
const stepOf = () => {
|
|
167
167
|
if (!stepping || !asked || !shown)
|
|
168
168
|
return null;
|
|
169
|
-
const done = (run, disabled, label) => (_jsx("div", { className: "o-views-list-step-foot", children: _jsx(Button, { kind: "primary", className: "o-views-list-step-act", disabled: disabled, onClick: () => { run(); toList(); }, children: label }) }));
|
|
169
|
+
const done = (run, disabled, label) => (_jsx("div", { className: "o-views-list-step-foot", children: _jsx(Button, { kind: "primary", className: "o-views-list-step-act", "data-slot": "vk-view-menu-act", disabled: disabled, onClick: () => { run(); toList(); }, children: label }) }));
|
|
170
170
|
if (asked.what === "menu" && target) {
|
|
171
171
|
const leaving = (list) => list.map((e) => e.kind === undefined || e.kind === "action" ? { ...e, onSelect: () => { toList(); e.onSelect?.(); } } : e.kind === "group" ? { ...e, entries: leaving(e.entries) } : e);
|
|
172
172
|
return { title: target.name, onBack: toList, body: _jsx("div", { style: { display: "contents" }, ...MENU_LIST_CARD_FRAME, children: _jsx(MenuList, { label: target.name, ...tilesOf(leaving(entries(target.id))), ...(closeRow ? { onClose: toList } : {}), closeWord: w.close }) }) };
|
|
@@ -36,7 +36,7 @@ export function useViewsList(props) {
|
|
|
36
36
|
return mark == null ? {} : { as: { mark: _jsx("span", { className: "o-views-list-mark", children: mark }) } };
|
|
37
37
|
};
|
|
38
38
|
const items = listed(views, privateViews).map((v) => ({
|
|
39
|
-
value: v.id, label: v.name, ...markOf(v.layout),
|
|
39
|
+
value: v.id, label: v.name, ...markOf(v.layout), slot: { slot: "vk-views-list-row", key: v.id },
|
|
40
40
|
...(props.entries ? { menu: props.entries(v.id) } : {}),
|
|
41
41
|
...(typeof v.count === "number" ? { count: v.count } : {}),
|
|
42
42
|
...(privateViews ? { group: v.private ? w.justMe : w.shared, ...(v.private ? { after: LOCK } : {}) } : {}),
|
|
@@ -50,7 +50,7 @@ export function useViewsList(props) {
|
|
|
50
50
|
...(props.onNew ? { actions: [{ id: "new", label: w.newView, icon: _jsx(Icon, { name: "plus" }), onSelect: () => { setOpener(null); props.onNew(); } }] } : {}),
|
|
51
51
|
search: phone ? w.find : w.search, searchShown: true, heldInPlace: true, actionsUnder: true, fromHeld: true,
|
|
52
52
|
...(w.none ? { none: w.none } : {}), ...(w.picker ? { words: w.picker } : {}), ...(w.menu ? { menuWords: w.menu } : {}),
|
|
53
|
-
menuFrame: MENU_LIST_CARD_FRAME,
|
|
53
|
+
menuFrame: MENU_LIST_CARD_FRAME, menuSlot: "vk-view-menu",
|
|
54
54
|
...(phone && props.onMenu ? { onRowMenu: (id) => { setOpener(views.find((v) => v.id === id)?.name ?? null); props.onMenu(id); } } : {}),
|
|
55
55
|
});
|
|
56
56
|
const step = phone ? props.step ?? null : null;
|
|
@@ -60,11 +60,11 @@ export function useViewsList(props) {
|
|
|
60
60
|
if (step) {
|
|
61
61
|
const back = _jsx(SheetButton, { "aria-label": w.back, className: "o-sheet-back", icon: _jsx(Icon, { name: "left" }), onClick: step.onBack });
|
|
62
62
|
return {
|
|
63
|
-
body: _jsx("div", { ref: placeRoot, className: "o-views-list", "data-kit": "views-list", "data-views-form": "phone", "data-views-step": "", ...phoneMark(!!screen || small), children: step.body }),
|
|
63
|
+
body: _jsx("div", { ref: placeRoot, className: "o-views-list", "data-slot": "vk-views-list", "data-kit": "views-list", "data-views-form": "phone", "data-views-step": "", ...phoneMark(!!screen || small), children: step.body }),
|
|
64
64
|
head: { left: back, children: step.title, right: _jsx("span", {}) },
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
const body = (_jsx("div", { ref: placeRoot, className: "o-views-list", "data-kit": "views-list", "data-views-form": phone ? "phone" : "computer", ...phoneMark(!!screen || small), children: picker.body }));
|
|
67
|
+
const body = (_jsx("div", { ref: placeRoot, className: "o-views-list", "data-slot": "vk-views-list", "data-kit": "views-list", "data-views-form": phone ? "phone" : "computer", ...phoneMark(!!screen || small), children: picker.body }));
|
|
68
68
|
return { body, head: picker.head };
|
|
69
69
|
}
|
|
70
70
|
export function ViewsList(props) {
|
|
@@ -155,5 +155,5 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
|
|
|
155
155
|
if (details?.reason === "escape-key" && (inMarkedStep(document.activeElement) || goBack()))
|
|
156
156
|
return;
|
|
157
157
|
close("escape");
|
|
158
|
-
}, title: sheetTitle, ...(typeof sheetTitle === "string" || typeof sheetTitle === "number" ? { label: String(sheetTitle) } : {}), ...(actions && { actions }), snap: snap, children: _jsxs("div", { ref: panelRef, "data-slot": "vk-editor-panel", children: [actions ? null : (_jsxs("div", { "data-slot": "vk-editor-bar", className: "flex items-center justify-between px-2 pb-1", children: [step ? (_jsx(Button, { variant: "ghost", size: "icon", "aria-label": backLabel, onClick: back, children: _jsx(Back, { className: "size-4" }) })) : (_jsx(Button, { variant: "ghost", size: "icon", "aria-label": discardLabel, onClick: () => close("escape"), children: _jsx(Discard, { className: "size-4" }) })), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": saveLabel, onClick: () => close("enter"), children: _jsx(Save, { className: "size-4" }) })] })), _jsx(BodyStepContext.Provider, { value: hold, children: editor }), reason] }) }) }));
|
|
158
|
+
}, title: sheetTitle, ...(typeof sheetTitle === "string" || typeof sheetTitle === "number" ? { label: String(sheetTitle) } : {}), ...(actions && { actions }), snap: snap, children: _jsxs("div", { ref: panelRef, "data-slot": "vk-editor-panel", children: [actions ? null : (_jsxs("div", { "data-slot": "vk-editor-bar", className: "flex items-center justify-between px-2 pb-1", children: [step ? (_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "vk-editor-back", "aria-label": backLabel, onClick: back, children: _jsx(Back, { className: "size-4" }) })) : (_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "vk-editor-close", "aria-label": discardLabel, onClick: () => close("escape"), children: _jsx(Discard, { className: "size-4" }) })), _jsx(Button, { variant: "ghost", size: "icon", "data-slot": "vk-editor-save", "aria-label": saveLabel, onClick: () => close("enter"), children: _jsx(Save, { className: "size-4" }) })] })), _jsx(BodyStepContext.Provider, { value: hold, children: editor }), reason] }) }) }));
|
|
159
159
|
}
|
|
@@ -204,9 +204,22 @@ function FieldRowImpl({ binding, row, value, editValue, writable, ready = true,
|
|
|
204
204
|
const glyph = binding.icon ? (_jsx(AppIcon, { name: binding.icon, className: "h-3.5 w-3.5 text-(color:--vk-fg-subtlest)" })) : (_jsx(TypeGlyph, { className: "h-3.5 w-3.5 text-(color:--vk-fg-subtlest)" }));
|
|
205
205
|
const menuItems = fieldRowMenuItems(menu, ready, messages);
|
|
206
206
|
const valueNode = (_jsxs("span", { ref: valueRef, className: "flex min-w-0 flex-1 items-center gap-2", children: [_jsx("span", { className: "min-w-0 wrap-break-word", children: body }), meta ? _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtle)", children: meta }) : null] }));
|
|
207
|
+
const handOver = () => {
|
|
208
|
+
const row = rowRef.current;
|
|
209
|
+
if (!row || !buttonRef.current || document.activeElement !== buttonRef.current)
|
|
210
|
+
return;
|
|
211
|
+
row.tabIndex = -1;
|
|
212
|
+
row.style.outline = "none";
|
|
213
|
+
row.focus({ preventScroll: true });
|
|
214
|
+
row.addEventListener("blur", () => {
|
|
215
|
+
row.removeAttribute("tabindex");
|
|
216
|
+
row.style.removeProperty("outline");
|
|
217
|
+
}, { once: true });
|
|
218
|
+
};
|
|
207
219
|
const open = (byKey) => {
|
|
208
220
|
if (pending)
|
|
209
221
|
return;
|
|
222
|
+
handOver();
|
|
210
223
|
setError(null);
|
|
211
224
|
setByKey(byKey);
|
|
212
225
|
setEditing(true);
|
|
@@ -25,6 +25,7 @@ export type MoneyColumn<Row> = DenominatedColumn<Row> & {
|
|
|
25
25
|
accessor?: ((row: Row) => unknown) | null;
|
|
26
26
|
aggAccessor?: (row: Row) => number | null;
|
|
27
27
|
editAccessor?: ((row: Row) => unknown) | null;
|
|
28
|
+
sortAccessor?: (row: Row) => number | null;
|
|
28
29
|
};
|
|
29
30
|
export declare function isMoneyOpensOn(value: unknown): value is MoneyOpensOn;
|
|
30
31
|
/** The reading a declaration opens on, for this reader. */
|
|
@@ -45,8 +46,10 @@ export declare function convertMoney<Row>(money: MoneyDeclaration<Row>, row: Row
|
|
|
45
46
|
/** The column, read the given way. Every derivation starts from `money`, so
|
|
46
47
|
* reading a column twice is the same as reading it once. `C` keeps the
|
|
47
48
|
* caller's column type (a grid `ListColumn`, a server `SourceColumn`); the
|
|
48
|
-
* intersection is what lets `Row` be inferred from the declaration.
|
|
49
|
-
|
|
49
|
+
* intersection is what lets `Row` be inferred from the declaration. Under the
|
|
50
|
+
* Original reading, `sortIn` (the reader's default currency, which
|
|
51
|
+
* `readMoneyColumns` hands) gives the column its `sortAccessor`. */
|
|
52
|
+
export declare function readMoneyColumn<Row, C extends MoneyColumn<Row>>(column: C & MoneyColumn<Row>, reading: MoneyReading, sortIn?: DisplayCurrency): C;
|
|
50
53
|
/** Every money column read the reader's way: their `gridCurrencies` by FIELD
|
|
51
54
|
* key, else a host's legacy choice (read once, never written), else what the
|
|
52
55
|
* column opens on — for this reader's default currency. */
|
|
@@ -19,7 +19,7 @@ export function convertMoney(money, row, value, to) {
|
|
|
19
19
|
return null;
|
|
20
20
|
return convertRowAmount({ currency: money.code(row), fx: rates }, value, to);
|
|
21
21
|
}
|
|
22
|
-
export function readMoneyColumn(column, reading) {
|
|
22
|
+
export function readMoneyColumn(column, reading, sortIn) {
|
|
23
23
|
const money = column.money;
|
|
24
24
|
if (!money)
|
|
25
25
|
return column;
|
|
@@ -35,6 +35,17 @@ export function readMoneyColumn(column, reading) {
|
|
|
35
35
|
delete next.aggAccessor;
|
|
36
36
|
next.currencyAccessor = money.code;
|
|
37
37
|
delete next.surfaceOwnsCurrency;
|
|
38
|
+
if (sortIn !== undefined)
|
|
39
|
+
next.sortAccessor = (row) => {
|
|
40
|
+
try {
|
|
41
|
+
return convertMoney(money, row, money.amount(row), sortIn);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
else
|
|
48
|
+
delete next.sortAccessor;
|
|
38
49
|
}
|
|
39
50
|
else {
|
|
40
51
|
format.currency = reading;
|
|
@@ -46,6 +57,7 @@ export function readMoneyColumn(column, reading) {
|
|
|
46
57
|
else
|
|
47
58
|
delete next.aggAccessor;
|
|
48
59
|
delete next.currencyAccessor;
|
|
60
|
+
delete next.sortAccessor;
|
|
49
61
|
next.surfaceOwnsCurrency = true;
|
|
50
62
|
}
|
|
51
63
|
next.format = format;
|
|
@@ -58,7 +70,7 @@ export function readMoneyColumns(columns, readings, defaultCurrency, legacy) {
|
|
|
58
70
|
const reading = readings[column.field.key] ??
|
|
59
71
|
legacy?.(column) ??
|
|
60
72
|
resolveOpensOn(column.money.opensOn, defaultCurrency);
|
|
61
|
-
return readMoneyColumn(column, reading);
|
|
73
|
+
return readMoneyColumn(column, reading, defaultCurrency);
|
|
62
74
|
});
|
|
63
75
|
}
|
|
64
76
|
export function moneyReadingOf(column) {
|
|
@@ -24,6 +24,7 @@ import { groupMenuParts } from "./grid-group-menu-parts.js";
|
|
|
24
24
|
import { GRID_HEAD_KEY } from "../core/grid-focus.js";
|
|
25
25
|
import { gridAriaLayout } from "../core/grid-aria.js";
|
|
26
26
|
import { GridBody } from "./GridStructure.js";
|
|
27
|
+
import { withEditThroughLocks } from "../../model/column-capabilities.js";
|
|
27
28
|
import { useGridScaleStyles } from "./useGridScaleStyles.js";
|
|
28
29
|
import { useGridTableInteractionModel } from "./useGridTableInteractionModel.js";
|
|
29
30
|
import { useGridRowOpener } from "./useGridRowOpener.js";
|
|
@@ -89,7 +90,9 @@ function GridRowsWait({ gridProps, waiting, RowsWait, loading, }) {
|
|
|
89
90
|
return null;
|
|
90
91
|
return (_jsx(GridWaitContext.Provider, { value: wait, children: _jsx(GridRowsSlotContext.Provider, { value: slot, children: _jsx("div", { className: "contents", inert: holding, children: grid }) }) }));
|
|
91
92
|
}
|
|
92
|
-
function GridTableContent(
|
|
93
|
+
function GridTableContent(given) {
|
|
94
|
+
const widenedConfig = useMemo(() => withEditThroughLocks(given.listConfig, given.columns.map((column) => column.field)), [given.listConfig, given.columns]);
|
|
95
|
+
const props = useMemo(() => (widenedConfig === given.listConfig ? given : { ...given, listConfig: widenedConfig }), [given, widenedConfig]);
|
|
93
96
|
const { groups, grouped, getRowId, columns, isCollapsed, onToggleGroup, renderGroupLabel, onHideGroup, renderAggregate, countOf, onOpenRow, onPrefetchRow, rowHref, rowClassName, onRowDelete, rowActions, rowIcon, showRowIcon = true, freezeIdentity = true, selection, loadMore, pages, emptyState, sort, sortMark, groupBy, sortOptions, groupSummary, aggregates, onAggregateChange, onGroupSummaryChange, groupFigures, countNoun, optionColors, onOptionColorChange, dateStyles, onDateStyleChange, durationStyles, onDurationStyleChange, numberFormats, onNumberFormatChange, showTimeOverrides, onShowTimeChange, percentDisplays, onPercentDisplayChange, columnState, onColumnStateChange, listConfig, } = props;
|
|
94
97
|
const leaveScope = useEditLeaveScope();
|
|
95
98
|
const rowsWait = useContext(GridWaitContext);
|
|
@@ -5,6 +5,8 @@ export { cellClearPrev, cellCopyShown, cellEditBaseline, cellPrevPayload, rowHol
|
|
|
5
5
|
export declare function getGridClipboard(): GridCellClipboard | null;
|
|
6
6
|
/** Puts one cell's text on the system clipboard through the app's port, and keeps the typed entry
|
|
7
7
|
* the grid pastes from — which survives a refused system write. The text reads `shown` (`cellCopyShown`: a
|
|
8
|
-
* relation as its cell shows it), the entry keeps `baseline`. */
|
|
9
|
-
export declare function copyCell<Row>(write: ViewsClipboardPort["writeText"], col: ListColumn<Row>, baseline: unknown, unit?: string, shown?: unknown
|
|
8
|
+
* relation as its cell shows it, a place's country in `language`), the entry keeps `baseline`. */
|
|
9
|
+
export declare function copyCell<Row>(write: ViewsClipboardPort["writeText"], col: ListColumn<Row>, baseline: unknown, unit?: string, shown?: unknown,
|
|
10
|
+
/** The names language a place's country is written in (`conventions.language`). */
|
|
11
|
+
language?: string): Promise<string>;
|
|
10
12
|
export declare function copyCells(write: ViewsClipboardPort["writeText"], matrix: GridClipboardCell[][]): Promise<string>;
|
|
@@ -4,8 +4,8 @@ let clipboard = null;
|
|
|
4
4
|
export function getGridClipboard() {
|
|
5
5
|
return clipboard;
|
|
6
6
|
}
|
|
7
|
-
export async function copyCell(write, col, baseline, unit, shown = baseline) {
|
|
8
|
-
const text = cellCopyText(col, shown);
|
|
7
|
+
export async function copyCell(write, col, baseline, unit, shown = baseline, language) {
|
|
8
|
+
const text = cellCopyText(col, shown, language);
|
|
9
9
|
clipboard = { text, value: baseline, type: col.type, unit };
|
|
10
10
|
try {
|
|
11
11
|
await write(text);
|
|
@@ -7,7 +7,9 @@ export function renderTypedCell(col, row, opts) {
|
|
|
7
7
|
const cell = renderTypedCellValue(col, row, opts);
|
|
8
8
|
if (col.type === "title")
|
|
9
9
|
return cell;
|
|
10
|
-
const indicator = col.indicator?.(row
|
|
10
|
+
const indicator = col.indicator?.(row, {
|
|
11
|
+
value: opts?.valueOverride !== undefined ? opts.valueOverride : col.accessor?.(row),
|
|
12
|
+
});
|
|
11
13
|
if (!indicator)
|
|
12
14
|
return cell;
|
|
13
15
|
return (_jsxs("span", { className: "flex h-(--vk-line-h) min-w-0 flex-1 flex-wrap content-start items-center gap-x-1.5 overflow-hidden leading-(--vk-line-h)", children: [_jsx("span", { className: "max-w-full flex-none truncate", children: cell }), indicator] }));
|
|
@@ -74,7 +74,7 @@ export function gridRowMenuItems(menuRow, menuColumnId, views) {
|
|
|
74
74
|
? columns.find((column) => column.id === menuColumnId)
|
|
75
75
|
: undefined;
|
|
76
76
|
const editBaseline = (column) => cellEditBaseline(column, row, pendingByCol);
|
|
77
|
-
const copy = (column, unit) => void copyCell(ports.clipboard.writeText, column, editBaseline(column), unit, cellCopyShown(column, row, pendingByCol));
|
|
77
|
+
const copy = (column, unit) => void copyCell(ports.clipboard.writeText, column, editBaseline(column), unit, cellCopyShown(column, row, pendingByCol), conventions.language);
|
|
78
78
|
const canEdit = (column) => editingEnabled && rowWritable && columnWritable(column);
|
|
79
79
|
const off = (reason) => reason === null ? { disabled: false } : { disabled: true, disabledReason: reason };
|
|
80
80
|
const nothingToPaste = messages({ key: "views.grid.paste-empty" });
|
|
@@ -3,9 +3,10 @@ import { type GridCellPos } from "../core/coordinates.js";
|
|
|
3
3
|
import type { GridCellRange } from "../core/useGridRange.js";
|
|
4
4
|
import type { ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
5
5
|
import type { ListColumn } from "../../model/column-schema.js";
|
|
6
|
+
import { type GridEditsState } from "../core/edits-sink.js";
|
|
6
7
|
import type { GridRangeVerbs } from "./useGridRangeActions.js";
|
|
7
8
|
import { type GridChromeTarget, type GridFocusShape } from "../core/grid-focus.js";
|
|
8
|
-
export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
|
|
9
|
+
export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited, editsState, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
|
|
9
10
|
rootRef: RefObject<HTMLDivElement | null>;
|
|
10
11
|
/** A column name, a footer cell, a bar or a checkbox holding the focus (`useGridFocus`); null: a data cell, or
|
|
11
12
|
* nothing. */
|
|
@@ -63,6 +64,8 @@ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell
|
|
|
63
64
|
/** This grid is the one the page edited last (`useGridEditing`'s `isLastEdited`): with the focus in no grid's frame,
|
|
64
65
|
* only it answers ⌘Z. Absent: it always is. */
|
|
65
66
|
isLastEdited?: () => boolean;
|
|
67
|
+
/** The edits' state a sink above the grid reads (`GridEditsSinkContext`). Absent: nothing to tell. */
|
|
68
|
+
editsState?: () => GridEditsState;
|
|
66
69
|
}): {
|
|
67
70
|
onEditorTab: (rowId: string, columnId: string, backwards: boolean) => void;
|
|
68
71
|
onEditorEnter: (rowId: string, columnId: string) => void;
|
|
@@ -10,6 +10,7 @@ import { activeRangeHead, gridNavIntent, nextCellLinear, nextCellPos, resolveNav
|
|
|
10
10
|
import { moveCaretToLineEdge } from "./grid-caret-keys.js";
|
|
11
11
|
import { copyCell } from "./cell-clipboard.js";
|
|
12
12
|
import { GridWaitContext } from "./grid-wait.js";
|
|
13
|
+
import { GridEditsSinkContext } from "../core/edits-sink.js";
|
|
13
14
|
import { GRID_KEY_OWNING_SURFACES, gridFocusElement } from "./useGridFocus.js";
|
|
14
15
|
import { isGridRowMenuKey, openGridRowMenu } from "./grid-row-menu-key.js";
|
|
15
16
|
import { openGridEditEscape } from "./grid-edit-escape.js";
|
|
@@ -23,6 +24,8 @@ const NAV_KEYS = {
|
|
|
23
24
|
};
|
|
24
25
|
const KEY_OWNING_SURFACES = GRID_KEY_OWNING_SURFACES;
|
|
25
26
|
const INTERACTIVE = 'button, a[href], [role="button"], [tabindex]:not([tabindex="-1"])';
|
|
27
|
+
const NO_HISTORY = { undo: () => false, redo: () => false };
|
|
28
|
+
const NO_EDITS = { saving: false, canUndo: false, canRedo: false };
|
|
26
29
|
function eventBelongsElsewhere(target, root) {
|
|
27
30
|
if (!target?.closest)
|
|
28
31
|
return false;
|
|
@@ -30,8 +33,8 @@ function eventBelongsElsewhere(target, root) {
|
|
|
30
33
|
return true;
|
|
31
34
|
return !!target.closest(INTERACTIVE) && !root?.contains(target);
|
|
32
35
|
}
|
|
33
|
-
export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited = () => true, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome = null, setChrome = () => { }, shape, toggleGroup, }) {
|
|
34
|
-
const { ports, messages } = useViews();
|
|
36
|
+
export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, rowWritable, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited = () => true, editsState, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome = null, setChrome = () => { }, shape, toggleGroup, }) {
|
|
37
|
+
const { ports, messages, conventions } = useViews();
|
|
35
38
|
const navFromEditorRef = useRef({ tab: () => { }, enter: () => { } });
|
|
36
39
|
const onEditorTab = useCallback((rowId, columnId, backwards) => navFromEditorRef.current.tab(rowId, columnId, backwards), []);
|
|
37
40
|
const onEditorEnter = useCallback((rowId, columnId) => navFromEditorRef.current.enter(rowId, columnId), []);
|
|
@@ -56,9 +59,20 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
56
59
|
};
|
|
57
60
|
}, [focusCell, revealCell, visibleColIds, visibleRowIds]);
|
|
58
61
|
const rowsWait = useContext(GridWaitContext);
|
|
62
|
+
const historyRef = useRef(NO_HISTORY);
|
|
63
|
+
const editsStateRef = useRef(editsState);
|
|
64
|
+
editsStateRef.current = editsState;
|
|
65
|
+
const sink = useContext(GridEditsSinkContext);
|
|
59
66
|
useEffect(() => {
|
|
60
|
-
if (!
|
|
67
|
+
if (!sink)
|
|
61
68
|
return;
|
|
69
|
+
return sink.attach({
|
|
70
|
+
undo: () => historyRef.current.undo(),
|
|
71
|
+
redo: () => historyRef.current.redo(),
|
|
72
|
+
state: () => editsStateRef.current?.() ?? NO_EDITS,
|
|
73
|
+
});
|
|
74
|
+
}, [sink]);
|
|
75
|
+
useEffect(() => {
|
|
62
76
|
const scrollToCell = ({ rowId, columnId }) => {
|
|
63
77
|
const key = rowByKey.has(rowId) ? rowId : visibleRowIds.find((k) => gridRowIdFromKey(k) === rowId);
|
|
64
78
|
if (key == null)
|
|
@@ -67,6 +81,15 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
67
81
|
focusCell(key, columnId);
|
|
68
82
|
requestAnimationFrame(() => revealCell(pos, "smooth"));
|
|
69
83
|
};
|
|
84
|
+
const resolveRow = (rowId) => rows.find((row) => getRowId(row) === rowId);
|
|
85
|
+
historyRef.current = editingEnabled
|
|
86
|
+
? {
|
|
87
|
+
undo: () => !rowsWait?.waiting.current && undo(resolveRow, scrollToCell),
|
|
88
|
+
redo: () => !rowsWait?.waiting.current && redo(resolveRow, scrollToCell),
|
|
89
|
+
}
|
|
90
|
+
: NO_HISTORY;
|
|
91
|
+
if (!editingEnabled)
|
|
92
|
+
return;
|
|
70
93
|
const onKeyDown = (event) => {
|
|
71
94
|
if (!(event.metaKey || event.ctrlKey) || event.altKey || event.key.toLowerCase() !== "z") {
|
|
72
95
|
return;
|
|
@@ -78,7 +101,6 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
78
101
|
const holder = event.target?.closest?.('[data-slot="vk-grid"]') ?? null;
|
|
79
102
|
if (holder ? holder !== rootRef.current : !isLastEdited())
|
|
80
103
|
return;
|
|
81
|
-
const resolveRow = (rowId) => rows.find((row) => getRowId(row) === rowId);
|
|
82
104
|
const handled = event.shiftKey
|
|
83
105
|
? redo(resolveRow, scrollToCell)
|
|
84
106
|
: undo(resolveRow, scrollToCell);
|
|
@@ -370,7 +392,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
370
392
|
return;
|
|
371
393
|
const pending = pendingByRow.get(rowId);
|
|
372
394
|
const baseline = cellEditBaseline(column, row, pending);
|
|
373
|
-
void copyCell(ports.clipboard.writeText, column, baseline, column.editUnit?.value(row), cellCopyShown(column, row, pending));
|
|
395
|
+
void copyCell(ports.clipboard.writeText, column, baseline, column.editUnit?.value(row), cellCopyShown(column, row, pending), conventions.language);
|
|
374
396
|
}
|
|
375
397
|
else if (mod && event.key.toLowerCase() === "x" && !editingCell) {
|
|
376
398
|
event.preventDefault();
|
|
@@ -388,7 +410,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
388
410
|
return;
|
|
389
411
|
const pending = pendingByRow.get(rowId);
|
|
390
412
|
const baseline = cellEditBaseline(column, row, pending);
|
|
391
|
-
void copyCell(ports.clipboard.writeText, column, baseline, column.editUnit?.value(row), cellCopyShown(column, row, pending));
|
|
413
|
+
void copyCell(ports.clipboard.writeText, column, baseline, column.editUnit?.value(row), cellCopyShown(column, row, pending), conventions.language);
|
|
392
414
|
commitEdit(row, rowId, column.id, cellClearPrev(column, row, pendingByRow.get(rowId)), "");
|
|
393
415
|
}
|
|
394
416
|
else if ((event.key === "Delete" || event.key === "Backspace") && !editingCell) {
|
|
@@ -438,6 +460,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
438
460
|
return () => root.removeEventListener("keydown", onKeyDown);
|
|
439
461
|
}, [
|
|
440
462
|
cancelEdit,
|
|
463
|
+
conventions.language,
|
|
441
464
|
chrome,
|
|
442
465
|
clearFocus,
|
|
443
466
|
commitEdit,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { useViews } from "../../provider/context.js";
|
|
4
4
|
import { useGridEditing } from "../core/useGridEditing.js";
|
|
5
|
+
import { GridEditsSinkContext } from "../core/edits-sink.js";
|
|
5
6
|
import { useGridRange } from "../core/useGridRange.js";
|
|
6
7
|
import { gridRefusalSentence } from "../core/refusal-sentence.js";
|
|
7
8
|
import { columnEffectiveWritable, columnLabel, gridColumnLocked, gridEditRefusal, gridNormalizeWrite, } from "../../model/column-capabilities.js";
|
|
@@ -33,7 +34,7 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
|
|
|
33
34
|
const columnById = useMemo(() => new Map([...columns, ...visibleColumns].map((column) => [column.id, column])), [columns, visibleColumns]);
|
|
34
35
|
const partOfWhole = useCallback((wholeId) => [...columnById.values()].find((column) => column.partOf?.column === wholeId)?.partOf, [columnById]);
|
|
35
36
|
const keepsSent = useCallback((columnId) => partOfWhole(columnId) != null, [partOfWhole]);
|
|
36
|
-
const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, hasInflight, pendingBaseline, sent, sentCells, forgetSent, isLastEdited, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent);
|
|
37
|
+
const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, canUndo: canUndoNow, canRedo: canRedoNow, saving: savingNow, hasInflight, pendingBaseline, sent, sentCells, forgetSent, isLastEdited, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent);
|
|
37
38
|
const wholeStored = useCallback((rowId, wholeId, row) => {
|
|
38
39
|
const part = partOfWhole(wholeId);
|
|
39
40
|
const overlay = pendingOf(rowId);
|
|
@@ -268,6 +269,11 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
|
|
|
268
269
|
useEffect(() => {
|
|
269
270
|
finishFillRef.current = rangeActions.finishFill;
|
|
270
271
|
}, [rangeActions.finishFill]);
|
|
272
|
+
const editsState = useCallback(() => ({ saving: savingNow(), canUndo: canUndoNow(), canRedo: canRedoNow() }), [savingNow, canUndoNow, canRedoNow]);
|
|
273
|
+
const editsSink = useContext(GridEditsSinkContext);
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
editsSink?.changed();
|
|
276
|
+
}, [editsSink, pendingByRow, writeStateByRow]);
|
|
271
277
|
const keyboard = useGridKeyboard({
|
|
272
278
|
releaseToFrame: focus.releaseToFrame,
|
|
273
279
|
lastCellRef: focus.lastCellRef,
|
|
@@ -298,6 +304,7 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
|
|
|
298
304
|
undo,
|
|
299
305
|
redo,
|
|
300
306
|
isLastEdited,
|
|
307
|
+
editsState,
|
|
301
308
|
rangeSetRect,
|
|
302
309
|
rangeExtendTo,
|
|
303
310
|
ranges,
|
|
@@ -35,7 +35,9 @@ export declare function cellEditBaseline<Row>(col: ListColumn<Row>, row: Row, pe
|
|
|
35
35
|
* paste stays exact. A pending value is the cell's own, and a cell that draws itself has no shown value to read.
|
|
36
36
|
*/
|
|
37
37
|
export declare function cellCopyShown<Row>(col: ListColumn<Row>, row: Row, pendingByCol?: Readonly<Record<string, unknown>>): unknown;
|
|
38
|
-
|
|
38
|
+
/** A cell's copied text. `language` is the names language (`conventions.language`) a place's country is named in, as
|
|
39
|
+
* its cell shows it; English without one. */
|
|
40
|
+
export declare function cellCopyText<Row>(col: ListColumn<Row>, baseline: unknown, language?: string): string;
|
|
39
41
|
/** Parse external plain text as a spreadsheet matrix. */
|
|
40
42
|
export declare function parseTsvText(text: string): {
|
|
41
43
|
text: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { actorLabel, formatLocalMinute, isActorValue, isBreakdown, isRangeValue, isValueItem, listValues, locationText, nameText, parseNumber, rangeShownText, relationIdOf, relationKey, relationLinksOf, relationStoredOf, utcDay, } from "viewkitjs/fields";
|
|
1
|
+
import { actorLabel, formatLocalMinute, isActorValue, isBreakdown, isIntegerField, isRangeValue, isValueItem, listValues, locationText, nameText, parseNumber, rangeShownText, relationIdOf, relationKey, relationLinksOf, relationStoredOf, roundTo, utcDay, } from "viewkitjs/fields";
|
|
2
2
|
import { phoneText } from "viewkitjs/fields/phone";
|
|
3
3
|
import { msToDurationUnit, parseDateInput, parseDurationInput } from "viewkitjs/fields/query";
|
|
4
4
|
import { calendarDayOf } from "./value-equality.js";
|
|
@@ -20,22 +20,22 @@ export function cellCopyShown(col, row, pendingByCol) {
|
|
|
20
20
|
return col.accessor(row);
|
|
21
21
|
return cellEditBaseline(col, row, pendingByCol);
|
|
22
22
|
}
|
|
23
|
-
export function cellCopyText(col, baseline) {
|
|
23
|
+
export function cellCopyText(col, baseline, language) {
|
|
24
24
|
if (baseline == null)
|
|
25
25
|
return "";
|
|
26
26
|
if (Array.isArray(baseline))
|
|
27
27
|
return (baseline.some(isValueItem) ? listValues(baseline) : baseline)
|
|
28
|
-
.map((entry) => cellValueText(col, entry))
|
|
28
|
+
.map((entry) => cellValueText(col, entry, language))
|
|
29
29
|
.join(", ");
|
|
30
|
-
return cellValueText(col, baseline);
|
|
30
|
+
return cellValueText(col, baseline, language);
|
|
31
31
|
}
|
|
32
|
-
function cellValueText(col, value) {
|
|
32
|
+
function cellValueText(col, value, language) {
|
|
33
33
|
if (value == null)
|
|
34
34
|
return "";
|
|
35
35
|
if (isValueItem(value))
|
|
36
|
-
return cellValueText(col, value.value);
|
|
36
|
+
return cellValueText(col, value.value, language);
|
|
37
37
|
if (fieldTypeOf(col) === "location")
|
|
38
|
-
return locationText(value);
|
|
38
|
+
return locationText(value, language);
|
|
39
39
|
if (fieldTypeOf(col) === "name")
|
|
40
40
|
return nameText(value);
|
|
41
41
|
if (fieldTypeOf(col) === "phone") {
|
|
@@ -250,11 +250,12 @@ export function coercePaste(col, source, opts) {
|
|
|
250
250
|
reason: messages({ key: duration ? "views.grid.paste-not-duration" : "views.grid.paste-not-number" }),
|
|
251
251
|
};
|
|
252
252
|
}
|
|
253
|
+
const figure = col.field && isIntegerField(col.field) ? roundTo(value, 0) : value;
|
|
253
254
|
const unit = pasteUnit(source.unit, opts.currentUnit, col.editUnit?.options, fieldTypeOf(col) === "currency" && (opts.holdsCurrency ?? true));
|
|
254
255
|
if ("refuse" in unit) {
|
|
255
256
|
return { ok: false, reason: messages({ key: "views.grid.paste-other-currency", values: { currency: unit.refuse } }) };
|
|
256
257
|
}
|
|
257
|
-
const next = { value, unit: unit.unit };
|
|
258
|
+
const next = { value: figure, unit: unit.unit };
|
|
258
259
|
return { ok: true, next, overlay };
|
|
259
260
|
}
|
|
260
261
|
case "date": {
|
|
@@ -58,6 +58,9 @@ export declare class GridEditingController<Row> {
|
|
|
58
58
|
setCallbacks(callbacks: GridEditingCallbacks<Row>): void;
|
|
59
59
|
canUndo(): boolean;
|
|
60
60
|
canRedo(): boolean;
|
|
61
|
+
/** Is any write still out, in any cell? An overlay outlives its write until the rows show the value (`reconcile`), so
|
|
62
|
+
* the overlays can't answer this; an undo or a redo pressed and not yet sent counts as on its way. */
|
|
63
|
+
saving(): boolean;
|
|
61
64
|
getPendingByRow(): ReadonlyMap<string, Record<string, unknown>>;
|
|
62
65
|
/**
|
|
63
66
|
* Resolves TRUE once every cell has landed on the server, false if any
|
|
@@ -36,6 +36,12 @@ export class GridEditingController {
|
|
|
36
36
|
canRedo() {
|
|
37
37
|
return this.history.redo.length > 0;
|
|
38
38
|
}
|
|
39
|
+
saving() {
|
|
40
|
+
for (const writes of this.inflight.values())
|
|
41
|
+
if (writes.size > 0)
|
|
42
|
+
return true;
|
|
43
|
+
return this.pins.size > 0;
|
|
44
|
+
}
|
|
39
45
|
getPendingByRow() {
|
|
40
46
|
return groupGridPendingByRow(this.pending);
|
|
41
47
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A grid's edits as they stand: a write still out, and whether an undo or a redo has anything to take. */
|
|
2
|
+
export type GridEditsState = {
|
|
3
|
+
saving: boolean;
|
|
4
|
+
canUndo: boolean;
|
|
5
|
+
canRedo: boolean;
|
|
6
|
+
};
|
|
7
|
+
/** What a grid hands its sink: undo and redo as its ⌘Z and ⌘⇧Z do them, and its edits' state, read when asked. */
|
|
8
|
+
export type GridEditsHandle = {
|
|
9
|
+
undo: () => boolean;
|
|
10
|
+
redo: () => boolean;
|
|
11
|
+
state: () => GridEditsState;
|
|
12
|
+
};
|
|
13
|
+
export type GridEditsSink = {
|
|
14
|
+
/** The grid below attaches as it mounts; the answer detaches it. */
|
|
15
|
+
attach: (handle: GridEditsHandle) => () => void;
|
|
16
|
+
/** The grid's edits changed (a commit, a settle, an undo or a redo). */
|
|
17
|
+
changed: () => void;
|
|
18
|
+
};
|
|
19
|
+
export declare const GridEditsSinkContext: import("react").Context<GridEditsSink | null>;
|
|
@@ -37,7 +37,7 @@ export function buildGridCopyMatrix(model, rect) {
|
|
|
37
37
|
const pending = model.pendingByRow.get(rowId);
|
|
38
38
|
const baseline = cellEditBaseline(col, row, pending);
|
|
39
39
|
cells.push({
|
|
40
|
-
text: cellCopyText(col, cellCopyShown(col, row, pending)),
|
|
40
|
+
text: cellCopyText(col, cellCopyShown(col, row, pending), model.conventions.language),
|
|
41
41
|
value: baseline,
|
|
42
42
|
type: col.type,
|
|
43
43
|
unit: col.editUnit?.value(row),
|
|
@@ -47,6 +47,11 @@ type GridEditingApi<Row> = {
|
|
|
47
47
|
undo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
|
|
48
48
|
redo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
|
|
49
49
|
reconcile: (matchedKeys: string[]) => void;
|
|
50
|
+
/** Whether an undo or a redo has anything to take. */
|
|
51
|
+
canUndo: () => boolean;
|
|
52
|
+
canRedo: () => boolean;
|
|
53
|
+
/** True while any write of this grid is out — see GridEditingController.saving. */
|
|
54
|
+
saving: () => boolean;
|
|
50
55
|
/** True while a write for this cell has not settled — see hasInflight. */
|
|
51
56
|
hasInflight: (rowId: string, columnId: string) => boolean;
|
|
52
57
|
/** What the cell held before its pending write — see GridPendingEntry.baseline. */
|
|
@@ -76,6 +76,9 @@ export function useGridEditing(onCellCommit, onCellsCommit, onRefused, keepsSent
|
|
|
76
76
|
const undo = useCallback((resolveRow, onApply) => applyHistory("undo", resolveRow, onApply), [applyHistory]);
|
|
77
77
|
const redo = useCallback((resolveRow, onApply) => applyHistory("redo", resolveRow, onApply), [applyHistory]);
|
|
78
78
|
const reconcile = useCallback((matchedKeys) => controller.reconcile(matchedKeys), [controller]);
|
|
79
|
+
const canUndo = useCallback(() => controller.canUndo(), [controller]);
|
|
80
|
+
const canRedo = useCallback(() => controller.canRedo(), [controller]);
|
|
81
|
+
const saving = useCallback(() => controller.saving(), [controller]);
|
|
79
82
|
const hasInflight = useCallback((rowId, columnId) => controller.hasInflight(rowId, columnId), [controller]);
|
|
80
83
|
const pendingBaseline = useCallback((rowId, columnId) => controller.pendingBaseline(rowId, columnId), [controller]);
|
|
81
84
|
const pendingOf = useCallback((rowId) => controller.getPendingByRow().get(rowId), [controller]);
|
|
@@ -99,6 +102,9 @@ export function useGridEditing(onCellCommit, onCellsCommit, onRefused, keepsSent
|
|
|
99
102
|
undo,
|
|
100
103
|
redo,
|
|
101
104
|
reconcile,
|
|
105
|
+
canUndo,
|
|
106
|
+
canRedo,
|
|
107
|
+
saving,
|
|
102
108
|
hasInflight,
|
|
103
109
|
pendingBaseline,
|
|
104
110
|
sent,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FieldConventions } from "viewkitjs/fields";
|
|
2
|
+
import { type ListHold, type ListRow, type ListSettings, type ListTotal } from "viewkitjs/fields/query";
|
|
3
|
+
import type { ListGroup } from "../grouping/types.js";
|
|
4
|
+
import type { FieldBinding } from "../fields/binding.js";
|
|
5
|
+
import type { ListColumn } from "../model/column-schema.js";
|
|
6
|
+
import type { PanelGroupHead, SettingsPanelsInput } from "../panels/settings/input.js";
|
|
7
|
+
import type { ListFieldsRegistry } from "./columns.js";
|
|
8
|
+
/** The values a list's filter offers. */
|
|
9
|
+
export type ListFilterValues = NonNullable<SettingsPanelsInput<ListRow>["filterData"]>;
|
|
10
|
+
/** The rows a list shows, as its root keeps them. */
|
|
11
|
+
export type ListAnswerState<Row extends ListRow = ListRow> = {
|
|
12
|
+
/** The groups the grid draws (one group keyed "all" with label null when the list isn't grouped). */
|
|
13
|
+
groups: ListGroup<Row>[];
|
|
14
|
+
grouped: boolean;
|
|
15
|
+
/** Every bucket's head, hidden ones included, for the group panel. */
|
|
16
|
+
groupHeads: PanelGroupHead[];
|
|
17
|
+
/** The rows in hand, in the order drawn: the selection's order. */
|
|
18
|
+
ids: readonly string[];
|
|
19
|
+
/** How many rows match (rows in memory: `{ count, exact: true }`); null while unknown. */
|
|
20
|
+
total: ListTotal | null;
|
|
21
|
+
/** The values the filter offers. */
|
|
22
|
+
filterValues: ListFilterValues;
|
|
23
|
+
/** A source's first page is out, for the newest settings (always false in memory). */
|
|
24
|
+
loading: boolean;
|
|
25
|
+
/** The source's refusal, in its own words; null, none. */
|
|
26
|
+
refused: string | null;
|
|
27
|
+
/** What there is still to load: the ungrouped list's next page, and each group's (a source's; none in memory). */
|
|
28
|
+
more: {
|
|
29
|
+
rows: boolean;
|
|
30
|
+
groups: Readonly<Record<string, boolean>>;
|
|
31
|
+
};
|
|
32
|
+
/** The rows come a page at a time, from a source: the rows in hand aren't every matching row. */
|
|
33
|
+
paged: boolean;
|
|
34
|
+
/** Each saved view's count, where a source answered them; null, none. */
|
|
35
|
+
viewCounts: Readonly<Record<string, number>> | null;
|
|
36
|
+
/** Each quick filter's values counted, by field and value, where a source answered them; null, none. */
|
|
37
|
+
holdCounts: Readonly<Record<string, Readonly<Record<string, number>>>> | null;
|
|
38
|
+
};
|
|
39
|
+
/** What a list's settings ask of the rows it holds. */
|
|
40
|
+
export declare function answerInMemory<Row extends ListRow>(rows: readonly Row[], settings: ListSettings, fields: ListFieldsRegistry, columns: ListColumn<Row>[], conventions?: FieldConventions, bindings?: Readonly<Record<string, FieldBinding<Row>>>, hold?: ListHold): ListAnswerState<Row>;
|