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
|
@@ -16,6 +16,12 @@ function cellRefusal(model, col) {
|
|
|
16
16
|
return ((col && gridEditRefusal(col, model.listConfig, model.conventions, messages)) ||
|
|
17
17
|
messages({ key: "views.grid.cell-read-only" }));
|
|
18
18
|
}
|
|
19
|
+
function rowWrites(model, row) {
|
|
20
|
+
return model.rowWritable?.(row) ?? true;
|
|
21
|
+
}
|
|
22
|
+
function rowRefusal(model) {
|
|
23
|
+
return (model.messages ?? resolveViewsMessage)({ key: "views.grid.cell-read-only" });
|
|
24
|
+
}
|
|
19
25
|
export function buildGridCopyMatrix(model, rect) {
|
|
20
26
|
const matrix = [];
|
|
21
27
|
for (let r = rect.r1; r <= rect.r2; r++) {
|
|
@@ -61,10 +67,16 @@ export function planGridClear(model, rect) {
|
|
|
61
67
|
if (entry == null)
|
|
62
68
|
continue;
|
|
63
69
|
const { row, rowId } = entry;
|
|
70
|
+
const rowOk = rowWrites(model, row);
|
|
64
71
|
for (let c = rect.c1; c <= rect.c2; c++) {
|
|
65
72
|
const col = model.visibleColumns[c];
|
|
66
73
|
if (!col || !columnWritable(col))
|
|
67
74
|
continue;
|
|
75
|
+
if (!rowOk && !gridColumnLocked(col, model.listConfig)) {
|
|
76
|
+
if (col.clearable || gridBooleanMode(col))
|
|
77
|
+
addRefusal(refusals, rowRefusal(model));
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
68
80
|
if (!col.clearable && !gridBooleanMode(col)) {
|
|
69
81
|
const held = cellEditBaseline(col, row, model.pendingByRow.get(rowId));
|
|
70
82
|
if (!gridColumnLocked(col, model.listConfig) && !holdsNothing(held))
|
|
@@ -137,6 +149,11 @@ export function planGridPaste(model, matrix, anchor, activeRect, selectValuesByC
|
|
|
137
149
|
addRefusal(refusals, cellRefusal(model, col));
|
|
138
150
|
continue;
|
|
139
151
|
}
|
|
152
|
+
if (!rowWrites(model, row)) {
|
|
153
|
+
skipped++;
|
|
154
|
+
addRefusal(refusals, rowRefusal(model));
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
140
157
|
const coerced = coercePaste(col, source, {
|
|
141
158
|
conventions: model.conventions,
|
|
142
159
|
messages: model.messages,
|
|
@@ -231,6 +248,7 @@ export function planGridFill(model, ranges, focused, targetRowId) {
|
|
|
231
248
|
continue;
|
|
232
249
|
const { row: sourceRow, rowId: sourceRowId } = source;
|
|
233
250
|
const { row: nextRow, rowId: nextRowId } = next_;
|
|
251
|
+
const rowOk = rowWrites(model, nextRow);
|
|
234
252
|
for (let c = rect.c1; c <= rect.c2; c++) {
|
|
235
253
|
const col = model.visibleColumns[c];
|
|
236
254
|
if (!col || !columnWritable(col))
|
|
@@ -240,6 +258,11 @@ export function planGridFill(model, ranges, focused, targetRowId) {
|
|
|
240
258
|
addRefusal(refusals, cellRefusal(model, col));
|
|
241
259
|
continue;
|
|
242
260
|
}
|
|
261
|
+
if (!rowOk) {
|
|
262
|
+
skipped++;
|
|
263
|
+
addRefusal(refusals, rowRefusal(model));
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
243
266
|
const sourceBaseline = cellEditBaseline(col, sourceRow, model.pendingByRow.get(sourceRowId));
|
|
244
267
|
const empty = sourceBaseline == null || sourceBaseline === "";
|
|
245
268
|
if (empty && !col.clearable && !gridBooleanMode(col))
|
|
@@ -15,8 +15,9 @@ export type { GridGroupByState, GridSortState } from "./chrome/GridColumnMenu.js
|
|
|
15
15
|
export type { GridGroupSortOption } from "./chrome/GridGroupMenu.js";
|
|
16
16
|
export type { GridGroupMenuPart } from "./chrome/grid-group-menu-parts.js";
|
|
17
17
|
export type { GridRowOpenedFrom } from "./core/row-opened-from.js";
|
|
18
|
-
export type { GridCellAt, GridCellPick, GridDeclaredFigure, GridDrawnFigure, GridGroupFigure, GridPages, GroupCountNoun, } from "./chrome/grid-table-props.js";
|
|
19
|
-
export type { GridCellCommitFn, GridCellsCommitFn, GridCommitContext, GridCommitOutcome, } from "./core/commit-model.js";
|
|
18
|
+
export type { GridCellAt, GridCellPick, GridDeclaredFigure, GridDrawnFigure, GridGroupFigure, GridMenus, GridPages, GroupCountNoun, } from "./chrome/grid-table-props.js";
|
|
19
|
+
export type { GridCellCommitFn, GridCellsCommitFn, GridCommitContext, GridCommitOutcome, ListChange, ListSave, } from "./core/commit-model.js";
|
|
20
|
+
export { gridSave, type GridSaveOptions } from "./core/save-path.js";
|
|
20
21
|
export { deriveGridRelationValues, deriveGridSelectValues } from "./core/column-values.js";
|
|
21
22
|
export { cellCopyText, cellEditBaseline } from "./core/clipboard-model.js";
|
|
22
23
|
export { GRID_TITLE_LINK_CLASS } from "./chrome/grid-cell-classes.js";
|
package/views/dist/grid/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { useGridTablePrefs } from "./useGridTablePrefs.js";
|
|
2
2
|
export { useGridTableSettings } from "./useGridTableSettings.js";
|
|
3
3
|
export { GridTable } from "./chrome/GridTable.js";
|
|
4
|
+
export { gridSave } from "./core/save-path.js";
|
|
4
5
|
export { deriveGridRelationValues, deriveGridSelectValues } from "./core/column-values.js";
|
|
5
6
|
export { cellCopyText, cellEditBaseline } from "./core/clipboard-model.js";
|
|
6
7
|
export { GRID_TITLE_LINK_CLASS } from "./chrome/grid-cell-classes.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** Field rows' card, as a Field in it sees it: where its note and error go, under the card. */
|
|
3
|
+
export interface FieldRowsCard {
|
|
4
|
+
/** A Field joins the card as it comes, and leaves it as it goes: the foot keeps its Fields' notes in that order, the rows'. */
|
|
5
|
+
enter(id: string): () => void;
|
|
6
|
+
/** A Field says whether it has a note or an error to show under the card; the card draws its foot while any does. */
|
|
7
|
+
need(id: string, on: boolean): void;
|
|
8
|
+
/** The Field's own place in the foot, once drawn: it portals its note and error into it. */
|
|
9
|
+
slot(id: string): HTMLElement | null;
|
|
10
|
+
}
|
|
11
|
+
export declare const FieldRowsCardContext: React.Context<FieldRowsCard | null>;
|
|
12
|
+
/** True inside a computer's SettingRows whose Fields option is At the end (VK-985): a Field placed in it is one of its rows, its
|
|
13
|
+
* control at the row's end. */
|
|
14
|
+
export declare const SettingRowField: React.Context<boolean>;
|
|
15
|
+
/** What stands at the end of such a Field row, and the row's name when its label is words: a RadioGroup there draws as a Select
|
|
16
|
+
* of its Radios, named by it. */
|
|
17
|
+
export declare const AtSettingRowEnd: React.Context<{
|
|
18
|
+
name?: string;
|
|
19
|
+
} | null>;
|
|
20
|
+
/** True inside a Field drawn as a row of Field rows: its Input or InputGroup stands typed in place, with no box. */
|
|
21
|
+
export declare const InFieldRow: React.Context<boolean>;
|
|
22
|
+
/** A place of its own: what it holds stands as it does anywhere else, no row of a Field rows card around it, whatever holds it.
|
|
23
|
+
* A popup, an editor and a record's row are each one (React's context reaches through a portal). */
|
|
24
|
+
export declare function OutOfFieldRows({ children }: {
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
}): React.ReactNode;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export const FieldRowsCardContext = React.createContext(null);
|
|
3
|
+
export const SettingRowField = React.createContext(false);
|
|
4
|
+
export const AtSettingRowEnd = React.createContext(null);
|
|
5
|
+
export const InFieldRow = React.createContext(false);
|
|
6
|
+
export function OutOfFieldRows({ children }) {
|
|
7
|
+
return React.createElement(FieldRowsCardContext.Provider, { value: null }, React.createElement(InFieldRow.Provider, { value: false }, React.createElement(SettingRowField.Provider, { value: false }, React.createElement(AtSettingRowEnd.Provider, { value: null }, children))));
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type PageClosePhase = "drafts" | "sends";
|
|
2
|
+
/** Whether the page is going: from its `pagehide` until a `pageshow` brings it back (the back-forward cache). False
|
|
3
|
+
* where there is no window. */
|
|
4
|
+
export declare function isPageClosing(): boolean;
|
|
5
|
+
/** Calls `flush` inside the page's `pagehide`, synchronously, in the order the flushes were added: every `"drafts"`
|
|
6
|
+
* flush, then every `"sends"` one. Returns what takes it off. Nothing where there is no window. */
|
|
7
|
+
export declare function onPageClose(flush: () => void, phase?: PageClosePhase): () => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
let closing = false;
|
|
2
|
+
let listening = false;
|
|
3
|
+
const flushes = { drafts: [], sends: [] };
|
|
4
|
+
function onHide() {
|
|
5
|
+
closing = true;
|
|
6
|
+
for (const phase of ["drafts", "sends"]) {
|
|
7
|
+
for (const flush of [...flushes[phase]]) {
|
|
8
|
+
try {
|
|
9
|
+
flush();
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
queueMicrotask(() => {
|
|
13
|
+
throw error;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function onShow() {
|
|
20
|
+
closing = false;
|
|
21
|
+
}
|
|
22
|
+
function listen() {
|
|
23
|
+
if (listening || typeof window === "undefined")
|
|
24
|
+
return;
|
|
25
|
+
listening = true;
|
|
26
|
+
window.addEventListener("pagehide", onHide, { capture: true });
|
|
27
|
+
window.addEventListener("pageshow", onShow, { capture: true });
|
|
28
|
+
}
|
|
29
|
+
export function isPageClosing() {
|
|
30
|
+
listen();
|
|
31
|
+
return closing;
|
|
32
|
+
}
|
|
33
|
+
export function onPageClose(flush, phase = "sends") {
|
|
34
|
+
listen();
|
|
35
|
+
if (typeof window === "undefined")
|
|
36
|
+
return () => { };
|
|
37
|
+
flushes[phase].push(flush);
|
|
38
|
+
return () => {
|
|
39
|
+
const at = flushes[phase].indexOf(flush);
|
|
40
|
+
if (at >= 0)
|
|
41
|
+
flushes[phase].splice(at, 1);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ViewSeed, ViewsStore } from "./views-store.js";
|
|
2
|
+
export type BrowserViewsStoreOptions = {
|
|
3
|
+
/** The entries' prefix: a list's entry is `${key}:${listId}`. Default "vk:views". */
|
|
4
|
+
key?: string;
|
|
5
|
+
/** The app's own views, by list id: listed first, shared, read-only. */
|
|
6
|
+
seed?: Readonly<Record<string, readonly ViewSeed[]>>;
|
|
7
|
+
/** Where it keeps them; default `window.localStorage` where there is one. `null`: in memory, for the page's life. */
|
|
8
|
+
storage?: Pick<Storage, "getItem" | "setItem"> | null;
|
|
9
|
+
};
|
|
10
|
+
export declare function browserViewsStore(options?: BrowserViewsStoreOptions): ViewsStore;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { listPersonalLayerSchema, listSettingsChangeSchema, savedViewSchema, settingsForSaving, } from "viewkitjs/fields/query";
|
|
2
|
+
const EPOCH = "1970-01-01T00:00:00.000Z";
|
|
3
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
function readEntry(raw) {
|
|
5
|
+
const entry = { views: [], drafts: {}, layer: {} };
|
|
6
|
+
if (!raw)
|
|
7
|
+
return entry;
|
|
8
|
+
let held;
|
|
9
|
+
try {
|
|
10
|
+
held = JSON.parse(raw);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return entry;
|
|
14
|
+
}
|
|
15
|
+
if (!isObject(held) || held.v !== 1)
|
|
16
|
+
return entry;
|
|
17
|
+
if (Array.isArray(held.views)) {
|
|
18
|
+
for (const view of held.views) {
|
|
19
|
+
const read = savedViewSchema.safeParse(view);
|
|
20
|
+
if (read.success && read.data.scope === "personal" && !read.data.readOnly)
|
|
21
|
+
entry.views.push(read.data);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (isObject(held.drafts)) {
|
|
25
|
+
for (const [id, draft] of Object.entries(held.drafts)) {
|
|
26
|
+
if (!isObject(draft) || typeof draft.base !== "string")
|
|
27
|
+
continue;
|
|
28
|
+
const change = listSettingsChangeSchema.safeParse(draft.change);
|
|
29
|
+
if (!change.success)
|
|
30
|
+
continue;
|
|
31
|
+
const { search: _search, ...kept } = change.data;
|
|
32
|
+
entry.drafts[id] = { change: kept, base: draft.base };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const layer = listPersonalLayerSchema.safeParse(held.layer);
|
|
36
|
+
if (layer.success)
|
|
37
|
+
entry.layer = layer.data;
|
|
38
|
+
return entry;
|
|
39
|
+
}
|
|
40
|
+
function refused(what, error) {
|
|
41
|
+
const issue = error.issues[0];
|
|
42
|
+
const where = issue?.path.length ? ` (${issue.path.map(String).join(".")})` : "";
|
|
43
|
+
return new Error(`${what}: ${issue?.message ?? "it doesn't read"}${where}`);
|
|
44
|
+
}
|
|
45
|
+
function defaultStorage() {
|
|
46
|
+
try {
|
|
47
|
+
return typeof window === "undefined" ? null : window.localStorage;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function browserViewsStore(options = {}) {
|
|
54
|
+
const prefix = options.key ?? "vk:views";
|
|
55
|
+
const storage = options.storage === undefined ? defaultStorage() : options.storage;
|
|
56
|
+
const kept = new Map();
|
|
57
|
+
const readers = new Map();
|
|
58
|
+
const keyOf = (listId) => `${prefix}:${listId}`;
|
|
59
|
+
const raw = (key) => {
|
|
60
|
+
if (kept.has(key))
|
|
61
|
+
return kept.get(key);
|
|
62
|
+
try {
|
|
63
|
+
return storage?.getItem(key) ?? null;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const read = (listId) => readEntry(raw(keyOf(listId)));
|
|
70
|
+
const write = (listId, entry) => {
|
|
71
|
+
const key = keyOf(listId);
|
|
72
|
+
const text = JSON.stringify({ v: 1, ...entry });
|
|
73
|
+
try {
|
|
74
|
+
if (!storage)
|
|
75
|
+
throw new Error("no storage");
|
|
76
|
+
storage.setItem(key, text);
|
|
77
|
+
kept.delete(key);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
kept.set(key, text);
|
|
81
|
+
}
|
|
82
|
+
for (const reader of [...(readers.get(listId) ?? [])])
|
|
83
|
+
reader();
|
|
84
|
+
};
|
|
85
|
+
const seedsOf = (listId) => (options.seed?.[listId] ?? []).map((seed, position) => ({
|
|
86
|
+
id: seed.id,
|
|
87
|
+
name: seed.name,
|
|
88
|
+
scope: "shared",
|
|
89
|
+
settings: settingsForSaving(seed.settings),
|
|
90
|
+
position,
|
|
91
|
+
updatedAt: EPOCH,
|
|
92
|
+
readOnly: true,
|
|
93
|
+
}));
|
|
94
|
+
const byPosition = (a, b) => a.position - b.position;
|
|
95
|
+
return {
|
|
96
|
+
list: (listId) => [...seedsOf(listId), ...read(listId).views.sort(byPosition)],
|
|
97
|
+
save: (listId, view) => {
|
|
98
|
+
if (view.scope !== "personal")
|
|
99
|
+
throw new Error("the browser store keeps only a person's own views");
|
|
100
|
+
if (view.id !== undefined && seedsOf(listId).some((seed) => seed.id === view.id)) {
|
|
101
|
+
throw new Error(`${view.id} is declared by the app and can't be changed`);
|
|
102
|
+
}
|
|
103
|
+
const entry = read(listId);
|
|
104
|
+
const was = view.id === undefined ? undefined : entry.views.find((held) => held.id === view.id);
|
|
105
|
+
const last = entry.views.reduce((most, held) => Math.max(most, held.position), -1);
|
|
106
|
+
let stamp = Date.now();
|
|
107
|
+
if (was && stamp <= Date.parse(was.updatedAt))
|
|
108
|
+
stamp = Date.parse(was.updatedAt) + 1;
|
|
109
|
+
const checked = savedViewSchema.safeParse({
|
|
110
|
+
id: view.id ?? globalThis.crypto.randomUUID(),
|
|
111
|
+
name: view.name,
|
|
112
|
+
scope: "personal",
|
|
113
|
+
settings: settingsForSaving(view.settings),
|
|
114
|
+
position: view.id !== undefined ? view.position : last + 1,
|
|
115
|
+
updatedAt: new Date(stamp).toISOString(),
|
|
116
|
+
});
|
|
117
|
+
if (!checked.success)
|
|
118
|
+
throw refused("This view can't be saved", checked.error);
|
|
119
|
+
const saved = checked.data;
|
|
120
|
+
entry.views = was ? entry.views.map((held) => (held.id === saved.id ? saved : held)) : [...entry.views, saved];
|
|
121
|
+
write(listId, entry);
|
|
122
|
+
return saved;
|
|
123
|
+
},
|
|
124
|
+
remove: (listId, id) => {
|
|
125
|
+
const entry = read(listId);
|
|
126
|
+
entry.views = entry.views.filter((held) => held.id !== id);
|
|
127
|
+
delete entry.drafts[id];
|
|
128
|
+
write(listId, entry);
|
|
129
|
+
},
|
|
130
|
+
reorder: (listId, scope, ids) => {
|
|
131
|
+
if (scope !== "personal")
|
|
132
|
+
return;
|
|
133
|
+
const entry = read(listId);
|
|
134
|
+
entry.views = entry.views.map((held) => (ids.includes(held.id) ? { ...held, position: ids.indexOf(held.id) } : held));
|
|
135
|
+
write(listId, entry);
|
|
136
|
+
},
|
|
137
|
+
subscribe: (listId, onChange) => {
|
|
138
|
+
const own = readers.get(listId) ?? new Set();
|
|
139
|
+
readers.set(listId, own);
|
|
140
|
+
own.add(onChange);
|
|
141
|
+
const key = keyOf(listId);
|
|
142
|
+
const heard = (event) => {
|
|
143
|
+
if (event.key === null || event.key === key)
|
|
144
|
+
onChange();
|
|
145
|
+
};
|
|
146
|
+
if (typeof window !== "undefined")
|
|
147
|
+
window.addEventListener("storage", heard);
|
|
148
|
+
return () => {
|
|
149
|
+
own.delete(onChange);
|
|
150
|
+
if (typeof window !== "undefined")
|
|
151
|
+
window.removeEventListener("storage", heard);
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
draft: {
|
|
155
|
+
get: (listId, viewId) => read(listId).drafts[viewId] ?? null,
|
|
156
|
+
set: (listId, viewId, draft) => {
|
|
157
|
+
const entry = read(listId);
|
|
158
|
+
if (draft) {
|
|
159
|
+
const checked = listSettingsChangeSchema.safeParse(draft.change);
|
|
160
|
+
if (!checked.success)
|
|
161
|
+
throw refused("This change can't be kept", checked.error);
|
|
162
|
+
const { search: _search, ...change } = checked.data;
|
|
163
|
+
entry.drafts[viewId] = { change, base: draft.base };
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
delete entry.drafts[viewId];
|
|
167
|
+
write(listId, entry);
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
layer: {
|
|
171
|
+
get: (listId) => read(listId).layer,
|
|
172
|
+
set: (listId, layer) => {
|
|
173
|
+
const checked = listPersonalLayerSchema.safeParse(layer);
|
|
174
|
+
if (!checked.success)
|
|
175
|
+
throw refused("These widths and folds can't be kept", checked.error);
|
|
176
|
+
const entry = read(listId);
|
|
177
|
+
entry.layer = checked.data;
|
|
178
|
+
write(listId, entry);
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { browserViewsStore } from "./browser-views-store.js";
|
|
2
|
+
export type { BrowserViewsStoreOptions } from "./browser-views-store.js";
|
|
3
|
+
export { fetchSource } from "./source.js";
|
|
4
|
+
export { ListRoot } from "./root.js";
|
|
5
|
+
export { ListFill } from "./slot.js";
|
|
6
|
+
export type { ListFillProps } from "./slot.js";
|
|
7
|
+
export type { ListMenus } from "./menu.js";
|
|
8
|
+
export type { ListRootProps } from "./root.js";
|
|
9
|
+
export { ListSlot } from "./slot.js";
|
|
10
|
+
export type { ListSlotProps } from "./slot.js";
|
|
11
|
+
export type { ListSource } from "./source.js";
|
|
12
|
+
export type { ListState } from "./store.js";
|
|
13
|
+
export { ListToolbar } from "./toolbar.js";
|
|
14
|
+
export type { ListToolbarProps } from "./toolbar.js";
|
|
15
|
+
export { menu } from "./menu.js";
|
|
16
|
+
export type { MenuPlace } from "./menu.js";
|
|
17
|
+
export type { ListViewsOptions } from "./root.js";
|
|
18
|
+
export type { ListViewsState } from "./views.js";
|
|
19
|
+
export type { SavedViewInput } from "./views-store.js";
|
|
20
|
+
export { useList } from "./root.js";
|
|
21
|
+
export type { ViewDraft } from "./views-store.js";
|
|
22
|
+
export type { ViewSeed } from "./views-store.js";
|
|
23
|
+
export type { ViewsStore } from "./views-store.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { browserViewsStore } from "./browser-views-store.js";
|
|
2
|
+
export { fetchSource } from "./source.js";
|
|
3
|
+
export { ListRoot } from "./root.js";
|
|
4
|
+
export { ListFill } from "./slot.js";
|
|
5
|
+
export { ListSlot } from "./slot.js";
|
|
6
|
+
export { ListToolbar } from "./toolbar.js";
|
|
7
|
+
export { menu } from "./menu.js";
|
|
8
|
+
export { useList } from "./root.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GridMenus } from "../grid/chrome/grid-table-props.js";
|
|
2
|
+
import type { ToolbarMenus } from "../panels/react/toolbar/ReadyToolbar.js";
|
|
3
|
+
import type { ViewsMenuItem } from "../provider/components.js";
|
|
4
|
+
/** Every menu of a list as data: the grid's (`column`, `row`, `group`, which `GridTable` takes as `menus`) and the toolbar's
|
|
5
|
+
* (`view`, `add`, `more`, which `ReadyToolbar` and `ListToolbar` take as `menus`). Each is handed its default items and hands
|
|
6
|
+
* back the items it shows; a menu with no function is as ViewKit draws it. */
|
|
7
|
+
export type ListMenus<Row> = GridMenus<Row> & ToolbarMenus;
|
|
8
|
+
/** Where a row goes: right after the row of that key, or right before it. */
|
|
9
|
+
export type MenuPlace = {
|
|
10
|
+
after: string;
|
|
11
|
+
} | {
|
|
12
|
+
before: string;
|
|
13
|
+
};
|
|
14
|
+
/** What the helpers reshape: a keyed row, perhaps opening a block, perhaps holding rows of its own. */
|
|
15
|
+
type Keyed<T> = {
|
|
16
|
+
key: string;
|
|
17
|
+
separatorBefore?: boolean;
|
|
18
|
+
children?: T[];
|
|
19
|
+
};
|
|
20
|
+
declare function drop<T extends Keyed<T>>(items: T[], ...keys: string[]): T[];
|
|
21
|
+
declare function rename(items: ViewsMenuItem[], key: string, label: string): ViewsMenuItem[];
|
|
22
|
+
declare function add<T extends Keyed<T>>(items: T[], item: T, place?: MenuPlace): T[];
|
|
23
|
+
declare function move<T extends Keyed<T>>(items: T[], key: string, place: MenuPlace): T[];
|
|
24
|
+
/** The four changes an app's menu function makes to the items it is handed. */
|
|
25
|
+
export declare const menu: {
|
|
26
|
+
drop: typeof drop;
|
|
27
|
+
rename: typeof rename;
|
|
28
|
+
add: typeof add;
|
|
29
|
+
move: typeof move;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const bare = (item) => {
|
|
2
|
+
if (!item.separatorBefore)
|
|
3
|
+
return item;
|
|
4
|
+
const { separatorBefore: _, ...rest } = item;
|
|
5
|
+
return rest;
|
|
6
|
+
};
|
|
7
|
+
const lead = (items) => (items[0]?.separatorBefore ? [bare(items[0]), ...items.slice(1)] : items);
|
|
8
|
+
function inList(items, key, edit) {
|
|
9
|
+
const at = items.findIndex((item) => item.key === key);
|
|
10
|
+
if (at >= 0)
|
|
11
|
+
return edit(items, at);
|
|
12
|
+
for (let i = 0; i < items.length; i++) {
|
|
13
|
+
const children = items[i].children;
|
|
14
|
+
const changed = children ? inList(children, key, edit) : null;
|
|
15
|
+
if (changed)
|
|
16
|
+
return [...items.slice(0, i), { ...items[i], children: changed }, ...items.slice(i + 1)];
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const find = (items, key) => {
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
if (item.key === key)
|
|
23
|
+
return item;
|
|
24
|
+
const inner = item.children && find(item.children, key);
|
|
25
|
+
if (inner)
|
|
26
|
+
return inner;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
};
|
|
30
|
+
function drop(items, ...keys) {
|
|
31
|
+
const gone = new Set(keys);
|
|
32
|
+
const walk = (list) => {
|
|
33
|
+
const out = [];
|
|
34
|
+
let carry = false;
|
|
35
|
+
for (const item of list) {
|
|
36
|
+
if (gone.has(item.key)) {
|
|
37
|
+
carry ||= !!item.separatorBefore;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const children = item.children && walk(item.children);
|
|
41
|
+
if (item.children?.length && !children?.length) {
|
|
42
|
+
carry ||= !!item.separatorBefore;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
let next = children ? { ...item, children } : item;
|
|
46
|
+
if (carry && !next.separatorBefore)
|
|
47
|
+
next = { ...next, separatorBefore: true };
|
|
48
|
+
carry = false;
|
|
49
|
+
out.push(next);
|
|
50
|
+
}
|
|
51
|
+
return lead(out);
|
|
52
|
+
};
|
|
53
|
+
return walk(items);
|
|
54
|
+
}
|
|
55
|
+
function rename(items, key, label) {
|
|
56
|
+
return inList(items, key, (list, at) => [...list.slice(0, at), { ...list[at], label }, ...list.slice(at + 1)]) ?? items;
|
|
57
|
+
}
|
|
58
|
+
function add(items, item, place) {
|
|
59
|
+
const placed = place &&
|
|
60
|
+
inList(items, "after" in place ? place.after : place.before, (list, at) => {
|
|
61
|
+
if ("after" in place)
|
|
62
|
+
return [...list.slice(0, at + 1), item, ...list.slice(at + 1)];
|
|
63
|
+
const anchor = list[at];
|
|
64
|
+
const taken = anchor.separatorBefore ? { ...item, separatorBefore: true } : bare(item);
|
|
65
|
+
return lead([...list.slice(0, at), taken, bare(anchor), ...list.slice(at + 1)]);
|
|
66
|
+
});
|
|
67
|
+
return placed ?? lead([...items, item]);
|
|
68
|
+
}
|
|
69
|
+
function move(items, key, place) {
|
|
70
|
+
const anchor = "after" in place ? place.after : place.before;
|
|
71
|
+
const item = find(items, key);
|
|
72
|
+
if (!item || anchor === key || !find(items, anchor) || find(item.children ?? [], anchor))
|
|
73
|
+
return items;
|
|
74
|
+
return add(drop(items, key), bare(item), place);
|
|
75
|
+
}
|
|
76
|
+
export const menu = { drop, rename, add, move };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolbarPart } from "../panels/react/toolbar/Toolbar.js";
|
|
2
|
+
import type { ToolbarPartPlace, ToolbarParts, ToolbarPartsContext } from "../panels/react/toolbar/ReadyToolbar.js";
|
|
3
|
+
/** Each part's place, in the order the form draws them: the row's start and end, then the bar's (a kit phone's one line). */
|
|
4
|
+
export declare function placesOf(parts: readonly ToolbarPart[], ctx: ToolbarPartsContext): ToolbarPartPlace[];
|
|
5
|
+
/** The form's parts as the app's `toolbarParts` places them. */
|
|
6
|
+
export declare function applyParts(parts: readonly ToolbarPart[], place: ToolbarParts, ctx: ToolbarPartsContext): readonly ToolbarPart[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { arrangeToolbar } from "../panels/toolbar/model.js";
|
|
2
|
+
const kitPhone = (ctx) => ctx.arrangement === "kit" && ctx.phone;
|
|
3
|
+
const lineOf = (part) => ((part.line ?? 1) === 2 ? "bar" : "row");
|
|
4
|
+
export function placesOf(parts, ctx) {
|
|
5
|
+
const byKey = new Map(parts.map((part) => [part.key, part]));
|
|
6
|
+
const place = (part, line) => ({
|
|
7
|
+
key: part.key,
|
|
8
|
+
line,
|
|
9
|
+
side: part.side ?? "start",
|
|
10
|
+
words: part.words ?? "both",
|
|
11
|
+
});
|
|
12
|
+
if (kitPhone(ctx)) {
|
|
13
|
+
const [line] = arrangeToolbar(parts, "phone", { fold: true });
|
|
14
|
+
const slots = line ? [...line.start, ...line.end] : [];
|
|
15
|
+
return slots.flatMap((slot) => {
|
|
16
|
+
const part = byKey.get(slot.key);
|
|
17
|
+
return part ? [place(part, part.key === "new" && part.foot !== false ? "foot" : "row")] : [];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const drawn = (line, side) => parts.filter((part) => lineOf(part) === line && (part.side ?? "start") === side).map((part) => place(part, line));
|
|
21
|
+
return [...drawn("row", "start"), ...drawn("row", "end"), ...drawn("bar", "start"), ...drawn("bar", "end")];
|
|
22
|
+
}
|
|
23
|
+
const samePlaces = (a, b) => a.length === b.length &&
|
|
24
|
+
a.every((p, i) => p.key === b[i].key && p.line === b[i].line && p.side === b[i].side && p.words === b[i].words && p.node === undefined);
|
|
25
|
+
export function applyParts(parts, place, ctx) {
|
|
26
|
+
const given = placesOf(parts, ctx);
|
|
27
|
+
const back = place(given, ctx);
|
|
28
|
+
if (samePlaces(back, given))
|
|
29
|
+
return parts;
|
|
30
|
+
const byKey = new Map(parts.map((part) => [part.key, part]));
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
const one = kitPhone(ctx);
|
|
33
|
+
return back.flatMap((at) => {
|
|
34
|
+
if (seen.has(at.key))
|
|
35
|
+
return [];
|
|
36
|
+
seen.add(at.key);
|
|
37
|
+
const part = byKey.get(at.key);
|
|
38
|
+
const line = !one && at.line === "bar" ? 2 : 1;
|
|
39
|
+
if (!part)
|
|
40
|
+
return at.node === undefined ? [] : [{ key: at.key, line, side: at.side, words: at.words, node: at.node }];
|
|
41
|
+
const own = part.words ?? "both";
|
|
42
|
+
const next = { ...part };
|
|
43
|
+
if (line !== (part.line ?? 1))
|
|
44
|
+
next.line = line;
|
|
45
|
+
if (at.side !== (part.side ?? "start"))
|
|
46
|
+
next.side = at.side;
|
|
47
|
+
if (at.words !== own)
|
|
48
|
+
next.words = at.words;
|
|
49
|
+
if (at.words === "both" && own === "icon" && !part.shed)
|
|
50
|
+
next.shed = true;
|
|
51
|
+
if (one && part.key === "new") {
|
|
52
|
+
if (at.line === "foot")
|
|
53
|
+
delete next.foot;
|
|
54
|
+
else
|
|
55
|
+
next.foot = false;
|
|
56
|
+
}
|
|
57
|
+
return [next];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ListStore } from "./store.js";
|
|
2
|
+
export type ListRegistry = {
|
|
3
|
+
subscribe: (listener: () => void) => () => void;
|
|
4
|
+
store: (id: string) => ListStore | undefined;
|
|
5
|
+
addStore: (id: string, store: ListStore) => () => void;
|
|
6
|
+
slot: (name: string) => HTMLElement | undefined;
|
|
7
|
+
addSlot: (name: string, element: HTMLElement) => () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function createListRegistry(): ListRegistry;
|
|
10
|
+
/** The registry of the `ViewsProvider` around a part; null outside one. */
|
|
11
|
+
export declare const ListRegistryContext: import("react").Context<ListRegistry | null>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
export function createListRegistry() {
|
|
3
|
+
const stores = new Map();
|
|
4
|
+
const slots = new Map();
|
|
5
|
+
const listeners = new Set();
|
|
6
|
+
const tell = () => {
|
|
7
|
+
for (const listener of [...listeners])
|
|
8
|
+
listener();
|
|
9
|
+
};
|
|
10
|
+
const add = (map) => (key, value) => {
|
|
11
|
+
map.set(key, value);
|
|
12
|
+
tell();
|
|
13
|
+
return () => {
|
|
14
|
+
if (map.get(key) !== value)
|
|
15
|
+
return;
|
|
16
|
+
map.delete(key);
|
|
17
|
+
tell();
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
subscribe: (listener) => {
|
|
22
|
+
listeners.add(listener);
|
|
23
|
+
return () => listeners.delete(listener);
|
|
24
|
+
},
|
|
25
|
+
store: (id) => stores.get(id),
|
|
26
|
+
addStore: add(stores),
|
|
27
|
+
slot: (name) => slots.get(name),
|
|
28
|
+
addSlot: add(slots),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export const ListRegistryContext = createContext(null);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ListLinkReading, ListSettings } from "viewkitjs/fields/query";
|
|
3
|
+
import type { ToolbarPanelState } from "../panels/react/toolbar/panel-state.js";
|
|
4
|
+
import { type ListState, type ListStore, type ListSync } from "./store.js";
|
|
5
|
+
import type { ViewSeed, ViewsStore } from "./views-store.js";
|
|
6
|
+
/** The root's saved views: a store, or the browser store with the app's own views for this list. */
|
|
7
|
+
export type ListViewsOptions = {
|
|
8
|
+
store?: ViewsStore;
|
|
9
|
+
/** The app's own views for this list, on the browser store (ignored with `store`): listed first, shared, read-only. */
|
|
10
|
+
seed?: readonly ViewSeed[];
|
|
11
|
+
/** What the list holds, in the delete question's line ("deals"). Default "records". */
|
|
12
|
+
records?: string;
|
|
13
|
+
};
|
|
14
|
+
/** The list root's props: its id, and either its settings and layer as the app holds them (memory mode: what
|
|
15
|
+
* `useListSettingsState` returns, with the shared view), or no settings, and the root keeps them through a store. A
|
|
16
|
+
* root keeps the mode it mounted in. Either way, the toolbar's `sortFilter` and `bar`. */
|
|
17
|
+
export type ListRootProps = {
|
|
18
|
+
id: string;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
} & (ListSync | {
|
|
21
|
+
settings?: undefined;
|
|
22
|
+
/** Where the list's saved views are kept: a store, or options; default `browserViewsStore()`. */
|
|
23
|
+
views?: ViewsStore | ListViewsOptions;
|
|
24
|
+
/** What a list with no saved view shows, and a new view's start. Default `LIST_SETTINGS_DEFAULTS`. */
|
|
25
|
+
defaults?: ListSettings;
|
|
26
|
+
/** The address's reading (`readListLink`) as the list opened: its view and change win over the draft. */
|
|
27
|
+
link?: ListLinkReading;
|
|
28
|
+
sortFilter?: ListSync["sortFilter"];
|
|
29
|
+
bar?: ListSync["bar"];
|
|
30
|
+
});
|
|
31
|
+
export declare function ListRoot({ id, children, ...props }: ListRootProps): ReactNode;
|
|
32
|
+
/** The store of the list root around this part (not on the door). */
|
|
33
|
+
export declare function useListStore(): ListStore;
|
|
34
|
+
/** What this part selects of its list's state: it re-renders only when that changes (by `equal`, `Object.is` by
|
|
35
|
+
* default). Select an action as it stands (`useList((s) => s.openPanel)`): actions never change. Handed an `id` first,
|
|
36
|
+
* it reads the root of that id from anywhere under the `ViewsProvider` (VK-740): `undefined` while none stands. */
|
|
37
|
+
export declare function useList<T>(select: (state: ListState) => T, equal?: (a: T, b: T) => boolean): T;
|
|
38
|
+
export declare function useList<T>(id: string, select: (state: ListState) => T, equal?: (a: T, b: T) => boolean): T | undefined;
|
|
39
|
+
/** One of the root's panels as a part's open state and page, by its key (not on the door). */
|
|
40
|
+
export declare function useListPanel(key: string): ToolbarPanelState;
|