@rowsncolumns/spreadsheet 10.11.0 → 10.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/split-pane.d.ts +1 -0
- package/dist/cjs/api/split-pane.d.ts.map +1 -1
- package/dist/cjs/api/split-pane.js +5 -1
- package/dist/cjs/atoms/calculated-column-fill.atom.d.ts +6 -2
- package/dist/cjs/atoms/calculated-column-fill.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/calculated-column-fill.atom.js +6 -2
- package/dist/cjs/atoms/cell-input-context.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/fill-options.atom.d.ts +5 -0
- package/dist/cjs/atoms/fill-options.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/table-auto-expansion.atom.d.ts +5 -2
- package/dist/cjs/atoms/table-auto-expansion.atom.d.ts.map +1 -1
- package/dist/cjs/atoms/table-auto-expansion.atom.js +5 -2
- package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts +37 -0
- package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts.map +1 -0
- package/dist/cjs/components/autocorrect-options-smart-tag/index.js +84 -0
- package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/cjs/components/canvas-grid/index.js +388 -123
- package/dist/cjs/components/canvas-grid/typings.d.ts +45 -0
- package/dist/cjs/components/canvas-grid/typings.d.ts.map +1 -1
- package/dist/cjs/components/embeds/chart-component.d.ts +9 -0
- package/dist/cjs/components/embeds/chart-component.d.ts.map +1 -1
- package/dist/cjs/components/embeds/embed-component.d.ts +9 -0
- package/dist/cjs/components/embeds/embed-component.d.ts.map +1 -1
- package/dist/cjs/components/embeds/embed-component.js +13 -114
- package/dist/cjs/components/embeds/embed-draggable.d.ts +17 -2
- package/dist/cjs/components/embeds/embed-draggable.d.ts.map +1 -1
- package/dist/cjs/components/embeds/embed-draggable.js +336 -25
- package/dist/cjs/components/embeds/object-focus.d.ts +32 -0
- package/dist/cjs/components/embeds/object-focus.d.ts.map +1 -0
- package/dist/cjs/components/embeds/object-focus.js +140 -0
- package/dist/cjs/components/embeds/page-gaps.d.ts +67 -0
- package/dist/cjs/components/embeds/page-gaps.d.ts.map +1 -0
- package/dist/cjs/components/embeds/page-gaps.js +159 -0
- package/dist/cjs/components/embeds/pane-copy.d.ts +35 -0
- package/dist/cjs/components/embeds/pane-copy.d.ts.map +1 -0
- package/dist/cjs/components/embeds/pane-copy.js +29 -0
- package/dist/cjs/components/embeds/slicer-component.d.ts +9 -0
- package/dist/cjs/components/embeds/slicer-component.d.ts.map +1 -1
- package/dist/cjs/components/embeds/text-box-view.d.ts +18 -0
- package/dist/cjs/components/embeds/text-box-view.d.ts.map +1 -0
- package/dist/cjs/components/embeds/text-box-view.js +130 -0
- package/dist/cjs/components/filter-box/filter-by-color.d.ts.map +1 -1
- package/dist/cjs/components/filter-box/filter-by-color.js +10 -3
- package/dist/cjs/components/filter-box/index.d.ts.map +1 -1
- package/dist/cjs/components/filter-box/index.js +5 -1
- package/dist/cjs/components/print-preview/page-block.d.ts +46 -0
- package/dist/cjs/components/print-preview/page-block.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/page-block.js +111 -6
- package/dist/cjs/components/print-preview/print-cells.d.ts +5 -0
- package/dist/cjs/components/print-preview/print-cells.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/print-cells.js +1 -0
- package/dist/cjs/components/print-preview/print-preview-dialog.d.ts +16 -2
- package/dist/cjs/components/print-preview/print-preview-dialog.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/print-preview-dialog.js +246 -14
- package/dist/cjs/components/print-preview/settings.d.ts +8 -0
- package/dist/cjs/components/print-preview/settings.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/settings.js +4 -1
- package/dist/cjs/components/print-preview/sheet-page-setup.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/sheet-page-setup.js +14 -2
- package/dist/cjs/components/selection/fill-options-menu.d.ts +8 -1
- package/dist/cjs/components/selection/fill-options-menu.d.ts.map +1 -1
- package/dist/cjs/components/selection/fill-options-menu.js +5 -3
- package/dist/cjs/components/selection/index.d.ts +1 -1
- package/dist/cjs/components/selection/index.d.ts.map +1 -1
- package/dist/cjs/components/selection/index.js +5 -6
- package/dist/cjs/components/selection/types.d.ts +13 -8
- package/dist/cjs/components/selection/types.d.ts.map +1 -1
- package/dist/cjs/components/sheet-background/index.d.ts +26 -0
- package/dist/cjs/components/sheet-background/index.d.ts.map +1 -0
- package/dist/cjs/components/sheet-background/index.js +106 -0
- package/dist/cjs/components/sort-range-dialog/index.d.ts.map +1 -1
- package/dist/cjs/components/sort-range-dialog/index.js +6 -3
- package/dist/cjs/hooks/object-clipboard-payload.d.ts +58 -0
- package/dist/cjs/hooks/object-clipboard-payload.d.ts.map +1 -0
- package/dist/cjs/hooks/object-clipboard-payload.js +488 -0
- package/dist/cjs/hooks/object-spec-schema.generated.d.ts +24 -0
- package/dist/cjs/hooks/object-spec-schema.generated.d.ts.map +1 -0
- package/dist/cjs/hooks/object-spec-schema.generated.js +4779 -0
- package/dist/cjs/hooks/use-chart-clipboard.d.ts +55 -9
- package/dist/cjs/hooks/use-chart-clipboard.d.ts.map +1 -1
- package/dist/cjs/hooks/use-chart-clipboard.js +307 -55
- package/dist/cjs/hooks/use-embeds-charts.d.ts +12 -1
- package/dist/cjs/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/cjs/hooks/use-embeds-charts.js +86 -17
- package/dist/cjs/hooks/use-grid-children.d.ts +4 -2
- package/dist/cjs/hooks/use-grid-children.d.ts.map +1 -1
- package/dist/cjs/hooks/use-grid-children.js +74 -16
- package/dist/cjs/hooks/use-selection-renderer.d.ts +16 -5
- package/dist/cjs/hooks/use-selection-renderer.d.ts.map +1 -1
- package/dist/cjs/hooks/use-selection-renderer.js +59 -32
- package/dist/cjs/hooks/use-shown-notes.d.ts +11 -1
- package/dist/cjs/hooks/use-shown-notes.d.ts.map +1 -1
- package/dist/cjs/hooks/use-shown-notes.js +34 -12
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/release-date.js +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +64 -0
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/api/split-pane.d.ts +1 -0
- package/dist/esm/api/split-pane.d.ts.map +1 -1
- package/dist/esm/api/split-pane.js +5 -1
- package/dist/esm/atoms/calculated-column-fill.atom.d.ts +6 -2
- package/dist/esm/atoms/calculated-column-fill.atom.d.ts.map +1 -1
- package/dist/esm/atoms/calculated-column-fill.atom.js +6 -2
- package/dist/esm/atoms/cell-input-context.atom.d.ts.map +1 -1
- package/dist/esm/atoms/fill-options.atom.d.ts +5 -0
- package/dist/esm/atoms/fill-options.atom.d.ts.map +1 -1
- package/dist/esm/atoms/table-auto-expansion.atom.d.ts +5 -2
- package/dist/esm/atoms/table-auto-expansion.atom.d.ts.map +1 -1
- package/dist/esm/atoms/table-auto-expansion.atom.js +5 -2
- package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts +37 -0
- package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts.map +1 -0
- package/dist/esm/components/autocorrect-options-smart-tag/index.js +87 -0
- package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/esm/components/canvas-grid/index.js +307 -59
- package/dist/esm/components/canvas-grid/typings.d.ts +45 -0
- package/dist/esm/components/canvas-grid/typings.d.ts.map +1 -1
- package/dist/esm/components/embeds/chart-component.d.ts +9 -0
- package/dist/esm/components/embeds/chart-component.d.ts.map +1 -1
- package/dist/esm/components/embeds/embed-component.d.ts +9 -0
- package/dist/esm/components/embeds/embed-component.d.ts.map +1 -1
- package/dist/esm/components/embeds/embed-component.js +12 -113
- package/dist/esm/components/embeds/embed-draggable.d.ts +17 -2
- package/dist/esm/components/embeds/embed-draggable.d.ts.map +1 -1
- package/dist/esm/components/embeds/embed-draggable.js +327 -19
- package/dist/esm/components/embeds/object-focus.d.ts +32 -0
- package/dist/esm/components/embeds/object-focus.d.ts.map +1 -0
- package/dist/esm/components/embeds/object-focus.js +118 -0
- package/dist/esm/components/embeds/page-gaps.d.ts +67 -0
- package/dist/esm/components/embeds/page-gaps.d.ts.map +1 -0
- package/dist/esm/components/embeds/page-gaps.js +86 -0
- package/dist/esm/components/embeds/pane-copy.d.ts +35 -0
- package/dist/esm/components/embeds/pane-copy.d.ts.map +1 -0
- package/dist/esm/components/embeds/pane-copy.js +22 -0
- package/dist/esm/components/embeds/slicer-component.d.ts +9 -0
- package/dist/esm/components/embeds/slicer-component.d.ts.map +1 -1
- package/dist/esm/components/embeds/text-box-view.d.ts +18 -0
- package/dist/esm/components/embeds/text-box-view.d.ts.map +1 -0
- package/dist/esm/components/embeds/text-box-view.js +118 -0
- package/dist/esm/components/filter-box/filter-by-color.d.ts.map +1 -1
- package/dist/esm/components/filter-box/filter-by-color.js +9 -2
- package/dist/esm/components/filter-box/index.d.ts.map +1 -1
- package/dist/esm/components/filter-box/index.js +5 -1
- package/dist/esm/components/print-preview/page-block.d.ts +46 -0
- package/dist/esm/components/print-preview/page-block.d.ts.map +1 -1
- package/dist/esm/components/print-preview/page-block.js +122 -4
- package/dist/esm/components/print-preview/print-cells.d.ts +5 -0
- package/dist/esm/components/print-preview/print-cells.d.ts.map +1 -1
- package/dist/esm/components/print-preview/print-cells.js +1 -0
- package/dist/esm/components/print-preview/print-preview-dialog.d.ts +16 -2
- package/dist/esm/components/print-preview/print-preview-dialog.d.ts.map +1 -1
- package/dist/esm/components/print-preview/print-preview-dialog.js +195 -4
- package/dist/esm/components/print-preview/settings.d.ts +8 -0
- package/dist/esm/components/print-preview/settings.d.ts.map +1 -1
- package/dist/esm/components/print-preview/settings.js +4 -1
- package/dist/esm/components/print-preview/sheet-page-setup.d.ts.map +1 -1
- package/dist/esm/components/print-preview/sheet-page-setup.js +14 -0
- package/dist/esm/components/selection/fill-options-menu.d.ts +8 -1
- package/dist/esm/components/selection/fill-options-menu.d.ts.map +1 -1
- package/dist/esm/components/selection/fill-options-menu.js +5 -3
- package/dist/esm/components/selection/index.d.ts +1 -1
- package/dist/esm/components/selection/index.d.ts.map +1 -1
- package/dist/esm/components/selection/index.js +5 -6
- package/dist/esm/components/selection/types.d.ts +13 -8
- package/dist/esm/components/selection/types.d.ts.map +1 -1
- package/dist/esm/components/sheet-background/index.d.ts +26 -0
- package/dist/esm/components/sheet-background/index.d.ts.map +1 -0
- package/dist/esm/components/sheet-background/index.js +93 -0
- package/dist/esm/components/sort-range-dialog/index.d.ts.map +1 -1
- package/dist/esm/components/sort-range-dialog/index.js +5 -2
- package/dist/esm/hooks/object-clipboard-payload.d.ts +58 -0
- package/dist/esm/hooks/object-clipboard-payload.d.ts.map +1 -0
- package/dist/esm/hooks/object-clipboard-payload.js +404 -0
- package/dist/esm/hooks/object-spec-schema.generated.d.ts +24 -0
- package/dist/esm/hooks/object-spec-schema.generated.d.ts.map +1 -0
- package/dist/esm/hooks/object-spec-schema.generated.js +4776 -0
- package/dist/esm/hooks/use-chart-clipboard.d.ts +55 -9
- package/dist/esm/hooks/use-chart-clipboard.d.ts.map +1 -1
- package/dist/esm/hooks/use-chart-clipboard.js +298 -53
- package/dist/esm/hooks/use-embeds-charts.d.ts +12 -1
- package/dist/esm/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/esm/hooks/use-embeds-charts.js +83 -16
- package/dist/esm/hooks/use-grid-children.d.ts +4 -2
- package/dist/esm/hooks/use-grid-children.d.ts.map +1 -1
- package/dist/esm/hooks/use-grid-children.js +59 -16
- package/dist/esm/hooks/use-selection-renderer.d.ts +16 -5
- package/dist/esm/hooks/use-selection-renderer.d.ts.map +1 -1
- package/dist/esm/hooks/use-selection-renderer.js +54 -28
- package/dist/esm/hooks/use-shown-notes.d.ts +11 -1
- package/dist/esm/hooks/use-shown-notes.d.ts.map +1 -1
- package/dist/esm/hooks/use-shown-notes.js +23 -12
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/release-date.js +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +64 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/spreadsheet.min.css +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type ScrollPosition = {
|
|
3
|
+
scrollLeft?: number;
|
|
4
|
+
scrollTop?: number;
|
|
5
|
+
};
|
|
6
|
+
export type SheetBackgroundHandle = {
|
|
7
|
+
/** Move the tiles with the grid's scroll (called from the grid's scroll handler). */
|
|
8
|
+
setScrollPosition: (position: ScrollPosition) => void;
|
|
9
|
+
};
|
|
10
|
+
export type SheetBackgroundProps = {
|
|
11
|
+
/** The picture, as a `data:` URL or an http(s) URL. Nothing is drawn without one. */
|
|
12
|
+
imageUrl?: string | null;
|
|
13
|
+
/** Width of the row-heading strip (0 when headings are hidden). */
|
|
14
|
+
headerWidth: number;
|
|
15
|
+
/** Height of the column-heading strip (0 when headings are hidden). */
|
|
16
|
+
headerHeight: number;
|
|
17
|
+
/** The sheet's zoom, so the tiles scale with the cells. */
|
|
18
|
+
scale?: number;
|
|
19
|
+
/** A right-to-left sheet keeps its headings on the right. */
|
|
20
|
+
rightToLeft?: boolean;
|
|
21
|
+
/** The grid's scroll position when the layer appears (a picture set on a scrolled sheet). */
|
|
22
|
+
getScrollPosition?: () => ScrollPosition;
|
|
23
|
+
};
|
|
24
|
+
export declare const SheetBackground: React.NamedExoticComponent<SheetBackgroundProps & React.RefAttributes<SheetBackgroundHandle>>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/sheet-background/index.tsx"],"names":[],"mappings":"AAiBA,OAAO,KASN,MAAM,OAAO,CAAC;AAEf,KAAK,cAAc,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,MAAM,MAAM,qBAAqB,GAAG;IAClC,qFAAqF;IACrF,iBAAiB,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6FAA6F;IAC7F,iBAAiB,CAAC,EAAE,MAAM,cAAc,CAAC;CAC1C,CAAC;AAsHF,eAAO,MAAM,eAAe,+FAA6B,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Page Layout ▸ Background — the picture Excel tiles behind a sheet's cells.
|
|
2
|
+
//
|
|
3
|
+
// It is a VIEW, not content: it repeats from the top-left of the grid, scrolls
|
|
4
|
+
// with the cells, never covers the row / column headings, and Excel never
|
|
5
|
+
// prints it (the print preview and the printed page ignore it entirely). Cell
|
|
6
|
+
// fills paint over it, so it only shows through cells that have no fill.
|
|
7
|
+
//
|
|
8
|
+
// Drawn as one DOM layer BEHIND the canvas (`z-index: -1`): the grid's Konva
|
|
9
|
+
// stage is transparent where no cell has a fill, and a negative z-index paints
|
|
10
|
+
// below in-flow content but above the wrapper's own background colour.
|
|
11
|
+
//
|
|
12
|
+
// Its grid moves it: `CanvasGrid` calls `setScrollPosition` from its own
|
|
13
|
+
// scroll handler, which writes `background-position` straight onto the layer's
|
|
14
|
+
// node — no React render per scroll frame, and no page-wide subject, so two
|
|
15
|
+
// grids on one page never move each other's picture. With no picture there is
|
|
16
|
+
// no node, and the call does nothing.
|
|
17
|
+
import React, { forwardRef, memo, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
18
|
+
const positionOf = ({ scrollLeft = 0, scrollTop = 0 }) => `${-scrollLeft}px ${-scrollTop}px`;
|
|
19
|
+
/**
|
|
20
|
+
* The picture's natural size in CSS pixels, read once per picture: a tile is
|
|
21
|
+
* that size times the zoom. Does nothing without a picture.
|
|
22
|
+
*/
|
|
23
|
+
const useNaturalSize = (imageUrl) => {
|
|
24
|
+
const [size, setSize] = useState(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!imageUrl || typeof Image === "undefined")
|
|
27
|
+
return;
|
|
28
|
+
const image = new Image();
|
|
29
|
+
image.onload = () => {
|
|
30
|
+
if (image.naturalWidth > 0 && image.naturalHeight > 0)
|
|
31
|
+
setSize({
|
|
32
|
+
url: imageUrl,
|
|
33
|
+
width: image.naturalWidth,
|
|
34
|
+
height: image.naturalHeight,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
image.src = imageUrl;
|
|
38
|
+
return () => {
|
|
39
|
+
image.onload = null;
|
|
40
|
+
};
|
|
41
|
+
}, [imageUrl]);
|
|
42
|
+
return size && size.url === imageUrl ? size : null;
|
|
43
|
+
};
|
|
44
|
+
const SheetBackgroundLayer = forwardRef(function SheetBackground({ imageUrl, headerWidth, headerHeight, scale = 1, rightToLeft = false, getScrollPosition, }, ref) {
|
|
45
|
+
const layerRef = useRef(null);
|
|
46
|
+
const naturalSize = useNaturalSize(imageUrl);
|
|
47
|
+
useImperativeHandle(ref, () => ({
|
|
48
|
+
setScrollPosition: (position) => {
|
|
49
|
+
const node = layerRef.current;
|
|
50
|
+
if (node)
|
|
51
|
+
node.style.backgroundPosition = positionOf(position);
|
|
52
|
+
},
|
|
53
|
+
}), []);
|
|
54
|
+
// `background-position` is never part of the React style below, so a
|
|
55
|
+
// re-render (zoom, headings) leaves the position the scroll handler wrote.
|
|
56
|
+
// A layer that appears takes the grid's current position.
|
|
57
|
+
// Only when the layer appears; later moves come through the handle.
|
|
58
|
+
const getScrollPositionRef = useRef(getScrollPosition);
|
|
59
|
+
getScrollPositionRef.current = getScrollPosition;
|
|
60
|
+
const hasPicture = Boolean(imageUrl);
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
const node = layerRef.current;
|
|
63
|
+
if (!hasPicture || !node)
|
|
64
|
+
return;
|
|
65
|
+
node.style.backgroundPosition = positionOf(getScrollPositionRef.current?.() ?? {});
|
|
66
|
+
}, [hasPicture]);
|
|
67
|
+
// The picture string is built once per picture; zoom and headings rebuild
|
|
68
|
+
// only the cheap fields.
|
|
69
|
+
const backgroundImage = useMemo(() => imageUrl ? `url("${imageUrl.replace(/["\\]/g, "\\$&")}")` : undefined, [imageUrl]);
|
|
70
|
+
const style = useMemo(() => backgroundImage
|
|
71
|
+
? {
|
|
72
|
+
position: "absolute",
|
|
73
|
+
top: headerHeight,
|
|
74
|
+
bottom: 0,
|
|
75
|
+
left: rightToLeft ? 0 : headerWidth,
|
|
76
|
+
right: rightToLeft ? headerWidth : 0,
|
|
77
|
+
zIndex: -1,
|
|
78
|
+
pointerEvents: "none",
|
|
79
|
+
backgroundImage,
|
|
80
|
+
backgroundRepeat: "repeat",
|
|
81
|
+
// A tile is the picture's own size times the zoom (a percentage
|
|
82
|
+
// would be measured against the layer and stretch one copy).
|
|
83
|
+
backgroundSize: naturalSize
|
|
84
|
+
? `${naturalSize.width * scale}px ${naturalSize.height * scale}px`
|
|
85
|
+
: "auto",
|
|
86
|
+
}
|
|
87
|
+
: null, [backgroundImage, headerHeight, headerWidth, rightToLeft, naturalSize, scale]);
|
|
88
|
+
if (!style)
|
|
89
|
+
return null;
|
|
90
|
+
return (React.createElement("div", { ref: layerRef, "data-testid": "sheet-background", "aria-hidden": true, style: style }));
|
|
91
|
+
});
|
|
92
|
+
export const SheetBackground = memo(SheetBackgroundLayer);
|
|
93
|
+
SheetBackground.displayName = "SheetBackground";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/sort-range-dialog/index.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAA0D,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/sort-range-dialog/index.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAA0D,MAAM,OAAO,CAAC;AAI/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,aAAa,CAAC;AAQxD;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,2BAA2B;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAClC,oCAAoC;IACpC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC;IAC3B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC1B,wCAAwC;IACxC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,qCAAqC;IACrC,kBAAkB,CAAC,EAAE,eAAe,CAAC;IACrC;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAAC;CACpE,CAAC;AAEF,2FAA2F;AAC3F,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,CAAC;AAEjD,8DAA8D;AAC9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,OAAO,CAAC;IACnB,oEAAoE;IACpE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,oEAAoE;IACpE,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B,CAAC;AAEF,yGAAyG;AACzG,eAAO,MAAM,eAAe,GAC1B,QAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,QAAQ,CAAC,EAClD,WAAW,OAAO,KACjB,MAGF,CAAC;AAyEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,kLAavB,eAAe,uBAmcnB,CAAC;AAIF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;CAoB/B,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ArrowDownIcon, ArrowUpIcon, Cross1Icon, PlusIcon, SortDownIcon, SortUpIcon, TrashIcon, } from "@rowsncolumns/icons";
|
|
2
2
|
import { Button, Dialog, DialogBody, DialogCloseButton, DialogContent, DialogTitle, IconButton, Select, SelectContent, SelectItem, SelectPortal, SelectTrigger, SelectValue, Separator, } from "@rowsncolumns/ui";
|
|
3
3
|
import React, { memo, useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { getCfIcon } from "../../api/cf-icons";
|
|
5
|
+
import { CfIconPreview } from "../cf-icon-preview";
|
|
4
6
|
import { useSortDialogState } from "../../atoms/sort-dialog.atom";
|
|
5
7
|
/** The label a sort level shows for a column: its header while the data has headers, else its letter. */
|
|
6
8
|
export const sortColumnLabel = (column, hasHeader) => {
|
|
@@ -9,7 +11,8 @@ export const sortColumnLabel = (column, hasHeader) => {
|
|
|
9
11
|
};
|
|
10
12
|
const CUSTOM_LIST_PREFIX = "custom:";
|
|
11
13
|
const ColorSwatch = ({ color }) => (React.createElement("span", { className: "inline-block h-3.5 w-3.5 rounded border border-gray-300 shrink-0", style: { backgroundColor: color } }));
|
|
12
|
-
|
|
14
|
+
/** A conditional-format icon, drawn by the grid's icon painter (no font glyph); the text stand-in only for an unknown set. */
|
|
15
|
+
const IconSwatch = ({ glyph, color, iconSet, iconId, }) => iconSet && typeof iconId === "number" && getCfIcon(iconSet, iconId) ? (React.createElement(CfIconPreview, { iconSet: iconSet, iconId: iconId, size: 14 })) : (React.createElement("span", { className: "inline-block h-3.5 w-3.5 leading-none text-center text-sm shrink-0", style: color ? { color } : undefined }, glyph));
|
|
13
16
|
const makeDefaultLevel = (columns) => ({
|
|
14
17
|
dimensionIndex: columns[0]?.dimensionIndex ?? 0,
|
|
15
18
|
sortBy: "value",
|
|
@@ -215,7 +218,7 @@ export const SortRangeDialog = memo(({ open, onOpenChange, columns, customLists,
|
|
|
215
218
|
React.createElement(SelectPortal, null,
|
|
216
219
|
React.createElement(SelectContent, null, icons.map((icon) => (React.createElement(SelectItem, { key: `${icon.iconSet}:${icon.iconId}`, value: `${icon.iconSet}:${icon.iconId}` },
|
|
217
220
|
React.createElement("span", { className: "flex items-center gap-2" },
|
|
218
|
-
React.createElement(IconSwatch, { glyph: icon.glyph, color: icon.color }),
|
|
221
|
+
React.createElement(IconSwatch, { glyph: icon.glyph, color: icon.color, iconSet: icon.iconSet, iconId: icon.iconId }),
|
|
219
222
|
`${icon.iconSet} ${icon.iconId}`)))))))) : (React.createElement("div", { className: "flex gap-1" },
|
|
220
223
|
React.createElement(IconButton, { tooltip: "Sort A \u2192 Z", isActive: lvl.sortOrder === "ASCENDING", onClick: () => updateLevel(rowIndex, { sortOrder: "ASCENDING" }) },
|
|
221
224
|
React.createElement(SortDownIcon, null)),
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { EmbeddedChart, EmbeddedObject } from "../types";
|
|
2
|
+
/** What a URL in a pasted object is for. */
|
|
3
|
+
export type ObjectClipboardUrlUse = "image" | "link";
|
|
4
|
+
export type ObjectClipboardPolicy = {
|
|
5
|
+
/**
|
|
6
|
+
* Whether an `https:` URL in a pasted object (a picture's `imageUrl`, a link) may be kept.
|
|
7
|
+
* Without it every `https:` URL is refused. `data:image/…` pictures and `blob:` URLs of this
|
|
8
|
+
* page's origin are always kept; any other scheme never is.
|
|
9
|
+
*/
|
|
10
|
+
isUrlAllowed?: (url: string, use: ObjectClipboardUrlUse) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* A pasted object of a kind the engine does not know (a host-defined embed such as `asset`):
|
|
13
|
+
* return the object to create, or `undefined` to refuse it. Without it every such object is
|
|
14
|
+
* refused. Called with the payload's own `spec` (untrusted, plain data) and a checked position.
|
|
15
|
+
*/
|
|
16
|
+
acceptHostEmbed?: (embed: EmbeddedObject) => EmbeddedObject | undefined;
|
|
17
|
+
/** This page's origin (`window.location.origin`): the only `blob:` URLs kept are its own. */
|
|
18
|
+
origin?: string;
|
|
19
|
+
};
|
|
20
|
+
/** A clipboard payload longer than this is not read (a data-URL picture of about 12 MB). */
|
|
21
|
+
export declare const MAX_OBJECT_PAYLOAD_LENGTH: number;
|
|
22
|
+
/** The largest width or height a pasted object keeps, in pixels. */
|
|
23
|
+
export declare const MAX_OBJECT_PIXELS = 20000;
|
|
24
|
+
/** The largest offset into an anchor cell a pasted object keeps, in pixels. */
|
|
25
|
+
export declare const MAX_ANCHOR_OFFSET_PIXELS = 4096;
|
|
26
|
+
/** A colour string in a form the engine writes: hex, `rgb()` or `rgba()`. Nothing else. */
|
|
27
|
+
export declare const isColourString: (value: unknown) => value is string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether a pasted object may keep `url`: a `data:image/…` picture, a `blob:` URL of this page's
|
|
30
|
+
* origin, or an `https:` URL the host allows. Never `javascript:`, `http:` or any other scheme.
|
|
31
|
+
*/
|
|
32
|
+
export declare const isPastedUrlAllowed: (url: string, use: ObjectClipboardUrlUse, policy: ObjectClipboardPolicy) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Parts a payload from elsewhere never brings, though the model has them:
|
|
35
|
+
* - `ChartXmlElement`: DrawingML the exporters write into the file verbatim
|
|
36
|
+
* (`pivotFormats[].body`); from another page it could be anything.
|
|
37
|
+
*/
|
|
38
|
+
export declare const OBJECT_TYPES_NOT_PASTED: Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* What a paste deliberately leaves out of an object copied elsewhere, with why. The drift and
|
|
41
|
+
* round-trip specs read this list: anything else the importer writes must survive a paste.
|
|
42
|
+
*/
|
|
43
|
+
export declare const OBJECT_FIELDS_NOT_PASTED: Record<string, string>;
|
|
44
|
+
/**
|
|
45
|
+
* A picture, shape, text box or form control from another tab's copy, rebuilt against its spec
|
|
46
|
+
* type's schema, or a host-defined kind the host accepts; `undefined` when nothing may be pasted.
|
|
47
|
+
* The id is a placeholder the paste replaces.
|
|
48
|
+
*/
|
|
49
|
+
export declare const parseEmbedPayload: (serialized: string | undefined, policy: ObjectClipboardPolicy) => EmbeddedObject | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* A chart from another tab's copy, rebuilt against `ChartSpec`'s schema all the way down: no
|
|
52
|
+
* verbatim DrawingML, ranges pinned to a sheet and dropped when this workbook has no such sheet
|
|
53
|
+
* (`sheetExists`); the position bounded and the id a placeholder the paste replaces.
|
|
54
|
+
*/
|
|
55
|
+
export declare const parseChartPayload: (serialized: string | undefined, options?: {
|
|
56
|
+
sheetExists?: (sheetId: number) => boolean;
|
|
57
|
+
}) => EmbeddedChart | undefined;
|
|
58
|
+
//# sourceMappingURL=object-clipboard-payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-clipboard-payload.d.ts","sourceRoot":"","sources":["../../../hooks/object-clipboard-payload.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,aAAa,EACb,cAAc,EAGf,MAAM,UAAU,CAAC;AAMlB,4CAA4C;AAC5C,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,qBAAqB,KAAK,OAAO,CAAC;IACpE;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,cAAc,GAAG,SAAS,CAAC;IACxE,6FAA6F;IAC7F,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,4FAA4F;AAC5F,eAAO,MAAM,yBAAyB,QAAmB,CAAC;AAC1D,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AACvC,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAgD7C,2FAA2F;AAC3F,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACoC,CAAC;AAI9F;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,KAAK,MAAM,EACX,KAAK,qBAAqB,EAC1B,QAAQ,qBAAqB,YAe9B,CAAC;AAyBF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAE1D,CAAC;AAgOF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAS3D,CAAC;AAmBF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,YAAY,MAAM,GAAG,SAAS,EAC9B,QAAQ,qBAAqB,KAC5B,cAAc,GAAG,SA0BnB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,YAAY,MAAM,GAAG,SAAS,EAC9B,UAAS;IAAE,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAA;CAAO,KAC3D,aAAa,GAAG,SAmBlB,CAAC"}
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// What a paste may build from an object copied in another tab (the `application/x-rowsncolumns-*`
|
|
2
|
+
// clipboard types). Any page can write those types in its own copy event, so the payload is
|
|
3
|
+
// untrusted input. It is rebuilt against the schema generated from the model's own types
|
|
4
|
+
// (`object-spec-schema.generated.ts`): known kinds, known keys at every depth with their types
|
|
5
|
+
// checked, colours only as hex / `rgb()` / `rgba()` / theme colours, URLs only of the kinds this
|
|
6
|
+
// page trusts, sizes bounded. Anything else is dropped, and a payload that fails is not pasted.
|
|
7
|
+
import { OBJECT_SPEC_SCHEMA, } from "./object-spec-schema.generated";
|
|
8
|
+
/** A clipboard payload longer than this is not read (a data-URL picture of about 12 MB). */
|
|
9
|
+
export const MAX_OBJECT_PAYLOAD_LENGTH = 16 * 1024 * 1024;
|
|
10
|
+
/** The largest width or height a pasted object keeps, in pixels. */
|
|
11
|
+
export const MAX_OBJECT_PIXELS = 20000;
|
|
12
|
+
/** The largest offset into an anchor cell a pasted object keeps, in pixels. */
|
|
13
|
+
export const MAX_ANCHOR_OFFSET_PIXELS = 4096;
|
|
14
|
+
const MAX_ROW_INDEX = 1048576;
|
|
15
|
+
const MAX_COLUMN_INDEX = 16384;
|
|
16
|
+
const MAX_TEXT = 32767;
|
|
17
|
+
const MAX_LIST = 10000;
|
|
18
|
+
const MAX_KEYS = 512;
|
|
19
|
+
const MAX_DEPTH = 24;
|
|
20
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
+
/** Keys a rebuilt object never takes: they would reach its prototype, not its data. */
|
|
22
|
+
const UNSAFE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
23
|
+
/** A record's own entries, without the unsafe keys, at most `max` of them. */
|
|
24
|
+
const safeEntries = (value, max) => Object.keys(value)
|
|
25
|
+
.filter((key) => !UNSAFE_KEYS.has(key))
|
|
26
|
+
.slice(0, max)
|
|
27
|
+
.map((key) => [key, value[key]]);
|
|
28
|
+
const str = (value, max = MAX_TEXT) => typeof value === "string" && value.length <= max ? value : undefined;
|
|
29
|
+
const num = (value, min, max) => typeof value === "number" && Number.isFinite(value)
|
|
30
|
+
? Math.min(max, Math.max(min, value))
|
|
31
|
+
: undefined;
|
|
32
|
+
const int = (value, min, max) => {
|
|
33
|
+
const n = num(value, min, max);
|
|
34
|
+
return n === undefined ? undefined : Math.round(n);
|
|
35
|
+
};
|
|
36
|
+
/** Drops the keys whose value is `undefined`. */
|
|
37
|
+
const compact = (record) => {
|
|
38
|
+
for (const key of Object.keys(record)) {
|
|
39
|
+
if (record[key] === undefined)
|
|
40
|
+
delete record[key];
|
|
41
|
+
}
|
|
42
|
+
return record;
|
|
43
|
+
};
|
|
44
|
+
const HEX_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
45
|
+
const CHANNEL = String.raw `\s*\d{1,3}(?:\.\d+)?%?\s*`;
|
|
46
|
+
const ALPHA = String.raw `\s*(?:0|1|0?\.\d+|\d{1,3}%)\s*`;
|
|
47
|
+
const RGB_COLOR = new RegExp(`^rgba?\\(${CHANNEL},${CHANNEL},${CHANNEL}(?:,${ALPHA})?\\)$`, "i");
|
|
48
|
+
/** A colour string in a form the engine writes: hex, `rgb()` or `rgba()`. Nothing else. */
|
|
49
|
+
export const isColourString = (value) => typeof value === "string" && (HEX_COLOR.test(value.trim()) || RGB_COLOR.test(value.trim()));
|
|
50
|
+
const DATA_IMAGE = /^data:image\/[a-z0-9.+-]+(?:;[a-z0-9=.+-]+)*,/i;
|
|
51
|
+
/**
|
|
52
|
+
* Whether a pasted object may keep `url`: a `data:image/…` picture, a `blob:` URL of this page's
|
|
53
|
+
* origin, or an `https:` URL the host allows. Never `javascript:`, `http:` or any other scheme.
|
|
54
|
+
*/
|
|
55
|
+
export const isPastedUrlAllowed = (url, use, policy) => {
|
|
56
|
+
const trimmed = url.trim();
|
|
57
|
+
if (use === "image" && DATA_IMAGE.test(trimmed))
|
|
58
|
+
return true;
|
|
59
|
+
if (/^blob:/i.test(trimmed)) {
|
|
60
|
+
return Boolean(policy.origin) && trimmed.startsWith(`blob:${policy.origin}/`);
|
|
61
|
+
}
|
|
62
|
+
if (!/^https:\/\//i.test(trimmed))
|
|
63
|
+
return false;
|
|
64
|
+
try {
|
|
65
|
+
// A URL the platform cannot read is not kept.
|
|
66
|
+
new URL(trimmed);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return policy.isUrlAllowed?.(trimmed, use) ?? false;
|
|
72
|
+
};
|
|
73
|
+
/** JSON data only, bounded in depth and size, without the unsafe keys. */
|
|
74
|
+
const jsonValue = (value, depth) => {
|
|
75
|
+
if (depth > MAX_DEPTH)
|
|
76
|
+
return undefined;
|
|
77
|
+
if (value === null || typeof value === "boolean")
|
|
78
|
+
return value;
|
|
79
|
+
if (typeof value === "number")
|
|
80
|
+
return Number.isFinite(value) ? value : undefined;
|
|
81
|
+
if (typeof value === "string")
|
|
82
|
+
return value.length <= MAX_TEXT ? value : undefined;
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
return value
|
|
85
|
+
.slice(0, MAX_LIST)
|
|
86
|
+
.map((item) => jsonValue(item, depth + 1))
|
|
87
|
+
.filter((item) => item !== undefined);
|
|
88
|
+
}
|
|
89
|
+
if (isRecord(value)) {
|
|
90
|
+
const next = {};
|
|
91
|
+
for (const [key, item] of safeEntries(value, MAX_KEYS)) {
|
|
92
|
+
const kept = jsonValue(item, depth + 1);
|
|
93
|
+
if (kept !== undefined)
|
|
94
|
+
next[key] = kept;
|
|
95
|
+
}
|
|
96
|
+
return next;
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Parts a payload from elsewhere never brings, though the model has them:
|
|
102
|
+
* - `ChartXmlElement`: DrawingML the exporters write into the file verbatim
|
|
103
|
+
* (`pivotFormats[].body`); from another page it could be anything.
|
|
104
|
+
*/
|
|
105
|
+
export const OBJECT_TYPES_NOT_PASTED = {
|
|
106
|
+
ChartXmlElement: "verbatim chart XML the exporters write into the file as given",
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Keys that must be present for an object to mean anything; without them the object is
|
|
110
|
+
* dropped (a list drops the entry): a range without its corners, a picture without its image,
|
|
111
|
+
* a pivot format without its index.
|
|
112
|
+
*/
|
|
113
|
+
const REQUIRED_KEYS = {
|
|
114
|
+
SheetRange: ["startRowIndex", "endRowIndex", "startColumnIndex", "endColumnIndex"],
|
|
115
|
+
CellInterface: ["rowIndex", "columnIndex"],
|
|
116
|
+
EmbedImageSpec: ["imageUrl"],
|
|
117
|
+
ShapeGeometry: ["preset"],
|
|
118
|
+
EmbedShapeSpec: ["geometry"],
|
|
119
|
+
PivotChartFormat: ["index"],
|
|
120
|
+
EmbedFormControlSpec: ["objectType"],
|
|
121
|
+
Border: ["style", "width"],
|
|
122
|
+
ColorTheme: ["theme"],
|
|
123
|
+
TextBoxRichTextRun: ["text"],
|
|
124
|
+
};
|
|
125
|
+
/** Numbers the renderers read as fractions or bounded sizes, clamped to their range. */
|
|
126
|
+
const NUMBER_RANGES = {
|
|
127
|
+
"EmbedImageSpec.brightness": [-1, 1],
|
|
128
|
+
"EmbedImageSpec.contrast": [-1, 1],
|
|
129
|
+
"EmbedImageSpec.transparency": [0, 1],
|
|
130
|
+
"ImageCrop.left": [0, 1],
|
|
131
|
+
"ImageCrop.top": [0, 1],
|
|
132
|
+
"ImageCrop.right": [0, 1],
|
|
133
|
+
"ImageCrop.bottom": [0, 1],
|
|
134
|
+
"TextFormat.fontSize": [1, 409],
|
|
135
|
+
"ChartTextFormat.fontSize": [1, 409],
|
|
136
|
+
"ShapeOutline.width": [0, 100],
|
|
137
|
+
"ShapeShadow.blurRadius": [0, 200],
|
|
138
|
+
"ShapeShadow.offsetXPixels": [-200, 200],
|
|
139
|
+
"ShapeShadow.offsetYPixels": [-200, 200],
|
|
140
|
+
"EmbedTextBoxSpec.padding": [0, 200],
|
|
141
|
+
"ShapeTextBody.padding": [0, 200],
|
|
142
|
+
};
|
|
143
|
+
const FORM_CONTROL_TYPES = new Set([
|
|
144
|
+
"Button",
|
|
145
|
+
"CheckBox",
|
|
146
|
+
"Drop",
|
|
147
|
+
"EditBox",
|
|
148
|
+
"GBox",
|
|
149
|
+
"Label",
|
|
150
|
+
"List",
|
|
151
|
+
"Radio",
|
|
152
|
+
"Scroll",
|
|
153
|
+
"Spin",
|
|
154
|
+
"Dialog",
|
|
155
|
+
]);
|
|
156
|
+
/** A form control's attributes that run a macro or read / write cells: never pasted from outside. */
|
|
157
|
+
const FORM_CONTROL_LINK_KEYS = /^(?:fmla\w*|macro|linkedCell|listFillRange)$/i;
|
|
158
|
+
/** The attribute bags of a form control (`properties`, `controlProperties`): plain names only. */
|
|
159
|
+
const ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9]{0,40}$/;
|
|
160
|
+
/** `value` read as `schema` describes it (field `owner.key`), or `undefined` when it is not that. */
|
|
161
|
+
const readValue = (value, schema, context, depth, field) => {
|
|
162
|
+
if (depth > MAX_DEPTH)
|
|
163
|
+
return undefined;
|
|
164
|
+
switch (schema.kind) {
|
|
165
|
+
case "string":
|
|
166
|
+
return str(value);
|
|
167
|
+
case "colour":
|
|
168
|
+
return isColourString(value) ? value.trim() : undefined;
|
|
169
|
+
case "url":
|
|
170
|
+
return typeof value === "string" &&
|
|
171
|
+
value.length <= MAX_OBJECT_PAYLOAD_LENGTH &&
|
|
172
|
+
isPastedUrlAllowed(value, schema.use, context.policy)
|
|
173
|
+
? value
|
|
174
|
+
: undefined;
|
|
175
|
+
case "number": {
|
|
176
|
+
const range = NUMBER_RANGES[field];
|
|
177
|
+
return range
|
|
178
|
+
? num(value, range[0], range[1])
|
|
179
|
+
: typeof value === "number" && Number.isFinite(value)
|
|
180
|
+
? value
|
|
181
|
+
: undefined;
|
|
182
|
+
}
|
|
183
|
+
case "boolean":
|
|
184
|
+
return typeof value === "boolean" ? value : undefined;
|
|
185
|
+
case "null":
|
|
186
|
+
return value === null ? null : undefined;
|
|
187
|
+
case "json":
|
|
188
|
+
return undefined;
|
|
189
|
+
case "enum":
|
|
190
|
+
return schema.values.includes(value) ? value : undefined;
|
|
191
|
+
case "array": {
|
|
192
|
+
if (schema.of.kind === "object" && schema.of.ref in OBJECT_TYPES_NOT_PASTED)
|
|
193
|
+
return undefined;
|
|
194
|
+
if (!Array.isArray(value))
|
|
195
|
+
return undefined;
|
|
196
|
+
const items = [];
|
|
197
|
+
for (const item of value.slice(0, MAX_LIST)) {
|
|
198
|
+
const read = readValue(item, schema.of, context, depth + 1, field);
|
|
199
|
+
// An entry stripped of everything it had is left out, not kept as `{}`.
|
|
200
|
+
if (read === undefined ||
|
|
201
|
+
(isRecord(read) && !Object.keys(read).length && isRecord(item) && Object.keys(item).length)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
items.push(read);
|
|
205
|
+
}
|
|
206
|
+
// A list whose every entry was stripped is left out too.
|
|
207
|
+
return value.length && !items.length ? undefined : items;
|
|
208
|
+
}
|
|
209
|
+
case "object":
|
|
210
|
+
return readObject(value, schema.ref, context, depth);
|
|
211
|
+
case "union": {
|
|
212
|
+
// Of several object kinds, the one that keeps the most of the value.
|
|
213
|
+
let best;
|
|
214
|
+
let bestKeys = -1;
|
|
215
|
+
for (const option of schema.of) {
|
|
216
|
+
const read = readValue(value, option, context, depth, field);
|
|
217
|
+
if (read === undefined)
|
|
218
|
+
continue;
|
|
219
|
+
if (option.kind !== "object")
|
|
220
|
+
return read;
|
|
221
|
+
const keys = Object.keys(read).length;
|
|
222
|
+
if (keys > bestKeys) {
|
|
223
|
+
best = read;
|
|
224
|
+
bestKeys = keys;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return best;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const isRange = (value) => typeof value.startRowIndex === "number" && typeof value.startColumnIndex === "number";
|
|
232
|
+
const readObject = (value, ref, context, depth) => {
|
|
233
|
+
const shape = OBJECT_SPEC_SCHEMA[ref];
|
|
234
|
+
if (!shape || ref in OBJECT_TYPES_NOT_PASTED || !isRecord(value))
|
|
235
|
+
return undefined;
|
|
236
|
+
const next = {};
|
|
237
|
+
for (const [key, item] of safeEntries(value, MAX_KEYS)) {
|
|
238
|
+
const schema = shape.keys[key] ?? shape.record;
|
|
239
|
+
if (!schema)
|
|
240
|
+
continue;
|
|
241
|
+
const kept = readValue(item, schema, context, depth + 1, `${ref}.${key}`);
|
|
242
|
+
if (kept !== undefined)
|
|
243
|
+
next[key] = kept;
|
|
244
|
+
}
|
|
245
|
+
if (REQUIRED_KEYS[ref]?.some((key) => next[key] === undefined))
|
|
246
|
+
return undefined;
|
|
247
|
+
if (ref === "SheetRange" && isRange(next)) {
|
|
248
|
+
// A range reads the sheet it names, or the chart's own sheet; one naming a sheet this
|
|
249
|
+
// workbook does not have is dropped.
|
|
250
|
+
const sheetId = typeof next.sheetId === "number" ? next.sheetId : context.sourceSheetId;
|
|
251
|
+
if (context.sheetExists && !context.sheetExists(sheetId))
|
|
252
|
+
return undefined;
|
|
253
|
+
next.sheetId = sheetId;
|
|
254
|
+
}
|
|
255
|
+
if (ref === "ShapeGeometry" && !/^[A-Za-z0-9]{1,64}$/.test(String(next.preset)))
|
|
256
|
+
return undefined;
|
|
257
|
+
if (ref === "EmbedFormControlSpec") {
|
|
258
|
+
if (!FORM_CONTROL_TYPES.has(String(next.objectType)))
|
|
259
|
+
return undefined;
|
|
260
|
+
// A pasted control is a new control: no shape id of its own (the exporters give it one),
|
|
261
|
+
// nothing that runs a macro or links it to cells.
|
|
262
|
+
delete next.shapeId;
|
|
263
|
+
for (const bag of ["properties", "controlProperties"]) {
|
|
264
|
+
const attributes = next[bag];
|
|
265
|
+
if (!isRecord(attributes))
|
|
266
|
+
continue;
|
|
267
|
+
for (const name of Object.keys(attributes)) {
|
|
268
|
+
if (!ATTRIBUTE_NAME.test(name) || FORM_CONTROL_LINK_KEYS.test(name))
|
|
269
|
+
delete attributes[name];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!isRecord(next.properties))
|
|
273
|
+
next.properties = {};
|
|
274
|
+
}
|
|
275
|
+
return next;
|
|
276
|
+
};
|
|
277
|
+
/** A pasted object's position, every number bounded; `undefined` without an anchor cell. */
|
|
278
|
+
const position = (value) => {
|
|
279
|
+
if (!isRecord(value) || !isRecord(value.overlayPosition))
|
|
280
|
+
return undefined;
|
|
281
|
+
const overlay = value.overlayPosition;
|
|
282
|
+
const cell = (raw) => {
|
|
283
|
+
if (!isRecord(raw))
|
|
284
|
+
return undefined;
|
|
285
|
+
const rowIndex = int(raw.rowIndex, 1, MAX_ROW_INDEX);
|
|
286
|
+
const columnIndex = int(raw.columnIndex, 1, MAX_COLUMN_INDEX);
|
|
287
|
+
return rowIndex === undefined || columnIndex === undefined ? undefined : { rowIndex, columnIndex };
|
|
288
|
+
};
|
|
289
|
+
const anchorCell = cell(overlay.anchorCell);
|
|
290
|
+
const sheetId = int(value.sheetId, -1e9, 1e9);
|
|
291
|
+
if (!anchorCell || sheetId === undefined)
|
|
292
|
+
return undefined;
|
|
293
|
+
const toCell = cell(overlay.toCell);
|
|
294
|
+
const placement = overlay.placement;
|
|
295
|
+
const overlayPosition = compact({
|
|
296
|
+
anchorCell,
|
|
297
|
+
widthPixels: num(overlay.widthPixels, 1, MAX_OBJECT_PIXELS),
|
|
298
|
+
heightPixels: num(overlay.heightPixels, 1, MAX_OBJECT_PIXELS),
|
|
299
|
+
offsetXPixels: num(overlay.offsetXPixels, 0, MAX_ANCHOR_OFFSET_PIXELS),
|
|
300
|
+
offsetYPixels: num(overlay.offsetYPixels, 0, MAX_ANCHOR_OFFSET_PIXELS),
|
|
301
|
+
placement: placement === "moveAndSize" || placement === "moveOnly" || placement === "absolute"
|
|
302
|
+
? placement
|
|
303
|
+
: undefined,
|
|
304
|
+
toCell,
|
|
305
|
+
toOffsetXPixels: toCell ? num(overlay.toOffsetXPixels, 0, MAX_ANCHOR_OFFSET_PIXELS) : undefined,
|
|
306
|
+
toOffsetYPixels: toCell ? num(overlay.toOffsetYPixels, 0, MAX_ANCHOR_OFFSET_PIXELS) : undefined,
|
|
307
|
+
});
|
|
308
|
+
// `zOrder` is not read: a paste goes on top of the sheet's objects.
|
|
309
|
+
return { sheetId, overlayPosition };
|
|
310
|
+
};
|
|
311
|
+
/** The fields every floating object shares (`EmbeddedObjectProperty`, its outline colour). */
|
|
312
|
+
const objectFields = (value) => ({
|
|
313
|
+
borderColor: isColourString(value.borderColor) ? value.borderColor.trim() : undefined,
|
|
314
|
+
resizable: typeof value.resizable === "boolean" ? value.resizable : undefined,
|
|
315
|
+
draggable: typeof value.draggable === "boolean" ? value.draggable : undefined,
|
|
316
|
+
rotatable: typeof value.rotatable === "boolean" ? value.rotatable : undefined,
|
|
317
|
+
});
|
|
318
|
+
/**
|
|
319
|
+
* What a paste deliberately leaves out of an object copied elsewhere, with why. The drift and
|
|
320
|
+
* round-trip specs read this list: anything else the importer writes must survive a paste.
|
|
321
|
+
*/
|
|
322
|
+
export const OBJECT_FIELDS_NOT_PASTED = {
|
|
323
|
+
"embedId / chartId": "a paste creates a new object with a new id",
|
|
324
|
+
"position.zOrder": "a paste goes on top of the sheet's objects",
|
|
325
|
+
hidden: "only a visible object can be selected and copied; the pasted one is visible",
|
|
326
|
+
"EmbedFormControlSpec.shapeId": "a pasted control is a new control; the exporters give it an id",
|
|
327
|
+
"EmbedFormControlSpec.properties.fmla* / controlProperties.macro, linkedCell, listFillRange": "a control from elsewhere never runs a macro or reads / writes this workbook's cells",
|
|
328
|
+
"PivotChartFormat.body": OBJECT_TYPES_NOT_PASTED.ChartXmlElement,
|
|
329
|
+
linkedPicture: "a linked picture reads a range by sheet id, which another workbook does not have",
|
|
330
|
+
};
|
|
331
|
+
const parseJson = (serialized) => {
|
|
332
|
+
if (!serialized || serialized.length > MAX_OBJECT_PAYLOAD_LENGTH)
|
|
333
|
+
return undefined;
|
|
334
|
+
try {
|
|
335
|
+
const parsed = JSON.parse(serialized);
|
|
336
|
+
return isRecord(parsed) ? parsed : undefined;
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const EMBED_SPEC_TYPES = {
|
|
343
|
+
image: "EmbedImageSpec",
|
|
344
|
+
textbox: "EmbedTextBoxSpec",
|
|
345
|
+
shape: "EmbedShapeSpec",
|
|
346
|
+
formControl: "EmbedFormControlSpec",
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* A picture, shape, text box or form control from another tab's copy, rebuilt against its spec
|
|
350
|
+
* type's schema, or a host-defined kind the host accepts; `undefined` when nothing may be pasted.
|
|
351
|
+
* The id is a placeholder the paste replaces.
|
|
352
|
+
*/
|
|
353
|
+
export const parseEmbedPayload = (serialized, policy) => {
|
|
354
|
+
const raw = parseJson(serialized);
|
|
355
|
+
if (!raw || !isRecord(raw.spec))
|
|
356
|
+
return undefined;
|
|
357
|
+
const at = position(raw.position);
|
|
358
|
+
if (!at)
|
|
359
|
+
return undefined;
|
|
360
|
+
const common = compact({
|
|
361
|
+
embedId: "",
|
|
362
|
+
position: at,
|
|
363
|
+
rotation: num(raw.rotation, -360, 360),
|
|
364
|
+
lockAspectRatio: typeof raw.lockAspectRatio === "boolean" ? raw.lockAspectRatio : undefined,
|
|
365
|
+
...objectFields(raw),
|
|
366
|
+
});
|
|
367
|
+
const spec = raw.spec;
|
|
368
|
+
const ref = typeof spec.type === "string" ? EMBED_SPEC_TYPES[spec.type] : undefined;
|
|
369
|
+
if (ref) {
|
|
370
|
+
const read = readObject(spec, ref, { policy, sourceSheetId: at.sheetId }, 0);
|
|
371
|
+
return read ? { ...common, spec: read } : undefined;
|
|
372
|
+
}
|
|
373
|
+
if (!policy.acceptHostEmbed || typeof spec.type !== "string" || spec.type === "linkedPicture") {
|
|
374
|
+
return undefined;
|
|
375
|
+
}
|
|
376
|
+
const accepted = policy.acceptHostEmbed({
|
|
377
|
+
...common,
|
|
378
|
+
spec: jsonValue(spec, 1),
|
|
379
|
+
});
|
|
380
|
+
return accepted ? { ...accepted, embedId: "", position: at } : undefined;
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* A chart from another tab's copy, rebuilt against `ChartSpec`'s schema all the way down: no
|
|
384
|
+
* verbatim DrawingML, ranges pinned to a sheet and dropped when this workbook has no such sheet
|
|
385
|
+
* (`sheetExists`); the position bounded and the id a placeholder the paste replaces.
|
|
386
|
+
*/
|
|
387
|
+
export const parseChartPayload = (serialized, options = {}) => {
|
|
388
|
+
const raw = parseJson(serialized);
|
|
389
|
+
if (!raw || !isRecord(raw.spec))
|
|
390
|
+
return undefined;
|
|
391
|
+
const at = position(raw.position);
|
|
392
|
+
if (!at)
|
|
393
|
+
return undefined;
|
|
394
|
+
const spec = readObject(raw.spec, "ChartSpec", { policy: {}, sourceSheetId: at.sheetId, sheetExists: options.sheetExists }, 0);
|
|
395
|
+
if (!spec)
|
|
396
|
+
return undefined;
|
|
397
|
+
return compact({
|
|
398
|
+
chartId: "",
|
|
399
|
+
position: at,
|
|
400
|
+
spec: spec,
|
|
401
|
+
description: str(raw.description),
|
|
402
|
+
...objectFields(raw),
|
|
403
|
+
});
|
|
404
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type SchemaValue = {
|
|
2
|
+
kind: "string" | "number" | "boolean" | "colour" | "null" | "json";
|
|
3
|
+
} | {
|
|
4
|
+
kind: "url";
|
|
5
|
+
use: "image" | "link";
|
|
6
|
+
} | {
|
|
7
|
+
kind: "enum";
|
|
8
|
+
values: Array<string | number>;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "array";
|
|
11
|
+
of: SchemaValue;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "object";
|
|
14
|
+
ref: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "union";
|
|
17
|
+
of: SchemaValue[];
|
|
18
|
+
};
|
|
19
|
+
export type SchemaObject = {
|
|
20
|
+
keys: Record<string, SchemaValue>;
|
|
21
|
+
record?: SchemaValue;
|
|
22
|
+
};
|
|
23
|
+
export declare const OBJECT_SPEC_SCHEMA: Record<string, SchemaObject>;
|
|
24
|
+
//# sourceMappingURL=object-spec-schema.generated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-spec-schema.generated.d.ts","sourceRoot":"","sources":["../../../hooks/object-spec-schema.generated.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,WAAW,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAqqJ3D,CAAC"}
|