@rowsncolumns/spreadsheet 10.10.5 → 10.13.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 +10 -0
- package/dist/cjs/api/split-pane.d.ts.map +1 -1
- package/dist/cjs/api/split-pane.js +29 -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 +327 -115
- package/dist/cjs/components/canvas-grid/typings.d.ts +33 -1
- 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 +323 -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/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 +4767 -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 +7 -1
- package/dist/cjs/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/cjs/hooks/use-embeds-charts.js +74 -14
- package/dist/cjs/hooks/use-grid-children.d.ts +8 -2
- package/dist/cjs/hooks/use-grid-children.d.ts.map +1 -1
- package/dist/cjs/hooks/use-grid-children.js +71 -4
- 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/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 +58 -0
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/api/split-pane.d.ts +10 -0
- package/dist/esm/api/split-pane.d.ts.map +1 -1
- package/dist/esm/api/split-pane.js +25 -0
- 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 +248 -52
- package/dist/esm/components/canvas-grid/typings.d.ts +33 -1
- 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 +314 -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/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 +4764 -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 +7 -1
- package/dist/esm/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/esm/hooks/use-embeds-charts.js +72 -14
- package/dist/esm/hooks/use-grid-children.d.ts +8 -2
- package/dist/esm/hooks/use-grid-children.d.ts.map +1 -1
- package/dist/esm/hooks/use-grid-children.js +71 -4
- 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/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 +58 -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,15 @@
|
|
|
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, 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 { resolvePageGaps, splitAcrossPages, toGapFree, toScreen, } from "./page-gaps";
|
|
11
|
+
/** The smallest width and height a resize leaves: react-resizable's default `minConstraints`. */
|
|
12
|
+
const MIN_OBJECT_SIZE = 20;
|
|
7
13
|
/** Lifts the selected object over every unselected one (ranks count from 1 per object). */
|
|
8
14
|
const SELECTED_Z_INDEX_LIFT = 100_000;
|
|
9
15
|
const ARROW_KEY_DELTAS = {
|
|
@@ -34,7 +40,7 @@ const resizeHandles = [
|
|
|
34
40
|
"nw",
|
|
35
41
|
"sw",
|
|
36
42
|
];
|
|
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, }) => {
|
|
43
|
+
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
44
|
// Right-to-left sheet: the object sits at its mirrored anchor; flip its box
|
|
39
45
|
// back so a chart or picture is not drawn mirrored. Its geometry stays in
|
|
40
46
|
// sheet (logical) pixels, so a pointer or arrow-key movement to the
|
|
@@ -42,6 +48,9 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
42
48
|
const unmirror = useIsInRtlMirrorLayer();
|
|
43
49
|
const physicalToLogicalX = unmirror ? -1 : 1;
|
|
44
50
|
const { getCellOffsetFromCoords } = useGridContext();
|
|
51
|
+
const pageGaps = pageGapIndexes
|
|
52
|
+
? resolvePageGaps(pageGapIndexes, getCellOffsetFromCoords)
|
|
53
|
+
: undefined;
|
|
45
54
|
const position = getCellOffsetFromCoords?.(anchorCell);
|
|
46
55
|
const x = (position?.x ?? 0) + offsetXPixels;
|
|
47
56
|
const y = (position?.y ?? 0) + offsetYPixels;
|
|
@@ -49,8 +58,16 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
49
58
|
// after a delete draws nothing rather than a negative box)
|
|
50
59
|
const toPosition = toCell ? getCellOffsetFromCoords?.(toCell) : undefined;
|
|
51
60
|
if (toPosition) {
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
// Across Page Layout's gaps the frame is what lies between the anchors on the sheet itself,
|
|
62
|
+
// not the gaps between them.
|
|
63
|
+
width = Math.max(0, pageGaps
|
|
64
|
+
? toGapFree(pageGaps.x, toPosition.x + toOffsetXPixels) -
|
|
65
|
+
toGapFree(pageGaps.x, x)
|
|
66
|
+
: toPosition.x + toOffsetXPixels - x);
|
|
67
|
+
height = Math.max(0, pageGaps
|
|
68
|
+
? toGapFree(pageGaps.y, toPosition.y + toOffsetYPixels) -
|
|
69
|
+
toGapFree(pageGaps.y, y)
|
|
70
|
+
: toPosition.y + toOffsetYPixels - y);
|
|
54
71
|
}
|
|
55
72
|
const [dimensions, setDimensions] = useState(() => ({
|
|
56
73
|
internalWidth: width,
|
|
@@ -69,16 +86,97 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
69
86
|
const gestureRef = useRef(dimensions);
|
|
70
87
|
// Shift on a corner handle keeps the aspect ratio for the rest of the gesture
|
|
71
88
|
const [shiftLocksAspectRatio, setShiftLocksAspectRatio] = useState(false);
|
|
89
|
+
/** In Page Layout view: the object's edges in grid pixels, where the pointer put them. */
|
|
90
|
+
const pageGestureRef = useRef(null);
|
|
91
|
+
/**
|
|
92
|
+
* The object as drawn: one box, or in Page Layout view its pieces per page and the extent they
|
|
93
|
+
* span with the gaps between them.
|
|
94
|
+
*/
|
|
95
|
+
const pagesOf = useCallback((box) => pageGaps
|
|
96
|
+
? {
|
|
97
|
+
x: splitAcrossPages(pageGaps.x, box.internalX, box.internalWidth),
|
|
98
|
+
y: splitAcrossPages(pageGaps.y, box.internalY, box.internalHeight),
|
|
99
|
+
}
|
|
100
|
+
: undefined, [pageGaps]);
|
|
72
101
|
const commit = useCallback((next) => {
|
|
73
102
|
appliedRef.current = next;
|
|
74
103
|
setDimensions(next);
|
|
75
104
|
}, []);
|
|
76
|
-
//
|
|
105
|
+
// The keyboard follows the selection, however the object was selected: a click, an insert,
|
|
106
|
+
// a paste, the Selection Pane (`mayTakeFocus`: never from a cell being edited, a dialog or an
|
|
107
|
+
// editable control other than the sheet's own cell editor).
|
|
108
|
+
const editingCell = useAtomValue(editingCellAtom);
|
|
109
|
+
const editingRef = useRef(false);
|
|
110
|
+
editingRef.current = editingCell !== undefined;
|
|
111
|
+
const focusTargets = useAtomValue(objectFocusTargetsAtom);
|
|
112
|
+
const sheetFocusTargets = useAtomValue(sheetFocusTargetsAtom);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
const node = nodeRef.current;
|
|
115
|
+
if (!node)
|
|
116
|
+
return;
|
|
117
|
+
focusTargets.set(id, node);
|
|
118
|
+
return () => {
|
|
119
|
+
if (focusTargets.get(id) === node)
|
|
120
|
+
focusTargets.delete(id);
|
|
121
|
+
};
|
|
122
|
+
}, [focusTargets, id]);
|
|
77
123
|
useIsomorphicLayoutEffect(() => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
124
|
+
const node = nodeRef.current;
|
|
125
|
+
if (!isSelected || !node)
|
|
126
|
+
return;
|
|
127
|
+
const ownerDocument = getOwnerDocument(node);
|
|
128
|
+
if (!ownerDocument)
|
|
129
|
+
return;
|
|
130
|
+
const origins = commandOrigins(node);
|
|
131
|
+
if (ownerDocument.activeElement !== node) {
|
|
132
|
+
if (!mayTakeFocus(node, editingRef.current, sheetFocusTargets)) {
|
|
133
|
+
// Focus stayed where the person is (an editor, a dialog, a field): nothing to take back.
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
node.focus({ preventScroll: true });
|
|
81
137
|
}
|
|
138
|
+
// What closes the command that selected it often moves focus right after (a menu hands it
|
|
139
|
+
// back to its trigger, a host returns it to the sheet): until the person next presses a key
|
|
140
|
+
// or the pointer, or a second has passed, the object takes it back from the page, the
|
|
141
|
+
// sheet's own target or the command's control (`mayReclaimFocus`), and from nowhere else.
|
|
142
|
+
let timer;
|
|
143
|
+
const schedule = () => {
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
timer = setTimeout(() => {
|
|
146
|
+
if (node.isConnected &&
|
|
147
|
+
ownerDocument.activeElement !== node &&
|
|
148
|
+
mayReclaimFocus(node, editingRef.current, sheetFocusTargets, origins)) {
|
|
149
|
+
node.focus({ preventScroll: true });
|
|
150
|
+
}
|
|
151
|
+
}, 0);
|
|
152
|
+
};
|
|
153
|
+
const onFocusIn = (event) => {
|
|
154
|
+
const target = event.target;
|
|
155
|
+
if (target && node.contains(target))
|
|
156
|
+
return;
|
|
157
|
+
schedule();
|
|
158
|
+
};
|
|
159
|
+
// Focus dropped to the page fires no `focusin`.
|
|
160
|
+
const onFocusOut = (event) => {
|
|
161
|
+
if (event.relatedTarget === null)
|
|
162
|
+
schedule();
|
|
163
|
+
};
|
|
164
|
+
const stop = () => {
|
|
165
|
+
ownerDocument.removeEventListener("focusin", onFocusIn, true);
|
|
166
|
+
node.removeEventListener("focusout", onFocusOut);
|
|
167
|
+
ownerDocument.removeEventListener("pointerdown", stop, true);
|
|
168
|
+
ownerDocument.removeEventListener("keydown", stop, true);
|
|
169
|
+
clearTimeout(expiry);
|
|
170
|
+
};
|
|
171
|
+
ownerDocument.addEventListener("focusin", onFocusIn, true);
|
|
172
|
+
node.addEventListener("focusout", onFocusOut);
|
|
173
|
+
ownerDocument.addEventListener("pointerdown", stop, true);
|
|
174
|
+
ownerDocument.addEventListener("keydown", stop, true);
|
|
175
|
+
const expiry = setTimeout(stop, 1000);
|
|
176
|
+
return () => {
|
|
177
|
+
stop();
|
|
178
|
+
clearTimeout(timer);
|
|
179
|
+
};
|
|
82
180
|
}, [isSelected]);
|
|
83
181
|
// Starts moving
|
|
84
182
|
const handleMoveStart = useCallback((e) => {
|
|
@@ -105,16 +203,30 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
105
203
|
}, [bounds, snapToGrid, commit, physicalToLogicalX]);
|
|
106
204
|
// Ends moving
|
|
107
205
|
const handleMoveEnd = useCallback(() => {
|
|
206
|
+
if (pageGaps) {
|
|
207
|
+
// A corner dropped in the gap between pages lands at the start of the page after it.
|
|
208
|
+
const applied = appliedRef.current;
|
|
209
|
+
const snappedX = toScreen(pageGaps.x, toGapFree(pageGaps.x, applied.internalX));
|
|
210
|
+
const snappedY = toScreen(pageGaps.y, toGapFree(pageGaps.y, applied.internalY));
|
|
211
|
+
if (snappedX !== applied.internalX || snappedY !== applied.internalY) {
|
|
212
|
+
commit({ ...applied, internalX: snappedX, internalY: snappedY });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
108
215
|
const { internalX, internalY, internalWidth, internalHeight } = appliedRef.current;
|
|
109
216
|
if (incomingDimensionRef.current?.x === internalX &&
|
|
110
217
|
incomingDimensionRef.current?.y === internalY) {
|
|
111
218
|
return;
|
|
112
219
|
}
|
|
113
220
|
onMove?.(id, internalX, internalY, internalWidth, internalHeight);
|
|
114
|
-
}, [onMove, id]);
|
|
221
|
+
}, [onMove, id, pageGaps, commit]);
|
|
115
222
|
// Arrow keys nudge the object by whole pixels, clamped like a drag is
|
|
116
223
|
const handleNudge = useCallback((dx, dy) => {
|
|
117
|
-
|
|
224
|
+
// In Page Layout view a nudge steps over the gap between pages, as the sheet runs on.
|
|
225
|
+
const { x: nextX, y: nextY } = clampToBounds(pageGaps
|
|
226
|
+
? toScreen(pageGaps.x, toGapFree(pageGaps.x, internalX) + dx)
|
|
227
|
+
: internalX + dx, pageGaps
|
|
228
|
+
? toScreen(pageGaps.y, toGapFree(pageGaps.y, internalY) + dy)
|
|
229
|
+
: internalY + dy, internalWidth, internalHeight, bounds);
|
|
118
230
|
if (nextX === internalX && nextY === internalY) {
|
|
119
231
|
return;
|
|
120
232
|
}
|
|
@@ -129,16 +241,110 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
129
241
|
onMove,
|
|
130
242
|
id,
|
|
131
243
|
commit,
|
|
244
|
+
pageGaps,
|
|
132
245
|
]);
|
|
133
246
|
// Starts resizing
|
|
134
247
|
const handleResizeStart = useCallback((e, { handle }) => {
|
|
135
248
|
gestureRef.current = { ...appliedRef.current };
|
|
249
|
+
const pages = pagesOf(appliedRef.current);
|
|
250
|
+
pageGestureRef.current = pages
|
|
251
|
+
? {
|
|
252
|
+
left: pages.x.start,
|
|
253
|
+
top: pages.y.start,
|
|
254
|
+
right: pages.x.start + pages.x.extent,
|
|
255
|
+
bottom: pages.y.start + pages.y.extent,
|
|
256
|
+
}
|
|
257
|
+
: null;
|
|
136
258
|
setShiftLocksAspectRatio(isCornerHandle(handle) && Boolean(e.shiftKey));
|
|
137
|
-
}, []);
|
|
259
|
+
}, [pagesOf]);
|
|
138
260
|
// Resizing: Update internal state; Alt snaps the dragged edges to the cell grid
|
|
139
261
|
const handleResize = useCallback((e, { size, handle }) => {
|
|
140
262
|
const { altKey, shiftKey } = e;
|
|
141
263
|
setShiftLocksAspectRatio(isCornerHandle(handle) && Boolean(shiftKey));
|
|
264
|
+
const pageRaw = pageGestureRef.current;
|
|
265
|
+
// What react-resizable measured this event against: the frame as rendered.
|
|
266
|
+
const rendered = pagesOf(dimensions);
|
|
267
|
+
if (pageGaps && pageRaw && rendered) {
|
|
268
|
+
// Page Layout view: the pointer moves the dragged edges over the pages as drawn, gaps
|
|
269
|
+
// included; the object's own size is what lies between its edges on the sheet.
|
|
270
|
+
const deltaWidth = size.width - rendered.x.extent;
|
|
271
|
+
const deltaHeight = size.height - rendered.y.extent;
|
|
272
|
+
const side = handle[handle.length - 1];
|
|
273
|
+
const logicalSide = unmirror && side === "e" ? "w" : unmirror && side === "w" ? "e" : side;
|
|
274
|
+
const movesLeft = logicalSide === "w";
|
|
275
|
+
const movesTop = handle[0] === "n";
|
|
276
|
+
if (movesLeft)
|
|
277
|
+
pageRaw.left -= deltaWidth;
|
|
278
|
+
if (logicalSide === "e")
|
|
279
|
+
pageRaw.right += deltaWidth;
|
|
280
|
+
if (movesTop)
|
|
281
|
+
pageRaw.top -= deltaHeight;
|
|
282
|
+
if (handle[0] === "s")
|
|
283
|
+
pageRaw.bottom += deltaHeight;
|
|
284
|
+
let left = clampEdge(pageRaw.left, bounds?.left, undefined);
|
|
285
|
+
let top = clampEdge(pageRaw.top, bounds?.top, undefined);
|
|
286
|
+
let right = clampEdge(pageRaw.right, undefined, bounds?.right);
|
|
287
|
+
let bottom = clampEdge(pageRaw.bottom, undefined, bounds?.bottom);
|
|
288
|
+
if (altKey && snapToGrid) {
|
|
289
|
+
left = logicalSide === "w" ? snapToGrid(left, top)?.x ?? left : left;
|
|
290
|
+
right = logicalSide === "e" ? snapToGrid(right, top)?.x ?? right : right;
|
|
291
|
+
top = handle[0] === "n" ? snapToGrid(left, top)?.y ?? top : top;
|
|
292
|
+
bottom = handle[0] === "s" ? snapToGrid(left, bottom)?.y ?? bottom : bottom;
|
|
293
|
+
}
|
|
294
|
+
let gapFreeLeft = toGapFree(pageGaps.x, left);
|
|
295
|
+
let gapFreeTop = toGapFree(pageGaps.y, top);
|
|
296
|
+
let gapFreeRight = toGapFree(pageGaps.x, right);
|
|
297
|
+
let gapFreeBottom = toGapFree(pageGaps.y, bottom);
|
|
298
|
+
// A locked ratio holds for the object's own size, not the frame as drawn (which spans the
|
|
299
|
+
// gaps): the rule react-resizable applies in Normal view, on the gap-free size.
|
|
300
|
+
const locked = lockAspectRatio || (isCornerHandle(handle) && Boolean(shiftKey));
|
|
301
|
+
if (locked && dimensions.internalHeight > 0) {
|
|
302
|
+
const ratio = dimensions.internalWidth / dimensions.internalHeight;
|
|
303
|
+
let width = gapFreeRight - gapFreeLeft;
|
|
304
|
+
let height = gapFreeBottom - gapFreeTop;
|
|
305
|
+
const deltaW = width - dimensions.internalWidth;
|
|
306
|
+
const deltaH = height - dimensions.internalHeight;
|
|
307
|
+
if (Math.abs(deltaW) > Math.abs(deltaH * ratio)) {
|
|
308
|
+
height = width / ratio;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
width = height * ratio;
|
|
312
|
+
}
|
|
313
|
+
if (movesTop)
|
|
314
|
+
gapFreeTop = gapFreeBottom - height;
|
|
315
|
+
else
|
|
316
|
+
gapFreeBottom = gapFreeTop + height;
|
|
317
|
+
if (movesLeft)
|
|
318
|
+
gapFreeLeft = gapFreeRight - width;
|
|
319
|
+
else
|
|
320
|
+
gapFreeRight = gapFreeLeft + width;
|
|
321
|
+
pageRaw.left = toScreen(pageGaps.x, gapFreeLeft);
|
|
322
|
+
pageRaw.top = toScreen(pageGaps.y, gapFreeTop);
|
|
323
|
+
pageRaw.right = toScreen(pageGaps.x, gapFreeRight);
|
|
324
|
+
pageRaw.bottom = toScreen(pageGaps.y, gapFreeBottom);
|
|
325
|
+
}
|
|
326
|
+
// Normal view's smallest object: react-resizable's `minConstraints`, applied after the
|
|
327
|
+
// ratio as it applies them, moving the dragged edge.
|
|
328
|
+
if (gapFreeRight - gapFreeLeft < MIN_OBJECT_SIZE) {
|
|
329
|
+
if (movesLeft)
|
|
330
|
+
gapFreeLeft = gapFreeRight - MIN_OBJECT_SIZE;
|
|
331
|
+
else
|
|
332
|
+
gapFreeRight = gapFreeLeft + MIN_OBJECT_SIZE;
|
|
333
|
+
}
|
|
334
|
+
if (gapFreeBottom - gapFreeTop < MIN_OBJECT_SIZE) {
|
|
335
|
+
if (movesTop)
|
|
336
|
+
gapFreeTop = gapFreeBottom - MIN_OBJECT_SIZE;
|
|
337
|
+
else
|
|
338
|
+
gapFreeBottom = gapFreeTop + MIN_OBJECT_SIZE;
|
|
339
|
+
}
|
|
340
|
+
commit({
|
|
341
|
+
internalX: toScreen(pageGaps.x, gapFreeLeft),
|
|
342
|
+
internalY: toScreen(pageGaps.y, gapFreeTop),
|
|
343
|
+
internalWidth: gapFreeRight - gapFreeLeft,
|
|
344
|
+
internalHeight: gapFreeBottom - gapFreeTop,
|
|
345
|
+
});
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
142
348
|
// `size` is the rendered size (`dimensions`) plus this event's pointer delta
|
|
143
349
|
const deltaHeight = size.height - dimensions.internalHeight;
|
|
144
350
|
const deltaWidth = size.width - dimensions.internalWidth;
|
|
@@ -201,7 +407,16 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
201
407
|
internalWidth: right - left,
|
|
202
408
|
internalHeight: bottom - top,
|
|
203
409
|
});
|
|
204
|
-
}, [
|
|
410
|
+
}, [
|
|
411
|
+
dimensions,
|
|
412
|
+
snapToGrid,
|
|
413
|
+
commit,
|
|
414
|
+
unmirror,
|
|
415
|
+
pageGaps,
|
|
416
|
+
pagesOf,
|
|
417
|
+
bounds,
|
|
418
|
+
lockAspectRatio,
|
|
419
|
+
]);
|
|
205
420
|
// Resize ends
|
|
206
421
|
const handleResizeEnd = useCallback(() => {
|
|
207
422
|
setShiftLocksAspectRatio(false);
|
|
@@ -227,13 +442,54 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
227
442
|
internalWidth: width,
|
|
228
443
|
});
|
|
229
444
|
}, [width, height, x, y, commit]);
|
|
445
|
+
const pages = pagesOf(dimensions);
|
|
446
|
+
const isCut = pages !== undefined &&
|
|
447
|
+
(pages.x.pieces.length > 1 || pages.y.pieces.length > 1);
|
|
448
|
+
/** What is drawn: one box as before, or the pieces of an object a page boundary cuts. */
|
|
449
|
+
const drawn = pages && isCut
|
|
450
|
+
? {
|
|
451
|
+
x: pages.x.start,
|
|
452
|
+
y: pages.y.start,
|
|
453
|
+
width: pages.x.extent,
|
|
454
|
+
height: pages.y.extent,
|
|
455
|
+
pieces: pages.y.pieces.flatMap((row, rowIndex) => pages.x.pieces.map((column, columnIndex) => ({
|
|
456
|
+
x: column.offset,
|
|
457
|
+
y: row.offset,
|
|
458
|
+
width: column.length,
|
|
459
|
+
height: row.length,
|
|
460
|
+
contentX: column.content,
|
|
461
|
+
contentY: row.content,
|
|
462
|
+
// Which of the object's own edges this piece carries (the others are cut edges).
|
|
463
|
+
edges: {
|
|
464
|
+
top: rowIndex === 0,
|
|
465
|
+
bottom: rowIndex === pages.y.pieces.length - 1,
|
|
466
|
+
left: columnIndex === 0,
|
|
467
|
+
right: columnIndex === pages.x.pieces.length - 1,
|
|
468
|
+
},
|
|
469
|
+
}))),
|
|
470
|
+
}
|
|
471
|
+
: {
|
|
472
|
+
x: internalX,
|
|
473
|
+
y: internalY,
|
|
474
|
+
width: internalWidth,
|
|
475
|
+
height: internalHeight,
|
|
476
|
+
pieces: undefined,
|
|
477
|
+
};
|
|
230
478
|
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
|
-
|
|
479
|
+
React.createElement(Resizable, { width: drawn.width, height: drawn.height, onResizeStart: handleResizeStart, onResize: handleResize, onResizeStop: handleResizeEnd,
|
|
480
|
+
// In Page Layout view the ratio is held on the object's own size (`handleResize`).
|
|
481
|
+
lockAspectRatio: pageGaps ? false : lockAspectRatio || shiftLocksAspectRatio, resizeHandles: resizable ? resizeHandles : [] },
|
|
482
|
+
React.createElement("div", { className: cn(
|
|
483
|
+
// A cut object's frame spans the desk between its pieces: only the pieces and the
|
|
484
|
+
// handles take the pointer, so a press on the desk or a margin reaches the sheet.
|
|
485
|
+
drawn.pieces
|
|
486
|
+
? "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"
|
|
487
|
+
: "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: {
|
|
488
|
+
width: drawn.width,
|
|
489
|
+
height: drawn.height,
|
|
490
|
+
transform: `translate(${drawn.x}px, ${drawn.y}px)${unmirror ? " scaleX(-1)" : ""}`,
|
|
491
|
+
// A cut object's outline is drawn on its pieces, never across the desk between them.
|
|
492
|
+
borderColor: drawn.pieces ? "transparent" : borderColor,
|
|
237
493
|
zIndex: isSelected
|
|
238
494
|
? (zIndex ?? 0) + SELECTED_Z_INDEX_LIFT
|
|
239
495
|
: zIndex,
|
|
@@ -290,5 +546,44 @@ export const EmbedDraggable = ({ id, scale = 1, height, width, offsetXPixels, of
|
|
|
290
546
|
}
|
|
291
547
|
e.preventDefault();
|
|
292
548
|
onRequestContextMenu(id, e.clientX, e.clientY, e.currentTarget);
|
|
293
|
-
} },
|
|
549
|
+
} },
|
|
550
|
+
drawn.pieces
|
|
551
|
+
? drawn.pieces.map((piece, index, pieces) => (React.createElement("div", {
|
|
552
|
+
// By index: a piece keeps its content mounted while the object is dragged.
|
|
553
|
+
key: index, "data-page-piece": "", className: "absolute overflow-hidden pointer-events-auto", style: {
|
|
554
|
+
left: piece.x,
|
|
555
|
+
top: piece.y,
|
|
556
|
+
width: piece.width,
|
|
557
|
+
height: piece.height,
|
|
558
|
+
} },
|
|
559
|
+
React.createElement("div", { className: "absolute flex", style: {
|
|
560
|
+
left: -piece.contentX,
|
|
561
|
+
top: -piece.contentY,
|
|
562
|
+
width: internalWidth,
|
|
563
|
+
height: internalHeight,
|
|
564
|
+
} }, children(internalWidth, internalHeight, {
|
|
565
|
+
index,
|
|
566
|
+
count: pieces.length,
|
|
567
|
+
})))))
|
|
568
|
+
: children(internalWidth, internalHeight),
|
|
569
|
+
drawn.pieces && borderColor
|
|
570
|
+
? drawn.pieces.map((piece, index) => {
|
|
571
|
+
// The frame's 1px border sits outside its content box: each piece's share of it
|
|
572
|
+
// lies just outside the piece, on the object's own edges only.
|
|
573
|
+
const { top, bottom, left, right } = piece.edges;
|
|
574
|
+
return (React.createElement("div", { key: `outline-${index}`, "data-page-piece-outline": "", className: "absolute pointer-events-none", style: {
|
|
575
|
+
left: piece.x - (left ? 1 : 0),
|
|
576
|
+
top: piece.y - (top ? 1 : 0),
|
|
577
|
+
width: piece.width + (left ? 1 : 0) + (right ? 1 : 0),
|
|
578
|
+
height: piece.height + (top ? 1 : 0) + (bottom ? 1 : 0),
|
|
579
|
+
boxSizing: "border-box",
|
|
580
|
+
borderStyle: "solid",
|
|
581
|
+
borderColor,
|
|
582
|
+
borderTopWidth: top ? 1 : 0,
|
|
583
|
+
borderBottomWidth: bottom ? 1 : 0,
|
|
584
|
+
borderLeftWidth: left ? 1 : 0,
|
|
585
|
+
borderRightWidth: right ? 1 : 0,
|
|
586
|
+
} }));
|
|
587
|
+
})
|
|
588
|
+
: null))));
|
|
294
589
|
};
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-gaps.d.ts","sourceRoot":"","sources":["../../../../components/embeds/page-gaps.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,8FAA8F;AAC9F,MAAM,MAAM,eAAe,GAAG;IAC5B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,WAAW,GAAG,SAAS,eAAe,EAAE,CAAC;AAErD,uDAAuD;AACvD,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,EAAE,WAAW,CAAC;IAAC,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnD,IAAI,EAAE,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACjD,CAAC;AAEF,iFAAiF;AACjF,eAAO,MAAM,eAAe,GAC1B,SAAS,cAAc,EACvB,yBACI,CAAC,CAAC,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,KAC7C;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GACxB,SAAS,GACT,IAAI,CAAC,GACT,SAAS,KACZ,QAAQ,GAAG,SAeb,CAAC;AAEF,kGAAkG;AAClG,eAAO,MAAM,SAAS,GAAI,MAAM,WAAW,EAAE,IAAI,MAAM,KAAG,MAWzD,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,QAAQ,GAAI,MAAM,WAAW,EAAE,IAAI,MAAM,KAAG,MAUxD,CAAC;AAEF,4DAA4D;AAC5D,MAAM,MAAM,SAAS,GAAG;IACtB,wFAAwF;IACxF,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,WAAW,EACjB,OAAO,MAAM,EACb,QAAQ,MAAM,KACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,EAAE,CAAA;CAuBtD,CAAC"}
|