@rowsncolumns/spreadsheet 10.11.0 → 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/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 +265 -115
- package/dist/cjs/components/canvas-grid/typings.d.ts +25 -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 +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-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/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 +186 -51
- package/dist/esm/components/canvas-grid/typings.d.ts +25 -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 +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-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,12 +1,15 @@
|
|
|
1
1
|
import type { CellInterface } from "@rowsncolumns/grid";
|
|
2
2
|
import type { CanvasGridProps } from "../components/canvas-grid/typings";
|
|
3
|
-
import type { EmbeddedChart } from "../types";
|
|
3
|
+
import type { EmbeddedChart, EmbeddedObject } from "../types";
|
|
4
|
+
import { type ObjectClipboardPolicy } from "./object-clipboard-payload";
|
|
4
5
|
/**
|
|
5
6
|
* Clipboard type the copied chart rides on, so a paste in another tab of the
|
|
6
7
|
* same browser rebuilds it. Browsers keep custom types only for their own
|
|
7
8
|
* paste events, hence the in-memory entry below is the primary source.
|
|
8
9
|
*/
|
|
9
10
|
export declare const CHART_CLIPBOARD_MIME = "application/x-rowsncolumns-chart";
|
|
11
|
+
/** Clipboard type a copied picture, shape or text box rides on (as `CHART_CLIPBOARD_MIME`). */
|
|
12
|
+
export declare const EMBED_CLIPBOARD_MIME = "application/x-rowsncolumns-embed";
|
|
10
13
|
/**
|
|
11
14
|
* Excel nudges a pasted or duplicated object this far down-right of the
|
|
12
15
|
* original when the destination is the object's own spot.
|
|
@@ -21,35 +24,78 @@ export type UseChartClipboardProps = {
|
|
|
21
24
|
readonly?: boolean;
|
|
22
25
|
onCreateChart: CanvasGridProps["onCreateChart"];
|
|
23
26
|
onDeleteChart: CanvasGridProps["onDeleteChart"];
|
|
27
|
+
/** Pictures, shapes and text boxes: copied, cut, pasted and duplicated the way charts are. */
|
|
28
|
+
embeds?: CanvasGridProps["embeds"];
|
|
29
|
+
onCreateEmbed?: CanvasGridProps["onCreateEmbed"];
|
|
30
|
+
onDeleteEmbed?: CanvasGridProps["onDeleteEmbed"];
|
|
24
31
|
/** Host hooks notified after the grid's clipboard copied / cut a chart. */
|
|
25
32
|
onCopyChart?: CanvasGridProps["onCopyChart"];
|
|
26
33
|
onCutChart?: CanvasGridProps["onCutChart"];
|
|
27
34
|
/** Return keyboard focus to the grid once a cut removed the focused chart. */
|
|
28
35
|
focusSheet(): void;
|
|
36
|
+
/**
|
|
37
|
+
* The destination sheet's size and its column widths / row heights: a pasted object is kept on
|
|
38
|
+
* the sheet (shifted back from its far edge) and its far anchor stored on a cell that exists,
|
|
39
|
+
* never with a negative offset.
|
|
40
|
+
*/
|
|
41
|
+
rowCount?: number;
|
|
42
|
+
columnCount?: number;
|
|
43
|
+
getColumnWidth?: (columnIndex: number) => number;
|
|
44
|
+
getRowHeight?: (rowIndex: number) => number;
|
|
45
|
+
/**
|
|
46
|
+
* What a paste may build from an object copied in another tab (see `ObjectClipboardPolicy`):
|
|
47
|
+
* which `https:` URLs a picture or link may keep, and whether a host-defined embed kind (an
|
|
48
|
+
* `asset` embed, …) may be pasted or duplicated at all. Default: neither.
|
|
49
|
+
*/
|
|
50
|
+
objectClipboardPolicy?: Omit<ObjectClipboardPolicy, "origin">;
|
|
51
|
+
/**
|
|
52
|
+
* Whether this workbook has the sheet: a chart pasted from elsewhere drops a range on a sheet
|
|
53
|
+
* that does not exist here. Without it every range is kept.
|
|
54
|
+
*/
|
|
55
|
+
sheetExists?: (sheetId: number) => boolean;
|
|
29
56
|
};
|
|
30
57
|
/** The chart clipboard as `useEmbedsCharts` consumes it (keyboard + right-click menu). */
|
|
31
|
-
export type ChartClipboard = Pick<ReturnType<typeof useChartClipboard>, "copyChart" | "cutChart" | "pasteChart" | "duplicateChart" | "hasChartOnClipboard">;
|
|
58
|
+
export type ChartClipboard = Pick<ReturnType<typeof useChartClipboard>, "copyChart" | "cutChart" | "pasteChart" | "duplicateChart" | "hasChartOnClipboard" | "copyEmbed" | "cutEmbed" | "duplicateEmbed">;
|
|
32
59
|
/**
|
|
33
60
|
* A chart pasted onto another sheet must keep reading its original data:
|
|
34
61
|
* every range in the spec that relied on the implicit "own sheet" gets that
|
|
35
62
|
* sheet written in.
|
|
36
63
|
*/
|
|
37
64
|
export declare const pinSpecRangesToSheet: <T>(value: T, sheetId: number) => T;
|
|
65
|
+
type Axis = {
|
|
66
|
+
anchor: number;
|
|
67
|
+
anchorOffset: number;
|
|
68
|
+
to: number;
|
|
69
|
+
toOffset: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* One axis (columns or rows) of a pasted object's two anchors, stored the way a move stores them:
|
|
73
|
+
* an offset past its cell's size moves on to the next cell and a negative far offset back to the
|
|
74
|
+
* previous one (never a negative offset); a far anchor past the sheet's last row / column shifts
|
|
75
|
+
* the whole object back onto the sheet, and when it is larger than the sheet the corner stays on
|
|
76
|
+
* the last cell's last pixel. `size` is a column's width or a row's height.
|
|
77
|
+
*/
|
|
78
|
+
export declare const placeAnchorAxis: (axis: Axis, last: number, size: (index: number) => number) => Axis;
|
|
38
79
|
/**
|
|
39
|
-
* Ctrl+C / Ctrl+X / Ctrl+V / Ctrl+D on a selected chart (Excel object
|
|
40
|
-
* clipboard). The copied
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
80
|
+
* Ctrl+C / Ctrl+X / Ctrl+V / Ctrl+D on a selected chart, picture, shape or text box (Excel's object
|
|
81
|
+
* clipboard). The copied object lives in memory (plus a custom clipboard type for same-browser
|
|
82
|
+
* tabs); a paste creates an object with a fresh id — a chart bound to the SAME source data (pasting
|
|
83
|
+
* onto another sheet keeps the references pointing at the original sheet) — and selects it. A cut
|
|
84
|
+
* removes the object immediately (Excel removes cut objects on Ctrl+X, unlike cut cells which wait
|
|
85
|
+
* for the paste). Every paste, cut and duplicate goes through the host's create / delete handlers,
|
|
86
|
+
* one undo step each.
|
|
45
87
|
*/
|
|
46
|
-
export declare const useChartClipboard: ({ sheetId, activeCell, charts, readonly, onCreateChart, onDeleteChart, onCopyChart, onCutChart, focusSheet, }: UseChartClipboardProps) => {
|
|
88
|
+
export declare const useChartClipboard: ({ sheetId, activeCell, charts, readonly, onCreateChart, onDeleteChart, onCopyChart, onCutChart, embeds, onCreateEmbed, onDeleteEmbed, focusSheet, rowCount, columnCount, getColumnWidth, getRowHeight, objectClipboardPolicy, sheetExists, }: UseChartClipboardProps) => {
|
|
47
89
|
copyChart: (chartId: EmbeddedChart["chartId"], e?: ClipboardEvent) => boolean;
|
|
48
90
|
cutChart: (chartId: EmbeddedChart["chartId"], e?: ClipboardEvent) => boolean;
|
|
49
91
|
pasteChart: (e?: ClipboardEvent) => boolean;
|
|
50
92
|
duplicateChart: (chartId: EmbeddedChart["chartId"]) => EmbeddedChart | undefined;
|
|
93
|
+
copyEmbed: (embedId: EmbeddedObject["embedId"], e?: ClipboardEvent) => boolean;
|
|
94
|
+
cutEmbed: (embedId: EmbeddedObject["embedId"], e?: ClipboardEvent) => boolean;
|
|
95
|
+
duplicateEmbed: (embedId: EmbeddedObject["embedId"]) => EmbeddedObject | undefined;
|
|
51
96
|
clearChartClipboard: () => void;
|
|
52
97
|
hasChartOnClipboard: () => boolean;
|
|
53
98
|
getSelectedChart: () => EmbeddedChart | undefined;
|
|
54
99
|
};
|
|
100
|
+
export {};
|
|
55
101
|
//# sourceMappingURL=use-chart-clipboard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-chart-clipboard.d.ts","sourceRoot":"","sources":["../../../hooks/use-chart-clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-chart-clipboard.d.ts","sourceRoot":"","sources":["../../../hooks/use-chart-clipboard.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useChartClipboard = exports.pinSpecRangesToSheet = exports.CHART_PASTE_OFFSET_PIXELS = exports.CHART_CLIPBOARD_MIME = void 0;
|
|
3
|
+
exports.useChartClipboard = exports.placeAnchorAxis = exports.pinSpecRangesToSheet = exports.CHART_PASTE_OFFSET_PIXELS = exports.EMBED_CLIPBOARD_MIME = exports.CHART_CLIPBOARD_MIME = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var utils_1 = require("@rowsncolumns/utils");
|
|
6
6
|
var react_1 = require("react");
|
|
7
7
|
var atoms_1 = require("../atoms");
|
|
8
|
+
var z_order_1 = require("../utils/z-order");
|
|
9
|
+
var object_clipboard_payload_1 = require("./object-clipboard-payload");
|
|
8
10
|
var use_callback_ref_1 = require("./use-callback-ref");
|
|
9
11
|
/**
|
|
10
12
|
* Clipboard type the copied chart rides on, so a paste in another tab of the
|
|
@@ -12,11 +14,18 @@ var use_callback_ref_1 = require("./use-callback-ref");
|
|
|
12
14
|
* paste events, hence the in-memory entry below is the primary source.
|
|
13
15
|
*/
|
|
14
16
|
exports.CHART_CLIPBOARD_MIME = "application/x-rowsncolumns-chart";
|
|
17
|
+
/** Clipboard type a copied picture, shape or text box rides on (as `CHART_CLIPBOARD_MIME`). */
|
|
18
|
+
exports.EMBED_CLIPBOARD_MIME = "application/x-rowsncolumns-embed";
|
|
15
19
|
/**
|
|
16
20
|
* Excel nudges a pasted or duplicated object this far down-right of the
|
|
17
21
|
* original when the destination is the object's own spot.
|
|
18
22
|
*/
|
|
19
23
|
exports.CHART_PASTE_OFFSET_PIXELS = 10;
|
|
24
|
+
var MAX_ROW_INDEX = 1048576;
|
|
25
|
+
var MAX_COLUMN_INDEX = 16384;
|
|
26
|
+
/** Cell sizes assumed when the grid gives none (a host calling the hook without geometry). */
|
|
27
|
+
var DEFAULT_ANCHOR_CELL_WIDTH = 100;
|
|
28
|
+
var DEFAULT_ANCHOR_CELL_HEIGHT = 21;
|
|
20
29
|
var isRange = function (value) {
|
|
21
30
|
return typeof value.startRowIndex === "number" &&
|
|
22
31
|
typeof value.startColumnIndex === "number";
|
|
@@ -58,21 +67,102 @@ exports.pinSpecRangesToSheet = pinSpecRangesToSheet;
|
|
|
58
67
|
var cloneChart = function (chart) {
|
|
59
68
|
return JSON.parse(JSON.stringify(chart));
|
|
60
69
|
};
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
var cloneEmbed = function (embed) {
|
|
71
|
+
return JSON.parse(JSON.stringify(embed));
|
|
72
|
+
};
|
|
73
|
+
/** The embed kinds the object clipboard copies, pastes and duplicates itself. */
|
|
74
|
+
var CLIPBOARD_EMBED_TYPES = new Set(["image", "shape", "textbox", "formControl"]);
|
|
75
|
+
/** Excel's default name of each form control kind ("Check Box 1"). */
|
|
76
|
+
var FORM_CONTROL_NAMES = {
|
|
77
|
+
Button: "Button",
|
|
78
|
+
CheckBox: "Check Box",
|
|
79
|
+
Drop: "Drop Down",
|
|
80
|
+
EditBox: "Edit Box",
|
|
81
|
+
GBox: "Group Box",
|
|
82
|
+
Label: "Label",
|
|
83
|
+
List: "List Box",
|
|
84
|
+
Radio: "Option Button",
|
|
85
|
+
Scroll: "Scroll Bar",
|
|
86
|
+
Spin: "Spinner",
|
|
87
|
+
Dialog: "Dialog",
|
|
88
|
+
};
|
|
89
|
+
var NUMBERED_NAME = /^(.*?)\s*(\d+)$/;
|
|
90
|
+
/**
|
|
91
|
+
* A pasted or duplicated form control is a new control, as in Excel: it takes the next free
|
|
92
|
+
* number of its name ("Check Box 1" → "Check Box 2", counting every form control in `embeds`)
|
|
93
|
+
* and no `shapeId` (the exporters give it its own).
|
|
94
|
+
*/
|
|
95
|
+
var renameFormControl = function (embed, embeds) {
|
|
96
|
+
var e_2, _a;
|
|
97
|
+
var _b, _c, _d, _e, _f;
|
|
98
|
+
if (embed.spec.type !== "formControl")
|
|
99
|
+
return embed;
|
|
100
|
+
var spec = embed.spec;
|
|
101
|
+
var base = (_e = (_d = (spec.name ? (_c = (_b = NUMBERED_NAME.exec(spec.name)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : spec.name : undefined)) !== null && _d !== void 0 ? _d : FORM_CONTROL_NAMES[spec.objectType]) !== null && _e !== void 0 ? _e : spec.objectType;
|
|
102
|
+
var highest = 0;
|
|
67
103
|
try {
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
for (var _g = tslib_1.__values(embeds !== null && embeds !== void 0 ? embeds : []), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
105
|
+
var other = _h.value;
|
|
106
|
+
if (other.spec.type !== "formControl")
|
|
107
|
+
continue;
|
|
108
|
+
var match = NUMBERED_NAME.exec((_f = other.spec.name) !== null && _f !== void 0 ? _f : "");
|
|
109
|
+
if (match && match[1] === base)
|
|
110
|
+
highest = Math.max(highest, Number(match[2]));
|
|
111
|
+
}
|
|
72
112
|
}
|
|
73
|
-
catch (
|
|
74
|
-
|
|
113
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
114
|
+
finally {
|
|
115
|
+
try {
|
|
116
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
117
|
+
}
|
|
118
|
+
finally { if (e_2) throw e_2.error; }
|
|
75
119
|
}
|
|
120
|
+
var _shapeId = spec.shapeId, rest = tslib_1.__rest(spec, ["shapeId"]);
|
|
121
|
+
return tslib_1.__assign(tslib_1.__assign({}, embed), { spec: tslib_1.__assign(tslib_1.__assign({}, rest), { name: "".concat(base, " ").concat(highest + 1) }) });
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* One axis (columns or rows) of a pasted object's two anchors, stored the way a move stores them:
|
|
125
|
+
* an offset past its cell's size moves on to the next cell and a negative far offset back to the
|
|
126
|
+
* previous one (never a negative offset); a far anchor past the sheet's last row / column shifts
|
|
127
|
+
* the whole object back onto the sheet, and when it is larger than the sheet the corner stays on
|
|
128
|
+
* the last cell's last pixel. `size` is a column's width or a row's height.
|
|
129
|
+
*/
|
|
130
|
+
var placeAnchorAxis = function (axis, last, size) {
|
|
131
|
+
var anchor = axis.anchor, anchorOffset = axis.anchorOffset, to = axis.to, toOffset = axis.toOffset;
|
|
132
|
+
var lastPixel = function (index) { return Math.max(0, size(index) - 1); };
|
|
133
|
+
for (var guard = 0; toOffset < 0 && to > anchor && guard < 100000; guard++) {
|
|
134
|
+
to -= 1;
|
|
135
|
+
toOffset += size(to);
|
|
136
|
+
}
|
|
137
|
+
toOffset = Math.max(0, toOffset);
|
|
138
|
+
anchorOffset = Math.max(0, anchorOffset);
|
|
139
|
+
for (var guard = 0; anchor < last && size(anchor) > 0 && anchorOffset > size(anchor) && guard < 100000; guard++) {
|
|
140
|
+
anchorOffset -= size(anchor);
|
|
141
|
+
anchor += 1;
|
|
142
|
+
to = Math.max(to, anchor);
|
|
143
|
+
}
|
|
144
|
+
for (var guard = 0; to < last && size(to) > 0 && toOffset > size(to) && guard < 100000; guard++) {
|
|
145
|
+
toOffset -= size(to);
|
|
146
|
+
to += 1;
|
|
147
|
+
}
|
|
148
|
+
if (to > last) {
|
|
149
|
+
var shift = Math.min(to - last, anchor - 1);
|
|
150
|
+
anchor -= shift;
|
|
151
|
+
to -= shift;
|
|
152
|
+
if (to > last) {
|
|
153
|
+
to = last;
|
|
154
|
+
toOffset = lastPixel(last);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (to === last)
|
|
158
|
+
toOffset = Math.min(toOffset, lastPixel(last));
|
|
159
|
+
if (anchor === last)
|
|
160
|
+
anchorOffset = Math.min(anchorOffset, lastPixel(last));
|
|
161
|
+
return { anchor: anchor, anchorOffset: anchorOffset, to: to, toOffset: toOffset };
|
|
162
|
+
};
|
|
163
|
+
exports.placeAnchorAxis = placeAnchorAxis;
|
|
164
|
+
var positionOf = function (entry) {
|
|
165
|
+
return entry.kind === "chart" ? entry.chart.position : entry.embed.position;
|
|
76
166
|
};
|
|
77
167
|
/**
|
|
78
168
|
* Cell copies write text + html; anything else on the clipboard (external
|
|
@@ -87,19 +177,24 @@ var carriesForeignContent = function (data) {
|
|
|
87
177
|
((_a = data.files) === null || _a === void 0 ? void 0 : _a.length)));
|
|
88
178
|
};
|
|
89
179
|
/**
|
|
90
|
-
* Ctrl+C / Ctrl+X / Ctrl+V / Ctrl+D on a selected chart (Excel object
|
|
91
|
-
* clipboard). The copied
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
180
|
+
* Ctrl+C / Ctrl+X / Ctrl+V / Ctrl+D on a selected chart, picture, shape or text box (Excel's object
|
|
181
|
+
* clipboard). The copied object lives in memory (plus a custom clipboard type for same-browser
|
|
182
|
+
* tabs); a paste creates an object with a fresh id — a chart bound to the SAME source data (pasting
|
|
183
|
+
* onto another sheet keeps the references pointing at the original sheet) — and selects it. A cut
|
|
184
|
+
* removes the object immediately (Excel removes cut objects on Ctrl+X, unlike cut cells which wait
|
|
185
|
+
* for the paste). Every paste, cut and duplicate goes through the host's create / delete handlers,
|
|
186
|
+
* one undo step each.
|
|
96
187
|
*/
|
|
97
188
|
var useChartClipboard = function (_a) {
|
|
98
|
-
var sheetId = _a.sheetId, activeCell = _a.activeCell, charts = _a.charts, readonly = _a.readonly, onCreateChart = _a.onCreateChart, onDeleteChart = _a.onDeleteChart, onCopyChart = _a.onCopyChart, onCutChart = _a.onCutChart, focusSheet = _a.focusSheet;
|
|
189
|
+
var sheetId = _a.sheetId, activeCell = _a.activeCell, charts = _a.charts, readonly = _a.readonly, onCreateChart = _a.onCreateChart, onDeleteChart = _a.onDeleteChart, onCopyChart = _a.onCopyChart, onCutChart = _a.onCutChart, embeds = _a.embeds, onCreateEmbed = _a.onCreateEmbed, onDeleteEmbed = _a.onDeleteEmbed, focusSheet = _a.focusSheet, rowCount = _a.rowCount, columnCount = _a.columnCount, getColumnWidth = _a.getColumnWidth, getRowHeight = _a.getRowHeight, objectClipboardPolicy = _a.objectClipboardPolicy, sheetExists = _a.sheetExists;
|
|
99
190
|
var _b = tslib_1.__read((0, atoms_1.useSelectedChartEmbed)(), 2), selectedChartId = _b[0], setSelectedChartId = _b[1];
|
|
100
191
|
var entryRef = (0, react_1.useRef)(undefined);
|
|
192
|
+
/** The custom-type payload this grid last wrote: a paste that reads it back is its own copy. */
|
|
193
|
+
var writtenRef = (0, react_1.useRef)(undefined);
|
|
101
194
|
var onCreateChartRef = (0, use_callback_ref_1.useCallbackRef)(onCreateChart);
|
|
102
195
|
var onDeleteChartRef = (0, use_callback_ref_1.useCallbackRef)(onDeleteChart);
|
|
196
|
+
var onCreateEmbedRef = (0, use_callback_ref_1.useCallbackRef)(onCreateEmbed);
|
|
197
|
+
var onDeleteEmbedRef = (0, use_callback_ref_1.useCallbackRef)(onDeleteEmbed);
|
|
103
198
|
var onCopyChartRef = (0, use_callback_ref_1.useCallbackRef)(onCopyChart);
|
|
104
199
|
var onCutChartRef = (0, use_callback_ref_1.useCallbackRef)(onCutChart);
|
|
105
200
|
var focusSheetRef = (0, use_callback_ref_1.useCallbackRef)(focusSheet);
|
|
@@ -107,61 +202,133 @@ var useChartClipboard = function (_a) {
|
|
|
107
202
|
sheetId: sheetId,
|
|
108
203
|
activeCell: activeCell,
|
|
109
204
|
charts: charts,
|
|
205
|
+
embeds: embeds,
|
|
110
206
|
readonly: readonly,
|
|
111
207
|
selectedChartId: selectedChartId,
|
|
208
|
+
canCreateEmbed: Boolean(onCreateEmbed),
|
|
209
|
+
lastRow: Math.max(1, rowCount !== null && rowCount !== void 0 ? rowCount : MAX_ROW_INDEX),
|
|
210
|
+
lastColumn: Math.max(1, columnCount !== null && columnCount !== void 0 ? columnCount : MAX_COLUMN_INDEX),
|
|
211
|
+
getColumnWidth: getColumnWidth !== null && getColumnWidth !== void 0 ? getColumnWidth : (function () { return DEFAULT_ANCHOR_CELL_WIDTH; }),
|
|
212
|
+
getRowHeight: getRowHeight !== null && getRowHeight !== void 0 ? getRowHeight : (function () { return DEFAULT_ANCHOR_CELL_HEIGHT; }),
|
|
213
|
+
policy: objectClipboardPolicy,
|
|
214
|
+
sheetExists: sheetExists,
|
|
112
215
|
}); });
|
|
216
|
+
/** Whether the clipboard handles `embed` itself, or the host accepted its kind. */
|
|
217
|
+
var acceptEmbed = (0, react_1.useCallback)(function (embed) {
|
|
218
|
+
var _a, _b;
|
|
219
|
+
if (CLIPBOARD_EMBED_TYPES.has(embed.spec.type))
|
|
220
|
+
return embed;
|
|
221
|
+
var accepted = (_b = (_a = getContext().policy) === null || _a === void 0 ? void 0 : _a.acceptHostEmbed) === null || _b === void 0 ? void 0 : _b.call(_a, cloneEmbed(embed));
|
|
222
|
+
return accepted ? cloneEmbed(accepted) : undefined;
|
|
223
|
+
}, [getContext]);
|
|
113
224
|
var findChart = (0, react_1.useCallback)(function (chartId) {
|
|
114
225
|
var _a;
|
|
115
226
|
return chartId === undefined
|
|
116
227
|
? undefined
|
|
117
228
|
: (_a = getContext().charts) === null || _a === void 0 ? void 0 : _a.find(function (chart) { return chart.chartId === chartId; });
|
|
118
229
|
}, [getContext]);
|
|
230
|
+
var findEmbed = (0, react_1.useCallback)(function (embedId) {
|
|
231
|
+
var _a;
|
|
232
|
+
return embedId === undefined
|
|
233
|
+
? undefined
|
|
234
|
+
: (_a = getContext().embeds) === null || _a === void 0 ? void 0 : _a.find(function (embed) { return embed.embedId === embedId; });
|
|
235
|
+
}, [getContext]);
|
|
119
236
|
/** The chart the grid's copy / cut / duplicate shortcuts act on. */
|
|
120
237
|
var getSelectedChart = (0, react_1.useCallback)(function () { return findChart(getContext().selectedChartId); }, [findChart, getContext]);
|
|
121
238
|
/**
|
|
122
|
-
* Where a pasted
|
|
123
|
-
*
|
|
239
|
+
* Where a pasted object lands: the active cell, or — when an object is still selected on the
|
|
240
|
+
* source sheet (nothing moved) — offset from the source. An object anchored to two cells keeps
|
|
241
|
+
* its size: its second anchor moves with the first.
|
|
124
242
|
*/
|
|
125
|
-
var
|
|
126
|
-
var _a, _b;
|
|
127
|
-
var
|
|
128
|
-
var overlayPosition = source.
|
|
129
|
-
|
|
243
|
+
var placeObject = (0, react_1.useCallback)(function (source, nearSource) {
|
|
244
|
+
var _a, _b, _c, _d;
|
|
245
|
+
var _e = getContext(), sheetId = _e.sheetId, activeCell = _e.activeCell, lastRow = _e.lastRow, lastColumn = _e.lastColumn, getColumnWidth = _e.getColumnWidth, getRowHeight = _e.getRowHeight;
|
|
246
|
+
var overlayPosition = source.overlayPosition;
|
|
247
|
+
var sourceAnchor = overlayPosition.anchorCell;
|
|
248
|
+
var offsetX = (_a = overlayPosition.offsetXPixels) !== null && _a !== void 0 ? _a : 0;
|
|
249
|
+
var offsetY = (_b = overlayPosition.offsetYPixels) !== null && _b !== void 0 ? _b : 0;
|
|
250
|
+
var nudge = nearSource ? exports.CHART_PASTE_OFFSET_PIXELS : 0;
|
|
251
|
+
var anchor = nearSource ? sourceAnchor : activeCell;
|
|
252
|
+
var toCell = overlayPosition.toCell;
|
|
253
|
+
if (!toCell) {
|
|
130
254
|
return {
|
|
131
255
|
sheetId: sheetId,
|
|
132
|
-
overlayPosition: tslib_1.__assign(tslib_1.__assign({}, overlayPosition), {
|
|
256
|
+
overlayPosition: tslib_1.__assign(tslib_1.__assign({}, overlayPosition), { anchorCell: anchor, offsetXPixels: nearSource ? offsetX + nudge : 0, offsetYPixels: nearSource ? offsetY + nudge : 0 }),
|
|
133
257
|
};
|
|
134
258
|
}
|
|
259
|
+
// Both corners move together: the far anchor keeps its distance from the near one.
|
|
260
|
+
var toOffsetX = (_c = overlayPosition.toOffsetXPixels) !== null && _c !== void 0 ? _c : 0;
|
|
261
|
+
var toOffsetY = (_d = overlayPosition.toOffsetYPixels) !== null && _d !== void 0 ? _d : 0;
|
|
262
|
+
var columns = (0, exports.placeAnchorAxis)({
|
|
263
|
+
anchor: anchor.columnIndex,
|
|
264
|
+
anchorOffset: nearSource ? offsetX + nudge : 0,
|
|
265
|
+
to: anchor.columnIndex + (toCell.columnIndex - sourceAnchor.columnIndex),
|
|
266
|
+
toOffset: nearSource ? toOffsetX + nudge : toOffsetX - offsetX,
|
|
267
|
+
}, lastColumn, getColumnWidth);
|
|
268
|
+
var rows = (0, exports.placeAnchorAxis)({
|
|
269
|
+
anchor: anchor.rowIndex,
|
|
270
|
+
anchorOffset: nearSource ? offsetY + nudge : 0,
|
|
271
|
+
to: anchor.rowIndex + (toCell.rowIndex - sourceAnchor.rowIndex),
|
|
272
|
+
toOffset: nearSource ? toOffsetY + nudge : toOffsetY - offsetY,
|
|
273
|
+
}, lastRow, getRowHeight);
|
|
135
274
|
return {
|
|
136
275
|
sheetId: sheetId,
|
|
137
|
-
overlayPosition: tslib_1.__assign(tslib_1.__assign({}, overlayPosition), { anchorCell:
|
|
276
|
+
overlayPosition: tslib_1.__assign(tslib_1.__assign({}, overlayPosition), { anchorCell: { rowIndex: rows.anchor, columnIndex: columns.anchor }, offsetXPixels: columns.anchorOffset, offsetYPixels: rows.anchorOffset, toCell: { rowIndex: rows.to, columnIndex: columns.to }, toOffsetXPixels: columns.toOffset, toOffsetYPixels: rows.toOffset }),
|
|
138
277
|
};
|
|
139
278
|
}, [getContext]);
|
|
140
279
|
var createChartAt = (0, react_1.useCallback)(function (source, position) {
|
|
141
|
-
var
|
|
142
|
-
|
|
280
|
+
var _a = getContext(), activeCell = _a.activeCell, charts = _a.charts, embeds = _a.embeds;
|
|
281
|
+
// The pasted chart goes on top of the sheet's objects, as Excel's paste does.
|
|
282
|
+
var stack = (0, z_order_1.getStackingOrder)(charts, embeds, position.sheetId);
|
|
283
|
+
var top = stack.length ? stack[stack.length - 1].zOrder + 1 : undefined;
|
|
284
|
+
var chart = tslib_1.__assign(tslib_1.__assign({}, cloneChart(source)), { chartId: (0, utils_1.uuid)(), position: tslib_1.__assign(tslib_1.__assign({}, position), { zOrder: top }), spec: (0, exports.pinSpecRangesToSheet)(source.spec, source.position.sheetId) });
|
|
143
285
|
onCreateChartRef(position.sheetId, activeCell, [], chart);
|
|
144
286
|
setSelectedChartId(chart.chartId);
|
|
145
287
|
return chart;
|
|
146
288
|
}, [getContext, onCreateChartRef, setSelectedChartId]);
|
|
289
|
+
var createEmbedAt = (0, react_1.useCallback)(function (source, position) {
|
|
290
|
+
var _a = getContext(), charts = _a.charts, embeds = _a.embeds;
|
|
291
|
+
// The pasted object goes on top of the sheet's objects, as Excel's paste does.
|
|
292
|
+
var stack = (0, z_order_1.getStackingOrder)(charts, embeds, position.sheetId);
|
|
293
|
+
var top = stack.length ? stack[stack.length - 1].zOrder + 1 : undefined;
|
|
294
|
+
var embed = tslib_1.__assign(tslib_1.__assign({}, renameFormControl(cloneEmbed(source), embeds)), { embedId: (0, utils_1.uuid)(), position: tslib_1.__assign(tslib_1.__assign({}, position), { zOrder: top }) });
|
|
295
|
+
onCreateEmbedRef(embed);
|
|
296
|
+
setSelectedChartId(embed.embedId);
|
|
297
|
+
return embed;
|
|
298
|
+
}, [getContext, onCreateEmbedRef, setSelectedChartId]);
|
|
299
|
+
var writeEntry = function (entry, e) {
|
|
300
|
+
var _a, _b;
|
|
301
|
+
entryRef.current = entry;
|
|
302
|
+
writtenRef.current = undefined;
|
|
303
|
+
if (e) {
|
|
304
|
+
e.preventDefault();
|
|
305
|
+
// Overwrite whatever cells were copied before, so the object is what the next paste sees
|
|
306
|
+
// even where the custom type is dropped.
|
|
307
|
+
var payload = JSON.stringify(entry.kind === "chart" ? entry.chart : entry.embed);
|
|
308
|
+
(_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.setData("text/plain", "");
|
|
309
|
+
(_b = e.clipboardData) === null || _b === void 0 ? void 0 : _b.setData(entry.kind === "chart" ? exports.CHART_CLIPBOARD_MIME : exports.EMBED_CLIPBOARD_MIME, payload);
|
|
310
|
+
writtenRef.current = payload;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
147
313
|
/** Ctrl+C on a chart. Returns false when `chartId` is not a chart on this grid. */
|
|
148
314
|
var copyChart = (0, react_1.useCallback)(function (chartId, e) {
|
|
149
|
-
var _a, _b;
|
|
150
315
|
var chart = findChart(chartId);
|
|
151
316
|
if (!chart) {
|
|
152
317
|
return false;
|
|
153
318
|
}
|
|
154
|
-
|
|
155
|
-
if (e) {
|
|
156
|
-
e.preventDefault();
|
|
157
|
-
// Overwrite whatever cells were copied before, so the chart is what
|
|
158
|
-
// the next paste sees even where the custom type is dropped.
|
|
159
|
-
(_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.setData("text/plain", "");
|
|
160
|
-
(_b = e.clipboardData) === null || _b === void 0 ? void 0 : _b.setData(exports.CHART_CLIPBOARD_MIME, JSON.stringify(entryRef.current));
|
|
161
|
-
}
|
|
319
|
+
writeEntry({ kind: "chart", chart: cloneChart(chart) }, e);
|
|
162
320
|
onCopyChartRef(chartId);
|
|
163
321
|
return true;
|
|
164
322
|
}, [findChart, onCopyChartRef]);
|
|
323
|
+
/** Ctrl+C on a picture, shape or text box. Returns false when `embedId` is not one on this grid. */
|
|
324
|
+
var copyEmbed = (0, react_1.useCallback)(function (embedId, e) {
|
|
325
|
+
var embed = findEmbed(embedId);
|
|
326
|
+
if (!embed || !acceptEmbed(embed)) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
writeEntry({ kind: "embed", embed: cloneEmbed(embed) }, e);
|
|
330
|
+
return true;
|
|
331
|
+
}, [findEmbed, acceptEmbed]);
|
|
165
332
|
/** Ctrl+X on a chart: copy, then remove it (one history step). */
|
|
166
333
|
var cutChart = (0, react_1.useCallback)(function (chartId, e) {
|
|
167
334
|
if (getContext().readonly || !copyChart(chartId, e)) {
|
|
@@ -182,47 +349,132 @@ var useChartClipboard = function (_a) {
|
|
|
182
349
|
focusSheetRef,
|
|
183
350
|
onCutChartRef,
|
|
184
351
|
]);
|
|
185
|
-
/**
|
|
352
|
+
/** Ctrl+X on a picture, shape or text box: copy, then remove it (one history step). */
|
|
353
|
+
var cutEmbed = (0, react_1.useCallback)(function (embedId, e) {
|
|
354
|
+
if (getContext().readonly || !onDeleteEmbed || !copyEmbed(embedId, e)) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
onDeleteEmbedRef(embedId);
|
|
358
|
+
if (getContext().selectedChartId === embedId) {
|
|
359
|
+
setSelectedChartId(undefined);
|
|
360
|
+
}
|
|
361
|
+
focusSheetRef();
|
|
362
|
+
return true;
|
|
363
|
+
}, [getContext, onDeleteEmbed, copyEmbed, onDeleteEmbedRef, setSelectedChartId, focusSheetRef]);
|
|
364
|
+
/** A cell copy supersedes the object on the clipboard. */
|
|
186
365
|
var clearChartClipboard = (0, react_1.useCallback)(function () {
|
|
187
366
|
entryRef.current = undefined;
|
|
367
|
+
writtenRef.current = undefined;
|
|
188
368
|
}, []);
|
|
189
|
-
/** Whether a paste would create
|
|
190
|
-
var hasChartOnClipboard = (0, react_1.useCallback)(function () {
|
|
369
|
+
/** Whether a paste would create an object (drives the menu's Paste item). */
|
|
370
|
+
var hasChartOnClipboard = (0, react_1.useCallback)(function () {
|
|
371
|
+
var _a = getContext(), readonly = _a.readonly, canCreateEmbed = _a.canCreateEmbed;
|
|
372
|
+
var entry = entryRef.current;
|
|
373
|
+
return Boolean(entry) && !readonly && ((entry === null || entry === void 0 ? void 0 : entry.kind) === "chart" || canCreateEmbed);
|
|
374
|
+
}, [getContext]);
|
|
191
375
|
/**
|
|
192
|
-
* Ctrl+V. Returns true when the clipboard held
|
|
193
|
-
*
|
|
376
|
+
* Ctrl+V. Returns true when the clipboard held an object and it was pasted (the caller must
|
|
377
|
+
* then skip the cell paste), false to fall through.
|
|
194
378
|
*/
|
|
195
379
|
var pasteChart = (0, react_1.useCallback)(function (e) {
|
|
196
|
-
var _a
|
|
197
|
-
var
|
|
380
|
+
var _a;
|
|
381
|
+
var _b = getContext(), sheetId = _b.sheetId, readonly = _b.readonly, selectedChartId = _b.selectedChartId, canCreateEmbed = _b.canCreateEmbed, policy = _b.policy, sheetExists = _b.sheetExists;
|
|
198
382
|
if (readonly) {
|
|
199
383
|
return false;
|
|
200
384
|
}
|
|
201
385
|
var data = e === null || e === void 0 ? void 0 : e.clipboardData;
|
|
202
|
-
|
|
203
|
-
|
|
386
|
+
// Text, HTML or files on the clipboard are a copy from elsewhere: they paste as cells,
|
|
387
|
+
// whatever custom type rides along.
|
|
388
|
+
if (carriesForeignContent(data)) {
|
|
204
389
|
clearChartClipboard();
|
|
205
390
|
return false;
|
|
206
391
|
}
|
|
392
|
+
var chartPayload = (data === null || data === void 0 ? void 0 : data.getData(exports.CHART_CLIPBOARD_MIME)) || undefined;
|
|
393
|
+
var embedPayload = (data === null || data === void 0 ? void 0 : data.getData(exports.EMBED_CLIPBOARD_MIME)) || undefined;
|
|
394
|
+
var payload = chartPayload !== null && chartPayload !== void 0 ? chartPayload : embedPayload;
|
|
395
|
+
var source;
|
|
396
|
+
// A payload from elsewhere is accepted (host kinds included) while it is parsed.
|
|
397
|
+
var parsed = false;
|
|
398
|
+
if (payload && payload === writtenRef.current && entryRef.current) {
|
|
399
|
+
// This grid's own copy, read back.
|
|
400
|
+
source = entryRef.current;
|
|
401
|
+
}
|
|
402
|
+
else if (chartPayload) {
|
|
403
|
+
parsed = true;
|
|
404
|
+
var chart = (0, object_clipboard_payload_1.parseChartPayload)(chartPayload, { sheetExists: sheetExists });
|
|
405
|
+
source = chart ? { kind: "chart", chart: chart } : undefined;
|
|
406
|
+
}
|
|
407
|
+
else if (embedPayload) {
|
|
408
|
+
parsed = true;
|
|
409
|
+
var embed = (0, object_clipboard_payload_1.parseEmbedPayload)(embedPayload, tslib_1.__assign(tslib_1.__assign({}, policy), { origin: typeof window === "undefined" ? undefined : window.location.origin }));
|
|
410
|
+
source = embed ? { kind: "embed", embed: embed } : undefined;
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
source = entryRef.current;
|
|
414
|
+
}
|
|
415
|
+
if (!source) {
|
|
416
|
+
// A payload that is not a valid object pastes nothing; the cell paste reads the rest.
|
|
417
|
+
if (payload)
|
|
418
|
+
clearChartClipboard();
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
if (source.kind === "embed") {
|
|
422
|
+
var accepted = !canCreateEmbed
|
|
423
|
+
? undefined
|
|
424
|
+
: parsed
|
|
425
|
+
? source.embed
|
|
426
|
+
: acceptEmbed(source.embed);
|
|
427
|
+
if (!accepted)
|
|
428
|
+
return false;
|
|
429
|
+
source = { kind: "embed", embed: accepted };
|
|
430
|
+
}
|
|
207
431
|
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
208
|
-
var
|
|
209
|
-
|
|
210
|
-
|
|
432
|
+
var selected = (_a = findChart(selectedChartId)) !== null && _a !== void 0 ? _a : findEmbed(selectedChartId);
|
|
433
|
+
var nearSource = positionOf(source).sheetId === sheetId && (selected === null || selected === void 0 ? void 0 : selected.position.sheetId) === sheetId;
|
|
434
|
+
var position = placeObject(positionOf(source), nearSource);
|
|
435
|
+
if (source.kind === "chart") {
|
|
436
|
+
createChartAt(source.chart, position);
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
createEmbedAt(source.embed, position);
|
|
440
|
+
}
|
|
211
441
|
return true;
|
|
212
|
-
}, [
|
|
442
|
+
}, [
|
|
443
|
+
getContext,
|
|
444
|
+
clearChartClipboard,
|
|
445
|
+
acceptEmbed,
|
|
446
|
+
findChart,
|
|
447
|
+
findEmbed,
|
|
448
|
+
placeObject,
|
|
449
|
+
createChartAt,
|
|
450
|
+
createEmbedAt,
|
|
451
|
+
]);
|
|
213
452
|
/** Ctrl+D on a chart: a copy offset down-right, clipboard untouched. */
|
|
214
453
|
var duplicateChart = (0, react_1.useCallback)(function (chartId) {
|
|
215
454
|
var chart = findChart(chartId);
|
|
216
455
|
if (!chart || getContext().readonly) {
|
|
217
456
|
return undefined;
|
|
218
457
|
}
|
|
219
|
-
return createChartAt(chart,
|
|
220
|
-
}, [findChart, getContext, createChartAt,
|
|
458
|
+
return createChartAt(chart, placeObject(chart.position, true));
|
|
459
|
+
}, [findChart, getContext, createChartAt, placeObject]);
|
|
460
|
+
/** Ctrl+D on a picture, shape or text box: a copy offset down-right, clipboard untouched. */
|
|
461
|
+
var duplicateEmbed = (0, react_1.useCallback)(function (embedId) {
|
|
462
|
+
var embed = findEmbed(embedId);
|
|
463
|
+
var _a = getContext(), readonly = _a.readonly, canCreateEmbed = _a.canCreateEmbed;
|
|
464
|
+
var accepted = embed && !readonly && canCreateEmbed ? acceptEmbed(embed) : undefined;
|
|
465
|
+
if (!accepted) {
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
return createEmbedAt(accepted, placeObject(accepted.position, true));
|
|
469
|
+
}, [findEmbed, getContext, acceptEmbed, createEmbedAt, placeObject]);
|
|
221
470
|
return {
|
|
222
471
|
copyChart: copyChart,
|
|
223
472
|
cutChart: cutChart,
|
|
224
473
|
pasteChart: pasteChart,
|
|
225
474
|
duplicateChart: duplicateChart,
|
|
475
|
+
copyEmbed: copyEmbed,
|
|
476
|
+
cutEmbed: cutEmbed,
|
|
477
|
+
duplicateEmbed: duplicateEmbed,
|
|
226
478
|
clearChartClipboard: clearChartClipboard,
|
|
227
479
|
hasChartOnClipboard: hasChartOnClipboard,
|
|
228
480
|
getSelectedChart: getSelectedChart,
|
|
@@ -4,6 +4,7 @@ import React from "react";
|
|
|
4
4
|
import type { CanvasGridProps, SpreadsheetTheme } from "../components/canvas-grid/typings";
|
|
5
5
|
import { type GetLinkedPictureSource } from "../components/embeds/linked-picture";
|
|
6
6
|
import type { OverlayPosition } from "../types";
|
|
7
|
+
import type { SheetPageLayout } from "../components/page-layout-view/compute-page-layout";
|
|
7
8
|
import type { ChartClipboard } from "./use-chart-clipboard";
|
|
8
9
|
import { type ContextMenuWrapperProps } from "./use-context-menu";
|
|
9
10
|
export type OverlayBounds = {
|
|
@@ -253,8 +254,13 @@ export type UseEmbedsChartsProps = {
|
|
|
253
254
|
* Disable embeds
|
|
254
255
|
*/
|
|
255
256
|
disabled: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Page Layout view's pages (`CanvasGrid`'s page layout): an object crossing the gap between
|
|
259
|
+
* pages is drawn clipped per page. Omitted in Normal view and Page Break Preview.
|
|
260
|
+
*/
|
|
261
|
+
pageLayout?: Pick<SheetPageLayout, "rowBands" | "columnBands" | "getRowGap" | "getColumnGap">;
|
|
256
262
|
};
|
|
257
|
-
export declare const useEmbedsCharts: ({ scale, charts, embeds, slicers, sheetId, frozenRows, frozenColumns, getCellOffsetFromCoords, getCellCoordsFromOffset, getAbsolutePositionFromOffset, getRelativePositionFromOffset, ContextMenuWrapper, focusSheet, getBounds, selectedColor, onMoveChart, onResizeChart, chartClipboard, onMoveEmbed, onResizeEmbed, onDeleteChart, onUpdateChart, onChangeZOrder, onDeleteEmbed, onRequestEditEmbed, onMoveSlicer, onResizeSlicer, onDeleteSlicer, onDeleteObjects, onRequestEditSlicer, onFilterTable, onFilterPivot, tables, pivotTables, getFormattedValue, getLinkedPictureSource, getSheetName, getChartComponent, getEmbedComponent, getSlicerComponent, readonly, locale, theme, backgroundColor, disabled, }: UseEmbedsChartsProps) => {
|
|
263
|
+
export declare const useEmbedsCharts: ({ scale, charts, embeds, slicers, sheetId, frozenRows, frozenColumns, getCellOffsetFromCoords, getCellCoordsFromOffset, getAbsolutePositionFromOffset, getRelativePositionFromOffset, ContextMenuWrapper, focusSheet, getBounds, selectedColor, onMoveChart, onResizeChart, chartClipboard, onMoveEmbed, onResizeEmbed, onDeleteChart, onUpdateChart, onChangeZOrder, onDeleteEmbed, onRequestEditEmbed, onMoveSlicer, onResizeSlicer, onDeleteSlicer, onDeleteObjects, onRequestEditSlicer, onFilterTable, onFilterPivot, tables, pivotTables, getFormattedValue, getLinkedPictureSource, getSheetName, getChartComponent, getEmbedComponent, getSlicerComponent, readonly, locale, theme, backgroundColor, disabled, pageLayout, }: UseEmbedsChartsProps) => {
|
|
258
264
|
chartComponents: CategorizedComponents<React.JSX.Element>;
|
|
259
265
|
embedComponents: CategorizedComponents<React.JSX.Element>;
|
|
260
266
|
slicerComponents: CategorizedComponents<React.JSX.Element>;
|