@viewkitjs/views 0.3.0 → 0.5.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 +641 -0
- package/README.md +3 -3
- package/dist/atoms/CommandMenu.d.ts +1 -1
- package/dist/atoms/CommandMenu.js +7 -3
- package/dist/atoms/DrillRows.d.ts +3 -0
- package/dist/atoms/DrillRows.js +25 -0
- package/dist/atoms/PanelRows.d.ts +5 -0
- package/dist/atoms/PanelRows.js +40 -0
- package/dist/atoms/PanelSearch.d.ts +2 -0
- package/dist/atoms/PanelSearch.js +21 -0
- package/dist/atoms/RelationRoles.d.ts +2 -0
- package/dist/atoms/RelationRoles.js +6 -0
- package/dist/atoms/Row.js +2 -1
- package/dist/atoms/RowMenu.js +2 -1
- package/dist/atoms/SelectionSheet.d.ts +3 -0
- package/dist/atoms/SelectionSheet.js +30 -0
- package/dist/atoms/StatusMarker.js +3 -1
- package/dist/atoms/Tag.js +2 -1
- package/dist/atoms/defaults.js +14 -0
- package/dist/atoms/types.d.ts +146 -8
- package/dist/cells/cell-values.js +4 -2
- package/dist/cells/relation-wrap.js +3 -1
- package/dist/contract.d.ts +212 -17
- package/dist/contract.js +208 -6
- package/dist/display/boolean.js +3 -1
- package/dist/display/date.d.ts +1 -1
- package/dist/display/date.js +4 -2
- package/dist/display/format.js +20 -4
- package/dist/display/link.js +4 -3
- package/dist/display/multi-value.js +2 -1
- package/dist/display/percent.js +2 -1
- package/dist/display/phone.js +2 -1
- package/dist/display/range.js +3 -13
- package/dist/display/relation.js +23 -8
- package/dist/display/rich-text.js +2 -1
- package/dist/editors/ChipsEditor.d.ts +5 -1
- package/dist/editors/ChipsEditor.js +15 -2
- package/dist/editors/DateEditor.d.ts +2 -0
- package/dist/editors/DateEditor.js +76 -10
- package/dist/editors/EditorPanel.d.ts +14 -4
- package/dist/editors/EditorPanel.js +21 -4
- package/dist/editors/LocationEditor.js +35 -3
- package/dist/editors/NumberEditor.js +3 -2
- package/dist/editors/RangeEditor.d.ts +8 -0
- package/dist/editors/RangeEditor.js +3 -2
- package/dist/editors/RelationEditor.d.ts +2 -0
- package/dist/editors/RelationEditor.js +16 -2
- package/dist/editors/RelationSetEditor.d.ts +4 -2
- package/dist/editors/RelationSetEditor.js +36 -2
- package/dist/editors/SelectEditor.d.ts +5 -2
- package/dist/editors/SelectEditor.js +31 -4
- package/dist/editors/TextEditor.js +3 -1
- package/dist/editors/ValueListEditor.d.ts +3 -0
- package/dist/editors/ValueListEditor.js +10 -4
- package/dist/editors/edit-session.d.ts +14 -2
- package/dist/editors/edit-session.js +13 -5
- package/dist/editors/escape-rule.d.ts +12 -0
- package/dist/editors/escape-rule.js +8 -0
- package/dist/editors/open-value.js +2 -1
- package/dist/editors/picker-slot.d.ts +25 -0
- package/dist/editors/picker-slot.js +37 -0
- package/dist/editors/relation-picker.d.ts +44 -0
- package/dist/editors/relation-picker.js +49 -0
- package/dist/editors/relation-source.d.ts +1 -0
- package/dist/editors/relation-source.js +7 -1
- package/dist/field-row/FieldNoteLine.js +2 -1
- package/dist/field-row/FieldRow.js +41 -6
- package/dist/field-row/FieldRowLane.js +3 -1
- package/dist/field-row/editors/RowChipsEditor.js +1 -1
- package/dist/field-row/editors/RowDateEditor.js +1 -1
- package/dist/field-row/editors/RowEditor.js +2 -1
- package/dist/field-row/editors/RowRangeEditor.js +2 -1
- package/dist/field-row/editors/RowRelationEditor.js +2 -2
- package/dist/field-row/editors/RowSelectEditor.d.ts +1 -1
- package/dist/field-row/editors/RowSelectEditor.js +2 -2
- package/dist/field-row/editors/RowValueListEditor.js +1 -1
- package/dist/field-row/editors/host.d.ts +3 -0
- package/dist/field-row/editors/row-session.js +4 -1
- package/dist/fields/menus.d.ts +2 -0
- package/dist/fields/range-unit.d.ts +7 -0
- package/dist/fields/range-unit.js +13 -0
- package/dist/figures.d.ts +5 -48
- package/dist/figures.js +1 -63
- package/dist/grid/chrome/GridAddColumn.d.ts +8 -0
- package/dist/grid/chrome/GridAddColumn.js +66 -9
- package/dist/grid/chrome/GridAggregateMenu.d.ts +5 -2
- package/dist/grid/chrome/GridAggregateMenu.js +33 -4
- package/dist/grid/chrome/GridCellEditors.d.ts +9 -2
- package/dist/grid/chrome/GridCellEditors.js +24 -5
- package/dist/grid/chrome/GridCellOutline.d.ts +3 -2
- package/dist/grid/chrome/GridCellOutline.js +11 -1
- package/dist/grid/chrome/GridChipsEditor.js +1 -1
- package/dist/grid/chrome/GridColumnColorSection.d.ts +2 -0
- package/dist/grid/chrome/GridColumnColorSection.js +2 -2
- package/dist/grid/chrome/GridColumnDateSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDateSection.js +2 -2
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +2 -2
- package/dist/grid/chrome/GridColumnMenu.d.ts +10 -6
- package/dist/grid/chrome/GridColumnMenu.js +62 -24
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +2 -2
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +1 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +1 -1
- package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
- package/dist/grid/chrome/GridDateEditor.js +1 -1
- package/dist/grid/chrome/GridFooter.js +7 -48
- package/dist/grid/chrome/GridGroupMenu.d.ts +11 -5
- package/dist/grid/chrome/GridGroupMenu.js +28 -13
- package/dist/grid/chrome/GridHeader.d.ts +3 -1
- package/dist/grid/chrome/GridHeader.js +8 -8
- package/dist/grid/chrome/GridNumberEditor.js +3 -24
- package/dist/grid/chrome/GridRangeEditor.js +3 -2
- package/dist/grid/chrome/GridRelationEditor.js +2 -2
- package/dist/grid/chrome/GridRow.d.ts +2 -1
- package/dist/grid/chrome/GridRow.js +13 -37
- package/dist/grid/chrome/GridRowActions.js +2 -1
- package/dist/grid/chrome/GridRowCells.js +9 -4
- package/dist/grid/chrome/GridSelectEditor.js +30 -20
- package/dist/grid/chrome/GridStructure.d.ts +11 -4
- package/dist/grid/chrome/GridStructure.js +19 -7
- package/dist/grid/chrome/GridTable.js +138 -16
- package/dist/grid/chrome/GridTableSurface.d.ts +25 -12
- package/dist/grid/chrome/GridTableSurface.js +13 -6
- package/dist/grid/chrome/GridTextEditor.js +3 -1
- package/dist/grid/chrome/GridValueListEditor.js +1 -1
- package/dist/grid/chrome/cell-clipboard.d.ts +1 -1
- package/dist/grid/chrome/cell-clipboard.js +1 -1
- package/dist/grid/chrome/checks.d.ts +10 -2
- package/dist/grid/chrome/checks.js +17 -11
- package/dist/grid/chrome/column-glyph.d.ts +2 -2
- package/dist/grid/chrome/column-glyph.js +4 -0
- package/dist/grid/chrome/grid-add-column-items.d.ts +13 -0
- package/dist/grid/chrome/grid-add-column-items.js +40 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +2 -0
- package/dist/grid/chrome/grid-cell-classes.js +10 -4
- package/dist/grid/chrome/grid-column-menu-items.d.ts +75 -0
- package/dist/grid/chrome/grid-column-menu-items.js +263 -0
- package/dist/grid/chrome/grid-edit-escape.d.ts +4 -0
- package/dist/grid/chrome/grid-edit-escape.js +12 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +2 -1
- package/dist/grid/chrome/grid-edit-session.js +14 -1
- package/dist/grid/chrome/grid-figure-value.d.ts +25 -0
- package/dist/grid/chrome/grid-figure-value.js +40 -0
- package/dist/grid/chrome/grid-fitted-box.d.ts +15 -0
- package/dist/grid/chrome/grid-fitted-box.js +26 -0
- package/dist/grid/chrome/grid-group-menu-items.d.ts +31 -0
- package/dist/grid/chrome/grid-group-menu-items.js +75 -0
- package/dist/grid/chrome/grid-group-menu-parts.d.ts +27 -0
- package/dist/grid/chrome/grid-group-menu-parts.js +19 -0
- package/dist/grid/chrome/grid-hover.d.ts +1 -0
- package/dist/grid/chrome/grid-hover.js +13 -1
- package/dist/grid/chrome/grid-lab.d.ts +7 -0
- package/dist/grid/chrome/grid-lab.js +7 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +12 -0
- package/dist/grid/chrome/grid-menu-focus.js +13 -0
- package/dist/grid/chrome/{useGridRowContextMenu.d.ts → grid-row-menu-items.d.ts} +15 -4
- package/dist/grid/chrome/{useGridRowContextMenu.js → grid-row-menu-items.js} +15 -18
- package/dist/grid/chrome/grid-row-props.d.ts +3 -1
- package/dist/grid/chrome/grid-row-window.d.ts +15 -5
- package/dist/grid/chrome/grid-row-window.js +44 -10
- package/dist/grid/chrome/grid-rows-menu.d.ts +38 -0
- package/dist/grid/chrome/grid-rows-menu.js +83 -0
- package/dist/grid/chrome/grid-table-props.d.ts +53 -8
- package/dist/grid/chrome/useGridBandFigures.d.ts +26 -0
- package/dist/grid/chrome/useGridBandFigures.js +50 -0
- package/dist/grid/chrome/useGridBoxes.d.ts +22 -0
- package/dist/grid/chrome/useGridBoxes.js +22 -0
- package/dist/grid/chrome/useGridColumnLayout.js +29 -4
- package/dist/grid/chrome/useGridKeyboard.js +7 -2
- package/dist/grid/chrome/useGridPartColumns.d.ts +5 -0
- package/dist/grid/chrome/useGridPartColumns.js +9 -0
- package/dist/grid/chrome/useGridRangeGestures.js +2 -1
- package/dist/grid/chrome/useGridRecorder.d.ts +16 -0
- package/dist/grid/chrome/useGridRecorder.js +144 -0
- package/dist/grid/chrome/useGridRowOpener.d.ts +41 -0
- package/dist/grid/chrome/useGridRowOpener.js +83 -0
- package/dist/grid/chrome/useGridScrollArea.d.ts +38 -12
- package/dist/grid/chrome/useGridScrollArea.js +70 -17
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +67 -9
- package/dist/grid/core/clipboard-model.d.ts +11 -3
- package/dist/grid/core/clipboard-model.js +9 -4
- package/dist/grid/core/commit-model.d.ts +7 -0
- package/dist/grid/core/editing-controller.d.ts +31 -1
- package/dist/grid/core/editing-controller.js +65 -0
- package/dist/grid/core/grid-recorder.d.ts +111 -0
- package/dist/grid/core/grid-recorder.js +223 -0
- package/dist/grid/core/part-edits.d.ts +18 -0
- package/dist/grid/core/part-edits.js +48 -0
- package/dist/grid/core/pending-reconciliation.js +12 -3
- package/dist/grid/core/refusal-sentence.d.ts +3 -0
- package/dist/grid/core/refusal-sentence.js +15 -0
- package/dist/grid/core/row-opened-from.d.ts +21 -0
- package/dist/grid/core/row-opened-from.js +11 -0
- package/dist/grid/core/useGridEditing.d.ts +16 -2
- package/dist/grid/core/useGridEditing.js +10 -4
- package/dist/grid/core/value-equality.d.ts +19 -1
- package/dist/grid/core/value-equality.js +24 -0
- package/dist/grid/index.d.ts +4 -1
- package/dist/grid/index.js +1 -0
- package/dist/grid/useGridTablePrefs.d.ts +1 -1
- package/dist/grid-lab.d.ts +18 -0
- package/dist/grid-lab.js +16 -0
- package/dist/grouping/sort-groups.d.ts +6 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/reset.d.ts +9 -0
- package/dist/internal/reset.js +1 -0
- package/dist/model/aggregates.d.ts +3 -3
- package/dist/model/aggregates.js +17 -71
- package/dist/model/column-capabilities.d.ts +29 -2
- package/dist/model/column-capabilities.js +27 -3
- package/dist/model/column-filters.js +24 -4
- package/dist/model/column-inspect.d.ts +2 -1
- package/dist/model/column-order.d.ts +2 -2
- package/dist/model/column-schema.d.ts +18 -7
- package/dist/model/column-state.d.ts +9 -20
- package/dist/model/column-state.js +1 -4
- package/dist/model/column-types.d.ts +1 -15
- package/dist/model/column-types.js +1 -1
- package/dist/model/part-columns.d.ts +17 -0
- package/dist/model/part-columns.js +67 -0
- package/dist/model/part-rows.d.ts +3 -10
- package/dist/model/part-rows.js +6 -11
- package/dist/model/part-write.d.ts +11 -0
- package/dist/model/part-write.js +52 -0
- package/dist/model/preferences.d.ts +3 -23
- package/dist/model/preferences.js +1 -17
- package/dist/model/prefs-buckets.d.ts +0 -27
- package/dist/model/prefs-buckets.js +1 -1
- package/dist/model/relation-filters.d.ts +0 -1
- package/dist/model/relation-filters.js +1 -1
- package/dist/model/row-icon.d.ts +5 -9
- package/dist/model/view-rules.d.ts +32 -6
- package/dist/model/view-rules.js +101 -21
- package/dist/provider/ViewsProvider.d.ts +22 -2
- package/dist/provider/ViewsProvider.js +21 -2
- package/dist/provider/components.d.ts +197 -9
- package/dist/provider/context.d.ts +12 -1
- package/dist/provider/desktop.d.ts +3 -0
- package/dist/provider/desktop.js +7 -4
- package/dist/provider/menu-groups.d.ts +3 -2
- package/dist/provider/menu-groups.js +13 -7
- package/dist/provider/missing-slot.d.ts +10 -0
- package/dist/provider/missing-slot.js +15 -0
- package/dist/provider/plain-input.d.ts +3 -2
- package/dist/provider/plain-input.js +3 -1
- package/dist/react.d.ts +3 -2
- package/dist/selection/SelectionBar.d.ts +18 -0
- package/dist/selection/SelectionBar.js +92 -0
- package/dist/selection/SelectionBarPhone.d.ts +3 -0
- package/dist/selection/SelectionBarPhone.js +14 -0
- package/dist/selection/bar-overflow.d.ts +12 -0
- package/dist/selection/bar-overflow.js +42 -0
- package/dist/selection/bar-parts.d.ts +15 -0
- package/dist/selection/bar-parts.js +17 -0
- package/dist/selection/index.d.ts +2 -0
- package/dist/selection/index.js +1 -0
- package/dist/selection/types.d.ts +3 -2
- package/dist/selection/verbs.d.ts +34 -0
- package/dist/selection/verbs.js +1 -0
- package/docs/contract.md +142 -39
- package/docs/getting-started.md +1 -1
- package/docs/guides/atoms.md +32 -4
- package/docs/guides/columns.md +1 -1
- package/docs/guides/display.md +1 -1
- package/docs/guides/editors.md +3 -3
- package/docs/guides/ports.md +1 -1
- package/docs/guides/selection.md +32 -20
- package/docs/guides/the-grid.md +43 -21
- package/docs/guides/the-provider.md +14 -4
- package/docs/index.md +2 -0
- package/docs/install.md +8 -1
- package/docs/reference/editors-date.md +2 -0
- package/docs/reference/editors-panel.md +4 -4
- package/docs/reference/editors-range.md +1 -1
- package/docs/reference/editors-relation.md +3 -3
- package/docs/reference/editors-select.md +1 -1
- package/docs/reference/editors-session.md +3 -2
- package/docs/reference/editors-value-list.md +1 -1
- package/docs/reference/field-row.md +2 -2
- package/docs/reference/grid.md +25 -6
- package/docs/reference/react.md +30 -8
- package/docs/reference/selection.md +10 -2
- package/docs/reference/views.md +42 -36
- package/package.json +22 -3
- package/skills/views/SKILL.md +3 -3
package/dist/model/view-rules.js
CHANGED
|
@@ -6,16 +6,25 @@ export function fieldKeyOf(col) {
|
|
|
6
6
|
return col.field?.key ?? col.id;
|
|
7
7
|
}
|
|
8
8
|
export function fromListFilterRule(fieldKey, type, rule, part) {
|
|
9
|
-
const
|
|
9
|
+
const read = wholeFromListFilterRule(fieldKey, type, rule);
|
|
10
|
+
const whole = read && VALUELESS.has(read.operator) ? { ...read, value: null } : read;
|
|
10
11
|
return whole && part !== undefined ? { ...whole, part } : whole;
|
|
11
12
|
}
|
|
13
|
+
const VALUELESS = new Set(["is_empty", "is_not_empty"]);
|
|
14
|
+
function numberEnds(value) {
|
|
15
|
+
return {
|
|
16
|
+
value: value[0] == null ? null : Number(value[0]),
|
|
17
|
+
value2: value[1] == null ? null : Number(value[1]),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
12
20
|
function wholeFromListFilterRule(fieldKey, type, rule) {
|
|
13
21
|
switch (rule.editor) {
|
|
14
22
|
case "text":
|
|
15
23
|
return { fieldKey, operator: rule.operator, value: rule.query };
|
|
16
24
|
case "number":
|
|
17
25
|
return rule.operator === "between"
|
|
18
|
-
?
|
|
26
|
+
?
|
|
27
|
+
{ fieldKey, operator: "between", value: [rule.value ?? null, rule.value2 ?? null] }
|
|
19
28
|
: { fieldKey, operator: rule.operator, value: rule.value };
|
|
20
29
|
case "date":
|
|
21
30
|
if (rule.operator === "is_relative")
|
|
@@ -59,12 +68,7 @@ export function toListFilterRule(type, rule, opts) {
|
|
|
59
68
|
case "percent":
|
|
60
69
|
case "currency":
|
|
61
70
|
if (Array.isArray(rule.value))
|
|
62
|
-
return {
|
|
63
|
-
editor: "number",
|
|
64
|
-
operator: "between",
|
|
65
|
-
value: Number(rule.value[0]),
|
|
66
|
-
value2: Number(rule.value[1]),
|
|
67
|
-
};
|
|
71
|
+
return { editor: "number", operator: "between", ...numberEnds(rule.value) };
|
|
68
72
|
return {
|
|
69
73
|
editor: "number",
|
|
70
74
|
operator: rule.operator,
|
|
@@ -129,6 +133,14 @@ function partListFilterRule(type, rule, part) {
|
|
|
129
133
|
const ops = operatorsFor(type, part);
|
|
130
134
|
if (!ops.includes(rule.operator))
|
|
131
135
|
return null;
|
|
136
|
+
if (type === "range")
|
|
137
|
+
return Array.isArray(rule.value)
|
|
138
|
+
? { editor: "number", operator: "between", ...numberEnds(rule.value) }
|
|
139
|
+
: {
|
|
140
|
+
editor: "number",
|
|
141
|
+
operator: rule.operator,
|
|
142
|
+
value: typeof rule.value === "number" ? rule.value : null,
|
|
143
|
+
};
|
|
132
144
|
if (ops[0] === "is_any_of")
|
|
133
145
|
return rule.operator === "is_any_of" && Array.isArray(rule.value)
|
|
134
146
|
? { editor: "options", values: [...rule.value] }
|
|
@@ -142,7 +154,7 @@ function partListFilterRule(type, rule, part) {
|
|
|
142
154
|
export function rootRulesByColumn(tree, columns, opts) {
|
|
143
155
|
const out = {};
|
|
144
156
|
for (const item of tree.items) {
|
|
145
|
-
if (isFilterGroup(item) || isRelationRule(item))
|
|
157
|
+
if (isFilterGroup(item) || isRelationRule(item) || item.setAside)
|
|
146
158
|
continue;
|
|
147
159
|
const col = columns.find((c) => fieldKeyOf(c) === item.fieldKey);
|
|
148
160
|
if (!col?.field)
|
|
@@ -153,31 +165,98 @@ export function rootRulesByColumn(tree, columns, opts) {
|
|
|
153
165
|
}
|
|
154
166
|
return out;
|
|
155
167
|
}
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
let next = tree;
|
|
168
|
+
function columnRows(columns, opts) {
|
|
169
|
+
const rows = [];
|
|
159
170
|
for (const col of columns) {
|
|
160
171
|
if (!col.field)
|
|
161
172
|
continue;
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
const type = valueTypeOf(col.field);
|
|
174
|
+
const fieldKey = fieldKeyOf(col);
|
|
175
|
+
rows.push({ key: col.id, fieldKey, type });
|
|
176
|
+
if (opts?.parts)
|
|
177
|
+
for (const part of FILTER_PART_ROWS[type] ?? [])
|
|
178
|
+
rows.push({ key: partKey(col.id, part), fieldKey, type, part });
|
|
179
|
+
}
|
|
180
|
+
return rows;
|
|
181
|
+
}
|
|
182
|
+
const quickRows = (fields) => fields.map((f) => ({ key: f.key, fieldKey: f.key, type: f.type }));
|
|
183
|
+
function sameValue(a, b) {
|
|
184
|
+
if (a === b)
|
|
185
|
+
return true;
|
|
186
|
+
if (Array.isArray(a) || Array.isArray(b))
|
|
187
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((x, i) => sameValue(x, b[i]));
|
|
188
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
189
|
+
const keys = Object.keys(a);
|
|
190
|
+
return (keys.length === Object.keys(b).length &&
|
|
191
|
+
keys.every((k) => sameValue(a[k], b[k])));
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
function sameRule(a, b) {
|
|
196
|
+
if (a.fieldKey !== b.fieldKey || a.part !== b.part || a.operator !== b.operator)
|
|
197
|
+
return false;
|
|
198
|
+
return VALUELESS.has(a.operator) || sameValue(a.value, b.value);
|
|
199
|
+
}
|
|
200
|
+
function readRows(tree, rows) {
|
|
201
|
+
const rules = {};
|
|
202
|
+
const rest = [];
|
|
203
|
+
for (const item of tree.items) {
|
|
204
|
+
if (isFilterGroup(item) || isRelationRule(item) || item.setAside) {
|
|
205
|
+
rest.push(item);
|
|
206
|
+
continue;
|
|
168
207
|
}
|
|
208
|
+
const row = rows.find((r) => !(r.key in rules) && r.fieldKey === item.fieldKey && r.part === item.part);
|
|
209
|
+
const rule = row ? toListFilterRule(row.type, item, { parts: true }) : null;
|
|
210
|
+
const back = row && rule ? fromListFilterRule(row.fieldKey, row.type, rule, row.part) : null;
|
|
211
|
+
if (row && rule && back && sameRule(back, item))
|
|
212
|
+
rules[row.key] = rule;
|
|
213
|
+
else
|
|
214
|
+
rest.push(item);
|
|
215
|
+
}
|
|
216
|
+
return { rules, rest };
|
|
217
|
+
}
|
|
218
|
+
function writeRows(op, rows, rules, rest) {
|
|
219
|
+
const items = [];
|
|
220
|
+
for (const row of rows) {
|
|
221
|
+
const rule = rules[row.key];
|
|
222
|
+
const next = rule ? fromListFilterRule(row.fieldKey, row.type, rule, row.part) : null;
|
|
223
|
+
if (next)
|
|
224
|
+
items.push(next);
|
|
225
|
+
}
|
|
226
|
+
return { op, items: [...items, ...rest] };
|
|
227
|
+
}
|
|
228
|
+
export function filterPanelFromTree(tree, columns, opts) {
|
|
229
|
+
return { op: tree.op, ...readRows(tree, columnRows(columns, opts)) };
|
|
230
|
+
}
|
|
231
|
+
export function treeFromFilterPanel(panel, columns, opts) {
|
|
232
|
+
return writeRows(panel.op, columnRows(columns, opts), panel.rules, panel.rest);
|
|
233
|
+
}
|
|
234
|
+
export function quickValuesFromTree(tree, fields) {
|
|
235
|
+
const out = {};
|
|
236
|
+
for (const [key, rule] of Object.entries(readRows(tree, quickRows(fields)).rules))
|
|
237
|
+
if (rule.editor === "options")
|
|
238
|
+
out[key] = rule.values;
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
export function withQuickValues(tree, fields, values) {
|
|
242
|
+
const rows = quickRows(fields);
|
|
243
|
+
const rules = {};
|
|
244
|
+
for (const f of fields) {
|
|
245
|
+
const picked = values[f.key];
|
|
246
|
+
if (picked?.length)
|
|
247
|
+
rules[f.key] = { editor: "options", values: [...picked] };
|
|
169
248
|
}
|
|
170
|
-
return
|
|
249
|
+
return writeRows(tree.op, rows, rules, readRows(tree, rows).rest);
|
|
171
250
|
}
|
|
172
251
|
export function rootRelationRules(tree) {
|
|
173
252
|
const out = {};
|
|
174
253
|
for (const item of tree.items)
|
|
175
|
-
if (isRelationRule(item))
|
|
254
|
+
if (isRelationRule(item) && !item.setAside)
|
|
176
255
|
out[item.fieldKey] = item;
|
|
177
256
|
return out;
|
|
178
257
|
}
|
|
179
258
|
export function withRootRelationRules(tree, rules) {
|
|
180
|
-
const kept = tree.items.filter((item) => !isRelationRule(item));
|
|
259
|
+
const kept = tree.items.filter((item) => !isRelationRule(item) || item.setAside);
|
|
181
260
|
return { op: tree.op, items: [...kept, ...Object.values(rules)] };
|
|
182
261
|
}
|
|
183
262
|
export function withRootRule(tree, col, rule, part) {
|
|
@@ -185,6 +264,7 @@ export function withRootRule(tree, col, rule, part) {
|
|
|
185
264
|
const type = col.field ? valueTypeOf(col.field) : undefined;
|
|
186
265
|
const kept = tree.items.filter((item) => isFilterGroup(item) ||
|
|
187
266
|
isRelationRule(item) ||
|
|
267
|
+
item.setAside ||
|
|
188
268
|
item.fieldKey !== key ||
|
|
189
269
|
item.part !== part ||
|
|
190
270
|
(part !== undefined && (!type || !toListFilterRule(type, item, { parts: true }))));
|
|
@@ -3,8 +3,9 @@ import type { FieldConventions } from "@viewkitjs/fields";
|
|
|
3
3
|
import { type ViewsMessageResolver } from "../contract.js";
|
|
4
4
|
import type { ViewsAtoms } from "../atoms/types.js";
|
|
5
5
|
import type { FieldPresentation } from "../display/options.js";
|
|
6
|
-
import type { ViewsComponents } from "./components.js";
|
|
6
|
+
import type { ViewsComponents, ViewsMenuRoute, ViewsSelectionBarSettings, ViewsSheetActionsPlace } from "./components.js";
|
|
7
7
|
import type { ViewsIcons } from "./icons.js";
|
|
8
|
+
import type { ViewsEscapeRules } from "../editors/escape-rule.js";
|
|
8
9
|
import { type ViewsPorts } from "./ports.js";
|
|
9
10
|
export { useViews, type ViewsContextValue } from "./context.js";
|
|
10
11
|
export type ViewsProviderProps = {
|
|
@@ -25,6 +26,25 @@ export type ViewsProviderProps = {
|
|
|
25
26
|
* elsewhere. Hand in the one your own shell switches on. Default `DEFAULT_DESKTOP_QUERY`,
|
|
26
27
|
* `(min-width: 1024px)`. */
|
|
27
28
|
desktopQuery?: string;
|
|
29
|
+
/** Where the editor panel's ✕ and ✓ stand on a phone. `bar` (the default): the panel draws its own
|
|
30
|
+
* bar inside your `Sheet`. `head`: your `Sheet` is handed them as `actions`, for its own head, and
|
|
31
|
+
* the panel draws no bar. */
|
|
32
|
+
sheetActions?: ViewsSheetActionsPlace;
|
|
33
|
+
/** What Escape does in an editor of each field type: `keep` keeps what was typed and closes, as a press
|
|
34
|
+
* outside does; a type left out throws the edit away. Desktop only: on a phone every way out of the
|
|
35
|
+
* sheet throws it away. Pass a module-level object. */
|
|
36
|
+
escape?: ViewsEscapeRules;
|
|
37
|
+
/** The grid says, through the toast port's `error`, why your app refused an edit it sent. Default false:
|
|
38
|
+
* your app says it. */
|
|
39
|
+
sayRefusals?: boolean;
|
|
40
|
+
/** How the grid opens its own menus. `popover` (the default): ViewKit's rows in your `Popover`. `menu`:
|
|
41
|
+
* your `Menu`, handed its rows as data, with the three hints a row may carry (`beside`, `keepOpen`,
|
|
42
|
+
* `detail`). */
|
|
43
|
+
menus?: ViewsMenuRoute;
|
|
44
|
+
/** Where the selection bar sits: its bottom, its layer and its classes on the desktop and on the phone,
|
|
45
|
+
* and the media query that makes it the phone's pill. Pass a module-level object. Default: 1rem above
|
|
46
|
+
* the screen's foot, layer 50, the pill wherever `desktopQuery` does not match. */
|
|
47
|
+
selectionBar?: ViewsSelectionBarSettings;
|
|
28
48
|
children: ReactNode;
|
|
29
49
|
};
|
|
30
|
-
export declare function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages, presentation, desktopQuery, }: ViewsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
export declare function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages, presentation, desktopQuery, sheetActions, escape, sayRefusals, menus, selectionBar, }: ViewsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,18 +5,37 @@ import { resolveViewsMessage } from "../contract.js";
|
|
|
5
5
|
import { DEFAULT_VIEWS_ATOMS } from "../atoms/defaults.js";
|
|
6
6
|
import { ViewsContext } from "./context.js";
|
|
7
7
|
import { PlainInput } from "./plain-input.js";
|
|
8
|
+
import { missingComponent, missingParts } from "./missing-slot.js";
|
|
8
9
|
import { withSettledGroups } from "./menu-groups.js";
|
|
9
10
|
import { DEFAULT_DESKTOP_QUERY } from "./desktop.js";
|
|
10
11
|
import { browserConfirm } from "./ports.js";
|
|
11
12
|
export { useViews } from "./context.js";
|
|
12
|
-
|
|
13
|
+
const MISSING_COMMAND_PARTS = missingParts("Command");
|
|
14
|
+
const MISSING_CALENDAR_COMPONENT = missingComponent("Calendar");
|
|
15
|
+
export function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages = resolveViewsMessage, presentation, desktopQuery = DEFAULT_DESKTOP_QUERY, sheetActions = "bar", escape, sayRefusals = false, menus = "popover", selectionBar, }) {
|
|
13
16
|
const merged = useMemo(() => ({ ...DEFAULT_VIEWS_ATOMS, ...atoms }), [atoms]);
|
|
14
17
|
const settled = useMemo(() => ({
|
|
15
18
|
...components,
|
|
16
19
|
Menu: withSettledGroups(components.Menu),
|
|
17
20
|
Input: components.Input ?? PlainInput,
|
|
21
|
+
Command: components.Command ?? MISSING_COMMAND_PARTS,
|
|
22
|
+
Calendar: components.Calendar ?? MISSING_CALENDAR_COMPONENT,
|
|
18
23
|
}), [components]);
|
|
19
24
|
const resolved = useMemo(() => (ports.confirm ? ports : { ...ports, confirm: browserConfirm }), [ports]);
|
|
20
|
-
const value = useMemo(() => ({
|
|
25
|
+
const value = useMemo(() => ({
|
|
26
|
+
components: settled,
|
|
27
|
+
atoms: merged,
|
|
28
|
+
conventions,
|
|
29
|
+
icons,
|
|
30
|
+
ports: resolved,
|
|
31
|
+
messages,
|
|
32
|
+
presentation,
|
|
33
|
+
desktopQuery,
|
|
34
|
+
sheetActions,
|
|
35
|
+
escape,
|
|
36
|
+
sayRefusals,
|
|
37
|
+
menus,
|
|
38
|
+
selectionBar,
|
|
39
|
+
}), [settled, merged, conventions, icons, resolved, messages, presentation, desktopQuery, sheetActions, escape, sayRefusals, menus, selectionBar]);
|
|
21
40
|
return _jsx(ViewsContext.Provider, { value: value, children: children });
|
|
22
41
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ComponentPropsWithRef, ComponentType, CSSProperties, KeyboardEvent as ReactKeyboardEvent, MouseEvent as ReactMouseEvent, ReactElement, ReactNode, Ref, RefObject } from "react";
|
|
2
|
+
import type { CategoryColor } from "@viewkitjs/fields/design/category-colors";
|
|
3
|
+
import type { StatusSlot } from "@viewkitjs/fields/design/status-slots";
|
|
2
4
|
/** Where a floating part attaches: an element, a ref to one, or a point (a context menu). */
|
|
3
5
|
export type ViewsAnchor = HTMLElement | RefObject<HTMLElement | null> | {
|
|
4
6
|
x: number;
|
|
@@ -87,25 +89,42 @@ export type ViewsCheckboxProps = {
|
|
|
87
89
|
/** A menu is data: the app draws it with its own primitive. */
|
|
88
90
|
export type ViewsMenuItem = {
|
|
89
91
|
key: string;
|
|
90
|
-
|
|
92
|
+
/** The row's words: always text, so a menu that writes its rows' names takes it as it is. */
|
|
93
|
+
label: string;
|
|
91
94
|
icon?: ReactNode;
|
|
92
95
|
onSelect?: () => void;
|
|
93
96
|
disabled?: boolean;
|
|
97
|
+
/** Why a disabled row can't be used, in words: the app shows it (a tooltip, a second line). A row
|
|
98
|
+
* under a disabled group that gives none carries the group's. */
|
|
99
|
+
disabledReason?: string;
|
|
94
100
|
destructive?: boolean;
|
|
95
|
-
/** A checkable row: the app draws its tick. A checkable row closes the menu like any row
|
|
101
|
+
/** A checkable row: the app draws its tick. A checkable row closes the menu like any row, unless it
|
|
102
|
+
* asks to `keepOpen`. */
|
|
96
103
|
checked?: boolean;
|
|
97
|
-
/** A group: its rows drawn in place under this row's label,
|
|
98
|
-
* label, not a target: its own `onSelect`, `href` and `checked` are ignored. A disabled group
|
|
104
|
+
/** A group: its rows drawn in place under this row's label, unless it asks to open `beside`. A group
|
|
105
|
+
* row is a label, not a target: its own `onSelect`, `href` and `checked` are ignored. A disabled group
|
|
99
106
|
* disables every row under it: the provider hands the app's `Menu` those rows already `disabled`. */
|
|
100
107
|
children?: ViewsMenuItem[];
|
|
108
|
+
/** A group (`children`) that opens its rows beside the menu, one level in, rather than in place: its row
|
|
109
|
+
* shows its label and `detail` and opens on a hover, a press or →. A hint: an adapter with no flyouts
|
|
110
|
+
* draws the group in place under its label, as every group is drawn. Ignored on a row with no `children`. */
|
|
111
|
+
beside?: boolean;
|
|
112
|
+
/** A checkable row (`checked` set) that leaves the menu open when picked, so several can be ticked in
|
|
113
|
+
* turn. A hint: an adapter that ignores it closes the menu, as any row does. Ignored on a row that isn't
|
|
114
|
+
* checkable. */
|
|
115
|
+
keepOpen?: boolean;
|
|
116
|
+
/** The row's current value in words, drawn at its end ("2", "Short"): on a group that opens beside, the
|
|
117
|
+
* choice made in it. Optional for an adapter to draw: one that ignores it draws the label alone, and a
|
|
118
|
+
* group's choice still shows by its ticked row. */
|
|
119
|
+
detail?: string;
|
|
101
120
|
separatorBefore?: boolean;
|
|
102
121
|
/** A keyboard hint drawn at the row's end, never bound by the menu. */
|
|
103
122
|
shortcut?: string;
|
|
104
123
|
/** A link item: the row is an anchor and `onSelect` still fires. */
|
|
105
124
|
href?: string;
|
|
106
125
|
};
|
|
107
|
-
/** Opens at `anchor`, with no trigger child
|
|
108
|
-
* positioner and popup, the anchor handed to the positioner. */
|
|
126
|
+
/** Opens at `anchor`, with no trigger child; a group opens beside it only where it asks to and the
|
|
127
|
+
* adapter can. On Base UI, the menu's root, positioner and popup, the anchor handed to the positioner. */
|
|
109
128
|
export type ViewsMenuProps = {
|
|
110
129
|
open: boolean;
|
|
111
130
|
onOpenChange: ViewsOpenChange;
|
|
@@ -113,6 +132,9 @@ export type ViewsMenuProps = {
|
|
|
113
132
|
items: ViewsMenuItem[];
|
|
114
133
|
side?: ViewsSide;
|
|
115
134
|
align?: ViewsAlign;
|
|
135
|
+
/** The menu's name, which a screen reader announces as it opens: the menu's `aria-label`. Every
|
|
136
|
+
* menu the package opens hands one. */
|
|
137
|
+
label?: string;
|
|
116
138
|
className?: string;
|
|
117
139
|
};
|
|
118
140
|
/** The command list's parts, the shape both cmdk-based shadcn copies already have. */
|
|
@@ -169,6 +191,87 @@ export type ViewsCommandParts = {
|
|
|
169
191
|
className?: string;
|
|
170
192
|
}>;
|
|
171
193
|
};
|
|
194
|
+
/** One row of an app's picker body, as data: the value it stands for, its words, and how they are dressed. */
|
|
195
|
+
export type ViewsPickerItem = {
|
|
196
|
+
value: string;
|
|
197
|
+
label: string;
|
|
198
|
+
/** A status's step: draw your status badge in this slot. */
|
|
199
|
+
slot?: StatusSlot;
|
|
200
|
+
/** A category's colour: draw your option chip or tag in it. */
|
|
201
|
+
color?: CategoryColor;
|
|
202
|
+
/** Your own glyph's name, as `AppIcon` draws it, before the words. */
|
|
203
|
+
icon?: string;
|
|
204
|
+
/** A quieter second line. */
|
|
205
|
+
line?: string;
|
|
206
|
+
/** The heading it stands under. */
|
|
207
|
+
group?: string;
|
|
208
|
+
disabled?: boolean;
|
|
209
|
+
/** A word at the row's end telling kinds apart in a list of several ("Person"). */
|
|
210
|
+
badge?: string;
|
|
211
|
+
/** The record's own glyph, drawn before its words, unsized; wins over `icon`. */
|
|
212
|
+
glyph?: ReactNode;
|
|
213
|
+
/** The record's picture, for an avatar. */
|
|
214
|
+
avatarUrl?: string | null;
|
|
215
|
+
/** The record's kind, as the app names it (for the avatar's shape): not the `badge` word. */
|
|
216
|
+
kind?: string;
|
|
217
|
+
};
|
|
218
|
+
/** A row that does something rather than pick (create a record with what was typed): picking it closes the
|
|
219
|
+
* editor, then runs it. */
|
|
220
|
+
export type ViewsPickerAction = {
|
|
221
|
+
key: string;
|
|
222
|
+
label: string;
|
|
223
|
+
icon?: ReactNode;
|
|
224
|
+
onSelect: () => void;
|
|
225
|
+
};
|
|
226
|
+
/** A whole pick list your app draws: its search, its rows, its empty row and its create row. The editor
|
|
227
|
+
* around it keeps the draft, Tab, Escape, the save and the phone's ✕ and ✓. */
|
|
228
|
+
export type ViewsPickerProps = {
|
|
229
|
+
/** The field's name: the list's accessible name. */
|
|
230
|
+
label: string;
|
|
231
|
+
items: ViewsPickerItem[];
|
|
232
|
+
/** Several values may be held. Default false. */
|
|
233
|
+
multiple?: boolean;
|
|
234
|
+
/** What is held: one value, or null when none; several, a list. */
|
|
235
|
+
value: string | string[] | null;
|
|
236
|
+
/** One: the pick, null for the empty row. Several: the whole new list, on every change. Nothing is
|
|
237
|
+
* saved until the editor closes. */
|
|
238
|
+
onValueChange: (value: string | string[] | null) => void;
|
|
239
|
+
/** A pick of one is made: the editor closes and saves it. */
|
|
240
|
+
onDone: () => void;
|
|
241
|
+
/** The empty row's words; absent, a value of one can't be emptied. */
|
|
242
|
+
empty?: string;
|
|
243
|
+
/** The search's words before anything is typed. */
|
|
244
|
+
search?: string;
|
|
245
|
+
/** Takes new values: handed what was typed, it returns the value made, which you then pick (one) or
|
|
246
|
+
* add (several). Absent, nothing typed is added. */
|
|
247
|
+
onCreate?: (typed: string) => string;
|
|
248
|
+
/** What was typed on what opened it: the list opens filtered by it, the search holding it. */
|
|
249
|
+
typed?: string;
|
|
250
|
+
/** Put the focus inside as it opens, without scrolling the page. */
|
|
251
|
+
autoFocus?: boolean;
|
|
252
|
+
/** `phone`: draw no ✕, ✓ or Cancel of your own (the editor's panel holds them), and hand every change
|
|
253
|
+
* through `onValueChange` as it is made. */
|
|
254
|
+
form: "computer" | "phone";
|
|
255
|
+
/** The editor filters or fetches: hand it every typed query, and draw `items` as they come, in order, never
|
|
256
|
+
* filtered again. */
|
|
257
|
+
onSearch?: (query: string) => void;
|
|
258
|
+
/** What the list is doing besides showing its rows: a first page in flight, or the last ask failed. */
|
|
259
|
+
doing?: "searching" | "failed";
|
|
260
|
+
/** Ask again after `doing: "failed"`. */
|
|
261
|
+
onRetry?: () => void;
|
|
262
|
+
/** More rows are to come: call it each time the list's end comes into view. */
|
|
263
|
+
onMore?: () => void;
|
|
264
|
+
/** Rows that do something rather than pick, drawn after the rows. */
|
|
265
|
+
actions?: ViewsPickerAction[];
|
|
266
|
+
/** Several held, one of them leading: which, a way to make another lead, and the words for both. A body
|
|
267
|
+
* that draws none of it leaves the first held value leading. */
|
|
268
|
+
lead?: {
|
|
269
|
+
value: string | null;
|
|
270
|
+
onLead: (value: string) => void;
|
|
271
|
+
label: string;
|
|
272
|
+
makeLabel: string;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
172
275
|
/** A calendar over ISO days (`YYYY-MM-DD`) and months (`YYYY-MM`); the app's date library stays its own. */
|
|
173
276
|
export type ViewsCalendarProps = {
|
|
174
277
|
value: string | null;
|
|
@@ -188,6 +291,37 @@ export type ViewsCalendarProps = {
|
|
|
188
291
|
locale: string;
|
|
189
292
|
className?: string;
|
|
190
293
|
};
|
|
294
|
+
/** A quick pick a date body offers: a day the editor names, or `none`, which empties the field. */
|
|
295
|
+
export type ViewsDatePick = "today" | "tomorrow" | "next-monday" | "none";
|
|
296
|
+
/** A whole date body your app draws: its typed line, its days, its quick picks and its time. The editor
|
|
297
|
+
* around it keeps the draft, Tab, Escape, the save and the phone's ✕ and ✓. */
|
|
298
|
+
export type ViewsDateBodyProps = {
|
|
299
|
+
/** The field's name: the days' accessible name. */
|
|
300
|
+
label: string;
|
|
301
|
+
/** What is held, on the local calendar: a day ("2026-11-12"), a day and time ("2026-11-12T14:30"), or null. */
|
|
302
|
+
value: string | null;
|
|
303
|
+
/** Every change as it is made, in `value`'s shape: a day picked, a day typed once it reads as one, a time
|
|
304
|
+
* set, or null for the empty pick. Nothing is saved until the editor closes. */
|
|
305
|
+
onValueChange: (value: string | null) => void;
|
|
306
|
+
/** A pick that finishes the edit is made (a day on a field with no time, the empty pick): the editor
|
|
307
|
+
* closes and saves it. */
|
|
308
|
+
onDone: () => void;
|
|
309
|
+
/** It holds a time too. */
|
|
310
|
+
time: boolean;
|
|
311
|
+
/** It may be emptied: offer the `none` pick. */
|
|
312
|
+
empty: boolean;
|
|
313
|
+
/** The quick picks, in order: `next-monday` is the Monday after today (a week on when today is one). */
|
|
314
|
+
picks: ViewsDatePick[];
|
|
315
|
+
/** Today, on the local calendar ("YYYY-MM-DD"). */
|
|
316
|
+
today: string;
|
|
317
|
+
/** What was typed on what opened it: the line starts with it. */
|
|
318
|
+
typed?: string;
|
|
319
|
+
/** Put the focus inside as it opens, without scrolling the page. */
|
|
320
|
+
autoFocus: boolean;
|
|
321
|
+
/** `phone`: draw no ✕, ✓ or Cancel of your own (the editor's panel holds them), and hand every change
|
|
322
|
+
* through `onValueChange` as it is made. */
|
|
323
|
+
form: "computer" | "phone";
|
|
324
|
+
};
|
|
191
325
|
export type ViewsCollapseProps = {
|
|
192
326
|
open: boolean;
|
|
193
327
|
children: ReactNode;
|
|
@@ -196,12 +330,53 @@ export type ViewsCollapseProps = {
|
|
|
196
330
|
clipClassName?: string;
|
|
197
331
|
durationMs?: number;
|
|
198
332
|
};
|
|
333
|
+
/** One of the editor panel's buttons, handed to a Sheet that draws them in its own head: its
|
|
334
|
+
* accessible name and what a press does. The glyph is the app's (✕, ✓). */
|
|
335
|
+
export type ViewsSheetAction = {
|
|
336
|
+
label: string;
|
|
337
|
+
onPress: () => void;
|
|
338
|
+
};
|
|
339
|
+
/** The editor panel's ✕ and ✓. `close` throws the edit away, as a swipe does; `done` closes it as
|
|
340
|
+
* done, and is absent where the body saves on its pick (a pick of one), which needs no ✓. */
|
|
341
|
+
export type ViewsSheetActions = {
|
|
342
|
+
close: ViewsSheetAction;
|
|
343
|
+
done?: ViewsSheetAction;
|
|
344
|
+
};
|
|
345
|
+
/** Where the editor panel's ✕ and ✓ stand on a phone: `bar`, the panel's own bar inside the Sheet;
|
|
346
|
+
* `head`, handed to the Sheet as `actions` for its own head, with no bar. */
|
|
347
|
+
export type ViewsSheetActionsPlace = "bar" | "head";
|
|
348
|
+
/** How the grid opens its own menus (a column's, a footer's figure picker, a group's ⋯, Add column):
|
|
349
|
+
* `popover`, ViewKit's rows in your `Popover`; `menu`, your `Menu`, handed rows as data. The row menu and
|
|
350
|
+
* a command cell's menu always go through your `Menu`. */
|
|
351
|
+
export type ViewsMenuRoute = "popover" | "menu";
|
|
352
|
+
/** Where the selection bar's fixed box sits on one form. `bottom` is a CSS length (default
|
|
353
|
+
* `calc(1rem + env(safe-area-inset-bottom))`), `zIndex` its layer (default 50), and `className` the app's
|
|
354
|
+
* own classes on the box (a hook its CSS reads, a rule that hides the bar). */
|
|
355
|
+
export type ViewsBarPlacement = {
|
|
356
|
+
bottom?: string;
|
|
357
|
+
zIndex?: number;
|
|
358
|
+
className?: string;
|
|
359
|
+
};
|
|
360
|
+
/** The selection bar, as the app places it: on the desktop an island, on the phone a pill whose Actions
|
|
361
|
+
* open a sheet. `phoneQuery`, when handed, is the media query under which the bar is the phone's pill;
|
|
362
|
+
* without it the bar is the pill wherever the provider's `desktopQuery` does not match. */
|
|
363
|
+
export type ViewsSelectionBarSettings = {
|
|
364
|
+
phoneQuery?: string;
|
|
365
|
+
desktop?: ViewsBarPlacement;
|
|
366
|
+
phone?: ViewsBarPlacement;
|
|
367
|
+
};
|
|
199
368
|
/** A phone sheet. `snap` is a hint: an app whose sheet has no snap points ignores it. */
|
|
200
369
|
export type ViewsSheetProps = {
|
|
201
370
|
open: boolean;
|
|
202
371
|
onOpenChange: ViewsOpenChange;
|
|
203
372
|
title?: ReactNode;
|
|
373
|
+
/** The title in words, whenever the title is words: the sheet's accessible name, and the title of
|
|
374
|
+
* a head that takes only text. Absent for a title that is something else (a header with a glyph). */
|
|
375
|
+
label?: string;
|
|
204
376
|
description?: string;
|
|
377
|
+
/** The editor panel's ✕ and ✓, handed only when the provider's `sheetActions` is `head`: draw both
|
|
378
|
+
* in the sheet's head (no `done`, no ✓). With `bar`, the default, the panel draws them itself. */
|
|
379
|
+
actions?: ViewsSheetActions;
|
|
205
380
|
snap?: "full" | "half" | "peek" | "auto";
|
|
206
381
|
className?: string;
|
|
207
382
|
children: ReactNode;
|
|
@@ -219,8 +394,12 @@ export type ViewsComponents = {
|
|
|
219
394
|
Tooltip: ComponentType<ViewsTooltipProps>;
|
|
220
395
|
Checkbox: ComponentType<ViewsCheckboxProps>;
|
|
221
396
|
Menu: ComponentType<ViewsMenuProps>;
|
|
222
|
-
|
|
223
|
-
|
|
397
|
+
/** Optional: the editors' lists and the popover route's menus draw through it. An app that hands `Picker`
|
|
398
|
+
* and sets `menus: "menu"` needs none. Reached without one, it throws an error naming it. */
|
|
399
|
+
Command?: ViewsCommandParts;
|
|
400
|
+
/** Optional: the date editor draws its month through it. Handed `DateBody`, it is never reached.
|
|
401
|
+
* Reached without one, it throws an error naming it. */
|
|
402
|
+
Calendar?: ComponentType<ViewsCalendarProps>;
|
|
224
403
|
Collapse: ComponentType<ViewsCollapseProps>;
|
|
225
404
|
Sheet: ComponentType<ViewsSheetProps>;
|
|
226
405
|
/** The app's own icon component by the app's own names, for glyphs a host
|
|
@@ -241,8 +420,17 @@ export type ViewsComponents = {
|
|
|
241
420
|
/** Optional: every editor's single-line box draws through it. Left out, the provider draws a
|
|
242
421
|
* plain `<input>`. */
|
|
243
422
|
Input?: ComponentType<ViewsInputProps>;
|
|
423
|
+
/** Optional: a whole pick list your app draws. Handed one, the select, several-values, place and relation
|
|
424
|
+
* editors open it, handed their rows as data; left out, they draw from `Command`. */
|
|
425
|
+
Picker?: ComponentType<ViewsPickerProps>;
|
|
426
|
+
/** Optional: a whole date body your app draws. Handed one, the date editor opens it; left out, it draws
|
|
427
|
+
* its own line, quick days and time around `Calendar`. */
|
|
428
|
+
DateBody?: ComponentType<ViewsDateBodyProps>;
|
|
244
429
|
};
|
|
245
|
-
/** The map as the views read it:
|
|
430
|
+
/** The map as the views read it: `Input`, `Command` and `Calendar` always filled, the app's or the
|
|
431
|
+
* package's own; `Picker` and `DateBody` as the app handed them. */
|
|
246
432
|
export type ViewsResolvedComponents = ViewsComponents & {
|
|
247
433
|
Input: ComponentType<ViewsInputProps>;
|
|
434
|
+
Command: ViewsCommandParts;
|
|
435
|
+
Calendar: ComponentType<ViewsCalendarProps>;
|
|
248
436
|
};
|
|
@@ -2,9 +2,10 @@ import type { FieldConventions } from "@viewkitjs/fields";
|
|
|
2
2
|
import type { ViewsMessageResolver } from "../contract.js";
|
|
3
3
|
import type { ViewsAtoms } from "../atoms/types.js";
|
|
4
4
|
import type { FieldPresentation } from "../display/options.js";
|
|
5
|
-
import type { ViewsResolvedComponents } from "./components.js";
|
|
5
|
+
import type { ViewsMenuRoute, ViewsResolvedComponents, ViewsSelectionBarSettings, ViewsSheetActionsPlace } from "./components.js";
|
|
6
6
|
import type { ViewsIcons } from "./icons.js";
|
|
7
7
|
import type { ViewsResolvedPorts } from "./ports.js";
|
|
8
|
+
import type { ViewsEscapeRules } from "../editors/escape-rule.js";
|
|
8
9
|
export type ViewsContextValue = {
|
|
9
10
|
/** The app's components, with the optional ones filled: the app's own, or the package's plain default. */
|
|
10
11
|
components: ViewsResolvedComponents;
|
|
@@ -18,6 +19,16 @@ export type ViewsContextValue = {
|
|
|
18
19
|
presentation?: (defaults: FieldPresentation) => FieldPresentation;
|
|
19
20
|
/** The media query that means a desktop: the app's own, or `DEFAULT_DESKTOP_QUERY`. */
|
|
20
21
|
desktopQuery: string;
|
|
22
|
+
/** Where the editor panel's ✕ and ✓ stand on a phone. Absent means `bar`. */
|
|
23
|
+
sheetActions?: ViewsSheetActionsPlace;
|
|
24
|
+
/** What Escape does per field type (`ViewsProvider`'s `escape`); absent, every type throws the edit away. */
|
|
25
|
+
escape?: ViewsEscapeRules;
|
|
26
|
+
/** The grid says why the app refused an edit it sent (`ViewsProvider`'s `sayRefusals`); absent, it says nothing. */
|
|
27
|
+
sayRefusals?: boolean;
|
|
28
|
+
/** How the grid opens its own menus (`ViewsProvider`'s `menus`). Absent means `popover`. */
|
|
29
|
+
menus?: ViewsMenuRoute;
|
|
30
|
+
/** Where the selection bar sits (`ViewsProvider`'s `selectionBar`); absent, the package's defaults. */
|
|
31
|
+
selectionBar?: ViewsSelectionBarSettings;
|
|
21
32
|
};
|
|
22
33
|
export declare const ViewsContext: import("react").Context<ViewsContextValue | null>;
|
|
23
34
|
export declare function useViews(): ViewsContextValue;
|
|
@@ -7,3 +7,6 @@ export declare function isDesktopNow(query: string): boolean;
|
|
|
7
7
|
/** Whether the screen is a desktop, by the provider's `desktopQuery`: true where there is no
|
|
8
8
|
* `matchMedia`. It follows the query's changes. The package's own: no entry point exports it. */
|
|
9
9
|
export declare function useDesktop(): boolean;
|
|
10
|
+
/** Whether `query` matches the screen, following its changes. `fallback` is the answer where the screen
|
|
11
|
+
* can't be asked (a server render, no `matchMedia`). The package's own: no entry point exports it. */
|
|
12
|
+
export declare function useMediaQuery(query: string, fallback: boolean): boolean;
|
package/dist/provider/desktop.js
CHANGED
|
@@ -10,13 +10,16 @@ export function isDesktopNow(query) {
|
|
|
10
10
|
}
|
|
11
11
|
export function useDesktop() {
|
|
12
12
|
const { desktopQuery } = useViews();
|
|
13
|
+
return useMediaQuery(desktopQuery, true);
|
|
14
|
+
}
|
|
15
|
+
export function useMediaQuery(query, fallback) {
|
|
13
16
|
const subscribe = useCallback((onChange) => {
|
|
14
17
|
if (!canAsk())
|
|
15
18
|
return () => { };
|
|
16
|
-
const list = window.matchMedia(
|
|
19
|
+
const list = window.matchMedia(query);
|
|
17
20
|
list.addEventListener("change", onChange);
|
|
18
21
|
return () => list.removeEventListener("change", onChange);
|
|
19
|
-
}, [
|
|
20
|
-
const read = () =>
|
|
21
|
-
return useSyncExternalStore(subscribe, read, () =>
|
|
22
|
+
}, [query]);
|
|
23
|
+
const read = () => (canAsk() ? window.matchMedia(query).matches : fallback);
|
|
24
|
+
return useSyncExternalStore(subscribe, read, () => fallback);
|
|
22
25
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ComponentType } from "react";
|
|
2
2
|
import type { ViewsMenuItem, ViewsMenuProps } from "./components.js";
|
|
3
|
-
/** The items with every row under a disabled group marked `disabled`, at every depth
|
|
4
|
-
* path to a disabled group is copied; with none, the
|
|
3
|
+
/** The items with every row under a disabled group marked `disabled`, at every depth, each row that
|
|
4
|
+
* gives no reason carrying the group's. Only the path to a disabled group is copied; with none, the
|
|
5
|
+
* same array comes back. */
|
|
5
6
|
export declare function settleMenuGroups(items: ViewsMenuItem[]): ViewsMenuItem[];
|
|
6
7
|
/** The app's Menu, handed its items settled. One wrapper per app Menu, so an open menu never
|
|
7
8
|
* remounts; a wrapper handed in again (a nested provider) comes back as it is. */
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { createElement, useMemo } from "react";
|
|
2
|
-
function disableAll(items) {
|
|
3
|
-
return items.map((item) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
function disableAll(items, reason) {
|
|
3
|
+
return items.map((item) => {
|
|
4
|
+
const own = item.disabledReason ?? reason;
|
|
5
|
+
return {
|
|
6
|
+
...item,
|
|
7
|
+
disabled: true,
|
|
8
|
+
...(own !== undefined && { disabledReason: own }),
|
|
9
|
+
...(item.children && { children: disableAll(item.children, own) }),
|
|
10
|
+
};
|
|
11
|
+
});
|
|
8
12
|
}
|
|
9
13
|
export function settleMenuGroups(items) {
|
|
10
14
|
let changed = false;
|
|
11
15
|
const settled = items.map((item) => {
|
|
12
16
|
if (!item.children || item.children.length === 0)
|
|
13
17
|
return item;
|
|
14
|
-
const children = item.disabled
|
|
18
|
+
const children = item.disabled
|
|
19
|
+
? disableAll(item.children, item.disabledReason)
|
|
20
|
+
: settleMenuGroups(item.children);
|
|
15
21
|
if (children === item.children)
|
|
16
22
|
return item;
|
|
17
23
|
changed = true;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { ViewsCalendarProps, ViewsCommandParts } from "./components.js";
|
|
3
|
+
/** What a list says when it reaches the components map's `Command` and the app handed none. */
|
|
4
|
+
export declare const MISSING_COMMAND = "ViewKit drew a list through the components map's `Command`, and the app handed none. Hand `Command`, or hand `Picker` for the editors' lists and set the provider's `menus` to \"menu\" for the grid's menus.";
|
|
5
|
+
/** What the date editor says when it reaches the components map's `Calendar` and the app handed none. */
|
|
6
|
+
export declare const MISSING_CALENDAR = "ViewKit drew the date editor's month through the components map's `Calendar`, and the app handed none. Hand `Calendar`, or hand `DateBody`, your whole date body, which the date editor then opens instead.";
|
|
7
|
+
/** Parts standing in for a `Command` the app left out: each throws the error naming the slot. */
|
|
8
|
+
export declare function missingParts(name: "Command"): ViewsCommandParts;
|
|
9
|
+
/** A component standing in for a slot the app left out: it throws the error naming the slot. */
|
|
10
|
+
export declare function missingComponent(name: "Calendar"): ComponentType<ViewsCalendarProps>;
|