@rowsncolumns/spreadsheet 10.11.0 → 10.14.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/dist/cjs/api/split-pane.d.ts +1 -0
- package/dist/cjs/api/split-pane.d.ts.map +1 -1
- package/dist/cjs/api/split-pane.js +5 -1
- package/dist/cjs/atoms/calculated-column-fill.atom.d.ts +6 -2
- package/dist/cjs/atoms/calculated-column-fill.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/calculated-column-fill.atom.js +6 -2
- package/dist/cjs/atoms/cell-input-context.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/fill-options.atom.d.ts +5 -0
- package/dist/cjs/atoms/fill-options.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/table-auto-expansion.atom.d.ts +5 -2
- package/dist/cjs/atoms/table-auto-expansion.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/table-auto-expansion.atom.js +5 -2
- package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts +37 -0
- package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts.map +1 -0
- package/dist/cjs/components/autocorrect-options-smart-tag/index.js +84 -0
- package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/cjs/components/canvas-grid/index.js +388 -123
- package/dist/cjs/components/canvas-grid/typings.d.ts +45 -0
- package/dist/cjs/components/canvas-grid/typings.d.ts.map +1 -1
- package/dist/cjs/components/embeds/chart-component.d.ts +9 -0
- package/dist/cjs/components/embeds/chart-component.d.ts.map +1 -1
- package/dist/cjs/components/embeds/embed-component.d.ts +9 -0
- package/dist/cjs/components/embeds/embed-component.d.ts.map +1 -1
- package/dist/cjs/components/embeds/embed-component.js +13 -114
- package/dist/cjs/components/embeds/embed-draggable.d.ts +17 -2
- package/dist/cjs/components/embeds/embed-draggable.d.ts.map +1 -1
- package/dist/cjs/components/embeds/embed-draggable.js +336 -25
- package/dist/cjs/components/embeds/object-focus.d.ts +32 -0
- package/dist/cjs/components/embeds/object-focus.d.ts.map +1 -0
- package/dist/cjs/components/embeds/object-focus.js +140 -0
- package/dist/cjs/components/embeds/page-gaps.d.ts +67 -0
- package/dist/cjs/components/embeds/page-gaps.d.ts.map +1 -0
- package/dist/cjs/components/embeds/page-gaps.js +159 -0
- package/dist/cjs/components/embeds/pane-copy.d.ts +35 -0
- package/dist/cjs/components/embeds/pane-copy.d.ts.map +1 -0
- package/dist/cjs/components/embeds/pane-copy.js +29 -0
- package/dist/cjs/components/embeds/slicer-component.d.ts +9 -0
- package/dist/cjs/components/embeds/slicer-component.d.ts.map +1 -1
- package/dist/cjs/components/embeds/text-box-view.d.ts +18 -0
- package/dist/cjs/components/embeds/text-box-view.d.ts.map +1 -0
- package/dist/cjs/components/embeds/text-box-view.js +130 -0
- package/dist/cjs/components/filter-box/filter-by-color.d.ts.map +1 -1
- package/dist/cjs/components/filter-box/filter-by-color.js +10 -3
- package/dist/cjs/components/filter-box/index.d.ts.map +1 -1
- package/dist/cjs/components/filter-box/index.js +5 -1
- package/dist/cjs/components/print-preview/page-block.d.ts +46 -0
- package/dist/cjs/components/print-preview/page-block.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/page-block.js +111 -6
- package/dist/cjs/components/print-preview/print-cells.d.ts +5 -0
- package/dist/cjs/components/print-preview/print-cells.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/print-cells.js +1 -0
- package/dist/cjs/components/print-preview/print-preview-dialog.d.ts +16 -2
- package/dist/cjs/components/print-preview/print-preview-dialog.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/print-preview-dialog.js +246 -14
- package/dist/cjs/components/print-preview/settings.d.ts +8 -0
- package/dist/cjs/components/print-preview/settings.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/settings.js +4 -1
- package/dist/cjs/components/print-preview/sheet-page-setup.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/sheet-page-setup.js +14 -2
- package/dist/cjs/components/selection/fill-options-menu.d.ts +8 -1
- package/dist/cjs/components/selection/fill-options-menu.d.ts.map +1 -1
- package/dist/cjs/components/selection/fill-options-menu.js +5 -3
- package/dist/cjs/components/selection/index.d.ts +1 -1
- package/dist/cjs/components/selection/index.d.ts.map +1 -1
- package/dist/cjs/components/selection/index.js +5 -6
- package/dist/cjs/components/selection/types.d.ts +13 -8
- package/dist/cjs/components/selection/types.d.ts.map +1 -1
- package/dist/cjs/components/sheet-background/index.d.ts +26 -0
- package/dist/cjs/components/sheet-background/index.d.ts.map +1 -0
- package/dist/cjs/components/sheet-background/index.js +106 -0
- package/dist/cjs/components/sort-range-dialog/index.d.ts.map +1 -1
- package/dist/cjs/components/sort-range-dialog/index.js +6 -3
- package/dist/cjs/hooks/object-clipboard-payload.d.ts +58 -0
- package/dist/cjs/hooks/object-clipboard-payload.d.ts.map +1 -0
- package/dist/cjs/hooks/object-clipboard-payload.js +488 -0
- package/dist/cjs/hooks/object-spec-schema.generated.d.ts +24 -0
- package/dist/cjs/hooks/object-spec-schema.generated.d.ts.map +1 -0
- package/dist/cjs/hooks/object-spec-schema.generated.js +4779 -0
- package/dist/cjs/hooks/use-chart-clipboard.d.ts +55 -9
- package/dist/cjs/hooks/use-chart-clipboard.d.ts.map +1 -1
- package/dist/cjs/hooks/use-chart-clipboard.js +307 -55
- package/dist/cjs/hooks/use-embeds-charts.d.ts +12 -1
- package/dist/cjs/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/cjs/hooks/use-embeds-charts.js +86 -17
- package/dist/cjs/hooks/use-grid-children.d.ts +4 -2
- package/dist/cjs/hooks/use-grid-children.d.ts.map +1 -1
- package/dist/cjs/hooks/use-grid-children.js +74 -16
- package/dist/cjs/hooks/use-selection-renderer.d.ts +16 -5
- package/dist/cjs/hooks/use-selection-renderer.d.ts.map +1 -1
- package/dist/cjs/hooks/use-selection-renderer.js +59 -32
- package/dist/cjs/hooks/use-shown-notes.d.ts +11 -1
- package/dist/cjs/hooks/use-shown-notes.d.ts.map +1 -1
- package/dist/cjs/hooks/use-shown-notes.js +34 -12
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/release-date.js +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +64 -0
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/api/split-pane.d.ts +1 -0
- package/dist/esm/api/split-pane.d.ts.map +1 -1
- package/dist/esm/api/split-pane.js +5 -1
- package/dist/esm/atoms/calculated-column-fill.atom.d.ts +6 -2
- package/dist/esm/atoms/calculated-column-fill.atom.d.ts.map +1 -1
- package/dist/esm/atoms/calculated-column-fill.atom.js +6 -2
- package/dist/esm/atoms/cell-input-context.atom.d.ts.map +1 -1
- package/dist/esm/atoms/fill-options.atom.d.ts +5 -0
- package/dist/esm/atoms/fill-options.atom.d.ts.map +1 -1
- package/dist/esm/atoms/table-auto-expansion.atom.d.ts +5 -2
- package/dist/esm/atoms/table-auto-expansion.atom.d.ts.map +1 -1
- package/dist/esm/atoms/table-auto-expansion.atom.js +5 -2
- package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts +37 -0
- package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts.map +1 -0
- package/dist/esm/components/autocorrect-options-smart-tag/index.js +87 -0
- package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/esm/components/canvas-grid/index.js +307 -59
- package/dist/esm/components/canvas-grid/typings.d.ts +45 -0
- package/dist/esm/components/canvas-grid/typings.d.ts.map +1 -1
- package/dist/esm/components/embeds/chart-component.d.ts +9 -0
- package/dist/esm/components/embeds/chart-component.d.ts.map +1 -1
- package/dist/esm/components/embeds/embed-component.d.ts +9 -0
- package/dist/esm/components/embeds/embed-component.d.ts.map +1 -1
- package/dist/esm/components/embeds/embed-component.js +12 -113
- package/dist/esm/components/embeds/embed-draggable.d.ts +17 -2
- package/dist/esm/components/embeds/embed-draggable.d.ts.map +1 -1
- package/dist/esm/components/embeds/embed-draggable.js +327 -19
- package/dist/esm/components/embeds/object-focus.d.ts +32 -0
- package/dist/esm/components/embeds/object-focus.d.ts.map +1 -0
- package/dist/esm/components/embeds/object-focus.js +118 -0
- package/dist/esm/components/embeds/page-gaps.d.ts +67 -0
- package/dist/esm/components/embeds/page-gaps.d.ts.map +1 -0
- package/dist/esm/components/embeds/page-gaps.js +86 -0
- package/dist/esm/components/embeds/pane-copy.d.ts +35 -0
- package/dist/esm/components/embeds/pane-copy.d.ts.map +1 -0
- package/dist/esm/components/embeds/pane-copy.js +22 -0
- package/dist/esm/components/embeds/slicer-component.d.ts +9 -0
- package/dist/esm/components/embeds/slicer-component.d.ts.map +1 -1
- package/dist/esm/components/embeds/text-box-view.d.ts +18 -0
- package/dist/esm/components/embeds/text-box-view.d.ts.map +1 -0
- package/dist/esm/components/embeds/text-box-view.js +118 -0
- package/dist/esm/components/filter-box/filter-by-color.d.ts.map +1 -1
- package/dist/esm/components/filter-box/filter-by-color.js +9 -2
- package/dist/esm/components/filter-box/index.d.ts.map +1 -1
- package/dist/esm/components/filter-box/index.js +5 -1
- package/dist/esm/components/print-preview/page-block.d.ts +46 -0
- package/dist/esm/components/print-preview/page-block.d.ts.map +1 -1
- package/dist/esm/components/print-preview/page-block.js +122 -4
- package/dist/esm/components/print-preview/print-cells.d.ts +5 -0
- package/dist/esm/components/print-preview/print-cells.d.ts.map +1 -1
- package/dist/esm/components/print-preview/print-cells.js +1 -0
- package/dist/esm/components/print-preview/print-preview-dialog.d.ts +16 -2
- package/dist/esm/components/print-preview/print-preview-dialog.d.ts.map +1 -1
- package/dist/esm/components/print-preview/print-preview-dialog.js +195 -4
- package/dist/esm/components/print-preview/settings.d.ts +8 -0
- package/dist/esm/components/print-preview/settings.d.ts.map +1 -1
- package/dist/esm/components/print-preview/settings.js +4 -1
- package/dist/esm/components/print-preview/sheet-page-setup.d.ts.map +1 -1
- package/dist/esm/components/print-preview/sheet-page-setup.js +14 -0
- package/dist/esm/components/selection/fill-options-menu.d.ts +8 -1
- package/dist/esm/components/selection/fill-options-menu.d.ts.map +1 -1
- package/dist/esm/components/selection/fill-options-menu.js +5 -3
- package/dist/esm/components/selection/index.d.ts +1 -1
- package/dist/esm/components/selection/index.d.ts.map +1 -1
- package/dist/esm/components/selection/index.js +5 -6
- package/dist/esm/components/selection/types.d.ts +13 -8
- package/dist/esm/components/selection/types.d.ts.map +1 -1
- package/dist/esm/components/sheet-background/index.d.ts +26 -0
- package/dist/esm/components/sheet-background/index.d.ts.map +1 -0
- package/dist/esm/components/sheet-background/index.js +93 -0
- package/dist/esm/components/sort-range-dialog/index.d.ts.map +1 -1
- package/dist/esm/components/sort-range-dialog/index.js +5 -2
- package/dist/esm/hooks/object-clipboard-payload.d.ts +58 -0
- package/dist/esm/hooks/object-clipboard-payload.d.ts.map +1 -0
- package/dist/esm/hooks/object-clipboard-payload.js +404 -0
- package/dist/esm/hooks/object-spec-schema.generated.d.ts +24 -0
- package/dist/esm/hooks/object-spec-schema.generated.d.ts.map +1 -0
- package/dist/esm/hooks/object-spec-schema.generated.js +4776 -0
- package/dist/esm/hooks/use-chart-clipboard.d.ts +55 -9
- package/dist/esm/hooks/use-chart-clipboard.d.ts.map +1 -1
- package/dist/esm/hooks/use-chart-clipboard.js +298 -53
- package/dist/esm/hooks/use-embeds-charts.d.ts +12 -1
- package/dist/esm/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/esm/hooks/use-embeds-charts.js +83 -16
- package/dist/esm/hooks/use-grid-children.d.ts +4 -2
- package/dist/esm/hooks/use-grid-children.d.ts.map +1 -1
- package/dist/esm/hooks/use-grid-children.js +59 -16
- package/dist/esm/hooks/use-selection-renderer.d.ts +16 -5
- package/dist/esm/hooks/use-selection-renderer.d.ts.map +1 -1
- package/dist/esm/hooks/use-selection-renderer.js +54 -28
- package/dist/esm/hooks/use-shown-notes.d.ts +11 -1
- package/dist/esm/hooks/use-shown-notes.d.ts.map +1 -1
- package/dist/esm/hooks/use-shown-notes.js +23 -12
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/release-date.js +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +64 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/spreadsheet.min.css +1 -1
- package/package.json +4 -4
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { getOwnerDocument, useGridContext, useIsInRtlMirrorLayer, } from "@rowsncolumns/grid";
|
|
2
2
|
import { cn } from "@rowsncolumns/ui";
|
|
3
|
-
import
|
|
3
|
+
import { useAtomValue } from "jotai";
|
|
4
|
+
import React, { useCallback, useContext, useEffect, useRef, useState, } from "react";
|
|
4
5
|
import { DraggableCore } from "react-draggable";
|
|
5
6
|
import { Resizable } from "react-resizable";
|
|
7
|
+
import { editingCellAtom } from "../../atoms/editing-cell.atom";
|
|
6
8
|
import { useIsomorphicLayoutEffect } from "../../hooks/use-isomorphic-layout-effect";
|
|
9
|
+
import { commandOrigins, mayReclaimFocus, mayTakeFocus, objectFocusTargetsAtom, sheetFocusTargetsAtom, } from "./object-focus";
|
|
10
|
+
import { PaneCopyContext, paneCopyPiece } from "./pane-copy";
|
|
11
|
+
import { resolvePageGaps, splitAcrossPages, toGapFree, toScreen, } from "./page-gaps";
|
|
12
|
+
/** The smallest width and height a resize leaves: react-resizable's default `minConstraints`. */
|
|
13
|
+
const MIN_OBJECT_SIZE = 20;
|
|
7
14
|
/** Lifts the selected object over every unselected one (ranks count from 1 per object). */
|
|
8
15
|
const SELECTED_Z_INDEX_LIFT = 100_000;
|
|
9
16
|
const ARROW_KEY_DELTAS = {
|
|
@@ -34,7 +41,7 @@ const resizeHandles = [
|
|
|
34
41
|
"nw",
|
|
35
42
|
"sw",
|
|
36
43
|
];
|
|
37
|
-
export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, offsetYPixels, isSelected, borderColor, lockAspectRatio, zIndex, resizable = true, draggable = true, children, onMove, onResize, onDelete, onDuplicate, onCopy, onCut, onPaste, onDeselect, onDoubleClick, snapToGrid, onRequestContextMenu, onMouseMove, onPointerDown, onSelectAllObjects, bounds, anchorCell, toCell, toOffsetXPixels = 0, toOffsetYPixels = 0, }) => {
|
|
44
|
+
export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, offsetYPixels, isSelected, borderColor, lockAspectRatio, zIndex, resizable = true, draggable = true, children, onMove, onResize, onDelete, onDuplicate, onCopy, onCut, onPaste, onDeselect, onDoubleClick, snapToGrid, onRequestContextMenu, onMouseMove, onPointerDown, onSelectAllObjects, bounds, anchorCell, toCell, toOffsetXPixels = 0, toOffsetYPixels = 0, pageGaps: pageGapIndexes, }) => {
|
|
38
45
|
// Right-to-left sheet: the object sits at its mirrored anchor; flip its box
|
|
39
46
|
// back so a chart or picture is not drawn mirrored. Its geometry stays in
|
|
40
47
|
// sheet (logical) pixels, so a pointer or arrow-key movement to the
|
|
@@ -42,6 +49,10 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
42
49
|
const unmirror = useIsInRtlMirrorLayer();
|
|
43
50
|
const physicalToLogicalX = unmirror ? -1 : 1;
|
|
44
51
|
const { getCellOffsetFromCoords } = useGridContext();
|
|
52
|
+
const paneCopy = useContext(PaneCopyContext);
|
|
53
|
+
const pageGaps = pageGapIndexes
|
|
54
|
+
? resolvePageGaps(pageGapIndexes, getCellOffsetFromCoords)
|
|
55
|
+
: undefined;
|
|
45
56
|
const position = getCellOffsetFromCoords?.(anchorCell);
|
|
46
57
|
const x = (position?.x ?? 0) + offsetXPixels;
|
|
47
58
|
const y = (position?.y ?? 0) + offsetYPixels;
|
|
@@ -49,8 +60,16 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
49
60
|
// after a delete draws nothing rather than a negative box)
|
|
50
61
|
const toPosition = toCell ? getCellOffsetFromCoords?.(toCell) : undefined;
|
|
51
62
|
if (toPosition) {
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
// Across Page Layout's gaps the frame is what lies between the anchors on the sheet itself,
|
|
64
|
+
// not the gaps between them.
|
|
65
|
+
width = Math.max(0, pageGaps
|
|
66
|
+
? toGapFree(pageGaps.x, toPosition.x + toOffsetXPixels) -
|
|
67
|
+
toGapFree(pageGaps.x, x)
|
|
68
|
+
: toPosition.x + toOffsetXPixels - x);
|
|
69
|
+
height = Math.max(0, pageGaps
|
|
70
|
+
? toGapFree(pageGaps.y, toPosition.y + toOffsetYPixels) -
|
|
71
|
+
toGapFree(pageGaps.y, y)
|
|
72
|
+
: toPosition.y + toOffsetYPixels - y);
|
|
54
73
|
}
|
|
55
74
|
const [dimensions, setDimensions] = useState(() => ({
|
|
56
75
|
internalWidth: width,
|
|
@@ -69,16 +88,97 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
69
88
|
const gestureRef = useRef(dimensions);
|
|
70
89
|
// Shift on a corner handle keeps the aspect ratio for the rest of the gesture
|
|
71
90
|
const [shiftLocksAspectRatio, setShiftLocksAspectRatio] = useState(false);
|
|
91
|
+
/** In Page Layout view: the object's edges in grid pixels, where the pointer put them. */
|
|
92
|
+
const pageGestureRef = useRef(null);
|
|
93
|
+
/**
|
|
94
|
+
* The object as drawn: one box, or in Page Layout view its pieces per page and the extent they
|
|
95
|
+
* span with the gaps between them.
|
|
96
|
+
*/
|
|
97
|
+
const pagesOf = useCallback((box) => pageGaps
|
|
98
|
+
? {
|
|
99
|
+
x: splitAcrossPages(pageGaps.x, box.internalX, box.internalWidth),
|
|
100
|
+
y: splitAcrossPages(pageGaps.y, box.internalY, box.internalHeight),
|
|
101
|
+
}
|
|
102
|
+
: undefined, [pageGaps]);
|
|
72
103
|
const commit = useCallback((next) => {
|
|
73
104
|
appliedRef.current = next;
|
|
74
105
|
setDimensions(next);
|
|
75
106
|
}, []);
|
|
76
|
-
//
|
|
107
|
+
// The keyboard follows the selection, however the object was selected: a click, an insert,
|
|
108
|
+
// a paste, the Selection Pane (`mayTakeFocus`: never from a cell being edited, a dialog or an
|
|
109
|
+
// editable control other than the sheet's own cell editor).
|
|
110
|
+
const editingCell = useAtomValue(editingCellAtom);
|
|
111
|
+
const editingRef = useRef(false);
|
|
112
|
+
editingRef.current = editingCell !== undefined;
|
|
113
|
+
const focusTargets = useAtomValue(objectFocusTargetsAtom);
|
|
114
|
+
const sheetFocusTargets = useAtomValue(sheetFocusTargetsAtom);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
const node = nodeRef.current;
|
|
117
|
+
if (!node)
|
|
118
|
+
return;
|
|
119
|
+
focusTargets.set(id, node);
|
|
120
|
+
return () => {
|
|
121
|
+
if (focusTargets.get(id) === node)
|
|
122
|
+
focusTargets.delete(id);
|
|
123
|
+
};
|
|
124
|
+
}, [focusTargets, id]);
|
|
77
125
|
useIsomorphicLayoutEffect(() => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
126
|
+
const node = nodeRef.current;
|
|
127
|
+
if (!isSelected || !node)
|
|
128
|
+
return;
|
|
129
|
+
const ownerDocument = getOwnerDocument(node);
|
|
130
|
+
if (!ownerDocument)
|
|
131
|
+
return;
|
|
132
|
+
const origins = commandOrigins(node);
|
|
133
|
+
if (ownerDocument.activeElement !== node) {
|
|
134
|
+
if (!mayTakeFocus(node, editingRef.current, sheetFocusTargets)) {
|
|
135
|
+
// Focus stayed where the person is (an editor, a dialog, a field): nothing to take back.
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
node.focus({ preventScroll: true });
|
|
81
139
|
}
|
|
140
|
+
// What closes the command that selected it often moves focus right after (a menu hands it
|
|
141
|
+
// back to its trigger, a host returns it to the sheet): until the person next presses a key
|
|
142
|
+
// or the pointer, or a second has passed, the object takes it back from the page, the
|
|
143
|
+
// sheet's own target or the command's control (`mayReclaimFocus`), and from nowhere else.
|
|
144
|
+
let timer;
|
|
145
|
+
const schedule = () => {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
timer = setTimeout(() => {
|
|
148
|
+
if (node.isConnected &&
|
|
149
|
+
ownerDocument.activeElement !== node &&
|
|
150
|
+
mayReclaimFocus(node, editingRef.current, sheetFocusTargets, origins)) {
|
|
151
|
+
node.focus({ preventScroll: true });
|
|
152
|
+
}
|
|
153
|
+
}, 0);
|
|
154
|
+
};
|
|
155
|
+
const onFocusIn = (event) => {
|
|
156
|
+
const target = event.target;
|
|
157
|
+
if (target && node.contains(target))
|
|
158
|
+
return;
|
|
159
|
+
schedule();
|
|
160
|
+
};
|
|
161
|
+
// Focus dropped to the page fires no `focusin`.
|
|
162
|
+
const onFocusOut = (event) => {
|
|
163
|
+
if (event.relatedTarget === null)
|
|
164
|
+
schedule();
|
|
165
|
+
};
|
|
166
|
+
const stop = () => {
|
|
167
|
+
ownerDocument.removeEventListener("focusin", onFocusIn, true);
|
|
168
|
+
node.removeEventListener("focusout", onFocusOut);
|
|
169
|
+
ownerDocument.removeEventListener("pointerdown", stop, true);
|
|
170
|
+
ownerDocument.removeEventListener("keydown", stop, true);
|
|
171
|
+
clearTimeout(expiry);
|
|
172
|
+
};
|
|
173
|
+
ownerDocument.addEventListener("focusin", onFocusIn, true);
|
|
174
|
+
node.addEventListener("focusout", onFocusOut);
|
|
175
|
+
ownerDocument.addEventListener("pointerdown", stop, true);
|
|
176
|
+
ownerDocument.addEventListener("keydown", stop, true);
|
|
177
|
+
const expiry = setTimeout(stop, 1000);
|
|
178
|
+
return () => {
|
|
179
|
+
stop();
|
|
180
|
+
clearTimeout(timer);
|
|
181
|
+
};
|
|
82
182
|
}, [isSelected]);
|
|
83
183
|
// Starts moving
|
|
84
184
|
const handleMoveStart = useCallback((e) => {
|
|
@@ -105,16 +205,30 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
105
205
|
}, [bounds, snapToGrid, commit, physicalToLogicalX]);
|
|
106
206
|
// Ends moving
|
|
107
207
|
const handleMoveEnd = useCallback(() => {
|
|
208
|
+
if (pageGaps) {
|
|
209
|
+
// A corner dropped in the gap between pages lands at the start of the page after it.
|
|
210
|
+
const applied = appliedRef.current;
|
|
211
|
+
const snappedX = toScreen(pageGaps.x, toGapFree(pageGaps.x, applied.internalX));
|
|
212
|
+
const snappedY = toScreen(pageGaps.y, toGapFree(pageGaps.y, applied.internalY));
|
|
213
|
+
if (snappedX !== applied.internalX || snappedY !== applied.internalY) {
|
|
214
|
+
commit({ ...applied, internalX: snappedX, internalY: snappedY });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
108
217
|
const { internalX, internalY, internalWidth, internalHeight } = appliedRef.current;
|
|
109
218
|
if (incomingDimensionRef.current?.x === internalX &&
|
|
110
219
|
incomingDimensionRef.current?.y === internalY) {
|
|
111
220
|
return;
|
|
112
221
|
}
|
|
113
222
|
onMove?.(id, internalX, internalY, internalWidth, internalHeight);
|
|
114
|
-
}, [onMove, id]);
|
|
223
|
+
}, [onMove, id, pageGaps, commit]);
|
|
115
224
|
// Arrow keys nudge the object by whole pixels, clamped like a drag is
|
|
116
225
|
const handleNudge = useCallback((dx, dy) => {
|
|
117
|
-
|
|
226
|
+
// In Page Layout view a nudge steps over the gap between pages, as the sheet runs on.
|
|
227
|
+
const { x: nextX, y: nextY } = clampToBounds(pageGaps
|
|
228
|
+
? toScreen(pageGaps.x, toGapFree(pageGaps.x, internalX) + dx)
|
|
229
|
+
: internalX + dx, pageGaps
|
|
230
|
+
? toScreen(pageGaps.y, toGapFree(pageGaps.y, internalY) + dy)
|
|
231
|
+
: internalY + dy, internalWidth, internalHeight, bounds);
|
|
118
232
|
if (nextX === internalX && nextY === internalY) {
|
|
119
233
|
return;
|
|
120
234
|
}
|
|
@@ -129,16 +243,110 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
129
243
|
onMove,
|
|
130
244
|
id,
|
|
131
245
|
commit,
|
|
246
|
+
pageGaps,
|
|
132
247
|
]);
|
|
133
248
|
// Starts resizing
|
|
134
249
|
const handleResizeStart = useCallback((e, { handle }) => {
|
|
135
250
|
gestureRef.current = { ...appliedRef.current };
|
|
251
|
+
const pages = pagesOf(appliedRef.current);
|
|
252
|
+
pageGestureRef.current = pages
|
|
253
|
+
? {
|
|
254
|
+
left: pages.x.start,
|
|
255
|
+
top: pages.y.start,
|
|
256
|
+
right: pages.x.start + pages.x.extent,
|
|
257
|
+
bottom: pages.y.start + pages.y.extent,
|
|
258
|
+
}
|
|
259
|
+
: null;
|
|
136
260
|
setShiftLocksAspectRatio(isCornerHandle(handle) && Boolean(e.shiftKey));
|
|
137
|
-
}, []);
|
|
261
|
+
}, [pagesOf]);
|
|
138
262
|
// Resizing: Update internal state; Alt snaps the dragged edges to the cell grid
|
|
139
263
|
const handleResize = useCallback((e, { size, handle }) => {
|
|
140
264
|
const { altKey, shiftKey } = e;
|
|
141
265
|
setShiftLocksAspectRatio(isCornerHandle(handle) && Boolean(shiftKey));
|
|
266
|
+
const pageRaw = pageGestureRef.current;
|
|
267
|
+
// What react-resizable measured this event against: the frame as rendered.
|
|
268
|
+
const rendered = pagesOf(dimensions);
|
|
269
|
+
if (pageGaps && pageRaw && rendered) {
|
|
270
|
+
// Page Layout view: the pointer moves the dragged edges over the pages as drawn, gaps
|
|
271
|
+
// included; the object's own size is what lies between its edges on the sheet.
|
|
272
|
+
const deltaWidth = size.width - rendered.x.extent;
|
|
273
|
+
const deltaHeight = size.height - rendered.y.extent;
|
|
274
|
+
const side = handle[handle.length - 1];
|
|
275
|
+
const logicalSide = unmirror && side === "e" ? "w" : unmirror && side === "w" ? "e" : side;
|
|
276
|
+
const movesLeft = logicalSide === "w";
|
|
277
|
+
const movesTop = handle[0] === "n";
|
|
278
|
+
if (movesLeft)
|
|
279
|
+
pageRaw.left -= deltaWidth;
|
|
280
|
+
if (logicalSide === "e")
|
|
281
|
+
pageRaw.right += deltaWidth;
|
|
282
|
+
if (movesTop)
|
|
283
|
+
pageRaw.top -= deltaHeight;
|
|
284
|
+
if (handle[0] === "s")
|
|
285
|
+
pageRaw.bottom += deltaHeight;
|
|
286
|
+
let left = clampEdge(pageRaw.left, bounds?.left, undefined);
|
|
287
|
+
let top = clampEdge(pageRaw.top, bounds?.top, undefined);
|
|
288
|
+
let right = clampEdge(pageRaw.right, undefined, bounds?.right);
|
|
289
|
+
let bottom = clampEdge(pageRaw.bottom, undefined, bounds?.bottom);
|
|
290
|
+
if (altKey && snapToGrid) {
|
|
291
|
+
left = logicalSide === "w" ? snapToGrid(left, top)?.x ?? left : left;
|
|
292
|
+
right = logicalSide === "e" ? snapToGrid(right, top)?.x ?? right : right;
|
|
293
|
+
top = handle[0] === "n" ? snapToGrid(left, top)?.y ?? top : top;
|
|
294
|
+
bottom = handle[0] === "s" ? snapToGrid(left, bottom)?.y ?? bottom : bottom;
|
|
295
|
+
}
|
|
296
|
+
let gapFreeLeft = toGapFree(pageGaps.x, left);
|
|
297
|
+
let gapFreeTop = toGapFree(pageGaps.y, top);
|
|
298
|
+
let gapFreeRight = toGapFree(pageGaps.x, right);
|
|
299
|
+
let gapFreeBottom = toGapFree(pageGaps.y, bottom);
|
|
300
|
+
// A locked ratio holds for the object's own size, not the frame as drawn (which spans the
|
|
301
|
+
// gaps): the rule react-resizable applies in Normal view, on the gap-free size.
|
|
302
|
+
const locked = lockAspectRatio || (isCornerHandle(handle) && Boolean(shiftKey));
|
|
303
|
+
if (locked && dimensions.internalHeight > 0) {
|
|
304
|
+
const ratio = dimensions.internalWidth / dimensions.internalHeight;
|
|
305
|
+
let width = gapFreeRight - gapFreeLeft;
|
|
306
|
+
let height = gapFreeBottom - gapFreeTop;
|
|
307
|
+
const deltaW = width - dimensions.internalWidth;
|
|
308
|
+
const deltaH = height - dimensions.internalHeight;
|
|
309
|
+
if (Math.abs(deltaW) > Math.abs(deltaH * ratio)) {
|
|
310
|
+
height = width / ratio;
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
width = height * ratio;
|
|
314
|
+
}
|
|
315
|
+
if (movesTop)
|
|
316
|
+
gapFreeTop = gapFreeBottom - height;
|
|
317
|
+
else
|
|
318
|
+
gapFreeBottom = gapFreeTop + height;
|
|
319
|
+
if (movesLeft)
|
|
320
|
+
gapFreeLeft = gapFreeRight - width;
|
|
321
|
+
else
|
|
322
|
+
gapFreeRight = gapFreeLeft + width;
|
|
323
|
+
pageRaw.left = toScreen(pageGaps.x, gapFreeLeft);
|
|
324
|
+
pageRaw.top = toScreen(pageGaps.y, gapFreeTop);
|
|
325
|
+
pageRaw.right = toScreen(pageGaps.x, gapFreeRight);
|
|
326
|
+
pageRaw.bottom = toScreen(pageGaps.y, gapFreeBottom);
|
|
327
|
+
}
|
|
328
|
+
// Normal view's smallest object: react-resizable's `minConstraints`, applied after the
|
|
329
|
+
// ratio as it applies them, moving the dragged edge.
|
|
330
|
+
if (gapFreeRight - gapFreeLeft < MIN_OBJECT_SIZE) {
|
|
331
|
+
if (movesLeft)
|
|
332
|
+
gapFreeLeft = gapFreeRight - MIN_OBJECT_SIZE;
|
|
333
|
+
else
|
|
334
|
+
gapFreeRight = gapFreeLeft + MIN_OBJECT_SIZE;
|
|
335
|
+
}
|
|
336
|
+
if (gapFreeBottom - gapFreeTop < MIN_OBJECT_SIZE) {
|
|
337
|
+
if (movesTop)
|
|
338
|
+
gapFreeTop = gapFreeBottom - MIN_OBJECT_SIZE;
|
|
339
|
+
else
|
|
340
|
+
gapFreeBottom = gapFreeTop + MIN_OBJECT_SIZE;
|
|
341
|
+
}
|
|
342
|
+
commit({
|
|
343
|
+
internalX: toScreen(pageGaps.x, gapFreeLeft),
|
|
344
|
+
internalY: toScreen(pageGaps.y, gapFreeTop),
|
|
345
|
+
internalWidth: gapFreeRight - gapFreeLeft,
|
|
346
|
+
internalHeight: gapFreeBottom - gapFreeTop,
|
|
347
|
+
});
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
142
350
|
// `size` is the rendered size (`dimensions`) plus this event's pointer delta
|
|
143
351
|
const deltaHeight = size.height - dimensions.internalHeight;
|
|
144
352
|
const deltaWidth = size.width - dimensions.internalWidth;
|
|
@@ -201,7 +409,16 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
201
409
|
internalWidth: right - left,
|
|
202
410
|
internalHeight: bottom - top,
|
|
203
411
|
});
|
|
204
|
-
}, [
|
|
412
|
+
}, [
|
|
413
|
+
dimensions,
|
|
414
|
+
snapToGrid,
|
|
415
|
+
commit,
|
|
416
|
+
unmirror,
|
|
417
|
+
pageGaps,
|
|
418
|
+
pagesOf,
|
|
419
|
+
bounds,
|
|
420
|
+
lockAspectRatio,
|
|
421
|
+
]);
|
|
205
422
|
// Resize ends
|
|
206
423
|
const handleResizeEnd = useCallback(() => {
|
|
207
424
|
setShiftLocksAspectRatio(false);
|
|
@@ -227,13 +444,65 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
227
444
|
internalWidth: width,
|
|
228
445
|
});
|
|
229
446
|
}, [width, height, x, y, commit]);
|
|
447
|
+
const pages = pagesOf(dimensions);
|
|
448
|
+
const isCut = pages !== undefined &&
|
|
449
|
+
(pages.x.pieces.length > 1 || pages.y.pieces.length > 1);
|
|
450
|
+
/** What is drawn: one box as before, or the pieces of an object a page boundary cuts. */
|
|
451
|
+
const drawn = pages && isCut
|
|
452
|
+
? {
|
|
453
|
+
x: pages.x.start,
|
|
454
|
+
y: pages.y.start,
|
|
455
|
+
width: pages.x.extent,
|
|
456
|
+
height: pages.y.extent,
|
|
457
|
+
pieces: pages.y.pieces.flatMap((row, rowIndex) => pages.x.pieces.map((column, columnIndex) => ({
|
|
458
|
+
x: column.offset,
|
|
459
|
+
y: row.offset,
|
|
460
|
+
width: column.length,
|
|
461
|
+
height: row.length,
|
|
462
|
+
contentX: column.content,
|
|
463
|
+
contentY: row.content,
|
|
464
|
+
// Which of the object's own edges this piece carries (the others are cut edges).
|
|
465
|
+
edges: {
|
|
466
|
+
top: rowIndex === 0,
|
|
467
|
+
bottom: rowIndex === pages.y.pieces.length - 1,
|
|
468
|
+
left: columnIndex === 0,
|
|
469
|
+
right: columnIndex === pages.x.pieces.length - 1,
|
|
470
|
+
},
|
|
471
|
+
}))),
|
|
472
|
+
}
|
|
473
|
+
: {
|
|
474
|
+
x: internalX,
|
|
475
|
+
y: internalY,
|
|
476
|
+
width: internalWidth,
|
|
477
|
+
height: internalHeight,
|
|
478
|
+
pieces: undefined,
|
|
479
|
+
};
|
|
480
|
+
/**
|
|
481
|
+
* On a split sheet this is one pane's copy of the object. It is drawn only in the panes it is
|
|
482
|
+
* visible in — judged by the STORED box, so a copy never disappears in the middle of its own
|
|
483
|
+
* drag — and tells its content which piece it is, as Page Layout's pieces do.
|
|
484
|
+
*/
|
|
485
|
+
const panePiece = paneCopy
|
|
486
|
+
? paneCopyPiece(paneCopy, { x, y, width, height })
|
|
487
|
+
: undefined;
|
|
488
|
+
if (paneCopy && !panePiece)
|
|
489
|
+
return null;
|
|
490
|
+
const pieceOfPanes = panePiece && panePiece.count > 1 ? panePiece : undefined;
|
|
230
491
|
return (React.createElement(DraggableCore, { nodeRef: nodeRef, onStart: handleMoveStart, onDrag: handleMove, onStop: handleMoveEnd, cancel: ".react-resizable-handle, .rnc-draggable-ignore", scale: 1, disabled: !draggable },
|
|
231
|
-
React.createElement(Resizable, { width:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
492
|
+
React.createElement(Resizable, { width: drawn.width, height: drawn.height, onResizeStart: handleResizeStart, onResize: handleResize, onResizeStop: handleResizeEnd,
|
|
493
|
+
// In Page Layout view the ratio is held on the object's own size (`handleResize`).
|
|
494
|
+
lockAspectRatio: pageGaps ? false : lockAspectRatio || shiftLocksAspectRatio, resizeHandles: resizable ? resizeHandles : [] },
|
|
495
|
+
React.createElement("div", { className: cn(
|
|
496
|
+
// A cut object's frame spans the desk between its pieces: only the pieces and the
|
|
497
|
+
// handles take the pointer, so a press on the desk or a margin reaches the sheet.
|
|
498
|
+
drawn.pieces
|
|
499
|
+
? "text-rnc-foreground text-sm pointer-events-none [&_.react-resizable-handle]:pointer-events-auto border border-solid border-transparent flex select-none box-content absolute rnc-embed-component outline-none"
|
|
500
|
+
: "text-rnc-foreground text-sm pointer-events-auto border border-solid border-transparent flex select-none box-content absolute rnc-embed-component outline-none", isSelected ? "[&_.react-resizable-handle]:bg-[#1a73e8]" : undefined, isSelected ? "rnc-embed-active" : undefined), style: {
|
|
501
|
+
width: drawn.width,
|
|
502
|
+
height: drawn.height,
|
|
503
|
+
transform: `translate(${drawn.x}px, ${drawn.y}px)${unmirror ? " scaleX(-1)" : ""}`,
|
|
504
|
+
// A cut object's outline is drawn on its pieces, never across the desk between them.
|
|
505
|
+
borderColor: drawn.pieces ? "transparent" : borderColor,
|
|
237
506
|
zIndex: isSelected
|
|
238
507
|
? (zIndex ?? 0) + SELECTED_Z_INDEX_LIFT
|
|
239
508
|
: zIndex,
|
|
@@ -290,5 +559,44 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
290
559
|
}
|
|
291
560
|
e.preventDefault();
|
|
292
561
|
onRequestContextMenu(id, e.clientX, e.clientY, e.currentTarget);
|
|
293
|
-
} },
|
|
562
|
+
} },
|
|
563
|
+
drawn.pieces
|
|
564
|
+
? drawn.pieces.map((piece, index, pieces) => (React.createElement("div", {
|
|
565
|
+
// By index: a piece keeps its content mounted while the object is dragged.
|
|
566
|
+
key: index, "data-page-piece": "", className: "absolute overflow-hidden pointer-events-auto", style: {
|
|
567
|
+
left: piece.x,
|
|
568
|
+
top: piece.y,
|
|
569
|
+
width: piece.width,
|
|
570
|
+
height: piece.height,
|
|
571
|
+
} },
|
|
572
|
+
React.createElement("div", { className: "absolute flex", style: {
|
|
573
|
+
left: -piece.contentX,
|
|
574
|
+
top: -piece.contentY,
|
|
575
|
+
width: internalWidth,
|
|
576
|
+
height: internalHeight,
|
|
577
|
+
} }, children(internalWidth, internalHeight, {
|
|
578
|
+
index,
|
|
579
|
+
count: pieces.length,
|
|
580
|
+
})))))
|
|
581
|
+
: children(internalWidth, internalHeight, pieceOfPanes),
|
|
582
|
+
drawn.pieces && borderColor
|
|
583
|
+
? drawn.pieces.map((piece, index) => {
|
|
584
|
+
// The frame's 1px border sits outside its content box: each piece's share of it
|
|
585
|
+
// lies just outside the piece, on the object's own edges only.
|
|
586
|
+
const { top, bottom, left, right } = piece.edges;
|
|
587
|
+
return (React.createElement("div", { key: `outline-${index}`, "data-page-piece-outline": "", className: "absolute pointer-events-none", style: {
|
|
588
|
+
left: piece.x - (left ? 1 : 0),
|
|
589
|
+
top: piece.y - (top ? 1 : 0),
|
|
590
|
+
width: piece.width + (left ? 1 : 0) + (right ? 1 : 0),
|
|
591
|
+
height: piece.height + (top ? 1 : 0) + (bottom ? 1 : 0),
|
|
592
|
+
boxSizing: "border-box",
|
|
593
|
+
borderStyle: "solid",
|
|
594
|
+
borderColor,
|
|
595
|
+
borderTopWidth: top ? 1 : 0,
|
|
596
|
+
borderBottomWidth: bottom ? 1 : 0,
|
|
597
|
+
borderLeftWidth: left ? 1 : 0,
|
|
598
|
+
borderRightWidth: right ? 1 : 0,
|
|
599
|
+
} }));
|
|
600
|
+
})
|
|
601
|
+
: null))));
|
|
294
602
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Each mounted object's keyboard target (the frame `EmbedDraggable` focuses), by object id: what
|
|
3
|
+
* `CanvasGrid`'s `focus()` gives the keyboard to while an object is selected. One map per store.
|
|
4
|
+
*/
|
|
5
|
+
export declare const objectFocusTargetsAtom: import("jotai").Atom<Map<string | number, HTMLElement>>;
|
|
6
|
+
/**
|
|
7
|
+
* Each sheet's own keyboard target (its cell editor), keyed by the sheet's wrapper element
|
|
8
|
+
* (`.rnc-canvas-wrapper`); `CanvasGrid` registers it. One map per store.
|
|
9
|
+
*/
|
|
10
|
+
export declare const sheetFocusTargetsAtom: import("jotai").Atom<WeakMap<Element, () => HTMLElement | null | undefined>>;
|
|
11
|
+
type SheetFocusTargets = WeakMap<Element, () => HTMLElement | null | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Whether an object just selected without a click may take the keyboard from where it is now:
|
|
14
|
+
* from the page, the sheet's own target, or an ordinary control such as the menu item or button
|
|
15
|
+
* that ran the command. Never from a cell being edited, anything in a dialog, or an editable
|
|
16
|
+
* control anywhere, the sheet's own cell editor excepted.
|
|
17
|
+
*/
|
|
18
|
+
export declare const mayTakeFocus: (node: HTMLElement, editing: boolean, targets: SheetFocusTargets) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether focus that moved away right after the selection is taken back: only when it went to
|
|
21
|
+
* the page, to the sheet's own target, or to the control that ran the command (`origins`: what
|
|
22
|
+
* had focus when the object was selected, and a menu's trigger). Focus anywhere else, inside or
|
|
23
|
+
* outside the sheet, is the person's.
|
|
24
|
+
*/
|
|
25
|
+
export declare const mayReclaimFocus: (node: HTMLElement, editing: boolean, targets: SheetFocusTargets, origins: readonly Element[]) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The controls that ran the command selecting an object: what has focus now, and, when that is
|
|
28
|
+
* an item of an open menu or list, the control that opened it (`aria-controls` names the menu).
|
|
29
|
+
*/
|
|
30
|
+
export declare const commandOrigins: (node: HTMLElement) => Element[];
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=object-focus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-focus.d.ts","sourceRoot":"","sources":["../../../../components/embeds/object-focus.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,eAAO,MAAM,sBAAsB,yDAElC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,8CACC,WAAW,GAAG,IAAI,GAAG,SAAS,EAChE,CAAC;AAEF,KAAK,iBAAiB,GAAG,OAAO,CAC9B,OAAO,EACP,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CACrC,CAAC;AAoDF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,WAAW,EACjB,SAAS,OAAO,EAChB,SAAS,iBAAiB,KACzB,OASF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,WAAW,EACjB,SAAS,OAAO,EAChB,SAAS,iBAAiB,EAC1B,SAAS,SAAS,OAAO,EAAE,KAC1B,OAQF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,WAAW,KAAG,OAAO,EAsBzD,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { getOwnerDocument } from "@rowsncolumns/grid";
|
|
2
|
+
import { atom } from "jotai";
|
|
3
|
+
/**
|
|
4
|
+
* Each mounted object's keyboard target (the frame `EmbedDraggable` focuses), by object id: what
|
|
5
|
+
* `CanvasGrid`'s `focus()` gives the keyboard to while an object is selected. One map per store.
|
|
6
|
+
*/
|
|
7
|
+
export const objectFocusTargetsAtom = atom(() => new Map());
|
|
8
|
+
/**
|
|
9
|
+
* Each sheet's own keyboard target (its cell editor), keyed by the sheet's wrapper element
|
|
10
|
+
* (`.rnc-canvas-wrapper`); `CanvasGrid` registers it. One map per store.
|
|
11
|
+
*/
|
|
12
|
+
export const sheetFocusTargetsAtom = atom(() => new WeakMap());
|
|
13
|
+
const SHEET = ".rnc-canvas-wrapper";
|
|
14
|
+
const DIALOG = '[role="dialog"], [role="alertdialog"], [aria-modal="true"]';
|
|
15
|
+
/** Text inputs: an `input` of any type that takes typing. */
|
|
16
|
+
const TYPING_INPUT_TYPES = new Set([
|
|
17
|
+
"text",
|
|
18
|
+
"search",
|
|
19
|
+
"email",
|
|
20
|
+
"url",
|
|
21
|
+
"tel",
|
|
22
|
+
"password",
|
|
23
|
+
"number",
|
|
24
|
+
"date",
|
|
25
|
+
"datetime-local",
|
|
26
|
+
"month",
|
|
27
|
+
"time",
|
|
28
|
+
"week",
|
|
29
|
+
]);
|
|
30
|
+
const isEditable = (element) => element.isContentEditable ||
|
|
31
|
+
// `isContentEditable` is not implemented everywhere (jsdom); the attribute says the same.
|
|
32
|
+
!!element.closest('[contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]') ||
|
|
33
|
+
element.tagName === "TEXTAREA" ||
|
|
34
|
+
element.tagName === "SELECT" ||
|
|
35
|
+
(element.tagName === "INPUT" &&
|
|
36
|
+
TYPING_INPUT_TYPES.has(element.type || "text"));
|
|
37
|
+
/**
|
|
38
|
+
* The sheet's own keyboard target: the grid itself (its wrapper) or its cell editor. The cell
|
|
39
|
+
* editor counts only while no cell is being edited (the caller checks `editing` first).
|
|
40
|
+
*/
|
|
41
|
+
const isSheetFocusTarget = (node, element, targets) => {
|
|
42
|
+
const sheet = node.closest(SHEET);
|
|
43
|
+
if (!sheet)
|
|
44
|
+
return false;
|
|
45
|
+
if (element === sheet)
|
|
46
|
+
return true;
|
|
47
|
+
const sink = targets.get(sheet)?.();
|
|
48
|
+
return !!sink && (element === sink || sink.contains(element));
|
|
49
|
+
};
|
|
50
|
+
const activeElementOf = (node) => {
|
|
51
|
+
const ownerDocument = getOwnerDocument(node);
|
|
52
|
+
const active = (ownerDocument?.activeElement ?? null);
|
|
53
|
+
return { ownerDocument, active };
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Whether an object just selected without a click may take the keyboard from where it is now:
|
|
57
|
+
* from the page, the sheet's own target, or an ordinary control such as the menu item or button
|
|
58
|
+
* that ran the command. Never from a cell being edited, anything in a dialog, or an editable
|
|
59
|
+
* control anywhere, the sheet's own cell editor excepted.
|
|
60
|
+
*/
|
|
61
|
+
export const mayTakeFocus = (node, editing, targets) => {
|
|
62
|
+
if (editing)
|
|
63
|
+
return false;
|
|
64
|
+
const { ownerDocument, active } = activeElementOf(node);
|
|
65
|
+
if (!active || active === ownerDocument?.body || node.contains(active)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (isSheetFocusTarget(node, active, targets))
|
|
69
|
+
return true;
|
|
70
|
+
if (active.closest(DIALOG))
|
|
71
|
+
return false;
|
|
72
|
+
return !isEditable(active);
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Whether focus that moved away right after the selection is taken back: only when it went to
|
|
76
|
+
* the page, to the sheet's own target, or to the control that ran the command (`origins`: what
|
|
77
|
+
* had focus when the object was selected, and a menu's trigger). Focus anywhere else, inside or
|
|
78
|
+
* outside the sheet, is the person's.
|
|
79
|
+
*/
|
|
80
|
+
export const mayReclaimFocus = (node, editing, targets, origins) => {
|
|
81
|
+
if (editing)
|
|
82
|
+
return false;
|
|
83
|
+
const { ownerDocument, active } = activeElementOf(node);
|
|
84
|
+
if (!active || active === ownerDocument?.body)
|
|
85
|
+
return true;
|
|
86
|
+
if (node.contains(active))
|
|
87
|
+
return false;
|
|
88
|
+
if (active.closest(DIALOG))
|
|
89
|
+
return false;
|
|
90
|
+
if (isSheetFocusTarget(node, active, targets))
|
|
91
|
+
return true;
|
|
92
|
+
return origins.includes(active);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The controls that ran the command selecting an object: what has focus now, and, when that is
|
|
96
|
+
* an item of an open menu or list, the control that opened it (`aria-controls` names the menu).
|
|
97
|
+
*/
|
|
98
|
+
export const commandOrigins = (node) => {
|
|
99
|
+
const { ownerDocument, active } = activeElementOf(node);
|
|
100
|
+
// An editable control is never a command's control: focus coming back to a field the person
|
|
101
|
+
// types in (a chat box refocusing itself) stays theirs.
|
|
102
|
+
if (!active ||
|
|
103
|
+
active === ownerDocument?.body ||
|
|
104
|
+
node.contains(active) ||
|
|
105
|
+
isEditable(active)) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const origins = [active];
|
|
109
|
+
const popup = active.closest('[role="menu"], [role="listbox"]');
|
|
110
|
+
if (popup?.id && ownerDocument) {
|
|
111
|
+
for (const element of Array.from(ownerDocument.querySelectorAll("[aria-controls]"))) {
|
|
112
|
+
if (element.getAttribute("aria-controls") === popup.id) {
|
|
113
|
+
origins.push(element);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return origins;
|
|
118
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel's Page Layout view draws the sheet as pages of paper with a gap (margins and desk) between
|
|
3
|
+
* them. A chart, picture, shape or slicer keeps its size in sheet pixels, so one that crosses a
|
|
4
|
+
* page boundary is drawn clipped per page: the part on the next page continues past the gap.
|
|
5
|
+
*
|
|
6
|
+
* These helpers map one axis between the grid's coordinates (which include the gaps) and gap-free
|
|
7
|
+
* sheet coordinates (the object's own), and cut an object's extent into its per-page pieces.
|
|
8
|
+
*/
|
|
9
|
+
/** A page boundary on one axis: where the page's first row (column) starts, after its gap. */
|
|
10
|
+
export type PageGapBoundary = {
|
|
11
|
+
/** Grid coordinate of the page's first row (column), after the gap. */
|
|
12
|
+
start: number;
|
|
13
|
+
/** Size of the gap just before it, in grid pixels. */
|
|
14
|
+
gap: number;
|
|
15
|
+
};
|
|
16
|
+
/** One axis of the Page Layout gaps, boundaries in ascending order. */
|
|
17
|
+
export type PageGapAxis = readonly PageGapBoundary[];
|
|
18
|
+
/** Both axes; `undefined` outside Page Layout view. */
|
|
19
|
+
export type PageGaps = {
|
|
20
|
+
x: PageGapAxis;
|
|
21
|
+
y: PageGapAxis;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Where Page Layout view's pages start, as row and column indexes with the gap before each (grid
|
|
25
|
+
* pixels): resolved into grid coordinates (`resolvePageGaps`) when the grid can measure them.
|
|
26
|
+
*/
|
|
27
|
+
export type PageGapIndexes = {
|
|
28
|
+
columns: readonly {
|
|
29
|
+
index: number;
|
|
30
|
+
gap: number;
|
|
31
|
+
}[];
|
|
32
|
+
rows: readonly {
|
|
33
|
+
index: number;
|
|
34
|
+
gap: number;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
/** The page boundaries in grid coordinates, read off the grid's cell offsets. */
|
|
38
|
+
export declare const resolvePageGaps: (indexes: PageGapIndexes, getCellOffsetFromCoords: ((cell: {
|
|
39
|
+
rowIndex: number;
|
|
40
|
+
columnIndex: number;
|
|
41
|
+
}) => {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
} | undefined | null) | undefined) => PageGaps | undefined;
|
|
45
|
+
/** A grid coordinate in gap-free sheet pixels; a point inside a gap maps to the page it opens. */
|
|
46
|
+
export declare const toGapFree: (axis: PageGapAxis, at: number) => number;
|
|
47
|
+
/** A gap-free sheet coordinate in grid pixels; a page's first pixel lies after its gap. */
|
|
48
|
+
export declare const toScreen: (axis: PageGapAxis, at: number) => number;
|
|
49
|
+
/** One page's piece of an object's extent along an axis. */
|
|
50
|
+
export type PagePiece = {
|
|
51
|
+
/** Where the piece is drawn, from the start of the whole drawn extent (grid pixels). */
|
|
52
|
+
offset: number;
|
|
53
|
+
length: number;
|
|
54
|
+
/** Where the piece starts within the object itself (gap-free pixels). */
|
|
55
|
+
content: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Cuts an object starting at grid coordinate `start` and `length` gap-free pixels long into its
|
|
59
|
+
* per-page pieces. `extent` is the length drawn from the first piece's start to the last piece's
|
|
60
|
+
* end, gaps included; with no boundary inside the object it is one piece of `length`.
|
|
61
|
+
*/
|
|
62
|
+
export declare const splitAcrossPages: (axis: PageGapAxis, start: number, length: number) => {
|
|
63
|
+
start: number;
|
|
64
|
+
extent: number;
|
|
65
|
+
pieces: PagePiece[];
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=page-gaps.d.ts.map
|