@viewkitjs/views 0.1.0 → 0.2.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 +196 -1
- package/README.md +90 -41
- package/dist/atoms/Row.js +1 -1
- package/dist/atoms/RowMenu.d.ts +1 -1
- package/dist/atoms/RowMenu.js +15 -4
- package/dist/atoms/types.d.ts +4 -4
- package/dist/contract.d.ts +37 -7
- package/dist/contract.js +24 -5
- package/dist/display/format.d.ts +16 -1
- package/dist/display/format.js +10 -1
- package/dist/display/index.d.ts +1 -1
- package/dist/display/index.js +1 -1
- package/dist/display/link.js +5 -3
- package/dist/display/location.d.ts +4 -3
- package/dist/display/location.js +12 -5
- package/dist/display/options.d.ts +1 -1
- package/dist/display/percent.js +10 -3
- package/dist/display/phone.d.ts +2 -1
- package/dist/display/phone.js +8 -1
- package/dist/display/relation.js +1 -1
- package/dist/editors/ChipsEditor.js +1 -1
- package/dist/editors/LocationEditor.js +16 -17
- package/dist/editors/NameEditor.js +5 -4
- package/dist/editors/NumberEditor.js +2 -2
- package/dist/editors/RangeEditor.js +2 -2
- package/dist/editors/ValueListEditor.d.ts +2 -2
- package/dist/editors/ValueListEditor.js +8 -8
- package/dist/editors/edit-cores.d.ts +1 -1
- package/dist/fields/binding.d.ts +1 -1
- package/dist/fields/currency.d.ts +0 -10
- package/dist/fields/currency.js +0 -14
- package/dist/fields/money.d.ts +1 -0
- package/dist/fields/money.js +1 -0
- package/dist/filters/filter-model.d.ts +0 -1
- package/dist/filters/registry.d.ts +3 -36
- package/dist/filters/registry.js +0 -38
- package/dist/grid/chrome/GridAddColumn.d.ts +11 -0
- package/dist/grid/chrome/GridAddColumn.js +29 -0
- package/dist/grid/chrome/GridAggregateMenu.d.ts +31 -0
- package/dist/grid/chrome/GridAggregateMenu.js +27 -0
- package/dist/grid/chrome/GridCellEditors.d.ts +64 -0
- package/dist/grid/chrome/GridCellEditors.js +55 -0
- package/dist/grid/chrome/GridCellOutline.d.ts +70 -0
- package/dist/grid/chrome/GridCellOutline.js +21 -0
- package/dist/grid/chrome/GridChipsEditor.d.ts +28 -0
- package/dist/grid/chrome/GridChipsEditor.js +40 -0
- package/dist/grid/chrome/GridColumnColorSection.d.ts +11 -0
- package/dist/grid/chrome/GridColumnColorSection.js +40 -0
- package/dist/grid/chrome/GridColumnDateSection.d.ts +23 -0
- package/dist/grid/chrome/GridColumnDateSection.js +23 -0
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +19 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +24 -0
- package/dist/grid/chrome/GridColumnMenu.d.ts +101 -0
- package/dist/grid/chrome/GridColumnMenu.js +99 -0
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +25 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +27 -0
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +15 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +16 -0
- package/dist/grid/chrome/GridColumnSortSection.d.ts +18 -0
- package/dist/grid/chrome/GridColumnSortSection.js +16 -0
- package/dist/grid/chrome/GridDateEditor.d.ts +22 -0
- package/dist/grid/chrome/GridDateEditor.js +31 -0
- package/dist/grid/chrome/GridFlyout.d.ts +44 -0
- package/dist/grid/chrome/GridFlyout.js +80 -0
- package/dist/grid/chrome/GridFooter.d.ts +23 -0
- package/dist/grid/chrome/GridFooter.js +81 -0
- package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
- package/dist/grid/chrome/GridGroupMenu.js +57 -0
- package/dist/grid/chrome/GridHeader.d.ts +61 -0
- package/dist/grid/chrome/GridHeader.js +37 -0
- package/dist/grid/chrome/GridLongTextEditor.d.ts +36 -0
- package/dist/grid/chrome/GridLongTextEditor.js +127 -0
- package/dist/grid/chrome/GridMenuRow.d.ts +15 -0
- package/dist/grid/chrome/GridMenuRow.js +15 -0
- package/dist/grid/chrome/GridNameEditor.d.ts +19 -0
- package/dist/grid/chrome/GridNameEditor.js +36 -0
- package/dist/grid/chrome/GridNumberEditor.d.ts +35 -0
- package/dist/grid/chrome/GridNumberEditor.js +25 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +20 -0
- package/dist/grid/chrome/GridRangeEditor.js +25 -0
- package/dist/grid/chrome/GridRelationEditor.d.ts +21 -0
- package/dist/grid/chrome/GridRelationEditor.js +30 -0
- package/dist/grid/chrome/GridResizeHandle.d.ts +19 -0
- package/dist/grid/chrome/GridResizeHandle.js +19 -0
- package/dist/grid/chrome/GridRow.d.ts +25 -0
- package/dist/grid/chrome/GridRow.js +136 -0
- package/dist/grid/chrome/GridRowActions.d.ts +32 -0
- package/dist/grid/chrome/GridRowActions.js +25 -0
- package/dist/grid/chrome/GridRowCells.d.ts +4 -0
- package/dist/grid/chrome/GridRowCells.js +133 -0
- package/dist/grid/chrome/GridRowGlyph.d.ts +12 -0
- package/dist/grid/chrome/GridRowGlyph.js +13 -0
- package/dist/grid/chrome/GridSelectEditor.d.ts +18 -0
- package/dist/grid/chrome/GridSelectEditor.js +49 -0
- package/dist/grid/chrome/GridStructure.d.ts +48 -0
- package/dist/grid/chrome/GridStructure.js +45 -0
- package/dist/grid/chrome/GridTable.d.ts +4 -0
- package/dist/grid/chrome/GridTable.js +125 -0
- package/dist/grid/chrome/GridTableSurface.d.ts +15 -0
- package/dist/grid/chrome/GridTableSurface.js +6 -0
- package/dist/grid/chrome/GridTextEditor.d.ts +11 -0
- package/dist/grid/chrome/GridTextEditor.js +40 -0
- package/dist/grid/chrome/GridValueListEditor.d.ts +18 -0
- package/dist/grid/chrome/GridValueListEditor.js +36 -0
- package/dist/grid/chrome/StuckMarker.d.ts +16 -0
- package/dist/grid/chrome/StuckMarker.js +34 -0
- package/dist/grid/chrome/cell-clipboard.d.ts +9 -0
- package/dist/grid/chrome/cell-clipboard.js +28 -0
- package/dist/grid/chrome/cells.d.ts +21 -0
- package/dist/grid/chrome/cells.js +20 -0
- package/dist/grid/chrome/checks.d.ts +35 -0
- package/dist/grid/chrome/checks.js +22 -0
- package/dist/grid/chrome/column-glyph.d.ts +14 -0
- package/dist/grid/chrome/column-glyph.js +44 -0
- package/dist/grid/chrome/editors.d.ts +9 -0
- package/dist/grid/chrome/editors.js +10 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +59 -0
- package/dist/grid/chrome/grid-cell-classes.js +30 -0
- package/dist/grid/chrome/grid-menu-search.d.ts +7 -0
- package/dist/grid/chrome/grid-menu-search.js +7 -0
- package/dist/grid/chrome/grid-row-props.d.ts +131 -0
- package/dist/grid/chrome/grid-row-props.js +1 -0
- package/dist/grid/chrome/grid-styles.d.ts +37 -0
- package/dist/grid/chrome/grid-styles.js +8 -0
- package/dist/grid/chrome/grid-table-props.d.ts +173 -0
- package/dist/grid/chrome/grid-table-props.js +1 -0
- package/dist/grid/chrome/useGridBatchApi.d.ts +34 -0
- package/dist/grid/chrome/useGridBatchApi.js +35 -0
- package/dist/grid/chrome/useGridColumnLayout.d.ts +30 -0
- package/dist/grid/chrome/useGridColumnLayout.js +206 -0
- package/dist/grid/chrome/useGridHeaderDrag.d.ts +20 -0
- package/dist/grid/chrome/useGridHeaderDrag.js +37 -0
- package/dist/grid/chrome/useGridKeyboard.d.ts +47 -0
- package/dist/grid/chrome/useGridKeyboard.js +274 -0
- package/dist/grid/chrome/useGridPendingReconciliation.d.ts +12 -0
- package/dist/grid/chrome/useGridPendingReconciliation.js +32 -0
- package/dist/grid/chrome/useGridRailReveal.d.ts +57 -0
- package/dist/grid/chrome/useGridRailReveal.js +67 -0
- package/dist/grid/chrome/useGridRangeActions.d.ts +49 -0
- package/dist/grid/chrome/useGridRangeActions.js +188 -0
- package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
- package/dist/grid/chrome/useGridRangeGestures.js +190 -0
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +35 -0
- package/dist/grid/chrome/useGridRowContextMenu.js +127 -0
- package/dist/grid/chrome/useGridScaleStyles.d.ts +1 -0
- package/dist/grid/chrome/useGridScaleStyles.js +29 -0
- package/dist/grid/chrome/useGridScrollSync.d.ts +38 -0
- package/dist/grid/chrome/useGridScrollSync.js +176 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +55 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +197 -0
- package/dist/grid/chrome/useGridTableSelection.d.ts +29 -0
- package/dist/grid/chrome/useGridTableSelection.js +55 -0
- package/dist/grid/chrome/useHeaderDragReorder.d.ts +21 -0
- package/dist/grid/chrome/useHeaderDragReorder.js +216 -0
- package/dist/grid/core/clipboard-model.d.ts +81 -0
- package/dist/grid/core/clipboard-model.js +291 -0
- package/dist/grid/core/column-values.d.ts +27 -0
- package/dist/grid/core/column-values.js +76 -0
- package/dist/grid/core/commit-model.d.ts +34 -0
- package/dist/grid/core/commit-model.js +3 -0
- package/dist/grid/core/coordinates.d.ts +48 -0
- package/dist/grid/core/coordinates.js +27 -0
- package/dist/grid/core/edit-values.d.ts +9 -0
- package/dist/grid/core/edit-values.js +1 -0
- package/dist/grid/core/editing-controller.d.ts +59 -0
- package/dist/grid/core/editing-controller.js +240 -0
- package/dist/grid/core/editing-model.d.ts +78 -0
- package/dist/grid/core/editing-model.js +136 -0
- package/dist/grid/core/grid-scale.d.ts +14 -0
- package/dist/grid/core/grid-scale.js +8 -0
- package/dist/grid/core/nav.d.ts +94 -0
- package/dist/grid/core/nav.js +92 -0
- package/dist/grid/core/pending-reconciliation.d.ts +50 -0
- package/dist/grid/core/pending-reconciliation.js +49 -0
- package/dist/grid/core/range-model.d.ts +25 -0
- package/dist/grid/core/range-model.js +59 -0
- package/dist/grid/core/spreadsheet-operations.d.ts +85 -0
- package/dist/grid/core/spreadsheet-operations.js +253 -0
- package/dist/grid/core/useGridEditing.d.ts +43 -0
- package/dist/grid/core/useGridEditing.js +90 -0
- package/dist/grid/core/useGridRange.d.ts +20 -0
- package/dist/grid/core/useGridRange.js +24 -0
- package/dist/grid/core/value-equality.d.ts +32 -0
- package/dist/grid/core/value-equality.js +34 -0
- package/dist/grid/index.d.ts +18 -0
- package/dist/grid/index.js +5 -0
- package/dist/grid/useGridTablePrefs.d.ts +50 -0
- package/dist/grid/useGridTablePrefs.js +101 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/internal/viewport.d.ts +5 -0
- package/dist/internal/viewport.js +29 -0
- package/dist/model/column-capabilities.d.ts +2 -2
- package/dist/model/column-state.d.ts +1 -1
- package/dist/model/density.js +3 -3
- package/dist/model/filter-capabilities.d.ts +1 -1
- package/dist/model/filter-capabilities.js +1 -1
- package/dist/model/index.d.ts +4 -6
- package/dist/model/index.js +0 -1
- package/dist/model/preferences.d.ts +7 -3
- package/dist/provider/ViewsProvider.d.ts +1 -1
- package/dist/provider/ViewsProvider.js +5 -1
- package/dist/provider/components.d.ts +16 -8
- package/dist/provider/context.d.ts +3 -2
- package/dist/provider/menu-groups.d.ts +8 -0
- package/dist/provider/menu-groups.js +38 -0
- package/dist/provider/ports.d.ts +22 -0
- package/dist/provider/ports.js +1 -0
- package/dist/react.d.ts +1 -1
- package/docs/contract.md +128 -56
- package/docs/getting-started.md +250 -0
- package/docs/guides/atoms.md +245 -0
- package/docs/guides/cells.md +302 -0
- package/docs/guides/columns.md +412 -0
- package/docs/guides/display.md +203 -0
- package/docs/guides/editors.md +404 -0
- package/docs/guides/ports.md +246 -0
- package/docs/guides/selection.md +270 -0
- package/docs/guides/the-grid.md +677 -0
- package/docs/guides/the-provider.md +446 -0
- package/docs/index.md +50 -0
- package/docs/install.md +9 -47
- package/docs/reference/cells.md +28 -0
- package/docs/reference/display.md +42 -0
- package/docs/reference/editors-chips.md +6 -0
- package/docs/reference/editors-date.md +6 -0
- package/docs/reference/editors-location.md +10 -0
- package/docs/reference/editors-name.md +6 -0
- package/docs/reference/editors-number.md +11 -0
- package/docs/reference/editors-open-values.md +9 -0
- package/docs/reference/editors-range.md +6 -0
- package/docs/reference/editors-relation.md +9 -0
- package/docs/reference/editors-select.md +8 -0
- package/docs/reference/editors-session.md +9 -0
- package/docs/reference/editors-value-list.md +6 -0
- package/docs/reference/editors.md +5 -0
- package/docs/reference/grid.md +39 -0
- package/docs/reference/react.md +86 -0
- package/docs/reference/selection.md +33 -0
- package/docs/reference/views.md +601 -0
- package/package.json +7 -3
- package/skills/views/SKILL.md +20 -5
- package/dist/filters/types.d.ts +0 -27
- package/dist/filters/types.js +0 -1
- package/dist/model/filter-pushdown.d.ts +0 -106
- package/dist/model/filter-pushdown.js +0 -147
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
import { fieldKeyOf } from "../model/view-rules.js";
|
|
4
|
+
import { GRID_SCALE_MULTIPLIER } from "./core/grid-scale.js";
|
|
5
|
+
import { normalizeGroupSummary, setAggregate, setDateStyle, setCurrency, setDecimals, setDurationStyle, setOptionColor, setPercentDisplay, setShowTime, } from "../model/preferences.js";
|
|
6
|
+
import { moneyReadingOf } from "../fields/money.js";
|
|
7
|
+
import { isMoneyReading, MONEY_READING_OPTIONS } from "../fields/currency.js";
|
|
8
|
+
export function useGridTablePrefs({ prefs, setPrefs, columns, viewBacked = false, }) {
|
|
9
|
+
const { gridVerticalBorders, gridRowIcon, gridFreezeIdentity, gridWrapCells, gridAlwaysCheckboxes, gridOptionColors, gridDateStyles, gridDurationStyles, gridShowTime, gridPercentDisplays, gridDecimals, gridCurrencies, gridAggregates, gridColumns, gridScale, groupSummary, } = prefs;
|
|
10
|
+
const onOptionColorChange = useCallback((key, value, color) => {
|
|
11
|
+
setPrefs({ gridOptionColors: setOptionColor(gridOptionColors, key, value, color) });
|
|
12
|
+
}, [gridOptionColors, setPrefs]);
|
|
13
|
+
const onDateStyleChange = useCallback((key, style) => setPrefs({ gridDateStyles: setDateStyle(gridDateStyles, key, style) }), [gridDateStyles, setPrefs]);
|
|
14
|
+
const onDurationStyleChange = useCallback((key, style) => setPrefs({ gridDurationStyles: setDurationStyle(gridDurationStyles, key, style) }), [gridDurationStyles, setPrefs]);
|
|
15
|
+
const onShowTimeChange = useCallback((key, show) => setPrefs({ gridShowTime: setShowTime(gridShowTime, key, show) }), [gridShowTime, setPrefs]);
|
|
16
|
+
const onPercentDisplayChange = useCallback((key, display) => setPrefs({ gridPercentDisplays: setPercentDisplay(gridPercentDisplays, key, display) }), [gridPercentDisplays, setPrefs]);
|
|
17
|
+
const onColumnStateChange = useCallback((next) => setPrefs({ gridColumns: next }), [setPrefs]);
|
|
18
|
+
const summaryParts = useMemo(() => normalizeGroupSummary(groupSummary), [groupSummary]);
|
|
19
|
+
const onGroupSummaryChange = useCallback((part, next) => setPrefs({
|
|
20
|
+
groupSummary: next
|
|
21
|
+
? Array.from(new Set([...normalizeGroupSummary(groupSummary), part]))
|
|
22
|
+
: normalizeGroupSummary(groupSummary).filter((p) => p !== part),
|
|
23
|
+
}), [groupSummary, setPrefs]);
|
|
24
|
+
const onAggregateChange = useCallback((columnId, kind) => setPrefs({ gridAggregates: setAggregate(gridAggregates, columnId, kind) }), [gridAggregates, setPrefs]);
|
|
25
|
+
const numberFormats = useMemo(() => {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const col of columns) {
|
|
28
|
+
const key = fieldKeyOf(col);
|
|
29
|
+
const reading = moneyReadingOf(col);
|
|
30
|
+
if (gridDecimals[key] === undefined && !reading)
|
|
31
|
+
continue;
|
|
32
|
+
out[key] = {
|
|
33
|
+
decimals: gridDecimals[key],
|
|
34
|
+
...(reading ? { currency: reading, currencyOptions: MONEY_READING_OPTIONS } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}, [columns, gridDecimals]);
|
|
39
|
+
const onNumberFormatChange = useCallback((key, patch) => {
|
|
40
|
+
if (patch.currency != null && isMoneyReading(patch.currency))
|
|
41
|
+
setPrefs({ gridCurrencies: setCurrency(gridCurrencies, key, patch.currency) });
|
|
42
|
+
if (patch.decimals === null)
|
|
43
|
+
setPrefs({ gridDecimals: { [key]: null } });
|
|
44
|
+
else if (patch.decimals !== undefined)
|
|
45
|
+
setPrefs({ gridDecimals: setDecimals(gridDecimals, key, patch.decimals) });
|
|
46
|
+
}, [gridCurrencies, gridDecimals, setPrefs]);
|
|
47
|
+
const gridProps = useMemo(() => ({
|
|
48
|
+
verticalBorders: gridVerticalBorders,
|
|
49
|
+
showRowIcon: gridRowIcon,
|
|
50
|
+
freezeIdentity: gridFreezeIdentity,
|
|
51
|
+
wrapCells: gridWrapCells,
|
|
52
|
+
alwaysCheckboxes: gridAlwaysCheckboxes,
|
|
53
|
+
scale: GRID_SCALE_MULTIPLIER[gridScale],
|
|
54
|
+
optionColors: gridOptionColors,
|
|
55
|
+
onOptionColorChange,
|
|
56
|
+
dateStyles: gridDateStyles,
|
|
57
|
+
onDateStyleChange,
|
|
58
|
+
durationStyles: gridDurationStyles,
|
|
59
|
+
onDurationStyleChange,
|
|
60
|
+
showTimeOverrides: gridShowTime,
|
|
61
|
+
onShowTimeChange,
|
|
62
|
+
percentDisplays: gridPercentDisplays,
|
|
63
|
+
onPercentDisplayChange,
|
|
64
|
+
columnState: gridColumns,
|
|
65
|
+
onColumnStateChange,
|
|
66
|
+
groupSummary: summaryParts,
|
|
67
|
+
onGroupSummaryChange,
|
|
68
|
+
aggregates: gridAggregates,
|
|
69
|
+
onAggregateChange,
|
|
70
|
+
viewBacked,
|
|
71
|
+
numberFormats,
|
|
72
|
+
onNumberFormatChange,
|
|
73
|
+
}), [
|
|
74
|
+
gridVerticalBorders,
|
|
75
|
+
gridRowIcon,
|
|
76
|
+
gridFreezeIdentity,
|
|
77
|
+
gridWrapCells,
|
|
78
|
+
gridAlwaysCheckboxes,
|
|
79
|
+
gridScale,
|
|
80
|
+
gridOptionColors,
|
|
81
|
+
onOptionColorChange,
|
|
82
|
+
gridDateStyles,
|
|
83
|
+
onDateStyleChange,
|
|
84
|
+
gridDurationStyles,
|
|
85
|
+
onDurationStyleChange,
|
|
86
|
+
gridShowTime,
|
|
87
|
+
onShowTimeChange,
|
|
88
|
+
gridPercentDisplays,
|
|
89
|
+
onPercentDisplayChange,
|
|
90
|
+
gridColumns,
|
|
91
|
+
onColumnStateChange,
|
|
92
|
+
summaryParts,
|
|
93
|
+
onGroupSummaryChange,
|
|
94
|
+
gridAggregates,
|
|
95
|
+
onAggregateChange,
|
|
96
|
+
viewBacked,
|
|
97
|
+
numberFormats,
|
|
98
|
+
onNumberFormatChange,
|
|
99
|
+
]);
|
|
100
|
+
return { gridProps };
|
|
101
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export * from "./model/column-format.js";
|
|
|
6
6
|
export * from "./model/column-inspect.js";
|
|
7
7
|
export * from "./model/column-money.js";
|
|
8
8
|
export * from "./filters/registry.js";
|
|
9
|
-
export * from "./filters/types.js";
|
|
10
9
|
export * from "./filters/text-filter.js";
|
|
11
10
|
export * from "./filters/number-filter.js";
|
|
12
11
|
export * from "./filters/range-filter.js";
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ export * from "./model/column-format.js";
|
|
|
6
6
|
export * from "./model/column-inspect.js";
|
|
7
7
|
export * from "./model/column-money.js";
|
|
8
8
|
export * from "./filters/registry.js";
|
|
9
|
-
export * from "./filters/types.js";
|
|
10
9
|
export * from "./filters/text-filter.js";
|
|
11
10
|
export * from "./filters/number-filter.js";
|
|
12
11
|
export * from "./filters/range-filter.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** True below 768px wide, from the first effect on; false during a server render. */
|
|
2
|
+
export declare function useIsMobile(): boolean;
|
|
3
|
+
/** True when the primary input can hover (a mouse, a trackpad); true during a server render, so
|
|
4
|
+
* the hover-capable rendering is what the server sends. */
|
|
5
|
+
export declare function useHasHover(): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
const MOBILE_BREAKPOINT = 768;
|
|
4
|
+
export function useIsMobile() {
|
|
5
|
+
const [isMobile, setIsMobile] = useState(undefined);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
8
|
+
const onChange = () => {
|
|
9
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
10
|
+
};
|
|
11
|
+
mql.addEventListener("change", onChange);
|
|
12
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
13
|
+
return () => mql.removeEventListener("change", onChange);
|
|
14
|
+
}, []);
|
|
15
|
+
return !!isMobile;
|
|
16
|
+
}
|
|
17
|
+
export function useHasHover() {
|
|
18
|
+
const [hasHover, setHasHover] = useState(true);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (typeof window === "undefined" || !window.matchMedia)
|
|
21
|
+
return;
|
|
22
|
+
const mq = window.matchMedia("(hover: hover) and (pointer: fine)");
|
|
23
|
+
setHasHover(mq.matches);
|
|
24
|
+
const handler = (e) => setHasHover(e.matches);
|
|
25
|
+
mq.addEventListener("change", handler);
|
|
26
|
+
return () => mq.removeEventListener("change", handler);
|
|
27
|
+
}, []);
|
|
28
|
+
return hasHover;
|
|
29
|
+
}
|
|
@@ -153,8 +153,8 @@ export type GridWriteResult = {
|
|
|
153
153
|
export declare function gridNormalizeWrite<Row>(col: ListColumn<Row>, next: unknown, conventions: FieldConventions,
|
|
154
154
|
/** `region`: the record's country, where a phone typed without its country code is read. A host whose rows carry
|
|
155
155
|
* a country passes the row's here; absent, the conventions' region reads it. `messages`: the app's words for a
|
|
156
|
-
* refusal, the package's English when absent. `stored`: the cell's value before this edit, as stored; a
|
|
157
|
-
* that comes back as it is here is kept, never read again
|
|
156
|
+
* refusal, the package's English when absent. `stored`: the cell's value before this edit, as stored; a value
|
|
157
|
+
* fields keeps by `stored` (a phone, a url) that comes back as it is here is kept, never read again. */
|
|
158
158
|
options?: {
|
|
159
159
|
region?: string | null;
|
|
160
160
|
messages?: ViewsMessageResolver;
|
|
@@ -36,7 +36,7 @@ export declare const LIST_DEFAULT_MIN_WIDTH = 60;
|
|
|
36
36
|
/**
|
|
37
37
|
* The density vocabulary, shared by every view. How a view SPENDS it differs —
|
|
38
38
|
* the grid multiplies its pixel scale, the rows views widen their padding — so
|
|
39
|
-
* only the names live here; see `grid
|
|
39
|
+
* only the names live here; see `grid/core/grid-scale.ts`.
|
|
40
40
|
*/
|
|
41
41
|
export type ListDensity = "compact" | "default" | "spacious";
|
|
42
42
|
/**
|
package/dist/model/density.js
CHANGED
|
@@ -6,8 +6,8 @@ const DENSITY = {
|
|
|
6
6
|
export function densityStyle(density) {
|
|
7
7
|
const spec = DENSITY[density] ?? DENSITY.default;
|
|
8
8
|
return {
|
|
9
|
-
"--
|
|
10
|
-
"--
|
|
11
|
-
"--
|
|
9
|
+
"--vk-row-py": spec.py,
|
|
10
|
+
"--vk-head-mb": spec.headMb,
|
|
11
|
+
"--vk-row-gap": spec.gap,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { type ListFilterCapability, type ListFilterCapabilities } from "../filters/registry.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/model/index.d.ts
CHANGED
|
@@ -3,17 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* What a list's columns ARE (`column-schema`), what may be DONE to them
|
|
5
5
|
* (`column-capabilities`), which of them are shown and in what order
|
|
6
|
-
* (`column-state`), how they narrow a cohort (`column-filters
|
|
7
|
-
*
|
|
8
|
-
* (`preferences`).
|
|
6
|
+
* (`column-state`), how they narrow a cohort (`column-filters`), and what a
|
|
7
|
+
* user has persisted about them (`preferences`).
|
|
9
8
|
*
|
|
10
|
-
* It lives OUTSIDE `grid
|
|
9
|
+
* It lives OUTSIDE `grid/` because none of it is about a spreadsheet.
|
|
11
10
|
* A table view reads the same schema to align its columns; a card view reads
|
|
12
11
|
* it to find the title field; a board would read a `select` column's `options`
|
|
13
12
|
* to get its lanes; and all of them must ask `column-capabilities` before a
|
|
14
13
|
* write, or a workspace lock would protect the grid and nothing else.
|
|
15
14
|
*
|
|
16
|
-
* What stayed behind in `grid
|
|
15
|
+
* What stayed behind in `grid/` is what only a spreadsheet does: cell
|
|
17
16
|
* editors, range selection, clipboard, keyboard navigation, and the pixel
|
|
18
17
|
* scale (`core/grid-scale.ts`).
|
|
19
18
|
*/
|
|
@@ -29,7 +28,6 @@ export * from "./column-types.js";
|
|
|
29
28
|
export * from "./column-capabilities.js";
|
|
30
29
|
export * from "./column-warnings.js";
|
|
31
30
|
export * from "./column-filters.js";
|
|
32
|
-
export * from "./filter-pushdown.js";
|
|
33
31
|
export * from "./filter-capabilities.js";
|
|
34
32
|
export * from "./preferences.js";
|
|
35
33
|
export * from "./view-rules.js";
|
package/dist/model/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export * from "./column-types.js";
|
|
|
10
10
|
export * from "./column-capabilities.js";
|
|
11
11
|
export * from "./column-warnings.js";
|
|
12
12
|
export * from "./column-filters.js";
|
|
13
|
-
export * from "./filter-pushdown.js";
|
|
14
13
|
export * from "./filter-capabilities.js";
|
|
15
14
|
export * from "./preferences.js";
|
|
16
15
|
export * from "./view-rules.js";
|
|
@@ -132,8 +132,10 @@ export declare function isGroupSummaryPart(value: unknown): value is ListGroupSu
|
|
|
132
132
|
*
|
|
133
133
|
* It was a single `"count" | "total"` before, so every persisted blob out there
|
|
134
134
|
* still holds a bare string — parsed here rather than migrated, because a view
|
|
135
|
-
* pref is not worth a migration
|
|
136
|
-
*
|
|
135
|
+
* pref is not worth a migration. Keeps the parts it recognises and drops the
|
|
136
|
+
* rest, so a value it cannot read comes back as `[]`, a bare group name, never
|
|
137
|
+
* the default: a caller with no stored value applies
|
|
138
|
+
* `LIST_VIEW_PREF_DEFAULTS.groupSummary` itself before calling.
|
|
137
139
|
*/
|
|
138
140
|
export declare function normalizeGroupSummary(value: unknown): ListGroupSummaryPart[];
|
|
139
141
|
export declare const LIST_VIEW_PREF_DEFAULTS: ListViewPrefs;
|
|
@@ -141,7 +143,9 @@ export declare const LIST_VIEW_PREF_DEFAULTS: ListViewPrefs;
|
|
|
141
143
|
export declare function setFilterRule(current: ListFilterRuleState, columnId: string, rule: ListFilterRule | null): ListFilterRuleState;
|
|
142
144
|
export declare function setOptionColor(current: ListOptionColorOverrides, columnId: string, value: string, color: ListSelectColor | null): ListOptionColorOverrides;
|
|
143
145
|
export declare function setDateStyle(current: ListDateStyleOverrides, columnId: string, style: ListDateStyle): ListDateStyleOverrides;
|
|
144
|
-
/** Set one column's duration rendering
|
|
146
|
+
/** Set one column's duration rendering. Always writes the entry, the column's
|
|
147
|
+
* own style included: unlike `setFilterRule` and `setOptionColor`, it never
|
|
148
|
+
* drops one. */
|
|
145
149
|
export declare function setDurationStyle(current: ListDurationStyleOverrides, columnId: string, style: ListDurationStyle): ListDurationStyleOverrides;
|
|
146
150
|
export declare function setShowTime(current: ListShowTimeOverrides, columnId: string, show: boolean): ListShowTimeOverrides;
|
|
147
151
|
export declare function setPercentDisplay(current: ListPercentDisplayOverrides, key: string, display: PercentDisplay): ListPercentDisplayOverrides;
|
|
@@ -5,7 +5,7 @@ import type { ViewsAtoms } from "../atoms/types.js";
|
|
|
5
5
|
import type { FieldPresentation } from "../display/options.js";
|
|
6
6
|
import type { ViewsComponents } from "./components.js";
|
|
7
7
|
import type { ViewsIcons } from "./icons.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type ViewsPorts } from "./ports.js";
|
|
9
9
|
export { useViews, type ViewsContextValue } from "./context.js";
|
|
10
10
|
export type ViewsProviderProps = {
|
|
11
11
|
components: ViewsComponents;
|
|
@@ -4,9 +4,13 @@ import { useMemo } from "react";
|
|
|
4
4
|
import { resolveViewsMessage } from "../contract.js";
|
|
5
5
|
import { DEFAULT_VIEWS_ATOMS } from "../atoms/defaults.js";
|
|
6
6
|
import { ViewsContext } from "./context.js";
|
|
7
|
+
import { withSettledGroups } from "./menu-groups.js";
|
|
8
|
+
import { browserConfirm } from "./ports.js";
|
|
7
9
|
export { useViews } from "./context.js";
|
|
8
10
|
export function ViewsProvider({ children, components, conventions, icons, ports, atoms, messages = resolveViewsMessage, presentation, }) {
|
|
9
11
|
const merged = useMemo(() => ({ ...DEFAULT_VIEWS_ATOMS, ...atoms }), [atoms]);
|
|
10
|
-
const
|
|
12
|
+
const settled = useMemo(() => ({ ...components, Menu: withSettledGroups(components.Menu) }), [components]);
|
|
13
|
+
const resolved = useMemo(() => (ports.confirm ? ports : { ...ports, confirm: browserConfirm }), [ports]);
|
|
14
|
+
const value = useMemo(() => ({ components: settled, atoms: merged, conventions, icons, ports: resolved, messages, presentation }), [settled, merged, conventions, icons, resolved, messages, presentation]);
|
|
11
15
|
return _jsx(ViewsContext.Provider, { value: value, children: children });
|
|
12
16
|
}
|
|
@@ -32,7 +32,8 @@ export type ViewsPopoverProps = {
|
|
|
32
32
|
sideOffset?: number;
|
|
33
33
|
alignOffset?: number;
|
|
34
34
|
/** False keeps focus where it was when the popup opens (an editor that owns
|
|
35
|
-
* its own input)
|
|
35
|
+
* its own input); that editor focuses its input with `preventScroll`, so the
|
|
36
|
+
* page stays where it is however the popup places itself. Default true. */
|
|
36
37
|
initialFocus?: boolean;
|
|
37
38
|
/** Called on a press outside the popup before it closes; return false to keep it open.
|
|
38
39
|
* `event` is the pointer press, with its `target` where the press landed, also when the
|
|
@@ -42,8 +43,9 @@ export type ViewsPopoverProps = {
|
|
|
42
43
|
/** Called on Escape before the popup closes; return false to keep it open. */
|
|
43
44
|
onEscape?: (event: KeyboardEvent) => void | false;
|
|
44
45
|
/** The popup's look. `panel` is the app's card popover; `menu` is its menu
|
|
45
|
-
* panel, for a popover that holds a list
|
|
46
|
-
* own). Default
|
|
46
|
+
* panel's surface, for a popover that holds a list: no inset (the list
|
|
47
|
+
* carries its own) and no card width (it is as wide as its list). Default
|
|
48
|
+
* `panel`. */
|
|
47
49
|
chrome?: "panel" | "menu";
|
|
48
50
|
/** A click inside the popup. A popup is a portal, so its clicks still bubble
|
|
49
51
|
* through the React tree to the anchor's row; the rendering stops them here. */
|
|
@@ -93,7 +95,8 @@ export type ViewsMenuItem = {
|
|
|
93
95
|
/** A checkable row: the app draws its tick. A checkable row closes the menu like any row. */
|
|
94
96
|
checked?: boolean;
|
|
95
97
|
/** A group: its rows drawn in place under this row's label, never a flyout. A group row is a
|
|
96
|
-
* label, not a target: its own `onSelect`, `href` and `checked` are ignored.
|
|
98
|
+
* label, not a target: its own `onSelect`, `href` and `checked` are ignored. A disabled group
|
|
99
|
+
* disables every row under it: the provider hands the app's `Menu` those rows already `disabled`. */
|
|
97
100
|
children?: ViewsMenuItem[];
|
|
98
101
|
separatorBefore?: boolean;
|
|
99
102
|
/** A keyboard hint drawn at the row's end, never bound by the menu. */
|
|
@@ -101,6 +104,8 @@ export type ViewsMenuItem = {
|
|
|
101
104
|
/** A link item: the row is an anchor and `onSelect` still fires. */
|
|
102
105
|
href?: string;
|
|
103
106
|
};
|
|
107
|
+
/** Opens at `anchor`, with no trigger child and no flyouts: on Base UI, the menu's root,
|
|
108
|
+
* positioner and popup, the anchor handed to the positioner. */
|
|
104
109
|
export type ViewsMenuProps = {
|
|
105
110
|
open: boolean;
|
|
106
111
|
onOpenChange: ViewsOpenChange;
|
|
@@ -152,8 +157,9 @@ export type ViewsCommandParts = {
|
|
|
152
157
|
value: string;
|
|
153
158
|
onSelect: (value: string) => void;
|
|
154
159
|
disabled?: boolean;
|
|
155
|
-
/** The value this item stands for is the current one
|
|
156
|
-
* the
|
|
160
|
+
/** The value this item stands for is the current one. The app colours the item as its
|
|
161
|
+
* chosen row; the check is the package's, drawn by the row inside, so the item draws no
|
|
162
|
+
* tick of its own. */
|
|
157
163
|
chosen?: boolean;
|
|
158
164
|
children: ReactNode;
|
|
159
165
|
className?: string;
|
|
@@ -186,7 +192,7 @@ export type ViewsCollapseProps = {
|
|
|
186
192
|
clipClassName?: string;
|
|
187
193
|
durationMs?: number;
|
|
188
194
|
};
|
|
189
|
-
/** A phone sheet.
|
|
195
|
+
/** A phone sheet. `snap` is a hint: an app whose sheet has no snap points ignores it. */
|
|
190
196
|
export type ViewsSheetProps = {
|
|
191
197
|
open: boolean;
|
|
192
198
|
onOpenChange: ViewsOpenChange;
|
|
@@ -207,7 +213,9 @@ export type ViewsComponents = {
|
|
|
207
213
|
Collapse: ComponentType<ViewsCollapseProps>;
|
|
208
214
|
Sheet: ComponentType<ViewsSheetProps>;
|
|
209
215
|
/** The app's own icon component by the app's own names, for glyphs a host
|
|
210
|
-
* declares (`rowIcon`, a binding's `icon`).
|
|
216
|
+
* declares (`rowIcon`, a binding's `icon`). It draws on the first paint,
|
|
217
|
+
* because rows are measured as they mount: map the names from a static
|
|
218
|
+
* record, never icons loaded on demand. Semantic glyphs use `icons`. */
|
|
211
219
|
AppIcon: ComponentType<{
|
|
212
220
|
name: string;
|
|
213
221
|
className?: string;
|
|
@@ -4,12 +4,13 @@ import type { ViewsAtoms } from "../atoms/types.js";
|
|
|
4
4
|
import type { FieldPresentation } from "../display/options.js";
|
|
5
5
|
import type { ViewsComponents } from "./components.js";
|
|
6
6
|
import type { ViewsIcons } from "./icons.js";
|
|
7
|
-
import type {
|
|
7
|
+
import type { ViewsResolvedPorts } from "./ports.js";
|
|
8
8
|
export type ViewsContextValue = {
|
|
9
9
|
components: ViewsComponents;
|
|
10
10
|
atoms: ViewsAtoms;
|
|
11
11
|
icons: ViewsIcons;
|
|
12
|
-
ports
|
|
12
|
+
/** The app's ports, with `confirm` always a function (the browser's where the app handed none). */
|
|
13
|
+
ports: ViewsResolvedPorts;
|
|
13
14
|
messages: ViewsMessageResolver;
|
|
14
15
|
conventions: FieldConventions;
|
|
15
16
|
/** The app's formatting: given the package's defaults, return the app's. */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ComponentType } from "react";
|
|
2
|
+
import type { ViewsMenuItem, ViewsMenuProps } from "./components.js";
|
|
3
|
+
/** The items with every row under a disabled group marked `disabled`, at every depth. Only the
|
|
4
|
+
* path to a disabled group is copied; with none, the same array comes back. */
|
|
5
|
+
export declare function settleMenuGroups(items: ViewsMenuItem[]): ViewsMenuItem[];
|
|
6
|
+
/** The app's Menu, handed its items settled. One wrapper per app Menu, so an open menu never
|
|
7
|
+
* remounts; a wrapper handed in again (a nested provider) comes back as it is. */
|
|
8
|
+
export declare function withSettledGroups(Menu: ComponentType<ViewsMenuProps>): ComponentType<ViewsMenuProps>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createElement, useMemo } from "react";
|
|
2
|
+
function disableAll(items) {
|
|
3
|
+
return items.map((item) => ({
|
|
4
|
+
...item,
|
|
5
|
+
disabled: true,
|
|
6
|
+
...(item.children && { children: disableAll(item.children) }),
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
export function settleMenuGroups(items) {
|
|
10
|
+
let changed = false;
|
|
11
|
+
const settled = items.map((item) => {
|
|
12
|
+
if (!item.children || item.children.length === 0)
|
|
13
|
+
return item;
|
|
14
|
+
const children = item.disabled ? disableAll(item.children) : settleMenuGroups(item.children);
|
|
15
|
+
if (children === item.children)
|
|
16
|
+
return item;
|
|
17
|
+
changed = true;
|
|
18
|
+
return { ...item, children };
|
|
19
|
+
});
|
|
20
|
+
return changed ? settled : items;
|
|
21
|
+
}
|
|
22
|
+
const wrappers = new WeakMap();
|
|
23
|
+
const settledMenus = new WeakSet();
|
|
24
|
+
export function withSettledGroups(Menu) {
|
|
25
|
+
if (settledMenus.has(Menu))
|
|
26
|
+
return Menu;
|
|
27
|
+
const known = wrappers.get(Menu);
|
|
28
|
+
if (known)
|
|
29
|
+
return known;
|
|
30
|
+
function SettledMenu(props) {
|
|
31
|
+
const items = useMemo(() => settleMenuGroups(props.items), [props.items]);
|
|
32
|
+
return createElement(Menu, { ...props, items });
|
|
33
|
+
}
|
|
34
|
+
SettledMenu.displayName = `Settled(${Menu.displayName ?? (Menu.name || "Menu")})`;
|
|
35
|
+
wrappers.set(Menu, SettledMenu);
|
|
36
|
+
settledMenus.add(SettledMenu);
|
|
37
|
+
return SettledMenu;
|
|
38
|
+
}
|
package/dist/provider/ports.d.ts
CHANGED
|
@@ -25,11 +25,33 @@ export type ViewsPrefsPort = {
|
|
|
25
25
|
set: <T>(key: string, value: T) => void;
|
|
26
26
|
subscribe: (key: string, listener: () => void) => () => void;
|
|
27
27
|
};
|
|
28
|
+
/** A question asked before an act, for the person to answer: the app's own dialog, or the browser's. */
|
|
29
|
+
export type ViewsConfirmRequest = {
|
|
30
|
+
/** The question, worded by the package's message (a row's Delete: `views.menus.row-delete-confirm`). */
|
|
31
|
+
message: string;
|
|
32
|
+
/** The yes button's words (a row's Delete: `views.menus.row-delete`). */
|
|
33
|
+
confirmLabel: string;
|
|
34
|
+
/** What the act is done to, as the host names it (a row's `deleteLabel`). Absent when it names nothing. */
|
|
35
|
+
subject?: string;
|
|
36
|
+
/** The act removes something: the app draws its destructive look. */
|
|
37
|
+
destructive?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** Resolves to whether the person said yes. */
|
|
40
|
+
export type ViewsConfirmPort = (request: ViewsConfirmRequest) => Promise<boolean>;
|
|
28
41
|
export type ViewsPorts = {
|
|
29
42
|
toast: ViewsToastPort;
|
|
30
43
|
haptics: ViewsHapticsPort;
|
|
31
44
|
clipboard: ViewsClipboardPort;
|
|
32
45
|
viewPrefs: ViewsPrefsPort;
|
|
46
|
+
/** Asks before a destructive act (a row's Delete). Absent: the browser's own confirm with `message`. */
|
|
47
|
+
confirm?: ViewsConfirmPort;
|
|
48
|
+
};
|
|
49
|
+
/** The ports as the provider hands them on: `confirm` always there, the browser's where the app
|
|
50
|
+
* handed none. */
|
|
51
|
+
export type ViewsResolvedPorts = ViewsPorts & {
|
|
52
|
+
confirm: ViewsConfirmPort;
|
|
33
53
|
};
|
|
54
|
+
/** The browser's own dialog, read when it is asked, so a server render never reaches `window`. */
|
|
55
|
+
export declare const browserConfirm: ViewsConfirmPort;
|
|
34
56
|
/** Ports that do nothing: a server render, a test, an app without a device. */
|
|
35
57
|
export declare const NOOP_PORTS: ViewsPorts;
|
package/dist/provider/ports.js
CHANGED
package/dist/react.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type { ViewsContextValue, ViewsProviderProps } from "./provider/ViewsProv
|
|
|
3
3
|
export type { ViewsAlign, ViewsAnchor, ViewsButtonProps, ViewsCalendarProps, ViewsCheckboxProps, ViewsCloseReason, ViewsCollapseProps, ViewsCommandParts, ViewsComponents, ViewsMenuItem, ViewsMenuProps, ViewsOpenChange, ViewsPopoverProps, ViewsSheetProps, ViewsSide, ViewsTooltipProps, } from "./provider/components.js";
|
|
4
4
|
export type { ViewsIconProps, ViewsIcons } from "./provider/icons.js";
|
|
5
5
|
export { NOOP_PORTS } from "./provider/ports.js";
|
|
6
|
-
export type { ViewsClipboardPort, ViewsHapticsPort, ViewsPorts, ViewsPrefsPort, ViewsToastPort, } from "./provider/ports.js";
|
|
6
|
+
export type { ViewsClipboardPort, ViewsConfirmPort, ViewsConfirmRequest, ViewsHapticsPort, ViewsPorts, ViewsPrefsPort, ViewsResolvedPorts, ViewsToastPort, } from "./provider/ports.js";
|
|
7
7
|
export { DEFAULT_VIEWS_ATOMS } from "./atoms/defaults.js";
|
|
8
8
|
export type { ViewsAtoms, ViewsCommandMenuProps, ViewsRowMenuItem, ViewsRowMenuProps, ViewsListProps, ViewsRelationLinkProps, ViewsLoadingProps, ViewsLoadMoreProps, ViewsPlatformMarkProps, ViewsRowContentProps, ViewsRowProps, ViewsStatusBadgeProps, ViewsStatusMarkerProps, ViewsTagProps, ViewsTickBoxProps, } from "./atoms/types.js";
|
|
9
9
|
export type { ComponentName, PortName, ViewsIconName, ViewsMessage, ViewsMessageResolver } from "./contract.js";
|