viewkitjs 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/fields/dist/index.d.ts +1 -1
- package/fields/dist/index.js +1 -1
- package/fields/dist/query/evaluate.d.ts +7 -0
- package/fields/dist/query/exact-number.d.ts +8 -2
- package/fields/dist/query/exact-number.js +14 -1
- package/fields/dist/query/sort.js +13 -10
- package/fields/dist/registry.js +5 -1
- package/fields/dist/types.d.ts +4 -1
- package/fields/dist/zod.d.ts +5 -0
- package/fields/dist/zod.js +10 -1
- package/fields/docs/guides/contact-values.md +12 -0
- package/fields/docs/guides/field-types.md +1 -1
- package/fields/docs/guides/queries.md +3 -1
- package/fields/docs/reference/fields.md +1 -0
- package/package.json +1 -1
- package/postgres/dist/check.js +4 -1
- package/postgres/dist/definitions/formula-forms.js +3 -1
- package/postgres/dist/definitions/money.js +2 -1
- package/postgres/dist/page.js +6 -3
- package/postgres/dist/rules.d.ts +15 -1
- package/postgres/dist/rules.js +16 -0
- package/postgres/dist/sort.js +7 -2
- package/postgres/docs/guides/definitions.md +1 -1
- package/postgres/docs/guides/field-map.md +1 -1
- package/postgres/docs/reference/definitions.md +1 -1
- package/postgres/docs/reference/postgres.md +1 -1
- package/views/dist/atoms/ToolbarButton.d.ts +1 -1
- package/views/dist/atoms/ToolbarButton.js +4 -3
- package/views/dist/atoms/frame-parts.d.ts +6 -0
- package/views/dist/atoms/frame-parts.js +15 -0
- package/views/dist/atoms/types.d.ts +16 -7
- package/views/dist/cells/cell-title.d.ts +3 -1
- package/views/dist/cells/cell-title.js +2 -2
- package/views/dist/cells/cell-values.js +2 -2
- package/views/dist/contract.d.ts +31 -6
- package/views/dist/contract.js +123 -0
- package/views/dist/controls/button/map-button.js +2 -0
- package/views/dist/controls/checkbox/checkbox.d.ts +3 -2
- package/views/dist/controls/checkbox/checkbox.js +2 -2
- package/views/dist/controls/compound-editor/compound-editor.d.ts +1 -1
- package/views/dist/controls/compound-editor/name-parts.js +4 -4
- package/views/dist/controls/compound-editor/place-parts.js +19 -19
- package/views/dist/controls/compound-editor/range-parts.js +14 -14
- package/views/dist/controls/compound-editor/row.d.ts +3 -1
- package/views/dist/controls/compound-editor/row.js +2 -2
- package/views/dist/controls/controls.d.ts +2 -0
- package/views/dist/controls/controls.js +2 -0
- package/views/dist/controls/customize/customize.js +37 -35
- package/views/dist/controls/customize/map-customize-body.d.ts +2 -0
- package/views/dist/controls/customize/map-customize-body.js +4 -0
- package/views/dist/controls/date-editor/date-days.js +2 -2
- package/views/dist/controls/date-editor/date-editor.js +18 -18
- package/views/dist/controls/date-editor/date-parts.js +6 -6
- package/views/dist/controls/date-editor/map-calendar.js +1 -1
- package/views/dist/controls/date-editor.css +2 -2
- package/views/dist/controls/field/field.d.ts +3 -0
- package/views/dist/controls/field/field.js +6 -6
- package/views/dist/controls/filter-editor/block.d.ts +2 -2
- package/views/dist/controls/filter-editor/block.js +5 -5
- package/views/dist/controls/filter-editor/filter-editor.js +31 -33
- package/views/dist/controls/filter-editor/how.d.ts +3 -1
- package/views/dist/controls/filter-editor/map-filter-body.d.ts +1 -0
- package/views/dist/controls/filter-editor/map-filter-body.js +7 -3
- package/views/dist/controls/filter-editor/map-rules.js +1 -1
- package/views/dist/controls/filter-editor/parts.js +2 -1
- package/views/dist/controls/group-editor/group-editor.js +15 -13
- package/views/dist/controls/index.d.ts +2 -0
- package/views/dist/controls/index.js +1 -0
- package/views/dist/controls/input/input.js +2 -2
- package/views/dist/controls/input/map-input.js +2 -0
- package/views/dist/controls/internal/editor-parts.js +1 -1
- package/views/dist/controls/internal/map-panel-controls.d.ts +8 -0
- package/views/dist/controls/internal/map-panel-controls.js +20 -0
- package/views/dist/controls/internal/panel-controls.d.ts +50 -0
- package/views/dist/controls/internal/panel-controls.js +197 -0
- package/views/dist/controls/internal/part-slot.d.ts +12 -0
- package/views/dist/controls/internal/part-slot.js +5 -0
- package/views/dist/controls/links-editor/links-editor.d.ts +1 -1
- package/views/dist/controls/links-editor/links-editor.js +27 -27
- package/views/dist/controls/menu/map-menu.d.ts +2 -2
- package/views/dist/controls/menu/map-menu.js +15 -12
- package/views/dist/controls/menu/menu.d.ts +2 -0
- package/views/dist/controls/menu/menu.js +3 -3
- package/views/dist/controls/menu-list/menu-list.d.ts +14 -4
- package/views/dist/controls/menu-list/menu-list.js +23 -22
- package/views/dist/controls/notice/notice.d.ts +3 -1
- package/views/dist/controls/notice/notice.js +2 -2
- package/views/dist/controls/number-editor/number-editor.d.ts +1 -1
- package/views/dist/controls/number-editor/number-editor.js +13 -13
- package/views/dist/controls/number-field/number-field.js +5 -3
- package/views/dist/controls/pane/pane.d.ts +4 -2
- package/views/dist/controls/pane/pane.js +4 -4
- package/views/dist/controls/picker/picker.d.ts +2 -0
- package/views/dist/controls/picker/picker.js +37 -36
- package/views/dist/controls/picker/rows.d.ts +4 -0
- package/views/dist/controls/popover/map-popover.d.ts +1 -1
- package/views/dist/controls/popover/map-popover.js +4 -2
- package/views/dist/controls/quick-filters/quick-filters.js +4 -4
- package/views/dist/controls/radio/radio.d.ts +3 -0
- package/views/dist/controls/radio/radio.js +4 -3
- package/views/dist/controls/select/map-select.d.ts +3 -0
- package/views/dist/controls/select/map-select.js +8 -0
- package/views/dist/controls/select/select.d.ts +3 -0
- package/views/dist/controls/select/select.js +3 -3
- package/views/dist/controls/sheet/bottom-sheet.d.ts +5 -1
- package/views/dist/controls/sheet/bottom-sheet.js +2 -2
- package/views/dist/controls/sheet/map-sheet.js +1 -1
- package/views/dist/controls/sort-editor/map-sort-body.d.ts +1 -0
- package/views/dist/controls/sort-editor/map-sort-body.js +7 -3
- package/views/dist/controls/sort-editor/sort-editor.js +24 -26
- package/views/dist/controls/sort-editor.css +5 -0
- package/views/dist/controls/text-editor/text-editor.d.ts +1 -1
- package/views/dist/controls/text-editor/text-editor.js +8 -8
- package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +3 -3
- package/views/dist/controls/toolbar-button/atom-toolbar-button.js +7 -6
- package/views/dist/controls/values-editor/values-editor.d.ts +1 -1
- package/views/dist/controls/values-editor/values-editor.js +22 -22
- package/views/dist/controls/views-list/map-view-menu.js +1 -1
- package/views/dist/controls/views-list/view-menu.js +6 -6
- package/views/dist/controls/views-list/views-list.js +4 -4
- package/views/dist/editors/EditorPanel.js +1 -1
- package/views/dist/field-row/FieldRow.js +13 -0
- package/views/dist/fields/money.d.ts +5 -2
- package/views/dist/fields/money.js +14 -2
- package/views/dist/grid/chrome/GridTable.js +4 -1
- package/views/dist/grid/chrome/cell-clipboard.d.ts +4 -2
- package/views/dist/grid/chrome/cell-clipboard.js +2 -2
- package/views/dist/grid/chrome/cells.js +3 -1
- package/views/dist/grid/chrome/grid-row-menu-items.js +1 -1
- package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -1
- package/views/dist/grid/chrome/useGridKeyboard.js +29 -6
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +9 -2
- package/views/dist/grid/core/clipboard-model.d.ts +3 -1
- package/views/dist/grid/core/clipboard-model.js +9 -8
- package/views/dist/grid/core/editing-controller.d.ts +3 -0
- package/views/dist/grid/core/editing-controller.js +6 -0
- package/views/dist/grid/core/edits-sink.d.ts +19 -0
- package/views/dist/grid/core/edits-sink.js +2 -0
- package/views/dist/grid/core/spreadsheet-operations.js +1 -1
- package/views/dist/grid/core/useGridEditing.d.ts +5 -0
- package/views/dist/grid/core/useGridEditing.js +6 -0
- package/views/dist/list/answer.d.ts +40 -0
- package/views/dist/list/answer.js +43 -0
- package/views/dist/list/bulk-bar.d.ts +7 -0
- package/views/dist/list/bulk-bar.js +10 -0
- package/views/dist/list/columns.d.ts +24 -0
- package/views/dist/list/columns.js +27 -0
- package/views/dist/list/edits.d.ts +19 -0
- package/views/dist/list/edits.js +56 -0
- package/views/dist/list/grid.d.ts +11 -0
- package/views/dist/list/grid.js +76 -0
- package/views/dist/list/index.d.ts +14 -1
- package/views/dist/list/index.js +4 -1
- package/views/dist/list/link.d.ts +8 -0
- package/views/dist/list/link.js +78 -0
- package/views/dist/list/list.d.ts +70 -0
- package/views/dist/list/list.js +14 -0
- package/views/dist/list/parts.js +10 -3
- package/views/dist/list/root-base.d.ts +46 -0
- package/views/dist/list/root-base.js +137 -0
- package/views/dist/list/root.d.ts +35 -34
- package/views/dist/list/root.js +153 -113
- package/views/dist/list/source-answers.d.ts +39 -0
- package/views/dist/list/source-answers.js +225 -0
- package/views/dist/list/store.d.ts +37 -5
- package/views/dist/list/store.js +31 -0
- package/views/dist/list/toolbar.d.ts +3 -2
- package/views/dist/list/toolbar.js +14 -2
- package/views/dist/list/views-axis.js +4 -2
- package/views/dist/list/views.d.ts +7 -2
- package/views/dist/list/views.js +16 -5
- package/views/dist/model/column-capabilities.d.ts +13 -0
- package/views/dist/model/column-capabilities.js +23 -2
- package/views/dist/model/column-schema.d.ts +11 -1
- package/views/dist/model/view-rules.js +1 -0
- package/views/dist/panels/model.d.ts +2 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +8 -2
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +2 -2
- package/views/dist/panels/react/toolbar/Toolbar.d.ts +8 -1
- package/views/dist/panels/react/toolbar/Toolbar.js +12 -3
- package/views/dist/panels/react/toolbar/ToolbarAdvancedFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarAsideFilter.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +4 -4
- package/views/dist/panels/react/toolbar/ToolbarButton.js +4 -1
- package/views/dist/panels/react/toolbar/ToolbarFilter.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarNew.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarOptions.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSort.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +6 -4
- package/views/dist/panels/react/toolbar/context.d.ts +10 -1
- package/views/dist/panels/react/toolbar/panel-part.d.ts +4 -1
- package/views/dist/panels/react/toolbar/panel-part.js +5 -3
- package/views/dist/panels/settings/filter-groups.js +6 -1
- package/views/dist/provider/ViewsProvider.d.ts +6 -2
- package/views/dist/provider/ViewsProvider.js +18 -1
- package/views/dist/provider/components.d.ts +59 -0
- package/views/dist/provider/components.js +1 -1
- package/views/dist/provider/context.d.ts +4 -1
- package/views/dist/provider/own-control.d.ts +4 -0
- package/views/dist/provider/own-control.js +7 -0
- package/views/dist/provider/select-items.d.ts +3 -0
- package/views/dist/provider/select-items.js +6 -0
- package/views/dist/react.d.ts +4 -2
- package/views/dist/react.js +2 -0
- package/views/dist/styles.css +86 -78
- package/views/dist/styles.unlayered.css +86 -78
- package/views/docs/contract.md +252 -5
- package/views/docs/controls/compound-editor.md +4 -0
- package/views/docs/controls/customize.md +6 -0
- package/views/docs/controls/date-editor.md +4 -0
- package/views/docs/controls/field.md +4 -0
- package/views/docs/controls/filter-editor.md +8 -0
- package/views/docs/controls/group-editor.md +6 -0
- package/views/docs/controls/input.md +4 -0
- package/views/docs/controls/links-editor.md +4 -0
- package/views/docs/controls/menu-list.md +8 -0
- package/views/docs/controls/menu.md +4 -0
- package/views/docs/controls/notice.md +4 -0
- package/views/docs/controls/number-editor.md +4 -0
- package/views/docs/controls/pane.md +4 -0
- package/views/docs/controls/picker.md +8 -0
- package/views/docs/controls/quick-filters.md +6 -0
- package/views/docs/controls/radio.md +4 -0
- package/views/docs/controls/select.md +8 -0
- package/views/docs/controls/sheet.md +4 -0
- package/views/docs/controls/sort-editor.md +8 -0
- package/views/docs/controls/text-editor.md +4 -0
- package/views/docs/controls/values-editor.md +4 -0
- package/views/docs/controls/views-list.md +6 -0
- package/views/docs/guides/the-grid.md +2 -2
- package/views/docs/guides/the-provider.md +19 -2
- package/views/docs/reference/controls.md +7 -5
- package/views/docs/reference/field-row.md +1 -1
- package/views/docs/reference/grid.md +1 -1
- package/views/docs/reference/list.md +141 -11
- package/views/docs/reference/panels-react.md +2 -2
- package/views/docs/reference/react.md +15 -9
- package/views/docs/reference/views.md +8 -4
- package/views/docs/reshaping.md +6 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { answerFor, isRefused, LIST_REQUEST_LIMITS, LIST_SETTINGS_DEFAULTS, LIST_REQUEST_VERSION, } from "viewkitjs/fields/query";
|
|
2
|
+
const OPTIONAL_PARTS = ["rowOrderMode", "itemPositions"];
|
|
3
|
+
export function requestSettingsOf(settings) {
|
|
4
|
+
const out = { filter: settings.filter, sorts: settings.sorts, group: settings.group };
|
|
5
|
+
if (settings.search?.trim())
|
|
6
|
+
out.search = settings.search;
|
|
7
|
+
for (const key of OPTIONAL_PARTS)
|
|
8
|
+
if (settings[key] !== undefined)
|
|
9
|
+
out[key] = settings[key];
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
const pageSizeOf = (size) => Math.min(LIST_REQUEST_LIMITS.pageSize, Math.max(1, Math.floor(Number.isFinite(size) ? size : 50)));
|
|
13
|
+
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
14
|
+
const NO_FILTER_VALUES = { selectValues: {}, relationValues: {} };
|
|
15
|
+
export function createListAnswers(o) {
|
|
16
|
+
const size = pageSizeOf(o.pageSize);
|
|
17
|
+
let generation = 0;
|
|
18
|
+
let asked = null;
|
|
19
|
+
let base = {
|
|
20
|
+
version: LIST_REQUEST_VERSION,
|
|
21
|
+
settings: requestSettingsOf(LIST_SETTINGS_DEFAULTS),
|
|
22
|
+
};
|
|
23
|
+
let rows = [];
|
|
24
|
+
let next = null;
|
|
25
|
+
let moreOut = false;
|
|
26
|
+
let groups = null;
|
|
27
|
+
let groupedBy = null;
|
|
28
|
+
let total = null;
|
|
29
|
+
let refused = null;
|
|
30
|
+
let landed = 0;
|
|
31
|
+
let first = false;
|
|
32
|
+
let shown = null;
|
|
33
|
+
const changed = () => {
|
|
34
|
+
shown = null;
|
|
35
|
+
o.onChange();
|
|
36
|
+
};
|
|
37
|
+
const send = async (request) => {
|
|
38
|
+
let answer;
|
|
39
|
+
try {
|
|
40
|
+
answer = await o.source(request);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
o.onError(messageOf(error));
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return answerFor(request, answer);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
o.onError(messageOf(error));
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const tracked = async (request, land, after) => {
|
|
55
|
+
const at = generation;
|
|
56
|
+
changed();
|
|
57
|
+
const answer = await send(request);
|
|
58
|
+
if (at !== generation)
|
|
59
|
+
return;
|
|
60
|
+
if (answer)
|
|
61
|
+
land(answer);
|
|
62
|
+
after?.();
|
|
63
|
+
changed();
|
|
64
|
+
};
|
|
65
|
+
const ask = (settings, hold) => {
|
|
66
|
+
const parts = requestSettingsOf(settings);
|
|
67
|
+
const held = hold?.length ? hold : null;
|
|
68
|
+
const key = JSON.stringify([parts, held]);
|
|
69
|
+
if (key === asked)
|
|
70
|
+
return;
|
|
71
|
+
asked = key;
|
|
72
|
+
generation += 1;
|
|
73
|
+
first = true;
|
|
74
|
+
base = { version: LIST_REQUEST_VERSION, settings: parts, ...(held && { hold: held }) };
|
|
75
|
+
moreOut = false;
|
|
76
|
+
const at = generation;
|
|
77
|
+
void tracked({ ...base, part: "rows", page: { size } }, (answer) => {
|
|
78
|
+
landed = at;
|
|
79
|
+
groupedBy = parts.group;
|
|
80
|
+
if (isRefused(answer)) {
|
|
81
|
+
refused = answer.refused.message;
|
|
82
|
+
rows = [];
|
|
83
|
+
next = null;
|
|
84
|
+
groups = null;
|
|
85
|
+
total = null;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
refused = null;
|
|
89
|
+
total = answer.total;
|
|
90
|
+
if (answer.groups) {
|
|
91
|
+
rows = [];
|
|
92
|
+
next = null;
|
|
93
|
+
groups = answer.groups.map((g) => ({
|
|
94
|
+
key: g.key,
|
|
95
|
+
label: g.label,
|
|
96
|
+
count: g.count,
|
|
97
|
+
hidden: g.hidden,
|
|
98
|
+
rows: g.rows,
|
|
99
|
+
next: g.next ?? null,
|
|
100
|
+
out: false,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
groups = null;
|
|
105
|
+
rows = answer.rows;
|
|
106
|
+
next = answer.next;
|
|
107
|
+
}
|
|
108
|
+
}, () => {
|
|
109
|
+
first = false;
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const loadMore = () => {
|
|
113
|
+
if (landed !== generation || groups || next === null || moreOut)
|
|
114
|
+
return;
|
|
115
|
+
moreOut = true;
|
|
116
|
+
void tracked({ ...base, part: "rows", page: { size, after: next } }, (answer) => {
|
|
117
|
+
if (isRefused(answer)) {
|
|
118
|
+
refused = answer.refused.message;
|
|
119
|
+
next = null;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
rows = [...rows, ...answer.rows];
|
|
123
|
+
next = answer.next;
|
|
124
|
+
}, () => {
|
|
125
|
+
moreOut = false;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const loadGroup = (key) => {
|
|
129
|
+
const group = landed === generation ? groups?.find((g) => g.key === key) : undefined;
|
|
130
|
+
if (!group || group.out || (group.rows !== undefined && group.next === null))
|
|
131
|
+
return;
|
|
132
|
+
group.out = true;
|
|
133
|
+
void tracked({
|
|
134
|
+
...base,
|
|
135
|
+
part: "group",
|
|
136
|
+
group: { key },
|
|
137
|
+
page: { size, after: group.rows === undefined ? null : group.next },
|
|
138
|
+
}, (answer) => {
|
|
139
|
+
if (isRefused(answer)) {
|
|
140
|
+
refused = answer.refused.message;
|
|
141
|
+
group.next = null;
|
|
142
|
+
group.rows ??= [];
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (answer.key !== key) {
|
|
146
|
+
o.onError(`answered group ${answer.key} to a group ${key} request`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
group.rows = [...(group.rows ?? []), ...answer.rows];
|
|
150
|
+
group.next = answer.next;
|
|
151
|
+
}, () => {
|
|
152
|
+
group.out = false;
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const once = async (request) => {
|
|
156
|
+
const answer = await send(request);
|
|
157
|
+
return answer && !isRefused(answer) ? answer : null;
|
|
158
|
+
};
|
|
159
|
+
const labelOf = (g) => g.label ?? (groupedBy && o.nameGroup?.(groupedBy, g.key)) ?? null;
|
|
160
|
+
const state = () => {
|
|
161
|
+
if (shown)
|
|
162
|
+
return shown;
|
|
163
|
+
const current = landed === generation;
|
|
164
|
+
const drawn = groups
|
|
165
|
+
? groups
|
|
166
|
+
.filter((g) => !g.hidden)
|
|
167
|
+
.map((g) => ({ key: g.key, label: labelOf(g), items: g.rows ?? [] }))
|
|
168
|
+
: [{ key: "all", label: null, items: rows }];
|
|
169
|
+
shown = {
|
|
170
|
+
groups: drawn,
|
|
171
|
+
grouped: !!groups,
|
|
172
|
+
groupHeads: (groups ?? []).map((g) => ({
|
|
173
|
+
key: g.key,
|
|
174
|
+
label: labelOf(g) ?? g.key,
|
|
175
|
+
count: g.count,
|
|
176
|
+
hidden: g.hidden,
|
|
177
|
+
})),
|
|
178
|
+
ids: drawn.flatMap((g) => g.items.map((row) => row.id)),
|
|
179
|
+
total,
|
|
180
|
+
filterValues: NO_FILTER_VALUES,
|
|
181
|
+
loading: first,
|
|
182
|
+
refused,
|
|
183
|
+
paged: true,
|
|
184
|
+
viewCounts: null,
|
|
185
|
+
holdCounts: null,
|
|
186
|
+
more: {
|
|
187
|
+
rows: current && !groups && next !== null,
|
|
188
|
+
groups: Object.fromEntries((groups ?? []).map((g) => [g.key, current && g.count > 0 && (g.rows === undefined || g.next !== null)])),
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
return shown;
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
ask,
|
|
195
|
+
loadMore,
|
|
196
|
+
loadGroup,
|
|
197
|
+
ids: async () => {
|
|
198
|
+
const at = generation;
|
|
199
|
+
const answer = await send({ ...base, part: "ids" });
|
|
200
|
+
if (!answer || at !== generation)
|
|
201
|
+
return null;
|
|
202
|
+
if (isRefused(answer)) {
|
|
203
|
+
o.onError(answer.refused.message);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
return answer.ids;
|
|
207
|
+
},
|
|
208
|
+
counts: async (of, fields) => (await once({
|
|
209
|
+
...base,
|
|
210
|
+
part: "counts",
|
|
211
|
+
counts: { of, fields: [...fields] },
|
|
212
|
+
}))?.counts ?? null,
|
|
213
|
+
values: async (field) => {
|
|
214
|
+
const answer = await once({ ...base, part: "values", field });
|
|
215
|
+
return answer ? { values: answer.values, labels: answer.labels } : null;
|
|
216
|
+
},
|
|
217
|
+
viewCounts: async (views) => (await once({
|
|
218
|
+
...base,
|
|
219
|
+
settings: { ...base.settings, filter: LIST_SETTINGS_DEFAULTS.filter },
|
|
220
|
+
part: "view-counts",
|
|
221
|
+
views: views.map((v) => ({ id: v.id, filter: v.filter })),
|
|
222
|
+
}))?.counts ?? null,
|
|
223
|
+
state,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { ListPersonalLayer, ListSettings, ListSettingsChange } from "viewkitjs/fields/query";
|
|
1
|
+
import type { ListPersonalLayer, ListRow, ListSettings, ListSettingsChange } from "viewkitjs/fields/query";
|
|
2
2
|
import type { ActivePanel } from "../panels/model.js";
|
|
3
3
|
import type { Pending } from "../panels/react/filter/editor-ctx.js";
|
|
4
4
|
import type { CollectionViewState } from "../panels/view-state.js";
|
|
5
|
+
import type { GridEditsState } from "../grid/core/edits-sink.js";
|
|
6
|
+
import type { ListColumn } from "../model/column-schema.js";
|
|
7
|
+
import type { ListAnswerState } from "./answer.js";
|
|
5
8
|
import type { ListViewsState } from "./views.js";
|
|
6
9
|
/** One list's state, as a part selects it (`useList((s) => …)`). */
|
|
7
10
|
export type ListState = {
|
|
@@ -37,6 +40,12 @@ export type ListState = {
|
|
|
37
40
|
};
|
|
38
41
|
/** The list's saved views where the root keeps them through a store (VK-196); null in memory mode. */
|
|
39
42
|
views: ListViewsState | null;
|
|
43
|
+
/** The list's columns, from its fields (the root's `fields`); null where the root holds none. */
|
|
44
|
+
columns: ListColumn<ListRow>[] | null;
|
|
45
|
+
/** The rows the list shows; null where the root holds none (no `rows`). */
|
|
46
|
+
answer: ListAnswerState | null;
|
|
47
|
+
/** The grid's edits: a write still out, and whether an undo or a redo has anything to take. */
|
|
48
|
+
edits: GridEditsState;
|
|
40
49
|
/** A change to the settings, handed to the app. */
|
|
41
50
|
setSettings: (change: ListSettingsChange) => void;
|
|
42
51
|
/** A patch to the person's layer, handed to the app. */
|
|
@@ -56,6 +65,12 @@ export type ListState = {
|
|
|
56
65
|
resetView: () => void;
|
|
57
66
|
/** Takes back the list's last edit; nothing until the list holds edits. */
|
|
58
67
|
undo: () => void;
|
|
68
|
+
/** Puts back the last edit undone; nothing until there is one. */
|
|
69
|
+
redo: () => void;
|
|
70
|
+
/** The list's next page, where its rows come from a source and there is one; nothing in memory. */
|
|
71
|
+
loadMore: () => void;
|
|
72
|
+
/** A group's next page, likewise. */
|
|
73
|
+
loadGroup: (key: string) => void;
|
|
59
74
|
};
|
|
60
75
|
/** What the app hands the root: synced in on every render. */
|
|
61
76
|
export type ListSync = {
|
|
@@ -73,15 +88,32 @@ export type ListStore = {
|
|
|
73
88
|
/** Takes the app's latest props without telling anyone; `flush` tells. */
|
|
74
89
|
sync: (props: ListSync) => void;
|
|
75
90
|
flush: () => void;
|
|
91
|
+
/** Takes the root's latest columns and answer, worked out as it renders, without telling anyone; `flush` tells. */
|
|
92
|
+
syncData: (data: {
|
|
93
|
+
columns: ListColumn<ListRow>[] | null;
|
|
94
|
+
answer: ListAnswerState | null;
|
|
95
|
+
}) => void;
|
|
76
96
|
/** The toolbar's published bar (`barShown`, `footHere`), and the root's saved views. The ready List widens it with its
|
|
77
97
|
* answer and edits. */
|
|
78
98
|
patch: (patch: {
|
|
79
99
|
panels?: Partial<Pick<ListState["panels"], "barShown" | "footHere">>;
|
|
80
100
|
views?: ListViewsState | null;
|
|
101
|
+
columns?: ListColumn<ListRow>[] | null;
|
|
102
|
+
answer?: ListAnswerState | null;
|
|
103
|
+
edits?: GridEditsState;
|
|
104
|
+
selection?: ListState["selection"];
|
|
81
105
|
}) => void;
|
|
82
|
-
/** The
|
|
83
|
-
wire: (handlers:
|
|
84
|
-
|
|
85
|
-
|
|
106
|
+
/** The grid wires its edits' undo and redo here, and its selection's `select`. */
|
|
107
|
+
wire: (handlers: Wired) => void;
|
|
108
|
+
};
|
|
109
|
+
type Wired = {
|
|
110
|
+
undo?: () => void;
|
|
111
|
+
redo?: () => void;
|
|
112
|
+
select?: (ids: readonly string[] | "all") => void;
|
|
113
|
+
/** Every matching row picked, where the rows in hand aren't all of them (a source's). */
|
|
114
|
+
selectAll?: () => void;
|
|
115
|
+
loadMore?: () => void;
|
|
116
|
+
loadGroup?: (key: string) => void;
|
|
86
117
|
};
|
|
87
118
|
export declare function createListStore(id: string, props: ListSync): ListStore;
|
|
119
|
+
export {};
|
package/views/dist/list/store.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
const NO_EDITS = { saving: false, canUndo: false, canRedo: false };
|
|
1
2
|
const sameKeys = (a, b) => Object.keys(b).every((key) => Object.is(a[key], b[key]));
|
|
2
3
|
const sameIds = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
|
|
4
|
+
const sameSelection = (a, b) => a.all === b.all && a.count === b.count && sameIds(a.ids, b.ids);
|
|
3
5
|
export function createListStore(id, props) {
|
|
4
6
|
let latest = props;
|
|
5
7
|
let wired = {};
|
|
@@ -39,6 +41,10 @@ export function createListStore(id, props) {
|
|
|
39
41
|
write({ panels: { ...state.panels, held } });
|
|
40
42
|
},
|
|
41
43
|
select: (ids) => {
|
|
44
|
+
if (ids === "all" && wired.selectAll)
|
|
45
|
+
return wired.selectAll();
|
|
46
|
+
if (wired.select)
|
|
47
|
+
return wired.select(ids);
|
|
42
48
|
const { selection } = state;
|
|
43
49
|
if (ids === "all" ? selection.all : !selection.all && sameIds(selection.ids, ids))
|
|
44
50
|
return;
|
|
@@ -47,6 +53,9 @@ export function createListStore(id, props) {
|
|
|
47
53
|
saveView: () => latest.view?.onPublish(),
|
|
48
54
|
resetView: () => latest.view?.onReset(),
|
|
49
55
|
undo: () => wired.undo?.(),
|
|
56
|
+
redo: () => wired.redo?.(),
|
|
57
|
+
loadMore: () => wired.loadMore?.(),
|
|
58
|
+
loadGroup: (key) => wired.loadGroup?.(key),
|
|
50
59
|
};
|
|
51
60
|
const data = {
|
|
52
61
|
id,
|
|
@@ -62,6 +71,9 @@ export function createListStore(id, props) {
|
|
|
62
71
|
},
|
|
63
72
|
selection: { ids: [], all: false, count: 0 },
|
|
64
73
|
views: null,
|
|
74
|
+
columns: null,
|
|
75
|
+
answer: null,
|
|
76
|
+
edits: NO_EDITS,
|
|
65
77
|
};
|
|
66
78
|
let state = { ...data, ...actions };
|
|
67
79
|
function swap(next) {
|
|
@@ -92,6 +104,17 @@ export function createListStore(id, props) {
|
|
|
92
104
|
swap(changed);
|
|
93
105
|
dirty = true;
|
|
94
106
|
},
|
|
107
|
+
syncData: (data) => {
|
|
108
|
+
const changed = {};
|
|
109
|
+
if (!Object.is(state.columns, data.columns))
|
|
110
|
+
changed.columns = data.columns;
|
|
111
|
+
if (!Object.is(state.answer, data.answer))
|
|
112
|
+
changed.answer = data.answer;
|
|
113
|
+
if (Object.keys(changed).length === 0)
|
|
114
|
+
return;
|
|
115
|
+
swap(changed);
|
|
116
|
+
dirty = true;
|
|
117
|
+
},
|
|
95
118
|
flush: () => {
|
|
96
119
|
if (!dirty)
|
|
97
120
|
return;
|
|
@@ -105,6 +128,14 @@ export function createListStore(id, props) {
|
|
|
105
128
|
next.panels = { ...state.panels, ...patch.panels };
|
|
106
129
|
if (patch.views !== undefined && !Object.is(state.views, patch.views))
|
|
107
130
|
next.views = patch.views;
|
|
131
|
+
if (patch.columns !== undefined && !Object.is(state.columns, patch.columns))
|
|
132
|
+
next.columns = patch.columns;
|
|
133
|
+
if (patch.answer !== undefined && !Object.is(state.answer, patch.answer))
|
|
134
|
+
next.answer = patch.answer;
|
|
135
|
+
if (patch.edits && !sameKeys(state.edits, patch.edits))
|
|
136
|
+
next.edits = patch.edits;
|
|
137
|
+
if (patch.selection && !sameSelection(state.selection, patch.selection))
|
|
138
|
+
next.selection = patch.selection;
|
|
108
139
|
if (Object.keys(next).length > 0)
|
|
109
140
|
write(next);
|
|
110
141
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { ReadyToolbarProps } from "../panels/react/toolbar/ReadyToolbar.js";
|
|
3
3
|
/** `ReadyToolbar`'s props but those the root holds: the settings and the layer with their callbacks, the shared view,
|
|
4
|
-
* `sortFilter` and `bar`.
|
|
5
|
-
|
|
4
|
+
* `sortFilter` and `bar`. `columns`, `groupHeads` and `filterData` default to the root's, where it holds a list's
|
|
5
|
+
* fields and rows; handed, they win. */
|
|
6
|
+
export type ListToolbarProps<Row> = Omit<ReadyToolbarProps<Row>, "settings" | "layer" | "onChange" | "onLayerChange" | "view" | "sortFilter" | "bar" | "columns"> & Partial<Pick<ReadyToolbarProps<Row>, "columns">>;
|
|
6
7
|
export declare function ListToolbar<Row>(props: ListToolbarProps<Row>): ReactNode;
|
|
@@ -26,11 +26,13 @@ import { ToolbarSortPill } from "../panels/react/toolbar/ToolbarSortPill.js";
|
|
|
26
26
|
import { ToolbarAdvancedFilters } from "../panels/react/toolbar/ToolbarAdvancedFilters.js";
|
|
27
27
|
import { ToolbarViews } from "../panels/react/toolbar/ToolbarViews.js";
|
|
28
28
|
import { applyParts } from "./parts.js";
|
|
29
|
-
import { useList, useListPanel, useListStore } from "./root.js";
|
|
29
|
+
import { useList, useListPanel, useListStore } from "./root-base.js";
|
|
30
30
|
import { useListViewsAxis } from "./views-axis.js";
|
|
31
31
|
export function ListToolbar(props) {
|
|
32
32
|
const { views: viewsHanded, viewsLayout, onAdd, addItems, addLabel, fieldEditor, searchPlaceholder, searching, hosts, narrow, className, viewName, onRenameView, onCopyLink, onExport, exportCount, menus, toolbarParts, } = props;
|
|
33
33
|
const storeViews = useListViewsAxis(props.layouts);
|
|
34
|
+
const rootColumns = useList((s) => s.columns);
|
|
35
|
+
const answer = useList((s) => s.answer);
|
|
34
36
|
const views = viewsHanded ?? storeViews;
|
|
35
37
|
const store = useListStore();
|
|
36
38
|
const settings = useList((s) => s.view.settings);
|
|
@@ -71,6 +73,9 @@ export function ListToolbar(props) {
|
|
|
71
73
|
const { toolbarParts: _placed, ...settingsProps } = props;
|
|
72
74
|
const input = {
|
|
73
75
|
...settingsProps,
|
|
76
|
+
columns: props.columns ?? rootColumns ?? [],
|
|
77
|
+
groupHeads: props.groupHeads ?? answer?.groupHeads,
|
|
78
|
+
filterData: props.filterData ?? answer?.filterValues,
|
|
74
79
|
settings,
|
|
75
80
|
layer,
|
|
76
81
|
onChange,
|
|
@@ -118,8 +123,15 @@ export function ListToolbar(props) {
|
|
|
118
123
|
} }));
|
|
119
124
|
const sortNode = several && panels.sorts ? (_jsx(ToolbarSortPill, { sorts: panels.sorts, open: sortState.open, onOpenChange: sortState.onOpenChange, host: hosts?.sort, addAfter: props.addAfter })) : (_jsx(ToolbarSort, { sort: panels.sort, open: sortState.open, onOpenChange: sortState.onOpenChange, host: hosts?.sort }));
|
|
120
125
|
const filterNode = (_jsx(ToolbarFilter, { filters: panels.filters, filterTree: panels.filterTree, onClear: clear("filters"), open: filterState.open, onOpenChange: filterState.onOpenChange, page: filterState.page, onPageChange: filterState.onPageChange, host: hosts?.filter }));
|
|
126
|
+
const holdCounts = answer?.holdCounts;
|
|
121
127
|
const quick = props.quickFilters?.fields.length
|
|
122
|
-
? {
|
|
128
|
+
? {
|
|
129
|
+
...props.quickFilters,
|
|
130
|
+
showCounts: props.quickFilters.showCounts ?? show,
|
|
131
|
+
...(holdCounts && {
|
|
132
|
+
fields: props.quickFilters.fields.map((field) => field.counts === undefined && holdCounts[field.key] ? { ...field, counts: holdCounts[field.key] } : field),
|
|
133
|
+
}),
|
|
134
|
+
}
|
|
123
135
|
: null;
|
|
124
136
|
const quickNode = quick ? (_jsx(ToolbarQuickFilters, { quickFilters: quick, open: quickState.open, onOpenChange: quickState.onOpenChange, host: hosts?.quick })) : null;
|
|
125
137
|
const arrangement = props.arrangement ?? "kit";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { writeListLink } from "viewkitjs/fields/query";
|
|
4
4
|
import { useViews } from "../provider/context.js";
|
|
5
|
-
import { useList } from "./root.js";
|
|
5
|
+
import { useList } from "./root-base.js";
|
|
6
6
|
const LAYOUT_NAMES = {
|
|
7
7
|
table: { key: "views.panels.layout-table" },
|
|
8
8
|
list: { key: "views.panels.layout-list" },
|
|
@@ -12,6 +12,7 @@ const LAYOUT_NAMES = {
|
|
|
12
12
|
const isLayout = (id) => id in LAYOUT_NAMES;
|
|
13
13
|
export function useListViewsAxis(layouts) {
|
|
14
14
|
const views = useList((s) => s.views);
|
|
15
|
+
const counts = useList((s) => s.answer?.viewCounts ?? null);
|
|
15
16
|
const changes = useList((s) => s.view.shared?.changes ?? 0);
|
|
16
17
|
const settings = useList((s) => s.view.settings);
|
|
17
18
|
const openPanel = useList((s) => s.openPanel);
|
|
@@ -69,6 +70,7 @@ export function useListViewsAxis(layouts) {
|
|
|
69
70
|
layout: v.settings.layout,
|
|
70
71
|
...(!views.canSave(v) && { readOnly: true }),
|
|
71
72
|
...(v.id === views.open && changes > 0 && { changed: true }),
|
|
73
|
+
...(counts?.[v.id] !== undefined && { count: counts[v.id] }),
|
|
72
74
|
})),
|
|
73
75
|
onChange: views.openView,
|
|
74
76
|
onCreate: () => { },
|
|
@@ -92,5 +94,5 @@ export function useListViewsAxis(layouts) {
|
|
|
92
94
|
onChange,
|
|
93
95
|
},
|
|
94
96
|
};
|
|
95
|
-
}, [views, changes, settings.search, openPanel, messages, ports, layouts]);
|
|
97
|
+
}, [views, changes, counts, settings.search, openPanel, messages, ports, layouts]);
|
|
96
98
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ListLayout, type ListLinkReading, type ListSettings, type SavedView } from "viewkitjs/fields/query";
|
|
1
|
+
import { type ListLayout, type ListLinkReading, type ListSettings, type ListSettingsChange, type SavedView } from "viewkitjs/fields/query";
|
|
2
2
|
import type { ListSync } from "./store.js";
|
|
3
3
|
import type { ViewsStore } from "./views-store.js";
|
|
4
4
|
/** A list's saved views as the root holds them (`ListState.views`): null in memory mode. */
|
|
@@ -15,7 +15,8 @@ export type ListViewsState = {
|
|
|
15
15
|
pending: boolean;
|
|
16
16
|
/** What the list holds, in the delete question's line (`ListViewsOptions.records`, default "records"). */
|
|
17
17
|
records: string;
|
|
18
|
-
|
|
18
|
+
/** Opens a view; with `change`, lays it over the view as the edited settings, its draft replaced (a link wins). */
|
|
19
|
+
openView: (id: string, change?: ListSettingsChange) => void;
|
|
19
20
|
/** The open view's edits saved over it, where this person may (`canSave`). */
|
|
20
21
|
save: () => void;
|
|
21
22
|
/** A new view of the person's own, named `name`: the edited settings of `from` (its edits let go), or with no `from`
|
|
@@ -58,6 +59,10 @@ export declare function createListViews(o: {
|
|
|
58
59
|
link?: ListLinkReading;
|
|
59
60
|
/** The delete question's noun; default "records". */
|
|
60
61
|
records?: string;
|
|
62
|
+
/** `false` takes "Save for everyone" away, even where the store lets this person share. */
|
|
63
|
+
share?: boolean;
|
|
64
|
+
/** The view this person had open last: opened where no link names one and the store still holds it. */
|
|
65
|
+
kept?: string;
|
|
61
66
|
/** Told whenever the settings, the layer or the slice change, after the controller has synced them into the list store. */
|
|
62
67
|
onChange: () => void;
|
|
63
68
|
/** Said when a store write fails (the root hands `ports.toast.error`). */
|
package/views/dist/list/views.js
CHANGED
|
@@ -20,7 +20,7 @@ export function createListViews(o) {
|
|
|
20
20
|
const { id: listId, store } = o;
|
|
21
21
|
const link = o.link && (o.link.view !== undefined || Object.keys(o.link.change).some((k) => k !== "search")) ? o.link : null;
|
|
22
22
|
const linkSearch = o.link?.change.search;
|
|
23
|
-
const share = !!store.can?.share;
|
|
23
|
+
const share = !!store.can?.share && o.share !== false;
|
|
24
24
|
const records = o.records ?? "records";
|
|
25
25
|
let generation = 0;
|
|
26
26
|
let ready = false;
|
|
@@ -137,7 +137,8 @@ export function createListViews(o) {
|
|
|
137
137
|
run(() => store.list(listId), (views) => {
|
|
138
138
|
list = listing(views);
|
|
139
139
|
const linked = link?.view !== undefined ? list.find((v) => v.id === link.view) : undefined;
|
|
140
|
-
const
|
|
140
|
+
const kept = !linked && o.kept !== undefined ? list.find((v) => v.id === o.kept) : undefined;
|
|
141
|
+
const view = linked ?? kept ?? list[0];
|
|
141
142
|
const land = (draft) => {
|
|
142
143
|
open = view?.id ?? null;
|
|
143
144
|
const saved = view?.settings ?? settingsForSaving(o.defaults);
|
|
@@ -221,13 +222,23 @@ export function createListViews(o) {
|
|
|
221
222
|
write(() => store.reorder(listId, scope, ids));
|
|
222
223
|
};
|
|
223
224
|
const actions = {
|
|
224
|
-
openView: (id) => {
|
|
225
|
-
if (!ready
|
|
225
|
+
openView: (id, change) => {
|
|
226
|
+
if (!ready)
|
|
226
227
|
return;
|
|
227
228
|
const view = list.find((v) => v.id === id);
|
|
228
229
|
if (!view)
|
|
229
230
|
return;
|
|
230
|
-
|
|
231
|
+
if (change === undefined) {
|
|
232
|
+
if (id === open)
|
|
233
|
+
return;
|
|
234
|
+
opening(view);
|
|
235
|
+
tell();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
open = view.id;
|
|
239
|
+
base = null;
|
|
240
|
+
edited = applySettingsChange(view.settings, change);
|
|
241
|
+
writeDraft();
|
|
231
242
|
tell();
|
|
232
243
|
},
|
|
233
244
|
save: () => {
|
|
@@ -115,6 +115,19 @@ export declare function baseColumnOrder<Row>(columns: ListColumn<Row>[], order:
|
|
|
115
115
|
* stays because a lock site reads better saying what it is looking up.
|
|
116
116
|
*/
|
|
117
117
|
export declare function lockKeyOf<Row>(col: ListColumn<Row>): string;
|
|
118
|
+
/**
|
|
119
|
+
* A list's locks with each edit-through pair locked together: a lock stored under either a worked-out field edited
|
|
120
|
+
* through a stored one (`editThrough`) or that stored field holds under both keys. A lock is a rule about what an edit
|
|
121
|
+
* writes, and an edit of the worked-out field writes the stored one, so a lock on Paid on locks the Date edited
|
|
122
|
+
* through it, and a lock on Date locks Paid on. The stored config is untouched: each key keeps its own toggle, and
|
|
123
|
+
* this is the config a lock is checked against. The grid widens its `listConfig` with its columns' fields; a surface
|
|
124
|
+
* that checks a lock by field key (a drawer's `LockedResolver`) passes its own fields. Gives back the same config when
|
|
125
|
+
* no pair widens it.
|
|
126
|
+
*/
|
|
127
|
+
export declare function withEditThroughLocks(config: ListSettingsConfig | undefined, fields: Iterable<{
|
|
128
|
+
key: string;
|
|
129
|
+
editThrough?: string;
|
|
130
|
+
} | null | undefined>): ListSettingsConfig | undefined;
|
|
118
131
|
/** Is this column locked by the workspace config (a column lock or the whole
|
|
119
132
|
* table's read-only)? Locks only ever SUBTRACT — they never grant. */
|
|
120
133
|
export declare function gridColumnLocked<Row>(col: ListColumn<Row>, config: ListSettingsConfig | undefined): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { acceptFieldCommit, isMultipleType, lockReason, relationIdOf, valueTypeOf, } from "viewkitjs/fields";
|
|
1
|
+
import { acceptFieldCommit, isMultipleType, lockReason, relationIdOf, valueTypeOf, withUrlScheme, } from "viewkitjs/fields";
|
|
2
2
|
import { resolveViewsMessage } from "../contract.js";
|
|
3
3
|
import { opensAsList } from "./one-value.js";
|
|
4
4
|
import { prettifyOptionValue, resolveColumnOrder } from "./column-state.js";
|
|
@@ -116,6 +116,27 @@ export function baseColumnOrder(columns, order, viewBacked) {
|
|
|
116
116
|
export function lockKeyOf(col) {
|
|
117
117
|
return col.partOf?.field.key ?? fieldKeyOf(col);
|
|
118
118
|
}
|
|
119
|
+
export function withEditThroughLocks(config, fields) {
|
|
120
|
+
const locked = config?.columns;
|
|
121
|
+
if (!locked)
|
|
122
|
+
return config;
|
|
123
|
+
let widened;
|
|
124
|
+
for (const field of fields) {
|
|
125
|
+
const through = field?.editThrough;
|
|
126
|
+
if (!field || !through)
|
|
127
|
+
continue;
|
|
128
|
+
const pairLocked = !!locked[field.key]?.locked || !!locked[through]?.locked;
|
|
129
|
+
if (!pairLocked)
|
|
130
|
+
continue;
|
|
131
|
+
for (const key of [field.key, through]) {
|
|
132
|
+
if (locked[key]?.locked || widened?.[key]?.locked)
|
|
133
|
+
continue;
|
|
134
|
+
widened ??= { ...locked };
|
|
135
|
+
widened[key] = { ...locked[key], locked: true };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return widened ? { ...config, columns: widened } : config;
|
|
139
|
+
}
|
|
119
140
|
export function gridColumnLocked(col, config) {
|
|
120
141
|
if (!config)
|
|
121
142
|
return false;
|
|
@@ -210,7 +231,7 @@ export function coerceWrite(col, next, messages) {
|
|
|
210
231
|
return { ok: true, value: next };
|
|
211
232
|
if (typeof next !== "string")
|
|
212
233
|
return { ok: true, value: next };
|
|
213
|
-
const trimmed = next.trim();
|
|
234
|
+
const trimmed = col.field?.type === "url" && col.field.bareHost === "https" ? withUrlScheme(next) : next.trim();
|
|
214
235
|
if (!URL_SHAPE.test(trimmed)) {
|
|
215
236
|
return { ok: false, reason: messages({ key: "views.grid.write-not-url" }) };
|
|
216
237
|
}
|
|
@@ -113,7 +113,10 @@ export type ListColumn<Row> = {
|
|
|
113
113
|
* custom money cell draws the chassis's reading and converts nothing. */
|
|
114
114
|
render?: (row: Row, cell?: RenderedValue) => ReactNode;
|
|
115
115
|
actions?: ListCellAction<Row>[];
|
|
116
|
-
|
|
116
|
+
/** An adornment beside the cell's value, drawn by the app. Handed the row and, beside it, the value the cell
|
|
117
|
+
* shows: a write still saving (a paste, a fill, an edit) while it saves, else what `accessor` reads, so a cue
|
|
118
|
+
* read from it agrees with the value beside it from the moment it shows, and goes back with it if the save fails. */
|
|
119
|
+
indicator?: (row: Row, cell?: RenderedValue) => ReactNode;
|
|
117
120
|
accessor?: (row: Row) => unknown;
|
|
118
121
|
/** Raw field used for editing when display accessor contains fallbacks. */
|
|
119
122
|
editAccessor?: (row: Row) => unknown;
|
|
@@ -153,6 +156,13 @@ export type ListColumn<Row> = {
|
|
|
153
156
|
money?: MoneyDeclaration<Row>;
|
|
154
157
|
/** The reading in force on a convertible column — set by `readMoneyColumn`. */
|
|
155
158
|
reading?: MoneyReading;
|
|
159
|
+
/** What a convertible money column SORTS by when it shows each row's own
|
|
160
|
+
* currency: the row's figure converted into the reader's default currency
|
|
161
|
+
* (`null`: no figure, or no rate), so rows in different currencies order as
|
|
162
|
+
* one number that flips with the direction. Set by `readMoneyColumns` under
|
|
163
|
+
* the Original reading; absent, the column sorts by `accessor`, clustered by
|
|
164
|
+
* code. */
|
|
165
|
+
sortAccessor?: (row: Row) => number | null;
|
|
156
166
|
defaultAggregate?: ListAggregateKind;
|
|
157
167
|
/** The field whose database figures this column's footer reads, when it is
|
|
158
168
|
* not the column's own (Transactions' Amount totals its paid figure). A
|
|
@@ -296,5 +296,6 @@ export function viewReaderFrom(columns, decimals = {}) {
|
|
|
296
296
|
return decimals[key] ?? col.format?.decimals ?? fallback;
|
|
297
297
|
},
|
|
298
298
|
codeOf: (row, key) => denominationOf(byKey.get(key), row),
|
|
299
|
+
sortAmountOf: (row, key) => byKey.get(key)?.sortAccessor?.(row),
|
|
299
300
|
};
|
|
300
301
|
}
|
|
@@ -79,6 +79,8 @@ export type FilterEditorField = {
|
|
|
79
79
|
far?: readonly FilterEditorField[];
|
|
80
80
|
/** How its field is marked, as the grid's header marks its column (`columnMark`); a relation has none. */
|
|
81
81
|
mark?: FieldMark;
|
|
82
|
+
/** A number field that holds whole numbers only (`isIntegerField`): its box takes whole numbers. */
|
|
83
|
+
integer?: true;
|
|
82
84
|
/** Why no rule can be made on it, in the app's words (an unavailable capability's reason, else
|
|
83
85
|
* `views.panels.filter-not-offered`); absent, it can. Only in `FilterTreeConfig.listed`: a field list draws it greyed. */
|
|
84
86
|
disabled?: string;
|