@viewkitjs/views 0.1.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 +767 -1
- package/README.md +92 -41
- package/dist/atoms/LoadMore.js +11 -1
- package/dist/atoms/Row.js +1 -1
- package/dist/atoms/RowMenu.d.ts +1 -1
- package/dist/atoms/RowMenu.js +20 -6
- package/dist/atoms/types.d.ts +4 -4
- 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 +79 -8
- package/dist/contract.js +55 -8
- package/dist/display/converted.d.ts +19 -0
- package/dist/display/converted.js +12 -0
- package/dist/display/format.d.ts +16 -1
- package/dist/display/format.js +10 -1
- package/dist/display/index.d.ts +2 -1
- package/dist/display/index.js +2 -1
- package/dist/display/link-click.d.ts +11 -0
- package/dist/display/link-click.js +3 -0
- package/dist/display/link.js +12 -6
- package/dist/display/location.d.ts +4 -3
- package/dist/display/location.js +12 -5
- package/dist/display/multi-value.d.ts +1 -1
- package/dist/display/multi-value.js +1 -1
- package/dist/display/options.d.ts +8 -2
- package/dist/display/percent.js +10 -3
- package/dist/display/phone.d.ts +2 -1
- package/dist/display/phone.js +11 -2
- package/dist/display/relation.js +1 -1
- package/dist/editors/ChipsEditor.d.ts +9 -4
- package/dist/editors/ChipsEditor.js +7 -3
- 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 +28 -21
- package/dist/editors/NameEditor.d.ts +3 -0
- package/dist/editors/NameEditor.js +15 -10
- package/dist/editors/NumberEditor.d.ts +3 -0
- package/dist/editors/NumberEditor.js +7 -7
- package/dist/editors/RangeEditor.d.ts +16 -1
- package/dist/editors/RangeEditor.js +22 -6
- 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 +5 -2
- package/dist/editors/ValueListEditor.js +11 -9
- package/dist/editors/edit-cores.d.ts +13 -10
- 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 +7 -2
- package/dist/fields/binding.js +13 -6
- package/dist/fields/currency.d.ts +0 -10
- package/dist/fields/currency.js +0 -14
- 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 +6 -0
- package/dist/fields/money.js +11 -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/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 +29 -0
- package/dist/grid/chrome/GridCellEditors.d.ts +71 -0
- package/dist/grid/chrome/GridCellEditors.js +126 -0
- package/dist/grid/chrome/GridCellOutline.d.ts +49 -0
- package/dist/grid/chrome/GridCellOutline.js +16 -0
- package/dist/grid/chrome/GridChipsEditor.d.ts +38 -0
- package/dist/grid/chrome/GridChipsEditor.js +35 -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 +103 -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 +34 -0
- package/dist/grid/chrome/GridDateEditor.js +19 -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 +33 -0
- package/dist/grid/chrome/GridFooter.js +85 -0
- package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
- package/dist/grid/chrome/GridGroupMenu.js +64 -0
- package/dist/grid/chrome/GridHeader.d.ts +66 -0
- package/dist/grid/chrome/GridHeader.js +42 -0
- package/dist/grid/chrome/GridLongTextEditor.d.ts +55 -0
- package/dist/grid/chrome/GridLongTextEditor.js +69 -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 +24 -0
- package/dist/grid/chrome/GridNameEditor.js +21 -0
- package/dist/grid/chrome/GridNumberEditor.d.ts +49 -0
- package/dist/grid/chrome/GridNumberEditor.js +51 -0
- package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
- package/dist/grid/chrome/GridPlaceEditor.js +22 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +30 -0
- package/dist/grid/chrome/GridRangeEditor.js +21 -0
- package/dist/grid/chrome/GridRelationEditor.d.ts +45 -0
- package/dist/grid/chrome/GridRelationEditor.js +92 -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 +31 -0
- package/dist/grid/chrome/GridRow.js +179 -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 +128 -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 +33 -0
- package/dist/grid/chrome/GridSelectEditor.js +43 -0
- package/dist/grid/chrome/GridStructure.d.ts +47 -0
- package/dist/grid/chrome/GridStructure.js +41 -0
- package/dist/grid/chrome/GridTable.d.ts +4 -0
- package/dist/grid/chrome/GridTable.js +192 -0
- package/dist/grid/chrome/GridTableSurface.d.ts +52 -0
- package/dist/grid/chrome/GridTableSurface.js +15 -0
- package/dist/grid/chrome/GridTextEditor.d.ts +45 -0
- package/dist/grid/chrome/GridTextEditor.js +38 -0
- package/dist/grid/chrome/GridValueListEditor.d.ts +30 -0
- package/dist/grid/chrome/GridValueListEditor.js +19 -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/cell-cut-off.d.ts +11 -0
- package/dist/grid/chrome/cell-cut-off.js +20 -0
- package/dist/grid/chrome/cells.d.ts +21 -0
- package/dist/grid/chrome/cells.js +19 -0
- package/dist/grid/chrome/checks.d.ts +32 -0
- package/dist/grid/chrome/checks.js +32 -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 +53 -0
- package/dist/grid/chrome/grid-cell-classes.js +32 -0
- 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-menu-search.d.ts +7 -0
- package/dist/grid/chrome/grid-menu-search.js +7 -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 +143 -0
- package/dist/grid/chrome/grid-row-props.js +1 -0
- 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 +40 -0
- package/dist/grid/chrome/grid-styles.js +9 -0
- package/dist/grid/chrome/grid-table-props.d.ts +172 -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/useGridFocus.d.ts +45 -0
- package/dist/grid/chrome/useGridFocus.js +122 -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 +64 -0
- package/dist/grid/chrome/useGridKeyboard.js +450 -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 +51 -0
- package/dist/grid/chrome/useGridRangeActions.js +195 -0
- package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
- package/dist/grid/chrome/useGridRangeGestures.js +237 -0
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +37 -0
- package/dist/grid/chrome/useGridRowContextMenu.js +153 -0
- package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -0
- package/dist/grid/chrome/useGridScaleStyles.js +28 -0
- package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
- package/dist/grid/chrome/useGridScrollArea.js +65 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +78 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +249 -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 +83 -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 +41 -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/edge-scroll.d.ts +21 -0
- package/dist/grid/core/edge-scroll.js +23 -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 +60 -0
- package/dist/grid/core/editing-controller.js +266 -0
- package/dist/grid/core/editing-model.d.ts +87 -0
- package/dist/grid/core/editing-model.js +148 -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/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 +53 -0
- package/dist/grid/core/pending-reconciliation.js +51 -0
- package/dist/grid/core/range-model.d.ts +25 -0
- package/dist/grid/core/range-model.js +59 -0
- 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 +101 -0
- package/dist/grid/core/spreadsheet-operations.js +280 -0
- package/dist/grid/core/useGridEditing.d.ts +46 -0
- package/dist/grid/core/useGridEditing.js +93 -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 +54 -0
- package/dist/grid/core/value-equality.js +80 -0
- package/dist/grid/index.d.ts +18 -0
- package/dist/grid/index.js +5 -0
- package/dist/grid/useGridTablePrefs.d.ts +49 -0
- package/dist/grid/useGridTablePrefs.js +99 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/viewport.d.ts +3 -0
- package/dist/internal/viewport.js +15 -0
- package/dist/model/column-capabilities.d.ts +3 -2
- 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-state.d.ts +1 -1
- package/dist/model/column-types.d.ts +3 -1
- package/dist/model/column-types.js +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 -7
- 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 +6 -2
- package/dist/provider/ViewsProvider.js +12 -2
- package/dist/provider/components.d.ts +35 -9
- package/dist/provider/components.js +4 -2
- package/dist/provider/context.d.ts +8 -4
- package/dist/provider/desktop.d.ts +9 -0
- package/dist/provider/desktop.js +22 -0
- package/dist/provider/menu-groups.d.ts +8 -0
- package/dist/provider/menu-groups.js +38 -0
- package/dist/provider/plain-input.d.ts +8 -0
- package/dist/provider/plain-input.js +5 -0
- package/dist/provider/ports.d.ts +22 -0
- package/dist/provider/ports.js +1 -0
- package/dist/react.d.ts +3 -2
- 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 +202 -72
- 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 +413 -0
- package/docs/guides/display.md +204 -0
- package/docs/guides/editors.md +462 -0
- package/docs/guides/ports.md +246 -0
- package/docs/guides/selection.md +270 -0
- package/docs/guides/the-grid.md +696 -0
- package/docs/guides/the-provider.md +448 -0
- package/docs/index.md +52 -0
- package/docs/install.md +9 -47
- package/docs/reference/cells.md +28 -0
- package/docs/reference/display.md +44 -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 +10 -0
- package/docs/reference/editors-panel.md +12 -0
- package/docs/reference/editors-range.md +6 -0
- package/docs/reference/editors-relation.md +12 -0
- package/docs/reference/editors-select.md +9 -0
- package/docs/reference/editors-session.md +11 -0
- package/docs/reference/editors-text.md +9 -0
- package/docs/reference/editors-value-list.md +6 -0
- package/docs/reference/editors.md +5 -0
- package/docs/reference/field-row.md +16 -0
- package/docs/reference/grid.md +39 -0
- package/docs/reference/react.md +89 -0
- package/docs/reference/selection.md +33 -0
- package/docs/reference/views.md +622 -0
- package/package.json +27 -4
- 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,206 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo, useRef, useState, } from "react";
|
|
3
|
+
import { baseColumnOrder, columnPlacedByView, resolveViewColumnOrder, } from "../../model/column-capabilities.js";
|
|
4
|
+
import { gridWidthVar } from "../core/grid-scale.js";
|
|
5
|
+
import { clampColumnWidth, columnHideable, isColumnHidden, prettifyOptionValue, resolveColumnOrder, resolveColumnWidths, resolveVisibleColumns, toggleColumnHidden, } from "../../model/column-state.js";
|
|
6
|
+
import { useViews } from "../../provider/context.js";
|
|
7
|
+
import { gridColumnGlyph } from "./column-glyph.js";
|
|
8
|
+
function setBodyResizeState(active) {
|
|
9
|
+
document.body.style.cursor = active ? "col-resize" : "";
|
|
10
|
+
document.body.style.userSelect = active ? "none" : "";
|
|
11
|
+
}
|
|
12
|
+
export function useGridColumnLayout({ rootRef, columns, columnState, onColumnStateChange, scale, freezeIdentity = true, viewBacked = false, }) {
|
|
13
|
+
const { icons, components } = useViews();
|
|
14
|
+
const orderKey = columnState?.order;
|
|
15
|
+
const hiddenKey = columnState?.hidden;
|
|
16
|
+
const shownKey = columnState?.visible;
|
|
17
|
+
const visibleColumns = useMemo(() => {
|
|
18
|
+
if (!viewBacked) {
|
|
19
|
+
return resolveVisibleColumns(columns, {
|
|
20
|
+
order: orderKey,
|
|
21
|
+
hidden: hiddenKey,
|
|
22
|
+
visible: shownKey,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const managedIds = new Set(columns.filter(columnPlacedByView).map((column) => column.id));
|
|
26
|
+
return resolveVisibleColumns(columns, {
|
|
27
|
+
order: resolveViewColumnOrder(columns, orderKey),
|
|
28
|
+
hidden: hiddenKey?.filter((id) => managedIds.has(id)),
|
|
29
|
+
visible: shownKey?.filter((id) => managedIds.has(id)),
|
|
30
|
+
});
|
|
31
|
+
}, [columns, orderKey, hiddenKey, shownKey, viewBacked]);
|
|
32
|
+
const effectiveWidths = useMemo(() => resolveColumnWidths(visibleColumns, columnState?.widths), [visibleColumns, columnState?.widths]);
|
|
33
|
+
const frozenCount = useMemo(() => {
|
|
34
|
+
if (!freezeIdentity)
|
|
35
|
+
return 0;
|
|
36
|
+
const i = visibleColumns.findIndex((c) => c.type === "title");
|
|
37
|
+
if (i < 0)
|
|
38
|
+
return 0;
|
|
39
|
+
return Math.max(0, Math.min(i + 1, visibleColumns.length - 1));
|
|
40
|
+
}, [freezeIdentity, visibleColumns]);
|
|
41
|
+
const frozenLeft = useCallback((i) => `calc(var(--vk-rail-w)` +
|
|
42
|
+
visibleColumns
|
|
43
|
+
.slice(0, i)
|
|
44
|
+
.map((c) => ` + var(${gridWidthVar(c.id)}) * var(--vk-scale)`)
|
|
45
|
+
.join("") +
|
|
46
|
+
`)`, [visibleColumns]);
|
|
47
|
+
const frozenWidth = useMemo(() => frozenCount === 0
|
|
48
|
+
? "0px"
|
|
49
|
+
: `calc((${visibleColumns
|
|
50
|
+
.slice(0, frozenCount)
|
|
51
|
+
.map((c) => `var(${gridWidthVar(c.id)})`)
|
|
52
|
+
.join(" + ")}) * var(--vk-scale))`, [visibleColumns, frozenCount]);
|
|
53
|
+
const widthVarsStyle = useMemo(() => {
|
|
54
|
+
const style = {};
|
|
55
|
+
for (const col of visibleColumns) {
|
|
56
|
+
style[gridWidthVar(col.id)] = `${effectiveWidths[col.id]}px`;
|
|
57
|
+
}
|
|
58
|
+
style["--vk-frozen-w"] = frozenWidth;
|
|
59
|
+
style["--vk-frozen-on"] = frozenCount > 0 ? "1" : "0";
|
|
60
|
+
return style;
|
|
61
|
+
}, [effectiveWidths, visibleColumns, frozenWidth, frozenCount]);
|
|
62
|
+
const columnManager = useMemo(() => {
|
|
63
|
+
if (!onColumnStateChange)
|
|
64
|
+
return null;
|
|
65
|
+
return {
|
|
66
|
+
items: resolveColumnOrder(columns, viewBacked ? resolveViewColumnOrder(columns, columnState?.order) : columnState?.order).map((col) => ({
|
|
67
|
+
id: col.id,
|
|
68
|
+
label: typeof col.header === "string" && col.header ? col.header : prettifyOptionValue(col.id),
|
|
69
|
+
icon: gridColumnGlyph({ icons, AppIcon: components.AppIcon }, col, "h-3.5 w-3.5"),
|
|
70
|
+
hidden: isColumnHidden(col, viewBacked && !columnPlacedByView(col) ? undefined : columnState),
|
|
71
|
+
hideable: !viewBacked || columnPlacedByView(col) ? columnHideable(col) : false,
|
|
72
|
+
fixed: viewBacked && !columnPlacedByView(col),
|
|
73
|
+
})),
|
|
74
|
+
onToggleHidden: (id, hide) => {
|
|
75
|
+
const col = columns.find((candidate) => candidate.id === id);
|
|
76
|
+
if (viewBacked && col && !columnPlacedByView(col))
|
|
77
|
+
return;
|
|
78
|
+
if (col)
|
|
79
|
+
onColumnStateChange(toggleColumnHidden(columnState, col, hide));
|
|
80
|
+
},
|
|
81
|
+
onReorder: (ids) => onColumnStateChange({
|
|
82
|
+
...columnState,
|
|
83
|
+
order: viewBacked ? resolveViewColumnOrder(columns, ids) : ids,
|
|
84
|
+
}),
|
|
85
|
+
onReset: () => onColumnStateChange({}),
|
|
86
|
+
dirty: Object.keys(columnState ?? {}).length > 0,
|
|
87
|
+
};
|
|
88
|
+
}, [columnState, columns, components.AppIcon, icons, onColumnStateChange, viewBacked]);
|
|
89
|
+
const gridTemplate = useMemo(() => [
|
|
90
|
+
"0px",
|
|
91
|
+
...visibleColumns.map((col) => `calc(var(${gridWidthVar(col.id)}) * var(--vk-scale))`),
|
|
92
|
+
"minmax(var(--vk-tail-w),1fr)",
|
|
93
|
+
].join(" "), [visibleColumns]);
|
|
94
|
+
const minWidth = useMemo(() => `calc((${visibleColumns
|
|
95
|
+
.map((col) => `var(${gridWidthVar(col.id)})`)
|
|
96
|
+
.join(" + ")}) * var(--vk-scale) + 2*var(--vk-gutter,0px) + var(--vk-indent,0px) + var(--vk-tail-w))`, [visibleColumns]);
|
|
97
|
+
const [resizingId, setResizingId] = useState(null);
|
|
98
|
+
const dragRef = useRef(null);
|
|
99
|
+
const rafRef = useRef(null);
|
|
100
|
+
const pendingXRef = useRef(0);
|
|
101
|
+
const lastGestureMovedRef = useRef(false);
|
|
102
|
+
const startResize = (col, event) => {
|
|
103
|
+
dragRef.current = {
|
|
104
|
+
col,
|
|
105
|
+
startX: event.clientX,
|
|
106
|
+
startW: effectiveWidths[col.id],
|
|
107
|
+
lastW: null,
|
|
108
|
+
moved: false,
|
|
109
|
+
};
|
|
110
|
+
lastGestureMovedRef.current = false;
|
|
111
|
+
setResizingId(col.id);
|
|
112
|
+
setBodyResizeState(true);
|
|
113
|
+
};
|
|
114
|
+
const moveResize = (event) => {
|
|
115
|
+
if (!dragRef.current)
|
|
116
|
+
return;
|
|
117
|
+
pendingXRef.current = event.clientX;
|
|
118
|
+
if (rafRef.current != null)
|
|
119
|
+
return;
|
|
120
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
121
|
+
rafRef.current = null;
|
|
122
|
+
const drag = dragRef.current;
|
|
123
|
+
if (!drag)
|
|
124
|
+
return;
|
|
125
|
+
const delta = pendingXRef.current - drag.startX;
|
|
126
|
+
if (Math.abs(delta) > 2)
|
|
127
|
+
drag.moved = true;
|
|
128
|
+
const width = clampColumnWidth(drag.col, drag.startW + delta / scale);
|
|
129
|
+
drag.lastW = width;
|
|
130
|
+
rootRef.current?.style.setProperty(gridWidthVar(drag.col.id), `${width}px`);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const endResize = () => {
|
|
134
|
+
const drag = dragRef.current;
|
|
135
|
+
dragRef.current = null;
|
|
136
|
+
if (rafRef.current != null) {
|
|
137
|
+
cancelAnimationFrame(rafRef.current);
|
|
138
|
+
rafRef.current = null;
|
|
139
|
+
}
|
|
140
|
+
setResizingId(null);
|
|
141
|
+
setBodyResizeState(false);
|
|
142
|
+
if (!drag)
|
|
143
|
+
return;
|
|
144
|
+
lastGestureMovedRef.current = drag.moved;
|
|
145
|
+
if (!drag.moved || drag.lastW == null || drag.lastW === effectiveWidths[drag.col.id])
|
|
146
|
+
return;
|
|
147
|
+
onColumnStateChange?.({
|
|
148
|
+
...columnState,
|
|
149
|
+
widths: { ...(columnState?.widths ?? {}), [drag.col.id]: drag.lastW },
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const resetColumnWidth = (col) => {
|
|
153
|
+
if (lastGestureMovedRef.current)
|
|
154
|
+
return;
|
|
155
|
+
const widths = { ...(columnState?.widths ?? {}) };
|
|
156
|
+
if (!(col.id in widths))
|
|
157
|
+
return;
|
|
158
|
+
delete widths[col.id];
|
|
159
|
+
const next = { ...columnState };
|
|
160
|
+
if (Object.keys(widths).length === 0)
|
|
161
|
+
delete next.widths;
|
|
162
|
+
else
|
|
163
|
+
next.widths = widths;
|
|
164
|
+
onColumnStateChange?.(next);
|
|
165
|
+
};
|
|
166
|
+
const hideColumn = (col) => {
|
|
167
|
+
if (viewBacked && !columnPlacedByView(col))
|
|
168
|
+
return;
|
|
169
|
+
onColumnStateChange?.(toggleColumnHidden(columnState, col, true));
|
|
170
|
+
};
|
|
171
|
+
const moveColumn = (col, direction) => {
|
|
172
|
+
if (viewBacked && !columnPlacedByView(col))
|
|
173
|
+
return;
|
|
174
|
+
const ordered = baseColumnOrder(columns, columnState?.order, viewBacked);
|
|
175
|
+
const visibleIds = visibleColumns.map((c) => c.id);
|
|
176
|
+
const at = visibleIds.indexOf(col.id);
|
|
177
|
+
const neighbour = visibleIds[at + direction];
|
|
178
|
+
if (at < 0 || !neighbour)
|
|
179
|
+
return;
|
|
180
|
+
if (viewBacked && !columnPlacedByView(columns.find((c) => c.id === neighbour)))
|
|
181
|
+
return;
|
|
182
|
+
const i = ordered.indexOf(col.id);
|
|
183
|
+
const j = ordered.indexOf(neighbour);
|
|
184
|
+
[ordered[i], ordered[j]] = [ordered[j], ordered[i]];
|
|
185
|
+
onColumnStateChange?.({
|
|
186
|
+
...columnState,
|
|
187
|
+
order: viewBacked ? resolveViewColumnOrder(columns, ordered) : ordered,
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
visibleColumns,
|
|
192
|
+
widthVarsStyle,
|
|
193
|
+
frozenCount,
|
|
194
|
+
frozenLeft,
|
|
195
|
+
columnManager,
|
|
196
|
+
gridTemplate,
|
|
197
|
+
minWidth,
|
|
198
|
+
resizingId,
|
|
199
|
+
startResize,
|
|
200
|
+
moveResize,
|
|
201
|
+
endResize,
|
|
202
|
+
resetColumnWidth,
|
|
203
|
+
hideColumn,
|
|
204
|
+
moveColumn,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { GridCellPos } from "../core/coordinates.js";
|
|
3
|
+
import { type GridChromeTarget, type GridFocusTarget } from "../core/grid-focus.js";
|
|
4
|
+
/** Text entry and overlay surfaces: they own their keys and their focus wherever they live, inside the grid or out
|
|
5
|
+
* (an editor's input, a rename, a menu, a dialog). A checkbox is no text entry: the grid's Space ticks it. */
|
|
6
|
+
export declare const GRID_KEY_OWNING_SURFACES = "input:not([type=\"checkbox\"]), textarea, select, [contenteditable=\"true\"], [role=\"menu\"], [role=\"dialog\"]";
|
|
7
|
+
/** The element a target draws, found in the grid's own DOM; null when it isn't drawn. */
|
|
8
|
+
export declare function gridFocusElement(root: HTMLElement, target: GridFocusTarget): HTMLElement | null;
|
|
9
|
+
/**
|
|
10
|
+
* A mouse press on a part that takes focus (a cell, a column name, a footer cell) focuses it at once without scrolling:
|
|
11
|
+
* the browser's own focus on mousedown would scroll a part half under the pinned head or the frozen columns into
|
|
12
|
+
* view, and finds it already focused. A press in text being typed, or inside the part already holding focus (its open
|
|
13
|
+
* editor), is left alone.
|
|
14
|
+
*/
|
|
15
|
+
export declare function gridFocusOnPress(event: {
|
|
16
|
+
pointerType: string;
|
|
17
|
+
button: number;
|
|
18
|
+
target: EventTarget | null;
|
|
19
|
+
}, part: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Where a chrome target goes when the element it stood for is gone (a column hidden or the list regrouped from its
|
|
22
|
+
* own menu, a group's ⋯ that no longer draws): the same row's first cell where that row is still drawn, the bar's
|
|
23
|
+
* name for its ⋯; null where nothing of it is left.
|
|
24
|
+
*/
|
|
25
|
+
export declare function gridChromeFallback(root: HTMLElement, target: GridChromeTarget): GridChromeTarget | null;
|
|
26
|
+
/**
|
|
27
|
+
* Where real focus belongs in the grid, and the effect that puts it there. A data cell's focus stays the editing
|
|
28
|
+
* model's `focusedCell`; a column name, a footer cell, a bar or a checkbox is the `chrome` target beside it. After a
|
|
29
|
+
* render that moved the target, real focus follows it, but only while nothing else on the page has the focus (it is
|
|
30
|
+
* on the body, the frame, a guard or inside the grid) and no editor is open: the grid never takes focus from the
|
|
31
|
+
* toolbar, and an open editor keeps its own. An editor that answered by Enter or Tab and still plays its close is not
|
|
32
|
+
* open: the focused cell has moved on, and the focus follows it at once.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useGridFocus({ rootRef, focusedCell, editingCell, }: {
|
|
35
|
+
rootRef: RefObject<HTMLDivElement | null>;
|
|
36
|
+
focusedCell: GridCellPos | null;
|
|
37
|
+
editingCell: GridCellPos | null;
|
|
38
|
+
}): {
|
|
39
|
+
chrome: GridChromeTarget | null;
|
|
40
|
+
setChrome: (target: GridChromeTarget | null) => void;
|
|
41
|
+
target: GridFocusTarget | null;
|
|
42
|
+
releaseToFrame: () => void;
|
|
43
|
+
/** The last data cell that held the focus, for coming back in after a let-go. */
|
|
44
|
+
lastCellRef: RefObject<GridCellPos | null>;
|
|
45
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { GRID_ADD_COLUMN, GRID_RAIL_COLUMN, } from "../core/grid-focus.js";
|
|
4
|
+
const esc = (value) => CSS.escape(value);
|
|
5
|
+
export const GRID_KEY_OWNING_SURFACES = 'input:not([type="checkbox"]), textarea, select, [contenteditable="true"], [role="menu"], [role="dialog"]';
|
|
6
|
+
export function gridFocusElement(root, target) {
|
|
7
|
+
switch (target.kind) {
|
|
8
|
+
case "cell":
|
|
9
|
+
return root.querySelector(`[data-row-id="${esc(target.pos.rowId)}"] [data-col-id="${esc(target.pos.columnId)}"]`);
|
|
10
|
+
case "rail": {
|
|
11
|
+
const row = `[data-row-id="${esc(target.rowKey)}"] [data-slot="vk-grid-rail"]`;
|
|
12
|
+
return root.querySelector(`${row} button, ${row} input`);
|
|
13
|
+
}
|
|
14
|
+
case "head": {
|
|
15
|
+
const head = root.querySelector(`[data-slot="vk-grid-header"][data-group-key="${esc(target.groupKey)}"]`);
|
|
16
|
+
if (!head)
|
|
17
|
+
return null;
|
|
18
|
+
if (target.columnId === GRID_RAIL_COLUMN) {
|
|
19
|
+
return head.querySelector('[data-slot="vk-grid-rail"] button, [data-slot="vk-grid-rail"] input');
|
|
20
|
+
}
|
|
21
|
+
if (target.columnId === GRID_ADD_COLUMN)
|
|
22
|
+
return head.querySelector('[data-slot="vk-grid-tail"] button');
|
|
23
|
+
return head.querySelector(`[data-headcell="${esc(target.columnId)}"]`);
|
|
24
|
+
}
|
|
25
|
+
case "foot": {
|
|
26
|
+
const foot = root.querySelector(`[data-slot="vk-grid-footer"][data-group-key="${esc(target.groupKey)}"]`);
|
|
27
|
+
return foot?.querySelector(`[data-footcell="${esc(target.columnId)}"]`) ?? null;
|
|
28
|
+
}
|
|
29
|
+
case "bar": {
|
|
30
|
+
const group = root.querySelector(`[data-slot="vk-grid-group"][data-group-key="${esc(target.groupKey)}"]`);
|
|
31
|
+
if (!group)
|
|
32
|
+
return null;
|
|
33
|
+
return target.part === "name"
|
|
34
|
+
? group.querySelector("[data-bar-name]")
|
|
35
|
+
: group.querySelector('[data-slot="vk-grid-group-header"] [aria-haspopup]');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function gridFocusOnPress(event, part) {
|
|
40
|
+
if (event.pointerType !== "mouse" || event.button !== 0)
|
|
41
|
+
return;
|
|
42
|
+
const target = event.target;
|
|
43
|
+
if (!target?.closest || target.closest(GRID_KEY_OWNING_SURFACES))
|
|
44
|
+
return;
|
|
45
|
+
const element = target.closest(part);
|
|
46
|
+
if (!element || element.contains(document.activeElement))
|
|
47
|
+
return;
|
|
48
|
+
element.focus({ preventScroll: true });
|
|
49
|
+
}
|
|
50
|
+
export function gridChromeFallback(root, target) {
|
|
51
|
+
if (target.kind === "head" || target.kind === "foot") {
|
|
52
|
+
const slot = target.kind === "head" ? "vk-grid-header" : "vk-grid-footer";
|
|
53
|
+
const attr = target.kind === "head" ? "data-headcell" : "data-footcell";
|
|
54
|
+
const line = root.querySelector(`[data-slot="${slot}"][data-group-key="${esc(target.groupKey)}"]`);
|
|
55
|
+
const first = line?.querySelector(`[${attr}]`)?.getAttribute(attr);
|
|
56
|
+
return first != null ? { kind: target.kind, groupKey: target.groupKey, columnId: first } : null;
|
|
57
|
+
}
|
|
58
|
+
if (target.kind === "bar" && target.part === "menu") {
|
|
59
|
+
const name = { kind: "bar", groupKey: target.groupKey, part: "name" };
|
|
60
|
+
return gridFocusElement(root, name) ? name : null;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function targetKey(target) {
|
|
65
|
+
if (!target)
|
|
66
|
+
return "";
|
|
67
|
+
return target.kind === "cell" ? `cell:${target.pos.rowId}:${target.pos.columnId}` : JSON.stringify(target);
|
|
68
|
+
}
|
|
69
|
+
export function useGridFocus({ rootRef, focusedCell, editingCell, }) {
|
|
70
|
+
const [chrome, setChromeState] = useState(null);
|
|
71
|
+
const target = chrome ?? (focusedCell ? { kind: "cell", pos: focusedCell } : null);
|
|
72
|
+
const key = targetKey(target);
|
|
73
|
+
const lastCellRef = useRef(null);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!focusedCell)
|
|
76
|
+
return;
|
|
77
|
+
lastCellRef.current = focusedCell;
|
|
78
|
+
setChromeState(null);
|
|
79
|
+
}, [focusedCell]);
|
|
80
|
+
const heldRef = useRef(false);
|
|
81
|
+
const setChrome = useCallback((next) => setChromeState(next), []);
|
|
82
|
+
const releaseToFrame = useCallback(() => {
|
|
83
|
+
rootRef.current?.focus({ preventScroll: true });
|
|
84
|
+
}, [rootRef]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const root = rootRef.current;
|
|
87
|
+
if (!root || !chrome || gridFocusElement(root, chrome))
|
|
88
|
+
return;
|
|
89
|
+
const fallback = gridChromeFallback(root, chrome);
|
|
90
|
+
setChromeState(fallback);
|
|
91
|
+
const active = document.activeElement;
|
|
92
|
+
if (!fallback && (active == null || active === document.body))
|
|
93
|
+
root.focus({ preventScroll: true });
|
|
94
|
+
});
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const root = rootRef.current;
|
|
97
|
+
const answered = editingCell != null &&
|
|
98
|
+
target?.kind === "cell" &&
|
|
99
|
+
(target.pos.rowId !== editingCell.rowId || target.pos.columnId !== editingCell.columnId);
|
|
100
|
+
if (!root || (editingCell && !answered))
|
|
101
|
+
return;
|
|
102
|
+
const active = document.activeElement;
|
|
103
|
+
const onBody = active == null || active === document.body;
|
|
104
|
+
const free = answered || onBody || (root.contains(active) && !active.closest(GRID_KEY_OWNING_SURFACES));
|
|
105
|
+
if (!target) {
|
|
106
|
+
if (heldRef.current && onBody)
|
|
107
|
+
root.focus({ preventScroll: true });
|
|
108
|
+
else if (free && !onBody && active !== root && active instanceof HTMLElement && !active.closest("[data-grid-guard]"))
|
|
109
|
+
active.blur();
|
|
110
|
+
heldRef.current = false;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const element = gridFocusElement(root, target);
|
|
114
|
+
if (element && free && active !== element) {
|
|
115
|
+
element.focus({ preventScroll: true });
|
|
116
|
+
if (target.kind !== "cell")
|
|
117
|
+
element.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
118
|
+
}
|
|
119
|
+
heldRef.current = element != null && document.activeElement === element;
|
|
120
|
+
}, [key, editingCell, rootRef]);
|
|
121
|
+
return { chrome, setChrome, target, releaseToFrame, lastCellRef };
|
|
122
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MutableRefObject } from "react";
|
|
2
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
3
|
+
import type { ListColumnState } from "../../model/column-state.js";
|
|
4
|
+
/** Bind visible header drag order back onto the complete stored column order. */
|
|
5
|
+
export declare function useGridHeaderDrag<Row>({ columns, columnState, onColumnStateChange, visibleColumnIds, scrollXRef, getScroller, viewBacked, }: {
|
|
6
|
+
columns: ListColumn<Row>[];
|
|
7
|
+
columnState?: ListColumnState;
|
|
8
|
+
onColumnStateChange?: (next: ListColumnState) => void;
|
|
9
|
+
visibleColumnIds: string[];
|
|
10
|
+
scrollXRef: MutableRefObject<number>;
|
|
11
|
+
getScroller: () => HTMLElement | undefined;
|
|
12
|
+
viewBacked?: boolean;
|
|
13
|
+
}): {
|
|
14
|
+
cellStyle: (id: string, index: number) => React.CSSProperties | undefined;
|
|
15
|
+
onCellPointerDown: (id: string, index: number) => (e: React.PointerEvent<HTMLElement>) => void;
|
|
16
|
+
onCellPointerMove: (e: React.PointerEvent<HTMLElement>) => void;
|
|
17
|
+
onCellPointerUp: (e: React.PointerEvent<HTMLElement>) => void;
|
|
18
|
+
onCellPointerCancel: () => void;
|
|
19
|
+
onCellClickCapture: (e: React.MouseEvent<HTMLElement>) => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { baseColumnOrder, columnPlacedByView, resolveViewColumnOrder, } from "../../model/column-capabilities.js";
|
|
3
|
+
import { useHeaderDragReorder } from "./useHeaderDragReorder.js";
|
|
4
|
+
export function useGridHeaderDrag({ columns, columnState, onColumnStateChange, visibleColumnIds, scrollXRef, getScroller, viewBacked = false, }) {
|
|
5
|
+
return useHeaderDragReorder({
|
|
6
|
+
enabled: !!onColumnStateChange,
|
|
7
|
+
ids: visibleColumnIds,
|
|
8
|
+
scrollXRef,
|
|
9
|
+
getScroller,
|
|
10
|
+
canDrag: (id) => {
|
|
11
|
+
const column = columns.find((candidate) => candidate.id === id);
|
|
12
|
+
return !viewBacked || !column || columnPlacedByView(column);
|
|
13
|
+
},
|
|
14
|
+
onReorder: (movedId, nextVisible) => {
|
|
15
|
+
if (!onColumnStateChange)
|
|
16
|
+
return;
|
|
17
|
+
const moved = columns.find((column) => column.id === movedId);
|
|
18
|
+
if (viewBacked && moved && !columnPlacedByView(moved))
|
|
19
|
+
return;
|
|
20
|
+
const completeOrder = baseColumnOrder(columns, columnState?.order, viewBacked);
|
|
21
|
+
const remaining = completeOrder.filter((id) => id !== movedId);
|
|
22
|
+
const position = nextVisible.indexOf(movedId);
|
|
23
|
+
const follower = nextVisible[position + 1];
|
|
24
|
+
const previous = nextVisible[position - 1];
|
|
25
|
+
const insertAt = follower != null
|
|
26
|
+
? remaining.indexOf(follower)
|
|
27
|
+
: previous != null
|
|
28
|
+
? remaining.indexOf(previous) + 1
|
|
29
|
+
: remaining.length;
|
|
30
|
+
remaining.splice(insertAt, 0, movedId);
|
|
31
|
+
onColumnStateChange({
|
|
32
|
+
...columnState,
|
|
33
|
+
order: viewBacked ? resolveViewColumnOrder(columns, remaining) : remaining,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { type GridCellPos } from "../core/coordinates.js";
|
|
3
|
+
import type { GridCellRange } from "../core/useGridRange.js";
|
|
4
|
+
import type { ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
5
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
6
|
+
import type { GridRangeVerbs } from "./useGridRangeActions.js";
|
|
7
|
+
import { type GridChromeTarget, type GridFocusShape } from "../core/grid-focus.js";
|
|
8
|
+
export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
|
|
9
|
+
rootRef: RefObject<HTMLDivElement | null>;
|
|
10
|
+
/** A column name, a footer cell, a bar or a checkbox holding the focus (`useGridFocus`); null: a data cell, or
|
|
11
|
+
* nothing. */
|
|
12
|
+
chrome?: GridChromeTarget | null;
|
|
13
|
+
setChrome?: (target: GridChromeTarget | null) => void;
|
|
14
|
+
/** What the keyboard walks beyond the data cells: the sections, their footers and menus, the checkbox lane. None:
|
|
15
|
+
* a grid whose keys stay on its data cells. */
|
|
16
|
+
shape?: GridFocusShape;
|
|
17
|
+
/** Collapse or open a group: a bar's Enter, Space, ← and →. */
|
|
18
|
+
toggleGroup?: (groupKey: string) => void;
|
|
19
|
+
/** Puts real focus on the grid's frame: Escape's let-go (`useGridFocus`). */
|
|
20
|
+
releaseToFrame: () => void;
|
|
21
|
+
/** The last data cell that held the focus: an arrow on the let-go frame comes back in there. */
|
|
22
|
+
lastCellRef: RefObject<GridCellPos | null>;
|
|
23
|
+
/** The grid's one reveal (`grid-scroll-owner.ts`'s `revealGridCell`, with the table's `revealRow`): brings a
|
|
24
|
+
* cell into view whether or not the page holds its row. */
|
|
25
|
+
revealCell: (pos: GridCellPos, behavior: ScrollBehavior) => void;
|
|
26
|
+
focusedCell: GridCellPos | null;
|
|
27
|
+
editingCell: GridCellPos | null;
|
|
28
|
+
editingEnabled: boolean;
|
|
29
|
+
/** Workspace-settings capability config — the keyboard routes ask the same effective
|
|
30
|
+
* write gate the cells do, so a lock holds here too. */
|
|
31
|
+
listConfig?: ListSettingsConfig;
|
|
32
|
+
visibleRowIds: string[];
|
|
33
|
+
/** Row key → the rendered row and its DATA id. Focus is a KEY; a commit needs
|
|
34
|
+
* the record and the id behind it. */
|
|
35
|
+
rowByKey: ReadonlyMap<string, {
|
|
36
|
+
row: Row;
|
|
37
|
+
rowId: string;
|
|
38
|
+
}>;
|
|
39
|
+
visibleColIds: string[];
|
|
40
|
+
visibleColumns: ListColumn<Row>[];
|
|
41
|
+
rows: Row[];
|
|
42
|
+
getRowId: (row: Row) => string;
|
|
43
|
+
pendingByRow: ReadonlyMap<string, Record<string, unknown>>;
|
|
44
|
+
rangeVerbsRef: RefObject<GridRangeVerbs | null>;
|
|
45
|
+
focusCell: (rowId: string, columnId: string) => void;
|
|
46
|
+
clearFocus: () => void;
|
|
47
|
+
/** Seed a fresh rectangle (⌘A, or extending with no range yet). */
|
|
48
|
+
rangeSetRect: (anchor: GridCellPos, head: GridCellPos) => void;
|
|
49
|
+
/** Grow the ACTIVE range to a new head, anchor untouched. */
|
|
50
|
+
rangeExtendTo: (pos: GridCellPos) => void;
|
|
51
|
+
/** Live ranges — the last one is active; read for its head. */
|
|
52
|
+
ranges: GridCellRange[];
|
|
53
|
+
startEdit: (rowId: string, columnId: string, seed?: string | null, whole?: boolean) => void;
|
|
54
|
+
cancelEdit: () => void;
|
|
55
|
+
commitEdit: (row: Row, rowId: string, columnId: string, previous: unknown, next: unknown) => void;
|
|
56
|
+
/** Say why a cell can't be written; answers whether it said anything. */
|
|
57
|
+
refuseEdit: (columnId: string) => boolean;
|
|
58
|
+
undo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
|
|
59
|
+
redo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
|
|
60
|
+
}): {
|
|
61
|
+
onEditorTab: (rowId: string, columnId: string, backwards: boolean) => void;
|
|
62
|
+
onEditorEnter: (rowId: string, columnId: string) => void;
|
|
63
|
+
enterGrid: (_which: "start" | "end", from: Element | null) => void;
|
|
64
|
+
};
|