viewkitjs 0.31.0 → 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 +129 -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 +5 -1
- 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 +3 -3
- package/views/dist/controls/avatar/avatar.js +1 -1
- package/views/dist/controls/avatar/tokens.d.ts +44 -0
- package/views/dist/controls/avatar/tokens.js +11 -0
- package/views/dist/controls/avatar.css +22 -5
- 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 +2 -1
- package/views/dist/controls/index.js +2 -1
- package/views/dist/controls/input/input.js +5 -2
- package/views/dist/controls/input/tokens.d.ts +4 -0
- package/views/dist/controls/input/tokens.js +1 -0
- package/views/dist/controls/input.css +31 -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 +5 -3
- package/views/dist/controls/radio/radio.js +18 -2
- package/views/dist/controls/radio/tokens.d.ts +44 -0
- package/views/dist/controls/radio/tokens.js +11 -0
- package/views/dist/controls/radio.css +79 -1
- package/views/dist/controls/select/select.d.ts +4 -0
- package/views/dist/controls/select/select.js +11 -5
- 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 +1 -1
- package/views/dist/controls/setting-row/looks.js +9 -4
- package/views/dist/controls/setting-row/setting-row.d.ts +45 -10
- package/views/dist/controls/setting-row/setting-row.js +82 -15
- package/views/dist/controls/setting-row/tokens.d.ts +74 -2
- package/views/dist/controls/setting-row/tokens.js +19 -1
- package/views/dist/controls/setting-row.css +135 -14
- 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/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/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/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 +418 -59
- package/views/dist/styles.unlayered.css +418 -59
- package/views/docs/contract.md +42 -31
- package/views/docs/controls/avatar.md +11 -0
- package/views/docs/controls/choice.md +0 -1
- package/views/docs/controls/field.md +3 -0
- package/views/docs/controls/input.md +1 -0
- package/views/docs/controls/radio.md +16 -1
- package/views/docs/controls/select.md +2 -0
- package/views/docs/controls/setting-row.md +18 -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 +35 -25
- 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 +1 -1
- 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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { writeListLink } from "viewkitjs/fields/query";
|
|
4
|
+
import { useViews } from "../provider/context.js";
|
|
5
|
+
import { useList } from "./root.js";
|
|
6
|
+
const LAYOUT_NAMES = {
|
|
7
|
+
table: { key: "views.panels.layout-table" },
|
|
8
|
+
list: { key: "views.panels.layout-list" },
|
|
9
|
+
board: { key: "views.panels.layout-board" },
|
|
10
|
+
calendar: { key: "views.panels.layout-calendar" },
|
|
11
|
+
};
|
|
12
|
+
const isLayout = (id) => id in LAYOUT_NAMES;
|
|
13
|
+
export function useListViewsAxis(layouts) {
|
|
14
|
+
const views = useList((s) => s.views);
|
|
15
|
+
const changes = useList((s) => s.view.shared?.changes ?? 0);
|
|
16
|
+
const settings = useList((s) => s.view.settings);
|
|
17
|
+
const openPanel = useList((s) => s.openPanel);
|
|
18
|
+
const { messages, ports } = useViews();
|
|
19
|
+
return useMemo(() => {
|
|
20
|
+
if (!views || (!views.ready && views.list.length === 0))
|
|
21
|
+
return undefined;
|
|
22
|
+
const byId = (id) => views.list.find((v) => v.id === id);
|
|
23
|
+
const onChange = (change) => {
|
|
24
|
+
switch (change.kind) {
|
|
25
|
+
case "rename":
|
|
26
|
+
return views.rename(change.id, change.name);
|
|
27
|
+
case "create":
|
|
28
|
+
return views.saveAs(change.name, {
|
|
29
|
+
...(change.from !== undefined && { from: change.from }),
|
|
30
|
+
...(isLayout(change.layout) && { layout: change.layout }),
|
|
31
|
+
});
|
|
32
|
+
case "duplicate": {
|
|
33
|
+
const view = byId(change.id);
|
|
34
|
+
if (view)
|
|
35
|
+
views.duplicate(view.id, messages({ key: "views.panels.view-copy-name", values: { name: view.name } }));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
case "delete":
|
|
39
|
+
return views.remove(change.id);
|
|
40
|
+
case "restore":
|
|
41
|
+
return views.restore(change.view.id, change.open);
|
|
42
|
+
case "save":
|
|
43
|
+
return views.save();
|
|
44
|
+
case "reset":
|
|
45
|
+
return views.reset();
|
|
46
|
+
case "edit":
|
|
47
|
+
return openPanel("options");
|
|
48
|
+
case "link": {
|
|
49
|
+
const view = byId(change.id);
|
|
50
|
+
if (!view || typeof location === "undefined")
|
|
51
|
+
return;
|
|
52
|
+
const shown = view.id === views.open ? { ...view.settings, ...(settings.search && { search: settings.search }) } : view.settings;
|
|
53
|
+
const { params } = writeListLink(location.search, { view: view.id, base: view.settings, settings: shown });
|
|
54
|
+
const query = params.toString();
|
|
55
|
+
void ports.clipboard.writeText(`${location.origin}${location.pathname}${query ? `?${query}` : ""}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
case "favorite":
|
|
59
|
+
case "private":
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
value: views.open ?? "",
|
|
65
|
+
options: views.list.map((v) => ({
|
|
66
|
+
value: v.id,
|
|
67
|
+
label: v.name,
|
|
68
|
+
private: v.scope === "personal",
|
|
69
|
+
layout: v.settings.layout,
|
|
70
|
+
...(!views.canSave(v) && { readOnly: true }),
|
|
71
|
+
...(v.id === views.open && changes > 0 && { changed: true }),
|
|
72
|
+
})),
|
|
73
|
+
onChange: views.openView,
|
|
74
|
+
onCreate: () => { },
|
|
75
|
+
onReorder: (ids) => {
|
|
76
|
+
const first = byId(ids[0] ?? "");
|
|
77
|
+
if (first)
|
|
78
|
+
views.reorder(first.scope, ids);
|
|
79
|
+
},
|
|
80
|
+
canDrag: (id) => {
|
|
81
|
+
const view = byId(id);
|
|
82
|
+
return !!view && views.canSave(view);
|
|
83
|
+
},
|
|
84
|
+
verbs: {
|
|
85
|
+
layouts: (layouts?.length ? layouts : ["table"]).map((id) => ({
|
|
86
|
+
id,
|
|
87
|
+
name: messages(LAYOUT_NAMES[id]),
|
|
88
|
+
icon: "layout",
|
|
89
|
+
line: "",
|
|
90
|
+
})),
|
|
91
|
+
records: views.records,
|
|
92
|
+
onChange,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}, [views, changes, settings.search, openPanel, messages, ports, layouts]);
|
|
96
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ListPersonalLayer, ListSettingsChange, SavedListSettings, SavedView } from "viewkitjs/fields/query";
|
|
2
|
+
/** A person's unsaved change over one view, and the view's `updatedAt` when it started. */
|
|
3
|
+
export type ViewDraft = {
|
|
4
|
+
change: ListSettingsChange;
|
|
5
|
+
base: string;
|
|
6
|
+
};
|
|
7
|
+
/** A view the app declares in its code: listed first, shared with everyone, read-only. */
|
|
8
|
+
export type ViewSeed = {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
settings: SavedListSettings;
|
|
12
|
+
};
|
|
13
|
+
/** What `save` takes: a view without its `updatedAt` (the store stamps it) and without `readOnly`; no `id` saves a
|
|
14
|
+
* new view, and the store makes its id. With an `id` the store no longer holds, it saves that view again. */
|
|
15
|
+
export type SavedViewInput = Omit<SavedView, "id" | "updatedAt" | "readOnly"> & {
|
|
16
|
+
id?: string;
|
|
17
|
+
};
|
|
18
|
+
/** Where a list's saved views, a person's drafts and their layer are kept. */
|
|
19
|
+
export interface ViewsStore {
|
|
20
|
+
/** The list's views: the shared ones, then the person's own, each in its `position`'s order. */
|
|
21
|
+
list(listId: string): readonly SavedView[] | Promise<readonly SavedView[]>;
|
|
22
|
+
/** Saves a view (save, save as, rename, a scope moved) and hands back the view as kept. */
|
|
23
|
+
save(listId: string, view: SavedViewInput): SavedView | Promise<SavedView>;
|
|
24
|
+
remove(listId: string, id: string): void | Promise<void>;
|
|
25
|
+
/** The views of one scope in a new order: every view of that scope, once. */
|
|
26
|
+
reorder(listId: string, scope: SavedView["scope"], ids: readonly string[]): void | Promise<void>;
|
|
27
|
+
/** Tells when the list's views change from elsewhere (another tab, another person); the answer stops it. */
|
|
28
|
+
subscribe?(listId: string, onChange: () => void): () => void;
|
|
29
|
+
draft: {
|
|
30
|
+
get(listId: string, viewId: string): ViewDraft | null | Promise<ViewDraft | null>;
|
|
31
|
+
set(listId: string, viewId: string, draft: ViewDraft | null): void | Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
layer: {
|
|
34
|
+
get(listId: string): ListPersonalLayer | Promise<ListPersonalLayer>;
|
|
35
|
+
set(listId: string, layer: ListPersonalLayer): void | Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
/** What this person may do: `share`, write shared views. Absent, they may not. */
|
|
38
|
+
can?: {
|
|
39
|
+
share: boolean;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type ListLayout, type ListLinkReading, type ListSettings, type SavedView } from "viewkitjs/fields/query";
|
|
2
|
+
import type { ListSync } from "./store.js";
|
|
3
|
+
import type { ViewsStore } from "./views-store.js";
|
|
4
|
+
/** A list's saved views as the root holds them (`ListState.views`): null in memory mode. */
|
|
5
|
+
export type ListViewsState = {
|
|
6
|
+
/** The views the row shows: shared first, then the person's own, each by position; a view held for Undo left out. */
|
|
7
|
+
list: readonly SavedView[];
|
|
8
|
+
/** The open view's id; null while the list has none. */
|
|
9
|
+
open: string | null;
|
|
10
|
+
/** The store has answered. */
|
|
11
|
+
ready: boolean;
|
|
12
|
+
/** This person may write shared views (`store.can.share`). */
|
|
13
|
+
share: boolean;
|
|
14
|
+
/** A write is under way. */
|
|
15
|
+
pending: boolean;
|
|
16
|
+
/** What the list holds, in the delete question's line (`ListViewsOptions.records`, default "records"). */
|
|
17
|
+
records: string;
|
|
18
|
+
openView: (id: string) => void;
|
|
19
|
+
/** The open view's edits saved over it, where this person may (`canSave`). */
|
|
20
|
+
save: () => void;
|
|
21
|
+
/** A new view of the person's own, named `name`: the edited settings of `from` (its edits let go), or with no `from`
|
|
22
|
+
* the defaults in `layout`. Opens it. */
|
|
23
|
+
saveAs: (name: string, options?: {
|
|
24
|
+
from?: string;
|
|
25
|
+
layout?: ListLayout;
|
|
26
|
+
}) => void;
|
|
27
|
+
rename: (id: string, name: string) => void;
|
|
28
|
+
/** A copy of what `id` saved, named `name`, right after it in its scope's order; opens it. */
|
|
29
|
+
duplicate: (id: string, name: string) => void;
|
|
30
|
+
/** Held: out of the row at once, `remove` once the hold ends (`holdMs`) or the page closes. */
|
|
31
|
+
remove: (id: string) => void;
|
|
32
|
+
/** Undo of `remove`: back in its place, opened again where `open`. */
|
|
33
|
+
restore: (id: string, open: boolean) => void;
|
|
34
|
+
reorder: (scope: SavedView["scope"], ids: readonly string[]) => void;
|
|
35
|
+
/** The open view's draft let go. */
|
|
36
|
+
reset: () => void;
|
|
37
|
+
/** Whether this person may change `view` (rename, delete, save over): not read-only, and shared only with `share`. */
|
|
38
|
+
canSave: (view: SavedView) => boolean;
|
|
39
|
+
};
|
|
40
|
+
export type ListViewsController = {
|
|
41
|
+
/** The `ListSync` the list store takes: the edited settings, the layer, their handlers and the open view's state,
|
|
42
|
+
* with the app's `sortFilter` and `bar`. */
|
|
43
|
+
sync: (extra: Pick<ListSync, "sortFilter" | "bar">) => ListSync;
|
|
44
|
+
/** Reads the store and starts following it (subscribe, `pagehide`); the cleanup stops both, the held deletes' timers
|
|
45
|
+
* too, and flushes them. Called from the root's layout effect. */
|
|
46
|
+
start: () => () => void;
|
|
47
|
+
/** The slice as it stands. */
|
|
48
|
+
state: () => ListViewsState;
|
|
49
|
+
};
|
|
50
|
+
/** The Toast's own time where nothing declares it: `--vk-toast-duration` as it reaches the toast's viewport (which its
|
|
51
|
+
* stylesheet hands the Toast), else the page's root, else 4000 ms. Read here, not imported: nothing outside the controls
|
|
52
|
+
* part imports from it. */
|
|
53
|
+
export declare function toastTime(): number;
|
|
54
|
+
export declare function createListViews(o: {
|
|
55
|
+
id: string;
|
|
56
|
+
store: ViewsStore;
|
|
57
|
+
defaults: ListSettings;
|
|
58
|
+
link?: ListLinkReading;
|
|
59
|
+
/** The delete question's noun; default "records". */
|
|
60
|
+
records?: string;
|
|
61
|
+
/** Told whenever the settings, the layer or the slice change, after the controller has synced them into the list store. */
|
|
62
|
+
onChange: () => void;
|
|
63
|
+
/** Said when a store write fails (the root hands `ports.toast.error`). */
|
|
64
|
+
onError: (message: string) => void;
|
|
65
|
+
/** How long a deleted view is held; default the Toast's own time (`toastTime()`). */
|
|
66
|
+
holdMs?: number;
|
|
67
|
+
}): ListViewsController;
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { applySettingsChange, settingsChange, settingsForSaving, } from "viewkitjs/fields/query";
|
|
2
|
+
export function toastTime() {
|
|
3
|
+
if (typeof document === "undefined")
|
|
4
|
+
return 4000;
|
|
5
|
+
const msOf = (el) => {
|
|
6
|
+
if (!el)
|
|
7
|
+
return 0;
|
|
8
|
+
const value = getComputedStyle(el).getPropertyValue("--vk-toast-duration").trim();
|
|
9
|
+
const n = parseFloat(value);
|
|
10
|
+
if (Number.isNaN(n))
|
|
11
|
+
return 0;
|
|
12
|
+
return /\dms$/.test(value) ? n : /\ds$/.test(value) ? n * 1000 : n;
|
|
13
|
+
};
|
|
14
|
+
return msOf(document.querySelector(".o-toast-viewport")) || msOf(document.documentElement) || 4000;
|
|
15
|
+
}
|
|
16
|
+
const isThenable = (value) => typeof value?.then === "function";
|
|
17
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
18
|
+
const withSearch = (settings, search) => search === undefined ? settingsForSaving(settings) : { ...settings, search };
|
|
19
|
+
export function createListViews(o) {
|
|
20
|
+
const { id: listId, store } = o;
|
|
21
|
+
const link = o.link && (o.link.view !== undefined || Object.keys(o.link.change).some((k) => k !== "search")) ? o.link : null;
|
|
22
|
+
const linkSearch = o.link?.change.search;
|
|
23
|
+
const share = !!store.can?.share;
|
|
24
|
+
const records = o.records ?? "records";
|
|
25
|
+
let generation = 0;
|
|
26
|
+
let ready = false;
|
|
27
|
+
let list = [];
|
|
28
|
+
let open = null;
|
|
29
|
+
let edited = o.defaults;
|
|
30
|
+
let base = null;
|
|
31
|
+
let layer = {};
|
|
32
|
+
let writes = 0;
|
|
33
|
+
let waitingChanges = [];
|
|
34
|
+
let waitingLayer = null;
|
|
35
|
+
const held = new Map();
|
|
36
|
+
const gone = new Map();
|
|
37
|
+
const openOf = () => (open === null ? undefined : list.find((v) => v.id === open));
|
|
38
|
+
const savedOf = () => openOf()?.settings ?? settingsForSaving(o.defaults);
|
|
39
|
+
const draftKey = () => open ?? "";
|
|
40
|
+
const changeOf = () => settingsChange(savedOf(), settingsForSaving(edited));
|
|
41
|
+
const canSave = (view) => !view.readOnly && (view.scope === "personal" || share);
|
|
42
|
+
const tell = () => o.onChange();
|
|
43
|
+
const run = (call, done, failed, gated = true) => {
|
|
44
|
+
const at = generation;
|
|
45
|
+
let value;
|
|
46
|
+
try {
|
|
47
|
+
value = call();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
failed(error);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!isThenable(value))
|
|
54
|
+
return done(value);
|
|
55
|
+
value.then((answer) => (!gated || at === generation) && done(answer), (error) => (!gated || at === generation) && failed(error));
|
|
56
|
+
};
|
|
57
|
+
const readFailed = (error) => o.onError(messageOf(error));
|
|
58
|
+
const write = (call, done = () => { }) => {
|
|
59
|
+
const at = generation;
|
|
60
|
+
writes += 1;
|
|
61
|
+
tell();
|
|
62
|
+
run(call, (value) => {
|
|
63
|
+
writes -= 1;
|
|
64
|
+
if (at === generation)
|
|
65
|
+
done(value);
|
|
66
|
+
tell();
|
|
67
|
+
}, (error) => {
|
|
68
|
+
writes -= 1;
|
|
69
|
+
o.onError(messageOf(error));
|
|
70
|
+
if (at === generation)
|
|
71
|
+
refresh();
|
|
72
|
+
tell();
|
|
73
|
+
}, false);
|
|
74
|
+
};
|
|
75
|
+
const writeDraft = () => {
|
|
76
|
+
const change = changeOf();
|
|
77
|
+
const { search: _search, ...kept } = change;
|
|
78
|
+
if (Object.keys(kept).length === 0) {
|
|
79
|
+
base = null;
|
|
80
|
+
write(() => store.draft.set(listId, draftKey(), null));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (base === null)
|
|
84
|
+
base = openOf()?.updatedAt ?? "";
|
|
85
|
+
const draft = { change: kept, base };
|
|
86
|
+
write(() => store.draft.set(listId, draftKey(), draft));
|
|
87
|
+
};
|
|
88
|
+
const opening = (view, then) => {
|
|
89
|
+
const search = edited.search;
|
|
90
|
+
open = view?.id ?? null;
|
|
91
|
+
base = null;
|
|
92
|
+
edited = withSearch(view?.settings ?? o.defaults, search);
|
|
93
|
+
const key = draftKey();
|
|
94
|
+
run(() => store.draft.get(listId, key), (draft) => {
|
|
95
|
+
if (draftKey() !== key)
|
|
96
|
+
return;
|
|
97
|
+
if (draft) {
|
|
98
|
+
edited = withSearch(applySettingsChange(view?.settings ?? settingsForSaving(o.defaults), draft.change), search);
|
|
99
|
+
base = draft.base;
|
|
100
|
+
}
|
|
101
|
+
then?.();
|
|
102
|
+
tell();
|
|
103
|
+
}, readFailed);
|
|
104
|
+
};
|
|
105
|
+
const same = (a, b) => a.id === b.id && a.updatedAt === b.updatedAt && a.position === b.position && a.name === b.name && a.scope === b.scope && !!a.readOnly === !!b.readOnly;
|
|
106
|
+
const listing = (views) => {
|
|
107
|
+
const next = views.filter((v) => !held.has(v.id));
|
|
108
|
+
return next.length === list.length && next.every((v, i) => same(v, list[i])) ? list : next;
|
|
109
|
+
};
|
|
110
|
+
const edits = () => Object.keys(changeOf()).some((key) => key !== "search");
|
|
111
|
+
const refresh = () => {
|
|
112
|
+
run(() => store.list(listId), (views) => {
|
|
113
|
+
const was = openOf();
|
|
114
|
+
const editing = edits();
|
|
115
|
+
const before = list;
|
|
116
|
+
list = listing(views);
|
|
117
|
+
if (list === before)
|
|
118
|
+
return;
|
|
119
|
+
const now = openOf();
|
|
120
|
+
if (open !== null && !now)
|
|
121
|
+
opening(list[0]);
|
|
122
|
+
else if (now && was && now.updatedAt !== was.updatedAt && !editing)
|
|
123
|
+
edited = withSearch(now.settings, edited.search);
|
|
124
|
+
tell();
|
|
125
|
+
}, readFailed);
|
|
126
|
+
};
|
|
127
|
+
const layered = (under, over) => {
|
|
128
|
+
const merged = { ...under };
|
|
129
|
+
for (const [key, value] of Object.entries(over)) {
|
|
130
|
+
const was = merged[key];
|
|
131
|
+
const record = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
132
|
+
merged[key] = record(was) && record(value) ? { ...was, ...value } : value;
|
|
133
|
+
}
|
|
134
|
+
return merged;
|
|
135
|
+
};
|
|
136
|
+
const load = () => {
|
|
137
|
+
run(() => store.list(listId), (views) => {
|
|
138
|
+
list = listing(views);
|
|
139
|
+
const linked = link?.view !== undefined ? list.find((v) => v.id === link.view) : undefined;
|
|
140
|
+
const view = linked ?? list[0];
|
|
141
|
+
const land = (draft) => {
|
|
142
|
+
open = view?.id ?? null;
|
|
143
|
+
const saved = view?.settings ?? settingsForSaving(o.defaults);
|
|
144
|
+
const change = link ? link.change : { ...draft?.change, ...(linkSearch !== undefined && { search: linkSearch }) };
|
|
145
|
+
let next = applySettingsChange(view ? saved : o.defaults, change);
|
|
146
|
+
for (const waiting of waitingChanges)
|
|
147
|
+
next = applySettingsChange(next, waiting);
|
|
148
|
+
edited = next;
|
|
149
|
+
base = link ? null : draft?.base ?? null;
|
|
150
|
+
run(() => store.layer.get(listId), (stored) => {
|
|
151
|
+
layer = waitingLayer ? layered(stored, waitingLayer) : stored;
|
|
152
|
+
ready = true;
|
|
153
|
+
if (waitingChanges.length > 0)
|
|
154
|
+
writeDraft();
|
|
155
|
+
if (waitingLayer)
|
|
156
|
+
write(() => store.layer.set(listId, layer));
|
|
157
|
+
waitingChanges = [];
|
|
158
|
+
waitingLayer = null;
|
|
159
|
+
tell();
|
|
160
|
+
}, readFailed);
|
|
161
|
+
};
|
|
162
|
+
if (link)
|
|
163
|
+
land(null);
|
|
164
|
+
else
|
|
165
|
+
run(() => store.draft.get(listId, view?.id ?? ""), land, readFailed);
|
|
166
|
+
}, readFailed);
|
|
167
|
+
};
|
|
168
|
+
const start = () => {
|
|
169
|
+
generation += 1;
|
|
170
|
+
const at = generation;
|
|
171
|
+
load();
|
|
172
|
+
const stopFollowing = store.subscribe?.(listId, () => (ready ? refresh() : load()));
|
|
173
|
+
const leaving = () => flushHolds();
|
|
174
|
+
if (typeof window !== "undefined")
|
|
175
|
+
window.addEventListener("pagehide", leaving);
|
|
176
|
+
return () => {
|
|
177
|
+
if (generation === at)
|
|
178
|
+
generation += 1;
|
|
179
|
+
stopFollowing?.();
|
|
180
|
+
if (typeof window !== "undefined")
|
|
181
|
+
window.removeEventListener("pagehide", leaving);
|
|
182
|
+
flushHolds();
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
const letGo = (id) => {
|
|
186
|
+
const hold = held.get(id);
|
|
187
|
+
if (!hold)
|
|
188
|
+
return;
|
|
189
|
+
clearTimeout(hold.timer);
|
|
190
|
+
held.delete(id);
|
|
191
|
+
gone.set(id, hold.view);
|
|
192
|
+
write(() => store.remove(listId, id));
|
|
193
|
+
};
|
|
194
|
+
const flushHolds = () => {
|
|
195
|
+
for (const id of [...held.keys()])
|
|
196
|
+
letGo(id);
|
|
197
|
+
};
|
|
198
|
+
const scopeOrder = (views) => [
|
|
199
|
+
...views.filter((v) => v.scope === "shared"),
|
|
200
|
+
...views.filter((v) => v.scope === "personal"),
|
|
201
|
+
];
|
|
202
|
+
const inputOf = (view, patch = {}) => ({
|
|
203
|
+
id: view.id,
|
|
204
|
+
name: view.name,
|
|
205
|
+
scope: view.scope,
|
|
206
|
+
position: view.position,
|
|
207
|
+
settings: view.settings,
|
|
208
|
+
...patch,
|
|
209
|
+
});
|
|
210
|
+
const replace = (saved) => {
|
|
211
|
+
list = list.some((v) => v.id === saved.id) ? list.map((v) => (v.id === saved.id ? saved : v)) : scopeOrder([...list, saved]);
|
|
212
|
+
};
|
|
213
|
+
const endOf = (scope) => list.reduce((most, v) => (v.scope === scope ? Math.max(most, v.position) : most), -1) + 1;
|
|
214
|
+
const reorder = (scope, ids) => {
|
|
215
|
+
if (!ready || (scope === "shared" && !share))
|
|
216
|
+
return;
|
|
217
|
+
const block = ids.map((id) => list.find((v) => v.id === id && v.scope === scope)).filter((v) => !!v);
|
|
218
|
+
const moved = block.map((v, position) => ({ ...v, position }));
|
|
219
|
+
list = scope === "shared" ? [...moved, ...list.filter((v) => v.scope !== "shared")] : [...list.filter((v) => v.scope !== "personal"), ...moved];
|
|
220
|
+
tell();
|
|
221
|
+
write(() => store.reorder(listId, scope, ids));
|
|
222
|
+
};
|
|
223
|
+
const actions = {
|
|
224
|
+
openView: (id) => {
|
|
225
|
+
if (!ready || id === open)
|
|
226
|
+
return;
|
|
227
|
+
const view = list.find((v) => v.id === id);
|
|
228
|
+
if (!view)
|
|
229
|
+
return;
|
|
230
|
+
opening(view);
|
|
231
|
+
tell();
|
|
232
|
+
},
|
|
233
|
+
save: () => {
|
|
234
|
+
const view = openOf();
|
|
235
|
+
if (!ready || !view || !canSave(view))
|
|
236
|
+
return;
|
|
237
|
+
write(() => store.save(listId, inputOf(view, { settings: settingsForSaving(edited) })), (saved) => {
|
|
238
|
+
replace(saved);
|
|
239
|
+
base = null;
|
|
240
|
+
write(() => store.draft.set(listId, saved.id, null));
|
|
241
|
+
refresh();
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
saveAs: (name, options = {}) => {
|
|
245
|
+
if (!ready)
|
|
246
|
+
return;
|
|
247
|
+
const from = options.from === undefined ? undefined : list.find((v) => v.id === options.from);
|
|
248
|
+
const settings = from
|
|
249
|
+
? from.id === open
|
|
250
|
+
? settingsForSaving(edited)
|
|
251
|
+
: from.settings
|
|
252
|
+
: settingsForSaving({ ...o.defaults, layout: options.layout ?? o.defaults.layout });
|
|
253
|
+
write(() => store.save(listId, { name, scope: "personal", position: endOf("personal"), settings: settings }), (saved) => {
|
|
254
|
+
if (from)
|
|
255
|
+
write(() => store.draft.set(listId, from.id, null));
|
|
256
|
+
replace(saved);
|
|
257
|
+
const search = edited.search;
|
|
258
|
+
open = saved.id;
|
|
259
|
+
base = null;
|
|
260
|
+
edited = withSearch(saved.settings, search);
|
|
261
|
+
refresh();
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
rename: (id, name) => {
|
|
265
|
+
const view = list.find((v) => v.id === id);
|
|
266
|
+
if (!ready || !view || !canSave(view) || !name.trim())
|
|
267
|
+
return;
|
|
268
|
+
write(() => store.save(listId, inputOf(view, { name: name.trim() })), (saved) => {
|
|
269
|
+
replace(saved);
|
|
270
|
+
if (saved.id === open && base === view.updatedAt) {
|
|
271
|
+
base = saved.updatedAt;
|
|
272
|
+
writeDraft();
|
|
273
|
+
}
|
|
274
|
+
refresh();
|
|
275
|
+
});
|
|
276
|
+
},
|
|
277
|
+
duplicate: (id, name) => {
|
|
278
|
+
const view = list.find((v) => v.id === id);
|
|
279
|
+
if (!ready || !view)
|
|
280
|
+
return;
|
|
281
|
+
const scope = view.scope === "shared" && share ? "shared" : "personal";
|
|
282
|
+
write(() => store.save(listId, { name, scope, position: endOf(scope), settings: view.settings }), (saved) => {
|
|
283
|
+
replace(saved);
|
|
284
|
+
const block = list.filter((v) => v.scope === scope && v.id !== saved.id).map((v) => v.id);
|
|
285
|
+
const after = block.indexOf(view.id);
|
|
286
|
+
if (after >= 0 && after < block.length - 1)
|
|
287
|
+
reorder(scope, [...block.slice(0, after + 1), saved.id, ...block.slice(after + 1)]);
|
|
288
|
+
opening(saved);
|
|
289
|
+
refresh();
|
|
290
|
+
});
|
|
291
|
+
},
|
|
292
|
+
remove: (id) => {
|
|
293
|
+
const index = list.findIndex((v) => v.id === id);
|
|
294
|
+
const view = list[index];
|
|
295
|
+
if (!ready || !view || !canSave(view))
|
|
296
|
+
return;
|
|
297
|
+
held.set(id, { view, index, timer: setTimeout(() => letGo(id), o.holdMs ?? toastTime()) });
|
|
298
|
+
list = list.filter((v) => v.id !== id);
|
|
299
|
+
if (open === id)
|
|
300
|
+
opening(list[0]);
|
|
301
|
+
tell();
|
|
302
|
+
},
|
|
303
|
+
restore: (id, reopen) => {
|
|
304
|
+
const hold = held.get(id);
|
|
305
|
+
if (hold) {
|
|
306
|
+
clearTimeout(hold.timer);
|
|
307
|
+
held.delete(id);
|
|
308
|
+
list = [...list.slice(0, hold.index), hold.view, ...list.slice(hold.index)];
|
|
309
|
+
if (reopen)
|
|
310
|
+
opening(hold.view);
|
|
311
|
+
tell();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const was = gone.get(id);
|
|
315
|
+
if (!was)
|
|
316
|
+
return;
|
|
317
|
+
write(() => store.save(listId, inputOf(was)), (saved) => {
|
|
318
|
+
gone.delete(id);
|
|
319
|
+
replace(saved);
|
|
320
|
+
if (reopen)
|
|
321
|
+
opening(saved);
|
|
322
|
+
refresh();
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
reorder,
|
|
326
|
+
reset: () => {
|
|
327
|
+
if (!ready)
|
|
328
|
+
return;
|
|
329
|
+
edited = withSearch(savedOf(), edited.search);
|
|
330
|
+
writeDraft();
|
|
331
|
+
tell();
|
|
332
|
+
},
|
|
333
|
+
canSave,
|
|
334
|
+
};
|
|
335
|
+
const setSettings = (change) => {
|
|
336
|
+
edited = applySettingsChange(edited, change);
|
|
337
|
+
if (ready)
|
|
338
|
+
writeDraft();
|
|
339
|
+
else
|
|
340
|
+
waitingChanges = [...waitingChanges, change];
|
|
341
|
+
tell();
|
|
342
|
+
};
|
|
343
|
+
const setLayer = (given) => {
|
|
344
|
+
const patch = given.widths ? { ...given, widths: fitWidths(given.widths) } : given;
|
|
345
|
+
layer = { ...layer, ...patch };
|
|
346
|
+
if (ready)
|
|
347
|
+
write(() => store.layer.set(listId, layer));
|
|
348
|
+
else
|
|
349
|
+
waitingLayer = { ...waitingLayer, ...patch };
|
|
350
|
+
tell();
|
|
351
|
+
};
|
|
352
|
+
let shown;
|
|
353
|
+
const viewState = () => {
|
|
354
|
+
const view = openOf();
|
|
355
|
+
if (!view)
|
|
356
|
+
return (shown = undefined);
|
|
357
|
+
const { search: _search, ...change } = changeOf();
|
|
358
|
+
const next = {
|
|
359
|
+
changes: Object.keys(change).length,
|
|
360
|
+
stale: base !== null && base !== "" && Date.parse(base) < Date.parse(view.updatedAt),
|
|
361
|
+
canPublish: canSave(view),
|
|
362
|
+
own: view.scope === "personal",
|
|
363
|
+
pending: writes > 0,
|
|
364
|
+
};
|
|
365
|
+
if (shown && Object.keys(next).every((key) => shown[key] === next[key]))
|
|
366
|
+
return shown;
|
|
367
|
+
return (shown = { ...next, onReset: actions.reset, onPublish: actions.save });
|
|
368
|
+
};
|
|
369
|
+
let synced;
|
|
370
|
+
let slice;
|
|
371
|
+
return {
|
|
372
|
+
sync: (extra) => {
|
|
373
|
+
const view = viewState();
|
|
374
|
+
if (synced &&
|
|
375
|
+
synced.settings === edited &&
|
|
376
|
+
synced.layer === layer &&
|
|
377
|
+
synced.view === view &&
|
|
378
|
+
synced.sortFilter === extra.sortFilter &&
|
|
379
|
+
synced.bar === extra.bar)
|
|
380
|
+
return synced;
|
|
381
|
+
return (synced = {
|
|
382
|
+
settings: edited,
|
|
383
|
+
layer,
|
|
384
|
+
onChange: setSettings,
|
|
385
|
+
onLayerChange: setLayer,
|
|
386
|
+
...(view && { view }),
|
|
387
|
+
...(extra.sortFilter !== undefined && { sortFilter: extra.sortFilter }),
|
|
388
|
+
...(extra.bar !== undefined && { bar: extra.bar }),
|
|
389
|
+
});
|
|
390
|
+
},
|
|
391
|
+
start,
|
|
392
|
+
state: () => {
|
|
393
|
+
const pending = writes > 0;
|
|
394
|
+
if (slice && slice.list === list && slice.open === open && slice.ready === ready && slice.pending === pending)
|
|
395
|
+
return slice;
|
|
396
|
+
return (slice = { ...actions, list, open, ready, share, pending, records });
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
const fitWidths = (widths) => Object.fromEntries(Object.entries(widths).map(([key, width]) => [key, Math.round(Math.min(2000, Math.max(24, width)))]));
|
|
@@ -5,7 +5,7 @@ export { getViewOptionAvailability, resolvePersonalSection } from "./availabilit
|
|
|
5
5
|
export { groupSortChoices, groupSortValue, offersManualOrder } from "./group-sort.js";
|
|
6
6
|
export { useFilterOpened } from "./use-filter-opened.js";
|
|
7
7
|
export { GROUP_BY_SEARCH_AFTER, activeGroupDimension, dateRangeValueLabel, drawsUnnamedValue, filterRowValueLabel, filterValueLabel, groupDateByLabel, groupSortLabel, groupValueLabel, layoutValueLabel, matchGroupDimensions, matchSortOptions, relationSentence, sortValueLabel, timeScopeRowValueLabel, } from "./labels.js";
|
|
8
|
-
export type { CollectionChildAxis, CollectionViewsConfig, CollectionViewsInput, PillOption, ViewTabOption, ViewsLayout, } from "./views-row/model.js";
|
|
8
|
+
export type { CollectionChildAxis, CollectionViewsConfig, CollectionViewsInput, PillOption, PillViewMenu, ViewTabOption, ViewsLayout, } from "./views-row/model.js";
|
|
9
9
|
export { splitViewAxes, toViewAxes } from "./views-row/model.js";
|
|
10
10
|
export { settingsPanels } from "./settings/settings-panels.js";
|
|
11
11
|
export type { SettingsPanels } from "./settings/settings-panels.js";
|
|
@@ -24,6 +24,8 @@ export { TOOLBAR_NARROW_BELOW, arrangeToolbar, foldState, foldSteps, toolbarForm
|
|
|
24
24
|
export type { FoldStep, ToolbarForm, ToolbarLine, ToolbarPlacement, ToolbarSlot } from "./toolbar/model.js";
|
|
25
25
|
export { SHOW_COUNTS_KEY, countsToggle, groupShown, showCountsChange, showCountsOf, withCounts, } from "./toolbar/counts.js";
|
|
26
26
|
export { withEditView } from "./toolbar/edit-view.js";
|
|
27
|
+
export { withViewMenu } from "./toolbar/edit-view.js";
|
|
28
|
+
export type { ViewMenuFn } from "./toolbar/edit-view.js";
|
|
27
29
|
export { settingsCleared } from "./toolbar/clear.js";
|
|
28
30
|
export { asideFilterWords, barFilterWords } from "./toolbar/filter-words.js";
|
|
29
31
|
export type { BarFilterWords } from "./toolbar/filter-words.js";
|
|
@@ -17,6 +17,7 @@ export { boardFieldOf, calendarFieldOf } from "./settings/axes.js";
|
|
|
17
17
|
export { TOOLBAR_NARROW_BELOW, arrangeToolbar, foldState, foldSteps, toolbarForm } from "./toolbar/model.js";
|
|
18
18
|
export { SHOW_COUNTS_KEY, countsToggle, groupShown, showCountsChange, showCountsOf, withCounts, } from "./toolbar/counts.js";
|
|
19
19
|
export { withEditView } from "./toolbar/edit-view.js";
|
|
20
|
+
export { withViewMenu } from "./toolbar/edit-view.js";
|
|
20
21
|
export { settingsCleared } from "./toolbar/clear.js";
|
|
21
22
|
export { asideFilterWords, barFilterWords } from "./toolbar/filter-words.js";
|
|
22
23
|
export { QUICK_SEARCH_AFTER, holdAfterPress, holdStands, quickFieldsShown, quickFirstOpen, quickHeldNames, quickHoldFits, quickPressCloses, quickReminderWords, quickValuesFound, quickValuesShown, } from "./quick/model.js";
|
|
@@ -112,6 +112,7 @@ export function customizeBodyPropsOf(props, { components, icons, messages, conve
|
|
|
112
112
|
pending: view.pending,
|
|
113
113
|
onReset: view.onReset,
|
|
114
114
|
onPublish: view.onPublish,
|
|
115
|
+
...(view.own && { own: true }),
|
|
115
116
|
},
|
|
116
117
|
}),
|
|
117
118
|
...(viewFoot && { foot: viewFoot }),
|