mirror of
https://github.com/excalidraw/excalidraw.git
synced 2024-11-02 03:25:53 +01:00
feat: Calculate width/height
of canvas based on container dimensions (".excalidraw" selector) & remove props width & height (#3379)
* Remove width/height from the ".excalidraw" container so it will sized automatically. * updated all ref calculation to ".excalidraw" instead of parent since now ".excalidraw" will get resized * Remove props width/height as its not needed anymore. * Resize handler is also not needed anymore. * Position absolute canvas due to #3379 (comment) * move css to style and remove one extra rerendering * factor out mock logic for test * set height, width so as to avoid unnecessary updates of regression snap * better mock * better type checking and omit width,height from getDefaultAppState and also restore * revert * default to window dimensions in constructor * update docs * update * update * tweaks
This commit is contained in:
parent
3b976613ba
commit
c54a099010
@ -147,6 +147,9 @@
|
||||
color: var(--popup-text-color);
|
||||
font-size: 1.3em;
|
||||
}
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
@ -6,7 +6,10 @@ import { AppState, ExcalidrawProps } from "../types";
|
||||
export type ActionResult =
|
||||
| {
|
||||
elements?: readonly ExcalidrawElement[] | null;
|
||||
appState?: MarkOptional<AppState, "offsetTop" | "offsetLeft"> | null;
|
||||
appState?: MarkOptional<
|
||||
AppState,
|
||||
"offsetTop" | "offsetLeft" | "width" | "height"
|
||||
> | null;
|
||||
commitToHistory: boolean;
|
||||
syncHistory?: boolean;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import { getDateTime } from "./utils";
|
||||
|
||||
export const getDefaultAppState = (): Omit<
|
||||
AppState,
|
||||
"offsetTop" | "offsetLeft"
|
||||
"offsetTop" | "offsetLeft" | "width" | "height"
|
||||
> => {
|
||||
return {
|
||||
theme: "light",
|
||||
@ -43,7 +43,6 @@ export const getDefaultAppState = (): Omit<
|
||||
exportWithDarkMode: false,
|
||||
fileHandle: null,
|
||||
gridSize: null,
|
||||
height: window.innerHeight,
|
||||
isBindingEnabled: true,
|
||||
isLibraryOpen: false,
|
||||
isLoading: false,
|
||||
@ -70,7 +69,6 @@ export const getDefaultAppState = (): Omit<
|
||||
suggestedBindings: [],
|
||||
toastMessage: null,
|
||||
viewBackgroundColor: oc.white,
|
||||
width: window.innerWidth,
|
||||
zenModeEnabled: false,
|
||||
zoom: { value: 1 as NormalizedZoomValue, translation: { x: 0, y: 0 } },
|
||||
viewModeEnabled: false,
|
||||
|
@ -293,19 +293,12 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
actionManager: ActionManager;
|
||||
private excalidrawContainerRef = React.createRef<HTMLDivElement>();
|
||||
|
||||
public static defaultProps: Partial<ExcalidrawProps> = {
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
};
|
||||
private scene: Scene;
|
||||
private resizeObserver: ResizeObserver | undefined;
|
||||
constructor(props: ExcalidrawProps) {
|
||||
super(props);
|
||||
const defaultAppState = getDefaultAppState();
|
||||
|
||||
const {
|
||||
width = window.innerWidth,
|
||||
height = window.innerHeight,
|
||||
excalidrawRef,
|
||||
viewModeEnabled = false,
|
||||
zenModeEnabled = false,
|
||||
@ -317,13 +310,13 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
...defaultAppState,
|
||||
theme,
|
||||
isLoading: true,
|
||||
width,
|
||||
height,
|
||||
...this.getCanvasOffsets(),
|
||||
viewModeEnabled,
|
||||
zenModeEnabled,
|
||||
gridSize: gridModeEnabled ? GRID_SIZE : null,
|
||||
name,
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
};
|
||||
if (excalidrawRef) {
|
||||
const readyPromise =
|
||||
@ -447,10 +440,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
"excalidraw--view-mode": viewModeEnabled,
|
||||
})}
|
||||
ref={this.excalidrawContainerRef}
|
||||
style={{
|
||||
width: canvasDOMWidth,
|
||||
height: canvasDOMHeight,
|
||||
}}
|
||||
>
|
||||
<LayerUI
|
||||
canvas={this.canvas}
|
||||
@ -561,7 +550,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
if (typeof this.props.name !== "undefined") {
|
||||
name = this.props.name;
|
||||
}
|
||||
|
||||
this.setState(
|
||||
(state) => {
|
||||
// using Object.assign instead of spread to fool TS 4.2.2+ into
|
||||
@ -570,10 +558,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
return Object.assign(actionResult.appState || {}, {
|
||||
editingElement:
|
||||
editingElement || actionResult.appState?.editingElement || null,
|
||||
width: state.width,
|
||||
height: state.height,
|
||||
offsetTop: state.offsetTop,
|
||||
offsetLeft: state.offsetLeft,
|
||||
viewModeEnabled,
|
||||
zenModeEnabled,
|
||||
gridSize,
|
||||
@ -706,7 +690,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
if (!this.state.isLoading) {
|
||||
this.setState({ isLoading: true });
|
||||
}
|
||||
|
||||
let initialData = null;
|
||||
try {
|
||||
initialData = (await this.props.initialData) || null;
|
||||
@ -715,7 +698,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
}
|
||||
|
||||
const scene = restore(initialData, null);
|
||||
|
||||
scene.appState = {
|
||||
...scene.appState,
|
||||
isLoading: false,
|
||||
@ -787,14 +769,11 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
this.scene.addCallback(this.onSceneUpdated);
|
||||
this.addEventListeners();
|
||||
|
||||
if (
|
||||
"ResizeObserver" in window &&
|
||||
this.excalidrawContainerRef?.current?.parentElement
|
||||
) {
|
||||
this.resizeObserver = new ResizeObserver(() => this.setCanvasOffsets());
|
||||
this.resizeObserver?.observe(
|
||||
this.excalidrawContainerRef.current.parentElement,
|
||||
);
|
||||
if ("ResizeObserver" in window && this.excalidrawContainerRef?.current) {
|
||||
this.resizeObserver = new ResizeObserver(() => {
|
||||
this.updateDOMRect();
|
||||
});
|
||||
this.resizeObserver?.observe(this.excalidrawContainerRef.current);
|
||||
}
|
||||
const searchParams = new URLSearchParams(window.location.search.slice(1));
|
||||
|
||||
@ -802,9 +781,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
// Obtain a file that was shared via the Web Share Target API.
|
||||
this.restoreFileFromShare();
|
||||
} else {
|
||||
this.setState(this.getCanvasOffsets(), () => {
|
||||
this.initializeScene();
|
||||
});
|
||||
this.updateDOMRect(this.initializeScene);
|
||||
}
|
||||
}
|
||||
|
||||
@ -906,17 +883,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
this.updateLanguage();
|
||||
}
|
||||
|
||||
if (
|
||||
prevProps.width !== this.props.width ||
|
||||
prevProps.height !== this.props.height
|
||||
) {
|
||||
this.setState({
|
||||
width: this.props.width ?? window.innerWidth,
|
||||
height: this.props.height ?? window.innerHeight,
|
||||
...this.getCanvasOffsets(),
|
||||
});
|
||||
}
|
||||
|
||||
if (prevProps.viewModeEnabled !== this.props.viewModeEnabled) {
|
||||
this.setState(
|
||||
{ viewModeEnabled: !!this.props.viewModeEnabled },
|
||||
@ -4093,14 +4059,56 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
}
|
||||
}, 300);
|
||||
|
||||
private updateDOMRect = (cb?: () => void) => {
|
||||
if (this.excalidrawContainerRef?.current) {
|
||||
const excalidrawContainer = this.excalidrawContainerRef.current;
|
||||
const {
|
||||
width,
|
||||
height,
|
||||
left: offsetLeft,
|
||||
top: offsetTop,
|
||||
} = excalidrawContainer.getBoundingClientRect();
|
||||
const {
|
||||
width: currentWidth,
|
||||
height: currentHeight,
|
||||
offsetTop: currentOffsetTop,
|
||||
offsetLeft: currentOffsetLeft,
|
||||
} = this.state;
|
||||
|
||||
if (
|
||||
width === currentWidth &&
|
||||
height === currentHeight &&
|
||||
offsetLeft === currentOffsetLeft &&
|
||||
offsetTop === currentOffsetTop
|
||||
) {
|
||||
if (cb) {
|
||||
cb();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState(
|
||||
{
|
||||
width,
|
||||
height,
|
||||
offsetLeft,
|
||||
offsetTop,
|
||||
},
|
||||
() => {
|
||||
cb && cb();
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
public setCanvasOffsets = () => {
|
||||
this.setState({ ...this.getCanvasOffsets() });
|
||||
};
|
||||
|
||||
private getCanvasOffsets(): Pick<AppState, "offsetTop" | "offsetLeft"> {
|
||||
if (this.excalidrawContainerRef?.current?.parentElement) {
|
||||
const parentElement = this.excalidrawContainerRef.current.parentElement;
|
||||
const { left, top } = parentElement.getBoundingClientRect();
|
||||
if (this.excalidrawContainerRef?.current) {
|
||||
const excalidrawContainer = this.excalidrawContainerRef.current;
|
||||
const { left, top } = excalidrawContainer.getBoundingClientRect();
|
||||
return {
|
||||
offsetLeft: left,
|
||||
offsetTop: top,
|
||||
|
@ -16,6 +16,8 @@
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
// serves 2 purposes:
|
||||
// 1. prevent selecting text outside the component when double-clicking or
|
||||
@ -45,6 +47,10 @@
|
||||
image-rendering: -moz-crisp-edges; // FF
|
||||
|
||||
z-index: var(--zIndex-canvas);
|
||||
|
||||
// Remove canvas from document flow to avoid resizeObserver feedback loop
|
||||
// (see https://github.com/excalidraw/excalidraw/pull/3379)
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
&.theme--dark {
|
||||
|
@ -144,7 +144,7 @@ export const restoreElements = (
|
||||
export const restoreAppState = (
|
||||
appState: ImportedDataState["appState"],
|
||||
localAppState: Partial<AppState> | null,
|
||||
): AppState => {
|
||||
): DataState["appState"] => {
|
||||
appState = appState || {};
|
||||
|
||||
const defaultAppState = getDefaultAppState();
|
||||
@ -166,8 +166,6 @@ export const restoreAppState = (
|
||||
|
||||
return {
|
||||
...nextAppState,
|
||||
offsetLeft: appState.offsetLeft || 0,
|
||||
offsetTop: appState.offsetTop || 0,
|
||||
// Migrates from previous version where appState.zoom was a number
|
||||
zoom:
|
||||
typeof appState.zoom === "number"
|
||||
|
@ -6,7 +6,7 @@ export interface DataState {
|
||||
version?: string;
|
||||
source?: string;
|
||||
elements: readonly ExcalidrawElement[];
|
||||
appState: MarkOptional<AppState, "offsetTop" | "offsetLeft">;
|
||||
appState: Omit<AppState, "offsetTop" | "offsetLeft" | "width" | "height">;
|
||||
}
|
||||
|
||||
export interface ImportedDataState {
|
||||
|
@ -3,7 +3,6 @@ import React, {
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
@ -163,30 +162,10 @@ const initializeScene = async (opts: {
|
||||
};
|
||||
|
||||
const ExcalidrawWrapper = () => {
|
||||
// dimensions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const [dimensions, setDimensions] = useState({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
const currentLangCode = languageDetector.detect() || defaultLang.code;
|
||||
const [langCode, setLangCode] = useState(currentLangCode);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const onResize = () => {
|
||||
setDimensions({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("resize", onResize);
|
||||
|
||||
return () => window.removeEventListener("resize", onResize);
|
||||
}, []);
|
||||
|
||||
// initial state
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -337,8 +316,6 @@ const ExcalidrawWrapper = () => {
|
||||
<Excalidraw
|
||||
ref={excalidrawRefCallback}
|
||||
onChange={onChange}
|
||||
width={dimensions.width}
|
||||
height={dimensions.height}
|
||||
initialData={initialStatePromiseRef.current.promise}
|
||||
onCollabButtonClick={collabAPI?.onCollabButtonClick}
|
||||
isCollaborating={collabAPI?.isCollaborating()}
|
||||
|
@ -63,6 +63,8 @@ const canvas = exportToCanvas(
|
||||
...getDefaultAppState(),
|
||||
offsetTop: 0,
|
||||
offsetLeft: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
},
|
||||
{
|
||||
exportBackground: true,
|
||||
|
@ -18,6 +18,9 @@ Please add the latest change on the top under the correct section.
|
||||
|
||||
### Features
|
||||
|
||||
- Calculate `width/height` of canvas based on excalidraw component (".excalidraw" selector) & also resize and update offsets whenever the dimensions of excalidraw component gets updated [#3379](https://github.com/excalidraw/excalidraw/pull/3379). You also don't need to add a resize handler anymore for excalidraw as its handled now in excalidraw itself.
|
||||
#### BREAKING CHANGE
|
||||
- `width/height` props have been removed. Instead now it takes `100%` of `width` and `height` of the container so you need to make sure the container in which you are rendering Excalidraw has non zero dimensions (It should have non zero width and height so Excalidraw can match the dimensions of containing block)
|
||||
- Calculate offsets when excalidraw container resizes using resize observer api [#3374](https://github.com/excalidraw/excalidraw/pull/3374).
|
||||
- Export types for the package so now it can be used with typescript [#3337](https://github.com/excalidraw/excalidraw/pull/3337). The types are available at `@excalidraw/excalirdraw/types`.
|
||||
- Add `renderCustomStats` prop to render extra stats on host, and expose `setToastMessage` API via refs which can be used to show toast with custom message [#3360](https://github.com/excalidraw/excalidraw/pull/3360).
|
||||
|
@ -45,32 +45,11 @@ import "./styles.scss";
|
||||
|
||||
export default function App() {
|
||||
const excalidrawRef = useRef(null);
|
||||
const excalidrawWrapperRef = useRef(null);
|
||||
const [dimensions, setDimensions] = useState({
|
||||
width: undefined,
|
||||
height: undefined,
|
||||
});
|
||||
|
||||
const [viewModeEnabled, setViewModeEnabled] = useState(false);
|
||||
const [zenModeEnabled, setZenModeEnabled] = useState(false);
|
||||
const [gridModeEnabled, setGridModeEnabled] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setDimensions({
|
||||
width: excalidrawWrapperRef.current.getBoundingClientRect().width,
|
||||
height: excalidrawWrapperRef.current.getBoundingClientRect().height,
|
||||
});
|
||||
const onResize = () => {
|
||||
setDimensions({
|
||||
width: excalidrawWrapperRef.current.getBoundingClientRect().width,
|
||||
height: excalidrawWrapperRef.current.getBoundingClientRect().height,
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("resize", onResize);
|
||||
|
||||
return () => window.removeEventListener("resize", onResize);
|
||||
}, [excalidrawWrapperRef]);
|
||||
|
||||
const updateScene = () => {
|
||||
const sceneData = {
|
||||
@ -144,13 +123,11 @@ export default function App() {
|
||||
Grid mode
|
||||
</label>
|
||||
</div>
|
||||
<div className="excalidraw-wrapper" ref={excalidrawWrapperRef}>
|
||||
<div className="excalidraw-wrapper">
|
||||
<Excalidraw
|
||||
ref={excalidrawRef}
|
||||
width={dimensions.width}
|
||||
height={dimensions.height}
|
||||
initialData={InitialData}
|
||||
onChange={(elements, state) =>
|
||||
onChange={(elements, state) => {
|
||||
console.log("Elements :", elements, "State : ", state)
|
||||
}
|
||||
onPointerUpdate={(payload) => console.log(payload)}
|
||||
@ -246,33 +223,11 @@ import InitialData from "./initialData";
|
||||
|
||||
const App = () => {
|
||||
const excalidrawRef = React.useRef(null);
|
||||
const excalidrawWrapperRef = React.useRef(null);
|
||||
const [dimensions, setDimensions] = React.useState({
|
||||
width: undefined,
|
||||
height: undefined,
|
||||
});
|
||||
|
||||
const [viewModeEnabled, setViewModeEnabled] = React.useState(false);
|
||||
const [zenModeEnabled, setZenModeEnabled] = React.useState(false);
|
||||
const [gridModeEnabled, setGridModeEnabled] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
setDimensions({
|
||||
width: excalidrawWrapperRef.current.getBoundingClientRect().width,
|
||||
height: excalidrawWrapperRef.current.getBoundingClientRect().height,
|
||||
});
|
||||
const onResize = () => {
|
||||
setDimensions({
|
||||
width: excalidrawWrapperRef.current.getBoundingClientRect().width,
|
||||
height: excalidrawWrapperRef.current.getBoundingClientRect().height,
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("resize", onResize);
|
||||
|
||||
return () => window.removeEventListener("resize", onResize);
|
||||
}, [excalidrawWrapperRef]);
|
||||
|
||||
const updateScene = () => {
|
||||
const sceneData = {
|
||||
elements: [
|
||||
@ -365,9 +320,6 @@ const App = () => {
|
||||
ref: excalidrawWrapperRef,
|
||||
},
|
||||
React.createElement(Excalidraw.default, {
|
||||
ref: excalidrawRef,
|
||||
width: dimensions.width,
|
||||
height: dimensions.height,
|
||||
initialData: InitialData,
|
||||
onChange: (elements, state) =>
|
||||
console.log("Elements :", elements, "State : ", state),
|
||||
@ -396,8 +348,6 @@ To view the full example visit :point_down:
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [`width`](#width) | Number | `window.innerWidth` | The width of Excalidraw component |
|
||||
| [`height`](#height) | Number | `window.innerHeight` | The height of Excalidraw component |
|
||||
| [`onChange`](#onChange) | Function | | This callback is triggered whenever the component updates due to any change. This callback will receive the excalidraw elements and the current app state. |
|
||||
| [`initialData`](#initialData) | <pre>{elements?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L78">ExcalidrawElement[]</a>, appState?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L37">AppState<a> } </pre> | null | The initial data with which app loads. |
|
||||
| [`ref`](#ref) | [`createRef`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) or [`callbackRef`](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) or <pre>{ current: { readyPromise: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L317">resolvablePromise</a> } }</pre> | | Ref to be passed to Excalidraw |
|
||||
@ -415,13 +365,9 @@ To view the full example visit :point_down:
|
||||
| [`theme`](#theme) | `light` or `dark` | | The theme of the Excalidraw component |
|
||||
| [`name`](#name) | string | | Name of the drawing |
|
||||
|
||||
#### `width`
|
||||
### Dimensions of Excalidraw
|
||||
|
||||
This props defines the `width` of the Excalidraw component. Defaults to `window.innerWidth` if not passed.
|
||||
|
||||
#### `height`
|
||||
|
||||
This props defines the `height` of the Excalidraw component. Defaults to `window.innerHeight` if not passed.
|
||||
Excalidraw takes `100%` of `width` and `height` of the containing block so you need to make sure the container in which you are rendering Excalidraw has non zero dimensions (It should have non zero width and height so Excalidraw can match the dimensions of the containing block). This is to make sure you don't have to worry about updating the offsets of dimensions when resizing Excalidraw.
|
||||
|
||||
#### `onChange`
|
||||
|
||||
|
@ -13,8 +13,6 @@ import { defaultLang } from "../../i18n";
|
||||
|
||||
const Excalidraw = (props: ExcalidrawProps) => {
|
||||
const {
|
||||
width,
|
||||
height,
|
||||
onChange,
|
||||
initialData,
|
||||
excalidrawRef,
|
||||
@ -55,8 +53,6 @@ const Excalidraw = (props: ExcalidrawProps) => {
|
||||
<InitializeApp langCode={langCode}>
|
||||
<IsMobileProvider>
|
||||
<App
|
||||
width={width}
|
||||
height={height}
|
||||
onChange={onChange}
|
||||
initialData={initialData}
|
||||
excalidrawRef={excalidrawRef}
|
||||
|
@ -33,7 +33,7 @@ export const exportToCanvas = ({
|
||||
} = restoredAppState;
|
||||
return _exportToCanvas(
|
||||
getNonDeletedElements(restoredElements),
|
||||
{ ...restoredAppState, offsetTop: 0, offsetLeft: 0 },
|
||||
{ ...restoredAppState, offsetTop: 0, offsetLeft: 0, width: 0, height: 0 },
|
||||
{ exportBackground, viewBackgroundColor, shouldAddWatermark },
|
||||
(width: number, height: number) => {
|
||||
const canvas = document.createElement("canvas");
|
||||
|
@ -459,7 +459,7 @@ Object {
|
||||
|
||||
exports[`given element A and group of elements B and given both are selected when user clicks on B, on pointer up only elements from B should be selected: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`given element A and group of elements B and given both are selected when user clicks on B, on pointer up only elements from B should be selected: [end of test] number of renders 1`] = `26`;
|
||||
exports[`given element A and group of elements B and given both are selected when user clicks on B, on pointer up only elements from B should be selected: [end of test] number of renders 1`] = `27`;
|
||||
|
||||
exports[`given element A and group of elements B and given both are selected when user shift-clicks on B, on pointer up only element A should be selected: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -926,7 +926,7 @@ Object {
|
||||
|
||||
exports[`given element A and group of elements B and given both are selected when user shift-clicks on B, on pointer up only element A should be selected: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`given element A and group of elements B and given both are selected when user shift-clicks on B, on pointer up only element A should be selected: [end of test] number of renders 1`] = `22`;
|
||||
exports[`given element A and group of elements B and given both are selected when user shift-clicks on B, on pointer up only element A should be selected: [end of test] number of renders 1`] = `23`;
|
||||
|
||||
exports[`regression tests Cmd/Ctrl-click exclusively select element under pointer: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -1702,7 +1702,7 @@ Object {
|
||||
|
||||
exports[`regression tests Cmd/Ctrl-click exclusively select element under pointer: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests Cmd/Ctrl-click exclusively select element under pointer: [end of test] number of renders 1`] = `41`;
|
||||
exports[`regression tests Cmd/Ctrl-click exclusively select element under pointer: [end of test] number of renders 1`] = `42`;
|
||||
|
||||
exports[`regression tests Drags selected element when hitting only bounding box and keeps element selected: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -1906,7 +1906,7 @@ Object {
|
||||
|
||||
exports[`regression tests Drags selected element when hitting only bounding box and keeps element selected: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests Drags selected element when hitting only bounding box and keeps element selected: [end of test] number of renders 1`] = `10`;
|
||||
exports[`regression tests Drags selected element when hitting only bounding box and keeps element selected: [end of test] number of renders 1`] = `11`;
|
||||
|
||||
exports[`regression tests adjusts z order when grouping: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -2364,7 +2364,7 @@ Object {
|
||||
|
||||
exports[`regression tests adjusts z order when grouping: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests adjusts z order when grouping: [end of test] number of renders 1`] = `20`;
|
||||
exports[`regression tests adjusts z order when grouping: [end of test] number of renders 1`] = `21`;
|
||||
|
||||
exports[`regression tests alt-drag duplicates an element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -2617,7 +2617,7 @@ Object {
|
||||
|
||||
exports[`regression tests alt-drag duplicates an element: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests alt-drag duplicates an element: [end of test] number of renders 1`] = `10`;
|
||||
exports[`regression tests alt-drag duplicates an element: [end of test] number of renders 1`] = `11`;
|
||||
|
||||
exports[`regression tests arrow keys: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -2781,7 +2781,7 @@ Object {
|
||||
|
||||
exports[`regression tests arrow keys: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests arrow keys: [end of test] number of renders 1`] = `19`;
|
||||
exports[`regression tests arrow keys: [end of test] number of renders 1`] = `20`;
|
||||
|
||||
exports[`regression tests can drag element that covers another element, while another elem is selected: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -3258,7 +3258,7 @@ Object {
|
||||
|
||||
exports[`regression tests can drag element that covers another element, while another elem is selected: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests can drag element that covers another element, while another elem is selected: [end of test] number of renders 1`] = `18`;
|
||||
exports[`regression tests can drag element that covers another element, while another elem is selected: [end of test] number of renders 1`] = `19`;
|
||||
|
||||
exports[`regression tests change the properties of a shape: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -3494,7 +3494,7 @@ Object {
|
||||
|
||||
exports[`regression tests change the properties of a shape: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests change the properties of a shape: [end of test] number of renders 1`] = `11`;
|
||||
exports[`regression tests change the properties of a shape: [end of test] number of renders 1`] = `12`;
|
||||
|
||||
exports[`regression tests click on an element and drag it: [dragged] appState 1`] = `
|
||||
Object {
|
||||
@ -3698,7 +3698,7 @@ Object {
|
||||
|
||||
exports[`regression tests click on an element and drag it: [dragged] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests click on an element and drag it: [dragged] number of renders 1`] = `10`;
|
||||
exports[`regression tests click on an element and drag it: [dragged] number of renders 1`] = `11`;
|
||||
|
||||
exports[`regression tests click on an element and drag it: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -3942,7 +3942,7 @@ Object {
|
||||
|
||||
exports[`regression tests click on an element and drag it: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests click on an element and drag it: [end of test] number of renders 1`] = `13`;
|
||||
exports[`regression tests click on an element and drag it: [end of test] number of renders 1`] = `14`;
|
||||
|
||||
exports[`regression tests click to select a shape: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -4194,7 +4194,7 @@ Object {
|
||||
|
||||
exports[`regression tests click to select a shape: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests click to select a shape: [end of test] number of renders 1`] = `13`;
|
||||
exports[`regression tests click to select a shape: [end of test] number of renders 1`] = `14`;
|
||||
|
||||
exports[`regression tests click-drag to select a group: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -4555,7 +4555,7 @@ Object {
|
||||
|
||||
exports[`regression tests click-drag to select a group: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests click-drag to select a group: [end of test] number of renders 1`] = `19`;
|
||||
exports[`regression tests click-drag to select a group: [end of test] number of renders 1`] = `20`;
|
||||
|
||||
exports[`regression tests deselects group of selected elements on pointer down when pointer doesn't hit any element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -4850,7 +4850,7 @@ Object {
|
||||
|
||||
exports[`regression tests deselects group of selected elements on pointer down when pointer doesn't hit any element: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests deselects group of selected elements on pointer down when pointer doesn't hit any element: [end of test] number of renders 1`] = `14`;
|
||||
exports[`regression tests deselects group of selected elements on pointer down when pointer doesn't hit any element: [end of test] number of renders 1`] = `15`;
|
||||
|
||||
exports[`regression tests deselects group of selected elements on pointer up when pointer hits common bounding box without hitting any element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -5157,7 +5157,7 @@ Object {
|
||||
|
||||
exports[`regression tests deselects group of selected elements on pointer up when pointer hits common bounding box without hitting any element: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests deselects group of selected elements on pointer up when pointer hits common bounding box without hitting any element: [end of test] number of renders 1`] = `15`;
|
||||
exports[`regression tests deselects group of selected elements on pointer up when pointer hits common bounding box without hitting any element: [end of test] number of renders 1`] = `16`;
|
||||
|
||||
exports[`regression tests deselects selected element on pointer down when pointer doesn't hit any element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -5365,7 +5365,7 @@ Object {
|
||||
|
||||
exports[`regression tests deselects selected element on pointer down when pointer doesn't hit any element: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests deselects selected element on pointer down when pointer doesn't hit any element: [end of test] number of renders 1`] = `8`;
|
||||
exports[`regression tests deselects selected element on pointer down when pointer doesn't hit any element: [end of test] number of renders 1`] = `9`;
|
||||
|
||||
exports[`regression tests deselects selected element, on pointer up, when click hits element bounding box but doesn't hit the element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -5551,7 +5551,7 @@ Object {
|
||||
|
||||
exports[`regression tests deselects selected element, on pointer up, when click hits element bounding box but doesn't hit the element: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests deselects selected element, on pointer up, when click hits element bounding box but doesn't hit the element: [end of test] number of renders 1`] = `9`;
|
||||
exports[`regression tests deselects selected element, on pointer up, when click hits element bounding box but doesn't hit the element: [end of test] number of renders 1`] = `10`;
|
||||
|
||||
exports[`regression tests double click to edit a group: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -6004,7 +6004,7 @@ Object {
|
||||
|
||||
exports[`regression tests double click to edit a group: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests double click to edit a group: [end of test] number of renders 1`] = `18`;
|
||||
exports[`regression tests double click to edit a group: [end of test] number of renders 1`] = `19`;
|
||||
|
||||
exports[`regression tests drags selected elements from point inside common bounding box that doesn't hit any element and keeps elements selected after dragging: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -6322,7 +6322,7 @@ Object {
|
||||
|
||||
exports[`regression tests drags selected elements from point inside common bounding box that doesn't hit any element and keeps elements selected after dragging: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests drags selected elements from point inside common bounding box that doesn't hit any element and keeps elements selected after dragging: [end of test] number of renders 1`] = `16`;
|
||||
exports[`regression tests drags selected elements from point inside common bounding box that doesn't hit any element and keeps elements selected after dragging: [end of test] number of renders 1`] = `17`;
|
||||
|
||||
exports[`regression tests draw every type of shape: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -8356,7 +8356,7 @@ Object {
|
||||
|
||||
exports[`regression tests draw every type of shape: [end of test] number of elements 1`] = `8`;
|
||||
|
||||
exports[`regression tests draw every type of shape: [end of test] number of renders 1`] = `51`;
|
||||
exports[`regression tests draw every type of shape: [end of test] number of renders 1`] = `52`;
|
||||
|
||||
exports[`regression tests given a group of selected elements with an element that is not selected inside the group common bounding box when element that is not selected is clicked should switch selection to not selected element on pointer up: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -8718,7 +8718,7 @@ Object {
|
||||
|
||||
exports[`regression tests given a group of selected elements with an element that is not selected inside the group common bounding box when element that is not selected is clicked should switch selection to not selected element on pointer up: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests given a group of selected elements with an element that is not selected inside the group common bounding box when element that is not selected is clicked should switch selection to not selected element on pointer up: [end of test] number of renders 1`] = `19`;
|
||||
exports[`regression tests given a group of selected elements with an element that is not selected inside the group common bounding box when element that is not selected is clicked should switch selection to not selected element on pointer up: [end of test] number of renders 1`] = `20`;
|
||||
|
||||
exports[`regression tests given a selected element A and a not selected element B with higher z-index than A and given B partialy overlaps A when there's a shift-click on the overlapped section B is added to the selection: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -8973,7 +8973,7 @@ Object {
|
||||
|
||||
exports[`regression tests given a selected element A and a not selected element B with higher z-index than A and given B partialy overlaps A when there's a shift-click on the overlapped section B is added to the selection: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests given a selected element A and a not selected element B with higher z-index than A and given B partialy overlaps A when there's a shift-click on the overlapped section B is added to the selection: [end of test] number of renders 1`] = `17`;
|
||||
exports[`regression tests given a selected element A and a not selected element B with higher z-index than A and given B partialy overlaps A when there's a shift-click on the overlapped section B is added to the selection: [end of test] number of renders 1`] = `18`;
|
||||
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when clicking intersection between A and B B should be selected on pointer up: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -9226,7 +9226,7 @@ Object {
|
||||
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when clicking intersection between A and B B should be selected on pointer up: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when clicking intersection between A and B B should be selected on pointer up: [end of test] number of renders 1`] = `17`;
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when clicking intersection between A and B B should be selected on pointer up: [end of test] number of renders 1`] = `18`;
|
||||
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when dragging on intersection between A and B A should be dragged and keep being selected: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -9541,7 +9541,7 @@ Object {
|
||||
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when dragging on intersection between A and B A should be dragged and keep being selected: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when dragging on intersection between A and B A should be dragged and keep being selected: [end of test] number of renders 1`] = `18`;
|
||||
exports[`regression tests given selected element A with lower z-index than unselected element B and given B is partially over A when dragging on intersection between A and B A should be dragged and keep being selected: [end of test] number of renders 1`] = `19`;
|
||||
|
||||
exports[`regression tests key 2 selects rectangle tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -9705,7 +9705,7 @@ Object {
|
||||
|
||||
exports[`regression tests key 2 selects rectangle tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key 2 selects rectangle tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key 2 selects rectangle tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key 3 selects diamond tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -9869,7 +9869,7 @@ Object {
|
||||
|
||||
exports[`regression tests key 3 selects diamond tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key 3 selects diamond tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key 3 selects diamond tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key 4 selects ellipse tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -10033,7 +10033,7 @@ Object {
|
||||
|
||||
exports[`regression tests key 4 selects ellipse tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key 4 selects ellipse tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key 4 selects ellipse tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key 5 selects arrow tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -10227,7 +10227,7 @@ Object {
|
||||
|
||||
exports[`regression tests key 5 selects arrow tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key 5 selects arrow tool: [end of test] number of renders 1`] = `8`;
|
||||
exports[`regression tests key 5 selects arrow tool: [end of test] number of renders 1`] = `9`;
|
||||
|
||||
exports[`regression tests key 6 selects line tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -10421,7 +10421,7 @@ Object {
|
||||
|
||||
exports[`regression tests key 6 selects line tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key 6 selects line tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key 6 selects line tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key 7 selects draw tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -10615,7 +10615,7 @@ Object {
|
||||
|
||||
exports[`regression tests key 7 selects draw tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key 7 selects draw tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key 7 selects draw tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key a selects arrow tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -10809,7 +10809,7 @@ Object {
|
||||
|
||||
exports[`regression tests key a selects arrow tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key a selects arrow tool: [end of test] number of renders 1`] = `8`;
|
||||
exports[`regression tests key a selects arrow tool: [end of test] number of renders 1`] = `9`;
|
||||
|
||||
exports[`regression tests key d selects diamond tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -10973,7 +10973,7 @@ Object {
|
||||
|
||||
exports[`regression tests key d selects diamond tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key d selects diamond tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key d selects diamond tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key e selects ellipse tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -11137,7 +11137,7 @@ Object {
|
||||
|
||||
exports[`regression tests key e selects ellipse tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key e selects ellipse tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key e selects ellipse tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key l selects line tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -11331,7 +11331,7 @@ Object {
|
||||
|
||||
exports[`regression tests key l selects line tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key l selects line tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key l selects line tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key r selects rectangle tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -11495,7 +11495,7 @@ Object {
|
||||
|
||||
exports[`regression tests key r selects rectangle tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key r selects rectangle tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key r selects rectangle tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests key x selects draw tool: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -11689,7 +11689,7 @@ Object {
|
||||
|
||||
exports[`regression tests key x selects draw tool: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests key x selects draw tool: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests key x selects draw tool: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests make a group and duplicate it: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -12405,7 +12405,7 @@ Object {
|
||||
|
||||
exports[`regression tests make a group and duplicate it: [end of test] number of elements 1`] = `6`;
|
||||
|
||||
exports[`regression tests make a group and duplicate it: [end of test] number of renders 1`] = `22`;
|
||||
exports[`regression tests make a group and duplicate it: [end of test] number of renders 1`] = `23`;
|
||||
|
||||
exports[`regression tests noop interaction after undo shouldn't create history entry: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -12658,7 +12658,7 @@ Object {
|
||||
|
||||
exports[`regression tests noop interaction after undo shouldn't create history entry: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests noop interaction after undo shouldn't create history entry: [end of test] number of renders 1`] = `19`;
|
||||
exports[`regression tests noop interaction after undo shouldn't create history entry: [end of test] number of renders 1`] = `20`;
|
||||
|
||||
exports[`regression tests pinch-to-zoom works: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -12760,7 +12760,7 @@ Object {
|
||||
|
||||
exports[`regression tests pinch-to-zoom works: [end of test] number of elements 1`] = `0`;
|
||||
|
||||
exports[`regression tests pinch-to-zoom works: [end of test] number of renders 1`] = `9`;
|
||||
exports[`regression tests pinch-to-zoom works: [end of test] number of renders 1`] = `10`;
|
||||
|
||||
exports[`regression tests rerenders UI on language change: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -12860,7 +12860,7 @@ Object {
|
||||
|
||||
exports[`regression tests rerenders UI on language change: [end of test] number of elements 1`] = `0`;
|
||||
|
||||
exports[`regression tests rerenders UI on language change: [end of test] number of renders 1`] = `8`;
|
||||
exports[`regression tests rerenders UI on language change: [end of test] number of renders 1`] = `9`;
|
||||
|
||||
exports[`regression tests selecting 'Add to library' in context menu adds element to library: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -13024,7 +13024,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Add to library' in context menu adds element to library: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests selecting 'Add to library' in context menu adds element to library: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests selecting 'Add to library' in context menu adds element to library: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests selecting 'Bring forward' in context menu brings element forward: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -13332,7 +13332,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Bring forward' in context menu brings element forward: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Bring forward' in context menu brings element forward: [end of test] number of renders 1`] = `13`;
|
||||
exports[`regression tests selecting 'Bring forward' in context menu brings element forward: [end of test] number of renders 1`] = `14`;
|
||||
|
||||
exports[`regression tests selecting 'Bring to front' in context menu brings element to front: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -13640,7 +13640,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Bring to front' in context menu brings element to front: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Bring to front' in context menu brings element to front: [end of test] number of renders 1`] = `13`;
|
||||
exports[`regression tests selecting 'Bring to front' in context menu brings element to front: [end of test] number of renders 1`] = `14`;
|
||||
|
||||
exports[`regression tests selecting 'Copy styles' in context menu copies styles: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -13804,7 +13804,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Copy styles' in context menu copies styles: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests selecting 'Copy styles' in context menu copies styles: [end of test] number of renders 1`] = `8`;
|
||||
exports[`regression tests selecting 'Copy styles' in context menu copies styles: [end of test] number of renders 1`] = `9`;
|
||||
|
||||
exports[`regression tests selecting 'Delete' in context menu deletes element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -14000,7 +14000,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Delete' in context menu deletes element: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests selecting 'Delete' in context menu deletes element: [end of test] number of renders 1`] = `8`;
|
||||
exports[`regression tests selecting 'Delete' in context menu deletes element: [end of test] number of renders 1`] = `9`;
|
||||
|
||||
exports[`regression tests selecting 'Duplicate' in context menu duplicates element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -14249,7 +14249,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Duplicate' in context menu duplicates element: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Duplicate' in context menu duplicates element: [end of test] number of renders 1`] = `8`;
|
||||
exports[`regression tests selecting 'Duplicate' in context menu duplicates element: [end of test] number of renders 1`] = `9`;
|
||||
|
||||
exports[`regression tests selecting 'Group selection' in context menu groups selected elements: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -14573,7 +14573,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Group selection' in context menu groups selected elements: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Group selection' in context menu groups selected elements: [end of test] number of renders 1`] = `14`;
|
||||
exports[`regression tests selecting 'Group selection' in context menu groups selected elements: [end of test] number of renders 1`] = `15`;
|
||||
|
||||
exports[`regression tests selecting 'Paste styles' in context menu pastes styles: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -15294,7 +15294,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Paste styles' in context menu pastes styles: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Paste styles' in context menu pastes styles: [end of test] number of renders 1`] = `23`;
|
||||
exports[`regression tests selecting 'Paste styles' in context menu pastes styles: [end of test] number of renders 1`] = `24`;
|
||||
|
||||
exports[`regression tests selecting 'Send backward' in context menu sends element backward: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -15602,7 +15602,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Send backward' in context menu sends element backward: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Send backward' in context menu sends element backward: [end of test] number of renders 1`] = `12`;
|
||||
exports[`regression tests selecting 'Send backward' in context menu sends element backward: [end of test] number of renders 1`] = `13`;
|
||||
|
||||
exports[`regression tests selecting 'Send to back' in context menu sends element to back: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -15910,7 +15910,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Send to back' in context menu sends element to back: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Send to back' in context menu sends element to back: [end of test] number of renders 1`] = `12`;
|
||||
exports[`regression tests selecting 'Send to back' in context menu sends element to back: [end of test] number of renders 1`] = `13`;
|
||||
|
||||
exports[`regression tests selecting 'Ungroup selection' in context menu ungroups selected group: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -16289,7 +16289,7 @@ Object {
|
||||
|
||||
exports[`regression tests selecting 'Ungroup selection' in context menu ungroups selected group: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests selecting 'Ungroup selection' in context menu ungroups selected group: [end of test] number of renders 1`] = `15`;
|
||||
exports[`regression tests selecting 'Ungroup selection' in context menu ungroups selected group: [end of test] number of renders 1`] = `16`;
|
||||
|
||||
exports[`regression tests shift click on selected element should deselect it on pointer up: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -16456,7 +16456,7 @@ Object {
|
||||
|
||||
exports[`regression tests shift click on selected element should deselect it on pointer up: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests shift click on selected element should deselect it on pointer up: [end of test] number of renders 1`] = `9`;
|
||||
exports[`regression tests shift click on selected element should deselect it on pointer up: [end of test] number of renders 1`] = `10`;
|
||||
|
||||
exports[`regression tests shift-click to multiselect, then drag: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -16777,7 +16777,7 @@ Object {
|
||||
|
||||
exports[`regression tests shift-click to multiselect, then drag: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests shift-click to multiselect, then drag: [end of test] number of renders 1`] = `18`;
|
||||
exports[`regression tests shift-click to multiselect, then drag: [end of test] number of renders 1`] = `19`;
|
||||
|
||||
exports[`regression tests should show fill icons when element has non transparent background: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -16980,7 +16980,7 @@ Object {
|
||||
|
||||
exports[`regression tests should show fill icons when element has non transparent background: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests should show fill icons when element has non transparent background: [end of test] number of renders 1`] = `11`;
|
||||
exports[`regression tests should show fill icons when element has non transparent background: [end of test] number of renders 1`] = `12`;
|
||||
|
||||
exports[`regression tests shows 'Group selection' in context menu for multiple selected elements: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -17235,7 +17235,7 @@ Object {
|
||||
|
||||
exports[`regression tests shows 'Group selection' in context menu for multiple selected elements: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests shows 'Group selection' in context menu for multiple selected elements: [end of test] number of renders 1`] = `15`;
|
||||
exports[`regression tests shows 'Group selection' in context menu for multiple selected elements: [end of test] number of renders 1`] = `16`;
|
||||
|
||||
exports[`regression tests shows 'Ungroup selection' in context menu for group inside selected elements: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -17562,7 +17562,7 @@ Object {
|
||||
|
||||
exports[`regression tests shows 'Ungroup selection' in context menu for group inside selected elements: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests shows 'Ungroup selection' in context menu for group inside selected elements: [end of test] number of renders 1`] = `16`;
|
||||
exports[`regression tests shows 'Ungroup selection' in context menu for group inside selected elements: [end of test] number of renders 1`] = `17`;
|
||||
|
||||
exports[`regression tests shows context menu for canvas: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -17662,7 +17662,7 @@ Object {
|
||||
|
||||
exports[`regression tests shows context menu for canvas: [end of test] number of elements 1`] = `0`;
|
||||
|
||||
exports[`regression tests shows context menu for canvas: [end of test] number of renders 1`] = `3`;
|
||||
exports[`regression tests shows context menu for canvas: [end of test] number of renders 1`] = `4`;
|
||||
|
||||
exports[`regression tests shows context menu for element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -17826,7 +17826,7 @@ Object {
|
||||
|
||||
exports[`regression tests shows context menu for element: [end of test] number of elements 1`] = `1`;
|
||||
|
||||
exports[`regression tests shows context menu for element: [end of test] number of renders 1`] = `7`;
|
||||
exports[`regression tests shows context menu for element: [end of test] number of renders 1`] = `8`;
|
||||
|
||||
exports[`regression tests single-clicking on a subgroup of a selected group should not alter selection: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -18647,7 +18647,7 @@ Object {
|
||||
|
||||
exports[`regression tests single-clicking on a subgroup of a selected group should not alter selection: [end of test] number of elements 1`] = `4`;
|
||||
|
||||
exports[`regression tests single-clicking on a subgroup of a selected group should not alter selection: [end of test] number of renders 1`] = `37`;
|
||||
exports[`regression tests single-clicking on a subgroup of a selected group should not alter selection: [end of test] number of renders 1`] = `38`;
|
||||
|
||||
exports[`regression tests spacebar + drag scrolls the canvas: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -18747,7 +18747,7 @@ Object {
|
||||
|
||||
exports[`regression tests spacebar + drag scrolls the canvas: [end of test] number of elements 1`] = `0`;
|
||||
|
||||
exports[`regression tests spacebar + drag scrolls the canvas: [end of test] number of renders 1`] = `6`;
|
||||
exports[`regression tests spacebar + drag scrolls the canvas: [end of test] number of renders 1`] = `7`;
|
||||
|
||||
exports[`regression tests supports nested groups: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -19479,7 +19479,7 @@ Object {
|
||||
|
||||
exports[`regression tests supports nested groups: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests supports nested groups: [end of test] number of renders 1`] = `30`;
|
||||
exports[`regression tests supports nested groups: [end of test] number of renders 1`] = `31`;
|
||||
|
||||
exports[`regression tests switches from group of selected elements to another element on pointer down: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -19884,7 +19884,7 @@ Object {
|
||||
|
||||
exports[`regression tests switches from group of selected elements to another element on pointer down: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests switches from group of selected elements to another element on pointer down: [end of test] number of renders 1`] = `18`;
|
||||
exports[`regression tests switches from group of selected elements to another element on pointer down: [end of test] number of renders 1`] = `19`;
|
||||
|
||||
exports[`regression tests switches selected element on pointer down: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -20179,7 +20179,7 @@ Object {
|
||||
|
||||
exports[`regression tests switches selected element on pointer down: [end of test] number of elements 1`] = `2`;
|
||||
|
||||
exports[`regression tests switches selected element on pointer down: [end of test] number of renders 1`] = `12`;
|
||||
exports[`regression tests switches selected element on pointer down: [end of test] number of renders 1`] = `13`;
|
||||
|
||||
exports[`regression tests two-finger scroll works: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -20281,7 +20281,7 @@ Object {
|
||||
|
||||
exports[`regression tests two-finger scroll works: [end of test] number of elements 1`] = `0`;
|
||||
|
||||
exports[`regression tests two-finger scroll works: [end of test] number of renders 1`] = `11`;
|
||||
exports[`regression tests two-finger scroll works: [end of test] number of renders 1`] = `12`;
|
||||
|
||||
exports[`regression tests undo/redo drawing an element: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -20779,7 +20779,7 @@ Object {
|
||||
|
||||
exports[`regression tests undo/redo drawing an element: [end of test] number of elements 1`] = `3`;
|
||||
|
||||
exports[`regression tests undo/redo drawing an element: [end of test] number of renders 1`] = `28`;
|
||||
exports[`regression tests undo/redo drawing an element: [end of test] number of renders 1`] = `29`;
|
||||
|
||||
exports[`regression tests updates fontSize & fontFamily appState: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -20879,7 +20879,7 @@ Object {
|
||||
|
||||
exports[`regression tests updates fontSize & fontFamily appState: [end of test] number of elements 1`] = `0`;
|
||||
|
||||
exports[`regression tests updates fontSize & fontFamily appState: [end of test] number of renders 1`] = `5`;
|
||||
exports[`regression tests updates fontSize & fontFamily appState: [end of test] number of renders 1`] = `6`;
|
||||
|
||||
exports[`regression tests zoom hotkeys: [end of test] appState 1`] = `
|
||||
Object {
|
||||
@ -20979,4 +20979,4 @@ Object {
|
||||
|
||||
exports[`regression tests zoom hotkeys: [end of test] number of elements 1`] = `0`;
|
||||
|
||||
exports[`regression tests zoom hotkeys: [end of test] number of renders 1`] = `5`;
|
||||
exports[`regression tests zoom hotkeys: [end of test] number of renders 1`] = `6`;
|
||||
|
@ -36,8 +36,8 @@ Object {
|
||||
"version": 3,
|
||||
"versionNonce": 449462985,
|
||||
"width": 30,
|
||||
"x": 30,
|
||||
"y": 20,
|
||||
"x": 10,
|
||||
"y": 10,
|
||||
}
|
||||
`;
|
||||
|
||||
@ -77,8 +77,8 @@ Object {
|
||||
"version": 3,
|
||||
"versionNonce": 449462985,
|
||||
"width": 30,
|
||||
"x": 30,
|
||||
"y": 20,
|
||||
"x": 10,
|
||||
"y": 10,
|
||||
}
|
||||
`;
|
||||
|
||||
@ -103,8 +103,8 @@ Object {
|
||||
"version": 2,
|
||||
"versionNonce": 1278240551,
|
||||
"width": 30,
|
||||
"x": 30,
|
||||
"y": 20,
|
||||
"x": 10,
|
||||
"y": 10,
|
||||
}
|
||||
`;
|
||||
|
||||
@ -129,8 +129,8 @@ Object {
|
||||
"version": 2,
|
||||
"versionNonce": 1278240551,
|
||||
"width": 30,
|
||||
"x": 30,
|
||||
"y": 20,
|
||||
"x": 10,
|
||||
"y": 10,
|
||||
}
|
||||
`;
|
||||
|
||||
@ -155,7 +155,7 @@ Object {
|
||||
"version": 2,
|
||||
"versionNonce": 1278240551,
|
||||
"width": 30,
|
||||
"x": 30,
|
||||
"y": 20,
|
||||
"x": 10,
|
||||
"y": 10,
|
||||
}
|
||||
`;
|
||||
|
@ -3,7 +3,12 @@ import ReactDOM from "react-dom";
|
||||
import ExcalidrawApp from "../excalidraw-app";
|
||||
import * as Renderer from "../renderer/renderScene";
|
||||
import { KEYS } from "../keys";
|
||||
import { render, fireEvent } from "./test-utils";
|
||||
import {
|
||||
render,
|
||||
fireEvent,
|
||||
mockBoundingClientRect,
|
||||
restoreOriginalGetBoundingClientRect,
|
||||
} from "./test-utils";
|
||||
import { ExcalidrawLinearElement } from "../element/types";
|
||||
import { reseed } from "../random";
|
||||
|
||||
@ -37,7 +42,7 @@ describe("add element to the scene when pointer dragging long enough", () => {
|
||||
// finish (position does not matter)
|
||||
fireEvent.pointerUp(canvas);
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(7);
|
||||
expect(renderScene).toHaveBeenCalledTimes(8);
|
||||
expect(h.state.selectionElement).toBeNull();
|
||||
|
||||
expect(h.elements.length).toEqual(1);
|
||||
@ -68,7 +73,7 @@ describe("add element to the scene when pointer dragging long enough", () => {
|
||||
// finish (position does not matter)
|
||||
fireEvent.pointerUp(canvas);
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(7);
|
||||
expect(renderScene).toHaveBeenCalledTimes(8);
|
||||
expect(h.state.selectionElement).toBeNull();
|
||||
|
||||
expect(h.elements.length).toEqual(1);
|
||||
@ -99,7 +104,7 @@ describe("add element to the scene when pointer dragging long enough", () => {
|
||||
// finish (position does not matter)
|
||||
fireEvent.pointerUp(canvas);
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(7);
|
||||
expect(renderScene).toHaveBeenCalledTimes(8);
|
||||
expect(h.state.selectionElement).toBeNull();
|
||||
|
||||
expect(h.elements.length).toEqual(1);
|
||||
@ -130,7 +135,7 @@ describe("add element to the scene when pointer dragging long enough", () => {
|
||||
// finish (position does not matter)
|
||||
fireEvent.pointerUp(canvas);
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(7);
|
||||
expect(renderScene).toHaveBeenCalledTimes(8);
|
||||
expect(h.state.selectionElement).toBeNull();
|
||||
|
||||
expect(h.elements.length).toEqual(1);
|
||||
@ -165,7 +170,7 @@ describe("add element to the scene when pointer dragging long enough", () => {
|
||||
// finish (position does not matter)
|
||||
fireEvent.pointerUp(canvas);
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(7);
|
||||
expect(renderScene).toHaveBeenCalledTimes(8);
|
||||
expect(h.state.selectionElement).toBeNull();
|
||||
|
||||
expect(h.elements.length).toEqual(1);
|
||||
@ -184,6 +189,13 @@ describe("add element to the scene when pointer dragging long enough", () => {
|
||||
});
|
||||
|
||||
describe("do not add element to the scene if size is too small", () => {
|
||||
beforeAll(() => {
|
||||
mockBoundingClientRect();
|
||||
});
|
||||
afterAll(() => {
|
||||
restoreOriginalGetBoundingClientRect();
|
||||
});
|
||||
|
||||
it("rectangle", async () => {
|
||||
const { getByToolName, container } = await render(<ExcalidrawApp />);
|
||||
// select tool
|
||||
|
@ -38,7 +38,7 @@ describe("move element", () => {
|
||||
fireEvent.pointerMove(canvas, { clientX: 60, clientY: 70 });
|
||||
fireEvent.pointerUp(canvas);
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(7);
|
||||
expect(renderScene).toHaveBeenCalledTimes(8);
|
||||
expect(h.state.selectionElement).toBeNull();
|
||||
expect(h.elements.length).toEqual(1);
|
||||
expect(h.state.selectedElementIds[h.elements[0].id]).toBeTruthy();
|
||||
@ -120,7 +120,7 @@ describe("duplicate element on move when ALT is clicked", () => {
|
||||
fireEvent.pointerMove(canvas, { clientX: 60, clientY: 70 });
|
||||
fireEvent.pointerUp(canvas);
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(7);
|
||||
expect(renderScene).toHaveBeenCalledTimes(8);
|
||||
expect(h.state.selectionElement).toBeNull();
|
||||
expect(h.elements.length).toEqual(1);
|
||||
expect(h.state.selectedElementIds[h.elements[0].id]).toBeTruthy();
|
||||
|
@ -1,6 +1,11 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { render, fireEvent } from "./test-utils";
|
||||
import {
|
||||
render,
|
||||
fireEvent,
|
||||
mockBoundingClientRect,
|
||||
restoreOriginalGetBoundingClientRect,
|
||||
} from "./test-utils";
|
||||
import ExcalidrawApp from "../excalidraw-app";
|
||||
import * as Renderer from "../renderer/renderScene";
|
||||
import { KEYS } from "../keys";
|
||||
@ -20,6 +25,14 @@ beforeEach(() => {
|
||||
const { h } = window;
|
||||
|
||||
describe("remove shape in non linear elements", () => {
|
||||
beforeAll(() => {
|
||||
mockBoundingClientRect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
restoreOriginalGetBoundingClientRect();
|
||||
});
|
||||
|
||||
it("rectangle", async () => {
|
||||
const { getByToolName, container } = await render(<ExcalidrawApp />);
|
||||
// select tool
|
||||
@ -88,7 +101,7 @@ describe("multi point mode in linear elements", () => {
|
||||
fireEvent.pointerUp(canvas);
|
||||
fireEvent.keyDown(document, { key: KEYS.ENTER });
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(13);
|
||||
expect(renderScene).toHaveBeenCalledTimes(14);
|
||||
expect(h.elements.length).toEqual(1);
|
||||
|
||||
const element = h.elements[0] as ExcalidrawLinearElement;
|
||||
@ -129,7 +142,7 @@ describe("multi point mode in linear elements", () => {
|
||||
fireEvent.pointerUp(canvas);
|
||||
fireEvent.keyDown(document, { key: KEYS.ENTER });
|
||||
|
||||
expect(renderScene).toHaveBeenCalledTimes(13);
|
||||
expect(renderScene).toHaveBeenCalledTimes(14);
|
||||
expect(h.elements.length).toEqual(1);
|
||||
|
||||
const element = h.elements[0] as ExcalidrawLinearElement;
|
||||
|
@ -32,7 +32,6 @@ Object {
|
||||
"exportWithDarkMode": false,
|
||||
"fileHandle": null,
|
||||
"gridSize": null,
|
||||
"height": 768,
|
||||
"isBindingEnabled": true,
|
||||
"isLibraryOpen": false,
|
||||
"isLoading": false,
|
||||
@ -42,8 +41,6 @@ Object {
|
||||
"metadata": undefined,
|
||||
"multiElement": null,
|
||||
"name": "name",
|
||||
"offsetLeft": 0,
|
||||
"offsetTop": 0,
|
||||
"openMenu": null,
|
||||
"pasteDialog": Object {
|
||||
"data": null,
|
||||
@ -67,7 +64,6 @@ Object {
|
||||
"toastMessage": null,
|
||||
"viewBackgroundColor": "#ffffff",
|
||||
"viewModeEnabled": false,
|
||||
"width": 1024,
|
||||
"zenModeEnabled": false,
|
||||
"zoom": Object {
|
||||
"translation": Object {
|
||||
|
@ -76,6 +76,7 @@ beforeEach(async () => {
|
||||
finger2.reset();
|
||||
|
||||
await render(<ExcalidrawApp />);
|
||||
h.setState({ height: 768, width: 1024 });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -1,5 +1,10 @@
|
||||
import React from "react";
|
||||
import { render, waitFor } from "./test-utils";
|
||||
import {
|
||||
mockBoundingClientRect,
|
||||
render,
|
||||
restoreOriginalGetBoundingClientRect,
|
||||
waitFor,
|
||||
} from "./test-utils";
|
||||
import Excalidraw from "../packages/excalidraw/index";
|
||||
import { API } from "./helpers/api";
|
||||
|
||||
@ -7,34 +12,19 @@ const { h } = window;
|
||||
|
||||
describe("appState", () => {
|
||||
it("scroll-to-content on init works with non-zero offsets", async () => {
|
||||
const WIDTH = 600;
|
||||
const HEIGHT = 700;
|
||||
const OFFSET_LEFT = 200;
|
||||
const OFFSET_TOP = 100;
|
||||
const WIDTH = 200;
|
||||
const HEIGHT = 100;
|
||||
const OFFSET_LEFT = 20;
|
||||
const OFFSET_TOP = 10;
|
||||
|
||||
const ELEM_WIDTH = 100;
|
||||
const ELEM_HEIGHT = 60;
|
||||
|
||||
const originalGetBoundingClientRect =
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect;
|
||||
// override getBoundingClientRect as by default it will always return all values as 0 even if customized in html
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect = () => ({
|
||||
top: OFFSET_TOP,
|
||||
left: OFFSET_LEFT,
|
||||
bottom: 10,
|
||||
right: 10,
|
||||
width: 100,
|
||||
x: 10,
|
||||
y: 20,
|
||||
height: 100,
|
||||
toJSON: () => {},
|
||||
});
|
||||
mockBoundingClientRect();
|
||||
|
||||
await render(
|
||||
<div>
|
||||
<Excalidraw
|
||||
width={WIDTH}
|
||||
height={HEIGHT}
|
||||
initialData={{
|
||||
elements: [
|
||||
API.createElement({
|
||||
@ -50,8 +40,8 @@ describe("appState", () => {
|
||||
</div>,
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(h.state.width).toBe(WIDTH);
|
||||
expect(h.state.height).toBe(HEIGHT);
|
||||
expect(h.state.width).toBe(200);
|
||||
expect(h.state.height).toBe(100);
|
||||
expect(h.state.offsetLeft).toBe(OFFSET_LEFT);
|
||||
expect(h.state.offsetTop).toBe(OFFSET_TOP);
|
||||
|
||||
@ -59,6 +49,6 @@ describe("appState", () => {
|
||||
expect(h.state.scrollX).toBe(WIDTH / 2 - ELEM_WIDTH / 2);
|
||||
expect(h.state.scrollY).toBe(HEIGHT / 2 - ELEM_HEIGHT / 2);
|
||||
});
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect = originalGetBoundingClientRect;
|
||||
restoreOriginalGetBoundingClientRect();
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,11 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { render, fireEvent } from "./test-utils";
|
||||
import {
|
||||
render,
|
||||
fireEvent,
|
||||
mockBoundingClientRect,
|
||||
restoreOriginalGetBoundingClientRect,
|
||||
} from "./test-utils";
|
||||
import ExcalidrawApp from "../excalidraw-app";
|
||||
import * as Renderer from "../renderer/renderScene";
|
||||
import { KEYS } from "../keys";
|
||||
@ -77,6 +82,14 @@ describe("selection element", () => {
|
||||
});
|
||||
|
||||
describe("select single element on the scene", () => {
|
||||
beforeAll(() => {
|
||||
mockBoundingClientRect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
restoreOriginalGetBoundingClientRect();
|
||||
});
|
||||
|
||||
it("rectangle", async () => {
|
||||
const { getByToolName, container } = await render(<ExcalidrawApp />);
|
||||
const canvas = container.querySelector("canvas")!;
|
||||
|
@ -102,3 +102,25 @@ const initLocalStorage = (data: ImportedDataState) => {
|
||||
export const updateSceneData = (data: SceneData) => {
|
||||
(window.collab as any).excalidrawAPI.updateScene(data);
|
||||
};
|
||||
|
||||
const originalGetBoundingClientRect =
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect;
|
||||
|
||||
export const mockBoundingClientRect = () => {
|
||||
// override getBoundingClientRect as by default it will always return all values as 0 even if customized in html
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect = () => ({
|
||||
top: 10,
|
||||
left: 20,
|
||||
bottom: 10,
|
||||
right: 10,
|
||||
width: 200,
|
||||
x: 10,
|
||||
y: 20,
|
||||
height: 100,
|
||||
toJSON: () => {},
|
||||
});
|
||||
};
|
||||
|
||||
export const restoreOriginalGetBoundingClientRect = () => {
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect = originalGetBoundingClientRect;
|
||||
};
|
||||
|
@ -159,8 +159,6 @@ export type ExcalidrawAPIRefValue =
|
||||
};
|
||||
|
||||
export interface ExcalidrawProps {
|
||||
width?: number;
|
||||
height?: number;
|
||||
onChange?: (
|
||||
elements: readonly ExcalidrawElement[],
|
||||
appState: AppState,
|
||||
|
Loading…
Reference in New Issue
Block a user