Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77edb39a7e | ||
|
|
56c9ea9259 | ||
|
|
0d34177761 |
@@ -24,4 +24,4 @@ jobs:
|
|||||||
- name: Auto release
|
- name: Auto release
|
||||||
run: |
|
run: |
|
||||||
yarn add @actions/core -W
|
yarn add @actions/core -W
|
||||||
yarn release --tag=next --non-interactive
|
yarn autorelease
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
name: Auto release excalidraw preview
|
||||||
|
on:
|
||||||
|
issue_comment:
|
||||||
|
types: [created, edited]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Auto-release-excalidraw-preview:
|
||||||
|
name: Auto release preview
|
||||||
|
if: github.event.comment.body == '@excalibot trigger release' && github.event.issue.pull_request
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: React to release comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
|
||||||
|
comment-id: ${{ github.event.comment.id }}
|
||||||
|
reactions: "+1"
|
||||||
|
- name: Get PR SHA
|
||||||
|
id: sha
|
||||||
|
uses: actions/github-script@v4
|
||||||
|
with:
|
||||||
|
result-encoding: string
|
||||||
|
script: |
|
||||||
|
const { owner, repo, number } = context.issue;
|
||||||
|
const pr = await github.pulls.get({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
pull_number: number,
|
||||||
|
});
|
||||||
|
return pr.data.head.sha
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{ steps.sha.outputs.result }}
|
||||||
|
fetch-depth: 2
|
||||||
|
- name: Setup Node.js 18.x
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 18.x
|
||||||
|
- name: Set up publish access
|
||||||
|
run: |
|
||||||
|
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
|
||||||
|
env:
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
- name: Auto release preview
|
||||||
|
id: "autorelease"
|
||||||
|
run: |
|
||||||
|
yarn add @actions/core -W
|
||||||
|
yarn autorelease preview ${{ github.event.issue.number }}
|
||||||
|
- name: Post comment post release
|
||||||
|
if: always()
|
||||||
|
uses: peter-evans/create-or-update-comment@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
|
||||||
|
issue-number: ${{ github.event.issue.number }}
|
||||||
|
body: "@${{ github.event.comment.user.login }} ${{ steps.autorelease.outputs.result }}"
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
name: Playwright Tests
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main, master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main, master ]
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
timeout-minutes: 60
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: lts/*
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm install -g yarn && yarn
|
|
||||||
- name: Install Playwright Browsers
|
|
||||||
run: yarn playwright install --with-deps
|
|
||||||
- name: Run Playwright tests
|
|
||||||
run: yarn playwright test
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
if: ${{ !cancelled() }}
|
|
||||||
with:
|
|
||||||
name: playwright-report
|
|
||||||
path: playwright-report/
|
|
||||||
retention-days: 30
|
|
||||||
@@ -17,14 +17,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v3
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
tags: excalidraw/excalidraw:latest
|
tags: excalidraw/excalidraw:latest
|
||||||
platforms: linux/amd64, linux/arm64, linux/arm/v7
|
|
||||||
|
|||||||
@@ -27,9 +27,3 @@ dev-dist
|
|||||||
html
|
html
|
||||||
meta*.json
|
meta*.json
|
||||||
.claude
|
.claude
|
||||||
|
|
||||||
# Playwright
|
|
||||||
/test-results/
|
|
||||||
/playwright-report/
|
|
||||||
/blob-report/
|
|
||||||
/playwright/.cache/
|
|
||||||
|
|||||||
+4
-5
@@ -1,4 +1,4 @@
|
|||||||
FROM --platform=${BUILDPLATFORM} node:18 AS build
|
FROM node:18 AS build
|
||||||
|
|
||||||
WORKDIR /opt/node_app
|
WORKDIR /opt/node_app
|
||||||
|
|
||||||
@@ -6,14 +6,13 @@ COPY . .
|
|||||||
|
|
||||||
# do not ignore optional dependencies:
|
# do not ignore optional dependencies:
|
||||||
# Error: Cannot find module @rollup/rollup-linux-x64-gnu
|
# Error: Cannot find module @rollup/rollup-linux-x64-gnu
|
||||||
RUN --mount=type=cache,target=/root/.cache/yarn \
|
RUN yarn --network-timeout 600000
|
||||||
npm_config_target_arch=${TARGETARCH} yarn --network-timeout 600000
|
|
||||||
|
|
||||||
ARG NODE_ENV=production
|
ARG NODE_ENV=production
|
||||||
|
|
||||||
RUN npm_config_target_arch=${TARGETARCH} yarn build:app:docker
|
RUN yarn build:app:docker
|
||||||
|
|
||||||
FROM --platform=${TARGETPLATFORM} nginx:1.27-alpine
|
FROM nginx:1.27-alpine
|
||||||
|
|
||||||
COPY --from=build /opt/node_app/excalidraw-app/build /usr/share/nginx/html
|
COPY --from=build /opt/node_app/excalidraw-app/build /usr/share/nginx/html
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,32 @@ To start the example app using the `@excalidraw/excalidraw` package, follow the
|
|||||||
|
|
||||||
## Releasing
|
## Releasing
|
||||||
|
|
||||||
|
### Create a test release
|
||||||
|
|
||||||
|
You can create a test release by posting the below comment in your pull request:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
@excalibot trigger release
|
||||||
|
```
|
||||||
|
|
||||||
|
Once the version is released `@excalibot` will post a comment with the release version.
|
||||||
|
|
||||||
### Creating a production release
|
### Creating a production release
|
||||||
|
|
||||||
To release the next stable version follow the below steps:
|
To release the next stable version follow the below steps:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn release --tag=latest --version=0.19.0
|
yarn prerelease:excalidraw
|
||||||
```
|
```
|
||||||
|
|
||||||
You will need to pass the `latest` tag with `version` for which you want to create the release. This will make the changes needed before publishing the packages into NPM, like updating dependencies of all `@excalidraw/*` packages, generating new entries in `CHANGELOG.md` and more.
|
You need to pass the `version` for which you want to create the release. This will make the changes needed before making the release like updating `package.json`, `changelog` and more.
|
||||||
|
|
||||||
|
The next step is to run the `release` script:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn release:excalidraw
|
||||||
|
```
|
||||||
|
|
||||||
|
This will publish the package.
|
||||||
|
|
||||||
|
Right now there are two steps to create a production release but once this works fine these scripts will be combined and more automation will be done.
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ const ExcalidrawScope = {
|
|||||||
initialData,
|
initialData,
|
||||||
useI18n: ExcalidrawComp.useI18n,
|
useI18n: ExcalidrawComp.useI18n,
|
||||||
convertToExcalidrawElements: ExcalidrawComp.convertToExcalidrawElements,
|
convertToExcalidrawElements: ExcalidrawComp.convertToExcalidrawElements,
|
||||||
CaptureUpdateAction: ExcalidrawComp.CaptureUpdateAction,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ExcalidrawScope;
|
export default ExcalidrawScope;
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:packages": "yarn --cwd ../../ build:packages",
|
"build:workspace": "yarn workspace @excalidraw/excalidraw run build:esm && yarn copy:assets",
|
||||||
"build:workspace": "yarn build:packages && yarn copy:assets",
|
|
||||||
"copy:assets": "cp -r ../../packages/excalidraw/dist/prod/fonts ./public",
|
"copy:assets": "cp -r ../../packages/excalidraw/dist/prod/fonts ./public",
|
||||||
"dev": "yarn build:workspace && next dev -p 3005",
|
"dev": "yarn build:workspace && next dev -p 3005",
|
||||||
"build": "yarn build:workspace && next build",
|
"build": "yarn build:workspace && next build",
|
||||||
|
|||||||
@@ -17,6 +17,6 @@
|
|||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview --port 5002",
|
"preview": "vite preview --port 5002",
|
||||||
"build:preview": "yarn build && yarn preview",
|
"build:preview": "yarn build && yarn preview",
|
||||||
"build:packages": "yarn --cwd ../../ build:packages"
|
"build:package": "yarn workspace @excalidraw/excalidraw run build:esm"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"outputDirectory": "dist",
|
"outputDirectory": "dist",
|
||||||
"installCommand": "yarn install",
|
"installCommand": "yarn install",
|
||||||
"buildCommand": "yarn build:packages && yarn build"
|
"buildCommand": "yarn build:package && yarn build"
|
||||||
}
|
}
|
||||||
|
|||||||
+271
-1
@@ -4,6 +4,7 @@ import {
|
|||||||
TTDDialogTrigger,
|
TTDDialogTrigger,
|
||||||
CaptureUpdateAction,
|
CaptureUpdateAction,
|
||||||
reconcileElements,
|
reconcileElements,
|
||||||
|
convertToExcalidrawElements,
|
||||||
} from "@excalidraw/excalidraw";
|
} from "@excalidraw/excalidraw";
|
||||||
import { trackEvent } from "@excalidraw/excalidraw/analytics";
|
import { trackEvent } from "@excalidraw/excalidraw/analytics";
|
||||||
import { getDefaultAppState } from "@excalidraw/excalidraw/appState";
|
import { getDefaultAppState } from "@excalidraw/excalidraw/appState";
|
||||||
@@ -74,7 +75,6 @@ import type {
|
|||||||
import type { ResolutionType } from "@excalidraw/common/utility-types";
|
import type { ResolutionType } from "@excalidraw/common/utility-types";
|
||||||
import type { ResolvablePromise } from "@excalidraw/common/utils";
|
import type { ResolvablePromise } from "@excalidraw/common/utils";
|
||||||
|
|
||||||
import "./record";
|
|
||||||
import CustomStats from "./CustomStats";
|
import CustomStats from "./CustomStats";
|
||||||
import {
|
import {
|
||||||
Provider,
|
Provider,
|
||||||
@@ -472,6 +472,276 @@ const ExcalidrawWrapper = () => {
|
|||||||
|
|
||||||
initializeScene({ collabAPI, excalidrawAPI }).then(async (data) => {
|
initializeScene({ collabAPI, excalidrawAPI }).then(async (data) => {
|
||||||
loadImages(data, /* isInitialLoad */ true);
|
loadImages(data, /* isInitialLoad */ true);
|
||||||
|
if (data.scene) {
|
||||||
|
data.scene.elements = data.scene.elements?.length
|
||||||
|
? data.scene.elements
|
||||||
|
: convertToExcalidrawElements([
|
||||||
|
{
|
||||||
|
id: "MyWwgGwbjyZoxKSa2pfBI",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 43.5,
|
||||||
|
y: 52.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#ff8787",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 246249428,
|
||||||
|
version: 427,
|
||||||
|
versionNonce: 2079096276,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ABor4pClpJJs6adQb4iqs",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 357.5,
|
||||||
|
y: 481.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#b2f2bb",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 1800887636,
|
||||||
|
version: 445,
|
||||||
|
versionNonce: 650486612,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "-FGknlZxdFGYZNoUr2lG5",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 1280.5,
|
||||||
|
y: 47.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#69db7c",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 883462868,
|
||||||
|
version: 532,
|
||||||
|
versionNonce: 912136404,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "XQ3bRtQnS_ydtq13c_p99",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 863.5,
|
||||||
|
y: 334.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#a5d8ff",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 2033653844,
|
||||||
|
version: 459,
|
||||||
|
versionNonce: 1984683604,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "GmC3zgvVq3xUd2Qn0cNX3",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 897.5,
|
||||||
|
y: 697.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#ffec99",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 81325524,
|
||||||
|
version: 488,
|
||||||
|
versionNonce: 1332016084,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "8nvmvwbmFmNAcLAmwZryR",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 456.5,
|
||||||
|
y: 229.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#eebefa",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 950276948,
|
||||||
|
version: 649,
|
||||||
|
versionNonce: 532633940,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "7dyXEvhPDLA0-e3XCaM2H",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 1446.5,
|
||||||
|
y: 609.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#d0bfff",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 1659799764,
|
||||||
|
version: 570,
|
||||||
|
versionNonce: 313593556,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "gJubXeAjkEAr6yywtiZ0T",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 1182.5,
|
||||||
|
y: 800.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#96f2d7",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 391007828,
|
||||||
|
version: 563,
|
||||||
|
versionNonce: 2026902612,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "pSB2Izj9osR_XxVCzyVnD",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 1477.5,
|
||||||
|
y: 295.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#9775fa",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 110715860,
|
||||||
|
version: 590,
|
||||||
|
versionNonce: 535980500,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "yc7IKdtbnjLRaxJI5_q7m",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 696.5,
|
||||||
|
y: 21.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#4dabf7",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 1457899860,
|
||||||
|
version: 587,
|
||||||
|
versionNonce: 724438868,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "7KjY1vcMQm_i_i05wowTC",
|
||||||
|
type: "rectangle",
|
||||||
|
x: 447.5,
|
||||||
|
y: 771.5,
|
||||||
|
width: 357,
|
||||||
|
height: 280,
|
||||||
|
strokeColor: "transparent",
|
||||||
|
backgroundColor: "#ffc9c9",
|
||||||
|
fillStyle: "solid",
|
||||||
|
strokeWidth: 2,
|
||||||
|
strokeStyle: "solid",
|
||||||
|
roughness: 1,
|
||||||
|
opacity: 100,
|
||||||
|
groupIds: [],
|
||||||
|
frameId: null,
|
||||||
|
roundness: { type: 3 },
|
||||||
|
seed: 2072608468,
|
||||||
|
version: 610,
|
||||||
|
versionNonce: 1792607444,
|
||||||
|
boundElements: [],
|
||||||
|
link: null,
|
||||||
|
locked: false,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
initialStatePromiseRef.current.promise.resolve(data.scene);
|
initialStatePromiseRef.current.promise.resolve(data.scene);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
} from "@excalidraw/excalidraw/renderer/helpers";
|
} from "@excalidraw/excalidraw/renderer/helpers";
|
||||||
import { type AppState } from "@excalidraw/excalidraw/types";
|
import { type AppState } from "@excalidraw/excalidraw/types";
|
||||||
import { throttleRAF } from "@excalidraw/common";
|
import { throttleRAF } from "@excalidraw/common";
|
||||||
import { useCallback } from "react";
|
import { useCallback, useImperativeHandle, useRef } from "react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isLineSegment,
|
isLineSegment,
|
||||||
@@ -18,12 +18,10 @@ import {
|
|||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
import { isCurve } from "@excalidraw/math/curve";
|
import { isCurve } from "@excalidraw/math/curve";
|
||||||
|
|
||||||
import React from "react";
|
import type { DebugElement } from "@excalidraw/excalidraw/visualdebug";
|
||||||
|
|
||||||
import type { Curve } from "@excalidraw/math";
|
import type { Curve } from "@excalidraw/math";
|
||||||
|
|
||||||
import type { DebugElement } from "@excalidraw/utils/visualdebug";
|
|
||||||
|
|
||||||
import { STORAGE_KEYS } from "../app_constants";
|
import { STORAGE_KEYS } from "../app_constants";
|
||||||
|
|
||||||
const renderLine = (
|
const renderLine = (
|
||||||
@@ -115,6 +113,10 @@ const _debugRenderer = (
|
|||||||
scale,
|
scale,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (appState.height !== canvas.height || appState.width !== canvas.width) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
const context = bootstrapCanvas({
|
const context = bootstrapCanvas({
|
||||||
canvas,
|
canvas,
|
||||||
scale,
|
scale,
|
||||||
@@ -312,29 +314,35 @@ export const DebugFooter = ({ onChange }: { onChange: () => void }) => {
|
|||||||
interface DebugCanvasProps {
|
interface DebugCanvasProps {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
scale: number;
|
scale: number;
|
||||||
|
ref?: React.Ref<HTMLCanvasElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DebugCanvas = React.forwardRef<HTMLCanvasElement, DebugCanvasProps>(
|
const DebugCanvas = ({ appState, scale, ref }: DebugCanvasProps) => {
|
||||||
({ appState, scale }, ref) => {
|
const { width, height } = appState;
|
||||||
const { width, height } = appState;
|
|
||||||
|
|
||||||
return (
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
<canvas
|
useImperativeHandle<HTMLCanvasElement | null, HTMLCanvasElement | null>(
|
||||||
style={{
|
ref,
|
||||||
width,
|
() => canvasRef.current,
|
||||||
height,
|
[canvasRef],
|
||||||
position: "absolute",
|
);
|
||||||
zIndex: 2,
|
|
||||||
pointerEvents: "none",
|
return (
|
||||||
}}
|
<canvas
|
||||||
width={width * scale}
|
style={{
|
||||||
height={height * scale}
|
width,
|
||||||
ref={ref}
|
height,
|
||||||
>
|
position: "absolute",
|
||||||
Debug Canvas
|
zIndex: 2,
|
||||||
</canvas>
|
pointerEvents: "none",
|
||||||
);
|
}}
|
||||||
},
|
width={width * scale}
|
||||||
);
|
height={height * scale}
|
||||||
|
ref={canvasRef}
|
||||||
|
>
|
||||||
|
Debug Canvas
|
||||||
|
</canvas>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default DebugCanvas;
|
export default DebugCanvas;
|
||||||
|
|||||||
@@ -259,9 +259,7 @@ export const loadFromFirebase = async (
|
|||||||
}
|
}
|
||||||
const storedScene = docSnap.data() as FirebaseStoredScene;
|
const storedScene = docSnap.data() as FirebaseStoredScene;
|
||||||
const elements = getSyncableElements(
|
const elements = getSyncableElements(
|
||||||
restoreElements(await decryptElements(storedScene, roomKey), null, {
|
restoreElements(await decryptElements(storedScene, roomKey), null),
|
||||||
deleteInvisibleElements: true,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (socket) {
|
if (socket) {
|
||||||
|
|||||||
@@ -258,16 +258,11 @@ export const loadScene = async (
|
|||||||
await importFromBackend(id, privateKey),
|
await importFromBackend(id, privateKey),
|
||||||
localDataState?.appState,
|
localDataState?.appState,
|
||||||
localDataState?.elements,
|
localDataState?.elements,
|
||||||
{
|
{ repairBindings: true, refreshDimensions: false },
|
||||||
repairBindings: true,
|
|
||||||
refreshDimensions: false,
|
|
||||||
deleteInvisibleElements: true,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
data = restore(localDataState || null, null, null, {
|
data = restore(localDataState || null, null, null, {
|
||||||
repairBindings: true,
|
repairBindings: true,
|
||||||
deleteInvisibleElements: true,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>
|
<title>Excalidraw | Hand-drawn look & feel • Collaborative • Secure</title>
|
||||||
Free, collaborative whiteboard • Hand-drawn look & feel | Excalidraw
|
|
||||||
</title>
|
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no"
|
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no"
|
||||||
@@ -16,7 +14,7 @@
|
|||||||
<!-- Primary Meta Tags -->
|
<!-- Primary Meta Tags -->
|
||||||
<meta
|
<meta
|
||||||
name="title"
|
name="title"
|
||||||
content="Free, collaborative whiteboard • Hand-drawn look & feel | Excalidraw"
|
content="Excalidraw — Collaborative whiteboarding made easy"
|
||||||
/>
|
/>
|
||||||
<meta
|
<meta
|
||||||
name="description"
|
name="description"
|
||||||
|
|||||||
@@ -46,7 +46,6 @@
|
|||||||
"build:version": "node ../scripts/build-version.js",
|
"build:version": "node ../scripts/build-version.js",
|
||||||
"build": "yarn build:app && yarn build:version",
|
"build": "yarn build:app && yarn build:version",
|
||||||
"start": "yarn && vite",
|
"start": "yarn && vite",
|
||||||
"start:test": "yarn && vite --mode test",
|
|
||||||
"start:production": "yarn build && yarn serve",
|
"start:production": "yarn build && yarn serve",
|
||||||
"serve": "npx http-server build -a localhost -p 5001 -o",
|
"serve": "npx http-server build -a localhost -p 5001 -o",
|
||||||
"build:preview": "yarn build && vite preview --port 5000"
|
"build:preview": "yarn build && vite preview --port 5000"
|
||||||
|
|||||||
@@ -1,270 +0,0 @@
|
|||||||
import { isDevEnv } from "@excalidraw/common";
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface Window {
|
|
||||||
record: typeof Record;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Record {
|
|
||||||
private static recording: boolean = false;
|
|
||||||
private static events: string = "";
|
|
||||||
private static timestamp: number = 0;
|
|
||||||
|
|
||||||
public static get isRecording() {
|
|
||||||
return Record.recording;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static header() {
|
|
||||||
Record.events += " await page.addInitScript(() => {\n";
|
|
||||||
Record.events += " Math.random = () => 0.42;\n\n";
|
|
||||||
|
|
||||||
// Capture LocalStorage, which is essential to re-establish state
|
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
|
||||||
const key = localStorage.key(i);
|
|
||||||
if (key != null) {
|
|
||||||
const value = JSON.stringify(localStorage.getItem(key));
|
|
||||||
Record.events += ` localStorage.getItem("${key}");\n`;
|
|
||||||
Record.events += ` localStorage.setItem("${key}", ${value});\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Record.events += " });\n";
|
|
||||||
Record.events += ` await page.setViewportSize({ width: ${window.innerWidth}, height: ${window.innerHeight} });\n`;
|
|
||||||
Record.events += ` await page.goto("http://localhost:3000");\n`;
|
|
||||||
Record.events += ` await page.waitForLoadState("load");\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static restart() {
|
|
||||||
if (!Record.recording) {
|
|
||||||
Record.start();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Record.events += `});\n\n`;
|
|
||||||
Record.events += `test("${
|
|
||||||
Date.now() + Math.floor(Math.random() * Date.now()).toString(36)
|
|
||||||
}", async ({ page }) => {\n`;
|
|
||||||
|
|
||||||
Record.header();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static start() {
|
|
||||||
Record.recording = true;
|
|
||||||
|
|
||||||
// Record header
|
|
||||||
this.header();
|
|
||||||
|
|
||||||
// Set up the events
|
|
||||||
Record.timestamp = performance.now();
|
|
||||||
|
|
||||||
window.addEventListener("mousemove", this.onMouseMove);
|
|
||||||
window.addEventListener("mousedown", this.onMouseDown);
|
|
||||||
window.addEventListener("mouseup", this.onMouseUp);
|
|
||||||
window.addEventListener("keydown", this.onKeyDown);
|
|
||||||
window.addEventListener("keyup", this.onKeyUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static stop() {
|
|
||||||
window.removeEventListener("mousemove", this.onMouseMove);
|
|
||||||
window.removeEventListener("mousedown", this.onMouseDown);
|
|
||||||
window.removeEventListener("mouseup", this.onMouseUp);
|
|
||||||
window.removeEventListener("keydown", this.onKeyDown);
|
|
||||||
window.removeEventListener("keyup", this.onKeyUp);
|
|
||||||
Record.recording = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Displays a window as an absolutely positioned DIV with the generated
|
|
||||||
/// events within <pre> tags as formatted JSON, so it can be copied easily.
|
|
||||||
public static showGeneratedEvents() {
|
|
||||||
if (Record.recording) {
|
|
||||||
Record.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
const div = document.createElement("div");
|
|
||||||
div.style.position = "absolute";
|
|
||||||
div.style.top = "10px";
|
|
||||||
div.style.right = "10px";
|
|
||||||
div.style.left = "10px";
|
|
||||||
div.style.height = "60vh";
|
|
||||||
div.style.backgroundColor = "gray";
|
|
||||||
div.style.padding = "10px";
|
|
||||||
div.style.zIndex = "10000";
|
|
||||||
|
|
||||||
const pre = document.createElement("pre");
|
|
||||||
|
|
||||||
let textContent = `import { expect, test } from "@playwright/test";\n\n`;
|
|
||||||
textContent += `test("${
|
|
||||||
Date.now() + Math.floor(Math.random() * Date.now()).toString(36)
|
|
||||||
}", async ({ page }) => {\n`;
|
|
||||||
textContent += Record.events;
|
|
||||||
textContent += `});\n`;
|
|
||||||
|
|
||||||
pre.textContent = textContent;
|
|
||||||
//pre.textContent = Record.events;
|
|
||||||
|
|
||||||
pre.style.marginTop = "18px";
|
|
||||||
pre.style.maxHeight = "60vh";
|
|
||||||
pre.style.overflow = "auto";
|
|
||||||
div.appendChild(pre);
|
|
||||||
|
|
||||||
const copyBtn = document.createElement("button");
|
|
||||||
copyBtn.textContent = "Copy";
|
|
||||||
copyBtn.title = "Copy generated events to clipboard";
|
|
||||||
copyBtn.setAttribute("aria-label", "Copy generated events to clipboard");
|
|
||||||
copyBtn.style.position = "absolute";
|
|
||||||
copyBtn.style.top = "4px";
|
|
||||||
copyBtn.style.left = "4px";
|
|
||||||
copyBtn.style.border = "none";
|
|
||||||
copyBtn.style.background = "transparent";
|
|
||||||
copyBtn.style.fontSize = "12px";
|
|
||||||
copyBtn.style.lineHeight = "1";
|
|
||||||
copyBtn.style.cursor = "pointer";
|
|
||||||
copyBtn.style.padding = "4px 8px";
|
|
||||||
copyBtn.addEventListener("click", async () => {
|
|
||||||
const text = pre.textContent ?? "";
|
|
||||||
try {
|
|
||||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
||||||
await navigator.clipboard.writeText(text);
|
|
||||||
} else {
|
|
||||||
const ta = document.createElement("textarea");
|
|
||||||
ta.value = text;
|
|
||||||
document.body.appendChild(ta);
|
|
||||||
ta.select();
|
|
||||||
document.execCommand("copy");
|
|
||||||
document.body.removeChild(ta);
|
|
||||||
}
|
|
||||||
const orig = copyBtn.textContent;
|
|
||||||
copyBtn.textContent = "Copied";
|
|
||||||
setTimeout(() => (copyBtn.textContent = orig), 1000);
|
|
||||||
} catch {}
|
|
||||||
});
|
|
||||||
div.appendChild(copyBtn);
|
|
||||||
|
|
||||||
const closeBtn = document.createElement("button");
|
|
||||||
closeBtn.textContent = "×";
|
|
||||||
closeBtn.title = "Close";
|
|
||||||
closeBtn.style.position = "absolute";
|
|
||||||
closeBtn.style.top = "4px";
|
|
||||||
closeBtn.style.right = "4px";
|
|
||||||
closeBtn.style.border = "none";
|
|
||||||
closeBtn.style.background = "transparent";
|
|
||||||
closeBtn.style.fontSize = "18px";
|
|
||||||
closeBtn.style.lineHeight = "1";
|
|
||||||
closeBtn.style.cursor = "pointer";
|
|
||||||
closeBtn.addEventListener("click", () => {
|
|
||||||
// remove the dialog from DOM
|
|
||||||
if (div.parentNode) {
|
|
||||||
div.parentNode.removeChild(div);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
div.appendChild(closeBtn);
|
|
||||||
|
|
||||||
document.body.appendChild(div);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static onMouseMove(event: MouseEvent) {
|
|
||||||
if (
|
|
||||||
event.clientX < 0 ||
|
|
||||||
event.clientX > window.innerWidth ||
|
|
||||||
event.clientY < 0 ||
|
|
||||||
event.clientY > window.innerHeight
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const now = event.timeStamp || performance.now();
|
|
||||||
const delay = now - Record.timestamp;
|
|
||||||
Record.timestamp = now;
|
|
||||||
|
|
||||||
if (delay > 0) {
|
|
||||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
|
||||||
}
|
|
||||||
Record.events += ` await page.mouse.move(${event.clientX}, ${event.clientY});\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static onMouseDown(event: MouseEvent) {
|
|
||||||
const now = event.timeStamp || performance.now();
|
|
||||||
const delay = now - Record.timestamp;
|
|
||||||
Record.timestamp = now;
|
|
||||||
|
|
||||||
if (delay > 0) {
|
|
||||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
|
||||||
}
|
|
||||||
const button =
|
|
||||||
event.button === 0 ? "left" : event.button === 1 ? "middle" : "right";
|
|
||||||
Record.events += ` await page.mouse.down({ button: "${button}" });\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static onMouseUp(event: MouseEvent) {
|
|
||||||
const now = event.timeStamp || performance.now();
|
|
||||||
const delay = now - Record.timestamp;
|
|
||||||
Record.timestamp = now;
|
|
||||||
|
|
||||||
if (delay > 0) {
|
|
||||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
|
||||||
}
|
|
||||||
const button =
|
|
||||||
event.button === 0 ? "left" : event.button === 1 ? "middle" : "right";
|
|
||||||
Record.events += ` await page.mouse.up({ button: "${button}" });\n`;
|
|
||||||
|
|
||||||
Record.events += " await expect(page).toHaveScreenshot({\n";
|
|
||||||
Record.events += " maxDiffPixels: 100,\n";
|
|
||||||
Record.events += " maxDiffPixelRatio: 0.01,\n";
|
|
||||||
Record.events += " });\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static onKeyDown(event: KeyboardEvent) {
|
|
||||||
// Only record if the recording key is not pressed
|
|
||||||
if (event.key !== "F2") {
|
|
||||||
const now = event.timeStamp || performance.now();
|
|
||||||
const delay = now - Record.timestamp;
|
|
||||||
Record.timestamp = now;
|
|
||||||
|
|
||||||
if (delay > 0) {
|
|
||||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
|
||||||
}
|
|
||||||
Record.events += ` await page.keyboard.down("${event.key}");\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static onKeyUp(event: KeyboardEvent) {
|
|
||||||
// Only record if the recording key is not pressed
|
|
||||||
if (event.key !== "F2") {
|
|
||||||
const now = event.timeStamp || performance.now();
|
|
||||||
const delay = now - Record.timestamp;
|
|
||||||
Record.timestamp = now;
|
|
||||||
|
|
||||||
if (delay > 0) {
|
|
||||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
|
||||||
}
|
|
||||||
Record.events += ` await page.keyboard.up("${event.key}");\n`;
|
|
||||||
|
|
||||||
Record.events += " await expect(page).toHaveScreenshot({\n";
|
|
||||||
Record.events += " maxDiffPixels: 100,\n";
|
|
||||||
Record.events += " maxDiffPixelRatio: 0.01,\n";
|
|
||||||
Record.events += " });\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDevEnv()) {
|
|
||||||
window.record = Record;
|
|
||||||
|
|
||||||
window.addEventListener("keyup", (event) => {
|
|
||||||
if (event.key === "F2") {
|
|
||||||
if (Record.isRecording) {
|
|
||||||
if (event.ctrlKey) {
|
|
||||||
console.info("Stopping Playwright recording");
|
|
||||||
Record.stop();
|
|
||||||
} else {
|
|
||||||
Record.restart();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.info("Starting Playwright recording");
|
|
||||||
Record.start();
|
|
||||||
}
|
|
||||||
} else if (event.key === "Enter" && event.ctrlKey) {
|
|
||||||
Record.showGeneratedEvents();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,716 +0,0 @@
|
|||||||
import { expect, test } from "@playwright/test";
|
|
||||||
|
|
||||||
test("17562123239901g67cqde", async ({ page }) => {
|
|
||||||
await page.addInitScript(() => {
|
|
||||||
Math.random = () => 0.42;
|
|
||||||
|
|
||||||
localStorage.getItem("i18nextLng");
|
|
||||||
localStorage.setItem("i18nextLng", "en");
|
|
||||||
localStorage.getItem("excalidraw-collab");
|
|
||||||
localStorage.setItem("excalidraw-collab", '{"username":""}');
|
|
||||||
localStorage.getItem("excalidraw-debug");
|
|
||||||
localStorage.setItem("excalidraw-debug", '{"enabled":true}');
|
|
||||||
localStorage.getItem("excalidraw-theme");
|
|
||||||
localStorage.setItem("excalidraw-theme", "dark");
|
|
||||||
localStorage.getItem("version-files");
|
|
||||||
localStorage.setItem("version-files", "1756212319038");
|
|
||||||
localStorage.getItem("version-dataState");
|
|
||||||
localStorage.setItem("version-dataState", "1756212319038");
|
|
||||||
localStorage.getItem("excalidraw-state");
|
|
||||||
localStorage.setItem(
|
|
||||||
"excalidraw-state",
|
|
||||||
'{"showWelcomeScreen":true,"theme":"dark","currentChartType":"bar","currentItemBackgroundColor":"#a5d8ff","currentItemEndArrowhead":"arrow","currentItemFillStyle":"solid","currentItemFontFamily":5,"currentItemFontSize":20,"currentItemOpacity":100,"currentItemRoughness":2,"currentItemStartArrowhead":null,"currentItemStrokeColor":"#1e1e1e","currentItemRoundness":"round","currentItemArrowType":"round","currentItemStrokeStyle":"solid","currentItemStrokeWidth":2,"currentItemTextAlign":"left","cursorButton":"up","editingGroupId":null,"activeTool":{"type":"arrow","customType":null,"locked":false,"fromSelection":false,"lastActiveTool":null},"penMode":false,"penDetected":false,"exportBackground":true,"exportScale":1,"exportEmbedScene":false,"exportWithDarkMode":false,"gridSize":20,"gridStep":5,"gridModeEnabled":false,"defaultSidebarDockedPreference":false,"lastPointerDownWith":"mouse","name":"Untitled-2025-07-28-1603","openMenu":null,"openSidebar":null,"previousSelectedElementIds":{},"scrolledOutside":false,"scrollX":688.1079394457738,"scrollY":349.585883261872,"selectedElementIds":{},"selectedGroupIds":{},"shouldCacheIgnoreZoom":false,"stats":{"open":true,"panels":3},"viewBackgroundColor":"#ffffff","zenModeEnabled":false,"zoom":{"value":1.331666},"selectedLinearElement":null,"objectsSnapModeEnabled":false,"lockedMultiSelections":{}}',
|
|
||||||
);
|
|
||||||
localStorage.getItem("excalidraw");
|
|
||||||
localStorage.setItem(
|
|
||||||
"excalidraw",
|
|
||||||
'[{"id":"hJuTw4QcwTsFtadNNnkLj","type":"rectangle","x":-100,"y":-100,"width":200,"height":200,"angle":0,"strokeColor":"#1e1e1e","backgroundColor":"#a5d8ff","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":1,"opacity":100,"groupIds":[],"frameId":null,"index":"a1","roundness":{"type":3},"seed":43277494,"version":839,"versionNonce":1923298088,"isDeleted":false,"boundElements":[{"id":"0xSZCPMN8RzKiJOpvGaKB","type":"arrow"}],"updated":1756212298830,"link":null,"locked":false},{"id":"qXw5KqKvAjHRr5uwPi9B-","type":"rectangle","x":-523.1841597523046,"y":-129.52451989693097,"width":200,"height":200,"angle":0,"strokeColor":"#1e1e1e","backgroundColor":"#a5d8ff","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":1,"opacity":100,"groupIds":[],"frameId":null,"index":"a2","roundness":{"type":3},"seed":392633439,"version":963,"versionNonce":210394408,"isDeleted":false,"boundElements":[{"id":"0xSZCPMN8RzKiJOpvGaKB","type":"arrow"}],"updated":1756212298830,"link":null,"locked":false}]',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
await page.setViewportSize({ width: 1280, height: 1001 });
|
|
||||||
await page.goto("http://localhost:3000");
|
|
||||||
await page.waitForLoadState("load");
|
|
||||||
await page.waitForTimeout(3.599999999627471);
|
|
||||||
await page.mouse.move(425, 390);
|
|
||||||
await page.waitForTimeout(9.900000000372529);
|
|
||||||
await page.mouse.move(424, 390);
|
|
||||||
await page.waitForTimeout(51.09999999962747);
|
|
||||||
await page.mouse.move(423, 390);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(423, 392);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(422, 392);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(420, 393);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(420, 395);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(418, 395);
|
|
||||||
await page.waitForTimeout(6);
|
|
||||||
await page.mouse.move(417, 396);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(416, 396);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(416, 397);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(414, 397);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(414, 399);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(413, 399);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(413, 401);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(413, 402);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(411, 402);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(411, 403);
|
|
||||||
await page.waitForTimeout(32);
|
|
||||||
await page.mouse.move(412, 403);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(412, 403);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(412, 402);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(413, 402);
|
|
||||||
await page.waitForTimeout(0.900000000372529);
|
|
||||||
await page.mouse.move(413, 400);
|
|
||||||
await page.waitForTimeout(1.099999999627471);
|
|
||||||
await page.mouse.move(415, 400);
|
|
||||||
await page.waitForTimeout(7);
|
|
||||||
await page.mouse.move(416, 400);
|
|
||||||
await page.waitForTimeout(71);
|
|
||||||
await page.mouse.move(417, 400);
|
|
||||||
await page.waitForTimeout(450);
|
|
||||||
await page.mouse.move(417, 399);
|
|
||||||
await page.waitForTimeout(6);
|
|
||||||
await page.mouse.move(418, 399);
|
|
||||||
await page.waitForTimeout(6.1000000005587935);
|
|
||||||
await page.mouse.move(419, 399);
|
|
||||||
await page.mouse.down({ button: "left" });
|
|
||||||
await page.waitForTimeout(11.899999999441206);
|
|
||||||
await page.mouse.move(420, 399);
|
|
||||||
await page.waitForTimeout(69);
|
|
||||||
await page.mouse.move(421, 399);
|
|
||||||
await page.waitForTimeout(13);
|
|
||||||
await page.mouse.move(422, 399);
|
|
||||||
await page.waitForTimeout(7.1000000005587935);
|
|
||||||
await page.mouse.move(423, 399);
|
|
||||||
await page.waitForTimeout(5.3999999994412065);
|
|
||||||
await page.mouse.move(425, 399);
|
|
||||||
await page.waitForTimeout(0.5);
|
|
||||||
await page.mouse.move(427, 401);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(428, 401);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(428, 403);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(430, 403);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(432, 403);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(432, 404);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(433, 404);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(434, 404);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(436, 406);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(437, 406);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(438, 407);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(440, 407);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(442, 407);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(443, 409);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(445, 409);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(447, 411);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(451, 411);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(455, 411);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(457, 413);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(459, 413);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(461, 415);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(463, 417);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(467, 419);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(469, 419);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(471, 420);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(473, 424);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(477, 424);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(477, 426);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(478, 426);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(482, 428);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(484, 430);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(486, 430);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(488, 430);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(488, 432);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(489, 432);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(491, 432);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(493, 434);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(495, 434);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(499, 436);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(501, 436);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(502, 436);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(504, 438);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(506, 440);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(508, 440);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(510, 442);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(512, 444);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(514, 444);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(514, 445);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(515, 445);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(517, 445);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(517, 447);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(519, 448);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(521, 448);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(522, 450);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(524, 450);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(525, 450);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(527, 450);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(529, 450);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(530, 450);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(532, 450);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(533, 451);
|
|
||||||
await page.waitForTimeout(6);
|
|
||||||
await page.mouse.move(534, 451);
|
|
||||||
await page.waitForTimeout(3.1000000005587935);
|
|
||||||
await page.mouse.move(535, 451);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(535, 453);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(537, 453);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(538, 453);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(540, 453);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(540, 454);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(541, 454);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(542, 454);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(543, 454);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(544, 454);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(544, 455);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(546, 455);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(547, 455);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(548, 455);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(549, 455);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(551, 455);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(552, 455);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(554, 455);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(555, 455);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(557, 455);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(559, 457);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(560, 457);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(562, 459);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(564, 459);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(566, 459);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(567, 459);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(569, 459);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(570, 459);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(574, 460);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(575, 460);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(575, 462);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(577, 464);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(578, 464);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(580, 464);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(582, 465);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(584, 465);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(585, 465);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(586, 465);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(588, 467);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(590, 467);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(591, 467);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(591, 468);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(594, 468);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(595, 468);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(597, 468);
|
|
||||||
await page.waitForTimeout(2.7000000001862645);
|
|
||||||
await page.mouse.move(601, 470);
|
|
||||||
await page.waitForTimeout(1.400000000372529);
|
|
||||||
await page.mouse.move(602, 470);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(603, 470);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(605, 470);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(607, 470);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(608, 470);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(610, 470);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(612, 470);
|
|
||||||
await page.waitForTimeout(2.8999999994412065);
|
|
||||||
await page.mouse.move(613, 470);
|
|
||||||
await page.waitForTimeout(1.2000000001862645);
|
|
||||||
await page.mouse.move(613, 471);
|
|
||||||
await page.waitForTimeout(1.7999999998137355);
|
|
||||||
await page.mouse.move(614, 471);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(616, 473);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(618, 473);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(621, 473);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(623, 473);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(625, 473);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(626, 473);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(628, 473);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(629, 473);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(631, 473);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(634, 475);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(636, 475);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(638, 475);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(639, 475);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(640, 475);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(642, 475);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(644, 475);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(647, 475);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(649, 475);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(650, 475);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(652, 475);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(653, 475);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(655, 475);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(656, 476);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(658, 476);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(659, 476);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(660, 476);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(662, 476);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(663, 476);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(664, 476);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(666, 474);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(668, 474);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(670, 474);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(671, 474);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(673, 476);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(675, 476);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(678, 476);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(680, 476);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(682, 476);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(683, 476);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(684, 476);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(686, 476);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(690, 476);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(694, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(696, 478);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(698, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(699, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(703, 478);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(705, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(707, 478);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(708, 478);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(711, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(713, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(714, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(716, 478);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(717, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(719, 478);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(722, 478);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(724, 478);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(725, 478);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(726, 478);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(727, 478);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(733, 480);
|
|
||||||
await page.waitForTimeout(2.8999999994412065);
|
|
||||||
await page.mouse.move(734, 480);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(735, 480);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(737, 480);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(739, 480);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(740, 480);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(742, 480);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(744, 480);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(744, 482);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(745, 482);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(747, 482);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(748, 482);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(749, 482);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(751, 482);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(753, 482);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(755, 482);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(758, 482);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(760, 482);
|
|
||||||
await page.waitForTimeout(6);
|
|
||||||
await page.mouse.move(761, 483);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(763, 484);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(765, 484);
|
|
||||||
await page.waitForTimeout(2.8999999994412065);
|
|
||||||
await page.mouse.move(766, 485);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(767, 485);
|
|
||||||
await page.waitForTimeout(11);
|
|
||||||
await page.mouse.move(768, 485);
|
|
||||||
await page.waitForTimeout(12.100000000558794);
|
|
||||||
await page.mouse.move(769, 485);
|
|
||||||
await page.waitForTimeout(51.89999999944121);
|
|
||||||
await page.mouse.move(770, 485);
|
|
||||||
await page.waitForTimeout(9);
|
|
||||||
await page.mouse.move(771, 485);
|
|
||||||
await page.waitForTimeout(3.1000000005587935);
|
|
||||||
await page.mouse.move(772, 485);
|
|
||||||
await page.waitForTimeout(5);
|
|
||||||
await page.mouse.move(773, 485);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(774, 485);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(776, 487);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(777, 487);
|
|
||||||
await page.waitForTimeout(4.1000000005587935);
|
|
||||||
await page.mouse.move(778, 487);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(779, 487);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(780, 488);
|
|
||||||
await page.waitForTimeout(2.8999999994412065);
|
|
||||||
await page.mouse.move(781, 488);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(782, 488);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(784, 488);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(785, 488);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(786, 488);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(788, 488);
|
|
||||||
await page.waitForTimeout(8.899999999441206);
|
|
||||||
await page.mouse.move(789, 488);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(790, 488);
|
|
||||||
await page.waitForTimeout(5);
|
|
||||||
await page.mouse.move(791, 488);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(792, 488);
|
|
||||||
await page.waitForTimeout(6.1000000005587935);
|
|
||||||
await page.mouse.move(793, 488);
|
|
||||||
await page.waitForTimeout(3.8999999994412065);
|
|
||||||
await page.mouse.move(793, 489);
|
|
||||||
await page.waitForTimeout(6);
|
|
||||||
await page.mouse.move(794, 489);
|
|
||||||
await page.waitForTimeout(4.1000000005587935);
|
|
||||||
await page.mouse.move(795, 489);
|
|
||||||
await page.waitForTimeout(7.599999999627471);
|
|
||||||
await page.mouse.move(796, 489);
|
|
||||||
await page.waitForTimeout(3.400000000372529);
|
|
||||||
await page.mouse.move(797, 489);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(798, 489);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(799, 489);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(800, 489);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(801, 489);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(802, 489);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(803, 489);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(804, 489);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(805, 489);
|
|
||||||
await page.waitForTimeout(5.8999999994412065);
|
|
||||||
await page.mouse.move(806, 490);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(807, 490);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(809, 490);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(810, 490);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(812, 490);
|
|
||||||
await page.waitForTimeout(1.8999999994412065);
|
|
||||||
await page.mouse.move(813, 490);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(815, 490);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(816, 492);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(818, 492);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(819, 492);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(820, 492);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(822, 492);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(823, 492);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(825, 492);
|
|
||||||
await page.waitForTimeout(2.8999999994412065);
|
|
||||||
await page.mouse.move(826, 492);
|
|
||||||
await page.waitForTimeout(1.1000000005587935);
|
|
||||||
await page.mouse.move(827, 492);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(828, 492);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(830, 492);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(831, 492);
|
|
||||||
await page.waitForTimeout(2.1000000005587935);
|
|
||||||
await page.mouse.move(832, 492);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(833, 493);
|
|
||||||
await page.waitForTimeout(6.1000000005587935);
|
|
||||||
await page.mouse.move(835, 493);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(836, 493);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(838, 493);
|
|
||||||
await page.waitForTimeout(0.8999999994412065);
|
|
||||||
await page.mouse.move(839, 493);
|
|
||||||
await page.waitForTimeout(4.1000000005587935);
|
|
||||||
await page.mouse.move(841, 493);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(842, 493);
|
|
||||||
await page.waitForTimeout(3.8999999994412065);
|
|
||||||
await page.mouse.move(843, 493);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(843, 492);
|
|
||||||
await page.waitForTimeout(4.1000000005587935);
|
|
||||||
await page.mouse.move(844, 492);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(844, 493);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(845, 493);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(846, 493);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(847, 494);
|
|
||||||
await page.waitForTimeout(24.899999999441206);
|
|
||||||
await page.mouse.move(847, 495);
|
|
||||||
await page.waitForTimeout(29.100000000558794);
|
|
||||||
await page.mouse.move(848, 495);
|
|
||||||
await page.waitForTimeout(297.8999999994412);
|
|
||||||
await page.mouse.move(848, 495);
|
|
||||||
await page.waitForTimeout(5.7000000001862645);
|
|
||||||
await page.mouse.up({ button: "left" });
|
|
||||||
await expect(page).toHaveScreenshot({
|
|
||||||
maxDiffPixels: 100,
|
|
||||||
maxDiffPixelRatio: 0.01,
|
|
||||||
});
|
|
||||||
await page.waitForTimeout(11.299999999813735);
|
|
||||||
await page.mouse.move(847, 495);
|
|
||||||
await page.waitForTimeout(199.1000000005588);
|
|
||||||
await page.mouse.move(847, 495);
|
|
||||||
await page.waitForTimeout(249.29999999981374);
|
|
||||||
await page.mouse.move(846, 495);
|
|
||||||
await page.waitForTimeout(5.7000000001862645);
|
|
||||||
await page.mouse.move(846, 496);
|
|
||||||
await page.waitForTimeout(6);
|
|
||||||
await page.mouse.move(845, 496);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(845, 497);
|
|
||||||
await page.waitForTimeout(9);
|
|
||||||
await page.mouse.move(845, 498);
|
|
||||||
await page.waitForTimeout(3.8999999994412065);
|
|
||||||
await page.mouse.move(844, 498);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(844, 500);
|
|
||||||
await page.waitForTimeout(8);
|
|
||||||
await page.mouse.move(844, 501);
|
|
||||||
await page.waitForTimeout(3.1000000005587935);
|
|
||||||
await page.mouse.move(843, 501);
|
|
||||||
await page.waitForTimeout(137);
|
|
||||||
await page.mouse.move(844, 501);
|
|
||||||
await page.waitForTimeout(68.09999999962747);
|
|
||||||
await page.mouse.move(845, 501);
|
|
||||||
await page.waitForTimeout(7.7999999998137355);
|
|
||||||
await page.mouse.move(845, 500);
|
|
||||||
await page.waitForTimeout(1);
|
|
||||||
await page.mouse.move(846, 500);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(847, 500);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(848, 500);
|
|
||||||
await page.waitForTimeout(3.1000000005587935);
|
|
||||||
await page.mouse.move(849, 500);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(850, 500);
|
|
||||||
await page.waitForTimeout(5);
|
|
||||||
await page.mouse.move(851, 500);
|
|
||||||
await page.waitForTimeout(2);
|
|
||||||
await page.mouse.move(852, 499);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(854, 499);
|
|
||||||
await page.waitForTimeout(5);
|
|
||||||
await page.mouse.move(855, 499);
|
|
||||||
await page.waitForTimeout(3);
|
|
||||||
await page.mouse.move(856, 499);
|
|
||||||
await page.waitForTimeout(6);
|
|
||||||
await page.mouse.move(857, 499);
|
|
||||||
await page.waitForTimeout(12);
|
|
||||||
await page.mouse.move(858, 499);
|
|
||||||
await page.waitForTimeout(24);
|
|
||||||
await page.mouse.move(858, 498);
|
|
||||||
await page.waitForTimeout(4);
|
|
||||||
await page.mouse.move(858, 498);
|
|
||||||
await page.waitForTimeout(59.200000000186265);
|
|
||||||
await page.keyboard.down("Control");
|
|
||||||
});
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB |
+5
-13
@@ -11,11 +11,9 @@
|
|||||||
"@babel/preset-env": "7.26.9",
|
"@babel/preset-env": "7.26.9",
|
||||||
"@excalidraw/eslint-config": "1.0.3",
|
"@excalidraw/eslint-config": "1.0.3",
|
||||||
"@excalidraw/prettier-config": "1.0.2",
|
"@excalidraw/prettier-config": "1.0.2",
|
||||||
"@playwright/test": "1.55.0",
|
|
||||||
"@types/chai": "4.3.0",
|
"@types/chai": "4.3.0",
|
||||||
"@types/jest": "27.4.0",
|
"@types/jest": "27.4.0",
|
||||||
"@types/lodash.throttle": "4.1.7",
|
"@types/lodash.throttle": "4.1.7",
|
||||||
"@types/node": "24.3.0",
|
|
||||||
"@types/react": "19.0.10",
|
"@types/react": "19.0.10",
|
||||||
"@types/react-dom": "19.0.4",
|
"@types/react-dom": "19.0.4",
|
||||||
"@types/socket.io-client": "3.0.0",
|
"@types/socket.io-client": "3.0.0",
|
||||||
@@ -54,18 +52,13 @@
|
|||||||
"build-node": "node ./scripts/build-node.js",
|
"build-node": "node ./scripts/build-node.js",
|
||||||
"build:app:docker": "yarn --cwd ./excalidraw-app build:app:docker",
|
"build:app:docker": "yarn --cwd ./excalidraw-app build:app:docker",
|
||||||
"build:app": "yarn --cwd ./excalidraw-app build:app",
|
"build:app": "yarn --cwd ./excalidraw-app build:app",
|
||||||
"build:common": "yarn --cwd ./packages/common build:esm",
|
"build:package": "yarn --cwd ./packages/excalidraw build:esm",
|
||||||
"build:element": "yarn --cwd ./packages/element build:esm",
|
|
||||||
"build:excalidraw": "yarn --cwd ./packages/excalidraw build:esm",
|
|
||||||
"build:math": "yarn --cwd ./packages/math build:esm",
|
|
||||||
"build:packages": "yarn build:common && yarn build:math && yarn build:element && yarn build:excalidraw",
|
|
||||||
"build:version": "yarn --cwd ./excalidraw-app build:version",
|
"build:version": "yarn --cwd ./excalidraw-app build:version",
|
||||||
"build": "yarn --cwd ./excalidraw-app build",
|
"build": "yarn --cwd ./excalidraw-app build",
|
||||||
"build:preview": "yarn --cwd ./excalidraw-app build:preview",
|
"build:preview": "yarn --cwd ./excalidraw-app build:preview",
|
||||||
"start": "yarn --cwd ./excalidraw-app start",
|
"start": "yarn --cwd ./excalidraw-app start",
|
||||||
"start:production": "yarn --cwd ./excalidraw-app start:production",
|
"start:production": "yarn --cwd ./excalidraw-app start:production",
|
||||||
"start:test": "yarn --cwd ./excalidraw-app start:test",
|
"start:example": "yarn build:package && yarn --cwd ./examples/with-script-in-browser start",
|
||||||
"start:example": "yarn build:packages && yarn --cwd ./examples/with-script-in-browser start",
|
|
||||||
"test:all": "yarn test:typecheck && yarn test:code && yarn test:other && yarn test:app --watch=false",
|
"test:all": "yarn test:typecheck && yarn test:code && yarn test:other && yarn test:app --watch=false",
|
||||||
"test:app": "vitest",
|
"test:app": "vitest",
|
||||||
"test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .",
|
"test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .",
|
||||||
@@ -83,10 +76,9 @@
|
|||||||
"locales-coverage:description": "node scripts/locales-coverage-description.js",
|
"locales-coverage:description": "node scripts/locales-coverage-description.js",
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"prettier": "prettier \"**/*.{css,scss,json,md,html,yml}\" --ignore-path=.eslintignore",
|
"prettier": "prettier \"**/*.{css,scss,json,md,html,yml}\" --ignore-path=.eslintignore",
|
||||||
"release": "node scripts/release.js",
|
"autorelease": "node scripts/autorelease.js",
|
||||||
"release:test": "node scripts/release.js --tag=test",
|
"prerelease:excalidraw": "node scripts/prerelease.js",
|
||||||
"release:next": "node scripts/release.js --tag=next",
|
"release:excalidraw": "node scripts/release.js",
|
||||||
"release:latest": "node scripts/release.js --tag=latest",
|
|
||||||
"rm:build": "rimraf --glob excalidraw-app/build excalidraw-app/dist excalidraw-app/dev-dist packages/*/dist packages/*/build examples/*/build examples/*/dist",
|
"rm:build": "rimraf --glob excalidraw-app/build excalidraw-app/dist excalidraw-app/dev-dist packages/*/dist packages/*/build examples/*/build examples/*/dist",
|
||||||
"rm:node_modules": "rimraf --glob node_modules excalidraw-app/node_modules packages/*/node_modules",
|
"rm:node_modules": "rimraf --glob node_modules excalidraw-app/node_modules packages/*/node_modules",
|
||||||
"clean-install": "yarn rm:node_modules && yarn install"
|
"clean-install": "yarn rm:node_modules && yarn install"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@excalidraw/common",
|
"name": "@excalidraw/common",
|
||||||
"version": "0.18.0",
|
"version": "0.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./dist/types/common/src/index.d.ts",
|
"types": "./dist/types/common/src/index.d.ts",
|
||||||
"main": "./dist/prod/index.js",
|
"main": "./dist/prod/index.js",
|
||||||
@@ -13,10 +13,7 @@
|
|||||||
"default": "./dist/prod/index.js"
|
"default": "./dist/prod/index.js"
|
||||||
},
|
},
|
||||||
"./*": {
|
"./*": {
|
||||||
"types": "./dist/types/common/src/*.d.ts",
|
"types": "./dist/types/common/src/*.d.ts"
|
||||||
"development": "./dist/dev/index.js",
|
|
||||||
"production": "./dist/prod/index.js",
|
|
||||||
"default": "./dist/prod/index.js"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@@ -18,22 +18,13 @@ export const isChrome = navigator.userAgent.indexOf("Chrome") !== -1;
|
|||||||
export const isSafari =
|
export const isSafari =
|
||||||
!isChrome && navigator.userAgent.indexOf("Safari") !== -1;
|
!isChrome && navigator.userAgent.indexOf("Safari") !== -1;
|
||||||
export const isIOS =
|
export const isIOS =
|
||||||
/iPad|iPhone/i.test(navigator.platform) ||
|
/iPad|iPhone/.test(navigator.platform) ||
|
||||||
// iPadOS 13+
|
// iPadOS 13+
|
||||||
(navigator.userAgent.includes("Mac") && "ontouchend" in document);
|
(navigator.userAgent.includes("Mac") && "ontouchend" in document);
|
||||||
// keeping function so it can be mocked in test
|
// keeping function so it can be mocked in test
|
||||||
export const isBrave = () =>
|
export const isBrave = () =>
|
||||||
(navigator as any).brave?.isBrave?.name === "isBrave";
|
(navigator as any).brave?.isBrave?.name === "isBrave";
|
||||||
|
|
||||||
export const isMobile =
|
|
||||||
isIOS ||
|
|
||||||
/android|webos|ipod|blackberry|iemobile|opera mini/i.test(
|
|
||||||
navigator.userAgent.toLowerCase(),
|
|
||||||
) ||
|
|
||||||
/android|ios|ipod|blackberry|windows phone/i.test(
|
|
||||||
navigator.platform.toLowerCase(),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const supportsResizeObserver =
|
export const supportsResizeObserver =
|
||||||
typeof window !== "undefined" && "ResizeObserver" in window;
|
typeof window !== "undefined" && "ResizeObserver" in window;
|
||||||
|
|
||||||
@@ -45,7 +36,6 @@ export const APP_NAME = "Excalidraw";
|
|||||||
// (happens a lot with fast clicks with the text tool)
|
// (happens a lot with fast clicks with the text tool)
|
||||||
export const TEXT_AUTOWRAP_THRESHOLD = 36; // px
|
export const TEXT_AUTOWRAP_THRESHOLD = 36; // px
|
||||||
export const DRAGGING_THRESHOLD = 10; // px
|
export const DRAGGING_THRESHOLD = 10; // px
|
||||||
export const MINIMUM_ARROW_SIZE = 20; // px
|
|
||||||
export const LINE_CONFIRM_THRESHOLD = 8; // px
|
export const LINE_CONFIRM_THRESHOLD = 8; // px
|
||||||
export const ELEMENT_SHIFT_TRANSLATE_AMOUNT = 5;
|
export const ELEMENT_SHIFT_TRANSLATE_AMOUNT = 5;
|
||||||
export const ELEMENT_TRANSLATE_AMOUNT = 1;
|
export const ELEMENT_TRANSLATE_AMOUNT = 1;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { average } from "@excalidraw/math";
|
import { average, pointFrom, type GlobalPoint } from "@excalidraw/math";
|
||||||
|
import { getCenterForBounds, getElementBounds } from "@excalidraw/element";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawBindableElement,
|
ExcalidrawBindableElement,
|
||||||
FontFamilyValues,
|
FontFamilyValues,
|
||||||
FontString,
|
FontString,
|
||||||
|
ExcalidrawElement,
|
||||||
|
ElementsMap,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -1236,6 +1239,17 @@ export const escapeDoubleQuotes = (str: string) => {
|
|||||||
export const castArray = <T>(value: T | T[]): T[] =>
|
export const castArray = <T>(value: T | T[]): T[] =>
|
||||||
Array.isArray(value) ? value : [value];
|
Array.isArray(value) ? value : [value];
|
||||||
|
|
||||||
|
export const elementCenterPoint = (
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
xOffset: number = 0,
|
||||||
|
yOffset: number = 0,
|
||||||
|
) => {
|
||||||
|
const [x, y] = getCenterForBounds(getElementBounds(element, elementsMap));
|
||||||
|
|
||||||
|
return pointFrom<GlobalPoint>(x + xOffset, y + yOffset);
|
||||||
|
};
|
||||||
|
|
||||||
/** hack for Array.isArray type guard not working with readonly value[] */
|
/** hack for Array.isArray type guard not working with readonly value[] */
|
||||||
export const isReadonlyArray = (value?: any): value is readonly any[] => {
|
export const isReadonlyArray = (value?: any): value is readonly any[] => {
|
||||||
return Array.isArray(value);
|
return Array.isArray(value);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@excalidraw/element",
|
"name": "@excalidraw/element",
|
||||||
"version": "0.18.0",
|
"version": "0.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./dist/types/element/src/index.d.ts",
|
"types": "./dist/types/element/src/index.d.ts",
|
||||||
"main": "./dist/prod/index.js",
|
"main": "./dist/prod/index.js",
|
||||||
@@ -13,10 +13,7 @@
|
|||||||
"default": "./dist/prod/index.js"
|
"default": "./dist/prod/index.js"
|
||||||
},
|
},
|
||||||
"./*": {
|
"./*": {
|
||||||
"types": "./dist/types/element/src/*.d.ts",
|
"types": "./dist/types/element/src/*.d.ts"
|
||||||
"development": "./dist/dev/index.js",
|
|
||||||
"production": "./dist/prod/index.js",
|
|
||||||
"default": "./dist/prod/index.js"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -55,9 +52,5 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"gen:types": "rimraf types && tsc",
|
"gen:types": "rimraf types && tsc",
|
||||||
"build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
|
"build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@excalidraw/common": "0.18.0",
|
|
||||||
"@excalidraw/math": "0.18.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,14 +164,9 @@ export class Scene {
|
|||||||
return this.frames;
|
return this.frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(elements: ElementsMapOrArray | null = null) {
|
||||||
elements: ElementsMapOrArray | null = null,
|
|
||||||
options?: {
|
|
||||||
skipValidation?: true;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
if (elements) {
|
if (elements) {
|
||||||
this.replaceAllElements(elements, options);
|
this.replaceAllElements(elements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,19 +263,12 @@ export class Scene {
|
|||||||
return didChange;
|
return didChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceAllElements(
|
replaceAllElements(nextElements: ElementsMapOrArray) {
|
||||||
nextElements: ElementsMapOrArray,
|
|
||||||
options?: {
|
|
||||||
skipValidation?: true;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
// we do trust the insertion order on the map, though maybe we shouldn't and should prefer order defined by fractional indices
|
// we do trust the insertion order on the map, though maybe we shouldn't and should prefer order defined by fractional indices
|
||||||
const _nextElements = toArray(nextElements);
|
const _nextElements = toArray(nextElements);
|
||||||
const nextFrameLikes: ExcalidrawFrameLikeElement[] = [];
|
const nextFrameLikes: ExcalidrawFrameLikeElement[] = [];
|
||||||
|
|
||||||
if (!options?.skipValidation) {
|
validateIndicesThrottled(_nextElements);
|
||||||
validateIndicesThrottled(_nextElements);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.elements = syncInvalidIndices(_nextElements);
|
this.elements = syncInvalidIndices(_nextElements);
|
||||||
this.elementsMap.clear();
|
this.elementsMap.clear();
|
||||||
|
|||||||
@@ -1,28 +1,12 @@
|
|||||||
import { simplify } from "points-on-curve";
|
import { simplify } from "points-on-curve";
|
||||||
|
|
||||||
import {
|
|
||||||
type GeometricShape,
|
|
||||||
getClosedCurveShape,
|
|
||||||
getCurveShape,
|
|
||||||
getEllipseShape,
|
|
||||||
getFreedrawShape,
|
|
||||||
getPolygonShape,
|
|
||||||
} from "@excalidraw/utils/shape";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
pointFrom,
|
pointFrom,
|
||||||
pointDistance,
|
pointDistance,
|
||||||
type LocalPoint,
|
type LocalPoint,
|
||||||
pointRotateRads,
|
pointRotateRads,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
import {
|
import { ROUGHNESS, isTransparent, assertNever } from "@excalidraw/common";
|
||||||
ROUGHNESS,
|
|
||||||
isTransparent,
|
|
||||||
assertNever,
|
|
||||||
COLOR_PALETTE,
|
|
||||||
LINE_POLYGON_POINT_MERGE_DISTANCE,
|
|
||||||
isTestEnv,
|
|
||||||
} from "@excalidraw/common";
|
|
||||||
|
|
||||||
import { RoughGenerator } from "roughjs/bin/generator";
|
import { RoughGenerator } from "roughjs/bin/generator";
|
||||||
|
|
||||||
@@ -30,26 +14,17 @@ import type { GlobalPoint } from "@excalidraw/math";
|
|||||||
|
|
||||||
import type { Mutable } from "@excalidraw/common/utility-types";
|
import type { Mutable } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import type {
|
import type { EmbedsValidationStatus } from "@excalidraw/excalidraw/types";
|
||||||
AppState,
|
import type { ElementShapes } from "@excalidraw/excalidraw/scene/types";
|
||||||
EmbedsValidationStatus,
|
|
||||||
} from "@excalidraw/excalidraw/types";
|
|
||||||
import type {
|
|
||||||
ElementShape,
|
|
||||||
ElementShapes,
|
|
||||||
} from "@excalidraw/excalidraw/scene/types";
|
|
||||||
|
|
||||||
import { elementWithCanvasCache } from "./renderElement";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
canBecomePolygon,
|
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
isEmbeddableElement,
|
isEmbeddableElement,
|
||||||
isIframeElement,
|
isIframeElement,
|
||||||
isIframeLikeElement,
|
isIframeLikeElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
import { getCornerRadius, isPathALoop } from "./utils";
|
import { getCornerRadius, isPathALoop } from "./shapes";
|
||||||
import { headingForPointIsHorizontal } from "./heading";
|
import { headingForPointIsHorizontal } from "./heading";
|
||||||
|
|
||||||
import { canChangeRoundness } from "./comparisons";
|
import { canChangeRoundness } from "./comparisons";
|
||||||
@@ -58,9 +33,8 @@ import {
|
|||||||
getArrowheadPoints,
|
getArrowheadPoints,
|
||||||
getCenterForBounds,
|
getCenterForBounds,
|
||||||
getDiamondPoints,
|
getDiamondPoints,
|
||||||
getElementAbsoluteCoords,
|
getElementBounds,
|
||||||
} from "./bounds";
|
} from "./bounds";
|
||||||
import { shouldTestInside } from "./collision";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
@@ -70,87 +44,11 @@ import type {
|
|||||||
Arrowhead,
|
Arrowhead,
|
||||||
ExcalidrawFreeDrawElement,
|
ExcalidrawFreeDrawElement,
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
ExcalidrawLineElement,
|
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
import type { Drawable, Options } from "roughjs/bin/core";
|
import type { Drawable, Options } from "roughjs/bin/core";
|
||||||
import type { Point as RoughPoint } from "roughjs/bin/geometry";
|
import type { Point as RoughPoint } from "roughjs/bin/geometry";
|
||||||
|
|
||||||
export class ShapeCache {
|
|
||||||
private static rg = new RoughGenerator();
|
|
||||||
private static cache = new WeakMap<ExcalidrawElement, ElementShape>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves shape from cache if available. Use this only if shape
|
|
||||||
* is optional and you have a fallback in case it's not cached.
|
|
||||||
*/
|
|
||||||
public static get = <T extends ExcalidrawElement>(element: T) => {
|
|
||||||
return ShapeCache.cache.get(
|
|
||||||
element,
|
|
||||||
) as T["type"] extends keyof ElementShapes
|
|
||||||
? ElementShapes[T["type"]] | undefined
|
|
||||||
: ElementShape | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
public static set = <T extends ExcalidrawElement>(
|
|
||||||
element: T,
|
|
||||||
shape: T["type"] extends keyof ElementShapes
|
|
||||||
? ElementShapes[T["type"]]
|
|
||||||
: Drawable,
|
|
||||||
) => ShapeCache.cache.set(element, shape);
|
|
||||||
|
|
||||||
public static delete = (element: ExcalidrawElement) =>
|
|
||||||
ShapeCache.cache.delete(element);
|
|
||||||
|
|
||||||
public static destroy = () => {
|
|
||||||
ShapeCache.cache = new WeakMap();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates & caches shape for element if not already cached, otherwise
|
|
||||||
* returns cached shape.
|
|
||||||
*/
|
|
||||||
public static generateElementShape = <
|
|
||||||
T extends Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
|
||||||
>(
|
|
||||||
element: T,
|
|
||||||
renderConfig: {
|
|
||||||
isExporting: boolean;
|
|
||||||
canvasBackgroundColor: AppState["viewBackgroundColor"];
|
|
||||||
embedsValidationStatus: EmbedsValidationStatus;
|
|
||||||
} | null,
|
|
||||||
) => {
|
|
||||||
// when exporting, always regenerated to guarantee the latest shape
|
|
||||||
const cachedShape = renderConfig?.isExporting
|
|
||||||
? undefined
|
|
||||||
: ShapeCache.get(element);
|
|
||||||
|
|
||||||
// `null` indicates no rc shape applicable for this element type,
|
|
||||||
// but it's considered a valid cache value (= do not regenerate)
|
|
||||||
if (cachedShape !== undefined) {
|
|
||||||
return cachedShape;
|
|
||||||
}
|
|
||||||
|
|
||||||
elementWithCanvasCache.delete(element);
|
|
||||||
|
|
||||||
const shape = generateElementShape(
|
|
||||||
element,
|
|
||||||
ShapeCache.rg,
|
|
||||||
renderConfig || {
|
|
||||||
isExporting: false,
|
|
||||||
canvasBackgroundColor: COLOR_PALETTE.white,
|
|
||||||
embedsValidationStatus: null,
|
|
||||||
},
|
|
||||||
) as T["type"] extends keyof ElementShapes
|
|
||||||
? ElementShapes[T["type"]]
|
|
||||||
: Drawable | null;
|
|
||||||
|
|
||||||
ShapeCache.cache.set(element, shape);
|
|
||||||
|
|
||||||
return shape;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const getDashArrayDashed = (strokeWidth: number) => [8, 8 + strokeWidth];
|
const getDashArrayDashed = (strokeWidth: number) => [8, 8 + strokeWidth];
|
||||||
|
|
||||||
const getDashArrayDotted = (strokeWidth: number) => [1.5, 6 + strokeWidth];
|
const getDashArrayDotted = (strokeWidth: number) => [1.5, 6 + strokeWidth];
|
||||||
@@ -183,7 +81,7 @@ export const generateRoughOptions = (
|
|||||||
continuousPath = false,
|
continuousPath = false,
|
||||||
): Options => {
|
): Options => {
|
||||||
const options: Options = {
|
const options: Options = {
|
||||||
seed: isTestEnv() ? 1 : element.seed,
|
seed: element.seed,
|
||||||
strokeLineDash:
|
strokeLineDash:
|
||||||
element.strokeStyle === "dashed"
|
element.strokeStyle === "dashed"
|
||||||
? getDashArrayDashed(element.strokeWidth)
|
? getDashArrayDashed(element.strokeWidth)
|
||||||
@@ -422,6 +320,7 @@ const getArrowheadShapes = (
|
|||||||
|
|
||||||
export const generateLinearCollisionShape = (
|
export const generateLinearCollisionShape = (
|
||||||
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
) => {
|
) => {
|
||||||
const generator = new RoughGenerator();
|
const generator = new RoughGenerator();
|
||||||
const options: Options = {
|
const options: Options = {
|
||||||
@@ -432,18 +331,7 @@ export const generateLinearCollisionShape = (
|
|||||||
preserveVertices: true,
|
preserveVertices: true,
|
||||||
};
|
};
|
||||||
const center = getCenterForBounds(
|
const center = getCenterForBounds(
|
||||||
// Need a non-rotated center point
|
getElementBounds(element, elementsMap, true),
|
||||||
element.points.reduce(
|
|
||||||
(acc, point) => {
|
|
||||||
return [
|
|
||||||
Math.min(element.x + point[0], acc[0]),
|
|
||||||
Math.min(element.y + point[1], acc[1]),
|
|
||||||
Math.max(element.x + point[0], acc[2]),
|
|
||||||
Math.max(element.y + point[1], acc[3]),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
[Infinity, Infinity, -Infinity, -Infinity],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
switch (element.type) {
|
switch (element.type) {
|
||||||
@@ -603,7 +491,7 @@ export const generateLinearCollisionShape = (
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const generateElementShape = (
|
export const _generateElementShape = (
|
||||||
element: Exclude<NonDeletedExcalidrawElement, ExcalidrawSelectionElement>,
|
element: Exclude<NonDeletedExcalidrawElement, ExcalidrawSelectionElement>,
|
||||||
generator: RoughGenerator,
|
generator: RoughGenerator,
|
||||||
{
|
{
|
||||||
@@ -904,103 +792,3 @@ const generateElbowArrowShape = (
|
|||||||
|
|
||||||
return d.join(" ");
|
return d.join(" ");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* get the pure geometric shape of an excalidraw elementw
|
|
||||||
* which is then used for hit detection
|
|
||||||
*/
|
|
||||||
export const getElementShape = <Point extends GlobalPoint | LocalPoint>(
|
|
||||||
element: ExcalidrawElement,
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
): GeometricShape<Point> => {
|
|
||||||
switch (element.type) {
|
|
||||||
case "rectangle":
|
|
||||||
case "diamond":
|
|
||||||
case "frame":
|
|
||||||
case "magicframe":
|
|
||||||
case "embeddable":
|
|
||||||
case "image":
|
|
||||||
case "iframe":
|
|
||||||
case "text":
|
|
||||||
case "selection":
|
|
||||||
return getPolygonShape(element);
|
|
||||||
case "arrow":
|
|
||||||
case "line": {
|
|
||||||
const roughShape =
|
|
||||||
ShapeCache.get(element)?.[0] ??
|
|
||||||
ShapeCache.generateElementShape(element, null)[0];
|
|
||||||
const [, , , , cx, cy] = getElementAbsoluteCoords(element, elementsMap);
|
|
||||||
|
|
||||||
return shouldTestInside(element)
|
|
||||||
? getClosedCurveShape<Point>(
|
|
||||||
element,
|
|
||||||
roughShape,
|
|
||||||
pointFrom<Point>(element.x, element.y),
|
|
||||||
element.angle,
|
|
||||||
pointFrom(cx, cy),
|
|
||||||
)
|
|
||||||
: getCurveShape<Point>(
|
|
||||||
roughShape,
|
|
||||||
pointFrom<Point>(element.x, element.y),
|
|
||||||
element.angle,
|
|
||||||
pointFrom(cx, cy),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
case "ellipse":
|
|
||||||
return getEllipseShape(element);
|
|
||||||
|
|
||||||
case "freedraw": {
|
|
||||||
const [, , , , cx, cy] = getElementAbsoluteCoords(element, elementsMap);
|
|
||||||
return getFreedrawShape(
|
|
||||||
element,
|
|
||||||
pointFrom(cx, cy),
|
|
||||||
shouldTestInside(element),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const toggleLinePolygonState = (
|
|
||||||
element: ExcalidrawLineElement,
|
|
||||||
nextPolygonState: boolean,
|
|
||||||
): {
|
|
||||||
polygon: ExcalidrawLineElement["polygon"];
|
|
||||||
points: ExcalidrawLineElement["points"];
|
|
||||||
} | null => {
|
|
||||||
const updatedPoints = [...element.points];
|
|
||||||
|
|
||||||
if (nextPolygonState) {
|
|
||||||
if (!canBecomePolygon(element.points)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstPoint = updatedPoints[0];
|
|
||||||
const lastPoint = updatedPoints[updatedPoints.length - 1];
|
|
||||||
|
|
||||||
const distance = Math.hypot(
|
|
||||||
firstPoint[0] - lastPoint[0],
|
|
||||||
firstPoint[1] - lastPoint[1],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
distance > LINE_POLYGON_POINT_MERGE_DISTANCE ||
|
|
||||||
updatedPoints.length < 4
|
|
||||||
) {
|
|
||||||
updatedPoints.push(pointFrom(firstPoint[0], firstPoint[1]));
|
|
||||||
} else {
|
|
||||||
updatedPoints[updatedPoints.length - 1] = pointFrom(
|
|
||||||
firstPoint[0],
|
|
||||||
firstPoint[1],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: satisfies ElementUpdate<ExcalidrawLineElement>
|
|
||||||
const ret = {
|
|
||||||
polygon: nextPolygonState,
|
|
||||||
points: updatedPoints,
|
|
||||||
};
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import { RoughGenerator } from "roughjs/bin/generator";
|
||||||
|
|
||||||
|
import { COLOR_PALETTE } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import type {
|
||||||
|
AppState,
|
||||||
|
EmbedsValidationStatus,
|
||||||
|
} from "@excalidraw/excalidraw/types";
|
||||||
|
import type {
|
||||||
|
ElementShape,
|
||||||
|
ElementShapes,
|
||||||
|
} from "@excalidraw/excalidraw/scene/types";
|
||||||
|
|
||||||
|
import { _generateElementShape } from "./Shape";
|
||||||
|
|
||||||
|
import { elementWithCanvasCache } from "./renderElement";
|
||||||
|
|
||||||
|
import type { ExcalidrawElement, ExcalidrawSelectionElement } from "./types";
|
||||||
|
|
||||||
|
import type { Drawable } from "roughjs/bin/core";
|
||||||
|
|
||||||
|
export class ShapeCache {
|
||||||
|
private static rg = new RoughGenerator();
|
||||||
|
private static cache = new WeakMap<ExcalidrawElement, ElementShape>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves shape from cache if available. Use this only if shape
|
||||||
|
* is optional and you have a fallback in case it's not cached.
|
||||||
|
*/
|
||||||
|
public static get = <T extends ExcalidrawElement>(element: T) => {
|
||||||
|
return ShapeCache.cache.get(
|
||||||
|
element,
|
||||||
|
) as T["type"] extends keyof ElementShapes
|
||||||
|
? ElementShapes[T["type"]] | undefined
|
||||||
|
: ElementShape | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
public static set = <T extends ExcalidrawElement>(
|
||||||
|
element: T,
|
||||||
|
shape: T["type"] extends keyof ElementShapes
|
||||||
|
? ElementShapes[T["type"]]
|
||||||
|
: Drawable,
|
||||||
|
) => ShapeCache.cache.set(element, shape);
|
||||||
|
|
||||||
|
public static delete = (element: ExcalidrawElement) =>
|
||||||
|
ShapeCache.cache.delete(element);
|
||||||
|
|
||||||
|
public static destroy = () => {
|
||||||
|
ShapeCache.cache = new WeakMap();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates & caches shape for element if not already cached, otherwise
|
||||||
|
* returns cached shape.
|
||||||
|
*/
|
||||||
|
public static generateElementShape = <
|
||||||
|
T extends Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
||||||
|
>(
|
||||||
|
element: T,
|
||||||
|
renderConfig: {
|
||||||
|
isExporting: boolean;
|
||||||
|
canvasBackgroundColor: AppState["viewBackgroundColor"];
|
||||||
|
embedsValidationStatus: EmbedsValidationStatus;
|
||||||
|
} | null,
|
||||||
|
) => {
|
||||||
|
// when exporting, always regenerated to guarantee the latest shape
|
||||||
|
const cachedShape = renderConfig?.isExporting
|
||||||
|
? undefined
|
||||||
|
: ShapeCache.get(element);
|
||||||
|
|
||||||
|
// `null` indicates no rc shape applicable for this element type,
|
||||||
|
// but it's considered a valid cache value (= do not regenerate)
|
||||||
|
if (cachedShape !== undefined) {
|
||||||
|
return cachedShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
elementWithCanvasCache.delete(element);
|
||||||
|
|
||||||
|
const shape = _generateElementShape(
|
||||||
|
element,
|
||||||
|
ShapeCache.rg,
|
||||||
|
renderConfig || {
|
||||||
|
isExporting: false,
|
||||||
|
canvasBackgroundColor: COLOR_PALETTE.white,
|
||||||
|
embedsValidationStatus: null,
|
||||||
|
},
|
||||||
|
) as T["type"] extends keyof ElementShapes
|
||||||
|
? ElementShapes[T["type"]]
|
||||||
|
: Drawable | null;
|
||||||
|
|
||||||
|
ShapeCache.cache.set(element, shape);
|
||||||
|
|
||||||
|
return shape;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
|
||||||
|
|
||||||
import { updateBoundElements } from "./binding";
|
import { updateBoundElements } from "./binding";
|
||||||
import { getCommonBoundingBox } from "./bounds";
|
import { getCommonBoundingBox } from "./bounds";
|
||||||
import { getSelectedElementsByGroup } from "./groups";
|
import { getMaximumGroups } from "./groups";
|
||||||
|
|
||||||
import type { Scene } from "./Scene";
|
import type { Scene } from "./Scene";
|
||||||
|
|
||||||
@@ -18,12 +16,11 @@ export const alignElements = (
|
|||||||
selectedElements: ExcalidrawElement[],
|
selectedElements: ExcalidrawElement[],
|
||||||
alignment: Alignment,
|
alignment: Alignment,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
appState: Readonly<AppState>,
|
|
||||||
): ExcalidrawElement[] => {
|
): ExcalidrawElement[] => {
|
||||||
const groups: ExcalidrawElement[][] = getSelectedElementsByGroup(
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
const groups: ExcalidrawElement[][] = getMaximumGroups(
|
||||||
selectedElements,
|
selectedElements,
|
||||||
scene.getNonDeletedElementsMap(),
|
elementsMap,
|
||||||
appState,
|
|
||||||
);
|
);
|
||||||
const selectionBoundingBox = getCommonBoundingBox(selectedElements);
|
const selectionBoundingBox = getCommonBoundingBox(selectedElements);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
invariant,
|
invariant,
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
isTestEnv,
|
isTestEnv,
|
||||||
|
elementCenterPoint,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -33,9 +34,9 @@ import type { AppState } from "@excalidraw/excalidraw/types";
|
|||||||
import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";
|
import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
doBoundsIntersect,
|
|
||||||
getCenterForBounds,
|
getCenterForBounds,
|
||||||
getElementBounds,
|
getElementBounds,
|
||||||
|
doBoundsIntersect,
|
||||||
} from "./bounds";
|
} from "./bounds";
|
||||||
import { intersectElementWithLineSegment } from "./collision";
|
import { intersectElementWithLineSegment } from "./collision";
|
||||||
import { distanceToElement } from "./distance";
|
import { distanceToElement } from "./distance";
|
||||||
@@ -60,7 +61,7 @@ import {
|
|||||||
isTextElement,
|
isTextElement,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
|
|
||||||
import { aabbForElement, elementCenterPoint } from "./bounds";
|
import { aabbForElement } from "./shapes";
|
||||||
import { updateElbowArrowPoints } from "./elbowArrow";
|
import { updateElbowArrowPoints } from "./elbowArrow";
|
||||||
|
|
||||||
import type { Scene } from "./Scene";
|
import type { Scene } from "./Scene";
|
||||||
@@ -384,48 +385,6 @@ export const getSuggestedBindingsForArrows = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const maybeSuggestBindingsForLinearElementAtCoords = (
|
|
||||||
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
|
||||||
/** scene coords */
|
|
||||||
pointerCoords: {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
}[],
|
|
||||||
scene: Scene,
|
|
||||||
zoom: AppState["zoom"],
|
|
||||||
// During line creation the start binding hasn't been written yet
|
|
||||||
// into `linearElement`
|
|
||||||
oppositeBindingBoundElement?: ExcalidrawBindableElement | null,
|
|
||||||
): ExcalidrawBindableElement[] =>
|
|
||||||
Array.from(
|
|
||||||
pointerCoords.reduce(
|
|
||||||
(acc: Set<NonDeleted<ExcalidrawBindableElement>>, coords) => {
|
|
||||||
const hoveredBindableElement = getHoveredElementForBinding(
|
|
||||||
coords,
|
|
||||||
scene.getNonDeletedElements(),
|
|
||||||
scene.getNonDeletedElementsMap(),
|
|
||||||
zoom,
|
|
||||||
isElbowArrow(linearElement),
|
|
||||||
isElbowArrow(linearElement),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
hoveredBindableElement != null &&
|
|
||||||
!isLinearElementSimpleAndAlreadyBound(
|
|
||||||
linearElement,
|
|
||||||
oppositeBindingBoundElement?.id,
|
|
||||||
hoveredBindableElement,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
acc.add(hoveredBindableElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
new Set() as Set<NonDeleted<ExcalidrawBindableElement>>,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const maybeBindLinearElement = (
|
export const maybeBindLinearElement = (
|
||||||
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
@@ -555,7 +514,7 @@ export const isLinearElementSimpleAndAlreadyBound = (
|
|||||||
|
|
||||||
const isLinearElementSimple = (
|
const isLinearElementSimple = (
|
||||||
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
||||||
): boolean => linearElement.points.length < 3 && !isElbowArrow(linearElement);
|
): boolean => linearElement.points.length < 3;
|
||||||
|
|
||||||
const unbindLinearElement = (
|
const unbindLinearElement = (
|
||||||
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
linearElement: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ import type { AppState } from "@excalidraw/excalidraw/types";
|
|||||||
|
|
||||||
import type { Mutable } from "@excalidraw/common/utility-types";
|
import type { Mutable } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import { generateRoughOptions } from "./shape";
|
import { generateRoughOptions } from "./Shape";
|
||||||
import { ShapeCache } from "./shape";
|
import { ShapeCache } from "./ShapeCache";
|
||||||
import { LinearElementEditor } from "./linearElementEditor";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
import { getBoundTextElement, getContainerElement } from "./textElement";
|
import { getBoundTextElement, getContainerElement } from "./textElement";
|
||||||
import {
|
import {
|
||||||
@@ -45,7 +45,7 @@ import {
|
|||||||
isTextElement,
|
isTextElement,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
|
|
||||||
import { getElementShape } from "./shape";
|
import { getElementShape } from "./shapes";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
deconstructDiamondElement,
|
deconstructDiamondElement,
|
||||||
@@ -584,7 +584,7 @@ const solveQuadratic = (
|
|||||||
return [s1, s2];
|
return [s1, s2];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCubicBezierCurveBound = (
|
const getCubicBezierCurveBound = (
|
||||||
p0: GlobalPoint,
|
p0: GlobalPoint,
|
||||||
p1: GlobalPoint,
|
p1: GlobalPoint,
|
||||||
p2: GlobalPoint,
|
p2: GlobalPoint,
|
||||||
@@ -1165,71 +1165,6 @@ export const getCenterForBounds = (bounds: Bounds): GlobalPoint =>
|
|||||||
bounds[1] + (bounds[3] - bounds[1]) / 2,
|
bounds[1] + (bounds[3] - bounds[1]) / 2,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the axis-aligned bounding box for a given element
|
|
||||||
*/
|
|
||||||
export const aabbForElement = (
|
|
||||||
element: Readonly<ExcalidrawElement>,
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
offset?: [number, number, number, number],
|
|
||||||
) => {
|
|
||||||
const bbox = {
|
|
||||||
minX: element.x,
|
|
||||||
minY: element.y,
|
|
||||||
maxX: element.x + element.width,
|
|
||||||
maxY: element.y + element.height,
|
|
||||||
midX: element.x + element.width / 2,
|
|
||||||
midY: element.y + element.height / 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
const center = elementCenterPoint(element, elementsMap);
|
|
||||||
const [topLeftX, topLeftY] = pointRotateRads(
|
|
||||||
pointFrom(bbox.minX, bbox.minY),
|
|
||||||
center,
|
|
||||||
element.angle,
|
|
||||||
);
|
|
||||||
const [topRightX, topRightY] = pointRotateRads(
|
|
||||||
pointFrom(bbox.maxX, bbox.minY),
|
|
||||||
center,
|
|
||||||
element.angle,
|
|
||||||
);
|
|
||||||
const [bottomRightX, bottomRightY] = pointRotateRads(
|
|
||||||
pointFrom(bbox.maxX, bbox.maxY),
|
|
||||||
center,
|
|
||||||
element.angle,
|
|
||||||
);
|
|
||||||
const [bottomLeftX, bottomLeftY] = pointRotateRads(
|
|
||||||
pointFrom(bbox.minX, bbox.maxY),
|
|
||||||
center,
|
|
||||||
element.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
const bounds = [
|
|
||||||
Math.min(topLeftX, topRightX, bottomRightX, bottomLeftX),
|
|
||||||
Math.min(topLeftY, topRightY, bottomRightY, bottomLeftY),
|
|
||||||
Math.max(topLeftX, topRightX, bottomRightX, bottomLeftX),
|
|
||||||
Math.max(topLeftY, topRightY, bottomRightY, bottomLeftY),
|
|
||||||
] as Bounds;
|
|
||||||
|
|
||||||
if (offset) {
|
|
||||||
const [topOffset, rightOffset, downOffset, leftOffset] = offset;
|
|
||||||
return [
|
|
||||||
bounds[0] - leftOffset,
|
|
||||||
bounds[1] - topOffset,
|
|
||||||
bounds[2] + rightOffset,
|
|
||||||
bounds[3] + downOffset,
|
|
||||||
] as Bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bounds;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const pointInsideBounds = <P extends GlobalPoint | LocalPoint>(
|
|
||||||
p: P,
|
|
||||||
bounds: Bounds,
|
|
||||||
): boolean =>
|
|
||||||
p[0] > bounds[0] && p[0] < bounds[2] && p[1] > bounds[1] && p[1] < bounds[3];
|
|
||||||
|
|
||||||
export const doBoundsIntersect = (
|
export const doBoundsIntersect = (
|
||||||
bounds1: Bounds | null,
|
bounds1: Bounds | null,
|
||||||
bounds2: Bounds | null,
|
bounds2: Bounds | null,
|
||||||
@@ -1243,14 +1178,3 @@ export const doBoundsIntersect = (
|
|||||||
|
|
||||||
return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;
|
return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const elementCenterPoint = (
|
|
||||||
element: ExcalidrawElement,
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
xOffset: number = 0,
|
|
||||||
yOffset: number = 0,
|
|
||||||
) => {
|
|
||||||
const [x, y] = getCenterForBounds(getElementBounds(element, elementsMap));
|
|
||||||
|
|
||||||
return pointFrom<GlobalPoint>(x + xOffset, y + yOffset);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isTransparent } from "@excalidraw/common";
|
import { isTransparent, elementCenterPoint } from "@excalidraw/common";
|
||||||
import {
|
import {
|
||||||
curveIntersectLineSegment,
|
curveIntersectLineSegment,
|
||||||
isPointWithinBounds,
|
isPointWithinBounds,
|
||||||
@@ -18,22 +18,15 @@ import {
|
|||||||
ellipseSegmentInterceptPoints,
|
ellipseSegmentInterceptPoints,
|
||||||
} from "@excalidraw/math/ellipse";
|
} from "@excalidraw/math/ellipse";
|
||||||
|
|
||||||
import type {
|
import type { GlobalPoint, LineSegment, Radians } from "@excalidraw/math";
|
||||||
Curve,
|
|
||||||
GlobalPoint,
|
|
||||||
LineSegment,
|
|
||||||
Radians,
|
|
||||||
} from "@excalidraw/math";
|
|
||||||
|
|
||||||
import type { FrameNameBounds } from "@excalidraw/excalidraw/types";
|
import type { FrameNameBounds } from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
import { isPathALoop } from "./utils";
|
import { isPathALoop } from "./shapes";
|
||||||
import {
|
import {
|
||||||
type Bounds,
|
type Bounds,
|
||||||
doBoundsIntersect,
|
doBoundsIntersect,
|
||||||
elementCenterPoint,
|
|
||||||
getCenterForBounds,
|
getCenterForBounds,
|
||||||
getCubicBezierCurveBound,
|
|
||||||
getElementBounds,
|
getElementBounds,
|
||||||
} from "./bounds";
|
} from "./bounds";
|
||||||
import {
|
import {
|
||||||
@@ -257,79 +250,26 @@ export const intersectElementWithLineSegment = (
|
|||||||
case "line":
|
case "line":
|
||||||
case "freedraw":
|
case "freedraw":
|
||||||
case "arrow":
|
case "arrow":
|
||||||
return intersectLinearOrFreeDrawWithLineSegment(element, line, onlyFirst);
|
return intersectLinearOrFreeDrawWithLineSegment(
|
||||||
|
element,
|
||||||
|
elementsMap,
|
||||||
|
line,
|
||||||
|
onlyFirst,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const curveIntersections = (
|
|
||||||
curves: Curve<GlobalPoint>[],
|
|
||||||
segment: LineSegment<GlobalPoint>,
|
|
||||||
intersections: GlobalPoint[],
|
|
||||||
center: GlobalPoint,
|
|
||||||
angle: Radians,
|
|
||||||
onlyFirst = false,
|
|
||||||
) => {
|
|
||||||
for (const c of curves) {
|
|
||||||
// Optimize by doing a cheap bounding box check first
|
|
||||||
const b1 = getCubicBezierCurveBound(c[0], c[1], c[2], c[3]);
|
|
||||||
const b2 = [
|
|
||||||
Math.min(segment[0][0], segment[1][0]),
|
|
||||||
Math.min(segment[0][1], segment[1][1]),
|
|
||||||
Math.max(segment[0][0], segment[1][0]),
|
|
||||||
Math.max(segment[0][1], segment[1][1]),
|
|
||||||
] as Bounds;
|
|
||||||
|
|
||||||
if (!doBoundsIntersect(b1, b2)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const hits = curveIntersectLineSegment(c, segment);
|
|
||||||
|
|
||||||
if (hits.length > 0) {
|
|
||||||
for (const j of hits) {
|
|
||||||
intersections.push(pointRotateRads(j, center, angle));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onlyFirst) {
|
|
||||||
return intersections;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return intersections;
|
|
||||||
};
|
|
||||||
|
|
||||||
const lineIntersections = (
|
|
||||||
lines: LineSegment<GlobalPoint>[],
|
|
||||||
segment: LineSegment<GlobalPoint>,
|
|
||||||
intersections: GlobalPoint[],
|
|
||||||
center: GlobalPoint,
|
|
||||||
angle: Radians,
|
|
||||||
onlyFirst = false,
|
|
||||||
) => {
|
|
||||||
for (const l of lines) {
|
|
||||||
const intersection = lineSegmentIntersectionPoints(l, segment);
|
|
||||||
if (intersection) {
|
|
||||||
intersections.push(pointRotateRads(intersection, center, angle));
|
|
||||||
|
|
||||||
if (onlyFirst) {
|
|
||||||
return intersections;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return intersections;
|
|
||||||
};
|
|
||||||
|
|
||||||
const intersectLinearOrFreeDrawWithLineSegment = (
|
const intersectLinearOrFreeDrawWithLineSegment = (
|
||||||
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
segment: LineSegment<GlobalPoint>,
|
segment: LineSegment<GlobalPoint>,
|
||||||
onlyFirst = false,
|
onlyFirst = false,
|
||||||
): GlobalPoint[] => {
|
): GlobalPoint[] => {
|
||||||
// NOTE: This is the only one which return the decomposed elements
|
const [lines, curves] = deconstructLinearOrFreeDrawElement(
|
||||||
// rotated! This is due to taking advantage of roughjs definitions.
|
element,
|
||||||
const [lines, curves] = deconstructLinearOrFreeDrawElement(element);
|
elementsMap,
|
||||||
const intersections: GlobalPoint[] = [];
|
);
|
||||||
|
const intersections = [];
|
||||||
|
|
||||||
for (const l of lines) {
|
for (const l of lines) {
|
||||||
const intersection = lineSegmentIntersectionPoints(l, segment);
|
const intersection = lineSegmentIntersectionPoints(l, segment);
|
||||||
@@ -343,19 +283,6 @@ const intersectLinearOrFreeDrawWithLineSegment = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const c of curves) {
|
for (const c of curves) {
|
||||||
// Optimize by doing a cheap bounding box check first
|
|
||||||
const b1 = getCubicBezierCurveBound(c[0], c[1], c[2], c[3]);
|
|
||||||
const b2 = [
|
|
||||||
Math.min(segment[0][0], segment[1][0]),
|
|
||||||
Math.min(segment[0][1], segment[1][1]),
|
|
||||||
Math.max(segment[0][0], segment[1][0]),
|
|
||||||
Math.max(segment[0][1], segment[1][1]),
|
|
||||||
] as Bounds;
|
|
||||||
|
|
||||||
if (!doBoundsIntersect(b1, b2)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const hits = curveIntersectLineSegment(c, segment);
|
const hits = curveIntersectLineSegment(c, segment);
|
||||||
|
|
||||||
if (hits.length > 0) {
|
if (hits.length > 0) {
|
||||||
@@ -373,7 +300,7 @@ const intersectLinearOrFreeDrawWithLineSegment = (
|
|||||||
const intersectRectanguloidWithLineSegment = (
|
const intersectRectanguloidWithLineSegment = (
|
||||||
element: ExcalidrawRectanguloidElement,
|
element: ExcalidrawRectanguloidElement,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
segment: LineSegment<GlobalPoint>,
|
l: LineSegment<GlobalPoint>,
|
||||||
offset: number = 0,
|
offset: number = 0,
|
||||||
onlyFirst = false,
|
onlyFirst = false,
|
||||||
): GlobalPoint[] => {
|
): GlobalPoint[] => {
|
||||||
@@ -381,43 +308,48 @@ const intersectRectanguloidWithLineSegment = (
|
|||||||
// To emulate a rotated rectangle we rotate the point in the inverse angle
|
// To emulate a rotated rectangle we rotate the point in the inverse angle
|
||||||
// instead. It's all the same distance-wise.
|
// instead. It's all the same distance-wise.
|
||||||
const rotatedA = pointRotateRads<GlobalPoint>(
|
const rotatedA = pointRotateRads<GlobalPoint>(
|
||||||
segment[0],
|
l[0],
|
||||||
center,
|
center,
|
||||||
-element.angle as Radians,
|
-element.angle as Radians,
|
||||||
);
|
);
|
||||||
const rotatedB = pointRotateRads<GlobalPoint>(
|
const rotatedB = pointRotateRads<GlobalPoint>(
|
||||||
segment[1],
|
l[1],
|
||||||
center,
|
center,
|
||||||
-element.angle as Radians,
|
-element.angle as Radians,
|
||||||
);
|
);
|
||||||
const rotatedIntersector = lineSegment(rotatedA, rotatedB);
|
|
||||||
|
|
||||||
// Get the element's building components we can test against
|
// Get the element's building components we can test against
|
||||||
const [sides, corners] = deconstructRectanguloidElement(element, offset);
|
const [sides, corners] = deconstructRectanguloidElement(element, offset);
|
||||||
|
|
||||||
const intersections: GlobalPoint[] = [];
|
const intersections: GlobalPoint[] = [];
|
||||||
|
|
||||||
lineIntersections(
|
for (const s of sides) {
|
||||||
sides,
|
const intersection = lineSegmentIntersectionPoints(
|
||||||
rotatedIntersector,
|
lineSegment(rotatedA, rotatedB),
|
||||||
intersections,
|
s,
|
||||||
center,
|
);
|
||||||
element.angle,
|
if (intersection) {
|
||||||
onlyFirst,
|
intersections.push(pointRotateRads(intersection, center, element.angle));
|
||||||
);
|
|
||||||
|
|
||||||
if (onlyFirst && intersections.length > 0) {
|
if (onlyFirst) {
|
||||||
return intersections;
|
return intersections;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
curveIntersections(
|
for (const t of corners) {
|
||||||
corners,
|
const hits = curveIntersectLineSegment(t, lineSegment(rotatedA, rotatedB));
|
||||||
rotatedIntersector,
|
|
||||||
intersections,
|
if (hits.length > 0) {
|
||||||
center,
|
for (const j of hits) {
|
||||||
element.angle,
|
intersections.push(pointRotateRads(j, center, element.angle));
|
||||||
onlyFirst,
|
}
|
||||||
);
|
|
||||||
|
if (onlyFirst) {
|
||||||
|
return intersections;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return intersections;
|
return intersections;
|
||||||
};
|
};
|
||||||
@@ -442,32 +374,38 @@ const intersectDiamondWithLineSegment = (
|
|||||||
// points. It's all the same distance-wise.
|
// points. It's all the same distance-wise.
|
||||||
const rotatedA = pointRotateRads(l[0], center, -element.angle as Radians);
|
const rotatedA = pointRotateRads(l[0], center, -element.angle as Radians);
|
||||||
const rotatedB = pointRotateRads(l[1], center, -element.angle as Radians);
|
const rotatedB = pointRotateRads(l[1], center, -element.angle as Radians);
|
||||||
const rotatedIntersector = lineSegment(rotatedA, rotatedB);
|
|
||||||
|
|
||||||
const [sides, corners] = deconstructDiamondElement(element, offset);
|
const [sides, corners] = deconstructDiamondElement(element, offset);
|
||||||
|
|
||||||
const intersections: GlobalPoint[] = [];
|
const intersections: GlobalPoint[] = [];
|
||||||
|
|
||||||
lineIntersections(
|
for (const s of sides) {
|
||||||
sides,
|
const intersection = lineSegmentIntersectionPoints(
|
||||||
rotatedIntersector,
|
lineSegment(rotatedA, rotatedB),
|
||||||
intersections,
|
s,
|
||||||
center,
|
);
|
||||||
element.angle,
|
if (intersection) {
|
||||||
onlyFirst,
|
intersections.push(pointRotateRads(intersection, center, element.angle));
|
||||||
);
|
|
||||||
|
|
||||||
if (onlyFirst && intersections.length > 0) {
|
if (onlyFirst) {
|
||||||
return intersections;
|
return intersections;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
curveIntersections(
|
for (const t of corners) {
|
||||||
corners,
|
const hits = curveIntersectLineSegment(t, lineSegment(rotatedA, rotatedB));
|
||||||
rotatedIntersector,
|
|
||||||
intersections,
|
if (hits.length > 0) {
|
||||||
center,
|
for (const j of hits) {
|
||||||
element.angle,
|
intersections.push(pointRotateRads(j, center, element.angle));
|
||||||
onlyFirst,
|
}
|
||||||
);
|
|
||||||
|
if (onlyFirst) {
|
||||||
|
return intersections;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return intersections;
|
return intersections;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ import {
|
|||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
import { type Point } from "points-on-curve";
|
import { type Point } from "points-on-curve";
|
||||||
|
|
||||||
|
import { elementCenterPoint } from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
elementCenterPoint,
|
|
||||||
getElementAbsoluteCoords,
|
getElementAbsoluteCoords,
|
||||||
getResizedElementAbsoluteCoords,
|
getResizedElementAbsoluteCoords,
|
||||||
} from "./bounds";
|
} from "./bounds";
|
||||||
|
|||||||
+125
-370
@@ -55,10 +55,10 @@ import { getNonDeletedGroupIds } from "./groups";
|
|||||||
|
|
||||||
import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex";
|
import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex";
|
||||||
|
|
||||||
import { StoreSnapshot } from "./store";
|
|
||||||
|
|
||||||
import { Scene } from "./Scene";
|
import { Scene } from "./Scene";
|
||||||
|
|
||||||
|
import { StoreSnapshot } from "./store";
|
||||||
|
|
||||||
import type { BindableProp, BindingProp } from "./binding";
|
import type { BindableProp, BindingProp } from "./binding";
|
||||||
|
|
||||||
import type { ElementUpdate } from "./mutateElement";
|
import type { ElementUpdate } from "./mutateElement";
|
||||||
@@ -150,27 +150,13 @@ export class Delta<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges two deltas into a new one.
|
|
||||||
*/
|
|
||||||
public static merge<T>(
|
|
||||||
delta1: Delta<T>,
|
|
||||||
delta2: Delta<T>,
|
|
||||||
delta3: Delta<T> = Delta.empty(),
|
|
||||||
) {
|
|
||||||
return Delta.create(
|
|
||||||
{ ...delta1.deleted, ...delta2.deleted, ...delta3.deleted },
|
|
||||||
{ ...delta1.inserted, ...delta2.inserted, ...delta3.inserted },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges deleted and inserted object partials.
|
* Merges deleted and inserted object partials.
|
||||||
*/
|
*/
|
||||||
public static mergeObjects<T extends { [key: string]: unknown }>(
|
public static mergeObjects<T extends { [key: string]: unknown }>(
|
||||||
prev: T,
|
prev: T,
|
||||||
added: T,
|
added: T,
|
||||||
removed: T = {} as T,
|
removed: T,
|
||||||
) {
|
) {
|
||||||
const cloned = { ...prev };
|
const cloned = { ...prev };
|
||||||
|
|
||||||
@@ -510,11 +496,6 @@ export interface DeltaContainer<T> {
|
|||||||
*/
|
*/
|
||||||
applyTo(previous: T, ...options: unknown[]): [T, boolean];
|
applyTo(previous: T, ...options: unknown[]): [T, boolean];
|
||||||
|
|
||||||
/**
|
|
||||||
* Squashes the current delta with the given one.
|
|
||||||
*/
|
|
||||||
squash(delta: DeltaContainer<T>): this;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether all `Delta`s are empty.
|
* Checks whether all `Delta`s are empty.
|
||||||
*/
|
*/
|
||||||
@@ -522,11 +503,7 @@ export interface DeltaContainer<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AppStateDelta implements DeltaContainer<AppState> {
|
export class AppStateDelta implements DeltaContainer<AppState> {
|
||||||
private constructor(public delta: Delta<ObservedAppState>) {}
|
private constructor(public readonly delta: Delta<ObservedAppState>) {}
|
||||||
|
|
||||||
public static create(delta: Delta<ObservedAppState>): AppStateDelta {
|
|
||||||
return new AppStateDelta(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static calculate<T extends ObservedAppState>(
|
public static calculate<T extends ObservedAppState>(
|
||||||
prevAppState: T,
|
prevAppState: T,
|
||||||
@@ -557,124 +534,53 @@ export class AppStateDelta implements DeltaContainer<AppState> {
|
|||||||
return new AppStateDelta(inversedDelta);
|
return new AppStateDelta(inversedDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public squash(delta: AppStateDelta): this {
|
|
||||||
if (delta.isEmpty()) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mergedDeletedSelectedElementIds = Delta.mergeObjects(
|
|
||||||
this.delta.deleted.selectedElementIds ?? {},
|
|
||||||
delta.delta.deleted.selectedElementIds ?? {},
|
|
||||||
);
|
|
||||||
|
|
||||||
const mergedInsertedSelectedElementIds = Delta.mergeObjects(
|
|
||||||
this.delta.inserted.selectedElementIds ?? {},
|
|
||||||
delta.delta.inserted.selectedElementIds ?? {},
|
|
||||||
);
|
|
||||||
|
|
||||||
const mergedDeletedSelectedGroupIds = Delta.mergeObjects(
|
|
||||||
this.delta.deleted.selectedGroupIds ?? {},
|
|
||||||
delta.delta.deleted.selectedGroupIds ?? {},
|
|
||||||
);
|
|
||||||
|
|
||||||
const mergedInsertedSelectedGroupIds = Delta.mergeObjects(
|
|
||||||
this.delta.inserted.selectedGroupIds ?? {},
|
|
||||||
delta.delta.inserted.selectedGroupIds ?? {},
|
|
||||||
);
|
|
||||||
|
|
||||||
const mergedDeletedLockedMultiSelections = Delta.mergeObjects(
|
|
||||||
this.delta.deleted.lockedMultiSelections ?? {},
|
|
||||||
delta.delta.deleted.lockedMultiSelections ?? {},
|
|
||||||
);
|
|
||||||
|
|
||||||
const mergedInsertedLockedMultiSelections = Delta.mergeObjects(
|
|
||||||
this.delta.inserted.lockedMultiSelections ?? {},
|
|
||||||
delta.delta.inserted.lockedMultiSelections ?? {},
|
|
||||||
);
|
|
||||||
|
|
||||||
const mergedInserted: Partial<ObservedAppState> = {};
|
|
||||||
const mergedDeleted: Partial<ObservedAppState> = {};
|
|
||||||
|
|
||||||
if (
|
|
||||||
Object.keys(mergedDeletedSelectedElementIds).length ||
|
|
||||||
Object.keys(mergedInsertedSelectedElementIds).length
|
|
||||||
) {
|
|
||||||
mergedDeleted.selectedElementIds = mergedDeletedSelectedElementIds;
|
|
||||||
mergedInserted.selectedElementIds = mergedInsertedSelectedElementIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
Object.keys(mergedDeletedSelectedGroupIds).length ||
|
|
||||||
Object.keys(mergedInsertedSelectedGroupIds).length
|
|
||||||
) {
|
|
||||||
mergedDeleted.selectedGroupIds = mergedDeletedSelectedGroupIds;
|
|
||||||
mergedInserted.selectedGroupIds = mergedInsertedSelectedGroupIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
Object.keys(mergedDeletedLockedMultiSelections).length ||
|
|
||||||
Object.keys(mergedInsertedLockedMultiSelections).length
|
|
||||||
) {
|
|
||||||
mergedDeleted.lockedMultiSelections = mergedDeletedLockedMultiSelections;
|
|
||||||
mergedInserted.lockedMultiSelections =
|
|
||||||
mergedInsertedLockedMultiSelections;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.delta = Delta.merge(
|
|
||||||
this.delta,
|
|
||||||
delta.delta,
|
|
||||||
Delta.create(mergedDeleted, mergedInserted),
|
|
||||||
);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public applyTo(
|
public applyTo(
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
nextElements: SceneElementsMap,
|
nextElements: SceneElementsMap,
|
||||||
): [AppState, boolean] {
|
): [AppState, boolean] {
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
selectedElementIds: deletedSelectedElementIds = {},
|
selectedElementIds: removedSelectedElementIds = {},
|
||||||
selectedGroupIds: deletedSelectedGroupIds = {},
|
selectedGroupIds: removedSelectedGroupIds = {},
|
||||||
lockedMultiSelections: deletedLockedMultiSelections = {},
|
|
||||||
} = this.delta.deleted;
|
} = this.delta.deleted;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
selectedElementIds: insertedSelectedElementIds = {},
|
selectedElementIds: addedSelectedElementIds = {},
|
||||||
selectedGroupIds: insertedSelectedGroupIds = {},
|
selectedGroupIds: addedSelectedGroupIds = {},
|
||||||
lockedMultiSelections: insertedLockedMultiSelections = {},
|
selectedLinearElementId,
|
||||||
selectedLinearElement: insertedSelectedLinearElement,
|
editingLinearElementId,
|
||||||
...directlyApplicablePartial
|
...directlyApplicablePartial
|
||||||
} = this.delta.inserted;
|
} = this.delta.inserted;
|
||||||
|
|
||||||
const mergedSelectedElementIds = Delta.mergeObjects(
|
const mergedSelectedElementIds = Delta.mergeObjects(
|
||||||
appState.selectedElementIds,
|
appState.selectedElementIds,
|
||||||
insertedSelectedElementIds,
|
addedSelectedElementIds,
|
||||||
deletedSelectedElementIds,
|
removedSelectedElementIds,
|
||||||
);
|
);
|
||||||
|
|
||||||
const mergedSelectedGroupIds = Delta.mergeObjects(
|
const mergedSelectedGroupIds = Delta.mergeObjects(
|
||||||
appState.selectedGroupIds,
|
appState.selectedGroupIds,
|
||||||
insertedSelectedGroupIds,
|
addedSelectedGroupIds,
|
||||||
deletedSelectedGroupIds,
|
removedSelectedGroupIds,
|
||||||
);
|
|
||||||
|
|
||||||
const mergedLockedMultiSelections = Delta.mergeObjects(
|
|
||||||
appState.lockedMultiSelections,
|
|
||||||
insertedLockedMultiSelections,
|
|
||||||
deletedLockedMultiSelections,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const selectedLinearElement =
|
const selectedLinearElement =
|
||||||
insertedSelectedLinearElement &&
|
selectedLinearElementId && nextElements.has(selectedLinearElementId)
|
||||||
nextElements.has(insertedSelectedLinearElement.elementId)
|
|
||||||
? new LinearElementEditor(
|
? new LinearElementEditor(
|
||||||
nextElements.get(
|
nextElements.get(
|
||||||
insertedSelectedLinearElement.elementId,
|
selectedLinearElementId,
|
||||||
|
) as NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
nextElements,
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const editingLinearElement =
|
||||||
|
editingLinearElementId && nextElements.has(editingLinearElementId)
|
||||||
|
? new LinearElementEditor(
|
||||||
|
nextElements.get(
|
||||||
|
editingLinearElementId,
|
||||||
) as NonDeleted<ExcalidrawLinearElement>,
|
) as NonDeleted<ExcalidrawLinearElement>,
|
||||||
nextElements,
|
nextElements,
|
||||||
insertedSelectedLinearElement.isEditing,
|
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -683,11 +589,14 @@ export class AppStateDelta implements DeltaContainer<AppState> {
|
|||||||
...directlyApplicablePartial,
|
...directlyApplicablePartial,
|
||||||
selectedElementIds: mergedSelectedElementIds,
|
selectedElementIds: mergedSelectedElementIds,
|
||||||
selectedGroupIds: mergedSelectedGroupIds,
|
selectedGroupIds: mergedSelectedGroupIds,
|
||||||
lockedMultiSelections: mergedLockedMultiSelections,
|
|
||||||
selectedLinearElement:
|
selectedLinearElement:
|
||||||
typeof insertedSelectedLinearElement !== "undefined"
|
typeof selectedLinearElementId !== "undefined"
|
||||||
? selectedLinearElement
|
? selectedLinearElement // element was either inserted or deleted
|
||||||
: appState.selectedLinearElement,
|
: appState.selectedLinearElement, // otherwise assign what we had before
|
||||||
|
editingLinearElement:
|
||||||
|
typeof editingLinearElementId !== "undefined"
|
||||||
|
? editingLinearElement // element was either inserted or deleted
|
||||||
|
: appState.editingLinearElement, // otherwise assign what we had before
|
||||||
};
|
};
|
||||||
|
|
||||||
const constainsVisibleChanges = this.filterInvisibleChanges(
|
const constainsVisibleChanges = this.filterInvisibleChanges(
|
||||||
@@ -816,53 +725,52 @@ export class AppStateDelta implements DeltaContainer<AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "selectedLinearElement":
|
case "selectedLinearElementId":
|
||||||
const nextLinearElement = nextAppState[key];
|
case "editingLinearElementId":
|
||||||
|
const appStateKey = AppStateDelta.convertToAppStateKey(key);
|
||||||
|
const linearElement = nextAppState[appStateKey];
|
||||||
|
|
||||||
if (!nextLinearElement) {
|
if (!linearElement) {
|
||||||
// previously there was a linear element (assuming visible), now there is none
|
// previously there was a linear element (assuming visible), now there is none
|
||||||
visibleDifferenceFlag.value = true;
|
visibleDifferenceFlag.value = true;
|
||||||
} else {
|
} else {
|
||||||
const element = nextElements.get(nextLinearElement.elementId);
|
const element = nextElements.get(linearElement.elementId);
|
||||||
|
|
||||||
if (element && !element.isDeleted) {
|
if (element && !element.isDeleted) {
|
||||||
// previously there wasn't a linear element, now there is one which is visible
|
// previously there wasn't a linear element, now there is one which is visible
|
||||||
visibleDifferenceFlag.value = true;
|
visibleDifferenceFlag.value = true;
|
||||||
} else {
|
} else {
|
||||||
// there was assigned a linear element now, but it's deleted
|
// there was assigned a linear element now, but it's deleted
|
||||||
nextAppState[key] = null;
|
nextAppState[appStateKey] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "lockedMultiSelections":
|
case "lockedMultiSelections": {
|
||||||
const prevLockedUnits = prevAppState[key] || {};
|
const prevLockedUnits = prevAppState[key] || {};
|
||||||
const nextLockedUnits = nextAppState[key] || {};
|
const nextLockedUnits = nextAppState[key] || {};
|
||||||
|
|
||||||
// TODO: this seems wrong, we are already doing this comparison generically above,
|
|
||||||
// hence instead we should check whether elements are actually visible,
|
|
||||||
// so that once these changes are applied they actually result in a visible change to the user
|
|
||||||
if (!isShallowEqual(prevLockedUnits, nextLockedUnits)) {
|
if (!isShallowEqual(prevLockedUnits, nextLockedUnits)) {
|
||||||
visibleDifferenceFlag.value = true;
|
visibleDifferenceFlag.value = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "activeLockedId":
|
}
|
||||||
|
case "activeLockedId": {
|
||||||
const prevHitLockedId = prevAppState[key] || null;
|
const prevHitLockedId = prevAppState[key] || null;
|
||||||
const nextHitLockedId = nextAppState[key] || null;
|
const nextHitLockedId = nextAppState[key] || null;
|
||||||
|
|
||||||
// TODO: this seems wrong, we are already doing this comparison generically above,
|
|
||||||
// hence instead we should check whether elements are actually visible,
|
|
||||||
// so that once these changes are applied they actually result in a visible change to the user
|
|
||||||
if (prevHitLockedId !== nextHitLockedId) {
|
if (prevHitLockedId !== nextHitLockedId) {
|
||||||
visibleDifferenceFlag.value = true;
|
visibleDifferenceFlag.value = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
assertNever(
|
assertNever(
|
||||||
key,
|
key,
|
||||||
`Unknown ObservedElementsAppState's key "${key}"`,
|
`Unknown ObservedElementsAppState's key "${key}"`,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -870,6 +778,20 @@ export class AppStateDelta implements DeltaContainer<AppState> {
|
|||||||
return visibleDifferenceFlag.value;
|
return visibleDifferenceFlag.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static convertToAppStateKey(
|
||||||
|
key: keyof Pick<
|
||||||
|
ObservedElementsAppState,
|
||||||
|
"selectedLinearElementId" | "editingLinearElementId"
|
||||||
|
>,
|
||||||
|
): keyof Pick<AppState, "selectedLinearElement" | "editingLinearElement"> {
|
||||||
|
switch (key) {
|
||||||
|
case "selectedLinearElementId":
|
||||||
|
return "selectedLinearElement";
|
||||||
|
case "editingLinearElementId":
|
||||||
|
return "editingLinearElement";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static filterSelectedElements(
|
private static filterSelectedElements(
|
||||||
selectedElementIds: AppState["selectedElementIds"],
|
selectedElementIds: AppState["selectedElementIds"],
|
||||||
elements: SceneElementsMap,
|
elements: SceneElementsMap,
|
||||||
@@ -934,7 +856,8 @@ export class AppStateDelta implements DeltaContainer<AppState> {
|
|||||||
editingGroupId,
|
editingGroupId,
|
||||||
selectedGroupIds,
|
selectedGroupIds,
|
||||||
selectedElementIds,
|
selectedElementIds,
|
||||||
selectedLinearElement,
|
editingLinearElementId,
|
||||||
|
selectedLinearElementId,
|
||||||
croppingElementId,
|
croppingElementId,
|
||||||
lockedMultiSelections,
|
lockedMultiSelections,
|
||||||
activeLockedId,
|
activeLockedId,
|
||||||
@@ -988,6 +911,12 @@ export class AppStateDelta implements DeltaContainer<AppState> {
|
|||||||
"lockedMultiSelections",
|
"lockedMultiSelections",
|
||||||
(prevValue) => (prevValue ?? {}) as ValueOf<T["lockedMultiSelections"]>,
|
(prevValue) => (prevValue ?? {}) as ValueOf<T["lockedMultiSelections"]>,
|
||||||
);
|
);
|
||||||
|
Delta.diffObjects(
|
||||||
|
deleted,
|
||||||
|
inserted,
|
||||||
|
"activeLockedId",
|
||||||
|
(prevValue) => (prevValue ?? null) as ValueOf<T["activeLockedId"]>,
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// if postprocessing fails it does not make sense to bubble up, but let's make sure we know about it
|
// if postprocessing fails it does not make sense to bubble up, but let's make sure we know about it
|
||||||
console.error(`Couldn't postprocess appstate change deltas.`);
|
console.error(`Couldn't postprocess appstate change deltas.`);
|
||||||
@@ -1016,13 +945,12 @@ type ElementPartial<TElement extends ExcalidrawElement = ExcalidrawElement> =
|
|||||||
Omit<Partial<Ordered<TElement>>, "id" | "updated" | "seed">;
|
Omit<Partial<Ordered<TElement>>, "id" | "updated" | "seed">;
|
||||||
|
|
||||||
export type ApplyToOptions = {
|
export type ApplyToOptions = {
|
||||||
excludedProperties?: Set<keyof ElementPartial>;
|
excludedProperties: Set<keyof ElementPartial>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ApplyToFlags = {
|
type ApplyToFlags = {
|
||||||
containsVisibleDifference: boolean;
|
containsVisibleDifference: boolean;
|
||||||
containsZindexDifference: boolean;
|
containsZindexDifference: boolean;
|
||||||
applyDirection: "forward" | "backward" | undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1123,15 +1051,6 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
deleted.version !== inserted.version
|
deleted.version !== inserted.version
|
||||||
);
|
);
|
||||||
|
|
||||||
private static satisfiesUniqueInvariants = (
|
|
||||||
elementsDelta: ElementsDelta,
|
|
||||||
id: string,
|
|
||||||
) => {
|
|
||||||
const { added, removed, updated } = elementsDelta;
|
|
||||||
// it's required that there is only one unique delta type per element
|
|
||||||
return [added[id], removed[id], updated[id]].filter(Boolean).length === 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
private static validate(
|
private static validate(
|
||||||
elementsDelta: ElementsDelta,
|
elementsDelta: ElementsDelta,
|
||||||
type: "added" | "removed" | "updated",
|
type: "added" | "removed" | "updated",
|
||||||
@@ -1140,7 +1059,6 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
for (const [id, delta] of Object.entries(elementsDelta[type])) {
|
for (const [id, delta] of Object.entries(elementsDelta[type])) {
|
||||||
if (
|
if (
|
||||||
!this.satisfiesCommmonInvariants(delta) ||
|
!this.satisfiesCommmonInvariants(delta) ||
|
||||||
!this.satisfiesUniqueInvariants(elementsDelta, id) ||
|
|
||||||
!satifiesSpecialInvariants(delta)
|
!satifiesSpecialInvariants(delta)
|
||||||
) {
|
) {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -1177,7 +1095,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
const nextElement = nextElements.get(prevElement.id);
|
const nextElement = nextElements.get(prevElement.id);
|
||||||
|
|
||||||
if (!nextElement) {
|
if (!nextElement) {
|
||||||
const deleted = { ...prevElement } as ElementPartial;
|
const deleted = { ...prevElement, isDeleted: false } as ElementPartial;
|
||||||
|
|
||||||
const inserted = {
|
const inserted = {
|
||||||
isDeleted: true,
|
isDeleted: true,
|
||||||
@@ -1191,10 +1109,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
ElementsDelta.stripIrrelevantProps,
|
ElementsDelta.stripIrrelevantProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
// ignore updates which would "delete" already deleted element
|
removed[prevElement.id] = delta;
|
||||||
if (!prevElement.isDeleted) {
|
|
||||||
removed[prevElement.id] = delta;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1210,6 +1125,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
|
|
||||||
const inserted = {
|
const inserted = {
|
||||||
...nextElement,
|
...nextElement,
|
||||||
|
isDeleted: false,
|
||||||
} as ElementPartial;
|
} as ElementPartial;
|
||||||
|
|
||||||
const delta = Delta.create(
|
const delta = Delta.create(
|
||||||
@@ -1218,10 +1134,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
ElementsDelta.stripIrrelevantProps,
|
ElementsDelta.stripIrrelevantProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
// ignore updates which would "delete" already deleted element
|
added[nextElement.id] = delta;
|
||||||
if (!nextElement.isDeleted) {
|
|
||||||
added[nextElement.id] = delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1250,13 +1163,8 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const strippedDeleted = ElementsDelta.stripVersionProps(delta.deleted);
|
// making sure there are at least some changes
|
||||||
const strippedInserted = ElementsDelta.stripVersionProps(
|
if (!Delta.isEmpty(delta)) {
|
||||||
delta.inserted,
|
|
||||||
);
|
|
||||||
|
|
||||||
// making sure there are at least some changes and only changed version & versionNonce does not count!
|
|
||||||
if (Delta.isInnerDifferent(strippedDeleted, strippedInserted, true)) {
|
|
||||||
updated[nextElement.id] = delta;
|
updated[nextElement.id] = delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1273,8 +1181,8 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
const inverseInternal = (deltas: Record<string, Delta<ElementPartial>>) => {
|
const inverseInternal = (deltas: Record<string, Delta<ElementPartial>>) => {
|
||||||
const inversedDeltas: Record<string, Delta<ElementPartial>> = {};
|
const inversedDeltas: Record<string, Delta<ElementPartial>> = {};
|
||||||
|
|
||||||
for (const [id, { inserted, deleted }] of Object.entries(deltas)) {
|
for (const [id, delta] of Object.entries(deltas)) {
|
||||||
inversedDeltas[id] = Delta.create({ ...inserted }, { ...deleted });
|
inversedDeltas[id] = Delta.create(delta.inserted, delta.deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
return inversedDeltas;
|
return inversedDeltas;
|
||||||
@@ -1372,15 +1280,8 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
latestDelta = delta;
|
latestDelta = delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
const strippedDeleted = ElementsDelta.stripVersionProps(
|
|
||||||
latestDelta.deleted,
|
|
||||||
);
|
|
||||||
const strippedInserted = ElementsDelta.stripVersionProps(
|
|
||||||
latestDelta.inserted,
|
|
||||||
);
|
|
||||||
|
|
||||||
// it might happen that after applying latest changes the delta itself does not contain any changes
|
// it might happen that after applying latest changes the delta itself does not contain any changes
|
||||||
if (Delta.isInnerDifferent(strippedDeleted, strippedInserted)) {
|
if (Delta.isInnerDifferent(latestDelta.deleted, latestDelta.inserted)) {
|
||||||
modifiedDeltas[id] = latestDelta;
|
modifiedDeltas[id] = latestDelta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1400,7 +1301,9 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
public applyTo(
|
public applyTo(
|
||||||
elements: SceneElementsMap,
|
elements: SceneElementsMap,
|
||||||
snapshot: StoreSnapshot["elements"] = StoreSnapshot.empty().elements,
|
snapshot: StoreSnapshot["elements"] = StoreSnapshot.empty().elements,
|
||||||
options?: ApplyToOptions,
|
options: ApplyToOptions = {
|
||||||
|
excludedProperties: new Set(),
|
||||||
|
},
|
||||||
): [SceneElementsMap, boolean] {
|
): [SceneElementsMap, boolean] {
|
||||||
let nextElements = new Map(elements) as SceneElementsMap;
|
let nextElements = new Map(elements) as SceneElementsMap;
|
||||||
let changedElements: Map<string, OrderedExcalidrawElement>;
|
let changedElements: Map<string, OrderedExcalidrawElement>;
|
||||||
@@ -1408,28 +1311,22 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
const flags: ApplyToFlags = {
|
const flags: ApplyToFlags = {
|
||||||
containsVisibleDifference: false,
|
containsVisibleDifference: false,
|
||||||
containsZindexDifference: false,
|
containsZindexDifference: false,
|
||||||
applyDirection: undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// mimic a transaction by applying deltas into `nextElements` (always new instance, no mutation)
|
// mimic a transaction by applying deltas into `nextElements` (always new instance, no mutation)
|
||||||
try {
|
try {
|
||||||
const applyDeltas = ElementsDelta.createApplier(
|
const applyDeltas = ElementsDelta.createApplier(
|
||||||
elements,
|
|
||||||
nextElements,
|
nextElements,
|
||||||
snapshot,
|
snapshot,
|
||||||
flags,
|
|
||||||
options,
|
options,
|
||||||
|
flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
const addedElements = applyDeltas(this.added);
|
const addedElements = applyDeltas(this.added);
|
||||||
const removedElements = applyDeltas(this.removed);
|
const removedElements = applyDeltas(this.removed);
|
||||||
const updatedElements = applyDeltas(this.updated);
|
const updatedElements = applyDeltas(this.updated);
|
||||||
|
|
||||||
const affectedElements = this.resolveConflicts(
|
const affectedElements = this.resolveConflicts(elements, nextElements);
|
||||||
elements,
|
|
||||||
nextElements,
|
|
||||||
flags.applyDirection,
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO: #7348 validate elements semantically and syntactically the changed elements, in case they would result data integrity issues
|
// TODO: #7348 validate elements semantically and syntactically the changed elements, in case they would result data integrity issues
|
||||||
changedElements = new Map([
|
changedElements = new Map([
|
||||||
@@ -1453,15 +1350,22 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// the following reorder performs mutations, but only on new instances of changed elements,
|
// the following reorder performs also mutations, but only on new instances of changed elements
|
||||||
// unless something goes really bad and it fallbacks to fixing all invalid indices
|
// (unless something goes really bad and it fallbacks to fixing all invalid indices)
|
||||||
nextElements = ElementsDelta.reorderElements(
|
nextElements = ElementsDelta.reorderElements(
|
||||||
nextElements,
|
nextElements,
|
||||||
changedElements,
|
changedElements,
|
||||||
flags,
|
flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
ElementsDelta.redrawElements(nextElements, changedElements);
|
// we don't have an up-to-date scene, as we can be just in the middle of applying history entry
|
||||||
|
// we also don't have a scene on the server
|
||||||
|
// so we are creating a temp scene just to query and mutate elements
|
||||||
|
const tempScene = new Scene(nextElements);
|
||||||
|
|
||||||
|
ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
|
||||||
|
// Need ordered nextElements to avoid z-index binding issues
|
||||||
|
ElementsDelta.redrawBoundArrows(tempScene, changedElements);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(
|
console.error(
|
||||||
`Couldn't mutate elements after applying elements change`,
|
`Couldn't mutate elements after applying elements change`,
|
||||||
@@ -1476,113 +1380,12 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public squash(delta: ElementsDelta): this {
|
|
||||||
if (delta.isEmpty()) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { added, removed, updated } = delta;
|
|
||||||
|
|
||||||
const mergeBoundElements = (
|
|
||||||
prevDelta: Delta<ElementPartial>,
|
|
||||||
nextDelta: Delta<ElementPartial>,
|
|
||||||
) => {
|
|
||||||
const mergedDeletedBoundElements =
|
|
||||||
Delta.mergeArrays(
|
|
||||||
prevDelta.deleted.boundElements ?? [],
|
|
||||||
nextDelta.deleted.boundElements ?? [],
|
|
||||||
undefined,
|
|
||||||
(x) => x.id,
|
|
||||||
) ?? [];
|
|
||||||
|
|
||||||
const mergedInsertedBoundElements =
|
|
||||||
Delta.mergeArrays(
|
|
||||||
prevDelta.inserted.boundElements ?? [],
|
|
||||||
nextDelta.inserted.boundElements ?? [],
|
|
||||||
undefined,
|
|
||||||
(x) => x.id,
|
|
||||||
) ?? [];
|
|
||||||
|
|
||||||
if (
|
|
||||||
!mergedDeletedBoundElements.length &&
|
|
||||||
!mergedInsertedBoundElements.length
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Delta.create(
|
|
||||||
{
|
|
||||||
boundElements: mergedDeletedBoundElements,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
boundElements: mergedInsertedBoundElements,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const [id, nextDelta] of Object.entries(added)) {
|
|
||||||
const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
|
|
||||||
|
|
||||||
if (!prevDelta) {
|
|
||||||
this.added[id] = nextDelta;
|
|
||||||
} else {
|
|
||||||
const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
|
|
||||||
delete this.removed[id];
|
|
||||||
delete this.updated[id];
|
|
||||||
|
|
||||||
this.added[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [id, nextDelta] of Object.entries(removed)) {
|
|
||||||
const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
|
|
||||||
|
|
||||||
if (!prevDelta) {
|
|
||||||
this.removed[id] = nextDelta;
|
|
||||||
} else {
|
|
||||||
const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
|
|
||||||
delete this.added[id];
|
|
||||||
delete this.updated[id];
|
|
||||||
|
|
||||||
this.removed[id] = Delta.merge(prevDelta, nextDelta, mergedDelta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [id, nextDelta] of Object.entries(updated)) {
|
|
||||||
const prevDelta = this.added[id] ?? this.removed[id] ?? this.updated[id];
|
|
||||||
|
|
||||||
if (!prevDelta) {
|
|
||||||
this.updated[id] = nextDelta;
|
|
||||||
} else {
|
|
||||||
const mergedDelta = mergeBoundElements(prevDelta, nextDelta);
|
|
||||||
const updatedDelta = Delta.merge(prevDelta, nextDelta, mergedDelta);
|
|
||||||
|
|
||||||
if (prevDelta === this.added[id]) {
|
|
||||||
this.added[id] = updatedDelta;
|
|
||||||
} else if (prevDelta === this.removed[id]) {
|
|
||||||
this.removed[id] = updatedDelta;
|
|
||||||
} else {
|
|
||||||
this.updated[id] = updatedDelta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isTestEnv() || isDevEnv()) {
|
|
||||||
ElementsDelta.validate(this, "added", ElementsDelta.satisfiesAddition);
|
|
||||||
ElementsDelta.validate(this, "removed", ElementsDelta.satisfiesRemoval);
|
|
||||||
ElementsDelta.validate(this, "updated", ElementsDelta.satisfiesUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static createApplier =
|
private static createApplier =
|
||||||
(
|
(
|
||||||
prevElements: SceneElementsMap,
|
|
||||||
nextElements: SceneElementsMap,
|
nextElements: SceneElementsMap,
|
||||||
snapshot: StoreSnapshot["elements"],
|
snapshot: StoreSnapshot["elements"],
|
||||||
|
options: ApplyToOptions,
|
||||||
flags: ApplyToFlags,
|
flags: ApplyToFlags,
|
||||||
options?: ApplyToOptions,
|
|
||||||
) =>
|
) =>
|
||||||
(deltas: Record<string, Delta<ElementPartial>>) => {
|
(deltas: Record<string, Delta<ElementPartial>>) => {
|
||||||
const getElement = ElementsDelta.createGetter(
|
const getElement = ElementsDelta.createGetter(
|
||||||
@@ -1595,26 +1398,15 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
const element = getElement(id, delta.inserted);
|
const element = getElement(id, delta.inserted);
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
const nextElement = ElementsDelta.applyDelta(
|
const newElement = ElementsDelta.applyDelta(
|
||||||
element,
|
element,
|
||||||
delta,
|
delta,
|
||||||
flags,
|
|
||||||
options,
|
options,
|
||||||
|
flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
nextElements.set(nextElement.id, nextElement);
|
nextElements.set(newElement.id, newElement);
|
||||||
acc.set(nextElement.id, nextElement);
|
acc.set(newElement.id, newElement);
|
||||||
|
|
||||||
if (!flags.applyDirection) {
|
|
||||||
const prevElement = prevElements.get(id);
|
|
||||||
|
|
||||||
if (prevElement) {
|
|
||||||
flags.applyDirection =
|
|
||||||
prevElement.version > nextElement.version
|
|
||||||
? "backward"
|
|
||||||
: "forward";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
@@ -1659,8 +1451,8 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
private static applyDelta(
|
private static applyDelta(
|
||||||
element: OrderedExcalidrawElement,
|
element: OrderedExcalidrawElement,
|
||||||
delta: Delta<ElementPartial>,
|
delta: Delta<ElementPartial>,
|
||||||
|
options: ApplyToOptions,
|
||||||
flags: ApplyToFlags,
|
flags: ApplyToFlags,
|
||||||
options?: ApplyToOptions,
|
|
||||||
) {
|
) {
|
||||||
const directlyApplicablePartial: Mutable<ElementPartial> = {};
|
const directlyApplicablePartial: Mutable<ElementPartial> = {};
|
||||||
|
|
||||||
@@ -1674,7 +1466,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.excludedProperties?.has(key)) {
|
if (options.excludedProperties.has(key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1714,7 +1506,7 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
delta.deleted.index !== delta.inserted.index;
|
delta.deleted.index !== delta.inserted.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return newElementWith(element, directlyApplicablePartial, true);
|
return newElementWith(element, directlyApplicablePartial);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1754,7 +1546,6 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
private resolveConflicts(
|
private resolveConflicts(
|
||||||
prevElements: SceneElementsMap,
|
prevElements: SceneElementsMap,
|
||||||
nextElements: SceneElementsMap,
|
nextElements: SceneElementsMap,
|
||||||
applyDirection: "forward" | "backward" = "forward",
|
|
||||||
) {
|
) {
|
||||||
const nextAffectedElements = new Map<string, OrderedExcalidrawElement>();
|
const nextAffectedElements = new Map<string, OrderedExcalidrawElement>();
|
||||||
const updater = (
|
const updater = (
|
||||||
@@ -1766,36 +1557,21 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const prevElement = prevElements.get(element.id);
|
|
||||||
const nextVersion =
|
|
||||||
applyDirection === "forward"
|
|
||||||
? nextElement.version + 1
|
|
||||||
: nextElement.version - 1;
|
|
||||||
|
|
||||||
const elementUpdates = updates as ElementUpdate<OrderedExcalidrawElement>;
|
|
||||||
|
|
||||||
let affectedElement: OrderedExcalidrawElement;
|
let affectedElement: OrderedExcalidrawElement;
|
||||||
|
|
||||||
if (prevElement === nextElement) {
|
if (prevElements.get(element.id) === nextElement) {
|
||||||
// create the new element instance in case we didn't modify the element yet
|
// create the new element instance in case we didn't modify the element yet
|
||||||
// so that we won't end up in an incosistent state in case we would fail in the middle of mutations
|
// so that we won't end up in an incosistent state in case we would fail in the middle of mutations
|
||||||
affectedElement = newElementWith(
|
affectedElement = newElementWith(
|
||||||
nextElement,
|
nextElement,
|
||||||
{
|
updates as ElementUpdate<OrderedExcalidrawElement>,
|
||||||
...elementUpdates,
|
|
||||||
version: nextVersion,
|
|
||||||
},
|
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
affectedElement = mutateElement(nextElement, nextElements, {
|
affectedElement = mutateElement(
|
||||||
...elementUpdates,
|
nextElement,
|
||||||
// don't modify the version further, if it's already different
|
nextElements,
|
||||||
version:
|
updates as ElementUpdate<OrderedExcalidrawElement>,
|
||||||
prevElement?.version !== nextElement.version
|
);
|
||||||
? nextElement.version
|
|
||||||
: nextVersion,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nextAffectedElements.set(affectedElement.id, affectedElement);
|
nextAffectedElements.set(affectedElement.id, affectedElement);
|
||||||
@@ -1833,12 +1609,25 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
Array.from(prevElements).filter(([id]) => nextAffectedElements.has(id)),
|
Array.from(prevElements).filter(([id]) => nextAffectedElements.has(id)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// calculate complete deltas for affected elements, and squash them back to the current deltas
|
// calculate complete deltas for affected elements, and assign them back to all the deltas
|
||||||
this.squash(
|
// technically we could do better here if perf. would become an issue
|
||||||
// technically we could do better here if perf. would become an issue
|
const { added, removed, updated } = ElementsDelta.calculate(
|
||||||
ElementsDelta.calculate(prevAffectedElements, nextAffectedElements),
|
prevAffectedElements,
|
||||||
|
nextAffectedElements,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
for (const [id, delta] of Object.entries(added)) {
|
||||||
|
this.added[id] = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [id, delta] of Object.entries(removed)) {
|
||||||
|
this.removed[id] = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [id, delta] of Object.entries(updated)) {
|
||||||
|
this.updated[id] = delta;
|
||||||
|
}
|
||||||
|
|
||||||
return nextAffectedElements;
|
return nextAffectedElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1900,31 +1689,6 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
BindableElement.rebindAffected(nextElements, nextElement(), updater);
|
BindableElement.rebindAffected(nextElements, nextElement(), updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static redrawElements(
|
|
||||||
nextElements: SceneElementsMap,
|
|
||||||
changedElements: Map<string, OrderedExcalidrawElement>,
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
// we don't have an up-to-date scene, as we can be just in the middle of applying history entry
|
|
||||||
// we also don't have a scene on the server
|
|
||||||
// so we are creating a temp scene just to query and mutate elements
|
|
||||||
const tempScene = new Scene(nextElements, { skipValidation: true });
|
|
||||||
|
|
||||||
ElementsDelta.redrawTextBoundingBoxes(tempScene, changedElements);
|
|
||||||
|
|
||||||
// needs ordered nextElements to avoid z-index binding issues
|
|
||||||
ElementsDelta.redrawBoundArrows(tempScene, changedElements);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Couldn't redraw elements`, e);
|
|
||||||
|
|
||||||
if (isTestEnv() || isDevEnv()) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
return nextElements;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static redrawTextBoundingBoxes(
|
private static redrawTextBoundingBoxes(
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
changed: Map<string, OrderedExcalidrawElement>,
|
changed: Map<string, OrderedExcalidrawElement>,
|
||||||
@@ -1979,7 +1743,6 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
) {
|
) {
|
||||||
for (const element of changed.values()) {
|
for (const element of changed.values()) {
|
||||||
if (!element.isDeleted && isBindableElement(element)) {
|
if (!element.isDeleted && isBindableElement(element)) {
|
||||||
// TODO: with precise bindings this is quite expensive, so consider optimisation so it's only triggered when the arrow does not intersect (imprecise) element bounds
|
|
||||||
updateBoundElements(element, scene, {
|
updateBoundElements(element, scene, {
|
||||||
changedElements: changed,
|
changedElements: changed,
|
||||||
});
|
});
|
||||||
@@ -2075,12 +1838,4 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
|||||||
|
|
||||||
return strippedPartial;
|
return strippedPartial;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static stripVersionProps(
|
|
||||||
partial: Partial<OrderedExcalidrawElement>,
|
|
||||||
): ElementPartial {
|
|
||||||
const { version, versionNonce, ...strippedPartial } = partial;
|
|
||||||
|
|
||||||
return strippedPartial;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
|
|
||||||
import { ellipse, ellipseDistanceFromPoint } from "@excalidraw/math/ellipse";
|
import { ellipse, ellipseDistanceFromPoint } from "@excalidraw/math/ellipse";
|
||||||
|
|
||||||
|
import { elementCenterPoint } from "@excalidraw/common";
|
||||||
|
|
||||||
import type { GlobalPoint, Radians } from "@excalidraw/math";
|
import type { GlobalPoint, Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -14,8 +16,6 @@ import {
|
|||||||
deconstructRectanguloidElement,
|
deconstructRectanguloidElement,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
|
||||||
import { elementCenterPoint } from "./bounds";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
@@ -48,7 +48,7 @@ export const distanceToElement = (
|
|||||||
case "line":
|
case "line":
|
||||||
case "arrow":
|
case "arrow":
|
||||||
case "freedraw":
|
case "freedraw":
|
||||||
return distanceToLinearOrFreeDraElement(element, p);
|
return distanceToLinearOrFreeDraElement(element, elementsMap, p);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -133,9 +133,13 @@ const distanceToEllipseElement = (
|
|||||||
|
|
||||||
const distanceToLinearOrFreeDraElement = (
|
const distanceToLinearOrFreeDraElement = (
|
||||||
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
p: GlobalPoint,
|
p: GlobalPoint,
|
||||||
) => {
|
) => {
|
||||||
const [lines, curves] = deconstructLinearOrFreeDrawElement(element);
|
const [lines, curves] = deconstructLinearOrFreeDrawElement(
|
||||||
|
element,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
return Math.min(
|
return Math.min(
|
||||||
...lines.map((s) => distanceToLineSegment(p, s)),
|
...lines.map((s) => distanceToLineSegment(p, s)),
|
||||||
...curves.map((a) => curvePointDistance(a, p)),
|
...curves.map((a) => curvePointDistance(a, p)),
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
|
||||||
|
|
||||||
import { getCommonBoundingBox } from "./bounds";
|
import { getCommonBoundingBox } from "./bounds";
|
||||||
import { newElementWith } from "./mutateElement";
|
import { newElementWith } from "./mutateElement";
|
||||||
|
|
||||||
import { getSelectedElementsByGroup } from "./groups";
|
import { getMaximumGroups } from "./groups";
|
||||||
|
|
||||||
import type { ElementsMap, ExcalidrawElement } from "./types";
|
import type { ElementsMap, ExcalidrawElement } from "./types";
|
||||||
|
|
||||||
@@ -16,7 +14,6 @@ export const distributeElements = (
|
|||||||
selectedElements: ExcalidrawElement[],
|
selectedElements: ExcalidrawElement[],
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
distribution: Distribution,
|
distribution: Distribution,
|
||||||
appState: Readonly<AppState>,
|
|
||||||
): ExcalidrawElement[] => {
|
): ExcalidrawElement[] => {
|
||||||
const [start, mid, end, extent] =
|
const [start, mid, end, extent] =
|
||||||
distribution.axis === "x"
|
distribution.axis === "x"
|
||||||
@@ -24,11 +21,7 @@ export const distributeElements = (
|
|||||||
: (["minY", "midY", "maxY", "height"] as const);
|
: (["minY", "midY", "maxY", "height"] as const);
|
||||||
|
|
||||||
const bounds = getCommonBoundingBox(selectedElements);
|
const bounds = getCommonBoundingBox(selectedElements);
|
||||||
const groups = getSelectedElementsByGroup(
|
const groups = getMaximumGroups(selectedElements, elementsMap)
|
||||||
selectedElements,
|
|
||||||
elementsMap,
|
|
||||||
appState,
|
|
||||||
)
|
|
||||||
.map((group) => [group, getCommonBoundingBox(group)] as const)
|
.map((group) => [group, getCommonBoundingBox(group)] as const)
|
||||||
.sort((a, b) => a[1][mid] - b[1][mid]);
|
.sort((a, b) => a[1][mid] - b[1][mid]);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import {
|
|||||||
tupleToCoors,
|
tupleToCoors,
|
||||||
getSizeFromPoints,
|
getSizeFromPoints,
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
arrayToMap,
|
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
import type { AppState } from "@excalidraw/excalidraw/types";
|
||||||
@@ -52,7 +51,7 @@ import {
|
|||||||
type NonDeletedSceneElementsMap,
|
type NonDeletedSceneElementsMap,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
import { aabbForElement, pointInsideBounds } from "./bounds";
|
import { aabbForElement, pointInsideBounds } from "./shapes";
|
||||||
|
|
||||||
import type { Bounds } from "./bounds";
|
import type { Bounds } from "./bounds";
|
||||||
import type { Heading } from "./heading";
|
import type { Heading } from "./heading";
|
||||||
@@ -2209,12 +2208,20 @@ const getGlobalPoint = (
|
|||||||
return initialPoint;
|
return initialPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element) {
|
if (element && elementsMap) {
|
||||||
return getGlobalFixedPointForBindableElement(
|
const fixedGlobalPoint = getGlobalFixedPointForBindableElement(
|
||||||
fixedPointRatio || [0, 0],
|
fixedPointRatio || [0, 0],
|
||||||
element,
|
element,
|
||||||
elementsMap ?? arrayToMap([element]),
|
elementsMap,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// NOTE: Resize scales the binding position point too, so we need to update it
|
||||||
|
return Math.abs(
|
||||||
|
distanceToElement(element, elementsMap, fixedGlobalPoint) -
|
||||||
|
FIXED_BINDING_DISTANCE,
|
||||||
|
) > 0.01
|
||||||
|
? bindPointToSnapToElementOutline(arrow, element, startOrEnd, elementsMap)
|
||||||
|
: fixedGlobalPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return initialPoint;
|
return initialPoint;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ type IframeDataWithSandbox = MarkRequired<IframeData, "sandbox">;
|
|||||||
const embeddedLinkCache = new Map<string, IframeDataWithSandbox>();
|
const embeddedLinkCache = new Map<string, IframeDataWithSandbox>();
|
||||||
|
|
||||||
const RE_YOUTUBE =
|
const RE_YOUTUBE =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/;
|
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
|
||||||
|
|
||||||
const RE_VIMEO =
|
const RE_VIMEO =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
||||||
@@ -56,35 +56,6 @@ const RE_REDDIT =
|
|||||||
const RE_REDDIT_EMBED =
|
const RE_REDDIT_EMBED =
|
||||||
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
|
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
|
||||||
|
|
||||||
const parseYouTubeTimestamp = (url: string): number => {
|
|
||||||
let timeParam: string | null | undefined;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const urlObj = new URL(url.startsWith("http") ? url : `https://${url}`);
|
|
||||||
timeParam =
|
|
||||||
urlObj.searchParams.get("t") || urlObj.searchParams.get("start");
|
|
||||||
} catch (error) {
|
|
||||||
const timeMatch = url.match(/[?&#](?:t|start)=([^&#\s]+)/);
|
|
||||||
timeParam = timeMatch?.[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!timeParam) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (/^\d+$/.test(timeParam)) {
|
|
||||||
return parseInt(timeParam, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeMatch = timeParam.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);
|
|
||||||
if (!timeMatch) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [, hours = "0", minutes = "0", seconds = "0"] = timeMatch;
|
|
||||||
return parseInt(hours) * 3600 + parseInt(minutes) * 60 + parseInt(seconds);
|
|
||||||
};
|
|
||||||
|
|
||||||
const ALLOWED_DOMAINS = new Set([
|
const ALLOWED_DOMAINS = new Set([
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
"youtu.be",
|
"youtu.be",
|
||||||
@@ -142,8 +113,7 @@ export const getEmbedLink = (
|
|||||||
let aspectRatio = { w: 560, h: 840 };
|
let aspectRatio = { w: 560, h: 840 };
|
||||||
const ytLink = link.match(RE_YOUTUBE);
|
const ytLink = link.match(RE_YOUTUBE);
|
||||||
if (ytLink?.[2]) {
|
if (ytLink?.[2]) {
|
||||||
const startTime = parseYouTubeTimestamp(originalLink);
|
const time = ytLink[3] ? `&start=${ytLink[3]}` : ``;
|
||||||
const time = startTime > 0 ? `&start=${startTime}` : ``;
|
|
||||||
const isPortrait = link.includes("shorts");
|
const isPortrait = link.includes("shorts");
|
||||||
type = "video";
|
type = "video";
|
||||||
switch (ytLink[1]) {
|
switch (ytLink[1]) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
import { LinearElementEditor } from "./linearElementEditor";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
import { mutateElement } from "./mutateElement";
|
import { mutateElement } from "./mutateElement";
|
||||||
import { newArrowElement, newElement } from "./newElement";
|
import { newArrowElement, newElement } from "./newElement";
|
||||||
import { aabbForElement } from "./bounds";
|
import { aabbForElement } from "./shapes";
|
||||||
import { elementsAreInFrameBounds, elementOverlapsWithFrame } from "./frame";
|
import { elementsAreInFrameBounds, elementOverlapsWithFrame } from "./frame";
|
||||||
import {
|
import {
|
||||||
isBindableElement,
|
isBindableElement,
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import type { Mutable } from "@excalidraw/common/utility-types";
|
|||||||
|
|
||||||
import { getBoundTextElement } from "./textElement";
|
import { getBoundTextElement } from "./textElement";
|
||||||
|
|
||||||
import { isBoundToContainer } from "./typeChecks";
|
|
||||||
|
|
||||||
import { makeNextSelectedElementIds, getSelectedElements } from "./selection";
|
import { makeNextSelectedElementIds, getSelectedElements } from "./selection";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -404,78 +402,3 @@ export const getNewGroupIdsForDuplication = (
|
|||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
// given a list of selected elements, return the element grouped by their immediate group selected state
|
|
||||||
// in the case if only one group is selected and all elements selected are within the group, it will respect group hierarchy in accordance to their nested grouping order
|
|
||||||
export const getSelectedElementsByGroup = (
|
|
||||||
selectedElements: ExcalidrawElement[],
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
appState: Readonly<AppState>,
|
|
||||||
): ExcalidrawElement[][] => {
|
|
||||||
const selectedGroupIds = getSelectedGroupIds(appState);
|
|
||||||
const unboundElements = selectedElements.filter(
|
|
||||||
(element) => !isBoundToContainer(element),
|
|
||||||
);
|
|
||||||
const groups: Map<string, ExcalidrawElement[]> = new Map();
|
|
||||||
const elements: Map<string, ExcalidrawElement[]> = new Map();
|
|
||||||
|
|
||||||
// helper function to add an element to the elements map
|
|
||||||
const addToElementsMap = (element: ExcalidrawElement) => {
|
|
||||||
// elements
|
|
||||||
const currentElementMembers = elements.get(element.id) || [];
|
|
||||||
const boundTextElement = getBoundTextElement(element, elementsMap);
|
|
||||||
|
|
||||||
if (boundTextElement) {
|
|
||||||
currentElementMembers.push(boundTextElement);
|
|
||||||
}
|
|
||||||
elements.set(element.id, [...currentElementMembers, element]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// helper function to add an element to the groups map
|
|
||||||
const addToGroupsMap = (element: ExcalidrawElement, groupId: string) => {
|
|
||||||
// groups
|
|
||||||
const currentGroupMembers = groups.get(groupId) || [];
|
|
||||||
const boundTextElement = getBoundTextElement(element, elementsMap);
|
|
||||||
|
|
||||||
if (boundTextElement) {
|
|
||||||
currentGroupMembers.push(boundTextElement);
|
|
||||||
}
|
|
||||||
groups.set(groupId, [...currentGroupMembers, element]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// helper function to handle the case where a single group is selected
|
|
||||||
// and all elements selected are within the group, it will respect group hierarchy in accordance to
|
|
||||||
// their nested grouping order
|
|
||||||
const handleSingleSelectedGroupCase = (
|
|
||||||
element: ExcalidrawElement,
|
|
||||||
selectedGroupId: GroupId,
|
|
||||||
) => {
|
|
||||||
const indexOfSelectedGroupId = element.groupIds.indexOf(selectedGroupId, 0);
|
|
||||||
const nestedGroupCount = element.groupIds.slice(
|
|
||||||
0,
|
|
||||||
indexOfSelectedGroupId,
|
|
||||||
).length;
|
|
||||||
return nestedGroupCount > 0
|
|
||||||
? addToGroupsMap(element, element.groupIds[indexOfSelectedGroupId - 1])
|
|
||||||
: addToElementsMap(element);
|
|
||||||
};
|
|
||||||
|
|
||||||
const isAllInSameGroup = selectedElements.every((element) =>
|
|
||||||
isSelectedViaGroup(appState, element),
|
|
||||||
);
|
|
||||||
|
|
||||||
unboundElements.forEach((element) => {
|
|
||||||
const selectedGroupId = getSelectedGroupIdForElement(
|
|
||||||
element,
|
|
||||||
appState.selectedGroupIds,
|
|
||||||
);
|
|
||||||
if (!selectedGroupId) {
|
|
||||||
addToElementsMap(element);
|
|
||||||
} else if (selectedGroupIds.length === 1 && isAllInSameGroup) {
|
|
||||||
handleSingleSelectedGroupCase(element, selectedGroupId);
|
|
||||||
} else {
|
|
||||||
addToGroupsMap(element, selectedGroupId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return Array.from(groups.values()).concat(Array.from(elements.values()));
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -102,7 +102,9 @@ export * from "./resizeElements";
|
|||||||
export * from "./resizeTest";
|
export * from "./resizeTest";
|
||||||
export * from "./Scene";
|
export * from "./Scene";
|
||||||
export * from "./selection";
|
export * from "./selection";
|
||||||
export * from "./shape";
|
export * from "./Shape";
|
||||||
|
export * from "./ShapeCache";
|
||||||
|
export * from "./shapes";
|
||||||
export * from "./showSelectedShapeActions";
|
export * from "./showSelectedShapeActions";
|
||||||
export * from "./sizeHelpers";
|
export * from "./sizeHelpers";
|
||||||
export * from "./sortElements";
|
export * from "./sortElements";
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import {
|
|||||||
type LocalPoint,
|
type LocalPoint,
|
||||||
pointDistance,
|
pointDistance,
|
||||||
vectorFromPoint,
|
vectorFromPoint,
|
||||||
curveLength,
|
|
||||||
curvePointAtLength,
|
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import { getCurvePathOps } from "@excalidraw/utils/shape";
|
import { getCurvePathOps } from "@excalidraw/utils/shape";
|
||||||
@@ -20,14 +18,9 @@ import {
|
|||||||
getGridPoint,
|
getGridPoint,
|
||||||
invariant,
|
invariant,
|
||||||
tupleToCoors,
|
tupleToCoors,
|
||||||
viewportCoordsToSceneCoords,
|
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import type { Store } from "@excalidraw/element";
|
||||||
deconstructLinearOrFreeDrawElement,
|
|
||||||
isPathALoop,
|
|
||||||
type Store,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { Radians } from "@excalidraw/math";
|
import type { Radians } from "@excalidraw/math";
|
||||||
|
|
||||||
@@ -46,7 +39,6 @@ import {
|
|||||||
bindOrUnbindLinearElement,
|
bindOrUnbindLinearElement,
|
||||||
getHoveredElementForBinding,
|
getHoveredElementForBinding,
|
||||||
isBindingEnabled,
|
isBindingEnabled,
|
||||||
maybeSuggestBindingsForLinearElementAtCoords,
|
|
||||||
} from "./binding";
|
} from "./binding";
|
||||||
import {
|
import {
|
||||||
getElementAbsoluteCoords,
|
getElementAbsoluteCoords,
|
||||||
@@ -63,7 +55,16 @@ import {
|
|||||||
isFixedPointBinding,
|
isFixedPointBinding,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
|
|
||||||
import { ShapeCache, toggleLinePolygonState } from "./shape";
|
import { ShapeCache } from "./ShapeCache";
|
||||||
|
|
||||||
|
import {
|
||||||
|
isPathALoop,
|
||||||
|
getBezierCurveLength,
|
||||||
|
getControlPointsForBezierCurve,
|
||||||
|
mapIntervalToBezierT,
|
||||||
|
getBezierXY,
|
||||||
|
toggleLinePolygonState,
|
||||||
|
} from "./shapes";
|
||||||
|
|
||||||
import { getLockedLinearCursorAlignSize } from "./sizeHelpers";
|
import { getLockedLinearCursorAlignSize } from "./sizeHelpers";
|
||||||
|
|
||||||
@@ -149,12 +150,10 @@ export class LinearElementEditor {
|
|||||||
public readonly segmentMidPointHoveredCoords: GlobalPoint | null;
|
public readonly segmentMidPointHoveredCoords: GlobalPoint | null;
|
||||||
public readonly elbowed: boolean;
|
public readonly elbowed: boolean;
|
||||||
public readonly customLineAngle: number | null;
|
public readonly customLineAngle: number | null;
|
||||||
public readonly isEditing: boolean;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
element: NonDeleted<ExcalidrawLinearElement>,
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
isEditing: boolean = false,
|
|
||||||
) {
|
) {
|
||||||
this.elementId = element.id as string & {
|
this.elementId = element.id as string & {
|
||||||
_brand: "excalidrawLinearElementId";
|
_brand: "excalidrawLinearElementId";
|
||||||
@@ -189,7 +188,6 @@ export class LinearElementEditor {
|
|||||||
this.segmentMidPointHoveredCoords = null;
|
this.segmentMidPointHoveredCoords = null;
|
||||||
this.elbowed = isElbowArrow(element) && element.elbowed;
|
this.elbowed = isElbowArrow(element) && element.elbowed;
|
||||||
this.customLineAngle = null;
|
this.customLineAngle = null;
|
||||||
this.isEditing = isEditing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -197,7 +195,6 @@ export class LinearElementEditor {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static POINT_HANDLE_SIZE = 10;
|
static POINT_HANDLE_SIZE = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id the `elementId` from the instance of this class (so that we can
|
* @param id the `elementId` from the instance of this class (so that we can
|
||||||
* statically guarantee this method returns an ExcalidrawLinearElement)
|
* statically guarantee this method returns an ExcalidrawLinearElement)
|
||||||
@@ -219,14 +216,11 @@ export class LinearElementEditor {
|
|||||||
setState: React.Component<any, AppState>["setState"],
|
setState: React.Component<any, AppState>["setState"],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
) {
|
) {
|
||||||
if (
|
if (!appState.editingLinearElement || !appState.selectionElement) {
|
||||||
!appState.selectedLinearElement?.isEditing ||
|
|
||||||
!appState.selectionElement
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const { selectedLinearElement } = appState;
|
const { editingLinearElement } = appState;
|
||||||
const { selectedPointsIndices, elementId } = selectedLinearElement;
|
const { selectedPointsIndices, elementId } = editingLinearElement;
|
||||||
|
|
||||||
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
||||||
if (!element) {
|
if (!element) {
|
||||||
@@ -267,8 +261,8 @@ export class LinearElementEditor {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setState({
|
setState({
|
||||||
selectedLinearElement: {
|
editingLinearElement: {
|
||||||
...selectedLinearElement,
|
...editingLinearElement,
|
||||||
selectedPointsIndices: nextSelectedPoints.length
|
selectedPointsIndices: nextSelectedPoints.length
|
||||||
? nextSelectedPoints
|
? nextSelectedPoints
|
||||||
: null,
|
: null,
|
||||||
@@ -284,13 +278,18 @@ export class LinearElementEditor {
|
|||||||
app: AppClassProperties,
|
app: AppClassProperties,
|
||||||
scenePointerX: number,
|
scenePointerX: number,
|
||||||
scenePointerY: number,
|
scenePointerY: number,
|
||||||
|
maybeSuggestBinding: (
|
||||||
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
pointSceneCoords: { x: number; y: number }[],
|
||||||
|
) => void,
|
||||||
linearElementEditor: LinearElementEditor,
|
linearElementEditor: LinearElementEditor,
|
||||||
): Pick<AppState, keyof AppState> | null {
|
scene: Scene,
|
||||||
|
): LinearElementEditor | null {
|
||||||
if (!linearElementEditor) {
|
if (!linearElementEditor) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const { elementId } = linearElementEditor;
|
const { elementId } = linearElementEditor;
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
||||||
let customLineAngle = linearElementEditor.customLineAngle;
|
let customLineAngle = linearElementEditor.customLineAngle;
|
||||||
if (!element) {
|
if (!element) {
|
||||||
@@ -351,7 +350,7 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
LinearElementEditor.movePoints(
|
LinearElementEditor.movePoints(
|
||||||
element,
|
element,
|
||||||
app.scene,
|
scene,
|
||||||
new Map([
|
new Map([
|
||||||
[
|
[
|
||||||
selectedIndex,
|
selectedIndex,
|
||||||
@@ -379,7 +378,7 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
LinearElementEditor.movePoints(
|
LinearElementEditor.movePoints(
|
||||||
element,
|
element,
|
||||||
app.scene,
|
scene,
|
||||||
new Map(
|
new Map(
|
||||||
selectedPointsIndices.map((pointIndex) => {
|
selectedPointsIndices.map((pointIndex) => {
|
||||||
const newPointPosition: LocalPoint =
|
const newPointPosition: LocalPoint =
|
||||||
@@ -411,59 +410,46 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
const boundTextElement = getBoundTextElement(element, elementsMap);
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
||||||
if (boundTextElement) {
|
if (boundTextElement) {
|
||||||
handleBindTextResize(element, app.scene, false);
|
handleBindTextResize(element, scene, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// suggest bindings for first and last point if selected
|
// suggest bindings for first and last point if selected
|
||||||
let suggestedBindings: ExcalidrawBindableElement[] = [];
|
|
||||||
if (isBindingElement(element, false)) {
|
if (isBindingElement(element, false)) {
|
||||||
const firstSelectedIndex = selectedPointsIndices[0] === 0;
|
|
||||||
const lastSelectedIndex =
|
|
||||||
selectedPointsIndices[selectedPointsIndices.length - 1] ===
|
|
||||||
element.points.length - 1;
|
|
||||||
const coords: { x: number; y: number }[] = [];
|
const coords: { x: number; y: number }[] = [];
|
||||||
|
|
||||||
if (!firstSelectedIndex !== !lastSelectedIndex) {
|
const firstSelectedIndex = selectedPointsIndices[0];
|
||||||
coords.push({ x: scenePointerX, y: scenePointerY });
|
if (firstSelectedIndex === 0) {
|
||||||
} else {
|
coords.push(
|
||||||
if (firstSelectedIndex) {
|
tupleToCoors(
|
||||||
coords.push(
|
LinearElementEditor.getPointGlobalCoordinates(
|
||||||
tupleToCoors(
|
element,
|
||||||
LinearElementEditor.getPointGlobalCoordinates(
|
element.points[0],
|
||||||
element,
|
elementsMap,
|
||||||
element.points[0],
|
|
||||||
elementsMap,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (lastSelectedIndex) {
|
const lastSelectedIndex =
|
||||||
coords.push(
|
selectedPointsIndices[selectedPointsIndices.length - 1];
|
||||||
tupleToCoors(
|
if (lastSelectedIndex === element.points.length - 1) {
|
||||||
LinearElementEditor.getPointGlobalCoordinates(
|
coords.push(
|
||||||
element,
|
tupleToCoors(
|
||||||
element.points[
|
LinearElementEditor.getPointGlobalCoordinates(
|
||||||
selectedPointsIndices[selectedPointsIndices.length - 1]
|
element,
|
||||||
],
|
element.points[lastSelectedIndex],
|
||||||
elementsMap,
|
elementsMap,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coords.length) {
|
if (coords.length) {
|
||||||
suggestedBindings = maybeSuggestBindingsForLinearElementAtCoords(
|
maybeSuggestBinding(element, coords);
|
||||||
element,
|
|
||||||
coords,
|
|
||||||
app.scene,
|
|
||||||
app.state.zoom,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLinearElementEditor = {
|
return {
|
||||||
...linearElementEditor,
|
...linearElementEditor,
|
||||||
selectedPointsIndices,
|
selectedPointsIndices,
|
||||||
segmentMidPointHoveredCoords:
|
segmentMidPointHoveredCoords:
|
||||||
@@ -483,12 +469,6 @@ export class LinearElementEditor {
|
|||||||
isDragging: true,
|
isDragging: true,
|
||||||
customLineAngle,
|
customLineAngle,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
|
||||||
...app.state,
|
|
||||||
selectedLinearElement: newLinearElementEditor,
|
|
||||||
suggestedBindings,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -502,7 +482,6 @@ export class LinearElementEditor {
|
|||||||
): LinearElementEditor {
|
): LinearElementEditor {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const elements = scene.getNonDeletedElements();
|
const elements = scene.getNonDeletedElements();
|
||||||
const pointerCoords = viewportCoordsToSceneCoords(event, appState);
|
|
||||||
|
|
||||||
const { elementId, selectedPointsIndices, isDragging, pointerDownState } =
|
const { elementId, selectedPointsIndices, isDragging, pointerDownState } =
|
||||||
editingLinearElement;
|
editingLinearElement;
|
||||||
@@ -558,15 +537,13 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
const bindingElement = isBindingEnabled(appState)
|
const bindingElement = isBindingEnabled(appState)
|
||||||
? getHoveredElementForBinding(
|
? getHoveredElementForBinding(
|
||||||
(selectedPointsIndices?.length ?? 0) > 1
|
tupleToCoors(
|
||||||
? tupleToCoors(
|
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
element,
|
||||||
element,
|
selectedPoint!,
|
||||||
selectedPoint!,
|
elementsMap,
|
||||||
elementsMap,
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
: pointerCoords,
|
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
appState.zoom,
|
||||||
@@ -622,7 +599,7 @@ export class LinearElementEditor {
|
|||||||
// Since its not needed outside editor unless 2 pointer lines or bound text
|
// Since its not needed outside editor unless 2 pointer lines or bound text
|
||||||
if (
|
if (
|
||||||
!isElbowArrow(element) &&
|
!isElbowArrow(element) &&
|
||||||
!appState.selectedLinearElement?.isEditing &&
|
!appState.editingLinearElement &&
|
||||||
element.points.length > 2 &&
|
element.points.length > 2 &&
|
||||||
!boundText
|
!boundText
|
||||||
) {
|
) {
|
||||||
@@ -652,7 +629,10 @@ export class LinearElementEditor {
|
|||||||
}
|
}
|
||||||
const segmentMidPoint = LinearElementEditor.getSegmentMidPoint(
|
const segmentMidPoint = LinearElementEditor.getSegmentMidPoint(
|
||||||
element,
|
element,
|
||||||
|
points[index],
|
||||||
|
points[index + 1],
|
||||||
index + 1,
|
index + 1,
|
||||||
|
elementsMap,
|
||||||
);
|
);
|
||||||
midpoints.push(segmentMidPoint);
|
midpoints.push(segmentMidPoint);
|
||||||
index++;
|
index++;
|
||||||
@@ -688,7 +668,7 @@ export class LinearElementEditor {
|
|||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
points.length >= 3 &&
|
points.length >= 3 &&
|
||||||
!appState.selectedLinearElement?.isEditing &&
|
!appState.editingLinearElement &&
|
||||||
!isElbowArrow(element)
|
!isElbowArrow(element)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
@@ -754,18 +734,7 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
let distance = pointDistance(startPoint, endPoint);
|
let distance = pointDistance(startPoint, endPoint);
|
||||||
if (element.points.length > 2 && element.roundness) {
|
if (element.points.length > 2 && element.roundness) {
|
||||||
const [lines, curves] = deconstructLinearOrFreeDrawElement(element);
|
distance = getBezierCurveLength(element, endPoint);
|
||||||
|
|
||||||
invariant(
|
|
||||||
lines.length === 0 && curves.length > 0,
|
|
||||||
"Only linears built out of curves are supported",
|
|
||||||
);
|
|
||||||
invariant(
|
|
||||||
lines.length + curves.length >= index,
|
|
||||||
"Invalid segment index while calculating mid point",
|
|
||||||
);
|
|
||||||
|
|
||||||
distance = curveLength<GlobalPoint>(curves[index]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return distance * zoom.value < LinearElementEditor.POINT_HANDLE_SIZE * 4;
|
return distance * zoom.value < LinearElementEditor.POINT_HANDLE_SIZE * 4;
|
||||||
@@ -773,42 +742,39 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
static getSegmentMidPoint(
|
static getSegmentMidPoint(
|
||||||
element: NonDeleted<ExcalidrawLinearElement>,
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
index: number,
|
startPoint: GlobalPoint,
|
||||||
|
endPoint: GlobalPoint,
|
||||||
|
endPointIndex: number,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
): GlobalPoint {
|
): GlobalPoint {
|
||||||
if (isElbowArrow(element)) {
|
let segmentMidPoint = pointCenter(startPoint, endPoint);
|
||||||
invariant(
|
if (element.points.length > 2 && element.roundness) {
|
||||||
element.points.length >= index,
|
const controlPoints = getControlPointsForBezierCurve(
|
||||||
"Invalid segment index while calculating elbow arrow mid point",
|
element,
|
||||||
|
element.points[endPointIndex],
|
||||||
);
|
);
|
||||||
|
if (controlPoints) {
|
||||||
|
const t = mapIntervalToBezierT(
|
||||||
|
element,
|
||||||
|
element.points[endPointIndex],
|
||||||
|
0.5,
|
||||||
|
);
|
||||||
|
|
||||||
const p = pointCenter(element.points[index - 1], element.points[index]);
|
segmentMidPoint = LinearElementEditor.getPointGlobalCoordinates(
|
||||||
|
element,
|
||||||
return pointFrom<GlobalPoint>(element.x + p[0], element.y + p[1]);
|
getBezierXY(
|
||||||
|
controlPoints[0],
|
||||||
|
controlPoints[1],
|
||||||
|
controlPoints[2],
|
||||||
|
controlPoints[3],
|
||||||
|
t,
|
||||||
|
),
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [lines, curves] = deconstructLinearOrFreeDrawElement(element);
|
return segmentMidPoint;
|
||||||
|
|
||||||
invariant(
|
|
||||||
(lines.length === 0 && curves.length > 0) ||
|
|
||||||
(lines.length > 0 && curves.length === 0),
|
|
||||||
"Only linears built out of either segments or curves are supported",
|
|
||||||
);
|
|
||||||
invariant(
|
|
||||||
lines.length + curves.length >= index,
|
|
||||||
"Invalid segment index while calculating mid point",
|
|
||||||
);
|
|
||||||
|
|
||||||
if (lines.length) {
|
|
||||||
const segment = lines[index - 1];
|
|
||||||
return pointCenter(segment[0], segment[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curves.length) {
|
|
||||||
const segment = curves[index - 1];
|
|
||||||
return curvePointAtLength(segment, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
invariant(false, "Invalid segment type while calculating mid point");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSegmentMidPointIndex(
|
static getSegmentMidPointIndex(
|
||||||
@@ -885,7 +851,7 @@ export class LinearElementEditor {
|
|||||||
segmentMidpoint,
|
segmentMidpoint,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
} else if (event.altKey && appState.selectedLinearElement?.isEditing) {
|
} else if (event.altKey && appState.editingLinearElement) {
|
||||||
if (linearElementEditor.lastUncommittedPoint == null) {
|
if (linearElementEditor.lastUncommittedPoint == null) {
|
||||||
scene.mutateElement(element, {
|
scene.mutateElement(element, {
|
||||||
points: [
|
points: [
|
||||||
@@ -1027,14 +993,14 @@ export class LinearElementEditor {
|
|||||||
app: AppClassProperties,
|
app: AppClassProperties,
|
||||||
): LinearElementEditor | null {
|
): LinearElementEditor | null {
|
||||||
const appState = app.state;
|
const appState = app.state;
|
||||||
if (!appState.selectedLinearElement?.isEditing) {
|
if (!appState.editingLinearElement) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const { elementId, lastUncommittedPoint } = appState.selectedLinearElement;
|
const { elementId, lastUncommittedPoint } = appState.editingLinearElement;
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
const elementsMap = app.scene.getNonDeletedElementsMap();
|
||||||
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return appState.selectedLinearElement;
|
return appState.editingLinearElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { points } = element;
|
const { points } = element;
|
||||||
@@ -1044,12 +1010,10 @@ export class LinearElementEditor {
|
|||||||
if (lastPoint === lastUncommittedPoint) {
|
if (lastPoint === lastUncommittedPoint) {
|
||||||
LinearElementEditor.deletePoints(element, app, [points.length - 1]);
|
LinearElementEditor.deletePoints(element, app, [points.length - 1]);
|
||||||
}
|
}
|
||||||
return appState.selectedLinearElement?.lastUncommittedPoint
|
return {
|
||||||
? {
|
...appState.editingLinearElement,
|
||||||
...appState.selectedLinearElement,
|
lastUncommittedPoint: null,
|
||||||
lastUncommittedPoint: null,
|
};
|
||||||
}
|
|
||||||
: appState.selectedLinearElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let newPoint: LocalPoint;
|
let newPoint: LocalPoint;
|
||||||
@@ -1073,8 +1037,8 @@ export class LinearElementEditor {
|
|||||||
newPoint = LinearElementEditor.createPointAt(
|
newPoint = LinearElementEditor.createPointAt(
|
||||||
element,
|
element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
scenePointerX - appState.selectedLinearElement.pointerOffset.x,
|
scenePointerX - appState.editingLinearElement.pointerOffset.x,
|
||||||
scenePointerY - appState.selectedLinearElement.pointerOffset.y,
|
scenePointerY - appState.editingLinearElement.pointerOffset.y,
|
||||||
event[KEYS.CTRL_OR_CMD] || isElbowArrow(element)
|
event[KEYS.CTRL_OR_CMD] || isElbowArrow(element)
|
||||||
? null
|
? null
|
||||||
: app.getEffectiveGridSize(),
|
: app.getEffectiveGridSize(),
|
||||||
@@ -1098,7 +1062,7 @@ export class LinearElementEditor {
|
|||||||
LinearElementEditor.addPoints(element, app.scene, [newPoint]);
|
LinearElementEditor.addPoints(element, app.scene, [newPoint]);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...appState.selectedLinearElement,
|
...appState.editingLinearElement,
|
||||||
lastUncommittedPoint: element.points[element.points.length - 1],
|
lastUncommittedPoint: element.points[element.points.length - 1],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1257,12 +1221,12 @@ export class LinearElementEditor {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
static duplicateSelectedPoints(appState: AppState, scene: Scene): AppState {
|
static duplicateSelectedPoints(appState: AppState, scene: Scene): AppState {
|
||||||
invariant(
|
invariant(
|
||||||
appState.selectedLinearElement?.isEditing,
|
appState.editingLinearElement,
|
||||||
"Not currently editing a linear element",
|
"Not currently editing a linear element",
|
||||||
);
|
);
|
||||||
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const { selectedPointsIndices, elementId } = appState.selectedLinearElement;
|
const { selectedPointsIndices, elementId } = appState.editingLinearElement;
|
||||||
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
||||||
|
|
||||||
invariant(
|
invariant(
|
||||||
@@ -1324,8 +1288,8 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...appState,
|
...appState,
|
||||||
selectedLinearElement: {
|
editingLinearElement: {
|
||||||
...appState.selectedLinearElement,
|
...appState.editingLinearElement,
|
||||||
selectedPointsIndices: nextSelectedIndices,
|
selectedPointsIndices: nextSelectedIndices,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -1337,9 +1301,8 @@ export class LinearElementEditor {
|
|||||||
pointIndices: readonly number[],
|
pointIndices: readonly number[],
|
||||||
) {
|
) {
|
||||||
const isUncommittedPoint =
|
const isUncommittedPoint =
|
||||||
app.state.selectedLinearElement?.isEditing &&
|
app.state.editingLinearElement?.lastUncommittedPoint ===
|
||||||
app.state.selectedLinearElement?.lastUncommittedPoint ===
|
element.points[element.points.length - 1];
|
||||||
element.points[element.points.length - 1];
|
|
||||||
|
|
||||||
const nextPoints = element.points.filter((_, idx) => {
|
const nextPoints = element.points.filter((_, idx) => {
|
||||||
return !pointIndices.includes(idx);
|
return !pointIndices.includes(idx);
|
||||||
@@ -1512,7 +1475,7 @@ export class LinearElementEditor {
|
|||||||
pointFrom(pointerCoords.x, pointerCoords.y),
|
pointFrom(pointerCoords.x, pointerCoords.y),
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
!appState.selectedLinearElement?.isEditing &&
|
!appState.editingLinearElement &&
|
||||||
dist < DRAGGING_THRESHOLD / appState.zoom.value
|
dist < DRAGGING_THRESHOLD / appState.zoom.value
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1707,7 +1670,10 @@ export class LinearElementEditor {
|
|||||||
const index = element.points.length / 2 - 1;
|
const index = element.points.length / 2 - 1;
|
||||||
const midSegmentMidpoint = LinearElementEditor.getSegmentMidPoint(
|
const midSegmentMidpoint = LinearElementEditor.getSegmentMidPoint(
|
||||||
element,
|
element,
|
||||||
|
points[index],
|
||||||
|
points[index + 1],
|
||||||
index + 1,
|
index + 1,
|
||||||
|
elementsMap,
|
||||||
);
|
);
|
||||||
|
|
||||||
x = midSegmentMidpoint[0] - boundTextElement.width / 2;
|
x = midSegmentMidpoint[0] - boundTextElement.width / 2;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import type { Radians } from "@excalidraw/math";
|
|||||||
|
|
||||||
import type { Mutable } from "@excalidraw/common/utility-types";
|
import type { Mutable } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import { ShapeCache } from "./shape";
|
import { ShapeCache } from "./ShapeCache";
|
||||||
|
|
||||||
import { updateElbowArrowPoints } from "./elbowArrow";
|
import { updateElbowArrowPoints } from "./elbowArrow";
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ import {
|
|||||||
isImageElement,
|
isImageElement,
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
import { getContainingFrame } from "./frame";
|
import { getContainingFrame } from "./frame";
|
||||||
import { getCornerRadius } from "./utils";
|
import { getCornerRadius } from "./shapes";
|
||||||
|
|
||||||
import { ShapeCache } from "./shape";
|
import { ShapeCache } from "./ShapeCache";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
@@ -106,11 +106,6 @@ const getCanvasPadding = (element: ExcalidrawElement) => {
|
|||||||
return element.strokeWidth * 12;
|
return element.strokeWidth * 12;
|
||||||
case "text":
|
case "text":
|
||||||
return element.fontSize / 2;
|
return element.fontSize / 2;
|
||||||
case "arrow":
|
|
||||||
if (element.endArrowhead || element.endArrowhead) {
|
|
||||||
return 40;
|
|
||||||
}
|
|
||||||
return 20;
|
|
||||||
default:
|
default:
|
||||||
return 20;
|
return 20;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
pointCenter,
|
pointCenter,
|
||||||
normalizeRadians,
|
normalizeRadians,
|
||||||
pointFrom,
|
pointFrom,
|
||||||
|
pointFromPair,
|
||||||
pointRotateRads,
|
pointRotateRads,
|
||||||
type Radians,
|
type Radians,
|
||||||
type LocalPoint,
|
type LocalPoint,
|
||||||
@@ -103,6 +104,18 @@ export const transformElements = (
|
|||||||
);
|
);
|
||||||
updateBoundElements(element, scene);
|
updateBoundElements(element, scene);
|
||||||
}
|
}
|
||||||
|
} else if (isTextElement(element) && transformHandleType) {
|
||||||
|
resizeSingleTextElement(
|
||||||
|
originalElements,
|
||||||
|
element,
|
||||||
|
scene,
|
||||||
|
transformHandleType,
|
||||||
|
shouldResizeFromCenter,
|
||||||
|
pointerX,
|
||||||
|
pointerY,
|
||||||
|
);
|
||||||
|
updateBoundElements(element, scene);
|
||||||
|
return true;
|
||||||
} else if (transformHandleType) {
|
} else if (transformHandleType) {
|
||||||
const elementId = selectedElements[0].id;
|
const elementId = selectedElements[0].id;
|
||||||
const latestElement = elementsMap.get(elementId);
|
const latestElement = elementsMap.get(elementId);
|
||||||
@@ -137,9 +150,6 @@ export const transformElements = (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isTextElement(element)) {
|
|
||||||
updateBoundElements(element, scene);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else if (selectedElements.length > 1) {
|
} else if (selectedElements.length > 1) {
|
||||||
if (transformHandleType === "rotation") {
|
if (transformHandleType === "rotation") {
|
||||||
@@ -272,50 +282,151 @@ export const measureFontSizeFromWidth = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resizeSingleTextElement = (
|
const resizeSingleTextElement = (
|
||||||
origElement: NonDeleted<ExcalidrawTextElement>,
|
originalElements: PointerDownState["originalElements"],
|
||||||
element: NonDeleted<ExcalidrawTextElement>,
|
element: NonDeleted<ExcalidrawTextElement>,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
transformHandleType: TransformHandleDirection,
|
transformHandleType: TransformHandleDirection,
|
||||||
shouldResizeFromCenter: boolean,
|
shouldResizeFromCenter: boolean,
|
||||||
nextWidth: number,
|
pointerX: number,
|
||||||
nextHeight: number,
|
pointerY: number,
|
||||||
) => {
|
) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(
|
||||||
|
element,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
// rotation pointer with reverse angle
|
||||||
|
const [rotatedX, rotatedY] = pointRotateRads(
|
||||||
|
pointFrom(pointerX, pointerY),
|
||||||
|
pointFrom(cx, cy),
|
||||||
|
-element.angle as Radians,
|
||||||
|
);
|
||||||
|
let scaleX = 0;
|
||||||
|
let scaleY = 0;
|
||||||
|
|
||||||
const metricsWidth = element.width * (nextHeight / element.height);
|
if (transformHandleType !== "e" && transformHandleType !== "w") {
|
||||||
|
if (transformHandleType.includes("e")) {
|
||||||
const metrics = measureFontSizeFromWidth(element, elementsMap, metricsWidth);
|
scaleX = (rotatedX - x1) / (x2 - x1);
|
||||||
if (metrics === null) {
|
}
|
||||||
return;
|
if (transformHandleType.includes("w")) {
|
||||||
|
scaleX = (x2 - rotatedX) / (x2 - x1);
|
||||||
|
}
|
||||||
|
if (transformHandleType.includes("n")) {
|
||||||
|
scaleY = (y2 - rotatedY) / (y2 - y1);
|
||||||
|
}
|
||||||
|
if (transformHandleType.includes("s")) {
|
||||||
|
scaleY = (rotatedY - y1) / (y2 - y1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transformHandleType.includes("n") || transformHandleType.includes("s")) {
|
const scale = Math.max(scaleX, scaleY);
|
||||||
const previousOrigin = pointFrom<GlobalPoint>(origElement.x, origElement.y);
|
|
||||||
|
|
||||||
const newOrigin = getResizedOrigin(
|
if (scale > 0) {
|
||||||
previousOrigin,
|
const nextWidth = element.width * scale;
|
||||||
origElement.width,
|
const nextHeight = element.height * scale;
|
||||||
origElement.height,
|
const metrics = measureFontSizeFromWidth(element, elementsMap, nextWidth);
|
||||||
metricsWidth,
|
if (metrics === null) {
|
||||||
nextHeight,
|
return;
|
||||||
origElement.angle,
|
}
|
||||||
transformHandleType,
|
|
||||||
false,
|
const startTopLeft = [x1, y1];
|
||||||
shouldResizeFromCenter,
|
const startBottomRight = [x2, y2];
|
||||||
|
const startCenter = [cx, cy];
|
||||||
|
|
||||||
|
let newTopLeft = pointFrom<GlobalPoint>(x1, y1);
|
||||||
|
if (["n", "w", "nw"].includes(transformHandleType)) {
|
||||||
|
newTopLeft = pointFrom<GlobalPoint>(
|
||||||
|
startBottomRight[0] - Math.abs(nextWidth),
|
||||||
|
startBottomRight[1] - Math.abs(nextHeight),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (transformHandleType === "ne") {
|
||||||
|
const bottomLeft = [startTopLeft[0], startBottomRight[1]];
|
||||||
|
newTopLeft = pointFrom<GlobalPoint>(
|
||||||
|
bottomLeft[0],
|
||||||
|
bottomLeft[1] - Math.abs(nextHeight),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (transformHandleType === "sw") {
|
||||||
|
const topRight = [startBottomRight[0], startTopLeft[1]];
|
||||||
|
newTopLeft = pointFrom<GlobalPoint>(
|
||||||
|
topRight[0] - Math.abs(nextWidth),
|
||||||
|
topRight[1],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (["s", "n"].includes(transformHandleType)) {
|
||||||
|
newTopLeft[0] = startCenter[0] - nextWidth / 2;
|
||||||
|
}
|
||||||
|
if (["e", "w"].includes(transformHandleType)) {
|
||||||
|
newTopLeft[1] = startCenter[1] - nextHeight / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldResizeFromCenter) {
|
||||||
|
newTopLeft[0] = startCenter[0] - Math.abs(nextWidth) / 2;
|
||||||
|
newTopLeft[1] = startCenter[1] - Math.abs(nextHeight) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
const angle = element.angle;
|
||||||
|
const rotatedTopLeft = pointRotateRads(
|
||||||
|
newTopLeft,
|
||||||
|
pointFrom(cx, cy),
|
||||||
|
angle,
|
||||||
);
|
);
|
||||||
|
const newCenter = pointFrom<GlobalPoint>(
|
||||||
|
newTopLeft[0] + Math.abs(nextWidth) / 2,
|
||||||
|
newTopLeft[1] + Math.abs(nextHeight) / 2,
|
||||||
|
);
|
||||||
|
const rotatedNewCenter = pointRotateRads(
|
||||||
|
newCenter,
|
||||||
|
pointFrom(cx, cy),
|
||||||
|
angle,
|
||||||
|
);
|
||||||
|
newTopLeft = pointRotateRads(
|
||||||
|
rotatedTopLeft,
|
||||||
|
rotatedNewCenter,
|
||||||
|
-angle as Radians,
|
||||||
|
);
|
||||||
|
const [nextX, nextY] = newTopLeft;
|
||||||
|
|
||||||
scene.mutateElement(element, {
|
scene.mutateElement(element, {
|
||||||
fontSize: metrics.size,
|
fontSize: metrics.size,
|
||||||
width: metricsWidth,
|
width: nextWidth,
|
||||||
height: nextHeight,
|
height: nextHeight,
|
||||||
x: newOrigin.x,
|
x: nextX,
|
||||||
y: newOrigin.y,
|
y: nextY,
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transformHandleType === "e" || transformHandleType === "w") {
|
if (transformHandleType === "e" || transformHandleType === "w") {
|
||||||
|
const stateAtResizeStart = originalElements.get(element.id)!;
|
||||||
|
const [x1, y1, x2, y2] = getResizedElementAbsoluteCoords(
|
||||||
|
stateAtResizeStart,
|
||||||
|
stateAtResizeStart.width,
|
||||||
|
stateAtResizeStart.height,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
const startTopLeft = pointFrom<GlobalPoint>(x1, y1);
|
||||||
|
const startBottomRight = pointFrom<GlobalPoint>(x2, y2);
|
||||||
|
const startCenter = pointCenter(startTopLeft, startBottomRight);
|
||||||
|
|
||||||
|
const rotatedPointer = pointRotateRads(
|
||||||
|
pointFrom(pointerX, pointerY),
|
||||||
|
startCenter,
|
||||||
|
-stateAtResizeStart.angle as Radians,
|
||||||
|
);
|
||||||
|
|
||||||
|
const [esx1, , esx2] = getResizedElementAbsoluteCoords(
|
||||||
|
element,
|
||||||
|
element.width,
|
||||||
|
element.height,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
const boundsCurrentWidth = esx2 - esx1;
|
||||||
|
|
||||||
|
const atStartBoundsWidth = startBottomRight[0] - startTopLeft[0];
|
||||||
const minWidth = getMinTextElementWidth(
|
const minWidth = getMinTextElementWidth(
|
||||||
getFontString({
|
getFontString({
|
||||||
fontSize: element.fontSize,
|
fontSize: element.fontSize,
|
||||||
@@ -324,7 +435,17 @@ export const resizeSingleTextElement = (
|
|||||||
element.lineHeight,
|
element.lineHeight,
|
||||||
);
|
);
|
||||||
|
|
||||||
const newWidth = Math.max(minWidth, nextWidth);
|
let scaleX = atStartBoundsWidth / boundsCurrentWidth;
|
||||||
|
|
||||||
|
if (transformHandleType.includes("e")) {
|
||||||
|
scaleX = (rotatedPointer[0] - startTopLeft[0]) / boundsCurrentWidth;
|
||||||
|
}
|
||||||
|
if (transformHandleType.includes("w")) {
|
||||||
|
scaleX = (startBottomRight[0] - rotatedPointer[0]) / boundsCurrentWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newWidth =
|
||||||
|
element.width * scaleX < minWidth ? minWidth : element.width * scaleX;
|
||||||
|
|
||||||
const text = wrapText(
|
const text = wrapText(
|
||||||
element.originalText,
|
element.originalText,
|
||||||
@@ -337,27 +458,49 @@ export const resizeSingleTextElement = (
|
|||||||
element.lineHeight,
|
element.lineHeight,
|
||||||
);
|
);
|
||||||
|
|
||||||
const newHeight = metrics.height;
|
const eleNewHeight = metrics.height;
|
||||||
|
|
||||||
const previousOrigin = pointFrom<GlobalPoint>(origElement.x, origElement.y);
|
const [newBoundsX1, newBoundsY1, newBoundsX2, newBoundsY2] =
|
||||||
|
getResizedElementAbsoluteCoords(
|
||||||
|
stateAtResizeStart,
|
||||||
|
newWidth,
|
||||||
|
eleNewHeight,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
const newBoundsWidth = newBoundsX2 - newBoundsX1;
|
||||||
|
const newBoundsHeight = newBoundsY2 - newBoundsY1;
|
||||||
|
|
||||||
const newOrigin = getResizedOrigin(
|
let newTopLeft = [...startTopLeft] as [number, number];
|
||||||
previousOrigin,
|
if (["n", "w", "nw"].includes(transformHandleType)) {
|
||||||
origElement.width,
|
newTopLeft = [
|
||||||
origElement.height,
|
startBottomRight[0] - Math.abs(newBoundsWidth),
|
||||||
newWidth,
|
startTopLeft[1],
|
||||||
newHeight,
|
];
|
||||||
element.angle,
|
}
|
||||||
transformHandleType,
|
|
||||||
false,
|
// adjust topLeft to new rotation point
|
||||||
shouldResizeFromCenter,
|
const angle = stateAtResizeStart.angle;
|
||||||
|
const rotatedTopLeft = pointRotateRads(
|
||||||
|
pointFromPair(newTopLeft),
|
||||||
|
startCenter,
|
||||||
|
angle,
|
||||||
|
);
|
||||||
|
const newCenter = pointFrom(
|
||||||
|
newTopLeft[0] + Math.abs(newBoundsWidth) / 2,
|
||||||
|
newTopLeft[1] + Math.abs(newBoundsHeight) / 2,
|
||||||
|
);
|
||||||
|
const rotatedNewCenter = pointRotateRads(newCenter, startCenter, angle);
|
||||||
|
newTopLeft = pointRotateRads(
|
||||||
|
rotatedTopLeft,
|
||||||
|
rotatedNewCenter,
|
||||||
|
-angle as Radians,
|
||||||
);
|
);
|
||||||
|
|
||||||
const resizedElement: Partial<ExcalidrawTextElement> = {
|
const resizedElement: Partial<ExcalidrawTextElement> = {
|
||||||
width: Math.abs(newWidth),
|
width: Math.abs(newWidth),
|
||||||
height: Math.abs(metrics.height),
|
height: Math.abs(metrics.height),
|
||||||
x: newOrigin.x,
|
x: newTopLeft[0],
|
||||||
y: newOrigin.y,
|
y: newTopLeft[1],
|
||||||
text,
|
text,
|
||||||
autoResize: false,
|
autoResize: false,
|
||||||
};
|
};
|
||||||
@@ -678,18 +821,6 @@ export const resizeSingleElement = (
|
|||||||
shouldInformMutation?: boolean;
|
shouldInformMutation?: boolean;
|
||||||
} = {},
|
} = {},
|
||||||
) => {
|
) => {
|
||||||
if (isTextElement(latestElement) && isTextElement(origElement)) {
|
|
||||||
return resizeSingleTextElement(
|
|
||||||
origElement,
|
|
||||||
latestElement,
|
|
||||||
scene,
|
|
||||||
handleDirection,
|
|
||||||
shouldResizeFromCenter,
|
|
||||||
nextWidth,
|
|
||||||
nextHeight,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let boundTextFont: { fontSize?: number } = {};
|
let boundTextFont: { fontSize?: number } = {};
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
||||||
@@ -1387,7 +1518,11 @@ export const resizeMultipleElements = (
|
|||||||
} of elementsAndUpdates) {
|
} of elementsAndUpdates) {
|
||||||
const { width, height, angle } = update;
|
const { width, height, angle } = update;
|
||||||
|
|
||||||
scene.mutateElement(element, update);
|
scene.mutateElement(element, update, {
|
||||||
|
informMutation: true,
|
||||||
|
// needed for the fixed binding point udpate to take effect
|
||||||
|
isDragging: true,
|
||||||
|
});
|
||||||
|
|
||||||
updateBoundElements(element, scene, {
|
updateBoundElements(element, scene, {
|
||||||
simultaneouslyUpdated: elementsToUpdate,
|
simultaneouslyUpdated: elementsToUpdate,
|
||||||
|
|||||||
@@ -0,0 +1,447 @@
|
|||||||
|
import {
|
||||||
|
DEFAULT_ADAPTIVE_RADIUS,
|
||||||
|
DEFAULT_PROPORTIONAL_RADIUS,
|
||||||
|
LINE_CONFIRM_THRESHOLD,
|
||||||
|
ROUNDNESS,
|
||||||
|
invariant,
|
||||||
|
elementCenterPoint,
|
||||||
|
LINE_POLYGON_POINT_MERGE_DISTANCE,
|
||||||
|
} from "@excalidraw/common";
|
||||||
|
import {
|
||||||
|
isPoint,
|
||||||
|
pointFrom,
|
||||||
|
pointDistance,
|
||||||
|
pointFromPair,
|
||||||
|
pointRotateRads,
|
||||||
|
pointsEqual,
|
||||||
|
type GlobalPoint,
|
||||||
|
type LocalPoint,
|
||||||
|
} from "@excalidraw/math";
|
||||||
|
import {
|
||||||
|
getClosedCurveShape,
|
||||||
|
getCurvePathOps,
|
||||||
|
getCurveShape,
|
||||||
|
getEllipseShape,
|
||||||
|
getFreedrawShape,
|
||||||
|
getPolygonShape,
|
||||||
|
type GeometricShape,
|
||||||
|
} from "@excalidraw/utils/shape";
|
||||||
|
|
||||||
|
import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
|
import { shouldTestInside } from "./collision";
|
||||||
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
|
import { getBoundTextElement } from "./textElement";
|
||||||
|
import { ShapeCache } from "./ShapeCache";
|
||||||
|
|
||||||
|
import { getElementAbsoluteCoords, type Bounds } from "./bounds";
|
||||||
|
|
||||||
|
import { canBecomePolygon } from "./typeChecks";
|
||||||
|
|
||||||
|
import type {
|
||||||
|
ElementsMap,
|
||||||
|
ExcalidrawElement,
|
||||||
|
ExcalidrawLinearElement,
|
||||||
|
ExcalidrawLineElement,
|
||||||
|
NonDeleted,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the pure geometric shape of an excalidraw elementw
|
||||||
|
* which is then used for hit detection
|
||||||
|
*/
|
||||||
|
export const getElementShape = <Point extends GlobalPoint | LocalPoint>(
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
): GeometricShape<Point> => {
|
||||||
|
switch (element.type) {
|
||||||
|
case "rectangle":
|
||||||
|
case "diamond":
|
||||||
|
case "frame":
|
||||||
|
case "magicframe":
|
||||||
|
case "embeddable":
|
||||||
|
case "image":
|
||||||
|
case "iframe":
|
||||||
|
case "text":
|
||||||
|
case "selection":
|
||||||
|
return getPolygonShape(element);
|
||||||
|
case "arrow":
|
||||||
|
case "line": {
|
||||||
|
const roughShape =
|
||||||
|
ShapeCache.get(element)?.[0] ??
|
||||||
|
ShapeCache.generateElementShape(element, null)[0];
|
||||||
|
const [, , , , cx, cy] = getElementAbsoluteCoords(element, elementsMap);
|
||||||
|
|
||||||
|
return shouldTestInside(element)
|
||||||
|
? getClosedCurveShape<Point>(
|
||||||
|
element,
|
||||||
|
roughShape,
|
||||||
|
pointFrom<Point>(element.x, element.y),
|
||||||
|
element.angle,
|
||||||
|
pointFrom(cx, cy),
|
||||||
|
)
|
||||||
|
: getCurveShape<Point>(
|
||||||
|
roughShape,
|
||||||
|
pointFrom<Point>(element.x, element.y),
|
||||||
|
element.angle,
|
||||||
|
pointFrom(cx, cy),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "ellipse":
|
||||||
|
return getEllipseShape(element);
|
||||||
|
|
||||||
|
case "freedraw": {
|
||||||
|
const [, , , , cx, cy] = getElementAbsoluteCoords(element, elementsMap);
|
||||||
|
return getFreedrawShape(
|
||||||
|
element,
|
||||||
|
pointFrom(cx, cy),
|
||||||
|
shouldTestInside(element),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBoundTextShape = <Point extends GlobalPoint | LocalPoint>(
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
): GeometricShape<Point> | null => {
|
||||||
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
||||||
|
|
||||||
|
if (boundTextElement) {
|
||||||
|
if (element.type === "arrow") {
|
||||||
|
return getElementShape(
|
||||||
|
{
|
||||||
|
...boundTextElement,
|
||||||
|
// arrow's bound text accurate position is not stored in the element's property
|
||||||
|
// but rather calculated and returned from the following static method
|
||||||
|
...LinearElementEditor.getBoundTextElementPosition(
|
||||||
|
element,
|
||||||
|
boundTextElement,
|
||||||
|
elementsMap,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return getElementShape(boundTextElement, elementsMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getControlPointsForBezierCurve = <
|
||||||
|
P extends GlobalPoint | LocalPoint,
|
||||||
|
>(
|
||||||
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
endPoint: P,
|
||||||
|
) => {
|
||||||
|
const shape = ShapeCache.generateElementShape(element, null);
|
||||||
|
if (!shape) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ops = getCurvePathOps(shape[0]);
|
||||||
|
let currentP = pointFrom<P>(0, 0);
|
||||||
|
let index = 0;
|
||||||
|
let minDistance = Infinity;
|
||||||
|
let controlPoints: P[] | null = null;
|
||||||
|
|
||||||
|
while (index < ops.length) {
|
||||||
|
const { op, data } = ops[index];
|
||||||
|
if (op === "move") {
|
||||||
|
invariant(
|
||||||
|
isPoint(data),
|
||||||
|
"The returned ops is not compatible with a point",
|
||||||
|
);
|
||||||
|
currentP = pointFromPair(data);
|
||||||
|
}
|
||||||
|
if (op === "bcurveTo") {
|
||||||
|
const p0 = currentP;
|
||||||
|
const p1 = pointFrom<P>(data[0], data[1]);
|
||||||
|
const p2 = pointFrom<P>(data[2], data[3]);
|
||||||
|
const p3 = pointFrom<P>(data[4], data[5]);
|
||||||
|
const distance = pointDistance(p3, endPoint);
|
||||||
|
if (distance < minDistance) {
|
||||||
|
minDistance = distance;
|
||||||
|
controlPoints = [p0, p1, p2, p3];
|
||||||
|
}
|
||||||
|
currentP = p3;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return controlPoints;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBezierXY = <P extends GlobalPoint | LocalPoint>(
|
||||||
|
p0: P,
|
||||||
|
p1: P,
|
||||||
|
p2: P,
|
||||||
|
p3: P,
|
||||||
|
t: number,
|
||||||
|
): P => {
|
||||||
|
const equation = (t: number, idx: number) =>
|
||||||
|
Math.pow(1 - t, 3) * p3[idx] +
|
||||||
|
3 * t * Math.pow(1 - t, 2) * p2[idx] +
|
||||||
|
3 * Math.pow(t, 2) * (1 - t) * p1[idx] +
|
||||||
|
p0[idx] * Math.pow(t, 3);
|
||||||
|
const tx = equation(t, 0);
|
||||||
|
const ty = equation(t, 1);
|
||||||
|
return pointFrom(tx, ty);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPointsInBezierCurve = <P extends GlobalPoint | LocalPoint>(
|
||||||
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
endPoint: P,
|
||||||
|
) => {
|
||||||
|
const controlPoints: P[] = getControlPointsForBezierCurve(element, endPoint)!;
|
||||||
|
if (!controlPoints) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const pointsOnCurve: P[] = [];
|
||||||
|
let t = 1;
|
||||||
|
// Take 20 points on curve for better accuracy
|
||||||
|
while (t > 0) {
|
||||||
|
const p = getBezierXY(
|
||||||
|
controlPoints[0],
|
||||||
|
controlPoints[1],
|
||||||
|
controlPoints[2],
|
||||||
|
controlPoints[3],
|
||||||
|
t,
|
||||||
|
);
|
||||||
|
pointsOnCurve.push(pointFrom(p[0], p[1]));
|
||||||
|
t -= 0.05;
|
||||||
|
}
|
||||||
|
if (pointsOnCurve.length) {
|
||||||
|
if (pointsEqual(pointsOnCurve.at(-1)!, endPoint)) {
|
||||||
|
pointsOnCurve.push(pointFrom(endPoint[0], endPoint[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pointsOnCurve;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getBezierCurveArcLengths = <P extends GlobalPoint | LocalPoint>(
|
||||||
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
endPoint: P,
|
||||||
|
) => {
|
||||||
|
const arcLengths: number[] = [];
|
||||||
|
arcLengths[0] = 0;
|
||||||
|
const points = getPointsInBezierCurve(element, endPoint);
|
||||||
|
let index = 0;
|
||||||
|
let distance = 0;
|
||||||
|
while (index < points.length - 1) {
|
||||||
|
const segmentDistance = pointDistance(points[index], points[index + 1]);
|
||||||
|
distance += segmentDistance;
|
||||||
|
arcLengths.push(distance);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return arcLengths;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBezierCurveLength = <P extends GlobalPoint | LocalPoint>(
|
||||||
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
endPoint: P,
|
||||||
|
) => {
|
||||||
|
const arcLengths = getBezierCurveArcLengths(element, endPoint);
|
||||||
|
return arcLengths.at(-1) as number;
|
||||||
|
};
|
||||||
|
|
||||||
|
// This maps interval to actual interval t on the curve so that when t = 0.5, its actually the point at 50% of the length
|
||||||
|
export const mapIntervalToBezierT = <P extends GlobalPoint | LocalPoint>(
|
||||||
|
element: NonDeleted<ExcalidrawLinearElement>,
|
||||||
|
endPoint: P,
|
||||||
|
interval: number, // The interval between 0 to 1 for which you want to find the point on the curve,
|
||||||
|
) => {
|
||||||
|
const arcLengths = getBezierCurveArcLengths(element, endPoint);
|
||||||
|
const pointsCount = arcLengths.length - 1;
|
||||||
|
const curveLength = arcLengths.at(-1) as number;
|
||||||
|
const targetLength = interval * curveLength;
|
||||||
|
let low = 0;
|
||||||
|
let high = pointsCount;
|
||||||
|
let index = 0;
|
||||||
|
// Doing a binary search to find the largest length that is less than the target length
|
||||||
|
while (low < high) {
|
||||||
|
index = Math.floor(low + (high - low) / 2);
|
||||||
|
if (arcLengths[index] < targetLength) {
|
||||||
|
low = index + 1;
|
||||||
|
} else {
|
||||||
|
high = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (arcLengths[index] > targetLength) {
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
if (arcLengths[index] === targetLength) {
|
||||||
|
return index / pointsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
1 -
|
||||||
|
(index +
|
||||||
|
(targetLength - arcLengths[index]) /
|
||||||
|
(arcLengths[index + 1] - arcLengths[index])) /
|
||||||
|
pointsCount
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the axis-aligned bounding box for a given element
|
||||||
|
*/
|
||||||
|
export const aabbForElement = (
|
||||||
|
element: Readonly<ExcalidrawElement>,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
offset?: [number, number, number, number],
|
||||||
|
) => {
|
||||||
|
const bbox = {
|
||||||
|
minX: element.x,
|
||||||
|
minY: element.y,
|
||||||
|
maxX: element.x + element.width,
|
||||||
|
maxY: element.y + element.height,
|
||||||
|
midX: element.x + element.width / 2,
|
||||||
|
midY: element.y + element.height / 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
const center = elementCenterPoint(element, elementsMap);
|
||||||
|
const [topLeftX, topLeftY] = pointRotateRads(
|
||||||
|
pointFrom(bbox.minX, bbox.minY),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
);
|
||||||
|
const [topRightX, topRightY] = pointRotateRads(
|
||||||
|
pointFrom(bbox.maxX, bbox.minY),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
);
|
||||||
|
const [bottomRightX, bottomRightY] = pointRotateRads(
|
||||||
|
pointFrom(bbox.maxX, bbox.maxY),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
);
|
||||||
|
const [bottomLeftX, bottomLeftY] = pointRotateRads(
|
||||||
|
pointFrom(bbox.minX, bbox.maxY),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
);
|
||||||
|
|
||||||
|
const bounds = [
|
||||||
|
Math.min(topLeftX, topRightX, bottomRightX, bottomLeftX),
|
||||||
|
Math.min(topLeftY, topRightY, bottomRightY, bottomLeftY),
|
||||||
|
Math.max(topLeftX, topRightX, bottomRightX, bottomLeftX),
|
||||||
|
Math.max(topLeftY, topRightY, bottomRightY, bottomLeftY),
|
||||||
|
] as Bounds;
|
||||||
|
|
||||||
|
if (offset) {
|
||||||
|
const [topOffset, rightOffset, downOffset, leftOffset] = offset;
|
||||||
|
return [
|
||||||
|
bounds[0] - leftOffset,
|
||||||
|
bounds[1] - topOffset,
|
||||||
|
bounds[2] + rightOffset,
|
||||||
|
bounds[3] + downOffset,
|
||||||
|
] as Bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bounds;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const pointInsideBounds = <P extends GlobalPoint | LocalPoint>(
|
||||||
|
p: P,
|
||||||
|
bounds: Bounds,
|
||||||
|
): boolean =>
|
||||||
|
p[0] > bounds[0] && p[0] < bounds[2] && p[1] > bounds[1] && p[1] < bounds[3];
|
||||||
|
|
||||||
|
export const aabbsOverlapping = (a: Bounds, b: Bounds) =>
|
||||||
|
pointInsideBounds(pointFrom(a[0], a[1]), b) ||
|
||||||
|
pointInsideBounds(pointFrom(a[2], a[1]), b) ||
|
||||||
|
pointInsideBounds(pointFrom(a[2], a[3]), b) ||
|
||||||
|
pointInsideBounds(pointFrom(a[0], a[3]), b) ||
|
||||||
|
pointInsideBounds(pointFrom(b[0], b[1]), a) ||
|
||||||
|
pointInsideBounds(pointFrom(b[2], b[1]), a) ||
|
||||||
|
pointInsideBounds(pointFrom(b[2], b[3]), a) ||
|
||||||
|
pointInsideBounds(pointFrom(b[0], b[3]), a);
|
||||||
|
|
||||||
|
export const getCornerRadius = (x: number, element: ExcalidrawElement) => {
|
||||||
|
if (
|
||||||
|
element.roundness?.type === ROUNDNESS.PROPORTIONAL_RADIUS ||
|
||||||
|
element.roundness?.type === ROUNDNESS.LEGACY
|
||||||
|
) {
|
||||||
|
return x * DEFAULT_PROPORTIONAL_RADIUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.roundness?.type === ROUNDNESS.ADAPTIVE_RADIUS) {
|
||||||
|
const fixedRadiusSize = element.roundness?.value ?? DEFAULT_ADAPTIVE_RADIUS;
|
||||||
|
|
||||||
|
const CUTOFF_SIZE = fixedRadiusSize / DEFAULT_PROPORTIONAL_RADIUS;
|
||||||
|
|
||||||
|
if (x <= CUTOFF_SIZE) {
|
||||||
|
return x * DEFAULT_PROPORTIONAL_RADIUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fixedRadiusSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Checks if the first and last point are close enough
|
||||||
|
// to be considered a loop
|
||||||
|
export const isPathALoop = (
|
||||||
|
points: ExcalidrawLinearElement["points"],
|
||||||
|
/** supply if you want the loop detection to account for current zoom */
|
||||||
|
zoomValue: Zoom["value"] = 1 as NormalizedZoomValue,
|
||||||
|
): boolean => {
|
||||||
|
if (points.length >= 3) {
|
||||||
|
const [first, last] = [points[0], points[points.length - 1]];
|
||||||
|
const distance = pointDistance(first, last);
|
||||||
|
|
||||||
|
// Adjusting LINE_CONFIRM_THRESHOLD to current zoom so that when zoomed in
|
||||||
|
// really close we make the threshold smaller, and vice versa.
|
||||||
|
return distance <= LINE_CONFIRM_THRESHOLD / zoomValue;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const toggleLinePolygonState = (
|
||||||
|
element: ExcalidrawLineElement,
|
||||||
|
nextPolygonState: boolean,
|
||||||
|
): {
|
||||||
|
polygon: ExcalidrawLineElement["polygon"];
|
||||||
|
points: ExcalidrawLineElement["points"];
|
||||||
|
} | null => {
|
||||||
|
const updatedPoints = [...element.points];
|
||||||
|
|
||||||
|
if (nextPolygonState) {
|
||||||
|
if (!canBecomePolygon(element.points)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstPoint = updatedPoints[0];
|
||||||
|
const lastPoint = updatedPoints[updatedPoints.length - 1];
|
||||||
|
|
||||||
|
const distance = Math.hypot(
|
||||||
|
firstPoint[0] - lastPoint[0],
|
||||||
|
firstPoint[1] - lastPoint[1],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
distance > LINE_POLYGON_POINT_MERGE_DISTANCE ||
|
||||||
|
updatedPoints.length < 4
|
||||||
|
) {
|
||||||
|
updatedPoints.push(pointFrom(firstPoint[0], firstPoint[1]));
|
||||||
|
} else {
|
||||||
|
updatedPoints[updatedPoints.length - 1] = pointFrom(
|
||||||
|
firstPoint[0],
|
||||||
|
firstPoint[1],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: satisfies ElementUpdate<ExcalidrawLineElement>
|
||||||
|
const ret = {
|
||||||
|
polygon: nextPolygonState,
|
||||||
|
points: updatedPoints,
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
@@ -23,12 +23,8 @@ import {
|
|||||||
syncInvalidIndicesImmutable,
|
syncInvalidIndicesImmutable,
|
||||||
hashElementsVersion,
|
hashElementsVersion,
|
||||||
hashString,
|
hashString,
|
||||||
isInitializedImageElement,
|
|
||||||
isImageElement,
|
|
||||||
} from "./index";
|
} from "./index";
|
||||||
|
|
||||||
import type { ApplyToOptions } from "./delta";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
OrderedExcalidrawElement,
|
OrderedExcalidrawElement,
|
||||||
@@ -76,9 +72,8 @@ type MicroActionsQueue = (() => void)[];
|
|||||||
* Store which captures the observed changes and emits them as `StoreIncrement` events.
|
* Store which captures the observed changes and emits them as `StoreIncrement` events.
|
||||||
*/
|
*/
|
||||||
export class Store {
|
export class Store {
|
||||||
// for internal use by history
|
// internally used by history
|
||||||
public readonly onDurableIncrementEmitter = new Emitter<[DurableIncrement]>();
|
public readonly onDurableIncrementEmitter = new Emitter<[DurableIncrement]>();
|
||||||
// for public use as part of onIncrement API
|
|
||||||
public readonly onStoreIncrementEmitter = new Emitter<
|
public readonly onStoreIncrementEmitter = new Emitter<
|
||||||
[DurableIncrement | EphemeralIncrement]
|
[DurableIncrement | EphemeralIncrement]
|
||||||
>();
|
>();
|
||||||
@@ -142,8 +137,6 @@ export class Store {
|
|||||||
} else {
|
} else {
|
||||||
// immediately create an immutable change of the scheduled updates,
|
// immediately create an immutable change of the scheduled updates,
|
||||||
// compared to the current state, so that they won't mutate later on during batching
|
// compared to the current state, so that they won't mutate later on during batching
|
||||||
// also, we have to compare against the current state,
|
|
||||||
// as comparing against the snapshot might include yet uncomitted changes (i.e. async freedraw / text / image, etc.)
|
|
||||||
const currentSnapshot = StoreSnapshot.create(
|
const currentSnapshot = StoreSnapshot.create(
|
||||||
this.app.scene.getElementsMapIncludingDeleted(),
|
this.app.scene.getElementsMapIncludingDeleted(),
|
||||||
this.app.state,
|
this.app.state,
|
||||||
@@ -240,6 +233,7 @@ export class Store {
|
|||||||
if (!storeDelta.isEmpty()) {
|
if (!storeDelta.isEmpty()) {
|
||||||
const increment = new DurableIncrement(storeChange, storeDelta);
|
const increment = new DurableIncrement(storeChange, storeDelta);
|
||||||
|
|
||||||
|
// Notify listeners with the increment
|
||||||
this.onDurableIncrementEmitter.trigger(increment);
|
this.onDurableIncrementEmitter.trigger(increment);
|
||||||
this.onStoreIncrementEmitter.trigger(increment);
|
this.onStoreIncrementEmitter.trigger(increment);
|
||||||
}
|
}
|
||||||
@@ -552,26 +546,10 @@ export class StoreDelta {
|
|||||||
public static load({
|
public static load({
|
||||||
id,
|
id,
|
||||||
elements: { added, removed, updated },
|
elements: { added, removed, updated },
|
||||||
appState: { delta: appStateDelta },
|
|
||||||
}: DTO<StoreDelta>) {
|
}: DTO<StoreDelta>) {
|
||||||
const elements = ElementsDelta.create(added, removed, updated);
|
const elements = ElementsDelta.create(added, removed, updated);
|
||||||
const appState = AppStateDelta.create(appStateDelta);
|
|
||||||
|
|
||||||
return new this(id, elements, appState);
|
return new this(id, elements, AppStateDelta.empty());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Squash the passed deltas into the aggregated delta instance.
|
|
||||||
*/
|
|
||||||
public static squash(...deltas: StoreDelta[]) {
|
|
||||||
const aggregatedDelta = StoreDelta.empty();
|
|
||||||
|
|
||||||
for (const delta of deltas) {
|
|
||||||
aggregatedDelta.elements.squash(delta.elements);
|
|
||||||
aggregatedDelta.appState.squash(delta.appState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return aggregatedDelta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -588,13 +566,9 @@ export class StoreDelta {
|
|||||||
delta: StoreDelta,
|
delta: StoreDelta,
|
||||||
elements: SceneElementsMap,
|
elements: SceneElementsMap,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
options?: ApplyToOptions,
|
|
||||||
): [SceneElementsMap, AppState, boolean] {
|
): [SceneElementsMap, AppState, boolean] {
|
||||||
const [nextElements, elementsContainVisibleChange] = delta.elements.applyTo(
|
const [nextElements, elementsContainVisibleChange] =
|
||||||
elements,
|
delta.elements.applyTo(elements);
|
||||||
StoreSnapshot.empty().elements,
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
|
|
||||||
const [nextAppState, appStateContainsVisibleChange] =
|
const [nextAppState, appStateContainsVisibleChange] =
|
||||||
delta.appState.applyTo(appState, nextElements);
|
delta.appState.applyTo(appState, nextElements);
|
||||||
@@ -627,10 +601,6 @@ export class StoreDelta {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static empty() {
|
|
||||||
return StoreDelta.create(ElementsDelta.empty(), AppStateDelta.empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
public isEmpty() {
|
public isEmpty() {
|
||||||
return this.elements.isEmpty() && this.appState.isEmpty();
|
return this.elements.isEmpty() && this.appState.isEmpty();
|
||||||
}
|
}
|
||||||
@@ -899,7 +869,7 @@ export class StoreSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect if there are any changed elements.
|
* Detect if there any changed elements.
|
||||||
*/
|
*/
|
||||||
private detectChangedElements(
|
private detectChangedElements(
|
||||||
nextElements: SceneElementsMap,
|
nextElements: SceneElementsMap,
|
||||||
@@ -934,14 +904,6 @@ export class StoreSnapshot {
|
|||||||
!prevElement || // element was added
|
!prevElement || // element was added
|
||||||
prevElement.version < nextElement.version // element was updated
|
prevElement.version < nextElement.version // element was updated
|
||||||
) {
|
) {
|
||||||
if (
|
|
||||||
isImageElement(nextElement) &&
|
|
||||||
!isInitializedImageElement(nextElement)
|
|
||||||
) {
|
|
||||||
// ignore any updates on uninitialized image elements
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
changedElements.set(nextElement.id, nextElement);
|
changedElements.set(nextElement.id, nextElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -996,7 +958,8 @@ const getDefaultObservedAppState = (): ObservedAppState => {
|
|||||||
viewBackgroundColor: COLOR_PALETTE.white,
|
viewBackgroundColor: COLOR_PALETTE.white,
|
||||||
selectedElementIds: {},
|
selectedElementIds: {},
|
||||||
selectedGroupIds: {},
|
selectedGroupIds: {},
|
||||||
selectedLinearElement: null,
|
editingLinearElementId: null,
|
||||||
|
selectedLinearElementId: null,
|
||||||
croppingElementId: null,
|
croppingElementId: null,
|
||||||
activeLockedId: null,
|
activeLockedId: null,
|
||||||
lockedMultiSelections: {},
|
lockedMultiSelections: {},
|
||||||
@@ -1015,12 +978,14 @@ export const getObservedAppState = (
|
|||||||
croppingElementId: appState.croppingElementId,
|
croppingElementId: appState.croppingElementId,
|
||||||
activeLockedId: appState.activeLockedId,
|
activeLockedId: appState.activeLockedId,
|
||||||
lockedMultiSelections: appState.lockedMultiSelections,
|
lockedMultiSelections: appState.lockedMultiSelections,
|
||||||
selectedLinearElement: appState.selectedLinearElement
|
editingLinearElementId:
|
||||||
? {
|
(appState as AppState).editingLinearElement?.elementId ?? // prefer app state, as it's likely newer
|
||||||
elementId: appState.selectedLinearElement.elementId,
|
(appState as ObservedAppState).editingLinearElementId ?? // fallback to observed app state, as it's likely older coming from a previous snapshot
|
||||||
isEditing: !!appState.selectedLinearElement.isEditing,
|
null,
|
||||||
}
|
selectedLinearElementId:
|
||||||
: null,
|
(appState as AppState).selectedLinearElement?.elementId ??
|
||||||
|
(appState as ObservedAppState).selectedLinearElementId ??
|
||||||
|
null,
|
||||||
};
|
};
|
||||||
|
|
||||||
Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
|
Reflect.defineProperty(observedAppState, hiddenObservedAppStateProp, {
|
||||||
|
|||||||
@@ -326,7 +326,10 @@ export const getContainerCenter = (
|
|||||||
if (!midSegmentMidpoint) {
|
if (!midSegmentMidpoint) {
|
||||||
midSegmentMidpoint = LinearElementEditor.getSegmentMidPoint(
|
midSegmentMidpoint = LinearElementEditor.getSegmentMidPoint(
|
||||||
container,
|
container,
|
||||||
|
points[index],
|
||||||
|
points[index + 1],
|
||||||
index + 1,
|
index + 1,
|
||||||
|
elementsMap,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return { x: midSegmentMidpoint[0], y: midSegmentMidpoint[1] };
|
return { x: midSegmentMidpoint[0], y: midSegmentMidpoint[1] };
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ export const shouldShowBoundingBox = (
|
|||||||
elements: readonly NonDeletedExcalidrawElement[],
|
elements: readonly NonDeletedExcalidrawElement[],
|
||||||
appState: InteractiveCanvasAppState,
|
appState: InteractiveCanvasAppState,
|
||||||
) => {
|
) => {
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
if (appState.editingLinearElement) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (elements.length > 1) {
|
if (elements.length > 1) {
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
import {
|
|
||||||
DEFAULT_ADAPTIVE_RADIUS,
|
|
||||||
DEFAULT_PROPORTIONAL_RADIUS,
|
|
||||||
LINE_CONFIRM_THRESHOLD,
|
|
||||||
ROUNDNESS,
|
|
||||||
} from "@excalidraw/common";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
curve,
|
curve,
|
||||||
curveCatmullRomCubicApproxPoints,
|
curveCatmullRomCubicApproxPoints,
|
||||||
curveOffsetPoints,
|
curveOffsetPoints,
|
||||||
lineSegment,
|
lineSegment,
|
||||||
pointDistance,
|
|
||||||
pointFrom,
|
pointFrom,
|
||||||
pointFromArray,
|
pointFromArray,
|
||||||
rectangle,
|
rectangle,
|
||||||
@@ -19,13 +11,14 @@ import {
|
|||||||
|
|
||||||
import type { Curve, LineSegment, LocalPoint } from "@excalidraw/math";
|
import type { Curve, LineSegment, LocalPoint } from "@excalidraw/math";
|
||||||
|
|
||||||
import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types";
|
import { getCornerRadius } from "./shapes";
|
||||||
|
|
||||||
import { getDiamondPoints } from "./bounds";
|
import { getDiamondPoints } from "./bounds";
|
||||||
|
|
||||||
import { generateLinearCollisionShape } from "./shape";
|
import { generateLinearCollisionShape } from "./Shape";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
ElementsMap,
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawFreeDrawElement,
|
ExcalidrawFreeDrawElement,
|
||||||
@@ -90,14 +83,9 @@ const setElementShapesCacheEntry = <T extends ExcalidrawElement>(
|
|||||||
shapes.set(offset, shape);
|
shapes.set(offset, shape);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the **rotated** components of freedraw, line or arrow elements.
|
|
||||||
*
|
|
||||||
* @param element The linear element to deconstruct
|
|
||||||
* @returns The rotated in components.
|
|
||||||
*/
|
|
||||||
export function deconstructLinearOrFreeDrawElement(
|
export function deconstructLinearOrFreeDrawElement(
|
||||||
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
element: ExcalidrawLinearElement | ExcalidrawFreeDrawElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
): [LineSegment<GlobalPoint>[], Curve<GlobalPoint>[]] {
|
): [LineSegment<GlobalPoint>[], Curve<GlobalPoint>[]] {
|
||||||
const cachedShape = getElementShapesCacheEntry(element, 0);
|
const cachedShape = getElementShapesCacheEntry(element, 0);
|
||||||
|
|
||||||
@@ -105,7 +93,7 @@ export function deconstructLinearOrFreeDrawElement(
|
|||||||
return cachedShape;
|
return cachedShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ops = generateLinearCollisionShape(element) as {
|
const ops = generateLinearCollisionShape(element, elementsMap) as {
|
||||||
op: string;
|
op: string;
|
||||||
data: number[];
|
data: number[];
|
||||||
}[];
|
}[];
|
||||||
@@ -177,11 +165,11 @@ export function deconstructLinearOrFreeDrawElement(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the building components of a rectanguloid element in the form of
|
* Get the building components of a rectanguloid element in the form of
|
||||||
* line segments and curves **unrotated**.
|
* line segments and curves.
|
||||||
*
|
*
|
||||||
* @param element Target rectanguloid element
|
* @param element Target rectanguloid element
|
||||||
* @param offset Optional offset to expand the rectanguloid shape
|
* @param offset Optional offset to expand the rectanguloid shape
|
||||||
* @returns Tuple of **unrotated** line segments (0) and curves (1)
|
* @returns Tuple of line segments (0) and curves (1)
|
||||||
*/
|
*/
|
||||||
export function deconstructRectanguloidElement(
|
export function deconstructRectanguloidElement(
|
||||||
element: ExcalidrawRectanguloidElement,
|
element: ExcalidrawRectanguloidElement,
|
||||||
@@ -316,12 +304,12 @@ export function deconstructRectanguloidElement(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the **unrotated** building components of a diamond element
|
* Get the building components of a diamond element in the form of
|
||||||
* in the form of line segments and curves as a tuple, in this order.
|
* line segments and curves as a tuple, in this order.
|
||||||
*
|
*
|
||||||
* @param element The element to deconstruct
|
* @param element The element to deconstruct
|
||||||
* @param offset An optional offset
|
* @param offset An optional offset
|
||||||
* @returns Tuple of line **unrotated** segments (0) and curves (1)
|
* @returns Tuple of line segments (0) and curves (1)
|
||||||
*/
|
*/
|
||||||
export function deconstructDiamondElement(
|
export function deconstructDiamondElement(
|
||||||
element: ExcalidrawDiamondElement,
|
element: ExcalidrawDiamondElement,
|
||||||
@@ -440,44 +428,3 @@ export function deconstructDiamondElement(
|
|||||||
|
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if the first and last point are close enough
|
|
||||||
// to be considered a loop
|
|
||||||
export const isPathALoop = (
|
|
||||||
points: ExcalidrawLinearElement["points"],
|
|
||||||
/** supply if you want the loop detection to account for current zoom */
|
|
||||||
zoomValue: Zoom["value"] = 1 as NormalizedZoomValue,
|
|
||||||
): boolean => {
|
|
||||||
if (points.length >= 3) {
|
|
||||||
const [first, last] = [points[0], points[points.length - 1]];
|
|
||||||
const distance = pointDistance(first, last);
|
|
||||||
|
|
||||||
// Adjusting LINE_CONFIRM_THRESHOLD to current zoom so that when zoomed in
|
|
||||||
// really close we make the threshold smaller, and vice versa.
|
|
||||||
return distance <= LINE_CONFIRM_THRESHOLD / zoomValue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getCornerRadius = (x: number, element: ExcalidrawElement) => {
|
|
||||||
if (
|
|
||||||
element.roundness?.type === ROUNDNESS.PROPORTIONAL_RADIUS ||
|
|
||||||
element.roundness?.type === ROUNDNESS.LEGACY
|
|
||||||
) {
|
|
||||||
return x * DEFAULT_PROPORTIONAL_RADIUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.roundness?.type === ROUNDNESS.ADAPTIVE_RADIUS) {
|
|
||||||
const fixedRadiusSize = element.roundness?.value ?? DEFAULT_ADAPTIVE_RADIUS;
|
|
||||||
|
|
||||||
const CUTOFF_SIZE = fixedRadiusSize / DEFAULT_PROPORTIONAL_RADIUS;
|
|
||||||
|
|
||||||
if (x <= CUTOFF_SIZE) {
|
|
||||||
return x * DEFAULT_PROPORTIONAL_RADIUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fixedRadiusSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -589,424 +589,4 @@ describe("aligning", () => {
|
|||||||
expect(API.getSelectedElements()[2].x).toEqual(250);
|
expect(API.getSelectedElements()[2].x).toEqual(250);
|
||||||
expect(API.getSelectedElements()[3].x).toEqual(150);
|
expect(API.getSelectedElements()[3].x).toEqual(150);
|
||||||
});
|
});
|
||||||
|
|
||||||
const createGroupAndSelectInEditGroupMode = () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(0, 0);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
// select the first element.
|
|
||||||
// The second rectangle is already reselected because it was the last element created
|
|
||||||
mouse.reset();
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.moveTo(10, 0);
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
API.executeAction(actionGroup);
|
|
||||||
mouse.reset();
|
|
||||||
mouse.moveTo(10, 0);
|
|
||||||
mouse.doubleClick();
|
|
||||||
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.click();
|
|
||||||
mouse.moveTo(100, 100);
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
it("aligns elements within a group while in group edit mode correctly to the top", () => {
|
|
||||||
createGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignTop);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns elements within a group while in group edit mode correctly to the bottom", () => {
|
|
||||||
createGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignBottom);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
});
|
|
||||||
it("aligns elements within a group while in group edit mode correctly to the left", () => {
|
|
||||||
createGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignLeft);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns elements within a group while in group edit mode correctly to the right", () => {
|
|
||||||
createGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignRight);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
});
|
|
||||||
it("aligns elements within a group while in group edit mode correctly to the vertical center", () => {
|
|
||||||
createGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignVerticallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(50);
|
|
||||||
});
|
|
||||||
it("aligns elements within a group while in group edit mode correctly to the horizontal center", () => {
|
|
||||||
createGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignHorizontallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(50);
|
|
||||||
});
|
|
||||||
|
|
||||||
const createNestedGroupAndSelectInEditGroupMode = () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(0, 0);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
// Select the first element.
|
|
||||||
// The second rectangle is already reselected because it was the last element created
|
|
||||||
mouse.reset();
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.moveTo(10, 0);
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
API.executeAction(actionGroup);
|
|
||||||
|
|
||||||
mouse.reset();
|
|
||||||
mouse.moveTo(200, 200);
|
|
||||||
// create third element
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(0, 0);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
// third element is already selected, select the initial group and group together
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.moveTo(10, 0);
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
API.executeAction(actionGroup);
|
|
||||||
|
|
||||||
// double click to enter edit mode
|
|
||||||
mouse.doubleClick();
|
|
||||||
|
|
||||||
// select nested group and other element within the group
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.moveTo(200, 200);
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
it("aligns element and nested group while in group edit mode correctly to the top", () => {
|
|
||||||
createNestedGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignTop);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns element and nested group while in group edit mode correctly to the bottom", () => {
|
|
||||||
createNestedGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignBottom);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(200);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
});
|
|
||||||
it("aligns element and nested group while in group edit mode correctly to the left", () => {
|
|
||||||
createNestedGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignLeft);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns element and nested group while in group edit mode correctly to the right", () => {
|
|
||||||
createNestedGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignRight);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(200);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
});
|
|
||||||
it("aligns element and nested group while in group edit mode correctly to the vertical center", () => {
|
|
||||||
createNestedGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignVerticallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(150);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(100);
|
|
||||||
});
|
|
||||||
it("aligns elements and nested group within a group while in group edit mode correctly to the horizontal center", () => {
|
|
||||||
createNestedGroupAndSelectInEditGroupMode();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignHorizontallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(150);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(100);
|
|
||||||
});
|
|
||||||
|
|
||||||
const createAndSelectSingleGroup = () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(0, 0);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
// Select the first element.
|
|
||||||
// The second rectangle is already reselected because it was the last element created
|
|
||||||
mouse.reset();
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.moveTo(10, 0);
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
API.executeAction(actionGroup);
|
|
||||||
};
|
|
||||||
|
|
||||||
it("aligns elements within a single-selected group correctly to the top", () => {
|
|
||||||
createAndSelectSingleGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignTop);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group correctly to the bottom", () => {
|
|
||||||
createAndSelectSingleGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignBottom);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group correctly to the left", () => {
|
|
||||||
createAndSelectSingleGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignLeft);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group correctly to the right", () => {
|
|
||||||
createAndSelectSingleGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignRight);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group correctly to the vertical center", () => {
|
|
||||||
createAndSelectSingleGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignVerticallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(50);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group correctly to the horizontal center", () => {
|
|
||||||
createAndSelectSingleGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignHorizontallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(50);
|
|
||||||
});
|
|
||||||
|
|
||||||
const createAndSelectSingleGroupWithNestedGroup = () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(0, 0);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
// Select the first element.
|
|
||||||
// The second rectangle is already reselected because it was the last element created
|
|
||||||
mouse.reset();
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.moveTo(10, 0);
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
API.executeAction(actionGroup);
|
|
||||||
|
|
||||||
mouse.reset();
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(200, 200);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
// Add group to current selection
|
|
||||||
mouse.restorePosition(10, 0);
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create the nested group
|
|
||||||
API.executeAction(actionGroup);
|
|
||||||
};
|
|
||||||
it("aligns elements within a single-selected group containing a nested group correctly to the top", () => {
|
|
||||||
createAndSelectSingleGroupWithNestedGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignTop);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group containing a nested group correctly to the bottom", () => {
|
|
||||||
createAndSelectSingleGroupWithNestedGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignBottom);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(200);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group containing a nested group correctly to the left", () => {
|
|
||||||
createAndSelectSingleGroupWithNestedGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignLeft);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(0);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group containing a nested group correctly to the right", () => {
|
|
||||||
createAndSelectSingleGroupWithNestedGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignRight);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(200);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group containing a nested group correctly to the vertical center", () => {
|
|
||||||
createAndSelectSingleGroupWithNestedGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignVerticallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(150);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(100);
|
|
||||||
});
|
|
||||||
it("aligns elements within a single-selected group containing a nested group correctly to the horizontal center", () => {
|
|
||||||
createAndSelectSingleGroupWithNestedGroup();
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(actionAlignHorizontallyCentered);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(150);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(100);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -155,10 +155,10 @@ describe("element binding", () => {
|
|||||||
// NOTE this mouse down/up + await needs to be done in order to repro
|
// NOTE this mouse down/up + await needs to be done in order to repro
|
||||||
// the issue, due to https://github.com/excalidraw/excalidraw/blob/46bff3daceb602accf60c40a84610797260fca94/src/components/App.tsx#L740
|
// the issue, due to https://github.com/excalidraw/excalidraw/blob/46bff3daceb602accf60c40a84610797260fca94/src/components/App.tsx#L740
|
||||||
mouse.reset();
|
mouse.reset();
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement).not.toBe(null);
|
||||||
mouse.down(0, 0);
|
mouse.down(0, 0);
|
||||||
await new Promise((r) => setTimeout(r, 100));
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement).toBe(null);
|
||||||
expect(API.getSelectedElement().type).toBe("rectangle");
|
expect(API.getSelectedElement().type).toBe("rectangle");
|
||||||
mouse.up();
|
mouse.up();
|
||||||
expect(API.getSelectedElement().type).toBe("rectangle");
|
expect(API.getSelectedElement().type).toBe("rectangle");
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ describe("check rotated elements can be hit:", () => {
|
|||||||
//const p = [120, -211];
|
//const p = [120, -211];
|
||||||
//const p = [0, 13];
|
//const p = [0, 13];
|
||||||
const hit = hitElementItself({
|
const hit = hitElementItself({
|
||||||
point: pointFrom<GlobalPoint>(88, -68),
|
point: pointFrom<GlobalPoint>(87, -68),
|
||||||
element: window.h.elements[0],
|
element: window.h.elements[0],
|
||||||
threshold: 10,
|
threshold: 10,
|
||||||
elementsMap: window.h.scene.getNonDeletedElementsMap(),
|
elementsMap: window.h.scene.getNonDeletedElementsMap(),
|
||||||
|
|||||||
@@ -1,328 +1,13 @@
|
|||||||
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
|
||||||
|
|
||||||
import type { ObservedAppState } from "@excalidraw/excalidraw/types";
|
import type { ObservedAppState } from "@excalidraw/excalidraw/types";
|
||||||
import type { LinearElementEditor } from "@excalidraw/element";
|
import type { LinearElementEditor } from "@excalidraw/element";
|
||||||
import type { SceneElementsMap } from "@excalidraw/element/types";
|
|
||||||
|
|
||||||
import { AppStateDelta, Delta, ElementsDelta } from "../src/delta";
|
import { AppStateDelta } from "../src/delta";
|
||||||
|
|
||||||
describe("ElementsDelta", () => {
|
|
||||||
describe("elements delta calculation", () => {
|
|
||||||
it("should not create removed delta when element gets removed but was already deleted", () => {
|
|
||||||
const element = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 100,
|
|
||||||
y: 100,
|
|
||||||
isDeleted: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const prevElements = new Map([[element.id, element]]);
|
|
||||||
const nextElements = new Map();
|
|
||||||
|
|
||||||
const delta = ElementsDelta.calculate(prevElements, nextElements);
|
|
||||||
|
|
||||||
expect(delta.isEmpty()).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should not create added delta when adding element as already deleted", () => {
|
|
||||||
const element = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 100,
|
|
||||||
y: 100,
|
|
||||||
isDeleted: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const prevElements = new Map();
|
|
||||||
const nextElements = new Map([[element.id, element]]);
|
|
||||||
|
|
||||||
const delta = ElementsDelta.calculate(prevElements, nextElements);
|
|
||||||
|
|
||||||
expect(delta.isEmpty()).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should not create updated delta when there is only version and versionNonce change", () => {
|
|
||||||
const baseElement = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 100,
|
|
||||||
y: 100,
|
|
||||||
strokeColor: "#000000",
|
|
||||||
backgroundColor: "#ffffff",
|
|
||||||
});
|
|
||||||
|
|
||||||
const modifiedElement = {
|
|
||||||
...baseElement,
|
|
||||||
version: baseElement.version + 1,
|
|
||||||
versionNonce: baseElement.versionNonce + 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create maps for the delta calculation
|
|
||||||
const prevElements = new Map([[baseElement.id, baseElement]]);
|
|
||||||
const nextElements = new Map([[modifiedElement.id, modifiedElement]]);
|
|
||||||
|
|
||||||
// Calculate the delta
|
|
||||||
const delta = ElementsDelta.calculate(
|
|
||||||
prevElements as SceneElementsMap,
|
|
||||||
nextElements as SceneElementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(delta.isEmpty()).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("squash", () => {
|
|
||||||
it("should not squash when second delta is empty", () => {
|
|
||||||
const updatedDelta = Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1 },
|
|
||||||
{ x: 200, version: 2, versionNonce: 2 },
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta1 = ElementsDelta.create(
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{ id1: updatedDelta },
|
|
||||||
);
|
|
||||||
const elementsDelta2 = ElementsDelta.empty();
|
|
||||||
const elementsDelta = elementsDelta1.squash(elementsDelta2);
|
|
||||||
|
|
||||||
expect(elementsDelta.isEmpty()).toBeFalsy();
|
|
||||||
expect(elementsDelta).toBe(elementsDelta1);
|
|
||||||
expect(elementsDelta.updated.id1).toBe(updatedDelta);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should squash mutually exclusive delta types", () => {
|
|
||||||
const addedDelta = Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1, isDeleted: true },
|
|
||||||
{ x: 200, version: 2, versionNonce: 2, isDeleted: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
const removedDelta = Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1, isDeleted: false },
|
|
||||||
{ x: 200, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedDelta = Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1 },
|
|
||||||
{ x: 200, version: 2, versionNonce: 2 },
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta1 = ElementsDelta.create(
|
|
||||||
{ id1: addedDelta },
|
|
||||||
{ id2: removedDelta },
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta2 = ElementsDelta.create(
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{ id3: updatedDelta },
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta = elementsDelta1.squash(elementsDelta2);
|
|
||||||
|
|
||||||
expect(elementsDelta.isEmpty()).toBeFalsy();
|
|
||||||
expect(elementsDelta).toBe(elementsDelta1);
|
|
||||||
expect(elementsDelta.added.id1).toBe(addedDelta);
|
|
||||||
expect(elementsDelta.removed.id2).toBe(removedDelta);
|
|
||||||
expect(elementsDelta.updated.id3).toBe(updatedDelta);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should squash the same delta types", () => {
|
|
||||||
const elementsDelta1 = ElementsDelta.create(
|
|
||||||
{
|
|
||||||
id1: Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1, isDeleted: true },
|
|
||||||
{ x: 200, version: 2, versionNonce: 2, isDeleted: false },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id2: Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1, isDeleted: false },
|
|
||||||
{ x: 200, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id3: Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1 },
|
|
||||||
{ x: 200, version: 2, versionNonce: 2 },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta2 = ElementsDelta.create(
|
|
||||||
{
|
|
||||||
id1: Delta.create(
|
|
||||||
{ y: 100, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
{ y: 200, version: 3, versionNonce: 3, isDeleted: false },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id2: Delta.create(
|
|
||||||
{ y: 100, version: 2, versionNonce: 2, isDeleted: false },
|
|
||||||
{ y: 200, version: 3, versionNonce: 3, isDeleted: true },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id3: Delta.create(
|
|
||||||
{ y: 100, version: 2, versionNonce: 2 },
|
|
||||||
{ y: 200, version: 3, versionNonce: 3 },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta = elementsDelta1.squash(elementsDelta2);
|
|
||||||
|
|
||||||
expect(elementsDelta.isEmpty()).toBeFalsy();
|
|
||||||
expect(elementsDelta).toBe(elementsDelta1);
|
|
||||||
expect(elementsDelta.added.id1).toEqual(
|
|
||||||
Delta.create(
|
|
||||||
{ x: 100, y: 100, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
{ x: 200, y: 200, version: 3, versionNonce: 3, isDeleted: false },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(elementsDelta.removed.id2).toEqual(
|
|
||||||
Delta.create(
|
|
||||||
{ x: 100, y: 100, version: 2, versionNonce: 2, isDeleted: false },
|
|
||||||
{ x: 200, y: 200, version: 3, versionNonce: 3, isDeleted: true },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(elementsDelta.updated.id3).toEqual(
|
|
||||||
Delta.create(
|
|
||||||
{ x: 100, y: 100, version: 2, versionNonce: 2 },
|
|
||||||
{ x: 200, y: 200, version: 3, versionNonce: 3 },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should squash different delta types ", () => {
|
|
||||||
// id1: added -> updated => added
|
|
||||||
// id2: removed -> added => added
|
|
||||||
// id3: updated -> removed => removed
|
|
||||||
const elementsDelta1 = ElementsDelta.create(
|
|
||||||
{
|
|
||||||
id1: Delta.create(
|
|
||||||
{ x: 100, version: 1, versionNonce: 1, isDeleted: true },
|
|
||||||
{ x: 101, version: 2, versionNonce: 2, isDeleted: false },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id2: Delta.create(
|
|
||||||
{ x: 200, version: 1, versionNonce: 1, isDeleted: false },
|
|
||||||
{ x: 201, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id3: Delta.create(
|
|
||||||
{ x: 300, version: 1, versionNonce: 1 },
|
|
||||||
{ x: 301, version: 2, versionNonce: 2 },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta2 = ElementsDelta.create(
|
|
||||||
{
|
|
||||||
id2: Delta.create(
|
|
||||||
{ y: 200, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
{ y: 201, version: 3, versionNonce: 3, isDeleted: false },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id3: Delta.create(
|
|
||||||
{ y: 300, version: 2, versionNonce: 2, isDeleted: false },
|
|
||||||
{ y: 301, version: 3, versionNonce: 3, isDeleted: true },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id1: Delta.create(
|
|
||||||
{ y: 100, version: 2, versionNonce: 2 },
|
|
||||||
{ y: 101, version: 3, versionNonce: 3 },
|
|
||||||
),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta = elementsDelta1.squash(elementsDelta2);
|
|
||||||
|
|
||||||
expect(elementsDelta.isEmpty()).toBeFalsy();
|
|
||||||
expect(elementsDelta).toBe(elementsDelta1);
|
|
||||||
expect(elementsDelta.added).toEqual({
|
|
||||||
id1: Delta.create(
|
|
||||||
{ x: 100, y: 100, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
{ x: 101, y: 101, version: 3, versionNonce: 3, isDeleted: false },
|
|
||||||
),
|
|
||||||
id2: Delta.create(
|
|
||||||
{ x: 200, y: 200, version: 2, versionNonce: 2, isDeleted: true },
|
|
||||||
{ x: 201, y: 201, version: 3, versionNonce: 3, isDeleted: false },
|
|
||||||
),
|
|
||||||
});
|
|
||||||
expect(elementsDelta.removed).toEqual({
|
|
||||||
id3: Delta.create(
|
|
||||||
{ x: 300, y: 300, version: 2, versionNonce: 2, isDeleted: false },
|
|
||||||
{ x: 301, y: 301, version: 3, versionNonce: 3, isDeleted: true },
|
|
||||||
),
|
|
||||||
});
|
|
||||||
expect(elementsDelta.updated).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should squash bound elements", () => {
|
|
||||||
const elementsDelta1 = ElementsDelta.create(
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
id1: Delta.create(
|
|
||||||
{
|
|
||||||
version: 1,
|
|
||||||
versionNonce: 1,
|
|
||||||
boundElements: [{ id: "t1", type: "text" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
version: 2,
|
|
||||||
versionNonce: 2,
|
|
||||||
boundElements: [{ id: "t2", type: "text" }],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta2 = ElementsDelta.create(
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
id1: Delta.create(
|
|
||||||
{
|
|
||||||
version: 2,
|
|
||||||
versionNonce: 2,
|
|
||||||
boundElements: [{ id: "a1", type: "arrow" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
version: 3,
|
|
||||||
versionNonce: 3,
|
|
||||||
boundElements: [{ id: "a2", type: "arrow" }],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const elementsDelta = elementsDelta1.squash(elementsDelta2);
|
|
||||||
|
|
||||||
expect(elementsDelta.updated.id1.deleted.boundElements).toEqual([
|
|
||||||
{ id: "t1", type: "text" },
|
|
||||||
{ id: "a1", type: "arrow" },
|
|
||||||
]);
|
|
||||||
expect(elementsDelta.updated.id1.inserted.boundElements).toEqual([
|
|
||||||
{ id: "t2", type: "text" },
|
|
||||||
{ id: "a2", type: "arrow" },
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("AppStateDelta", () => {
|
describe("AppStateDelta", () => {
|
||||||
describe("ensure stable delta properties order", () => {
|
describe("ensure stable delta properties order", () => {
|
||||||
it("should maintain stable order for root properties", () => {
|
it("should maintain stable order for root properties", () => {
|
||||||
const name = "untitled scene";
|
const name = "untitled scene";
|
||||||
const selectedLinearElement = {
|
const selectedLinearElementId = "id1" as LinearElementEditor["elementId"];
|
||||||
elementId: "id1" as LinearElementEditor["elementId"],
|
|
||||||
isEditing: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
const commonAppState = {
|
const commonAppState = {
|
||||||
viewBackgroundColor: "#ffffff",
|
viewBackgroundColor: "#ffffff",
|
||||||
@@ -331,7 +16,6 @@ describe("AppStateDelta", () => {
|
|||||||
editingGroupId: null,
|
editingGroupId: null,
|
||||||
croppingElementId: null,
|
croppingElementId: null,
|
||||||
editingLinearElementId: null,
|
editingLinearElementId: null,
|
||||||
selectedLinearElementIsEditing: null,
|
|
||||||
lockedMultiSelections: {},
|
lockedMultiSelections: {},
|
||||||
activeLockedId: null,
|
activeLockedId: null,
|
||||||
};
|
};
|
||||||
@@ -339,23 +23,23 @@ describe("AppStateDelta", () => {
|
|||||||
const prevAppState1: ObservedAppState = {
|
const prevAppState1: ObservedAppState = {
|
||||||
...commonAppState,
|
...commonAppState,
|
||||||
name: "",
|
name: "",
|
||||||
selectedLinearElement: null,
|
selectedLinearElementId: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextAppState1: ObservedAppState = {
|
const nextAppState1: ObservedAppState = {
|
||||||
...commonAppState,
|
...commonAppState,
|
||||||
name,
|
name,
|
||||||
selectedLinearElement,
|
selectedLinearElementId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const prevAppState2: ObservedAppState = {
|
const prevAppState2: ObservedAppState = {
|
||||||
selectedLinearElement: null,
|
selectedLinearElementId: null,
|
||||||
name: "",
|
name: "",
|
||||||
...commonAppState,
|
...commonAppState,
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextAppState2: ObservedAppState = {
|
const nextAppState2: ObservedAppState = {
|
||||||
selectedLinearElement,
|
selectedLinearElementId,
|
||||||
name,
|
name,
|
||||||
...commonAppState,
|
...commonAppState,
|
||||||
};
|
};
|
||||||
@@ -373,7 +57,8 @@ describe("AppStateDelta", () => {
|
|||||||
selectedGroupIds: {},
|
selectedGroupIds: {},
|
||||||
editingGroupId: null,
|
editingGroupId: null,
|
||||||
croppingElementId: null,
|
croppingElementId: null,
|
||||||
selectedLinearElement: null,
|
selectedLinearElementId: null,
|
||||||
|
editingLinearElementId: null,
|
||||||
activeLockedId: null,
|
activeLockedId: null,
|
||||||
lockedMultiSelections: {},
|
lockedMultiSelections: {},
|
||||||
};
|
};
|
||||||
@@ -419,7 +104,8 @@ describe("AppStateDelta", () => {
|
|||||||
selectedElementIds: {},
|
selectedElementIds: {},
|
||||||
editingGroupId: null,
|
editingGroupId: null,
|
||||||
croppingElementId: null,
|
croppingElementId: null,
|
||||||
selectedLinearElement: null,
|
selectedLinearElementId: null,
|
||||||
|
editingLinearElementId: null,
|
||||||
activeLockedId: null,
|
activeLockedId: null,
|
||||||
lockedMultiSelections: {},
|
lockedMultiSelections: {},
|
||||||
};
|
};
|
||||||
@@ -460,97 +146,4 @@ describe("AppStateDelta", () => {
|
|||||||
expect(JSON.stringify(delta1)).toBe(JSON.stringify(delta2));
|
expect(JSON.stringify(delta1)).toBe(JSON.stringify(delta2));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("squash", () => {
|
|
||||||
it("should not squash when second delta is empty", () => {
|
|
||||||
const delta = Delta.create(
|
|
||||||
{ name: "untitled scene" },
|
|
||||||
{ name: "titled scene" },
|
|
||||||
);
|
|
||||||
|
|
||||||
const appStateDelta1 = AppStateDelta.create(delta);
|
|
||||||
const appStateDelta2 = AppStateDelta.empty();
|
|
||||||
const appStateDelta = appStateDelta1.squash(appStateDelta2);
|
|
||||||
|
|
||||||
expect(appStateDelta.isEmpty()).toBeFalsy();
|
|
||||||
expect(appStateDelta).toBe(appStateDelta1);
|
|
||||||
expect(appStateDelta.delta).toBe(delta);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should squash exclusive properties", () => {
|
|
||||||
const delta1 = Delta.create(
|
|
||||||
{ name: "untitled scene" },
|
|
||||||
{ name: "titled scene" },
|
|
||||||
);
|
|
||||||
const delta2 = Delta.create(
|
|
||||||
{ viewBackgroundColor: "#ffffff" },
|
|
||||||
{ viewBackgroundColor: "#000000" },
|
|
||||||
);
|
|
||||||
|
|
||||||
const appStateDelta1 = AppStateDelta.create(delta1);
|
|
||||||
const appStateDelta2 = AppStateDelta.create(delta2);
|
|
||||||
const appStateDelta = appStateDelta1.squash(appStateDelta2);
|
|
||||||
|
|
||||||
expect(appStateDelta.isEmpty()).toBeFalsy();
|
|
||||||
expect(appStateDelta).toBe(appStateDelta1);
|
|
||||||
expect(appStateDelta.delta).toEqual(
|
|
||||||
Delta.create(
|
|
||||||
{ name: "untitled scene", viewBackgroundColor: "#ffffff" },
|
|
||||||
{ name: "titled scene", viewBackgroundColor: "#000000" },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should squash selectedElementIds, selectedGroupIds and lockedMultiSelections", () => {
|
|
||||||
const delta1 = Delta.create<Partial<ObservedAppState>>(
|
|
||||||
{
|
|
||||||
name: "untitled scene",
|
|
||||||
selectedElementIds: { id1: true },
|
|
||||||
selectedGroupIds: {},
|
|
||||||
lockedMultiSelections: { g1: true },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "titled scene",
|
|
||||||
selectedElementIds: { id2: true },
|
|
||||||
selectedGroupIds: { g1: true },
|
|
||||||
lockedMultiSelections: {},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const delta2 = Delta.create<Partial<ObservedAppState>>(
|
|
||||||
{
|
|
||||||
selectedElementIds: { id3: true },
|
|
||||||
selectedGroupIds: { g1: true },
|
|
||||||
lockedMultiSelections: {},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
selectedElementIds: { id2: true },
|
|
||||||
selectedGroupIds: { g2: true, g3: true },
|
|
||||||
lockedMultiSelections: { g3: true },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const appStateDelta1 = AppStateDelta.create(delta1);
|
|
||||||
const appStateDelta2 = AppStateDelta.create(delta2);
|
|
||||||
const appStateDelta = appStateDelta1.squash(appStateDelta2);
|
|
||||||
|
|
||||||
expect(appStateDelta.isEmpty()).toBeFalsy();
|
|
||||||
expect(appStateDelta).toBe(appStateDelta1);
|
|
||||||
expect(appStateDelta.delta).toEqual(
|
|
||||||
Delta.create<Partial<ObservedAppState>>(
|
|
||||||
{
|
|
||||||
name: "untitled scene",
|
|
||||||
selectedElementIds: { id1: true, id3: true },
|
|
||||||
selectedGroupIds: { g1: true },
|
|
||||||
lockedMultiSelections: { g1: true },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "titled scene",
|
|
||||||
selectedElementIds: { id2: true },
|
|
||||||
selectedGroupIds: { g1: true, g2: true, g3: true },
|
|
||||||
lockedMultiSelections: { g3: true },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
import {
|
|
||||||
distributeHorizontally,
|
|
||||||
distributeVertically,
|
|
||||||
} from "@excalidraw/excalidraw/actions";
|
|
||||||
import { defaultLang, setLanguage } from "@excalidraw/excalidraw/i18n";
|
|
||||||
import { Excalidraw } from "@excalidraw/excalidraw";
|
|
||||||
|
|
||||||
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
|
||||||
import { UI, Pointer, Keyboard } from "@excalidraw/excalidraw/tests/helpers/ui";
|
|
||||||
import {
|
|
||||||
act,
|
|
||||||
unmountComponent,
|
|
||||||
render,
|
|
||||||
} from "@excalidraw/excalidraw/tests/test-utils";
|
|
||||||
|
|
||||||
const mouse = new Pointer("mouse");
|
|
||||||
|
|
||||||
// Scenario: three rectangles that will be distributed with gaps
|
|
||||||
const createAndSelectThreeRectanglesWithGap = () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(100, 100);
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(10, 10);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(300, 300);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
// Last rectangle is selected by default
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.click(0, 10);
|
|
||||||
mouse.click(10, 0);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Scenario: three rectangles that will be distributed by their centers
|
|
||||||
const createAndSelectThreeRectanglesWithoutGap = () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(100, 100);
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(10, 10);
|
|
||||||
mouse.up(200, 200);
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(200, 200);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
// Last rectangle is selected by default
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.click(0, 10);
|
|
||||||
mouse.click(10, 0);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("distributing", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
unmountComponent();
|
|
||||||
mouse.reset();
|
|
||||||
|
|
||||||
await act(() => {
|
|
||||||
return setLanguage(defaultLang);
|
|
||||||
});
|
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should distribute selected elements horizontally", async () => {
|
|
||||||
createAndSelectThreeRectanglesWithGap();
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(10);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(300);
|
|
||||||
|
|
||||||
API.executeAction(distributeHorizontally);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(150);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(300);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should distribute selected elements vertically", async () => {
|
|
||||||
createAndSelectThreeRectanglesWithGap();
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(10);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(300);
|
|
||||||
|
|
||||||
API.executeAction(distributeVertically);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(150);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(300);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should distribute selected elements horizontally based on their centers", async () => {
|
|
||||||
createAndSelectThreeRectanglesWithoutGap();
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(10);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(distributeHorizontally);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].x).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should distribute selected elements vertically with based on their centers", async () => {
|
|
||||||
createAndSelectThreeRectanglesWithoutGap();
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(10);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
|
|
||||||
API.executeAction(distributeVertically);
|
|
||||||
|
|
||||||
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
||||||
expect(API.getSelectedElements()[1].y).toEqual(50);
|
|
||||||
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
import { getEmbedLink } from "../src/embeddable";
|
|
||||||
|
|
||||||
describe("YouTube timestamp parsing", () => {
|
|
||||||
it("should parse YouTube URLs with timestamp in seconds", () => {
|
|
||||||
const testCases = [
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=90",
|
|
||||||
expectedStart: 90,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://youtu.be/dQw4w9WgXcQ?t=120",
|
|
||||||
expectedStart: 120,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&start=150",
|
|
||||||
expectedStart: 150,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
testCases.forEach(({ url, expectedStart }) => {
|
|
||||||
const result = getEmbedLink(url);
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
expect(result?.type).toBe("video");
|
|
||||||
if (result?.type === "video" || result?.type === "generic") {
|
|
||||||
expect(result.link).toContain(`start=${expectedStart}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should parse YouTube URLs with timestamp in time format", () => {
|
|
||||||
const testCases = [
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=1m30s",
|
|
||||||
expectedStart: 90, // 1*60 + 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://youtu.be/dQw4w9WgXcQ?t=2m45s",
|
|
||||||
expectedStart: 165, // 2*60 + 45
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=1h2m3s",
|
|
||||||
expectedStart: 3723, // 1*3600 + 2*60 + 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=45s",
|
|
||||||
expectedStart: 45,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=5m",
|
|
||||||
expectedStart: 300, // 5*60
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=2h",
|
|
||||||
expectedStart: 7200, // 2*3600
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
testCases.forEach(({ url, expectedStart }) => {
|
|
||||||
const result = getEmbedLink(url);
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
expect(result?.type).toBe("video");
|
|
||||||
if (result?.type === "video" || result?.type === "generic") {
|
|
||||||
expect(result.link).toContain(`start=${expectedStart}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle YouTube URLs without timestamps", () => {
|
|
||||||
const testCases = [
|
|
||||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
|
||||||
"https://youtu.be/dQw4w9WgXcQ",
|
|
||||||
"https://www.youtube.com/embed/dQw4w9WgXcQ",
|
|
||||||
];
|
|
||||||
|
|
||||||
testCases.forEach((url) => {
|
|
||||||
const result = getEmbedLink(url);
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
expect(result?.type).toBe("video");
|
|
||||||
if (result?.type === "video" || result?.type === "generic") {
|
|
||||||
expect(result.link).not.toContain("start=");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle YouTube shorts URLs with timestamps", () => {
|
|
||||||
const url = "https://www.youtube.com/shorts/dQw4w9WgXcQ?t=30";
|
|
||||||
const result = getEmbedLink(url);
|
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
expect(result?.type).toBe("video");
|
|
||||||
if (result?.type === "video" || result?.type === "generic") {
|
|
||||||
expect(result.link).toContain("start=30");
|
|
||||||
}
|
|
||||||
// Shorts should have portrait aspect ratio
|
|
||||||
expect(result?.intrinsicSize).toEqual({ w: 315, h: 560 });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle playlist URLs with timestamps", () => {
|
|
||||||
const url =
|
|
||||||
"https://www.youtube.com/playlist?list=PLrAXtmRdnEQy1KbG5lbfgQ0-PKQY6FKYZ&t=60";
|
|
||||||
const result = getEmbedLink(url);
|
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
expect(result?.type).toBe("video");
|
|
||||||
if (result?.type === "video" || result?.type === "generic") {
|
|
||||||
expect(result.link).toContain("start=60");
|
|
||||||
expect(result.link).toContain("list=PLrAXtmRdnEQy1KbG5lbfgQ0-PKQY6FKYZ");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle malformed or edge case timestamps", () => {
|
|
||||||
const testCases = [
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=abc",
|
|
||||||
expectedStart: 0, // Invalid timestamp should default to 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=",
|
|
||||||
expectedStart: 0, // Empty timestamp should default to 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=0",
|
|
||||||
expectedStart: 0, // Zero timestamp should be handled
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
testCases.forEach(({ url, expectedStart }) => {
|
|
||||||
const result = getEmbedLink(url);
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
expect(result?.type).toBe("video");
|
|
||||||
if (result?.type === "video" || result?.type === "generic") {
|
|
||||||
if (expectedStart === 0) {
|
|
||||||
expect(result.link).not.toContain("start=");
|
|
||||||
} else {
|
|
||||||
expect(result.link).toContain(`start=${expectedStart}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should preserve other URL parameters", () => {
|
|
||||||
const url =
|
|
||||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=90&feature=youtu.be&list=PLtest";
|
|
||||||
const result = getEmbedLink(url);
|
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
expect(result?.type).toBe("video");
|
|
||||||
if (result?.type === "video" || result?.type === "generic") {
|
|
||||||
expect(result.link).toContain("start=90");
|
|
||||||
expect(result.link).toContain("enablejsapi=1");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -136,8 +136,7 @@ describe("Test Linear Elements", () => {
|
|||||||
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||||
Keyboard.keyPress(KEYS.ENTER);
|
Keyboard.keyPress(KEYS.ENTER);
|
||||||
});
|
});
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(line.id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(line.id);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const drag = (startPoint: GlobalPoint, endPoint: GlobalPoint) => {
|
const drag = (startPoint: GlobalPoint, endPoint: GlobalPoint) => {
|
||||||
@@ -254,82 +253,75 @@ describe("Test Linear Elements", () => {
|
|||||||
});
|
});
|
||||||
fireEvent.click(queryByText(contextMenu as HTMLElement, "Edit line")!);
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Edit line")!);
|
||||||
|
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(h.elements[0].id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(h.elements[0].id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should enter line editor via enter (line)", () => {
|
it("should enter line editor via enter (line)", () => {
|
||||||
createTwoPointerLinearElement("line");
|
createTwoPointerLinearElement("line");
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement?.elementId).toBeUndefined();
|
||||||
|
|
||||||
mouse.clickAt(midpoint[0], midpoint[1]);
|
mouse.clickAt(midpoint[0], midpoint[1]);
|
||||||
Keyboard.keyPress(KEYS.ENTER);
|
Keyboard.keyPress(KEYS.ENTER);
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(h.elements[0].id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(h.elements[0].id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ctrl+enter alias (to align with arrows)
|
// ctrl+enter alias (to align with arrows)
|
||||||
it("should enter line editor via ctrl+enter (line)", () => {
|
it("should enter line editor via ctrl+enter (line)", () => {
|
||||||
createTwoPointerLinearElement("line");
|
createTwoPointerLinearElement("line");
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement?.elementId).toBeUndefined();
|
||||||
|
|
||||||
mouse.clickAt(midpoint[0], midpoint[1]);
|
mouse.clickAt(midpoint[0], midpoint[1]);
|
||||||
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||||
Keyboard.keyPress(KEYS.ENTER);
|
Keyboard.keyPress(KEYS.ENTER);
|
||||||
});
|
});
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(h.elements[0].id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(h.elements[0].id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should enter line editor via ctrl+enter (arrow)", () => {
|
it("should enter line editor via ctrl+enter (arrow)", () => {
|
||||||
createTwoPointerLinearElement("arrow");
|
createTwoPointerLinearElement("arrow");
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement?.elementId).toBeUndefined();
|
||||||
|
|
||||||
mouse.clickAt(midpoint[0], midpoint[1]);
|
mouse.clickAt(midpoint[0], midpoint[1]);
|
||||||
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||||
Keyboard.keyPress(KEYS.ENTER);
|
Keyboard.keyPress(KEYS.ENTER);
|
||||||
});
|
});
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(h.elements[0].id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(h.elements[0].id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should enter line editor on ctrl+dblclick (simple arrow)", () => {
|
it("should enter line editor on ctrl+dblclick (simple arrow)", () => {
|
||||||
createTwoPointerLinearElement("arrow");
|
createTwoPointerLinearElement("arrow");
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement?.elementId).toBeUndefined();
|
||||||
|
|
||||||
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||||
mouse.doubleClick();
|
mouse.doubleClick();
|
||||||
});
|
});
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(h.elements[0].id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(h.elements[0].id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should enter line editor on ctrl+dblclick (line)", () => {
|
it("should enter line editor on ctrl+dblclick (line)", () => {
|
||||||
createTwoPointerLinearElement("line");
|
createTwoPointerLinearElement("line");
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement?.elementId).toBeUndefined();
|
||||||
|
|
||||||
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
||||||
mouse.doubleClick();
|
mouse.doubleClick();
|
||||||
});
|
});
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(h.elements[0].id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(h.elements[0].id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should enter line editor on dblclick (line)", () => {
|
it("should enter line editor on dblclick (line)", () => {
|
||||||
createTwoPointerLinearElement("line");
|
createTwoPointerLinearElement("line");
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement?.elementId).toBeUndefined();
|
||||||
|
|
||||||
mouse.doubleClick();
|
mouse.doubleClick();
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(h.elements[0].id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(h.elements[0].id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not enter line editor on dblclick (arrow)", async () => {
|
it("should not enter line editor on dblclick (arrow)", async () => {
|
||||||
createTwoPointerLinearElement("arrow");
|
createTwoPointerLinearElement("arrow");
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(false);
|
expect(h.state.editingLinearElement?.elementId).toBeUndefined();
|
||||||
|
|
||||||
mouse.doubleClick();
|
mouse.doubleClick();
|
||||||
expect(h.state.selectedLinearElement).toBe(null);
|
expect(h.state.editingLinearElement).toEqual(null);
|
||||||
await getTextEditor();
|
await getTextEditor();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -338,12 +330,10 @@ describe("Test Linear Elements", () => {
|
|||||||
const arrow = h.elements[0] as ExcalidrawLinearElement;
|
const arrow = h.elements[0] as ExcalidrawLinearElement;
|
||||||
enterLineEditingMode(arrow);
|
enterLineEditingMode(arrow);
|
||||||
|
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(arrow.id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(arrow.id);
|
|
||||||
|
|
||||||
mouse.doubleClick();
|
mouse.doubleClick();
|
||||||
expect(h.state.selectedLinearElement?.isEditing).toBe(true);
|
expect(h.state.editingLinearElement?.elementId).toEqual(arrow.id);
|
||||||
expect(h.state.selectedLinearElement?.elementId).toEqual(arrow.id);
|
|
||||||
expect(h.elements.length).toEqual(1);
|
expect(h.elements.length).toEqual(1);
|
||||||
|
|
||||||
expect(document.querySelector(TEXT_EDITOR_SELECTOR)).toBe(null);
|
expect(document.querySelector(TEXT_EDITOR_SELECTOR)).toBe(null);
|
||||||
@@ -377,7 +367,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(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
||||||
|
|
||||||
@@ -433,12 +423,12 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(midPointsWithRoundEdge).toMatchInlineSnapshot(`
|
expect(midPointsWithRoundEdge).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
"54.27552",
|
"55.96978",
|
||||||
"46.16120",
|
"47.44233",
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"76.95494",
|
"76.08587",
|
||||||
"44.56052",
|
"43.29417",
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
@@ -479,7 +469,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(startPoint, endPoint);
|
drag(startPoint, endPoint);
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -498,12 +488,12 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(newMidPoints).toMatchInlineSnapshot(`
|
expect(newMidPoints).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
"104.27552",
|
"105.96978",
|
||||||
"66.16120",
|
"67.44233",
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"126.95494",
|
"126.08587",
|
||||||
"64.56052",
|
"63.29417",
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
@@ -547,7 +537,7 @@ describe("Test Linear Elements", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`14`,
|
`16`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -598,7 +588,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(hitCoords, pointFrom(hitCoords[0] - delta, hitCoords[1] - delta));
|
drag(hitCoords, pointFrom(hitCoords[0] - delta, hitCoords[1] - delta));
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
||||||
|
|
||||||
@@ -639,7 +629,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
||||||
|
|
||||||
@@ -687,7 +677,7 @@ describe("Test Linear Elements", () => {
|
|||||||
deletePoint(points[2]);
|
deletePoint(points[2]);
|
||||||
expect(line.points.length).toEqual(3);
|
expect(line.points.length).toEqual(3);
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`17`,
|
`18`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -745,7 +735,7 @@ describe("Test Linear Elements", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`14`,
|
`16`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
expect(line.points.length).toEqual(5);
|
expect(line.points.length).toEqual(5);
|
||||||
@@ -814,12 +804,12 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(newMidPoints).toMatchInlineSnapshot(`
|
expect(newMidPoints).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
"29.28349",
|
"31.88408",
|
||||||
"20.91105",
|
"23.13276",
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"78.86048",
|
"77.74793",
|
||||||
"46.12277",
|
"44.57841",
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
@@ -843,7 +833,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
||||||
|
|
||||||
@@ -903,12 +893,12 @@ describe("Test Linear Elements", () => {
|
|||||||
expect(newMidPoints).toMatchInlineSnapshot(`
|
expect(newMidPoints).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
"54.27552",
|
"55.96978",
|
||||||
"46.16120",
|
"47.44233",
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"76.95494",
|
"76.08587",
|
||||||
"44.56052",
|
"43.29417",
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
@@ -1070,8 +1060,8 @@ describe("Test Linear Elements", () => {
|
|||||||
);
|
);
|
||||||
expect(position).toMatchInlineSnapshot(`
|
expect(position).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"x": "86.17305",
|
"x": "85.82202",
|
||||||
"y": "76.11251",
|
"y": "75.63461",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import { alignElements } from "@excalidraw/element";
|
|||||||
|
|
||||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
|
|
||||||
import { getSelectedElementsByGroup } from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import type { Alignment } from "@excalidraw/element";
|
import type { Alignment } from "@excalidraw/element";
|
||||||
@@ -40,11 +38,7 @@ export const alignActionsPredicate = (
|
|||||||
) => {
|
) => {
|
||||||
const selectedElements = app.scene.getSelectedElements(appState);
|
const selectedElements = app.scene.getSelectedElements(appState);
|
||||||
return (
|
return (
|
||||||
getSelectedElementsByGroup(
|
selectedElements.length > 1 &&
|
||||||
selectedElements,
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
appState as Readonly<AppState>,
|
|
||||||
).length > 1 &&
|
|
||||||
// TODO enable aligning frames when implemented properly
|
// TODO enable aligning frames when implemented properly
|
||||||
!selectedElements.some((el) => isFrameLikeElement(el))
|
!selectedElements.some((el) => isFrameLikeElement(el))
|
||||||
);
|
);
|
||||||
@@ -58,12 +52,7 @@ const alignSelectedElements = (
|
|||||||
) => {
|
) => {
|
||||||
const selectedElements = app.scene.getSelectedElements(appState);
|
const selectedElements = app.scene.getSelectedElements(appState);
|
||||||
|
|
||||||
const updatedElements = alignElements(
|
const updatedElements = alignElements(selectedElements, alignment, app.scene);
|
||||||
selectedElements,
|
|
||||||
alignment,
|
|
||||||
app.scene,
|
|
||||||
appState,
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedElementsMap = arrayToMap(updatedElements);
|
const updatedElementsMap = arrayToMap(updatedElements);
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export const actionClearCanvas = register({
|
|||||||
pasteDialog: appState.pasteDialog,
|
pasteDialog: appState.pasteDialog,
|
||||||
activeTool:
|
activeTool:
|
||||||
appState.activeTool.type === "image"
|
appState.activeTool.type === "image"
|
||||||
? { ...appState.activeTool, type: app.defaultSelectionTool }
|
? { ...appState.activeTool, type: "selection" }
|
||||||
: appState.activeTool,
|
: appState.activeTool,
|
||||||
},
|
},
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
@@ -494,13 +494,13 @@ export const actionToggleEraserTool = register({
|
|||||||
name: "toggleEraserTool",
|
name: "toggleEraserTool",
|
||||||
label: "toolBar.eraser",
|
label: "toolBar.eraser",
|
||||||
trackEvent: { category: "toolbar" },
|
trackEvent: { category: "toolbar" },
|
||||||
perform: (elements, appState, _, app) => {
|
perform: (elements, appState) => {
|
||||||
let activeTool: AppState["activeTool"];
|
let activeTool: AppState["activeTool"];
|
||||||
|
|
||||||
if (isEraserActive(appState)) {
|
if (isEraserActive(appState)) {
|
||||||
activeTool = updateActiveTool(appState, {
|
activeTool = updateActiveTool(appState, {
|
||||||
...(appState.activeTool.lastActiveTool || {
|
...(appState.activeTool.lastActiveTool || {
|
||||||
type: app.defaultSelectionTool,
|
type: "selection",
|
||||||
}),
|
}),
|
||||||
lastActiveToolBeforeEraser: null,
|
lastActiveToolBeforeEraser: null,
|
||||||
});
|
});
|
||||||
@@ -530,9 +530,6 @@ export const actionToggleLassoTool = register({
|
|||||||
label: "toolBar.lasso",
|
label: "toolBar.lasso",
|
||||||
icon: LassoIcon,
|
icon: LassoIcon,
|
||||||
trackEvent: { category: "toolbar" },
|
trackEvent: { category: "toolbar" },
|
||||||
predicate: (elements, appState, props, app) => {
|
|
||||||
return app.defaultSelectionTool !== "lasso";
|
|
||||||
},
|
|
||||||
perform: (elements, appState, _, app) => {
|
perform: (elements, appState, _, app) => {
|
||||||
let activeTool: AppState["activeTool"];
|
let activeTool: AppState["activeTool"];
|
||||||
|
|
||||||
|
|||||||
@@ -205,19 +205,16 @@ export const actionDeleteSelected = register({
|
|||||||
icon: TrashIcon,
|
icon: TrashIcon,
|
||||||
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.editingLinearElement) {
|
||||||
const {
|
const {
|
||||||
elementId,
|
elementId,
|
||||||
selectedPointsIndices,
|
selectedPointsIndices,
|
||||||
startBindingElement,
|
startBindingElement,
|
||||||
endBindingElement,
|
endBindingElement,
|
||||||
} = appState.selectedLinearElement;
|
} = appState.editingLinearElement;
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
const elementsMap = app.scene.getNonDeletedElementsMap();
|
||||||
const linearElement = LinearElementEditor.getElement(
|
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
||||||
elementId,
|
if (!element) {
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
if (!linearElement) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// case: no point selected → do nothing, as deleting the whole element
|
// case: no point selected → do nothing, as deleting the whole element
|
||||||
@@ -228,10 +225,10 @@ export const actionDeleteSelected = register({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// case: deleting all points
|
// case: deleting last remaining point
|
||||||
if (selectedPointsIndices.length >= linearElement.points.length) {
|
if (element.points.length < 2) {
|
||||||
const nextElements = elements.map((el) => {
|
const nextElements = elements.map((el) => {
|
||||||
if (el.id === linearElement.id) {
|
if (el.id === element.id) {
|
||||||
return newElementWith(el, { isDeleted: true });
|
return newElementWith(el, { isDeleted: true });
|
||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
@@ -242,7 +239,7 @@ export const actionDeleteSelected = register({
|
|||||||
elements: nextElements,
|
elements: nextElements,
|
||||||
appState: {
|
appState: {
|
||||||
...nextAppState,
|
...nextAppState,
|
||||||
selectedLinearElement: null,
|
editingLinearElement: null,
|
||||||
},
|
},
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
@@ -255,24 +252,20 @@ export const actionDeleteSelected = register({
|
|||||||
? null
|
? null
|
||||||
: startBindingElement,
|
: startBindingElement,
|
||||||
endBindingElement: selectedPointsIndices?.includes(
|
endBindingElement: selectedPointsIndices?.includes(
|
||||||
linearElement.points.length - 1,
|
element.points.length - 1,
|
||||||
)
|
)
|
||||||
? null
|
? null
|
||||||
: endBindingElement,
|
: endBindingElement,
|
||||||
};
|
};
|
||||||
|
|
||||||
LinearElementEditor.deletePoints(
|
LinearElementEditor.deletePoints(element, app, selectedPointsIndices);
|
||||||
linearElement,
|
|
||||||
app,
|
|
||||||
selectedPointsIndices,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements,
|
elements,
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
selectedLinearElement: {
|
editingLinearElement: {
|
||||||
...appState.selectedLinearElement,
|
...appState.editingLinearElement,
|
||||||
...binding,
|
...binding,
|
||||||
selectedPointsIndices:
|
selectedPointsIndices:
|
||||||
selectedPointsIndices?.[0] > 0
|
selectedPointsIndices?.[0] > 0
|
||||||
@@ -298,9 +291,7 @@ export const actionDeleteSelected = register({
|
|||||||
elements: nextElements,
|
elements: nextElements,
|
||||||
appState: {
|
appState: {
|
||||||
...nextAppState,
|
...nextAppState,
|
||||||
activeTool: updateActiveTool(appState, {
|
activeTool: updateActiveTool(appState, { type: "selection" }),
|
||||||
type: app.defaultSelectionTool,
|
|
||||||
}),
|
|
||||||
multiElement: null,
|
multiElement: null,
|
||||||
activeEmbeddable: null,
|
activeEmbeddable: null,
|
||||||
selectedLinearElement: null,
|
selectedLinearElement: null,
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import { distributeElements } from "@excalidraw/element";
|
|||||||
|
|
||||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
|
|
||||||
import { getSelectedElementsByGroup } from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import type { Distribution } from "@excalidraw/element";
|
import type { Distribution } from "@excalidraw/element";
|
||||||
@@ -33,11 +31,7 @@ import type { AppClassProperties, AppState } from "../types";
|
|||||||
const enableActionGroup = (appState: AppState, app: AppClassProperties) => {
|
const enableActionGroup = (appState: AppState, app: AppClassProperties) => {
|
||||||
const selectedElements = app.scene.getSelectedElements(appState);
|
const selectedElements = app.scene.getSelectedElements(appState);
|
||||||
return (
|
return (
|
||||||
getSelectedElementsByGroup(
|
selectedElements.length > 1 &&
|
||||||
selectedElements,
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
appState as Readonly<AppState>,
|
|
||||||
).length > 2 &&
|
|
||||||
// TODO enable distributing frames when implemented properly
|
// TODO enable distributing frames when implemented properly
|
||||||
!selectedElements.some((el) => isFrameLikeElement(el))
|
!selectedElements.some((el) => isFrameLikeElement(el))
|
||||||
);
|
);
|
||||||
@@ -55,7 +49,6 @@ const distributeSelectedElements = (
|
|||||||
selectedElements,
|
selectedElements,
|
||||||
app.scene.getNonDeletedElementsMap(),
|
app.scene.getNonDeletedElementsMap(),
|
||||||
distribution,
|
distribution,
|
||||||
appState,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const updatedElementsMap = arrayToMap(updatedElements);
|
const updatedElementsMap = arrayToMap(updatedElements);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const actionDuplicateSelection = register({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// duplicate selected point(s) if editing a line
|
// duplicate selected point(s) if editing a line
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
if (appState.editingLinearElement) {
|
||||||
// TODO: Invariants should be checked here instead of duplicateSelectedPoints()
|
// TODO: Invariants should be checked here instead of duplicateSelectedPoints()
|
||||||
try {
|
try {
|
||||||
const newAppState = LinearElementEditor.duplicateSelectedPoints(
|
const newAppState = LinearElementEditor.duplicateSelectedPoints(
|
||||||
|
|||||||
@@ -5,11 +5,7 @@ import {
|
|||||||
bindOrUnbindLinearElement,
|
bindOrUnbindLinearElement,
|
||||||
isBindingEnabled,
|
isBindingEnabled,
|
||||||
} from "@excalidraw/element/binding";
|
} from "@excalidraw/element/binding";
|
||||||
import {
|
import { isValidPolygon, LinearElementEditor } from "@excalidraw/element";
|
||||||
isValidPolygon,
|
|
||||||
LinearElementEditor,
|
|
||||||
newElementWith,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isBindingElement,
|
isBindingElement,
|
||||||
@@ -18,12 +14,7 @@ import {
|
|||||||
isLineElement,
|
isLineElement,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import { KEYS, arrayToMap, updateActiveTool } from "@excalidraw/common";
|
||||||
KEYS,
|
|
||||||
arrayToMap,
|
|
||||||
tupleToCoors,
|
|
||||||
updateActiveTool,
|
|
||||||
} from "@excalidraw/common";
|
|
||||||
import { isPathALoop } from "@excalidraw/element";
|
import { isPathALoop } from "@excalidraw/element";
|
||||||
|
|
||||||
import { isInvisiblySmallElement } from "@excalidraw/element";
|
import { isInvisiblySmallElement } from "@excalidraw/element";
|
||||||
@@ -52,16 +43,12 @@ export const actionFinalize = register({
|
|||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, data, app) => {
|
perform: (elements, appState, data, app) => {
|
||||||
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?.event && appState.selectedLinearElement) {
|
||||||
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
||||||
event,
|
data.event,
|
||||||
appState.selectedLinearElement,
|
appState.selectedLinearElement,
|
||||||
appState,
|
appState,
|
||||||
app.scene,
|
app.scene,
|
||||||
@@ -82,14 +69,7 @@ export const actionFinalize = register({
|
|||||||
let newElements = elements;
|
let newElements = elements;
|
||||||
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.filter((el) => el.id !== element!.id);
|
||||||
if (el.id === element.id) {
|
|
||||||
return newElementWith(el, {
|
|
||||||
isDeleted: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return el;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
elements: newElements,
|
elements: newElements,
|
||||||
@@ -105,9 +85,9 @@ export const actionFinalize = register({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
if (appState.editingLinearElement) {
|
||||||
const { elementId, startBindingElement, endBindingElement } =
|
const { elementId, startBindingElement, endBindingElement } =
|
||||||
appState.selectedLinearElement;
|
appState.editingLinearElement;
|
||||||
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
const element = LinearElementEditor.getElement(elementId, elementsMap);
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
@@ -128,21 +108,12 @@ export const actionFinalize = register({
|
|||||||
return {
|
return {
|
||||||
elements:
|
elements:
|
||||||
element.points.length < 2 || isInvisiblySmallElement(element)
|
element.points.length < 2 || isInvisiblySmallElement(element)
|
||||||
? elements.map((el) => {
|
? elements.filter((el) => el.id !== element.id)
|
||||||
if (el.id === element.id) {
|
|
||||||
return newElementWith(el, { isDeleted: true });
|
|
||||||
}
|
|
||||||
return el;
|
|
||||||
})
|
|
||||||
: undefined,
|
: undefined,
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
cursorButton: "up",
|
cursorButton: "up",
|
||||||
selectedLinearElement: new LinearElementEditor(
|
editingLinearElement: null,
|
||||||
element,
|
|
||||||
arrayToMap(elementsMap),
|
|
||||||
false, // exit editing mode
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
@@ -174,7 +145,11 @@ 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 (
|
||||||
|
appState.multiElement &&
|
||||||
|
element.type !== "freedraw" &&
|
||||||
|
appState.lastPointerDownWith !== "touch"
|
||||||
|
) {
|
||||||
const { points, lastCommittedPoint } = element;
|
const { points, lastCommittedPoint } = element;
|
||||||
if (
|
if (
|
||||||
!lastCommittedPoint ||
|
!lastCommittedPoint ||
|
||||||
@@ -188,12 +163,7 @@ export const actionFinalize = register({
|
|||||||
|
|
||||||
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.filter((el) => el.id !== element!.id);
|
||||||
if (el.id === element?.id) {
|
|
||||||
return newElementWith(el, { isDeleted: true });
|
|
||||||
}
|
|
||||||
return el;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLinearElement(element) || isFreeDrawElement(element)) {
|
if (isLinearElement(element) || isFreeDrawElement(element)) {
|
||||||
@@ -234,17 +204,12 @@ export const actionFinalize = register({
|
|||||||
element.points.length > 1 &&
|
element.points.length > 1 &&
|
||||||
isBindingEnabled(appState)
|
isBindingEnabled(appState)
|
||||||
) {
|
) {
|
||||||
const coords =
|
const [x, y] = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
sceneCoords ??
|
element,
|
||||||
tupleToCoors(
|
-1,
|
||||||
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
arrayToMap(elements),
|
||||||
element,
|
);
|
||||||
-1,
|
maybeBindLinearElement(element, appState, { x, y }, scene);
|
||||||
arrayToMap(elements),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
maybeBindLinearElement(element, appState, coords, scene);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,13 +226,13 @@ export const actionFinalize = register({
|
|||||||
if (appState.activeTool.type === "eraser") {
|
if (appState.activeTool.type === "eraser") {
|
||||||
activeTool = updateActiveTool(appState, {
|
activeTool = updateActiveTool(appState, {
|
||||||
...(appState.activeTool.lastActiveTool || {
|
...(appState.activeTool.lastActiveTool || {
|
||||||
type: app.defaultSelectionTool,
|
type: "selection",
|
||||||
}),
|
}),
|
||||||
lastActiveToolBeforeEraser: null,
|
lastActiveToolBeforeEraser: null,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
activeTool = updateActiveTool(appState, {
|
activeTool = updateActiveTool(appState, {
|
||||||
type: app.defaultSelectionTool,
|
type: "selection",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +275,7 @@ export const actionFinalize = register({
|
|||||||
},
|
},
|
||||||
keyTest: (event, appState) =>
|
keyTest: (event, appState) =>
|
||||||
(event.key === KEYS.ESCAPE &&
|
(event.key === KEYS.ESCAPE &&
|
||||||
(appState.selectedLinearElement?.isEditing ||
|
(appState.editingLinearElement !== null ||
|
||||||
(!appState.newElement && appState.multiElement === null))) ||
|
(!appState.newElement && appState.multiElement === null))) ||
|
||||||
((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) &&
|
((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) &&
|
||||||
appState.multiElement !== null),
|
appState.multiElement !== null),
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
|
import { LinearElementEditor } from "@excalidraw/element";
|
||||||
import {
|
import {
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isLineElement,
|
isLineElement,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
import { arrayToMap, invariant } from "@excalidraw/common";
|
import { arrayToMap } from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
toggleLinePolygonState,
|
|
||||||
CaptureUpdateAction,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
@@ -24,6 +22,8 @@ import { ButtonIcon } from "../components/ButtonIcon";
|
|||||||
|
|
||||||
import { newElementWith } from "../../element/src/mutateElement";
|
import { newElementWith } from "../../element/src/mutateElement";
|
||||||
|
|
||||||
|
import { toggleLinePolygonState } from "../../element/src/shapes";
|
||||||
|
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
|
|
||||||
export const actionToggleLinearEditor = register({
|
export const actionToggleLinearEditor = register({
|
||||||
@@ -45,7 +45,7 @@ export const actionToggleLinearEditor = register({
|
|||||||
predicate: (elements, appState, _, app) => {
|
predicate: (elements, appState, _, app) => {
|
||||||
const selectedElements = app.scene.getSelectedElements(appState);
|
const selectedElements = app.scene.getSelectedElements(appState);
|
||||||
if (
|
if (
|
||||||
!appState.selectedLinearElement?.isEditing &&
|
!appState.editingLinearElement &&
|
||||||
selectedElements.length === 1 &&
|
selectedElements.length === 1 &&
|
||||||
isLinearElement(selectedElements[0]) &&
|
isLinearElement(selectedElements[0]) &&
|
||||||
!isElbowArrow(selectedElements[0])
|
!isElbowArrow(selectedElements[0])
|
||||||
@@ -60,25 +60,14 @@ export const actionToggleLinearEditor = register({
|
|||||||
includeBoundTextElement: true,
|
includeBoundTextElement: true,
|
||||||
})[0] as ExcalidrawLinearElement;
|
})[0] as ExcalidrawLinearElement;
|
||||||
|
|
||||||
invariant(selectedElement, "No selected element found");
|
const editingLinearElement =
|
||||||
invariant(
|
appState.editingLinearElement?.elementId === selectedElement.id
|
||||||
appState.selectedLinearElement,
|
? null
|
||||||
"No selected linear element found",
|
: new LinearElementEditor(selectedElement, arrayToMap(elements));
|
||||||
);
|
|
||||||
invariant(
|
|
||||||
selectedElement.id === appState.selectedLinearElement.elementId,
|
|
||||||
"Selected element ID and linear editor elementId does not match",
|
|
||||||
);
|
|
||||||
|
|
||||||
const selectedLinearElement = {
|
|
||||||
...appState.selectedLinearElement,
|
|
||||||
isEditing: !appState.selectedLinearElement.isEditing,
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
selectedLinearElement,
|
editingLinearElement,
|
||||||
},
|
},
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,11 +52,9 @@ import {
|
|||||||
|
|
||||||
import { hasStrokeColor } from "@excalidraw/element";
|
import { hasStrokeColor } from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import { updateElbowArrowPoints } from "@excalidraw/element";
|
||||||
updateElbowArrowPoints,
|
|
||||||
CaptureUpdateAction,
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
toggleLinePolygonState,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { LocalPoint } from "@excalidraw/math";
|
import type { LocalPoint } from "@excalidraw/math";
|
||||||
|
|
||||||
@@ -137,6 +135,8 @@ import {
|
|||||||
isSomeElementSelected,
|
isSomeElementSelected,
|
||||||
} from "../scene";
|
} from "../scene";
|
||||||
|
|
||||||
|
import { toggleLinePolygonState } from "../../element/src/shapes";
|
||||||
|
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
|
|
||||||
import type { AppClassProperties, AppState, Primitive } from "../types";
|
import type { AppClassProperties, AppState, Primitive } from "../types";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const actionSelectAll = register({
|
|||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
viewMode: false,
|
viewMode: false,
|
||||||
perform: (elements, appState, value, app) => {
|
perform: (elements, appState, value, app) => {
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
if (appState.editingLinearElement) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
newElement: null,
|
newElement: null,
|
||||||
editingTextElement: null,
|
editingTextElement: null,
|
||||||
editingGroupId: null,
|
editingGroupId: null,
|
||||||
|
editingLinearElement: null,
|
||||||
activeTool: {
|
activeTool: {
|
||||||
type: "selection",
|
type: "selection",
|
||||||
customType: null,
|
customType: null,
|
||||||
@@ -174,6 +175,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
newElement: { browser: false, export: false, server: false },
|
newElement: { browser: false, export: false, server: false },
|
||||||
editingTextElement: { browser: false, export: false, server: false },
|
editingTextElement: { browser: false, export: false, server: false },
|
||||||
editingGroupId: { browser: true, export: false, server: false },
|
editingGroupId: { browser: true, export: false, server: false },
|
||||||
|
editingLinearElement: { browser: false, export: false, server: false },
|
||||||
activeTool: { browser: true, export: false, server: false },
|
activeTool: { browser: true, export: false, server: false },
|
||||||
penMode: { browser: true, export: false, server: false },
|
penMode: { browser: true, export: false, server: false },
|
||||||
penDetected: { browser: true, export: false, server: false },
|
penDetected: { browser: true, export: false, server: false },
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
.undo-redo-buttons {
|
.undo-redo-buttons {
|
||||||
background-color: var(--island-bg-color);
|
background-color: var(--island-bg-color);
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
box-shadow: 0 0 0 1px var(--color-surface-lowest);
|
// box-shadow: 0 0 0 1px var(--color-surface-lowest);
|
||||||
|
backdrop-filter: blur(40px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.zoom-button,
|
.zoom-button,
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
font-size: 0.875rem !important;
|
font-size: 0.875rem !important;
|
||||||
width: var(--lg-button-size);
|
width: var(--lg-button-size);
|
||||||
height: var(--lg-button-size);
|
height: var(--lg-button-size);
|
||||||
|
backdrop-filter: blur(40px);
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: var(--lg-icon-size) !important;
|
width: var(--lg-icon-size) !important;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import {
|
|||||||
hasStrokeWidth,
|
hasStrokeWidth,
|
||||||
} from "../scene";
|
} from "../scene";
|
||||||
|
|
||||||
import { getToolbarTools } from "./shapes";
|
import { SHAPES } from "./shapes";
|
||||||
|
|
||||||
import "./Actions.scss";
|
import "./Actions.scss";
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ export const SelectedShapeActions = ({
|
|||||||
targetElements.length === 1 || isSingleElementBoundContainer;
|
targetElements.length === 1 || isSingleElementBoundContainer;
|
||||||
|
|
||||||
const showLineEditorAction =
|
const showLineEditorAction =
|
||||||
!appState.selectedLinearElement?.isEditing &&
|
!appState.editingLinearElement &&
|
||||||
targetElements.length === 1 &&
|
targetElements.length === 1 &&
|
||||||
isLinearElement(targetElements[0]) &&
|
isLinearElement(targetElements[0]) &&
|
||||||
!isElbowArrow(targetElements[0]);
|
!isElbowArrow(targetElements[0]);
|
||||||
@@ -295,8 +295,7 @@ export const ShapesSwitcher = ({
|
|||||||
|
|
||||||
const frameToolSelected = activeTool.type === "frame";
|
const frameToolSelected = activeTool.type === "frame";
|
||||||
const laserToolSelected = activeTool.type === "laser";
|
const laserToolSelected = activeTool.type === "laser";
|
||||||
const lassoToolSelected =
|
const lassoToolSelected = activeTool.type === "lasso";
|
||||||
activeTool.type === "lasso" && app.defaultSelectionTool !== "lasso";
|
|
||||||
|
|
||||||
const embeddableToolSelected = activeTool.type === "embeddable";
|
const embeddableToolSelected = activeTool.type === "embeddable";
|
||||||
|
|
||||||
@@ -304,68 +303,63 @@ export const ShapesSwitcher = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{getToolbarTools(app).map(
|
{SHAPES.map(({ value, icon, key, numericKey, fillable }, index) => {
|
||||||
({ value, icon, key, numericKey, fillable }, index) => {
|
if (
|
||||||
if (
|
UIOptions.tools?.[
|
||||||
UIOptions.tools?.[
|
value as Extract<typeof value, keyof AppProps["UIOptions"]["tools"]>
|
||||||
value as Extract<
|
] === false
|
||||||
typeof value,
|
) {
|
||||||
keyof AppProps["UIOptions"]["tools"]
|
return null;
|
||||||
>
|
}
|
||||||
] === false
|
|
||||||
) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const label = t(`toolBar.${value}`);
|
const label = t(`toolBar.${value}`);
|
||||||
const letter =
|
const letter =
|
||||||
key && capitalizeString(typeof key === "string" ? key : key[0]);
|
key && capitalizeString(typeof key === "string" ? key : key[0]);
|
||||||
const shortcut = letter
|
const shortcut = letter
|
||||||
? `${letter} ${t("helpDialog.or")} ${numericKey}`
|
? `${letter} ${t("helpDialog.or")} ${numericKey}`
|
||||||
: `${numericKey}`;
|
: `${numericKey}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
className={clsx("Shape", { fillable })}
|
className={clsx("Shape", { fillable })}
|
||||||
key={value}
|
key={value}
|
||||||
type="radio"
|
type="radio"
|
||||||
icon={icon}
|
icon={icon}
|
||||||
checked={activeTool.type === value}
|
checked={activeTool.type === value}
|
||||||
name="editor-current-shape"
|
name="editor-current-shape"
|
||||||
title={`${capitalizeString(label)} — ${shortcut}`}
|
title={`${capitalizeString(label)} — ${shortcut}`}
|
||||||
keyBindingLabel={numericKey || letter}
|
keyBindingLabel={numericKey || letter}
|
||||||
aria-label={capitalizeString(label)}
|
aria-label={capitalizeString(label)}
|
||||||
aria-keyshortcuts={shortcut}
|
aria-keyshortcuts={shortcut}
|
||||||
data-testid={`toolbar-${value}`}
|
data-testid={`toolbar-${value}`}
|
||||||
onPointerDown={({ pointerType }) => {
|
onPointerDown={({ pointerType }) => {
|
||||||
if (!appState.penDetected && pointerType === "pen") {
|
if (!appState.penDetected && pointerType === "pen") {
|
||||||
app.togglePenMode(true);
|
app.togglePenMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value === "selection") {
|
if (value === "selection") {
|
||||||
if (appState.activeTool.type === "selection") {
|
if (appState.activeTool.type === "selection") {
|
||||||
app.setActiveTool({ type: "lasso" });
|
app.setActiveTool({ type: "lasso" });
|
||||||
} else {
|
|
||||||
app.setActiveTool({ type: "selection" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onChange={({ pointerType }) => {
|
|
||||||
if (appState.activeTool.type !== value) {
|
|
||||||
trackEvent("toolbar", value, "ui");
|
|
||||||
}
|
|
||||||
if (value === "image") {
|
|
||||||
app.setActiveTool({
|
|
||||||
type: value,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
app.setActiveTool({ type: value });
|
app.setActiveTool({ type: "selection" });
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
/>
|
}}
|
||||||
);
|
onChange={({ pointerType }) => {
|
||||||
},
|
if (appState.activeTool.type !== value) {
|
||||||
)}
|
trackEvent("toolbar", value, "ui");
|
||||||
|
}
|
||||||
|
if (value === "image") {
|
||||||
|
app.setActiveTool({
|
||||||
|
type: value,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
app.setActiveTool({ type: value });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
<div className="App-toolbar__divider" />
|
<div className="App-toolbar__divider" />
|
||||||
|
|
||||||
<DropdownMenu open={isExtraToolsMenuOpen}>
|
<DropdownMenu open={isExtraToolsMenuOpen}>
|
||||||
@@ -424,16 +418,14 @@ export const ShapesSwitcher = ({
|
|||||||
>
|
>
|
||||||
{t("toolBar.laser")}
|
{t("toolBar.laser")}
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
{app.defaultSelectionTool !== "lasso" && (
|
<DropdownMenu.Item
|
||||||
<DropdownMenu.Item
|
onSelect={() => app.setActiveTool({ type: "lasso" })}
|
||||||
onSelect={() => app.setActiveTool({ type: "lasso" })}
|
icon={LassoIcon}
|
||||||
icon={LassoIcon}
|
data-testid="toolbar-lasso"
|
||||||
data-testid="toolbar-lasso"
|
selected={lassoToolSelected}
|
||||||
selected={lassoToolSelected}
|
>
|
||||||
>
|
{t("toolBar.lasso")}
|
||||||
{t("toolBar.lasso")}
|
</DropdownMenu.Item>
|
||||||
</DropdownMenu.Item>
|
|
||||||
)}
|
|
||||||
<div style={{ margin: "6px 0", fontSize: 14, fontWeight: 600 }}>
|
<div style={{ margin: "6px 0", fontSize: 14, fontWeight: 600 }}>
|
||||||
Generate
|
Generate
|
||||||
</div>
|
</div>
|
||||||
@@ -513,3 +505,15 @@ export const ExitZenModeAction = ({
|
|||||||
{t("buttons.exitZenMode")}
|
{t("buttons.exitZenMode")}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const FinalizeAction = ({
|
||||||
|
renderAction,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
renderAction: ActionManager["renderAction"];
|
||||||
|
className?: string;
|
||||||
|
}) => (
|
||||||
|
<div className={`finalize-button ${className}`}>
|
||||||
|
{renderAction("finalize", { size: "small" })}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -108,7 +108,6 @@ $verticalBreakpoint: 861px;
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.25rem;
|
gap: 0.25rem;
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ import { useStableCallback } from "../../hooks/useStableCallback";
|
|||||||
import { activeConfirmDialogAtom } from "../ActiveConfirmDialog";
|
import { activeConfirmDialogAtom } from "../ActiveConfirmDialog";
|
||||||
import { useStable } from "../../hooks/useStable";
|
import { useStable } from "../../hooks/useStable";
|
||||||
|
|
||||||
import { Ellipsify } from "../Ellipsify";
|
|
||||||
|
|
||||||
import * as defaultItems from "./defaultCommandPaletteItems";
|
import * as defaultItems from "./defaultCommandPaletteItems";
|
||||||
|
|
||||||
import "./CommandPalette.scss";
|
import "./CommandPalette.scss";
|
||||||
@@ -966,7 +964,7 @@ const CommandItem = ({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Ellipsify>{command.label}</Ellipsify>
|
{command.label}
|
||||||
</div>
|
</div>
|
||||||
{showShortcut && command.shortcut && (
|
{showShortcut && command.shortcut && (
|
||||||
<CommandShortcutHint shortcut={command.shortcut} />
|
<CommandShortcutHint shortcut={command.shortcut} />
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
export const Ellipsify = ({
|
|
||||||
children,
|
|
||||||
...rest
|
|
||||||
}: { children: React.ReactNode } & React.HTMLAttributes<HTMLSpanElement>) => {
|
|
||||||
return (
|
|
||||||
<span
|
|
||||||
{...rest}
|
|
||||||
style={{
|
|
||||||
textOverflow: "ellipsis",
|
|
||||||
overflow: "hidden",
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
...rest.style,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -115,7 +115,7 @@ const getHints = ({
|
|||||||
appState.selectionElement &&
|
appState.selectionElement &&
|
||||||
!selectedElements.length &&
|
!selectedElements.length &&
|
||||||
!appState.editingTextElement &&
|
!appState.editingTextElement &&
|
||||||
!appState.selectedLinearElement?.isEditing
|
!appState.editingLinearElement
|
||||||
) {
|
) {
|
||||||
return [t("hints.deepBoxSelect")];
|
return [t("hints.deepBoxSelect")];
|
||||||
}
|
}
|
||||||
@@ -130,8 +130,8 @@ const getHints = ({
|
|||||||
|
|
||||||
if (selectedElements.length === 1) {
|
if (selectedElements.length === 1) {
|
||||||
if (isLinearElement(selectedElements[0])) {
|
if (isLinearElement(selectedElements[0])) {
|
||||||
if (appState.selectedLinearElement?.isEditing) {
|
if (appState.editingLinearElement) {
|
||||||
return appState.selectedLinearElement.selectedPointsIndices
|
return appState.editingLinearElement.selectedPointsIndices
|
||||||
? t("hints.lineEditor_pointSelected")
|
? t("hints.lineEditor_pointSelected")
|
||||||
: t("hints.lineEditor_nothingSelected");
|
: t("hints.lineEditor_nothingSelected");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ export const InlineIcon = ({ icon }: { icon: React.ReactNode }) => {
|
|||||||
display: "inline-block",
|
display: "inline-block",
|
||||||
lineHeight: 0,
|
lineHeight: 0,
|
||||||
verticalAlign: "middle",
|
verticalAlign: "middle",
|
||||||
flex: "0 0 auto",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{icon}
|
{icon}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
--padding: 0;
|
--padding: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background-color: var(--island-bg-color);
|
background-color: var(--island-bg-color);
|
||||||
|
backdrop-filter: blur(40px);
|
||||||
|
-webkit-backdrop-filter: blur(40px);
|
||||||
box-shadow: var(--shadow-island);
|
box-shadow: var(--shadow-island);
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
padding: calc(var(--padding) * var(--space-factor));
|
padding: calc(var(--padding) * var(--space-factor));
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ import {
|
|||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
import { resizeSingleElement } from "@excalidraw/element";
|
import { resizeSingleElement } from "@excalidraw/element";
|
||||||
import { isImageElement } from "@excalidraw/element";
|
import { isImageElement } from "@excalidraw/element";
|
||||||
import { isFrameLikeElement } from "@excalidraw/element";
|
|
||||||
import { getElementsInResizingFrame } from "@excalidraw/element";
|
|
||||||
import { replaceAllElementsInFrame } from "@excalidraw/element";
|
|
||||||
|
|
||||||
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
@@ -18,10 +15,7 @@ import type { Scene } from "@excalidraw/element";
|
|||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import { getStepSizedValue, isPropertyEditable } from "./utils";
|
import { getStepSizedValue, isPropertyEditable } from "./utils";
|
||||||
|
|
||||||
import type {
|
import type { DragInputCallbackType } from "./DragInput";
|
||||||
DragFinishedCallbackType,
|
|
||||||
DragInputCallbackType,
|
|
||||||
} from "./DragInput";
|
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
|
|
||||||
interface DimensionDragInputProps {
|
interface DimensionDragInputProps {
|
||||||
@@ -49,8 +43,6 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
originalAppState,
|
originalAppState,
|
||||||
instantChange,
|
instantChange,
|
||||||
scene,
|
scene,
|
||||||
app,
|
|
||||||
setAppState,
|
|
||||||
}) => {
|
}) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const origElement = originalElements[0];
|
const origElement = originalElements[0];
|
||||||
@@ -161,7 +153,6 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// User types in a value to stats then presses Enter
|
|
||||||
if (nextValue !== undefined) {
|
if (nextValue !== undefined) {
|
||||||
const nextWidth = Math.max(
|
const nextWidth = Math.max(
|
||||||
property === "width"
|
property === "width"
|
||||||
@@ -193,123 +184,52 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle frame membership update for resized frames
|
|
||||||
if (isFrameLikeElement(latestElement)) {
|
|
||||||
const nextElementsInFrame = getElementsInResizingFrame(
|
|
||||||
scene.getElementsIncludingDeleted(),
|
|
||||||
latestElement,
|
|
||||||
originalAppState,
|
|
||||||
scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedElements = replaceAllElementsInFrame(
|
|
||||||
scene.getElementsIncludingDeleted(),
|
|
||||||
nextElementsInFrame,
|
|
||||||
latestElement,
|
|
||||||
app,
|
|
||||||
);
|
|
||||||
|
|
||||||
scene.replaceAllElements(updatedElements);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
||||||
|
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
||||||
|
|
||||||
// Stats slider is dragged
|
let nextWidth = Math.max(0, origElement.width + changeInWidth);
|
||||||
{
|
if (property === "width") {
|
||||||
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
if (shouldChangeByStepSize) {
|
||||||
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
||||||
|
} else {
|
||||||
let nextWidth = Math.max(0, origElement.width + changeInWidth);
|
nextWidth = Math.round(nextWidth);
|
||||||
if (property === "width") {
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
|
||||||
} else {
|
|
||||||
nextWidth = Math.round(nextWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let nextHeight = Math.max(0, origElement.height + changeInHeight);
|
|
||||||
if (property === "height") {
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
|
||||||
} else {
|
|
||||||
nextHeight = Math.round(nextHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keepAspectRatio) {
|
|
||||||
if (property === "width") {
|
|
||||||
nextHeight = Math.round((nextWidth / aspectRatio) * 100) / 100;
|
|
||||||
} else {
|
|
||||||
nextWidth = Math.round(nextHeight * aspectRatio * 100) / 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
|
||||||
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
|
||||||
|
|
||||||
resizeSingleElement(
|
|
||||||
nextWidth,
|
|
||||||
nextHeight,
|
|
||||||
latestElement,
|
|
||||||
origElement,
|
|
||||||
originalElementsMap,
|
|
||||||
scene,
|
|
||||||
property === "width" ? "e" : "s",
|
|
||||||
{
|
|
||||||
shouldMaintainAspectRatio: keepAspectRatio,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle highlighting frame element candidates
|
|
||||||
if (isFrameLikeElement(latestElement)) {
|
|
||||||
const nextElementsInFrame = getElementsInResizingFrame(
|
|
||||||
scene.getElementsIncludingDeleted(),
|
|
||||||
latestElement,
|
|
||||||
originalAppState,
|
|
||||||
scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
setAppState({
|
|
||||||
elementsToHighlight: nextElementsInFrame,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDragFinished: DragFinishedCallbackType = ({
|
let nextHeight = Math.max(0, origElement.height + changeInHeight);
|
||||||
setAppState,
|
if (property === "height") {
|
||||||
app,
|
if (shouldChangeByStepSize) {
|
||||||
originalElements,
|
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
||||||
originalAppState,
|
} else {
|
||||||
}) => {
|
nextHeight = Math.round(nextHeight);
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
}
|
||||||
const origElement = originalElements?.[0];
|
}
|
||||||
const latestElement = origElement && elementsMap.get(origElement.id);
|
|
||||||
|
|
||||||
// Handle frame membership update for resized frames
|
if (keepAspectRatio) {
|
||||||
if (latestElement && isFrameLikeElement(latestElement)) {
|
if (property === "width") {
|
||||||
const nextElementsInFrame = getElementsInResizingFrame(
|
nextHeight = Math.round((nextWidth / aspectRatio) * 100) / 100;
|
||||||
app.scene.getElementsIncludingDeleted(),
|
} else {
|
||||||
|
nextWidth = Math.round(nextHeight * aspectRatio * 100) / 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
||||||
|
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
||||||
|
|
||||||
|
resizeSingleElement(
|
||||||
|
nextWidth,
|
||||||
|
nextHeight,
|
||||||
latestElement,
|
latestElement,
|
||||||
originalAppState,
|
origElement,
|
||||||
app.scene.getNonDeletedElementsMap(),
|
originalElementsMap,
|
||||||
|
scene,
|
||||||
|
property === "width" ? "e" : "s",
|
||||||
|
{
|
||||||
|
shouldMaintainAspectRatio: keepAspectRatio,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const updatedElements = replaceAllElementsInFrame(
|
|
||||||
app.scene.getElementsIncludingDeleted(),
|
|
||||||
nextElementsInFrame,
|
|
||||||
latestElement,
|
|
||||||
app,
|
|
||||||
);
|
|
||||||
|
|
||||||
app.scene.replaceAllElements(updatedElements);
|
|
||||||
|
|
||||||
setAppState({
|
|
||||||
elementsToHighlight: null,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -349,7 +269,6 @@ const DimensionDragInput = ({
|
|||||||
scene={scene}
|
scene={scene}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
property={property}
|
property={property}
|
||||||
dragFinishedCallback={handleDragFinished}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
|
|||||||
|
|
||||||
import type { Scene } from "@excalidraw/element";
|
import type { Scene } from "@excalidraw/element";
|
||||||
|
|
||||||
import { useApp, useExcalidrawSetAppState } from "../App";
|
import { useApp } from "../App";
|
||||||
import { InlineIcon } from "../InlineIcon";
|
import { InlineIcon } from "../InlineIcon";
|
||||||
|
|
||||||
import { SMALLEST_DELTA } from "./utils";
|
import { SMALLEST_DELTA } from "./utils";
|
||||||
@@ -36,15 +36,6 @@ export type DragInputCallbackType<
|
|||||||
property: P;
|
property: P;
|
||||||
originalAppState: AppState;
|
originalAppState: AppState;
|
||||||
setInputValue: (value: number) => void;
|
setInputValue: (value: number) => void;
|
||||||
app: ReturnType<typeof useApp>;
|
|
||||||
setAppState: ReturnType<typeof useExcalidrawSetAppState>;
|
|
||||||
}) => void;
|
|
||||||
|
|
||||||
export type DragFinishedCallbackType<E = ExcalidrawElement> = (props: {
|
|
||||||
app: ReturnType<typeof useApp>;
|
|
||||||
setAppState: ReturnType<typeof useExcalidrawSetAppState>;
|
|
||||||
originalElements: readonly E[] | null;
|
|
||||||
originalAppState: AppState;
|
|
||||||
}) => void;
|
}) => void;
|
||||||
|
|
||||||
interface StatsDragInputProps<
|
interface StatsDragInputProps<
|
||||||
@@ -63,7 +54,6 @@ interface StatsDragInputProps<
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
/** how many px you need to drag to get 1 unit change */
|
/** how many px you need to drag to get 1 unit change */
|
||||||
sensitivity?: number;
|
sensitivity?: number;
|
||||||
dragFinishedCallback?: DragFinishedCallbackType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const StatsDragInput = <
|
const StatsDragInput = <
|
||||||
@@ -81,10 +71,8 @@ const StatsDragInput = <
|
|||||||
scene,
|
scene,
|
||||||
appState,
|
appState,
|
||||||
sensitivity = 1,
|
sensitivity = 1,
|
||||||
dragFinishedCallback,
|
|
||||||
}: StatsDragInputProps<T, E>) => {
|
}: StatsDragInputProps<T, E>) => {
|
||||||
const app = useApp();
|
const app = useApp();
|
||||||
const setAppState = useExcalidrawSetAppState();
|
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const labelRef = useRef<HTMLDivElement>(null);
|
const labelRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
@@ -149,8 +137,6 @@ const StatsDragInput = <
|
|||||||
property,
|
property,
|
||||||
originalAppState: appState,
|
originalAppState: appState,
|
||||||
setInputValue: (value) => setInputValue(String(value)),
|
setInputValue: (value) => setInputValue(String(value)),
|
||||||
app,
|
|
||||||
setAppState,
|
|
||||||
});
|
});
|
||||||
app.syncActionResult({
|
app.syncActionResult({
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
@@ -277,8 +263,6 @@ const StatsDragInput = <
|
|||||||
scene,
|
scene,
|
||||||
originalAppState,
|
originalAppState,
|
||||||
setInputValue: (value) => setInputValue(String(value)),
|
setInputValue: (value) => setInputValue(String(value)),
|
||||||
app,
|
|
||||||
setAppState,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
stepChange = 0;
|
stepChange = 0;
|
||||||
@@ -303,14 +287,6 @@ const StatsDragInput = <
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Notify implementors
|
|
||||||
dragFinishedCallback?.({
|
|
||||||
app,
|
|
||||||
setAppState,
|
|
||||||
originalElements,
|
|
||||||
originalAppState,
|
|
||||||
});
|
|
||||||
|
|
||||||
lastPointer = null;
|
lastPointer = null;
|
||||||
accumulatedChange = 0;
|
accumulatedChange = 0;
|
||||||
stepChange = 0;
|
stepChange = 0;
|
||||||
|
|||||||
@@ -2,12 +2,7 @@ import { pointFrom, type GlobalPoint } from "@excalidraw/math";
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
|
||||||
import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common";
|
import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common";
|
||||||
import {
|
import { updateBoundElements } from "@excalidraw/element";
|
||||||
getElementsInResizingFrame,
|
|
||||||
isFrameLikeElement,
|
|
||||||
replaceAllElementsInFrame,
|
|
||||||
updateBoundElements,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
import {
|
import {
|
||||||
rescalePointsInElement,
|
rescalePointsInElement,
|
||||||
resizeSingleElement,
|
resizeSingleElement,
|
||||||
@@ -30,10 +25,7 @@ import DragInput from "./DragInput";
|
|||||||
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
||||||
import { getElementsInAtomicUnit } from "./utils";
|
import { getElementsInAtomicUnit } from "./utils";
|
||||||
|
|
||||||
import type {
|
import type { DragInputCallbackType } from "./DragInput";
|
||||||
DragFinishedCallbackType,
|
|
||||||
DragInputCallbackType,
|
|
||||||
} from "./DragInput";
|
|
||||||
import type { AtomicUnit } from "./utils";
|
import type { AtomicUnit } from "./utils";
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
|
|
||||||
@@ -161,8 +153,6 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
nextValue,
|
nextValue,
|
||||||
scene,
|
scene,
|
||||||
property,
|
property,
|
||||||
setAppState,
|
|
||||||
app,
|
|
||||||
}) => {
|
}) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
const atomicUnits = getAtomicUnits(originalElements, originalAppState);
|
const atomicUnits = getAtomicUnits(originalElements, originalAppState);
|
||||||
@@ -249,25 +239,6 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
shouldInformMutation: false,
|
shouldInformMutation: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle frame membership update for resized frames
|
|
||||||
if (isFrameLikeElement(latestElement)) {
|
|
||||||
const nextElementsInFrame = getElementsInResizingFrame(
|
|
||||||
scene.getElementsIncludingDeleted(),
|
|
||||||
latestElement,
|
|
||||||
originalAppState,
|
|
||||||
scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedElements = replaceAllElementsInFrame(
|
|
||||||
scene.getElementsIncludingDeleted(),
|
|
||||||
nextElementsInFrame,
|
|
||||||
latestElement,
|
|
||||||
app,
|
|
||||||
);
|
|
||||||
|
|
||||||
scene.replaceAllElements(updatedElements);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +250,6 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
|
|
||||||
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
||||||
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
||||||
const elementsToHighlight: ExcalidrawElement[] = [];
|
|
||||||
|
|
||||||
for (const atomicUnit of atomicUnits) {
|
for (const atomicUnit of atomicUnits) {
|
||||||
const elementsInUnit = getElementsInAtomicUnit(
|
const elementsInUnit = getElementsInAtomicUnit(
|
||||||
@@ -372,63 +342,13 @@ const handleDimensionChange: DragInputCallbackType<
|
|||||||
shouldInformMutation: false,
|
shouldInformMutation: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle highlighting frame element candidates
|
|
||||||
if (isFrameLikeElement(latestElement)) {
|
|
||||||
const nextElementsInFrame = getElementsInResizingFrame(
|
|
||||||
scene.getElementsIncludingDeleted(),
|
|
||||||
latestElement,
|
|
||||||
originalAppState,
|
|
||||||
scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
elementsToHighlight.push(...nextElementsInFrame);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setAppState({
|
|
||||||
elementsToHighlight,
|
|
||||||
});
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
scene.triggerUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDragFinished: DragFinishedCallbackType = ({
|
|
||||||
setAppState,
|
|
||||||
app,
|
|
||||||
originalElements,
|
|
||||||
originalAppState,
|
|
||||||
}) => {
|
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
|
||||||
const origElement = originalElements?.[0];
|
|
||||||
const latestElement = origElement && elementsMap.get(origElement.id);
|
|
||||||
|
|
||||||
// Handle frame membership update for resized frames
|
|
||||||
if (latestElement && isFrameLikeElement(latestElement)) {
|
|
||||||
const nextElementsInFrame = getElementsInResizingFrame(
|
|
||||||
app.scene.getElementsIncludingDeleted(),
|
|
||||||
latestElement,
|
|
||||||
originalAppState,
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedElements = replaceAllElementsInFrame(
|
|
||||||
app.scene.getElementsIncludingDeleted(),
|
|
||||||
nextElementsInFrame,
|
|
||||||
latestElement,
|
|
||||||
app,
|
|
||||||
);
|
|
||||||
|
|
||||||
app.scene.replaceAllElements(updatedElements);
|
|
||||||
|
|
||||||
setAppState({
|
|
||||||
elementsToHighlight: null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const MultiDimension = ({
|
const MultiDimension = ({
|
||||||
property,
|
property,
|
||||||
elements,
|
elements,
|
||||||
@@ -476,7 +396,6 @@ const MultiDimension = ({
|
|||||||
appState={appState}
|
appState={appState}
|
||||||
property={property}
|
property={property}
|
||||||
scene={scene}
|
scene={scene}
|
||||||
dragFinishedCallback={handleDragFinished}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -401,23 +401,11 @@ describe("stats for a non-generic element", () => {
|
|||||||
UI.updateInput(input, "36");
|
UI.updateInput(input, "36");
|
||||||
expect(text.fontSize).toBe(36);
|
expect(text.fontSize).toBe(36);
|
||||||
|
|
||||||
// can change width or height
|
// cannot change width or height
|
||||||
const width = UI.queryStatsProperty("W")?.querySelector(
|
const width = UI.queryStatsProperty("W")?.querySelector(".drag-input");
|
||||||
".drag-input",
|
expect(width).toBeUndefined();
|
||||||
) as HTMLInputElement;
|
const height = UI.queryStatsProperty("H")?.querySelector(".drag-input");
|
||||||
expect(width).toBeDefined();
|
expect(height).toBeUndefined();
|
||||||
const height = UI.queryStatsProperty("H")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(height).toBeDefined();
|
|
||||||
|
|
||||||
const textHeightBeforeWrapping = text.height;
|
|
||||||
const textBeforeWrapping = text.text;
|
|
||||||
const originalTextBeforeWrapping = textBeforeWrapping;
|
|
||||||
UI.updateInput(width, "30");
|
|
||||||
expect(text.height).toBeGreaterThan(textHeightBeforeWrapping);
|
|
||||||
expect(text.text).not.toBe(textBeforeWrapping);
|
|
||||||
expect(text.originalText).toBe(originalTextBeforeWrapping);
|
|
||||||
|
|
||||||
// min font size is 4
|
// min font size is 4
|
||||||
UI.updateInput(input, "0");
|
UI.updateInput(input, "0");
|
||||||
@@ -639,11 +627,12 @@ describe("stats for multiple elements", () => {
|
|||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
expect(fontSize).toBeDefined();
|
expect(fontSize).toBeDefined();
|
||||||
|
|
||||||
|
// changing width does not affect text
|
||||||
UI.updateInput(width, "200");
|
UI.updateInput(width, "200");
|
||||||
|
|
||||||
expect(rectangle?.width).toBe(200);
|
expect(rectangle?.width).toBe(200);
|
||||||
expect(frame.width).toBe(200);
|
expect(frame.width).toBe(200);
|
||||||
expect(text?.width).toBe(200);
|
expect(text?.width).not.toBe(200);
|
||||||
|
|
||||||
UI.updateInput(angle, "40");
|
UI.updateInput(angle, "40");
|
||||||
|
|
||||||
@@ -737,196 +726,3 @@ describe("stats for multiple elements", () => {
|
|||||||
expect(newGroupHeight).toBeCloseTo(500, 4);
|
expect(newGroupHeight).toBeCloseTo(500, 4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("frame resizing behavior", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
localStorage.clear();
|
|
||||||
renderStaticScene.mockClear();
|
|
||||||
reseed(7);
|
|
||||||
setDateTimeForTests("201933152653");
|
|
||||||
|
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
||||||
|
|
||||||
API.setElements([]);
|
|
||||||
|
|
||||||
fireEvent.contextMenu(GlobalTestState.interactiveCanvas, {
|
|
||||||
button: 2,
|
|
||||||
clientX: 1,
|
|
||||||
clientY: 1,
|
|
||||||
});
|
|
||||||
const contextMenu = UI.queryContextMenu();
|
|
||||||
fireEvent.click(queryByTestId(contextMenu!, "stats")!);
|
|
||||||
stats = UI.queryStats();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
mockBoundingClientRect();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
restoreOriginalGetBoundingClientRect();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should add shapes to frame when resizing frame to encompass them", () => {
|
|
||||||
// Create a frame
|
|
||||||
const frame = API.createElement({
|
|
||||||
type: "frame",
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 100,
|
|
||||||
height: 100,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create a rectangle outside the frame
|
|
||||||
const rectangle = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 150,
|
|
||||||
y: 50,
|
|
||||||
width: 50,
|
|
||||||
height: 50,
|
|
||||||
});
|
|
||||||
|
|
||||||
API.setElements([frame, rectangle]);
|
|
||||||
|
|
||||||
// Initially, rectangle should not be in the frame
|
|
||||||
expect(rectangle.frameId).toBe(null);
|
|
||||||
|
|
||||||
// Select the frame
|
|
||||||
API.setAppState({
|
|
||||||
selectedElementIds: {
|
|
||||||
[frame.id]: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
// Find the width input and update it to encompass the rectangle
|
|
||||||
const widthInput = UI.queryStatsProperty("W")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(widthInput).toBeDefined();
|
|
||||||
expect(widthInput.value).toBe("100");
|
|
||||||
|
|
||||||
// Resize frame to width 250, which should encompass the rectangle
|
|
||||||
UI.updateInput(widthInput, "250");
|
|
||||||
|
|
||||||
// After resizing, the rectangle should now be part of the frame
|
|
||||||
expect(h.elements.find((el) => el.id === rectangle.id)?.frameId).toBe(
|
|
||||||
frame.id,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should add multiple shapes when frame encompasses them through height resize", () => {
|
|
||||||
const frame = API.createElement({
|
|
||||||
type: "frame",
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 200,
|
|
||||||
height: 100,
|
|
||||||
});
|
|
||||||
|
|
||||||
const rectangle1 = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 50,
|
|
||||||
y: 150,
|
|
||||||
width: 50,
|
|
||||||
height: 50,
|
|
||||||
});
|
|
||||||
|
|
||||||
const rectangle2 = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 100,
|
|
||||||
y: 180,
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
});
|
|
||||||
|
|
||||||
API.setElements([frame, rectangle1, rectangle2]);
|
|
||||||
|
|
||||||
// Initially, rectangles should not be in the frame
|
|
||||||
expect(rectangle1.frameId).toBe(null);
|
|
||||||
expect(rectangle2.frameId).toBe(null);
|
|
||||||
|
|
||||||
// Select the frame
|
|
||||||
API.setAppState({
|
|
||||||
selectedElementIds: {
|
|
||||||
[frame.id]: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
// Resize frame height to encompass both rectangles
|
|
||||||
const heightInput = UI.queryStatsProperty("H")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
// Resize frame to height 250, which should encompass both rectangles
|
|
||||||
UI.updateInput(heightInput, "250");
|
|
||||||
|
|
||||||
// After resizing, both rectangles should now be part of the frame
|
|
||||||
expect(h.elements.find((el) => el.id === rectangle1.id)?.frameId).toBe(
|
|
||||||
frame.id,
|
|
||||||
);
|
|
||||||
expect(h.elements.find((el) => el.id === rectangle2.id)?.frameId).toBe(
|
|
||||||
frame.id,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should not affect shapes that remain outside frame after resize", () => {
|
|
||||||
const frame = API.createElement({
|
|
||||||
type: "frame",
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 100,
|
|
||||||
height: 100,
|
|
||||||
});
|
|
||||||
|
|
||||||
const insideRect = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 120,
|
|
||||||
y: 50,
|
|
||||||
width: 30,
|
|
||||||
height: 30,
|
|
||||||
});
|
|
||||||
|
|
||||||
const outsideRect = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
x: 300,
|
|
||||||
y: 50,
|
|
||||||
width: 30,
|
|
||||||
height: 30,
|
|
||||||
});
|
|
||||||
|
|
||||||
API.setElements([frame, insideRect, outsideRect]);
|
|
||||||
|
|
||||||
// Initially, both rectangles should not be in the frame
|
|
||||||
expect(insideRect.frameId).toBe(null);
|
|
||||||
expect(outsideRect.frameId).toBe(null);
|
|
||||||
|
|
||||||
// Select the frame
|
|
||||||
API.setAppState({
|
|
||||||
selectedElementIds: {
|
|
||||||
[frame.id]: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
// Resize frame width to 200, which should only encompass insideRect
|
|
||||||
const widthInput = UI.queryStatsProperty("W")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
UI.updateInput(widthInput, "200");
|
|
||||||
|
|
||||||
// After resizing, only insideRect should be in the frame
|
|
||||||
expect(h.elements.find((el) => el.id === insideRect.id)?.frameId).toBe(
|
|
||||||
frame.id,
|
|
||||||
);
|
|
||||||
expect(h.elements.find((el) => el.id === outsideRect.id)?.frameId).toBe(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { pointFrom, pointRotateRads } from "@excalidraw/math";
|
import { pointFrom, pointRotateRads } from "@excalidraw/math";
|
||||||
|
|
||||||
import { getBoundTextElement } from "@excalidraw/element";
|
import { getBoundTextElement } from "@excalidraw/element";
|
||||||
import { isFrameLikeElement } from "@excalidraw/element";
|
import { isFrameLikeElement, isTextElement } from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getSelectedGroupIds,
|
getSelectedGroupIds,
|
||||||
@@ -41,6 +41,12 @@ export const isPropertyEditable = (
|
|||||||
element: ExcalidrawElement,
|
element: ExcalidrawElement,
|
||||||
property: keyof ExcalidrawElement,
|
property: keyof ExcalidrawElement,
|
||||||
) => {
|
) => {
|
||||||
|
if (property === "height" && isTextElement(element)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (property === "width" && isTextElement(element)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (property === "angle" && isFrameLikeElement(element)) {
|
if (property === "angle" && isFrameLikeElement(element)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ const getRelevantAppStateProps = (
|
|||||||
viewModeEnabled: appState.viewModeEnabled,
|
viewModeEnabled: appState.viewModeEnabled,
|
||||||
openDialog: appState.openDialog,
|
openDialog: appState.openDialog,
|
||||||
editingGroupId: appState.editingGroupId,
|
editingGroupId: appState.editingGroupId,
|
||||||
|
editingLinearElement: appState.editingLinearElement,
|
||||||
selectedElementIds: appState.selectedElementIds,
|
selectedElementIds: appState.selectedElementIds,
|
||||||
frameToHighlight: appState.frameToHighlight,
|
frameToHighlight: appState.frameToHighlight,
|
||||||
offsetLeft: appState.offsetLeft,
|
offsetLeft: appState.offsetLeft,
|
||||||
|
|||||||
@@ -34,13 +34,6 @@ const StaticCanvas = (props: StaticCanvasProps) => {
|
|||||||
const wrapperRef = useRef<HTMLDivElement>(null);
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
||||||
const isComponentMounted = useRef(false);
|
const isComponentMounted = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
props.canvas.style.width = `${props.appState.width}px`;
|
|
||||||
props.canvas.style.height = `${props.appState.height}px`;
|
|
||||||
props.canvas.width = props.appState.width * props.scale;
|
|
||||||
props.canvas.height = props.appState.height * props.scale;
|
|
||||||
}, [props.appState.height, props.appState.width, props.canvas, props.scale]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const wrapper = wrapperRef.current;
|
const wrapper = wrapperRef.current;
|
||||||
if (!wrapper) {
|
if (!wrapper) {
|
||||||
@@ -56,6 +49,26 @@ const StaticCanvas = (props: StaticCanvasProps) => {
|
|||||||
canvas.classList.add("excalidraw__canvas", "static");
|
canvas.classList.add("excalidraw__canvas", "static");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const widthString = `${props.appState.width}px`;
|
||||||
|
const heightString = `${props.appState.height}px`;
|
||||||
|
if (canvas.style.width !== widthString) {
|
||||||
|
canvas.style.width = widthString;
|
||||||
|
}
|
||||||
|
if (canvas.style.height !== heightString) {
|
||||||
|
canvas.style.height = heightString;
|
||||||
|
}
|
||||||
|
|
||||||
|
const scaledWidth = props.appState.width * props.scale;
|
||||||
|
const scaledHeight = props.appState.height * props.scale;
|
||||||
|
// setting width/height resets the canvas even if dimensions not changed,
|
||||||
|
// which would cause flicker when we skip frame (due to throttling)
|
||||||
|
if (canvas.width !== scaledWidth) {
|
||||||
|
canvas.width = scaledWidth;
|
||||||
|
}
|
||||||
|
if (canvas.height !== scaledHeight) {
|
||||||
|
canvas.height = scaledHeight;
|
||||||
|
}
|
||||||
|
|
||||||
renderStaticScene(
|
renderStaticScene(
|
||||||
{
|
{
|
||||||
canvas,
|
canvas,
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
position: relative;
|
position: relative;
|
||||||
transition: box-shadow 0.5s ease-in-out;
|
transition: box-shadow 0.5s ease-in-out;
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
&.zen-mode {
|
&.zen-mode {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
@@ -102,7 +100,6 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border-radius: var(--border-radius-md);
|
border-radius: var(--border-radius-md);
|
||||||
flex: 1 0 auto;
|
|
||||||
|
|
||||||
@media screen and (min-width: 1921px) {
|
@media screen and (min-width: 1921px) {
|
||||||
height: 2.25rem;
|
height: 2.25rem;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { useDevice } from "../App";
|
import { useDevice } from "../App";
|
||||||
|
|
||||||
import { Ellipsify } from "../Ellipsify";
|
|
||||||
|
|
||||||
import type { JSX } from "react";
|
import type { JSX } from "react";
|
||||||
|
|
||||||
const MenuItemContent = ({
|
const MenuItemContent = ({
|
||||||
@@ -20,7 +18,7 @@ const MenuItemContent = ({
|
|||||||
<>
|
<>
|
||||||
{icon && <div className="dropdown-menu-item__icon">{icon}</div>}
|
{icon && <div className="dropdown-menu-item__icon">{icon}</div>}
|
||||||
<div style={textStyle} className="dropdown-menu-item__text">
|
<div style={textStyle} className="dropdown-menu-item__text">
|
||||||
<Ellipsify>{children}</Ellipsify>
|
{children}
|
||||||
</div>
|
</div>
|
||||||
{shortcut && !device.editor.isMobile && (
|
{shortcut && !device.editor.isMobile && (
|
||||||
<div className="dropdown-menu-item__shortcut">{shortcut}</div>
|
<div className="dropdown-menu-item__shortcut">{shortcut}</div>
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ import clsx from "clsx";
|
|||||||
|
|
||||||
import { actionShortcuts } from "../../actions";
|
import { actionShortcuts } from "../../actions";
|
||||||
import { useTunnels } from "../../context/tunnels";
|
import { useTunnels } from "../../context/tunnels";
|
||||||
import { ExitZenModeAction, UndoRedoActions, ZoomActions } from "../Actions";
|
import {
|
||||||
|
ExitZenModeAction,
|
||||||
|
FinalizeAction,
|
||||||
|
UndoRedoActions,
|
||||||
|
ZoomActions,
|
||||||
|
} from "../Actions";
|
||||||
|
import { useDevice } from "../App";
|
||||||
import { HelpButton } from "../HelpButton";
|
import { HelpButton } from "../HelpButton";
|
||||||
import { Section } from "../Section";
|
import { Section } from "../Section";
|
||||||
import Stack from "../Stack";
|
import Stack from "../Stack";
|
||||||
@@ -23,6 +29,10 @@ const Footer = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { FooterCenterTunnel, WelcomeScreenHelpHintTunnel } = useTunnels();
|
const { FooterCenterTunnel, WelcomeScreenHelpHintTunnel } = useTunnels();
|
||||||
|
|
||||||
|
const device = useDevice();
|
||||||
|
const showFinalize =
|
||||||
|
!appState.viewModeEnabled && appState.multiElement && device.isTouchScreen;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<footer
|
<footer
|
||||||
role="contentinfo"
|
role="contentinfo"
|
||||||
@@ -50,6 +60,15 @@ const Footer = ({
|
|||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{showFinalize && (
|
||||||
|
<FinalizeAction
|
||||||
|
renderAction={actionManager.renderAction}
|
||||||
|
className={clsx("zen-mode-transition", {
|
||||||
|
"layer-ui__wrapper__footer-left--transition-left":
|
||||||
|
appState.zenModeEnabled,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import {
|
|||||||
EraserIcon,
|
EraserIcon,
|
||||||
} from "./icons";
|
} from "./icons";
|
||||||
|
|
||||||
import type { AppClassProperties } from "../types";
|
|
||||||
|
|
||||||
export const SHAPES = [
|
export const SHAPES = [
|
||||||
{
|
{
|
||||||
icon: SelectionIcon,
|
icon: SelectionIcon,
|
||||||
@@ -88,23 +86,8 @@ export const SHAPES = [
|
|||||||
},
|
},
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const getToolbarTools = (app: AppClassProperties) => {
|
export const findShapeByKey = (key: string) => {
|
||||||
return app.defaultSelectionTool === "lasso"
|
const shape = SHAPES.find((shape, index) => {
|
||||||
? ([
|
|
||||||
{
|
|
||||||
value: "lasso",
|
|
||||||
icon: SelectionIcon,
|
|
||||||
key: KEYS.V,
|
|
||||||
numericKey: KEYS["1"],
|
|
||||||
fillable: true,
|
|
||||||
},
|
|
||||||
...SHAPES.slice(1),
|
|
||||||
] as const)
|
|
||||||
: SHAPES;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const findShapeByKey = (key: string, app: AppClassProperties) => {
|
|
||||||
const shape = getToolbarTools(app).find((shape, index) => {
|
|
||||||
return (
|
return (
|
||||||
(shape.numericKey != null && key === shape.numericKey.toString()) ||
|
(shape.numericKey != null && key === shape.numericKey.toString()) ||
|
||||||
(shape.key &&
|
(shape.key &&
|
||||||
|
|||||||
@@ -386,6 +386,9 @@ body.excalidraw-cursor-resize * {
|
|||||||
width: 12.5rem;
|
width: 12.5rem;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
background: transparent !important;
|
||||||
|
backdrop-filter: blur(40px);
|
||||||
|
-webkit-backdrop-filter: blur(40px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown-select {
|
.dropdown-select {
|
||||||
@@ -648,14 +651,16 @@ body.excalidraw-cursor-resize * {
|
|||||||
.App-mobile-menu,
|
.App-mobile-menu,
|
||||||
.App-menu__left {
|
.App-menu__left {
|
||||||
--button-border: transparent;
|
--button-border: transparent;
|
||||||
--button-bg: var(--color-surface-mid);
|
// --button-bg: var(--color-surface-mid);
|
||||||
|
--button-bg: rgba(255, 255, 255, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@at-root .excalidraw.theme--dark#{&} {
|
@at-root .excalidraw.theme--dark#{&} {
|
||||||
.App-mobile-menu,
|
.App-mobile-menu,
|
||||||
.App-menu__left {
|
.App-menu__left {
|
||||||
--button-hover-bg: #363541;
|
--button-hover-bg: #363541;
|
||||||
--button-bg: var(--color-surface-high);
|
// --button-bg: var(--color-surface-high);
|
||||||
|
--button-bg: rgba(0, 0, 0, 0.15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
--input-border-color: #{$oc-gray-4};
|
--input-border-color: #{$oc-gray-4};
|
||||||
--input-hover-bg-color: #{$oc-gray-1};
|
--input-hover-bg-color: #{$oc-gray-1};
|
||||||
--input-label-color: #{$oc-gray-7};
|
--input-label-color: #{$oc-gray-7};
|
||||||
--island-bg-color: #ffffff;
|
--island-bg-color: transparent !important;
|
||||||
--keybinding-color: var(--color-gray-40);
|
--keybinding-color: var(--color-gray-40);
|
||||||
--link-color: #{$oc-blue-7};
|
--link-color: #{$oc-blue-7};
|
||||||
--overlay-bg-color: #{transparentize($oc-white, 0.12)};
|
--overlay-bg-color: #{transparentize($oc-white, 0.12)};
|
||||||
@@ -149,16 +149,16 @@
|
|||||||
|
|
||||||
--color-surface-high: #f1f0ff;
|
--color-surface-high: #f1f0ff;
|
||||||
--color-surface-mid: #f6f6f9;
|
--color-surface-mid: #f6f6f9;
|
||||||
--color-surface-low: #ececf4;
|
--color-surface-low: rgba(236, 236, 244, 0.1);
|
||||||
--color-surface-lowest: #ffffff;
|
--color-surface-lowest: #ffffff;
|
||||||
--color-on-surface: #1b1b1f;
|
--color-on-surface: #1b1b1f;
|
||||||
--color-brand-hover: #5753d0;
|
--color-brand-hover: #5753d0;
|
||||||
--color-on-primary-container: #030064;
|
--color-on-primary-container: #030064;
|
||||||
--color-surface-primary-container: #e0dfff;
|
--color-surface-primary-container: rgba(224, 223, 255, 0.7);
|
||||||
--color-brand-active: #4440bf;
|
--color-brand-active: #4440bf;
|
||||||
--color-border-outline: #767680;
|
--color-border-outline: #767680;
|
||||||
--color-border-outline-variant: #c5c5d0;
|
--color-border-outline-variant: #c5c5d0;
|
||||||
--color-surface-primary-container: #e0dfff;
|
// --color-surface-primary-container: #e0dfff;
|
||||||
|
|
||||||
--color-badge: #0b6513;
|
--color-badge: #0b6513;
|
||||||
--background-color-badge: #d3ffd2;
|
--background-color-badge: #d3ffd2;
|
||||||
@@ -253,16 +253,15 @@
|
|||||||
--color-logo-text: #e2dfff;
|
--color-logo-text: #e2dfff;
|
||||||
|
|
||||||
--color-surface-high: #2e2d39;
|
--color-surface-high: #2e2d39;
|
||||||
--color-surface-low: hsl(240, 8%, 15%);
|
--color-surface-low: rgba(35, 35, 41, 0.1);
|
||||||
--color-surface-mid: hsl(240 6% 10%);
|
--color-surface-mid: hsl(240 6% 10%);
|
||||||
--color-surface-lowest: hsl(0, 0%, 7%);
|
--color-surface-lowest: hsl(0, 0%, 7%);
|
||||||
--color-on-surface: #e3e3e8;
|
--color-on-surface: #e3e3e8;
|
||||||
--color-brand-hover: #bbb8ff;
|
--color-brand-hover: #bbb8ff;
|
||||||
--color-on-primary-container: #e0dfff;
|
--color-on-primary-container: #e0dfff;
|
||||||
--color-surface-primary-container: #403e6a;
|
--color-surface-primary-container: rgba(64, 62, 106, 0.7);
|
||||||
--color-brand-active: #d0ccff;
|
--color-brand-active: #d0ccff;
|
||||||
--color-border-outline: #8e8d9c;
|
--color-border-outline: #8e8d9c;
|
||||||
--color-border-outline-variant: #46464f;
|
--color-border-outline-variant: #46464f;
|
||||||
--color-surface-primary-container: #403e6a;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,10 @@
|
|||||||
color: var(--button-color, var(--color-on-surface));
|
color: var(--button-color, var(--color-on-surface));
|
||||||
font-family: var(--ui-font);
|
font-family: var(--ui-font);
|
||||||
|
|
||||||
|
// background: transparent !important;
|
||||||
|
backdrop-filter: blur(40px);
|
||||||
|
-webkit-backdrop-filter: blur(40px);
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: var(--button-width, var(--lg-icon-size));
|
width: var(--button-width, var(--lg-icon-size));
|
||||||
height: var(--button-height, var(--lg-icon-size));
|
height: var(--button-height, var(--lg-icon-size));
|
||||||
@@ -183,6 +187,8 @@
|
|||||||
border: none;
|
border: none;
|
||||||
box-shadow: 0 0 0 1px var(--color-surface-lowest);
|
box-shadow: 0 0 0 1px var(--color-surface-lowest);
|
||||||
background-color: var(--color-surface-low);
|
background-color: var(--color-surface-low);
|
||||||
|
backdrop-filter: blur(40px);
|
||||||
|
-webkit-backdrop-filter: blur(40px);
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
box-shadow: 0 0 0 1px var(--color-brand-active);
|
box-shadow: 0 0 0 1px var(--color-brand-active);
|
||||||
|
|||||||
@@ -1791,7 +1791,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"versionNonce": Any<Number>,
|
"versionNonce": Any<Number>,
|
||||||
"verticalAlign": "middle",
|
"verticalAlign": "middle",
|
||||||
"width": 120,
|
"width": 120,
|
||||||
"x": 187.75450000000004,
|
"x": 187.7545,
|
||||||
"y": 44.5,
|
"y": 44.5,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -170,11 +170,7 @@ export const loadSceneOrLibraryFromBlob = async (
|
|||||||
},
|
},
|
||||||
localAppState,
|
localAppState,
|
||||||
localElements,
|
localElements,
|
||||||
{
|
{ repairBindings: true, refreshDimensions: false },
|
||||||
repairBindings: true,
|
|
||||||
refreshDimensions: false,
|
|
||||||
deleteInvisibleElements: true,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else if (isValidLibrary(data)) {
|
} else if (isValidLibrary(data)) {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export type ReconciledExcalidrawElement = OrderedExcalidrawElement &
|
|||||||
export type RemoteExcalidrawElement = OrderedExcalidrawElement &
|
export type RemoteExcalidrawElement = OrderedExcalidrawElement &
|
||||||
MakeBrand<"RemoteExcalidrawElement">;
|
MakeBrand<"RemoteExcalidrawElement">;
|
||||||
|
|
||||||
export const shouldDiscardRemoteElement = (
|
const shouldDiscardRemoteElement = (
|
||||||
localAppState: AppState,
|
localAppState: AppState,
|
||||||
local: OrderedExcalidrawElement | undefined,
|
local: OrderedExcalidrawElement | undefined,
|
||||||
remote: RemoteExcalidrawElement,
|
remote: RemoteExcalidrawElement,
|
||||||
@@ -30,7 +30,7 @@ export const shouldDiscardRemoteElement = (
|
|||||||
// local element is being edited
|
// local element is being edited
|
||||||
(local.id === localAppState.editingTextElement?.id ||
|
(local.id === localAppState.editingTextElement?.id ||
|
||||||
local.id === localAppState.resizingElement?.id ||
|
local.id === localAppState.resizingElement?.id ||
|
||||||
local.id === localAppState.newElement?.id ||
|
local.id === localAppState.newElement?.id || // TODO: Is this still valid? As newElement is selection element, which is never part of the elements array
|
||||||
// local element is newer
|
// local element is newer
|
||||||
local.version > remote.version ||
|
local.version > remote.version ||
|
||||||
// resolve conflicting edits deterministically by taking the one with
|
// resolve conflicting edits deterministically by taking the one with
|
||||||
|
|||||||
@@ -241,9 +241,8 @@ const restoreElementWithProperties = <
|
|||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const restoreElement = (
|
const restoreElement = (
|
||||||
element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
||||||
opts?: { deleteInvisibleElements?: boolean },
|
|
||||||
): typeof element | null => {
|
): typeof element | null => {
|
||||||
element = { ...element };
|
element = { ...element };
|
||||||
|
|
||||||
@@ -291,8 +290,7 @@ export const restoreElement = (
|
|||||||
|
|
||||||
// if empty text, mark as deleted. We keep in array
|
// if empty text, mark as deleted. We keep in array
|
||||||
// for data integrity purposes (collab etc.)
|
// for data integrity purposes (collab etc.)
|
||||||
if (opts?.deleteInvisibleElements && !text && !element.isDeleted) {
|
if (!text && !element.isDeleted) {
|
||||||
// TODO: we should not do this since it breaks sync / versioning when we exchange / apply just deltas and restore the elements (deletion isn't recorded)
|
|
||||||
element = { ...element, originalText: text, isDeleted: true };
|
element = { ...element, originalText: text, isDeleted: true };
|
||||||
element = bumpVersion(element);
|
element = bumpVersion(element);
|
||||||
}
|
}
|
||||||
@@ -525,13 +523,7 @@ export const restoreElements = (
|
|||||||
elements: ImportedDataState["elements"],
|
elements: ImportedDataState["elements"],
|
||||||
/** NOTE doesn't serve for reconciliation */
|
/** NOTE doesn't serve for reconciliation */
|
||||||
localElements: readonly ExcalidrawElement[] | null | undefined,
|
localElements: readonly ExcalidrawElement[] | null | undefined,
|
||||||
opts?:
|
opts?: { refreshDimensions?: boolean; repairBindings?: boolean } | undefined,
|
||||||
| {
|
|
||||||
refreshDimensions?: boolean;
|
|
||||||
repairBindings?: boolean;
|
|
||||||
deleteInvisibleElements?: boolean;
|
|
||||||
}
|
|
||||||
| undefined,
|
|
||||||
): 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>();
|
||||||
@@ -540,38 +532,24 @@ export const restoreElements = (
|
|||||||
(elements || []).reduce((elements, element) => {
|
(elements || []).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" && !isInvisiblySmallElement(element)) {
|
||||||
return elements;
|
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
||||||
|
if (migratedElement) {
|
||||||
|
const localElement = localElementsMap?.get(element.id);
|
||||||
|
if (localElement && localElement.version > migratedElement.version) {
|
||||||
|
migratedElement = bumpVersion(
|
||||||
|
migratedElement,
|
||||||
|
localElement.version,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (existingIds.has(migratedElement.id)) {
|
||||||
|
migratedElement = { ...migratedElement, id: randomId() };
|
||||||
|
}
|
||||||
|
existingIds.add(migratedElement.id);
|
||||||
|
|
||||||
|
elements.push(migratedElement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let migratedElement: ExcalidrawElement | null = restoreElement(element, {
|
|
||||||
deleteInvisibleElements: opts?.deleteInvisibleElements,
|
|
||||||
});
|
|
||||||
if (migratedElement) {
|
|
||||||
const localElement = localElementsMap?.get(element.id);
|
|
||||||
|
|
||||||
const shouldMarkAsDeleted =
|
|
||||||
opts?.deleteInvisibleElements && isInvisiblySmallElement(element);
|
|
||||||
|
|
||||||
if (
|
|
||||||
shouldMarkAsDeleted ||
|
|
||||||
(localElement && localElement.version > migratedElement.version)
|
|
||||||
) {
|
|
||||||
migratedElement = bumpVersion(migratedElement, localElement?.version);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldMarkAsDeleted) {
|
|
||||||
migratedElement = { ...migratedElement, isDeleted: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingIds.has(migratedElement.id)) {
|
|
||||||
migratedElement = { ...migratedElement, id: randomId() };
|
|
||||||
}
|
|
||||||
existingIds.add(migratedElement.id);
|
|
||||||
|
|
||||||
elements.push(migratedElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
}, [] as ExcalidrawElement[]),
|
}, [] as ExcalidrawElement[]),
|
||||||
);
|
);
|
||||||
@@ -812,11 +790,7 @@ export const restore = (
|
|||||||
*/
|
*/
|
||||||
localAppState: Partial<AppState> | null | undefined,
|
localAppState: Partial<AppState> | null | undefined,
|
||||||
localElements: readonly ExcalidrawElement[] | null | undefined,
|
localElements: readonly ExcalidrawElement[] | null | undefined,
|
||||||
elementsConfig?: {
|
elementsConfig?: { refreshDimensions?: boolean; repairBindings?: boolean },
|
||||||
refreshDimensions?: boolean;
|
|
||||||
repairBindings?: boolean;
|
|
||||||
deleteInvisibleElements?: boolean;
|
|
||||||
},
|
|
||||||
): RestoredDataState => {
|
): RestoredDataState => {
|
||||||
return {
|
return {
|
||||||
elements: restoreElements(data?.elements, localElements, elementsConfig),
|
elements: restoreElements(data?.elements, localElements, elementsConfig),
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ export class History {
|
|||||||
let nextAppState = appState;
|
let nextAppState = appState;
|
||||||
let containsVisibleChange = false;
|
let containsVisibleChange = false;
|
||||||
|
|
||||||
// iterate through the history entries in case they result in no visible changes
|
// iterate through the history entries in case ;they result in no visible changes
|
||||||
while (historyDelta) {
|
while (historyDelta) {
|
||||||
try {
|
try {
|
||||||
[nextElements, nextAppState, containsVisibleChange] =
|
[nextElements, nextAppState, containsVisibleChange] =
|
||||||
|
|||||||
@@ -229,7 +229,6 @@ export { defaultLang, useI18n, languages } from "./i18n";
|
|||||||
export {
|
export {
|
||||||
restore,
|
restore,
|
||||||
restoreAppState,
|
restoreAppState,
|
||||||
restoreElement,
|
|
||||||
restoreElements,
|
restoreElements,
|
||||||
restoreLibraryItems,
|
restoreLibraryItems,
|
||||||
} from "./data/restore";
|
} from "./data/restore";
|
||||||
@@ -282,7 +281,6 @@ export { Sidebar } from "./components/Sidebar/Sidebar";
|
|||||||
export { Button } from "./components/Button";
|
export { Button } from "./components/Button";
|
||||||
export { Footer };
|
export { Footer };
|
||||||
export { MainMenu };
|
export { MainMenu };
|
||||||
export { Ellipsify } from "./components/Ellipsify";
|
|
||||||
export { useDevice } from "./components/App";
|
export { useDevice } from "./components/App";
|
||||||
export { WelcomeScreen };
|
export { WelcomeScreen };
|
||||||
export { LiveCollaborationTrigger };
|
export { LiveCollaborationTrigger };
|
||||||
|
|||||||
@@ -66,22 +66,12 @@
|
|||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"repository": "https://github.com/excalidraw/excalidraw",
|
|
||||||
"bugs": "https://github.com/excalidraw/excalidraw/issues",
|
|
||||||
"homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
|
|
||||||
"scripts": {
|
|
||||||
"gen:types": "rimraf types && tsc",
|
|
||||||
"build:esm": "rimraf dist && node ../../scripts/buildPackage.js && yarn gen:types"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "^17.0.2 || ^18.2.0 || ^19.0.0",
|
"react": "^17.0.2 || ^18.2.0 || ^19.0.0",
|
||||||
"react-dom": "^17.0.2 || ^18.2.0 || ^19.0.0"
|
"react-dom": "^17.0.2 || ^18.2.0 || ^19.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braintree/sanitize-url": "6.0.2",
|
"@braintree/sanitize-url": "6.0.2",
|
||||||
"@excalidraw/common": "0.18.0",
|
|
||||||
"@excalidraw/element": "0.18.0",
|
|
||||||
"@excalidraw/math": "0.18.0",
|
|
||||||
"@excalidraw/laser-pointer": "1.3.1",
|
"@excalidraw/laser-pointer": "1.3.1",
|
||||||
"@excalidraw/mermaid-to-excalidraw": "1.1.2",
|
"@excalidraw/mermaid-to-excalidraw": "1.1.2",
|
||||||
"@excalidraw/random-username": "1.1.0",
|
"@excalidraw/random-username": "1.1.0",
|
||||||
@@ -134,5 +124,12 @@
|
|||||||
"harfbuzzjs": "0.3.6",
|
"harfbuzzjs": "0.3.6",
|
||||||
"jest-diff": "29.7.0",
|
"jest-diff": "29.7.0",
|
||||||
"typescript": "4.9.4"
|
"typescript": "4.9.4"
|
||||||
|
},
|
||||||
|
"repository": "https://github.com/excalidraw/excalidraw",
|
||||||
|
"bugs": "https://github.com/excalidraw/excalidraw/issues",
|
||||||
|
"homepage": "https://github.com/excalidraw/excalidraw/tree/master/packages/excalidraw",
|
||||||
|
"scripts": {
|
||||||
|
"gen:types": "rimraf types && tsc",
|
||||||
|
"build:esm": "rimraf dist && node ../../scripts/buildPackage.js && yarn gen:types"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { THEME, THEME_FILTER } from "@excalidraw/common";
|
import { elementCenterPoint, THEME, THEME_FILTER } from "@excalidraw/common";
|
||||||
|
|
||||||
import { FIXED_BINDING_DISTANCE } from "@excalidraw/element";
|
import { FIXED_BINDING_DISTANCE } from "@excalidraw/element";
|
||||||
import { getDiamondPoints } from "@excalidraw/element";
|
import { getDiamondPoints } from "@excalidraw/element";
|
||||||
import { elementCenterPoint, getCornerRadius } from "@excalidraw/element";
|
import { getCornerRadius } from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
curve,
|
curve,
|
||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
ExcalidrawRectanguloidElement,
|
ExcalidrawRectanguloidElement,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
@@ -129,12 +128,14 @@ function drawCatmullRomCubicApprox(
|
|||||||
export const drawHighlightForRectWithRotation = (
|
export const drawHighlightForRectWithRotation = (
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
element: ExcalidrawRectanguloidElement,
|
element: ExcalidrawRectanguloidElement,
|
||||||
elementsMap: ElementsMap,
|
|
||||||
padding: number,
|
padding: number,
|
||||||
) => {
|
) => {
|
||||||
const [x, y] = pointRotateRads(
|
const [x, y] = pointRotateRads(
|
||||||
pointFrom<GlobalPoint>(element.x, element.y),
|
pointFrom<GlobalPoint>(element.x, element.y),
|
||||||
elementCenterPoint(element, elementsMap),
|
elementCenterPoint(
|
||||||
|
element,
|
||||||
|
window.h.app.scene.getElementsMapIncludingDeleted(),
|
||||||
|
),
|
||||||
element.angle,
|
element.angle,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -288,11 +289,13 @@ export const drawHighlightForDiamondWithRotation = (
|
|||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
padding: number,
|
padding: number,
|
||||||
element: ExcalidrawDiamondElement,
|
element: ExcalidrawDiamondElement,
|
||||||
elementsMap: ElementsMap,
|
|
||||||
) => {
|
) => {
|
||||||
const [x, y] = pointRotateRads(
|
const [x, y] = pointRotateRads(
|
||||||
pointFrom<GlobalPoint>(element.x, element.y),
|
pointFrom<GlobalPoint>(element.x, element.y),
|
||||||
elementCenterPoint(element, elementsMap),
|
elementCenterPoint(
|
||||||
|
element,
|
||||||
|
window.h.app.scene.getElementsMapIncludingDeleted(),
|
||||||
|
),
|
||||||
element.angle,
|
element.angle,
|
||||||
);
|
);
|
||||||
context.save();
|
context.save();
|
||||||
|
|||||||
@@ -118,8 +118,7 @@ const renderLinearElementPointHighlight = (
|
|||||||
) => {
|
) => {
|
||||||
const { elementId, hoverPointIndex } = appState.selectedLinearElement!;
|
const { elementId, hoverPointIndex } = appState.selectedLinearElement!;
|
||||||
if (
|
if (
|
||||||
appState.selectedLinearElement?.isEditing &&
|
appState.editingLinearElement?.selectedPointsIndices?.includes(
|
||||||
appState.selectedLinearElement?.selectedPointsIndices?.includes(
|
|
||||||
hoverPointIndex,
|
hoverPointIndex,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
@@ -181,7 +180,7 @@ const renderSingleLinearPoint = <Point extends GlobalPoint | LocalPoint>(
|
|||||||
point[0],
|
point[0],
|
||||||
point[1],
|
point[1],
|
||||||
(isOverlappingPoint
|
(isOverlappingPoint
|
||||||
? radius * (appState.selectedLinearElement?.isEditing ? 1.5 : 2)
|
? radius * (appState.editingLinearElement ? 1.5 : 2)
|
||||||
: radius) / appState.zoom.value,
|
: radius) / appState.zoom.value,
|
||||||
!isPhantomPoint,
|
!isPhantomPoint,
|
||||||
!isOverlappingPoint || isSelected,
|
!isOverlappingPoint || isSelected,
|
||||||
@@ -206,15 +205,10 @@ const renderBindingHighlightForBindableElement = (
|
|||||||
case "embeddable":
|
case "embeddable":
|
||||||
case "frame":
|
case "frame":
|
||||||
case "magicframe":
|
case "magicframe":
|
||||||
drawHighlightForRectWithRotation(context, element, elementsMap, padding);
|
drawHighlightForRectWithRotation(context, element, padding);
|
||||||
break;
|
break;
|
||||||
case "diamond":
|
case "diamond":
|
||||||
drawHighlightForDiamondWithRotation(
|
drawHighlightForDiamondWithRotation(context, padding, element);
|
||||||
context,
|
|
||||||
padding,
|
|
||||||
element,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case "ellipse": {
|
case "ellipse": {
|
||||||
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
||||||
@@ -449,7 +443,7 @@ const renderLinearPointHandles = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { POINT_HANDLE_SIZE } = LinearElementEditor;
|
const { POINT_HANDLE_SIZE } = LinearElementEditor;
|
||||||
const radius = appState.selectedLinearElement?.isEditing
|
const radius = appState.editingLinearElement
|
||||||
? POINT_HANDLE_SIZE
|
? POINT_HANDLE_SIZE
|
||||||
: POINT_HANDLE_SIZE / 2;
|
: POINT_HANDLE_SIZE / 2;
|
||||||
|
|
||||||
@@ -471,8 +465,7 @@ const renderLinearPointHandles = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
let isSelected =
|
let isSelected =
|
||||||
!!appState.selectedLinearElement?.isEditing &&
|
!!appState.editingLinearElement?.selectedPointsIndices?.includes(idx);
|
||||||
!!appState.selectedLinearElement?.selectedPointsIndices?.includes(idx);
|
|
||||||
// when element is a polygon, highlight the last point as well if first
|
// when element is a polygon, highlight the last point as well if first
|
||||||
// point is selected since they overlap and the last point tends to be
|
// point is selected since they overlap and the last point tends to be
|
||||||
// rendered on top
|
// rendered on top
|
||||||
@@ -481,8 +474,7 @@ const renderLinearPointHandles = (
|
|||||||
element.polygon &&
|
element.polygon &&
|
||||||
!isSelected &&
|
!isSelected &&
|
||||||
idx === element.points.length - 1 &&
|
idx === element.points.length - 1 &&
|
||||||
!!appState.selectedLinearElement?.isEditing &&
|
!!appState.editingLinearElement?.selectedPointsIndices?.includes(0)
|
||||||
!!appState.selectedLinearElement?.selectedPointsIndices?.includes(0)
|
|
||||||
) {
|
) {
|
||||||
isSelected = true;
|
isSelected = true;
|
||||||
}
|
}
|
||||||
@@ -538,7 +530,7 @@ const renderLinearPointHandles = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
midPoints.forEach((segmentMidPoint) => {
|
midPoints.forEach((segmentMidPoint) => {
|
||||||
if (appState.selectedLinearElement?.isEditing || points.length === 2) {
|
if (appState.editingLinearElement || points.length === 2) {
|
||||||
renderSingleLinearPoint(
|
renderSingleLinearPoint(
|
||||||
context,
|
context,
|
||||||
appState,
|
appState,
|
||||||
@@ -763,10 +755,7 @@ const _renderInteractiveScene = ({
|
|||||||
// Getting the element using LinearElementEditor during collab mismatches version - being one head of visible elements due to
|
// Getting the element using LinearElementEditor during collab mismatches version - being one head of visible elements due to
|
||||||
// ShapeCache returns empty hence making sure that we get the
|
// ShapeCache returns empty hence making sure that we get the
|
||||||
// correct element from visible elements
|
// correct element from visible elements
|
||||||
if (
|
if (appState.editingLinearElement?.elementId === element.id) {
|
||||||
appState.selectedLinearElement?.isEditing &&
|
|
||||||
appState.selectedLinearElement.elementId === element.id
|
|
||||||
) {
|
|
||||||
if (element) {
|
if (element) {
|
||||||
editingLinearElement = element as NonDeleted<ExcalidrawLinearElement>;
|
editingLinearElement = element as NonDeleted<ExcalidrawLinearElement>;
|
||||||
}
|
}
|
||||||
@@ -859,8 +848,7 @@ const _renderInteractiveScene = ({
|
|||||||
// correct element from visible elements
|
// correct element from visible elements
|
||||||
if (
|
if (
|
||||||
selectedElements.length === 1 &&
|
selectedElements.length === 1 &&
|
||||||
appState.selectedLinearElement?.isEditing &&
|
appState.editingLinearElement?.elementId === selectedElements[0].id
|
||||||
appState.selectedLinearElement.elementId === selectedElements[0].id
|
|
||||||
) {
|
) {
|
||||||
renderLinearPointHandles(
|
renderLinearPointHandles(
|
||||||
context,
|
context,
|
||||||
@@ -891,7 +879,7 @@ const _renderInteractiveScene = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Paint selected elements
|
// Paint selected elements
|
||||||
if (!appState.multiElement && !appState.selectedLinearElement?.isEditing) {
|
if (!appState.multiElement && !appState.editingLinearElement) {
|
||||||
const showBoundingBox = shouldShowBoundingBox(selectedElements, appState);
|
const showBoundingBox = shouldShowBoundingBox(selectedElements, appState);
|
||||||
|
|
||||||
const isSingleLinearElementSelected =
|
const isSingleLinearElementSelected =
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
import { throttleRAF } from "@excalidraw/common";
|
import { throttleRAF } from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import { renderElement } from "@excalidraw/element";
|
||||||
getTargetFrame,
|
|
||||||
isInvisiblySmallElement,
|
|
||||||
renderElement,
|
|
||||||
shouldApplyFrameClip,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
|
|
||||||
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
|
import { bootstrapCanvas, getNormalizedCanvasDimensions } from "./helpers";
|
||||||
|
|
||||||
import { frameClip } from "./staticScene";
|
|
||||||
|
|
||||||
import type { NewElementSceneRenderConfig } from "../scene/types";
|
import type { NewElementSceneRenderConfig } from "../scene/types";
|
||||||
|
|
||||||
const _renderNewElementScene = ({
|
const _renderNewElementScene = ({
|
||||||
@@ -36,37 +29,11 @@ const _renderNewElementScene = ({
|
|||||||
normalizedHeight,
|
normalizedHeight,
|
||||||
});
|
});
|
||||||
|
|
||||||
context.save();
|
|
||||||
|
|
||||||
// Apply zoom
|
// Apply zoom
|
||||||
|
context.save();
|
||||||
context.scale(appState.zoom.value, appState.zoom.value);
|
context.scale(appState.zoom.value, appState.zoom.value);
|
||||||
|
|
||||||
if (newElement && newElement.type !== "selection") {
|
if (newElement && newElement.type !== "selection") {
|
||||||
// e.g. when creating arrows and we're still below the arrow drag distance
|
|
||||||
// threshold
|
|
||||||
// (for now we skip render only with elements while we're creating to be
|
|
||||||
// safe)
|
|
||||||
if (isInvisiblySmallElement(newElement)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const frameId = newElement.frameId || appState.frameToHighlight?.id;
|
|
||||||
|
|
||||||
if (
|
|
||||||
frameId &&
|
|
||||||
appState.frameRendering.enabled &&
|
|
||||||
appState.frameRendering.clip
|
|
||||||
) {
|
|
||||||
const frame = getTargetFrame(newElement, elementsMap, appState);
|
|
||||||
|
|
||||||
if (
|
|
||||||
frame &&
|
|
||||||
shouldApplyFrameClip(newElement, frame, appState, elementsMap)
|
|
||||||
) {
|
|
||||||
frameClip(frame, context, renderConfig, appState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderElement(
|
renderElement(
|
||||||
newElement,
|
newElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
@@ -79,8 +46,6 @@ const _renderNewElementScene = ({
|
|||||||
} else {
|
} else {
|
||||||
context.clearRect(0, 0, normalizedWidth, normalizedHeight);
|
context.clearRect(0, 0, normalizedWidth, normalizedHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.restore();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user