Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| be5d0bd925 | |||
| 292aa1cddb | |||
| e95222ed32 | |||
| d87620b239 | |||
| 7cc31ac64a | |||
| 071b17a217 | |||
| 859207b8bc | |||
| becaabfa0f | |||
| f06484c6ab | |||
| bf4c65f483 | |||
| 8d18078f5c | |||
| d080833f4d | |||
| 451bcac0b7 | |||
| 06f01e11f8 | |||
| 51ad8951d4 | |||
| 7497a08270 | |||
| 210dc85c8c | |||
| 019ce4c52c | |||
| c141960ada | |||
| d7e63e66a7 | |||
| b660478164 | |||
| 37882c66cb |
@@ -12,10 +12,10 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
- name: Setup Node.js 18.x
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 18.x
|
node-version: 20.x
|
||||||
- name: Set up publish access
|
- name: Set up publish access
|
||||||
run: |
|
run: |
|
||||||
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
|
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Node.js 18.x
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 18.x
|
node-version: 20.x
|
||||||
|
|
||||||
- name: Install and lint
|
- name: Install and lint
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
|
token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
|
||||||
|
|
||||||
- name: Setup Node.js 18.x
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 18.x
|
node-version: 20.x
|
||||||
|
|
||||||
- name: Create report file
|
- name: Create report file
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node.js 18.x
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 18.x
|
node-version: 20.x
|
||||||
- name: Install and build
|
- name: Install and build
|
||||||
run: |
|
run: |
|
||||||
yarn --frozen-lockfile
|
yarn --frozen-lockfile
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Setup Node.js 18.x
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18.x
|
node-version: 20.x
|
||||||
- name: Install in packages/excalidraw
|
- name: Install in packages/excalidraw
|
||||||
run: yarn
|
run: yarn
|
||||||
working-directory: packages/excalidraw
|
working-directory: packages/excalidraw
|
||||||
|
|||||||
@@ -23,23 +23,17 @@
|
|||||||
<br />
|
<br />
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/excalidraw/excalidraw/blob/master/LICENSE">
|
<a href="https://github.com/excalidraw/excalidraw/blob/master/LICENSE">
|
||||||
<img alt="Excalidraw is released under the MIT license." src="https://img.shields.io/badge/license-MIT-blue.svg" />
|
<img alt="Excalidraw is released under the MIT license." src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
|
||||||
</a>
|
|
||||||
<a href="https://www.npmjs.com/package/@excalidraw/excalidraw">
|
<a href="https://www.npmjs.com/package/@excalidraw/excalidraw">
|
||||||
<img alt="npm downloads/month" src="https://img.shields.io/npm/dm/@excalidraw/excalidraw" />
|
<img alt="npm downloads/month" src="https://img.shields.io/npm/dm/@excalidraw/excalidraw" /></a>
|
||||||
</a>
|
|
||||||
<a href="https://docs.excalidraw.com/docs/introduction/contributing">
|
<a href="https://docs.excalidraw.com/docs/introduction/contributing">
|
||||||
<img alt="PRs welcome!" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" />
|
<img alt="PRs welcome!" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" /></a>
|
||||||
</a>
|
|
||||||
<a href="https://discord.gg/UexuTaE">
|
<a href="https://discord.gg/UexuTaE">
|
||||||
<img alt="Chat on Discord" src="https://img.shields.io/discord/723672430744174682?color=738ad6&label=Chat%20on%20Discord&logo=discord&logoColor=ffffff&widge=false"/>
|
<img alt="Chat on Discord" src="https://img.shields.io/discord/723672430744174682?color=738ad6&label=Chat%20on%20Discord&logo=discord&logoColor=ffffff&widge=false"/></a>
|
||||||
</a>
|
|
||||||
<a href="https://deepwiki.com/excalidraw/excalidraw">
|
<a href="https://deepwiki.com/excalidraw/excalidraw">
|
||||||
<img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" />
|
<img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
||||||
</a>
|
|
||||||
<a href="https://twitter.com/excalidraw">
|
<a href="https://twitter.com/excalidraw">
|
||||||
<img alt="Follow Excalidraw on Twitter" src="https://img.shields.io/twitter/follow/excalidraw.svg?label=follow+@excalidraw&style=social&logo=twitter"/>
|
<img alt="Follow Excalidraw on Twitter" src="https://img.shields.io/twitter/follow/excalidraw.svg?label=follow+@excalidraw&style=social&logo=twitter"/></a>
|
||||||
</a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ class Collab extends PureComponent<CollabProps, CollabState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private decryptPayload = async (
|
private decryptPayload = async (
|
||||||
iv: Uint8Array,
|
iv: Uint8Array<ArrayBuffer>,
|
||||||
encryptedData: ArrayBuffer,
|
encryptedData: ArrayBuffer,
|
||||||
decryptionKey: string,
|
decryptionKey: string,
|
||||||
): Promise<ValueOf<SocketUpdateDataSource>> => {
|
): Promise<ValueOf<SocketUpdateDataSource>> => {
|
||||||
@@ -562,7 +562,7 @@ class Collab extends PureComponent<CollabProps, CollabState> {
|
|||||||
// All socket listeners are moving to Portal
|
// All socket listeners are moving to Portal
|
||||||
this.portal.socket.on(
|
this.portal.socket.on(
|
||||||
"client-broadcast",
|
"client-broadcast",
|
||||||
async (encryptedData: ArrayBuffer, iv: Uint8Array) => {
|
async (encryptedData: ArrayBuffer, iv: Uint8Array<ArrayBuffer>) => {
|
||||||
if (!this.portal.roomKey) {
|
if (!this.portal.roomKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -746,7 +746,10 @@ class Collab extends PureComponent<CollabProps, CollabState> {
|
|||||||
): ReconciledExcalidrawElement[] => {
|
): ReconciledExcalidrawElement[] => {
|
||||||
const localElements = this.getSceneElementsIncludingDeleted();
|
const localElements = this.getSceneElementsIncludingDeleted();
|
||||||
const appState = this.excalidrawAPI.getAppState();
|
const appState = this.excalidrawAPI.getAppState();
|
||||||
const restoredRemoteElements = restoreElements(remoteElements, null);
|
const restoredRemoteElements = restoreElements(
|
||||||
|
remoteElements,
|
||||||
|
this.excalidrawAPI.getSceneElementsMapIncludingDeleted(),
|
||||||
|
);
|
||||||
const reconciledElements = reconcileElements(
|
const reconciledElements = reconcileElements(
|
||||||
localElements,
|
localElements,
|
||||||
restoredRemoteElements as RemoteExcalidrawElement[],
|
restoredRemoteElements as RemoteExcalidrawElement[],
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
getGlobalFixedPointForBindableElement,
|
getGlobalFixedPointForBindableElement,
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
isBindableElement,
|
isBindableElement,
|
||||||
isFixedPointBinding,
|
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -35,7 +34,6 @@ import type {
|
|||||||
ExcalidrawBindableElement,
|
ExcalidrawBindableElement,
|
||||||
FixedPointBinding,
|
FixedPointBinding,
|
||||||
OrderedExcalidrawElement,
|
OrderedExcalidrawElement,
|
||||||
PointBinding,
|
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { STORAGE_KEYS } from "../app_constants";
|
import { STORAGE_KEYS } from "../app_constants";
|
||||||
@@ -91,48 +89,46 @@ const renderOrigin = (context: CanvasRenderingContext2D, zoom: number) => {
|
|||||||
|
|
||||||
const _renderBinding = (
|
const _renderBinding = (
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
binding: FixedPointBinding | PointBinding,
|
binding: FixedPointBinding,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
zoom: number,
|
zoom: number,
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
color: string,
|
color: string,
|
||||||
) => {
|
) => {
|
||||||
if (isFixedPointBinding(binding)) {
|
if (!binding.fixedPoint) {
|
||||||
if (!binding.fixedPoint) {
|
console.warn("Binding must have a fixedPoint");
|
||||||
console.warn("Binding must have a fixedPoint");
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bindable = elementsMap.get(
|
|
||||||
binding.elementId,
|
|
||||||
) as ExcalidrawBindableElement;
|
|
||||||
const [x, y] = getGlobalFixedPointForBindableElement(
|
|
||||||
binding.fixedPoint,
|
|
||||||
bindable,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
context.save();
|
|
||||||
context.strokeStyle = color;
|
|
||||||
context.lineWidth = 1;
|
|
||||||
context.beginPath();
|
|
||||||
context.moveTo(x * zoom, y * zoom);
|
|
||||||
context.bezierCurveTo(
|
|
||||||
x * zoom - width,
|
|
||||||
y * zoom - height,
|
|
||||||
x * zoom - width,
|
|
||||||
y * zoom + height,
|
|
||||||
x * zoom,
|
|
||||||
y * zoom,
|
|
||||||
);
|
|
||||||
context.stroke();
|
|
||||||
context.restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bindable = elementsMap.get(
|
||||||
|
binding.elementId,
|
||||||
|
) as ExcalidrawBindableElement;
|
||||||
|
const [x, y] = getGlobalFixedPointForBindableElement(
|
||||||
|
binding.fixedPoint,
|
||||||
|
bindable,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
context.save();
|
||||||
|
context.strokeStyle = color;
|
||||||
|
context.lineWidth = 1;
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(x * zoom, y * zoom);
|
||||||
|
context.bezierCurveTo(
|
||||||
|
x * zoom - width,
|
||||||
|
y * zoom - height,
|
||||||
|
x * zoom - width,
|
||||||
|
y * zoom + height,
|
||||||
|
x * zoom,
|
||||||
|
y * zoom,
|
||||||
|
);
|
||||||
|
context.stroke();
|
||||||
|
context.restore();
|
||||||
};
|
};
|
||||||
|
|
||||||
const _renderBindableBinding = (
|
const _renderBindableBinding = (
|
||||||
binding: FixedPointBinding | PointBinding,
|
binding: FixedPointBinding,
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
zoom: number,
|
zoom: number,
|
||||||
@@ -140,37 +136,35 @@ const _renderBindableBinding = (
|
|||||||
height: number,
|
height: number,
|
||||||
color: string,
|
color: string,
|
||||||
) => {
|
) => {
|
||||||
if (isFixedPointBinding(binding)) {
|
const bindable = elementsMap.get(
|
||||||
const bindable = elementsMap.get(
|
binding.elementId,
|
||||||
binding.elementId,
|
) as ExcalidrawBindableElement;
|
||||||
) as ExcalidrawBindableElement;
|
if (!binding.fixedPoint) {
|
||||||
if (!binding.fixedPoint) {
|
console.warn("Binding must have a fixedPoint");
|
||||||
console.warn("Binding must have a fixedPoint");
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [x, y] = getGlobalFixedPointForBindableElement(
|
|
||||||
binding.fixedPoint,
|
|
||||||
bindable,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
context.save();
|
|
||||||
context.strokeStyle = color;
|
|
||||||
context.lineWidth = 1;
|
|
||||||
context.beginPath();
|
|
||||||
context.moveTo(x * zoom, y * zoom);
|
|
||||||
context.bezierCurveTo(
|
|
||||||
x * zoom + width,
|
|
||||||
y * zoom + height,
|
|
||||||
x * zoom + width,
|
|
||||||
y * zoom - height,
|
|
||||||
x * zoom,
|
|
||||||
y * zoom,
|
|
||||||
);
|
|
||||||
context.stroke();
|
|
||||||
context.restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [x, y] = getGlobalFixedPointForBindableElement(
|
||||||
|
binding.fixedPoint,
|
||||||
|
bindable,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
context.save();
|
||||||
|
context.strokeStyle = color;
|
||||||
|
context.lineWidth = 1;
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(x * zoom, y * zoom);
|
||||||
|
context.bezierCurveTo(
|
||||||
|
x * zoom + width,
|
||||||
|
y * zoom + height,
|
||||||
|
x * zoom + width,
|
||||||
|
y * zoom - height,
|
||||||
|
x * zoom,
|
||||||
|
y * zoom,
|
||||||
|
);
|
||||||
|
context.stroke();
|
||||||
|
context.restore();
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderBindings = (
|
const renderBindings = (
|
||||||
@@ -197,12 +191,12 @@ const renderBindings = (
|
|||||||
|
|
||||||
_renderBinding(
|
_renderBinding(
|
||||||
context,
|
context,
|
||||||
element.startBinding as FixedPointBinding,
|
element.startBinding,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
zoom,
|
||||||
dim,
|
dim,
|
||||||
dim,
|
dim,
|
||||||
"red",
|
element.startBinding?.mode === "orbit" ? "red" : "black",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +215,7 @@ const renderBindings = (
|
|||||||
zoom,
|
zoom,
|
||||||
dim,
|
dim,
|
||||||
dim,
|
dim,
|
||||||
"red",
|
element.endBinding?.mode === "orbit" ? "red" : "black",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
DEFAULT_SIDEBAR,
|
DEFAULT_SIDEBAR,
|
||||||
debounce,
|
debounce,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
import { clearElementsForLocalStorage } from "@excalidraw/element";
|
|
||||||
import {
|
import {
|
||||||
createStore,
|
createStore,
|
||||||
entries,
|
entries,
|
||||||
@@ -28,6 +27,7 @@ import {
|
|||||||
} from "idb-keyval";
|
} from "idb-keyval";
|
||||||
|
|
||||||
import { appJotaiStore, atom } from "excalidraw-app/app-jotai";
|
import { appJotaiStore, atom } from "excalidraw-app/app-jotai";
|
||||||
|
import { getNonDeletedElements } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { LibraryPersistedData } from "@excalidraw/excalidraw/data/library";
|
import type { LibraryPersistedData } from "@excalidraw/excalidraw/data/library";
|
||||||
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
|
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
|
||||||
@@ -88,7 +88,7 @@ const saveDataStateToLocalStorage = (
|
|||||||
|
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
|
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
|
||||||
JSON.stringify(clearElementsForLocalStorage(elements)),
|
JSON.stringify(getNonDeletedElements(elements)),
|
||||||
);
|
);
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
|
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ const decryptElements = async (
|
|||||||
data: FirebaseStoredScene,
|
data: FirebaseStoredScene,
|
||||||
roomKey: string,
|
roomKey: string,
|
||||||
): Promise<readonly ExcalidrawElement[]> => {
|
): Promise<readonly ExcalidrawElement[]> => {
|
||||||
const ciphertext = data.ciphertext.toUint8Array();
|
const ciphertext = data.ciphertext.toUint8Array() as Uint8Array<ArrayBuffer>;
|
||||||
const iv = data.iv.toUint8Array();
|
const iv = data.iv.toUint8Array() as Uint8Array<ArrayBuffer>;
|
||||||
|
|
||||||
const decrypted = await decryptData(iv, ciphertext, roomKey);
|
const decrypted = await decryptData(iv, ciphertext, roomKey);
|
||||||
const decodedData = new TextDecoder("utf-8").decode(
|
const decodedData = new TextDecoder("utf-8").decode(
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
clearAppStateForLocalStorage,
|
clearAppStateForLocalStorage,
|
||||||
getDefaultAppState,
|
getDefaultAppState,
|
||||||
} from "@excalidraw/excalidraw/appState";
|
} from "@excalidraw/excalidraw/appState";
|
||||||
import { clearElementsForLocalStorage } from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
import type { AppState } from "@excalidraw/excalidraw/types";
|
||||||
@@ -50,7 +49,7 @@ export const importFromLocalStorage = () => {
|
|||||||
let elements: ExcalidrawElement[] = [];
|
let elements: ExcalidrawElement[] = [];
|
||||||
if (savedElements) {
|
if (savedElements) {
|
||||||
try {
|
try {
|
||||||
elements = clearElementsForLocalStorage(JSON.parse(savedElements));
|
elements = JSON.parse(savedElements);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
// Do nothing because elements array is already empty
|
// Do nothing because elements array is already empty
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getFeatureFlag } from "@excalidraw/common";
|
||||||
import * as Sentry from "@sentry/browser";
|
import * as Sentry from "@sentry/browser";
|
||||||
import callsites from "callsites";
|
import callsites from "callsites";
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ Sentry.init({
|
|||||||
Sentry.captureConsoleIntegration({
|
Sentry.captureConsoleIntegration({
|
||||||
levels: ["error"],
|
levels: ["error"],
|
||||||
}),
|
}),
|
||||||
|
Sentry.featureFlagsIntegration(),
|
||||||
],
|
],
|
||||||
beforeSend(event) {
|
beforeSend(event) {
|
||||||
if (event.request?.url) {
|
if (event.request?.url) {
|
||||||
@@ -79,3 +81,14 @@ Sentry.init({
|
|||||||
return event;
|
return event;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const flagsIntegration =
|
||||||
|
Sentry.getClient()?.getIntegrationByName<Sentry.FeatureFlagsIntegration>(
|
||||||
|
"FeatureFlags",
|
||||||
|
);
|
||||||
|
if (flagsIntegration) {
|
||||||
|
flagsIntegration.addFeatureFlag(
|
||||||
|
"COMPLEX_BINDINGS",
|
||||||
|
getFeatureFlag("COMPLEX_BINDINGS"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@
|
|||||||
"prettier": "2.6.2",
|
"prettier": "2.6.2",
|
||||||
"rewire": "6.0.0",
|
"rewire": "6.0.0",
|
||||||
"rimraf": "^5.0.0",
|
"rimraf": "^5.0.0",
|
||||||
"typescript": "4.9.4",
|
"typescript": "5.9.3",
|
||||||
"vite": "5.0.12",
|
"vite": "5.0.12",
|
||||||
"vite-plugin-checker": "0.7.2",
|
"vite-plugin-checker": "0.7.2",
|
||||||
"vite-plugin-ejs": "1.7.0",
|
"vite-plugin-ejs": "1.7.0",
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* x and y position of top left corner, x and y position of bottom right corner
|
||||||
|
*/
|
||||||
|
export type Bounds = readonly [
|
||||||
|
minX: number,
|
||||||
|
minY: number,
|
||||||
|
maxX: number,
|
||||||
|
maxY: number,
|
||||||
|
];
|
||||||
|
|
||||||
|
export const isBounds = (box: unknown): box is Bounds =>
|
||||||
|
Array.isArray(box) &&
|
||||||
|
box.length === 4 &&
|
||||||
|
typeof box[0] === "number" &&
|
||||||
|
typeof box[1] === "number" &&
|
||||||
|
typeof box[2] === "number" &&
|
||||||
|
typeof box[3] === "number";
|
||||||
@@ -105,8 +105,16 @@ export const CLASSES = {
|
|||||||
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
|
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
|
||||||
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
||||||
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
||||||
|
FRAME_NAME: "frame-name",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const FONT_SIZES = {
|
||||||
|
sm: 16,
|
||||||
|
md: 20,
|
||||||
|
lg: 28,
|
||||||
|
xl: 36,
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
|
export const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
|
||||||
export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
|
export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
|
||||||
|
|
||||||
@@ -498,6 +506,8 @@ export const LINE_POLYGON_POINT_MERGE_DISTANCE = 20;
|
|||||||
|
|
||||||
export const DOUBLE_TAP_POSITION_THRESHOLD = 35;
|
export const DOUBLE_TAP_POSITION_THRESHOLD = 35;
|
||||||
|
|
||||||
|
export const BIND_MODE_TIMEOUT = 700; // ms
|
||||||
|
|
||||||
// glass background for mobile action buttons
|
// glass background for mobile action buttons
|
||||||
export const MOBILE_ACTION_BUTTON_BG = {
|
export const MOBILE_ACTION_BUTTON_BG = {
|
||||||
background: "var(--mobile-action-button-bg)",
|
background: "var(--mobile-action-button-bg)",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from "./binary-heap";
|
export * from "./binary-heap";
|
||||||
|
export * from "./bounds";
|
||||||
export * from "./colors";
|
export * from "./colors";
|
||||||
export * from "./constants";
|
export * from "./constants";
|
||||||
export * from "./font-metadata";
|
export * from "./font-metadata";
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import { average } from "@excalidraw/math";
|
import { average } from "@excalidraw/math";
|
||||||
|
|
||||||
import type {
|
import type { FontFamilyValues, FontString } from "@excalidraw/element/types";
|
||||||
ExcalidrawBindableElement,
|
|
||||||
FontFamilyValues,
|
|
||||||
FontString,
|
|
||||||
} from "@excalidraw/element/types";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ActiveTool,
|
ActiveTool,
|
||||||
@@ -382,6 +378,10 @@ export const removeSelection = () => {
|
|||||||
|
|
||||||
export const distance = (x: number, y: number) => Math.abs(x - y);
|
export const distance = (x: number, y: number) => Math.abs(x - y);
|
||||||
|
|
||||||
|
export const isSelectionLikeTool = (type: ToolType | "custom") => {
|
||||||
|
return type === "selection" || type === "lasso";
|
||||||
|
};
|
||||||
|
|
||||||
export const updateActiveTool = (
|
export const updateActiveTool = (
|
||||||
appState: Pick<AppState, "activeTool">,
|
appState: Pick<AppState, "activeTool">,
|
||||||
data: ((
|
data: ((
|
||||||
@@ -558,9 +558,6 @@ export const isTransparent = (color: string) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isBindingFallthroughEnabled = (el: ExcalidrawBindableElement) =>
|
|
||||||
el.fillStyle !== "solid" || isTransparent(el.backgroundColor);
|
|
||||||
|
|
||||||
export type ResolvablePromise<T> = Promise<T> & {
|
export type ResolvablePromise<T> = Promise<T> & {
|
||||||
resolve: [T] extends [undefined]
|
resolve: [T] extends [undefined]
|
||||||
? (value?: MaybePromise<Awaited<T>>) => void
|
? (value?: MaybePromise<Awaited<T>>) => void
|
||||||
@@ -1270,3 +1267,47 @@ export const reduceToCommonValue = <T, R = T>(
|
|||||||
|
|
||||||
return commonValue;
|
return commonValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type FEATURE_FLAGS = {
|
||||||
|
COMPLEX_BINDINGS: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const FEATURE_FLAGS_STORAGE_KEY = "excalidraw-feature-flags";
|
||||||
|
const DEFAULT_FEATURE_FLAGS: FEATURE_FLAGS = {
|
||||||
|
COMPLEX_BINDINGS: false,
|
||||||
|
};
|
||||||
|
let featureFlags: FEATURE_FLAGS | null = null;
|
||||||
|
|
||||||
|
export const getFeatureFlag = <F extends keyof FEATURE_FLAGS>(
|
||||||
|
flag: F,
|
||||||
|
): FEATURE_FLAGS[F] => {
|
||||||
|
if (!featureFlags) {
|
||||||
|
try {
|
||||||
|
const serializedFlags = localStorage.getItem(FEATURE_FLAGS_STORAGE_KEY);
|
||||||
|
if (serializedFlags) {
|
||||||
|
const flags = JSON.parse(serializedFlags);
|
||||||
|
featureFlags = flags ?? DEFAULT_FEATURE_FLAGS;
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (featureFlags || DEFAULT_FEATURE_FLAGS)[flag];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setFeatureFlag = <F extends keyof FEATURE_FLAGS>(
|
||||||
|
flag: F,
|
||||||
|
value: FEATURE_FLAGS[F],
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
featureFlags = {
|
||||||
|
...(featureFlags || DEFAULT_FEATURE_FLAGS),
|
||||||
|
[flag]: value,
|
||||||
|
};
|
||||||
|
localStorage.setItem(
|
||||||
|
FEATURE_FLAGS_STORAGE_KEY,
|
||||||
|
JSON.stringify(featureFlags),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("unable to set feature flag", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ import {
|
|||||||
type LocalPoint,
|
type LocalPoint,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import { isBounds } from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { Curve } from "@excalidraw/math";
|
import type { Curve } from "@excalidraw/math";
|
||||||
import type { LineSegment } from "@excalidraw/utils";
|
import type { LineSegment } from "@excalidraw/utils";
|
||||||
|
|
||||||
import type { Bounds } from "@excalidraw/element";
|
import { type Bounds, isBounds } from "./bounds";
|
||||||
|
|
||||||
// The global data holder to collect the debug operations
|
// The global data holder to collect the debug operations
|
||||||
declare global {
|
declare global {
|
||||||
@@ -139,7 +137,7 @@ export const debugDrawPoints = (
|
|||||||
}: {
|
}: {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
points: LocalPoint[];
|
points: readonly LocalPoint[];
|
||||||
},
|
},
|
||||||
options?: any,
|
options?: any,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
+70
-43
@@ -88,8 +88,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s
|
|||||||
"endArrowhead": "arrow",
|
"endArrowhead": "arrow",
|
||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "ellipse-1",
|
"elementId": "ellipse-1",
|
||||||
"focus": -0.007519379844961235,
|
"fixedPoint": [
|
||||||
"gap": 11.562288374879595,
|
0.04,
|
||||||
|
0.4633333333333333,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
@@ -98,7 +101,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -118,8 +120,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s
|
|||||||
"startArrowhead": null,
|
"startArrowhead": null,
|
||||||
"startBinding": {
|
"startBinding": {
|
||||||
"elementId": "id49",
|
"elementId": "id49",
|
||||||
"focus": -0.0813953488372095,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
1,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"strokeColor": "#1864ab",
|
"strokeColor": "#1864ab",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
@@ -144,8 +149,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s
|
|||||||
"endArrowhead": "arrow",
|
"endArrowhead": "arrow",
|
||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "ellipse-1",
|
"elementId": "ellipse-1",
|
||||||
"focus": 0.10666666666666667,
|
"fixedPoint": [
|
||||||
"gap": 3.8343264684446097,
|
-0.01,
|
||||||
|
0.44666666666666666,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
@@ -154,7 +162,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a3",
|
"index": "a3",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -174,8 +181,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing s
|
|||||||
"startArrowhead": null,
|
"startArrowhead": null,
|
||||||
"startBinding": {
|
"startBinding": {
|
||||||
"elementId": "diamond-1",
|
"elementId": "diamond-1",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 4.535423522449215,
|
0.9357142857142857,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"strokeColor": "#e67700",
|
"strokeColor": "#e67700",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
@@ -334,8 +344,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
|
|||||||
"endArrowhead": "arrow",
|
"endArrowhead": "arrow",
|
||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "text-2",
|
"elementId": "text-2",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 16,
|
-2.05,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
@@ -344,7 +357,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -364,8 +376,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
|
|||||||
"startArrowhead": null,
|
"startArrowhead": null,
|
||||||
"startBinding": {
|
"startBinding": {
|
||||||
"elementId": "text-1",
|
"elementId": "text-1",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
1,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"strokeColor": "#1e1e1e",
|
"strokeColor": "#1e1e1e",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
@@ -436,8 +451,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
|
|||||||
"endArrowhead": "arrow",
|
"endArrowhead": "arrow",
|
||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "id42",
|
"elementId": "id42",
|
||||||
"focus": -0,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
0,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
@@ -446,7 +464,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -466,8 +483,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
|
|||||||
"startArrowhead": null,
|
"startArrowhead": null,
|
||||||
"startBinding": {
|
"startBinding": {
|
||||||
"elementId": "id41",
|
"elementId": "id41",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
1,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"strokeColor": "#1e1e1e",
|
"strokeColor": "#1e1e1e",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
@@ -612,8 +632,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
|
|||||||
"endArrowhead": "arrow",
|
"endArrowhead": "arrow",
|
||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "id46",
|
"elementId": "id46",
|
||||||
"focus": -0,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
0,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
@@ -622,7 +645,6 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -642,8 +664,11 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
|
|||||||
"startArrowhead": null,
|
"startArrowhead": null,
|
||||||
"startBinding": {
|
"startBinding": {
|
||||||
"elementId": "id45",
|
"elementId": "id45",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
1,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"strokeColor": "#1e1e1e",
|
"strokeColor": "#1e1e1e",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
@@ -839,7 +864,6 @@ exports[`Test Transform > should transform linear elements 1`] = `
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -887,7 +911,6 @@ exports[`Test Transform > should transform linear elements 2`] = `
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a1",
|
"index": "a1",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -934,7 +957,6 @@ exports[`Test Transform > should transform linear elements 3`] = `
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -982,7 +1004,6 @@ exports[`Test Transform > should transform linear elements 4`] = `
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a3",
|
"index": "a3",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -1476,8 +1497,11 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"endArrowhead": "arrow",
|
"endArrowhead": "arrow",
|
||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "Alice",
|
"elementId": "Alice",
|
||||||
"focus": -0,
|
"fixedPoint": [
|
||||||
"gap": 5.299874999999986,
|
-0.07542628418945944,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
@@ -1486,7 +1510,6 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a4",
|
"index": "a4",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -1508,8 +1531,11 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"startArrowhead": null,
|
"startArrowhead": null,
|
||||||
"startBinding": {
|
"startBinding": {
|
||||||
"elementId": "Bob",
|
"elementId": "Bob",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
1.000004978564514,
|
||||||
|
0.5001,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"strokeColor": "#1e1e1e",
|
"strokeColor": "#1e1e1e",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
@@ -1539,8 +1565,11 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"endArrowhead": "arrow",
|
"endArrowhead": "arrow",
|
||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "B",
|
"elementId": "B",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 32,
|
0.46387050630528887,
|
||||||
|
0.48466257668711654,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
@@ -1549,7 +1578,6 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a5",
|
"index": "a5",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -1567,8 +1595,11 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"startArrowhead": null,
|
"startArrowhead": null,
|
||||||
"startBinding": {
|
"startBinding": {
|
||||||
"elementId": "Bob",
|
"elementId": "Bob",
|
||||||
"focus": 0,
|
"fixedPoint": [
|
||||||
"gap": 1,
|
0.39381496335223337,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"mode": "orbit",
|
||||||
},
|
},
|
||||||
"strokeColor": "#1e1e1e",
|
"strokeColor": "#1e1e1e",
|
||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
@@ -1858,7 +1889,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -1911,7 +1941,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a1",
|
"index": "a1",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -1964,7 +1993,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
@@ -2017,7 +2045,6 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
"index": "a3",
|
"index": "a3",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"lastCommittedPoint": null,
|
|
||||||
"link": null,
|
"link": null,
|
||||||
"locked": false,
|
"locked": false,
|
||||||
"opacity": 100,
|
"opacity": 100,
|
||||||
+7
-12
@@ -1,11 +1,12 @@
|
|||||||
import { pointFrom } from "@excalidraw/math";
|
import { pointFrom } from "@excalidraw/math";
|
||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
|
|
||||||
import type { ExcalidrawArrowElement } from "@excalidraw/element/types";
|
import {
|
||||||
|
convertToExcalidrawElements,
|
||||||
|
type ExcalidrawElementSkeleton,
|
||||||
|
} from "../transform";
|
||||||
|
|
||||||
import { convertToExcalidrawElements } from "./transform";
|
import type { ExcalidrawArrowElement } from "../types";
|
||||||
|
|
||||||
import type { ExcalidrawElementSkeleton } from "./transform";
|
|
||||||
|
|
||||||
const opts = { regenerateIds: false };
|
const opts = { regenerateIds: false };
|
||||||
|
|
||||||
@@ -432,12 +433,9 @@ describe("Test Transform", () => {
|
|||||||
boundElements: [{ id: text.id, type: "text" }],
|
boundElements: [{ id: text.id, type: "text" }],
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: rectangle.id,
|
elementId: rectangle.id,
|
||||||
focus: 0,
|
|
||||||
gap: 1,
|
|
||||||
},
|
},
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: ellipse.id,
|
elementId: ellipse.id,
|
||||||
focus: -0,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -517,12 +515,9 @@ describe("Test Transform", () => {
|
|||||||
boundElements: [{ id: text1.id, type: "text" }],
|
boundElements: [{ id: text1.id, type: "text" }],
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: text2.id,
|
elementId: text2.id,
|
||||||
focus: 0,
|
|
||||||
gap: 1,
|
|
||||||
},
|
},
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: text3.id,
|
elementId: text3.id,
|
||||||
focus: -0,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -780,8 +775,8 @@ describe("Test Transform", () => {
|
|||||||
const [arrow, rect] = excalidrawElements;
|
const [arrow, rect] = excalidrawElements;
|
||||||
expect((arrow as ExcalidrawArrowElement).endBinding).toStrictEqual({
|
expect((arrow as ExcalidrawArrowElement).endBinding).toStrictEqual({
|
||||||
elementId: "rect-1",
|
elementId: "rect-1",
|
||||||
focus: -0,
|
fixedPoint: [-2.05, 0.5001],
|
||||||
gap: 25,
|
mode: "orbit",
|
||||||
});
|
});
|
||||||
expect(rect.boundElements).toStrictEqual([
|
expect(rect.boundElements).toStrictEqual([
|
||||||
{
|
{
|
||||||
+1703
-1234
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@ import rough from "roughjs/bin/rough";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
arrayToMap,
|
arrayToMap,
|
||||||
|
type Bounds,
|
||||||
invariant,
|
invariant,
|
||||||
rescalePoints,
|
rescalePoints,
|
||||||
sizeOf,
|
sizeOf,
|
||||||
@@ -78,16 +79,6 @@ export type RectangleBox = {
|
|||||||
|
|
||||||
type MaybeQuadraticSolution = [number | null, number | null] | false;
|
type MaybeQuadraticSolution = [number | null, number | null] | false;
|
||||||
|
|
||||||
/**
|
|
||||||
* x and y position of top left corner, x and y position of bottom right corner
|
|
||||||
*/
|
|
||||||
export type Bounds = readonly [
|
|
||||||
minX: number,
|
|
||||||
minY: number,
|
|
||||||
maxX: number,
|
|
||||||
maxY: number,
|
|
||||||
];
|
|
||||||
|
|
||||||
export type SceneBounds = readonly [
|
export type SceneBounds = readonly [
|
||||||
sceneX: number,
|
sceneX: number,
|
||||||
sceneY: number,
|
sceneY: number,
|
||||||
@@ -1276,6 +1267,13 @@ export const elementCenterPoint = (
|
|||||||
xOffset: number = 0,
|
xOffset: number = 0,
|
||||||
yOffset: number = 0,
|
yOffset: number = 0,
|
||||||
) => {
|
) => {
|
||||||
|
if (isLinearElement(element)) {
|
||||||
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
||||||
|
const [x, y] = pointFrom<GlobalPoint>((x1 + x2) / 2, (y1 + y2) / 2);
|
||||||
|
|
||||||
|
return pointFrom<GlobalPoint>(x + xOffset, y + yOffset);
|
||||||
|
}
|
||||||
|
|
||||||
const [x, y] = getCenterForBounds(getElementBounds(element, elementsMap));
|
const [x, y] = getCenterForBounds(getElementBounds(element, elementsMap));
|
||||||
|
|
||||||
return pointFrom<GlobalPoint>(x + xOffset, y + yOffset);
|
return pointFrom<GlobalPoint>(x + xOffset, y + yOffset);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isTransparent } from "@excalidraw/common";
|
import { invariant, isTransparent, type Bounds } from "@excalidraw/common";
|
||||||
import {
|
import {
|
||||||
curveIntersectLineSegment,
|
curveIntersectLineSegment,
|
||||||
isPointWithinBounds,
|
isPointWithinBounds,
|
||||||
@@ -29,15 +29,18 @@ import type { FrameNameBounds } from "@excalidraw/excalidraw/types";
|
|||||||
|
|
||||||
import { isPathALoop } from "./utils";
|
import { isPathALoop } from "./utils";
|
||||||
import {
|
import {
|
||||||
type Bounds,
|
|
||||||
doBoundsIntersect,
|
doBoundsIntersect,
|
||||||
elementCenterPoint,
|
elementCenterPoint,
|
||||||
getCenterForBounds,
|
getCenterForBounds,
|
||||||
getCubicBezierCurveBound,
|
getCubicBezierCurveBound,
|
||||||
|
getDiamondPoints,
|
||||||
getElementBounds,
|
getElementBounds,
|
||||||
|
pointInsideBounds,
|
||||||
} from "./bounds";
|
} from "./bounds";
|
||||||
import {
|
import {
|
||||||
hasBoundTextElement,
|
hasBoundTextElement,
|
||||||
|
isBindableElement,
|
||||||
|
isFrameLikeElement,
|
||||||
isFreeDrawElement,
|
isFreeDrawElement,
|
||||||
isIframeLikeElement,
|
isIframeLikeElement,
|
||||||
isImageElement,
|
isImageElement,
|
||||||
@@ -58,12 +61,17 @@ import { distanceToElement } from "./distance";
|
|||||||
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
|
ExcalidrawBindableElement,
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawEllipseElement,
|
ExcalidrawEllipseElement,
|
||||||
ExcalidrawFreeDrawElement,
|
ExcalidrawFreeDrawElement,
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
ExcalidrawRectanguloidElement,
|
ExcalidrawRectanguloidElement,
|
||||||
|
NonDeleted,
|
||||||
|
NonDeletedExcalidrawElement,
|
||||||
|
NonDeletedSceneElementsMap,
|
||||||
|
Ordered,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
export const shouldTestInside = (element: ExcalidrawElement) => {
|
export const shouldTestInside = (element: ExcalidrawElement) => {
|
||||||
@@ -94,6 +102,7 @@ export type HitTestArgs = {
|
|||||||
threshold: number;
|
threshold: number;
|
||||||
elementsMap: ElementsMap;
|
elementsMap: ElementsMap;
|
||||||
frameNameBound?: FrameNameBounds | null;
|
frameNameBound?: FrameNameBounds | null;
|
||||||
|
overrideShouldTestInside?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hitElementItself = ({
|
export const hitElementItself = ({
|
||||||
@@ -102,6 +111,7 @@ export const hitElementItself = ({
|
|||||||
threshold,
|
threshold,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
frameNameBound = null,
|
frameNameBound = null,
|
||||||
|
overrideShouldTestInside = false,
|
||||||
}: HitTestArgs) => {
|
}: HitTestArgs) => {
|
||||||
// Hit test against a frame's name
|
// Hit test against a frame's name
|
||||||
const hitFrameName = frameNameBound
|
const hitFrameName = frameNameBound
|
||||||
@@ -134,7 +144,9 @@ export const hitElementItself = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do the precise (and relatively costly) hit test
|
// Do the precise (and relatively costly) hit test
|
||||||
const hitElement = shouldTestInside(element)
|
const hitElement = (
|
||||||
|
overrideShouldTestInside ? true : shouldTestInside(element)
|
||||||
|
)
|
||||||
? // Since `inShape` tests STRICTLY againt the insides of a shape
|
? // Since `inShape` tests STRICTLY againt the insides of a shape
|
||||||
// we would need `onShape` as well to include the "borders"
|
// we would need `onShape` as well to include the "borders"
|
||||||
isPointInElement(point, element, elementsMap) ||
|
isPointInElement(point, element, elementsMap) ||
|
||||||
@@ -193,6 +205,116 @@ export const hitElementBoundText = (
|
|||||||
return isPointInElement(point, boundTextElement, elementsMap);
|
return isPointInElement(point, boundTextElement, elementsMap);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const bindingBorderTest = (
|
||||||
|
element: NonDeleted<ExcalidrawBindableElement>,
|
||||||
|
[x, y]: Readonly<GlobalPoint>,
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
tolerance: number = 0,
|
||||||
|
): boolean => {
|
||||||
|
const p = pointFrom<GlobalPoint>(x, y);
|
||||||
|
const shouldTestInside =
|
||||||
|
// disable fullshape snapping for frame elements so we
|
||||||
|
// can bind to frame children
|
||||||
|
!isFrameLikeElement(element);
|
||||||
|
|
||||||
|
// PERF: Run a cheap test to see if the binding element
|
||||||
|
// is even close to the element
|
||||||
|
const t = Math.max(1, tolerance);
|
||||||
|
const bounds = [x - t, y - t, x + t, y + t] as Bounds;
|
||||||
|
const elementBounds = getElementBounds(element, elementsMap);
|
||||||
|
if (!doBoundsIntersect(bounds, elementBounds)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the element is inside a frame, we should clip the element
|
||||||
|
if (element.frameId) {
|
||||||
|
const enclosingFrame = elementsMap.get(element.frameId);
|
||||||
|
if (enclosingFrame && isFrameLikeElement(enclosingFrame)) {
|
||||||
|
const enclosingFrameBounds = getElementBounds(
|
||||||
|
enclosingFrame,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
if (!pointInsideBounds(p, enclosingFrameBounds)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do the intersection test against the element since it's close enough
|
||||||
|
const intersections = intersectElementWithLineSegment(
|
||||||
|
element,
|
||||||
|
elementsMap,
|
||||||
|
lineSegment(elementCenterPoint(element, elementsMap), p),
|
||||||
|
);
|
||||||
|
const distance = distanceToElement(element, elementsMap, p);
|
||||||
|
|
||||||
|
return shouldTestInside
|
||||||
|
? intersections.length === 0 || distance <= tolerance
|
||||||
|
: intersections.length > 0 && distance <= t;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getAllHoveredElementAtPoint = (
|
||||||
|
point: Readonly<GlobalPoint>,
|
||||||
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
toleranceFn?: (element: ExcalidrawBindableElement) => number,
|
||||||
|
): NonDeleted<ExcalidrawBindableElement>[] => {
|
||||||
|
const candidateElements: NonDeleted<ExcalidrawBindableElement>[] = [];
|
||||||
|
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||||
|
// because array is ordered from lower z-index to highest and we want element z-index
|
||||||
|
// with higher z-index
|
||||||
|
for (let index = elements.length - 1; index >= 0; --index) {
|
||||||
|
const element = elements[index];
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
!element.isDeleted,
|
||||||
|
"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
isBindableElement(element, false) &&
|
||||||
|
bindingBorderTest(element, point, elementsMap, toleranceFn?.(element))
|
||||||
|
) {
|
||||||
|
candidateElements.push(element);
|
||||||
|
|
||||||
|
if (!isTransparent(element.backgroundColor)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidateElements;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getHoveredElementForBinding = (
|
||||||
|
point: Readonly<GlobalPoint>,
|
||||||
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
toleranceFn?: (element: ExcalidrawBindableElement) => number,
|
||||||
|
): NonDeleted<ExcalidrawBindableElement> | null => {
|
||||||
|
const candidateElements = getAllHoveredElementAtPoint(
|
||||||
|
point,
|
||||||
|
elements,
|
||||||
|
elementsMap,
|
||||||
|
toleranceFn,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!candidateElements || candidateElements.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (candidateElements.length === 1) {
|
||||||
|
return candidateElements[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer smaller shapes
|
||||||
|
return candidateElements
|
||||||
|
.sort(
|
||||||
|
(a, b) => b.width ** 2 + b.height ** 2 - (a.width ** 2 + a.height ** 2),
|
||||||
|
)
|
||||||
|
.pop() as NonDeleted<ExcalidrawBindableElement>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intersect a line with an element for binding test
|
* Intersect a line with an element for binding test
|
||||||
*
|
*
|
||||||
@@ -554,3 +676,61 @@ export const isPointInElement = (
|
|||||||
|
|
||||||
return intersections.length % 2 === 1;
|
return intersections.length % 2 === 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isBindableElementInsideOtherBindable = (
|
||||||
|
innerElement: ExcalidrawBindableElement,
|
||||||
|
outerElement: ExcalidrawBindableElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
): boolean => {
|
||||||
|
// Get corner points of the inner element based on its type
|
||||||
|
const getCornerPoints = (
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
offset: number,
|
||||||
|
): GlobalPoint[] => {
|
||||||
|
const { x, y, width, height, angle } = element;
|
||||||
|
const center = elementCenterPoint(element, elementsMap);
|
||||||
|
|
||||||
|
if (element.type === "diamond") {
|
||||||
|
// Diamond has 4 corner points at the middle of each side
|
||||||
|
const [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY] =
|
||||||
|
getDiamondPoints(element);
|
||||||
|
const corners: GlobalPoint[] = [
|
||||||
|
pointFrom(x + topX, y + topY - offset), // top
|
||||||
|
pointFrom(x + rightX + offset, y + rightY), // right
|
||||||
|
pointFrom(x + bottomX, y + bottomY + offset), // bottom
|
||||||
|
pointFrom(x + leftX - offset, y + leftY), // left
|
||||||
|
];
|
||||||
|
return corners.map((corner) => pointRotateRads(corner, center, angle));
|
||||||
|
}
|
||||||
|
if (element.type === "ellipse") {
|
||||||
|
// For ellipse, test points at the extremes (top, right, bottom, left)
|
||||||
|
const cx = x + width / 2;
|
||||||
|
const cy = y + height / 2;
|
||||||
|
const rx = width / 2;
|
||||||
|
const ry = height / 2;
|
||||||
|
const corners: GlobalPoint[] = [
|
||||||
|
pointFrom(cx, cy - ry - offset), // top
|
||||||
|
pointFrom(cx + rx + offset, cy), // right
|
||||||
|
pointFrom(cx, cy + ry + offset), // bottom
|
||||||
|
pointFrom(cx - rx - offset, cy), // left
|
||||||
|
];
|
||||||
|
return corners.map((corner) => pointRotateRads(corner, center, angle));
|
||||||
|
}
|
||||||
|
// Rectangle and other rectangular shapes (image, text, etc.)
|
||||||
|
const corners: GlobalPoint[] = [
|
||||||
|
pointFrom(x - offset, y - offset), // top-left
|
||||||
|
pointFrom(x + width + offset, y - offset), // top-right
|
||||||
|
pointFrom(x + width + offset, y + height + offset), // bottom-right
|
||||||
|
pointFrom(x - offset, y + height + offset), // bottom-left
|
||||||
|
];
|
||||||
|
return corners.map((corner) => pointRotateRads(corner, center, angle));
|
||||||
|
};
|
||||||
|
|
||||||
|
const offset = (-1 * Math.max(innerElement.width, innerElement.height)) / 20; // 5% offset
|
||||||
|
const innerCorners = getCornerPoints(innerElement, offset);
|
||||||
|
|
||||||
|
// Check if all corner points of the inner element are inside the outer element
|
||||||
|
return innerCorners.every((corner) =>
|
||||||
|
isPointInElement(corner, outerElement, elementsMap),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ export const hasStrokeColor = (type: ElementOrToolType) =>
|
|||||||
type === "freedraw" ||
|
type === "freedraw" ||
|
||||||
type === "arrow" ||
|
type === "arrow" ||
|
||||||
type === "line" ||
|
type === "line" ||
|
||||||
type === "text";
|
type === "text" ||
|
||||||
|
type === "embeddable";
|
||||||
|
|
||||||
export const hasStrokeWidth = (type: ElementOrToolType) =>
|
export const hasStrokeWidth = (type: ElementOrToolType) =>
|
||||||
type === "rectangle" ||
|
type === "rectangle" ||
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
|
type Bounds,
|
||||||
TEXT_AUTOWRAP_THRESHOLD,
|
TEXT_AUTOWRAP_THRESHOLD,
|
||||||
getGridPoint,
|
getGridPoint,
|
||||||
getFontString,
|
getFontString,
|
||||||
|
DRAGGING_THRESHOLD,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -13,7 +15,7 @@ import type {
|
|||||||
|
|
||||||
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
|
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { updateBoundElements } from "./binding";
|
import { unbindBindingElement, updateBoundElements } from "./binding";
|
||||||
import { getCommonBounds } from "./bounds";
|
import { getCommonBounds } from "./bounds";
|
||||||
import { getPerfectElementSize } from "./sizeHelpers";
|
import { getPerfectElementSize } from "./sizeHelpers";
|
||||||
import { getBoundTextElement } from "./textElement";
|
import { getBoundTextElement } from "./textElement";
|
||||||
@@ -28,7 +30,6 @@ import {
|
|||||||
|
|
||||||
import type { Scene } from "./Scene";
|
import type { Scene } from "./Scene";
|
||||||
|
|
||||||
import type { Bounds } from "./bounds";
|
|
||||||
import type { ExcalidrawElement } from "./types";
|
import type { ExcalidrawElement } from "./types";
|
||||||
|
|
||||||
export const dragSelectedElements = (
|
export const dragSelectedElements = (
|
||||||
@@ -102,9 +103,26 @@ export const dragSelectedElements = (
|
|||||||
gridSize,
|
gridSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const elementsToUpdateIds = new Set(
|
||||||
|
Array.from(elementsToUpdate, (el) => el.id),
|
||||||
|
);
|
||||||
|
|
||||||
elementsToUpdate.forEach((element) => {
|
elementsToUpdate.forEach((element) => {
|
||||||
updateElementCoords(pointerDownState, element, scene, adjustedOffset);
|
const isArrow = !isArrowElement(element);
|
||||||
|
const isStartBoundElementSelected =
|
||||||
|
isArrow ||
|
||||||
|
(element.startBinding
|
||||||
|
? elementsToUpdateIds.has(element.startBinding.elementId)
|
||||||
|
: false);
|
||||||
|
const isEndBoundElementSelected =
|
||||||
|
isArrow ||
|
||||||
|
(element.endBinding
|
||||||
|
? elementsToUpdateIds.has(element.endBinding.elementId)
|
||||||
|
: false);
|
||||||
|
|
||||||
if (!isArrowElement(element)) {
|
if (!isArrowElement(element)) {
|
||||||
|
updateElementCoords(pointerDownState, element, scene, adjustedOffset);
|
||||||
|
|
||||||
// skip arrow labels since we calculate its position during render
|
// skip arrow labels since we calculate its position during render
|
||||||
const textElement = getBoundTextElement(
|
const textElement = getBoundTextElement(
|
||||||
element,
|
element,
|
||||||
@@ -121,6 +139,33 @@ export const dragSelectedElements = (
|
|||||||
updateBoundElements(element, scene, {
|
updateBoundElements(element, scene, {
|
||||||
simultaneouslyUpdated: Array.from(elementsToUpdate),
|
simultaneouslyUpdated: Array.from(elementsToUpdate),
|
||||||
});
|
});
|
||||||
|
} else if (
|
||||||
|
// NOTE: Add a little initial drag to the arrow dragging when the arrow
|
||||||
|
// is the single element being dragged to avoid accidentally unbinding
|
||||||
|
// the arrow when the user just wants to select it.
|
||||||
|
|
||||||
|
elementsToUpdate.size > 1 ||
|
||||||
|
Math.max(Math.abs(adjustedOffset.x), Math.abs(adjustedOffset.y)) >
|
||||||
|
DRAGGING_THRESHOLD ||
|
||||||
|
(!element.startBinding && !element.endBinding)
|
||||||
|
) {
|
||||||
|
updateElementCoords(pointerDownState, element, scene, adjustedOffset);
|
||||||
|
|
||||||
|
const shouldUnbindStart =
|
||||||
|
element.startBinding && !isStartBoundElementSelected;
|
||||||
|
const shouldUnbindEnd = element.endBinding && !isEndBoundElementSelected;
|
||||||
|
if (shouldUnbindStart || shouldUnbindEnd) {
|
||||||
|
// NOTE: Moving the bound arrow should unbind it, otherwise we would
|
||||||
|
// have weird situations, like 0 lenght arrow when the user moves
|
||||||
|
// the arrow outside a filled shape suddenly forcing the arrow start
|
||||||
|
// and end point to jump "outside" the shape.
|
||||||
|
if (shouldUnbindStart) {
|
||||||
|
unbindBindingElement(element, "start", scene);
|
||||||
|
}
|
||||||
|
if (shouldUnbindEnd) {
|
||||||
|
unbindBindingElement(element, "end", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ import {
|
|||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
type Bounds,
|
||||||
BinaryHeap,
|
BinaryHeap,
|
||||||
invariant,
|
invariant,
|
||||||
isAnyTrue,
|
isAnyTrue,
|
||||||
tupleToCoors,
|
|
||||||
getSizeFromPoints,
|
getSizeFromPoints,
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
arrayToMap,
|
arrayToMap,
|
||||||
@@ -27,10 +27,11 @@ import type { AppState } from "@excalidraw/excalidraw/types";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
bindPointToSnapToElementOutline,
|
bindPointToSnapToElementOutline,
|
||||||
FIXED_BINDING_DISTANCE,
|
|
||||||
getHeadingForElbowArrowSnap,
|
getHeadingForElbowArrowSnap,
|
||||||
getGlobalFixedPointForBindableElement,
|
getGlobalFixedPointForBindableElement,
|
||||||
getHoveredElementForBinding,
|
getBindingGap,
|
||||||
|
maxBindingDistance_simple,
|
||||||
|
BASE_BINDING_GAP_ELBOW,
|
||||||
} from "./binding";
|
} from "./binding";
|
||||||
import { distanceToElement } from "./distance";
|
import { distanceToElement } from "./distance";
|
||||||
import {
|
import {
|
||||||
@@ -51,10 +52,9 @@ import {
|
|||||||
type ExcalidrawElbowArrowElement,
|
type ExcalidrawElbowArrowElement,
|
||||||
type NonDeletedSceneElementsMap,
|
type NonDeletedSceneElementsMap,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
import { aabbForElement, pointInsideBounds } from "./bounds";
|
import { aabbForElement, pointInsideBounds } from "./bounds";
|
||||||
|
import { getHoveredElementForBinding } from "./collision";
|
||||||
|
|
||||||
import type { Bounds } from "./bounds";
|
|
||||||
import type { Heading } from "./heading";
|
import type { Heading } from "./heading";
|
||||||
import type {
|
import type {
|
||||||
Arrowhead,
|
Arrowhead,
|
||||||
@@ -63,6 +63,7 @@ import type {
|
|||||||
FixedPointBinding,
|
FixedPointBinding,
|
||||||
FixedSegment,
|
FixedSegment,
|
||||||
NonDeletedExcalidrawElement,
|
NonDeletedExcalidrawElement,
|
||||||
|
Ordered,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
type GridAddress = [number, number] & { _brand: "gridaddress" };
|
type GridAddress = [number, number] & { _brand: "gridaddress" };
|
||||||
@@ -1243,6 +1244,7 @@ const getElbowArrowData = (
|
|||||||
const startGlobalPoint = getGlobalPoint(
|
const startGlobalPoint = getGlobalPoint(
|
||||||
{
|
{
|
||||||
...arrow,
|
...arrow,
|
||||||
|
angle: 0,
|
||||||
type: "arrow",
|
type: "arrow",
|
||||||
elbowed: true,
|
elbowed: true,
|
||||||
points: nextPoints,
|
points: nextPoints,
|
||||||
@@ -1257,6 +1259,7 @@ const getElbowArrowData = (
|
|||||||
const endGlobalPoint = getGlobalPoint(
|
const endGlobalPoint = getGlobalPoint(
|
||||||
{
|
{
|
||||||
...arrow,
|
...arrow,
|
||||||
|
angle: 0,
|
||||||
type: "arrow",
|
type: "arrow",
|
||||||
elbowed: true,
|
elbowed: true,
|
||||||
points: nextPoints,
|
points: nextPoints,
|
||||||
@@ -1274,6 +1277,7 @@ const getElbowArrowData = (
|
|||||||
hoveredStartElement,
|
hoveredStartElement,
|
||||||
origStartGlobalPoint,
|
origStartGlobalPoint,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
options?.zoom,
|
||||||
);
|
);
|
||||||
const endHeading = getBindPointHeading(
|
const endHeading = getBindPointHeading(
|
||||||
endGlobalPoint,
|
endGlobalPoint,
|
||||||
@@ -1281,6 +1285,7 @@ const getElbowArrowData = (
|
|||||||
hoveredEndElement,
|
hoveredEndElement,
|
||||||
origEndGlobalPoint,
|
origEndGlobalPoint,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
options?.zoom,
|
||||||
);
|
);
|
||||||
const startPointBounds = [
|
const startPointBounds = [
|
||||||
startGlobalPoint[0] - 2,
|
startGlobalPoint[0] - 2,
|
||||||
@@ -1301,8 +1306,8 @@ const getElbowArrowData = (
|
|||||||
offsetFromHeading(
|
offsetFromHeading(
|
||||||
startHeading,
|
startHeading,
|
||||||
arrow.startArrowhead
|
arrow.startArrowhead
|
||||||
? FIXED_BINDING_DISTANCE * 6
|
? getBindingGap(hoveredStartElement, { elbowed: true }) * 6
|
||||||
: FIXED_BINDING_DISTANCE * 2,
|
: getBindingGap(hoveredStartElement, { elbowed: true }) * 2,
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -1314,8 +1319,8 @@ const getElbowArrowData = (
|
|||||||
offsetFromHeading(
|
offsetFromHeading(
|
||||||
endHeading,
|
endHeading,
|
||||||
arrow.endArrowhead
|
arrow.endArrowhead
|
||||||
? FIXED_BINDING_DISTANCE * 6
|
? getBindingGap(hoveredEndElement, { elbowed: true }) * 6
|
||||||
: FIXED_BINDING_DISTANCE * 2,
|
: getBindingGap(hoveredEndElement, { elbowed: true }) * 2,
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -1362,8 +1367,8 @@ const getElbowArrowData = (
|
|||||||
? 0
|
? 0
|
||||||
: BASE_PADDING -
|
: BASE_PADDING -
|
||||||
(arrow.startArrowhead
|
(arrow.startArrowhead
|
||||||
? FIXED_BINDING_DISTANCE * 6
|
? BASE_BINDING_GAP_ELBOW * 6
|
||||||
: FIXED_BINDING_DISTANCE * 2),
|
: BASE_BINDING_GAP_ELBOW * 2),
|
||||||
BASE_PADDING,
|
BASE_PADDING,
|
||||||
),
|
),
|
||||||
boundsOverlap
|
boundsOverlap
|
||||||
@@ -1378,8 +1383,8 @@ const getElbowArrowData = (
|
|||||||
? 0
|
? 0
|
||||||
: BASE_PADDING -
|
: BASE_PADDING -
|
||||||
(arrow.endArrowhead
|
(arrow.endArrowhead
|
||||||
? FIXED_BINDING_DISTANCE * 6
|
? BASE_BINDING_GAP_ELBOW * 6
|
||||||
: FIXED_BINDING_DISTANCE * 2),
|
: BASE_BINDING_GAP_ELBOW * 2),
|
||||||
BASE_PADDING,
|
BASE_PADDING,
|
||||||
),
|
),
|
||||||
boundsOverlap,
|
boundsOverlap,
|
||||||
@@ -2239,6 +2244,7 @@ const getBindPointHeading = (
|
|||||||
hoveredElement: ExcalidrawBindableElement | null | undefined,
|
hoveredElement: ExcalidrawBindableElement | null | undefined,
|
||||||
origPoint: GlobalPoint,
|
origPoint: GlobalPoint,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
|
zoom?: AppState["zoom"],
|
||||||
): Heading =>
|
): Heading =>
|
||||||
getHeadingForElbowArrowSnap(
|
getHeadingForElbowArrowSnap(
|
||||||
p,
|
p,
|
||||||
@@ -2257,21 +2263,20 @@ const getBindPointHeading = (
|
|||||||
),
|
),
|
||||||
origPoint,
|
origPoint,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
zoom,
|
||||||
);
|
);
|
||||||
|
|
||||||
const getHoveredElement = (
|
const getHoveredElement = (
|
||||||
origPoint: GlobalPoint,
|
origPoint: GlobalPoint,
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
elements: readonly NonDeletedExcalidrawElement[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
zoom?: AppState["zoom"],
|
zoom?: AppState["zoom"],
|
||||||
) => {
|
) => {
|
||||||
return getHoveredElementForBinding(
|
return getHoveredElementForBinding(
|
||||||
tupleToCoors(origPoint),
|
origPoint,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
(element) => maxBindingDistance_simple(zoom),
|
||||||
true,
|
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type {
|
|||||||
PendingExcalidrawElements,
|
PendingExcalidrawElements,
|
||||||
} from "@excalidraw/excalidraw/types";
|
} from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
import { bindLinearElement } from "./binding";
|
import { bindBindingElement } from "./binding";
|
||||||
import { updateElbowArrowPoints } from "./elbowArrow";
|
import { updateElbowArrowPoints } from "./elbowArrow";
|
||||||
import {
|
import {
|
||||||
HEADING_DOWN,
|
HEADING_DOWN,
|
||||||
@@ -446,8 +446,14 @@ const createBindingArrow = (
|
|||||||
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
|
||||||
bindLinearElement(bindingArrow, startBindingElement, "start", scene);
|
bindBindingElement(
|
||||||
bindLinearElement(bindingArrow, endBindingElement, "end", scene);
|
bindingArrow,
|
||||||
|
startBindingElement,
|
||||||
|
"orbit",
|
||||||
|
"start",
|
||||||
|
scene,
|
||||||
|
);
|
||||||
|
bindBindingElement(bindingArrow, endBindingElement, "orbit", "end", scene);
|
||||||
|
|
||||||
const changedElements = new Map<string, OrderedExcalidrawElement>();
|
const changedElements = new Map<string, OrderedExcalidrawElement>();
|
||||||
changedElements.set(
|
changedElements.set(
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { invariant, isDevEnv, isTestEnv } from "@excalidraw/common";
|
import {
|
||||||
|
invariant,
|
||||||
|
isDevEnv,
|
||||||
|
isTestEnv,
|
||||||
|
type Bounds,
|
||||||
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
pointFrom,
|
pointFrom,
|
||||||
@@ -19,7 +24,7 @@ import type {
|
|||||||
Vector,
|
Vector,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import { getCenterForBounds, type Bounds } from "./bounds";
|
import { getCenterForBounds } from "./bounds";
|
||||||
|
|
||||||
import type { ExcalidrawBindableElement } from "./types";
|
import type { ExcalidrawBindableElement } from "./types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { toIterable } from "@excalidraw/common";
|
import { toIterable } from "@excalidraw/common";
|
||||||
|
|
||||||
import { isInvisiblySmallElement } from "./sizeHelpers";
|
import { isInvisiblySmallElement } from "./sizeHelpers";
|
||||||
import { isLinearElementType } from "./typeChecks";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
@@ -55,27 +54,6 @@ export const isNonDeletedElement = <T extends ExcalidrawElement>(
|
|||||||
element: T,
|
element: T,
|
||||||
): element is NonDeleted<T> => !element.isDeleted;
|
): element is NonDeleted<T> => !element.isDeleted;
|
||||||
|
|
||||||
const _clearElements = (
|
|
||||||
elements: readonly ExcalidrawElement[],
|
|
||||||
): ExcalidrawElement[] =>
|
|
||||||
getNonDeletedElements(elements).map((element) =>
|
|
||||||
isLinearElementType(element.type)
|
|
||||||
? { ...element, lastCommittedPoint: null }
|
|
||||||
: element,
|
|
||||||
);
|
|
||||||
|
|
||||||
export const clearElementsForDatabase = (
|
|
||||||
elements: readonly ExcalidrawElement[],
|
|
||||||
) => _clearElements(elements);
|
|
||||||
|
|
||||||
export const clearElementsForExport = (
|
|
||||||
elements: readonly ExcalidrawElement[],
|
|
||||||
) => _clearElements(elements);
|
|
||||||
|
|
||||||
export const clearElementsForLocalStorage = (
|
|
||||||
elements: readonly ExcalidrawElement[],
|
|
||||||
) => _clearElements(elements);
|
|
||||||
|
|
||||||
export * from "./align";
|
export * from "./align";
|
||||||
export * from "./binding";
|
export * from "./binding";
|
||||||
export * from "./bounds";
|
export * from "./bounds";
|
||||||
@@ -114,6 +92,7 @@ export * from "./store";
|
|||||||
export * from "./textElement";
|
export * from "./textElement";
|
||||||
export * from "./textMeasurements";
|
export * from "./textMeasurements";
|
||||||
export * from "./textWrapping";
|
export * from "./textWrapping";
|
||||||
|
export * from "./transform";
|
||||||
export * from "./transformHandles";
|
export * from "./transformHandles";
|
||||||
export * from "./typeChecks";
|
export * from "./typeChecks";
|
||||||
export * from "./utils";
|
export * from "./utils";
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -46,16 +46,13 @@ export const mutateElement = <TElement extends Mutable<ExcalidrawElement>>(
|
|||||||
|
|
||||||
// casting to any because can't use `in` operator
|
// casting to any because can't use `in` operator
|
||||||
// (see https://github.com/microsoft/TypeScript/issues/21732)
|
// (see https://github.com/microsoft/TypeScript/issues/21732)
|
||||||
const { points, fixedSegments, startBinding, endBinding, fileId } =
|
const { points, fixedSegments, fileId } = updates as any;
|
||||||
updates as any;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isElbowArrow(element) &&
|
isElbowArrow(element) &&
|
||||||
(Object.keys(updates).length === 0 || // normalization case
|
(Object.keys(updates).length === 0 || // normalization case
|
||||||
typeof points !== "undefined" || // repositioning
|
typeof points !== "undefined" || // repositioning
|
||||||
typeof fixedSegments !== "undefined" || // segment fixing
|
typeof fixedSegments !== "undefined") // segment fixing
|
||||||
typeof startBinding !== "undefined" ||
|
|
||||||
typeof endBinding !== "undefined") // manual binding to element
|
|
||||||
) {
|
) {
|
||||||
updates = {
|
updates = {
|
||||||
...updates,
|
...updates,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
getResizedElementAbsoluteCoords,
|
getResizedElementAbsoluteCoords,
|
||||||
} from "./bounds";
|
} from "./bounds";
|
||||||
import { newElementWith } from "./mutateElement";
|
import { newElementWith } from "./mutateElement";
|
||||||
import { getBoundTextMaxWidth } from "./textElement";
|
import { getBoundTextMaxWidth, getInitialTextMetrics } from "./textElement";
|
||||||
import { normalizeText, measureText } from "./textMeasurements";
|
import { normalizeText, measureText } from "./textMeasurements";
|
||||||
import { wrapText } from "./textWrapping";
|
import { wrapText } from "./textWrapping";
|
||||||
|
|
||||||
@@ -236,27 +236,30 @@ const getTextElementPositionOffsets = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type NewTextElementOptions = {
|
||||||
|
text: string;
|
||||||
|
originalText?: string;
|
||||||
|
fontSize?: number;
|
||||||
|
fontFamily?: FontFamilyValues;
|
||||||
|
textAlign?: TextAlign;
|
||||||
|
verticalAlign?: VerticalAlign;
|
||||||
|
containerId?: ExcalidrawTextContainer["id"] | null;
|
||||||
|
lineHeight?: ExcalidrawTextElement["lineHeight"];
|
||||||
|
autoResize?: ExcalidrawTextElement["autoResize"];
|
||||||
|
} & ElementConstructorOpts;
|
||||||
|
|
||||||
export const newTextElement = (
|
export const newTextElement = (
|
||||||
opts: {
|
opts: NewTextElementOptions,
|
||||||
text: string;
|
|
||||||
originalText?: string;
|
|
||||||
fontSize?: number;
|
|
||||||
fontFamily?: FontFamilyValues;
|
|
||||||
textAlign?: TextAlign;
|
|
||||||
verticalAlign?: VerticalAlign;
|
|
||||||
containerId?: ExcalidrawTextContainer["id"] | null;
|
|
||||||
lineHeight?: ExcalidrawTextElement["lineHeight"];
|
|
||||||
autoResize?: ExcalidrawTextElement["autoResize"];
|
|
||||||
} & ElementConstructorOpts,
|
|
||||||
): NonDeleted<ExcalidrawTextElement> => {
|
): NonDeleted<ExcalidrawTextElement> => {
|
||||||
const fontFamily = opts.fontFamily || DEFAULT_FONT_FAMILY;
|
const fontFamily = opts.fontFamily || DEFAULT_FONT_FAMILY;
|
||||||
const fontSize = opts.fontSize || DEFAULT_FONT_SIZE;
|
const fontSize = opts.fontSize || DEFAULT_FONT_SIZE;
|
||||||
const lineHeight = opts.lineHeight || getLineHeight(fontFamily);
|
const lineHeight = opts.lineHeight || getLineHeight(fontFamily);
|
||||||
const text = normalizeText(opts.text);
|
const normalizedText = normalizeText(opts.text);
|
||||||
const metrics = measureText(
|
const originalText = opts.originalText ?? normalizedText;
|
||||||
text,
|
const metrics = getInitialTextMetrics(
|
||||||
getFontString({ fontFamily, fontSize }),
|
{ ...opts, text: normalizedText },
|
||||||
lineHeight,
|
fontFamily,
|
||||||
|
fontSize,
|
||||||
);
|
);
|
||||||
const textAlign = opts.textAlign || DEFAULT_TEXT_ALIGN;
|
const textAlign = opts.textAlign || DEFAULT_TEXT_ALIGN;
|
||||||
const verticalAlign = opts.verticalAlign || DEFAULT_VERTICAL_ALIGN;
|
const verticalAlign = opts.verticalAlign || DEFAULT_VERTICAL_ALIGN;
|
||||||
@@ -267,7 +270,7 @@ export const newTextElement = (
|
|||||||
|
|
||||||
const textElementProps: ExcalidrawTextElement = {
|
const textElementProps: ExcalidrawTextElement = {
|
||||||
..._newElementBase<ExcalidrawTextElement>("text", opts),
|
..._newElementBase<ExcalidrawTextElement>("text", opts),
|
||||||
text,
|
text: normalizedText,
|
||||||
fontSize,
|
fontSize,
|
||||||
fontFamily,
|
fontFamily,
|
||||||
textAlign,
|
textAlign,
|
||||||
@@ -277,7 +280,7 @@ export const newTextElement = (
|
|||||||
width: metrics.width,
|
width: metrics.width,
|
||||||
height: metrics.height,
|
height: metrics.height,
|
||||||
containerId: opts.containerId || null,
|
containerId: opts.containerId || null,
|
||||||
originalText: opts.originalText ?? text,
|
originalText,
|
||||||
autoResize: opts.autoResize ?? true,
|
autoResize: opts.autoResize ?? true,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
};
|
};
|
||||||
@@ -452,7 +455,6 @@ export const newFreeDrawElement = (
|
|||||||
points: opts.points || [],
|
points: opts.points || [],
|
||||||
pressures: opts.pressures || [],
|
pressures: opts.pressures || [],
|
||||||
simulatePressure: opts.simulatePressure,
|
simulatePressure: opts.simulatePressure,
|
||||||
lastCommittedPoint: null,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -466,7 +468,7 @@ export const newLinearElement = (
|
|||||||
const element = {
|
const element = {
|
||||||
..._newElementBase<ExcalidrawLinearElement>(opts.type, opts),
|
..._newElementBase<ExcalidrawLinearElement>(opts.type, opts),
|
||||||
points: opts.points || [],
|
points: opts.points || [],
|
||||||
lastCommittedPoint: null,
|
|
||||||
startBinding: null,
|
startBinding: null,
|
||||||
endBinding: null,
|
endBinding: null,
|
||||||
startArrowhead: null,
|
startArrowhead: null,
|
||||||
@@ -501,7 +503,6 @@ export const newArrowElement = <T extends boolean>(
|
|||||||
return {
|
return {
|
||||||
..._newElementBase<ExcalidrawElbowArrowElement>(opts.type, opts),
|
..._newElementBase<ExcalidrawElbowArrowElement>(opts.type, opts),
|
||||||
points: opts.points || [],
|
points: opts.points || [],
|
||||||
lastCommittedPoint: null,
|
|
||||||
startBinding: null,
|
startBinding: null,
|
||||||
endBinding: null,
|
endBinding: null,
|
||||||
startArrowhead: opts.startArrowhead || null,
|
startArrowhead: opts.startArrowhead || null,
|
||||||
@@ -516,7 +517,6 @@ export const newArrowElement = <T extends boolean>(
|
|||||||
return {
|
return {
|
||||||
..._newElementBase<ExcalidrawArrowElement>(opts.type, opts),
|
..._newElementBase<ExcalidrawArrowElement>(opts.type, opts),
|
||||||
points: opts.points || [],
|
points: opts.points || [],
|
||||||
lastCommittedPoint: null,
|
|
||||||
startBinding: null,
|
startBinding: null,
|
||||||
endBinding: null,
|
endBinding: null,
|
||||||
startArrowhead: opts.startArrowhead || null,
|
startArrowhead: opts.startArrowhead || null,
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ const isPendingImageElement = (
|
|||||||
const shouldResetImageFilter = (
|
const shouldResetImageFilter = (
|
||||||
element: ExcalidrawElement,
|
element: ExcalidrawElement,
|
||||||
renderConfig: StaticCanvasRenderConfig,
|
renderConfig: StaticCanvasRenderConfig,
|
||||||
appState: StaticCanvasAppState,
|
appState: StaticCanvasAppState | InteractiveCanvasAppState,
|
||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
appState.theme === THEME.DARK &&
|
appState.theme === THEME.DARK &&
|
||||||
@@ -225,7 +225,7 @@ const generateElementCanvas = (
|
|||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
zoom: Zoom,
|
zoom: Zoom,
|
||||||
renderConfig: StaticCanvasRenderConfig,
|
renderConfig: StaticCanvasRenderConfig,
|
||||||
appState: StaticCanvasAppState,
|
appState: StaticCanvasAppState | InteractiveCanvasAppState,
|
||||||
): ExcalidrawElementWithCanvas | null => {
|
): ExcalidrawElementWithCanvas | null => {
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
const context = canvas.getContext("2d")!;
|
const context = canvas.getContext("2d")!;
|
||||||
@@ -277,7 +277,7 @@ const generateElementCanvas = (
|
|||||||
context.filter = IMAGE_INVERT_FILTER;
|
context.filter = IMAGE_INVERT_FILTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawElementOnCanvas(element, rc, context, renderConfig, appState);
|
drawElementOnCanvas(element, rc, context, renderConfig);
|
||||||
|
|
||||||
context.restore();
|
context.restore();
|
||||||
|
|
||||||
@@ -412,7 +412,6 @@ const drawElementOnCanvas = (
|
|||||||
rc: RoughCanvas,
|
rc: RoughCanvas,
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
renderConfig: StaticCanvasRenderConfig,
|
renderConfig: StaticCanvasRenderConfig,
|
||||||
appState: StaticCanvasAppState,
|
|
||||||
) => {
|
) => {
|
||||||
switch (element.type) {
|
switch (element.type) {
|
||||||
case "rectangle":
|
case "rectangle":
|
||||||
@@ -558,7 +557,7 @@ const generateElementWithCanvas = (
|
|||||||
element: NonDeletedExcalidrawElement,
|
element: NonDeletedExcalidrawElement,
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
renderConfig: StaticCanvasRenderConfig,
|
renderConfig: StaticCanvasRenderConfig,
|
||||||
appState: StaticCanvasAppState,
|
appState: StaticCanvasAppState | InteractiveCanvasAppState,
|
||||||
) => {
|
) => {
|
||||||
const zoom: Zoom = renderConfig
|
const zoom: Zoom = renderConfig
|
||||||
? appState.zoom
|
? appState.zoom
|
||||||
@@ -615,7 +614,7 @@ const drawElementFromCanvas = (
|
|||||||
elementWithCanvas: ExcalidrawElementWithCanvas,
|
elementWithCanvas: ExcalidrawElementWithCanvas,
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
renderConfig: StaticCanvasRenderConfig,
|
renderConfig: StaticCanvasRenderConfig,
|
||||||
appState: StaticCanvasAppState,
|
appState: StaticCanvasAppState | InteractiveCanvasAppState,
|
||||||
allElementsMap: NonDeletedSceneElementsMap,
|
allElementsMap: NonDeletedSceneElementsMap,
|
||||||
) => {
|
) => {
|
||||||
const element = elementWithCanvas.element;
|
const element = elementWithCanvas.element;
|
||||||
@@ -733,7 +732,7 @@ export const renderElement = (
|
|||||||
rc: RoughCanvas,
|
rc: RoughCanvas,
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
renderConfig: StaticCanvasRenderConfig,
|
renderConfig: StaticCanvasRenderConfig,
|
||||||
appState: StaticCanvasAppState,
|
appState: StaticCanvasAppState | InteractiveCanvasAppState,
|
||||||
) => {
|
) => {
|
||||||
const reduceAlphaForSelection =
|
const reduceAlphaForSelection =
|
||||||
appState.openDialog?.name === "elementLinkSelector" &&
|
appState.openDialog?.name === "elementLinkSelector" &&
|
||||||
@@ -803,7 +802,7 @@ export const renderElement = (
|
|||||||
context.translate(cx, cy);
|
context.translate(cx, cy);
|
||||||
context.rotate(element.angle);
|
context.rotate(element.angle);
|
||||||
context.translate(-shiftX, -shiftY);
|
context.translate(-shiftX, -shiftY);
|
||||||
drawElementOnCanvas(element, rc, context, renderConfig, appState);
|
drawElementOnCanvas(element, rc, context, renderConfig);
|
||||||
context.restore();
|
context.restore();
|
||||||
} else {
|
} else {
|
||||||
const elementWithCanvas = generateElementWithCanvas(
|
const elementWithCanvas = generateElementWithCanvas(
|
||||||
@@ -896,13 +895,7 @@ export const renderElement = (
|
|||||||
|
|
||||||
tempCanvasContext.translate(-shiftX, -shiftY);
|
tempCanvasContext.translate(-shiftX, -shiftY);
|
||||||
|
|
||||||
drawElementOnCanvas(
|
drawElementOnCanvas(element, tempRc, tempCanvasContext, renderConfig);
|
||||||
element,
|
|
||||||
tempRc,
|
|
||||||
tempCanvasContext,
|
|
||||||
renderConfig,
|
|
||||||
appState,
|
|
||||||
);
|
|
||||||
|
|
||||||
tempCanvasContext.translate(shiftX, shiftY);
|
tempCanvasContext.translate(shiftX, shiftY);
|
||||||
|
|
||||||
@@ -941,7 +934,7 @@ export const renderElement = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.translate(-shiftX, -shiftY);
|
context.translate(-shiftX, -shiftY);
|
||||||
drawElementOnCanvas(element, rc, context, renderConfig, appState);
|
drawElementOnCanvas(element, rc, context, renderConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.restore();
|
context.restore();
|
||||||
@@ -1122,7 +1115,7 @@ export function getFreedrawOutlinePoints(element: ExcalidrawFreeDrawElement) {
|
|||||||
smoothing: 0.5,
|
smoothing: 0.5,
|
||||||
streamline: 0.5,
|
streamline: 0.5,
|
||||||
easing: (t) => Math.sin((t * Math.PI) / 2), // https://easings.net/#easeOutSine
|
easing: (t) => Math.sin((t * Math.PI) / 2), // https://easings.net/#easeOutSine
|
||||||
last: !!element.lastCommittedPoint, // LastCommittedPoint is added on pointerup
|
last: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
return getStroke(inputPoints as number[][], options) as [number, number][];
|
return getStroke(inputPoints as number[][], options) as [number, number][];
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ import type { PointerDownState } from "@excalidraw/excalidraw/types";
|
|||||||
|
|
||||||
import type { Mutable } from "@excalidraw/common/utility-types";
|
import type { Mutable } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import { getArrowLocalFixedPoints, updateBoundElements } from "./binding";
|
import {
|
||||||
|
getArrowLocalFixedPoints,
|
||||||
|
unbindBindingElement,
|
||||||
|
updateBoundElements,
|
||||||
|
} from "./binding";
|
||||||
import {
|
import {
|
||||||
getElementAbsoluteCoords,
|
getElementAbsoluteCoords,
|
||||||
getCommonBounds,
|
getCommonBounds,
|
||||||
@@ -46,6 +50,7 @@ import {
|
|||||||
import { wrapText } from "./textWrapping";
|
import { wrapText } from "./textWrapping";
|
||||||
import {
|
import {
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
|
isBindingElement,
|
||||||
isBoundToContainer,
|
isBoundToContainer,
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
isFrameLikeElement,
|
isFrameLikeElement,
|
||||||
@@ -74,7 +79,9 @@ import type {
|
|||||||
ExcalidrawImageElement,
|
ExcalidrawImageElement,
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
ExcalidrawElbowArrowElement,
|
ExcalidrawElbowArrowElement,
|
||||||
|
ExcalidrawArrowElement,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
import type { ElementUpdate } from "./mutateElement";
|
||||||
|
|
||||||
// Returns true when transform (resizing/rotation) happened
|
// Returns true when transform (resizing/rotation) happened
|
||||||
export const transformElements = (
|
export const transformElements = (
|
||||||
@@ -220,7 +227,25 @@ const rotateSingleElement = (
|
|||||||
}
|
}
|
||||||
const boundTextElementId = getBoundTextElementId(element);
|
const boundTextElementId = getBoundTextElementId(element);
|
||||||
|
|
||||||
scene.mutateElement(element, { angle });
|
let update: ElementUpdate<NonDeletedExcalidrawElement> = {
|
||||||
|
angle,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isBindingElement(element)) {
|
||||||
|
update = {
|
||||||
|
...update,
|
||||||
|
} as ElementUpdate<ExcalidrawArrowElement>;
|
||||||
|
|
||||||
|
if (element.startBinding) {
|
||||||
|
unbindBindingElement(element, "start", scene);
|
||||||
|
}
|
||||||
|
if (element.endBinding) {
|
||||||
|
unbindBindingElement(element, "end", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scene.mutateElement(element, update);
|
||||||
|
|
||||||
if (boundTextElementId) {
|
if (boundTextElementId) {
|
||||||
const textElement =
|
const textElement =
|
||||||
scene.getElement<ExcalidrawTextElementWithContainer>(boundTextElementId);
|
scene.getElement<ExcalidrawTextElementWithContainer>(boundTextElementId);
|
||||||
@@ -394,6 +419,11 @@ const rotateMultipleElements = (
|
|||||||
centerAngle -= centerAngle % SHIFT_LOCKING_ANGLE;
|
centerAngle -= centerAngle % SHIFT_LOCKING_ANGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rotatedElementsMap = new Map<
|
||||||
|
ExcalidrawElement["id"],
|
||||||
|
NonDeletedExcalidrawElement
|
||||||
|
>(elements.map((element) => [element.id, element]));
|
||||||
|
|
||||||
for (const element of elements) {
|
for (const element of elements) {
|
||||||
if (!isFrameLikeElement(element)) {
|
if (!isFrameLikeElement(element)) {
|
||||||
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
||||||
@@ -424,6 +454,19 @@ const rotateMultipleElements = (
|
|||||||
simultaneouslyUpdated: elements,
|
simultaneouslyUpdated: elements,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isBindingElement(element)) {
|
||||||
|
if (element.startBinding) {
|
||||||
|
if (!rotatedElementsMap.has(element.startBinding.elementId)) {
|
||||||
|
unbindBindingElement(element, "start", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (element.endBinding) {
|
||||||
|
if (!rotatedElementsMap.has(element.endBinding.elementId)) {
|
||||||
|
unbindBindingElement(element, "end", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const boundText = getBoundTextElement(element, elementsMap);
|
const boundText = getBoundTextElement(element, elementsMap);
|
||||||
if (boundText && !isArrowElement(element)) {
|
if (boundText && !isArrowElement(element)) {
|
||||||
const { x, y } = computeBoundTextPosition(
|
const { x, y } = computeBoundTextPosition(
|
||||||
@@ -835,13 +878,32 @@ export const resizeSingleElement = (
|
|||||||
Number.isFinite(newOrigin.x) &&
|
Number.isFinite(newOrigin.x) &&
|
||||||
Number.isFinite(newOrigin.y)
|
Number.isFinite(newOrigin.y)
|
||||||
) {
|
) {
|
||||||
const updates = {
|
let updates: ElementUpdate<ExcalidrawElement> = {
|
||||||
...newOrigin,
|
...newOrigin,
|
||||||
width: Math.abs(nextWidth),
|
width: Math.abs(nextWidth),
|
||||||
height: Math.abs(nextHeight),
|
height: Math.abs(nextHeight),
|
||||||
...rescaledPoints,
|
...rescaledPoints,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isBindingElement(latestElement)) {
|
||||||
|
if (latestElement.startBinding) {
|
||||||
|
updates = {
|
||||||
|
...updates,
|
||||||
|
} as ElementUpdate<ExcalidrawArrowElement>;
|
||||||
|
|
||||||
|
if (latestElement.startBinding) {
|
||||||
|
unbindBindingElement(latestElement, "start", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (latestElement.endBinding) {
|
||||||
|
updates = {
|
||||||
|
...updates,
|
||||||
|
endBinding: null,
|
||||||
|
} as ElementUpdate<ExcalidrawArrowElement>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scene.mutateElement(latestElement, updates, {
|
scene.mutateElement(latestElement, updates, {
|
||||||
informMutation: shouldInformMutation,
|
informMutation: shouldInformMutation,
|
||||||
isDragging: false,
|
isDragging: false,
|
||||||
@@ -859,10 +921,7 @@ export const resizeSingleElement = (
|
|||||||
shouldMaintainAspectRatio,
|
shouldMaintainAspectRatio,
|
||||||
);
|
);
|
||||||
|
|
||||||
updateBoundElements(latestElement, scene, {
|
updateBoundElements(latestElement, scene);
|
||||||
// TODO: confirm with MARK if this actually makes sense
|
|
||||||
newSize: { width: nextWidth, height: nextHeight },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1396,20 +1455,36 @@ export const resizeMultipleElements = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const elementsToUpdate = elementsAndUpdates.map(({ element }) => element);
|
const elementsToUpdate = elementsAndUpdates.map(({ element }) => element);
|
||||||
|
const resizedElementsMap = new Map<
|
||||||
|
ExcalidrawElement["id"],
|
||||||
|
NonDeletedExcalidrawElement
|
||||||
|
>(elementsAndUpdates.map(({ element }) => [element.id, element]));
|
||||||
|
|
||||||
for (const {
|
for (const {
|
||||||
element,
|
element,
|
||||||
update: { boundTextFontSize, ...update },
|
update: { boundTextFontSize, ...update },
|
||||||
} of elementsAndUpdates) {
|
} of elementsAndUpdates) {
|
||||||
const { width, height, angle } = update;
|
const { angle } = update;
|
||||||
|
|
||||||
scene.mutateElement(element, update);
|
scene.mutateElement(element, update);
|
||||||
|
|
||||||
updateBoundElements(element, scene, {
|
updateBoundElements(element, scene, {
|
||||||
simultaneouslyUpdated: elementsToUpdate,
|
simultaneouslyUpdated: elementsToUpdate,
|
||||||
newSize: { width, height },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isBindingElement(element)) {
|
||||||
|
if (element.startBinding) {
|
||||||
|
if (!resizedElementsMap.has(element.startBinding.elementId)) {
|
||||||
|
unbindBindingElement(element, "start", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (element.endBinding) {
|
||||||
|
if (!resizedElementsMap.has(element.endBinding.elementId)) {
|
||||||
|
unbindBindingElement(element, "end", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(element, elementsMap);
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
||||||
if (boundTextElement && boundTextFontSize) {
|
if (boundTextElement && boundTextFontSize) {
|
||||||
scene.mutateElement(boundTextElement, {
|
scene.mutateElement(boundTextElement, {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
import type { GlobalPoint, LineSegment, LocalPoint } from "@excalidraw/math";
|
import type { GlobalPoint, LineSegment, LocalPoint } from "@excalidraw/math";
|
||||||
|
|
||||||
import type { AppState, Zoom } from "@excalidraw/excalidraw/types";
|
import type { AppState, Zoom } from "@excalidraw/excalidraw/types";
|
||||||
|
import type { Bounds } from "@excalidraw/common";
|
||||||
|
|
||||||
import { getElementAbsoluteCoords } from "./bounds";
|
import { getElementAbsoluteCoords } from "./bounds";
|
||||||
import {
|
import {
|
||||||
@@ -23,7 +24,6 @@ import {
|
|||||||
} from "./transformHandles";
|
} from "./transformHandles";
|
||||||
import { isImageElement, isLinearElement } from "./typeChecks";
|
import { isImageElement, isLinearElement } from "./typeChecks";
|
||||||
|
|
||||||
import type { Bounds } from "./bounds";
|
|
||||||
import type {
|
import type {
|
||||||
TransformHandleType,
|
TransformHandleType,
|
||||||
TransformHandle,
|
TransformHandle,
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
getFontString,
|
getFontString,
|
||||||
isProdEnv,
|
isProdEnv,
|
||||||
invariant,
|
invariant,
|
||||||
|
DEFAULT_FONT_FAMILY,
|
||||||
|
getLineHeight,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import { pointFrom, pointRotateRads, type Radians } from "@excalidraw/math";
|
import { pointFrom, pointRotateRads, type Radians } from "@excalidraw/math";
|
||||||
@@ -30,6 +32,8 @@ import {
|
|||||||
isTextElement,
|
isTextElement,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
|
|
||||||
|
import type { NewTextElementOptions } from "./newElement";
|
||||||
|
|
||||||
import type { Scene } from "./Scene";
|
import type { Scene } from "./Scene";
|
||||||
|
|
||||||
import type { MaybeTransformHandleType } from "./transformHandles";
|
import type { MaybeTransformHandleType } from "./transformHandles";
|
||||||
@@ -40,6 +44,7 @@ import type {
|
|||||||
ExcalidrawTextContainer,
|
ExcalidrawTextContainer,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
ExcalidrawTextElementWithContainer,
|
ExcalidrawTextElementWithContainer,
|
||||||
|
FontFamilyValues,
|
||||||
NonDeletedExcalidrawElement,
|
NonDeletedExcalidrawElement,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
@@ -528,3 +533,24 @@ export const getTextFromElements = (
|
|||||||
.join(separator);
|
.join(separator);
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** When text is already measured and wrapped, we want to respect those dimensions */
|
||||||
|
export const getInitialTextMetrics = (
|
||||||
|
text: NewTextElementOptions,
|
||||||
|
fontFamily: FontFamilyValues = DEFAULT_FONT_FAMILY,
|
||||||
|
fontSize: number = DEFAULT_FONT_SIZE,
|
||||||
|
) => {
|
||||||
|
const shouldUseProvidedDimensions =
|
||||||
|
text.autoResize === false && text.width && text.height;
|
||||||
|
|
||||||
|
return shouldUseProvidedDimensions
|
||||||
|
? {
|
||||||
|
width: text.width,
|
||||||
|
height: text.height,
|
||||||
|
}
|
||||||
|
: measureText(
|
||||||
|
text.text,
|
||||||
|
getFontString({ fontFamily, fontSize }),
|
||||||
|
text.lineHeight ?? getLineHeight(fontFamily),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import {
|
|||||||
arrayToMap,
|
arrayToMap,
|
||||||
assertNever,
|
assertNever,
|
||||||
cloneJSON,
|
cloneJSON,
|
||||||
getFontString,
|
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
toBrandedType,
|
toBrandedType,
|
||||||
getLineHeight,
|
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import { bindLinearElement } from "@excalidraw/element";
|
import type { MarkOptional } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
|
import { bindBindingElement } from "./binding";
|
||||||
import {
|
import {
|
||||||
newArrowElement,
|
newArrowElement,
|
||||||
newElement,
|
newElement,
|
||||||
@@ -25,21 +25,19 @@ import {
|
|||||||
newLinearElement,
|
newLinearElement,
|
||||||
newMagicFrameElement,
|
newMagicFrameElement,
|
||||||
newTextElement,
|
newTextElement,
|
||||||
} from "@excalidraw/element";
|
type ElementConstructorOpts,
|
||||||
import { measureText, normalizeText } from "@excalidraw/element";
|
} from "./newElement";
|
||||||
import { isArrowElement } from "@excalidraw/element";
|
import { isArrowElement } from "./typeChecks";
|
||||||
|
|
||||||
import { syncInvalidIndices } from "@excalidraw/element";
|
import { syncInvalidIndices } from "./fractionalIndex";
|
||||||
|
|
||||||
import { redrawTextBoundingBox } from "@excalidraw/element";
|
import { getInitialTextMetrics, redrawTextBoundingBox } from "./textElement";
|
||||||
|
|
||||||
import { LinearElementEditor } from "@excalidraw/element";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
|
|
||||||
import { getCommonBounds } from "@excalidraw/element";
|
import { getCommonBounds } from "./bounds";
|
||||||
|
|
||||||
import { Scene } from "@excalidraw/element";
|
import { Scene } from "./Scene";
|
||||||
|
|
||||||
import type { ElementConstructorOpts } from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawArrowElement,
|
ExcalidrawArrowElement,
|
||||||
@@ -59,9 +57,7 @@ import type {
|
|||||||
NonDeletedSceneElementsMap,
|
NonDeletedSceneElementsMap,
|
||||||
TextAlign,
|
TextAlign,
|
||||||
VerticalAlign,
|
VerticalAlign,
|
||||||
} from "@excalidraw/element/types";
|
} from "./types";
|
||||||
|
|
||||||
import type { MarkOptional } from "@excalidraw/common/utility-types";
|
|
||||||
|
|
||||||
export type ValidLinearElement = {
|
export type ValidLinearElement = {
|
||||||
type: "arrow" | "line";
|
type: "arrow" | "line";
|
||||||
@@ -330,9 +326,10 @@ const bindLinearElementToElement = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bindLinearElement(
|
bindBindingElement(
|
||||||
linearElement,
|
linearElement,
|
||||||
startBoundElement as ExcalidrawBindableElement,
|
startBoundElement as ExcalidrawBindableElement,
|
||||||
|
"orbit",
|
||||||
"start",
|
"start",
|
||||||
scene,
|
scene,
|
||||||
);
|
);
|
||||||
@@ -405,9 +402,10 @@ const bindLinearElementToElement = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bindLinearElement(
|
bindBindingElement(
|
||||||
linearElement,
|
linearElement,
|
||||||
endBoundElement as ExcalidrawBindableElement,
|
endBoundElement as ExcalidrawBindableElement,
|
||||||
|
"orbit",
|
||||||
"end",
|
"end",
|
||||||
scene,
|
scene,
|
||||||
);
|
);
|
||||||
@@ -578,14 +576,7 @@ export const convertToExcalidrawElements = (
|
|||||||
case "text": {
|
case "text": {
|
||||||
const fontFamily = element?.fontFamily || DEFAULT_FONT_FAMILY;
|
const fontFamily = element?.fontFamily || DEFAULT_FONT_FAMILY;
|
||||||
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE;
|
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE;
|
||||||
const lineHeight = element?.lineHeight || getLineHeight(fontFamily);
|
const metrics = getInitialTextMetrics(element, fontFamily, fontSize);
|
||||||
const text = element.text ?? "";
|
|
||||||
const normalizedText = normalizeText(text);
|
|
||||||
const metrics = measureText(
|
|
||||||
normalizedText,
|
|
||||||
getFontString({ fontFamily, fontSize }),
|
|
||||||
lineHeight,
|
|
||||||
);
|
|
||||||
|
|
||||||
excalidrawElement = newTextElement({
|
excalidrawElement = newTextElement({
|
||||||
width: metrics.width,
|
width: metrics.width,
|
||||||
@@ -11,6 +11,7 @@ import type {
|
|||||||
InteractiveCanvasAppState,
|
InteractiveCanvasAppState,
|
||||||
Zoom,
|
Zoom,
|
||||||
} from "@excalidraw/excalidraw/types";
|
} from "@excalidraw/excalidraw/types";
|
||||||
|
import type { Bounds } from "@excalidraw/common";
|
||||||
|
|
||||||
import { getElementAbsoluteCoords } from "./bounds";
|
import { getElementAbsoluteCoords } from "./bounds";
|
||||||
import {
|
import {
|
||||||
@@ -20,7 +21,6 @@ import {
|
|||||||
isLinearElement,
|
isLinearElement,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
|
|
||||||
import type { Bounds } from "./bounds";
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
@@ -330,7 +330,10 @@ export const hasBoundingBox = (
|
|||||||
appState: InteractiveCanvasAppState,
|
appState: InteractiveCanvasAppState,
|
||||||
editorInterface: EditorInterface,
|
editorInterface: EditorInterface,
|
||||||
) => {
|
) => {
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
if (
|
||||||
|
appState.selectedLinearElement?.isEditing ||
|
||||||
|
appState.selectedLinearElement?.isDragging
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (elements.length > 1) {
|
if (elements.length > 1) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import type { ElementOrToolType } from "@excalidraw/excalidraw/types";
|
|||||||
|
|
||||||
import type { MarkNonNullable } from "@excalidraw/common/utility-types";
|
import type { MarkNonNullable } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import type { Bounds } from "./bounds";
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
@@ -28,8 +27,6 @@ import type {
|
|||||||
ExcalidrawArrowElement,
|
ExcalidrawArrowElement,
|
||||||
ExcalidrawElbowArrowElement,
|
ExcalidrawElbowArrowElement,
|
||||||
ExcalidrawLineElement,
|
ExcalidrawLineElement,
|
||||||
PointBinding,
|
|
||||||
FixedPointBinding,
|
|
||||||
ExcalidrawFlowchartNodeElement,
|
ExcalidrawFlowchartNodeElement,
|
||||||
ExcalidrawLinearElementSubType,
|
ExcalidrawLinearElementSubType,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
@@ -163,7 +160,7 @@ export const isLinearElementType = (
|
|||||||
export const isBindingElement = (
|
export const isBindingElement = (
|
||||||
element?: ExcalidrawElement | null,
|
element?: ExcalidrawElement | null,
|
||||||
includeLocked = true,
|
includeLocked = true,
|
||||||
): element is ExcalidrawLinearElement => {
|
): element is ExcalidrawArrowElement => {
|
||||||
return (
|
return (
|
||||||
element != null &&
|
element != null &&
|
||||||
(!element.locked || includeLocked === true) &&
|
(!element.locked || includeLocked === true) &&
|
||||||
@@ -358,24 +355,6 @@ export const getDefaultRoundnessTypeForElement = (
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isFixedPointBinding = (
|
|
||||||
binding: PointBinding | FixedPointBinding,
|
|
||||||
): binding is FixedPointBinding => {
|
|
||||||
return (
|
|
||||||
Object.hasOwn(binding, "fixedPoint") &&
|
|
||||||
(binding as FixedPointBinding).fixedPoint != null
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Move this to @excalidraw/math
|
|
||||||
export const isBounds = (box: unknown): box is Bounds =>
|
|
||||||
Array.isArray(box) &&
|
|
||||||
box.length === 4 &&
|
|
||||||
typeof box[0] === "number" &&
|
|
||||||
typeof box[1] === "number" &&
|
|
||||||
typeof box[2] === "number" &&
|
|
||||||
typeof box[3] === "number";
|
|
||||||
|
|
||||||
export const getLinearElementSubType = (
|
export const getLinearElementSubType = (
|
||||||
element: ExcalidrawLinearElement,
|
element: ExcalidrawLinearElement,
|
||||||
): ExcalidrawLinearElementSubType => {
|
): ExcalidrawLinearElementSubType => {
|
||||||
|
|||||||
@@ -279,23 +279,22 @@ export type ExcalidrawTextElementWithContainer = {
|
|||||||
|
|
||||||
export type FixedPoint = [number, number];
|
export type FixedPoint = [number, number];
|
||||||
|
|
||||||
export type PointBinding = {
|
export type BindMode = "inside" | "orbit" | "skip";
|
||||||
elementId: ExcalidrawBindableElement["id"];
|
|
||||||
focus: number;
|
|
||||||
gap: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FixedPointBinding = Merge<
|
export type FixedPointBinding = {
|
||||||
PointBinding,
|
elementId: ExcalidrawBindableElement["id"];
|
||||||
{
|
|
||||||
// Represents the fixed point binding information in form of a vertical and
|
// Represents the fixed point binding information in form of a vertical and
|
||||||
// horizontal ratio (i.e. a percentage value in the 0.0-1.0 range). This ratio
|
// horizontal ratio (i.e. a percentage value in the 0.0-1.0 range). This ratio
|
||||||
// gives the user selected fixed point by multiplying the bound element width
|
// gives the user selected fixed point by multiplying the bound element width
|
||||||
// with fixedPoint[0] and the bound element height with fixedPoint[1] to get the
|
// with fixedPoint[0] and the bound element height with fixedPoint[1] to get the
|
||||||
// bound element-local point coordinate.
|
// bound element-local point coordinate.
|
||||||
fixedPoint: FixedPoint;
|
fixedPoint: FixedPoint;
|
||||||
}
|
|
||||||
>;
|
// Determines whether the arrow remains outside the shape or is allowed to
|
||||||
|
// go all the way inside the shape up to the exact fixed point.
|
||||||
|
mode: BindMode;
|
||||||
|
};
|
||||||
|
|
||||||
type Index = number;
|
type Index = number;
|
||||||
|
|
||||||
@@ -322,9 +321,8 @@ export type ExcalidrawLinearElement = _ExcalidrawElementBase &
|
|||||||
Readonly<{
|
Readonly<{
|
||||||
type: "line" | "arrow";
|
type: "line" | "arrow";
|
||||||
points: readonly LocalPoint[];
|
points: readonly LocalPoint[];
|
||||||
lastCommittedPoint: LocalPoint | null;
|
startBinding: FixedPointBinding | null;
|
||||||
startBinding: PointBinding | null;
|
endBinding: FixedPointBinding | null;
|
||||||
endBinding: PointBinding | null;
|
|
||||||
startArrowhead: Arrowhead | null;
|
startArrowhead: Arrowhead | null;
|
||||||
endArrowhead: Arrowhead | null;
|
endArrowhead: Arrowhead | null;
|
||||||
}>;
|
}>;
|
||||||
@@ -351,9 +349,9 @@ export type ExcalidrawElbowArrowElement = Merge<
|
|||||||
ExcalidrawArrowElement,
|
ExcalidrawArrowElement,
|
||||||
{
|
{
|
||||||
elbowed: true;
|
elbowed: true;
|
||||||
|
fixedSegments: readonly FixedSegment[] | null;
|
||||||
startBinding: FixedPointBinding | null;
|
startBinding: FixedPointBinding | null;
|
||||||
endBinding: FixedPointBinding | null;
|
endBinding: FixedPointBinding | null;
|
||||||
fixedSegments: readonly FixedSegment[] | null;
|
|
||||||
/**
|
/**
|
||||||
* Marks that the 3rd point should be used as the 2nd point of the arrow in
|
* Marks that the 3rd point should be used as the 2nd point of the arrow in
|
||||||
* order to temporarily hide the first segment of the arrow without losing
|
* order to temporarily hide the first segment of the arrow without losing
|
||||||
@@ -379,7 +377,6 @@ export type ExcalidrawFreeDrawElement = _ExcalidrawElementBase &
|
|||||||
points: readonly LocalPoint[];
|
points: readonly LocalPoint[];
|
||||||
pressures: readonly number[];
|
pressures: readonly number[];
|
||||||
simulatePressure: boolean;
|
simulatePressure: boolean;
|
||||||
lastCommittedPoint: LocalPoint | null;
|
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type FileId = string & { _brand: "FileId" };
|
export type FileId = string & { _brand: "FileId" };
|
||||||
|
|||||||
+152
-15
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
DEFAULT_ADAPTIVE_RADIUS,
|
DEFAULT_ADAPTIVE_RADIUS,
|
||||||
DEFAULT_PROPORTIONAL_RADIUS,
|
DEFAULT_PROPORTIONAL_RADIUS,
|
||||||
|
invariant,
|
||||||
LINE_CONFIRM_THRESHOLD,
|
LINE_CONFIRM_THRESHOLD,
|
||||||
ROUNDNESS,
|
ROUNDNESS,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
@@ -10,10 +11,17 @@ import {
|
|||||||
curveCatmullRomCubicApproxPoints,
|
curveCatmullRomCubicApproxPoints,
|
||||||
curveOffsetPoints,
|
curveOffsetPoints,
|
||||||
lineSegment,
|
lineSegment,
|
||||||
|
lineSegmentIntersectionPoints,
|
||||||
pointDistance,
|
pointDistance,
|
||||||
pointFrom,
|
pointFrom,
|
||||||
pointFromArray,
|
pointFromArray,
|
||||||
|
pointFromVector,
|
||||||
|
pointRotateRads,
|
||||||
|
pointTranslate,
|
||||||
rectangle,
|
rectangle,
|
||||||
|
vectorFromPoint,
|
||||||
|
vectorNormalize,
|
||||||
|
vectorScale,
|
||||||
type GlobalPoint,
|
type GlobalPoint,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
@@ -21,11 +29,17 @@ import type { Curve, LineSegment, LocalPoint } from "@excalidraw/math";
|
|||||||
|
|
||||||
import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types";
|
import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
import { getDiamondPoints } from "./bounds";
|
import { elementCenterPoint, getDiamondPoints } from "./bounds";
|
||||||
|
|
||||||
import { generateLinearCollisionShape } from "./shape";
|
import { generateLinearCollisionShape } from "./shape";
|
||||||
|
|
||||||
|
import { isPointInElement } from "./collision";
|
||||||
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
|
import { isRectangularElement } from "./typeChecks";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
ElementsMap,
|
||||||
|
ExcalidrawArrowElement,
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawFreeDrawElement,
|
ExcalidrawFreeDrawElement,
|
||||||
@@ -400,20 +414,10 @@ export function deconstructDiamondElement(
|
|||||||
), // TOP
|
), // TOP
|
||||||
];
|
];
|
||||||
|
|
||||||
const corners =
|
const corners = baseCorners.map(
|
||||||
offset > 0
|
(corner) =>
|
||||||
? baseCorners.map(
|
curveCatmullRomCubicApproxPoints(curveOffsetPoints(corner, offset))!,
|
||||||
(corner) =>
|
);
|
||||||
curveCatmullRomCubicApproxPoints(
|
|
||||||
curveOffsetPoints(corner, offset),
|
|
||||||
)!,
|
|
||||||
)
|
|
||||||
: [
|
|
||||||
[baseCorners[0]],
|
|
||||||
[baseCorners[1]],
|
|
||||||
[baseCorners[2]],
|
|
||||||
[baseCorners[3]],
|
|
||||||
];
|
|
||||||
|
|
||||||
const sides = [
|
const sides = [
|
||||||
lineSegment<GlobalPoint>(
|
lineSegment<GlobalPoint>(
|
||||||
@@ -481,3 +485,136 @@ export const getCornerRadius = (x: number, element: ExcalidrawElement) => {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getDiagonalsForBindableElement = (
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
) => {
|
||||||
|
// for rectangles, shrink the diagonals a bit because there's something
|
||||||
|
// going on with the focus points around the corners. Ask Mark for details.
|
||||||
|
const OFFSET_PX = element.type === "rectangle" ? 15 : 0;
|
||||||
|
const shrinkSegment = (seg: LineSegment<GlobalPoint>) => {
|
||||||
|
const v = vectorNormalize(vectorFromPoint(seg[1], seg[0]));
|
||||||
|
const offset = vectorScale(v, OFFSET_PX);
|
||||||
|
return lineSegment<GlobalPoint>(
|
||||||
|
pointTranslate(seg[0], offset),
|
||||||
|
pointTranslate(seg[1], vectorScale(offset, -1)),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const center = elementCenterPoint(element, elementsMap);
|
||||||
|
const diagonalOne = shrinkSegment(
|
||||||
|
isRectangularElement(element)
|
||||||
|
? lineSegment<GlobalPoint>(
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x, element.y),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
element.x + element.width,
|
||||||
|
element.y + element.height,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: lineSegment<GlobalPoint>(
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x + element.width / 2, element.y),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
element.x + element.width / 2,
|
||||||
|
element.y + element.height,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const diagonalTwo = shrinkSegment(
|
||||||
|
isRectangularElement(element)
|
||||||
|
? lineSegment<GlobalPoint>(
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x + element.width, element.y),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x, element.y + element.height),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: lineSegment<GlobalPoint>(
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x, element.y + element.height / 2),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
element.x + element.width,
|
||||||
|
element.y + element.height / 2,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return [diagonalOne, diagonalTwo];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const projectFixedPointOntoDiagonal = (
|
||||||
|
arrow: ExcalidrawArrowElement,
|
||||||
|
point: GlobalPoint,
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
startOrEnd: "start" | "end",
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
): GlobalPoint | null => {
|
||||||
|
invariant(arrow.points.length >= 2, "Arrow must have at least two points");
|
||||||
|
if (arrow.width < 3 && arrow.height < 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [diagonalOne, diagonalTwo] = getDiagonalsForBindableElement(
|
||||||
|
element,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
const a = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
arrow,
|
||||||
|
startOrEnd === "start" ? 1 : arrow.points.length - 2,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
const b = pointFromVector<GlobalPoint>(
|
||||||
|
vectorScale(
|
||||||
|
vectorFromPoint(point, a),
|
||||||
|
2 * pointDistance(a, point) +
|
||||||
|
Math.max(
|
||||||
|
pointDistance(diagonalOne[0], diagonalOne[1]),
|
||||||
|
pointDistance(diagonalTwo[0], diagonalTwo[1]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
a,
|
||||||
|
);
|
||||||
|
const intersector = lineSegment<GlobalPoint>(point, b);
|
||||||
|
const p1 = lineSegmentIntersectionPoints(diagonalOne, intersector);
|
||||||
|
const p2 = lineSegmentIntersectionPoints(diagonalTwo, intersector);
|
||||||
|
const d1 = p1 && pointDistance(a, p1);
|
||||||
|
const d2 = p2 && pointDistance(a, p2);
|
||||||
|
|
||||||
|
let p = null;
|
||||||
|
if (d1 != null && d2 != null) {
|
||||||
|
p = d1 < d2 ? p1 : p2;
|
||||||
|
} else {
|
||||||
|
p = p1 || p2 || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return p && isPointInElement(p, element, elementsMap) ? p : null;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common";
|
import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common";
|
||||||
|
|
||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
import type { AppState } from "@excalidraw/excalidraw/types";
|
||||||
|
import type { GlobalPoint } from "@excalidraw/math";
|
||||||
|
|
||||||
import { isFrameLikeElement } from "./typeChecks";
|
import { isFrameLikeElement, isTextElement } from "./typeChecks";
|
||||||
|
|
||||||
import { getElementsInGroup } from "./groups";
|
import { getElementsInGroup } from "./groups";
|
||||||
|
|
||||||
import { syncMovedIndices } from "./fractionalIndex";
|
import { syncMovedIndices } from "./fractionalIndex";
|
||||||
|
|
||||||
import { getSelectedElements } from "./selection";
|
import { getSelectedElements } from "./selection";
|
||||||
|
import { getBoundTextElement, getContainerElement } from "./textElement";
|
||||||
|
import { getHoveredElementForBinding } from "./collision";
|
||||||
|
|
||||||
import type { Scene } from "./Scene";
|
import type { Scene } from "./Scene";
|
||||||
|
import type {
|
||||||
import type { ExcalidrawElement, ExcalidrawFrameLikeElement } from "./types";
|
ExcalidrawArrowElement,
|
||||||
|
ExcalidrawElement,
|
||||||
|
ExcalidrawFrameLikeElement,
|
||||||
|
NonDeletedExcalidrawElement,
|
||||||
|
NonDeletedSceneElementsMap,
|
||||||
|
Ordered,
|
||||||
|
OrderedExcalidrawElement,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => {
|
const isOfTargetFrame = (element: ExcalidrawElement, frameId: string) => {
|
||||||
return element.frameId === frameId || element.id === frameId;
|
return element.frameId === frameId || element.id === frameId;
|
||||||
@@ -139,6 +146,51 @@ const getContiguousFrameRangeElements = (
|
|||||||
return allElements.slice(rangeStart, rangeEnd + 1);
|
return allElements.slice(rangeStart, rangeEnd + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the arrow element above any bindable elements it intersects with or
|
||||||
|
* hovers over.
|
||||||
|
*/
|
||||||
|
export const moveArrowAboveBindable = (
|
||||||
|
point: GlobalPoint,
|
||||||
|
arrow: ExcalidrawArrowElement,
|
||||||
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
scene: Scene,
|
||||||
|
): readonly OrderedExcalidrawElement[] => {
|
||||||
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
|
point,
|
||||||
|
elements,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hoveredElement) {
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
const boundTextElement = getBoundTextElement(hoveredElement, elementsMap);
|
||||||
|
const containerElement = isTextElement(hoveredElement)
|
||||||
|
? getContainerElement(hoveredElement, elementsMap)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const bindableIds = [
|
||||||
|
hoveredElement.id,
|
||||||
|
boundTextElement?.id,
|
||||||
|
containerElement?.id,
|
||||||
|
].filter((id): id is NonDeletedExcalidrawElement["id"] => !!id);
|
||||||
|
const bindableIdx = elements.findIndex((el) => bindableIds.includes(el.id));
|
||||||
|
const arrowIdx = elements.findIndex((el) => el.id === arrow.id);
|
||||||
|
|
||||||
|
if (arrowIdx !== -1 && bindableIdx !== -1 && arrowIdx < bindableIdx) {
|
||||||
|
const updatedElements = Array.from(elements);
|
||||||
|
const arrow = updatedElements.splice(arrowIdx, 1)[0];
|
||||||
|
updatedElements.splice(bindableIdx, 0, arrow);
|
||||||
|
|
||||||
|
scene.replaceAllElements(updatedElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns next candidate index that's available to be moved to. Currently that
|
* Returns next candidate index that's available to be moved to. Currently that
|
||||||
* is a non-deleted element, and not inside a group (unless we're editing it).
|
* is a non-deleted element, and not inside a group (unless we're editing it).
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -135,9 +135,9 @@ describe("getElementBounds", () => {
|
|||||||
} as ExcalidrawLinearElement;
|
} as ExcalidrawLinearElement;
|
||||||
|
|
||||||
const [x1, y1, x2, y2] = getElementBounds(element, arrayToMap([element]));
|
const [x1, y1, x2, y2] = getElementBounds(element, arrayToMap([element]));
|
||||||
expect(x1).toEqual(360.3176068760539);
|
expect(x1).toEqual(360.9291017525165);
|
||||||
expect(y1).toEqual(185.90654264413516);
|
expect(y1).toEqual(185.24770129343722);
|
||||||
expect(x2).toEqual(480.87005902729743);
|
expect(x2).toEqual(481.4815539037601);
|
||||||
expect(y2).toEqual(320.4751269334226);
|
expect(y2).toEqual(319.8162855827246);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -144,9 +144,8 @@ describe("duplicating multiple elements", () => {
|
|||||||
id: "arrow1",
|
id: "arrow1",
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: "rectangle1",
|
elementId: "rectangle1",
|
||||||
focus: 0.2,
|
|
||||||
gap: 7,
|
|
||||||
fixedPoint: [0.5, 1],
|
fixedPoint: [0.5, 1],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -155,9 +154,8 @@ describe("duplicating multiple elements", () => {
|
|||||||
id: "arrow2",
|
id: "arrow2",
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: "rectangle1",
|
elementId: "rectangle1",
|
||||||
focus: 0.2,
|
|
||||||
gap: 7,
|
|
||||||
fixedPoint: [0.5, 1],
|
fixedPoint: [0.5, 1],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
boundElements: [{ id: "text2", type: "text" }],
|
boundElements: [{ id: "text2", type: "text" }],
|
||||||
});
|
});
|
||||||
@@ -276,9 +274,8 @@ describe("duplicating multiple elements", () => {
|
|||||||
id: "arrow1",
|
id: "arrow1",
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: "rectangle1",
|
elementId: "rectangle1",
|
||||||
focus: 0.2,
|
|
||||||
gap: 7,
|
|
||||||
fixedPoint: [0.5, 1],
|
fixedPoint: [0.5, 1],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -293,15 +290,13 @@ describe("duplicating multiple elements", () => {
|
|||||||
id: "arrow2",
|
id: "arrow2",
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: "rectangle1",
|
elementId: "rectangle1",
|
||||||
focus: 0.2,
|
|
||||||
gap: 7,
|
|
||||||
fixedPoint: [0.5, 1],
|
fixedPoint: [0.5, 1],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: "rectangle-not-exists",
|
elementId: "rectangle-not-exists",
|
||||||
focus: 0.2,
|
|
||||||
gap: 7,
|
|
||||||
fixedPoint: [0.5, 1],
|
fixedPoint: [0.5, 1],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -310,15 +305,13 @@ describe("duplicating multiple elements", () => {
|
|||||||
id: "arrow3",
|
id: "arrow3",
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: "rectangle-not-exists",
|
elementId: "rectangle-not-exists",
|
||||||
focus: 0.2,
|
|
||||||
gap: 7,
|
|
||||||
fixedPoint: [0.5, 1],
|
fixedPoint: [0.5, 1],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: "rectangle1",
|
elementId: "rectangle1",
|
||||||
focus: 0.2,
|
|
||||||
gap: 7,
|
|
||||||
fixedPoint: [0.5, 1],
|
fixedPoint: [0.5, 1],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -821,7 +814,7 @@ describe("duplication z-order", () => {
|
|||||||
const arrow = UI.createElement("arrow", {
|
const arrow = UI.createElement("arrow", {
|
||||||
x: -100,
|
x: -100,
|
||||||
y: 50,
|
y: 50,
|
||||||
width: 95,
|
width: 115,
|
||||||
height: 0,
|
height: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import { ARROW_TYPE } from "@excalidraw/common";
|
import { ARROW_TYPE } from "@excalidraw/common";
|
||||||
import { pointFrom } from "@excalidraw/math";
|
import { pointFrom } from "@excalidraw/math";
|
||||||
import { Excalidraw } from "@excalidraw/excalidraw";
|
import { Excalidraw } from "@excalidraw/excalidraw";
|
||||||
|
|
||||||
import { actionSelectAll } from "@excalidraw/excalidraw/actions";
|
import { actionSelectAll } from "@excalidraw/excalidraw/actions";
|
||||||
import { actionDuplicateSelection } from "@excalidraw/excalidraw/actions/actionDuplicateSelection";
|
import { actionDuplicateSelection } from "@excalidraw/excalidraw/actions/actionDuplicateSelection";
|
||||||
|
|
||||||
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
||||||
import { Pointer, UI } from "@excalidraw/excalidraw/tests/helpers/ui";
|
import { Pointer, UI } from "@excalidraw/excalidraw/tests/helpers/ui";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
act,
|
act,
|
||||||
fireEvent,
|
fireEvent,
|
||||||
@@ -15,13 +12,11 @@ import {
|
|||||||
queryByTestId,
|
queryByTestId,
|
||||||
render,
|
render,
|
||||||
} from "@excalidraw/excalidraw/tests/test-utils";
|
} from "@excalidraw/excalidraw/tests/test-utils";
|
||||||
|
|
||||||
import "@excalidraw/utils/test-utils";
|
import "@excalidraw/utils/test-utils";
|
||||||
|
import { bindBindingElement } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { LocalPoint } from "@excalidraw/math";
|
import type { LocalPoint } from "@excalidraw/math";
|
||||||
|
|
||||||
import { bindLinearElement } from "../src/binding";
|
|
||||||
|
|
||||||
import { Scene } from "../src/Scene";
|
import { Scene } from "../src/Scene";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -136,6 +131,11 @@ describe("elbow arrow segment move", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("elbow arrow routing", () => {
|
describe("elbow arrow routing", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
localStorage.clear();
|
||||||
|
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
||||||
|
});
|
||||||
|
|
||||||
it("can properly generate orthogonal arrow points", () => {
|
it("can properly generate orthogonal arrow points", () => {
|
||||||
const scene = new Scene();
|
const scene = new Scene();
|
||||||
const arrow = API.createElement({
|
const arrow = API.createElement({
|
||||||
@@ -160,8 +160,8 @@ describe("elbow arrow routing", () => {
|
|||||||
expect(arrow.width).toEqual(90);
|
expect(arrow.width).toEqual(90);
|
||||||
expect(arrow.height).toEqual(200);
|
expect(arrow.height).toEqual(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can generate proper points for bound elbow arrow", () => {
|
it("can generate proper points for bound elbow arrow", () => {
|
||||||
const scene = new Scene();
|
|
||||||
const rectangle1 = API.createElement({
|
const rectangle1 = API.createElement({
|
||||||
type: "rectangle",
|
type: "rectangle",
|
||||||
x: -150,
|
x: -150,
|
||||||
@@ -185,25 +185,23 @@ describe("elbow arrow routing", () => {
|
|||||||
height: 200,
|
height: 200,
|
||||||
points: [pointFrom(0, 0), pointFrom(90, 200)],
|
points: [pointFrom(0, 0), pointFrom(90, 200)],
|
||||||
}) as ExcalidrawElbowArrowElement;
|
}) as ExcalidrawElbowArrowElement;
|
||||||
scene.insertElement(rectangle1);
|
API.setElements([rectangle1, rectangle2, arrow]);
|
||||||
scene.insertElement(rectangle2);
|
|
||||||
scene.insertElement(arrow);
|
|
||||||
|
|
||||||
bindLinearElement(arrow, rectangle1, "start", scene);
|
bindBindingElement(arrow, rectangle1, "orbit", "start", h.scene);
|
||||||
bindLinearElement(arrow, rectangle2, "end", scene);
|
bindBindingElement(arrow, rectangle2, "orbit", "end", h.scene);
|
||||||
|
|
||||||
expect(arrow.startBinding).not.toBe(null);
|
expect(arrow.startBinding).not.toBe(null);
|
||||||
expect(arrow.endBinding).not.toBe(null);
|
expect(arrow.endBinding).not.toBe(null);
|
||||||
|
|
||||||
h.app.scene.mutateElement(arrow, {
|
h.scene.mutateElement(arrow, {
|
||||||
points: [pointFrom<LocalPoint>(0, 0), pointFrom<LocalPoint>(90, 200)],
|
points: [pointFrom<LocalPoint>(0, 0), pointFrom<LocalPoint>(90, 200)],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(arrow.points).toEqual([
|
expect(arrow.points).toCloselyEqualPoints([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[45, 0],
|
[39, 0],
|
||||||
[45, 200],
|
[39, 200],
|
||||||
[90, 200],
|
[78, 200],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -242,9 +240,9 @@ describe("elbow arrow ui", () => {
|
|||||||
expect(h.state.currentItemArrowType).toBe(ARROW_TYPE.elbow);
|
expect(h.state.currentItemArrowType).toBe(ARROW_TYPE.elbow);
|
||||||
|
|
||||||
mouse.reset();
|
mouse.reset();
|
||||||
mouse.moveTo(-43, -99);
|
mouse.moveTo(-53, -99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
mouse.moveTo(43, 99);
|
mouse.moveTo(53, 99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
|
|
||||||
const arrow = h.scene.getSelectedElements(
|
const arrow = h.scene.getSelectedElements(
|
||||||
@@ -253,11 +251,11 @@ describe("elbow arrow ui", () => {
|
|||||||
|
|
||||||
expect(arrow.type).toBe("arrow");
|
expect(arrow.type).toBe("arrow");
|
||||||
expect(arrow.elbowed).toBe(true);
|
expect(arrow.elbowed).toBe(true);
|
||||||
expect(arrow.points).toEqual([
|
expect(arrow.points).toCloselyEqualPoints([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[45, 0],
|
[39, 0],
|
||||||
[45, 200],
|
[39, 200],
|
||||||
[90, 200],
|
[78, 200],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -279,9 +277,9 @@ describe("elbow arrow ui", () => {
|
|||||||
UI.clickOnTestId("elbow-arrow");
|
UI.clickOnTestId("elbow-arrow");
|
||||||
|
|
||||||
mouse.reset();
|
mouse.reset();
|
||||||
mouse.moveTo(-43, -99);
|
mouse.moveTo(-53, -99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
mouse.moveTo(43, 99);
|
mouse.moveTo(53, 99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
|
|
||||||
const arrow = h.scene.getSelectedElements(
|
const arrow = h.scene.getSelectedElements(
|
||||||
@@ -297,9 +295,11 @@ describe("elbow arrow ui", () => {
|
|||||||
|
|
||||||
expect(arrow.points.map((point) => point.map(Math.round))).toEqual([
|
expect(arrow.points.map((point) => point.map(Math.round))).toEqual([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[35, 0],
|
[36, 0],
|
||||||
[35, 165],
|
[36, 90],
|
||||||
[103, 165],
|
[28, 90],
|
||||||
|
[28, 164],
|
||||||
|
[101, 164],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -321,9 +321,9 @@ describe("elbow arrow ui", () => {
|
|||||||
UI.clickOnTestId("elbow-arrow");
|
UI.clickOnTestId("elbow-arrow");
|
||||||
|
|
||||||
mouse.reset();
|
mouse.reset();
|
||||||
mouse.moveTo(-43, -99);
|
mouse.moveTo(-53, -99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
mouse.moveTo(43, 99);
|
mouse.moveTo(53, 99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
|
|
||||||
const arrow = h.scene.getSelectedElements(
|
const arrow = h.scene.getSelectedElements(
|
||||||
@@ -351,11 +351,11 @@ describe("elbow arrow ui", () => {
|
|||||||
expect(duplicatedArrow.id).not.toBe(originalArrowId);
|
expect(duplicatedArrow.id).not.toBe(originalArrowId);
|
||||||
expect(duplicatedArrow.type).toBe("arrow");
|
expect(duplicatedArrow.type).toBe("arrow");
|
||||||
expect(duplicatedArrow.elbowed).toBe(true);
|
expect(duplicatedArrow.elbowed).toBe(true);
|
||||||
expect(duplicatedArrow.points).toEqual([
|
expect(duplicatedArrow.points).toCloselyEqualPoints([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[45, 0],
|
[39, 0],
|
||||||
[45, 200],
|
[39, 200],
|
||||||
[90, 200],
|
[78, 200],
|
||||||
]);
|
]);
|
||||||
expect(arrow.startBinding).not.toBe(null);
|
expect(arrow.startBinding).not.toBe(null);
|
||||||
expect(arrow.endBinding).not.toBe(null);
|
expect(arrow.endBinding).not.toBe(null);
|
||||||
@@ -379,9 +379,9 @@ describe("elbow arrow ui", () => {
|
|||||||
UI.clickOnTestId("elbow-arrow");
|
UI.clickOnTestId("elbow-arrow");
|
||||||
|
|
||||||
mouse.reset();
|
mouse.reset();
|
||||||
mouse.moveTo(-43, -99);
|
mouse.moveTo(-53, -99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
mouse.moveTo(43, 99);
|
mouse.moveTo(53, 99);
|
||||||
mouse.click();
|
mouse.click();
|
||||||
|
|
||||||
const arrow = h.scene.getSelectedElements(
|
const arrow = h.scene.getSelectedElements(
|
||||||
@@ -405,11 +405,11 @@ describe("elbow arrow ui", () => {
|
|||||||
expect(duplicatedArrow.id).not.toBe(originalArrowId);
|
expect(duplicatedArrow.id).not.toBe(originalArrowId);
|
||||||
expect(duplicatedArrow.type).toBe("arrow");
|
expect(duplicatedArrow.type).toBe("arrow");
|
||||||
expect(duplicatedArrow.elbowed).toBe(true);
|
expect(duplicatedArrow.elbowed).toBe(true);
|
||||||
expect(duplicatedArrow.points).toEqual([
|
expect(duplicatedArrow.points).toCloselyEqualPoints([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[0, 100],
|
[0, 100],
|
||||||
[90, 100],
|
[78, 100],
|
||||||
[90, 200],
|
[78, 200],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ describe("Test Linear Elements", () => {
|
|||||||
|
|
||||||
// drag line from midpoint
|
// drag line from midpoint
|
||||||
drag(midpoint, pointFrom(midpoint[0] + delta, midpoint[1] + delta));
|
drag(midpoint, pointFrom(midpoint[0] + delta, midpoint[1] + delta));
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(`9`);
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(`8`);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
expect(line.points.length).toEqual(3);
|
expect(line.points.length).toEqual(3);
|
||||||
expect(line.points).toMatchInlineSnapshot(`
|
expect(line.points).toMatchInlineSnapshot(`
|
||||||
@@ -329,7 +329,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
||||||
|
|
||||||
mouse.doubleClick();
|
mouse.doubleClick();
|
||||||
expect(h.state.selectedLinearElement).toBe(null);
|
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
||||||
await getTextEditor();
|
await getTextEditor();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -357,6 +357,7 @@ describe("Test Linear Elements", () => {
|
|||||||
const originalY = line.y;
|
const originalY = line.y;
|
||||||
enterLineEditingMode(line);
|
enterLineEditingMode(line);
|
||||||
|
|
||||||
|
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
||||||
expect(line.points.length).toEqual(2);
|
expect(line.points.length).toEqual(2);
|
||||||
|
|
||||||
mouse.clickAt(midpoint[0], midpoint[1]);
|
mouse.clickAt(midpoint[0], midpoint[1]);
|
||||||
@@ -379,7 +380,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`11`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
expect(line.points.length).toEqual(3);
|
expect(line.points.length).toEqual(3);
|
||||||
expect(line.points).toMatchInlineSnapshot(`
|
expect(line.points).toMatchInlineSnapshot(`
|
||||||
@@ -549,7 +550,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`14`,
|
`14`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`9`);
|
||||||
|
|
||||||
expect(line.points.length).toEqual(5);
|
expect(line.points.length).toEqual(5);
|
||||||
|
|
||||||
@@ -600,7 +601,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`11`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
const newPoints = LinearElementEditor.getPointsGlobalCoordinates(
|
const newPoints = LinearElementEditor.getPointsGlobalCoordinates(
|
||||||
line,
|
line,
|
||||||
@@ -641,7 +642,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`11`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
const newPoints = LinearElementEditor.getPointsGlobalCoordinates(
|
const newPoints = LinearElementEditor.getPointsGlobalCoordinates(
|
||||||
line,
|
line,
|
||||||
@@ -689,7 +690,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`17`,
|
`17`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`10`);
|
||||||
|
|
||||||
const newMidPoints = LinearElementEditor.getEditorMidPoints(
|
const newMidPoints = LinearElementEditor.getEditorMidPoints(
|
||||||
line,
|
line,
|
||||||
@@ -747,7 +748,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`14`,
|
`14`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`9`);
|
||||||
expect(line.points.length).toEqual(5);
|
expect(line.points.length).toEqual(5);
|
||||||
|
|
||||||
expect((h.elements[0] as ExcalidrawLinearElement).points)
|
expect((h.elements[0] as ExcalidrawLinearElement).points)
|
||||||
@@ -845,7 +846,7 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`11`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
const newPoints = LinearElementEditor.getPointsGlobalCoordinates(
|
const newPoints = LinearElementEditor.getPointsGlobalCoordinates(
|
||||||
line,
|
line,
|
||||||
@@ -1303,7 +1304,7 @@ describe("Test Linear Elements", () => {
|
|||||||
const arrow = UI.createElement("arrow", {
|
const arrow = UI.createElement("arrow", {
|
||||||
x: -10,
|
x: -10,
|
||||||
y: 250,
|
y: 250,
|
||||||
width: 400,
|
width: 410,
|
||||||
height: 1,
|
height: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1316,7 +1317,7 @@ describe("Test Linear Elements", () => {
|
|||||||
const textElement = h.elements[2] as ExcalidrawTextElementWithContainer;
|
const textElement = h.elements[2] as ExcalidrawTextElementWithContainer;
|
||||||
|
|
||||||
expect(arrow.endBinding?.elementId).toBe(rect.id);
|
expect(arrow.endBinding?.elementId).toBe(rect.id);
|
||||||
expect(arrow.width).toBe(400);
|
expect(arrow.width).toBeCloseTo(399);
|
||||||
expect(rect.x).toBe(400);
|
expect(rect.x).toBe(400);
|
||||||
expect(rect.y).toBe(0);
|
expect(rect.y).toBe(0);
|
||||||
expect(
|
expect(
|
||||||
@@ -1335,7 +1336,7 @@ describe("Test Linear Elements", () => {
|
|||||||
mouse.downAt(rect.x, rect.y);
|
mouse.downAt(rect.x, rect.y);
|
||||||
mouse.moveTo(200, 0);
|
mouse.moveTo(200, 0);
|
||||||
mouse.upAt(200, 0);
|
mouse.upAt(200, 0);
|
||||||
expect(arrow.width).toBeCloseTo(200, 0);
|
expect(arrow.width).toBeCloseTo(199);
|
||||||
expect(rect.x).toBe(200);
|
expect(rect.x).toBe(200);
|
||||||
expect(rect.y).toBe(0);
|
expect(rect.y).toBe(0);
|
||||||
expect(handleBindTextResizeSpy).toHaveBeenCalledWith(
|
expect(handleBindTextResizeSpy).toHaveBeenCalledWith(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { pointFrom } from "@excalidraw/math";
|
|||||||
|
|
||||||
import { Excalidraw } from "@excalidraw/excalidraw";
|
import { Excalidraw } from "@excalidraw/excalidraw";
|
||||||
import {
|
import {
|
||||||
|
type Bounds,
|
||||||
KEYS,
|
KEYS,
|
||||||
getSizeFromPoints,
|
getSizeFromPoints,
|
||||||
reseed,
|
reseed,
|
||||||
@@ -22,7 +23,6 @@ import { resizeSingleElement } from "../src/resizeElements";
|
|||||||
import { LinearElementEditor } from "../src/linearElementEditor";
|
import { LinearElementEditor } from "../src/linearElementEditor";
|
||||||
import { getElementPointsCoords } from "../src/bounds";
|
import { getElementPointsCoords } from "../src/bounds";
|
||||||
|
|
||||||
import type { Bounds } from "../src/bounds";
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElbowArrowElement,
|
ExcalidrawElbowArrowElement,
|
||||||
ExcalidrawFreeDrawElement,
|
ExcalidrawFreeDrawElement,
|
||||||
@@ -174,29 +174,29 @@ describe("generic element", () => {
|
|||||||
expect(rectangle.angle).toBeCloseTo(0);
|
expect(rectangle.angle).toBeCloseTo(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resizes with bound arrow", async () => {
|
// it("resizes with bound arrow", async () => {
|
||||||
const rectangle = UI.createElement("rectangle", {
|
// const rectangle = UI.createElement("rectangle", {
|
||||||
width: 200,
|
// width: 200,
|
||||||
height: 100,
|
// height: 100,
|
||||||
});
|
// });
|
||||||
const arrow = UI.createElement("arrow", {
|
// const arrow = UI.createElement("arrow", {
|
||||||
x: -30,
|
// x: -30,
|
||||||
y: 50,
|
// y: 50,
|
||||||
width: 28,
|
// width: 28,
|
||||||
height: 5,
|
// height: 5,
|
||||||
});
|
// });
|
||||||
|
|
||||||
expect(arrow.endBinding?.elementId).toEqual(rectangle.id);
|
// expect(arrow.endBinding?.elementId).toEqual(rectangle.id);
|
||||||
|
|
||||||
UI.resize(rectangle, "e", [40, 0]);
|
// UI.resize(rectangle, "e", [40, 0]);
|
||||||
|
|
||||||
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(30, 0);
|
// expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(30, 0);
|
||||||
|
|
||||||
UI.resize(rectangle, "w", [50, 0]);
|
// UI.resize(rectangle, "w", [50, 0]);
|
||||||
|
|
||||||
expect(arrow.endBinding?.elementId).toEqual(rectangle.id);
|
// expect(arrow.endBinding?.elementId).toEqual(rectangle.id);
|
||||||
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(80, 0);
|
// expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(80, 0);
|
||||||
});
|
// });
|
||||||
|
|
||||||
it("resizes with a label", async () => {
|
it("resizes with a label", async () => {
|
||||||
const rectangle = UI.createElement("rectangle", {
|
const rectangle = UI.createElement("rectangle", {
|
||||||
@@ -510,12 +510,12 @@ describe("arrow element", () => {
|
|||||||
h.state,
|
h.state,
|
||||||
)[0] as ExcalidrawElbowArrowElement;
|
)[0] as ExcalidrawElbowArrowElement;
|
||||||
|
|
||||||
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
|
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.06);
|
||||||
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
|
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
|
||||||
|
|
||||||
UI.resize(rectangle, "se", [-200, -150]);
|
UI.resize(rectangle, "se", [-200, -150]);
|
||||||
|
|
||||||
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
|
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.06);
|
||||||
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
|
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -538,11 +538,11 @@ describe("arrow element", () => {
|
|||||||
h.state,
|
h.state,
|
||||||
)[0] as ExcalidrawElbowArrowElement;
|
)[0] as ExcalidrawElbowArrowElement;
|
||||||
|
|
||||||
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
|
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.06);
|
||||||
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
|
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
|
||||||
|
|
||||||
UI.resize([rectangle, arrow], "nw", [300, 350]);
|
UI.resize([rectangle, arrow], "nw", [300, 350]);
|
||||||
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(-0.05);
|
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(-0.06);
|
||||||
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.25);
|
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.25);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -595,31 +595,31 @@ describe("text element", () => {
|
|||||||
expect(text.fontSize).toBeCloseTo(fontSize * scale);
|
expect(text.fontSize).toBeCloseTo(fontSize * scale);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resizes with bound arrow", async () => {
|
// it("resizes with bound arrow", async () => {
|
||||||
const text = UI.createElement("text");
|
// const text = UI.createElement("text");
|
||||||
await UI.editText(text, "hello\nworld");
|
// await UI.editText(text, "hello\nworld");
|
||||||
const boundArrow = UI.createElement("arrow", {
|
// const boundArrow = UI.createElement("arrow", {
|
||||||
x: -30,
|
// x: -30,
|
||||||
y: 25,
|
// y: 25,
|
||||||
width: 28,
|
// width: 28,
|
||||||
height: 5,
|
// height: 5,
|
||||||
});
|
// });
|
||||||
|
|
||||||
expect(boundArrow.endBinding?.elementId).toEqual(text.id);
|
// expect(boundArrow.endBinding?.elementId).toEqual(text.id);
|
||||||
|
|
||||||
UI.resize(text, "ne", [40, 0]);
|
// UI.resize(text, "ne", [40, 0]);
|
||||||
|
|
||||||
expect(boundArrow.width + boundArrow.endBinding!.gap).toBeCloseTo(30);
|
// expect(boundArrow.width + boundArrow.endBinding!.gap).toBeCloseTo(30);
|
||||||
|
|
||||||
const textWidth = text.width;
|
// const textWidth = text.width;
|
||||||
const scale = 20 / text.height;
|
// const scale = 20 / text.height;
|
||||||
UI.resize(text, "nw", [50, 20]);
|
// UI.resize(text, "nw", [50, 20]);
|
||||||
|
|
||||||
expect(boundArrow.endBinding?.elementId).toEqual(text.id);
|
// expect(boundArrow.endBinding?.elementId).toEqual(text.id);
|
||||||
expect(boundArrow.width + boundArrow.endBinding!.gap).toBeCloseTo(
|
// expect(boundArrow.width + boundArrow.endBinding!.gap).toBeCloseTo(
|
||||||
30 + textWidth * scale,
|
// 30 + textWidth * scale,
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
it("updates font size via keyboard", async () => {
|
it("updates font size via keyboard", async () => {
|
||||||
const text = UI.createElement("text");
|
const text = UI.createElement("text");
|
||||||
@@ -801,36 +801,36 @@ describe("image element", () => {
|
|||||||
expect(image.scale).toEqual([1, 1]);
|
expect(image.scale).toEqual([1, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resizes with bound arrow", async () => {
|
// it("resizes with bound arrow", async () => {
|
||||||
const image = API.createElement({
|
// const image = API.createElement({
|
||||||
type: "image",
|
// type: "image",
|
||||||
width: 100,
|
// width: 100,
|
||||||
height: 100,
|
// height: 100,
|
||||||
});
|
// });
|
||||||
API.setElements([image]);
|
// API.setElements([image]);
|
||||||
const arrow = UI.createElement("arrow", {
|
// const arrow = UI.createElement("arrow", {
|
||||||
x: -30,
|
// x: -30,
|
||||||
y: 50,
|
// y: 50,
|
||||||
width: 28,
|
// width: 28,
|
||||||
height: 5,
|
// height: 5,
|
||||||
});
|
// });
|
||||||
|
|
||||||
expect(arrow.endBinding?.elementId).toEqual(image.id);
|
// expect(arrow.endBinding?.elementId).toEqual(image.id);
|
||||||
|
|
||||||
UI.resize(image, "ne", [40, 0]);
|
// UI.resize(image, "ne", [40, 0]);
|
||||||
|
|
||||||
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(30, 0);
|
// expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(30, 0);
|
||||||
|
|
||||||
const imageWidth = image.width;
|
// const imageWidth = image.width;
|
||||||
const scale = 20 / image.height;
|
// const scale = 20 / image.height;
|
||||||
UI.resize(image, "nw", [50, 20]);
|
// UI.resize(image, "nw", [50, 20]);
|
||||||
|
|
||||||
expect(arrow.endBinding?.elementId).toEqual(image.id);
|
// expect(arrow.endBinding?.elementId).toEqual(image.id);
|
||||||
expect(Math.floor(arrow.width + arrow.endBinding!.gap)).toBeCloseTo(
|
// expect(Math.floor(arrow.width + arrow.endBinding!.gap)).toBeCloseTo(
|
||||||
30 + imageWidth * scale,
|
// 30 + imageWidth * scale,
|
||||||
0,
|
// 0,
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("multiple selection", () => {
|
describe("multiple selection", () => {
|
||||||
@@ -997,68 +997,80 @@ describe("multiple selection", () => {
|
|||||||
expect(diagLine.angle).toEqual(0);
|
expect(diagLine.angle).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resizes with bound arrows", async () => {
|
// it("resizes with bound arrows", async () => {
|
||||||
const rectangle = UI.createElement("rectangle", {
|
// const rectangle = UI.createElement("rectangle", {
|
||||||
position: 0,
|
// position: 0,
|
||||||
size: 100,
|
// size: 100,
|
||||||
});
|
// });
|
||||||
const leftBoundArrow = UI.createElement("arrow", {
|
// const leftBoundArrow = UI.createElement("arrow", {
|
||||||
x: -110,
|
// x: -110,
|
||||||
y: 50,
|
// y: 50,
|
||||||
width: 100,
|
// width: 100,
|
||||||
height: 0,
|
// height: 0,
|
||||||
});
|
// });
|
||||||
|
|
||||||
const rightBoundArrow = UI.createElement("arrow", {
|
// const rightBoundArrow = UI.createElement("arrow", {
|
||||||
x: 210,
|
// x: 210,
|
||||||
y: 50,
|
// y: 50,
|
||||||
width: -100,
|
// width: -100,
|
||||||
height: 0,
|
// height: 0,
|
||||||
});
|
// });
|
||||||
|
|
||||||
const selectionWidth = 210;
|
// const selectionWidth = 210;
|
||||||
const selectionHeight = 100;
|
// const selectionHeight = 100;
|
||||||
const move = [40, 40] as [number, number];
|
// const move = [40, 40] as [number, number];
|
||||||
const scale = Math.max(
|
// const scale = Math.max(
|
||||||
1 - move[0] / selectionWidth,
|
// 1 - move[0] / selectionWidth,
|
||||||
1 - move[1] / selectionHeight,
|
// 1 - move[1] / selectionHeight,
|
||||||
);
|
// );
|
||||||
const leftArrowBinding = { ...leftBoundArrow.endBinding };
|
// const leftArrowBinding: {
|
||||||
const rightArrowBinding = { ...rightBoundArrow.endBinding };
|
// elementId: string;
|
||||||
delete rightArrowBinding.gap;
|
// gap?: number;
|
||||||
|
// focus?: number;
|
||||||
|
// } = {
|
||||||
|
// ...leftBoundArrow.endBinding,
|
||||||
|
// } as PointBinding;
|
||||||
|
// const rightArrowBinding: {
|
||||||
|
// elementId: string;
|
||||||
|
// gap?: number;
|
||||||
|
// focus?: number;
|
||||||
|
// } = {
|
||||||
|
// ...rightBoundArrow.endBinding,
|
||||||
|
// } as PointBinding;
|
||||||
|
// delete rightArrowBinding.gap;
|
||||||
|
|
||||||
UI.resize([rectangle, rightBoundArrow], "nw", move, {
|
// UI.resize([rectangle, rightBoundArrow], "nw", move, {
|
||||||
shift: true,
|
// shift: true,
|
||||||
});
|
// });
|
||||||
|
|
||||||
expect(leftBoundArrow.x).toBeCloseTo(-110);
|
// expect(leftBoundArrow.x).toBeCloseTo(-110);
|
||||||
expect(leftBoundArrow.y).toBeCloseTo(50);
|
// expect(leftBoundArrow.y).toBeCloseTo(50);
|
||||||
expect(leftBoundArrow.width).toBeCloseTo(140, 0);
|
// expect(leftBoundArrow.width).toBeCloseTo(140, 0);
|
||||||
expect(leftBoundArrow.height).toBeCloseTo(7, 0);
|
// expect(leftBoundArrow.height).toBeCloseTo(7, 0);
|
||||||
expect(leftBoundArrow.angle).toEqual(0);
|
// expect(leftBoundArrow.angle).toEqual(0);
|
||||||
expect(leftBoundArrow.startBinding).toBeNull();
|
// expect(leftBoundArrow.startBinding).toBeNull();
|
||||||
expect(leftBoundArrow.endBinding?.gap).toBeCloseTo(10);
|
// expect(leftBoundArrow.endBinding?.gap).toBeCloseTo(10);
|
||||||
expect(leftBoundArrow.endBinding?.elementId).toBe(
|
// expect(leftBoundArrow.endBinding?.elementId).toBe(
|
||||||
leftArrowBinding.elementId,
|
// leftArrowBinding.elementId,
|
||||||
);
|
// );
|
||||||
expect(leftBoundArrow.endBinding?.focus).toBe(leftArrowBinding.focus);
|
// expect(leftBoundArrow.endBinding?.focus).toBe(leftArrowBinding.focus);
|
||||||
|
|
||||||
expect(rightBoundArrow.x).toBeCloseTo(210);
|
// expect(rightBoundArrow.x).toBeCloseTo(210);
|
||||||
expect(rightBoundArrow.y).toBeCloseTo(
|
// expect(rightBoundArrow.y).toBeCloseTo(
|
||||||
(selectionHeight - 50) * (1 - scale) + 50,
|
// (selectionHeight - 50) * (1 - scale) + 50,
|
||||||
);
|
// );
|
||||||
expect(rightBoundArrow.width).toBeCloseTo(100 * scale);
|
// expect(rightBoundArrow.width).toBeCloseTo(100 * scale);
|
||||||
expect(rightBoundArrow.height).toBeCloseTo(0);
|
// expect(rightBoundArrow.height).toBeCloseTo(0);
|
||||||
expect(rightBoundArrow.angle).toEqual(0);
|
// expect(rightBoundArrow.angle).toEqual(0);
|
||||||
expect(rightBoundArrow.startBinding).toBeNull();
|
// expect(rightBoundArrow.startBinding).toBeNull();
|
||||||
expect(rightBoundArrow.endBinding?.gap).toBeCloseTo(8.0952);
|
// expect(rightBoundArrow.endBinding?.gap).toBeCloseTo(8.0952);
|
||||||
expect(rightBoundArrow.endBinding?.elementId).toBe(
|
// expect(rightBoundArrow.endBinding?.elementId).toBe(
|
||||||
rightArrowBinding.elementId,
|
// rightArrowBinding.elementId,
|
||||||
);
|
// );
|
||||||
expect(rightBoundArrow.endBinding?.focus).toBeCloseTo(
|
// expect(rightBoundArrow.endBinding?.focus).toBeCloseTo(
|
||||||
rightArrowBinding.focus!,
|
// rightArrowBinding.focus!,
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
it("resizes with labeled arrows", async () => {
|
it("resizes with labeled arrows", async () => {
|
||||||
const topArrow = UI.createElement("arrow", {
|
const topArrow = UI.createElement("arrow", {
|
||||||
@@ -1338,8 +1350,8 @@ describe("multiple selection", () => {
|
|||||||
|
|
||||||
expect(boundArrow.x).toBeCloseTo(380 * scaleX);
|
expect(boundArrow.x).toBeCloseTo(380 * scaleX);
|
||||||
expect(boundArrow.y).toBeCloseTo(240 * scaleY);
|
expect(boundArrow.y).toBeCloseTo(240 * scaleY);
|
||||||
expect(boundArrow.points[1][0]).toBeCloseTo(-60 * scaleX);
|
expect(boundArrow.points[1][0]).toBeCloseTo(59.7979);
|
||||||
expect(boundArrow.points[1][1]).toBeCloseTo(-80 * scaleY);
|
expect(boundArrow.points[1][1]).toBeCloseTo(-79.7305);
|
||||||
|
|
||||||
expect(arrowLabelPos.x + arrowLabel.width / 2).toBeCloseTo(
|
expect(arrowLabelPos.x + arrowLabel.width / 2).toBeCloseTo(
|
||||||
boundArrow.x + boundArrow.points[1][0] / 2,
|
boundArrow.x + boundArrow.points[1][0] / 2,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ import { register } from "./register";
|
|||||||
|
|
||||||
import type { AppState, Offsets } from "../types";
|
import type { AppState, Offsets } from "../types";
|
||||||
|
|
||||||
export const actionChangeViewBackgroundColor = register({
|
export const actionChangeViewBackgroundColor = register<Partial<AppState>>({
|
||||||
name: "changeViewBackgroundColor",
|
name: "changeViewBackgroundColor",
|
||||||
label: "labels.canvasBackground",
|
label: "labels.canvasBackground",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -64,7 +64,7 @@ export const actionChangeViewBackgroundColor = register({
|
|||||||
perform: (_, appState, value) => {
|
perform: (_, appState, value) => {
|
||||||
return {
|
return {
|
||||||
appState: { ...appState, ...value },
|
appState: { ...appState, ...value },
|
||||||
captureUpdate: !!value.viewBackgroundColor
|
captureUpdate: !!value?.viewBackgroundColor
|
||||||
? CaptureUpdateAction.IMMEDIATELY
|
? CaptureUpdateAction.IMMEDIATELY
|
||||||
: CaptureUpdateAction.EVENTUALLY,
|
: CaptureUpdateAction.EVENTUALLY,
|
||||||
};
|
};
|
||||||
@@ -466,7 +466,7 @@ export const actionZoomToFit = register({
|
|||||||
!event[KEYS.CTRL_OR_CMD],
|
!event[KEYS.CTRL_OR_CMD],
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionToggleTheme = register({
|
export const actionToggleTheme = register<AppState["theme"]>({
|
||||||
name: "toggleTheme",
|
name: "toggleTheme",
|
||||||
label: (_, appState) => {
|
label: (_, appState) => {
|
||||||
return appState.theme === THEME.DARK
|
return appState.theme === THEME.DARK
|
||||||
@@ -474,7 +474,8 @@ export const actionToggleTheme = register({
|
|||||||
: "buttons.darkMode";
|
: "buttons.darkMode";
|
||||||
},
|
},
|
||||||
keywords: ["toggle", "dark", "light", "mode", "theme"],
|
keywords: ["toggle", "dark", "light", "mode", "theme"],
|
||||||
icon: (appState) => (appState.theme === THEME.LIGHT ? MoonIcon : SunIcon),
|
icon: (appState, elements) =>
|
||||||
|
appState.theme === THEME.LIGHT ? MoonIcon : SunIcon,
|
||||||
viewMode: true,
|
viewMode: true,
|
||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
perform: (_, appState, value) => {
|
perform: (_, appState, value) => {
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ import { t } from "../i18n";
|
|||||||
import { actionDeleteSelected } from "./actionDeleteSelected";
|
import { actionDeleteSelected } from "./actionDeleteSelected";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
|
|
||||||
export const actionCopy = register({
|
export const actionCopy = register<ClipboardEvent | null>({
|
||||||
name: "copy",
|
name: "copy",
|
||||||
label: "labels.copy",
|
label: "labels.copy",
|
||||||
icon: DuplicateIcon,
|
icon: DuplicateIcon,
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: async (elements, appState, event: ClipboardEvent | null, app) => {
|
perform: async (elements, appState, event, app) => {
|
||||||
const elementsToCopy = app.scene.getSelectedElements({
|
const elementsToCopy = app.scene.getSelectedElements({
|
||||||
selectedElementIds: appState.selectedElementIds,
|
selectedElementIds: appState.selectedElementIds,
|
||||||
includeBoundTextElement: true,
|
includeBoundTextElement: true,
|
||||||
@@ -109,12 +109,12 @@ export const actionPaste = register({
|
|||||||
keyTest: undefined,
|
keyTest: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionCut = register({
|
export const actionCut = register<ClipboardEvent | null>({
|
||||||
name: "cut",
|
name: "cut",
|
||||||
label: "labels.cut",
|
label: "labels.cut",
|
||||||
icon: cutIcon,
|
icon: cutIcon,
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements, appState, event: ClipboardEvent | null, app) => {
|
perform: (elements, appState, event, app) => {
|
||||||
actionCopy.perform(elements, appState, event, app);
|
actionCopy.perform(elements, appState, event, app);
|
||||||
return actionDeleteSelected.perform(elements, appState, null, app);
|
return actionDeleteSelected.perform(elements, appState, null, app);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -212,12 +212,8 @@ export const actionDeleteSelected = register({
|
|||||||
trackEvent: { category: "element", action: "delete" },
|
trackEvent: { category: "element", action: "delete" },
|
||||||
perform: (elements, appState, formData, app) => {
|
perform: (elements, appState, formData, app) => {
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
if (appState.selectedLinearElement?.isEditing) {
|
||||||
const {
|
const { elementId, selectedPointsIndices } =
|
||||||
elementId,
|
appState.selectedLinearElement;
|
||||||
selectedPointsIndices,
|
|
||||||
startBindingElement,
|
|
||||||
endBindingElement,
|
|
||||||
} = appState.selectedLinearElement;
|
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
const elementsMap = app.scene.getNonDeletedElementsMap();
|
||||||
const linearElement = LinearElementEditor.getElement(
|
const linearElement = LinearElementEditor.getElement(
|
||||||
elementId,
|
elementId,
|
||||||
@@ -254,19 +250,6 @@ export const actionDeleteSelected = register({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// We cannot do this inside `movePoint` because it is also called
|
|
||||||
// when deleting the uncommitted point (which hasn't caused any binding)
|
|
||||||
const binding = {
|
|
||||||
startBindingElement: selectedPointsIndices?.includes(0)
|
|
||||||
? null
|
|
||||||
: startBindingElement,
|
|
||||||
endBindingElement: selectedPointsIndices?.includes(
|
|
||||||
linearElement.points.length - 1,
|
|
||||||
)
|
|
||||||
? null
|
|
||||||
: endBindingElement,
|
|
||||||
};
|
|
||||||
|
|
||||||
LinearElementEditor.deletePoints(
|
LinearElementEditor.deletePoints(
|
||||||
linearElement,
|
linearElement,
|
||||||
app,
|
app,
|
||||||
@@ -279,7 +262,6 @@ export const actionDeleteSelected = register({
|
|||||||
...appState,
|
...appState,
|
||||||
selectedLinearElement: {
|
selectedLinearElement: {
|
||||||
...appState.selectedLinearElement,
|
...appState.selectedLinearElement,
|
||||||
...binding,
|
|
||||||
selectedPointsIndices:
|
selectedPointsIndices:
|
||||||
selectedPointsIndices?.[0] > 0
|
selectedPointsIndices?.[0] > 0
|
||||||
? [selectedPointsIndices[0] - 1]
|
? [selectedPointsIndices[0] - 1]
|
||||||
@@ -308,6 +290,7 @@ export const actionDeleteSelected = register({
|
|||||||
type: app.state.preferredSelectionTool.type,
|
type: app.state.preferredSelectionTool.type,
|
||||||
}),
|
}),
|
||||||
multiElement: null,
|
multiElement: null,
|
||||||
|
newElement: null,
|
||||||
activeEmbeddable: null,
|
activeEmbeddable: null,
|
||||||
selectedLinearElement: null,
|
selectedLinearElement: null,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ import "../components/ToolIcon.scss";
|
|||||||
|
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
|
|
||||||
export const actionChangeProjectName = register({
|
import type { AppState } from "../types";
|
||||||
|
|
||||||
|
export const actionChangeProjectName = register<AppState["name"]>({
|
||||||
name: "changeProjectName",
|
name: "changeProjectName",
|
||||||
label: "labels.fileTitle",
|
label: "labels.fileTitle",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -51,7 +53,7 @@ export const actionChangeProjectName = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeExportScale = register({
|
export const actionChangeExportScale = register<AppState["exportScale"]>({
|
||||||
name: "changeExportScale",
|
name: "changeExportScale",
|
||||||
label: "imageExportDialog.scale",
|
label: "imageExportDialog.scale",
|
||||||
trackEvent: { category: "export", action: "scale" },
|
trackEvent: { category: "export", action: "scale" },
|
||||||
@@ -101,7 +103,9 @@ export const actionChangeExportScale = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeExportBackground = register({
|
export const actionChangeExportBackground = register<
|
||||||
|
AppState["exportBackground"]
|
||||||
|
>({
|
||||||
name: "changeExportBackground",
|
name: "changeExportBackground",
|
||||||
label: "imageExportDialog.label.withBackground",
|
label: "imageExportDialog.label.withBackground",
|
||||||
trackEvent: { category: "export", action: "toggleBackground" },
|
trackEvent: { category: "export", action: "toggleBackground" },
|
||||||
@@ -121,7 +125,9 @@ export const actionChangeExportBackground = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeExportEmbedScene = register({
|
export const actionChangeExportEmbedScene = register<
|
||||||
|
AppState["exportEmbedScene"]
|
||||||
|
>({
|
||||||
name: "changeExportEmbedScene",
|
name: "changeExportEmbedScene",
|
||||||
label: "imageExportDialog.tooltip.embedScene",
|
label: "imageExportDialog.tooltip.embedScene",
|
||||||
trackEvent: { category: "export", action: "embedScene" },
|
trackEvent: { category: "export", action: "embedScene" },
|
||||||
@@ -288,7 +294,9 @@ export const actionLoadScene = register({
|
|||||||
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.O,
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.O,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionExportWithDarkMode = register({
|
export const actionExportWithDarkMode = register<
|
||||||
|
AppState["exportWithDarkMode"]
|
||||||
|
>({
|
||||||
name: "exportWithDarkMode",
|
name: "exportWithDarkMode",
|
||||||
label: "imageExportDialog.label.darkMode",
|
label: "imageExportDialog.label.darkMode",
|
||||||
trackEvent: { category: "export", action: "toggleTheme" },
|
trackEvent: { category: "export", action: "toggleTheme" },
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import { pointFrom } from "@excalidraw/math";
|
import { pointFrom } from "@excalidraw/math";
|
||||||
|
|
||||||
import {
|
import { bindOrUnbindBindingElement } from "@excalidraw/element/binding";
|
||||||
maybeBindLinearElement,
|
|
||||||
bindOrUnbindLinearElement,
|
|
||||||
isBindingEnabled,
|
|
||||||
} from "@excalidraw/element/binding";
|
|
||||||
import {
|
import {
|
||||||
isValidPolygon,
|
isValidPolygon,
|
||||||
LinearElementEditor,
|
LinearElementEditor,
|
||||||
@@ -21,7 +17,8 @@ import {
|
|||||||
import {
|
import {
|
||||||
KEYS,
|
KEYS,
|
||||||
arrayToMap,
|
arrayToMap,
|
||||||
tupleToCoors,
|
invariant,
|
||||||
|
shouldRotateWithDiscreteAngle,
|
||||||
updateActiveTool,
|
updateActiveTool,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
import { isPathALoop } from "@excalidraw/element";
|
import { isPathALoop } from "@excalidraw/element";
|
||||||
@@ -30,11 +27,12 @@ import { isInvisiblySmallElement } from "@excalidraw/element";
|
|||||||
|
|
||||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { LocalPoint } from "@excalidraw/math";
|
import type { GlobalPoint, LocalPoint } from "@excalidraw/math";
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
NonDeleted,
|
NonDeleted,
|
||||||
|
PointsPositionUpdates,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
@@ -46,20 +44,37 @@ import { register } from "./register";
|
|||||||
|
|
||||||
import type { AppState } from "../types";
|
import type { AppState } from "../types";
|
||||||
|
|
||||||
export const actionFinalize = register({
|
type FormData = {
|
||||||
|
event: PointerEvent;
|
||||||
|
sceneCoords: { x: number; y: number };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const actionFinalize = register<FormData>({
|
||||||
name: "finalize",
|
name: "finalize",
|
||||||
label: "",
|
label: "",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, data, app) => {
|
perform: (elements, appState, data, app) => {
|
||||||
|
let newElements = elements;
|
||||||
const { interactiveCanvas, focusContainer, scene } = app;
|
const { interactiveCanvas, focusContainer, scene } = app;
|
||||||
const { event, sceneCoords } =
|
|
||||||
(data as {
|
|
||||||
event?: PointerEvent;
|
|
||||||
sceneCoords?: { x: number; y: number };
|
|
||||||
}) ?? {};
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
|
||||||
if (event && appState.selectedLinearElement) {
|
if (data && appState.selectedLinearElement) {
|
||||||
|
const { event, sceneCoords } = data;
|
||||||
|
const element = LinearElementEditor.getElement(
|
||||||
|
appState.selectedLinearElement.elementId,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
element,
|
||||||
|
"Arrow element should exist if selectedLinearElement is set",
|
||||||
|
);
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
sceneCoords,
|
||||||
|
"sceneCoords should be defined if actionFinalize is called with event",
|
||||||
|
);
|
||||||
|
|
||||||
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
||||||
event,
|
event,
|
||||||
appState.selectedLinearElement,
|
appState.selectedLinearElement,
|
||||||
@@ -67,19 +82,57 @@ export const actionFinalize = register({
|
|||||||
app.scene,
|
app.scene,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { startBindingElement, endBindingElement } = linearElementEditor;
|
|
||||||
const element = app.scene.getElement(linearElementEditor.elementId);
|
|
||||||
if (isBindingElement(element)) {
|
if (isBindingElement(element)) {
|
||||||
bindOrUnbindLinearElement(
|
const newArrow = !!appState.newElement;
|
||||||
|
|
||||||
|
const selectedPointsIndices =
|
||||||
|
newArrow || !appState.selectedLinearElement.selectedPointsIndices
|
||||||
|
? [element.points.length - 1] // New arrow creation
|
||||||
|
: appState.selectedLinearElement.selectedPointsIndices;
|
||||||
|
|
||||||
|
const draggedPoints: PointsPositionUpdates =
|
||||||
|
selectedPointsIndices.reduce((map, index) => {
|
||||||
|
map.set(index, {
|
||||||
|
point: LinearElementEditor.pointFromAbsoluteCoords(
|
||||||
|
element,
|
||||||
|
pointFrom<GlobalPoint>(sceneCoords.x, sceneCoords.y),
|
||||||
|
elementsMap,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}, new Map()) ?? new Map();
|
||||||
|
|
||||||
|
bindOrUnbindBindingElement(
|
||||||
element,
|
element,
|
||||||
startBindingElement,
|
draggedPoints,
|
||||||
endBindingElement,
|
sceneCoords.x,
|
||||||
app.scene,
|
sceneCoords.y,
|
||||||
|
scene,
|
||||||
|
appState,
|
||||||
|
{
|
||||||
|
newArrow,
|
||||||
|
altKey: event.altKey,
|
||||||
|
angleLocked: shouldRotateWithDiscreteAngle(event),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
} else if (isLineElement(element)) {
|
||||||
|
if (
|
||||||
|
appState.selectedLinearElement?.isEditing &&
|
||||||
|
!appState.newElement &&
|
||||||
|
!isValidPolygon(element.points)
|
||||||
|
) {
|
||||||
|
scene.mutateElement(element, {
|
||||||
|
polygon: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linearElementEditor !== appState.selectedLinearElement) {
|
if (linearElementEditor !== appState.selectedLinearElement) {
|
||||||
let newElements = elements;
|
// `handlePointerUp()` updated the linear element instance,
|
||||||
|
// so filter out this element if it is too small,
|
||||||
|
// but do an update to all new elements anyway for undo/redo purposes.
|
||||||
|
|
||||||
if (element && isInvisiblySmallElement(element)) {
|
if (element && isInvisiblySmallElement(element)) {
|
||||||
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
||||||
newElements = newElements.map((el) => {
|
newElements = newElements.map((el) => {
|
||||||
@@ -91,39 +144,8 @@ export const actionFinalize = register({
|
|||||||
return el;
|
return el;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
elements: newElements,
|
|
||||||
appState: {
|
|
||||||
selectedLinearElement: {
|
|
||||||
...linearElementEditor,
|
|
||||||
selectedPointsIndices: null,
|
|
||||||
},
|
|
||||||
suggestedBindings: [],
|
|
||||||
},
|
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
const activeToolLocked = appState.activeTool?.locked;
|
||||||
const { elementId, startBindingElement, endBindingElement } =
|
|
||||||
appState.selectedLinearElement;
|
|
||||||
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
|
||||||
|
|
||||||
if (element) {
|
|
||||||
if (isBindingElement(element)) {
|
|
||||||
bindOrUnbindLinearElement(
|
|
||||||
element,
|
|
||||||
startBindingElement,
|
|
||||||
endBindingElement,
|
|
||||||
scene,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (isLineElement(element) && !isValidPolygon(element.points)) {
|
|
||||||
scene.mutateElement(element, {
|
|
||||||
polygon: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements:
|
elements:
|
||||||
@@ -134,23 +156,31 @@ export const actionFinalize = register({
|
|||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
})
|
})
|
||||||
: undefined,
|
: newElements,
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
cursorButton: "up",
|
cursorButton: "up",
|
||||||
selectedLinearElement: new LinearElementEditor(
|
selectedLinearElement: activeToolLocked
|
||||||
element,
|
? null
|
||||||
arrayToMap(elementsMap),
|
: {
|
||||||
false, // exit editing mode
|
...linearElementEditor,
|
||||||
),
|
selectedPointsIndices: null,
|
||||||
|
isEditing: false,
|
||||||
|
initialState: {
|
||||||
|
...linearElementEditor.initialState,
|
||||||
|
lastClickedPoint: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
selectionElement: null,
|
||||||
|
suggestedBinding: null,
|
||||||
|
newElement: null,
|
||||||
|
multiElement: null,
|
||||||
},
|
},
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let newElements = elements;
|
|
||||||
|
|
||||||
if (window.document.activeElement instanceof HTMLElement) {
|
if (window.document.activeElement instanceof HTMLElement) {
|
||||||
focusContainer();
|
focusContainer();
|
||||||
}
|
}
|
||||||
@@ -174,8 +204,14 @@ export const actionFinalize = register({
|
|||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
// pen and mouse have hover
|
// pen and mouse have hover
|
||||||
if (appState.multiElement && element.type !== "freedraw") {
|
if (
|
||||||
const { points, lastCommittedPoint } = element;
|
appState.selectedLinearElement &&
|
||||||
|
appState.multiElement &&
|
||||||
|
element.type !== "freedraw" &&
|
||||||
|
appState.lastPointerDownWith !== "touch"
|
||||||
|
) {
|
||||||
|
const { points } = element;
|
||||||
|
const { lastCommittedPoint } = appState.selectedLinearElement;
|
||||||
if (
|
if (
|
||||||
!lastCommittedPoint ||
|
!lastCommittedPoint ||
|
||||||
points[points.length - 1] !== lastCommittedPoint
|
points[points.length - 1] !== lastCommittedPoint
|
||||||
@@ -227,25 +263,6 @@ export const actionFinalize = register({
|
|||||||
polygon: false,
|
polygon: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
isBindingElement(element) &&
|
|
||||||
!isLoop &&
|
|
||||||
element.points.length > 1 &&
|
|
||||||
isBindingEnabled(appState)
|
|
||||||
) {
|
|
||||||
const coords =
|
|
||||||
sceneCoords ??
|
|
||||||
tupleToCoors(
|
|
||||||
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
|
||||||
element,
|
|
||||||
-1,
|
|
||||||
arrayToMap(elements),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
maybeBindLinearElement(element, appState, coords, scene);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,6 +288,25 @@ export const actionFinalize = register({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let selectedLinearElement =
|
||||||
|
element && isLinearElement(element)
|
||||||
|
? new LinearElementEditor(element, arrayToMap(newElements)) // To select the linear element when user has finished mutipoint editing
|
||||||
|
: appState.selectedLinearElement;
|
||||||
|
|
||||||
|
selectedLinearElement = selectedLinearElement
|
||||||
|
? {
|
||||||
|
...selectedLinearElement,
|
||||||
|
isEditing: appState.newElement
|
||||||
|
? false
|
||||||
|
: selectedLinearElement.isEditing,
|
||||||
|
initialState: {
|
||||||
|
...selectedLinearElement.initialState,
|
||||||
|
lastClickedPoint: -1,
|
||||||
|
origin: null,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: selectedLinearElement;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements: newElements,
|
elements: newElements,
|
||||||
appState: {
|
appState: {
|
||||||
@@ -288,7 +324,7 @@ export const actionFinalize = register({
|
|||||||
multiElement: null,
|
multiElement: null,
|
||||||
editingTextElement: null,
|
editingTextElement: null,
|
||||||
startBoundElement: null,
|
startBoundElement: null,
|
||||||
suggestedBindings: [],
|
suggestedBinding: null,
|
||||||
selectedElementIds:
|
selectedElementIds:
|
||||||
element &&
|
element &&
|
||||||
!appState.activeTool.locked &&
|
!appState.activeTool.locked &&
|
||||||
@@ -298,11 +334,8 @@ export const actionFinalize = register({
|
|||||||
[element.id]: true,
|
[element.id]: true,
|
||||||
}
|
}
|
||||||
: appState.selectedElementIds,
|
: appState.selectedElementIds,
|
||||||
// To select the linear element when user has finished mutipoint editing
|
|
||||||
selectedLinearElement:
|
selectedLinearElement,
|
||||||
element && isLinearElement(element)
|
|
||||||
? new LinearElementEditor(element, arrayToMap(newElements))
|
|
||||||
: appState.selectedLinearElement,
|
|
||||||
},
|
},
|
||||||
// TODO: #7348 we should not capture everything, but if we don't, it leads to incosistencies -> revisit
|
// TODO: #7348 we should not capture everything, but if we don't, it leads to incosistencies -> revisit
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
|
|||||||
@@ -38,15 +38,13 @@ describe("flipping re-centers selection", () => {
|
|||||||
height: 239.9,
|
height: 239.9,
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: "rec1",
|
elementId: "rec1",
|
||||||
focus: 0,
|
|
||||||
gap: 5,
|
|
||||||
fixedPoint: [0.49, -0.05],
|
fixedPoint: [0.49, -0.05],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: "rec2",
|
elementId: "rec2",
|
||||||
focus: 0,
|
|
||||||
gap: 5,
|
|
||||||
fixedPoint: [-0.05, 0.49],
|
fixedPoint: [-0.05, 0.49],
|
||||||
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
startArrowhead: null,
|
startArrowhead: null,
|
||||||
endArrowhead: "arrow",
|
endArrowhead: "arrow",
|
||||||
@@ -74,11 +72,11 @@ describe("flipping re-centers selection", () => {
|
|||||||
|
|
||||||
const rec1 = h.elements.find((el) => el.id === "rec1")!;
|
const rec1 = h.elements.find((el) => el.id === "rec1")!;
|
||||||
expect(rec1.x).toBeCloseTo(100, 0);
|
expect(rec1.x).toBeCloseTo(100, 0);
|
||||||
expect(rec1.y).toBeCloseTo(100, 0);
|
expect(rec1.y).toBeCloseTo(101, 0);
|
||||||
|
|
||||||
const rec2 = h.elements.find((el) => el.id === "rec2")!;
|
const rec2 = h.elements.find((el) => el.id === "rec2")!;
|
||||||
expect(rec2.x).toBeCloseTo(220, 0);
|
expect(rec2.x).toBeCloseTo(220, 0);
|
||||||
expect(rec2.y).toBeCloseTo(250, 0);
|
expect(rec2.y).toBeCloseTo(251, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -99,8 +97,8 @@ describe("flipping arrowheads", () => {
|
|||||||
endArrowhead: null,
|
endArrowhead: null,
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: rect.id,
|
elementId: rect.id,
|
||||||
focus: 0.5,
|
fixedPoint: [0.5, 0.5],
|
||||||
gap: 5,
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -139,13 +137,13 @@ describe("flipping arrowheads", () => {
|
|||||||
endArrowhead: "circle",
|
endArrowhead: "circle",
|
||||||
startBinding: {
|
startBinding: {
|
||||||
elementId: rect.id,
|
elementId: rect.id,
|
||||||
focus: 0.5,
|
fixedPoint: [0.5, 0.5],
|
||||||
gap: 5,
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: rect2.id,
|
elementId: rect2.id,
|
||||||
focus: 0.5,
|
fixedPoint: [0.5, 0.5],
|
||||||
gap: 5,
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -195,8 +193,8 @@ describe("flipping arrowheads", () => {
|
|||||||
endArrowhead: null,
|
endArrowhead: null,
|
||||||
endBinding: {
|
endBinding: {
|
||||||
elementId: rect.id,
|
elementId: rect.id,
|
||||||
focus: 0.5,
|
fixedPoint: [0.5, 0.5],
|
||||||
gap: 5,
|
mode: "orbit",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
import { getNonDeletedElements } from "@excalidraw/element";
|
import { getNonDeletedElements } from "@excalidraw/element";
|
||||||
import {
|
import { bindOrUnbindBindingElements } from "@excalidraw/element";
|
||||||
bindOrUnbindLinearElements,
|
|
||||||
isBindingEnabled,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
import { getCommonBoundingBox } from "@excalidraw/element";
|
import { getCommonBoundingBox } from "@excalidraw/element";
|
||||||
import { newElementWith } from "@excalidraw/element";
|
import { newElementWith } from "@excalidraw/element";
|
||||||
import { deepCopyElement } from "@excalidraw/element";
|
import { deepCopyElement } from "@excalidraw/element";
|
||||||
import { resizeMultipleElements } from "@excalidraw/element";
|
import { resizeMultipleElements } from "@excalidraw/element";
|
||||||
import {
|
import { isArrowElement, isElbowArrow } from "@excalidraw/element";
|
||||||
isArrowElement,
|
|
||||||
isElbowArrow,
|
|
||||||
isLinearElement,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element";
|
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element";
|
||||||
import { CODES, KEYS, arrayToMap } from "@excalidraw/common";
|
import { CODES, KEYS, arrayToMap } from "@excalidraw/common";
|
||||||
|
|
||||||
@@ -103,7 +96,6 @@ const flipSelectedElements = (
|
|||||||
const updatedElements = flipElements(
|
const updatedElements = flipElements(
|
||||||
selectedElements,
|
selectedElements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState,
|
|
||||||
flipDirection,
|
flipDirection,
|
||||||
app,
|
app,
|
||||||
);
|
);
|
||||||
@@ -118,7 +110,6 @@ const flipSelectedElements = (
|
|||||||
const flipElements = (
|
const flipElements = (
|
||||||
selectedElements: NonDeleted<ExcalidrawElement>[],
|
selectedElements: NonDeleted<ExcalidrawElement>[],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
appState: AppState,
|
|
||||||
flipDirection: "horizontal" | "vertical",
|
flipDirection: "horizontal" | "vertical",
|
||||||
app: AppClassProperties,
|
app: AppClassProperties,
|
||||||
): ExcalidrawElement[] => {
|
): ExcalidrawElement[] => {
|
||||||
@@ -158,12 +149,10 @@ const flipElements = (
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
bindOrUnbindLinearElements(
|
bindOrUnbindBindingElements(
|
||||||
selectedElements.filter(isLinearElement),
|
selectedElements.filter(isArrowElement),
|
||||||
isBindingEnabled(appState),
|
|
||||||
[],
|
|
||||||
app.scene,
|
app.scene,
|
||||||
appState.zoom,
|
app.state,
|
||||||
);
|
);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import clsx from "clsx";
|
|||||||
|
|
||||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
|
|
||||||
|
import { invariant } from "@excalidraw/common";
|
||||||
|
|
||||||
import { getClientColor } from "../clients";
|
import { getClientColor } from "../clients";
|
||||||
import { Avatar } from "../components/Avatar";
|
import { Avatar } from "../components/Avatar";
|
||||||
import {
|
import {
|
||||||
@@ -16,12 +18,17 @@ import { register } from "./register";
|
|||||||
import type { GoToCollaboratorComponentProps } from "../components/UserList";
|
import type { GoToCollaboratorComponentProps } from "../components/UserList";
|
||||||
import type { Collaborator } from "../types";
|
import type { Collaborator } from "../types";
|
||||||
|
|
||||||
export const actionGoToCollaborator = register({
|
export const actionGoToCollaborator = register<Collaborator>({
|
||||||
name: "goToCollaborator",
|
name: "goToCollaborator",
|
||||||
label: "Go to a collaborator",
|
label: "Go to a collaborator",
|
||||||
viewMode: true,
|
viewMode: true,
|
||||||
trackEvent: { category: "collab" },
|
trackEvent: { category: "collab" },
|
||||||
perform: (_elements, appState, collaborator: Collaborator) => {
|
perform: (_elements, appState, collaborator) => {
|
||||||
|
invariant(
|
||||||
|
collaborator,
|
||||||
|
"actionGoToCollaborator: collaborator should be defined when actionGoToCollaborator is called",
|
||||||
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!collaborator.socketId ||
|
!collaborator.socketId ||
|
||||||
appState.userToFollow?.socketId === collaborator.socketId ||
|
appState.userToFollow?.socketId === collaborator.socketId ||
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { pointFrom } from "@excalidraw/math";
|
import { pointFrom } from "@excalidraw/math";
|
||||||
|
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -20,12 +21,14 @@ import {
|
|||||||
getLineHeight,
|
getLineHeight,
|
||||||
isTransparent,
|
isTransparent,
|
||||||
reduceToCommonValue,
|
reduceToCommonValue,
|
||||||
|
invariant,
|
||||||
|
FONT_SIZES,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import { canBecomePolygon, getNonDeletedElements } from "@excalidraw/element";
|
import { canBecomePolygon, getNonDeletedElements } from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bindLinearElement,
|
bindBindingElement,
|
||||||
calculateFixedPointForElbowArrowBinding,
|
calculateFixedPointForElbowArrowBinding,
|
||||||
updateBoundElements,
|
updateBoundElements,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
@@ -59,7 +62,7 @@ import {
|
|||||||
|
|
||||||
import { deriveStylesPanelMode } from "@excalidraw/common";
|
import { deriveStylesPanelMode } from "@excalidraw/common";
|
||||||
|
|
||||||
import type { LocalPoint } from "@excalidraw/math";
|
import type { LocalPoint, Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Arrowhead,
|
Arrowhead,
|
||||||
@@ -306,13 +309,15 @@ const changeFontSize = (
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
export const actionChangeStrokeColor = register({
|
export const actionChangeStrokeColor = register<
|
||||||
|
Pick<AppState, "currentItemStrokeColor">
|
||||||
|
>({
|
||||||
name: "changeStrokeColor",
|
name: "changeStrokeColor",
|
||||||
label: "labels.stroke",
|
label: "labels.stroke",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value) => {
|
perform: (elements, appState, value) => {
|
||||||
return {
|
return {
|
||||||
...(value.currentItemStrokeColor && {
|
...(value?.currentItemStrokeColor && {
|
||||||
elements: changeProperty(
|
elements: changeProperty(
|
||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
@@ -330,7 +335,7 @@ export const actionChangeStrokeColor = register({
|
|||||||
...appState,
|
...appState,
|
||||||
...value,
|
...value,
|
||||||
},
|
},
|
||||||
captureUpdate: !!value.currentItemStrokeColor
|
captureUpdate: !!value?.currentItemStrokeColor
|
||||||
? CaptureUpdateAction.IMMEDIATELY
|
? CaptureUpdateAction.IMMEDIATELY
|
||||||
: CaptureUpdateAction.EVENTUALLY,
|
: CaptureUpdateAction.EVENTUALLY,
|
||||||
};
|
};
|
||||||
@@ -366,12 +371,14 @@ export const actionChangeStrokeColor = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeBackgroundColor = register({
|
export const actionChangeBackgroundColor = register<
|
||||||
|
Pick<AppState, "currentItemBackgroundColor" | "viewBackgroundColor">
|
||||||
|
>({
|
||||||
name: "changeBackgroundColor",
|
name: "changeBackgroundColor",
|
||||||
label: "labels.changeBackground",
|
label: "labels.changeBackground",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value, app) => {
|
perform: (elements, appState, value, app) => {
|
||||||
if (!value.currentItemBackgroundColor) {
|
if (!value?.currentItemBackgroundColor) {
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
@@ -451,7 +458,7 @@ export const actionChangeBackgroundColor = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeFillStyle = register({
|
export const actionChangeFillStyle = register<ExcalidrawElement["fillStyle"]>({
|
||||||
name: "changeFillStyle",
|
name: "changeFillStyle",
|
||||||
label: "labels.fill",
|
label: "labels.fill",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -533,7 +540,9 @@ export const actionChangeFillStyle = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeStrokeWidth = register({
|
export const actionChangeStrokeWidth = register<
|
||||||
|
ExcalidrawElement["strokeWidth"]
|
||||||
|
>({
|
||||||
name: "changeStrokeWidth",
|
name: "changeStrokeWidth",
|
||||||
label: "labels.strokeWidth",
|
label: "labels.strokeWidth",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -589,7 +598,7 @@ export const actionChangeStrokeWidth = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeSloppiness = register({
|
export const actionChangeSloppiness = register<ExcalidrawElement["roughness"]>({
|
||||||
name: "changeSloppiness",
|
name: "changeSloppiness",
|
||||||
label: "labels.sloppiness",
|
label: "labels.sloppiness",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -643,7 +652,9 @@ export const actionChangeSloppiness = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeStrokeStyle = register({
|
export const actionChangeStrokeStyle = register<
|
||||||
|
ExcalidrawElement["strokeStyle"]
|
||||||
|
>({
|
||||||
name: "changeStrokeStyle",
|
name: "changeStrokeStyle",
|
||||||
label: "labels.strokeStyle",
|
label: "labels.strokeStyle",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -696,7 +707,7 @@ export const actionChangeStrokeStyle = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeOpacity = register({
|
export const actionChangeOpacity = register<ExcalidrawElement["opacity"]>({
|
||||||
name: "changeOpacity",
|
name: "changeOpacity",
|
||||||
label: "labels.opacity",
|
label: "labels.opacity",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -720,89 +731,100 @@ export const actionChangeOpacity = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeFontSize = register({
|
export const actionChangeFontSize = register<ExcalidrawTextElement["fontSize"]>(
|
||||||
name: "changeFontSize",
|
{
|
||||||
label: "labels.fontSize",
|
name: "changeFontSize",
|
||||||
trackEvent: false,
|
label: "labels.fontSize",
|
||||||
perform: (elements, appState, value, app) => {
|
trackEvent: false,
|
||||||
return changeFontSize(elements, appState, app, () => value, value);
|
perform: (elements, appState, value, app) => {
|
||||||
},
|
return changeFontSize(
|
||||||
PanelComponent: ({ elements, appState, updateData, app, data }) => {
|
elements,
|
||||||
const { isCompact } = getStylesPanelInfo(app);
|
appState,
|
||||||
|
app,
|
||||||
|
() => {
|
||||||
|
invariant(value, "actionChangeFontSize: Expected a font size value");
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
PanelComponent: ({ elements, appState, updateData, app, data }) => {
|
||||||
|
const { isCompact } = getStylesPanelInfo(app);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.fontSize")}</legend>
|
<legend>{t("labels.fontSize")}</legend>
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
<RadioSelection
|
<RadioSelection
|
||||||
group="font-size"
|
group="font-size"
|
||||||
options={[
|
options={[
|
||||||
{
|
{
|
||||||
value: 16,
|
value: FONT_SIZES.sm,
|
||||||
text: t("labels.small"),
|
text: t("labels.small"),
|
||||||
icon: FontSizeSmallIcon,
|
icon: FontSizeSmallIcon,
|
||||||
testId: "fontSize-small",
|
testId: "fontSize-small",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 20,
|
value: FONT_SIZES.md,
|
||||||
text: t("labels.medium"),
|
text: t("labels.medium"),
|
||||||
icon: FontSizeMediumIcon,
|
icon: FontSizeMediumIcon,
|
||||||
testId: "fontSize-medium",
|
testId: "fontSize-medium",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 28,
|
value: FONT_SIZES.lg,
|
||||||
text: t("labels.large"),
|
text: t("labels.large"),
|
||||||
icon: FontSizeLargeIcon,
|
icon: FontSizeLargeIcon,
|
||||||
testId: "fontSize-large",
|
testId: "fontSize-large",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 36,
|
value: FONT_SIZES.xl,
|
||||||
text: t("labels.veryLarge"),
|
text: t("labels.veryLarge"),
|
||||||
icon: FontSizeExtraLargeIcon,
|
icon: FontSizeExtraLargeIcon,
|
||||||
testId: "fontSize-veryLarge",
|
testId: "fontSize-veryLarge",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
elements,
|
elements,
|
||||||
app,
|
app,
|
||||||
(element) => {
|
(element) => {
|
||||||
if (isTextElement(element)) {
|
if (isTextElement(element)) {
|
||||||
return element.fontSize;
|
return element.fontSize;
|
||||||
}
|
}
|
||||||
const boundTextElement = getBoundTextElement(
|
const boundTextElement = getBoundTextElement(
|
||||||
element,
|
element,
|
||||||
app.scene.getNonDeletedElementsMap(),
|
app.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
if (boundTextElement) {
|
||||||
|
return boundTextElement.fontSize;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
(element) =>
|
||||||
|
isTextElement(element) ||
|
||||||
|
getBoundTextElement(
|
||||||
|
element,
|
||||||
|
app.scene.getNonDeletedElementsMap(),
|
||||||
|
) !== null,
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection
|
||||||
|
? null
|
||||||
|
: appState.currentItemFontSize || DEFAULT_FONT_SIZE,
|
||||||
|
)}
|
||||||
|
onChange={(value) => {
|
||||||
|
withCaretPositionPreservation(
|
||||||
|
() => updateData(value),
|
||||||
|
isCompact,
|
||||||
|
!!appState.editingTextElement,
|
||||||
|
data?.onPreventClose,
|
||||||
);
|
);
|
||||||
if (boundTextElement) {
|
}}
|
||||||
return boundTextElement.fontSize;
|
/>
|
||||||
}
|
</div>
|
||||||
return null;
|
</fieldset>
|
||||||
},
|
);
|
||||||
(element) =>
|
},
|
||||||
isTextElement(element) ||
|
|
||||||
getBoundTextElement(
|
|
||||||
element,
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
) !== null,
|
|
||||||
(hasSelection) =>
|
|
||||||
hasSelection
|
|
||||||
? null
|
|
||||||
: appState.currentItemFontSize || DEFAULT_FONT_SIZE,
|
|
||||||
)}
|
|
||||||
onChange={(value) => {
|
|
||||||
withCaretPositionPreservation(
|
|
||||||
() => updateData(value),
|
|
||||||
isCompact,
|
|
||||||
!!appState.editingTextElement,
|
|
||||||
data?.onPreventClose,
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
export const actionDecreaseFontSize = register({
|
export const actionDecreaseFontSize = register({
|
||||||
name: "decreaseFontSize",
|
name: "decreaseFontSize",
|
||||||
@@ -862,7 +884,10 @@ type ChangeFontFamilyData = Partial<
|
|||||||
resetContainers?: true;
|
resetContainers?: true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actionChangeFontFamily = register({
|
export const actionChangeFontFamily = register<{
|
||||||
|
currentItemFontFamily: any;
|
||||||
|
currentHoveredFontFamily: any;
|
||||||
|
}>({
|
||||||
name: "changeFontFamily",
|
name: "changeFontFamily",
|
||||||
label: "labels.fontFamily",
|
label: "labels.fontFamily",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -899,6 +924,8 @@ export const actionChangeFontFamily = register({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invariant(value, "actionChangeFontFamily: value must be defined");
|
||||||
|
|
||||||
const { currentItemFontFamily, currentHoveredFontFamily } = value;
|
const { currentItemFontFamily, currentHoveredFontFamily } = value;
|
||||||
|
|
||||||
let nextCaptureUpdateAction: CaptureUpdateActionType =
|
let nextCaptureUpdateAction: CaptureUpdateActionType =
|
||||||
@@ -1241,7 +1268,7 @@ export const actionChangeFontFamily = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeTextAlign = register({
|
export const actionChangeTextAlign = register<TextAlign>({
|
||||||
name: "changeTextAlign",
|
name: "changeTextAlign",
|
||||||
label: "Change text alignment",
|
label: "Change text alignment",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -1342,7 +1369,7 @@ export const actionChangeTextAlign = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeVerticalAlign = register({
|
export const actionChangeVerticalAlign = register<VerticalAlign>({
|
||||||
name: "changeVerticalAlign",
|
name: "changeVerticalAlign",
|
||||||
label: "Change vertical alignment",
|
label: "Change vertical alignment",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
@@ -1442,7 +1469,7 @@ export const actionChangeVerticalAlign = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeRoundness = register({
|
export const actionChangeRoundness = register<"sharp" | "round">({
|
||||||
name: "changeRoundness",
|
name: "changeRoundness",
|
||||||
label: "Change edge roundness",
|
label: "Change edge roundness",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -1599,15 +1626,16 @@ const getArrowheadOptions = (flip: boolean) => {
|
|||||||
] as const;
|
] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actionChangeArrowhead = register({
|
export const actionChangeArrowhead = register<{
|
||||||
|
position: "start" | "end";
|
||||||
|
type: Arrowhead;
|
||||||
|
}>({
|
||||||
name: "changeArrowhead",
|
name: "changeArrowhead",
|
||||||
label: "Change arrowheads",
|
label: "Change arrowheads",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (
|
perform: (elements, appState, value) => {
|
||||||
elements,
|
invariant(value, "actionChangeArrowhead: value must be defined");
|
||||||
appState,
|
|
||||||
value: { position: "start" | "end"; type: Arrowhead },
|
|
||||||
) => {
|
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) => {
|
elements: changeProperty(elements, appState, (el) => {
|
||||||
if (isLinearElement(el)) {
|
if (isLinearElement(el)) {
|
||||||
@@ -1702,7 +1730,7 @@ export const actionChangeArrowProperties = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeArrowType = register({
|
export const actionChangeArrowType = register<keyof typeof ARROW_TYPE>({
|
||||||
name: "changeArrowType",
|
name: "changeArrowType",
|
||||||
label: "Change arrow types",
|
label: "Change arrow types",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
@@ -1711,7 +1739,20 @@ export const actionChangeArrowType = register({
|
|||||||
if (!isArrowElement(el)) {
|
if (!isArrowElement(el)) {
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
const elementsMap = app.scene.getNonDeletedElementsMap();
|
||||||
|
const startPoint = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
el,
|
||||||
|
0,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
const endPoint = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
el,
|
||||||
|
-1,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
let newElement = newElementWith(el, {
|
let newElement = newElementWith(el, {
|
||||||
|
x: value === ARROW_TYPE.elbow ? startPoint[0] : el.x,
|
||||||
|
y: value === ARROW_TYPE.elbow ? startPoint[1] : el.y,
|
||||||
roundness:
|
roundness:
|
||||||
value === ARROW_TYPE.round
|
value === ARROW_TYPE.round
|
||||||
? {
|
? {
|
||||||
@@ -1719,9 +1760,31 @@ export const actionChangeArrowType = register({
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
elbowed: value === ARROW_TYPE.elbow,
|
elbowed: value === ARROW_TYPE.elbow,
|
||||||
|
angle: value === ARROW_TYPE.elbow ? (0 as Radians) : el.angle,
|
||||||
points:
|
points:
|
||||||
value === ARROW_TYPE.elbow || el.elbowed
|
value === ARROW_TYPE.elbow || el.elbowed
|
||||||
? [el.points[0], el.points[el.points.length - 1]]
|
? [
|
||||||
|
LinearElementEditor.pointFromAbsoluteCoords(
|
||||||
|
{
|
||||||
|
...el,
|
||||||
|
x: startPoint[0],
|
||||||
|
y: startPoint[1],
|
||||||
|
angle: 0 as Radians,
|
||||||
|
},
|
||||||
|
startPoint,
|
||||||
|
elementsMap,
|
||||||
|
),
|
||||||
|
LinearElementEditor.pointFromAbsoluteCoords(
|
||||||
|
{
|
||||||
|
...el,
|
||||||
|
x: startPoint[0],
|
||||||
|
y: startPoint[1],
|
||||||
|
angle: 0 as Radians,
|
||||||
|
},
|
||||||
|
endPoint,
|
||||||
|
elementsMap,
|
||||||
|
),
|
||||||
|
]
|
||||||
: el.points,
|
: el.points,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1803,7 +1866,13 @@ export const actionChangeArrowType = register({
|
|||||||
newElement.startBinding.elementId,
|
newElement.startBinding.elementId,
|
||||||
) as ExcalidrawBindableElement;
|
) as ExcalidrawBindableElement;
|
||||||
if (startElement) {
|
if (startElement) {
|
||||||
bindLinearElement(newElement, startElement, "start", app.scene);
|
bindBindingElement(
|
||||||
|
newElement,
|
||||||
|
startElement,
|
||||||
|
appState.bindMode === "inside" ? "inside" : "orbit",
|
||||||
|
"start",
|
||||||
|
app.scene,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newElement.endBinding) {
|
if (newElement.endBinding) {
|
||||||
@@ -1811,7 +1880,13 @@ export const actionChangeArrowType = register({
|
|||||||
newElement.endBinding.elementId,
|
newElement.endBinding.elementId,
|
||||||
) as ExcalidrawBindableElement;
|
) as ExcalidrawBindableElement;
|
||||||
if (endElement) {
|
if (endElement) {
|
||||||
bindLinearElement(newElement, endElement, "end", app.scene);
|
bindBindingElement(
|
||||||
|
newElement,
|
||||||
|
endElement,
|
||||||
|
appState.bindMode === "inside" ? "inside" : "orbit",
|
||||||
|
"end",
|
||||||
|
app.scene,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ import type { Action } from "./types";
|
|||||||
|
|
||||||
export let actions: readonly Action[] = [];
|
export let actions: readonly Action[] = [];
|
||||||
|
|
||||||
export const register = <T extends Action>(action: T) => {
|
export const register = <
|
||||||
|
TData extends any,
|
||||||
|
T extends Action<TData> = Action<TData>,
|
||||||
|
>(
|
||||||
|
action: T,
|
||||||
|
) => {
|
||||||
actions = actions.concat(action);
|
actions = actions.concat(action);
|
||||||
return action as T & {
|
return action as T & {
|
||||||
keyTest?: unknown extends T["keyTest"] ? never : T["keyTest"];
|
keyTest?: unknown extends T["keyTest"] ? never : T["keyTest"];
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ export type ActionResult =
|
|||||||
}
|
}
|
||||||
| false;
|
| false;
|
||||||
|
|
||||||
type ActionFn = (
|
type ActionFn<TData = any> = (
|
||||||
elements: readonly OrderedExcalidrawElement[],
|
elements: readonly OrderedExcalidrawElement[],
|
||||||
appState: Readonly<AppState>,
|
appState: Readonly<AppState>,
|
||||||
formData: any,
|
formData: TData | undefined,
|
||||||
app: AppClassProperties,
|
app: AppClassProperties,
|
||||||
) => ActionResult | Promise<ActionResult>;
|
) => ActionResult | Promise<ActionResult>;
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ export type PanelComponentProps = {
|
|||||||
) => React.JSX.Element | null;
|
) => React.JSX.Element | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface Action {
|
export interface Action<TData = any> {
|
||||||
name: ActionName;
|
name: ActionName;
|
||||||
label:
|
label:
|
||||||
| string
|
| string
|
||||||
@@ -174,7 +174,7 @@ export interface Action {
|
|||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
) => React.ReactNode);
|
) => React.ReactNode);
|
||||||
PanelComponent?: React.FC<PanelComponentProps>;
|
PanelComponent?: React.FC<PanelComponentProps>;
|
||||||
perform: ActionFn;
|
perform: ActionFn<TData>;
|
||||||
keyPriority?: number;
|
keyPriority?: number;
|
||||||
keyTest?: (
|
keyTest?: (
|
||||||
event: React.KeyboardEvent | KeyboardEvent,
|
event: React.KeyboardEvent | KeyboardEvent,
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
panels: STATS_PANELS.generalStats | STATS_PANELS.elementProperties,
|
panels: STATS_PANELS.generalStats | STATS_PANELS.elementProperties,
|
||||||
},
|
},
|
||||||
startBoundElement: null,
|
startBoundElement: null,
|
||||||
suggestedBindings: [],
|
suggestedBinding: null,
|
||||||
frameRendering: { enabled: true, clip: true, name: true, outline: true },
|
frameRendering: { enabled: true, clip: true, name: true, outline: true },
|
||||||
frameToHighlight: null,
|
frameToHighlight: null,
|
||||||
editingFrame: null,
|
editingFrame: null,
|
||||||
@@ -127,6 +127,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
searchMatches: null,
|
searchMatches: null,
|
||||||
lockedMultiSelections: {},
|
lockedMultiSelections: {},
|
||||||
activeLockedId: null,
|
activeLockedId: null,
|
||||||
|
bindMode: "orbit",
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
shouldCacheIgnoreZoom: { browser: true, export: false, server: false },
|
shouldCacheIgnoreZoom: { browser: true, export: false, server: false },
|
||||||
stats: { browser: true, export: false, server: false },
|
stats: { browser: true, export: false, server: false },
|
||||||
startBoundElement: { browser: false, export: false, server: false },
|
startBoundElement: { browser: false, export: false, server: false },
|
||||||
suggestedBindings: { browser: false, export: false, server: false },
|
suggestedBinding: { browser: false, export: false, server: false },
|
||||||
frameRendering: { browser: false, export: false, server: false },
|
frameRendering: { browser: false, export: false, server: false },
|
||||||
frameToHighlight: { browser: false, export: false, server: false },
|
frameToHighlight: { browser: false, export: false, server: false },
|
||||||
editingFrame: { browser: false, export: false, server: false },
|
editingFrame: { browser: false, export: false, server: false },
|
||||||
@@ -252,6 +253,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
searchMatches: { browser: false, export: false, server: false },
|
searchMatches: { browser: false, export: false, server: false },
|
||||||
lockedMultiSelections: { browser: true, export: true, server: true },
|
lockedMultiSelections: { browser: true, export: true, server: true },
|
||||||
activeLockedId: { browser: false, export: false, server: false },
|
activeLockedId: { browser: false, export: false, server: false },
|
||||||
|
bindMode: { browser: true, export: false, server: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
const _clearAppStateForStorage = <
|
const _clearAppStateForStorage = <
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
VERTICAL_ALIGN,
|
VERTICAL_ALIGN,
|
||||||
randomId,
|
randomId,
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
|
FONT_SIZES,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -213,7 +214,7 @@ const chartXLabels = (
|
|||||||
y: y + BAR_GAP / 2,
|
y: y + BAR_GAP / 2,
|
||||||
width: BAR_WIDTH,
|
width: BAR_WIDTH,
|
||||||
angle: 5.87 as Radians,
|
angle: 5.87 as Radians,
|
||||||
fontSize: 16,
|
fontSize: FONT_SIZES.sm,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
verticalAlign: "top",
|
verticalAlign: "top",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ export const createPasteEvent = ({
|
|||||||
if (typeof value !== "string") {
|
if (typeof value !== "string") {
|
||||||
files = files || [];
|
files = files || [];
|
||||||
files.push(value);
|
files.push(value);
|
||||||
event.clipboardData?.items.add(value);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1049
-388
File diff suppressed because it is too large
Load Diff
@@ -1034,7 +1034,7 @@ const CommandItem = ({
|
|||||||
size="var(--icon-size, 1rem)"
|
size="var(--icon-size, 1rem)"
|
||||||
icon={
|
icon={
|
||||||
typeof command.icon === "function"
|
typeof command.icon === "function"
|
||||||
? command.icon(appState)
|
? command.icon(appState, [])
|
||||||
: command.icon
|
: command.icon
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { ActionManager } from "../../actions/manager";
|
import type { ActionManager } from "../../actions/manager";
|
||||||
import type { Action } from "../../actions/types";
|
import type { Action } from "../../actions/types";
|
||||||
import type { UIAppState } from "../../types";
|
|
||||||
|
|
||||||
export type CommandPaletteItem = {
|
export type CommandPaletteItem = {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -12,7 +11,7 @@ export type CommandPaletteItem = {
|
|||||||
* (deburred name + keywords)
|
* (deburred name + keywords)
|
||||||
*/
|
*/
|
||||||
haystack?: string;
|
haystack?: string;
|
||||||
icon?: React.ReactNode | ((appState: UIAppState) => React.ReactNode);
|
icon?: Action["icon"];
|
||||||
category: string;
|
category: string;
|
||||||
order?: number;
|
order?: number;
|
||||||
predicate?: boolean | Action["predicate"];
|
predicate?: boolean | Action["predicate"];
|
||||||
|
|||||||
@@ -844,7 +844,7 @@ const convertElementType = <
|
|||||||
}),
|
}),
|
||||||
) as typeof element;
|
) as typeof element;
|
||||||
|
|
||||||
updateBindings(nextElement, app.scene);
|
updateBindings(nextElement, app.scene, app.state);
|
||||||
|
|
||||||
return nextElement;
|
return nextElement;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,20 @@ const getHints = ({
|
|||||||
shortcut: getTaggedShortcutKey("Alt"),
|
shortcut: getTaggedShortcutKey("Alt"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectedElements = app.scene.getSelectedElements(appState);
|
||||||
|
|
||||||
|
// creating or dragging arrow point
|
||||||
|
if (
|
||||||
|
appState.selectedLinearElement?.isDragging &&
|
||||||
|
selectedElements[0]?.type === "arrow"
|
||||||
|
) {
|
||||||
|
return t("hints.arrowBindModifiers", {
|
||||||
|
shortcut_1: getTaggedShortcutKey("Ctrl"),
|
||||||
|
shortcut_2: getTaggedShortcutKey("Alt"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (activeTool.type === "arrow" || activeTool.type === "line") {
|
if (activeTool.type === "arrow" || activeTool.type === "line") {
|
||||||
if (multiMode) {
|
if (multiMode) {
|
||||||
return t("hints.linearElementMulti", {
|
return t("hints.linearElementMulti", {
|
||||||
@@ -89,8 +103,6 @@ const getHints = ({
|
|||||||
return t("hints.embeddable");
|
return t("hints.embeddable");
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedElements = app.scene.getSelectedElements(appState);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isResizing &&
|
isResizing &&
|
||||||
lastPointerDownWith === "mouse" &&
|
lastPointerDownWith === "mouse" &&
|
||||||
|
|||||||
@@ -646,14 +646,8 @@ const LayerUI = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const stripIrrelevantAppStateProps = (appState: AppState): UIAppState => {
|
const stripIrrelevantAppStateProps = (appState: AppState): UIAppState => {
|
||||||
const {
|
const { startBoundElement, cursorButton, scrollX, scrollY, ...ret } =
|
||||||
suggestedBindings,
|
appState;
|
||||||
startBoundElement,
|
|
||||||
cursorButton,
|
|
||||||
scrollX,
|
|
||||||
scrollY,
|
|
||||||
...ret
|
|
||||||
} = appState;
|
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const handleDegreeChange: DragInputCallbackType<AngleProps["property"]> = ({
|
|||||||
shouldChangeByStepSize,
|
shouldChangeByStepSize,
|
||||||
nextValue,
|
nextValue,
|
||||||
scene,
|
scene,
|
||||||
|
app,
|
||||||
}) => {
|
}) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const origElement = originalElements[0];
|
const origElement = originalElements[0];
|
||||||
@@ -48,7 +49,7 @@ const handleDegreeChange: DragInputCallbackType<AngleProps["property"]> = ({
|
|||||||
scene.mutateElement(latestElement, {
|
scene.mutateElement(latestElement, {
|
||||||
angle: nextAngle,
|
angle: nextAngle,
|
||||||
});
|
});
|
||||||
updateBindings(latestElement, scene);
|
updateBindings(latestElement, scene, app.state);
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
||||||
if (boundTextElement && !isArrowElement(latestElement)) {
|
if (boundTextElement && !isArrowElement(latestElement)) {
|
||||||
@@ -74,7 +75,7 @@ const handleDegreeChange: DragInputCallbackType<AngleProps["property"]> = ({
|
|||||||
scene.mutateElement(latestElement, {
|
scene.mutateElement(latestElement, {
|
||||||
angle: nextAngle,
|
angle: nextAngle,
|
||||||
});
|
});
|
||||||
updateBindings(latestElement, scene);
|
updateBindings(latestElement, scene, app.state);
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
||||||
if (boundTextElement && !isArrowElement(latestElement)) {
|
if (boundTextElement && !isArrowElement(latestElement)) {
|
||||||
|
|||||||
@@ -94,9 +94,7 @@ const resizeElementInGroup = (
|
|||||||
);
|
);
|
||||||
if (boundTextElement) {
|
if (boundTextElement) {
|
||||||
const newFontSize = boundTextElement.fontSize * scale;
|
const newFontSize = boundTextElement.fontSize * scale;
|
||||||
updateBoundElements(latestElement, scene, {
|
updateBoundElements(latestElement, scene);
|
||||||
newSize: { width: updates.width, height: updates.height },
|
|
||||||
});
|
|
||||||
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
|
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
|
||||||
if (latestBoundTextElement && isTextElement(latestBoundTextElement)) {
|
if (latestBoundTextElement && isTextElement(latestBoundTextElement)) {
|
||||||
scene.mutateElement(latestBoundTextElement, {
|
scene.mutateElement(latestBoundTextElement, {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ const moveElements = (
|
|||||||
originalElements: readonly ExcalidrawElement[],
|
originalElements: readonly ExcalidrawElement[],
|
||||||
originalElementsMap: ElementsMap,
|
originalElementsMap: ElementsMap,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
|
appState: AppState,
|
||||||
) => {
|
) => {
|
||||||
for (let i = 0; i < originalElements.length; i++) {
|
for (let i = 0; i < originalElements.length; i++) {
|
||||||
const origElement = originalElements[i];
|
const origElement = originalElements[i];
|
||||||
@@ -63,6 +64,7 @@ const moveElements = (
|
|||||||
newTopLeftY,
|
newTopLeftY,
|
||||||
origElement,
|
origElement,
|
||||||
scene,
|
scene,
|
||||||
|
appState,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
@@ -75,6 +77,7 @@ const moveGroupTo = (
|
|||||||
originalElements: ExcalidrawElement[],
|
originalElements: ExcalidrawElement[],
|
||||||
originalElementsMap: ElementsMap,
|
originalElementsMap: ElementsMap,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
|
appState: AppState,
|
||||||
) => {
|
) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const [x1, y1, ,] = getCommonBounds(originalElements);
|
const [x1, y1, ,] = getCommonBounds(originalElements);
|
||||||
@@ -107,6 +110,7 @@ const moveGroupTo = (
|
|||||||
topLeftY + offsetY,
|
topLeftY + offsetY,
|
||||||
origElement,
|
origElement,
|
||||||
scene,
|
scene,
|
||||||
|
appState,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
@@ -125,6 +129,7 @@ const handlePositionChange: DragInputCallbackType<
|
|||||||
property,
|
property,
|
||||||
scene,
|
scene,
|
||||||
originalAppState,
|
originalAppState,
|
||||||
|
app,
|
||||||
}) => {
|
}) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
|
||||||
@@ -152,6 +157,7 @@ const handlePositionChange: DragInputCallbackType<
|
|||||||
elementsInUnit.map((el) => el.original),
|
elementsInUnit.map((el) => el.original),
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
scene,
|
scene,
|
||||||
|
app.state,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const origElement = elementsInUnit[0]?.original;
|
const origElement = elementsInUnit[0]?.original;
|
||||||
@@ -178,6 +184,7 @@ const handlePositionChange: DragInputCallbackType<
|
|||||||
newTopLeftY,
|
newTopLeftY,
|
||||||
origElement,
|
origElement,
|
||||||
scene,
|
scene,
|
||||||
|
app.state,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
@@ -203,6 +210,7 @@ const handlePositionChange: DragInputCallbackType<
|
|||||||
originalElements,
|
originalElements,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
scene,
|
scene,
|
||||||
|
app.state,
|
||||||
);
|
);
|
||||||
|
|
||||||
scene.triggerUpdate();
|
scene.triggerUpdate();
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
|
|||||||
property,
|
property,
|
||||||
scene,
|
scene,
|
||||||
originalAppState,
|
originalAppState,
|
||||||
|
app,
|
||||||
}) => {
|
}) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const origElement = originalElements[0];
|
const origElement = originalElements[0];
|
||||||
@@ -131,6 +132,7 @@ const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
|
|||||||
newTopLeftY,
|
newTopLeftY,
|
||||||
origElement,
|
origElement,
|
||||||
scene,
|
scene,
|
||||||
|
app.state,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@@ -162,6 +164,7 @@ const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
|
|||||||
newTopLeftY,
|
newTopLeftY,
|
||||||
origElement,
|
origElement,
|
||||||
scene,
|
scene,
|
||||||
|
app.state,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { useEffect, useMemo, useState, memo } from "react";
|
|||||||
import { STATS_PANELS } from "@excalidraw/common";
|
import { STATS_PANELS } from "@excalidraw/common";
|
||||||
import { getCommonBounds } from "@excalidraw/element";
|
import { getCommonBounds } from "@excalidraw/element";
|
||||||
import { getUncroppedWidthAndHeight } from "@excalidraw/element";
|
import { getUncroppedWidthAndHeight } from "@excalidraw/element";
|
||||||
import { isElbowArrow, isImageElement } from "@excalidraw/element";
|
import { isImageElement } from "@excalidraw/element";
|
||||||
|
|
||||||
import { frameAndChildrenSelectedTogether } from "@excalidraw/element";
|
import { frameAndChildrenSelectedTogether } from "@excalidraw/element";
|
||||||
|
|
||||||
@@ -333,16 +333,14 @@ export const StatsInner = memo(
|
|||||||
appState={appState}
|
appState={appState}
|
||||||
/>
|
/>
|
||||||
</StatsRow>
|
</StatsRow>
|
||||||
{!isElbowArrow(singleElement) && (
|
<StatsRow>
|
||||||
<StatsRow>
|
<Angle
|
||||||
<Angle
|
property="angle"
|
||||||
property="angle"
|
element={singleElement}
|
||||||
element={singleElement}
|
scene={scene}
|
||||||
scene={scene}
|
appState={appState}
|
||||||
appState={appState}
|
/>
|
||||||
/>
|
</StatsRow>
|
||||||
</StatsRow>
|
|
||||||
)}
|
|
||||||
<StatsRow>
|
<StatsRow>
|
||||||
<FontSize
|
<FontSize
|
||||||
property="fontSize"
|
property="fontSize"
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ describe("binding with linear elements", () => {
|
|||||||
mouse.up(200, 100);
|
mouse.up(200, 100);
|
||||||
|
|
||||||
UI.clickTool("arrow");
|
UI.clickTool("arrow");
|
||||||
mouse.down(5, 0);
|
mouse.down(-5, 0);
|
||||||
mouse.up(300, 50);
|
mouse.up(300, 50);
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
elementStats = stats?.querySelector("#elementStats");
|
||||||
@@ -135,18 +135,7 @@ describe("binding with linear elements", () => {
|
|||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
expect(linear.startBinding).not.toBe(null);
|
expect(linear.startBinding).not.toBe(null);
|
||||||
expect(inputX).not.toBeNull();
|
expect(inputX).not.toBeNull();
|
||||||
UI.updateInput(inputX, String("204"));
|
UI.updateInput(inputX, String("186"));
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should remain bound to linear element on small angle change", async () => {
|
|
||||||
const linear = h.elements[1] as ExcalidrawLinearElement;
|
|
||||||
const inputAngle = UI.queryStatsProperty("A")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
UI.updateInput(inputAngle, String("1"));
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
expect(linear.startBinding).not.toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,17 +150,6 @@ describe("binding with linear elements", () => {
|
|||||||
UI.updateInput(inputX, String("254"));
|
UI.updateInput(inputX, String("254"));
|
||||||
expect(linear.startBinding).toBe(null);
|
expect(linear.startBinding).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should remain bound to linear element on small angle change", async () => {
|
|
||||||
const linear = h.elements[1] as ExcalidrawLinearElement;
|
|
||||||
const inputAngle = UI.queryStatsProperty("A")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
UI.updateInput(inputAngle, String("45"));
|
|
||||||
expect(linear.startBinding).toBe(null);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// single element
|
// single element
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { pointFrom, pointRotateRads } from "@excalidraw/math";
|
import { pointFrom, pointRotateRads } from "@excalidraw/math";
|
||||||
|
|
||||||
import { getBoundTextElement } from "@excalidraw/element";
|
import {
|
||||||
|
getBoundTextElement,
|
||||||
|
isBindingElement,
|
||||||
|
unbindBindingElement,
|
||||||
|
} from "@excalidraw/element";
|
||||||
import { isFrameLikeElement } from "@excalidraw/element";
|
import { isFrameLikeElement } from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -12,6 +16,7 @@ import {
|
|||||||
import { getFrameChildren } from "@excalidraw/element";
|
import { getFrameChildren } from "@excalidraw/element";
|
||||||
|
|
||||||
import { updateBindings } from "@excalidraw/element";
|
import { updateBindings } from "@excalidraw/element";
|
||||||
|
import { DRAGGING_THRESHOLD } from "@excalidraw/common";
|
||||||
|
|
||||||
import type { Radians } from "@excalidraw/math";
|
import type { Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
@@ -110,9 +115,25 @@ export const moveElement = (
|
|||||||
newTopLeftY: number,
|
newTopLeftY: number,
|
||||||
originalElement: ExcalidrawElement,
|
originalElement: ExcalidrawElement,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
|
appState: AppState,
|
||||||
originalElementsMap: ElementsMap,
|
originalElementsMap: ElementsMap,
|
||||||
shouldInformMutation = true,
|
shouldInformMutation = true,
|
||||||
) => {
|
) => {
|
||||||
|
if (
|
||||||
|
isBindingElement(originalElement) &&
|
||||||
|
(originalElement.startBinding || originalElement.endBinding)
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
Math.abs(newTopLeftX - originalElement.x) < DRAGGING_THRESHOLD &&
|
||||||
|
Math.abs(newTopLeftY - originalElement.y) < DRAGGING_THRESHOLD
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unbindBindingElement(originalElement, "start", scene);
|
||||||
|
unbindBindingElement(originalElement, "end", scene);
|
||||||
|
}
|
||||||
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const latestElement = elementsMap.get(originalElement.id);
|
const latestElement = elementsMap.get(originalElement.id);
|
||||||
if (!latestElement) {
|
if (!latestElement) {
|
||||||
@@ -145,7 +166,7 @@ export const moveElement = (
|
|||||||
},
|
},
|
||||||
{ informMutation: shouldInformMutation, isDragging: false },
|
{ informMutation: shouldInformMutation, isDragging: false },
|
||||||
);
|
);
|
||||||
updateBindings(latestElement, scene);
|
updateBindings(latestElement, scene, appState);
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(
|
const boundTextElement = getBoundTextElement(
|
||||||
originalElement,
|
originalElement,
|
||||||
@@ -203,7 +224,7 @@ export const moveElement = (
|
|||||||
},
|
},
|
||||||
{ informMutation: shouldInformMutation, isDragging: false },
|
{ informMutation: shouldInformMutation, isDragging: false },
|
||||||
);
|
);
|
||||||
updateBindings(latestChildElement, scene, {
|
updateBindings(latestChildElement, scene, appState, {
|
||||||
simultaneouslyUpdated: originalChildren,
|
simultaneouslyUpdated: originalChildren,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -157,6 +157,8 @@ const InteractiveCanvas = (props: InteractiveCanvasProps) => {
|
|||||||
remotePointerUserStates,
|
remotePointerUserStates,
|
||||||
selectionColor,
|
selectionColor,
|
||||||
renderScrollbars: props.renderScrollbars,
|
renderScrollbars: props.renderScrollbars,
|
||||||
|
// NOTE not memoized on so we don't rerender on cursor move
|
||||||
|
lastViewportPosition: props.app.lastViewportPosition,
|
||||||
},
|
},
|
||||||
editorInterface: props.editorInterface,
|
editorInterface: props.editorInterface,
|
||||||
callback: props.renderInteractiveSceneCallback,
|
callback: props.renderInteractiveSceneCallback,
|
||||||
@@ -242,8 +244,9 @@ const getRelevantAppStateProps = (
|
|||||||
selectedGroupIds: appState.selectedGroupIds,
|
selectedGroupIds: appState.selectedGroupIds,
|
||||||
selectedLinearElement: appState.selectedLinearElement,
|
selectedLinearElement: appState.selectedLinearElement,
|
||||||
multiElement: appState.multiElement,
|
multiElement: appState.multiElement,
|
||||||
|
newElement: appState.newElement,
|
||||||
isBindingEnabled: appState.isBindingEnabled,
|
isBindingEnabled: appState.isBindingEnabled,
|
||||||
suggestedBindings: appState.suggestedBindings,
|
suggestedBinding: appState.suggestedBinding,
|
||||||
isRotating: appState.isRotating,
|
isRotating: appState.isRotating,
|
||||||
elementsToHighlight: appState.elementsToHighlight,
|
elementsToHighlight: appState.elementsToHighlight,
|
||||||
collaborators: appState.collaborators, // Necessary for collab. sessions
|
collaborators: appState.collaborators, // Necessary for collab. sessions
|
||||||
@@ -255,6 +258,10 @@ const getRelevantAppStateProps = (
|
|||||||
croppingElementId: appState.croppingElementId,
|
croppingElementId: appState.croppingElementId,
|
||||||
searchMatches: appState.searchMatches,
|
searchMatches: appState.searchMatches,
|
||||||
activeLockedId: appState.activeLockedId,
|
activeLockedId: appState.activeLockedId,
|
||||||
|
hoveredElementIds: appState.hoveredElementIds,
|
||||||
|
frameRendering: appState.frameRendering,
|
||||||
|
shouldCacheIgnoreZoom: appState.shouldCacheIgnoreZoom,
|
||||||
|
exportScale: appState.exportScale,
|
||||||
});
|
});
|
||||||
|
|
||||||
const areEqual = (
|
const areEqual = (
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ const getRelevantAppStateProps = (appState: AppState): StaticCanvasAppState => {
|
|||||||
editingGroupId: appState.editingGroupId,
|
editingGroupId: appState.editingGroupId,
|
||||||
currentHoveredFontFamily: appState.currentHoveredFontFamily,
|
currentHoveredFontFamily: appState.currentHoveredFontFamily,
|
||||||
croppingElementId: appState.croppingElementId,
|
croppingElementId: appState.croppingElementId,
|
||||||
|
suggestedBinding: appState.suggestedBinding,
|
||||||
};
|
};
|
||||||
|
|
||||||
return relevantAppStateProps;
|
return relevantAppStateProps;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { hitElementBoundingBox } from "@excalidraw/element";
|
|||||||
|
|
||||||
import type { GlobalPoint, Radians } from "@excalidraw/math";
|
import type { GlobalPoint, Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
import type { Bounds } from "@excalidraw/element";
|
import type { Bounds } from "@excalidraw/common";
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
NonDeletedExcalidrawElement,
|
NonDeletedExcalidrawElement,
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import {
|
|||||||
isPromiseLike,
|
isPromiseLike,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import { clearElementsForExport } from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { ValueOf } from "@excalidraw/common/utility-types";
|
import type { ValueOf } from "@excalidraw/common/utility-types";
|
||||||
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
|
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
|
||||||
|
|
||||||
@@ -159,7 +157,7 @@ export const loadSceneOrLibraryFromBlob = async (
|
|||||||
type: MIME_TYPES.excalidraw,
|
type: MIME_TYPES.excalidraw,
|
||||||
data: restore(
|
data: restore(
|
||||||
{
|
{
|
||||||
elements: clearElementsForExport(data.elements || []),
|
elements: data.elements || [],
|
||||||
appState: {
|
appState: {
|
||||||
theme: localAppState?.theme,
|
theme: localAppState?.theme,
|
||||||
fileHandle: fileHandle || blob.handle || null,
|
fileHandle: fileHandle || blob.handle || null,
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ function dataView(
|
|||||||
*
|
*
|
||||||
* @param buffers each buffer (chunk) must be at most 2^32 bits large (~4GB)
|
* @param buffers each buffer (chunk) must be at most 2^32 bits large (~4GB)
|
||||||
*/
|
*/
|
||||||
const concatBuffers = (...buffers: Uint8Array[]) => {
|
const concatBuffers = (...buffers: Uint8Array[]): Uint8Array<ArrayBuffer> => {
|
||||||
const bufferView = new Uint8Array(
|
const bufferView = new Uint8Array(
|
||||||
VERSION_DATAVIEW_BYTES +
|
VERSION_DATAVIEW_BYTES +
|
||||||
NEXT_CHUNK_SIZE_DATAVIEW_BYTES * buffers.length +
|
NEXT_CHUNK_SIZE_DATAVIEW_BYTES * buffers.length +
|
||||||
@@ -295,12 +295,12 @@ const splitBuffers = (concatenatedBuffer: Uint8Array) => {
|
|||||||
|
|
||||||
/** @private */
|
/** @private */
|
||||||
const _encryptAndCompress = async (
|
const _encryptAndCompress = async (
|
||||||
data: Uint8Array | string,
|
data: Uint8Array<ArrayBuffer> | string,
|
||||||
encryptionKey: string,
|
encryptionKey: string,
|
||||||
) => {
|
) => {
|
||||||
const { encryptedBuffer, iv } = await encryptData(
|
const { encryptedBuffer, iv } = await encryptData(
|
||||||
encryptionKey,
|
encryptionKey,
|
||||||
deflate(data),
|
deflate(data) as Uint8Array<ArrayBuffer>,
|
||||||
);
|
);
|
||||||
|
|
||||||
return { iv, buffer: new Uint8Array(encryptedBuffer) };
|
return { iv, buffer: new Uint8Array(encryptedBuffer) };
|
||||||
@@ -330,7 +330,7 @@ export const compressData = async <T extends Record<string, any> = never>(
|
|||||||
: {
|
: {
|
||||||
metadata: T;
|
metadata: T;
|
||||||
}),
|
}),
|
||||||
): Promise<Uint8Array> => {
|
): Promise<Uint8Array<ArrayBuffer>> => {
|
||||||
const fileInfo: FileEncodingInfo = {
|
const fileInfo: FileEncodingInfo = {
|
||||||
version: 2,
|
version: 2,
|
||||||
compression: "pako@1",
|
compression: "pako@1",
|
||||||
@@ -355,8 +355,8 @@ export const compressData = async <T extends Record<string, any> = never>(
|
|||||||
|
|
||||||
/** @private */
|
/** @private */
|
||||||
const _decryptAndDecompress = async (
|
const _decryptAndDecompress = async (
|
||||||
iv: Uint8Array,
|
iv: Uint8Array<ArrayBuffer>,
|
||||||
decryptedBuffer: Uint8Array,
|
decryptedBuffer: Uint8Array<ArrayBuffer>,
|
||||||
decryptionKey: string,
|
decryptionKey: string,
|
||||||
isCompressed: boolean,
|
isCompressed: boolean,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { blobToArrayBuffer } from "./blob";
|
|||||||
|
|
||||||
export const IV_LENGTH_BYTES = 12;
|
export const IV_LENGTH_BYTES = 12;
|
||||||
|
|
||||||
export const createIV = () => {
|
export const createIV = (): Uint8Array<ArrayBuffer> => {
|
||||||
const arr = new Uint8Array(IV_LENGTH_BYTES);
|
const arr = new Uint8Array(IV_LENGTH_BYTES);
|
||||||
return window.crypto.getRandomValues(arr);
|
return window.crypto.getRandomValues(arr);
|
||||||
};
|
};
|
||||||
@@ -49,12 +49,12 @@ export const getCryptoKey = (key: string, usage: KeyUsage) =>
|
|||||||
|
|
||||||
export const encryptData = async (
|
export const encryptData = async (
|
||||||
key: string | CryptoKey,
|
key: string | CryptoKey,
|
||||||
data: Uint8Array | ArrayBuffer | Blob | File | string,
|
data: Uint8Array<ArrayBuffer> | ArrayBuffer | Blob | File | string,
|
||||||
): Promise<{ encryptedBuffer: ArrayBuffer; iv: Uint8Array }> => {
|
): Promise<{ encryptedBuffer: ArrayBuffer; iv: Uint8Array<ArrayBuffer> }> => {
|
||||||
const importedKey =
|
const importedKey =
|
||||||
typeof key === "string" ? await getCryptoKey(key, "encrypt") : key;
|
typeof key === "string" ? await getCryptoKey(key, "encrypt") : key;
|
||||||
const iv = createIV();
|
const iv = createIV();
|
||||||
const buffer: ArrayBuffer | Uint8Array =
|
const buffer: ArrayBuffer | Uint8Array<ArrayBuffer> =
|
||||||
typeof data === "string"
|
typeof data === "string"
|
||||||
? new TextEncoder().encode(data)
|
? new TextEncoder().encode(data)
|
||||||
: data instanceof Uint8Array
|
: data instanceof Uint8Array
|
||||||
@@ -71,15 +71,15 @@ export const encryptData = async (
|
|||||||
iv,
|
iv,
|
||||||
},
|
},
|
||||||
importedKey,
|
importedKey,
|
||||||
buffer as ArrayBuffer | Uint8Array,
|
buffer,
|
||||||
);
|
);
|
||||||
|
|
||||||
return { encryptedBuffer, iv };
|
return { encryptedBuffer, iv };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const decryptData = async (
|
export const decryptData = async (
|
||||||
iv: Uint8Array,
|
iv: Uint8Array<ArrayBuffer>,
|
||||||
encrypted: Uint8Array | ArrayBuffer,
|
encrypted: Uint8Array<ArrayBuffer> | ArrayBuffer,
|
||||||
privateKey: string,
|
privateKey: string,
|
||||||
): Promise<ArrayBuffer> => {
|
): Promise<ArrayBuffer> => {
|
||||||
const key = await getCryptoKey(privateKey, "decrypt");
|
const key = await getCryptoKey(privateKey, "decrypt");
|
||||||
|
|||||||
@@ -6,11 +6,6 @@ import {
|
|||||||
VERSIONS,
|
VERSIONS,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
|
||||||
clearElementsForDatabase,
|
|
||||||
clearElementsForExport,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { cleanAppStateForExport, clearAppStateForDatabase } from "../appState";
|
import { cleanAppStateForExport, clearAppStateForDatabase } from "../appState";
|
||||||
@@ -57,10 +52,7 @@ export const serializeAsJSON = (
|
|||||||
type: EXPORT_DATA_TYPES.excalidraw,
|
type: EXPORT_DATA_TYPES.excalidraw,
|
||||||
version: VERSIONS.excalidraw,
|
version: VERSIONS.excalidraw,
|
||||||
source: getExportSource(),
|
source: getExportSource(),
|
||||||
elements:
|
elements,
|
||||||
type === "local"
|
|
||||||
? clearElementsForExport(elements)
|
|
||||||
: clearElementsForDatabase(elements),
|
|
||||||
appState:
|
appState:
|
||||||
type === "local"
|
type === "local"
|
||||||
? cleanAppStateForExport(appState)
|
? cleanAppStateForExport(appState)
|
||||||
|
|||||||
@@ -18,7 +18,13 @@ import {
|
|||||||
normalizeLink,
|
normalizeLink,
|
||||||
getLineHeight,
|
getLineHeight,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
import { getNonDeletedElements, isValidPolygon } from "@excalidraw/element";
|
import {
|
||||||
|
calculateFixedPointForNonElbowArrowBinding,
|
||||||
|
getNonDeletedElements,
|
||||||
|
isPointInElement,
|
||||||
|
isValidPolygon,
|
||||||
|
projectFixedPointOntoDiagonal,
|
||||||
|
} from "@excalidraw/element";
|
||||||
import { normalizeFixedPoint } from "@excalidraw/element";
|
import { normalizeFixedPoint } from "@excalidraw/element";
|
||||||
import {
|
import {
|
||||||
updateElbowArrowPoints,
|
updateElbowArrowPoints,
|
||||||
@@ -32,7 +38,6 @@ import {
|
|||||||
isArrowBoundToElement,
|
isArrowBoundToElement,
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
isFixedPointBinding,
|
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isLineElement,
|
isLineElement,
|
||||||
isTextElement,
|
isTextElement,
|
||||||
@@ -50,10 +55,12 @@ import { isInvisiblySmallElement } from "@excalidraw/element";
|
|||||||
import type { LocalPoint, Radians } from "@excalidraw/math";
|
import type { LocalPoint, Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
ElementsMap,
|
||||||
|
ElementsMapOrArray,
|
||||||
ExcalidrawArrowElement,
|
ExcalidrawArrowElement,
|
||||||
|
ExcalidrawBindableElement,
|
||||||
ExcalidrawElbowArrowElement,
|
ExcalidrawElbowArrowElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawElementType,
|
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
ExcalidrawSelectionElement,
|
ExcalidrawSelectionElement,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
@@ -61,7 +68,6 @@ import type {
|
|||||||
FontFamilyValues,
|
FontFamilyValues,
|
||||||
NonDeletedSceneElementsMap,
|
NonDeletedSceneElementsMap,
|
||||||
OrderedExcalidrawElement,
|
OrderedExcalidrawElement,
|
||||||
PointBinding,
|
|
||||||
StrokeRoundness,
|
StrokeRoundness,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
@@ -121,38 +127,86 @@ const getFontFamilyByName = (fontFamilyName: string): FontFamilyValues => {
|
|||||||
return DEFAULT_FONT_FAMILY;
|
return DEFAULT_FONT_FAMILY;
|
||||||
};
|
};
|
||||||
|
|
||||||
const repairBinding = <T extends ExcalidrawLinearElement>(
|
const repairBinding = <T extends ExcalidrawArrowElement>(
|
||||||
element: T,
|
element: T,
|
||||||
binding: PointBinding | FixedPointBinding | null,
|
binding: FixedPointBinding | null,
|
||||||
): T extends ExcalidrawElbowArrowElement
|
targetElementsMap: Readonly<ElementsMap>,
|
||||||
? FixedPointBinding | null
|
localElementsMap: Readonly<ElementsMap> | null | undefined,
|
||||||
: PointBinding | FixedPointBinding | null => {
|
startOrEnd: "start" | "end",
|
||||||
|
): FixedPointBinding | null => {
|
||||||
if (!binding) {
|
if (!binding) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const focus = binding.focus || 0;
|
|
||||||
|
|
||||||
if (isElbowArrow(element)) {
|
if (isElbowArrow(element)) {
|
||||||
const fixedPointBinding:
|
const fixedPointBinding:
|
||||||
| ExcalidrawElbowArrowElement["startBinding"]
|
| ExcalidrawElbowArrowElement["startBinding"]
|
||||||
| ExcalidrawElbowArrowElement["endBinding"] = isFixedPointBinding(binding)
|
| ExcalidrawElbowArrowElement["endBinding"] = {
|
||||||
? {
|
...binding,
|
||||||
...binding,
|
fixedPoint: normalizeFixedPoint(binding.fixedPoint ?? [0, 0]),
|
||||||
focus,
|
mode: binding.mode || "orbit",
|
||||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint ?? [0, 0]),
|
};
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return fixedPointBinding;
|
return fixedPointBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
// Fallback if the bound element is missing but the binding is at least
|
||||||
...binding,
|
// looking like a valid one shape-wise
|
||||||
focus,
|
if (binding.mode && binding.fixedPoint && binding.elementId) {
|
||||||
} as T extends ExcalidrawElbowArrowElement
|
return {
|
||||||
? FixedPointBinding | null
|
elementId: binding.elementId,
|
||||||
: PointBinding | FixedPointBinding | null;
|
mode: binding.mode,
|
||||||
|
fixedPoint: normalizeFixedPoint(binding.fixedPoint || [0.5, 0.5]),
|
||||||
|
} as FixedPointBinding | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetBoundElement =
|
||||||
|
(targetElementsMap.get(binding.elementId) as ExcalidrawBindableElement) ||
|
||||||
|
undefined;
|
||||||
|
const boundElement =
|
||||||
|
targetBoundElement ||
|
||||||
|
(localElementsMap?.get(binding.elementId) as ExcalidrawBindableElement) ||
|
||||||
|
undefined;
|
||||||
|
const elementsMap = targetBoundElement ? targetElementsMap : localElementsMap;
|
||||||
|
|
||||||
|
// migrating legacy focus point bindings
|
||||||
|
if (boundElement && elementsMap) {
|
||||||
|
const p = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
element,
|
||||||
|
startOrEnd === "start" ? 0 : element.points.length - 1,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
const mode = isPointInElement(p, boundElement, elementsMap)
|
||||||
|
? "inside"
|
||||||
|
: "orbit";
|
||||||
|
const focusPoint =
|
||||||
|
mode === "inside"
|
||||||
|
? p
|
||||||
|
: projectFixedPointOntoDiagonal(
|
||||||
|
element,
|
||||||
|
p,
|
||||||
|
boundElement,
|
||||||
|
startOrEnd,
|
||||||
|
elementsMap,
|
||||||
|
) || p;
|
||||||
|
const { fixedPoint } = calculateFixedPointForNonElbowArrowBinding(
|
||||||
|
element,
|
||||||
|
boundElement,
|
||||||
|
startOrEnd,
|
||||||
|
elementsMap,
|
||||||
|
focusPoint,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
mode,
|
||||||
|
elementId: binding.elementId,
|
||||||
|
fixedPoint,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(`could not repair binding for element`);
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const restoreElementWithProperties = <
|
const restoreElementWithProperties = <
|
||||||
@@ -243,7 +297,11 @@ const restoreElementWithProperties = <
|
|||||||
|
|
||||||
export const restoreElement = (
|
export const restoreElement = (
|
||||||
element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
||||||
opts?: { deleteInvisibleElements?: boolean },
|
targetElementsMap: Readonly<ElementsMap>,
|
||||||
|
localElementsMap: Readonly<ElementsMap> | null | undefined,
|
||||||
|
opts?: {
|
||||||
|
deleteInvisibleElements?: boolean;
|
||||||
|
},
|
||||||
): typeof element | null => {
|
): typeof element | null => {
|
||||||
element = { ...element };
|
element = { ...element };
|
||||||
|
|
||||||
@@ -301,7 +359,6 @@ export const restoreElement = (
|
|||||||
case "freedraw": {
|
case "freedraw": {
|
||||||
return restoreElementWithProperties(element, {
|
return restoreElementWithProperties(element, {
|
||||||
points: element.points,
|
points: element.points,
|
||||||
lastCommittedPoint: null,
|
|
||||||
simulatePressure: element.simulatePressure,
|
simulatePressure: element.simulatePressure,
|
||||||
pressures: element.pressures,
|
pressures: element.pressures,
|
||||||
});
|
});
|
||||||
@@ -331,13 +388,9 @@ export const restoreElement = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
return restoreElementWithProperties(element, {
|
return restoreElementWithProperties(element, {
|
||||||
type:
|
type: "line",
|
||||||
(element.type as ExcalidrawElementType | "draw") === "draw"
|
startBinding: null,
|
||||||
? "line"
|
endBinding: null,
|
||||||
: element.type,
|
|
||||||
startBinding: repairBinding(element, element.startBinding),
|
|
||||||
endBinding: repairBinding(element, element.endBinding),
|
|
||||||
lastCommittedPoint: null,
|
|
||||||
startArrowhead,
|
startArrowhead,
|
||||||
endArrowhead,
|
endArrowhead,
|
||||||
points,
|
points,
|
||||||
@@ -354,23 +407,29 @@ export const restoreElement = (
|
|||||||
});
|
});
|
||||||
case "arrow": {
|
case "arrow": {
|
||||||
const { startArrowhead = null, endArrowhead = "arrow" } = element;
|
const { startArrowhead = null, endArrowhead = "arrow" } = element;
|
||||||
let x: number | undefined = element.x;
|
const x: number | undefined = element.x;
|
||||||
let y: number | undefined = element.y;
|
const y: number | undefined = element.y;
|
||||||
let points: readonly LocalPoint[] | undefined = // migrate old arrow model to new one
|
const points: readonly LocalPoint[] | undefined = // migrate old arrow model to new one
|
||||||
!Array.isArray(element.points) || element.points.length < 2
|
!Array.isArray(element.points) || element.points.length < 2
|
||||||
? [pointFrom(0, 0), pointFrom(element.width, element.height)]
|
? [pointFrom(0, 0), pointFrom(element.width, element.height)]
|
||||||
: element.points;
|
: element.points;
|
||||||
|
|
||||||
if (points[0][0] !== 0 || points[0][1] !== 0) {
|
|
||||||
({ points, x, y } =
|
|
||||||
LinearElementEditor.getNormalizeElementPointsAndCoords(element));
|
|
||||||
}
|
|
||||||
|
|
||||||
const base = {
|
const base = {
|
||||||
type: element.type,
|
type: element.type,
|
||||||
startBinding: repairBinding(element, element.startBinding),
|
startBinding: repairBinding(
|
||||||
endBinding: repairBinding(element, element.endBinding),
|
element as ExcalidrawArrowElement,
|
||||||
lastCommittedPoint: null,
|
element.startBinding,
|
||||||
|
targetElementsMap,
|
||||||
|
localElementsMap,
|
||||||
|
"start",
|
||||||
|
),
|
||||||
|
endBinding: repairBinding(
|
||||||
|
element as ExcalidrawArrowElement,
|
||||||
|
element.endBinding,
|
||||||
|
targetElementsMap,
|
||||||
|
localElementsMap,
|
||||||
|
"end",
|
||||||
|
),
|
||||||
startArrowhead,
|
startArrowhead,
|
||||||
endArrowhead,
|
endArrowhead,
|
||||||
points,
|
points,
|
||||||
@@ -378,15 +437,13 @@ export const restoreElement = (
|
|||||||
y,
|
y,
|
||||||
elbowed: (element as ExcalidrawArrowElement).elbowed,
|
elbowed: (element as ExcalidrawArrowElement).elbowed,
|
||||||
...getSizeFromPoints(points),
|
...getSizeFromPoints(points),
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
// TODO: Separate arrow from linear element
|
// TODO: Separate arrow from linear element
|
||||||
return isElbowArrow(element)
|
const restoredElement = isElbowArrow(element)
|
||||||
? restoreElementWithProperties(element as ExcalidrawElbowArrowElement, {
|
? restoreElementWithProperties(element as ExcalidrawElbowArrowElement, {
|
||||||
...base,
|
...base,
|
||||||
elbowed: true,
|
elbowed: true,
|
||||||
startBinding: repairBinding(element, element.startBinding),
|
|
||||||
endBinding: repairBinding(element, element.endBinding),
|
|
||||||
fixedSegments:
|
fixedSegments:
|
||||||
element.fixedSegments?.length && base.points.length >= 4
|
element.fixedSegments?.length && base.points.length >= 4
|
||||||
? element.fixedSegments
|
? element.fixedSegments
|
||||||
@@ -395,6 +452,13 @@ export const restoreElement = (
|
|||||||
endIsSpecial: element.endIsSpecial,
|
endIsSpecial: element.endIsSpecial,
|
||||||
})
|
})
|
||||||
: restoreElementWithProperties(element as ExcalidrawArrowElement, base);
|
: restoreElementWithProperties(element as ExcalidrawArrowElement, base);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...restoredElement,
|
||||||
|
...LinearElementEditor.getNormalizeElementPointsAndCoords(
|
||||||
|
restoredElement,
|
||||||
|
),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// generic elements
|
// generic elements
|
||||||
@@ -525,9 +589,9 @@ const repairFrameMembership = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const restoreElements = (
|
export const restoreElements = (
|
||||||
elements: ImportedDataState["elements"],
|
targetElements: ImportedDataState["elements"],
|
||||||
/** NOTE doesn't serve for reconciliation */
|
/** NOTE doesn't serve for reconciliation */
|
||||||
localElements: readonly ExcalidrawElement[] | null | undefined,
|
localElements: Readonly<ElementsMapOrArray> | null | undefined,
|
||||||
opts?:
|
opts?:
|
||||||
| {
|
| {
|
||||||
refreshDimensions?: boolean;
|
refreshDimensions?: boolean;
|
||||||
@@ -538,18 +602,24 @@ export const restoreElements = (
|
|||||||
): OrderedExcalidrawElement[] => {
|
): OrderedExcalidrawElement[] => {
|
||||||
// used to detect duplicate top-level element ids
|
// used to detect duplicate top-level element ids
|
||||||
const existingIds = new Set<string>();
|
const existingIds = new Set<string>();
|
||||||
|
const targetElementsMap = arrayToMap(targetElements || []);
|
||||||
const localElementsMap = localElements ? arrayToMap(localElements) : null;
|
const localElementsMap = localElements ? arrayToMap(localElements) : null;
|
||||||
const restoredElements = syncInvalidIndices(
|
const restoredElements = syncInvalidIndices(
|
||||||
(elements || []).reduce((elements, element) => {
|
(targetElements || []).reduce((elements, element) => {
|
||||||
// filtering out selection, which is legacy, no longer kept in elements,
|
// filtering out selection, which is legacy, no longer kept in elements,
|
||||||
// and causing issues if retained
|
// and causing issues if retained
|
||||||
if (element.type === "selection") {
|
if (element.type === "selection") {
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
let migratedElement: ExcalidrawElement | null = restoreElement(element, {
|
let migratedElement: ExcalidrawElement | null = restoreElement(
|
||||||
deleteInvisibleElements: opts?.deleteInvisibleElements,
|
element,
|
||||||
});
|
targetElementsMap,
|
||||||
|
localElementsMap,
|
||||||
|
{
|
||||||
|
deleteInvisibleElements: opts?.deleteInvisibleElements,
|
||||||
|
},
|
||||||
|
);
|
||||||
if (migratedElement) {
|
if (migratedElement) {
|
||||||
const localElement = localElementsMap?.get(element.id);
|
const localElement = localElementsMap?.get(element.id);
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { shouldTestInside } from "@excalidraw/element";
|
|||||||
import { hasBoundTextElement, isBoundToContainer } from "@excalidraw/element";
|
import { hasBoundTextElement, isBoundToContainer } from "@excalidraw/element";
|
||||||
import { getBoundTextElementId } from "@excalidraw/element";
|
import { getBoundTextElementId } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { Bounds } from "@excalidraw/element";
|
import type { Bounds } from "@excalidraw/common";
|
||||||
|
|
||||||
import type { GlobalPoint, LineSegment } from "@excalidraw/math/types";
|
import type { GlobalPoint, LineSegment } from "@excalidraw/math/types";
|
||||||
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
CJK_HAND_DRAWN_FALLBACK_FONT,
|
CJK_HAND_DRAWN_FALLBACK_FONT,
|
||||||
WINDOWS_EMOJI_FALLBACK_FONT,
|
WINDOWS_EMOJI_FALLBACK_FONT,
|
||||||
getFontFamilyFallbacks,
|
getFontFamilyFallbacks,
|
||||||
|
FONT_SIZES,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
import { getContainerElement } from "@excalidraw/element";
|
import { getContainerElement } from "@excalidraw/element";
|
||||||
import { charWidth } from "@excalidraw/element";
|
import { charWidth } from "@excalidraw/element";
|
||||||
@@ -240,7 +241,7 @@ export class Fonts {
|
|||||||
for (const [index, fontFamily] of fontFamilies.entries()) {
|
for (const [index, fontFamily] of fontFamilies.entries()) {
|
||||||
const font = getFontString({
|
const font = getFontString({
|
||||||
fontFamily,
|
fontFamily,
|
||||||
fontSize: 16,
|
fontSize: FONT_SIZES.sm,
|
||||||
});
|
});
|
||||||
|
|
||||||
// WARN: without "text" param it does not have to mean that all font faces are loaded as it could be just one irrelevant font face!
|
// WARN: without "text" param it does not have to mean that all font faces are loaded as it could be just one irrelevant font face!
|
||||||
|
|||||||
Vendored
+5
-2
@@ -42,7 +42,7 @@ declare module "png-chunk-text" {
|
|||||||
function decode(data: Uint8Array): { keyword: string; text: string };
|
function decode(data: Uint8Array): { keyword: string; text: string };
|
||||||
}
|
}
|
||||||
declare module "png-chunks-encode" {
|
declare module "png-chunks-encode" {
|
||||||
function encode(chunks: TEXtChunk[]): Uint8Array;
|
function encode(chunks: TEXtChunk[]): Uint8Array<ArrayBuffer>;
|
||||||
export = encode;
|
export = encode;
|
||||||
}
|
}
|
||||||
declare module "png-chunks-extract" {
|
declare module "png-chunks-extract" {
|
||||||
@@ -101,7 +101,10 @@ declare module "image-blob-reduce" {
|
|||||||
|
|
||||||
interface CustomMatchers {
|
interface CustomMatchers {
|
||||||
toBeNonNaNNumber(): void;
|
toBeNonNaNNumber(): void;
|
||||||
toCloselyEqualPoints(points: readonly [number, number][]): void;
|
toCloselyEqualPoints(
|
||||||
|
points: readonly [number, number][],
|
||||||
|
precision?: number,
|
||||||
|
): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare namespace jest {
|
declare namespace jest {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export function useOutsideClick<T extends HTMLElement>(
|
|||||||
* Returning `undefined` will fallback to the default behavior.
|
* Returning `undefined` will fallback to the default behavior.
|
||||||
*/
|
*/
|
||||||
isInside?: (
|
isInside?: (
|
||||||
event: Event & { target: HTMLElement },
|
event: Event & { target: T },
|
||||||
/** the element of the passed ref */
|
/** the element of the passed ref */
|
||||||
container: T,
|
container: T,
|
||||||
) => boolean | undefined,
|
) => boolean | undefined,
|
||||||
|
|||||||
@@ -293,8 +293,11 @@ export { TTDDialog } from "./components/TTDDialog/TTDDialog";
|
|||||||
export { TTDDialogTrigger } from "./components/TTDDialog/TTDDialogTrigger";
|
export { TTDDialogTrigger } from "./components/TTDDialog/TTDDialogTrigger";
|
||||||
|
|
||||||
export { zoomToFitBounds } from "./actions/actionCanvas";
|
export { zoomToFitBounds } from "./actions/actionCanvas";
|
||||||
export { convertToExcalidrawElements } from "./data/transform";
|
export {
|
||||||
export { getCommonBounds, getVisibleSceneBounds } from "@excalidraw/element";
|
getCommonBounds,
|
||||||
|
getVisibleSceneBounds,
|
||||||
|
convertToExcalidrawElements,
|
||||||
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
elementsOverlappingBBox,
|
elementsOverlappingBBox,
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import {
|
|||||||
polygonIncludesPointNonZero,
|
polygonIncludesPointNonZero,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
|
import { type Bounds } from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type Bounds,
|
|
||||||
computeBoundTextPosition,
|
computeBoundTextPosition,
|
||||||
doBoundsIntersect,
|
doBoundsIntersect,
|
||||||
getBoundTextElement,
|
getBoundTextElement,
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "انقر لبدء نقاط متعددة، اسحب لخط واحد",
|
"linearElement": "انقر لبدء نقاط متعددة، اسحب لخط واحد",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "انقر واسحب، أفرج عند الانتهاء",
|
"freeDraw": "انقر واسحب، أفرج عند الانتهاء",
|
||||||
"text": "نصيحة: يمكنك أيضًا إضافة نص بالنقر المزدوج في أي مكان بأداة الاختيار",
|
"text": "نصيحة: يمكنك أيضًا إضافة نص بالنقر المزدوج في أي مكان بأداة الاختيار",
|
||||||
"embeddable": "اضغط مع السحب لإنشاء موقع ويب مضمّن",
|
"embeddable": "اضغط مع السحب لإنشاء موقع ويب مضمّن",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "",
|
"linearElement": "",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "",
|
"freeDraw": "",
|
||||||
"text": "",
|
"text": "",
|
||||||
"embeddable": "",
|
"embeddable": "",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "Кликнете, за да стартирате няколко точки, плъзнете за една линия",
|
"linearElement": "Кликнете, за да стартирате няколко точки, плъзнете за една линия",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "Натиснете и влачете, пуснете като сте готови",
|
"freeDraw": "Натиснете и влачете, пуснете като сте готови",
|
||||||
"text": "Подсказка: Можете също да добавите текст като натиснете някъде два път с инструмента за селекция",
|
"text": "Подсказка: Можете също да добавите текст като натиснете някъде два път с инструмента за селекция",
|
||||||
"embeddable": "Натисни-премести, за да създадеш вметка за уебсайт",
|
"embeddable": "Натисни-премести, за да създадеш вметка за уебсайт",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "একাধিক বিন্দু শুরু করতে ক্লিক করুন, একক লাইনের জন্য টেনে আনুন",
|
"linearElement": "একাধিক বিন্দু শুরু করতে ক্লিক করুন, একক লাইনের জন্য টেনে আনুন",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "ক্লিক করুন এবং টেনে আনুন, আপনার কাজ শেষ হলে ছেড়ে দিন",
|
"freeDraw": "ক্লিক করুন এবং টেনে আনুন, আপনার কাজ শেষ হলে ছেড়ে দিন",
|
||||||
"text": "বিশেষ্য: আপনি নির্বাচন টুলের সাথে যে কোনো জায়গায় ডাবল-ক্লিক করে পাঠ্য যোগ করতে পারেন",
|
"text": "বিশেষ্য: আপনি নির্বাচন টুলের সাথে যে কোনো জায়গায় ডাবল-ক্লিক করে পাঠ্য যোগ করতে পারেন",
|
||||||
"embeddable": "",
|
"embeddable": "",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "একাধিক বিন্দু শুরু করতে ক্লিক করুন, একক লাইনের জন্য টেনে আনুন",
|
"linearElement": "একাধিক বিন্দু শুরু করতে ক্লিক করুন, একক লাইনের জন্য টেনে আনুন",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "ক্লিক করুন এবং টেনে আনুন, আপনার কাজ শেষ হলে ছেড়ে দিন",
|
"freeDraw": "ক্লিক করুন এবং টেনে আনুন, আপনার কাজ শেষ হলে ছেড়ে দিন",
|
||||||
"text": "বিশেষ্য: আপনি নির্বাচন টুলের সাথে যে কোনো জায়গায় ডাবল-ক্লিক করে পাঠ্য যোগ করতে পারেন",
|
"text": "বিশেষ্য: আপনি নির্বাচন টুলের সাথে যে কোনো জায়গায় ডাবল-ক্লিক করে পাঠ্য যোগ করতে পারেন",
|
||||||
"embeddable": "",
|
"embeddable": "",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "Feu clic per a dibuixar múltiples punts; arrossegueu per a una sola línia",
|
"linearElement": "Feu clic per a dibuixar múltiples punts; arrossegueu per a una sola línia",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "Feu clic i arrossegueu, deixeu anar per a finalitzar",
|
"freeDraw": "Feu clic i arrossegueu, deixeu anar per a finalitzar",
|
||||||
"text": "Consell: també podeu afegir text fent doble clic en qualsevol lloc amb l'eina de selecció",
|
"text": "Consell: també podeu afegir text fent doble clic en qualsevol lloc amb l'eina de selecció",
|
||||||
"embeddable": "Feu clic i arrossegueu per crear una Incrustació Web",
|
"embeddable": "Feu clic i arrossegueu per crear una Incrustació Web",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "Kliknutím pro více bodů, táhnutím pro jednu čáru",
|
"linearElement": "Kliknutím pro více bodů, táhnutím pro jednu čáru",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "Klikněte a táhněte, pro ukončení pusťte",
|
"freeDraw": "Klikněte a táhněte, pro ukončení pusťte",
|
||||||
"text": "Tip: Text můžete také přidat dvojitým kliknutím kdekoli pomocí nástroje pro výběr",
|
"text": "Tip: Text můžete také přidat dvojitým kliknutím kdekoli pomocí nástroje pro výběr",
|
||||||
"embeddable": "",
|
"embeddable": "",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "",
|
"linearElement": "",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "Klik og træk, slip når du er færdig",
|
"freeDraw": "Klik og træk, slip når du er færdig",
|
||||||
"text": "",
|
"text": "",
|
||||||
"embeddable": "",
|
"embeddable": "",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "Klicken für Linie mit mehreren Punkten, Ziehen für einzelne Linie",
|
"linearElement": "Klicken für Linie mit mehreren Punkten, Ziehen für einzelne Linie",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "Klicke und ziehe. Lass los, wenn du fertig bist",
|
"freeDraw": "Klicke und ziehe. Lass los, wenn du fertig bist",
|
||||||
"text": "Tipp: Du kannst auch Text hinzufügen, indem du mit dem Auswahlwerkzeug auf eine beliebige Stelle doppelklickst",
|
"text": "Tipp: Du kannst auch Text hinzufügen, indem du mit dem Auswahlwerkzeug auf eine beliebige Stelle doppelklickst",
|
||||||
"embeddable": "Klicken und ziehen, um eine Webseiten-Einbettung zu erstellen",
|
"embeddable": "Klicken und ziehen, um eine Webseiten-Einbettung zu erstellen",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "Klicken für Linie mit mehreren Punkten, Ziehen für einzelne Linie",
|
"linearElement": "Klicken für Linie mit mehreren Punkten, Ziehen für einzelne Linie",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "Klicke und ziehe. Lass los, wenn du fertig bist",
|
"freeDraw": "Klicke und ziehe. Lass los, wenn du fertig bist",
|
||||||
"text": "Tipp: Du kannst auch Text hinzufügen, indem du mit dem Auswahlwerkzeug auf eine beliebige Stelle doppelklickst",
|
"text": "Tipp: Du kannst auch Text hinzufügen, indem du mit dem Auswahlwerkzeug auf eine beliebige Stelle doppelklickst",
|
||||||
"embeddable": "Klicken und ziehen, um eine Webseiten-Einbettung zu erstellen",
|
"embeddable": "Klicken und ziehen, um eine Webseiten-Einbettung zu erstellen",
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
"canvasPanning": "",
|
"canvasPanning": "",
|
||||||
"linearElement": "Κάνε κλικ για να ξεκινήσεις πολλαπλά σημεία, σύρε για μια γραμμή",
|
"linearElement": "Κάνε κλικ για να ξεκινήσεις πολλαπλά σημεία, σύρε για μια γραμμή",
|
||||||
"arrowTool": "",
|
"arrowTool": "",
|
||||||
|
"arrowBindModifiers": "",
|
||||||
"freeDraw": "Κάντε κλικ και σύρτε, απελευθερώσατε όταν έχετε τελειώσει",
|
"freeDraw": "Κάντε κλικ και σύρτε, απελευθερώσατε όταν έχετε τελειώσει",
|
||||||
"text": "Tip: μπορείτε επίσης να προσθέστε κείμενο με διπλό-κλικ οπουδήποτε με το εργαλείο επιλογών",
|
"text": "Tip: μπορείτε επίσης να προσθέστε κείμενο με διπλό-κλικ οπουδήποτε με το εργαλείο επιλογών",
|
||||||
"embeddable": "Κάντε κλικ και σύρετε για να δημιουργήσετε μια ενσωματωμένη ιστοσελίδα",
|
"embeddable": "Κάντε κλικ και σύρετε για να δημιουργήσετε μια ενσωματωμένη ιστοσελίδα",
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user