@viewkitjs/views 0.2.0 → 0.3.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 +571 -0
- package/README.md +5 -3
- package/dist/atoms/LoadMore.js +11 -1
- package/dist/atoms/RowMenu.js +5 -2
- package/dist/cells/cell-format.d.ts +3 -3
- package/dist/cells/cell-title.d.ts +1 -2
- package/dist/cells/cell-title.js +2 -2
- package/dist/cells/cell-values.js +6 -3
- package/dist/contract.d.ts +50 -9
- package/dist/contract.js +33 -5
- package/dist/display/converted.d.ts +19 -0
- package/dist/display/converted.js +12 -0
- package/dist/display/index.d.ts +1 -0
- package/dist/display/index.js +1 -0
- package/dist/display/link-click.d.ts +11 -0
- package/dist/display/link-click.js +3 -0
- package/dist/display/link.js +7 -3
- package/dist/display/multi-value.d.ts +1 -1
- package/dist/display/multi-value.js +1 -1
- package/dist/display/options.d.ts +7 -1
- package/dist/display/phone.js +3 -1
- package/dist/editors/ChipsEditor.d.ts +9 -4
- package/dist/editors/ChipsEditor.js +6 -2
- package/dist/editors/DateEditor.d.ts +21 -6
- package/dist/editors/DateEditor.js +118 -30
- package/dist/editors/EditorPanel.d.ts +61 -0
- package/dist/editors/EditorPanel.js +54 -0
- package/dist/editors/LocationEditor.d.ts +3 -0
- package/dist/editors/LocationEditor.js +14 -6
- package/dist/editors/NameEditor.d.ts +3 -0
- package/dist/editors/NameEditor.js +11 -7
- package/dist/editors/NumberEditor.d.ts +3 -0
- package/dist/editors/NumberEditor.js +6 -6
- package/dist/editors/RangeEditor.d.ts +16 -1
- package/dist/editors/RangeEditor.js +21 -5
- package/dist/editors/RelationEditor.d.ts +13 -28
- package/dist/editors/RelationEditor.js +17 -40
- package/dist/editors/RelationSetEditor.d.ts +53 -0
- package/dist/editors/RelationSetEditor.js +112 -0
- package/dist/editors/SelectEditor.d.ts +21 -3
- package/dist/editors/SelectEditor.js +55 -9
- package/dist/editors/TextEditor.d.ts +51 -0
- package/dist/editors/TextEditor.js +81 -0
- package/dist/editors/ValueListEditor.d.ts +3 -0
- package/dist/editors/ValueListEditor.js +4 -2
- package/dist/editors/edit-cores.d.ts +12 -9
- package/dist/editors/edit-cores.js +7 -6
- package/dist/editors/edit-session.d.ts +21 -11
- package/dist/editors/edit-session.js +19 -5
- package/dist/editors/keep-inside.d.ts +12 -0
- package/dist/editors/keep-inside.js +20 -0
- package/dist/editors/open-value.d.ts +21 -0
- package/dist/editors/open-value.js +36 -0
- package/dist/editors/open-values.d.ts +4 -0
- package/dist/editors/open-values.js +7 -0
- package/dist/editors/relation-kinds.d.ts +7 -0
- package/dist/editors/relation-kinds.js +21 -0
- package/dist/editors/relation-panel.d.ts +69 -0
- package/dist/editors/relation-panel.js +40 -0
- package/dist/field-row/FieldNoteLine.d.ts +14 -0
- package/dist/field-row/FieldNoteLine.js +14 -0
- package/dist/field-row/FieldRow.d.ts +73 -0
- package/dist/field-row/FieldRow.js +157 -0
- package/dist/field-row/FieldRowLane.d.ts +19 -0
- package/dist/field-row/FieldRowLane.js +11 -0
- package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
- package/dist/field-row/editors/RowChipsEditor.js +25 -0
- package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
- package/dist/field-row/editors/RowDateEditor.js +18 -0
- package/dist/field-row/editors/RowEditor.d.ts +39 -0
- package/dist/field-row/editors/RowEditor.js +64 -0
- package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
- package/dist/field-row/editors/RowNameEditor.js +15 -0
- package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
- package/dist/field-row/editors/RowNumberEditor.js +18 -0
- package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
- package/dist/field-row/editors/RowPlaceEditor.js +18 -0
- package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
- package/dist/field-row/editors/RowRangeEditor.js +15 -0
- package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
- package/dist/field-row/editors/RowRelationEditor.js +77 -0
- package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
- package/dist/field-row/editors/RowSelectEditor.js +23 -0
- package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
- package/dist/field-row/editors/RowTextEditor.js +16 -0
- package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
- package/dist/field-row/editors/RowValueListEditor.js +21 -0
- package/dist/field-row/editors/host.d.ts +59 -0
- package/dist/field-row/editors/host.js +1 -0
- package/dist/field-row/editors/row-session.d.ts +49 -0
- package/dist/field-row/editors/row-session.js +49 -0
- package/dist/field-row/index.d.ts +5 -0
- package/dist/field-row/index.js +5 -0
- package/dist/field-row/row-target.d.ts +20 -0
- package/dist/field-row/row-target.js +3 -0
- package/dist/field-row/useFieldWrite.d.ts +45 -0
- package/dist/field-row/useFieldWrite.js +190 -0
- package/dist/field-row/useRowSettlement.d.ts +33 -0
- package/dist/field-row/useRowSettlement.js +23 -0
- package/dist/fields/binding.d.ts +6 -1
- package/dist/fields/binding.js +13 -6
- package/dist/fields/edit-core-types.d.ts +9 -9
- package/dist/fields/edit-core-types.js +6 -6
- package/dist/fields/money.d.ts +5 -0
- package/dist/fields/money.js +10 -0
- package/dist/fields/number-edit.d.ts +6 -0
- package/dist/fields/number-edit.js +4 -0
- package/dist/fields/prepare-write.js +6 -1
- package/dist/fields/relation-source-types.d.ts +12 -0
- package/dist/fields/write-target.d.ts +50 -0
- package/dist/fields/write-target.js +10 -0
- package/dist/grid/chrome/GridAddColumn.js +1 -1
- package/dist/grid/chrome/GridAggregateMenu.d.ts +1 -1
- package/dist/grid/chrome/GridAggregateMenu.js +8 -6
- package/dist/grid/chrome/GridCellEditors.d.ts +7 -0
- package/dist/grid/chrome/GridCellEditors.js +87 -16
- package/dist/grid/chrome/GridCellOutline.d.ts +22 -43
- package/dist/grid/chrome/GridCellOutline.js +2 -7
- package/dist/grid/chrome/GridChipsEditor.d.ts +16 -6
- package/dist/grid/chrome/GridChipsEditor.js +21 -26
- package/dist/grid/chrome/GridColumnMenu.d.ts +1 -1
- package/dist/grid/chrome/GridColumnMenu.js +7 -3
- package/dist/grid/chrome/GridDateEditor.d.ts +23 -11
- package/dist/grid/chrome/GridDateEditor.js +13 -25
- package/dist/grid/chrome/GridFooter.d.ts +12 -2
- package/dist/grid/chrome/GridFooter.js +10 -6
- package/dist/grid/chrome/GridGroupMenu.js +20 -13
- package/dist/grid/chrome/GridHeader.d.ts +9 -4
- package/dist/grid/chrome/GridHeader.js +15 -10
- package/dist/grid/chrome/GridLongTextEditor.d.ts +28 -9
- package/dist/grid/chrome/GridLongTextEditor.js +16 -74
- package/dist/grid/chrome/GridNameEditor.d.ts +11 -6
- package/dist/grid/chrome/GridNameEditor.js +12 -27
- package/dist/grid/chrome/GridNumberEditor.d.ts +20 -6
- package/dist/grid/chrome/GridNumberEditor.js +46 -20
- package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
- package/dist/grid/chrome/GridPlaceEditor.js +22 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +15 -5
- package/dist/grid/chrome/GridRangeEditor.js +16 -20
- package/dist/grid/chrome/GridRelationEditor.d.ts +38 -14
- package/dist/grid/chrome/GridRelationEditor.js +86 -24
- package/dist/grid/chrome/GridRow.d.ts +7 -1
- package/dist/grid/chrome/GridRow.js +57 -14
- package/dist/grid/chrome/GridRowActions.js +1 -1
- package/dist/grid/chrome/GridRowCells.js +18 -23
- package/dist/grid/chrome/GridSelectEditor.d.ts +19 -4
- package/dist/grid/chrome/GridSelectEditor.js +21 -27
- package/dist/grid/chrome/GridStructure.d.ts +9 -10
- package/dist/grid/chrome/GridStructure.js +10 -14
- package/dist/grid/chrome/GridTable.js +97 -30
- package/dist/grid/chrome/GridTableSurface.d.ts +39 -2
- package/dist/grid/chrome/GridTableSurface.js +12 -3
- package/dist/grid/chrome/GridTextEditor.d.ts +35 -1
- package/dist/grid/chrome/GridTextEditor.js +35 -37
- package/dist/grid/chrome/GridValueListEditor.d.ts +15 -3
- package/dist/grid/chrome/GridValueListEditor.js +10 -27
- package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
- package/dist/grid/chrome/cell-cut-off.js +20 -0
- package/dist/grid/chrome/cells.js +1 -2
- package/dist/grid/chrome/checks.d.ts +2 -5
- package/dist/grid/chrome/checks.js +15 -5
- package/dist/grid/chrome/editors.d.ts +1 -1
- package/dist/grid/chrome/editors.js +1 -1
- package/dist/grid/chrome/grid-cell-classes.d.ts +2 -8
- package/dist/grid/chrome/grid-cell-classes.js +10 -8
- package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
- package/dist/grid/chrome/grid-cell-link.js +9 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
- package/dist/grid/chrome/grid-edit-session.js +118 -0
- package/dist/grid/chrome/grid-hover.d.ts +60 -0
- package/dist/grid/chrome/grid-hover.js +81 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
- package/dist/grid/chrome/grid-menu-focus.js +93 -0
- package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
- package/dist/grid/chrome/grid-row-menu-key.js +36 -0
- package/dist/grid/chrome/grid-row-props.d.ts +16 -4
- package/dist/grid/chrome/grid-row-window.d.ts +61 -0
- package/dist/grid/chrome/grid-row-window.js +212 -0
- package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
- package/dist/grid/chrome/grid-scroll-owner.js +75 -0
- package/dist/grid/chrome/grid-styles.d.ts +4 -1
- package/dist/grid/chrome/grid-styles.js +1 -0
- package/dist/grid/chrome/grid-table-props.d.ts +2 -3
- package/dist/grid/chrome/useGridFocus.d.ts +45 -0
- package/dist/grid/chrome/useGridFocus.js +122 -0
- package/dist/grid/chrome/useGridKeyboard.d.ts +21 -4
- package/dist/grid/chrome/useGridKeyboard.js +214 -38
- package/dist/grid/chrome/useGridRangeActions.d.ts +3 -1
- package/dist/grid/chrome/useGridRangeActions.js +17 -10
- package/dist/grid/chrome/useGridRangeGestures.js +68 -21
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +4 -2
- package/dist/grid/chrome/useGridRowContextMenu.js +28 -2
- package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -1
- package/dist/grid/chrome/useGridScaleStyles.js +6 -7
- package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
- package/dist/grid/chrome/useGridScrollArea.js +65 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +28 -5
- package/dist/grid/chrome/useGridTableInteractionModel.js +66 -14
- package/dist/grid/chrome/useHeaderDragReorder.d.ts +2 -2
- package/dist/grid/core/clipboard-model.d.ts +2 -0
- package/dist/grid/core/clipboard-model.js +1 -1
- package/dist/grid/core/commit-model.d.ts +7 -0
- package/dist/grid/core/edge-scroll.d.ts +21 -0
- package/dist/grid/core/edge-scroll.js +23 -0
- package/dist/grid/core/editing-controller.d.ts +2 -1
- package/dist/grid/core/editing-controller.js +35 -9
- package/dist/grid/core/editing-model.d.ts +9 -0
- package/dist/grid/core/editing-model.js +12 -0
- package/dist/grid/core/flat-rows.d.ts +35 -0
- package/dist/grid/core/flat-rows.js +20 -0
- package/dist/grid/core/grid-aria.d.ts +27 -0
- package/dist/grid/core/grid-aria.js +39 -0
- package/dist/grid/core/grid-focus.d.ts +54 -0
- package/dist/grid/core/grid-focus.js +148 -0
- package/dist/grid/core/nav.d.ts +2 -2
- package/dist/grid/core/pending-reconciliation.d.ts +3 -0
- package/dist/grid/core/pending-reconciliation.js +5 -3
- package/dist/grid/core/row-window.d.ts +40 -0
- package/dist/grid/core/row-window.js +43 -0
- package/dist/grid/core/spreadsheet-operations.d.ts +17 -1
- package/dist/grid/core/spreadsheet-operations.js +33 -6
- package/dist/grid/core/useGridEditing.d.ts +3 -0
- package/dist/grid/core/useGridEditing.js +6 -3
- package/dist/grid/core/value-equality.d.ts +23 -1
- package/dist/grid/core/value-equality.js +46 -0
- package/dist/grid/useGridTablePrefs.d.ts +0 -1
- package/dist/grid/useGridTablePrefs.js +1 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/viewport.d.ts +0 -2
- package/dist/internal/viewport.js +0 -14
- package/dist/model/column-capabilities.d.ts +2 -1
- package/dist/model/column-capabilities.js +28 -8
- package/dist/model/column-from.js +3 -0
- package/dist/model/column-inspect.d.ts +10 -2
- package/dist/model/column-inspect.js +9 -0
- package/dist/model/column-schema.d.ts +6 -1
- package/dist/model/column-types.d.ts +3 -1
- package/dist/model/column-types.js +1 -1
- package/dist/model/preferences.d.ts +0 -4
- package/dist/model/preferences.js +0 -1
- package/dist/model/prefs-buckets.d.ts +0 -1
- package/dist/model/prefs-buckets.js +0 -3
- package/dist/model/render-count.d.ts +6 -0
- package/dist/model/render-count.js +11 -0
- package/dist/provider/ViewsProvider.d.ts +5 -1
- package/dist/provider/ViewsProvider.js +9 -3
- package/dist/provider/components.d.ts +19 -1
- package/dist/provider/components.js +4 -2
- package/dist/provider/context.d.ts +5 -2
- package/dist/provider/desktop.d.ts +9 -0
- package/dist/provider/desktop.js +22 -0
- package/dist/provider/plain-input.d.ts +8 -0
- package/dist/provider/plain-input.js +5 -0
- package/dist/react.d.ts +2 -1
- package/dist/react.js +1 -0
- package/dist/selection/SelectCheckbox.d.ts +3 -1
- package/dist/selection/SelectCheckbox.js +2 -2
- package/dist/selection/useCheckDragSelect.js +6 -5
- package/docs/contract.md +93 -35
- package/docs/guides/atoms.md +1 -1
- package/docs/guides/cells.md +2 -2
- package/docs/guides/columns.md +3 -2
- package/docs/guides/display.md +1 -0
- package/docs/guides/editors.md +71 -13
- package/docs/guides/the-grid.md +32 -13
- package/docs/guides/the-provider.md +3 -1
- package/docs/index.md +3 -1
- package/docs/install.md +1 -1
- package/docs/reference/cells.md +1 -1
- package/docs/reference/display.md +3 -1
- package/docs/reference/editors-chips.md +2 -2
- package/docs/reference/editors-date.md +3 -3
- package/docs/reference/editors-location.md +1 -1
- package/docs/reference/editors-number.md +1 -1
- package/docs/reference/editors-open-values.md +1 -0
- package/docs/reference/editors-panel.md +12 -0
- package/docs/reference/editors-range.md +1 -1
- package/docs/reference/editors-relation.md +6 -3
- package/docs/reference/editors-select.md +3 -2
- package/docs/reference/editors-session.md +4 -2
- package/docs/reference/editors-text.md +9 -0
- package/docs/reference/editors-value-list.md +1 -1
- package/docs/reference/editors.md +2 -2
- package/docs/reference/field-row.md +16 -0
- package/docs/reference/grid.md +3 -3
- package/docs/reference/react.md +8 -5
- package/docs/reference/views.md +36 -15
- package/package.json +23 -4
- package/skills/views/SKILL.md +4 -4
- package/dist/grid/chrome/useGridScrollSync.d.ts +0 -38
- package/dist/grid/chrome/useGridScrollSync.js +0 -176
|
@@ -18,11 +18,8 @@ export declare function GridRowCheck({ selecting, checked, revealed, onChange, "
|
|
|
18
18
|
* Select-all / group checkbox — the SAME rail slot the rows use, mounted as the
|
|
19
19
|
* header's leading track rather than as an overlay beside it.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* flow would have had to be counter-translated. Both halves of that stopped
|
|
24
|
-
* being true: the strip is a real scroll container now, and the rail travels
|
|
25
|
-
* with its row instead of standing still. An overlay would be the one piece of
|
|
21
|
+
* The header sits in the grid's one scroll area with the rows, so its rail slot
|
|
22
|
+
* travels and parks exactly as theirs do. An overlay would be the one piece of
|
|
26
23
|
* leading chrome that didn't move — parked at a fixed x while every row's
|
|
27
24
|
* checkbox slid away from it and stopped somewhere else.
|
|
28
25
|
*/
|
|
@@ -5,18 +5,28 @@ import { cx } from "../../internal/cx.js";
|
|
|
5
5
|
import { gridFrozenBg } from "./GridCellOutline.js";
|
|
6
6
|
import { GRID_GROUND } from "./grid-styles.js";
|
|
7
7
|
import { SelectCheckbox } from "../../selection/SelectCheckbox.js";
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const HOVER_RAISE = {
|
|
9
|
+
row: {
|
|
10
|
+
backing: "group-hover/gridrow:opacity-[max(var(--vk-frozen-on,0),var(--vk-parked,0))]",
|
|
11
|
+
rule: "group-hover/gridrow:opacity-(--vk-parked,0)",
|
|
12
|
+
},
|
|
13
|
+
head: {
|
|
14
|
+
backing: "group-hover/gridhead:opacity-[max(var(--vk-frozen-on,0),var(--vk-parked,0))]",
|
|
15
|
+
rule: "group-hover/gridhead:opacity-(--vk-parked,0)",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
function RailSlot({ selecting, selected = false, bordered = false, reveal, children, }) {
|
|
19
|
+
return (_jsx("div", { "data-slot": "vk-grid-rail", role: children ? (reveal === "head" ? "columnheader" : "gridcell") : undefined, "aria-colindex": children ? 1 : undefined, "aria-hidden": children ? undefined : true, className: cx("sticky left-(--vk-rail-w) z-10 h-full", "after:pointer-events-none after:absolute after:inset-y-0 after:left-(--vk-frozen-w,0px) after:w-1.5 after:content-['']", "after:bg-linear-to-r after:from-black/15 after:to-transparent dark:after:from-black/60", "after:opacity-[calc(var(--vk-parked,0)*var(--vk-frozen-on,0))] after:transition-opacity after:duration-150"), "data-action-menu": true, onClick: (e) => e.stopPropagation(), children: _jsxs("div", { "data-row-check": selecting ? "" : undefined, className: cx("relative flex h-full w-[calc(var(--vk-gutter,0px)+var(--vk-indent,0px))] -translate-x-full items-start justify-end", "pr-[calc(var(--vk-rail-gap)+((var(--vk-rail-w)-16px)/2-var(--vk-rail-gap))*var(--vk-parked,0)*(1-var(--vk-frozen-on,0)))]", "transition-[padding-right] duration-150"), children: [_jsx("span", { "aria-hidden": true, className: cx("absolute inset-0", gridFrozenBg(selected), "opacity-(--vk-frozen-on,0) transition-opacity duration-150", reveal && HOVER_RAISE[reveal].backing, "group-data-[rail=on]/gridtable:opacity-100") }), bordered && (_jsx("span", { "aria-hidden": true, className: cx("pointer-events-none absolute inset-x-0 bottom-0 h-px bg-(color:--vk-border-subtle) transition-opacity duration-150", "opacity-[calc(var(--vk-parked,0)*var(--vk-frozen-on,0))]", reveal && HOVER_RAISE[reveal].rule, "group-data-[rail=on]/gridtable:opacity-(--vk-parked,0)") })), children ? (_jsx("span", { "data-row-check": true, className: "relative flex h-full items-center", children: children })) : null] }) }));
|
|
10
20
|
}
|
|
11
21
|
export function GridRailSpacer({ selecting, bordered = false, }) {
|
|
12
22
|
return _jsx(RailSlot, { selecting: selecting, bordered: bordered });
|
|
13
23
|
}
|
|
14
24
|
export function GridRowCheck({ selecting, checked, revealed, onChange, "aria-label": ariaLabel, }) {
|
|
15
|
-
return (_jsx(RailSlot, { selecting: selecting, selected: checked, bordered: true, children: _jsx(SelectCheckbox, { checked: checked, revealed: revealed, onChange: onChange, "aria-label": ariaLabel, className: cx(GRID_GROUND, "transition-opacity duration-150 group-hover/gridrow:opacity-100 group-data-[rail=on]/gridtable:opacity-100") }) }));
|
|
25
|
+
return (_jsx(RailSlot, { selecting: selecting, selected: checked, bordered: true, reveal: "row", children: _jsx(SelectCheckbox, { checked: checked, revealed: revealed, onChange: onChange, "aria-label": ariaLabel, tabIndex: -1, className: cx(GRID_GROUND, "transition-opacity duration-150 group-hover/gridrow:opacity-100 group-data-[rail=on]/gridtable:opacity-100 focus-visible:opacity-100") }) }));
|
|
16
26
|
}
|
|
17
27
|
export function GridHeadCheck({ selecting, allSelected, someSelected, onToggle, "aria-label": ariaLabel, }) {
|
|
18
28
|
const { Checkbox } = useViews().components;
|
|
19
|
-
return (_jsx(RailSlot, { selecting: selecting, bordered: true, children: _jsx(Checkbox, { checked: allSelected, indeterminate: !allSelected && someSelected, onCheckedChange: (next) => onToggle(next), "aria-label": ariaLabel, partialTone: "brand", className: cx(cx(GRID_GROUND, "transition-opacity duration-150"), selecting || allSelected || someSelected
|
|
29
|
+
return (_jsx(RailSlot, { selecting: selecting, bordered: true, reveal: "head", children: _jsx(Checkbox, { checked: allSelected, indeterminate: !allSelected && someSelected, onCheckedChange: (next) => onToggle(next), "aria-label": ariaLabel, tabIndex: -1, partialTone: "brand", className: cx(cx(GRID_GROUND, "transition-opacity duration-150"), selecting || allSelected || someSelected
|
|
20
30
|
? "opacity-100"
|
|
21
|
-
: "opacity-0 group-hover/gridhead:opacity-100 group-data-[rail=on]/gridtable:opacity-100") }) }));
|
|
31
|
+
: "opacity-0 group-hover/gridhead:opacity-100 group-data-[rail=on]/gridtable:opacity-100 focus-visible:opacity-100") }) }));
|
|
22
32
|
}
|
|
@@ -6,4 +6,4 @@ export { GridChipsEditor } from "./GridChipsEditor.js";
|
|
|
6
6
|
export { GridNumberEditor } from "./GridNumberEditor.js";
|
|
7
7
|
export { GridRangeEditor } from "./GridRangeEditor.js";
|
|
8
8
|
export { GridDateEditor } from "./GridDateEditor.js";
|
|
9
|
-
export { GridRelationEditor } from "./GridRelationEditor.js";
|
|
9
|
+
export { GridRelationEditor, GridRelationSetEditor } from "./GridRelationEditor.js";
|
|
@@ -7,4 +7,4 @@ export { GridChipsEditor } from "./GridChipsEditor.js";
|
|
|
7
7
|
export { GridNumberEditor } from "./GridNumberEditor.js";
|
|
8
8
|
export { GridRangeEditor } from "./GridRangeEditor.js";
|
|
9
9
|
export { GridDateEditor } from "./GridDateEditor.js";
|
|
10
|
-
export { GridRelationEditor } from "./GridRelationEditor.js";
|
|
10
|
+
export { GridRelationEditor, GridRelationSetEditor } from "./GridRelationEditor.js";
|
|
@@ -5,8 +5,7 @@ import type { FieldSettlement } from "@viewkitjs/fields";
|
|
|
5
5
|
* Extracted from `GridRowCells` because that file is held under the line ceiling
|
|
6
6
|
* and the policy there is split, not raise — and because this is the one part
|
|
7
7
|
* of the cell that is pure: a dozen booleans in, a string out. That makes the
|
|
8
|
-
* geometry testable without rendering a grid
|
|
9
|
-
* mode, whose whole contract is "the unwrapped string is unchanged".
|
|
8
|
+
* geometry testable without rendering a grid.
|
|
10
9
|
*/
|
|
11
10
|
export type GridCellClassState = {
|
|
12
11
|
align?: "left" | "center" | "right";
|
|
@@ -24,9 +23,6 @@ export type GridCellClassState = {
|
|
|
24
23
|
/** Last visible column — its right border is always transparent. */
|
|
25
24
|
lastColumn: boolean;
|
|
26
25
|
verticalBorders: boolean;
|
|
27
|
-
/** Wrap mode: the cell grows with its content instead of clipping to one
|
|
28
|
-
* line, and its text top-aligns so line one still reads across the row. */
|
|
29
|
-
wrap: boolean;
|
|
30
26
|
/** The value is saved here but its provider has not accepted it yet (spec
|
|
31
27
|
* §11.2) — the one pending state the grid draws, beside `data-settlement`. */
|
|
32
28
|
settlement?: Extract<FieldSettlement, "requested">;
|
|
@@ -49,11 +45,9 @@ export declare function gridCellClassName(state: GridCellClassState): string;
|
|
|
49
45
|
* left edge stays aligned with the page content; pl includes --vk-indent (grouped tables shift
|
|
50
46
|
* right as one unit). The hover tint is FLAT and full-bleed, a one-stop background-IMAGE rather
|
|
51
47
|
* than a colour so it layers OVER the selected ground; the same string as GRID_FROZEN_HOVER, so
|
|
52
|
-
* pinned and scrolling cells tint the same.
|
|
53
|
-
* strip, so the checkbox lane and the title's hover actions sit beside line one. */
|
|
48
|
+
* pinned and scrolling cells tint the same. */
|
|
54
49
|
export declare function gridRowClassName(state: {
|
|
55
50
|
selected: boolean;
|
|
56
51
|
selectable: boolean;
|
|
57
|
-
wrapCells: boolean;
|
|
58
52
|
hostClass?: string;
|
|
59
53
|
}): string;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { ROW_NO_TEXT_SELECT } from "../../selection/row-click.js";
|
|
2
2
|
import { cx } from "../../internal/cx.js";
|
|
3
|
-
import { GRID_CELL_HOVER_SHADOW, gridFrozenBg } from "./GridCellOutline.js";
|
|
3
|
+
import { GRID_CELL_HOVER_RING, GRID_CELL_HOVER_SHADOW, gridFrozenBg } from "./GridCellOutline.js";
|
|
4
4
|
import { GRID_GROUND } from "./grid-styles.js";
|
|
5
5
|
const GRID_CELL_REQUESTED = "italic opacity-80";
|
|
6
6
|
export const GRID_TITLE_LINK_CLASS = "**:data-cell-open:underline-offset-2 [&_[data-cell-open]:hover]:text-(color:--vk-fg-brand) [&_[data-cell-open]:hover]:underline";
|
|
7
7
|
export const GRID_RANGE_TINT_CLASS = "pointer-events-none absolute left-0 top-0 -bottom-px -right-px -z-1 bg-(color:--vk-brand-subtlest)";
|
|
8
8
|
export function gridCellClassName(state) {
|
|
9
|
-
const { focused, editing, inRange, frozen, selected
|
|
10
|
-
return cx(state.settlement === "requested" && GRID_CELL_REQUESTED, "group/gridcell", "flex min-w-0 border-b border-r border-(color:--vk-border-subtle) px-(--vk-px) text-(length:--vk-text)",
|
|
11
|
-
? "min-h-(--vk-row-h) items-start py-(--vk-cell-py) leading-(--vk-line-h) [&>*:not(.absolute)]:min-h-(--vk-line-h)"
|
|
12
|
-
: "h-(--vk-row-h) items-center whitespace-nowrap", "scroll-mt-(--vk-scroll-mt)", "scroll-ml-[calc(var(--vk-rail-w)+var(--vk-frozen-w,0px))]", (!state.verticalBorders || state.lastColumn) && "border-r-transparent", state.align === "right" && "justify-end text-right tabular-nums", state.align === "center" && "justify-center text-center", frozen ? "sticky" : "relative", focused || editing || inRange ? "overflow-visible" : "overflow-hidden", frozen
|
|
9
|
+
const { focused, editing, inRange, frozen, selected } = state;
|
|
10
|
+
return cx(state.settlement === "requested" && GRID_CELL_REQUESTED, "group/gridcell", "outline-none", "flex min-w-0 border-b border-r border-(color:--vk-border-subtle) px-(--vk-px) text-(length:--vk-text)", "h-(--vk-row-h) items-center whitespace-nowrap", "scroll-mt-(--vk-scroll-mt)", "scroll-ml-[calc(var(--vk-rail-w)+var(--vk-frozen-w,0px))]", (!state.verticalBorders || state.lastColumn) && "border-r-transparent", state.align === "right" && "justify-end text-right tabular-nums", state.align === "center" && "justify-center text-center", frozen ? "sticky" : "relative", focused || editing || inRange ? "overflow-visible" : "overflow-hidden", frozen
|
|
13
11
|
? focused || editing
|
|
14
12
|
? "z-9"
|
|
15
13
|
: inRange
|
|
@@ -19,12 +17,16 @@ export function gridCellClassName(state) {
|
|
|
19
17
|
? "z-5"
|
|
20
18
|
: inRange
|
|
21
19
|
? "z-4"
|
|
22
|
-
: undefined, frozen && gridFrozenBg(selected), editing && GRID_GROUND, !focused &&
|
|
20
|
+
: undefined, frozen && gridFrozenBg(selected), editing && GRID_GROUND, !focused &&
|
|
21
|
+
!editing &&
|
|
22
|
+
!inRange &&
|
|
23
|
+
!state.isTitle &&
|
|
24
|
+
cx(GRID_CELL_HOVER_SHADOW, GRID_CELL_HOVER_RING), state.isTitle && GRID_TITLE_LINK_CLASS);
|
|
23
25
|
}
|
|
24
26
|
export function gridRowClassName(state) {
|
|
25
|
-
const { selected, selectable,
|
|
27
|
+
const { selected, selectable, hostClass } = state;
|
|
26
28
|
const hostPaintsGround = hostClass != null && /(?:^|\s)bg-/.test(hostClass);
|
|
27
|
-
return cx("group/gridrow relative grid cursor-pointer pl-[calc(var(--vk-gutter,0px)+var(--vk-indent,0px))] pr-(--vk-gutter,0px)", selectable && ROW_NO_TEXT_SELECT,
|
|
29
|
+
return cx("group/gridrow relative grid grid-cols-(--vk-cols) cursor-pointer pl-[calc(var(--vk-gutter,0px)+var(--vk-indent,0px))] pr-(--vk-gutter,0px)", selectable && ROW_NO_TEXT_SELECT, selected
|
|
28
30
|
? "hover:bg-[linear-gradient(color-mix(in_oklab,_var(--vk-brand)_10%,_transparent),color-mix(in_oklab,_var(--vk-brand)_10%,_transparent))]"
|
|
29
31
|
: "hover:bg-[linear-gradient(var(--vk-hovered),var(--vk-hovered))]", selected && !hostPaintsGround && "bg-(color:--vk-brand-subtlest)", hostClass);
|
|
30
32
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An email, phone, url or domain drawn in a grid cell (`hostOwnsPlainClick`): a link that is part of its cell, not a
|
|
3
|
+
* control beside it. A plain click on it is a click on the cell (it selects, a second click edits, and the link is
|
|
4
|
+
* not followed); a ⌘- or Ctrl-click follows it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const GRID_CELL_LINK = "[data-cell-link]";
|
|
7
|
+
/**
|
|
8
|
+
* The control a press landed on, which handles the press itself: the nearest real control, unless that is one of
|
|
9
|
+
* the cell's own links (`GRID_CELL_LINK`), which the cell handles as itself. Null when the press is the cell's.
|
|
10
|
+
*/
|
|
11
|
+
export declare function gridControlAt(target: HTMLElement): Element | null;
|
|
12
|
+
/** The cell link a press landed on, or null. */
|
|
13
|
+
export declare function gridCellLinkAt(target: HTMLElement): Element | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ROW_INTERACTIVE_SELECTOR } from "../../selection/row-click.js";
|
|
2
|
+
export const GRID_CELL_LINK = "[data-cell-link]";
|
|
3
|
+
export function gridControlAt(target) {
|
|
4
|
+
const hit = target.closest(ROW_INTERACTIVE_SELECTOR);
|
|
5
|
+
return hit && !hit.matches(GRID_CELL_LINK) ? hit : null;
|
|
6
|
+
}
|
|
7
|
+
export function gridCellLinkAt(target) {
|
|
8
|
+
return target.closest(GRID_CELL_LINK);
|
|
9
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from "react";
|
|
2
|
+
import type { CloseReason, CloseResolution } from "@viewkitjs/fields";
|
|
3
|
+
import { type EditSession } from "../../editors/edit-session.js";
|
|
4
|
+
/** The gap a grid editor waits after its sheet closes before it writes: a sheet slides away for
|
|
5
|
+
* about half a second, and the popover's 160 ms would unmount it mid-slide. */
|
|
6
|
+
export declare const GRID_SHEET_EXIT_MS = 500;
|
|
7
|
+
type Handle<P> = {
|
|
8
|
+
resolveClose: (reason: CloseReason) => CloseResolution<P>;
|
|
9
|
+
};
|
|
10
|
+
export type GridEditSessionArgs<P> = {
|
|
11
|
+
editorRef: RefObject<Handle<P> | null>;
|
|
12
|
+
/** Reshapes a commit before it is judged and written (a day field's timestamp trimmed to its day). */
|
|
13
|
+
mapPayload?: (payload: P) => unknown;
|
|
14
|
+
/** A type-in that stays in the cell on a desktop: its write lands at once, before the focus moves,
|
|
15
|
+
* so a click on another cell finds it done. Elsewhere the write waits for the exit. */
|
|
16
|
+
inPlace?: boolean;
|
|
17
|
+
/** The grid's own judgement of the value it is about to write: its reason when the grid would
|
|
18
|
+
* refuse it, or null. A refused value keeps the editor open with that reason. */
|
|
19
|
+
refuse?: (payload: unknown) => string | null;
|
|
20
|
+
onCommit: (payload: unknown) => void;
|
|
21
|
+
onCancel: () => void;
|
|
22
|
+
onTab?: (backwards: boolean) => void;
|
|
23
|
+
onEnter?: () => void;
|
|
24
|
+
};
|
|
25
|
+
export type GridEditSession = {
|
|
26
|
+
/** For `EditorPanel`: its own closes (the popover's dismissals, the sheet's ✕ and ✓) move no focus. */
|
|
27
|
+
session: EditSession;
|
|
28
|
+
/** For the editor's `onRequestClose`: Enter and Tab move the focus after the write, and in the
|
|
29
|
+
* sheet a blur is no close (tapping ✕ or ✓ blurs the box first). */
|
|
30
|
+
close: (reason: CloseReason) => void;
|
|
31
|
+
/** The edit opened in the sheet: the screen was not a desktop when it opened. Read once, as the
|
|
32
|
+
* panel reads it, so the gap matches the panel the edit opened in. */
|
|
33
|
+
sheet: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Runs one grid edit through the shared session, in its admitted mode. A close asks the editor for
|
|
37
|
+
* its answer (Escape is always a discard); a commit the grid would refuse stays open with its reason.
|
|
38
|
+
* An accepted answer is written at once by an in-place type-in on a desktop, and after the exit gap
|
|
39
|
+
* otherwise, so the popover or the sheet plays out before the cell repaints; on a desktop, Enter or
|
|
40
|
+
* Tab moves the focus at once all the same, and a key in the gap writes the answer first. Left mid-exit (the cell
|
|
41
|
+
* unmounted first), the answer is still written, and the focus stays where the person put it. Left
|
|
42
|
+
* while a refusal stands (another cell clicked), nothing is written and the reason is said in a toast,
|
|
43
|
+
* as the grid says every refusal it can't show in an editor.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useGridEditSession<P>(args: GridEditSessionArgs<P>): GridEditSession;
|
|
46
|
+
/**
|
|
47
|
+
* The value of a cell whose type-in is open: hidden where the editor stands in the cell (a desktop),
|
|
48
|
+
* drawn where it opened in the sheet (a phone), so the row behind the sheet still says what is being
|
|
49
|
+
* changed. Mounted only in the editing cell, and read once, at open, as the session and the panel
|
|
50
|
+
* read it, so all three agree on where the edit opened.
|
|
51
|
+
*/
|
|
52
|
+
export declare function GridValueUnderEditor({ children }: {
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
}): ReactNode;
|
|
55
|
+
/** Where a line hung under a type-in's cell sits: from the cell's left, or ending at its right where the left would run
|
|
56
|
+
* out of sight (`useKeepInside`). */
|
|
57
|
+
export declare const UNDER_CELL_CLASS = "absolute left-0 top-full z-90 mt-1 whitespace-nowrap rounded-md border border-(color:--vk-border) bg-(color:--vk-overlay) px-2 py-1 shadow-sm data-[side=end]:left-auto data-[side=end]:right-0";
|
|
58
|
+
/** A type-in's refusal, drawn under the cell it is typed in: in place there is no panel to hold it,
|
|
59
|
+
* and the editing cell drops its clip, so it hangs below the box. */
|
|
60
|
+
export declare function GridRefusal({ reason }: {
|
|
61
|
+
reason: string | null;
|
|
62
|
+
}): ReactNode;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useAnchoredEditSession } from "../../editors/edit-session.js";
|
|
5
|
+
import { useKeepInside } from "../../editors/keep-inside.js";
|
|
6
|
+
import { useViews } from "../../provider/context.js";
|
|
7
|
+
import { useDesktop } from "../../provider/desktop.js";
|
|
8
|
+
export const GRID_SHEET_EXIT_MS = 500;
|
|
9
|
+
export function useGridEditSession(args) {
|
|
10
|
+
const { editorRef, mapPayload, inPlace = false } = args;
|
|
11
|
+
const desktop = useDesktop();
|
|
12
|
+
const { ports } = useViews();
|
|
13
|
+
const [sheet] = useState(!desktop);
|
|
14
|
+
const latest = useRef(args);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
latest.current = args;
|
|
17
|
+
});
|
|
18
|
+
const viaRef = useRef(null);
|
|
19
|
+
const keptRef = useRef(null);
|
|
20
|
+
const refusedRef = useRef(null);
|
|
21
|
+
const movedRef = useRef(false);
|
|
22
|
+
const flushRef = useRef(null);
|
|
23
|
+
const stopFlush = () => {
|
|
24
|
+
if (flushRef.current)
|
|
25
|
+
document.removeEventListener("keydown", flushRef.current, true);
|
|
26
|
+
flushRef.current = null;
|
|
27
|
+
};
|
|
28
|
+
const move = () => {
|
|
29
|
+
const { onTab, onEnter } = latest.current;
|
|
30
|
+
if (viaRef.current === "enter")
|
|
31
|
+
onEnter?.();
|
|
32
|
+
if (viaRef.current === "tab")
|
|
33
|
+
onTab?.(false);
|
|
34
|
+
if (viaRef.current === "shift-tab")
|
|
35
|
+
onTab?.(true);
|
|
36
|
+
};
|
|
37
|
+
const write = (answer, moveFocus) => {
|
|
38
|
+
keptRef.current = null;
|
|
39
|
+
stopFlush();
|
|
40
|
+
const { onCommit, onCancel } = latest.current;
|
|
41
|
+
if (answer.kind === "commit")
|
|
42
|
+
onCommit(answer.payload);
|
|
43
|
+
else
|
|
44
|
+
onCancel();
|
|
45
|
+
if (moveFocus && !movedRef.current)
|
|
46
|
+
move();
|
|
47
|
+
};
|
|
48
|
+
const keep = (answer) => {
|
|
49
|
+
keptRef.current = answer;
|
|
50
|
+
if (sheet || (viaRef.current !== "enter" && viaRef.current !== "tab" && viaRef.current !== "shift-tab"))
|
|
51
|
+
return;
|
|
52
|
+
movedRef.current = true;
|
|
53
|
+
move();
|
|
54
|
+
const flush = () => {
|
|
55
|
+
if (keptRef.current)
|
|
56
|
+
write(keptRef.current, false);
|
|
57
|
+
else
|
|
58
|
+
stopFlush();
|
|
59
|
+
};
|
|
60
|
+
flushRef.current = flush;
|
|
61
|
+
document.addEventListener("keydown", flush, true);
|
|
62
|
+
};
|
|
63
|
+
const session = useAnchoredEditSession({
|
|
64
|
+
editorRef,
|
|
65
|
+
mapPayload,
|
|
66
|
+
exitMs: sheet ? GRID_SHEET_EXIT_MS : undefined,
|
|
67
|
+
onAttempt: (answer) => {
|
|
68
|
+
const reason = answer.kind === "commit" ? (latest.current.refuse?.(answer.payload) ?? null) : null;
|
|
69
|
+
refusedRef.current = reason;
|
|
70
|
+
if (reason !== null)
|
|
71
|
+
return { accepted: false, reason };
|
|
72
|
+
if (inPlace && !sheet)
|
|
73
|
+
write(answer, true);
|
|
74
|
+
else
|
|
75
|
+
keep(answer);
|
|
76
|
+
return { accepted: true };
|
|
77
|
+
},
|
|
78
|
+
onClose: () => {
|
|
79
|
+
if (keptRef.current)
|
|
80
|
+
write(keptRef.current, true);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
useEffect(() => () => {
|
|
84
|
+
if (keptRef.current)
|
|
85
|
+
write(keptRef.current, false);
|
|
86
|
+
else if (refusedRef.current)
|
|
87
|
+
ports.toast.error(refusedRef.current);
|
|
88
|
+
stopFlush();
|
|
89
|
+
}, []);
|
|
90
|
+
const close = (reason) => {
|
|
91
|
+
if (sheet && reason === "blur")
|
|
92
|
+
return;
|
|
93
|
+
viaRef.current = reason;
|
|
94
|
+
session.close(reason);
|
|
95
|
+
};
|
|
96
|
+
const closeFromPanel = (reason) => {
|
|
97
|
+
if (session.open)
|
|
98
|
+
viaRef.current = null;
|
|
99
|
+
session.close(reason);
|
|
100
|
+
};
|
|
101
|
+
return { session: { ...session, close: closeFromPanel }, close, sheet };
|
|
102
|
+
}
|
|
103
|
+
export function GridValueUnderEditor({ children }) {
|
|
104
|
+
const desktop = useDesktop();
|
|
105
|
+
const [sheet] = useState(!desktop);
|
|
106
|
+
return sheet ? children : null;
|
|
107
|
+
}
|
|
108
|
+
export const UNDER_CELL_CLASS = "absolute left-0 top-full z-90 mt-1 whitespace-nowrap rounded-md border border-(color:--vk-border) bg-(color:--vk-overlay) px-2 py-1 shadow-sm data-[side=end]:left-auto data-[side=end]:right-0";
|
|
109
|
+
export function GridRefusal({ reason }) {
|
|
110
|
+
if (!reason)
|
|
111
|
+
return null;
|
|
112
|
+
return _jsx(Refusal, { reason: reason });
|
|
113
|
+
}
|
|
114
|
+
function Refusal({ reason }) {
|
|
115
|
+
const ref = useRef(null);
|
|
116
|
+
useKeepInside(ref);
|
|
117
|
+
return (_jsx("p", { ref: ref, role: "alert", "data-slot": "vk-editor-refusal", className: `${UNDER_CELL_CLASS} text-xs text-(color:--vk-danger)`, children: reason }));
|
|
118
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent } from "react";
|
|
2
|
+
import type { ListCellAction } from "../../model/column-schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* WHERE THE POINTER IS, for the two things a row draws only there: the name's
|
|
5
|
+
* actions (on the row under the pointer) and a pick-list's ▾ (on the cell under
|
|
6
|
+
* it). Every other row draws neither, so a table of thousands of rows carries
|
|
7
|
+
* one lane and one ▾, not one per row and per cell.
|
|
8
|
+
*
|
|
9
|
+
* One store per table. A row's pointer handlers write `{ rowKey, colId }`; the
|
|
10
|
+
* lane and the ▾ each subscribe with a selector that answers a boolean, so a
|
|
11
|
+
* pointer move redraws only the lane or ▾ whose answer changed, never a row.
|
|
12
|
+
* Without a store (a row drawn outside a table) nothing is drawn by hover.
|
|
13
|
+
*/
|
|
14
|
+
export type GridHoverTarget = {
|
|
15
|
+
rowKey: string;
|
|
16
|
+
colId: string | null;
|
|
17
|
+
};
|
|
18
|
+
export type GridHoverStore = {
|
|
19
|
+
get(): GridHoverTarget | null;
|
|
20
|
+
set(target: GridHoverTarget | null): void;
|
|
21
|
+
subscribe(listener: () => void): () => void;
|
|
22
|
+
};
|
|
23
|
+
export declare function createGridHoverStore(): GridHoverStore;
|
|
24
|
+
export declare const GridHoverContext: import("react").Context<GridHoverStore | null>;
|
|
25
|
+
/** Whether the pointer is over this row. */
|
|
26
|
+
export declare function useGridRowHovered(rowKey: string): boolean;
|
|
27
|
+
/** Whether the pointer is over this cell. */
|
|
28
|
+
export declare function useGridCellHovered(rowKey: string, colId: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The row's pointer handlers. A touch pointer names nothing: a tap is not a
|
|
31
|
+
* hover, and a phone draws neither copy. An event from a portalled child (a
|
|
32
|
+
* picker drawn into the body) bubbles through the row in React but is not over
|
|
33
|
+
* it on screen, so it clears the row instead of naming it.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useGridRowHoverHandlers(rowKey: string): {
|
|
36
|
+
onPointerOver(event: ReactPointerEvent<HTMLElement>): void;
|
|
37
|
+
onPointerLeave(event: ReactPointerEvent<HTMLElement>): void;
|
|
38
|
+
};
|
|
39
|
+
/** The name's action lane, drawn only on the row under the pointer. */
|
|
40
|
+
export declare function GridRowHoverActions<Row>({ rowKey, row, selected, actions, }: {
|
|
41
|
+
rowKey: string;
|
|
42
|
+
row: Row;
|
|
43
|
+
selected: boolean;
|
|
44
|
+
actions: ListCellAction<Row>[];
|
|
45
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
46
|
+
/**
|
|
47
|
+
* A pick-list's ▾: the cue that the value is a choice, and its one-click
|
|
48
|
+
* opener. A real button (the row's click contract lets real controls win), so
|
|
49
|
+
* clicking it opens the picker directly, with no select-first step. Drawn on the
|
|
50
|
+
* cell under the pointer, and on the cell whose picker is open, where it flips
|
|
51
|
+
* up as a native select does; clicking it then closes the picker (the click
|
|
52
|
+
* lands during the exit animation and can't reopen). Never drawn on a phone,
|
|
53
|
+
* where a tap selects the cell and a second opens its editor in a sheet.
|
|
54
|
+
*/
|
|
55
|
+
export declare function GridPickerCaret({ rowKey, colId, editing, onOpen, }: {
|
|
56
|
+
rowKey: string;
|
|
57
|
+
colId: string;
|
|
58
|
+
editing: boolean;
|
|
59
|
+
onOpen: () => void;
|
|
60
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useSyncExternalStore, } from "react";
|
|
4
|
+
import { cx } from "../../internal/cx.js";
|
|
5
|
+
import { useDesktop } from "../../provider/desktop.js";
|
|
6
|
+
import { useViews } from "../../provider/context.js";
|
|
7
|
+
import { GridRowActions } from "./GridRowActions.js";
|
|
8
|
+
export function createGridHoverStore() {
|
|
9
|
+
let current = null;
|
|
10
|
+
const listeners = new Set();
|
|
11
|
+
return {
|
|
12
|
+
get: () => current,
|
|
13
|
+
set(target) {
|
|
14
|
+
if (current?.rowKey === target?.rowKey && current?.colId === target?.colId)
|
|
15
|
+
return;
|
|
16
|
+
current = target;
|
|
17
|
+
for (const listener of listeners)
|
|
18
|
+
listener();
|
|
19
|
+
},
|
|
20
|
+
subscribe(listener) {
|
|
21
|
+
listeners.add(listener);
|
|
22
|
+
return () => listeners.delete(listener);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export const GridHoverContext = createContext(null);
|
|
27
|
+
const NO_STORE = () => () => { };
|
|
28
|
+
function useHovered(answer) {
|
|
29
|
+
const store = useContext(GridHoverContext);
|
|
30
|
+
return useSyncExternalStore(store ? store.subscribe : NO_STORE, () => (store ? answer(store.get()) : false), () => false);
|
|
31
|
+
}
|
|
32
|
+
export function useGridRowHovered(rowKey) {
|
|
33
|
+
return useHovered((target) => target?.rowKey === rowKey);
|
|
34
|
+
}
|
|
35
|
+
export function useGridCellHovered(rowKey, colId) {
|
|
36
|
+
return useHovered((target) => target?.rowKey === rowKey && target.colId === colId);
|
|
37
|
+
}
|
|
38
|
+
export function useGridRowHoverHandlers(rowKey) {
|
|
39
|
+
const store = useContext(GridHoverContext);
|
|
40
|
+
const clearOwn = () => {
|
|
41
|
+
if (store?.get()?.rowKey === rowKey)
|
|
42
|
+
store.set(null);
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
onPointerOver(event) {
|
|
46
|
+
if (!store || event.pointerType === "touch")
|
|
47
|
+
return;
|
|
48
|
+
const row = event.currentTarget;
|
|
49
|
+
const target = event.target;
|
|
50
|
+
if (!row.contains(target)) {
|
|
51
|
+
clearOwn();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const from = target instanceof Element ? target : target.parentElement;
|
|
55
|
+
const cell = from?.closest("[data-col-id]");
|
|
56
|
+
store.set({ rowKey, colId: cell && row.contains(cell) ? cell.getAttribute("data-col-id") : null });
|
|
57
|
+
},
|
|
58
|
+
onPointerLeave: clearOwn,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function GridRowHoverActions({ rowKey, row, selected, actions, }) {
|
|
62
|
+
if (!useGridRowHovered(rowKey))
|
|
63
|
+
return null;
|
|
64
|
+
return _jsx(GridRowActions, { row: row, selected: selected, actions: actions });
|
|
65
|
+
}
|
|
66
|
+
export function GridPickerCaret({ rowKey, colId, editing, onOpen, }) {
|
|
67
|
+
const hovered = useGridCellHovered(rowKey, colId);
|
|
68
|
+
if (!hovered && !editing)
|
|
69
|
+
return null;
|
|
70
|
+
return _jsx(PickerCaretButton, { editing: editing, onOpen: onOpen });
|
|
71
|
+
}
|
|
72
|
+
function PickerCaretButton({ editing, onOpen }) {
|
|
73
|
+
const { icons, messages } = useViews();
|
|
74
|
+
if (!useDesktop())
|
|
75
|
+
return null;
|
|
76
|
+
return (_jsx("button", { type: "button", tabIndex: -1, "aria-label": messages({ key: "views.grid.change-value" }), onClick: (e) => {
|
|
77
|
+
e.stopPropagation();
|
|
78
|
+
if (!editing)
|
|
79
|
+
onOpen();
|
|
80
|
+
}, className: cx("absolute right-1 top-1/2 flex h-5 w-5 -translate-y-1/2 items-center justify-center hover:text-(color:--vk-fg)", editing ? "text-(color:--vk-fg)" : "text-(color:--vk-fg-subtlest)"), children: _jsx(icons.caretDown, { className: cx("h-3 w-3 transition-transform duration-100", editing && "rotate-180") }) }));
|
|
81
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Gives the focus back to `anchor` when a menu that opened from it has closed, and only where the focus had nowhere
|
|
4
|
+
* else to go. Focus on the body goes back at once. Focus still inside a popup (an app's popover that plays its exit
|
|
5
|
+
* stays on the page, the focus in it, after it closed) goes back once that element has left the page, if the focus
|
|
6
|
+
* then fell to the body: a popup with no trigger, as the grid's are, gives it back to nothing. Focus a press or a
|
|
7
|
+
* pick moved elsewhere (another cell, a dialog a pick opened) stays there.
|
|
8
|
+
*
|
|
9
|
+
* A cell inside an inert subtree can't take the focus: a list that reloads on a pick (a sort) holds the table it is
|
|
10
|
+
* leaving `inert`, the same cells, until the new rows are in. The focus then goes back once the cell is out of it, if
|
|
11
|
+
* it is still on nothing. Returns what stops the watch: a reopen, or the grid leaving the page.
|
|
12
|
+
*/
|
|
13
|
+
export declare function returnGridFocus(anchor: HTMLElement): () => void;
|
|
14
|
+
/**
|
|
15
|
+
* ↓ and ↑ for a grid menu's rows: the `onKeyDown` of the box that holds them. They move the focus to the next or the
|
|
16
|
+
* previous enabled row, round at either end, from the focused one (from outside them, ↓ to the first and ↑ to the
|
|
17
|
+
* last). Only the box's own rows answer: a flyout's popup, drawn elsewhere on the page, keeps its keys.
|
|
18
|
+
*
|
|
19
|
+
* A menu whose first rows sit in a searchable list hands its search field in as `search`: the field is then the
|
|
20
|
+
* walk's first stop, standing for the list, and a key that starts in it is the field's (`gridMenuSearchArrows`).
|
|
21
|
+
* Coming into the field, the walk moves the list's highlight to the end it enters from, ↓ (round from the last row)
|
|
22
|
+
* to the first match and ↑ (from the row below) to the last, by the Home and End a cmdk list answers; left on the
|
|
23
|
+
* other end, the field would hand the next key straight back. A list that doesn't answer them keeps its highlight.
|
|
24
|
+
*/
|
|
25
|
+
export declare function gridMenuArrows(event: ReactKeyboardEvent<HTMLElement>, search?: HTMLElement | null): void;
|
|
26
|
+
/**
|
|
27
|
+
* ↓ and ↑ in a grid menu's search field, its `onKeyDown`: the list walks its own matches, and at its ends the walk
|
|
28
|
+
* goes on through the menu's other rows in `box`, ↓ past the last match (or with none) to the first row and ↑ past
|
|
29
|
+
* the first match round to the last. The default is prevented there, so the list's own arrows stay still. The match
|
|
30
|
+
* the list has highlighted is the option the field names in `aria-activedescendant`, as a combobox does; a list that
|
|
31
|
+
* names none keeps its arrows, and Tab leaves it.
|
|
32
|
+
*/
|
|
33
|
+
export declare function gridMenuSearchArrows(event: ReactKeyboardEvent<HTMLElement>, box: HTMLElement | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* Focus for a menu the grid's chrome opens (a column's menu, a footer's figure picker, a group's ⋯): opened by a key
|
|
36
|
+
* (a click with no pointer behind it, `detail === 0`, which is what the grid's Enter and Space send), it opens with
|
|
37
|
+
* focus on its first row; opened by a pointer, as it always has, with nothing focused. Closed, it gives the focus back
|
|
38
|
+
* to its cell where it had nowhere else to go (`returnGridFocus`).
|
|
39
|
+
*/
|
|
40
|
+
export declare function useGridMenuFocus(open: boolean, anchor: HTMLElement | null): {
|
|
41
|
+
initialFocus: boolean;
|
|
42
|
+
noteOpen: (event: ReactMouseEvent) => void;
|
|
43
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
3
|
+
const POPUP = '[role="dialog"], [role="menu"]';
|
|
4
|
+
const onNothing = (active) => active == null || active === document.body;
|
|
5
|
+
export function returnGridFocus(anchor) {
|
|
6
|
+
const held = document.activeElement;
|
|
7
|
+
const waitsOnPopup = !onNothing(held) && !!held?.closest?.(POPUP);
|
|
8
|
+
if (!onNothing(held) && !waitsOnPopup)
|
|
9
|
+
return () => { };
|
|
10
|
+
const giveBack = () => {
|
|
11
|
+
if (waitsOnPopup && held.isConnected)
|
|
12
|
+
return false;
|
|
13
|
+
if (!onNothing(document.activeElement) || !anchor.isConnected)
|
|
14
|
+
return true;
|
|
15
|
+
if (anchor.closest("[inert]"))
|
|
16
|
+
return false;
|
|
17
|
+
anchor.focus({ preventScroll: true });
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
if (giveBack() || typeof MutationObserver === "undefined")
|
|
21
|
+
return () => { };
|
|
22
|
+
const stop = () => {
|
|
23
|
+
watch.disconnect();
|
|
24
|
+
document.removeEventListener("focusin", stop, true);
|
|
25
|
+
};
|
|
26
|
+
const watch = new MutationObserver(() => {
|
|
27
|
+
if (!giveBack())
|
|
28
|
+
return;
|
|
29
|
+
stop();
|
|
30
|
+
});
|
|
31
|
+
watch.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ["inert"] });
|
|
32
|
+
document.addEventListener("focusin", stop, true);
|
|
33
|
+
return stop;
|
|
34
|
+
}
|
|
35
|
+
const isArrow = (event) => (event.key === "ArrowDown" || event.key === "ArrowUp") && !(event.altKey || event.ctrlKey || event.metaKey || event.shiftKey);
|
|
36
|
+
const menuRows = (box) => [...box.querySelectorAll("button:not(:disabled)")];
|
|
37
|
+
export function gridMenuArrows(event, search) {
|
|
38
|
+
if (!isArrow(event))
|
|
39
|
+
return;
|
|
40
|
+
const box = event.currentTarget;
|
|
41
|
+
if (!box.contains(event.target))
|
|
42
|
+
return;
|
|
43
|
+
if (search?.contains(event.target))
|
|
44
|
+
return;
|
|
45
|
+
const rows = search?.isConnected ? [search, ...menuRows(box)] : menuRows(box);
|
|
46
|
+
if (rows.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
const at = rows.indexOf(document.activeElement);
|
|
50
|
+
const down = event.key === "ArrowDown";
|
|
51
|
+
const next = at < 0 ? (down ? 0 : rows.length - 1) : (at + (down ? 1 : -1) + rows.length) % rows.length;
|
|
52
|
+
const row = rows[next];
|
|
53
|
+
row.focus();
|
|
54
|
+
if (row === search) {
|
|
55
|
+
row.dispatchEvent(new KeyboardEvent("keydown", { key: down ? "Home" : "End", bubbles: true, cancelable: true }));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function gridMenuSearchArrows(event, box) {
|
|
59
|
+
if (!box || !isArrow(event))
|
|
60
|
+
return;
|
|
61
|
+
const rows = menuRows(box);
|
|
62
|
+
if (rows.length === 0)
|
|
63
|
+
return;
|
|
64
|
+
const down = event.key === "ArrowDown";
|
|
65
|
+
const matches = [...box.querySelectorAll('[role="option"]:not([aria-disabled="true"])')];
|
|
66
|
+
if (matches.length > 0) {
|
|
67
|
+
const named = event.currentTarget.getAttribute("aria-activedescendant");
|
|
68
|
+
if (!named)
|
|
69
|
+
return;
|
|
70
|
+
const at = matches.findIndex((match) => match.id === named);
|
|
71
|
+
if (at !== (down ? matches.length - 1 : 0))
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
(down ? rows[0] : rows[rows.length - 1]).focus();
|
|
76
|
+
}
|
|
77
|
+
export function useGridMenuFocus(open, anchor) {
|
|
78
|
+
const [byKey, setByKey] = useState(false);
|
|
79
|
+
const wasOpen = useRef(false);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (open) {
|
|
82
|
+
wasOpen.current = true;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!wasOpen.current)
|
|
86
|
+
return;
|
|
87
|
+
wasOpen.current = false;
|
|
88
|
+
if (anchor)
|
|
89
|
+
return returnGridFocus(anchor);
|
|
90
|
+
}, [open, anchor]);
|
|
91
|
+
const noteOpen = useCallback((event) => setByKey(event.detail === 0), []);
|
|
92
|
+
return { initialFocus: byKey, noteOpen };
|
|
93
|
+
}
|