viewkitjs 0.30.1 → 0.32.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 +143 -0
- package/MIGRATION.md +40 -6
- package/README.md +1 -1
- package/fields/dist/query/index.d.ts +2 -0
- package/fields/dist/query/index.js +2 -0
- package/fields/dist/query/list-request.d.ts +148 -0
- package/fields/dist/query/list-request.js +125 -0
- package/fields/dist/query/saved-view.d.ts +15 -0
- package/fields/dist/query/saved-view.js +11 -0
- package/fields/dist/query/settings.d.ts +9 -0
- package/fields/dist/query/settings.js +9 -0
- package/fields/docs/reference/query.md +66 -0
- package/package.json +8 -2
- package/postgres/README.md +1 -0
- package/postgres/dist/handler.d.ts +53 -0
- package/postgres/dist/handler.js +211 -0
- package/postgres/dist/ids.d.ts +1 -1
- package/postgres/dist/ids.js +19 -1
- package/postgres/dist/index.d.ts +1 -0
- package/postgres/dist/index.js +1 -0
- package/postgres/dist/limits.d.ts +3 -1
- package/postgres/dist/limits.js +1 -1
- package/postgres/dist/list-fields.d.ts +10 -0
- package/postgres/dist/list-fields.js +36 -0
- package/postgres/dist/readable.d.ts +4 -0
- package/postgres/dist/readable.js +4 -0
- package/postgres/dist/refusals.d.ts +9 -2
- package/postgres/dist/refusals.js +6 -0
- package/postgres/docs/guides/field-map.md +2 -2
- package/postgres/docs/guides/list-handler.md +99 -0
- package/postgres/docs/index.md +1 -0
- package/postgres/docs/reference/postgres.md +11 -3
- package/views/README.md +2 -2
- package/views/dist/atoms/RowMenu.d.ts +7 -0
- package/views/dist/atoms/RowMenu.js +18 -16
- package/views/dist/atoms/carried.d.ts +5 -0
- package/views/dist/atoms/carried.js +7 -0
- package/views/dist/atoms/types.d.ts +3 -0
- package/views/dist/contract.d.ts +26 -6
- package/views/dist/contract.js +25 -0
- package/views/dist/controls/alert-dialog/alert-dialog.js +2 -1
- package/views/dist/controls/atoms.d.ts +2 -0
- package/views/dist/controls/atoms.js +2 -0
- package/views/dist/controls/avatar/avatar.d.ts +10 -4
- package/views/dist/controls/avatar/avatar.js +5 -3
- package/views/dist/controls/avatar/tokens.d.ts +104 -0
- package/views/dist/controls/avatar/tokens.js +26 -0
- package/views/dist/controls/avatar.css +46 -15
- package/views/dist/controls/choice/tokens.d.ts +0 -4
- package/views/dist/controls/choice/tokens.js +0 -1
- package/views/dist/controls/choice.css +3 -3
- package/views/dist/controls/controls.d.ts +6 -0
- package/views/dist/controls/controls.js +10 -2
- package/views/dist/controls/customize/map-customize-body.js +1 -1
- package/views/dist/controls/field/field.d.ts +19 -4
- package/views/dist/controls/field/field.js +63 -5
- package/views/dist/controls/field/tokens.d.ts +4 -0
- package/views/dist/controls/field/tokens.js +1 -0
- package/views/dist/controls/field.css +41 -16
- package/views/dist/controls/glyphs/glyphs.d.ts +10 -0
- package/views/dist/controls/glyphs/glyphs.js +173 -0
- package/views/dist/controls/index.d.ts +4 -2
- package/views/dist/controls/index.js +3 -1
- package/views/dist/controls/input/input.d.ts +12 -1
- package/views/dist/controls/input/input.js +10 -6
- package/views/dist/controls/input/save-mark.d.ts +8 -0
- package/views/dist/controls/input/save-mark.js +26 -0
- package/views/dist/controls/input/tokens.d.ts +20 -0
- package/views/dist/controls/input/tokens.js +5 -0
- package/views/dist/controls/input.css +49 -3
- package/views/dist/controls/internal/icons.js +10 -0
- package/views/dist/controls/internal/keep-focus.d.ts +2 -0
- package/views/dist/controls/internal/keep-focus.js +17 -0
- package/views/dist/controls/internal/watch-frame.d.ts +2 -0
- package/views/dist/controls/internal/watch-frame.js +33 -0
- package/views/dist/controls/markdown/map-markdown.d.ts +4 -0
- package/views/dist/controls/markdown/map-markdown.js +5 -0
- package/views/dist/controls/menu/map-menu.js +2 -2
- package/views/dist/controls/menu-list/menu-list.d.ts +3 -0
- package/views/dist/controls/menu-list/menu-list.js +5 -4
- package/views/dist/controls/modal/modal.js +5 -1
- package/views/dist/controls/pane/pane.js +2 -1
- package/views/dist/controls/phone-header/header-bar.d.ts +5 -1
- package/views/dist/controls/phone-header/header-bar.js +2 -2
- package/views/dist/controls/phone-header.css +11 -1
- package/views/dist/controls/picker/map-picker.js +3 -0
- package/views/dist/controls/picker/picker.d.ts +14 -0
- package/views/dist/controls/picker/picker.js +30 -10
- package/views/dist/controls/picker.css +2 -0
- package/views/dist/controls/popover/popover.js +2 -1
- package/views/dist/controls/radio/radio.d.ts +12 -3
- package/views/dist/controls/radio/radio.js +25 -5
- package/views/dist/controls/radio/tokens.d.ts +84 -0
- package/views/dist/controls/radio/tokens.js +21 -0
- package/views/dist/controls/radio.css +130 -3
- package/views/dist/controls/select/select.d.ts +12 -2
- package/views/dist/controls/select/select.js +15 -7
- package/views/dist/controls/select/tokens.d.ts +8 -0
- package/views/dist/controls/select/tokens.js +2 -0
- package/views/dist/controls/select.css +17 -0
- package/views/dist/controls/setting-row/looks.d.ts +10 -0
- package/views/dist/controls/setting-row/looks.js +22 -0
- package/views/dist/controls/setting-row/setting-row.d.ts +100 -0
- package/views/dist/controls/setting-row/setting-row.js +133 -0
- package/views/dist/controls/setting-row/tokens.d.ts +156 -0
- package/views/dist/controls/setting-row/tokens.js +41 -0
- package/views/dist/controls/setting-row.css +215 -0
- package/views/dist/controls/sheet/bottom-sheet.d.ts +10 -2
- package/views/dist/controls/sheet/bottom-sheet.js +6 -3
- package/views/dist/controls/sheet.css +4 -1
- package/views/dist/controls/sort-editor/sort-editor.js +3 -2
- package/views/dist/controls/sort-editor.css +8 -2
- package/views/dist/controls/switch-row/switch-row.d.ts +1 -15
- package/views/dist/controls/switch-row/switch-row.js +1 -9
- package/views/dist/controls/switch-row/tokens.d.ts +0 -12
- package/views/dist/controls/switch-row/tokens.js +0 -3
- package/views/dist/controls/switch-row.css +3 -7
- package/views/dist/controls/switch.css +17 -7
- package/views/dist/controls/tag/tag.d.ts +3 -1
- package/views/dist/controls/tag/tag.js +2 -2
- package/views/dist/controls/tag/tokens.d.ts +4 -0
- package/views/dist/controls/tag/tokens.js +1 -0
- package/views/dist/controls/tag-field/tag-field.d.ts +5 -1
- package/views/dist/controls/tag-field/tag-field.js +11 -5
- package/views/dist/controls/tag-field/tokens.d.ts +16 -0
- package/views/dist/controls/tag-field/tokens.js +4 -0
- package/views/dist/controls/tag-field.css +19 -0
- package/views/dist/controls/tag.css +2 -0
- package/views/dist/controls/tokens.js +2 -0
- package/views/dist/controls/toolbar/toolbar.d.ts +15 -3
- package/views/dist/controls/toolbar/toolbar.js +22 -15
- package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +14 -0
- package/views/dist/controls/toolbar-button/atom-toolbar-button.js +51 -0
- package/views/dist/controls/toolbar-button/toolbar-button.d.ts +1 -1
- package/views/dist/controls/toolbar-button/toolbar-button.js +2 -3
- package/views/dist/controls/toolbar-button.css +4 -0
- package/views/dist/controls/toolbar.css +5 -0
- package/views/dist/controls/views-list/map-view-menu.d.ts +3 -0
- package/views/dist/controls/views-list/map-view-menu.js +25 -0
- package/views/dist/controls/views-list/map-views-list-body.d.ts +28 -1
- package/views/dist/controls/views-list/map-views-list-body.js +39 -21
- package/views/dist/controls/views-list/rules.d.ts +2 -0
- package/views/dist/controls/views-list/view-menu.d.ts +7 -0
- package/views/dist/controls/views-list/view-menu.js +28 -24
- package/views/dist/controls/views-list/words.d.ts +2 -0
- package/views/dist/controls/views-list/words.js +1 -1
- package/views/dist/editors/EditorPanel.js +2 -1
- package/views/dist/editors/edit-session.js +2 -5
- package/views/dist/field-row/FieldRow.d.ts +4 -2
- package/views/dist/field-row/FieldRow.js +67 -20
- package/views/dist/field-row/FieldRowLane.d.ts +7 -2
- package/views/dist/field-row/FieldRowLane.js +4 -3
- package/views/dist/field-row/editors/RowEditor.d.ts +12 -0
- package/views/dist/field-row/editors/RowEditor.js +31 -1
- package/views/dist/field-row/editors/RowValueListEditor.d.ts +5 -1
- package/views/dist/field-row/editors/RowValueListEditor.js +4 -1
- package/views/dist/field-row/field-row-button.d.ts +5 -0
- package/views/dist/field-row/field-row-button.js +2 -0
- package/views/dist/fields/binding.d.ts +3 -2
- package/views/dist/fields/binding.js +38 -5
- package/views/dist/grid/chrome/GridColumnMenu.d.ts +4 -2
- package/views/dist/grid/chrome/GridColumnMenu.js +3 -2
- package/views/dist/grid/chrome/GridGroupMenu.d.ts +4 -1
- package/views/dist/grid/chrome/GridGroupMenu.js +4 -3
- package/views/dist/grid/chrome/GridHeader.d.ts +4 -1
- package/views/dist/grid/chrome/GridHeader.js +2 -2
- package/views/dist/grid/chrome/GridRow.js +6 -5
- package/views/dist/grid/chrome/GridRowCells.js +6 -9
- package/views/dist/grid/chrome/GridStructure.d.ts +4 -1
- package/views/dist/grid/chrome/GridStructure.js +4 -4
- package/views/dist/grid/chrome/GridTable.js +5 -2
- package/views/dist/grid/chrome/grid-column-menu-items.js +1 -1
- package/views/dist/grid/chrome/grid-row-menu-items.d.ts +27 -3
- package/views/dist/grid/chrome/grid-row-menu-items.js +92 -6
- package/views/dist/grid/chrome/grid-row-props.d.ts +7 -2
- package/views/dist/grid/chrome/grid-rows-menu.js +34 -6
- package/views/dist/grid/chrome/grid-table-props.d.ts +38 -7
- package/views/dist/grid/chrome/useGridBatchApi.d.ts +3 -1
- package/views/dist/grid/chrome/useGridBatchApi.js +4 -2
- package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -2
- package/views/dist/grid/chrome/useGridKeyboard.js +15 -9
- package/views/dist/grid/chrome/useGridPendingReconciliation.js +1 -2
- package/views/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -1
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +11 -5
- package/views/dist/grid/core/commit-model.d.ts +20 -2
- package/views/dist/grid/core/editing-controller.d.ts +18 -0
- package/views/dist/grid/core/editing-controller.js +188 -42
- package/views/dist/grid/core/editing-model.d.ts +3 -0
- package/views/dist/grid/core/editing-model.js +3 -0
- package/views/dist/grid/core/save-path.d.ts +24 -0
- package/views/dist/grid/core/save-path.js +122 -0
- package/views/dist/grid/core/spreadsheet-operations.d.ts +3 -0
- package/views/dist/grid/core/spreadsheet-operations.js +23 -0
- package/views/dist/grid/index.d.ts +3 -2
- package/views/dist/grid/index.js +1 -0
- package/views/dist/internal/field-rows.d.ts +26 -0
- package/views/dist/internal/field-rows.js +8 -0
- package/views/dist/internal/page-close.d.ts +7 -0
- package/views/dist/internal/page-close.js +43 -0
- package/views/dist/list/browser-views-store.d.ts +10 -0
- package/views/dist/list/browser-views-store.js +182 -0
- package/views/dist/list/index.d.ts +23 -0
- package/views/dist/list/index.js +8 -0
- package/views/dist/list/menu.d.ts +31 -0
- package/views/dist/list/menu.js +76 -0
- package/views/dist/list/parts.d.ts +6 -0
- package/views/dist/list/parts.js +59 -0
- package/views/dist/list/registry.d.ts +11 -0
- package/views/dist/list/registry.js +31 -0
- package/views/dist/list/root.d.ts +40 -0
- package/views/dist/list/root.js +128 -0
- package/views/dist/list/slot.d.ts +14 -0
- package/views/dist/list/slot.js +22 -0
- package/views/dist/list/source.d.ts +11 -0
- package/views/dist/list/source.js +31 -0
- package/views/dist/list/store.d.ts +87 -0
- package/views/dist/list/store.js +115 -0
- package/views/dist/list/toolbar.d.ts +6 -0
- package/views/dist/list/toolbar.js +359 -0
- package/views/dist/list/views-axis.d.ts +5 -0
- package/views/dist/list/views-axis.js +96 -0
- package/views/dist/list/views-store.d.ts +41 -0
- package/views/dist/list/views-store.js +1 -0
- package/views/dist/list/views.d.ts +67 -0
- package/views/dist/list/views.js +400 -0
- package/views/dist/looks/index.d.ts +1 -0
- package/views/dist/looks/index.js +1 -0
- package/views/dist/looks/pieces.js +2 -0
- package/views/dist/model/preferences.js +1 -1
- package/views/dist/model/prefs-buckets.js +1 -1
- package/views/dist/panels/index.d.ts +3 -1
- package/views/dist/panels/index.js +1 -0
- package/views/dist/panels/react/customize-body.js +1 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +41 -4
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +6 -326
- package/views/dist/panels/react/toolbar/Toolbar.d.ts +9 -1
- package/views/dist/panels/react/toolbar/Toolbar.js +34 -23
- package/views/dist/panels/react/toolbar/ToolbarButton.js +4 -1
- package/views/dist/panels/react/toolbar/ToolbarNew.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +2 -2
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +3 -1
- package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
- package/views/dist/panels/react/toolbar/context.d.ts +10 -2
- package/views/dist/panels/react/toolbar/context.js +3 -1
- package/views/dist/panels/react/views-row/FoldingViewRow.d.ts +1 -1
- package/views/dist/panels/react/views-row/FoldingViewRow.js +15 -4
- package/views/dist/panels/react/views-row/PillGroup.d.ts +5 -2
- package/views/dist/panels/react/views-row/PillGroup.js +16 -7
- package/views/dist/panels/react/views-row/ViewPicker.js +2 -12
- package/views/dist/panels/react/views-row/ViewPickerRow.d.ts +4 -2
- package/views/dist/panels/react/views-row/ViewPickerRow.js +9 -5
- package/views/dist/panels/react.d.ts +2 -2
- package/views/dist/panels/toolbar/edit-view.d.ts +7 -1
- package/views/dist/panels/toolbar/edit-view.js +14 -0
- package/views/dist/panels/toolbar/model.d.ts +5 -0
- package/views/dist/panels/toolbar/model.js +7 -3
- package/views/dist/panels/view-state.d.ts +5 -3
- package/views/dist/panels/views-row/model.d.ts +19 -2
- package/views/dist/panels/views-row/model.js +14 -0
- package/views/dist/provider/ViewsProvider.d.ts +16 -7
- package/views/dist/provider/ViewsProvider.js +23 -5
- package/views/dist/provider/components.d.ts +43 -2
- package/views/dist/provider/context.d.ts +2 -1
- package/views/dist/provider/context.js +1 -1
- package/views/dist/provider/ports.d.ts +19 -12
- package/views/dist/provider/ports.js +69 -1
- package/views/dist/react.d.ts +1 -1
- package/views/dist/styles.css +583 -61
- package/views/dist/styles.unlayered.css +583 -61
- package/views/docs/contract.md +42 -31
- package/views/docs/controls/avatar.md +26 -0
- package/views/docs/controls/choice.md +0 -1
- package/views/docs/controls/field.md +3 -0
- package/views/docs/controls/input.md +9 -0
- package/views/docs/controls/radio.md +33 -0
- package/views/docs/controls/select.md +6 -0
- package/views/docs/controls/setting-row.md +44 -0
- package/views/docs/controls/switch-row.md +0 -3
- package/views/docs/controls/tag-field.md +4 -0
- package/views/docs/controls/tag.md +1 -0
- package/views/docs/getting-started.md +2 -2
- package/views/docs/guides/atoms.md +2 -2
- package/views/docs/guides/columns.md +1 -1
- package/views/docs/guides/ports.md +1 -1
- package/views/docs/guides/the-grid.md +34 -7
- package/views/docs/guides/the-provider.md +4 -2
- package/views/docs/index.md +1 -0
- package/views/docs/reference/controls.md +54 -27
- package/views/docs/reference/editors-session.md +1 -1
- package/views/docs/reference/field-row.md +9 -1
- package/views/docs/reference/grid.md +14 -8
- package/views/docs/reference/list.md +227 -0
- package/views/docs/reference/looks.md +3 -0
- package/views/docs/reference/panels-react.md +17 -12
- package/views/docs/reference/panels.md +8 -5
- package/views/docs/reference/react.md +11 -9
- package/views/docs/reference/views.md +2 -2
- package/views/skills/views/SKILL.md +9 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { deleteAsking } from "../../atoms/RowMenu.js";
|
|
3
4
|
import { columnClearRefusal, columnEditRefusal, columnWritable, gridBooleanMode, } from "../../model/column-capabilities.js";
|
|
4
5
|
import { cellClearPrev, cellCopyShown, cellEditBaseline, cellPrevPayload, coercePaste, copyCell, gridFigureOverlay, getGridClipboard, rowHoldsCurrency, } from "./cell-clipboard.js";
|
|
5
6
|
function nameActionItems(row, actions, hostItems) {
|
|
@@ -17,10 +18,39 @@ function nameActionItems(row, actions, hostItems) {
|
|
|
17
18
|
if (!icon)
|
|
18
19
|
continue;
|
|
19
20
|
const run = action.onClick;
|
|
20
|
-
items.push({ label, icon, onClick: () => run(row) });
|
|
21
|
+
items.push({ key: `action:${action.id}`, label, icon, onClick: () => run(row) });
|
|
21
22
|
}
|
|
22
23
|
return items.length > 0 ? [...items, { separator: true }] : [];
|
|
23
24
|
}
|
|
25
|
+
export function rowMenuItemsOf(rows) {
|
|
26
|
+
const items = [];
|
|
27
|
+
let rule = false;
|
|
28
|
+
for (const row of rows) {
|
|
29
|
+
if (row.separator) {
|
|
30
|
+
rule = items.length > 0;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const { key, onClick, separator: _, ...rest } = row;
|
|
34
|
+
items.push({ ...rest, key: key ?? row.label, onSelect: onClick, ...(rule && { separatorBefore: true }) });
|
|
35
|
+
rule = false;
|
|
36
|
+
}
|
|
37
|
+
return items;
|
|
38
|
+
}
|
|
39
|
+
export function rowMenuRows(items) {
|
|
40
|
+
return items.flatMap((item, at) => {
|
|
41
|
+
const row = {
|
|
42
|
+
key: item.key,
|
|
43
|
+
label: item.label,
|
|
44
|
+
onClick: item.onSelect ?? (() => { }),
|
|
45
|
+
...(item.icon !== undefined && { icon: item.icon }),
|
|
46
|
+
...(item.destructive && { destructive: true }),
|
|
47
|
+
...(item.disabled && { disabled: true }),
|
|
48
|
+
...(item.disabledReason !== undefined && { disabledReason: item.disabledReason }),
|
|
49
|
+
...(item.shortcut !== undefined && { shortcut: item.shortcut }),
|
|
50
|
+
};
|
|
51
|
+
return item.separatorBefore && at > 0 ? [{ separator: true }, row] : [row];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
24
54
|
export function gridRowMenuColumnAt(menuRow, target) {
|
|
25
55
|
const { columns, selecting, rowRange, rowKey, onFocusCell } = menuRow;
|
|
26
56
|
const columnId = target?.closest("[data-col-id]")?.getAttribute("data-col-id");
|
|
@@ -33,8 +63,9 @@ export function gridRowMenuColumnAt(menuRow, target) {
|
|
|
33
63
|
}
|
|
34
64
|
return column?.id ?? null;
|
|
35
65
|
}
|
|
36
|
-
export function gridRowMenuItems(menuRow, menuColumnId,
|
|
37
|
-
const {
|
|
66
|
+
export function gridRowMenuItems(menuRow, menuColumnId, views) {
|
|
67
|
+
const { conventions, ports, messages, icons } = views;
|
|
68
|
+
const { row, id, rowKey, columns, rowActions, selecting, selectable, selected, toggle, editingEnabled, rowWritable = true, pendingByCol, selectValues, contextMenu, rowMenuReshape, inActiveRange, rangeCanClear, onRangeCopy, onRangeCut, onRangePaste, onRangeClear, onPasteAtCell, onCommitCell, } = menuRow;
|
|
38
69
|
const copyLabel = messages({ key: "views.menus.copy" });
|
|
39
70
|
const cutLabel = messages({ key: "views.menus.cut" });
|
|
40
71
|
const pasteLabel = messages({ key: "views.menus.paste" });
|
|
@@ -44,13 +75,14 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
44
75
|
: undefined;
|
|
45
76
|
const editBaseline = (column) => cellEditBaseline(column, row, pendingByCol);
|
|
46
77
|
const copy = (column, unit) => void copyCell(ports.clipboard.writeText, column, editBaseline(column), unit, cellCopyShown(column, row, pendingByCol));
|
|
47
|
-
const canEdit = (column) => editingEnabled && columnWritable(column);
|
|
78
|
+
const canEdit = (column) => editingEnabled && rowWritable && columnWritable(column);
|
|
48
79
|
const off = (reason) => reason === null ? { disabled: false } : { disabled: true, disabledReason: reason };
|
|
49
80
|
const nothingToPaste = messages({ key: "views.grid.paste-empty" });
|
|
50
81
|
const cellItems = [];
|
|
51
82
|
if (menuColumn && !selecting && inActiveRange(rowKey, menuColumn.id)) {
|
|
52
83
|
const clipboard = getGridClipboard();
|
|
53
84
|
cellItems.push({
|
|
85
|
+
key: "copy",
|
|
54
86
|
label: copyLabel,
|
|
55
87
|
icon: _jsx(icons.copy, { className: "h-4 w-4" }),
|
|
56
88
|
shortcut: "⌘C",
|
|
@@ -59,18 +91,21 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
59
91
|
if (editingEnabled) {
|
|
60
92
|
const clearOff = off(rangeCanClear() ? null : messages({ key: "views.menus.range-not-clearable" }));
|
|
61
93
|
cellItems.push({
|
|
94
|
+
key: "cut",
|
|
62
95
|
label: cutLabel,
|
|
63
96
|
icon: _jsx(icons.cut, { className: "h-4 w-4" }),
|
|
64
97
|
shortcut: "⌘X",
|
|
65
98
|
...clearOff,
|
|
66
99
|
onClick: onRangeCut,
|
|
67
100
|
}, {
|
|
101
|
+
key: "paste",
|
|
68
102
|
label: pasteLabel,
|
|
69
103
|
icon: _jsx(icons.paste, { className: "h-4 w-4" }),
|
|
70
104
|
shortcut: "⌘V",
|
|
71
105
|
...off(clipboard ? null : nothingToPaste),
|
|
72
106
|
onClick: onRangePaste,
|
|
73
107
|
}, {
|
|
108
|
+
key: "clear",
|
|
74
109
|
label: clearLabel,
|
|
75
110
|
icon: _jsx(icons.clear, { className: "h-4 w-4" }),
|
|
76
111
|
...clearOff,
|
|
@@ -85,7 +120,8 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
85
120
|
const canClear = canWrite && (!!menuColumn.clearable || gridBooleanMode(menuColumn) != null);
|
|
86
121
|
const editRefusal = canWrite
|
|
87
122
|
? null
|
|
88
|
-
: (columnEditRefusal(menuColumn, conventions, messages) ??
|
|
123
|
+
: ((columnWritable(menuColumn) ? undefined : columnEditRefusal(menuColumn, conventions, messages)) ??
|
|
124
|
+
messages({ key: "views.grid.cell-read-only" }));
|
|
89
125
|
const clearOff = off(editRefusal ?? (canClear ? null : columnClearRefusal(menuColumn, messages)));
|
|
90
126
|
const clipboard = getGridClipboard();
|
|
91
127
|
const paste = canWrite && clipboard && !clipboard.matrix
|
|
@@ -99,6 +135,7 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
99
135
|
})
|
|
100
136
|
: null;
|
|
101
137
|
cellItems.push({
|
|
138
|
+
key: "copy",
|
|
102
139
|
label: copyLabel,
|
|
103
140
|
icon: _jsx(icons.copy, { className: "h-4 w-4" }),
|
|
104
141
|
shortcut: "⌘C",
|
|
@@ -106,6 +143,7 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
106
143
|
});
|
|
107
144
|
if (editingEnabled) {
|
|
108
145
|
cellItems.push({
|
|
146
|
+
key: "cut",
|
|
109
147
|
label: cutLabel,
|
|
110
148
|
icon: _jsx(icons.cut, { className: "h-4 w-4" }),
|
|
111
149
|
shortcut: "⌘X",
|
|
@@ -115,6 +153,7 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
115
153
|
onCommitCell(row, id, menuColumn.id, cellClearPrev(menuColumn, row, pendingByCol), "");
|
|
116
154
|
},
|
|
117
155
|
}, {
|
|
156
|
+
key: "paste",
|
|
118
157
|
label: pasteLabel,
|
|
119
158
|
icon: _jsx(icons.paste, { className: "h-4 w-4" }),
|
|
120
159
|
shortcut: "⌘V",
|
|
@@ -130,6 +169,7 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
130
169
|
}
|
|
131
170
|
},
|
|
132
171
|
}, {
|
|
172
|
+
key: "clear",
|
|
133
173
|
label: clearLabel,
|
|
134
174
|
icon: _jsx(icons.clear, { className: "h-4 w-4" }),
|
|
135
175
|
...clearOff,
|
|
@@ -141,6 +181,7 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
141
181
|
const selectItems = selectable
|
|
142
182
|
? [
|
|
143
183
|
{
|
|
184
|
+
key: "row-select",
|
|
144
185
|
label: messages({ key: "views.menus.row-select", values: { selected: selected ? "true" : "false" } }),
|
|
145
186
|
icon: _jsx(icons.selectRow, { className: "h-4 w-4" }),
|
|
146
187
|
onClick: () => toggle(id),
|
|
@@ -155,5 +196,50 @@ export function gridRowMenuItems(menuRow, menuColumnId, { conventions, ports, me
|
|
|
155
196
|
...nameActionItems(row, rowActions, hostItems),
|
|
156
197
|
...hostItems,
|
|
157
198
|
];
|
|
158
|
-
|
|
199
|
+
if (!rowMenuReshape)
|
|
200
|
+
return contextItems;
|
|
201
|
+
const href = menuRow.rowHref?.(row);
|
|
202
|
+
const onDelete = menuRow.onRowDelete;
|
|
203
|
+
const deleteLabel = menuRow.deleteLabel;
|
|
204
|
+
return [
|
|
205
|
+
...(href
|
|
206
|
+
? [
|
|
207
|
+
{
|
|
208
|
+
key: "row-open",
|
|
209
|
+
label: messages({ key: "views.menus.row-open" }),
|
|
210
|
+
icon: _jsx(icons.open, { className: "h-4 w-4" }),
|
|
211
|
+
onClick: () => void window.open(href, "_blank", "noopener,noreferrer"),
|
|
212
|
+
},
|
|
213
|
+
{ separator: true },
|
|
214
|
+
]
|
|
215
|
+
: []),
|
|
216
|
+
...contextItems,
|
|
217
|
+
...(onDelete
|
|
218
|
+
? [
|
|
219
|
+
{ separator: true },
|
|
220
|
+
{
|
|
221
|
+
key: "row-delete",
|
|
222
|
+
label: messages({ key: "views.menus.row-delete" }),
|
|
223
|
+
icon: _jsx(icons.delete, { className: "h-4 w-4" }),
|
|
224
|
+
destructive: true,
|
|
225
|
+
onClick: () => deleteAsking(views, onDelete, id, deleteLabel),
|
|
226
|
+
},
|
|
227
|
+
]
|
|
228
|
+
: []),
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
export function rowMenuWaiting({ messages, icons }) {
|
|
232
|
+
return [
|
|
233
|
+
{
|
|
234
|
+
key: "row-waiting",
|
|
235
|
+
label: messages({ key: "views.menus.row-waiting" }),
|
|
236
|
+
icon: _jsx(icons.loading, { className: "h-4 w-4" }),
|
|
237
|
+
disabled: true,
|
|
238
|
+
onClick: () => { },
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
export function reshapeRowMenu(reshape, rows, row) {
|
|
243
|
+
const shaped = reshape(rowMenuItemsOf(rows), { row });
|
|
244
|
+
return Array.isArray(shaped) ? rowMenuRows(shaped) : Promise.resolve(shaped).then(rowMenuRows);
|
|
159
245
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GridMenus } from "./grid-table-props.js";
|
|
1
2
|
import type { ReactNode } from "react";
|
|
2
3
|
import type { ViewsRowMenuItem } from "../../atoms/types.js";
|
|
3
4
|
import type { FieldMenus } from "../../fields/menus.js";
|
|
@@ -35,6 +36,8 @@ export type GridRowProps<Row> = {
|
|
|
35
36
|
toggle: (id: string, next?: boolean) => void;
|
|
36
37
|
toggleRange: (id: string) => void;
|
|
37
38
|
contextMenu?: (row: Row) => ViewsRowMenuItem[];
|
|
39
|
+
/** The app's function for the row's menu (`GridMenus.row`). */
|
|
40
|
+
rowMenuReshape?: GridMenus<Row>["row"];
|
|
38
41
|
rowClassName?: (row: Row) => string | undefined;
|
|
39
42
|
rowHref?: (row: Row) => string | undefined;
|
|
40
43
|
/** Opens the row from the cell at `at` (its key and column), which the grid's opener turns into the app's `from`. */
|
|
@@ -99,13 +102,15 @@ export type GridRowProps<Row> = {
|
|
|
99
102
|
/** Workspace-settings capability locks (table read-only / per-column) — subtracts from
|
|
100
103
|
* what the columns declare. Memo-stable: threaded straight from the host. */
|
|
101
104
|
listConfig?: ListSettingsConfig;
|
|
105
|
+
/** The grid's `rowWritable` answer for THIS row: false, and none of its cells writes. Default true. */
|
|
106
|
+
rowWritable?: boolean;
|
|
102
107
|
onFocusCell: (rowId: string, columnId: string) => void;
|
|
103
108
|
/** Open a cell's editor. `seed`: the character that opened it (type-to-replace). `whole`: the
|
|
104
109
|
* text was cut off in its cell, so it opens whole in the panel over the cell. */
|
|
105
110
|
onStartEdit: (rowId: string, columnId: string, seed?: string | null, whole?: boolean) => void;
|
|
106
111
|
/** A second click or a double-click on a cell that opens nothing: the grid
|
|
107
|
-
* says why it can't be edited (or nothing, when it can be written). */
|
|
108
|
-
onRefuseEdit?: (columnId: string) => void;
|
|
112
|
+
* says why it can't be edited (or nothing, when it can be written); `rowOk` false: the row is refused. */
|
|
113
|
+
onRefuseEdit?: (columnId: string, rowOk?: boolean) => void;
|
|
109
114
|
/** Tab out of an editor → next/prev cell in reading order (grid-owned so it
|
|
110
115
|
* matches Tab-while-focused; wraps rows). */
|
|
111
116
|
onEditorTab: (rowId: string, columnId: string, backwards: boolean) => void;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { cloneElement, createContext, useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
4
4
|
import { useViews } from "../../provider/context.js";
|
|
5
|
-
import { gridRowMenuColumnAt, gridRowMenuItems } from "./grid-row-menu-items.js";
|
|
5
|
+
import { gridRowMenuColumnAt, gridRowMenuItems, reshapeRowMenu, rowMenuWaiting } from "./grid-row-menu-items.js";
|
|
6
6
|
const ROW = '[data-slot="vk-grid-row"]';
|
|
7
7
|
function rowKeyAt(container, target) {
|
|
8
8
|
const row = target instanceof Element ? target.closest(ROW) : null;
|
|
@@ -16,6 +16,9 @@ export function GridRowsMenu({ rowPropsFor, selectable, answerHeldPress, childre
|
|
|
16
16
|
const RowMenu = views.atoms.RowMenu;
|
|
17
17
|
const [aim, setAim] = useState(null);
|
|
18
18
|
const [menuColumnId, setMenuColumnId] = useState(null);
|
|
19
|
+
const [opening, setOpening] = useState(null);
|
|
20
|
+
const openings = useRef(0);
|
|
21
|
+
const [answer, setAnswer] = useState(null);
|
|
19
22
|
const aimRef = useRef(null);
|
|
20
23
|
const touchTimer = useRef(null);
|
|
21
24
|
const settle = () => {
|
|
@@ -29,20 +32,45 @@ export function GridRowsMenu({ rowPropsFor, selectable, answerHeldPress, childre
|
|
|
29
32
|
aimRef.current = key;
|
|
30
33
|
setAim(key);
|
|
31
34
|
setMenuColumnId(columnId);
|
|
35
|
+
setOpening(null);
|
|
32
36
|
};
|
|
33
|
-
const latest = useRef({ rowPropsFor, aimAt, aim });
|
|
37
|
+
const latest = useRef({ rowPropsFor, aimAt, aim, views });
|
|
34
38
|
useLayoutEffect(() => {
|
|
35
|
-
latest.current = { rowPropsFor, aimAt, aim };
|
|
39
|
+
latest.current = { rowPropsFor, aimAt, aim, views };
|
|
36
40
|
});
|
|
37
41
|
const [aimByRow] = useState(() => (rowKey, event) => {
|
|
38
42
|
const aimed = latest.current.rowPropsFor(rowKey);
|
|
39
43
|
if (!aimed)
|
|
40
44
|
return;
|
|
41
45
|
AIMED.add(event.nativeEvent);
|
|
42
|
-
|
|
46
|
+
const columnId = gridRowMenuColumnAt(aimed, event.target instanceof Element ? event.target : null);
|
|
47
|
+
latest.current.aimAt(rowKey, columnId);
|
|
48
|
+
openings.current += 1;
|
|
49
|
+
const opened = openings.current;
|
|
50
|
+
setOpening(opened);
|
|
51
|
+
const shape = aimed.rowMenuReshape;
|
|
52
|
+
if (!shape)
|
|
53
|
+
return;
|
|
54
|
+
const rows = gridRowMenuItems(aimed, columnId, latest.current.views);
|
|
55
|
+
const shaped = reshapeRowMenu(shape, rows, aimed.row);
|
|
56
|
+
if (Array.isArray(shaped)) {
|
|
57
|
+
setAnswer({ opening: opened, rows: "now" });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setAnswer({ opening: opened, rows: null });
|
|
61
|
+
const land = (answered) => setAnswer((current) => (current?.opening === opened ? { opening: opened, rows: answered } : current));
|
|
62
|
+
shaped.then(land, () => land(rows));
|
|
43
63
|
});
|
|
44
64
|
const props = aim != null ? rowPropsFor(aim) : null;
|
|
45
|
-
const
|
|
65
|
+
const reshape = props?.rowMenuReshape;
|
|
66
|
+
const own = props ? gridRowMenuItems(props, menuColumnId, views) : [];
|
|
67
|
+
const opened = props && reshape ? opening : null;
|
|
68
|
+
let items = own;
|
|
69
|
+
if (props && reshape) {
|
|
70
|
+
const rows = answer && answer.opening === opened ? answer.rows : null;
|
|
71
|
+
const now = rows === "now" ? reshapeRowMenu(reshape, own, props.row) : rows;
|
|
72
|
+
items = Array.isArray(now) ? now : rowMenuWaiting(views);
|
|
73
|
+
}
|
|
46
74
|
const [target] = useState(() => ({
|
|
47
75
|
onPointerDownCapture: (event) => {
|
|
48
76
|
const key = rowKeyAt(event.currentTarget, event.target);
|
|
@@ -73,7 +101,7 @@ export function GridRowsMenu({ rowPropsFor, selectable, answerHeldPress, childre
|
|
|
73
101
|
},
|
|
74
102
|
}));
|
|
75
103
|
const rows = cloneElement(children, target);
|
|
76
|
-
return (_jsx(GridRowMenuAimContext.Provider, { value: aimByRow, children: _jsx(RowMenu, { rowId: props?.id ?? "", items: items, openHref: props ? props.rowHref?.(props.row) : undefined, onDelete: props?.onRowDelete, deleteLabel: props?.deleteLabel, onToggleSelect: selectable
|
|
104
|
+
return (_jsx(GridRowMenuAimContext.Provider, { value: aimByRow, children: _jsx(RowMenu, { rowId: props?.id ?? "", items: items, openHref: props && !reshape ? props.rowHref?.(props.row) : undefined, onDelete: reshape ? undefined : props?.onRowDelete, deleteLabel: props?.deleteLabel, onToggleSelect: selectable
|
|
77
105
|
? () => {
|
|
78
106
|
if (answerHeldPress?.())
|
|
79
107
|
return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import type { FieldDef } from "viewkitjs/fields";
|
|
2
3
|
import type { DisplayCurrency } from "../../fields/currency.js";
|
|
3
4
|
import type { ViewsRowMenuItem } from "../../atoms/types.js";
|
|
4
5
|
import type { ViewsMenuItem } from "../../provider/components.js";
|
|
@@ -17,6 +18,28 @@ import type { GridCellCommitFn, GridCellsCommitFn } from "../core/commit-model.j
|
|
|
17
18
|
import type { GridGroupByState, GridSortState } from "./GridColumnMenu.js";
|
|
18
19
|
import type { GridGroupSortOption } from "./GridGroupMenu.js";
|
|
19
20
|
import type { GridGroupMenuPart } from "./grid-group-menu-parts.js";
|
|
21
|
+
/** Each of the grid's menus as a function from its default items to the items it shows (`menu.drop`, `menu.rename`,
|
|
22
|
+
* `menu.add` and `menu.move` on `viewkitjs/views/list` do the usual changes). `column` gets the column and its field,
|
|
23
|
+
* `row` the row, `group` the group its band names. Each reshapes a menu the grid opens: a column or band whose menu holds
|
|
24
|
+
* none of the grid's rows stays without one. Called while a menu draws: keep them pure and cheap.
|
|
25
|
+
*
|
|
26
|
+
* `row` is asked as a row's menu opens (a right-click, the row's ⋯, the menu key), never for a row drawn or pressed, and
|
|
27
|
+
* may answer later: a promise is asked once per opening, the menu holding one greyed row that waits (`row-waiting`) until
|
|
28
|
+
* it answers, an answer that an opening since has outrun dropped, and one that fails drawing the grid's own rows. Its
|
|
29
|
+
* items hold Open page and Delete (`row-open`, `row-delete`, from `rowHref` and `onRowDelete`): drop `row-delete` for a
|
|
30
|
+
* row that can't be deleted. */
|
|
31
|
+
export type GridMenus<Row> = {
|
|
32
|
+
column?: (items: ViewsMenuItem[], ctx: {
|
|
33
|
+
field: FieldDef | undefined;
|
|
34
|
+
column: ListColumn<Row>;
|
|
35
|
+
}) => ViewsMenuItem[];
|
|
36
|
+
row?: (items: ViewsMenuItem[], ctx: {
|
|
37
|
+
row: Row;
|
|
38
|
+
}) => ViewsMenuItem[] | Promise<ViewsMenuItem[]>;
|
|
39
|
+
group?: (items: ViewsMenuItem[], ctx: {
|
|
40
|
+
group: ListGroup<Row>;
|
|
41
|
+
}) => ViewsMenuItem[];
|
|
42
|
+
};
|
|
20
43
|
/** A group count's noun, singular and plural ("company", "companies"): "2 companies". None: a bare
|
|
21
44
|
* count. */
|
|
22
45
|
export type GroupCountNoun = {
|
|
@@ -167,15 +190,16 @@ export type GridTableProps<Row> = {
|
|
|
167
190
|
sort?: GridSortState;
|
|
168
191
|
/** A sorted column's header wears `icons.sortAsc` or `icons.sortDesc` after its name. Default false. */
|
|
169
192
|
sortMark?: boolean;
|
|
170
|
-
/** The
|
|
171
|
-
*
|
|
193
|
+
/** The list's group, for a column menu's Group by and Ungroup, wherever you keep it (a saved view, the page's
|
|
194
|
+
* address): handed, every column whose field can split the list offers them, as `sort` offers Sort. */
|
|
172
195
|
groupBy?: GridGroupByState;
|
|
173
196
|
sortOptions?: GridGroupSortOption[];
|
|
174
197
|
/** Which figures ride beside a group name — a set, not a choice. */
|
|
175
198
|
groupSummary?: ListGroupSummaryPart[];
|
|
176
199
|
aggregates?: Record<string, ListAggregateKind>;
|
|
177
200
|
onAggregateChange?: (columnId: string, kind: ListAggregateKind) => void;
|
|
178
|
-
/**
|
|
201
|
+
/** The grid shows a saved view: Sort on every bound column, columns placed by the view, and figures only for
|
|
202
|
+
* field-backed columns. It doesn't decide Group by, which follows `groupBy` alone. */
|
|
179
203
|
viewBacked?: boolean;
|
|
180
204
|
onGroupSummaryChange?: (part: ListGroupSummaryPart, next: boolean) => void;
|
|
181
205
|
/** The figures a group header can show, in the list's order: each declared by its column and kind, or drawn
|
|
@@ -228,10 +252,11 @@ export type GridTableProps<Row> = {
|
|
|
228
252
|
* a sort's `fieldKey` and `by`), copies, edits and pastes as its part; an edit commits the whole column's id and
|
|
229
253
|
* the whole value with that part replaced, locked, refused and limited as its whole. Off by default. */
|
|
230
254
|
parts?: boolean;
|
|
231
|
-
/**
|
|
232
|
-
*
|
|
233
|
-
|
|
234
|
-
/** The host's rows for a column's field, as data, drawn just above Hide
|
|
255
|
+
/** Each menu's items reshaped by your function: a column's, a row's and a group band's (`GridMenus`). Without it, each
|
|
256
|
+
* menu holds the grid's rows and what `columnMenuItems`, `rowMenu`, `contextMenu` and `groupMenu` add. */
|
|
257
|
+
menus?: GridMenus<Row>;
|
|
258
|
+
/** The host's rows for a column's field, as data, drawn just above Hide (the old route: `menus.column` reshapes the
|
|
259
|
+
* whole menu); null or an empty
|
|
235
260
|
* list for a field the host adds nothing to. Their keys must not reuse the package's own (`sort-asc`,
|
|
236
261
|
* `hide-column` and the rest). It is called while the grid renders, for every column: keep it pure and cheap. */
|
|
237
262
|
columnMenuItems?: (fieldKey: string) => ViewsMenuItem[] | null;
|
|
@@ -263,6 +288,12 @@ export type GridTableProps<Row> = {
|
|
|
263
288
|
* `declaration → config → prefs` — it may only SUBTRACT from what the
|
|
264
289
|
* columns declare. UI constraint only; the host's API guards its own writes. */
|
|
265
290
|
listConfig?: ListSettingsConfig;
|
|
291
|
+
/** Whether a row's cells write, per row: a row it answers false for opens no editor, takes no typing, paste, fill,
|
|
292
|
+
* clear, cut or bulk-bar write, says "Cell is read-only" when a person tries, and marks its cells `aria-readonly`,
|
|
293
|
+
* as a read-only column's are. It only takes away: a column that doesn't write stays read-only on every row. Absent:
|
|
294
|
+
* every row writes as its columns say. Called while the grid renders, for every row: keep it pure and cheap. A
|
|
295
|
+
* constraint on the screen, while your API guards its own writes. */
|
|
296
|
+
rowWritable?: (row: Row) => boolean;
|
|
266
297
|
/** A row drawn as under the pointer, by its id: its tint, its rail's box, its ⋯ and the name's actions, as a real
|
|
267
298
|
* hover draws them, and `data-hovered` on the row. A real pointer still hovers any row beside it. Every copy of a
|
|
268
299
|
* record a grouping draws twice. Drawn, as a hover is, only on a screen whose pointer hovers (`any-hover`). Absent
|
|
@@ -16,12 +16,14 @@ import type { ListColumn } from "../../model/column-schema.js";
|
|
|
16
16
|
* oversized-debt ceiling whose policy says split the responsibility rather than
|
|
17
17
|
* raise the number.
|
|
18
18
|
*/
|
|
19
|
-
export declare function useGridBatchApi<Row>({ enabled, columns, listConfig, rows, getRowId, pendingByRow, commitBatch, }: {
|
|
19
|
+
export declare function useGridBatchApi<Row>({ enabled, columns, listConfig, rowWritable, rows, getRowId, pendingByRow, commitBatch, }: {
|
|
20
20
|
/** The grid can write at all (the host passed a commit handler). */
|
|
21
21
|
enabled: boolean;
|
|
22
22
|
/** Visible columns — the id resolves against what the user can actually see. */
|
|
23
23
|
columns: ListColumn<Row>[];
|
|
24
24
|
listConfig: ListSettingsConfig | undefined;
|
|
25
|
+
/** The grid's `rowWritable`: a row it refuses is passed over. */
|
|
26
|
+
rowWritable?: (row: Row) => boolean;
|
|
25
27
|
/** Every loaded row, for resolving selected ids to row objects. */
|
|
26
28
|
rows: Row[];
|
|
27
29
|
getRowId: (row: Row) => string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { cellEditBaseline, cellPrevPayload, gridFigureOverlay, gridPasteOverlay } from "./cell-clipboard.js";
|
|
4
4
|
import { columnEffectiveWritable } from "../../model/column-capabilities.js";
|
|
5
|
-
export function useGridBatchApi({ enabled, columns, listConfig, rows, getRowId, pendingByRow, commitBatch, }) {
|
|
5
|
+
export function useGridBatchApi({ enabled, columns, listConfig, rowWritable, rows, getRowId, pendingByRow, commitBatch, }) {
|
|
6
6
|
return useMemo(() => {
|
|
7
7
|
if (!enabled)
|
|
8
8
|
return undefined;
|
|
@@ -18,6 +18,8 @@ export function useGridBatchApi({ enabled, columns, listConfig, rows, getRowId,
|
|
|
18
18
|
const row = byId.get(rowId);
|
|
19
19
|
if (row == null)
|
|
20
20
|
continue;
|
|
21
|
+
if (rowWritable && !rowWritable(row))
|
|
22
|
+
continue;
|
|
21
23
|
const prev = cellPrevPayload(col, cellEditBaseline(col, row, pendingByRow.get(rowId)), col.editUnit?.value(row));
|
|
22
24
|
edits.push({
|
|
23
25
|
row,
|
|
@@ -32,5 +34,5 @@ export function useGridBatchApi({ enabled, columns, listConfig, rows, getRowId,
|
|
|
32
34
|
return commitBatch(edits);
|
|
33
35
|
},
|
|
34
36
|
};
|
|
35
|
-
}, [enabled, columns, listConfig, rows, getRowId, pendingByRow, commitBatch]);
|
|
37
|
+
}, [enabled, columns, listConfig, rowWritable, rows, getRowId, pendingByRow, commitBatch]);
|
|
36
38
|
}
|
|
@@ -5,7 +5,7 @@ import type { ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
|
5
5
|
import type { ListColumn } from "../../model/column-schema.js";
|
|
6
6
|
import type { GridRangeVerbs } from "./useGridRangeActions.js";
|
|
7
7
|
import { type GridChromeTarget, type GridFocusShape } from "../core/grid-focus.js";
|
|
8
|
-
export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, 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, }: {
|
|
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
9
|
rootRef: RefObject<HTMLDivElement | null>;
|
|
10
10
|
/** A column name, a footer cell, a bar or a checkbox holding the focus (`useGridFocus`); null: a data cell, or
|
|
11
11
|
* nothing. */
|
|
@@ -29,6 +29,8 @@ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell
|
|
|
29
29
|
/** Workspace-settings capability config — the keyboard routes ask the same effective
|
|
30
30
|
* write gate the cells do, so a lock holds here too. */
|
|
31
31
|
listConfig?: ListSettingsConfig;
|
|
32
|
+
/** The grid's per-row answer: a row it refuses takes no edit from a key, as a locked column doesn't. */
|
|
33
|
+
rowWritable?: (row: Row) => boolean;
|
|
32
34
|
visibleRowIds: string[];
|
|
33
35
|
/** Row key → the rendered row and its DATA id. Focus is a KEY; a commit needs
|
|
34
36
|
* the record and the id behind it. */
|
|
@@ -55,7 +57,7 @@ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell
|
|
|
55
57
|
cancelEdit: () => void;
|
|
56
58
|
commitEdit: (row: Row, rowId: string, columnId: string, previous: unknown, next: unknown) => void;
|
|
57
59
|
/** Say why a cell can't be written; answers whether it said anything. */
|
|
58
|
-
refuseEdit: (columnId: string) => boolean;
|
|
60
|
+
refuseEdit: (columnId: string, rowOk?: boolean) => boolean;
|
|
59
61
|
undo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
|
|
60
62
|
redo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
|
|
61
63
|
/** This grid is the one the page edited last (`useGridEditing`'s `isLastEdited`): with the focus in no grid's frame,
|
|
@@ -30,7 +30,7 @@ function eventBelongsElsewhere(target, root) {
|
|
|
30
30
|
return true;
|
|
31
31
|
return !!target.closest(INTERACTIVE) && !root?.contains(target);
|
|
32
32
|
}
|
|
33
|
-
export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, 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, }) {
|
|
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
34
|
const { ports, messages } = useViews();
|
|
35
35
|
const navFromEditorRef = useRef({ tab: () => { }, enter: () => { } });
|
|
36
36
|
const onEditorTab = useCallback((rowId, columnId, backwards) => navFromEditorRef.current.tab(rowId, columnId, backwards), []);
|
|
@@ -247,6 +247,11 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
247
247
|
};
|
|
248
248
|
function handleCellKey(event, focusedCell, leave) {
|
|
249
249
|
const resolveFocused = () => resolveFocusedAt(focusedCell);
|
|
250
|
+
const rowOk = () => {
|
|
251
|
+
const { row } = resolveFocused();
|
|
252
|
+
return row == null || (rowWritable?.(row) ?? true);
|
|
253
|
+
};
|
|
254
|
+
const cellWrites = (column) => columnEffectiveWritable(column, listConfig) && rowOk();
|
|
250
255
|
const mod = (event.metaKey || event.ctrlKey) && !event.shiftKey && !event.altKey;
|
|
251
256
|
const bare = !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
|
|
252
257
|
const navDirection = NAV_KEYS[event.key];
|
|
@@ -329,7 +334,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
329
334
|
isWholeTextColumn(column) &&
|
|
330
335
|
gridCellCutOff(findGridCell(rootRef.current, focusedCell));
|
|
331
336
|
if (column &&
|
|
332
|
-
((editingEnabled && gridColumnHasEditor(column) &&
|
|
337
|
+
((editingEnabled && gridColumnHasEditor(column) && cellWrites(column)) ||
|
|
333
338
|
gridColumnInspectable(column) ||
|
|
334
339
|
whole)) {
|
|
335
340
|
startEdit(focusedCell.rowId, focusedCell.columnId, undefined, whole, true);
|
|
@@ -338,7 +343,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
338
343
|
if (column &&
|
|
339
344
|
editingEnabled &&
|
|
340
345
|
gridBooleanMode(column) === "toggle" &&
|
|
341
|
-
|
|
346
|
+
cellWrites(column)) {
|
|
342
347
|
const { row, rowId } = resolveFocused();
|
|
343
348
|
if (row != null) {
|
|
344
349
|
const on = cellEditBaseline(column, row, pendingByRow.get(rowId)) === true;
|
|
@@ -346,7 +351,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
346
351
|
return;
|
|
347
352
|
}
|
|
348
353
|
}
|
|
349
|
-
if (column && refuseEdit(column.id))
|
|
354
|
+
if (column && refuseEdit(column.id, rowOk()))
|
|
350
355
|
return;
|
|
351
356
|
const next = nextCellPos(focusedCell, "down", visibleRowIds, visibleColIds);
|
|
352
357
|
if (!next)
|
|
@@ -377,7 +382,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
377
382
|
const { column, row, rowId } = resolveFocused();
|
|
378
383
|
if (!column || row == null)
|
|
379
384
|
return;
|
|
380
|
-
if (!editingEnabled || !
|
|
385
|
+
if (!editingEnabled || !cellWrites(column))
|
|
381
386
|
return;
|
|
382
387
|
if (!gridBooleanMode(column) && !column.clearable)
|
|
383
388
|
return;
|
|
@@ -396,8 +401,8 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
396
401
|
const { column, row, rowId } = resolveFocused();
|
|
397
402
|
if (!column || row == null || !editingEnabled)
|
|
398
403
|
return;
|
|
399
|
-
if (!
|
|
400
|
-
if (!refuseEdit(column.id))
|
|
404
|
+
if (!cellWrites(column)) {
|
|
405
|
+
if (!refuseEdit(column.id, rowOk()))
|
|
401
406
|
ports.toast.error(gridClearRefusal(column, listConfig, messages));
|
|
402
407
|
return;
|
|
403
408
|
}
|
|
@@ -417,8 +422,8 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
417
422
|
const column = visibleColumns.find((item) => item.id === focusedCell.columnId);
|
|
418
423
|
if (!column)
|
|
419
424
|
return;
|
|
420
|
-
if (!
|
|
421
|
-
if (refuseEdit(column.id))
|
|
425
|
+
if (!cellWrites(column)) {
|
|
426
|
+
if (refuseEdit(column.id, rowOk()))
|
|
422
427
|
event.preventDefault();
|
|
423
428
|
return;
|
|
424
429
|
}
|
|
@@ -444,6 +449,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
|
|
|
444
449
|
getRowId,
|
|
445
450
|
lastCellRef,
|
|
446
451
|
listConfig,
|
|
452
|
+
rowWritable,
|
|
447
453
|
releaseToFrame,
|
|
448
454
|
messages,
|
|
449
455
|
pendingByRow,
|
|
@@ -26,7 +26,6 @@ export function useGridPendingReconciliation({ rows, columns, getRowId, pendingB
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
const matched = findGridPendingMatches(rows, columns, getRowId, pendingByRow, hasInflight);
|
|
29
|
-
|
|
30
|
-
reconcile(matched);
|
|
29
|
+
reconcile(matched);
|
|
31
30
|
}, [columns, getRowId, hasInflight, messages, pendingBaseline, pendingByRow, ports, reconcile, rows]);
|
|
32
31
|
}
|
|
@@ -72,7 +72,7 @@ export declare function useGridTableInteractionModel<Row>({ rootRef, props, rows
|
|
|
72
72
|
commitBatch: (edits: (GridEditCell<Row> & {
|
|
73
73
|
row: Row;
|
|
74
74
|
})[]) => Promise<boolean>;
|
|
75
|
-
refuseEdit: (columnId: string) => boolean;
|
|
75
|
+
refuseEdit: (columnId: string, rowOk?: boolean) => boolean;
|
|
76
76
|
onExtendCell: (rowId: string, columnId: string) => void;
|
|
77
77
|
onAddCell: (rowId: string, columnId: string) => void;
|
|
78
78
|
handleRootPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -20,7 +20,7 @@ import { useGridRangeGestures } from "./useGridRangeGestures.js";
|
|
|
20
20
|
import { useGridCellPick } from "./useGridCellPick.js";
|
|
21
21
|
const REFUSAL_REPEAT_MS = 600;
|
|
22
22
|
export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows, heldRows, rowIndex, visibleColumns, selecting, revealRow, focusShape, groupOfRow, }) {
|
|
23
|
-
const { columns, getRowId, listConfig } = props;
|
|
23
|
+
const { columns, getRowId, listConfig, rowWritable } = props;
|
|
24
24
|
const { conventions, ports, messages } = useViews();
|
|
25
25
|
const editingEnabled = !!props.onCellCommit;
|
|
26
26
|
const sayRefusal = useCallback((refusal) => {
|
|
@@ -133,13 +133,17 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
|
|
|
133
133
|
return commitBatchRaw(kept);
|
|
134
134
|
}, [columnById, commitBatchRaw, conventions, messages, ports, lockedRefusal, wholeStored]);
|
|
135
135
|
const lastRefusalRef = useRef(null);
|
|
136
|
-
const refuseEdit = useCallback((columnId) => {
|
|
136
|
+
const refuseEdit = useCallback((columnId, rowOk = true) => {
|
|
137
137
|
if (!editingEnabled)
|
|
138
138
|
return false;
|
|
139
139
|
const col = visibleColumns.find((c) => c.id === columnId);
|
|
140
|
-
if (!col
|
|
140
|
+
if (!col)
|
|
141
141
|
return false;
|
|
142
|
-
const reason =
|
|
142
|
+
const reason = !columnEffectiveWritable(col, listConfig)
|
|
143
|
+
? gridEditRefusal(col, listConfig, conventions, messages)
|
|
144
|
+
: rowOk
|
|
145
|
+
? undefined
|
|
146
|
+
: messages({ key: "views.grid.cell-read-only" });
|
|
143
147
|
if (!reason)
|
|
144
148
|
return false;
|
|
145
149
|
const now = Date.now();
|
|
@@ -229,7 +233,8 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
|
|
|
229
233
|
conventions,
|
|
230
234
|
messages,
|
|
231
235
|
listConfig,
|
|
232
|
-
|
|
236
|
+
rowWritable,
|
|
237
|
+
}), [rows, rowIndex, visibleRows, visibleColumns, pendingByRow, conventions, messages, listConfig, rowWritable]);
|
|
233
238
|
const revealCell = useCallback((pos, behavior) => revealGridCell(rootRef.current, pos, behavior, revealRow), [revealRow, rootRef]);
|
|
234
239
|
const finishFillRef = useRef(() => { });
|
|
235
240
|
const { fillTargetRow, onExtendCell, onAddCell, handleRootPointerDown, handleRootPointerDownCapture, handleRootClickCapture, } = useGridRangeGestures({
|
|
@@ -275,6 +280,7 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
|
|
|
275
280
|
editingCell,
|
|
276
281
|
editingEnabled,
|
|
277
282
|
listConfig,
|
|
283
|
+
rowWritable,
|
|
278
284
|
visibleRowIds: visibleRows,
|
|
279
285
|
visibleColIds: visibleColumnIds,
|
|
280
286
|
visibleColumns,
|