viewkitjs 0.32.0 → 0.34.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 +98 -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 +46 -11
- package/views/dist/contract.js +157 -0
- package/views/dist/controls/alert/alert.js +2 -1
- package/views/dist/controls/alert-dialog/alert-dialog.js +3 -2
- package/views/dist/controls/bulk-bar/bulk-bar.js +25 -22
- 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 +4 -0
- package/views/dist/controls/controls.js +4 -0
- package/views/dist/controls/customize/customize.js +43 -39
- package/views/dist/controls/customize/map-customize-body.d.ts +2 -0
- package/views/dist/controls/customize/map-customize-body.js +7 -2
- package/views/dist/controls/date-editor/date-days.js +2 -2
- package/views/dist/controls/date-editor/date-editor.d.ts +3 -0
- package/views/dist/controls/date-editor/date-editor.js +27 -21
- package/views/dist/controls/date-editor/date-parts.js +6 -6
- package/views/dist/controls/date-editor/map-calendar.js +3 -1
- package/views/dist/controls/date-editor/map-date-body.d.ts +1 -1
- package/views/dist/controls/date-editor/map-date-body.js +7 -3
- 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 +3 -0
- package/views/dist/controls/filter-editor/map-filter-body.js +11 -4
- package/views/dist/controls/filter-editor/map-rules.js +1 -1
- package/views/dist/controls/filter-editor/parts.d.ts +3 -1
- package/views/dist/controls/filter-editor/parts.js +8 -6
- package/views/dist/controls/group-editor/group-editor.js +17 -14
- package/views/dist/controls/group-editor/map-group-body.d.ts +1 -0
- package/views/dist/controls/group-editor/map-group-body.js +5 -1
- package/views/dist/controls/index.d.ts +2 -0
- package/views/dist/controls/index.js +1 -0
- package/views/dist/controls/input/input.js +4 -3
- 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/head-button.d.ts +9 -0
- package/views/dist/controls/internal/head-button.js +13 -0
- 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 +58 -0
- package/views/dist/controls/internal/panel-controls.js +240 -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 +3 -0
- package/views/dist/controls/menu/menu.js +5 -5
- 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/modal/modal.js +5 -3
- 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/map-number-body.js +5 -1
- package/views/dist/controls/number-editor/number-editor.d.ts +1 -1
- package/views/dist/controls/number-editor/number-editor.js +16 -16
- package/views/dist/controls/number-field/number-field.js +5 -3
- package/views/dist/controls/pane/map-pane.d.ts +3 -0
- package/views/dist/controls/pane/map-pane.js +5 -0
- package/views/dist/controls/pane/pane.d.ts +4 -2
- package/views/dist/controls/pane/pane.js +4 -4
- package/views/dist/controls/picker/map-fields-body.js +25 -1
- 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/picker.css +10 -1
- 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/map-quick-filters-body.d.ts +2 -1
- package/views/dist/controls/quick-filters/map-quick-filters-body.js +7 -3
- package/views/dist/controls/quick-filters/quick-filters.js +8 -6
- 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/setting-row/looks.js +5 -5
- package/views/dist/controls/setting-row/setting-row.d.ts +3 -1
- package/views/dist/controls/setting-row/setting-row.js +3 -1
- package/views/dist/controls/setting-row.css +3 -2
- package/views/dist/controls/sheet/bottom-sheet.d.ts +8 -2
- package/views/dist/controls/sheet/bottom-sheet.js +4 -4
- 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 +8 -4
- 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/map-text-body.js +5 -1
- package/views/dist/controls/text-editor/text-editor.d.ts +1 -1
- package/views/dist/controls/text-editor/text-editor.js +11 -10
- package/views/dist/controls/toolbar/toolbar.d.ts +4 -2
- package/views/dist/controls/toolbar/toolbar.js +2 -2
- 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.d.ts +3 -2
- package/views/dist/controls/views-list/map-view-menu.js +7 -3
- package/views/dist/controls/views-list/map-views-list-body.d.ts +2 -1
- package/views/dist/controls/views-list/map-views-list-body.js +6 -5
- package/views/dist/controls/views-list/view-menu.js +9 -10
- package/views/dist/controls/views-list/views-list.js +6 -6
- package/views/dist/editors/EditorPanel.js +4 -4
- 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 +74 -0
- package/views/dist/list/list.js +18 -0
- package/views/dist/list/parts.js +11 -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 +23 -5
- 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 +21 -2
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +2 -2
- package/views/dist/panels/react/toolbar/Toolbar.d.ts +12 -1
- package/views/dist/panels/react/toolbar/Toolbar.js +20 -6
- package/views/dist/panels/react/toolbar/ToolbarAdvancedFilters.js +4 -3
- 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 +4 -3
- package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +5 -4
- 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 +8 -5
- package/views/dist/panels/react/toolbar/context.d.ts +31 -1
- package/views/dist/panels/react/toolbar/context.js +4 -0
- package/views/dist/panels/react/toolbar/pane-host.d.ts +6 -0
- package/views/dist/panels/react/toolbar/pane-host.js +17 -0
- package/views/dist/panels/react/toolbar/panel-part.d.ts +4 -1
- package/views/dist/panels/react/toolbar/panel-part.js +7 -4
- package/views/dist/panels/react.d.ts +1 -1
- package/views/dist/panels/settings/filter-groups.js +6 -1
- package/views/dist/provider/ViewsProvider.d.ts +7 -2
- package/views/dist/provider/ViewsProvider.js +18 -1
- package/views/dist/provider/components.d.ts +90 -2
- 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 +107 -80
- package/views/dist/styles.unlayered.css +107 -80
- package/views/docs/contract.md +310 -7
- package/views/docs/controls/alert-dialog.md +4 -0
- package/views/docs/controls/alert.md +4 -0
- package/views/docs/controls/bulk-bar.md +4 -0
- package/views/docs/controls/compound-editor.md +4 -0
- package/views/docs/controls/customize.md +8 -0
- package/views/docs/controls/date-editor.md +6 -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 +8 -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 +6 -0
- package/views/docs/controls/modal.md +4 -0
- package/views/docs/controls/notice.md +4 -0
- package/views/docs/controls/number-editor.md +6 -0
- package/views/docs/controls/pane.md +4 -0
- package/views/docs/controls/picker.md +8 -0
- package/views/docs/controls/quick-filters.md +8 -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 +6 -0
- package/views/docs/controls/toolbar.md +4 -0
- package/views/docs/controls/values-editor.md +4 -0
- package/views/docs/controls/views-list.md +8 -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 +11 -7
- package/views/docs/reference/field-row.md +1 -1
- package/views/docs/reference/grid.md +1 -1
- package/views/docs/reference/list.md +143 -11
- package/views/docs/reference/looks.md +1 -1
- package/views/docs/reference/panels-react.md +6 -5
- package/views/docs/reference/react.md +19 -12
- package/views/docs/reference/views.md +11 -5
- package/views/docs/reshaping.md +17 -1
- package/views/skills/views/SKILL.md +1 -1
|
@@ -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>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { evaluateView } from "viewkitjs/fields/query";
|
|
2
|
+
import { deriveGridSelectValues } from "../grid/core/column-values.js";
|
|
3
|
+
const NO_MORE = { rows: false, groups: {} };
|
|
4
|
+
export function answerInMemory(rows, settings, fields, columns, conventions, bindings, hold) {
|
|
5
|
+
const keys = Object.keys(fields);
|
|
6
|
+
const { rows: kept, buckets } = evaluateView(rows, {
|
|
7
|
+
filter: settings.filter,
|
|
8
|
+
search: settings.search ? { text: settings.search, fields: keys } : undefined,
|
|
9
|
+
sorts: settings.sorts,
|
|
10
|
+
group: settings.group,
|
|
11
|
+
...(hold?.length && { hold }),
|
|
12
|
+
...(settings.rowOrderMode && { rowOrderMode: settings.rowOrderMode }),
|
|
13
|
+
...(settings.itemPositions && { itemPositions: settings.itemPositions }),
|
|
14
|
+
}, {
|
|
15
|
+
fieldOf: (key) => fields[key],
|
|
16
|
+
read: (row, key) => {
|
|
17
|
+
const binding = bindings?.[key];
|
|
18
|
+
return binding ? binding.read(row) : row[key];
|
|
19
|
+
},
|
|
20
|
+
}, { ...(conventions && { conventions }), rowId: (row) => row.id });
|
|
21
|
+
const groups = buckets
|
|
22
|
+
? buckets.filter((bucket) => !bucket.hidden).map((bucket) => ({ key: bucket.key, label: bucket.label, items: bucket.items }))
|
|
23
|
+
: [{ key: "all", label: null, items: kept }];
|
|
24
|
+
return {
|
|
25
|
+
groups,
|
|
26
|
+
grouped: !!buckets,
|
|
27
|
+
groupHeads: (buckets ?? []).map((bucket) => ({
|
|
28
|
+
key: bucket.key,
|
|
29
|
+
label: bucket.label,
|
|
30
|
+
count: bucket.items.length,
|
|
31
|
+
hidden: bucket.hidden,
|
|
32
|
+
})),
|
|
33
|
+
ids: groups.flatMap((group) => group.items.map((row) => row.id)),
|
|
34
|
+
total: { count: kept.length, exact: true },
|
|
35
|
+
filterValues: { selectValues: deriveGridSelectValues(columns, rows), relationValues: {} },
|
|
36
|
+
loading: false,
|
|
37
|
+
refused: null,
|
|
38
|
+
more: NO_MORE,
|
|
39
|
+
paged: false,
|
|
40
|
+
viewCounts: null,
|
|
41
|
+
holdCounts: null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type SelectionBarProps } from "../selection/SelectionBar.js";
|
|
3
|
+
/** `SelectionBar`'s props but the count and the clear, which the root holds; `verbs` default none. */
|
|
4
|
+
export type ListBulkBarProps = Omit<SelectionBarProps, "count" | "onClear" | "verbs"> & {
|
|
5
|
+
verbs?: SelectionBarProps["verbs"];
|
|
6
|
+
};
|
|
7
|
+
export declare function ListBulkBar({ verbs, ...own }: ListBulkBarProps): ReactNode;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { SelectionBar } from "../selection/SelectionBar.js";
|
|
4
|
+
import { useList } from "./root.js";
|
|
5
|
+
const NONE = [];
|
|
6
|
+
export function ListBulkBar({ verbs = NONE, ...own }) {
|
|
7
|
+
const count = useList((s) => s.selection.count) ?? 0;
|
|
8
|
+
const select = useList((s) => s.select);
|
|
9
|
+
return _jsx(SelectionBar, { ...own, verbs: verbs, count: count, onClear: () => select([]) });
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FieldDef } from "viewkitjs/fields";
|
|
2
|
+
import { type ListRow, type ListSettings } from "viewkitjs/fields/query";
|
|
3
|
+
import { type FieldBinding, type FieldBindingSpec } from "../fields/binding.js";
|
|
4
|
+
import type { ListColumn } from "../model/column-schema.js";
|
|
5
|
+
/** A list's fields: what `defineFields` returns. */
|
|
6
|
+
export type ListFieldsRegistry = Readonly<Record<string, FieldDef>>;
|
|
7
|
+
/** One column's change over what the fields give it. `editable: false` only takes an edit away. `bind`: how the field
|
|
8
|
+
* reads and writes the row, where its key doesn't say (`bindFields`' spec); absent, bound by its key. */
|
|
9
|
+
export type ListColumnOverride<Row = ListRow> = {
|
|
10
|
+
width?: number;
|
|
11
|
+
hidden?: boolean;
|
|
12
|
+
editable?: boolean;
|
|
13
|
+
header?: string;
|
|
14
|
+
bind?: FieldBindingSpec<Row, FieldDef>;
|
|
15
|
+
};
|
|
16
|
+
/** Columns changed by their field's key. */
|
|
17
|
+
export type ListColumnsOverride<Row = ListRow> = Readonly<Record<string, ListColumnOverride<Row>>>;
|
|
18
|
+
export type ListColumnsOf<Row> = {
|
|
19
|
+
columns: ListColumn<Row>[];
|
|
20
|
+
bindings: Readonly<Record<string, FieldBinding<Row>>>;
|
|
21
|
+
/** `LIST_SETTINGS_DEFAULTS` with every field's column, in the registry's order, `visible: !hidden`. */
|
|
22
|
+
defaults: ListSettings;
|
|
23
|
+
};
|
|
24
|
+
export declare function columnsOf<Row extends ListRow>(fields: ListFieldsRegistry, overrides: ListColumnsOverride<Row> | undefined, writable: boolean): ListColumnsOf<Row>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LIST_SETTINGS_DEFAULTS } from "viewkitjs/fields/query";
|
|
2
|
+
import { bindFields } from "../fields/binding.js";
|
|
3
|
+
import { columnFrom } from "../model/column-from.js";
|
|
4
|
+
export function columnsOf(fields, overrides, writable) {
|
|
5
|
+
const keys = Object.keys(fields);
|
|
6
|
+
const specs = {};
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
const bind = overrides?.[key]?.bind;
|
|
9
|
+
if (bind)
|
|
10
|
+
specs[key] = bind;
|
|
11
|
+
}
|
|
12
|
+
const bindings = bindFields(fields, specs);
|
|
13
|
+
const columns = keys.map((key) => {
|
|
14
|
+
const own = overrides?.[key];
|
|
15
|
+
return columnFrom(bindings[key], {
|
|
16
|
+
id: key,
|
|
17
|
+
...(own?.width !== undefined && { width: own.width }),
|
|
18
|
+
...(own?.header !== undefined && { header: own.header }),
|
|
19
|
+
...((!writable || own?.editable === false) && { editable: false }),
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const defaults = {
|
|
23
|
+
...LIST_SETTINGS_DEFAULTS,
|
|
24
|
+
columns: keys.map((key) => ({ key, visible: !overrides?.[key]?.hidden })),
|
|
25
|
+
};
|
|
26
|
+
return { columns, bindings, defaults };
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ListRow } from "viewkitjs/fields/query";
|
|
2
|
+
import type { FieldBinding } from "../fields/binding.js";
|
|
3
|
+
import type { GridCellCommitFn, GridCellsCommitFn, ListSave } from "../grid/core/commit-model.js";
|
|
4
|
+
import type { GridEditsSink } from "../grid/core/edits-sink.js";
|
|
5
|
+
import type { ListStore } from "./store.js";
|
|
6
|
+
export type ListCommits<Row> = {
|
|
7
|
+
onCellCommit: GridCellCommitFn<Row>;
|
|
8
|
+
onCellsCommit: GridCellsCommitFn<Row>;
|
|
9
|
+
};
|
|
10
|
+
/** The root's commits, for the grid under it; null where the list doesn't write. */
|
|
11
|
+
export declare const ListCommitsContext: import("react").Context<ListCommits<ListRow> | null>;
|
|
12
|
+
/** The root's sink, for the grid under it. */
|
|
13
|
+
export declare const ListEditsSinkContext: import("react").Context<GridEditsSink | null>;
|
|
14
|
+
/** `gridSave` made once over the latest `save` and the latest bindings: its queues live in what one call returns.
|
|
15
|
+
* Null when the list doesn't write (no `save`, or `can.edit` false). */
|
|
16
|
+
export declare function useListCommits<Row extends ListRow>(save: ListSave<Row> | undefined, writable: boolean, bindings: Readonly<Record<string, FieldBinding<Row>>> | null): ListCommits<Row> | null;
|
|
17
|
+
/** The sink the root hands its grid: the grid's undo and redo wired into the store, its edits' state patched in on each
|
|
18
|
+
* change, and all of it let go when the grid leaves. */
|
|
19
|
+
export declare function useListEditsSink(store: ListStore): GridEditsSink;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createContext, useMemo, useRef, useLayoutEffect, useState } from "react";
|
|
2
|
+
import { gridSave } from "../grid/core/save-path.js";
|
|
3
|
+
export const ListCommitsContext = createContext(null);
|
|
4
|
+
export const ListEditsSinkContext = createContext(null);
|
|
5
|
+
const NO_EDITS = { saving: false, canUndo: false, canRedo: false };
|
|
6
|
+
function valuesOf(bindings, row, columnId, value) {
|
|
7
|
+
const write = bindings[columnId]?.write;
|
|
8
|
+
if (!write)
|
|
9
|
+
throw new Error(`${columnId} can't be edited`);
|
|
10
|
+
const patch = write(row, value);
|
|
11
|
+
if ("skip" in patch)
|
|
12
|
+
throw new Error(patch.reason ?? "This change can't be saved.");
|
|
13
|
+
return patch.body;
|
|
14
|
+
}
|
|
15
|
+
export function useListCommits(save, writable, bindings) {
|
|
16
|
+
const latest = useRef({ save, bindings });
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
latest.current = { save, bindings };
|
|
19
|
+
});
|
|
20
|
+
const [commits] = useState(() => commitsOver(latest));
|
|
21
|
+
return writable && !!save && !!bindings ? commits : null;
|
|
22
|
+
}
|
|
23
|
+
function commitsOver(latest) {
|
|
24
|
+
return gridSave((change) => latest.current.save?.(change) ?? Promise.reject(new Error("This list no longer saves.")), {
|
|
25
|
+
getRowId: (row) => row.id,
|
|
26
|
+
values: (row, columnId, value) => valuesOf(latest.current.bindings ?? {}, row, columnId, value),
|
|
27
|
+
read: (row, columnId) => {
|
|
28
|
+
const binding = latest.current.bindings?.[columnId];
|
|
29
|
+
return binding ? binding.read(row) : row[columnId];
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function useListEditsSink(store) {
|
|
34
|
+
return useMemo(() => editsSinkOf(store), [store]);
|
|
35
|
+
}
|
|
36
|
+
function editsSinkOf(store) {
|
|
37
|
+
let handle = null;
|
|
38
|
+
return {
|
|
39
|
+
attach: (next) => {
|
|
40
|
+
handle = next;
|
|
41
|
+
store.wire({ undo: () => void next.undo(), redo: () => void next.redo() });
|
|
42
|
+
store.patch({ edits: next.state() });
|
|
43
|
+
return () => {
|
|
44
|
+
if (handle !== next)
|
|
45
|
+
return;
|
|
46
|
+
handle = null;
|
|
47
|
+
store.wire({ undo: undefined, redo: undefined });
|
|
48
|
+
store.patch({ edits: NO_EDITS });
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
changed: () => {
|
|
52
|
+
if (handle)
|
|
53
|
+
store.patch({ edits: handle.state() });
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ListRow } from "viewkitjs/fields/query";
|
|
3
|
+
import type { GridTableProps } from "../grid/chrome/grid-table-props.js";
|
|
4
|
+
/** What the root draws for the grid: every `GridTable` prop is the app's to hand too, and wins over the root's. A
|
|
5
|
+
* `selection` handed is the app's own: the root's picks then stop following the grid, and the children (`ListBulkBar`)
|
|
6
|
+
* aren't drawn. */
|
|
7
|
+
export type ListGridProps<Row extends ListRow> = Partial<GridTableProps<Row>> & {
|
|
8
|
+
/** Drawn where the grid places its selection bar (`ListBulkBar`). */
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function ListGrid<Row extends ListRow>({ children, ...own }: ListGridProps<Row>): ReactNode;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useContext, useLayoutEffect, useMemo, useState } from "react";
|
|
4
|
+
import { GridTable } from "../grid/chrome/GridTable.js";
|
|
5
|
+
import { GridEditsSinkContext } from "../grid/core/edits-sink.js";
|
|
6
|
+
import { useGridTableSettings } from "../grid/useGridTableSettings.js";
|
|
7
|
+
import { LIST_VIEW_PREF_DEFAULTS } from "../model/preferences.js";
|
|
8
|
+
import { settingsPanels } from "../panels/settings/settings-panels.js";
|
|
9
|
+
import { useViews } from "../provider/context.js";
|
|
10
|
+
import { ListCommitsContext, ListEditsSinkContext } from "./edits.js";
|
|
11
|
+
import { useList, useListStore } from "./root.js";
|
|
12
|
+
const FORMATS = {
|
|
13
|
+
gridOptionColors: LIST_VIEW_PREF_DEFAULTS.gridOptionColors,
|
|
14
|
+
gridDateStyles: LIST_VIEW_PREF_DEFAULTS.gridDateStyles,
|
|
15
|
+
gridDurationStyles: LIST_VIEW_PREF_DEFAULTS.gridDurationStyles,
|
|
16
|
+
gridShowTime: LIST_VIEW_PREF_DEFAULTS.gridShowTime,
|
|
17
|
+
gridPercentDisplays: LIST_VIEW_PREF_DEFAULTS.gridPercentDisplays,
|
|
18
|
+
gridDecimals: LIST_VIEW_PREF_DEFAULTS.gridDecimals,
|
|
19
|
+
gridCurrencies: LIST_VIEW_PREF_DEFAULTS.gridCurrencies,
|
|
20
|
+
};
|
|
21
|
+
const getRowId = (row) => row.id;
|
|
22
|
+
const noop = () => { };
|
|
23
|
+
export function ListGrid({ children, ...own }) {
|
|
24
|
+
const store = useListStore();
|
|
25
|
+
const answer = useList((s) => s.answer);
|
|
26
|
+
const rootColumns = useList((s) => s.columns);
|
|
27
|
+
const settings = useList((s) => s.view.settings);
|
|
28
|
+
const layer = useList((s) => s.view.layer);
|
|
29
|
+
const onChange = useList((s) => s.setSettings);
|
|
30
|
+
const onLayerChange = useList((s) => s.setLayer);
|
|
31
|
+
const commits = useContext(ListCommitsContext);
|
|
32
|
+
const sink = useContext(ListEditsSinkContext);
|
|
33
|
+
const handedColumns = own.columns;
|
|
34
|
+
const columns = useMemo(() => handedColumns ?? rootColumns ?? [], [handedColumns, rootColumns]);
|
|
35
|
+
const [formats, setFormatsState] = useState(FORMATS);
|
|
36
|
+
const setFormats = useCallback((patch) => setFormatsState((held) => ({ ...held, ...patch })), []);
|
|
37
|
+
const { gridProps } = useGridTableSettings({ settings, layer, columns, onChange, onLayerChange, formats, setFormats });
|
|
38
|
+
const panels = useMemo(() => settingsPanels({ settings, layer, columns, onChange, onLayerChange, severalSorts: true }), [settings, layer, columns, onChange, onLayerChange]);
|
|
39
|
+
const folded = useMemo(() => new Set(layer.folded ?? []), [layer.folded]);
|
|
40
|
+
const toggleGroup = useCallback((key) => onLayerChange({ folded: folded.has(key) ? [...folded].filter((held) => held !== key) : [...folded, key] }), [folded, onLayerChange]);
|
|
41
|
+
const resetKey = useMemo(() => JSON.stringify([settings.search ?? "", settings.filter, settings.group]), [settings.search, settings.filter, settings.group]);
|
|
42
|
+
const ids = answer?.ids;
|
|
43
|
+
const orderedIds = useMemo(() => (ids ? [...ids] : []), [ids]);
|
|
44
|
+
const selection = useMemo(() => ({
|
|
45
|
+
orderedIds,
|
|
46
|
+
resetKey,
|
|
47
|
+
...(answer?.paged && { retention: "external" }),
|
|
48
|
+
renderBar: (sel) => (_jsx(PublishSelection, { sel: sel, store: store, children: children })),
|
|
49
|
+
}), [orderedIds, resetKey, store, children, answer?.paged]);
|
|
50
|
+
const { LoadMore } = useViews().atoms;
|
|
51
|
+
const loadMore = useList((s) => s.loadMore);
|
|
52
|
+
const loadGroup = useList((s) => s.loadGroup);
|
|
53
|
+
const more = answer?.more;
|
|
54
|
+
const sourced = useMemo(() => ({
|
|
55
|
+
...(more?.rows && { loadMore: { hasMore: true, onReveal: loadMore } }),
|
|
56
|
+
...(more && Object.values(more.groups).some(Boolean) && {
|
|
57
|
+
renderGroupFooter: (group) => more.groups[group.key] && !folded.has(group.key) ? _jsx(LoadMore, { onReveal: () => loadGroup(group.key) }) : null,
|
|
58
|
+
}),
|
|
59
|
+
}), [more, loadMore, loadGroup, folded, LoadMore]);
|
|
60
|
+
if (!answer)
|
|
61
|
+
return null;
|
|
62
|
+
return (_jsx(GridEditsSinkContext.Provider, { value: sink, children: _jsx(GridTable, { ...gridProps, groups: answer.groups, grouped: answer.grouped, getRowId: getRowId, columns: columns, sort: panels.sort, groupBy: panels.groupBy, sortMark: true, isCollapsed: (key) => folded.has(key), onToggleGroup: toggleGroup, onOpenRow: noop, ...commits, selection: selection, ...sourced, ...(answer.refused !== null && { emptyState: answer.refused }), ...(answer.loading && answer.ids.length === 0 && { transitionPending: true }), ...own }) }));
|
|
63
|
+
}
|
|
64
|
+
function PublishSelection({ sel, store, children }) {
|
|
65
|
+
const ids = useMemo(() => [...sel.selectedIds], [sel.selectedIds]);
|
|
66
|
+
useLayoutEffect(() => {
|
|
67
|
+
store.patch({ selection: { ids, all: false, count: ids.length } });
|
|
68
|
+
}, [store, ids]);
|
|
69
|
+
useLayoutEffect(() => () => store.patch({ selection: { ids: [], all: false, count: 0 } }), [store]);
|
|
70
|
+
const { selectAll, setSelected } = sel;
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
store.wire({ select: (next) => (next === "all" ? selectAll() : setSelected([...next])) });
|
|
73
|
+
return () => store.wire({ select: undefined });
|
|
74
|
+
}, [store, selectAll, setSelected]);
|
|
75
|
+
return children ?? null;
|
|
76
|
+
}
|