@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,195 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { useViews } from "../../provider/context.js";
|
|
4
|
+
import { gridRectContains, gridRectIsMulti } from "../core/coordinates.js";
|
|
5
|
+
import { computeRowRangeSpans } from "../core/range-model.js";
|
|
6
|
+
import { resolveActiveRangeRect } from "../core/range-model.js";
|
|
7
|
+
import { deriveGridSelectValues } from "../core/column-values.js";
|
|
8
|
+
import { buildGridCopyMatrix, extendGridFillPreview, gridRectHasClearable, planGridClear, planGridFill, planGridPaste, } from "../core/spreadsheet-operations.js";
|
|
9
|
+
import { copyCells, getGridClipboard, parseTsvText } from "./cell-clipboard.js";
|
|
10
|
+
export function useGridRangeActions({ ranges, focusedCell, editingCell, editingEnabled, fillTargetRow, visibleRowIds, visibleColumns, spreadsheetModel, commitBatch, focusCell, rangeSetRect, rangeExtendTo, revealCell, }) {
|
|
11
|
+
const { ports, messages, conventions } = useViews();
|
|
12
|
+
const visibleColIds = useMemo(() => visibleColumns.map((col) => col.id), [visibleColumns]);
|
|
13
|
+
const spanRanges = useMemo(() => extendGridFillPreview(ranges, fillTargetRow, visibleRowIds, visibleColIds), [fillTargetRow, ranges, visibleColIds, visibleRowIds]);
|
|
14
|
+
const rowSpansMap = useMemo(() => computeRowRangeSpans(spanRanges, visibleRowIds, visibleColIds), [spanRanges, visibleColIds, visibleRowIds]);
|
|
15
|
+
const selectValuesByColumn = useMemo(() => deriveGridSelectValues(visibleColumns, spreadsheetModel.rows), [spreadsheetModel.rows, visibleColumns]);
|
|
16
|
+
const sayRefusals = useCallback((verb, plan) => {
|
|
17
|
+
if (plan.targetCount === 1 && plan.refusals.length === 1) {
|
|
18
|
+
ports.toast.error(plan.refusals[0].reason);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const { reason, count } of plan.refusals) {
|
|
22
|
+
ports.toast.error(messages({ key: verb === "paste" ? "views.grid.paste-skipped" : "views.grid.fill-skipped", values: { count, reason } }));
|
|
23
|
+
}
|
|
24
|
+
}, [messages, ports]);
|
|
25
|
+
const finishFill = useCallback((targetRowId) => {
|
|
26
|
+
if (!editingEnabled)
|
|
27
|
+
return;
|
|
28
|
+
const plan = planGridFill(spreadsheetModel, ranges, focusedCell, targetRowId);
|
|
29
|
+
if (plan.edits.length > 0)
|
|
30
|
+
commitBatch(plan.edits);
|
|
31
|
+
if (plan.selectionHead)
|
|
32
|
+
rangeExtendTo(plan.selectionHead);
|
|
33
|
+
sayRefusals("fill", plan);
|
|
34
|
+
}, [commitBatch, editingEnabled, focusedCell, rangeExtendTo, ranges, sayRefusals, spreadsheetModel]);
|
|
35
|
+
const rangeVerbs = useMemo(() => {
|
|
36
|
+
const rectOfActiveRange = () => resolveActiveRangeRect(ranges, focusedCell, visibleRowIds, visibleColIds);
|
|
37
|
+
const activeRangeIsMulti = () => {
|
|
38
|
+
const rect = rectOfActiveRange();
|
|
39
|
+
return !!rect && gridRectIsMulti(rect);
|
|
40
|
+
};
|
|
41
|
+
const cellInActiveRange = (rowId, columnId) => {
|
|
42
|
+
if (!activeRangeIsMulti())
|
|
43
|
+
return false;
|
|
44
|
+
const rect = rectOfActiveRange();
|
|
45
|
+
return gridRectContains(rect, visibleRowIds.indexOf(rowId), visibleColIds.indexOf(columnId));
|
|
46
|
+
};
|
|
47
|
+
const copyRange = () => {
|
|
48
|
+
const rect = rectOfActiveRange();
|
|
49
|
+
if (!rect)
|
|
50
|
+
return;
|
|
51
|
+
const matrix = buildGridCopyMatrix(spreadsheetModel, rect);
|
|
52
|
+
if (matrix.length > 0)
|
|
53
|
+
void copyCells(ports.clipboard.writeText, matrix);
|
|
54
|
+
};
|
|
55
|
+
const activeRangeHasClearable = () => {
|
|
56
|
+
if (!editingEnabled)
|
|
57
|
+
return false;
|
|
58
|
+
const rect = rectOfActiveRange();
|
|
59
|
+
return !!rect && gridRectHasClearable(visibleColumns, rect);
|
|
60
|
+
};
|
|
61
|
+
const clearRange = (quiet = false) => {
|
|
62
|
+
if (!editingEnabled)
|
|
63
|
+
return;
|
|
64
|
+
const rect = rectOfActiveRange();
|
|
65
|
+
if (!rect)
|
|
66
|
+
return;
|
|
67
|
+
const plan = planGridClear(spreadsheetModel, rect);
|
|
68
|
+
if (plan.edits.length > 0)
|
|
69
|
+
commitBatch(plan.edits);
|
|
70
|
+
for (const { reason } of plan.refusals)
|
|
71
|
+
ports.toast.error(reason);
|
|
72
|
+
if (plan.required.length > 0) {
|
|
73
|
+
const fields = new Intl.ListFormat(conventions.locale, { type: "conjunction" }).format(plan.required);
|
|
74
|
+
ports.toast.error(messages({ key: "views.grid.clear-required", values: { fields } }));
|
|
75
|
+
}
|
|
76
|
+
else if (!quiet && plan.edits.length === 0 && plan.refusals.length === 0 && !activeRangeHasClearable()) {
|
|
77
|
+
ports.toast.error(messages({ key: "views.grid.clear-none" }));
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const cutRange = () => {
|
|
81
|
+
copyRange();
|
|
82
|
+
clearRange(true);
|
|
83
|
+
};
|
|
84
|
+
const pasteMatrix = (matrix, anchor) => {
|
|
85
|
+
if (!editingEnabled)
|
|
86
|
+
return;
|
|
87
|
+
const plan = planGridPaste(spreadsheetModel, matrix, anchor, rectOfActiveRange(), selectValuesByColumn);
|
|
88
|
+
if (plan.edits.length > 0) {
|
|
89
|
+
commitBatch(plan.edits);
|
|
90
|
+
if (plan.selection) {
|
|
91
|
+
focusCell(plan.selection.anchor.rowId, plan.selection.anchor.columnId);
|
|
92
|
+
rangeSetRect(plan.selection.anchor, plan.selection.head);
|
|
93
|
+
revealCell(plan.selection.anchor, "auto");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
sayRefusals("paste", plan);
|
|
97
|
+
};
|
|
98
|
+
const pasteAtCell = (rowId, columnId) => {
|
|
99
|
+
const clipboard = getGridClipboard();
|
|
100
|
+
if (!clipboard)
|
|
101
|
+
return;
|
|
102
|
+
const rowIdx = visibleRowIds.indexOf(rowId);
|
|
103
|
+
const colIdx = visibleColIds.indexOf(columnId);
|
|
104
|
+
if (rowIdx < 0 || colIdx < 0)
|
|
105
|
+
return;
|
|
106
|
+
pasteMatrix(clipboard.matrix ?? [[clipboard]], { rowIdx, colIdx });
|
|
107
|
+
};
|
|
108
|
+
const pasteAtRangeOrigin = () => {
|
|
109
|
+
const rect = rectOfActiveRange();
|
|
110
|
+
if (rect)
|
|
111
|
+
pasteAtCell(visibleRowIds[rect.r1], visibleColIds[rect.c1]);
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
copyRange,
|
|
115
|
+
cutRange,
|
|
116
|
+
clearRange,
|
|
117
|
+
pasteMatrix,
|
|
118
|
+
pasteAtCell,
|
|
119
|
+
pasteAtRangeOrigin,
|
|
120
|
+
activeRangeIsMulti,
|
|
121
|
+
activeRangeHasClearable,
|
|
122
|
+
cellInActiveRange,
|
|
123
|
+
};
|
|
124
|
+
}, [
|
|
125
|
+
commitBatch,
|
|
126
|
+
conventions,
|
|
127
|
+
editingEnabled,
|
|
128
|
+
focusCell,
|
|
129
|
+
focusedCell,
|
|
130
|
+
messages,
|
|
131
|
+
ports,
|
|
132
|
+
rangeSetRect,
|
|
133
|
+
ranges,
|
|
134
|
+
revealCell,
|
|
135
|
+
sayRefusals,
|
|
136
|
+
selectValuesByColumn,
|
|
137
|
+
spreadsheetModel,
|
|
138
|
+
visibleColIds,
|
|
139
|
+
visibleColumns,
|
|
140
|
+
visibleRowIds,
|
|
141
|
+
]);
|
|
142
|
+
const rangeVerbsRef = useRef(null);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
rangeVerbsRef.current = rangeVerbs;
|
|
145
|
+
}, [rangeVerbs]);
|
|
146
|
+
const onRangeCopy = useCallback(() => rangeVerbsRef.current?.copyRange(), []);
|
|
147
|
+
const onRangeCut = useCallback(() => rangeVerbsRef.current?.cutRange(), []);
|
|
148
|
+
const onRangeClear = useCallback(() => rangeVerbsRef.current?.clearRange(), []);
|
|
149
|
+
const onRangePaste = useCallback(() => rangeVerbsRef.current?.pasteAtRangeOrigin(), []);
|
|
150
|
+
const onPasteAtCell = useCallback((rowId, columnId) => rangeVerbsRef.current?.pasteAtCell(rowId, columnId), []);
|
|
151
|
+
const inActiveRange = useCallback((rowId, columnId) => rangeVerbsRef.current?.cellInActiveRange(rowId, columnId) ?? false, []);
|
|
152
|
+
const rangeCanClear = useCallback(() => rangeVerbsRef.current?.activeRangeHasClearable() ?? false, []);
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (!focusedCell || editingCell || !editingEnabled)
|
|
155
|
+
return;
|
|
156
|
+
const onPaste = (event) => {
|
|
157
|
+
const target = event.target;
|
|
158
|
+
if (target?.closest?.('input, textarea, select, [contenteditable="true"], [role="menu"]')) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
162
|
+
const clipboard = getGridClipboard();
|
|
163
|
+
const internal = clipboard && (clipboard.text === text || text === "") ? clipboard : null;
|
|
164
|
+
if (!internal && text === "")
|
|
165
|
+
return;
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
const matrix = internal
|
|
168
|
+
? (internal.matrix ?? [[internal]])
|
|
169
|
+
: parseTsvText(text);
|
|
170
|
+
if (matrix.length === 0)
|
|
171
|
+
return;
|
|
172
|
+
const rowIdx = visibleRowIds.indexOf(focusedCell.rowId);
|
|
173
|
+
const colIdx = visibleColIds.indexOf(focusedCell.columnId);
|
|
174
|
+
if (rowIdx < 0 || colIdx < 0)
|
|
175
|
+
return;
|
|
176
|
+
rangeVerbsRef.current?.pasteMatrix(matrix, { rowIdx, colIdx });
|
|
177
|
+
};
|
|
178
|
+
window.addEventListener("paste", onPaste);
|
|
179
|
+
return () => window.removeEventListener("paste", onPaste);
|
|
180
|
+
}, [editingCell, editingEnabled, focusedCell, visibleColIds, visibleRowIds]);
|
|
181
|
+
return {
|
|
182
|
+
visibleColIds,
|
|
183
|
+
rowSpansMap,
|
|
184
|
+
selectValuesByColumn,
|
|
185
|
+
finishFill,
|
|
186
|
+
onRangeCopy,
|
|
187
|
+
onRangeCut,
|
|
188
|
+
onRangeClear,
|
|
189
|
+
onRangePaste,
|
|
190
|
+
onPasteAtCell,
|
|
191
|
+
inActiveRange,
|
|
192
|
+
rangeCanClear,
|
|
193
|
+
rangeVerbsRef,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { GridCellPos } from "../core/coordinates.js";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a pointer event on a scrolling element landed on one of its
|
|
5
|
+
* scrollbars rather than its content. A scrollbar is drawn inside the border
|
|
6
|
+
* box but outside the client box, so a pointer past `clientWidth` /
|
|
7
|
+
* `clientHeight` (measured from the padding edge) is on the bar.
|
|
8
|
+
*/
|
|
9
|
+
export declare function onScrollbar(el: HTMLElement, event: {
|
|
10
|
+
clientX: number;
|
|
11
|
+
clientY: number;
|
|
12
|
+
}): boolean;
|
|
13
|
+
export declare function useGridRangeGestures({ rootRef, focusedCell, editingCell, editingEnabled, selecting, focusCell, clearFocus, rangeBeginDrag, rangeExtendTo, rangeAddCell, finishFillRef, }: {
|
|
14
|
+
rootRef: RefObject<HTMLDivElement | null>;
|
|
15
|
+
focusedCell: GridCellPos | null;
|
|
16
|
+
editingCell: GridCellPos | null;
|
|
17
|
+
editingEnabled: boolean;
|
|
18
|
+
selecting: boolean;
|
|
19
|
+
focusCell: (rowId: string, columnId: string) => void;
|
|
20
|
+
clearFocus: () => void;
|
|
21
|
+
rangeBeginDrag: (pos: GridCellPos, additive: boolean) => void;
|
|
22
|
+
rangeExtendTo: (pos: GridCellPos, fallbackAnchor?: GridCellPos) => void;
|
|
23
|
+
rangeAddCell: (pos: GridCellPos) => void;
|
|
24
|
+
finishFillRef: RefObject<(targetRowId: string) => void>;
|
|
25
|
+
}): {
|
|
26
|
+
fillTargetRow: string | null;
|
|
27
|
+
onExtendCell: (rowId: string, columnId: string) => void;
|
|
28
|
+
onAddCell: (rowId: string, columnId: string) => void;
|
|
29
|
+
handleRootPointerDown: (event: React.PointerEvent) => void;
|
|
30
|
+
handleRootPointerDownCapture: (event: React.PointerEvent) => void;
|
|
31
|
+
handleRootClickCapture: (event: React.MouseEvent) => void;
|
|
32
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { gridControlAt } from "./grid-cell-link.js";
|
|
4
|
+
import { findGridScrollOwner, gridDragScrollStep, gridHitAtPoint, gridVisibleBox } from "./grid-scroll-owner.js";
|
|
5
|
+
const MOUSE_DRAG_SELECT = false;
|
|
6
|
+
function setBodySelectionDisabled(disabled) {
|
|
7
|
+
document.body.style.userSelect = disabled ? "none" : "";
|
|
8
|
+
}
|
|
9
|
+
export function onScrollbar(el, event) {
|
|
10
|
+
if (!el.clientWidth || !el.clientHeight)
|
|
11
|
+
return false;
|
|
12
|
+
const rect = el.getBoundingClientRect();
|
|
13
|
+
const x = event.clientX - rect.left - el.clientLeft;
|
|
14
|
+
const y = event.clientY - rect.top - el.clientTop;
|
|
15
|
+
return x >= el.clientWidth || y >= el.clientHeight;
|
|
16
|
+
}
|
|
17
|
+
export function useGridRangeGestures({ rootRef, focusedCell, editingCell, editingEnabled, selecting, focusCell, clearFocus, rangeBeginDrag, rangeExtendTo, rangeAddCell, finishFillRef, }) {
|
|
18
|
+
const focusedRef = useRef(focusedCell);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
focusedRef.current = focusedCell;
|
|
21
|
+
}, [focusedCell]);
|
|
22
|
+
const onExtendCell = useCallback((rowId, columnId) => {
|
|
23
|
+
const pos = { rowId, columnId };
|
|
24
|
+
rangeExtendTo(pos, focusedRef.current ?? pos);
|
|
25
|
+
if (!focusedRef.current)
|
|
26
|
+
focusCell(rowId, columnId);
|
|
27
|
+
}, [focusCell, rangeExtendTo]);
|
|
28
|
+
const onAddCell = useCallback((rowId, columnId) => {
|
|
29
|
+
rangeAddCell({ rowId, columnId });
|
|
30
|
+
focusCell(rowId, columnId);
|
|
31
|
+
}, [focusCell, rangeAddCell]);
|
|
32
|
+
const cellDragRef = useRef(null);
|
|
33
|
+
const didCellDragRef = useRef(false);
|
|
34
|
+
const fillDragRef = useRef(false);
|
|
35
|
+
const [fillTargetRow, setFillTargetRow] = useState(null);
|
|
36
|
+
const fillTargetRef = useRef(null);
|
|
37
|
+
const pointerRef = useRef(null);
|
|
38
|
+
const ownerRef = useRef(null);
|
|
39
|
+
const frameRef = useRef(null);
|
|
40
|
+
const handleRootPointerDown = (event) => {
|
|
41
|
+
if (event.button !== 0 || event.pointerType !== "mouse")
|
|
42
|
+
return;
|
|
43
|
+
if (selecting || editingCell)
|
|
44
|
+
return;
|
|
45
|
+
const target = event.target;
|
|
46
|
+
if (editingEnabled && target.closest("[data-fill-dot]")) {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
fillDragRef.current = true;
|
|
49
|
+
pointerRef.current = { x: event.clientX, y: event.clientY };
|
|
50
|
+
ownerRef.current = findGridScrollOwner(target);
|
|
51
|
+
setBodySelectionDisabled(true);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!MOUSE_DRAG_SELECT)
|
|
55
|
+
return;
|
|
56
|
+
if (gridControlAt(target) || target.closest("[data-action-menu]"))
|
|
57
|
+
return;
|
|
58
|
+
const cell = target.closest("[data-col-id]");
|
|
59
|
+
const row = target.closest("[data-row-id]");
|
|
60
|
+
if (!cell || !row)
|
|
61
|
+
return;
|
|
62
|
+
cellDragRef.current = {
|
|
63
|
+
startX: event.clientX,
|
|
64
|
+
startY: event.clientY,
|
|
65
|
+
rowId: row.getAttribute("data-row-id"),
|
|
66
|
+
columnId: cell.getAttribute("data-col-id"),
|
|
67
|
+
additive: event.metaKey || event.ctrlKey,
|
|
68
|
+
extend: event.shiftKey,
|
|
69
|
+
active: false,
|
|
70
|
+
};
|
|
71
|
+
pointerRef.current = { x: event.clientX, y: event.clientY };
|
|
72
|
+
ownerRef.current = findGridScrollOwner(target);
|
|
73
|
+
};
|
|
74
|
+
const handleRootClickCapture = (event) => {
|
|
75
|
+
if (!didCellDragRef.current)
|
|
76
|
+
return;
|
|
77
|
+
didCellDragRef.current = false;
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
event.stopPropagation();
|
|
80
|
+
};
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const dragging = () => fillDragRef.current || !!cellDragRef.current?.active;
|
|
83
|
+
const retarget = () => {
|
|
84
|
+
const root = rootRef.current;
|
|
85
|
+
const owner = ownerRef.current;
|
|
86
|
+
const point = pointerRef.current;
|
|
87
|
+
if (!root || !owner || !point)
|
|
88
|
+
return;
|
|
89
|
+
const hit = gridHitAtPoint(root, point.x, point.y, gridVisibleBox(root, owner));
|
|
90
|
+
if (!hit)
|
|
91
|
+
return;
|
|
92
|
+
if (fillDragRef.current) {
|
|
93
|
+
if (hit.rowId !== fillTargetRef.current) {
|
|
94
|
+
fillTargetRef.current = hit.rowId;
|
|
95
|
+
setFillTargetRow(hit.rowId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (cellDragRef.current?.active && hit.columnId) {
|
|
99
|
+
rangeExtendTo({ rowId: hit.rowId, columnId: hit.columnId });
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const tick = () => {
|
|
103
|
+
frameRef.current = null;
|
|
104
|
+
const root = rootRef.current;
|
|
105
|
+
const owner = ownerRef.current;
|
|
106
|
+
const point = pointerRef.current;
|
|
107
|
+
if (!root || !owner || !point || !dragging())
|
|
108
|
+
return;
|
|
109
|
+
const step = gridDragScrollStep(root, owner, point.y);
|
|
110
|
+
if (step !== 0) {
|
|
111
|
+
owner.scrollTop += step;
|
|
112
|
+
retarget();
|
|
113
|
+
}
|
|
114
|
+
frameRef.current = requestAnimationFrame(tick);
|
|
115
|
+
};
|
|
116
|
+
const follow = (event) => {
|
|
117
|
+
pointerRef.current = { x: event.clientX, y: event.clientY };
|
|
118
|
+
retarget();
|
|
119
|
+
if (frameRef.current == null)
|
|
120
|
+
frameRef.current = requestAnimationFrame(tick);
|
|
121
|
+
};
|
|
122
|
+
const stopEdgeScroll = () => {
|
|
123
|
+
if (frameRef.current != null)
|
|
124
|
+
cancelAnimationFrame(frameRef.current);
|
|
125
|
+
frameRef.current = null;
|
|
126
|
+
pointerRef.current = null;
|
|
127
|
+
ownerRef.current = null;
|
|
128
|
+
};
|
|
129
|
+
const onMove = (event) => {
|
|
130
|
+
if (fillDragRef.current) {
|
|
131
|
+
follow(event);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const drag = cellDragRef.current;
|
|
135
|
+
if (!drag)
|
|
136
|
+
return;
|
|
137
|
+
if (!drag.active) {
|
|
138
|
+
if (Math.abs(event.clientX - drag.startX) < 4 &&
|
|
139
|
+
Math.abs(event.clientY - drag.startY) < 4) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
drag.active = true;
|
|
143
|
+
setBodySelectionDisabled(true);
|
|
144
|
+
const start = { rowId: drag.rowId, columnId: drag.columnId };
|
|
145
|
+
if (drag.extend) {
|
|
146
|
+
rangeExtendTo(start, focusedRef.current ?? start);
|
|
147
|
+
if (!focusedRef.current)
|
|
148
|
+
focusCell(start.rowId, start.columnId);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
rangeBeginDrag(start, drag.additive);
|
|
152
|
+
focusCell(start.rowId, start.columnId);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
follow(event);
|
|
156
|
+
};
|
|
157
|
+
const onUp = () => {
|
|
158
|
+
stopEdgeScroll();
|
|
159
|
+
if (fillDragRef.current) {
|
|
160
|
+
fillDragRef.current = false;
|
|
161
|
+
setBodySelectionDisabled(false);
|
|
162
|
+
const target = fillTargetRef.current;
|
|
163
|
+
fillTargetRef.current = null;
|
|
164
|
+
setFillTargetRow(null);
|
|
165
|
+
if (target) {
|
|
166
|
+
didCellDragRef.current = true;
|
|
167
|
+
finishFillRef.current(target);
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const drag = cellDragRef.current;
|
|
172
|
+
cellDragRef.current = null;
|
|
173
|
+
if (drag?.active) {
|
|
174
|
+
didCellDragRef.current = true;
|
|
175
|
+
setBodySelectionDisabled(false);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
window.addEventListener("pointermove", onMove);
|
|
179
|
+
window.addEventListener("pointerup", onUp);
|
|
180
|
+
if (dragging() && pointerRef.current && frameRef.current == null) {
|
|
181
|
+
frameRef.current = requestAnimationFrame(tick);
|
|
182
|
+
}
|
|
183
|
+
return () => {
|
|
184
|
+
window.removeEventListener("pointermove", onMove);
|
|
185
|
+
window.removeEventListener("pointerup", onUp);
|
|
186
|
+
if (frameRef.current != null)
|
|
187
|
+
cancelAnimationFrame(frameRef.current);
|
|
188
|
+
frameRef.current = null;
|
|
189
|
+
};
|
|
190
|
+
}, [finishFillRef, focusCell, rangeBeginDrag, rangeExtendTo, rootRef]);
|
|
191
|
+
const editingRef = useRef(editingCell);
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
editingRef.current = editingCell;
|
|
194
|
+
}, [editingCell]);
|
|
195
|
+
const treePressRef = useRef(null);
|
|
196
|
+
const handleRootPointerDownCapture = (event) => {
|
|
197
|
+
treePressRef.current = event.nativeEvent;
|
|
198
|
+
didCellDragRef.current = false;
|
|
199
|
+
};
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
if (!focusedCell)
|
|
202
|
+
return;
|
|
203
|
+
const onPointerDown = (event) => {
|
|
204
|
+
const inTree = treePressRef.current === event;
|
|
205
|
+
treePressRef.current = null;
|
|
206
|
+
const target = event.target;
|
|
207
|
+
if (!target)
|
|
208
|
+
return;
|
|
209
|
+
if (inTree && !rootRef.current?.contains(target))
|
|
210
|
+
return;
|
|
211
|
+
if (rootRef.current?.contains(target)) {
|
|
212
|
+
if (target.closest?.("[data-col-id]"))
|
|
213
|
+
return;
|
|
214
|
+
if (target.dataset?.slot === "vk-grid-scroll" && onScrollbar(target, event))
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (editingRef.current) {
|
|
218
|
+
window.setTimeout(() => {
|
|
219
|
+
if (!editingRef.current)
|
|
220
|
+
clearFocus();
|
|
221
|
+
}, 0);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
clearFocus();
|
|
225
|
+
};
|
|
226
|
+
window.addEventListener("pointerdown", onPointerDown);
|
|
227
|
+
return () => window.removeEventListener("pointerdown", onPointerDown);
|
|
228
|
+
}, [clearFocus, focusedCell, rootRef]);
|
|
229
|
+
return {
|
|
230
|
+
fillTargetRow,
|
|
231
|
+
onExtendCell,
|
|
232
|
+
onAddCell,
|
|
233
|
+
handleRootPointerDown,
|
|
234
|
+
handleRootPointerDownCapture,
|
|
235
|
+
handleRootClickCapture,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ViewsRowMenuItem } from "../../atoms/types.js";
|
|
2
|
+
import type { ListCellAction, ListColumn } from "../../model/column-schema.js";
|
|
3
|
+
import type { GridRowRangeSpan } from "../core/useGridRange.js";
|
|
4
|
+
export declare function useGridRowContextMenu<Row>({ row, id, rowKey, columns, rowActions, selecting, selectable, selected, toggle, editingEnabled, pendingByCol, selectValues, rowRange, contextMenu, inActiveRange, rangeCanClear, onRangeCopy, onRangeCut, onRangePaste, onRangeClear, onPasteAtCell, onCommitCell, onFocusCell, }: {
|
|
5
|
+
row: Row;
|
|
6
|
+
/** The DATA id — what a commit and the selection toggle address. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** This RENDERED row's identity — what a position (range, focus, paste
|
|
9
|
+
* target) is in terms of. See `GridCellPos`. */
|
|
10
|
+
rowKey: string;
|
|
11
|
+
columns: ListColumn<Row>[];
|
|
12
|
+
/** The name's actions, the title's lane: each that applies to the row is a row of its menu. */
|
|
13
|
+
rowActions?: ListCellAction<Row>[];
|
|
14
|
+
selecting: boolean;
|
|
15
|
+
selectable: boolean;
|
|
16
|
+
selected: boolean;
|
|
17
|
+
toggle: (id: string, next?: boolean) => void;
|
|
18
|
+
editingEnabled: boolean;
|
|
19
|
+
pendingByCol?: Record<string, unknown>;
|
|
20
|
+
selectValues?: Record<string, string[]>;
|
|
21
|
+
rowRange?: GridRowRangeSpan[];
|
|
22
|
+
contextMenu?: (row: Row) => ViewsRowMenuItem[];
|
|
23
|
+
inActiveRange: (rowId: string, columnId: string) => boolean;
|
|
24
|
+
rangeCanClear: () => boolean;
|
|
25
|
+
onRangeCopy: () => void;
|
|
26
|
+
onRangeCut: () => void;
|
|
27
|
+
onRangePaste: () => void;
|
|
28
|
+
onRangeClear: () => void;
|
|
29
|
+
onPasteAtCell: (rowId: string, columnId: string) => void;
|
|
30
|
+
onCommitCell: (row: Row, rowId: string, columnId: string, previous: unknown, next: unknown, options?: {
|
|
31
|
+
overlay?: boolean;
|
|
32
|
+
}) => void;
|
|
33
|
+
onFocusCell: (rowId: string, columnId: string) => void;
|
|
34
|
+
}): {
|
|
35
|
+
contextItems: ViewsRowMenuItem[];
|
|
36
|
+
handleContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
|
|
37
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useViews } from "../../provider/context.js";
|
|
5
|
+
import { gridColumnHasEditor } from "../../model/column-capabilities.js";
|
|
6
|
+
import { cellClearPrev, cellEditBaseline, cellPrevPayload, coercePaste, copyCell, getGridClipboard, rowHoldsCurrency, } from "./cell-clipboard.js";
|
|
7
|
+
function nameActionItems(row, actions, hostItems) {
|
|
8
|
+
if (!actions?.length)
|
|
9
|
+
return [];
|
|
10
|
+
const listed = new Set(hostItems.flatMap((item) => (item.separator ? [] : [item.label])));
|
|
11
|
+
const items = [];
|
|
12
|
+
for (const action of actions) {
|
|
13
|
+
if (!action.onClick)
|
|
14
|
+
continue;
|
|
15
|
+
const label = action.label?.(row);
|
|
16
|
+
if (!label || listed.has(label))
|
|
17
|
+
continue;
|
|
18
|
+
const icon = action.icon(row);
|
|
19
|
+
if (!icon)
|
|
20
|
+
continue;
|
|
21
|
+
const run = action.onClick;
|
|
22
|
+
items.push({ label, icon, onClick: () => run(row) });
|
|
23
|
+
}
|
|
24
|
+
return items.length > 0 ? [...items, { separator: true }] : [];
|
|
25
|
+
}
|
|
26
|
+
export function useGridRowContextMenu({ row, id, rowKey, columns, rowActions, selecting, selectable, selected, toggle, editingEnabled, pendingByCol, selectValues, rowRange, contextMenu, inActiveRange, rangeCanClear, onRangeCopy, onRangeCut, onRangePaste, onRangeClear, onPasteAtCell, onCommitCell, onFocusCell, }) {
|
|
27
|
+
const { conventions, ports, messages, icons } = useViews();
|
|
28
|
+
const copyLabel = messages({ key: "views.menus.copy" });
|
|
29
|
+
const cutLabel = messages({ key: "views.menus.cut" });
|
|
30
|
+
const pasteLabel = messages({ key: "views.menus.paste" });
|
|
31
|
+
const clearLabel = messages({ key: "views.menus.clear" });
|
|
32
|
+
const [menuColumnId, setMenuColumnId] = useState(null);
|
|
33
|
+
const menuColumn = menuColumnId
|
|
34
|
+
? columns.find((column) => column.id === menuColumnId)
|
|
35
|
+
: undefined;
|
|
36
|
+
const editBaseline = (column) => cellEditBaseline(column, row, pendingByCol);
|
|
37
|
+
const canEdit = (column) => editingEnabled && gridColumnHasEditor(column);
|
|
38
|
+
const cellItems = [];
|
|
39
|
+
if (menuColumn && !selecting && inActiveRange(rowKey, menuColumn.id)) {
|
|
40
|
+
const clipboard = getGridClipboard();
|
|
41
|
+
cellItems.push({
|
|
42
|
+
label: copyLabel,
|
|
43
|
+
icon: _jsx(icons.copy, { className: "h-4 w-4" }),
|
|
44
|
+
shortcut: "⌘C",
|
|
45
|
+
onClick: onRangeCopy,
|
|
46
|
+
});
|
|
47
|
+
if (editingEnabled) {
|
|
48
|
+
const canClear = rangeCanClear();
|
|
49
|
+
cellItems.push({
|
|
50
|
+
label: cutLabel,
|
|
51
|
+
icon: _jsx(icons.cut, { className: "h-4 w-4" }),
|
|
52
|
+
shortcut: "⌘X",
|
|
53
|
+
disabled: !canClear,
|
|
54
|
+
onClick: onRangeCut,
|
|
55
|
+
}, {
|
|
56
|
+
label: pasteLabel,
|
|
57
|
+
icon: _jsx(icons.paste, { className: "h-4 w-4" }),
|
|
58
|
+
shortcut: "⌘V",
|
|
59
|
+
disabled: !clipboard,
|
|
60
|
+
onClick: onRangePaste,
|
|
61
|
+
}, {
|
|
62
|
+
label: clearLabel,
|
|
63
|
+
icon: _jsx(icons.clear, { className: "h-4 w-4" }),
|
|
64
|
+
disabled: !canClear,
|
|
65
|
+
onClick: onRangeClear,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
cellItems.push({ separator: true });
|
|
69
|
+
}
|
|
70
|
+
else if (menuColumn && !selecting) {
|
|
71
|
+
const unit = menuColumn.editUnit?.value(row);
|
|
72
|
+
const canWrite = canEdit(menuColumn);
|
|
73
|
+
const canClear = canWrite && !!menuColumn.clearable;
|
|
74
|
+
const clipboard = getGridClipboard();
|
|
75
|
+
const paste = canWrite && clipboard && !clipboard.matrix
|
|
76
|
+
? coercePaste(menuColumn, clipboard, {
|
|
77
|
+
conventions,
|
|
78
|
+
messages,
|
|
79
|
+
currentUnit: unit,
|
|
80
|
+
holdsCurrency: rowHoldsCurrency(menuColumn, row),
|
|
81
|
+
values: selectValues?.[menuColumn.id],
|
|
82
|
+
region: menuColumn.region?.(row),
|
|
83
|
+
})
|
|
84
|
+
: null;
|
|
85
|
+
cellItems.push({
|
|
86
|
+
label: copyLabel,
|
|
87
|
+
icon: _jsx(icons.copy, { className: "h-4 w-4" }),
|
|
88
|
+
shortcut: "⌘C",
|
|
89
|
+
onClick: () => void copyCell(ports.clipboard.writeText, menuColumn, editBaseline(menuColumn), unit),
|
|
90
|
+
});
|
|
91
|
+
if (editingEnabled) {
|
|
92
|
+
cellItems.push({
|
|
93
|
+
label: cutLabel,
|
|
94
|
+
icon: _jsx(icons.cut, { className: "h-4 w-4" }),
|
|
95
|
+
shortcut: "⌘X",
|
|
96
|
+
disabled: !canClear,
|
|
97
|
+
onClick: () => {
|
|
98
|
+
void copyCell(ports.clipboard.writeText, menuColumn, editBaseline(menuColumn), unit);
|
|
99
|
+
onCommitCell(row, id, menuColumn.id, cellClearPrev(menuColumn, row, pendingByCol), "");
|
|
100
|
+
},
|
|
101
|
+
}, {
|
|
102
|
+
label: pasteLabel,
|
|
103
|
+
icon: _jsx(icons.paste, { className: "h-4 w-4" }),
|
|
104
|
+
shortcut: "⌘V",
|
|
105
|
+
disabled: clipboard?.matrix ? false : !paste?.ok,
|
|
106
|
+
onClick: () => {
|
|
107
|
+
if (clipboard?.matrix) {
|
|
108
|
+
onPasteAtCell(rowKey, menuColumn.id);
|
|
109
|
+
}
|
|
110
|
+
else if (paste?.ok) {
|
|
111
|
+
onCommitCell(row, id, menuColumn.id, cellPrevPayload(menuColumn, editBaseline(menuColumn), unit), paste.next, { overlay: paste.overlay });
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
}, {
|
|
115
|
+
label: clearLabel,
|
|
116
|
+
icon: _jsx(icons.clear, { className: "h-4 w-4" }),
|
|
117
|
+
disabled: !canClear,
|
|
118
|
+
onClick: () => onCommitCell(row, id, menuColumn.id, cellClearPrev(menuColumn, row, pendingByCol), ""),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
cellItems.push({ separator: true });
|
|
122
|
+
}
|
|
123
|
+
const selectItems = selectable
|
|
124
|
+
? [
|
|
125
|
+
{
|
|
126
|
+
label: messages({ key: "views.menus.row-select", values: { selected: selected ? "true" : "false" } }),
|
|
127
|
+
icon: _jsx(icons.selectRow, { className: "h-4 w-4" }),
|
|
128
|
+
onClick: () => toggle(id),
|
|
129
|
+
},
|
|
130
|
+
{ separator: true },
|
|
131
|
+
]
|
|
132
|
+
: [];
|
|
133
|
+
const hostItems = contextMenu?.(row) ?? [];
|
|
134
|
+
const contextItems = [
|
|
135
|
+
...cellItems,
|
|
136
|
+
...selectItems,
|
|
137
|
+
...nameActionItems(row, rowActions, hostItems),
|
|
138
|
+
...hostItems,
|
|
139
|
+
];
|
|
140
|
+
const handleContextMenu = (event) => {
|
|
141
|
+
const target = event.target;
|
|
142
|
+
const columnId = target.closest("[data-col-id]")?.getAttribute("data-col-id");
|
|
143
|
+
const column = columnId ? columns.find((item) => item.id === columnId) : undefined;
|
|
144
|
+
setMenuColumnId(column?.id ?? null);
|
|
145
|
+
if (column && !selecting) {
|
|
146
|
+
const index = columns.findIndex((item) => item.id === column.id);
|
|
147
|
+
const inRange = rowRange?.some((span) => index >= span.startCol && index <= span.endCol);
|
|
148
|
+
if (!inRange)
|
|
149
|
+
onFocusCell(rowKey, column.id);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
return { contextItems, handleContextMenu };
|
|
153
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** One row's height at scale 1, in px: `--vk-row-h` is built from it, and the row window counts rows by it. */
|
|
2
|
+
export declare const GRID_ROW_PX = 37;
|
|
3
|
+
export declare function useGridScaleStyles(scale: number, grouped: boolean, phone: boolean, addColumn?: boolean): import("react").CSSProperties;
|