Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c68c2be44c | |||
| be65ac7f22 | |||
| 09e249ae57 | |||
| f0c1e9707a | |||
| 7f4659339b | |||
| 0987c5b770 | |||
| 0a529bd2ed | |||
| 794b2b21a7 | |||
| 6e577d1308 | |||
| 80b9fd18b9 | |||
| dbc48cfee2 | |||
| 3fc89b716a | |||
| 30743ec726 | |||
| 86d49a273b | |||
| 92fe9b95d5 |
+1
-1
@@ -22,7 +22,7 @@ VITE_APP_DEV_ENABLE_SW=
|
|||||||
# whether to disable live reload / HMR. Usuaully what you want to do when
|
# whether to disable live reload / HMR. Usuaully what you want to do when
|
||||||
# debugging Service Workers.
|
# debugging Service Workers.
|
||||||
VITE_APP_DEV_DISABLE_LIVE_RELOAD=
|
VITE_APP_DEV_DISABLE_LIVE_RELOAD=
|
||||||
VITE_APP_ENABLE_TRACKING=true
|
VITE_APP_DISABLE_TRACKING=true
|
||||||
|
|
||||||
FAST_REFRESH=false
|
FAST_REFRESH=false
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -14,4 +14,4 @@ VITE_APP_WS_SERVER_URL=https://oss-collab.excalidraw.com
|
|||||||
|
|
||||||
VITE_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","authDomain":"excalidraw-room-persistence.firebaseapp.com","databaseURL":"https://excalidraw-room-persistence.firebaseio.com","projectId":"excalidraw-room-persistence","storageBucket":"excalidraw-room-persistence.appspot.com","messagingSenderId":"654800341332","appId":"1:654800341332:web:4a692de832b55bd57ce0c1"}'
|
VITE_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","authDomain":"excalidraw-room-persistence.firebaseapp.com","databaseURL":"https://excalidraw-room-persistence.firebaseio.com","projectId":"excalidraw-room-persistence","storageBucket":"excalidraw-room-persistence.appspot.com","messagingSenderId":"654800341332","appId":"1:654800341332:web:4a692de832b55bd57ce0c1"}'
|
||||||
|
|
||||||
VITE_APP_ENABLE_TRACKING=false
|
VITE_APP_DISABLE_TRACKING=
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
name: Tests
|
name: Tests
|
||||||
|
|
||||||
on:
|
on: pull_request
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches: master
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node.js 18.x
|
- name: Setup Node.js 18.x
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 18.x
|
node-version: 18.x
|
||||||
- name: Install and test
|
- name: Install and test
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Once the callback is triggered, you will need to store the api in state to acces
|
|||||||
```jsx showLineNumbers
|
```jsx showLineNumbers
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [excalidrawAPI, setExcalidrawAPI] = useState(null);
|
const [excalidrawAPI, setExcalidrawAPI] = useState(null);
|
||||||
return <Excalidraw excalidrawAPI={(api)=> setExcalidrawAPI(api)} />;
|
return <Excalidraw excalidrawAPI={{(api)=> setExcalidrawAPI(api)}} />;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ function App() {
|
|||||||
<img src={canvasUrl} alt="" />
|
<img src={canvasUrl} alt="" />
|
||||||
</div>
|
</div>
|
||||||
<div style={{ height: "400px" }}>
|
<div style={{ height: "400px" }}>
|
||||||
<Excalidraw excalidrawAPI={(api) => setExcalidrawAPI(api)}
|
<Excalidraw ref={(api) => setExcalidrawAPI(api)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ pre a {
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
background: #70b1ec;
|
background: #70b1ec;
|
||||||
color: white;
|
color: white;
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -872,7 +872,7 @@ export default function App({
|
|||||||
files: excalidrawAPI.getFiles(),
|
files: excalidrawAPI.getFiles(),
|
||||||
});
|
});
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
ctx.font = "30px Excalifont";
|
ctx.font = "30px Virgil";
|
||||||
ctx.strokeText("My custom text", 50, 60);
|
ctx.strokeText("My custom text", 50, 60);
|
||||||
setCanvasUrl(canvas.toDataURL());
|
setCanvasUrl(canvas.toDataURL());
|
||||||
}}
|
}}
|
||||||
@@ -893,7 +893,7 @@ export default function App({
|
|||||||
files: excalidrawAPI.getFiles(),
|
files: excalidrawAPI.getFiles(),
|
||||||
});
|
});
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
ctx.font = "30px Excalifont";
|
ctx.font = "30px Virgil";
|
||||||
ctx.strokeText("My custom text", 50, 60);
|
ctx.strokeText("My custom text", 50, 60);
|
||||||
setCanvasUrl(canvas.toDataURL());
|
setCanvasUrl(canvas.toDataURL());
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const elements: ExcalidrawElementSkeleton[] = [
|
|||||||
];
|
];
|
||||||
export default {
|
export default {
|
||||||
elements,
|
elements,
|
||||||
appState: { viewBackgroundColor: "#AFEEEE", currentItemFontFamily: 5 },
|
appState: { viewBackgroundColor: "#AFEEEE", currentItemFontFamily: 1 },
|
||||||
scrollToContent: true,
|
scrollToContent: true,
|
||||||
libraryItems: [
|
libraryItems: [
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -34,6 +34,3 @@ yarn-error.log*
|
|||||||
# typescript
|
# typescript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
|
||||||
# copied assets
|
|
||||||
public/*.woff2
|
|
||||||
@@ -3,8 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:workspace": "yarn workspace @excalidraw/excalidraw run build:esm && yarn copy:assets",
|
"build:workspace": "yarn workspace @excalidraw/excalidraw run build:esm",
|
||||||
"copy:assets": "cp ../../../packages/excalidraw/dist/browser/prod/excalidraw-assets/*.woff2 ./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",
|
||||||
"start": "next start -p 3006",
|
"start": "next start -p 3006",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import Script from "next/script";
|
|
||||||
import "../common.scss";
|
import "../common.scss";
|
||||||
|
|
||||||
// Since client components get prerenderd on server as well hence importing the excalidraw stuff dynamically
|
// Since client components get prerenderd on server as well hence importing the excalidraw stuff dynamically
|
||||||
@@ -16,9 +15,7 @@ export default function Page() {
|
|||||||
<>
|
<>
|
||||||
<a href="/excalidraw-in-pages">Switch to Pages router</a>
|
<a href="/excalidraw-in-pages">Switch to Pages router</a>
|
||||||
<h1 className="page-title">App Router</h1>
|
<h1 className="page-title">App Router</h1>
|
||||||
<Script id="load-env-variables" strategy="beforeInteractive">
|
|
||||||
{`window["EXCALIDRAW_ASSET_PATH"] = window.origin;`}
|
|
||||||
</Script>
|
|
||||||
{/* @ts-expect-error - https://github.com/vercel/next.js/issues/42292 */}
|
{/* @ts-expect-error - https://github.com/vercel/next.js/issues/42292 */}
|
||||||
<ExcalidrawWithClientOnly />
|
<ExcalidrawWithClientOnly />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ a {
|
|||||||
color: #1c7ed6;
|
color: #1c7ed6;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: 500;
|
font-weight: 550;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-title {
|
.page-title {
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
# copied assets
|
|
||||||
public/*.woff2
|
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
<title>React App</title>
|
<title>React App</title>
|
||||||
<script>
|
<script>
|
||||||
window.name = "codesandbox";
|
window.name = "codesandbox";
|
||||||
window.EXCALIDRAW_ASSET_PATH = window.origin;
|
|
||||||
</script>
|
</script>
|
||||||
<link rel="stylesheet" href="/dist/browser/dev/index.css" />
|
<link rel="stylesheet" href="/dist/browser/dev/index.css" />
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -12,10 +12,8 @@
|
|||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:workspace": "yarn workspace @excalidraw/excalidraw run build:esm && yarn copy:assets",
|
"start": "yarn workspace @excalidraw/excalidraw run build:esm && vite",
|
||||||
"copy:assets": "cp ../../../packages/excalidraw/dist/browser/prod/excalidraw-assets/*.woff2 ./public",
|
"build": "yarn workspace @excalidraw/excalidraw run build:esm && vite build",
|
||||||
"start": "yarn build:workspace && vite",
|
|
||||||
"build": "yarn build:workspace && vite build",
|
|
||||||
"build:preview": "yarn build && vite preview --port 5002"
|
"build:preview": "yarn build && vite preview --port 5002"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-16
@@ -1,4 +1,5 @@
|
|||||||
import polyfill from "../packages/excalidraw/polyfill";
|
import polyfill from "../packages/excalidraw/polyfill";
|
||||||
|
import LanguageDetector from "i18next-browser-languagedetector";
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { trackEvent } from "../packages/excalidraw/analytics";
|
import { trackEvent } from "../packages/excalidraw/analytics";
|
||||||
import { getDefaultAppState } from "../packages/excalidraw/appState";
|
import { getDefaultAppState } from "../packages/excalidraw/appState";
|
||||||
@@ -21,12 +22,12 @@ import { useCallbackRefState } from "../packages/excalidraw/hooks/useCallbackRef
|
|||||||
import { t } from "../packages/excalidraw/i18n";
|
import { t } from "../packages/excalidraw/i18n";
|
||||||
import {
|
import {
|
||||||
Excalidraw,
|
Excalidraw,
|
||||||
|
defaultLang,
|
||||||
LiveCollaborationTrigger,
|
LiveCollaborationTrigger,
|
||||||
TTDDialog,
|
TTDDialog,
|
||||||
TTDDialogTrigger,
|
TTDDialogTrigger,
|
||||||
StoreAction,
|
StoreAction,
|
||||||
reconcileElements,
|
reconcileElements,
|
||||||
normalizeIndices,
|
|
||||||
} from "../packages/excalidraw";
|
} from "../packages/excalidraw";
|
||||||
import type {
|
import type {
|
||||||
AppState,
|
AppState,
|
||||||
@@ -92,7 +93,7 @@ import {
|
|||||||
import { AppMainMenu } from "./components/AppMainMenu";
|
import { AppMainMenu } from "./components/AppMainMenu";
|
||||||
import { AppWelcomeScreen } from "./components/AppWelcomeScreen";
|
import { AppWelcomeScreen } from "./components/AppWelcomeScreen";
|
||||||
import { AppFooter } from "./components/AppFooter";
|
import { AppFooter } from "./components/AppFooter";
|
||||||
import { Provider, useAtom, useAtomValue } from "jotai";
|
import { atom, Provider, useAtom, useAtomValue } from "jotai";
|
||||||
import { useAtomWithInitialValue } from "../packages/excalidraw/jotai";
|
import { useAtomWithInitialValue } from "../packages/excalidraw/jotai";
|
||||||
import { appJotaiStore } from "./app-jotai";
|
import { appJotaiStore } from "./app-jotai";
|
||||||
|
|
||||||
@@ -120,8 +121,6 @@ import {
|
|||||||
youtubeIcon,
|
youtubeIcon,
|
||||||
} from "../packages/excalidraw/components/icons";
|
} from "../packages/excalidraw/components/icons";
|
||||||
import { appThemeAtom, useHandleAppTheme } from "./useHandleAppTheme";
|
import { appThemeAtom, useHandleAppTheme } from "./useHandleAppTheme";
|
||||||
import { getPreferredLanguage } from "./app-language/language-detector";
|
|
||||||
import { useAppLangCode } from "./app-language/language-state";
|
|
||||||
|
|
||||||
polyfill();
|
polyfill();
|
||||||
|
|
||||||
@@ -173,6 +172,11 @@ if (window.self !== window.top) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const languageDetector = new LanguageDetector();
|
||||||
|
languageDetector.init({
|
||||||
|
languageUtils: {},
|
||||||
|
});
|
||||||
|
|
||||||
const shareableLinkConfirmDialog = {
|
const shareableLinkConfirmDialog = {
|
||||||
title: t("overwriteConfirm.modal.shareableLink.title"),
|
title: t("overwriteConfirm.modal.shareableLink.title"),
|
||||||
description: (
|
description: (
|
||||||
@@ -306,34 +310,31 @@ const initializeScene = async (opts: {
|
|||||||
key: roomLinkData.roomKey,
|
key: roomLinkData.roomKey,
|
||||||
};
|
};
|
||||||
} else if (scene) {
|
} else if (scene) {
|
||||||
const normalizedScene = {
|
|
||||||
...scene,
|
|
||||||
// non-collab scenes are always always normalized on init
|
|
||||||
// collab scenes are normalized only on "first-in-room" as part of collabAPI
|
|
||||||
elements: normalizeIndices(scene.elements),
|
|
||||||
};
|
|
||||||
|
|
||||||
return isExternalScene && jsonBackendMatch
|
return isExternalScene && jsonBackendMatch
|
||||||
? {
|
? {
|
||||||
scene: normalizedScene,
|
scene,
|
||||||
isExternalScene,
|
isExternalScene,
|
||||||
id: jsonBackendMatch[1],
|
id: jsonBackendMatch[1],
|
||||||
key: jsonBackendMatch[2],
|
key: jsonBackendMatch[2],
|
||||||
}
|
}
|
||||||
: { scene: normalizedScene, isExternalScene: false };
|
: { scene, isExternalScene: false };
|
||||||
}
|
}
|
||||||
return { scene: null, isExternalScene: false };
|
return { scene: null, isExternalScene: false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const detectedLangCode = languageDetector.detect() || defaultLang.code;
|
||||||
|
export const appLangCodeAtom = atom(
|
||||||
|
Array.isArray(detectedLangCode) ? detectedLangCode[0] : detectedLangCode,
|
||||||
|
);
|
||||||
|
|
||||||
const ExcalidrawWrapper = () => {
|
const ExcalidrawWrapper = () => {
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
const [langCode, setLangCode] = useAtom(appLangCodeAtom);
|
||||||
const isCollabDisabled = isRunningInIframe();
|
const isCollabDisabled = isRunningInIframe();
|
||||||
|
|
||||||
const [appTheme, setAppTheme] = useAtom(appThemeAtom);
|
const [appTheme, setAppTheme] = useAtom(appThemeAtom);
|
||||||
const { editorTheme } = useHandleAppTheme();
|
const { editorTheme } = useHandleAppTheme();
|
||||||
|
|
||||||
const [langCode, setLangCode] = useAppLangCode();
|
|
||||||
|
|
||||||
// initial state
|
// initial state
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -489,7 +490,11 @@ const ExcalidrawWrapper = () => {
|
|||||||
if (isBrowserStorageStateNewer(STORAGE_KEYS.VERSION_DATA_STATE)) {
|
if (isBrowserStorageStateNewer(STORAGE_KEYS.VERSION_DATA_STATE)) {
|
||||||
const localDataState = importFromLocalStorage();
|
const localDataState = importFromLocalStorage();
|
||||||
const username = importUsernameFromLocalStorage();
|
const username = importUsernameFromLocalStorage();
|
||||||
setLangCode(getPreferredLanguage());
|
let langCode = languageDetector.detect() || defaultLang.code;
|
||||||
|
if (Array.isArray(langCode)) {
|
||||||
|
langCode = langCode[0];
|
||||||
|
}
|
||||||
|
setLangCode(langCode);
|
||||||
excalidrawAPI.updateScene({
|
excalidrawAPI.updateScene({
|
||||||
...localDataState,
|
...localDataState,
|
||||||
storeAction: StoreAction.UPDATE,
|
storeAction: StoreAction.UPDATE,
|
||||||
@@ -590,6 +595,10 @@ const ExcalidrawWrapper = () => {
|
|||||||
};
|
};
|
||||||
}, [excalidrawAPI]);
|
}, [excalidrawAPI]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
languageDetector.cacheUserLanguage(langCode);
|
||||||
|
}, [langCode]);
|
||||||
|
|
||||||
const onChange = (
|
const onChange = (
|
||||||
elements: readonly OrderedExcalidrawElement[],
|
elements: readonly OrderedExcalidrawElement[],
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import LanguageDetector from "i18next-browser-languagedetector";
|
|
||||||
import { defaultLang, languages } from "../../packages/excalidraw";
|
|
||||||
|
|
||||||
export const languageDetector = new LanguageDetector();
|
|
||||||
|
|
||||||
languageDetector.init({
|
|
||||||
languageUtils: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getPreferredLanguage = () => {
|
|
||||||
const detectedLanguages = languageDetector.detect();
|
|
||||||
|
|
||||||
const detectedLanguage = Array.isArray(detectedLanguages)
|
|
||||||
? detectedLanguages[0]
|
|
||||||
: detectedLanguages;
|
|
||||||
|
|
||||||
const initialLanguage =
|
|
||||||
(detectedLanguage
|
|
||||||
? // region code may not be defined if user uses generic preferred language
|
|
||||||
// (e.g. chinese vs instead of chinese-simplified)
|
|
||||||
languages.find((lang) => lang.code.startsWith(detectedLanguage))?.code
|
|
||||||
: null) || defaultLang.code;
|
|
||||||
|
|
||||||
return initialLanguage;
|
|
||||||
};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { atom, useAtom } from "jotai";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
import { getPreferredLanguage, languageDetector } from "./language-detector";
|
|
||||||
|
|
||||||
export const appLangCodeAtom = atom(getPreferredLanguage());
|
|
||||||
|
|
||||||
export const useAppLangCode = () => {
|
|
||||||
const [langCode, setLangCode] = useAtom(appLangCodeAtom);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
languageDetector.cacheUserLanguage(langCode);
|
|
||||||
}, [langCode]);
|
|
||||||
|
|
||||||
return [langCode, setLangCode] as const;
|
|
||||||
};
|
|
||||||
@@ -18,7 +18,6 @@ import {
|
|||||||
restoreElements,
|
restoreElements,
|
||||||
zoomToFitBounds,
|
zoomToFitBounds,
|
||||||
reconcileElements,
|
reconcileElements,
|
||||||
normalizeIndices,
|
|
||||||
} from "../../packages/excalidraw";
|
} from "../../packages/excalidraw";
|
||||||
import type { Collaborator, Gesture } from "../../packages/excalidraw/types";
|
import type { Collaborator, Gesture } from "../../packages/excalidraw/types";
|
||||||
import {
|
import {
|
||||||
@@ -638,16 +637,7 @@ class Collab extends PureComponent<CollabProps, CollabState> {
|
|||||||
fetchScene: true,
|
fetchScene: true,
|
||||||
roomLinkData: existingRoomLinkData,
|
roomLinkData: existingRoomLinkData,
|
||||||
});
|
});
|
||||||
|
scenePromise.resolve(sceneData);
|
||||||
if (sceneData) {
|
|
||||||
scenePromise.resolve({
|
|
||||||
...sceneData,
|
|
||||||
// normalize fractional indices on init for shared scenes, while making sure there are no other collaborators
|
|
||||||
elements: normalizeIndices([...sceneData.elements]),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
scenePromise.resolve(null);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.portal.socket.on(
|
this.portal.socket.on(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
import type { Theme } from "../../packages/excalidraw/element/types";
|
import type { Theme } from "../../packages/excalidraw/element/types";
|
||||||
import { MainMenu } from "../../packages/excalidraw/index";
|
import { MainMenu } from "../../packages/excalidraw/index";
|
||||||
import { isExcalidrawPlusSignedUser } from "../app_constants";
|
import { isExcalidrawPlusSignedUser } from "../app_constants";
|
||||||
import { LanguageList } from "../app-language/LanguageList";
|
import { LanguageList } from "./LanguageList";
|
||||||
|
|
||||||
export const AppMainMenu: React.FC<{
|
export const AppMainMenu: React.FC<{
|
||||||
onCollabDialogOpen: () => any;
|
onCollabDialogOpen: () => any;
|
||||||
@@ -34,7 +34,7 @@ export const AppMainMenu: React.FC<{
|
|||||||
<MainMenu.ItemLink
|
<MainMenu.ItemLink
|
||||||
icon={ExcalLogo}
|
icon={ExcalLogo}
|
||||||
href={`${
|
href={`${
|
||||||
import.meta.env.VITE_APP_PLUS_LP
|
import.meta.env.VITE_APP_PLUS_APP
|
||||||
}/plus?utm_source=excalidraw&utm_medium=app&utm_content=hamburger`}
|
}/plus?utm_source=excalidraw&utm_medium=app&utm_content=hamburger`}
|
||||||
className=""
|
className=""
|
||||||
>
|
>
|
||||||
|
|||||||
+3
-2
@@ -1,7 +1,8 @@
|
|||||||
import { useSetAtom } from "jotai";
|
import { useSetAtom } from "jotai";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useI18n, languages } from "../../packages/excalidraw/i18n";
|
import { appLangCodeAtom } from "../App";
|
||||||
import { appLangCodeAtom } from "./language-state";
|
import { useI18n } from "../../packages/excalidraw/i18n";
|
||||||
|
import { languages } from "../../packages/excalidraw/i18n";
|
||||||
|
|
||||||
export const LanguageList = ({ style }: { style?: React.CSSProperties }) => {
|
export const LanguageList = ({ style }: { style?: React.CSSProperties }) => {
|
||||||
const { t, langCode } = useI18n();
|
const { t, langCode } = useI18n();
|
||||||
@@ -254,7 +254,7 @@ export const loadScene = async (
|
|||||||
await importFromBackend(id, privateKey),
|
await importFromBackend(id, privateKey),
|
||||||
localDataState?.appState,
|
localDataState?.appState,
|
||||||
localDataState?.elements,
|
localDataState?.elements,
|
||||||
{ repairBindings: true },
|
{ repairBindings: true, refreshDimensions: false },
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
data = restore(localDataState || null, null, null, {
|
data = restore(localDataState || null, null, null, {
|
||||||
|
|||||||
@@ -114,14 +114,6 @@
|
|||||||
) {
|
) {
|
||||||
window.location.href = "https://app.excalidraw.com";
|
window.location.href = "https://app.excalidraw.com";
|
||||||
}
|
}
|
||||||
|
|
||||||
// point into our CDN in prod
|
|
||||||
window.EXCALIDRAW_ASSET_PATH =
|
|
||||||
"https://excalidraw.nyc3.cdn.digitaloceanspaces.com/fonts/oss/";
|
|
||||||
</script>
|
|
||||||
<% } else { %>
|
|
||||||
<script>
|
|
||||||
window.EXCALIDRAW_ASSET_PATH = window.origin;
|
|
||||||
</script>
|
</script>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
@@ -132,74 +124,22 @@
|
|||||||
<!-- Excalidraw version -->
|
<!-- Excalidraw version -->
|
||||||
<meta name="version" content="{version}" />
|
<meta name="version" content="{version}" />
|
||||||
|
|
||||||
<!-- Warmup the connection for Google fonts -->
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
||||||
|
|
||||||
<!-- Preload all default fonts and Virgil for backwards compatibility to avoid swap on init -->
|
|
||||||
<% if (typeof PROD != 'undefined' && PROD == true) { %>
|
|
||||||
<link
|
<link
|
||||||
rel="preload"
|
rel="preload"
|
||||||
href="https://excalidraw.nyc3.cdn.digitaloceanspaces.com/fonts/oss/Excalifont-Regular-C9eKQy_N.woff2"
|
href="/Virgil.woff2"
|
||||||
as="font"
|
as="font"
|
||||||
type="font/woff2"
|
type="font/woff2"
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
/>
|
/>
|
||||||
<link
|
<link
|
||||||
rel="preload"
|
rel="preload"
|
||||||
href="https://excalidraw.nyc3.cdn.digitaloceanspaces.com/fonts/oss/Virgil-Regular-hO16qHwV.woff2"
|
href="/Cascadia.woff2"
|
||||||
as="font"
|
|
||||||
type="font/woff2"
|
|
||||||
crossorigin="anonymous"
|
|
||||||
/>
|
|
||||||
<link
|
|
||||||
rel="preload"
|
|
||||||
href="https://excalidraw.nyc3.cdn.digitaloceanspaces.com/fonts/oss/ComicShanns-Regular-D0c8wzsC.woff2"
|
|
||||||
as="font"
|
|
||||||
type="font/woff2"
|
|
||||||
crossorigin="anonymous"
|
|
||||||
/>
|
|
||||||
<% } else { %>
|
|
||||||
<!-- in DEV we need to preload from the local server and without the hash -->
|
|
||||||
<link
|
|
||||||
rel="preload"
|
|
||||||
href="../packages/excalidraw/fonts/assets/Excalifont-Regular.woff2"
|
|
||||||
as="font"
|
|
||||||
type="font/woff2"
|
|
||||||
crossorigin="anonymous"
|
|
||||||
/>
|
|
||||||
<link
|
|
||||||
rel="preload"
|
|
||||||
href="../packages/excalidraw/fonts/assets/Virgil-Regular.woff2"
|
|
||||||
as="font"
|
|
||||||
type="font/woff2"
|
|
||||||
crossorigin="anonymous"
|
|
||||||
/>
|
|
||||||
<link
|
|
||||||
rel="preload"
|
|
||||||
href="../packages/excalidraw/fonts/assets/ComicShanns-Regular.woff2"
|
|
||||||
as="font"
|
|
||||||
type="font/woff2"
|
|
||||||
crossorigin="anonymous"
|
|
||||||
/>
|
|
||||||
<% } %>
|
|
||||||
|
|
||||||
<!-- For Nunito only preload the latin range, which should be enough for now -->
|
|
||||||
<link
|
|
||||||
rel="preload"
|
|
||||||
href="https://fonts.gstatic.com/s/nunito/v26/XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTQ3j6zbXWjgeg.woff2"
|
|
||||||
as="font"
|
as="font"
|
||||||
type="font/woff2"
|
type="font/woff2"
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Register Assistant as the UI font, before the scene inits -->
|
<link rel="stylesheet" href="/fonts/fonts.css" type="text/css" />
|
||||||
<link
|
|
||||||
rel="stylesheet"
|
|
||||||
href="../packages/excalidraw/fonts/assets/fonts.css"
|
|
||||||
type="text/css"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<% if (typeof VITE_APP_DEV_DISABLE_LIVE_RELOAD != 'undefined' &&
|
<% if (typeof VITE_APP_DEV_DISABLE_LIVE_RELOAD != 'undefined' &&
|
||||||
VITE_APP_DEV_DISABLE_LIVE_RELOAD == true) { %>
|
VITE_APP_DEV_DISABLE_LIVE_RELOAD == true) { %>
|
||||||
<script>
|
<script>
|
||||||
@@ -218,6 +158,7 @@
|
|||||||
</script>
|
</script>
|
||||||
<% } %>
|
<% } %>
|
||||||
<script>
|
<script>
|
||||||
|
window.EXCALIDRAW_ASSET_PATH = "/";
|
||||||
// setting this so that libraries installation reuses this window tab.
|
// setting this so that libraries installation reuses this window tab.
|
||||||
window.name = "_excalidraw";
|
window.name = "_excalidraw";
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
margin-bottom: auto;
|
margin-bottom: auto;
|
||||||
margin-inline-start: auto;
|
margin-inline-start: auto;
|
||||||
margin-inline-end: 0.6em;
|
margin-inline-end: 0.6em;
|
||||||
z-index: var(--zIndex-layerUI);
|
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: 1.2rem;
|
width: 1.2rem;
|
||||||
|
|||||||
@@ -31,13 +31,12 @@
|
|||||||
"prettier": "@excalidraw/prettier-config",
|
"prettier": "@excalidraw/prettier-config",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build-node": "node ./scripts/build-node.js",
|
"build-node": "node ./scripts/build-node.js",
|
||||||
"build:app:docker": "cross-env VITE_APP_DISABLE_SENTRY=true vite build",
|
"build:app:docker": "cross-env VITE_APP_DISABLE_SENTRY=true VITE_APP_DISABLE_TRACKING=true vite build",
|
||||||
"build:app": "cross-env VITE_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA cross-env VITE_APP_ENABLE_TRACKING=true vite build",
|
"build:app": "cross-env VITE_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA vite build",
|
||||||
"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:production": "yarn build && yarn serve",
|
"start:production": "npm run build && 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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ exports[`Test MobileMenu > should initialize with welcome screen and hide once u
|
|||||||
class="welcome-screen-center"
|
class="welcome-screen-center"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="welcome-screen-center__logo excalifont welcome-screen-decor"
|
class="welcome-screen-center__logo virgil welcome-screen-decor"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ExcalidrawLogo is-small"
|
class="ExcalidrawLogo is-small"
|
||||||
@@ -48,7 +48,7 @@ exports[`Test MobileMenu > should initialize with welcome screen and hide once u
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="welcome-screen-center__heading welcome-screen-decor excalifont"
|
class="welcome-screen-center__heading welcome-screen-decor virgil"
|
||||||
>
|
>
|
||||||
All your data is saved locally in your browser.
|
All your data is saved locally in your browser.
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { ViteEjsPlugin } from "vite-plugin-ejs";
|
|||||||
import { VitePWA } from "vite-plugin-pwa";
|
import { VitePWA } from "vite-plugin-pwa";
|
||||||
import checker from "vite-plugin-checker";
|
import checker from "vite-plugin-checker";
|
||||||
import { createHtmlPlugin } from "vite-plugin-html";
|
import { createHtmlPlugin } from "vite-plugin-html";
|
||||||
import { woff2BrowserPlugin } from "../scripts/woff2/woff2-vite-plugins";
|
|
||||||
|
|
||||||
// To load .env.local variables
|
// To load .env.local variables
|
||||||
const envVars = loadEnv("", `../`);
|
const envVars = loadEnv("", `../`);
|
||||||
@@ -23,14 +22,6 @@ export default defineConfig({
|
|||||||
outDir: "build",
|
outDir: "build",
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
assetFileNames(chunkInfo) {
|
|
||||||
if (chunkInfo?.name?.endsWith(".woff2")) {
|
|
||||||
// put on root so we are flexible about the CDN path
|
|
||||||
return '[name]-[hash][extname]';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'assets/[name]-[hash][extname]';
|
|
||||||
},
|
|
||||||
// Creating separate chunk for locales except for en and percentages.json so they
|
// Creating separate chunk for locales except for en and percentages.json so they
|
||||||
// can be cached at runtime and not merged with
|
// can be cached at runtime and not merged with
|
||||||
// app precache. en.json and percentages.json are needed for first load
|
// app precache. en.json and percentages.json are needed for first load
|
||||||
@@ -44,13 +35,12 @@ export default defineConfig({
|
|||||||
// Taking the substring after "locales/"
|
// Taking the substring after "locales/"
|
||||||
return `locales/${id.substring(index + 8)}`;
|
return `locales/${id.substring(index + 8)}`;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
woff2BrowserPlugin(),
|
|
||||||
react(),
|
react(),
|
||||||
checker({
|
checker({
|
||||||
typescript: true,
|
typescript: true,
|
||||||
|
|||||||
@@ -15,12 +15,8 @@ Please add the latest change on the top under the correct section.
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- `props.initialData` can now be a function that returns `ExcalidrawInitialDataState` or `Promise<ExcalidrawInitialDataState>`. [#8107](https://github.com/excalidraw/excalidraw/pull/8135)
|
|
||||||
|
|
||||||
- Added support for multiplayer undo/redo, by calculating invertible increments and storing them inside the local-only undo/redo stacks. [#7348](https://github.com/excalidraw/excalidraw/pull/7348)
|
- Added support for multiplayer undo/redo, by calculating invertible increments and storing them inside the local-only undo/redo stacks. [#7348](https://github.com/excalidraw/excalidraw/pull/7348)
|
||||||
|
|
||||||
- Added font picker component to have the ability to choose from a range of different fonts. Also, changed the default fonts to `Excalifont`, `Nunito` and `Comic Shanns` and deprecated `Virgil`, `Helvetica` and `Cascadia`.
|
|
||||||
|
|
||||||
- `MainMenu.DefaultItems.ToggleTheme` now supports `onSelect(theme: string)` callback, and optionally `allowSystemTheme: boolean` alongside `theme: string` to indicate you want to allow users to set to system theme (you need to handle this yourself). [#7853](https://github.com/excalidraw/excalidraw/pull/7853)
|
- `MainMenu.DefaultItems.ToggleTheme` now supports `onSelect(theme: string)` callback, and optionally `allowSystemTheme: boolean` alongside `theme: string` to indicate you want to allow users to set to system theme (you need to handle this yourself). [#7853](https://github.com/excalidraw/excalidraw/pull/7853)
|
||||||
|
|
||||||
- Add `useHandleLibrary`'s `opts.adapter` as the new recommended pattern to handle library initialization and persistence on library updates. [#7655](https://github.com/excalidraw/excalidraw/pull/7655)
|
- Add `useHandleLibrary`'s `opts.adapter` as the new recommended pattern to handle library initialization and persistence on library updates. [#7655](https://github.com/excalidraw/excalidraw/pull/7655)
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export const actionClearCanvas = register({
|
|||||||
exportBackground: appState.exportBackground,
|
exportBackground: appState.exportBackground,
|
||||||
exportEmbedScene: appState.exportEmbedScene,
|
exportEmbedScene: appState.exportEmbedScene,
|
||||||
gridSize: appState.gridSize,
|
gridSize: appState.gridSize,
|
||||||
stats: appState.stats,
|
showStats: appState.showStats,
|
||||||
pasteDialog: appState.pasteDialog,
|
pasteDialog: appState.pasteDialog,
|
||||||
activeTool:
|
activeTool:
|
||||||
appState.activeTool.type === "image"
|
appState.activeTool.type === "image"
|
||||||
|
|||||||
@@ -131,12 +131,7 @@ export const actionFinalize = register({
|
|||||||
-1,
|
-1,
|
||||||
arrayToMap(elements),
|
arrayToMap(elements),
|
||||||
);
|
);
|
||||||
maybeBindLinearElement(
|
maybeBindLinearElement(multiPointElement, appState, { x, y }, app);
|
||||||
multiPointElement,
|
|
||||||
appState,
|
|
||||||
{ x, y },
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ const flipElements = (
|
|||||||
|
|
||||||
bindOrUnbindLinearElements(
|
bindOrUnbindLinearElements(
|
||||||
selectedElements.filter(isLinearElement),
|
selectedElements.filter(isLinearElement),
|
||||||
elementsMap,
|
app,
|
||||||
isBindingEnabled(appState),
|
isBindingEnabled(appState),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -155,15 +155,13 @@ describe("element locking", () => {
|
|||||||
});
|
});
|
||||||
const text = API.createElement({
|
const text = API.createElement({
|
||||||
type: "text",
|
type: "text",
|
||||||
fontFamily: FONT_FAMILY["Comic Shanns"],
|
fontFamily: FONT_FAMILY.Cascadia,
|
||||||
});
|
});
|
||||||
h.elements = [rect, text];
|
h.elements = [rect, text];
|
||||||
API.setSelectedElements([rect, text]);
|
API.setSelectedElements([rect, text]);
|
||||||
|
|
||||||
expect(queryByTestId(document.body, `strokeWidth-bold`)).toBeChecked();
|
expect(queryByTestId(document.body, `strokeWidth-bold`)).toBeChecked();
|
||||||
expect(queryByTestId(document.body, `font-family-code`)).toHaveClass(
|
expect(queryByTestId(document.body, `font-family-code`)).toBeChecked();
|
||||||
"active",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
|
||||||
import type { AppClassProperties, AppState, Primitive } from "../types";
|
import type { AppClassProperties, AppState, Primitive } from "../types";
|
||||||
import type { StoreActionType } from "../store";
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE,
|
DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE,
|
||||||
DEFAULT_ELEMENT_BACKGROUND_PICKS,
|
DEFAULT_ELEMENT_BACKGROUND_PICKS,
|
||||||
@@ -11,7 +9,6 @@ import { trackEvent } from "../analytics";
|
|||||||
import { ButtonIconSelect } from "../components/ButtonIconSelect";
|
import { ButtonIconSelect } from "../components/ButtonIconSelect";
|
||||||
import { ColorPicker } from "../components/ColorPicker/ColorPicker";
|
import { ColorPicker } from "../components/ColorPicker/ColorPicker";
|
||||||
import { IconPicker } from "../components/IconPicker";
|
import { IconPicker } from "../components/IconPicker";
|
||||||
import { FontPicker } from "../components/FontPicker/FontPicker";
|
|
||||||
// TODO barnabasmolnar/editor-redesign
|
// TODO barnabasmolnar/editor-redesign
|
||||||
// TextAlignTopIcon, TextAlignBottomIcon,TextAlignMiddleIcon,
|
// TextAlignTopIcon, TextAlignBottomIcon,TextAlignMiddleIcon,
|
||||||
// ArrowHead icons
|
// ArrowHead icons
|
||||||
@@ -41,6 +38,9 @@ import {
|
|||||||
FontSizeExtraLargeIcon,
|
FontSizeExtraLargeIcon,
|
||||||
EdgeSharpIcon,
|
EdgeSharpIcon,
|
||||||
EdgeRoundIcon,
|
EdgeRoundIcon,
|
||||||
|
FreedrawIcon,
|
||||||
|
FontFamilyNormalIcon,
|
||||||
|
FontFamilyCodeIcon,
|
||||||
TextAlignLeftIcon,
|
TextAlignLeftIcon,
|
||||||
TextAlignCenterIcon,
|
TextAlignCenterIcon,
|
||||||
TextAlignRightIcon,
|
TextAlignRightIcon,
|
||||||
@@ -65,7 +65,10 @@ import {
|
|||||||
redrawTextBoundingBox,
|
redrawTextBoundingBox,
|
||||||
} from "../element";
|
} from "../element";
|
||||||
import { mutateElement, newElementWith } from "../element/mutateElement";
|
import { mutateElement, newElementWith } from "../element/mutateElement";
|
||||||
import { getBoundTextElement } from "../element/textElement";
|
import {
|
||||||
|
getBoundTextElement,
|
||||||
|
getDefaultLineHeight,
|
||||||
|
} from "../element/textElement";
|
||||||
import {
|
import {
|
||||||
isBoundToContainer,
|
isBoundToContainer,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
@@ -91,10 +94,9 @@ import {
|
|||||||
isSomeElementSelected,
|
isSomeElementSelected,
|
||||||
} from "../scene";
|
} from "../scene";
|
||||||
import { hasStrokeColor } from "../scene/comparisons";
|
import { hasStrokeColor } from "../scene/comparisons";
|
||||||
import { arrayToMap, getFontFamilyString, getShortcutKey } from "../utils";
|
import { arrayToMap, getShortcutKey } from "../utils";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { StoreAction } from "../store";
|
import { StoreAction } from "../store";
|
||||||
import { Fonts, getLineHeight } from "../fonts";
|
|
||||||
|
|
||||||
const FONT_SIZE_RELATIVE_INCREASE_STEP = 0.1;
|
const FONT_SIZE_RELATIVE_INCREASE_STEP = 0.1;
|
||||||
|
|
||||||
@@ -727,391 +729,104 @@ export const actionIncreaseFontSize = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
type ChangeFontFamilyData = Partial<
|
|
||||||
Pick<
|
|
||||||
AppState,
|
|
||||||
"openPopup" | "currentItemFontFamily" | "currentHoveredFontFamily"
|
|
||||||
>
|
|
||||||
> & {
|
|
||||||
/** cache of selected & editing elements populated on opened popup */
|
|
||||||
cachedElements?: Map<string, ExcalidrawElement>;
|
|
||||||
/** flag to reset all elements to their cached versions */
|
|
||||||
resetAll?: true;
|
|
||||||
/** flag to reset all containers to their cached versions */
|
|
||||||
resetContainers?: true;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const actionChangeFontFamily = register({
|
export const actionChangeFontFamily = register({
|
||||||
name: "changeFontFamily",
|
name: "changeFontFamily",
|
||||||
label: "labels.fontFamily",
|
label: "labels.fontFamily",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value, app) => {
|
perform: (elements, appState, value, app) => {
|
||||||
const { cachedElements, resetAll, resetContainers, ...nextAppState } =
|
return {
|
||||||
value as ChangeFontFamilyData;
|
elements: changeProperty(
|
||||||
|
|
||||||
if (resetAll) {
|
|
||||||
const nextElements = changeProperty(
|
|
||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => {
|
(oldElement) => {
|
||||||
const cachedElement = cachedElements?.get(element.id);
|
if (isTextElement(oldElement)) {
|
||||||
if (cachedElement) {
|
const newElement: ExcalidrawTextElement = newElementWith(
|
||||||
const newElement = newElementWith(element, {
|
oldElement,
|
||||||
...cachedElement,
|
{
|
||||||
});
|
fontFamily: value,
|
||||||
|
lineHeight: getDefaultLineHeight(value),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
redrawTextBoundingBox(
|
||||||
|
newElement,
|
||||||
|
app.scene.getContainerElement(oldElement),
|
||||||
|
app.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
return newElement;
|
return newElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return oldElement;
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
),
|
||||||
|
|
||||||
return {
|
|
||||||
elements: nextElements,
|
|
||||||
appState: {
|
|
||||||
...appState,
|
|
||||||
...nextAppState,
|
|
||||||
},
|
|
||||||
storeAction: StoreAction.UPDATE,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const { currentItemFontFamily, currentHoveredFontFamily } = value;
|
|
||||||
|
|
||||||
let nexStoreAction: StoreActionType = StoreAction.NONE;
|
|
||||||
let nextFontFamily: FontFamilyValues | undefined;
|
|
||||||
let skipOnHoverRender = false;
|
|
||||||
|
|
||||||
if (currentItemFontFamily) {
|
|
||||||
nextFontFamily = currentItemFontFamily;
|
|
||||||
nexStoreAction = StoreAction.CAPTURE;
|
|
||||||
} else if (currentHoveredFontFamily) {
|
|
||||||
nextFontFamily = currentHoveredFontFamily;
|
|
||||||
nexStoreAction = StoreAction.NONE;
|
|
||||||
|
|
||||||
const selectedTextElements = getSelectedElements(elements, appState, {
|
|
||||||
includeBoundTextElement: true,
|
|
||||||
}).filter((element) => isTextElement(element));
|
|
||||||
|
|
||||||
// skip on hover re-render for more than 200 text elements or for text element with more than 5000 chars combined
|
|
||||||
if (selectedTextElements.length > 200) {
|
|
||||||
skipOnHoverRender = true;
|
|
||||||
} else {
|
|
||||||
let i = 0;
|
|
||||||
let textLengthAccumulator = 0;
|
|
||||||
|
|
||||||
while (
|
|
||||||
i < selectedTextElements.length &&
|
|
||||||
textLengthAccumulator < 5000
|
|
||||||
) {
|
|
||||||
const textElement = selectedTextElements[i] as ExcalidrawTextElement;
|
|
||||||
textLengthAccumulator += textElement?.originalText.length || 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textLengthAccumulator > 5000) {
|
|
||||||
skipOnHoverRender = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
...nextAppState,
|
currentItemFontFamily: value,
|
||||||
},
|
},
|
||||||
storeAction: nexStoreAction,
|
storeAction: StoreAction.CAPTURE,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (nextFontFamily && !skipOnHoverRender) {
|
|
||||||
const elementContainerMapping = new Map<
|
|
||||||
ExcalidrawTextElement,
|
|
||||||
ExcalidrawElement | null
|
|
||||||
>();
|
|
||||||
let uniqueGlyphs = new Set<string>();
|
|
||||||
let skipFontFaceCheck = false;
|
|
||||||
|
|
||||||
const fontsCache = Array.from(Fonts.loadedFontsCache.values());
|
|
||||||
const fontFamily = Object.entries(FONT_FAMILY).find(
|
|
||||||
([_, value]) => value === nextFontFamily,
|
|
||||||
)?.[0];
|
|
||||||
|
|
||||||
// skip `document.font.check` check on hover, if at least one font family has loaded as it's super slow (could result in slightly different bbox, which is fine)
|
|
||||||
if (
|
|
||||||
currentHoveredFontFamily &&
|
|
||||||
fontFamily &&
|
|
||||||
fontsCache.some((sig) => sig.startsWith(fontFamily))
|
|
||||||
) {
|
|
||||||
skipFontFaceCheck = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// following causes re-render so make sure we changed the family
|
|
||||||
// otherwise it could cause unexpected issues, such as preventing opening the popover when in wysiwyg
|
|
||||||
Object.assign(result, {
|
|
||||||
elements: changeProperty(
|
|
||||||
elements,
|
|
||||||
appState,
|
|
||||||
(oldElement) => {
|
|
||||||
if (
|
|
||||||
isTextElement(oldElement) &&
|
|
||||||
(oldElement.fontFamily !== nextFontFamily ||
|
|
||||||
currentItemFontFamily) // force update on selection
|
|
||||||
) {
|
|
||||||
const newElement: ExcalidrawTextElement = newElementWith(
|
|
||||||
oldElement,
|
|
||||||
{
|
|
||||||
fontFamily: nextFontFamily,
|
|
||||||
lineHeight: getLineHeight(nextFontFamily!),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const cachedContainer =
|
|
||||||
cachedElements?.get(oldElement.containerId || "") || {};
|
|
||||||
|
|
||||||
const container = app.scene.getContainerElement(oldElement);
|
|
||||||
|
|
||||||
if (resetContainers && container && cachedContainer) {
|
|
||||||
// reset the container back to it's cached version
|
|
||||||
mutateElement(container, { ...cachedContainer }, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!skipFontFaceCheck) {
|
|
||||||
uniqueGlyphs = new Set([
|
|
||||||
...uniqueGlyphs,
|
|
||||||
...Array.from(newElement.originalText),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
elementContainerMapping.set(newElement, container);
|
|
||||||
|
|
||||||
return newElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
return oldElement;
|
|
||||||
},
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
// size is irrelevant, but necessary
|
|
||||||
const fontString = `10px ${getFontFamilyString({
|
|
||||||
fontFamily: nextFontFamily,
|
|
||||||
})}`;
|
|
||||||
const glyphs = Array.from(uniqueGlyphs.values()).join();
|
|
||||||
|
|
||||||
if (
|
|
||||||
skipFontFaceCheck ||
|
|
||||||
window.document.fonts.check(fontString, glyphs)
|
|
||||||
) {
|
|
||||||
// we either skip the check (have at least one font face loaded) or do the check and find out all the font faces have loaded
|
|
||||||
for (const [element, container] of elementContainerMapping) {
|
|
||||||
// trigger synchronous redraw
|
|
||||||
redrawTextBoundingBox(
|
|
||||||
element,
|
|
||||||
container,
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// otherwise try to load all font faces for the given glyphs and redraw elements once our font faces loaded
|
|
||||||
window.document.fonts.load(fontString, glyphs).then((fontFaces) => {
|
|
||||||
for (const [element, container] of elementContainerMapping) {
|
|
||||||
// use latest element state to ensure we don't have closure over an old instance in order to avoid possible race conditions (i.e. font faces load out-of-order while rapidly switching fonts)
|
|
||||||
const latestElement = app.scene.getElement(element.id);
|
|
||||||
const latestContainer = container
|
|
||||||
? app.scene.getElement(container.id)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (latestElement) {
|
|
||||||
// trigger async redraw
|
|
||||||
redrawTextBoundingBox(
|
|
||||||
latestElement as ExcalidrawTextElement,
|
|
||||||
latestContainer,
|
|
||||||
app.scene.getNonDeletedElementsMap(),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// trigger update once we've mutated all the elements, which also updates our cache
|
|
||||||
app.fonts.onLoaded(fontFaces);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, app, updateData }) => {
|
PanelComponent: ({ elements, appState, updateData, app }) => {
|
||||||
const cachedElementsRef = useRef<Map<string, ExcalidrawElement>>(new Map());
|
const options: {
|
||||||
const prevSelectedFontFamilyRef = useRef<number | null>(null);
|
value: FontFamilyValues;
|
||||||
// relying on state batching as multiple `FontPicker` handlers could be called in rapid succession and we want to combine them
|
text: string;
|
||||||
const [batchedData, setBatchedData] = useState<ChangeFontFamilyData>({});
|
icon: JSX.Element;
|
||||||
const isUnmounted = useRef(true);
|
testId: string;
|
||||||
|
}[] = [
|
||||||
const selectedFontFamily = useMemo(() => {
|
{
|
||||||
const getFontFamily = (
|
value: FONT_FAMILY.Virgil,
|
||||||
elementsArray: readonly ExcalidrawElement[],
|
text: t("labels.handDrawn"),
|
||||||
elementsMap: Map<string, ExcalidrawElement>,
|
icon: FreedrawIcon,
|
||||||
) =>
|
testId: "font-family-virgil",
|
||||||
getFormValue(
|
},
|
||||||
elementsArray,
|
{
|
||||||
appState,
|
value: FONT_FAMILY.Helvetica,
|
||||||
(element) => {
|
text: t("labels.normal"),
|
||||||
if (isTextElement(element)) {
|
icon: FontFamilyNormalIcon,
|
||||||
return element.fontFamily;
|
testId: "font-family-normal",
|
||||||
}
|
},
|
||||||
const boundTextElement = getBoundTextElement(element, elementsMap);
|
{
|
||||||
if (boundTextElement) {
|
value: FONT_FAMILY.Cascadia,
|
||||||
return boundTextElement.fontFamily;
|
text: t("labels.code"),
|
||||||
}
|
icon: FontFamilyCodeIcon,
|
||||||
return null;
|
testId: "font-family-code",
|
||||||
},
|
},
|
||||||
(element) =>
|
];
|
||||||
isTextElement(element) ||
|
|
||||||
getBoundTextElement(element, elementsMap) !== null,
|
|
||||||
(hasSelection) =>
|
|
||||||
hasSelection
|
|
||||||
? null
|
|
||||||
: appState.currentItemFontFamily || DEFAULT_FONT_FAMILY,
|
|
||||||
);
|
|
||||||
|
|
||||||
// popup opened, use cached elements
|
|
||||||
if (
|
|
||||||
batchedData.openPopup === "fontFamily" &&
|
|
||||||
appState.openPopup === "fontFamily"
|
|
||||||
) {
|
|
||||||
return getFontFamily(
|
|
||||||
Array.from(cachedElementsRef.current?.values() ?? []),
|
|
||||||
cachedElementsRef.current,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// popup closed, use all elements
|
|
||||||
if (!batchedData.openPopup && appState.openPopup !== "fontFamily") {
|
|
||||||
return getFontFamily(elements, app.scene.getNonDeletedElementsMap());
|
|
||||||
}
|
|
||||||
|
|
||||||
// popup props are not in sync, hence we are in the middle of an update, so keeping the previous value we've had
|
|
||||||
return prevSelectedFontFamilyRef.current;
|
|
||||||
}, [batchedData.openPopup, appState, elements, app.scene]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
prevSelectedFontFamilyRef.current = selectedFontFamily;
|
|
||||||
}, [selectedFontFamily]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (Object.keys(batchedData).length) {
|
|
||||||
updateData(batchedData);
|
|
||||||
// reset the data after we've used the data
|
|
||||||
setBatchedData({});
|
|
||||||
}
|
|
||||||
// call update only on internal state changes
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [batchedData]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
isUnmounted.current = false;
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
isUnmounted.current = true;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.fontFamily")}</legend>
|
<legend>{t("labels.fontFamily")}</legend>
|
||||||
<FontPicker
|
<ButtonIconSelect<FontFamilyValues | false>
|
||||||
isOpened={appState.openPopup === "fontFamily"}
|
group="font-family"
|
||||||
selectedFontFamily={selectedFontFamily}
|
options={options}
|
||||||
hoveredFontFamily={appState.currentHoveredFontFamily}
|
value={getFormValue(
|
||||||
onSelect={(fontFamily) => {
|
elements,
|
||||||
setBatchedData({
|
appState,
|
||||||
openPopup: null,
|
(element) => {
|
||||||
currentHoveredFontFamily: null,
|
if (isTextElement(element)) {
|
||||||
currentItemFontFamily: fontFamily,
|
return element.fontFamily;
|
||||||
});
|
|
||||||
|
|
||||||
// defensive clear so immediate close won't abuse the cached elements
|
|
||||||
cachedElementsRef.current.clear();
|
|
||||||
}}
|
|
||||||
onHover={(fontFamily) => {
|
|
||||||
setBatchedData({
|
|
||||||
currentHoveredFontFamily: fontFamily,
|
|
||||||
cachedElements: new Map(cachedElementsRef.current),
|
|
||||||
resetContainers: true,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
onLeave={() => {
|
|
||||||
setBatchedData({
|
|
||||||
currentHoveredFontFamily: null,
|
|
||||||
cachedElements: new Map(cachedElementsRef.current),
|
|
||||||
resetAll: true,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
onPopupChange={(open) => {
|
|
||||||
if (open) {
|
|
||||||
// open, populate the cache from scratch
|
|
||||||
cachedElementsRef.current.clear();
|
|
||||||
|
|
||||||
const { editingElement } = appState;
|
|
||||||
|
|
||||||
if (editingElement?.type === "text") {
|
|
||||||
// retrieve the latest version from the scene, as `editingElement` isn't mutated
|
|
||||||
const latestEditingElement = app.scene.getElement(
|
|
||||||
editingElement.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
// inside the wysiwyg editor
|
|
||||||
cachedElementsRef.current.set(
|
|
||||||
editingElement.id,
|
|
||||||
newElementWith(
|
|
||||||
latestEditingElement || editingElement,
|
|
||||||
{},
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const selectedElements = getSelectedElements(
|
|
||||||
elements,
|
|
||||||
appState,
|
|
||||||
{
|
|
||||||
includeBoundTextElement: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const element of selectedElements) {
|
|
||||||
cachedElementsRef.current.set(
|
|
||||||
element.id,
|
|
||||||
newElementWith(element, {}, true),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const boundTextElement = getBoundTextElement(
|
||||||
setBatchedData({
|
element,
|
||||||
openPopup: "fontFamily",
|
app.scene.getNonDeletedElementsMap(),
|
||||||
});
|
);
|
||||||
} else {
|
if (boundTextElement) {
|
||||||
// close, use the cache and clear it afterwards
|
return boundTextElement.fontFamily;
|
||||||
const data = {
|
|
||||||
openPopup: null,
|
|
||||||
currentHoveredFontFamily: null,
|
|
||||||
cachedElements: new Map(cachedElementsRef.current),
|
|
||||||
resetAll: true,
|
|
||||||
} as ChangeFontFamilyData;
|
|
||||||
|
|
||||||
if (isUnmounted.current) {
|
|
||||||
// in case the component was unmounted by the parent, trigger the update directly
|
|
||||||
updateData({ ...batchedData, ...data });
|
|
||||||
} else {
|
|
||||||
setBatchedData(data);
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
cachedElementsRef.current.clear();
|
},
|
||||||
}
|
(element) =>
|
||||||
}}
|
isTextElement(element) ||
|
||||||
|
getBoundTextElement(
|
||||||
|
element,
|
||||||
|
app.scene.getNonDeletedElementsMap(),
|
||||||
|
) !== null,
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection
|
||||||
|
? null
|
||||||
|
: appState.currentItemFontFamily || DEFAULT_FONT_FAMILY,
|
||||||
|
)}
|
||||||
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ import {
|
|||||||
DEFAULT_FONT_FAMILY,
|
DEFAULT_FONT_FAMILY,
|
||||||
DEFAULT_TEXT_ALIGN,
|
DEFAULT_TEXT_ALIGN,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import { getBoundTextElement } from "../element/textElement";
|
import {
|
||||||
|
getBoundTextElement,
|
||||||
|
getDefaultLineHeight,
|
||||||
|
} from "../element/textElement";
|
||||||
import {
|
import {
|
||||||
hasBoundTextElement,
|
hasBoundTextElement,
|
||||||
canApplyRoundnessTypeToElement,
|
canApplyRoundnessTypeToElement,
|
||||||
@@ -24,7 +27,6 @@ import { getSelectedElements } from "../scene";
|
|||||||
import type { ExcalidrawTextElement } from "../element/types";
|
import type { ExcalidrawTextElement } from "../element/types";
|
||||||
import { paintIcon } from "../components/icons";
|
import { paintIcon } from "../components/icons";
|
||||||
import { StoreAction } from "../store";
|
import { StoreAction } from "../store";
|
||||||
import { getLineHeight } from "../fonts";
|
|
||||||
|
|
||||||
// `copiedStyles` is exported only for tests.
|
// `copiedStyles` is exported only for tests.
|
||||||
export let copiedStyles: string = "{}";
|
export let copiedStyles: string = "{}";
|
||||||
@@ -120,7 +122,7 @@ export const actionPasteStyles = register({
|
|||||||
DEFAULT_TEXT_ALIGN,
|
DEFAULT_TEXT_ALIGN,
|
||||||
lineHeight:
|
lineHeight:
|
||||||
(elementStylesToCopyFrom as ExcalidrawTextElement).lineHeight ||
|
(elementStylesToCopyFrom as ExcalidrawTextElement).lineHeight ||
|
||||||
getLineHeight(fontFamily),
|
getDefaultLineHeight(fontFamily),
|
||||||
});
|
});
|
||||||
let container = null;
|
let container = null;
|
||||||
if (newElement.containerId) {
|
if (newElement.containerId) {
|
||||||
|
|||||||
@@ -5,22 +5,21 @@ import { StoreAction } from "../store";
|
|||||||
|
|
||||||
export const actionToggleStats = register({
|
export const actionToggleStats = register({
|
||||||
name: "stats",
|
name: "stats",
|
||||||
label: "stats.fullTitle",
|
label: "stats.title",
|
||||||
icon: abacusIcon,
|
icon: abacusIcon,
|
||||||
paletteName: "Toggle stats",
|
paletteName: "Toggle stats",
|
||||||
viewMode: true,
|
viewMode: true,
|
||||||
trackEvent: { category: "menu" },
|
trackEvent: { category: "menu" },
|
||||||
keywords: ["edit", "attributes", "customize"],
|
|
||||||
perform(elements, appState) {
|
perform(elements, appState) {
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
stats: { ...appState.stats, open: !this.checked!(appState) },
|
showStats: !this.checked!(appState),
|
||||||
},
|
},
|
||||||
storeAction: StoreAction.NONE,
|
storeAction: StoreAction.NONE,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
checked: (appState) => appState.stats.open,
|
checked: (appState) => appState.showStats,
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.SLASH,
|
!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.SLASH,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// place here categories that you want to track. We want to track just a
|
// place here categories that you want to track. We want to track just a
|
||||||
// small subset of categories at a given time.
|
// small subset of categories at a given time.
|
||||||
const ALLOWED_CATEGORIES_TO_TRACK = new Set(["command_palette"]);
|
const ALLOWED_CATEGORIES_TO_TRACK = ["ai", "command_palette"] as string[];
|
||||||
|
|
||||||
export const trackEvent = (
|
export const trackEvent = (
|
||||||
category: string,
|
category: string,
|
||||||
@@ -9,20 +9,17 @@ export const trackEvent = (
|
|||||||
value?: number,
|
value?: number,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
|
// prettier-ignore
|
||||||
if (
|
if (
|
||||||
typeof window === "undefined" ||
|
typeof window === "undefined"
|
||||||
import.meta.env.VITE_WORKER_ID ||
|
|| import.meta.env.VITE_WORKER_ID
|
||||||
import.meta.env.VITE_APP_ENABLE_TRACKING !== "true"
|
// comment out to debug locally
|
||||||
|
|| import.meta.env.PROD
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ALLOWED_CATEGORIES_TO_TRACK.has(category)) {
|
if (!ALLOWED_CATEGORIES_TO_TRACK.includes(category)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (import.meta.env.DEV) {
|
|
||||||
// comment out to debug in dev
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
DEFAULT_FONT_SIZE,
|
DEFAULT_FONT_SIZE,
|
||||||
DEFAULT_TEXT_ALIGN,
|
DEFAULT_TEXT_ALIGN,
|
||||||
EXPORT_SCALES,
|
EXPORT_SCALES,
|
||||||
STATS_PANELS,
|
|
||||||
THEME,
|
THEME,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
import type { AppState, NormalizedZoomValue } from "./types";
|
import type { AppState, NormalizedZoomValue } from "./types";
|
||||||
@@ -36,7 +35,6 @@ export const getDefaultAppState = (): Omit<
|
|||||||
currentItemStrokeStyle: DEFAULT_ELEMENT_PROPS.strokeStyle,
|
currentItemStrokeStyle: DEFAULT_ELEMENT_PROPS.strokeStyle,
|
||||||
currentItemStrokeWidth: DEFAULT_ELEMENT_PROPS.strokeWidth,
|
currentItemStrokeWidth: DEFAULT_ELEMENT_PROPS.strokeWidth,
|
||||||
currentItemTextAlign: DEFAULT_TEXT_ALIGN,
|
currentItemTextAlign: DEFAULT_TEXT_ALIGN,
|
||||||
currentHoveredFontFamily: null,
|
|
||||||
cursorButton: "up",
|
cursorButton: "up",
|
||||||
activeEmbeddable: null,
|
activeEmbeddable: null,
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
@@ -82,10 +80,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
selectedElementsAreBeingDragged: false,
|
selectedElementsAreBeingDragged: false,
|
||||||
selectionElement: null,
|
selectionElement: null,
|
||||||
shouldCacheIgnoreZoom: false,
|
shouldCacheIgnoreZoom: false,
|
||||||
stats: {
|
showStats: false,
|
||||||
open: false,
|
|
||||||
panels: STATS_PANELS.generalStats | STATS_PANELS.elementProperties,
|
|
||||||
},
|
|
||||||
startBoundElement: null,
|
startBoundElement: null,
|
||||||
suggestedBindings: [],
|
suggestedBindings: [],
|
||||||
frameRendering: { enabled: true, clip: true, name: true, outline: true },
|
frameRendering: { enabled: true, clip: true, name: true, outline: true },
|
||||||
@@ -150,7 +145,6 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
currentItemStrokeStyle: { browser: true, export: false, server: false },
|
currentItemStrokeStyle: { browser: true, export: false, server: false },
|
||||||
currentItemStrokeWidth: { browser: true, export: false, server: false },
|
currentItemStrokeWidth: { browser: true, export: false, server: false },
|
||||||
currentItemTextAlign: { browser: true, export: false, server: false },
|
currentItemTextAlign: { browser: true, export: false, server: false },
|
||||||
currentHoveredFontFamily: { browser: false, export: false, server: false },
|
|
||||||
cursorButton: { browser: true, export: false, server: false },
|
cursorButton: { browser: true, export: false, server: false },
|
||||||
activeEmbeddable: { browser: false, export: false, server: false },
|
activeEmbeddable: { browser: false, export: false, server: false },
|
||||||
draggingElement: { browser: false, export: false, server: false },
|
draggingElement: { browser: false, export: false, server: false },
|
||||||
@@ -202,7 +196,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
},
|
},
|
||||||
selectionElement: { browser: false, export: false, server: false },
|
selectionElement: { browser: false, export: false, server: false },
|
||||||
shouldCacheIgnoreZoom: { browser: true, export: false, server: false },
|
shouldCacheIgnoreZoom: { browser: true, export: false, server: false },
|
||||||
stats: { browser: true, export: false, server: false },
|
showStats: { browser: true, export: false, server: false },
|
||||||
startBoundElement: { browser: false, export: false, server: false },
|
startBoundElement: { browser: false, export: false, server: false },
|
||||||
suggestedBindings: { browser: false, export: false, server: false },
|
suggestedBindings: { browser: false, export: false, server: false },
|
||||||
frameRendering: { browser: false, export: false, server: false },
|
frameRendering: { browser: false, export: false, server: false },
|
||||||
|
|||||||
@@ -158,8 +158,10 @@ export const SelectedShapeActions = ({
|
|||||||
{(appState.activeTool.type === "text" ||
|
{(appState.activeTool.type === "text" ||
|
||||||
targetElements.some(isTextElement)) && (
|
targetElements.some(isTextElement)) && (
|
||||||
<>
|
<>
|
||||||
{renderAction("changeFontFamily")}
|
|
||||||
{renderAction("changeFontSize")}
|
{renderAction("changeFontSize")}
|
||||||
|
|
||||||
|
{renderAction("changeFontFamily")}
|
||||||
|
|
||||||
{(appState.activeTool.type === "text" ||
|
{(appState.activeTool.type === "text" ||
|
||||||
suppportsHorizontalAlign(targetElements, elementsMap)) &&
|
suppportsHorizontalAlign(targetElements, elementsMap)) &&
|
||||||
renderAction("changeTextAlign")}
|
renderAction("changeTextAlign")}
|
||||||
|
|||||||
@@ -224,8 +224,16 @@ import type {
|
|||||||
ScrollBars,
|
ScrollBars,
|
||||||
} from "../scene/types";
|
} from "../scene/types";
|
||||||
import { getStateForZoom } from "../scene/zoom";
|
import { getStateForZoom } from "../scene/zoom";
|
||||||
import { findShapeByKey, getBoundTextShape, getElementShape } from "../shapes";
|
import { findShapeByKey } from "../shapes";
|
||||||
import { getSelectionBoxShape } from "../../utils/geometry/shape";
|
import type { GeometricShape } from "../../utils/geometry/shape";
|
||||||
|
import {
|
||||||
|
getClosedCurveShape,
|
||||||
|
getCurveShape,
|
||||||
|
getEllipseShape,
|
||||||
|
getFreedrawShape,
|
||||||
|
getPolygonShape,
|
||||||
|
getSelectionBoxShape,
|
||||||
|
} from "../../utils/geometry/shape";
|
||||||
import { isPointInShape } from "../../utils/collision";
|
import { isPointInShape } from "../../utils/collision";
|
||||||
import type {
|
import type {
|
||||||
AppClassProperties,
|
AppClassProperties,
|
||||||
@@ -320,8 +328,8 @@ import {
|
|||||||
getBoundTextElement,
|
getBoundTextElement,
|
||||||
getContainerCenter,
|
getContainerCenter,
|
||||||
getContainerElement,
|
getContainerElement,
|
||||||
|
getDefaultLineHeight,
|
||||||
getLineHeightInPx,
|
getLineHeightInPx,
|
||||||
getMinTextElementWidth,
|
|
||||||
isMeasureTextSupported,
|
isMeasureTextSupported,
|
||||||
isValidTextContainer,
|
isValidTextContainer,
|
||||||
measureText,
|
measureText,
|
||||||
@@ -335,7 +343,7 @@ import {
|
|||||||
import { isLocalLink, normalizeLink, toValidURL } from "../data/url";
|
import { isLocalLink, normalizeLink, toValidURL } from "../data/url";
|
||||||
import { shouldShowBoundingBox } from "../element/transformHandles";
|
import { shouldShowBoundingBox } from "../element/transformHandles";
|
||||||
import { actionUnlockAllElements } from "../actions/actionElementLock";
|
import { actionUnlockAllElements } from "../actions/actionElementLock";
|
||||||
import { Fonts, getLineHeight } from "../fonts";
|
import { Fonts } from "../scene/Fonts";
|
||||||
import {
|
import {
|
||||||
getFrameChildren,
|
getFrameChildren,
|
||||||
isCursorInFrame,
|
isCursorInFrame,
|
||||||
@@ -414,6 +422,7 @@ import {
|
|||||||
hitElementBoundText,
|
hitElementBoundText,
|
||||||
hitElementBoundingBoxOnly,
|
hitElementBoundingBoxOnly,
|
||||||
hitElementItself,
|
hitElementItself,
|
||||||
|
shouldTestInside,
|
||||||
} from "../element/collision";
|
} from "../element/collision";
|
||||||
import { textWysiwyg } from "../element/textWysiwyg";
|
import { textWysiwyg } from "../element/textWysiwyg";
|
||||||
import { isOverScrollBars } from "../scene/scrollbars";
|
import { isOverScrollBars } from "../scene/scrollbars";
|
||||||
@@ -425,7 +434,7 @@ import {
|
|||||||
import { getShortcutFromShortcutName } from "../actions/shortcuts";
|
import { getShortcutFromShortcutName } from "../actions/shortcuts";
|
||||||
import { actionTextAutoResize } from "../actions/actionTextAutoResize";
|
import { actionTextAutoResize } from "../actions/actionTextAutoResize";
|
||||||
import { getVisibleSceneBounds } from "../element/bounds";
|
import { getVisibleSceneBounds } from "../element/bounds";
|
||||||
import { isMaybeMermaidDefinition } from "../mermaid";
|
import { Stats } from "./Stats";
|
||||||
|
|
||||||
const AppContext = React.createContext<AppClassProperties>(null!);
|
const AppContext = React.createContext<AppClassProperties>(null!);
|
||||||
const AppPropsContext = React.createContext<AppProps>(null!);
|
const AppPropsContext = React.createContext<AppProps>(null!);
|
||||||
@@ -530,14 +539,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
private excalidrawContainerRef = React.createRef<HTMLDivElement>();
|
private excalidrawContainerRef = React.createRef<HTMLDivElement>();
|
||||||
|
|
||||||
public scene: Scene;
|
public scene: Scene;
|
||||||
public fonts: Fonts;
|
|
||||||
public renderer: Renderer;
|
public renderer: Renderer;
|
||||||
|
private fonts: Fonts;
|
||||||
private resizeObserver: ResizeObserver | undefined;
|
private resizeObserver: ResizeObserver | undefined;
|
||||||
private nearestScrollableContainer: HTMLElement | Document | undefined;
|
private nearestScrollableContainer: HTMLElement | Document | undefined;
|
||||||
public library: AppClassProperties["library"];
|
public library: AppClassProperties["library"];
|
||||||
public libraryItemsFromStorage: LibraryItems | undefined;
|
public libraryItemsFromStorage: LibraryItems | undefined;
|
||||||
public id: string;
|
public id: string;
|
||||||
private store: Store;
|
store: Store;
|
||||||
private history: History;
|
private history: History;
|
||||||
private excalidrawContainerValue: {
|
private excalidrawContainerValue: {
|
||||||
container: HTMLDivElement | null;
|
container: HTMLDivElement | null;
|
||||||
@@ -1661,6 +1670,19 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{this.state.showStats && (
|
||||||
|
<Stats
|
||||||
|
appState={this.state}
|
||||||
|
setAppState={this.setState}
|
||||||
|
scene={this.scene}
|
||||||
|
onClose={() => {
|
||||||
|
this.actionManager.executeAction(
|
||||||
|
actionToggleStats,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
renderCustomStats={renderCustomStats}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<StaticCanvas
|
<StaticCanvas
|
||||||
canvas={this.canvas}
|
canvas={this.canvas}
|
||||||
rc={this.rc}
|
rc={this.rc}
|
||||||
@@ -1688,7 +1710,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
canvas={this.interactiveCanvas}
|
canvas={this.interactiveCanvas}
|
||||||
elementsMap={elementsMap}
|
elementsMap={elementsMap}
|
||||||
visibleElements={visibleElements}
|
visibleElements={visibleElements}
|
||||||
allElementsMap={allElementsMap}
|
|
||||||
selectedElements={selectedElements}
|
selectedElements={selectedElements}
|
||||||
sceneNonce={sceneNonce}
|
sceneNonce={sceneNonce}
|
||||||
selectionNonce={
|
selectionNonce={
|
||||||
@@ -2124,96 +2145,95 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public syncActionResult = withBatchedUpdates((actionResult: ActionResult) => {
|
private syncActionResult = withBatchedUpdates(
|
||||||
if (this.unmounted || actionResult === false) {
|
(actionResult: ActionResult) => {
|
||||||
return;
|
if (this.unmounted || actionResult === false) {
|
||||||
}
|
return;
|
||||||
|
|
||||||
if (actionResult.storeAction === StoreAction.UPDATE) {
|
|
||||||
this.store.shouldUpdateSnapshot();
|
|
||||||
} else if (actionResult.storeAction === StoreAction.CAPTURE) {
|
|
||||||
this.store.shouldCaptureIncrement();
|
|
||||||
}
|
|
||||||
|
|
||||||
let didUpdate = false;
|
|
||||||
|
|
||||||
let editingElement: AppState["editingElement"] | null = null;
|
|
||||||
if (actionResult.elements) {
|
|
||||||
actionResult.elements.forEach((element) => {
|
|
||||||
if (
|
|
||||||
this.state.editingElement?.id === element.id &&
|
|
||||||
this.state.editingElement !== element &&
|
|
||||||
isNonDeletedElement(element)
|
|
||||||
) {
|
|
||||||
editingElement = element;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.scene.replaceAllElements(actionResult.elements);
|
|
||||||
didUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actionResult.files) {
|
|
||||||
this.files = actionResult.replaceFiles
|
|
||||||
? actionResult.files
|
|
||||||
: { ...this.files, ...actionResult.files };
|
|
||||||
this.addNewImagesToImageCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actionResult.appState || editingElement || this.state.contextMenu) {
|
|
||||||
let viewModeEnabled = actionResult?.appState?.viewModeEnabled || false;
|
|
||||||
let zenModeEnabled = actionResult?.appState?.zenModeEnabled || false;
|
|
||||||
let gridSize = actionResult?.appState?.gridSize || null;
|
|
||||||
const theme =
|
|
||||||
actionResult?.appState?.theme || this.props.theme || THEME.LIGHT;
|
|
||||||
const name = actionResult?.appState?.name ?? this.state.name;
|
|
||||||
const errorMessage =
|
|
||||||
actionResult?.appState?.errorMessage ?? this.state.errorMessage;
|
|
||||||
if (typeof this.props.viewModeEnabled !== "undefined") {
|
|
||||||
viewModeEnabled = this.props.viewModeEnabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof this.props.zenModeEnabled !== "undefined") {
|
let editingElement: AppState["editingElement"] | null = null;
|
||||||
zenModeEnabled = this.props.zenModeEnabled;
|
if (actionResult.elements) {
|
||||||
}
|
actionResult.elements.forEach((element) => {
|
||||||
|
if (
|
||||||
if (typeof this.props.gridModeEnabled !== "undefined") {
|
this.state.editingElement?.id === element.id &&
|
||||||
gridSize = this.props.gridModeEnabled ? GRID_SIZE : null;
|
this.state.editingElement !== element &&
|
||||||
}
|
isNonDeletedElement(element)
|
||||||
|
) {
|
||||||
editingElement =
|
editingElement = element;
|
||||||
editingElement || actionResult.appState?.editingElement || null;
|
}
|
||||||
|
|
||||||
if (editingElement?.isDeleted) {
|
|
||||||
editingElement = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState((state) => {
|
|
||||||
// using Object.assign instead of spread to fool TS 4.2.2+ into
|
|
||||||
// regarding the resulting type as not containing undefined
|
|
||||||
// (which the following expression will never contain)
|
|
||||||
return Object.assign(actionResult.appState || {}, {
|
|
||||||
// NOTE this will prevent opening context menu using an action
|
|
||||||
// or programmatically from the host, so it will need to be
|
|
||||||
// rewritten later
|
|
||||||
contextMenu: null,
|
|
||||||
editingElement,
|
|
||||||
viewModeEnabled,
|
|
||||||
zenModeEnabled,
|
|
||||||
gridSize,
|
|
||||||
theme,
|
|
||||||
name,
|
|
||||||
errorMessage,
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
didUpdate = true;
|
if (actionResult.storeAction === StoreAction.UPDATE) {
|
||||||
}
|
this.store.shouldUpdateSnapshot();
|
||||||
|
} else if (actionResult.storeAction === StoreAction.CAPTURE) {
|
||||||
|
this.store.shouldCaptureIncrement();
|
||||||
|
}
|
||||||
|
|
||||||
if (!didUpdate && actionResult.storeAction !== StoreAction.NONE) {
|
this.scene.replaceAllElements(actionResult.elements);
|
||||||
this.scene.triggerUpdate();
|
}
|
||||||
}
|
|
||||||
});
|
if (actionResult.files) {
|
||||||
|
this.files = actionResult.replaceFiles
|
||||||
|
? actionResult.files
|
||||||
|
: { ...this.files, ...actionResult.files };
|
||||||
|
this.addNewImagesToImageCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionResult.appState || editingElement || this.state.contextMenu) {
|
||||||
|
if (actionResult.storeAction === StoreAction.UPDATE) {
|
||||||
|
this.store.shouldUpdateSnapshot();
|
||||||
|
} else if (actionResult.storeAction === StoreAction.CAPTURE) {
|
||||||
|
this.store.shouldCaptureIncrement();
|
||||||
|
}
|
||||||
|
|
||||||
|
let viewModeEnabled = actionResult?.appState?.viewModeEnabled || false;
|
||||||
|
let zenModeEnabled = actionResult?.appState?.zenModeEnabled || false;
|
||||||
|
let gridSize = actionResult?.appState?.gridSize || null;
|
||||||
|
const theme =
|
||||||
|
actionResult?.appState?.theme || this.props.theme || THEME.LIGHT;
|
||||||
|
const name = actionResult?.appState?.name ?? this.state.name;
|
||||||
|
const errorMessage =
|
||||||
|
actionResult?.appState?.errorMessage ?? this.state.errorMessage;
|
||||||
|
if (typeof this.props.viewModeEnabled !== "undefined") {
|
||||||
|
viewModeEnabled = this.props.viewModeEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof this.props.zenModeEnabled !== "undefined") {
|
||||||
|
zenModeEnabled = this.props.zenModeEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof this.props.gridModeEnabled !== "undefined") {
|
||||||
|
gridSize = this.props.gridModeEnabled ? GRID_SIZE : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
editingElement =
|
||||||
|
editingElement || actionResult.appState?.editingElement || null;
|
||||||
|
|
||||||
|
if (editingElement?.isDeleted) {
|
||||||
|
editingElement = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState((state) => {
|
||||||
|
// using Object.assign instead of spread to fool TS 4.2.2+ into
|
||||||
|
// regarding the resulting type as not containing undefined
|
||||||
|
// (which the following expression will never contain)
|
||||||
|
return Object.assign(actionResult.appState || {}, {
|
||||||
|
// NOTE this will prevent opening context menu using an action
|
||||||
|
// or programmatically from the host, so it will need to be
|
||||||
|
// rewritten later
|
||||||
|
contextMenu: null,
|
||||||
|
editingElement,
|
||||||
|
viewModeEnabled,
|
||||||
|
zenModeEnabled,
|
||||||
|
gridSize,
|
||||||
|
theme,
|
||||||
|
name,
|
||||||
|
errorMessage,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
|
|
||||||
@@ -2280,11 +2300,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
let initialData = null;
|
let initialData = null;
|
||||||
try {
|
try {
|
||||||
if (typeof this.props.initialData === "function") {
|
initialData = (await this.props.initialData) || null;
|
||||||
initialData = (await this.props.initialData()) || null;
|
|
||||||
} else {
|
|
||||||
initialData = (await this.props.initialData) || null;
|
|
||||||
}
|
|
||||||
if (initialData?.libraryItems) {
|
if (initialData?.libraryItems) {
|
||||||
this.library
|
this.library
|
||||||
.updateLibrary({
|
.updateLibrary({
|
||||||
@@ -2333,6 +2349,11 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// FontFaceSet loadingdone event we listen on may not always fire
|
||||||
|
// (looking at you Safari), so on init we manually load fonts for current
|
||||||
|
// text elements on canvas, and rerender them once done. This also
|
||||||
|
// seems faster even in browsers that do fire the loadingdone event.
|
||||||
|
this.fonts.loadFontsForElements(scene.elements);
|
||||||
|
|
||||||
this.resetStore();
|
this.resetStore();
|
||||||
this.resetHistory();
|
this.resetHistory();
|
||||||
@@ -2340,12 +2361,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
...scene,
|
...scene,
|
||||||
storeAction: StoreAction.UPDATE,
|
storeAction: StoreAction.UPDATE,
|
||||||
});
|
});
|
||||||
|
|
||||||
// FontFaceSet loadingdone event we listen on may not always
|
|
||||||
// fire (looking at you Safari), so on init we manually load all
|
|
||||||
// fonts and rerender scene text elements once done. This also
|
|
||||||
// seems faster even in browsers that do fire the loadingdone event.
|
|
||||||
this.fonts.load();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private isMobileBreakpoint = (width: number, height: number) => {
|
private isMobileBreakpoint = (width: number, height: number) => {
|
||||||
@@ -2438,10 +2453,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
configurable: true,
|
configurable: true,
|
||||||
value: this.store,
|
value: this.store,
|
||||||
},
|
},
|
||||||
fonts: {
|
|
||||||
configurable: true,
|
|
||||||
value: this.fonts,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2492,9 +2503,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
(window as any).launchQueue?.setConsumer(() => {});
|
|
||||||
this.renderer.destroy();
|
this.renderer.destroy();
|
||||||
this.scene.destroy();
|
|
||||||
this.scene = new Scene();
|
this.scene = new Scene();
|
||||||
this.fonts = new Fonts({ scene: this.scene });
|
this.fonts = new Fonts({ scene: this.scene });
|
||||||
this.renderer = new Renderer(this.scene);
|
this.renderer = new Renderer(this.scene);
|
||||||
@@ -2503,6 +2512,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.resizeObserver?.disconnect();
|
this.resizeObserver?.disconnect();
|
||||||
this.unmounted = true;
|
this.unmounted = true;
|
||||||
this.removeEventListeners();
|
this.removeEventListeners();
|
||||||
|
this.scene.destroy();
|
||||||
this.library.destroy();
|
this.library.destroy();
|
||||||
this.laserTrails.stop();
|
this.laserTrails.stop();
|
||||||
this.eraserTrail.stop();
|
this.eraserTrail.stop();
|
||||||
@@ -2579,7 +2589,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
// rerender text elements on font load to fix #637 && #1553
|
// rerender text elements on font load to fix #637 && #1553
|
||||||
addEventListener(document.fonts, "loadingdone", (event) => {
|
addEventListener(document.fonts, "loadingdone", (event) => {
|
||||||
const loadedFontFaces = (event as FontFaceSetLoadEvent).fontfaces;
|
const loadedFontFaces = (event as FontFaceSetLoadEvent).fontfaces;
|
||||||
this.fonts.onLoaded(loadedFontFaces);
|
this.fonts.onFontsLoaded(loadedFontFaces);
|
||||||
}),
|
}),
|
||||||
// Safari-only desktop pinch zoom
|
// Safari-only desktop pinch zoom
|
||||||
addEventListener(
|
addEventListener(
|
||||||
@@ -2814,7 +2824,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
nonDeletedElementsMap,
|
nonDeletedElementsMap,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3052,31 +3062,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
retainSeed: isPlainPaste,
|
retainSeed: isPlainPaste,
|
||||||
});
|
});
|
||||||
} else if (data.text) {
|
} else if (data.text) {
|
||||||
if (data.text && isMaybeMermaidDefinition(data.text)) {
|
|
||||||
const api = await import("@excalidraw/mermaid-to-excalidraw");
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { elements: skeletonElements, files } =
|
|
||||||
await api.parseMermaidToExcalidraw(data.text);
|
|
||||||
|
|
||||||
const elements = convertToExcalidrawElements(skeletonElements, {
|
|
||||||
regenerateIds: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addElementsFromPasteOrLibrary({
|
|
||||||
elements,
|
|
||||||
files,
|
|
||||||
position: "cursor",
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
} catch (err: any) {
|
|
||||||
console.warn(
|
|
||||||
`parsing pasted text as mermaid definition failed: ${err.message}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const nonEmptyLines = normalizeEOL(data.text)
|
const nonEmptyLines = normalizeEOL(data.text)
|
||||||
.split(/\n+/)
|
.split(/\n+/)
|
||||||
.map((s) => s.trim())
|
.map((s) => s.trim())
|
||||||
@@ -3382,7 +3367,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
fontSize: textElementProps.fontSize,
|
fontSize: textElementProps.fontSize,
|
||||||
fontFamily: textElementProps.fontFamily,
|
fontFamily: textElementProps.fontFamily,
|
||||||
});
|
});
|
||||||
const lineHeight = getLineHeight(textElementProps.fontFamily);
|
const lineHeight = getDefaultLineHeight(textElementProps.fontFamily);
|
||||||
const [x1, , x2] = getVisibleSceneBounds(this.state);
|
const [x1, , x2] = getVisibleSceneBounds(this.state);
|
||||||
// long texts should not go beyond 800 pixels in width nor should it go below 200 px
|
// long texts should not go beyond 800 pixels in width nor should it go below 200 px
|
||||||
const maxTextWidth = Math.max(Math.min((x2 - x1) * 0.5, 800), 200);
|
const maxTextWidth = Math.max(Math.min((x2 - x1) * 0.5, 800), 200);
|
||||||
@@ -3400,13 +3385,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let metrics = measureText(originalText, fontString, lineHeight);
|
let metrics = measureText(originalText, fontString, lineHeight);
|
||||||
const isTextUnwrapped = metrics.width > maxTextWidth;
|
const isTextWrapped = metrics.width > maxTextWidth;
|
||||||
|
|
||||||
const text = isTextUnwrapped
|
const text = isTextWrapped
|
||||||
? wrapText(originalText, fontString, maxTextWidth)
|
? wrapText(originalText, fontString, maxTextWidth)
|
||||||
: originalText;
|
: originalText;
|
||||||
|
|
||||||
metrics = isTextUnwrapped
|
metrics = isTextWrapped
|
||||||
? measureText(text, fontString, lineHeight)
|
? measureText(text, fontString, lineHeight)
|
||||||
: metrics;
|
: metrics;
|
||||||
|
|
||||||
@@ -3420,7 +3405,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
text,
|
text,
|
||||||
originalText,
|
originalText,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
autoResize: !isTextUnwrapped,
|
autoResize: !isTextWrapped,
|
||||||
frameId: topLayerFrame ? topLayerFrame.id : null,
|
frameId: topLayerFrame ? topLayerFrame.id : null,
|
||||||
});
|
});
|
||||||
acc.push(element);
|
acc.push(element);
|
||||||
@@ -4001,7 +3986,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
suggestedBindings: getSuggestedBindingsForArrows(
|
suggestedBindings: getSuggestedBindingsForArrows(
|
||||||
selectedElements,
|
selectedElements,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -4110,36 +4095,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
!event[KEYS.CTRL_OR_CMD] &&
|
|
||||||
event.shiftKey &&
|
|
||||||
event.key.toLowerCase() === KEYS.F
|
|
||||||
) {
|
|
||||||
const selectedElements = this.scene.getSelectedElements(this.state);
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.state.activeTool.type === "selection" &&
|
|
||||||
!selectedElements.length
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.state.activeTool.type === "text" ||
|
|
||||||
selectedElements.find(
|
|
||||||
(element) =>
|
|
||||||
isTextElement(element) ||
|
|
||||||
getBoundTextElement(
|
|
||||||
element,
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({ openPopup: "fontFamily" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === KEYS.K && !event.altKey && !event[KEYS.CTRL_OR_CMD]) {
|
if (event.key === KEYS.K && !event.altKey && !event[KEYS.CTRL_OR_CMD]) {
|
||||||
if (this.state.activeTool.type === "laser") {
|
if (this.state.activeTool.type === "laser") {
|
||||||
this.setActiveTool({ type: "selection" });
|
this.setActiveTool({ type: "selection" });
|
||||||
@@ -4202,7 +4157,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
if (isArrowKey(event.key)) {
|
if (isArrowKey(event.key)) {
|
||||||
bindOrUnbindLinearElements(
|
bindOrUnbindLinearElements(
|
||||||
this.scene.getSelectedElements(this.state).filter(isLinearElement),
|
this.scene.getSelectedElements(this.state).filter(isLinearElement),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
isBindingEnabled(this.state),
|
isBindingEnabled(this.state),
|
||||||
this.state.selectedLinearElement?.selectedPointsIndices ?? [],
|
this.state.selectedLinearElement?.selectedPointsIndices ?? [],
|
||||||
);
|
);
|
||||||
@@ -4478,11 +4433,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
element,
|
element,
|
||||||
excalidrawContainer: this.excalidrawContainerRef.current,
|
excalidrawContainer: this.excalidrawContainerRef.current,
|
||||||
app: this,
|
app: this,
|
||||||
// when text is selected, it's hard (at least on iOS) to re-position the
|
|
||||||
// caret (i.e. deselect). There's not much use for always selecting
|
|
||||||
// the text on edit anyway (and users can select-all from contextmenu
|
|
||||||
// if needed)
|
|
||||||
autoSelect: !this.device.isTouchScreen,
|
|
||||||
});
|
});
|
||||||
// deselect all other elements when inserting text
|
// deselect all other elements when inserting text
|
||||||
this.deselectElements();
|
this.deselectElements();
|
||||||
@@ -4514,6 +4464,84 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the pure geometric shape of an excalidraw element
|
||||||
|
* which is then used for hit detection
|
||||||
|
*/
|
||||||
|
public getElementShape(element: ExcalidrawElement): GeometricShape {
|
||||||
|
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,
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return shouldTestInside(element)
|
||||||
|
? getClosedCurveShape(
|
||||||
|
element,
|
||||||
|
roughShape,
|
||||||
|
[element.x, element.y],
|
||||||
|
element.angle,
|
||||||
|
[cx, cy],
|
||||||
|
)
|
||||||
|
: getCurveShape(roughShape, [element.x, element.y], element.angle, [
|
||||||
|
cx,
|
||||||
|
cy,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "ellipse":
|
||||||
|
return getEllipseShape(element);
|
||||||
|
|
||||||
|
case "freedraw": {
|
||||||
|
const [, , , , cx, cy] = getElementAbsoluteCoords(
|
||||||
|
element,
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
return getFreedrawShape(element, [cx, cy], shouldTestInside(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getBoundTextShape(element: ExcalidrawElement): GeometricShape | null {
|
||||||
|
const boundTextElement = getBoundTextElement(
|
||||||
|
element,
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (boundTextElement) {
|
||||||
|
if (element.type === "arrow") {
|
||||||
|
return this.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,
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.getElementShape(boundTextElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private getElementAtPosition(
|
private getElementAtPosition(
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
@@ -4547,10 +4575,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
element: elementWithHighestZIndex,
|
element: elementWithHighestZIndex,
|
||||||
shape: getElementShape(
|
shape: this.getElementShape(elementWithHighestZIndex),
|
||||||
elementWithHighestZIndex,
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
),
|
|
||||||
// when overlapping, we would like to be more precise
|
// when overlapping, we would like to be more precise
|
||||||
// this also avoids the need to update past tests
|
// this also avoids the need to update past tests
|
||||||
threshold: this.getElementHitThreshold() / 2,
|
threshold: this.getElementHitThreshold() / 2,
|
||||||
@@ -4645,7 +4670,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const hitBoundTextOfElement = hitElementBoundText(
|
const hitBoundTextOfElement = hitElementBoundText(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
getBoundTextShape(element, this.scene.getNonDeletedElementsMap()),
|
this.getBoundTextShape(element),
|
||||||
);
|
);
|
||||||
if (hitBoundTextOfElement) {
|
if (hitBoundTextOfElement) {
|
||||||
return true;
|
return true;
|
||||||
@@ -4655,7 +4680,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
element,
|
element,
|
||||||
shape: getElementShape(element, this.scene.getNonDeletedElementsMap()),
|
shape: this.getElementShape(element),
|
||||||
threshold: this.getElementHitThreshold(),
|
threshold: this.getElementHitThreshold(),
|
||||||
frameNameBound: isFrameLikeElement(element)
|
frameNameBound: isFrameLikeElement(element)
|
||||||
? this.frameNameBoundsCache.get(element)
|
? this.frameNameBoundsCache.get(element)
|
||||||
@@ -4687,10 +4712,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
element: elements[index],
|
element: elements[index],
|
||||||
shape: getElementShape(
|
shape: this.getElementShape(elements[index]),
|
||||||
elements[index],
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
),
|
|
||||||
threshold: this.getElementHitThreshold(),
|
threshold: this.getElementHitThreshold(),
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
@@ -4710,7 +4732,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
sceneY,
|
sceneY,
|
||||||
insertAtParentCenter = true,
|
insertAtParentCenter = true,
|
||||||
container,
|
container,
|
||||||
autoEdit = true,
|
|
||||||
}: {
|
}: {
|
||||||
/** X position to insert text at */
|
/** X position to insert text at */
|
||||||
sceneX: number;
|
sceneX: number;
|
||||||
@@ -4719,7 +4740,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
/** whether to attempt to insert at element center if applicable */
|
/** whether to attempt to insert at element center if applicable */
|
||||||
insertAtParentCenter?: boolean;
|
insertAtParentCenter?: boolean;
|
||||||
container?: ExcalidrawTextContainer | null;
|
container?: ExcalidrawTextContainer | null;
|
||||||
autoEdit?: boolean;
|
|
||||||
}) => {
|
}) => {
|
||||||
let shouldBindToContainer = false;
|
let shouldBindToContainer = false;
|
||||||
|
|
||||||
@@ -4763,7 +4783,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
existingTextElement?.fontFamily || this.state.currentItemFontFamily;
|
existingTextElement?.fontFamily || this.state.currentItemFontFamily;
|
||||||
|
|
||||||
const lineHeight =
|
const lineHeight =
|
||||||
existingTextElement?.lineHeight || getLineHeight(fontFamily);
|
existingTextElement?.lineHeight || getDefaultLineHeight(fontFamily);
|
||||||
const fontSize = this.state.currentItemFontSize;
|
const fontSize = this.state.currentItemFontSize;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -4852,16 +4872,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoEdit || existingTextElement || container) {
|
this.setState({
|
||||||
this.handleTextWysiwyg(element, {
|
editingElement: element,
|
||||||
isExistingElement: !!existingTextElement,
|
});
|
||||||
});
|
|
||||||
} else {
|
this.handleTextWysiwyg(element, {
|
||||||
this.setState({
|
isExistingElement: !!existingTextElement,
|
||||||
draggingElement: element,
|
});
|
||||||
multiElement: null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleCanvasDoubleClick = (
|
private handleCanvasDoubleClick = (
|
||||||
@@ -4948,10 +4965,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
x: sceneX,
|
x: sceneX,
|
||||||
y: sceneY,
|
y: sceneY,
|
||||||
element: container,
|
element: container,
|
||||||
shape: getElementShape(
|
shape: this.getElementShape(container),
|
||||||
container,
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
),
|
|
||||||
threshold: this.getElementHitThreshold(),
|
threshold: this.getElementHitThreshold(),
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
@@ -5643,10 +5657,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
x: scenePointerX,
|
x: scenePointerX,
|
||||||
y: scenePointerY,
|
y: scenePointerY,
|
||||||
element,
|
element,
|
||||||
shape: getElementShape(
|
shape: this.getElementShape(element),
|
||||||
element,
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
hoverPointIndex = LinearElementEditor.getPointIndexUnderCursor(
|
hoverPointIndex = LinearElementEditor.getPointIndexUnderCursor(
|
||||||
@@ -5902,6 +5913,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
if (this.state.activeTool.type === "text") {
|
if (this.state.activeTool.type === "text") {
|
||||||
this.handleTextOnPointerDown(event, pointerDownState);
|
this.handleTextOnPointerDown(event, pointerDownState);
|
||||||
|
return;
|
||||||
} else if (
|
} else if (
|
||||||
this.state.activeTool.type === "arrow" ||
|
this.state.activeTool.type === "arrow" ||
|
||||||
this.state.activeTool.type === "line"
|
this.state.activeTool.type === "line"
|
||||||
@@ -6022,7 +6034,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
const clicklength =
|
const clicklength =
|
||||||
event.timeStamp - (this.lastPointerDownEvent?.timeStamp ?? 0);
|
event.timeStamp - (this.lastPointerDownEvent?.timeStamp ?? 0);
|
||||||
|
|
||||||
if (this.device.editor.isMobile && clicklength < 300) {
|
if (this.device.editor.isMobile && clicklength < 300) {
|
||||||
const hitElement = this.getElementAtPosition(
|
const hitElement = this.getElementAtPosition(
|
||||||
scenePointer.x,
|
scenePointer.x,
|
||||||
@@ -6696,7 +6707,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
sceneY,
|
sceneY,
|
||||||
insertAtParentCenter: !event.altKey,
|
insertAtParentCenter: !event.altKey,
|
||||||
container,
|
container,
|
||||||
autoEdit: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
resetCursor(this.interactiveCanvas);
|
resetCursor(this.interactiveCanvas);
|
||||||
@@ -6765,7 +6775,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
const boundElement = getHoveredElementForBinding(
|
const boundElement = getHoveredElementForBinding(
|
||||||
pointerDownState.origin,
|
pointerDownState.origin,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
);
|
);
|
||||||
this.scene.insertElement(element);
|
this.scene.insertElement(element);
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -7027,7 +7037,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
});
|
});
|
||||||
const boundElement = getHoveredElementForBinding(
|
const boundElement = getHoveredElementForBinding(
|
||||||
pointerDownState.origin,
|
pointerDownState.origin,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scene.insertElement(element);
|
this.scene.insertElement(element);
|
||||||
@@ -7497,7 +7507,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
suggestedBindings: getSuggestedBindingsForArrows(
|
suggestedBindings: getSuggestedBindingsForArrows(
|
||||||
selectedElements,
|
selectedElements,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -8018,7 +8028,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
draggingElement,
|
draggingElement,
|
||||||
this.state,
|
this.state,
|
||||||
pointerCoords,
|
pointerCoords,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.setState({ suggestedBindings: [], startBoundElement: null });
|
this.setState({ suggestedBindings: [], startBoundElement: null });
|
||||||
@@ -8047,28 +8057,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTextElement(draggingElement)) {
|
|
||||||
const minWidth = getMinTextElementWidth(
|
|
||||||
getFontString({
|
|
||||||
fontSize: draggingElement.fontSize,
|
|
||||||
fontFamily: draggingElement.fontFamily,
|
|
||||||
}),
|
|
||||||
draggingElement.lineHeight,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (draggingElement.width < minWidth) {
|
|
||||||
mutateElement(draggingElement, {
|
|
||||||
autoResize: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resetCursor();
|
|
||||||
|
|
||||||
this.handleTextWysiwyg(draggingElement, {
|
|
||||||
isExistingElement: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
activeTool.type !== "selection" &&
|
activeTool.type !== "selection" &&
|
||||||
draggingElement &&
|
draggingElement &&
|
||||||
@@ -8508,10 +8496,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
x: pointerDownState.origin.x,
|
x: pointerDownState.origin.x,
|
||||||
y: pointerDownState.origin.y,
|
y: pointerDownState.origin.y,
|
||||||
element: hitElement,
|
element: hitElement,
|
||||||
shape: getElementShape(
|
shape: this.getElementShape(hitElement),
|
||||||
hitElement,
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
),
|
|
||||||
threshold: this.getElementHitThreshold(),
|
threshold: this.getElementHitThreshold(),
|
||||||
frameNameBound: isFrameLikeElement(hitElement)
|
frameNameBound: isFrameLikeElement(hitElement)
|
||||||
? this.frameNameBoundsCache.get(hitElement)
|
? this.frameNameBoundsCache.get(hitElement)
|
||||||
@@ -8579,7 +8564,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
bindOrUnbindLinearElements(
|
bindOrUnbindLinearElements(
|
||||||
linearElements,
|
linearElements,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
isBindingEnabled(this.state),
|
isBindingEnabled(this.state),
|
||||||
this.state.selectedLinearElement?.selectedPointsIndices ?? [],
|
this.state.selectedLinearElement?.selectedPointsIndices ?? [],
|
||||||
);
|
);
|
||||||
@@ -9067,7 +9052,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}): void => {
|
}): void => {
|
||||||
const hoveredBindableElement = getHoveredElementForBinding(
|
const hoveredBindableElement = getHoveredElementForBinding(
|
||||||
pointerCoords,
|
pointerCoords,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
);
|
);
|
||||||
this.setState({
|
this.setState({
|
||||||
suggestedBindings:
|
suggestedBindings:
|
||||||
@@ -9094,7 +9079,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
(acc: NonDeleted<ExcalidrawBindableElement>[], coords) => {
|
(acc: NonDeleted<ExcalidrawBindableElement>[], coords) => {
|
||||||
const hoveredBindableElement = getHoveredElementForBinding(
|
const hoveredBindableElement = getHoveredElementForBinding(
|
||||||
coords,
|
coords,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
hoveredBindableElement != null &&
|
hoveredBindableElement != null &&
|
||||||
@@ -9439,7 +9424,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
distance(pointerDownState.origin.y, pointerCoords.y),
|
distance(pointerDownState.origin.y, pointerCoords.y),
|
||||||
shouldMaintainAspectRatio(event),
|
shouldMaintainAspectRatio(event),
|
||||||
shouldResizeFromCenter(event),
|
shouldResizeFromCenter(event),
|
||||||
this.state.zoom.value,
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let [gridX, gridY] = getGridPoint(
|
let [gridX, gridY] = getGridPoint(
|
||||||
@@ -9497,7 +9481,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
? !shouldMaintainAspectRatio(event)
|
? !shouldMaintainAspectRatio(event)
|
||||||
: shouldMaintainAspectRatio(event),
|
: shouldMaintainAspectRatio(event),
|
||||||
shouldResizeFromCenter(event),
|
shouldResizeFromCenter(event),
|
||||||
this.state.zoom.value,
|
|
||||||
aspectRatio,
|
aspectRatio,
|
||||||
this.state.originSnapOffset,
|
this.state.originSnapOffset,
|
||||||
);
|
);
|
||||||
@@ -9626,7 +9609,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
) {
|
) {
|
||||||
const suggestedBindings = getSuggestedBindingsForArrows(
|
const suggestedBindings = getSuggestedBindingsForArrows(
|
||||||
selectedElements,
|
selectedElements,
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this,
|
||||||
);
|
);
|
||||||
|
|
||||||
const elementsToHighlight = new Set<ExcalidrawElement>();
|
const elementsToHighlight = new Set<ExcalidrawElement>();
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
@import "../css/theme";
|
|
||||||
|
|
||||||
.excalidraw {
|
|
||||||
button.standalone {
|
|
||||||
@include outlineButtonIconStyles;
|
|
||||||
|
|
||||||
& > * {
|
|
||||||
// dissalow pointer events on children, so we always have event.target on the button itself
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { forwardRef } from "react";
|
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
import "./ButtonIcon.scss";
|
|
||||||
|
|
||||||
interface ButtonIconProps {
|
|
||||||
icon: JSX.Element;
|
|
||||||
title: string;
|
|
||||||
className?: string;
|
|
||||||
testId?: string;
|
|
||||||
/** if not supplied, defaults to value identity check */
|
|
||||||
active?: boolean;
|
|
||||||
/** include standalone style (could interfere with parent styles) */
|
|
||||||
standalone?: boolean;
|
|
||||||
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ButtonIcon = forwardRef<HTMLButtonElement, ButtonIconProps>(
|
|
||||||
(props, ref) => {
|
|
||||||
const { title, className, testId, active, standalone, icon, onClick } =
|
|
||||||
props;
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
ref={ref}
|
|
||||||
key={title}
|
|
||||||
title={title}
|
|
||||||
data-testid={testId}
|
|
||||||
className={clsx(className, { standalone, active })}
|
|
||||||
onClick={onClick}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { ButtonIcon } from "./ButtonIcon";
|
|
||||||
|
|
||||||
// TODO: It might be "clever" to add option.icon to the existing component <ButtonSelect />
|
// TODO: It might be "clever" to add option.icon to the existing component <ButtonSelect />
|
||||||
export const ButtonIconSelect = <T extends Object>(
|
export const ButtonIconSelect = <T extends Object>(
|
||||||
@@ -25,17 +24,21 @@ export const ButtonIconSelect = <T extends Object>(
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
) => (
|
) => (
|
||||||
<div className="buttonList">
|
<div className="buttonList buttonListIcon">
|
||||||
{props.options.map((option) =>
|
{props.options.map((option) =>
|
||||||
props.type === "button" ? (
|
props.type === "button" ? (
|
||||||
<ButtonIcon
|
<button
|
||||||
|
type="button"
|
||||||
key={option.text}
|
key={option.text}
|
||||||
icon={option.icon}
|
|
||||||
title={option.text}
|
|
||||||
testId={option.testId}
|
|
||||||
active={option.active ?? props.value === option.value}
|
|
||||||
onClick={(event) => props.onClick(option.value, event)}
|
onClick={(event) => props.onClick(option.value, event)}
|
||||||
/>
|
className={clsx({
|
||||||
|
active: option.active ?? props.value === option.value,
|
||||||
|
})}
|
||||||
|
data-testid={option.testId}
|
||||||
|
title={option.text}
|
||||||
|
>
|
||||||
|
{option.icon}
|
||||||
|
</button>
|
||||||
) : (
|
) : (
|
||||||
<label
|
<label
|
||||||
key={option.text}
|
key={option.text}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
export const ButtonSeparator = () => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: 1,
|
|
||||||
height: "1rem",
|
|
||||||
backgroundColor: "var(--default-border-color)",
|
|
||||||
margin: "0 auto",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
@include isMobile {
|
@include isMobile {
|
||||||
max-width: 11rem;
|
max-width: 175px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
import { isTransparent } from "../../utils";
|
import { isInteractive, isTransparent, isWritableElement } from "../../utils";
|
||||||
import type { ExcalidrawElement } from "../../element/types";
|
import type { ExcalidrawElement } from "../../element/types";
|
||||||
import type { AppState } from "../../types";
|
import type { AppState } from "../../types";
|
||||||
import { TopPicks } from "./TopPicks";
|
import { TopPicks } from "./TopPicks";
|
||||||
import { ButtonSeparator } from "../ButtonSeparator";
|
|
||||||
import { Picker } from "./Picker";
|
import { Picker } from "./Picker";
|
||||||
import * as Popover from "@radix-ui/react-popover";
|
import * as Popover from "@radix-ui/react-popover";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import type { ColorPickerType } from "./colorPickerUtils";
|
import type { ColorPickerType } from "./colorPickerUtils";
|
||||||
import { activeColorPickerSectionAtom } from "./colorPickerUtils";
|
import { activeColorPickerSectionAtom } from "./colorPickerUtils";
|
||||||
import { useExcalidrawContainer } from "../App";
|
import { useDevice, useExcalidrawContainer } from "../App";
|
||||||
import type { ColorTuple, ColorPaletteCustom } from "../../colors";
|
import type { ColorTuple, ColorPaletteCustom } from "../../colors";
|
||||||
import { COLOR_PALETTE } from "../../colors";
|
import { COLOR_PALETTE } from "../../colors";
|
||||||
import PickerHeading from "./PickerHeading";
|
import PickerHeading from "./PickerHeading";
|
||||||
import { t } from "../../i18n";
|
import { t } from "../../i18n";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useRef } from "react";
|
|
||||||
import { jotaiScope } from "../../jotai";
|
import { jotaiScope } from "../../jotai";
|
||||||
import { ColorInput } from "./ColorInput";
|
import { ColorInput } from "./ColorInput";
|
||||||
|
import { useRef } from "react";
|
||||||
import { activeEyeDropperAtom } from "../EyeDropper";
|
import { activeEyeDropperAtom } from "../EyeDropper";
|
||||||
import { PropertiesPopover } from "../PropertiesPopover";
|
|
||||||
|
|
||||||
import "./ColorPicker.scss";
|
import "./ColorPicker.scss";
|
||||||
|
|
||||||
@@ -73,7 +71,6 @@ const ColorPickerPopupContent = ({
|
|||||||
| "palette"
|
| "palette"
|
||||||
| "updateData"
|
| "updateData"
|
||||||
>) => {
|
>) => {
|
||||||
const { container } = useExcalidrawContainer();
|
|
||||||
const [, setActiveColorPickerSection] = useAtom(activeColorPickerSectionAtom);
|
const [, setActiveColorPickerSection] = useAtom(activeColorPickerSectionAtom);
|
||||||
|
|
||||||
const [eyeDropperState, setEyeDropperState] = useAtom(
|
const [eyeDropperState, setEyeDropperState] = useAtom(
|
||||||
@@ -81,6 +78,9 @@ const ColorPickerPopupContent = ({
|
|||||||
jotaiScope,
|
jotaiScope,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { container } = useExcalidrawContainer();
|
||||||
|
const device = useDevice();
|
||||||
|
|
||||||
const colorInputJSX = (
|
const colorInputJSX = (
|
||||||
<div>
|
<div>
|
||||||
<PickerHeading>{t("colorPicker.hexCode")}</PickerHeading>
|
<PickerHeading>{t("colorPicker.hexCode")}</PickerHeading>
|
||||||
@@ -94,7 +94,6 @@ const ColorPickerPopupContent = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const popoverRef = useRef<HTMLDivElement>(null);
|
const popoverRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const focusPickerContent = () => {
|
const focusPickerContent = () => {
|
||||||
@@ -104,73 +103,120 @@ const ColorPickerPopupContent = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PropertiesPopover
|
<Popover.Portal container={container}>
|
||||||
container={container}
|
<Popover.Content
|
||||||
style={{ maxWidth: "208px" }}
|
ref={popoverRef}
|
||||||
onFocusOutside={(event) => {
|
className="focus-visible-none"
|
||||||
// refocus due to eye dropper
|
data-prevent-outside-click
|
||||||
focusPickerContent();
|
onFocusOutside={(event) => {
|
||||||
event.preventDefault();
|
focusPickerContent();
|
||||||
}}
|
|
||||||
onPointerDownOutside={(event) => {
|
|
||||||
if (eyeDropperState) {
|
|
||||||
// prevent from closing if we click outside the popover
|
|
||||||
// while eyedropping (e.g. click when clicking the sidebar;
|
|
||||||
// the eye-dropper-backdrop is prevented downstream)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}}
|
||||||
}}
|
onPointerDownOutside={(event) => {
|
||||||
onClose={() => {
|
if (eyeDropperState) {
|
||||||
updateData({ openPopup: null });
|
// prevent from closing if we click outside the popover
|
||||||
setActiveColorPickerSection(null);
|
// while eyedropping (e.g. click when clicking the sidebar;
|
||||||
}}
|
// the eye-dropper-backdrop is prevented downstream)
|
||||||
>
|
event.preventDefault();
|
||||||
{palette ? (
|
}
|
||||||
<Picker
|
}}
|
||||||
palette={palette}
|
onCloseAutoFocus={(e) => {
|
||||||
color={color}
|
e.stopPropagation();
|
||||||
onChange={(changedColor) => {
|
// prevents focusing the trigger
|
||||||
onChange(changedColor);
|
e.preventDefault();
|
||||||
}}
|
|
||||||
onEyeDropperToggle={(force) => {
|
|
||||||
setEyeDropperState((state) => {
|
|
||||||
if (force) {
|
|
||||||
state = state || {
|
|
||||||
keepOpenOnAlt: true,
|
|
||||||
onSelect: onChange,
|
|
||||||
colorPickerType: type,
|
|
||||||
};
|
|
||||||
state.keepOpenOnAlt = true;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
return force === false || state
|
// return focus to excalidraw container unless
|
||||||
? null
|
// user focuses an interactive element, such as a button, or
|
||||||
: {
|
// enters the text editor by clicking on canvas with the text tool
|
||||||
keepOpenOnAlt: false,
|
if (container && !isInteractive(document.activeElement)) {
|
||||||
|
container.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateData({ openPopup: null });
|
||||||
|
setActiveColorPickerSection(null);
|
||||||
|
}}
|
||||||
|
side={
|
||||||
|
device.editor.isMobile && !device.viewport.isLandscape
|
||||||
|
? "bottom"
|
||||||
|
: "right"
|
||||||
|
}
|
||||||
|
align={
|
||||||
|
device.editor.isMobile && !device.viewport.isLandscape
|
||||||
|
? "center"
|
||||||
|
: "start"
|
||||||
|
}
|
||||||
|
alignOffset={-16}
|
||||||
|
sideOffset={20}
|
||||||
|
style={{
|
||||||
|
zIndex: "var(--zIndex-layerUI)",
|
||||||
|
backgroundColor: "var(--popup-bg-color)",
|
||||||
|
maxWidth: "208px",
|
||||||
|
maxHeight: window.innerHeight,
|
||||||
|
padding: "12px",
|
||||||
|
borderRadius: "8px",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
overflowY: "auto",
|
||||||
|
boxShadow:
|
||||||
|
"0px 7px 14px rgba(0, 0, 0, 0.05), 0px 0px 3.12708px rgba(0, 0, 0, 0.0798), 0px 0px 0.931014px rgba(0, 0, 0, 0.1702)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{palette ? (
|
||||||
|
<Picker
|
||||||
|
palette={palette}
|
||||||
|
color={color}
|
||||||
|
onChange={(changedColor) => {
|
||||||
|
onChange(changedColor);
|
||||||
|
}}
|
||||||
|
onEyeDropperToggle={(force) => {
|
||||||
|
setEyeDropperState((state) => {
|
||||||
|
if (force) {
|
||||||
|
state = state || {
|
||||||
|
keepOpenOnAlt: true,
|
||||||
onSelect: onChange,
|
onSelect: onChange,
|
||||||
colorPickerType: type,
|
colorPickerType: type,
|
||||||
};
|
};
|
||||||
});
|
state.keepOpenOnAlt = true;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return force === false || state
|
||||||
|
? null
|
||||||
|
: {
|
||||||
|
keepOpenOnAlt: false,
|
||||||
|
onSelect: onChange,
|
||||||
|
colorPickerType: type,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
onEscape={(event) => {
|
||||||
|
if (eyeDropperState) {
|
||||||
|
setEyeDropperState(null);
|
||||||
|
} else if (isWritableElement(event.target)) {
|
||||||
|
focusPickerContent();
|
||||||
|
} else {
|
||||||
|
updateData({ openPopup: null });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
label={label}
|
||||||
|
type={type}
|
||||||
|
elements={elements}
|
||||||
|
updateData={updateData}
|
||||||
|
>
|
||||||
|
{colorInputJSX}
|
||||||
|
</Picker>
|
||||||
|
) : (
|
||||||
|
colorInputJSX
|
||||||
|
)}
|
||||||
|
<Popover.Arrow
|
||||||
|
width={20}
|
||||||
|
height={10}
|
||||||
|
style={{
|
||||||
|
fill: "var(--popup-bg-color)",
|
||||||
|
filter: "drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)",
|
||||||
}}
|
}}
|
||||||
onEscape={(event) => {
|
/>
|
||||||
if (eyeDropperState) {
|
</Popover.Content>
|
||||||
setEyeDropperState(null);
|
</Popover.Portal>
|
||||||
} else {
|
|
||||||
updateData({ openPopup: null });
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
label={label}
|
|
||||||
type={type}
|
|
||||||
elements={elements}
|
|
||||||
updateData={updateData}
|
|
||||||
>
|
|
||||||
{colorInputJSX}
|
|
||||||
</Picker>
|
|
||||||
) : (
|
|
||||||
colorInputJSX
|
|
||||||
)}
|
|
||||||
</PropertiesPopover>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -186,7 +232,7 @@ const ColorPickerTrigger = ({
|
|||||||
return (
|
return (
|
||||||
<Popover.Trigger
|
<Popover.Trigger
|
||||||
type="button"
|
type="button"
|
||||||
className={clsx("color-picker__button active-color properties-trigger", {
|
className={clsx("color-picker__button active-color", {
|
||||||
"is-transparent": color === "transparent" || !color,
|
"is-transparent": color === "transparent" || !color,
|
||||||
})}
|
})}
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
@@ -222,7 +268,14 @@ export const ColorPicker = ({
|
|||||||
type={type}
|
type={type}
|
||||||
topPicks={topPicks}
|
topPicks={topPicks}
|
||||||
/>
|
/>
|
||||||
<ButtonSeparator />
|
<div
|
||||||
|
style={{
|
||||||
|
width: 1,
|
||||||
|
height: "100%",
|
||||||
|
backgroundColor: "var(--default-border-color)",
|
||||||
|
margin: "0 auto",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Popover.Root
|
<Popover.Root
|
||||||
open={appState.openPopup === type}
|
open={appState.openPopup === type}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ export const Picker = ({
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className="color-picker-content properties-content"
|
className="color-picker-content"
|
||||||
// to allow focusing by clicking but not by tabbing
|
// to allow focusing by clicking but not by tabbing
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
@import "../../css/variables.module.scss";
|
|
||||||
|
|
||||||
.excalidraw {
|
|
||||||
.FontPicker__container {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: calc(1rem + 3 * var(--default-button-size)) 1rem 1fr; // calc ~ 2 gaps + 4 buttons
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
@include isMobile {
|
|
||||||
max-width: calc(
|
|
||||||
2rem + 4 * var(--default-button-size)
|
|
||||||
); // 4 gaps + 4 buttons
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
import React, { useCallback, useMemo } from "react";
|
|
||||||
import * as Popover from "@radix-ui/react-popover";
|
|
||||||
|
|
||||||
import { FontPickerList } from "./FontPickerList";
|
|
||||||
import { FontPickerTrigger } from "./FontPickerTrigger";
|
|
||||||
import { ButtonIconSelect } from "../ButtonIconSelect";
|
|
||||||
import {
|
|
||||||
FontFamilyCodeIcon,
|
|
||||||
FontFamilyNormalIcon,
|
|
||||||
FreedrawIcon,
|
|
||||||
} from "../icons";
|
|
||||||
import { ButtonSeparator } from "../ButtonSeparator";
|
|
||||||
import type { FontFamilyValues } from "../../element/types";
|
|
||||||
import { FONT_FAMILY } from "../../constants";
|
|
||||||
import { t } from "../../i18n";
|
|
||||||
|
|
||||||
import "./FontPicker.scss";
|
|
||||||
|
|
||||||
export const DEFAULT_FONTS = [
|
|
||||||
{
|
|
||||||
value: FONT_FAMILY.Excalifont,
|
|
||||||
icon: FreedrawIcon,
|
|
||||||
text: t("labels.handDrawn"),
|
|
||||||
testId: "font-family-handrawn",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: FONT_FAMILY.Nunito,
|
|
||||||
icon: FontFamilyNormalIcon,
|
|
||||||
text: t("labels.normal"),
|
|
||||||
testId: "font-family-normal",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: FONT_FAMILY["Comic Shanns"],
|
|
||||||
icon: FontFamilyCodeIcon,
|
|
||||||
text: t("labels.code"),
|
|
||||||
testId: "font-family-code",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const defaultFontFamilies = new Set(DEFAULT_FONTS.map((x) => x.value));
|
|
||||||
|
|
||||||
export const isDefaultFont = (fontFamily: number | null) => {
|
|
||||||
if (!fontFamily) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultFontFamilies.has(fontFamily);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface FontPickerProps {
|
|
||||||
isOpened: boolean;
|
|
||||||
selectedFontFamily: FontFamilyValues | null;
|
|
||||||
hoveredFontFamily: FontFamilyValues | null;
|
|
||||||
onSelect: (fontFamily: FontFamilyValues) => void;
|
|
||||||
onHover: (fontFamily: FontFamilyValues) => void;
|
|
||||||
onLeave: () => void;
|
|
||||||
onPopupChange: (open: boolean) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FontPicker = React.memo(
|
|
||||||
({
|
|
||||||
isOpened,
|
|
||||||
selectedFontFamily,
|
|
||||||
hoveredFontFamily,
|
|
||||||
onSelect,
|
|
||||||
onHover,
|
|
||||||
onLeave,
|
|
||||||
onPopupChange,
|
|
||||||
}: FontPickerProps) => {
|
|
||||||
const defaultFonts = useMemo(() => DEFAULT_FONTS, []);
|
|
||||||
const onSelectCallback = useCallback(
|
|
||||||
(value: number | false) => {
|
|
||||||
if (value) {
|
|
||||||
onSelect(value);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[onSelect],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div role="dialog" aria-modal="true" className="FontPicker__container">
|
|
||||||
<ButtonIconSelect<FontFamilyValues | false>
|
|
||||||
type="button"
|
|
||||||
options={defaultFonts}
|
|
||||||
value={selectedFontFamily}
|
|
||||||
onClick={onSelectCallback}
|
|
||||||
/>
|
|
||||||
<ButtonSeparator />
|
|
||||||
<Popover.Root open={isOpened} onOpenChange={onPopupChange}>
|
|
||||||
<FontPickerTrigger selectedFontFamily={selectedFontFamily} />
|
|
||||||
{isOpened && (
|
|
||||||
<FontPickerList
|
|
||||||
selectedFontFamily={selectedFontFamily}
|
|
||||||
hoveredFontFamily={hoveredFontFamily}
|
|
||||||
onSelect={onSelectCallback}
|
|
||||||
onHover={onHover}
|
|
||||||
onLeave={onLeave}
|
|
||||||
onOpen={() => onPopupChange(true)}
|
|
||||||
onClose={() => onPopupChange(false)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Popover.Root>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
(prev, next) =>
|
|
||||||
prev.isOpened === next.isOpened &&
|
|
||||||
prev.selectedFontFamily === next.selectedFontFamily &&
|
|
||||||
prev.hoveredFontFamily === next.hoveredFontFamily,
|
|
||||||
);
|
|
||||||
@@ -1,268 +0,0 @@
|
|||||||
import React, {
|
|
||||||
useMemo,
|
|
||||||
useState,
|
|
||||||
useRef,
|
|
||||||
useEffect,
|
|
||||||
useCallback,
|
|
||||||
type KeyboardEventHandler,
|
|
||||||
} from "react";
|
|
||||||
import { useApp, useAppProps, useExcalidrawContainer } from "../App";
|
|
||||||
import { PropertiesPopover } from "../PropertiesPopover";
|
|
||||||
import { QuickSearch } from "../QuickSearch";
|
|
||||||
import { ScrollableList } from "../ScrollableList";
|
|
||||||
import DropdownMenuGroup from "../dropdownMenu/DropdownMenuGroup";
|
|
||||||
import DropdownMenuItem, {
|
|
||||||
DropDownMenuItemBadgeType,
|
|
||||||
DropDownMenuItemBadge,
|
|
||||||
} from "../dropdownMenu/DropdownMenuItem";
|
|
||||||
import { type FontFamilyValues } from "../../element/types";
|
|
||||||
import { arrayToList, debounce, getFontFamilyString } from "../../utils";
|
|
||||||
import { t } from "../../i18n";
|
|
||||||
import { fontPickerKeyHandler } from "./keyboardNavHandlers";
|
|
||||||
import { Fonts } from "../../fonts";
|
|
||||||
import type { ValueOf } from "../../utility-types";
|
|
||||||
|
|
||||||
export interface FontDescriptor {
|
|
||||||
value: number;
|
|
||||||
icon: JSX.Element;
|
|
||||||
text: string;
|
|
||||||
deprecated?: true;
|
|
||||||
badge?: {
|
|
||||||
type: ValueOf<typeof DropDownMenuItemBadgeType>;
|
|
||||||
placeholder: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FontPickerListProps {
|
|
||||||
selectedFontFamily: FontFamilyValues | null;
|
|
||||||
hoveredFontFamily: FontFamilyValues | null;
|
|
||||||
onSelect: (value: number) => void;
|
|
||||||
onHover: (value: number) => void;
|
|
||||||
onLeave: () => void;
|
|
||||||
onOpen: () => void;
|
|
||||||
onClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FontPickerList = React.memo(
|
|
||||||
({
|
|
||||||
selectedFontFamily,
|
|
||||||
hoveredFontFamily,
|
|
||||||
onSelect,
|
|
||||||
onHover,
|
|
||||||
onLeave,
|
|
||||||
onOpen,
|
|
||||||
onClose,
|
|
||||||
}: FontPickerListProps) => {
|
|
||||||
const { container } = useExcalidrawContainer();
|
|
||||||
const { fonts } = useApp();
|
|
||||||
const { showDeprecatedFonts } = useAppProps();
|
|
||||||
|
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
|
||||||
const allFonts = useMemo(
|
|
||||||
() =>
|
|
||||||
Array.from(Fonts.registered.entries())
|
|
||||||
.filter(([_, { metadata }]) => !metadata.serverSide)
|
|
||||||
.map(([familyId, { metadata, fontFaces }]) => {
|
|
||||||
const font = {
|
|
||||||
value: familyId,
|
|
||||||
icon: metadata.icon,
|
|
||||||
text: fontFaces[0].fontFace.family,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (metadata.deprecated) {
|
|
||||||
Object.assign(font, {
|
|
||||||
deprecated: metadata.deprecated,
|
|
||||||
badge: {
|
|
||||||
type: DropDownMenuItemBadgeType.RED,
|
|
||||||
placeholder: t("fontList.badge.old"),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return font as FontDescriptor;
|
|
||||||
})
|
|
||||||
.sort((a, b) =>
|
|
||||||
a.text.toLowerCase() > b.text.toLowerCase() ? 1 : -1,
|
|
||||||
),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const sceneFamilies = useMemo(
|
|
||||||
() => new Set(fonts.sceneFamilies),
|
|
||||||
// cache per selected font family, so hover re-render won't mess it up
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
[selectedFontFamily],
|
|
||||||
);
|
|
||||||
|
|
||||||
const sceneFonts = useMemo(
|
|
||||||
() => allFonts.filter((font) => sceneFamilies.has(font.value)), // always show all the fonts in the scene, even those that were deprecated
|
|
||||||
[allFonts, sceneFamilies],
|
|
||||||
);
|
|
||||||
|
|
||||||
const availableFonts = useMemo(
|
|
||||||
() =>
|
|
||||||
allFonts.filter(
|
|
||||||
(font) =>
|
|
||||||
!sceneFamilies.has(font.value) &&
|
|
||||||
(showDeprecatedFonts || !font.deprecated), // skip deprecated fonts
|
|
||||||
),
|
|
||||||
[allFonts, sceneFamilies, showDeprecatedFonts],
|
|
||||||
);
|
|
||||||
|
|
||||||
const filteredFonts = useMemo(
|
|
||||||
() =>
|
|
||||||
arrayToList(
|
|
||||||
[...sceneFonts, ...availableFonts].filter((font) =>
|
|
||||||
font.text?.toLowerCase().includes(searchTerm),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
[sceneFonts, availableFonts, searchTerm],
|
|
||||||
);
|
|
||||||
|
|
||||||
const hoveredFont = useMemo(() => {
|
|
||||||
let font;
|
|
||||||
|
|
||||||
if (hoveredFontFamily) {
|
|
||||||
font = filteredFonts.find((font) => font.value === hoveredFontFamily);
|
|
||||||
} else if (selectedFontFamily) {
|
|
||||||
font = filteredFonts.find((font) => font.value === selectedFontFamily);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!font && searchTerm) {
|
|
||||||
if (filteredFonts[0]?.value) {
|
|
||||||
// hover first element on search
|
|
||||||
onHover(filteredFonts[0].value);
|
|
||||||
} else {
|
|
||||||
// re-render cache on no results
|
|
||||||
onLeave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return font;
|
|
||||||
}, [
|
|
||||||
hoveredFontFamily,
|
|
||||||
selectedFontFamily,
|
|
||||||
searchTerm,
|
|
||||||
filteredFonts,
|
|
||||||
onHover,
|
|
||||||
onLeave,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const onKeyDown = useCallback<KeyboardEventHandler<HTMLDivElement>>(
|
|
||||||
(event) => {
|
|
||||||
const handled = fontPickerKeyHandler({
|
|
||||||
event,
|
|
||||||
inputRef,
|
|
||||||
hoveredFont,
|
|
||||||
filteredFonts,
|
|
||||||
onSelect,
|
|
||||||
onHover,
|
|
||||||
onClose,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (handled) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[hoveredFont, filteredFonts, onSelect, onHover, onClose],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
onOpen();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const sceneFilteredFonts = useMemo(
|
|
||||||
() => filteredFonts.filter((font) => sceneFamilies.has(font.value)),
|
|
||||||
[filteredFonts, sceneFamilies],
|
|
||||||
);
|
|
||||||
|
|
||||||
const availableFilteredFonts = useMemo(
|
|
||||||
() => filteredFonts.filter((font) => !sceneFamilies.has(font.value)),
|
|
||||||
[filteredFonts, sceneFamilies],
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderFont = (font: FontDescriptor, index: number) => (
|
|
||||||
<DropdownMenuItem
|
|
||||||
key={font.value}
|
|
||||||
icon={font.icon}
|
|
||||||
value={font.value}
|
|
||||||
order={index}
|
|
||||||
textStyle={{
|
|
||||||
fontFamily: getFontFamilyString({ fontFamily: font.value }),
|
|
||||||
}}
|
|
||||||
hovered={font.value === hoveredFont?.value}
|
|
||||||
selected={font.value === selectedFontFamily}
|
|
||||||
// allow to tab between search and selected font
|
|
||||||
tabIndex={font.value === selectedFontFamily ? 0 : -1}
|
|
||||||
onClick={(e) => {
|
|
||||||
onSelect(Number(e.currentTarget.value));
|
|
||||||
}}
|
|
||||||
onMouseMove={() => {
|
|
||||||
if (hoveredFont?.value !== font.value) {
|
|
||||||
onHover(font.value);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{font.text}
|
|
||||||
{font.badge && (
|
|
||||||
<DropDownMenuItemBadge type={font.badge.type}>
|
|
||||||
{font.badge.placeholder}
|
|
||||||
</DropDownMenuItemBadge>
|
|
||||||
)}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
|
|
||||||
const groups = [];
|
|
||||||
|
|
||||||
if (sceneFilteredFonts.length) {
|
|
||||||
groups.push(
|
|
||||||
<DropdownMenuGroup title={t("fontList.sceneFonts")} key="group_1">
|
|
||||||
{sceneFilteredFonts.map(renderFont)}
|
|
||||||
</DropdownMenuGroup>,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (availableFilteredFonts.length) {
|
|
||||||
groups.push(
|
|
||||||
<DropdownMenuGroup title={t("fontList.availableFonts")} key="group_2">
|
|
||||||
{availableFilteredFonts.map((font, index) =>
|
|
||||||
renderFont(font, index + sceneFilteredFonts.length),
|
|
||||||
)}
|
|
||||||
</DropdownMenuGroup>,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PropertiesPopover
|
|
||||||
className="properties-content"
|
|
||||||
container={container}
|
|
||||||
style={{ width: "15rem" }}
|
|
||||||
onClose={onClose}
|
|
||||||
onPointerLeave={onLeave}
|
|
||||||
onKeyDown={onKeyDown}
|
|
||||||
>
|
|
||||||
<QuickSearch
|
|
||||||
ref={inputRef}
|
|
||||||
placeholder={t("quickSearch.placeholder")}
|
|
||||||
onChange={debounce(setSearchTerm, 20)}
|
|
||||||
/>
|
|
||||||
<ScrollableList
|
|
||||||
className="dropdown-menu fonts manual-hover"
|
|
||||||
placeholder={t("fontList.empty")}
|
|
||||||
>
|
|
||||||
{groups.length ? groups : null}
|
|
||||||
</ScrollableList>
|
|
||||||
</PropertiesPopover>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
(prev, next) =>
|
|
||||||
prev.selectedFontFamily === next.selectedFontFamily &&
|
|
||||||
prev.hoveredFontFamily === next.hoveredFontFamily,
|
|
||||||
);
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
|
||||||
import { useMemo } from "react";
|
|
||||||
import { ButtonIcon } from "../ButtonIcon";
|
|
||||||
import { TextIcon } from "../icons";
|
|
||||||
import type { FontFamilyValues } from "../../element/types";
|
|
||||||
import { t } from "../../i18n";
|
|
||||||
import { isDefaultFont } from "./FontPicker";
|
|
||||||
|
|
||||||
interface FontPickerTriggerProps {
|
|
||||||
selectedFontFamily: FontFamilyValues | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FontPickerTrigger = ({
|
|
||||||
selectedFontFamily,
|
|
||||||
}: FontPickerTriggerProps) => {
|
|
||||||
const isTriggerActive = useMemo(
|
|
||||||
() => Boolean(selectedFontFamily && !isDefaultFont(selectedFontFamily)),
|
|
||||||
[selectedFontFamily],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Popover.Trigger asChild>
|
|
||||||
{/* Empty div as trigger so it's stretched 100% due to different button sizes */}
|
|
||||||
<div>
|
|
||||||
<ButtonIcon
|
|
||||||
standalone
|
|
||||||
icon={TextIcon}
|
|
||||||
title={t("labels.showFonts")}
|
|
||||||
className="properties-trigger"
|
|
||||||
testId={"font-family-show-fonts"}
|
|
||||||
active={isTriggerActive}
|
|
||||||
// no-op
|
|
||||||
onClick={() => {}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Popover.Trigger>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import type { Node } from "../../utils";
|
|
||||||
import { KEYS } from "../../keys";
|
|
||||||
import { type FontDescriptor } from "./FontPickerList";
|
|
||||||
|
|
||||||
interface FontPickerKeyNavHandlerProps {
|
|
||||||
event: React.KeyboardEvent<HTMLDivElement>;
|
|
||||||
inputRef: React.RefObject<HTMLInputElement>;
|
|
||||||
hoveredFont: Node<FontDescriptor> | undefined;
|
|
||||||
filteredFonts: Node<FontDescriptor>[];
|
|
||||||
onClose: () => void;
|
|
||||||
onSelect: (value: number) => void;
|
|
||||||
onHover: (value: number) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const fontPickerKeyHandler = ({
|
|
||||||
event,
|
|
||||||
inputRef,
|
|
||||||
hoveredFont,
|
|
||||||
filteredFonts,
|
|
||||||
onClose,
|
|
||||||
onSelect,
|
|
||||||
onHover,
|
|
||||||
}: FontPickerKeyNavHandlerProps) => {
|
|
||||||
if (
|
|
||||||
!event[KEYS.CTRL_OR_CMD] &&
|
|
||||||
event.shiftKey &&
|
|
||||||
event.key.toLowerCase() === KEYS.F
|
|
||||||
) {
|
|
||||||
// refocus input on the popup trigger shortcut
|
|
||||||
inputRef.current?.focus();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === KEYS.ESCAPE) {
|
|
||||||
onClose();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === KEYS.ENTER) {
|
|
||||||
if (hoveredFont?.value) {
|
|
||||||
onSelect(hoveredFont.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === KEYS.ARROW_DOWN) {
|
|
||||||
if (hoveredFont?.next) {
|
|
||||||
onHover(hoveredFont.next.value);
|
|
||||||
} else if (filteredFonts[0]?.value) {
|
|
||||||
onHover(filteredFonts[0].value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.key === KEYS.ARROW_UP) {
|
|
||||||
if (hoveredFont?.prev) {
|
|
||||||
onHover(hoveredFont.prev.value);
|
|
||||||
} else if (filteredFonts[filteredFonts.length - 1]?.value) {
|
|
||||||
onHover(filteredFonts[filteredFonts.length - 1].value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
margin: 1.5rem 0;
|
margin: 1.5rem 0;
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
font-size: 1.125rem;
|
font-size: 1.125rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
&__island {
|
&__island {
|
||||||
h4 {
|
h4 {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
margin-bottom: 0.625rem;
|
margin-bottom: 0.625rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
|||||||
shortcuts={[getShortcutKey("Alt+Shift+D")]}
|
shortcuts={[getShortcutKey("Alt+Shift+D")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("stats.fullTitle")}
|
label={t("stats.title")}
|
||||||
shortcuts={[getShortcutKey("Alt+/")]}
|
shortcuts={[getShortcutKey("Alt+/")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
@@ -458,10 +458,6 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
|||||||
label={t("labels.showBackground")}
|
label={t("labels.showBackground")}
|
||||||
shortcuts={[getShortcutKey("G")]}
|
shortcuts={[getShortcutKey("G")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
|
||||||
label={t("labels.showFonts")}
|
|
||||||
shortcuts={[getShortcutKey("Shift+F")]}
|
|
||||||
/>
|
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.decreaseFontSize")}
|
label={t("labels.decreaseFontSize")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+<")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+<")]}
|
||||||
|
|||||||
@@ -27,99 +27,6 @@
|
|||||||
& > * {
|
& > * {
|
||||||
pointer-events: var(--ui-pointerEvents);
|
pointer-events: var(--ui-pointerEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
& > .Stats {
|
|
||||||
width: 204px;
|
|
||||||
position: absolute;
|
|
||||||
top: 60px;
|
|
||||||
font-size: 12px;
|
|
||||||
z-index: var(--zIndex-layerUI);
|
|
||||||
pointer-events: var(--ui-pointerEvents);
|
|
||||||
|
|
||||||
.title {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 12px;
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.sectionContent {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.elementType {
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: 700;
|
|
||||||
margin-top: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.elementsCount {
|
|
||||||
width: 100%;
|
|
||||||
font-size: 12px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-top: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.statsItem {
|
|
||||||
margin-top: 8px;
|
|
||||||
width: 100%;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
display: grid;
|
|
||||||
gap: 4px;
|
|
||||||
|
|
||||||
.label {
|
|
||||||
margin-right: 4px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
white-space: nowrap;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.close {
|
|
||||||
height: 16px;
|
|
||||||
width: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
svg {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
width: 100%;
|
|
||||||
th {
|
|
||||||
border-bottom: 1px solid var(--input-border-color);
|
|
||||||
padding: 4px;
|
|
||||||
}
|
|
||||||
tr {
|
|
||||||
td:nth-child(2) {
|
|
||||||
min-width: 24px;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.divider {
|
|
||||||
width: 100%;
|
|
||||||
height: 1px;
|
|
||||||
background-color: var(--default-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
left: 12px;
|
|
||||||
right: initial;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__footer {
|
&__footer {
|
||||||
|
|||||||
@@ -62,8 +62,6 @@ import Scene from "../scene/Scene";
|
|||||||
import { LaserPointerButton } from "./LaserPointerButton";
|
import { LaserPointerButton } from "./LaserPointerButton";
|
||||||
import { MagicSettings } from "./MagicSettings";
|
import { MagicSettings } from "./MagicSettings";
|
||||||
import { TTDDialog } from "./TTDDialog/TTDDialog";
|
import { TTDDialog } from "./TTDDialog/TTDDialog";
|
||||||
import { Stats } from "./Stats";
|
|
||||||
import { actionToggleStats } from "../actions";
|
|
||||||
|
|
||||||
interface LayerUIProps {
|
interface LayerUIProps {
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
@@ -241,11 +239,6 @@ const LayerUI = ({
|
|||||||
elements,
|
elements,
|
||||||
);
|
);
|
||||||
|
|
||||||
const shouldShowStats =
|
|
||||||
appState.stats.open &&
|
|
||||||
!appState.zenModeEnabled &&
|
|
||||||
!appState.viewModeEnabled;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FixedSideContainer side="top">
|
<FixedSideContainer side="top">
|
||||||
<div className="App-menu App-menu_top">
|
<div className="App-menu App-menu_top">
|
||||||
@@ -358,15 +351,6 @@ const LayerUI = ({
|
|||||||
appState.openSidebar?.name !== DEFAULT_SIDEBAR.name) && (
|
appState.openSidebar?.name !== DEFAULT_SIDEBAR.name) && (
|
||||||
<tunnels.DefaultSidebarTriggerTunnel.Out />
|
<tunnels.DefaultSidebarTriggerTunnel.Out />
|
||||||
)}
|
)}
|
||||||
{shouldShowStats && (
|
|
||||||
<Stats
|
|
||||||
scene={app.scene}
|
|
||||||
onClose={() => {
|
|
||||||
actionManager.executeAction(actionToggleStats);
|
|
||||||
}}
|
|
||||||
renderCustomStats={renderCustomStats}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</FixedSideContainer>
|
</FixedSideContainer>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
.library-actions-counter {
|
.library-actions-counter {
|
||||||
background-color: var(--color-primary);
|
background-color: var(--color-primary);
|
||||||
color: var(--color-primary-light);
|
color: var(--color-primary-light);
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
&__label {
|
&__label {
|
||||||
color: var(--color-primary);
|
color: var(--color-primary);
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
font-size: 1.125rem;
|
font-size: 1.125rem;
|
||||||
margin-bottom: 0.75rem;
|
margin-bottom: 0.75rem;
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
&__header {
|
&__header {
|
||||||
color: var(--color-primary);
|
color: var(--color-primary);
|
||||||
font-size: 1.125rem;
|
font-size: 1.125rem;
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
margin-bottom: 0.75rem;
|
margin-bottom: 0.75rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding-right: 4rem; // due to dropdown button
|
padding-right: 4rem; // due to dropdown button
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
import React, { type ReactNode } from "react";
|
|
||||||
import clsx from "clsx";
|
|
||||||
import * as Popover from "@radix-ui/react-popover";
|
|
||||||
|
|
||||||
import { useDevice } from "./App";
|
|
||||||
import { Island } from "./Island";
|
|
||||||
import { isInteractive } from "../utils";
|
|
||||||
|
|
||||||
interface PropertiesPopoverProps {
|
|
||||||
className?: string;
|
|
||||||
container: HTMLDivElement | null;
|
|
||||||
children: ReactNode;
|
|
||||||
style?: object;
|
|
||||||
onClose: () => void;
|
|
||||||
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
|
|
||||||
onPointerLeave?: React.PointerEventHandler<HTMLDivElement>;
|
|
||||||
onFocusOutside?: Popover.DismissableLayerProps["onFocusOutside"];
|
|
||||||
onPointerDownOutside?: Popover.DismissableLayerProps["onPointerDownOutside"];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PropertiesPopover = React.forwardRef<
|
|
||||||
HTMLDivElement,
|
|
||||||
PropertiesPopoverProps
|
|
||||||
>(
|
|
||||||
(
|
|
||||||
{
|
|
||||||
className,
|
|
||||||
container,
|
|
||||||
children,
|
|
||||||
style,
|
|
||||||
onClose,
|
|
||||||
onKeyDown,
|
|
||||||
onFocusOutside,
|
|
||||||
onPointerLeave,
|
|
||||||
onPointerDownOutside,
|
|
||||||
},
|
|
||||||
ref,
|
|
||||||
) => {
|
|
||||||
const device = useDevice();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Popover.Portal container={container}>
|
|
||||||
<Popover.Content
|
|
||||||
ref={ref}
|
|
||||||
className={clsx("focus-visible-none", className)}
|
|
||||||
data-prevent-outside-click
|
|
||||||
side={
|
|
||||||
device.editor.isMobile && !device.viewport.isLandscape
|
|
||||||
? "bottom"
|
|
||||||
: "right"
|
|
||||||
}
|
|
||||||
align={
|
|
||||||
device.editor.isMobile && !device.viewport.isLandscape
|
|
||||||
? "center"
|
|
||||||
: "start"
|
|
||||||
}
|
|
||||||
alignOffset={-16}
|
|
||||||
sideOffset={20}
|
|
||||||
style={{
|
|
||||||
zIndex: "var(--zIndex-popup)",
|
|
||||||
}}
|
|
||||||
onPointerLeave={onPointerLeave}
|
|
||||||
onKeyDown={onKeyDown}
|
|
||||||
onFocusOutside={onFocusOutside}
|
|
||||||
onPointerDownOutside={onPointerDownOutside}
|
|
||||||
onCloseAutoFocus={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
// prevents focusing the trigger
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
// return focus to excalidraw container unless
|
|
||||||
// user focuses an interactive element, such as a button, or
|
|
||||||
// enters the text editor by clicking on canvas with the text tool
|
|
||||||
if (container && !isInteractive(document.activeElement)) {
|
|
||||||
container.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Island padding={3} style={style}>
|
|
||||||
{children}
|
|
||||||
</Island>
|
|
||||||
<Popover.Arrow
|
|
||||||
width={20}
|
|
||||||
height={10}
|
|
||||||
style={{
|
|
||||||
fill: "var(--popup-bg-color)",
|
|
||||||
filter: "drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Popover.Content>
|
|
||||||
</Popover.Portal>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -133,7 +133,7 @@
|
|||||||
.required,
|
.required,
|
||||||
.error {
|
.error {
|
||||||
color: $oc-red-8;
|
color: $oc-red-8;
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
margin: 0.2rem;
|
margin: 0.2rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
.excalidraw {
|
|
||||||
--list-border-color: var(--color-gray-20);
|
|
||||||
|
|
||||||
.QuickSearch__wrapper {
|
|
||||||
position: relative;
|
|
||||||
height: 2.6rem; // added +0.1 due to Safari
|
|
||||||
border-bottom: 1px solid var(--list-border-color);
|
|
||||||
|
|
||||||
svg {
|
|
||||||
position: absolute;
|
|
||||||
top: 47.5%; // 50% is not exactly in the center of the input
|
|
||||||
transform: translateY(-50%);
|
|
||||||
left: 0.75rem;
|
|
||||||
width: 1.25rem;
|
|
||||||
height: 1.25rem;
|
|
||||||
color: var(--color-gray-40);
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
--list-border-color: var(--color-gray-80);
|
|
||||||
|
|
||||||
.QuickSearch__wrapper {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.QuickSearch__input {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
border: 0 !important;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
padding-left: 2.5rem !important;
|
|
||||||
padding-right: 0.75rem !important;
|
|
||||||
|
|
||||||
&::placeholder {
|
|
||||||
color: var(--color-gray-40);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
box-shadow: none !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import React from "react";
|
|
||||||
import { searchIcon } from "./icons";
|
|
||||||
|
|
||||||
import "./QuickSearch.scss";
|
|
||||||
|
|
||||||
interface QuickSearchProps {
|
|
||||||
className?: string;
|
|
||||||
placeholder: string;
|
|
||||||
onChange: (term: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const QuickSearch = React.forwardRef<HTMLInputElement, QuickSearchProps>(
|
|
||||||
({ className, placeholder, onChange }, ref) => {
|
|
||||||
return (
|
|
||||||
<div className={clsx("QuickSearch__wrapper", className)}>
|
|
||||||
{searchIcon}
|
|
||||||
<input
|
|
||||||
ref={ref}
|
|
||||||
className="QuickSearch__input"
|
|
||||||
type="text"
|
|
||||||
placeholder={placeholder}
|
|
||||||
onChange={(e) => onChange(e.target.value.trim().toLowerCase())}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
.excalidraw {
|
|
||||||
.ScrollableList__wrapper {
|
|
||||||
position: static !important;
|
|
||||||
border: none;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
overflow-y: auto;
|
|
||||||
|
|
||||||
& > .empty,
|
|
||||||
& > .hint {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0.5rem;
|
|
||||||
font-size: 0.75rem;
|
|
||||||
color: var(--color-gray-60);
|
|
||||||
overflow: hidden;
|
|
||||||
text-align: center;
|
|
||||||
line-height: 150%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import { Children } from "react";
|
|
||||||
|
|
||||||
import "./ScrollableList.scss";
|
|
||||||
|
|
||||||
interface ScrollableListProps {
|
|
||||||
className?: string;
|
|
||||||
placeholder: string;
|
|
||||||
children: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ScrollableList = ({
|
|
||||||
className,
|
|
||||||
placeholder,
|
|
||||||
children,
|
|
||||||
}: ScrollableListProps) => {
|
|
||||||
const isEmpty = !Children.count(children);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={clsx("ScrollableList__wrapper", className)} role="menu">
|
|
||||||
{isEmpty ? <div className="empty">{placeholder}</div> : children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,91 +1,73 @@
|
|||||||
import { mutateElement } from "../../element/mutateElement";
|
import { mutateElement } from "../../element/mutateElement";
|
||||||
import { getBoundTextElement } from "../../element/textElement";
|
import { getBoundTextElement } from "../../element/textElement";
|
||||||
import { isArrowElement } from "../../element/typeChecks";
|
import { isArrowElement } from "../../element/typeChecks";
|
||||||
import type { ExcalidrawElement } from "../../element/types";
|
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
||||||
import { degreeToRadian, radianToDegree } from "../../math";
|
import { degreeToRadian, radianToDegree } from "../../math";
|
||||||
import { angleIcon } from "../icons";
|
|
||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
import type { DragInputCallbackType } from "./DragInput";
|
||||||
import { getStepSizedValue, isPropertyEditable, updateBindings } from "./utils";
|
import { getStepSizedValue, isPropertyEditable } from "./utils";
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import type { AppState } from "../../types";
|
|
||||||
|
|
||||||
interface AngleProps {
|
interface AngleProps {
|
||||||
element: ExcalidrawElement;
|
element: ExcalidrawElement;
|
||||||
scene: Scene;
|
elementsMap: ElementsMap;
|
||||||
appState: AppState;
|
|
||||||
property: "angle";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const STEP_SIZE = 15;
|
const STEP_SIZE = 15;
|
||||||
|
|
||||||
const handleDegreeChange: DragInputCallbackType<AngleProps["property"]> = ({
|
const Angle = ({ element, elementsMap }: AngleProps) => {
|
||||||
accumulatedChange,
|
const handleDegreeChange: DragInputCallbackType = ({
|
||||||
originalElements,
|
accumulatedChange,
|
||||||
shouldChangeByStepSize,
|
stateAtStart,
|
||||||
nextValue,
|
shouldChangeByStepSize,
|
||||||
scene,
|
nextValue,
|
||||||
}) => {
|
}) => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const _stateAtStart = stateAtStart[0];
|
||||||
const origElement = originalElements[0];
|
if (_stateAtStart) {
|
||||||
if (origElement) {
|
if (nextValue !== undefined) {
|
||||||
const latestElement = elementsMap.get(origElement.id);
|
const nextAngle = degreeToRadian(nextValue);
|
||||||
if (!latestElement) {
|
mutateElement(element, {
|
||||||
return;
|
angle: nextAngle,
|
||||||
}
|
});
|
||||||
|
|
||||||
if (nextValue !== undefined) {
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
||||||
const nextAngle = degreeToRadian(nextValue);
|
if (boundTextElement && !isArrowElement(element)) {
|
||||||
mutateElement(latestElement, {
|
mutateElement(boundTextElement, { angle: nextAngle });
|
||||||
angle: nextAngle,
|
}
|
||||||
});
|
|
||||||
updateBindings(latestElement, elementsMap);
|
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
return;
|
||||||
if (boundTextElement && !isArrowElement(latestElement)) {
|
|
||||||
mutateElement(boundTextElement, { angle: nextAngle });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
const originalAngleInDegrees =
|
||||||
|
Math.round(radianToDegree(_stateAtStart.angle) * 100) / 100;
|
||||||
|
const changeInDegrees = Math.round(accumulatedChange);
|
||||||
|
let nextAngleInDegrees = (originalAngleInDegrees + changeInDegrees) % 360;
|
||||||
|
if (shouldChangeByStepSize) {
|
||||||
|
nextAngleInDegrees = getStepSizedValue(nextAngleInDegrees, STEP_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
nextAngleInDegrees =
|
||||||
|
nextAngleInDegrees < 0 ? nextAngleInDegrees + 360 : nextAngleInDegrees;
|
||||||
|
|
||||||
|
const nextAngle = degreeToRadian(nextAngleInDegrees);
|
||||||
|
|
||||||
|
mutateElement(element, {
|
||||||
|
angle: nextAngle,
|
||||||
|
});
|
||||||
|
|
||||||
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
||||||
|
if (boundTextElement && !isArrowElement(element)) {
|
||||||
|
mutateElement(boundTextElement, { angle: nextAngle });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const originalAngleInDegrees =
|
|
||||||
Math.round(radianToDegree(origElement.angle) * 100) / 100;
|
|
||||||
const changeInDegrees = Math.round(accumulatedChange);
|
|
||||||
let nextAngleInDegrees = (originalAngleInDegrees + changeInDegrees) % 360;
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextAngleInDegrees = getStepSizedValue(nextAngleInDegrees, STEP_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
nextAngleInDegrees =
|
|
||||||
nextAngleInDegrees < 0 ? nextAngleInDegrees + 360 : nextAngleInDegrees;
|
|
||||||
|
|
||||||
const nextAngle = degreeToRadian(nextAngleInDegrees);
|
|
||||||
|
|
||||||
mutateElement(latestElement, {
|
|
||||||
angle: nextAngle,
|
|
||||||
});
|
|
||||||
updateBindings(latestElement, elementsMap);
|
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
|
||||||
if (boundTextElement && !isArrowElement(latestElement)) {
|
|
||||||
mutateElement(boundTextElement, { angle: nextAngle });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const Angle = ({ element, scene, appState, property }: AngleProps) => {
|
|
||||||
return (
|
return (
|
||||||
<DragInput
|
<DragInput
|
||||||
label="A"
|
label="A"
|
||||||
icon={angleIcon}
|
value={Math.round(radianToDegree(element.angle) * 100) / 100}
|
||||||
value={Math.round((radianToDegree(element.angle) % 360) * 100) / 100}
|
|
||||||
elements={[element]}
|
elements={[element]}
|
||||||
dragInputCallback={handleDegreeChange}
|
dragInputCallback={handleDegreeChange}
|
||||||
editable={isPropertyEditable(element, "angle")}
|
editable={isPropertyEditable(element, "angle")}
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
property={property}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
import { InlineIcon } from "../InlineIcon";
|
|
||||||
import { collapseDownIcon, collapseUpIcon } from "../icons";
|
|
||||||
|
|
||||||
interface CollapsibleProps {
|
|
||||||
label: React.ReactNode;
|
|
||||||
// having it controlled so that the state is managed outside
|
|
||||||
// this is to keep the user's previous choice even when the
|
|
||||||
// Collapsible is unmounted
|
|
||||||
open: boolean;
|
|
||||||
openTrigger: () => void;
|
|
||||||
children: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Collapsible = ({
|
|
||||||
label,
|
|
||||||
open,
|
|
||||||
openTrigger,
|
|
||||||
children,
|
|
||||||
}: CollapsibleProps) => {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
cursor: "pointer",
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
onClick={openTrigger}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
<InlineIcon icon={open ? collapseUpIcon : collapseDownIcon} />
|
|
||||||
</div>
|
|
||||||
{open && <>{children}</>}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Collapsible;
|
|
||||||
@@ -1,16 +1,26 @@
|
|||||||
import type { ExcalidrawElement } from "../../element/types";
|
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
import type { DragInputCallbackType } from "./DragInput";
|
||||||
import { getStepSizedValue, isPropertyEditable, resizeElement } from "./utils";
|
import { getStepSizedValue, isPropertyEditable } from "./utils";
|
||||||
import { MIN_WIDTH_OR_HEIGHT } from "../../constants";
|
import { mutateElement } from "../../element/mutateElement";
|
||||||
import type Scene from "../../scene/Scene";
|
import {
|
||||||
import type { AppState } from "../../types";
|
measureFontSizeFromWidth,
|
||||||
|
rescalePointsInElement,
|
||||||
|
} from "../../element/resizeElements";
|
||||||
|
import {
|
||||||
|
getApproxMinLineHeight,
|
||||||
|
getApproxMinLineWidth,
|
||||||
|
getBoundTextElement,
|
||||||
|
getBoundTextMaxWidth,
|
||||||
|
handleBindTextResize,
|
||||||
|
} from "../../element/textElement";
|
||||||
|
import { getFontString } from "../../utils";
|
||||||
|
import { updateBoundElements } from "../../element/binding";
|
||||||
|
|
||||||
interface DimensionDragInputProps {
|
interface DimensionDragInputProps {
|
||||||
property: "width" | "height";
|
property: "width" | "height";
|
||||||
element: ExcalidrawElement;
|
element: ExcalidrawElement;
|
||||||
scene: Scene;
|
elementsMap: ElementsMap;
|
||||||
appState: AppState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const STEP_SIZE = 10;
|
const STEP_SIZE = 10;
|
||||||
@@ -18,115 +28,218 @@ const _shouldKeepAspectRatio = (element: ExcalidrawElement) => {
|
|||||||
return element.type === "image";
|
return element.type === "image";
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDimensionChange: DragInputCallbackType<
|
export const newOrigin = (
|
||||||
DimensionDragInputProps["property"]
|
x1: number,
|
||||||
> = ({
|
y1: number,
|
||||||
accumulatedChange,
|
w1: number,
|
||||||
originalElements,
|
h1: number,
|
||||||
originalElementsMap,
|
w2: number,
|
||||||
shouldKeepAspectRatio,
|
h2: number,
|
||||||
shouldChangeByStepSize,
|
angle: number,
|
||||||
nextValue,
|
) => {
|
||||||
property,
|
/**
|
||||||
scene,
|
* The formula below is the result of solving
|
||||||
}) => {
|
* rotate(x1, y1, cx1, cy1, angle) = rotate(x2, y2, cx2, cy2, angle)
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
* where rotate is the function defined in math.ts
|
||||||
const origElement = originalElements[0];
|
*
|
||||||
if (origElement) {
|
* This is so that the new origin (x2, y2),
|
||||||
const keepAspectRatio =
|
* when rotated against the new center (cx2, cy2),
|
||||||
shouldKeepAspectRatio || _shouldKeepAspectRatio(origElement);
|
* coincides with (x1, y1) rotated against (cx1, cy1)
|
||||||
const aspectRatio = origElement.width / origElement.height;
|
*
|
||||||
|
* The reason for doing this computation is so the element's top left corner
|
||||||
|
* on the canvas remains fixed after any changes in its dimension.
|
||||||
|
*/
|
||||||
|
|
||||||
if (nextValue !== undefined) {
|
return {
|
||||||
const nextWidth = Math.max(
|
x:
|
||||||
property === "width"
|
x1 +
|
||||||
? nextValue
|
(w1 - w2) / 2 +
|
||||||
: keepAspectRatio
|
((w2 - w1) / 2) * Math.cos(angle) +
|
||||||
? nextValue * aspectRatio
|
((h1 - h2) / 2) * Math.sin(angle),
|
||||||
: origElement.width,
|
y:
|
||||||
MIN_WIDTH_OR_HEIGHT,
|
y1 +
|
||||||
);
|
(h1 - h2) / 2 +
|
||||||
const nextHeight = Math.max(
|
((w2 - w1) / 2) * Math.sin(angle) +
|
||||||
property === "height"
|
((h2 - h1) / 2) * Math.cos(angle),
|
||||||
? nextValue
|
};
|
||||||
: keepAspectRatio
|
};
|
||||||
? nextValue / aspectRatio
|
|
||||||
: origElement.height,
|
|
||||||
MIN_WIDTH_OR_HEIGHT,
|
|
||||||
);
|
|
||||||
|
|
||||||
resizeElement(
|
const resizeElement = (
|
||||||
nextWidth,
|
nextWidth: number,
|
||||||
nextHeight,
|
nextHeight: number,
|
||||||
keepAspectRatio,
|
keepAspectRatio: boolean,
|
||||||
origElement,
|
latestState: ExcalidrawElement,
|
||||||
elementsMap,
|
stateAtStart: ExcalidrawElement,
|
||||||
);
|
elementsMap: ElementsMap,
|
||||||
|
originalElementsMap: Map<string, ExcalidrawElement>,
|
||||||
return;
|
) => {
|
||||||
}
|
mutateElement(latestState, {
|
||||||
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
...newOrigin(
|
||||||
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
latestState.x,
|
||||||
|
latestState.y,
|
||||||
let nextWidth = Math.max(0, origElement.width + changeInWidth);
|
latestState.width,
|
||||||
if (property === "width") {
|
latestState.height,
|
||||||
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);
|
|
||||||
|
|
||||||
resizeElement(
|
|
||||||
nextWidth,
|
nextWidth,
|
||||||
nextHeight,
|
nextHeight,
|
||||||
keepAspectRatio,
|
latestState.angle,
|
||||||
origElement,
|
),
|
||||||
elementsMap,
|
width: nextWidth,
|
||||||
);
|
height: nextHeight,
|
||||||
|
...rescalePointsInElement(stateAtStart, nextWidth, nextHeight, true),
|
||||||
|
});
|
||||||
|
|
||||||
|
let boundTextFont: { fontSize?: number } = {};
|
||||||
|
const boundTextElement = getBoundTextElement(latestState, elementsMap);
|
||||||
|
|
||||||
|
if (boundTextElement) {
|
||||||
|
boundTextFont = {
|
||||||
|
fontSize: boundTextElement.fontSize,
|
||||||
|
};
|
||||||
|
if (keepAspectRatio) {
|
||||||
|
const updatedElement = {
|
||||||
|
...latestState,
|
||||||
|
width: nextWidth,
|
||||||
|
height: nextHeight,
|
||||||
|
};
|
||||||
|
|
||||||
|
const nextFont = measureFontSizeFromWidth(
|
||||||
|
boundTextElement,
|
||||||
|
elementsMap,
|
||||||
|
getBoundTextMaxWidth(updatedElement, boundTextElement),
|
||||||
|
);
|
||||||
|
boundTextFont = {
|
||||||
|
fontSize: nextFont?.size ?? boundTextElement.fontSize,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const minWidth = getApproxMinLineWidth(
|
||||||
|
getFontString(boundTextElement),
|
||||||
|
boundTextElement.lineHeight,
|
||||||
|
);
|
||||||
|
const minHeight = getApproxMinLineHeight(
|
||||||
|
boundTextElement.fontSize,
|
||||||
|
boundTextElement.lineHeight,
|
||||||
|
);
|
||||||
|
nextWidth = Math.max(nextWidth, minWidth);
|
||||||
|
nextHeight = Math.max(nextHeight, minHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBoundElements(latestState, elementsMap, {
|
||||||
|
newSize: {
|
||||||
|
width: nextWidth,
|
||||||
|
height: nextHeight,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (boundTextElement && boundTextFont) {
|
||||||
|
mutateElement(boundTextElement, {
|
||||||
|
fontSize: boundTextFont.fontSize,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
handleBindTextResize(latestState, elementsMap, "e", keepAspectRatio);
|
||||||
};
|
};
|
||||||
|
|
||||||
const DimensionDragInput = ({
|
const DimensionDragInput = ({
|
||||||
property,
|
property,
|
||||||
element,
|
element,
|
||||||
scene,
|
elementsMap,
|
||||||
appState,
|
|
||||||
}: DimensionDragInputProps) => {
|
}: DimensionDragInputProps) => {
|
||||||
const value =
|
const handleDimensionChange: DragInputCallbackType = ({
|
||||||
Math.round((property === "width" ? element.width : element.height) * 100) /
|
accumulatedChange,
|
||||||
100;
|
stateAtStart,
|
||||||
|
originalElementsMap,
|
||||||
|
shouldKeepAspectRatio,
|
||||||
|
shouldChangeByStepSize,
|
||||||
|
nextValue,
|
||||||
|
}) => {
|
||||||
|
const _stateAtStart = stateAtStart[0];
|
||||||
|
if (_stateAtStart) {
|
||||||
|
const keepAspectRatio =
|
||||||
|
shouldKeepAspectRatio || _shouldKeepAspectRatio(element);
|
||||||
|
const aspectRatio = _stateAtStart.width / _stateAtStart.height;
|
||||||
|
|
||||||
|
if (nextValue !== undefined) {
|
||||||
|
const nextWidth = Math.max(
|
||||||
|
property === "width"
|
||||||
|
? nextValue
|
||||||
|
: keepAspectRatio
|
||||||
|
? nextValue * aspectRatio
|
||||||
|
: _stateAtStart.width,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const nextHeight = Math.max(
|
||||||
|
property === "height"
|
||||||
|
? nextValue
|
||||||
|
: keepAspectRatio
|
||||||
|
? nextValue / aspectRatio
|
||||||
|
: _stateAtStart.height,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
resizeElement(
|
||||||
|
nextWidth,
|
||||||
|
nextHeight,
|
||||||
|
keepAspectRatio,
|
||||||
|
element,
|
||||||
|
_stateAtStart,
|
||||||
|
elementsMap,
|
||||||
|
originalElementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
||||||
|
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
||||||
|
|
||||||
|
let nextWidth = Math.max(0, _stateAtStart.width + changeInWidth);
|
||||||
|
if (property === "width") {
|
||||||
|
if (shouldChangeByStepSize) {
|
||||||
|
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
||||||
|
} else {
|
||||||
|
nextWidth = Math.round(nextWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let nextHeight = Math.max(0, _stateAtStart.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resizeElement(
|
||||||
|
nextWidth,
|
||||||
|
nextHeight,
|
||||||
|
keepAspectRatio,
|
||||||
|
element,
|
||||||
|
_stateAtStart,
|
||||||
|
elementsMap,
|
||||||
|
originalElementsMap,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DragInput
|
<DragInput
|
||||||
label={property === "width" ? "W" : "H"}
|
label={property === "width" ? "W" : "H"}
|
||||||
elements={[element]}
|
elements={[element]}
|
||||||
dragInputCallback={handleDimensionChange}
|
dragInputCallback={handleDimensionChange}
|
||||||
value={value}
|
value={
|
||||||
|
Math.round(
|
||||||
|
(property === "width" ? element.width : element.height) * 100,
|
||||||
|
) / 100
|
||||||
|
}
|
||||||
editable={isPropertyEditable(element, property)}
|
editable={isPropertyEditable(element, property)}
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
property={property}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,13 +15,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.drag-input-label {
|
.drag-input-label {
|
||||||
|
height: var(--default-button-size);
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
|
||||||
border: 1px solid var(--default-border-color);
|
border: 1px solid var(--default-border-color);
|
||||||
border-right: 0;
|
border-right: 0;
|
||||||
width: 2rem;
|
|
||||||
height: 2rem;
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
color: var(--popup-text-color);
|
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
:root[dir="ltr"] & {
|
||||||
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
||||||
@@ -33,6 +32,7 @@
|
|||||||
border-left: 0;
|
border-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color: var(--input-label-color);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
color: var(--text-primary-color);
|
color: var(--text-primary-color);
|
||||||
border: 0;
|
border: 0;
|
||||||
outline: none;
|
outline: none;
|
||||||
height: 2rem;
|
height: var(--default-button-size);
|
||||||
border: 1px solid var(--default-border-color);
|
border: 1px solid var(--default-border-color);
|
||||||
border-left: 0;
|
border-left: 0;
|
||||||
letter-spacing: 0.4px;
|
letter-spacing: 0.4px;
|
||||||
|
|||||||
@@ -1,172 +1,65 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
import throttle from "lodash.throttle";
|
||||||
import { EVENT } from "../../constants";
|
import { EVENT } from "../../constants";
|
||||||
import { KEYS } from "../../keys";
|
import { KEYS } from "../../keys";
|
||||||
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
||||||
import { deepCopyElement } from "../../element/newElement";
|
import { deepCopyElement } from "../../element/newElement";
|
||||||
import clsx from "clsx";
|
|
||||||
import { useApp } from "../App";
|
|
||||||
import { InlineIcon } from "../InlineIcon";
|
|
||||||
import type { StatsInputProperty } from "./utils";
|
|
||||||
import { SMALLEST_DELTA } from "./utils";
|
|
||||||
import { StoreAction } from "../../store";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
|
|
||||||
import "./DragInput.scss";
|
import "./DragInput.scss";
|
||||||
import type { AppState } from "../../types";
|
import clsx from "clsx";
|
||||||
import { cloneJSON } from "../../utils";
|
import { useApp } from "../App";
|
||||||
|
|
||||||
export type DragInputCallbackType<
|
export type DragInputCallbackType = ({
|
||||||
P extends StatsInputProperty,
|
accumulatedChange,
|
||||||
E = ExcalidrawElement,
|
instantChange,
|
||||||
> = (props: {
|
stateAtStart,
|
||||||
|
originalElementsMap,
|
||||||
|
shouldKeepAspectRatio,
|
||||||
|
shouldChangeByStepSize,
|
||||||
|
nextValue,
|
||||||
|
}: {
|
||||||
accumulatedChange: number;
|
accumulatedChange: number;
|
||||||
instantChange: number;
|
instantChange: number;
|
||||||
originalElements: readonly E[];
|
stateAtStart: ExcalidrawElement[];
|
||||||
originalElementsMap: ElementsMap;
|
originalElementsMap: ElementsMap;
|
||||||
shouldKeepAspectRatio: boolean;
|
shouldKeepAspectRatio: boolean;
|
||||||
shouldChangeByStepSize: boolean;
|
shouldChangeByStepSize: boolean;
|
||||||
nextValue?: number;
|
nextValue?: number;
|
||||||
property: P;
|
|
||||||
scene: Scene;
|
|
||||||
originalAppState: AppState;
|
|
||||||
}) => void;
|
}) => void;
|
||||||
|
|
||||||
interface StatsDragInputProps<
|
interface StatsDragInputProps {
|
||||||
T extends StatsInputProperty,
|
|
||||||
E = ExcalidrawElement,
|
|
||||||
> {
|
|
||||||
label: string | React.ReactNode;
|
label: string | React.ReactNode;
|
||||||
icon?: React.ReactNode;
|
value: number;
|
||||||
value: number | "Mixed";
|
elements: ExcalidrawElement[];
|
||||||
elements: readonly E[];
|
|
||||||
editable?: boolean;
|
editable?: boolean;
|
||||||
shouldKeepAspectRatio?: boolean;
|
shouldKeepAspectRatio?: boolean;
|
||||||
dragInputCallback: DragInputCallbackType<T, E>;
|
dragInputCallback: DragInputCallbackType;
|
||||||
property: T;
|
|
||||||
scene: Scene;
|
|
||||||
appState: AppState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const StatsDragInput = <
|
const StatsDragInput = ({
|
||||||
T extends StatsInputProperty,
|
|
||||||
E extends ExcalidrawElement = ExcalidrawElement,
|
|
||||||
>({
|
|
||||||
label,
|
label,
|
||||||
icon,
|
|
||||||
dragInputCallback,
|
dragInputCallback,
|
||||||
value,
|
value,
|
||||||
elements,
|
elements,
|
||||||
editable = true,
|
editable = true,
|
||||||
shouldKeepAspectRatio,
|
shouldKeepAspectRatio,
|
||||||
property,
|
}: StatsDragInputProps) => {
|
||||||
scene,
|
|
||||||
appState,
|
|
||||||
}: StatsDragInputProps<T, E>) => {
|
|
||||||
const app = useApp();
|
const app = useApp();
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const labelRef = useRef<HTMLDivElement>(null);
|
const labelRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const cbThrottled = useMemo(() => {
|
||||||
|
return throttle(dragInputCallback, 16);
|
||||||
|
}, [dragInputCallback]);
|
||||||
|
|
||||||
const [inputValue, setInputValue] = useState(value.toString());
|
const [inputValue, setInputValue] = useState(value.toString());
|
||||||
|
|
||||||
const stateRef = useRef<{
|
|
||||||
originalAppState: AppState;
|
|
||||||
originalElements: readonly E[];
|
|
||||||
lastUpdatedValue: string;
|
|
||||||
updatePending: boolean;
|
|
||||||
}>(null!);
|
|
||||||
if (!stateRef.current) {
|
|
||||||
stateRef.current = {
|
|
||||||
originalAppState: cloneJSON(appState),
|
|
||||||
originalElements: elements,
|
|
||||||
lastUpdatedValue: inputValue,
|
|
||||||
updatePending: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const inputValue = value.toString();
|
setInputValue(value.toString());
|
||||||
setInputValue(inputValue);
|
|
||||||
stateRef.current.lastUpdatedValue = inputValue;
|
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
const handleInputValue = (
|
|
||||||
updatedValue: string,
|
|
||||||
elements: readonly E[],
|
|
||||||
appState: AppState,
|
|
||||||
) => {
|
|
||||||
if (!stateRef.current.updatePending) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
stateRef.current.updatePending = false;
|
|
||||||
|
|
||||||
const parsed = Number(updatedValue);
|
|
||||||
if (isNaN(parsed)) {
|
|
||||||
setInputValue(value.toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rounded = Number(parsed.toFixed(2));
|
|
||||||
const original = Number(value);
|
|
||||||
|
|
||||||
// only update when
|
|
||||||
// 1. original was "Mixed" and we have a new value
|
|
||||||
// 2. original was not "Mixed" and the difference between a new value and previous value is greater
|
|
||||||
// than the smallest delta allowed, which is 0.01
|
|
||||||
// reason: idempotent to avoid unnecessary
|
|
||||||
if (isNaN(original) || Math.abs(rounded - original) >= SMALLEST_DELTA) {
|
|
||||||
stateRef.current.lastUpdatedValue = updatedValue;
|
|
||||||
dragInputCallback({
|
|
||||||
accumulatedChange: 0,
|
|
||||||
instantChange: 0,
|
|
||||||
originalElements: elements,
|
|
||||||
originalElementsMap: app.scene.getNonDeletedElementsMap(),
|
|
||||||
shouldKeepAspectRatio: shouldKeepAspectRatio!!,
|
|
||||||
shouldChangeByStepSize: false,
|
|
||||||
nextValue: rounded,
|
|
||||||
property,
|
|
||||||
scene,
|
|
||||||
originalAppState: appState,
|
|
||||||
});
|
|
||||||
app.syncActionResult({ storeAction: StoreAction.CAPTURE });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleInputValueRef = useRef(handleInputValue);
|
|
||||||
handleInputValueRef.current = handleInputValue;
|
|
||||||
|
|
||||||
// make sure that clicking on canvas (which umounts the component)
|
|
||||||
// updates current input value (blur isn't triggered)
|
|
||||||
useEffect(() => {
|
|
||||||
const input = inputRef.current;
|
|
||||||
return () => {
|
|
||||||
const nextValue = input?.value;
|
|
||||||
if (nextValue) {
|
|
||||||
handleInputValueRef.current(
|
|
||||||
nextValue,
|
|
||||||
stateRef.current.originalElements,
|
|
||||||
stateRef.current.originalAppState,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [
|
|
||||||
// we need to track change of `editable` state as mount/unmount
|
|
||||||
// because react doesn't trigger `blur` when a an input is blurred due
|
|
||||||
// to being disabled (https://github.com/facebook/react/issues/9142).
|
|
||||||
// As such, if we keep rendering disabled inputs, then change in selection
|
|
||||||
// to an element that has a given property as non-editable would not trigger
|
|
||||||
// blur/unmount and wouldn't update the value.
|
|
||||||
editable,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!editable) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={clsx("drag-input-container", !editable && "disabled")}>
|
||||||
className={clsx("drag-input-container", !editable && "disabled")}
|
|
||||||
data-testid={label}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
className="drag-input-label"
|
className="drag-input-label"
|
||||||
ref={labelRef}
|
ref={labelRef}
|
||||||
@@ -182,48 +75,45 @@ const StatsDragInput = <
|
|||||||
y: number;
|
y: number;
|
||||||
} | null = null;
|
} | null = null;
|
||||||
|
|
||||||
|
let stateAtStart: ExcalidrawElement[] | null = null;
|
||||||
let originalElementsMap: Map<string, ExcalidrawElement> | null =
|
let originalElementsMap: Map<string, ExcalidrawElement> | null =
|
||||||
app.scene
|
null;
|
||||||
.getNonDeletedElements()
|
|
||||||
.reduce((acc: ElementsMap, element) => {
|
|
||||||
acc.set(element.id, deepCopyElement(element));
|
|
||||||
return acc;
|
|
||||||
}, new Map());
|
|
||||||
|
|
||||||
let originalElements: readonly E[] | null = elements.map(
|
|
||||||
(element) => originalElementsMap!.get(element.id) as E,
|
|
||||||
);
|
|
||||||
|
|
||||||
const originalAppState: AppState = cloneJSON(appState);
|
|
||||||
|
|
||||||
let accumulatedChange: number | null = null;
|
let accumulatedChange: number | null = null;
|
||||||
|
|
||||||
document.body.classList.add("excalidraw-cursor-resize");
|
document.body.classList.add("dragResize");
|
||||||
|
|
||||||
const onPointerMove = (event: PointerEvent) => {
|
const onPointerMove = (event: PointerEvent) => {
|
||||||
|
if (!stateAtStart) {
|
||||||
|
stateAtStart = elements.map((element) =>
|
||||||
|
deepCopyElement(element),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!originalElementsMap) {
|
||||||
|
originalElementsMap = app.scene
|
||||||
|
.getNonDeletedElements()
|
||||||
|
.reduce((acc, element) => {
|
||||||
|
acc.set(element.id, deepCopyElement(element));
|
||||||
|
return acc;
|
||||||
|
}, new Map() as ElementsMap);
|
||||||
|
}
|
||||||
|
|
||||||
if (!accumulatedChange) {
|
if (!accumulatedChange) {
|
||||||
accumulatedChange = 0;
|
accumulatedChange = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (lastPointer && stateAtStart && accumulatedChange !== null) {
|
||||||
lastPointer &&
|
|
||||||
originalElementsMap !== null &&
|
|
||||||
originalElements !== null &&
|
|
||||||
accumulatedChange !== null
|
|
||||||
) {
|
|
||||||
const instantChange = event.clientX - lastPointer.x;
|
const instantChange = event.clientX - lastPointer.x;
|
||||||
accumulatedChange += instantChange;
|
accumulatedChange += instantChange;
|
||||||
|
|
||||||
dragInputCallback({
|
cbThrottled({
|
||||||
accumulatedChange,
|
accumulatedChange,
|
||||||
instantChange,
|
instantChange,
|
||||||
originalElements,
|
stateAtStart,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
shouldKeepAspectRatio: shouldKeepAspectRatio!!,
|
shouldKeepAspectRatio: shouldKeepAspectRatio!!,
|
||||||
shouldChangeByStepSize: event.shiftKey,
|
shouldChangeByStepSize: event.shiftKey,
|
||||||
property,
|
|
||||||
scene,
|
|
||||||
originalAppState,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,14 +133,14 @@ const StatsDragInput = <
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
app.syncActionResult({ storeAction: StoreAction.CAPTURE });
|
app.store.shouldCaptureIncrement();
|
||||||
|
|
||||||
lastPointer = null;
|
lastPointer = null;
|
||||||
accumulatedChange = null;
|
accumulatedChange = null;
|
||||||
originalElements = null;
|
stateAtStart = null;
|
||||||
originalElementsMap = null;
|
originalElementsMap = null;
|
||||||
|
|
||||||
document.body.classList.remove("excalidraw-cursor-resize");
|
document.body.classList.remove("dragResize");
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
@@ -262,7 +152,7 @@ const StatsDragInput = <
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{icon ? <InlineIcon icon={icon} /> : label}
|
{label}
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
className="drag-input"
|
className="drag-input"
|
||||||
@@ -271,39 +161,46 @@ const StatsDragInput = <
|
|||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (editable) {
|
if (editable) {
|
||||||
const eventTarget = event.target;
|
const eventTarget = event.target;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
eventTarget instanceof HTMLInputElement &&
|
eventTarget instanceof HTMLInputElement &&
|
||||||
event.key === KEYS.ENTER
|
event.key === KEYS.ENTER
|
||||||
) {
|
) {
|
||||||
handleInputValue(eventTarget.value, elements, appState);
|
const v = Number(eventTarget.value);
|
||||||
app.focusContainer();
|
if (isNaN(v)) {
|
||||||
|
setInputValue(value.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dragInputCallback({
|
||||||
|
accumulatedChange: 0,
|
||||||
|
instantChange: 0,
|
||||||
|
stateAtStart: elements,
|
||||||
|
originalElementsMap: app.scene.getNonDeletedElementsMap(),
|
||||||
|
shouldKeepAspectRatio: shouldKeepAspectRatio!!,
|
||||||
|
shouldChangeByStepSize: false,
|
||||||
|
nextValue: v,
|
||||||
|
});
|
||||||
|
app.store.shouldCaptureIncrement();
|
||||||
|
eventTarget.blur();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
value={inputValue}
|
value={inputValue}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
stateRef.current.updatePending = true;
|
const eventTarget = event.target;
|
||||||
setInputValue(event.target.value);
|
if (eventTarget instanceof HTMLInputElement) {
|
||||||
|
setInputValue(event.target.value);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onFocus={(event) => {
|
onBlur={() => {
|
||||||
event.target.select();
|
|
||||||
stateRef.current.originalElements = elements;
|
|
||||||
stateRef.current.originalAppState = cloneJSON(appState);
|
|
||||||
}}
|
|
||||||
onBlur={(event) => {
|
|
||||||
if (!inputValue) {
|
if (!inputValue) {
|
||||||
setInputValue(value.toString());
|
setInputValue(value.toString());
|
||||||
} else if (editable) {
|
|
||||||
handleInputValue(
|
|
||||||
event.target.value,
|
|
||||||
stateRef.current.originalElements,
|
|
||||||
stateRef.current.originalAppState,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
disabled={!editable}
|
disabled={!editable}
|
||||||
/>
|
></input>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,97 +1,71 @@
|
|||||||
import type {
|
import type { ElementsMap, ExcalidrawTextElement } from "../../element/types";
|
||||||
ExcalidrawElement,
|
import { refreshTextDimensions } from "../../element/newElement";
|
||||||
ExcalidrawTextElement,
|
|
||||||
} from "../../element/types";
|
|
||||||
import StatsDragInput from "./DragInput";
|
import StatsDragInput from "./DragInput";
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
import type { DragInputCallbackType } from "./DragInput";
|
||||||
import { mutateElement } from "../../element/mutateElement";
|
import { mutateElement } from "../../element/mutateElement";
|
||||||
import { getStepSizedValue } from "./utils";
|
import { getStepSizedValue } from "./utils";
|
||||||
import { fontSizeIcon } from "../icons";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import type { AppState } from "../../types";
|
|
||||||
import { isTextElement, redrawTextBoundingBox } from "../../element";
|
|
||||||
import { hasBoundTextElement } from "../../element/typeChecks";
|
|
||||||
import { getBoundTextElement } from "../../element/textElement";
|
|
||||||
|
|
||||||
interface FontSizeProps {
|
interface FontSizeProps {
|
||||||
element: ExcalidrawElement;
|
element: ExcalidrawTextElement;
|
||||||
scene: Scene;
|
elementsMap: ElementsMap;
|
||||||
appState: AppState;
|
|
||||||
property: "fontSize";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MIN_FONT_SIZE = 4;
|
const MIN_FONT_SIZE = 4;
|
||||||
const STEP_SIZE = 4;
|
const STEP_SIZE = 4;
|
||||||
|
|
||||||
const handleFontSizeChange: DragInputCallbackType<
|
const FontSize = ({ element, elementsMap }: FontSizeProps) => {
|
||||||
FontSizeProps["property"],
|
const handleFontSizeChange: DragInputCallbackType = ({
|
||||||
ExcalidrawTextElement
|
accumulatedChange,
|
||||||
> = ({
|
stateAtStart,
|
||||||
accumulatedChange,
|
shouldChangeByStepSize,
|
||||||
originalElements,
|
nextValue,
|
||||||
shouldChangeByStepSize,
|
}) => {
|
||||||
nextValue,
|
const _stateAtStart = stateAtStart[0];
|
||||||
scene,
|
if (_stateAtStart) {
|
||||||
}) => {
|
if (nextValue) {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const nextFontSize = Math.max(Math.round(nextValue), MIN_FONT_SIZE);
|
||||||
|
|
||||||
const origElement = originalElements[0];
|
const newElement = {
|
||||||
if (origElement) {
|
...element,
|
||||||
const latestElement = elementsMap.get(origElement.id);
|
fontSize: nextFontSize,
|
||||||
if (!latestElement || !isTextElement(latestElement)) {
|
};
|
||||||
return;
|
const updates = refreshTextDimensions(newElement, null, elementsMap);
|
||||||
}
|
mutateElement(element, {
|
||||||
|
...updates,
|
||||||
|
fontSize: nextFontSize,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let nextFontSize;
|
if (_stateAtStart.type === "text") {
|
||||||
|
const originalFontSize = Math.round(_stateAtStart.fontSize);
|
||||||
if (nextValue !== undefined) {
|
const changeInFontSize = Math.round(accumulatedChange);
|
||||||
nextFontSize = Math.max(Math.round(nextValue), MIN_FONT_SIZE);
|
let nextFontSize = Math.max(
|
||||||
} else if (origElement.type === "text") {
|
originalFontSize + changeInFontSize,
|
||||||
const originalFontSize = Math.round(origElement.fontSize);
|
MIN_FONT_SIZE,
|
||||||
const changeInFontSize = Math.round(accumulatedChange);
|
);
|
||||||
nextFontSize = Math.max(
|
if (shouldChangeByStepSize) {
|
||||||
originalFontSize + changeInFontSize,
|
nextFontSize = getStepSizedValue(nextFontSize, STEP_SIZE);
|
||||||
MIN_FONT_SIZE,
|
}
|
||||||
);
|
const newElement = {
|
||||||
if (shouldChangeByStepSize) {
|
...element,
|
||||||
nextFontSize = getStepSizedValue(nextFontSize, STEP_SIZE);
|
fontSize: nextFontSize,
|
||||||
|
};
|
||||||
|
const updates = refreshTextDimensions(newElement, null, elementsMap);
|
||||||
|
mutateElement(element, {
|
||||||
|
...updates,
|
||||||
|
fontSize: nextFontSize,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if (nextFontSize) {
|
|
||||||
mutateElement(latestElement, {
|
|
||||||
fontSize: nextFontSize,
|
|
||||||
});
|
|
||||||
redrawTextBoundingBox(
|
|
||||||
latestElement,
|
|
||||||
scene.getContainerElement(latestElement),
|
|
||||||
scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const FontSize = ({ element, scene, appState, property }: FontSizeProps) => {
|
|
||||||
const _element = isTextElement(element)
|
|
||||||
? element
|
|
||||||
: hasBoundTextElement(element)
|
|
||||||
? getBoundTextElement(element, scene.getNonDeletedElementsMap())
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (!_element) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatsDragInput
|
<StatsDragInput
|
||||||
label="F"
|
label="F"
|
||||||
value={Math.round(_element.fontSize * 10) / 10}
|
value={Math.round(element.fontSize * 10) / 10}
|
||||||
elements={[_element]}
|
elements={[element]}
|
||||||
dragInputCallback={handleFontSizeChange}
|
dragInputCallback={handleFontSizeChange}
|
||||||
icon={fontSizeIcon}
|
|
||||||
appState={appState}
|
|
||||||
scene={scene}
|
|
||||||
property={property}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
import { mutateElement } from "../../element/mutateElement";
|
|
||||||
import { getBoundTextElement } from "../../element/textElement";
|
|
||||||
import { isArrowElement } from "../../element/typeChecks";
|
|
||||||
import type { ExcalidrawElement } from "../../element/types";
|
|
||||||
import { isInGroup } from "../../groups";
|
|
||||||
import { degreeToRadian, radianToDegree } from "../../math";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import { angleIcon } from "../icons";
|
|
||||||
import DragInput from "./DragInput";
|
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
|
||||||
import { getStepSizedValue, isPropertyEditable } from "./utils";
|
|
||||||
import type { AppState } from "../../types";
|
|
||||||
|
|
||||||
interface MultiAngleProps {
|
|
||||||
elements: readonly ExcalidrawElement[];
|
|
||||||
scene: Scene;
|
|
||||||
appState: AppState;
|
|
||||||
property: "angle";
|
|
||||||
}
|
|
||||||
|
|
||||||
const STEP_SIZE = 15;
|
|
||||||
|
|
||||||
const handleDegreeChange: DragInputCallbackType<
|
|
||||||
MultiAngleProps["property"]
|
|
||||||
> = ({
|
|
||||||
accumulatedChange,
|
|
||||||
originalElements,
|
|
||||||
shouldChangeByStepSize,
|
|
||||||
nextValue,
|
|
||||||
property,
|
|
||||||
scene,
|
|
||||||
}) => {
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
|
||||||
const editableLatestIndividualElements = originalElements
|
|
||||||
.map((el) => elementsMap.get(el.id))
|
|
||||||
.filter((el) => el && !isInGroup(el) && isPropertyEditable(el, property));
|
|
||||||
const editableOriginalIndividualElements = originalElements.filter(
|
|
||||||
(el) => !isInGroup(el) && isPropertyEditable(el, property),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (nextValue !== undefined) {
|
|
||||||
const nextAngle = degreeToRadian(nextValue);
|
|
||||||
|
|
||||||
for (const element of editableLatestIndividualElements) {
|
|
||||||
if (!element) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
mutateElement(
|
|
||||||
element,
|
|
||||||
{
|
|
||||||
angle: nextAngle,
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(element, elementsMap);
|
|
||||||
if (boundTextElement && !isArrowElement(element)) {
|
|
||||||
mutateElement(boundTextElement, { angle: nextAngle }, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < editableLatestIndividualElements.length; i++) {
|
|
||||||
const latestElement = editableLatestIndividualElements[i];
|
|
||||||
if (!latestElement) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const originalElement = editableOriginalIndividualElements[i];
|
|
||||||
const originalAngleInDegrees =
|
|
||||||
Math.round(radianToDegree(originalElement.angle) * 100) / 100;
|
|
||||||
const changeInDegrees = Math.round(accumulatedChange);
|
|
||||||
let nextAngleInDegrees = (originalAngleInDegrees + changeInDegrees) % 360;
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextAngleInDegrees = getStepSizedValue(nextAngleInDegrees, STEP_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
nextAngleInDegrees =
|
|
||||||
nextAngleInDegrees < 0 ? nextAngleInDegrees + 360 : nextAngleInDegrees;
|
|
||||||
|
|
||||||
const nextAngle = degreeToRadian(nextAngleInDegrees);
|
|
||||||
|
|
||||||
mutateElement(
|
|
||||||
latestElement,
|
|
||||||
{
|
|
||||||
angle: nextAngle,
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
|
||||||
if (boundTextElement && !isArrowElement(latestElement)) {
|
|
||||||
mutateElement(boundTextElement, { angle: nextAngle }, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scene.triggerUpdate();
|
|
||||||
};
|
|
||||||
|
|
||||||
const MultiAngle = ({
|
|
||||||
elements,
|
|
||||||
scene,
|
|
||||||
appState,
|
|
||||||
property,
|
|
||||||
}: MultiAngleProps) => {
|
|
||||||
const editableLatestIndividualElements = elements.filter(
|
|
||||||
(el) => !isInGroup(el) && isPropertyEditable(el, "angle"),
|
|
||||||
);
|
|
||||||
const angles = editableLatestIndividualElements.map(
|
|
||||||
(el) => Math.round((radianToDegree(el.angle) % 360) * 100) / 100,
|
|
||||||
);
|
|
||||||
const value = new Set(angles).size === 1 ? angles[0] : "Mixed";
|
|
||||||
|
|
||||||
const editable = editableLatestIndividualElements.some((el) =>
|
|
||||||
isPropertyEditable(el, "angle"),
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DragInput
|
|
||||||
label="A"
|
|
||||||
icon={angleIcon}
|
|
||||||
value={value}
|
|
||||||
elements={elements}
|
|
||||||
dragInputCallback={handleDegreeChange}
|
|
||||||
editable={editable}
|
|
||||||
appState={appState}
|
|
||||||
scene={scene}
|
|
||||||
property={property}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MultiAngle;
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import { getCommonBounds, isTextElement } from "../../element";
|
import { getCommonBounds, isTextElement } from "../../element";
|
||||||
import { updateBoundElements } from "../../element/binding";
|
import { updateBoundElements } from "../../element/binding";
|
||||||
import { mutateElement } from "../../element/mutateElement";
|
import { mutateElement } from "../../element/mutateElement";
|
||||||
@@ -7,27 +6,15 @@ import {
|
|||||||
getBoundTextElement,
|
getBoundTextElement,
|
||||||
handleBindTextResize,
|
handleBindTextResize,
|
||||||
} from "../../element/textElement";
|
} from "../../element/textElement";
|
||||||
import type {
|
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
||||||
ElementsMap,
|
|
||||||
ExcalidrawElement,
|
|
||||||
NonDeletedSceneElementsMap,
|
|
||||||
} from "../../element/types";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import type { AppState, Point } from "../../types";
|
|
||||||
import DragInput from "./DragInput";
|
import DragInput from "./DragInput";
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
import type { DragInputCallbackType } from "./DragInput";
|
||||||
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
import { getStepSizedValue } from "./utils";
|
||||||
import { getElementsInAtomicUnit, resizeElement } from "./utils";
|
|
||||||
import type { AtomicUnit } from "./utils";
|
|
||||||
import { MIN_WIDTH_OR_HEIGHT } from "../../constants";
|
|
||||||
|
|
||||||
interface MultiDimensionProps {
|
interface MultiDimensionProps {
|
||||||
property: "width" | "height";
|
property: "width" | "height";
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: ExcalidrawElement[];
|
||||||
elementsMap: NonDeletedSceneElementsMap;
|
elementsMap: ElementsMap;
|
||||||
atomicUnits: AtomicUnit[];
|
|
||||||
scene: Scene;
|
|
||||||
appState: AppState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const STEP_SIZE = 10;
|
const STEP_SIZE = 10;
|
||||||
@@ -36,12 +23,12 @@ const getResizedUpdates = (
|
|||||||
anchorX: number,
|
anchorX: number,
|
||||||
anchorY: number,
|
anchorY: number,
|
||||||
scale: number,
|
scale: number,
|
||||||
origElement: ExcalidrawElement,
|
stateAtStart: ExcalidrawElement,
|
||||||
) => {
|
) => {
|
||||||
const offsetX = origElement.x - anchorX;
|
const offsetX = stateAtStart.x - anchorX;
|
||||||
const offsetY = origElement.y - anchorY;
|
const offsetY = stateAtStart.y - anchorY;
|
||||||
const nextWidth = origElement.width * scale;
|
const nextWidth = stateAtStart.width * scale;
|
||||||
const nextHeight = origElement.height * scale;
|
const nextHeight = stateAtStart.height * scale;
|
||||||
const x = anchorX + offsetX * scale;
|
const x = anchorX + offsetX * scale;
|
||||||
const y = anchorY + offsetY * scale;
|
const y = anchorY + offsetY * scale;
|
||||||
|
|
||||||
@@ -50,26 +37,27 @@ const getResizedUpdates = (
|
|||||||
height: nextHeight,
|
height: nextHeight,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
...rescalePointsInElement(origElement, nextWidth, nextHeight, false),
|
...rescalePointsInElement(stateAtStart, nextWidth, nextHeight, false),
|
||||||
...(isTextElement(origElement)
|
...(isTextElement(stateAtStart)
|
||||||
? { fontSize: origElement.fontSize * scale }
|
? { fontSize: stateAtStart.fontSize * scale }
|
||||||
: {}),
|
: {}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const resizeElementInGroup = (
|
const resizeElement = (
|
||||||
anchorX: number,
|
anchorX: number,
|
||||||
anchorY: number,
|
anchorY: number,
|
||||||
property: MultiDimensionProps["property"],
|
property: MultiDimensionProps["property"],
|
||||||
scale: number,
|
scale: number,
|
||||||
latestElement: ExcalidrawElement,
|
latestElement: ExcalidrawElement,
|
||||||
origElement: ExcalidrawElement,
|
origElement: ExcalidrawElement,
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: ElementsMap,
|
||||||
originalElementsMap: ElementsMap,
|
originalElementsMap: ElementsMap,
|
||||||
|
shouldInformMutation: boolean,
|
||||||
) => {
|
) => {
|
||||||
const updates = getResizedUpdates(anchorX, anchorY, scale, origElement);
|
const updates = getResizedUpdates(anchorX, anchorY, scale, origElement);
|
||||||
|
|
||||||
mutateElement(latestElement, updates, false);
|
mutateElement(latestElement, updates, shouldInformMutation);
|
||||||
const boundTextElement = getBoundTextElement(
|
const boundTextElement = getBoundTextElement(
|
||||||
origElement,
|
origElement,
|
||||||
originalElementsMap,
|
originalElementsMap,
|
||||||
@@ -86,7 +74,7 @@ const resizeElementInGroup = (
|
|||||||
{
|
{
|
||||||
fontSize: newFontSize,
|
fontSize: newFontSize,
|
||||||
},
|
},
|
||||||
false,
|
shouldInformMutation,
|
||||||
);
|
);
|
||||||
handleBindTextResize(
|
handleBindTextResize(
|
||||||
latestElement,
|
latestElement,
|
||||||
@@ -98,283 +86,123 @@ const resizeElementInGroup = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const resizeGroup = (
|
|
||||||
nextWidth: number,
|
|
||||||
nextHeight: number,
|
|
||||||
initialHeight: number,
|
|
||||||
aspectRatio: number,
|
|
||||||
anchor: Point,
|
|
||||||
property: MultiDimensionProps["property"],
|
|
||||||
latestElements: ExcalidrawElement[],
|
|
||||||
originalElements: ExcalidrawElement[],
|
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
|
||||||
originalElementsMap: ElementsMap,
|
|
||||||
) => {
|
|
||||||
// keep aspect ratio for groups
|
|
||||||
if (property === "width") {
|
|
||||||
nextHeight = Math.round((nextWidth / aspectRatio) * 100) / 100;
|
|
||||||
} else {
|
|
||||||
nextWidth = Math.round(nextHeight * aspectRatio * 100) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
const scale = nextHeight / initialHeight;
|
|
||||||
|
|
||||||
for (let i = 0; i < originalElements.length; i++) {
|
|
||||||
const origElement = originalElements[i];
|
|
||||||
const latestElement = latestElements[i];
|
|
||||||
|
|
||||||
resizeElementInGroup(
|
|
||||||
anchor[0],
|
|
||||||
anchor[1],
|
|
||||||
property,
|
|
||||||
scale,
|
|
||||||
latestElement,
|
|
||||||
origElement,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDimensionChange: DragInputCallbackType<
|
|
||||||
MultiDimensionProps["property"]
|
|
||||||
> = ({
|
|
||||||
accumulatedChange,
|
|
||||||
originalElements,
|
|
||||||
originalElementsMap,
|
|
||||||
originalAppState,
|
|
||||||
shouldChangeByStepSize,
|
|
||||||
nextValue,
|
|
||||||
scene,
|
|
||||||
property,
|
|
||||||
}) => {
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
|
||||||
const atomicUnits = getAtomicUnits(originalElements, originalAppState);
|
|
||||||
if (nextValue !== undefined) {
|
|
||||||
for (const atomicUnit of atomicUnits) {
|
|
||||||
const elementsInUnit = getElementsInAtomicUnit(
|
|
||||||
atomicUnit,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (elementsInUnit.length > 1) {
|
|
||||||
const latestElements = elementsInUnit.map((el) => el.latest!);
|
|
||||||
const originalElements = elementsInUnit.map((el) => el.original!);
|
|
||||||
const [x1, y1, x2, y2] = getCommonBounds(originalElements);
|
|
||||||
const initialWidth = x2 - x1;
|
|
||||||
const initialHeight = y2 - y1;
|
|
||||||
const aspectRatio = initialWidth / initialHeight;
|
|
||||||
const nextWidth = Math.max(
|
|
||||||
MIN_WIDTH_OR_HEIGHT,
|
|
||||||
property === "width" ? Math.max(0, nextValue) : initialWidth,
|
|
||||||
);
|
|
||||||
const nextHeight = Math.max(
|
|
||||||
MIN_WIDTH_OR_HEIGHT,
|
|
||||||
property === "height" ? Math.max(0, nextValue) : initialHeight,
|
|
||||||
);
|
|
||||||
|
|
||||||
resizeGroup(
|
|
||||||
nextWidth,
|
|
||||||
nextHeight,
|
|
||||||
initialHeight,
|
|
||||||
aspectRatio,
|
|
||||||
[x1, y1],
|
|
||||||
property,
|
|
||||||
latestElements,
|
|
||||||
originalElements,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const [el] = elementsInUnit;
|
|
||||||
const latestElement = el?.latest;
|
|
||||||
const origElement = el?.original;
|
|
||||||
|
|
||||||
if (
|
|
||||||
latestElement &&
|
|
||||||
origElement &&
|
|
||||||
isPropertyEditable(latestElement, property)
|
|
||||||
) {
|
|
||||||
let nextWidth =
|
|
||||||
property === "width" ? Math.max(0, nextValue) : latestElement.width;
|
|
||||||
if (property === "width") {
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
|
||||||
} else {
|
|
||||||
nextWidth = Math.round(nextWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let nextHeight =
|
|
||||||
property === "height"
|
|
||||||
? Math.max(0, nextValue)
|
|
||||||
: latestElement.height;
|
|
||||||
if (property === "height") {
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
|
||||||
} else {
|
|
||||||
nextHeight = Math.round(nextHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
|
||||||
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
|
||||||
|
|
||||||
resizeElement(
|
|
||||||
nextWidth,
|
|
||||||
nextHeight,
|
|
||||||
false,
|
|
||||||
origElement,
|
|
||||||
elementsMap,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
|
||||||
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
|
||||||
|
|
||||||
for (const atomicUnit of atomicUnits) {
|
|
||||||
const elementsInUnit = getElementsInAtomicUnit(
|
|
||||||
atomicUnit,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (elementsInUnit.length > 1) {
|
|
||||||
const latestElements = elementsInUnit.map((el) => el.latest!);
|
|
||||||
const originalElements = elementsInUnit.map((el) => el.original!);
|
|
||||||
|
|
||||||
const [x1, y1, x2, y2] = getCommonBounds(originalElements);
|
|
||||||
const initialWidth = x2 - x1;
|
|
||||||
const initialHeight = y2 - y1;
|
|
||||||
const aspectRatio = initialWidth / initialHeight;
|
|
||||||
let nextWidth = Math.max(0, initialWidth + changeInWidth);
|
|
||||||
if (property === "width") {
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
|
||||||
} else {
|
|
||||||
nextWidth = Math.round(nextWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let nextHeight = Math.max(0, initialHeight + changeInHeight);
|
|
||||||
if (property === "height") {
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
|
||||||
} else {
|
|
||||||
nextHeight = Math.round(nextHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
|
||||||
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
|
||||||
|
|
||||||
resizeGroup(
|
|
||||||
nextWidth,
|
|
||||||
nextHeight,
|
|
||||||
initialHeight,
|
|
||||||
aspectRatio,
|
|
||||||
[x1, y1],
|
|
||||||
property,
|
|
||||||
latestElements,
|
|
||||||
originalElements,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const [el] = elementsInUnit;
|
|
||||||
const latestElement = el?.latest;
|
|
||||||
const origElement = el?.original;
|
|
||||||
|
|
||||||
if (
|
|
||||||
latestElement &&
|
|
||||||
origElement &&
|
|
||||||
isPropertyEditable(latestElement, property)
|
|
||||||
) {
|
|
||||||
let nextWidth = Math.max(0, origElement.width + changeInWidth);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
|
||||||
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
|
||||||
|
|
||||||
resizeElement(nextWidth, nextHeight, false, origElement, elementsMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
|
||||||
};
|
|
||||||
|
|
||||||
const MultiDimension = ({
|
const MultiDimension = ({
|
||||||
property,
|
property,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
atomicUnits,
|
|
||||||
scene,
|
|
||||||
appState,
|
|
||||||
}: MultiDimensionProps) => {
|
}: MultiDimensionProps) => {
|
||||||
const sizes = useMemo(
|
const handleDimensionChange: DragInputCallbackType = ({
|
||||||
() =>
|
accumulatedChange,
|
||||||
atomicUnits.map((atomicUnit) => {
|
stateAtStart,
|
||||||
const elementsInUnit = getElementsInAtomicUnit(atomicUnit, elementsMap);
|
originalElementsMap,
|
||||||
|
shouldChangeByStepSize,
|
||||||
|
nextValue,
|
||||||
|
}) => {
|
||||||
|
const [x1, y1, x2, y2] = getCommonBounds(stateAtStart);
|
||||||
|
const initialWidth = x2 - x1;
|
||||||
|
const initialHeight = y2 - y1;
|
||||||
|
const keepAspectRatio = true;
|
||||||
|
const aspectRatio = initialWidth / initialHeight;
|
||||||
|
|
||||||
if (elementsInUnit.length > 1) {
|
if (nextValue !== undefined) {
|
||||||
const [x1, y1, x2, y2] = getCommonBounds(
|
const nextHeight =
|
||||||
elementsInUnit.map((el) => el.latest),
|
property === "height" ? nextValue : nextValue / aspectRatio;
|
||||||
);
|
|
||||||
return (
|
const scale = nextHeight / initialHeight;
|
||||||
Math.round((property === "width" ? x2 - x1 : y2 - y1) * 100) / 100
|
const anchorX = property === "width" ? x1 : x1 + width / 2;
|
||||||
|
const anchorY = property === "height" ? y1 : y1 + height / 2;
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
while (i < stateAtStart.length) {
|
||||||
|
const latestElement = elements[i];
|
||||||
|
const origElement = stateAtStart[i];
|
||||||
|
|
||||||
|
// it should never happen that element and origElement are different
|
||||||
|
// but check just in case
|
||||||
|
if (latestElement.id === origElement.id) {
|
||||||
|
resizeElement(
|
||||||
|
anchorX,
|
||||||
|
anchorY,
|
||||||
|
property,
|
||||||
|
scale,
|
||||||
|
latestElement,
|
||||||
|
origElement,
|
||||||
|
elementsMap,
|
||||||
|
originalElementsMap,
|
||||||
|
i === stateAtStart.length - 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const [el] = elementsInUnit;
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return;
|
||||||
Math.round(
|
}
|
||||||
(property === "width" ? el.latest.width : el.latest.height) * 100,
|
|
||||||
) / 100
|
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
||||||
|
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
||||||
|
|
||||||
|
let nextWidth = Math.max(0, initialWidth + changeInWidth);
|
||||||
|
if (property === "width") {
|
||||||
|
if (shouldChangeByStepSize) {
|
||||||
|
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
||||||
|
} else {
|
||||||
|
nextWidth = Math.round(nextWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let nextHeight = Math.max(0, initialHeight + 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const scale = nextHeight / initialHeight;
|
||||||
|
const anchorX = property === "width" ? x1 : x1 + width / 2;
|
||||||
|
const anchorY = property === "height" ? y1 : y1 + height / 2;
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
while (i < stateAtStart.length) {
|
||||||
|
const latestElement = elements[i];
|
||||||
|
const origElement = stateAtStart[i];
|
||||||
|
|
||||||
|
if (latestElement.id === origElement.id) {
|
||||||
|
resizeElement(
|
||||||
|
anchorX,
|
||||||
|
anchorY,
|
||||||
|
property,
|
||||||
|
scale,
|
||||||
|
latestElement,
|
||||||
|
origElement,
|
||||||
|
elementsMap,
|
||||||
|
originalElementsMap,
|
||||||
|
i === stateAtStart.length - 1,
|
||||||
);
|
);
|
||||||
}),
|
}
|
||||||
[elementsMap, atomicUnits, property],
|
i++;
|
||||||
);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const value =
|
const [x1, y1, x2, y2] = getCommonBounds(elements);
|
||||||
new Set(sizes).size === 1 ? Math.round(sizes[0] * 100) / 100 : "Mixed";
|
const width = x2 - x1;
|
||||||
|
const height = y2 - y1;
|
||||||
const editable = sizes.length > 0;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DragInput
|
<DragInput
|
||||||
label={property === "width" ? "W" : "H"}
|
label={property === "width" ? "W" : "H"}
|
||||||
elements={elements}
|
elements={elements}
|
||||||
dragInputCallback={handleDimensionChange}
|
dragInputCallback={handleDimensionChange}
|
||||||
value={value}
|
value={Math.round((property === "width" ? width : height) * 100) / 100}
|
||||||
editable={editable}
|
|
||||||
appState={appState}
|
|
||||||
property={property}
|
|
||||||
scene={scene}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,164 +0,0 @@
|
|||||||
import { isTextElement, redrawTextBoundingBox } from "../../element";
|
|
||||||
import { mutateElement } from "../../element/mutateElement";
|
|
||||||
import { hasBoundTextElement } from "../../element/typeChecks";
|
|
||||||
import type {
|
|
||||||
ExcalidrawElement,
|
|
||||||
ExcalidrawTextElement,
|
|
||||||
NonDeletedSceneElementsMap,
|
|
||||||
} from "../../element/types";
|
|
||||||
import { isInGroup } from "../../groups";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import { fontSizeIcon } from "../icons";
|
|
||||||
import StatsDragInput from "./DragInput";
|
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
|
||||||
import { getStepSizedValue } from "./utils";
|
|
||||||
import type { AppState } from "../../types";
|
|
||||||
import { getBoundTextElement } from "../../element/textElement";
|
|
||||||
|
|
||||||
interface MultiFontSizeProps {
|
|
||||||
elements: readonly ExcalidrawElement[];
|
|
||||||
scene: Scene;
|
|
||||||
elementsMap: NonDeletedSceneElementsMap;
|
|
||||||
appState: AppState;
|
|
||||||
property: "fontSize";
|
|
||||||
}
|
|
||||||
|
|
||||||
const MIN_FONT_SIZE = 4;
|
|
||||||
const STEP_SIZE = 4;
|
|
||||||
|
|
||||||
const getApplicableTextElements = (
|
|
||||||
elements: readonly (ExcalidrawElement | undefined)[],
|
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
|
||||||
) =>
|
|
||||||
elements.reduce(
|
|
||||||
(acc: ExcalidrawTextElement[], el) => {
|
|
||||||
if (!el || isInGroup(el)) {
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
if (isTextElement(el)) {
|
|
||||||
acc.push(el);
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
if (hasBoundTextElement(el)) {
|
|
||||||
const boundTextElement = getBoundTextElement(el, elementsMap);
|
|
||||||
if (boundTextElement) {
|
|
||||||
acc.push(boundTextElement);
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleFontSizeChange: DragInputCallbackType<
|
|
||||||
MultiFontSizeProps["property"],
|
|
||||||
ExcalidrawTextElement
|
|
||||||
> = ({
|
|
||||||
accumulatedChange,
|
|
||||||
originalElements,
|
|
||||||
shouldChangeByStepSize,
|
|
||||||
nextValue,
|
|
||||||
scene,
|
|
||||||
}) => {
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
|
||||||
const latestTextElements = originalElements.map((el) =>
|
|
||||||
elementsMap.get(el.id),
|
|
||||||
) as ExcalidrawTextElement[];
|
|
||||||
|
|
||||||
let nextFontSize;
|
|
||||||
|
|
||||||
if (nextValue) {
|
|
||||||
nextFontSize = Math.max(Math.round(nextValue), MIN_FONT_SIZE);
|
|
||||||
|
|
||||||
for (const textElement of latestTextElements) {
|
|
||||||
mutateElement(
|
|
||||||
textElement,
|
|
||||||
{
|
|
||||||
fontSize: nextFontSize,
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
redrawTextBoundingBox(
|
|
||||||
textElement,
|
|
||||||
scene.getContainerElement(textElement),
|
|
||||||
elementsMap,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
|
||||||
} else {
|
|
||||||
const originalTextElements = originalElements as ExcalidrawTextElement[];
|
|
||||||
|
|
||||||
for (let i = 0; i < latestTextElements.length; i++) {
|
|
||||||
const latestElement = latestTextElements[i];
|
|
||||||
const originalElement = originalTextElements[i];
|
|
||||||
|
|
||||||
const originalFontSize = Math.round(originalElement.fontSize);
|
|
||||||
const changeInFontSize = Math.round(accumulatedChange);
|
|
||||||
let nextFontSize = Math.max(
|
|
||||||
originalFontSize + changeInFontSize,
|
|
||||||
MIN_FONT_SIZE,
|
|
||||||
);
|
|
||||||
if (shouldChangeByStepSize) {
|
|
||||||
nextFontSize = getStepSizedValue(nextFontSize, STEP_SIZE);
|
|
||||||
}
|
|
||||||
mutateElement(
|
|
||||||
latestElement,
|
|
||||||
{
|
|
||||||
fontSize: nextFontSize,
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
redrawTextBoundingBox(
|
|
||||||
latestElement,
|
|
||||||
scene.getContainerElement(latestElement),
|
|
||||||
elementsMap,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const MultiFontSize = ({
|
|
||||||
elements,
|
|
||||||
scene,
|
|
||||||
appState,
|
|
||||||
property,
|
|
||||||
elementsMap,
|
|
||||||
}: MultiFontSizeProps) => {
|
|
||||||
const latestTextElements = getApplicableTextElements(elements, elementsMap);
|
|
||||||
|
|
||||||
if (!latestTextElements.length) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fontSizes = latestTextElements.map(
|
|
||||||
(textEl) => Math.round(textEl.fontSize * 10) / 10,
|
|
||||||
);
|
|
||||||
const value = new Set(fontSizes).size === 1 ? fontSizes[0] : "Mixed";
|
|
||||||
const editable = fontSizes.length > 0;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StatsDragInput
|
|
||||||
label="F"
|
|
||||||
icon={fontSizeIcon}
|
|
||||||
elements={latestTextElements}
|
|
||||||
dragInputCallback={handleFontSizeChange}
|
|
||||||
value={value}
|
|
||||||
editable={editable}
|
|
||||||
scene={scene}
|
|
||||||
property={property}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MultiFontSize;
|
|
||||||
@@ -1,259 +0,0 @@
|
|||||||
import type {
|
|
||||||
ElementsMap,
|
|
||||||
ExcalidrawElement,
|
|
||||||
NonDeletedSceneElementsMap,
|
|
||||||
} from "../../element/types";
|
|
||||||
import { rotate } from "../../math";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import StatsDragInput from "./DragInput";
|
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
|
||||||
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
|
||||||
import { getCommonBounds, isTextElement } from "../../element";
|
|
||||||
import { useMemo } from "react";
|
|
||||||
import { getElementsInAtomicUnit, moveElement } from "./utils";
|
|
||||||
import type { AtomicUnit } from "./utils";
|
|
||||||
import type { AppState } from "../../types";
|
|
||||||
|
|
||||||
interface MultiPositionProps {
|
|
||||||
property: "x" | "y";
|
|
||||||
elements: readonly ExcalidrawElement[];
|
|
||||||
elementsMap: ElementsMap;
|
|
||||||
atomicUnits: AtomicUnit[];
|
|
||||||
scene: Scene;
|
|
||||||
appState: AppState;
|
|
||||||
}
|
|
||||||
|
|
||||||
const STEP_SIZE = 10;
|
|
||||||
|
|
||||||
const moveElements = (
|
|
||||||
property: MultiPositionProps["property"],
|
|
||||||
changeInTopX: number,
|
|
||||||
changeInTopY: number,
|
|
||||||
elements: readonly ExcalidrawElement[],
|
|
||||||
originalElements: readonly ExcalidrawElement[],
|
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
|
||||||
originalElementsMap: ElementsMap,
|
|
||||||
) => {
|
|
||||||
for (let i = 0; i < elements.length; i++) {
|
|
||||||
const origElement = originalElements[i];
|
|
||||||
|
|
||||||
const [cx, cy] = [
|
|
||||||
origElement.x + origElement.width / 2,
|
|
||||||
origElement.y + origElement.height / 2,
|
|
||||||
];
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
origElement.x,
|
|
||||||
origElement.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
origElement.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
const newTopLeftX =
|
|
||||||
property === "x" ? Math.round(topLeftX + changeInTopX) : topLeftX;
|
|
||||||
|
|
||||||
const newTopLeftY =
|
|
||||||
property === "y" ? Math.round(topLeftY + changeInTopY) : topLeftY;
|
|
||||||
|
|
||||||
moveElement(
|
|
||||||
newTopLeftX,
|
|
||||||
newTopLeftY,
|
|
||||||
origElement,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const moveGroupTo = (
|
|
||||||
nextX: number,
|
|
||||||
nextY: number,
|
|
||||||
originalElements: ExcalidrawElement[],
|
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
|
||||||
originalElementsMap: ElementsMap,
|
|
||||||
scene: Scene,
|
|
||||||
) => {
|
|
||||||
const [x1, y1, ,] = getCommonBounds(originalElements);
|
|
||||||
const offsetX = nextX - x1;
|
|
||||||
const offsetY = nextY - y1;
|
|
||||||
|
|
||||||
for (let i = 0; i < originalElements.length; i++) {
|
|
||||||
const origElement = originalElements[i];
|
|
||||||
|
|
||||||
const latestElement = elementsMap.get(origElement.id);
|
|
||||||
if (!latestElement) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// bound texts are moved with their containers
|
|
||||||
if (!isTextElement(latestElement) || !latestElement.containerId) {
|
|
||||||
const [cx, cy] = [
|
|
||||||
latestElement.x + latestElement.width / 2,
|
|
||||||
latestElement.y + latestElement.height / 2,
|
|
||||||
];
|
|
||||||
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
latestElement.x,
|
|
||||||
latestElement.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
latestElement.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
moveElement(
|
|
||||||
topLeftX + offsetX,
|
|
||||||
topLeftY + offsetY,
|
|
||||||
origElement,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePositionChange: DragInputCallbackType<
|
|
||||||
MultiPositionProps["property"]
|
|
||||||
> = ({
|
|
||||||
accumulatedChange,
|
|
||||||
originalElements,
|
|
||||||
originalElementsMap,
|
|
||||||
shouldChangeByStepSize,
|
|
||||||
nextValue,
|
|
||||||
property,
|
|
||||||
scene,
|
|
||||||
originalAppState,
|
|
||||||
}) => {
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
|
||||||
|
|
||||||
if (nextValue !== undefined) {
|
|
||||||
for (const atomicUnit of getAtomicUnits(
|
|
||||||
originalElements,
|
|
||||||
originalAppState,
|
|
||||||
)) {
|
|
||||||
const elementsInUnit = getElementsInAtomicUnit(
|
|
||||||
atomicUnit,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (elementsInUnit.length > 1) {
|
|
||||||
const [x1, y1, ,] = getCommonBounds(
|
|
||||||
elementsInUnit.map((el) => el.latest!),
|
|
||||||
);
|
|
||||||
const newTopLeftX = property === "x" ? nextValue : x1;
|
|
||||||
const newTopLeftY = property === "y" ? nextValue : y1;
|
|
||||||
|
|
||||||
moveGroupTo(
|
|
||||||
newTopLeftX,
|
|
||||||
newTopLeftY,
|
|
||||||
elementsInUnit.map((el) => el.original),
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
scene,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const origElement = elementsInUnit[0]?.original;
|
|
||||||
const latestElement = elementsInUnit[0]?.latest;
|
|
||||||
if (
|
|
||||||
origElement &&
|
|
||||||
latestElement &&
|
|
||||||
isPropertyEditable(latestElement, property)
|
|
||||||
) {
|
|
||||||
const [cx, cy] = [
|
|
||||||
origElement.x + origElement.width / 2,
|
|
||||||
origElement.y + origElement.height / 2,
|
|
||||||
];
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
origElement.x,
|
|
||||||
origElement.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
origElement.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
const newTopLeftX = property === "x" ? nextValue : topLeftX;
|
|
||||||
const newTopLeftY = property === "y" ? nextValue : topLeftY;
|
|
||||||
moveElement(
|
|
||||||
newTopLeftX,
|
|
||||||
newTopLeftY,
|
|
||||||
origElement,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const change = shouldChangeByStepSize
|
|
||||||
? getStepSizedValue(accumulatedChange, STEP_SIZE)
|
|
||||||
: accumulatedChange;
|
|
||||||
|
|
||||||
const changeInTopX = property === "x" ? change : 0;
|
|
||||||
const changeInTopY = property === "y" ? change : 0;
|
|
||||||
|
|
||||||
moveElements(
|
|
||||||
property,
|
|
||||||
changeInTopX,
|
|
||||||
changeInTopY,
|
|
||||||
originalElements,
|
|
||||||
originalElements,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
scene.triggerUpdate();
|
|
||||||
};
|
|
||||||
|
|
||||||
const MultiPosition = ({
|
|
||||||
property,
|
|
||||||
elements,
|
|
||||||
elementsMap,
|
|
||||||
atomicUnits,
|
|
||||||
scene,
|
|
||||||
appState,
|
|
||||||
}: MultiPositionProps) => {
|
|
||||||
const positions = useMemo(
|
|
||||||
() =>
|
|
||||||
atomicUnits.map((atomicUnit) => {
|
|
||||||
const elementsInUnit = Object.keys(atomicUnit)
|
|
||||||
.map((id) => elementsMap.get(id))
|
|
||||||
.filter((el) => el !== undefined) as ExcalidrawElement[];
|
|
||||||
|
|
||||||
// we're dealing with a group
|
|
||||||
if (elementsInUnit.length > 1) {
|
|
||||||
const [x1, y1] = getCommonBounds(elementsInUnit);
|
|
||||||
return Math.round((property === "x" ? x1 : y1) * 100) / 100;
|
|
||||||
}
|
|
||||||
const [el] = elementsInUnit;
|
|
||||||
const [cx, cy] = [el.x + el.width / 2, el.y + el.height / 2];
|
|
||||||
|
|
||||||
const [topLeftX, topLeftY] = rotate(el.x, el.y, cx, cy, el.angle);
|
|
||||||
|
|
||||||
return Math.round((property === "x" ? topLeftX : topLeftY) * 100) / 100;
|
|
||||||
}),
|
|
||||||
[atomicUnits, elementsMap, property],
|
|
||||||
);
|
|
||||||
|
|
||||||
const value = new Set(positions).size === 1 ? positions[0] : "Mixed";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StatsDragInput
|
|
||||||
label={property === "x" ? "X" : "Y"}
|
|
||||||
elements={elements}
|
|
||||||
dragInputCallback={handlePositionChange}
|
|
||||||
value={value}
|
|
||||||
property={property}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MultiPosition;
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
|
||||||
import { rotate } from "../../math";
|
|
||||||
import StatsDragInput from "./DragInput";
|
|
||||||
import type { DragInputCallbackType } from "./DragInput";
|
|
||||||
import { getStepSizedValue, moveElement } from "./utils";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import type { AppState } from "../../types";
|
|
||||||
|
|
||||||
interface PositionProps {
|
|
||||||
property: "x" | "y";
|
|
||||||
element: ExcalidrawElement;
|
|
||||||
elementsMap: ElementsMap;
|
|
||||||
scene: Scene;
|
|
||||||
appState: AppState;
|
|
||||||
}
|
|
||||||
|
|
||||||
const STEP_SIZE = 10;
|
|
||||||
|
|
||||||
const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
|
|
||||||
accumulatedChange,
|
|
||||||
originalElements,
|
|
||||||
originalElementsMap,
|
|
||||||
shouldChangeByStepSize,
|
|
||||||
nextValue,
|
|
||||||
property,
|
|
||||||
scene,
|
|
||||||
}) => {
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
|
||||||
const origElement = originalElements[0];
|
|
||||||
const [cx, cy] = [
|
|
||||||
origElement.x + origElement.width / 2,
|
|
||||||
origElement.y + origElement.height / 2,
|
|
||||||
];
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
origElement.x,
|
|
||||||
origElement.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
origElement.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (nextValue !== undefined) {
|
|
||||||
const newTopLeftX = property === "x" ? nextValue : topLeftX;
|
|
||||||
const newTopLeftY = property === "y" ? nextValue : topLeftY;
|
|
||||||
moveElement(
|
|
||||||
newTopLeftX,
|
|
||||||
newTopLeftY,
|
|
||||||
origElement,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const changeInTopX = property === "x" ? accumulatedChange : 0;
|
|
||||||
const changeInTopY = property === "y" ? accumulatedChange : 0;
|
|
||||||
|
|
||||||
const newTopLeftX =
|
|
||||||
property === "x"
|
|
||||||
? Math.round(
|
|
||||||
shouldChangeByStepSize
|
|
||||||
? getStepSizedValue(origElement.x + changeInTopX, STEP_SIZE)
|
|
||||||
: topLeftX + changeInTopX,
|
|
||||||
)
|
|
||||||
: topLeftX;
|
|
||||||
|
|
||||||
const newTopLeftY =
|
|
||||||
property === "y"
|
|
||||||
? Math.round(
|
|
||||||
shouldChangeByStepSize
|
|
||||||
? getStepSizedValue(origElement.y + changeInTopY, STEP_SIZE)
|
|
||||||
: topLeftY + changeInTopY,
|
|
||||||
)
|
|
||||||
: topLeftY;
|
|
||||||
|
|
||||||
moveElement(
|
|
||||||
newTopLeftX,
|
|
||||||
newTopLeftY,
|
|
||||||
origElement,
|
|
||||||
elementsMap,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Position = ({
|
|
||||||
property,
|
|
||||||
element,
|
|
||||||
elementsMap,
|
|
||||||
scene,
|
|
||||||
appState,
|
|
||||||
}: PositionProps) => {
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
element.x,
|
|
||||||
element.y,
|
|
||||||
element.x + element.width / 2,
|
|
||||||
element.y + element.height / 2,
|
|
||||||
element.angle,
|
|
||||||
);
|
|
||||||
const value =
|
|
||||||
Math.round((property === "x" ? topLeftX : topLeftY) * 100) / 100;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StatsDragInput
|
|
||||||
label={property === "x" ? "X" : "Y"}
|
|
||||||
elements={[element]}
|
|
||||||
dragInputCallback={handlePositionChange}
|
|
||||||
value={value}
|
|
||||||
property={property}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Position;
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
@import "../../css/variables.module.scss";
|
||||||
|
|
||||||
|
.excalidraw {
|
||||||
|
.Stats {
|
||||||
|
width: 204px;
|
||||||
|
position: absolute;
|
||||||
|
top: 64px;
|
||||||
|
right: 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
z-index: 10;
|
||||||
|
pointer-events: var(--ui-pointerEvents);
|
||||||
|
|
||||||
|
.sectionContent {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elementType {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elementsCount {
|
||||||
|
width: 100%;
|
||||||
|
font-size: 12px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statsItem {
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
.label {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin: 0 24px 8px 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close {
|
||||||
|
float: right;
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
svg {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
th {
|
||||||
|
border-bottom: 1px solid var(--input-border-color);
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
tr {
|
||||||
|
td:nth-child(2) {
|
||||||
|
min-width: 24px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.divider {
|
||||||
|
width: 100%;
|
||||||
|
height: 1px;
|
||||||
|
background-color: var(--default-border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[dir="rtl"] & {
|
||||||
|
left: 12px;
|
||||||
|
right: initial;
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin: 0 0 8px 24px;
|
||||||
|
}
|
||||||
|
.close {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import { useEffect, useMemo, useState, memo } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
import { getCommonBounds } from "../../element/bounds";
|
import { getCommonBounds } from "../../element/bounds";
|
||||||
import type { NonDeletedExcalidrawElement } from "../../element/types";
|
import type { NonDeletedExcalidrawElement } from "../../element/types";
|
||||||
import { t } from "../../i18n";
|
import { t } from "../../i18n";
|
||||||
|
import { getSelectedElements } from "../../scene";
|
||||||
|
import type Scene from "../../scene/Scene";
|
||||||
import type { AppState, ExcalidrawProps } from "../../types";
|
import type { AppState, ExcalidrawProps } from "../../types";
|
||||||
import { CloseIcon } from "../icons";
|
import { CloseIcon } from "../icons";
|
||||||
import { Island } from "../Island";
|
import { Island } from "../Island";
|
||||||
@@ -9,294 +11,165 @@ import { throttle } from "lodash";
|
|||||||
import Dimension from "./Dimension";
|
import Dimension from "./Dimension";
|
||||||
import Angle from "./Angle";
|
import Angle from "./Angle";
|
||||||
|
|
||||||
|
import "./index.scss";
|
||||||
import FontSize from "./FontSize";
|
import FontSize from "./FontSize";
|
||||||
import MultiDimension from "./MultiDimension";
|
import MultiDimension from "./MultiDimension";
|
||||||
import { elementsAreInSameGroup } from "../../groups";
|
import { elementsAreInSameGroup } from "../../groups";
|
||||||
import MultiAngle from "./MultiAngle";
|
|
||||||
import MultiFontSize from "./MultiFontSize";
|
|
||||||
import Position from "./Position";
|
|
||||||
import MultiPosition from "./MultiPosition";
|
|
||||||
import Collapsible from "./Collapsible";
|
|
||||||
import type Scene from "../../scene/Scene";
|
|
||||||
import { useExcalidrawAppState, useExcalidrawSetAppState } from "../App";
|
|
||||||
import { getAtomicUnits } from "./utils";
|
|
||||||
import { STATS_PANELS } from "../../constants";
|
|
||||||
|
|
||||||
interface StatsProps {
|
interface StatsProps {
|
||||||
|
appState: AppState;
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
renderCustomStats: ExcalidrawProps["renderCustomStats"];
|
renderCustomStats: ExcalidrawProps["renderCustomStats"];
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATS_TIMEOUT = 50;
|
const STATS_TIMEOUT = 50;
|
||||||
|
|
||||||
export const Stats = (props: StatsProps) => {
|
export const Stats = (props: StatsProps) => {
|
||||||
const appState = useExcalidrawAppState();
|
const elements = props.scene.getNonDeletedElements();
|
||||||
const sceneNonce = props.scene.getSceneNonce() || 1;
|
const elementsMap = props.scene.getNonDeletedElementsMap();
|
||||||
const selectedElements = props.scene.getSelectedElements({
|
const sceneNonce = props.scene.getSceneNonce();
|
||||||
selectedElementIds: appState.selectedElementIds,
|
// const selectedElements = getTargetElements(elements, props.appState);
|
||||||
includeBoundTextElement: false,
|
const selectedElements = getSelectedElements(
|
||||||
|
props.scene.getNonDeletedElementsMap(),
|
||||||
|
props.appState,
|
||||||
|
{
|
||||||
|
includeBoundTextElement: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const singleElement =
|
||||||
|
selectedElements.length === 1 ? selectedElements[0] : null;
|
||||||
|
|
||||||
|
const multipleElements =
|
||||||
|
selectedElements.length > 1 ? selectedElements : null;
|
||||||
|
|
||||||
|
const [sceneDimension, setSceneDimension] = useState<{
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
}>({
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const throttledSetSceneDimension = useMemo(
|
||||||
|
() =>
|
||||||
|
throttle((elements: readonly NonDeletedExcalidrawElement[]) => {
|
||||||
|
const boundingBox = getCommonBounds(elements);
|
||||||
|
setSceneDimension({
|
||||||
|
width: Math.round(boundingBox[2]) - Math.round(boundingBox[0]),
|
||||||
|
height: Math.round(boundingBox[3]) - Math.round(boundingBox[1]),
|
||||||
|
});
|
||||||
|
}, STATS_TIMEOUT),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
throttledSetSceneDimension(elements);
|
||||||
|
}, [sceneNonce, elements, throttledSetSceneDimension]);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => throttledSetSceneDimension.cancel(),
|
||||||
|
[throttledSetSceneDimension],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatsInner
|
<div className="Stats">
|
||||||
{...props}
|
<Island padding={3}>
|
||||||
appState={appState}
|
<div className="section">
|
||||||
sceneNonce={sceneNonce}
|
<div className="close" onClick={props.onClose}>
|
||||||
selectedElements={selectedElements}
|
{CloseIcon}
|
||||||
/>
|
</div>
|
||||||
|
<h3>{t("stats.generalStats")}</h3>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th colSpan={2}>{t("stats.scene")}</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.elements")}</td>
|
||||||
|
<td>{elements.length}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.width")}</td>
|
||||||
|
<td>{sceneDimension.width}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.height")}</td>
|
||||||
|
<td>{sceneDimension.height}</td>
|
||||||
|
</tr>
|
||||||
|
{props.renderCustomStats?.(elements, props.appState)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{selectedElements.length > 0 && (
|
||||||
|
<div
|
||||||
|
className="section"
|
||||||
|
style={{
|
||||||
|
marginTop: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h3>{t("stats.elementStats")}</h3>
|
||||||
|
|
||||||
|
{singleElement && (
|
||||||
|
<div className="sectionContent">
|
||||||
|
<div className="elementType">
|
||||||
|
{t(`element.${singleElement.type}`)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="statsItem">
|
||||||
|
<Dimension
|
||||||
|
property="width"
|
||||||
|
element={singleElement}
|
||||||
|
elementsMap={elementsMap}
|
||||||
|
/>
|
||||||
|
<Dimension
|
||||||
|
property="height"
|
||||||
|
element={singleElement}
|
||||||
|
elementsMap={elementsMap}
|
||||||
|
/>
|
||||||
|
<Angle element={singleElement} elementsMap={elementsMap} />
|
||||||
|
{singleElement.type === "text" && (
|
||||||
|
<FontSize
|
||||||
|
element={singleElement}
|
||||||
|
elementsMap={elementsMap}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{singleElement.type === "text" && <div></div>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{multipleElements && (
|
||||||
|
<div className="sectionContent">
|
||||||
|
{elementsAreInSameGroup(multipleElements) && (
|
||||||
|
<div className="elementType">{t("element.group")}</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="elementsCount">
|
||||||
|
<div>{t("stats.elements")}</div>
|
||||||
|
<div>{selectedElements.length}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="statsItem">
|
||||||
|
<MultiDimension
|
||||||
|
property="width"
|
||||||
|
elements={multipleElements}
|
||||||
|
elementsMap={elementsMap}
|
||||||
|
/>
|
||||||
|
<MultiDimension
|
||||||
|
property="height"
|
||||||
|
elements={multipleElements}
|
||||||
|
elementsMap={elementsMap}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Island>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const StatsInner = memo(
|
|
||||||
({
|
|
||||||
scene,
|
|
||||||
onClose,
|
|
||||||
renderCustomStats,
|
|
||||||
selectedElements,
|
|
||||||
appState,
|
|
||||||
sceneNonce,
|
|
||||||
}: StatsProps & {
|
|
||||||
sceneNonce: number;
|
|
||||||
selectedElements: readonly NonDeletedExcalidrawElement[];
|
|
||||||
appState: AppState;
|
|
||||||
}) => {
|
|
||||||
const elements = scene.getNonDeletedElements();
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
|
||||||
const setAppState = useExcalidrawSetAppState();
|
|
||||||
|
|
||||||
const singleElement =
|
|
||||||
selectedElements.length === 1 ? selectedElements[0] : null;
|
|
||||||
|
|
||||||
const multipleElements =
|
|
||||||
selectedElements.length > 1 ? selectedElements : null;
|
|
||||||
|
|
||||||
const [sceneDimension, setSceneDimension] = useState<{
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
}>({
|
|
||||||
width: 0,
|
|
||||||
height: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const throttledSetSceneDimension = useMemo(
|
|
||||||
() =>
|
|
||||||
throttle((elements: readonly NonDeletedExcalidrawElement[]) => {
|
|
||||||
const boundingBox = getCommonBounds(elements);
|
|
||||||
setSceneDimension({
|
|
||||||
width: Math.round(boundingBox[2]) - Math.round(boundingBox[0]),
|
|
||||||
height: Math.round(boundingBox[3]) - Math.round(boundingBox[1]),
|
|
||||||
});
|
|
||||||
}, STATS_TIMEOUT),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
throttledSetSceneDimension(elements);
|
|
||||||
}, [sceneNonce, elements, throttledSetSceneDimension]);
|
|
||||||
|
|
||||||
useEffect(
|
|
||||||
() => () => throttledSetSceneDimension.cancel(),
|
|
||||||
[throttledSetSceneDimension],
|
|
||||||
);
|
|
||||||
|
|
||||||
const atomicUnits = useMemo(() => {
|
|
||||||
return getAtomicUnits(selectedElements, appState);
|
|
||||||
}, [selectedElements, appState]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="Stats">
|
|
||||||
<Island padding={3}>
|
|
||||||
<div className="title">
|
|
||||||
<h2>{t("stats.title")}</h2>
|
|
||||||
<div className="close" onClick={onClose}>
|
|
||||||
{CloseIcon}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Collapsible
|
|
||||||
label={<h3>{t("stats.generalStats")}</h3>}
|
|
||||||
open={!!(appState.stats.panels & STATS_PANELS.generalStats)}
|
|
||||||
openTrigger={() =>
|
|
||||||
setAppState((state) => {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
stats: {
|
|
||||||
open: true,
|
|
||||||
panels: state.stats.panels ^ STATS_PANELS.generalStats,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th colSpan={2}>{t("stats.scene")}</th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{t("stats.elements")}</td>
|
|
||||||
<td>{elements.length}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{t("stats.width")}</td>
|
|
||||||
<td>{sceneDimension.width}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{t("stats.height")}</td>
|
|
||||||
<td>{sceneDimension.height}</td>
|
|
||||||
</tr>
|
|
||||||
{renderCustomStats?.(elements, appState)}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</Collapsible>
|
|
||||||
|
|
||||||
{selectedElements.length > 0 && (
|
|
||||||
<div
|
|
||||||
id="elementStats"
|
|
||||||
style={{
|
|
||||||
marginTop: 12,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Collapsible
|
|
||||||
label={<h3>{t("stats.elementProperties")}</h3>}
|
|
||||||
open={
|
|
||||||
!!(appState.stats.panels & STATS_PANELS.elementProperties)
|
|
||||||
}
|
|
||||||
openTrigger={() =>
|
|
||||||
setAppState((state) => {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
stats: {
|
|
||||||
open: true,
|
|
||||||
panels:
|
|
||||||
state.stats.panels ^ STATS_PANELS.elementProperties,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{singleElement && (
|
|
||||||
<div className="sectionContent">
|
|
||||||
<div className="elementType">
|
|
||||||
{t(`element.${singleElement.type}`)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="statsItem">
|
|
||||||
<Position
|
|
||||||
element={singleElement}
|
|
||||||
property="x"
|
|
||||||
elementsMap={elementsMap}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<Position
|
|
||||||
element={singleElement}
|
|
||||||
property="y"
|
|
||||||
elementsMap={elementsMap}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<Dimension
|
|
||||||
property="width"
|
|
||||||
element={singleElement}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<Dimension
|
|
||||||
property="height"
|
|
||||||
element={singleElement}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<Angle
|
|
||||||
property="angle"
|
|
||||||
element={singleElement}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<FontSize
|
|
||||||
property="fontSize"
|
|
||||||
element={singleElement}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{multipleElements && (
|
|
||||||
<div className="sectionContent">
|
|
||||||
{elementsAreInSameGroup(multipleElements) && (
|
|
||||||
<div className="elementType">{t("element.group")}</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="elementsCount">
|
|
||||||
<div>{t("stats.elements")}</div>
|
|
||||||
<div>{selectedElements.length}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="statsItem">
|
|
||||||
<MultiPosition
|
|
||||||
property="x"
|
|
||||||
elements={multipleElements}
|
|
||||||
elementsMap={elementsMap}
|
|
||||||
atomicUnits={atomicUnits}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<MultiPosition
|
|
||||||
property="y"
|
|
||||||
elements={multipleElements}
|
|
||||||
elementsMap={elementsMap}
|
|
||||||
atomicUnits={atomicUnits}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<MultiDimension
|
|
||||||
property="width"
|
|
||||||
elements={multipleElements}
|
|
||||||
elementsMap={elementsMap}
|
|
||||||
atomicUnits={atomicUnits}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<MultiDimension
|
|
||||||
property="height"
|
|
||||||
elements={multipleElements}
|
|
||||||
elementsMap={elementsMap}
|
|
||||||
atomicUnits={atomicUnits}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<MultiAngle
|
|
||||||
property="angle"
|
|
||||||
elements={multipleElements}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
<MultiFontSize
|
|
||||||
property="fontSize"
|
|
||||||
elements={multipleElements}
|
|
||||||
scene={scene}
|
|
||||||
appState={appState}
|
|
||||||
elementsMap={elementsMap}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Collapsible>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Island>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
(prev, next) => {
|
|
||||||
return (
|
|
||||||
prev.sceneNonce === next.sceneNonce &&
|
|
||||||
prev.selectedElements === next.selectedElements &&
|
|
||||||
prev.appState.stats.panels === next.appState.stats.panels
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -1,756 +0,0 @@
|
|||||||
import { fireEvent, queryByTestId } from "@testing-library/react";
|
|
||||||
import { Keyboard, Pointer, UI } from "../../tests/helpers/ui";
|
|
||||||
import { getStepSizedValue } from "./utils";
|
|
||||||
import {
|
|
||||||
GlobalTestState,
|
|
||||||
mockBoundingClientRect,
|
|
||||||
render,
|
|
||||||
restoreOriginalGetBoundingClientRect,
|
|
||||||
} from "../../tests/test-utils";
|
|
||||||
import * as StaticScene from "../../renderer/staticScene";
|
|
||||||
import { vi } from "vitest";
|
|
||||||
import { reseed } from "../../random";
|
|
||||||
import { setDateTimeForTests } from "../../utils";
|
|
||||||
import { Excalidraw, mutateElement } from "../..";
|
|
||||||
import { t } from "../../i18n";
|
|
||||||
import type {
|
|
||||||
ExcalidrawElement,
|
|
||||||
ExcalidrawLinearElement,
|
|
||||||
ExcalidrawTextElement,
|
|
||||||
} from "../../element/types";
|
|
||||||
import { degreeToRadian, rotate } from "../../math";
|
|
||||||
import { getTextEditor, updateTextEditor } from "../../tests/queries/dom";
|
|
||||||
import { getCommonBounds, isTextElement } from "../../element";
|
|
||||||
import { API } from "../../tests/helpers/api";
|
|
||||||
import { actionGroup } from "../../actions";
|
|
||||||
import { isInGroup } from "../../groups";
|
|
||||||
import React from "react";
|
|
||||||
|
|
||||||
const { h } = window;
|
|
||||||
const mouse = new Pointer("mouse");
|
|
||||||
const renderStaticScene = vi.spyOn(StaticScene, "renderStaticScene");
|
|
||||||
let stats: HTMLElement | null = null;
|
|
||||||
let elementStats: HTMLElement | null | undefined = null;
|
|
||||||
|
|
||||||
const editInput = (input: HTMLInputElement, value: string) => {
|
|
||||||
input.focus();
|
|
||||||
fireEvent.change(input, { target: { value } });
|
|
||||||
input.blur();
|
|
||||||
};
|
|
||||||
|
|
||||||
const getStatsProperty = (label: string) => {
|
|
||||||
const elementStats = UI.queryStats()?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
if (elementStats) {
|
|
||||||
const properties = elementStats?.querySelector(".statsItem");
|
|
||||||
return (
|
|
||||||
properties?.querySelector?.(
|
|
||||||
`.drag-input-container[data-testid="${label}"]`,
|
|
||||||
) || null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const testInputProperty = (
|
|
||||||
element: ExcalidrawElement,
|
|
||||||
property: "x" | "y" | "width" | "height" | "angle" | "fontSize",
|
|
||||||
label: string,
|
|
||||||
initialValue: number,
|
|
||||||
nextValue: number,
|
|
||||||
) => {
|
|
||||||
const input = getStatsProperty(label)?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(input).toBeDefined();
|
|
||||||
expect(input.value).toBe(initialValue.toString());
|
|
||||||
editInput(input, String(nextValue));
|
|
||||||
if (property === "angle") {
|
|
||||||
expect(element[property]).toBe(degreeToRadian(Number(nextValue)));
|
|
||||||
} else if (property === "fontSize" && isTextElement(element)) {
|
|
||||||
expect(element[property]).toBe(Number(nextValue));
|
|
||||||
} else if (property !== "fontSize") {
|
|
||||||
expect(element[property]).toBe(Number(nextValue));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("step sized value", () => {
|
|
||||||
it("should return edge values correctly", () => {
|
|
||||||
const steps = [10, 15, 20, 25, 30];
|
|
||||||
const values = [10, 15, 20, 25, 30];
|
|
||||||
|
|
||||||
steps.forEach((step, idx) => {
|
|
||||||
expect(getStepSizedValue(values[idx], step)).toEqual(values[idx]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("step sized value lies in the middle", () => {
|
|
||||||
let stepSize = 15;
|
|
||||||
let values = [7.5, 9, 12, 14.99, 15, 22.49];
|
|
||||||
|
|
||||||
values.forEach((value) => {
|
|
||||||
expect(getStepSizedValue(value, stepSize)).toEqual(15);
|
|
||||||
});
|
|
||||||
|
|
||||||
stepSize = 10;
|
|
||||||
values = [-5, 4.99, 0, 1.23];
|
|
||||||
values.forEach((value) => {
|
|
||||||
expect(getStepSizedValue(value, stepSize)).toEqual(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("binding with linear elements", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
localStorage.clear();
|
|
||||||
renderStaticScene.mockClear();
|
|
||||||
reseed(19);
|
|
||||||
setDateTimeForTests("201933152653");
|
|
||||||
|
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
||||||
|
|
||||||
h.elements = [];
|
|
||||||
|
|
||||||
fireEvent.contextMenu(GlobalTestState.interactiveCanvas, {
|
|
||||||
button: 2,
|
|
||||||
clientX: 1,
|
|
||||||
clientY: 1,
|
|
||||||
});
|
|
||||||
const contextMenu = UI.queryContextMenu();
|
|
||||||
fireEvent.click(queryByTestId(contextMenu!, "stats")!);
|
|
||||||
stats = UI.queryStats();
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(200, 100);
|
|
||||||
|
|
||||||
UI.clickTool("arrow");
|
|
||||||
mouse.down(5, 0);
|
|
||||||
mouse.up(300, 50);
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
mockBoundingClientRect();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
restoreOriginalGetBoundingClientRect();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should remain bound to linear element on small position change", async () => {
|
|
||||||
const linear = h.elements[1] as ExcalidrawLinearElement;
|
|
||||||
const inputX = getStatsProperty("X")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
expect(inputX).not.toBeNull();
|
|
||||||
editInput(inputX, String("204"));
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should remain bound to linear element on small angle change", async () => {
|
|
||||||
const linear = h.elements[1] as ExcalidrawLinearElement;
|
|
||||||
const inputAngle = getStatsProperty("A")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
editInput(inputAngle, String("1"));
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should unbind linear element on large position change", async () => {
|
|
||||||
const linear = h.elements[1] as ExcalidrawLinearElement;
|
|
||||||
const inputX = getStatsProperty("X")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
expect(inputX).not.toBeNull();
|
|
||||||
editInput(inputX, String("254"));
|
|
||||||
expect(linear.startBinding).toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should remain bound to linear element on small angle change", async () => {
|
|
||||||
const linear = h.elements[1] as ExcalidrawLinearElement;
|
|
||||||
const inputAngle = getStatsProperty("A")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(linear.startBinding).not.toBe(null);
|
|
||||||
editInput(inputAngle, String("45"));
|
|
||||||
expect(linear.startBinding).toBe(null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// single element
|
|
||||||
describe("stats for a generic element", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
localStorage.clear();
|
|
||||||
renderStaticScene.mockClear();
|
|
||||||
reseed(7);
|
|
||||||
setDateTimeForTests("201933152653");
|
|
||||||
|
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
||||||
|
|
||||||
h.elements = [];
|
|
||||||
|
|
||||||
fireEvent.contextMenu(GlobalTestState.interactiveCanvas, {
|
|
||||||
button: 2,
|
|
||||||
clientX: 1,
|
|
||||||
clientY: 1,
|
|
||||||
});
|
|
||||||
const contextMenu = UI.queryContextMenu();
|
|
||||||
fireEvent.click(queryByTestId(contextMenu!, "stats")!);
|
|
||||||
stats = UI.queryStats();
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(200, 100);
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
mockBoundingClientRect();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
restoreOriginalGetBoundingClientRect();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should open stats", () => {
|
|
||||||
expect(stats).toBeDefined();
|
|
||||||
expect(elementStats).toBeDefined();
|
|
||||||
|
|
||||||
// title
|
|
||||||
const title = elementStats?.querySelector("h3");
|
|
||||||
expect(title?.lastChild?.nodeValue)?.toBe(t("stats.elementProperties"));
|
|
||||||
|
|
||||||
// element type
|
|
||||||
const elementType = elementStats?.querySelector(".elementType");
|
|
||||||
expect(elementType).toBeDefined();
|
|
||||||
expect(elementType?.lastChild?.nodeValue).toBe(t("element.rectangle"));
|
|
||||||
|
|
||||||
// properties
|
|
||||||
const properties = elementStats?.querySelector(".statsItem");
|
|
||||||
expect(properties?.childNodes).toBeDefined();
|
|
||||||
["X", "Y", "W", "H", "A"].forEach((label) => () => {
|
|
||||||
expect(
|
|
||||||
properties?.querySelector?.(
|
|
||||||
`.drag-input-container[data-testid="${label}"]`,
|
|
||||||
),
|
|
||||||
).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should be able to edit all properties for a general element", () => {
|
|
||||||
const rectangle = h.elements[0];
|
|
||||||
const initialX = rectangle.x;
|
|
||||||
const initialY = rectangle.y;
|
|
||||||
|
|
||||||
testInputProperty(rectangle, "width", "W", 200, 100);
|
|
||||||
testInputProperty(rectangle, "height", "H", 100, 200);
|
|
||||||
testInputProperty(rectangle, "x", "X", initialX, 230);
|
|
||||||
testInputProperty(rectangle, "y", "Y", initialY, 220);
|
|
||||||
testInputProperty(rectangle, "angle", "A", 0, 45);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should keep only two decimal places", () => {
|
|
||||||
const rectangle = h.elements[0];
|
|
||||||
const rectangleId = rectangle.id;
|
|
||||||
|
|
||||||
const input = getStatsProperty("W")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(input).toBeDefined();
|
|
||||||
expect(input.value).toBe(rectangle.width.toString());
|
|
||||||
editInput(input, "123.123");
|
|
||||||
expect(h.elements.length).toBe(1);
|
|
||||||
expect(rectangle.id).toBe(rectangleId);
|
|
||||||
expect(input.value).toBe("123.12");
|
|
||||||
expect(rectangle.width).toBe(123.12);
|
|
||||||
|
|
||||||
editInput(input, "88.98766");
|
|
||||||
expect(input.value).toBe("88.99");
|
|
||||||
expect(rectangle.width).toBe(88.99);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should update input x and y when angle is changed", () => {
|
|
||||||
const rectangle = h.elements[0];
|
|
||||||
const [cx, cy] = [
|
|
||||||
rectangle.x + rectangle.width / 2,
|
|
||||||
rectangle.y + rectangle.height / 2,
|
|
||||||
];
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
rectangle.x,
|
|
||||||
rectangle.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
rectangle.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
const xInput = getStatsProperty("X")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
const yInput = getStatsProperty("Y")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(xInput.value).toBe(topLeftX.toString());
|
|
||||||
expect(yInput.value).toBe(topLeftY.toString());
|
|
||||||
|
|
||||||
testInputProperty(rectangle, "angle", "A", 0, 45);
|
|
||||||
|
|
||||||
let [newTopLeftX, newTopLeftY] = rotate(
|
|
||||||
rectangle.x,
|
|
||||||
rectangle.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
rectangle.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(newTopLeftX.toString()).not.toEqual(xInput.value);
|
|
||||||
expect(newTopLeftY.toString()).not.toEqual(yInput.value);
|
|
||||||
|
|
||||||
testInputProperty(rectangle, "angle", "A", 45, 66);
|
|
||||||
|
|
||||||
[newTopLeftX, newTopLeftY] = rotate(
|
|
||||||
rectangle.x,
|
|
||||||
rectangle.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
rectangle.angle,
|
|
||||||
);
|
|
||||||
expect(newTopLeftX.toString()).not.toEqual(xInput.value);
|
|
||||||
expect(newTopLeftY.toString()).not.toEqual(yInput.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should fix top left corner when width or height is changed", () => {
|
|
||||||
const rectangle = h.elements[0];
|
|
||||||
|
|
||||||
testInputProperty(rectangle, "angle", "A", 0, 45);
|
|
||||||
let [cx, cy] = [
|
|
||||||
rectangle.x + rectangle.width / 2,
|
|
||||||
rectangle.y + rectangle.height / 2,
|
|
||||||
];
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
rectangle.x,
|
|
||||||
rectangle.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
rectangle.angle,
|
|
||||||
);
|
|
||||||
testInputProperty(rectangle, "width", "W", rectangle.width, 400);
|
|
||||||
[cx, cy] = [
|
|
||||||
rectangle.x + rectangle.width / 2,
|
|
||||||
rectangle.y + rectangle.height / 2,
|
|
||||||
];
|
|
||||||
let [currentTopLeftX, currentTopLeftY] = rotate(
|
|
||||||
rectangle.x,
|
|
||||||
rectangle.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
rectangle.angle,
|
|
||||||
);
|
|
||||||
expect(currentTopLeftX).toBeCloseTo(topLeftX, 4);
|
|
||||||
expect(currentTopLeftY).toBeCloseTo(topLeftY, 4);
|
|
||||||
|
|
||||||
testInputProperty(rectangle, "height", "H", rectangle.height, 400);
|
|
||||||
[cx, cy] = [
|
|
||||||
rectangle.x + rectangle.width / 2,
|
|
||||||
rectangle.y + rectangle.height / 2,
|
|
||||||
];
|
|
||||||
[currentTopLeftX, currentTopLeftY] = rotate(
|
|
||||||
rectangle.x,
|
|
||||||
rectangle.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
rectangle.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(currentTopLeftX).toBeCloseTo(topLeftX, 4);
|
|
||||||
expect(currentTopLeftY).toBeCloseTo(topLeftY, 4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("stats for a non-generic element", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
localStorage.clear();
|
|
||||||
renderStaticScene.mockClear();
|
|
||||||
reseed(7);
|
|
||||||
setDateTimeForTests("201933152653");
|
|
||||||
|
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
||||||
|
|
||||||
h.elements = [];
|
|
||||||
|
|
||||||
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("text element", async () => {
|
|
||||||
UI.clickTool("text");
|
|
||||||
mouse.clickAt(20, 30);
|
|
||||||
const textEditorSelector = ".excalidraw-textEditorContainer > textarea";
|
|
||||||
const editor = await getTextEditor(textEditorSelector, true);
|
|
||||||
await new Promise((r) => setTimeout(r, 0));
|
|
||||||
updateTextEditor(editor, "Hello!");
|
|
||||||
editor.blur();
|
|
||||||
|
|
||||||
const text = h.elements[0] as ExcalidrawTextElement;
|
|
||||||
mouse.clickOn(text);
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
// can change font size
|
|
||||||
const input = getStatsProperty("F")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(input).toBeDefined();
|
|
||||||
expect(input.value).toBe(text.fontSize.toString());
|
|
||||||
editInput(input, "36");
|
|
||||||
expect(text.fontSize).toBe(36);
|
|
||||||
|
|
||||||
// cannot change width or height
|
|
||||||
const width = getStatsProperty("W")?.querySelector(".drag-input");
|
|
||||||
expect(width).toBeUndefined();
|
|
||||||
const height = getStatsProperty("H")?.querySelector(".drag-input");
|
|
||||||
expect(height).toBeUndefined();
|
|
||||||
|
|
||||||
// min font size is 4
|
|
||||||
editInput(input, "0");
|
|
||||||
expect(text.fontSize).not.toBe(0);
|
|
||||||
expect(text.fontSize).toBe(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("frame element", () => {
|
|
||||||
const frame = API.createElement({
|
|
||||||
id: "id0",
|
|
||||||
type: "frame",
|
|
||||||
x: 150,
|
|
||||||
width: 150,
|
|
||||||
});
|
|
||||||
h.elements = [frame];
|
|
||||||
h.setState({
|
|
||||||
selectedElementIds: {
|
|
||||||
[frame.id]: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
expect(elementStats).toBeDefined();
|
|
||||||
|
|
||||||
// cannot change angle
|
|
||||||
const angle = getStatsProperty("A")?.querySelector(".drag-input");
|
|
||||||
expect(angle).toBeUndefined();
|
|
||||||
|
|
||||||
// can change width or height
|
|
||||||
testInputProperty(frame, "width", "W", frame.width, 250);
|
|
||||||
testInputProperty(frame, "height", "H", frame.height, 500);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("image element", () => {
|
|
||||||
const image = API.createElement({ type: "image", width: 200, height: 100 });
|
|
||||||
h.elements = [image];
|
|
||||||
mouse.clickOn(image);
|
|
||||||
h.setState({
|
|
||||||
selectedElementIds: {
|
|
||||||
[image.id]: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
expect(elementStats).toBeDefined();
|
|
||||||
const widthToHeight = image.width / image.height;
|
|
||||||
|
|
||||||
// when width or height is changed, the aspect ratio is preserved
|
|
||||||
testInputProperty(image, "width", "W", image.width, 400);
|
|
||||||
expect(image.width).toBe(400);
|
|
||||||
expect(image.width / image.height).toBe(widthToHeight);
|
|
||||||
|
|
||||||
testInputProperty(image, "height", "H", image.height, 80);
|
|
||||||
expect(image.height).toBe(80);
|
|
||||||
expect(image.width / image.height).toBe(widthToHeight);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should display fontSize for bound text", () => {
|
|
||||||
const container = API.createElement({
|
|
||||||
type: "rectangle",
|
|
||||||
width: 200,
|
|
||||||
height: 100,
|
|
||||||
});
|
|
||||||
const text = API.createElement({
|
|
||||||
type: "text",
|
|
||||||
width: 200,
|
|
||||||
height: 100,
|
|
||||||
containerId: container.id,
|
|
||||||
fontSize: 20,
|
|
||||||
});
|
|
||||||
mutateElement(container, {
|
|
||||||
boundElements: [{ type: "text", id: text.id }],
|
|
||||||
});
|
|
||||||
h.elements = [container, text];
|
|
||||||
|
|
||||||
API.setSelectedElements([container]);
|
|
||||||
const fontSize = getStatsProperty("F")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(fontSize).toBeDefined();
|
|
||||||
|
|
||||||
editInput(fontSize, "40");
|
|
||||||
|
|
||||||
expect(text.fontSize).toBe(40);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// multiple elements
|
|
||||||
describe("stats for multiple elements", () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
mouse.reset();
|
|
||||||
localStorage.clear();
|
|
||||||
renderStaticScene.mockClear();
|
|
||||||
reseed(7);
|
|
||||||
setDateTimeForTests("201933152653");
|
|
||||||
|
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
||||||
|
|
||||||
h.elements = [];
|
|
||||||
|
|
||||||
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 display MIXED for elements with different values", () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(200, 100);
|
|
||||||
|
|
||||||
UI.clickTool("ellipse");
|
|
||||||
mouse.down(50, 50);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
UI.clickTool("diamond");
|
|
||||||
mouse.down(-100, -100);
|
|
||||||
mouse.up(125, 145);
|
|
||||||
|
|
||||||
h.setState({
|
|
||||||
selectedElementIds: h.elements.reduce((acc, el) => {
|
|
||||||
acc[el.id] = true;
|
|
||||||
return acc;
|
|
||||||
}, {} as Record<string, true>),
|
|
||||||
});
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
const width = getStatsProperty("W")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(width?.value).toBe("Mixed");
|
|
||||||
const height = getStatsProperty("H")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(height?.value).toBe("Mixed");
|
|
||||||
const angle = getStatsProperty("A")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(angle.value).toBe("0");
|
|
||||||
|
|
||||||
editInput(width, "250");
|
|
||||||
h.elements.forEach((el) => {
|
|
||||||
expect(el.width).toBe(250);
|
|
||||||
});
|
|
||||||
|
|
||||||
editInput(height, "450");
|
|
||||||
h.elements.forEach((el) => {
|
|
||||||
expect(el.height).toBe(450);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should display a property when one of the elements is editable for that property", async () => {
|
|
||||||
// text, rectangle, frame
|
|
||||||
UI.clickTool("text");
|
|
||||||
mouse.clickAt(20, 30);
|
|
||||||
const textEditorSelector = ".excalidraw-textEditorContainer > textarea";
|
|
||||||
const editor = await getTextEditor(textEditorSelector, true);
|
|
||||||
await new Promise((r) => setTimeout(r, 0));
|
|
||||||
updateTextEditor(editor, "Hello!");
|
|
||||||
editor.blur();
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(200, 100);
|
|
||||||
|
|
||||||
const frame = API.createElement({
|
|
||||||
type: "frame",
|
|
||||||
x: 150,
|
|
||||||
width: 150,
|
|
||||||
});
|
|
||||||
|
|
||||||
h.elements = [...h.elements, frame];
|
|
||||||
|
|
||||||
const text = h.elements.find((el) => el.type === "text");
|
|
||||||
const rectangle = h.elements.find((el) => el.type === "rectangle");
|
|
||||||
|
|
||||||
h.setState({
|
|
||||||
selectedElementIds: h.elements.reduce((acc, el) => {
|
|
||||||
acc[el.id] = true;
|
|
||||||
return acc;
|
|
||||||
}, {} as Record<string, true>),
|
|
||||||
});
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
const width = getStatsProperty("W")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(width).toBeDefined();
|
|
||||||
expect(width.value).toBe("Mixed");
|
|
||||||
|
|
||||||
const height = getStatsProperty("H")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(height).toBeDefined();
|
|
||||||
expect(height.value).toBe("Mixed");
|
|
||||||
|
|
||||||
const angle = getStatsProperty("A")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(angle).toBeDefined();
|
|
||||||
expect(angle.value).toBe("0");
|
|
||||||
|
|
||||||
const fontSize = getStatsProperty("F")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(fontSize).toBeDefined();
|
|
||||||
|
|
||||||
// changing width does not affect text
|
|
||||||
editInput(width, "200");
|
|
||||||
|
|
||||||
expect(rectangle?.width).toBe(200);
|
|
||||||
expect(frame.width).toBe(200);
|
|
||||||
expect(text?.width).not.toBe(200);
|
|
||||||
|
|
||||||
editInput(angle, "40");
|
|
||||||
|
|
||||||
const angleInRadian = degreeToRadian(40);
|
|
||||||
expect(rectangle?.angle).toBeCloseTo(angleInRadian, 4);
|
|
||||||
expect(text?.angle).toBeCloseTo(angleInRadian, 4);
|
|
||||||
expect(frame.angle).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should treat groups as single units", () => {
|
|
||||||
const createAndSelectGroup = () => {
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down();
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
UI.clickTool("rectangle");
|
|
||||||
mouse.down(0, 0);
|
|
||||||
mouse.up(100, 100);
|
|
||||||
|
|
||||||
mouse.reset();
|
|
||||||
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
||||||
mouse.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
h.app.actionManager.executeAction(actionGroup);
|
|
||||||
};
|
|
||||||
|
|
||||||
createAndSelectGroup();
|
|
||||||
|
|
||||||
const elementsInGroup = h.elements.filter((el) => isInGroup(el));
|
|
||||||
let [x1, y1, x2, y2] = getCommonBounds(elementsInGroup);
|
|
||||||
|
|
||||||
elementStats = stats?.querySelector("#elementStats");
|
|
||||||
|
|
||||||
const x = getStatsProperty("X")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(x).toBeDefined();
|
|
||||||
expect(Number(x.value)).toBe(x1);
|
|
||||||
|
|
||||||
editInput(x, "300");
|
|
||||||
|
|
||||||
expect(h.elements[0].x).toBe(300);
|
|
||||||
expect(h.elements[1].x).toBe(400);
|
|
||||||
expect(x.value).toBe("300");
|
|
||||||
|
|
||||||
const y = getStatsProperty("Y")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
|
|
||||||
expect(y).toBeDefined();
|
|
||||||
expect(Number(y.value)).toBe(y1);
|
|
||||||
|
|
||||||
editInput(y, "200");
|
|
||||||
|
|
||||||
expect(h.elements[0].y).toBe(200);
|
|
||||||
expect(h.elements[1].y).toBe(300);
|
|
||||||
expect(y.value).toBe("200");
|
|
||||||
|
|
||||||
const width = getStatsProperty("W")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(width).toBeDefined();
|
|
||||||
expect(Number(width.value)).toBe(200);
|
|
||||||
|
|
||||||
const height = getStatsProperty("H")?.querySelector(
|
|
||||||
".drag-input",
|
|
||||||
) as HTMLInputElement;
|
|
||||||
expect(height).toBeDefined();
|
|
||||||
expect(Number(height.value)).toBe(200);
|
|
||||||
|
|
||||||
editInput(width, "400");
|
|
||||||
|
|
||||||
[x1, y1, x2, y2] = getCommonBounds(elementsInGroup);
|
|
||||||
let newGroupWidth = x2 - x1;
|
|
||||||
|
|
||||||
expect(newGroupWidth).toBeCloseTo(400, 4);
|
|
||||||
|
|
||||||
editInput(width, "300");
|
|
||||||
|
|
||||||
[x1, y1, x2, y2] = getCommonBounds(elementsInGroup);
|
|
||||||
newGroupWidth = x2 - x1;
|
|
||||||
expect(newGroupWidth).toBeCloseTo(300, 4);
|
|
||||||
|
|
||||||
editInput(height, "500");
|
|
||||||
|
|
||||||
[x1, y1, x2, y2] = getCommonBounds(elementsInGroup);
|
|
||||||
const newGroupHeight = y2 - y1;
|
|
||||||
expect(newGroupHeight).toBeCloseTo(500, 4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,48 +1,5 @@
|
|||||||
import {
|
import { isFrameLikeElement, isTextElement } from "../../element/typeChecks";
|
||||||
bindOrUnbindLinearElements,
|
import type { ExcalidrawElement } from "../../element/types";
|
||||||
updateBoundElements,
|
|
||||||
} from "../../element/binding";
|
|
||||||
import { mutateElement } from "../../element/mutateElement";
|
|
||||||
import {
|
|
||||||
measureFontSizeFromWidth,
|
|
||||||
rescalePointsInElement,
|
|
||||||
} from "../../element/resizeElements";
|
|
||||||
import {
|
|
||||||
getApproxMinLineHeight,
|
|
||||||
getApproxMinLineWidth,
|
|
||||||
getBoundTextElement,
|
|
||||||
getBoundTextMaxWidth,
|
|
||||||
handleBindTextResize,
|
|
||||||
} from "../../element/textElement";
|
|
||||||
import {
|
|
||||||
isFrameLikeElement,
|
|
||||||
isLinearElement,
|
|
||||||
isTextElement,
|
|
||||||
} from "../../element/typeChecks";
|
|
||||||
import type {
|
|
||||||
ElementsMap,
|
|
||||||
ExcalidrawElement,
|
|
||||||
NonDeletedExcalidrawElement,
|
|
||||||
NonDeletedSceneElementsMap,
|
|
||||||
} from "../../element/types";
|
|
||||||
import {
|
|
||||||
getSelectedGroupIds,
|
|
||||||
getElementsInGroup,
|
|
||||||
isInGroup,
|
|
||||||
} from "../../groups";
|
|
||||||
import { rotate } from "../../math";
|
|
||||||
import type { AppState } from "../../types";
|
|
||||||
import { getFontString } from "../../utils";
|
|
||||||
|
|
||||||
export type StatsInputProperty =
|
|
||||||
| "x"
|
|
||||||
| "y"
|
|
||||||
| "width"
|
|
||||||
| "height"
|
|
||||||
| "angle"
|
|
||||||
| "fontSize";
|
|
||||||
|
|
||||||
export const SMALLEST_DELTA = 0.01;
|
|
||||||
|
|
||||||
export const isPropertyEditable = (
|
export const isPropertyEditable = (
|
||||||
element: ExcalidrawElement,
|
element: ExcalidrawElement,
|
||||||
@@ -64,238 +21,3 @@ export const getStepSizedValue = (value: number, stepSize: number) => {
|
|||||||
const v = value + stepSize / 2;
|
const v = value + stepSize / 2;
|
||||||
return v - (v % stepSize);
|
return v - (v % stepSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AtomicUnit = Record<string, true>;
|
|
||||||
export const getElementsInAtomicUnit = (
|
|
||||||
atomicUnit: AtomicUnit,
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
originalElementsMap?: ElementsMap,
|
|
||||||
) => {
|
|
||||||
return Object.keys(atomicUnit)
|
|
||||||
.map((id) => ({
|
|
||||||
original: (originalElementsMap ?? elementsMap).get(id),
|
|
||||||
latest: elementsMap.get(id),
|
|
||||||
}))
|
|
||||||
.filter((el) => el.original !== undefined && el.latest !== undefined) as {
|
|
||||||
original: NonDeletedExcalidrawElement;
|
|
||||||
latest: NonDeletedExcalidrawElement;
|
|
||||||
}[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const newOrigin = (
|
|
||||||
x1: number,
|
|
||||||
y1: number,
|
|
||||||
w1: number,
|
|
||||||
h1: number,
|
|
||||||
w2: number,
|
|
||||||
h2: number,
|
|
||||||
angle: number,
|
|
||||||
) => {
|
|
||||||
/**
|
|
||||||
* The formula below is the result of solving
|
|
||||||
* rotate(x1, y1, cx1, cy1, angle) = rotate(x2, y2, cx2, cy2, angle)
|
|
||||||
* where rotate is the function defined in math.ts
|
|
||||||
*
|
|
||||||
* This is so that the new origin (x2, y2),
|
|
||||||
* when rotated against the new center (cx2, cy2),
|
|
||||||
* coincides with (x1, y1) rotated against (cx1, cy1)
|
|
||||||
*
|
|
||||||
* The reason for doing this computation is so the element's top left corner
|
|
||||||
* on the canvas remains fixed after any changes in its dimension.
|
|
||||||
*/
|
|
||||||
|
|
||||||
return {
|
|
||||||
x:
|
|
||||||
x1 +
|
|
||||||
(w1 - w2) / 2 +
|
|
||||||
((w2 - w1) / 2) * Math.cos(angle) +
|
|
||||||
((h1 - h2) / 2) * Math.sin(angle),
|
|
||||||
y:
|
|
||||||
y1 +
|
|
||||||
(h1 - h2) / 2 +
|
|
||||||
((w2 - w1) / 2) * Math.sin(angle) +
|
|
||||||
((h2 - h1) / 2) * Math.cos(angle),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const resizeElement = (
|
|
||||||
nextWidth: number,
|
|
||||||
nextHeight: number,
|
|
||||||
keepAspectRatio: boolean,
|
|
||||||
origElement: ExcalidrawElement,
|
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
|
||||||
shouldInformMutation = true,
|
|
||||||
) => {
|
|
||||||
const latestElement = elementsMap.get(origElement.id);
|
|
||||||
if (!latestElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let boundTextFont: { fontSize?: number } = {};
|
|
||||||
const boundTextElement = getBoundTextElement(latestElement, elementsMap);
|
|
||||||
|
|
||||||
if (boundTextElement) {
|
|
||||||
const minWidth = getApproxMinLineWidth(
|
|
||||||
getFontString(boundTextElement),
|
|
||||||
boundTextElement.lineHeight,
|
|
||||||
);
|
|
||||||
const minHeight = getApproxMinLineHeight(
|
|
||||||
boundTextElement.fontSize,
|
|
||||||
boundTextElement.lineHeight,
|
|
||||||
);
|
|
||||||
nextWidth = Math.max(nextWidth, minWidth);
|
|
||||||
nextHeight = Math.max(nextHeight, minHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
mutateElement(
|
|
||||||
latestElement,
|
|
||||||
{
|
|
||||||
...newOrigin(
|
|
||||||
latestElement.x,
|
|
||||||
latestElement.y,
|
|
||||||
latestElement.width,
|
|
||||||
latestElement.height,
|
|
||||||
nextWidth,
|
|
||||||
nextHeight,
|
|
||||||
latestElement.angle,
|
|
||||||
),
|
|
||||||
width: nextWidth,
|
|
||||||
height: nextHeight,
|
|
||||||
...rescalePointsInElement(origElement, nextWidth, nextHeight, true),
|
|
||||||
},
|
|
||||||
shouldInformMutation,
|
|
||||||
);
|
|
||||||
updateBindings(latestElement, elementsMap, {
|
|
||||||
newSize: {
|
|
||||||
width: nextWidth,
|
|
||||||
height: nextHeight,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (boundTextElement) {
|
|
||||||
boundTextFont = {
|
|
||||||
fontSize: boundTextElement.fontSize,
|
|
||||||
};
|
|
||||||
if (keepAspectRatio) {
|
|
||||||
const updatedElement = {
|
|
||||||
...latestElement,
|
|
||||||
width: nextWidth,
|
|
||||||
height: nextHeight,
|
|
||||||
};
|
|
||||||
|
|
||||||
const nextFont = measureFontSizeFromWidth(
|
|
||||||
boundTextElement,
|
|
||||||
elementsMap,
|
|
||||||
getBoundTextMaxWidth(updatedElement, boundTextElement),
|
|
||||||
);
|
|
||||||
boundTextFont = {
|
|
||||||
fontSize: nextFont?.size ?? boundTextElement.fontSize,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (boundTextElement && boundTextFont) {
|
|
||||||
mutateElement(boundTextElement, {
|
|
||||||
fontSize: boundTextFont.fontSize,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
handleBindTextResize(latestElement, elementsMap, "e", keepAspectRatio);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const moveElement = (
|
|
||||||
newTopLeftX: number,
|
|
||||||
newTopLeftY: number,
|
|
||||||
originalElement: ExcalidrawElement,
|
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
|
||||||
originalElementsMap: ElementsMap,
|
|
||||||
shouldInformMutation = true,
|
|
||||||
) => {
|
|
||||||
const latestElement = elementsMap.get(originalElement.id);
|
|
||||||
if (!latestElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const [cx, cy] = [
|
|
||||||
originalElement.x + originalElement.width / 2,
|
|
||||||
originalElement.y + originalElement.height / 2,
|
|
||||||
];
|
|
||||||
const [topLeftX, topLeftY] = rotate(
|
|
||||||
originalElement.x,
|
|
||||||
originalElement.y,
|
|
||||||
cx,
|
|
||||||
cy,
|
|
||||||
originalElement.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
const changeInX = newTopLeftX - topLeftX;
|
|
||||||
const changeInY = newTopLeftY - topLeftY;
|
|
||||||
|
|
||||||
const [x, y] = rotate(
|
|
||||||
newTopLeftX,
|
|
||||||
newTopLeftY,
|
|
||||||
cx + changeInX,
|
|
||||||
cy + changeInY,
|
|
||||||
-originalElement.angle,
|
|
||||||
);
|
|
||||||
|
|
||||||
mutateElement(
|
|
||||||
latestElement,
|
|
||||||
{
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
},
|
|
||||||
shouldInformMutation,
|
|
||||||
);
|
|
||||||
updateBindings(latestElement, elementsMap);
|
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(
|
|
||||||
originalElement,
|
|
||||||
originalElementsMap,
|
|
||||||
);
|
|
||||||
if (boundTextElement) {
|
|
||||||
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
|
|
||||||
latestBoundTextElement &&
|
|
||||||
mutateElement(
|
|
||||||
latestBoundTextElement,
|
|
||||||
{
|
|
||||||
x: boundTextElement.x + changeInX,
|
|
||||||
y: boundTextElement.y + changeInY,
|
|
||||||
},
|
|
||||||
shouldInformMutation,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getAtomicUnits = (
|
|
||||||
targetElements: readonly ExcalidrawElement[],
|
|
||||||
appState: AppState,
|
|
||||||
) => {
|
|
||||||
const selectedGroupIds = getSelectedGroupIds(appState);
|
|
||||||
const _atomicUnits = selectedGroupIds.map((gid) => {
|
|
||||||
return getElementsInGroup(targetElements, gid).reduce((acc, el) => {
|
|
||||||
acc[el.id] = true;
|
|
||||||
return acc;
|
|
||||||
}, {} as AtomicUnit);
|
|
||||||
});
|
|
||||||
targetElements
|
|
||||||
.filter((el) => !isInGroup(el))
|
|
||||||
.forEach((el) => {
|
|
||||||
_atomicUnits.push({
|
|
||||||
[el.id]: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return _atomicUnits;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateBindings = (
|
|
||||||
latestElement: ExcalidrawElement,
|
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
|
||||||
options?: {
|
|
||||||
simultaneouslyUpdated?: readonly ExcalidrawElement[];
|
|
||||||
newSize?: { width: number; height: number };
|
|
||||||
},
|
|
||||||
) => {
|
|
||||||
if (isLinearElement(latestElement)) {
|
|
||||||
bindOrUnbindLinearElements([latestElement], elementsMap, true, []);
|
|
||||||
} else {
|
|
||||||
updateBoundElements(latestElement, elementsMap, options);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ $verticalBreakpoint: 861px;
|
|||||||
|
|
||||||
.ttd-dialog-output-error {
|
.ttd-dialog-output-error {
|
||||||
color: red;
|
color: red;
|
||||||
font-weight: 700;
|
font-weight: 800;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import type { MermaidConfig } from "@excalidraw/mermaid-to-excalidraw";
|
import type { MermaidOptions } from "@excalidraw/mermaid-to-excalidraw";
|
||||||
import type { MermaidToExcalidrawResult } from "@excalidraw/mermaid-to-excalidraw/dist/interfaces";
|
import type { MermaidToExcalidrawResult } from "@excalidraw/mermaid-to-excalidraw/dist/interfaces";
|
||||||
import { DEFAULT_EXPORT_PADDING, EDITOR_LS_KEYS } from "../../constants";
|
import {
|
||||||
|
DEFAULT_EXPORT_PADDING,
|
||||||
|
DEFAULT_FONT_SIZE,
|
||||||
|
EDITOR_LS_KEYS,
|
||||||
|
} from "../../constants";
|
||||||
import { convertToExcalidrawElements, exportToCanvas } from "../../index";
|
import { convertToExcalidrawElements, exportToCanvas } from "../../index";
|
||||||
import type { NonDeletedExcalidrawElement } from "../../element/types";
|
import type { NonDeletedExcalidrawElement } from "../../element/types";
|
||||||
import type { AppClassProperties, BinaryFiles } from "../../types";
|
import type { AppClassProperties, BinaryFiles } from "../../types";
|
||||||
@@ -34,7 +38,7 @@ export interface MermaidToExcalidrawLibProps {
|
|||||||
api: Promise<{
|
api: Promise<{
|
||||||
parseMermaidToExcalidraw: (
|
parseMermaidToExcalidraw: (
|
||||||
definition: string,
|
definition: string,
|
||||||
config?: MermaidConfig,
|
options: MermaidOptions,
|
||||||
) => Promise<MermaidToExcalidrawResult>;
|
) => Promise<MermaidToExcalidrawResult>;
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
@@ -74,10 +78,15 @@ export const convertMermaidToExcalidraw = async ({
|
|||||||
|
|
||||||
let ret;
|
let ret;
|
||||||
try {
|
try {
|
||||||
ret = await api.parseMermaidToExcalidraw(mermaidDefinition);
|
ret = await api.parseMermaidToExcalidraw(mermaidDefinition, {
|
||||||
|
fontSize: DEFAULT_FONT_SIZE,
|
||||||
|
});
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
ret = await api.parseMermaidToExcalidraw(
|
ret = await api.parseMermaidToExcalidraw(
|
||||||
mermaidDefinition.replace(/"/g, "'"),
|
mermaidDefinition.replace(/"/g, "'"),
|
||||||
|
{
|
||||||
|
fontSize: DEFAULT_FONT_SIZE,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const { elements, files } = ret;
|
const { elements, files } = ret;
|
||||||
|
|||||||
@@ -5,11 +5,10 @@
|
|||||||
--avatarList-gap: 0.625rem;
|
--avatarList-gap: 0.625rem;
|
||||||
--userList-padding: var(--space-factor);
|
--userList-padding: var(--space-factor);
|
||||||
|
|
||||||
.UserList__wrapper {
|
.UserList-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
align-items: center;
|
|
||||||
pointer-events: none !important;
|
pointer-events: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,6 +21,10 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--avatarList-gap);
|
gap: var(--avatarList-gap);
|
||||||
|
|
||||||
|
&:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
--max-size: calc(
|
--max-size: calc(
|
||||||
@@ -154,7 +157,66 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.UserList__collaborators {
|
.UserList__collaborators {
|
||||||
|
position: static;
|
||||||
top: auto;
|
top: auto;
|
||||||
|
margin-top: 0;
|
||||||
max-height: 50vh;
|
max-height: 50vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
border-top: 1px solid var(--userlist-collaborators-border-color);
|
||||||
|
border-bottom: 1px solid var(--userlist-collaborators-border-color);
|
||||||
|
|
||||||
|
&__empty {
|
||||||
|
color: var(--color-gray-60);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
line-height: 150%;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.UserList__hint {
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--userlist-hint-text-color);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.UserList__search-wrapper {
|
||||||
|
position: relative;
|
||||||
|
height: 2.5rem;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
left: 0.75rem;
|
||||||
|
width: 1.25rem;
|
||||||
|
height: 1.25rem;
|
||||||
|
color: var(--color-gray-40);
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.UserList__search {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 0 !important;
|
||||||
|
border-radius: 0 !important;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
padding-left: 2.5rem !important;
|
||||||
|
padding-right: 0.75rem !important;
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--color-gray-40);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,11 @@ import type { ActionManager } from "../actions/manager";
|
|||||||
|
|
||||||
import * as Popover from "@radix-ui/react-popover";
|
import * as Popover from "@radix-ui/react-popover";
|
||||||
import { Island } from "./Island";
|
import { Island } from "./Island";
|
||||||
import { QuickSearch } from "./QuickSearch";
|
import { searchIcon } from "./icons";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { isShallowEqual } from "../utils";
|
import { isShallowEqual } from "../utils";
|
||||||
import { supportsResizeObserver } from "../constants";
|
import { supportsResizeObserver } from "../constants";
|
||||||
import type { MarkRequired } from "../utility-types";
|
import type { MarkRequired } from "../utility-types";
|
||||||
import { ScrollableList } from "./ScrollableList";
|
|
||||||
|
|
||||||
export type GoToCollaboratorComponentProps = {
|
export type GoToCollaboratorComponentProps = {
|
||||||
socketId: SocketId;
|
socketId: SocketId;
|
||||||
@@ -41,7 +40,7 @@ const ConditionalTooltipWrapper = ({
|
|||||||
shouldWrap ? (
|
shouldWrap ? (
|
||||||
<Tooltip label={username || "Unknown user"}>{children}</Tooltip>
|
<Tooltip label={username || "Unknown user"}>{children}</Tooltip>
|
||||||
) : (
|
) : (
|
||||||
<>{children}</>
|
<React.Fragment>{children}</React.Fragment>
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderCollaborator = ({
|
const renderCollaborator = ({
|
||||||
@@ -129,10 +128,6 @@ export const UserList = React.memo(
|
|||||||
).filter((collaborator) => collaborator.username?.trim());
|
).filter((collaborator) => collaborator.username?.trim());
|
||||||
|
|
||||||
const [searchTerm, setSearchTerm] = React.useState("");
|
const [searchTerm, setSearchTerm] = React.useState("");
|
||||||
const filteredCollaborators = uniqueCollaboratorsArray.filter(
|
|
||||||
(collaborator) =>
|
|
||||||
collaborator.username?.toLowerCase().includes(searchTerm),
|
|
||||||
);
|
|
||||||
|
|
||||||
const userListWrapper = React.useRef<HTMLDivElement | null>(null);
|
const userListWrapper = React.useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
@@ -166,6 +161,14 @@ export const UserList = React.memo(
|
|||||||
|
|
||||||
const [maxAvatars, setMaxAvatars] = React.useState(DEFAULT_MAX_AVATARS);
|
const [maxAvatars, setMaxAvatars] = React.useState(DEFAULT_MAX_AVATARS);
|
||||||
|
|
||||||
|
const searchTermNormalized = searchTerm.trim().toLowerCase();
|
||||||
|
|
||||||
|
const filteredCollaborators = searchTermNormalized
|
||||||
|
? uniqueCollaboratorsArray.filter((collaborator) =>
|
||||||
|
collaborator.username?.toLowerCase().includes(searchTerm),
|
||||||
|
)
|
||||||
|
: uniqueCollaboratorsArray;
|
||||||
|
|
||||||
const firstNCollaborators = uniqueCollaboratorsArray.slice(
|
const firstNCollaborators = uniqueCollaboratorsArray.slice(
|
||||||
0,
|
0,
|
||||||
maxAvatars - 1,
|
maxAvatars - 1,
|
||||||
@@ -194,7 +197,7 @@ export const UserList = React.memo(
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="UserList__wrapper" ref={userListWrapper}>
|
<div className="UserList-wrapper" ref={userListWrapper}>
|
||||||
<div
|
<div
|
||||||
className={clsx("UserList", className)}
|
className={clsx("UserList", className)}
|
||||||
style={{ [`--max-avatars` as any]: maxAvatars }}
|
style={{ [`--max-avatars` as any]: maxAvatars }}
|
||||||
@@ -202,7 +205,13 @@ export const UserList = React.memo(
|
|||||||
{firstNAvatarsJSX}
|
{firstNAvatarsJSX}
|
||||||
|
|
||||||
{uniqueCollaboratorsArray.length > maxAvatars - 1 && (
|
{uniqueCollaboratorsArray.length > maxAvatars - 1 && (
|
||||||
<Popover.Root>
|
<Popover.Root
|
||||||
|
onOpenChange={(isOpen) => {
|
||||||
|
if (!isOpen) {
|
||||||
|
setSearchTerm("");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Popover.Trigger className="UserList__more">
|
<Popover.Trigger className="UserList__more">
|
||||||
+{uniqueCollaboratorsArray.length - maxAvatars + 1}
|
+{uniqueCollaboratorsArray.length - maxAvatars + 1}
|
||||||
</Popover.Trigger>
|
</Popover.Trigger>
|
||||||
@@ -215,43 +224,41 @@ export const UserList = React.memo(
|
|||||||
align="end"
|
align="end"
|
||||||
sideOffset={10}
|
sideOffset={10}
|
||||||
>
|
>
|
||||||
<Island padding={2}>
|
<Island style={{ overflow: "hidden" }}>
|
||||||
{uniqueCollaboratorsArray.length >=
|
{uniqueCollaboratorsArray.length >=
|
||||||
SHOW_COLLABORATORS_FILTER_AT && (
|
SHOW_COLLABORATORS_FILTER_AT && (
|
||||||
<QuickSearch
|
<div className="UserList__search-wrapper">
|
||||||
placeholder={t("quickSearch.placeholder")}
|
{searchIcon}
|
||||||
onChange={setSearchTerm}
|
<input
|
||||||
/>
|
className="UserList__search"
|
||||||
|
type="text"
|
||||||
|
placeholder={t("userList.search.placeholder")}
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => {
|
||||||
|
setSearchTerm(e.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
<ScrollableList
|
<div className="dropdown-menu UserList__collaborators">
|
||||||
className={"dropdown-menu UserList__collaborators"}
|
{filteredCollaborators.length === 0 && (
|
||||||
placeholder={t("userList.empty")}
|
<div className="UserList__collaborators__empty">
|
||||||
>
|
{t("userList.search.empty")}
|
||||||
{/* The list checks for `Children.count()`, hence defensively returning empty list */}
|
</div>
|
||||||
{filteredCollaborators.length > 0
|
)}
|
||||||
? [
|
<div className="UserList__hint">
|
||||||
<div className="hint">{t("userList.hint.text")}</div>,
|
{t("userList.hint.text")}
|
||||||
filteredCollaborators.map((collaborator) =>
|
</div>
|
||||||
renderCollaborator({
|
{filteredCollaborators.map((collaborator) =>
|
||||||
actionManager,
|
renderCollaborator({
|
||||||
collaborator,
|
actionManager,
|
||||||
socketId: collaborator.socketId,
|
collaborator,
|
||||||
withName: true,
|
socketId: collaborator.socketId,
|
||||||
isBeingFollowed:
|
withName: true,
|
||||||
collaborator.socketId === userToFollow,
|
isBeingFollowed: collaborator.socketId === userToFollow,
|
||||||
}),
|
}),
|
||||||
),
|
)}
|
||||||
]
|
</div>
|
||||||
: []}
|
|
||||||
</ScrollableList>
|
|
||||||
<Popover.Arrow
|
|
||||||
width={20}
|
|
||||||
height={10}
|
|
||||||
style={{
|
|
||||||
fill: "var(--popup-bg-color)",
|
|
||||||
filter: "drop-shadow(rgba(0, 0, 0, 0.05) 0px 3px 2px)",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Island>
|
</Island>
|
||||||
</Popover.Content>
|
</Popover.Content>
|
||||||
</Popover.Root>
|
</Popover.Root>
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import type {
|
|||||||
RenderableElementsMap,
|
RenderableElementsMap,
|
||||||
RenderInteractiveSceneCallback,
|
RenderInteractiveSceneCallback,
|
||||||
} from "../../scene/types";
|
} from "../../scene/types";
|
||||||
import type {
|
import type { NonDeletedExcalidrawElement } from "../../element/types";
|
||||||
NonDeletedExcalidrawElement,
|
|
||||||
NonDeletedSceneElementsMap,
|
|
||||||
} from "../../element/types";
|
|
||||||
import { isRenderThrottlingEnabled } from "../../reactUtils";
|
import { isRenderThrottlingEnabled } from "../../reactUtils";
|
||||||
import { renderInteractiveScene } from "../../renderer/interactiveScene";
|
import { renderInteractiveScene } from "../../renderer/interactiveScene";
|
||||||
|
|
||||||
@@ -22,7 +19,6 @@ type InteractiveCanvasProps = {
|
|||||||
elementsMap: RenderableElementsMap;
|
elementsMap: RenderableElementsMap;
|
||||||
visibleElements: readonly NonDeletedExcalidrawElement[];
|
visibleElements: readonly NonDeletedExcalidrawElement[];
|
||||||
selectedElements: readonly NonDeletedExcalidrawElement[];
|
selectedElements: readonly NonDeletedExcalidrawElement[];
|
||||||
allElementsMap: NonDeletedSceneElementsMap;
|
|
||||||
sceneNonce: number | undefined;
|
sceneNonce: number | undefined;
|
||||||
selectionNonce: number | undefined;
|
selectionNonce: number | undefined;
|
||||||
scale: number;
|
scale: number;
|
||||||
@@ -126,7 +122,6 @@ const InteractiveCanvas = (props: InteractiveCanvasProps) => {
|
|||||||
elementsMap: props.elementsMap,
|
elementsMap: props.elementsMap,
|
||||||
visibleElements: props.visibleElements,
|
visibleElements: props.visibleElements,
|
||||||
selectedElements: props.selectedElements,
|
selectedElements: props.selectedElements,
|
||||||
allElementsMap: props.allElementsMap,
|
|
||||||
scale: window.devicePixelRatio,
|
scale: window.devicePixelRatio,
|
||||||
appState: props.appState,
|
appState: props.appState,
|
||||||
renderConfig: {
|
renderConfig: {
|
||||||
@@ -202,7 +197,6 @@ const getRelevantAppStateProps = (
|
|||||||
activeEmbeddable: appState.activeEmbeddable,
|
activeEmbeddable: appState.activeEmbeddable,
|
||||||
snapLines: appState.snapLines,
|
snapLines: appState.snapLines,
|
||||||
zenModeEnabled: appState.zenModeEnabled,
|
zenModeEnabled: appState.zenModeEnabled,
|
||||||
editingElement: appState.editingElement,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const areEqual = (
|
const areEqual = (
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ const getRelevantAppStateProps = (
|
|||||||
selectedElementIds: appState.selectedElementIds,
|
selectedElementIds: appState.selectedElementIds,
|
||||||
frameToHighlight: appState.frameToHighlight,
|
frameToHighlight: appState.frameToHighlight,
|
||||||
editingGroupId: appState.editingGroupId,
|
editingGroupId: appState.editingGroupId,
|
||||||
currentHoveredFontFamily: appState.currentHoveredFontFamily,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const areEqual = (
|
const areEqual = (
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
.dropdown-menu {
|
.dropdown-menu {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 100%;
|
top: 100%;
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.25rem;
|
||||||
|
|
||||||
&--mobile {
|
&--mobile {
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -35,69 +35,21 @@
|
|||||||
|
|
||||||
.dropdown-menu-item-base {
|
.dropdown-menu-item-base {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
padding: 0 0.625rem;
|
||||||
column-gap: 0.625rem;
|
column-gap: 0.625rem;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
color: var(--color-on-surface);
|
color: var(--color-on-surface);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
font-weight: 400;
|
font-weight: normal;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.manual-hover {
|
|
||||||
// disable built-in hover due to keyboard navigation
|
|
||||||
.dropdown-menu-item {
|
|
||||||
&:hover {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
&--hovered {
|
|
||||||
background-color: var(--button-hover-bg) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
&--selected {
|
|
||||||
background-color: var(--color-primary-light) !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.fonts {
|
|
||||||
margin-top: 1rem;
|
|
||||||
// display max 7 items per list, where each has 2rem (2.25) height and 1px margin top & bottom
|
|
||||||
// count in 2 groups, where each allocates 1.3*0.75rem font-size and 0.5rem margin bottom, plus one extra 1rem margin top
|
|
||||||
max-height: calc(7 * (2rem + 2px) + 2 * (0.5rem + 1.3 * 0.75rem) + 1rem);
|
|
||||||
|
|
||||||
@media screen and (min-width: 1921px) {
|
|
||||||
max-height: calc(
|
|
||||||
7 * (2.25rem + 2px) + 2 * (0.5rem + 1.3 * 0.75rem) + 1rem
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu-item-base {
|
|
||||||
display: inline-flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu-group:not(:first-child) {
|
|
||||||
margin-top: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu-group-title {
|
|
||||||
font-size: 0.75rem;
|
|
||||||
text-align: left;
|
|
||||||
font-weight: 400;
|
|
||||||
margin: 0 0 0.5rem;
|
|
||||||
line-height: 1.3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu-item {
|
.dropdown-menu-item {
|
||||||
height: 2rem;
|
|
||||||
margin: 1px;
|
|
||||||
padding: 0 0.5rem;
|
|
||||||
width: calc(100% - 2px);
|
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
height: 2rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border-radius: var(--border-radius-md);
|
border-radius: var(--border-radius-md);
|
||||||
|
|
||||||
@@ -105,6 +57,11 @@
|
|||||||
height: 2.25rem;
|
height: 2.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--selected {
|
||||||
|
background: var(--color-primary-light);
|
||||||
|
--icon-fill-color: var(--color-primary-darker);
|
||||||
|
}
|
||||||
|
|
||||||
&__text {
|
&__text {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -126,11 +83,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&--selected {
|
|
||||||
background: var(--color-primary-light);
|
|
||||||
--icon-fill-color: var(--color-primary-darker);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--button-hover-bg);
|
background-color: var(--button-hover-bg);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|||||||
@@ -1,62 +1,37 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
import React from "react";
|
||||||
import {
|
import {
|
||||||
getDropdownMenuItemClassName,
|
getDropdownMenuItemClassName,
|
||||||
useHandleDropdownMenuItemClick,
|
useHandleDropdownMenuItemClick,
|
||||||
} from "./common";
|
} from "./common";
|
||||||
import MenuItemContent from "./DropdownMenuItemContent";
|
import MenuItemContent from "./DropdownMenuItemContent";
|
||||||
import { useExcalidrawAppState } from "../App";
|
|
||||||
import { THEME } from "../../constants";
|
|
||||||
import type { ValueOf } from "../../utility-types";
|
|
||||||
|
|
||||||
const DropdownMenuItem = ({
|
const DropdownMenuItem = ({
|
||||||
icon,
|
icon,
|
||||||
value,
|
onSelect,
|
||||||
order,
|
|
||||||
children,
|
children,
|
||||||
shortcut,
|
shortcut,
|
||||||
className,
|
className,
|
||||||
hovered,
|
|
||||||
selected,
|
selected,
|
||||||
textStyle,
|
|
||||||
onSelect,
|
|
||||||
onClick,
|
|
||||||
...rest
|
...rest
|
||||||
}: {
|
}: {
|
||||||
icon?: JSX.Element;
|
icon?: JSX.Element;
|
||||||
value?: string | number | undefined;
|
onSelect: (event: Event) => void;
|
||||||
order?: number;
|
|
||||||
onSelect?: (event: Event) => void;
|
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
hovered?: boolean;
|
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
textStyle?: React.CSSProperties;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
||||||
const handleClick = useHandleDropdownMenuItemClick(onClick, onSelect);
|
const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect);
|
||||||
const ref = useRef<HTMLButtonElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (hovered) {
|
|
||||||
if (order === 0) {
|
|
||||||
// scroll into the first item differently, so it's visible what is above (i.e. group title)
|
|
||||||
ref.current?.scrollIntoView({ block: "end" });
|
|
||||||
} else {
|
|
||||||
ref.current?.scrollIntoView({ block: "nearest" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [hovered, order]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
{...rest}
|
{...rest}
|
||||||
ref={ref}
|
|
||||||
value={value}
|
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
className={getDropdownMenuItemClassName(className, selected, hovered)}
|
type="button"
|
||||||
|
className={getDropdownMenuItemClassName(className, selected)}
|
||||||
title={rest.title ?? rest["aria-label"]}
|
title={rest.title ?? rest["aria-label"]}
|
||||||
>
|
>
|
||||||
<MenuItemContent textStyle={textStyle} icon={icon} shortcut={shortcut}>
|
<MenuItemContent icon={icon} shortcut={shortcut}>
|
||||||
{children}
|
{children}
|
||||||
</MenuItemContent>
|
</MenuItemContent>
|
||||||
</button>
|
</button>
|
||||||
@@ -64,53 +39,24 @@ const DropdownMenuItem = ({
|
|||||||
};
|
};
|
||||||
DropdownMenuItem.displayName = "DropdownMenuItem";
|
DropdownMenuItem.displayName = "DropdownMenuItem";
|
||||||
|
|
||||||
export const DropDownMenuItemBadgeType = {
|
|
||||||
GREEN: "green",
|
|
||||||
RED: "red",
|
|
||||||
BLUE: "blue",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const DropDownMenuItemBadge = ({
|
export const DropDownMenuItemBadge = ({
|
||||||
type = DropDownMenuItemBadgeType.BLUE,
|
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
type?: ValueOf<typeof DropDownMenuItemBadgeType>;
|
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
const { theme } = useExcalidrawAppState();
|
return (
|
||||||
const style = {
|
<div
|
||||||
display: "inline-flex",
|
style={{
|
||||||
marginLeft: "auto",
|
display: "inline-flex",
|
||||||
padding: "2px 4px",
|
marginLeft: "auto",
|
||||||
borderRadius: 6,
|
padding: "2px 4px",
|
||||||
fontSize: 9,
|
|
||||||
fontFamily: "Cascadia, monospace",
|
|
||||||
border: theme === THEME.LIGHT ? "1.5px solid white" : "none",
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case DropDownMenuItemBadgeType.GREEN:
|
|
||||||
Object.assign(style, {
|
|
||||||
backgroundColor: "var(--background-color-badge)",
|
|
||||||
color: "var(--color-badge)",
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case DropDownMenuItemBadgeType.RED:
|
|
||||||
Object.assign(style, {
|
|
||||||
backgroundColor: "pink",
|
|
||||||
color: "darkred",
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case DropDownMenuItemBadgeType.BLUE:
|
|
||||||
default:
|
|
||||||
Object.assign(style, {
|
|
||||||
background: "var(--color-promo)",
|
background: "var(--color-promo)",
|
||||||
color: "var(--color-surface-lowest)",
|
color: "var(--color-surface-lowest)",
|
||||||
});
|
borderRadius: 6,
|
||||||
}
|
fontSize: 9,
|
||||||
|
fontFamily: "Cascadia, monospace",
|
||||||
return (
|
}}
|
||||||
<div className="DropDownMenuItemBadge" style={style}>
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
import { useDevice } from "../App";
|
import { useDevice } from "../App";
|
||||||
|
|
||||||
const MenuItemContent = ({
|
const MenuItemContent = ({
|
||||||
textStyle,
|
|
||||||
icon,
|
icon,
|
||||||
shortcut,
|
shortcut,
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
icon?: JSX.Element;
|
icon?: JSX.Element;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
textStyle?: React.CSSProperties;
|
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{icon && <div className="dropdown-menu-item__icon">{icon}</div>}
|
<div className="dropdown-menu-item__icon">{icon}</div>
|
||||||
<div style={textStyle} className="dropdown-menu-item__text">
|
<div className="dropdown-menu-item__text">{children}</div>
|
||||||
{children}
|
|
||||||
</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>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -9,11 +9,9 @@ export const DropdownMenuContentPropsContext = React.createContext<{
|
|||||||
export const getDropdownMenuItemClassName = (
|
export const getDropdownMenuItemClassName = (
|
||||||
className = "",
|
className = "",
|
||||||
selected = false,
|
selected = false,
|
||||||
hovered = false,
|
|
||||||
) => {
|
) => {
|
||||||
return `dropdown-menu-item dropdown-menu-item-base ${className}
|
return `dropdown-menu-item dropdown-menu-item-base ${className} ${
|
||||||
${selected ? "dropdown-menu-item--selected" : ""} ${
|
selected ? "dropdown-menu-item--selected" : ""
|
||||||
hovered ? "dropdown-menu-item--hovered" : ""
|
|
||||||
}`.trim();
|
}`.trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1438,27 +1438,6 @@ export const fontSizeIcon = createIcon(
|
|||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const FontFamilyHeadingIcon = createIcon(
|
|
||||||
<>
|
|
||||||
<g
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth="1.25"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
>
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
||||||
<path d="M7 12h10" />
|
|
||||||
<path d="M7 5v14" />
|
|
||||||
<path d="M17 5v14" />
|
|
||||||
<path d="M15 19h4" />
|
|
||||||
<path d="M15 5h4" />
|
|
||||||
<path d="M5 19h4" />
|
|
||||||
<path d="M5 5h4" />
|
|
||||||
</g>
|
|
||||||
</>,
|
|
||||||
tablerIconProps,
|
|
||||||
);
|
|
||||||
|
|
||||||
export const FontFamilyNormalIcon = createIcon(
|
export const FontFamilyNormalIcon = createIcon(
|
||||||
<>
|
<>
|
||||||
<g
|
<g
|
||||||
@@ -1594,18 +1573,6 @@ export const TextAlignMiddleIcon = React.memo(({ theme }: { theme: Theme }) =>
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const angleIcon = createIcon(
|
|
||||||
<g>
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
||||||
<path d="M21 19h-18l9 -15" />
|
|
||||||
<path d="M20.615 15.171h.015" />
|
|
||||||
<path d="M19.515 11.771h.015" />
|
|
||||||
<path d="M17.715 8.671h.015" />
|
|
||||||
<path d="M15.415 5.971h.015" />
|
|
||||||
</g>,
|
|
||||||
tablerIconProps,
|
|
||||||
);
|
|
||||||
|
|
||||||
export const publishIcon = createIcon(
|
export const publishIcon = createIcon(
|
||||||
<path
|
<path
|
||||||
d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zM393.4 288H328v112c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V288h-65.4c-14.3 0-21.4-17.2-11.3-27.3l105.4-105.4c6.2-6.2 16.4-6.2 22.6 0l105.4 105.4c10.1 10.1 2.9 27.3-11.3 27.3z"
|
d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zM393.4 288H328v112c0 8.8-7.2 16-16 16h-48c-8.8 0-16-7.2-16-16V288h-65.4c-14.3 0-21.4-17.2-11.3-27.3l105.4-105.4c6.2-6.2 16.4-6.2 22.6 0l105.4 105.4c10.1 10.1 2.9 27.3-11.3 27.3z"
|
||||||
@@ -2094,19 +2061,3 @@ export const lineEditorIcon = createIcon(
|
|||||||
</g>,
|
</g>,
|
||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const collapseDownIcon = createIcon(
|
|
||||||
<g>
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
||||||
<path d="M6 9l6 6l6 -6" />
|
|
||||||
</g>,
|
|
||||||
tablerIconProps,
|
|
||||||
);
|
|
||||||
|
|
||||||
export const collapseUpIcon = createIcon(
|
|
||||||
<g>
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
||||||
<path d="M6 15l6 -6l6 6" />
|
|
||||||
</g>,
|
|
||||||
tablerIconProps,
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ Center.displayName = "Center";
|
|||||||
|
|
||||||
const Logo = ({ children }: { children?: React.ReactNode }) => {
|
const Logo = ({ children }: { children?: React.ReactNode }) => {
|
||||||
return (
|
return (
|
||||||
<div className="welcome-screen-center__logo excalifont welcome-screen-decor">
|
<div className="welcome-screen-center__logo virgil welcome-screen-decor">
|
||||||
{children || <ExcalidrawLogo withText />}
|
{children || <ExcalidrawLogo withText />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -118,7 +118,7 @@ Logo.displayName = "Logo";
|
|||||||
|
|
||||||
const Heading = ({ children }: { children: React.ReactNode }) => {
|
const Heading = ({ children }: { children: React.ReactNode }) => {
|
||||||
return (
|
return (
|
||||||
<div className="welcome-screen-center__heading welcome-screen-decor excalifont">
|
<div className="welcome-screen-center__heading welcome-screen-decor virgil">
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const MenuHint = ({ children }: { children?: React.ReactNode }) => {
|
|||||||
const { WelcomeScreenMenuHintTunnel } = useTunnels();
|
const { WelcomeScreenMenuHintTunnel } = useTunnels();
|
||||||
return (
|
return (
|
||||||
<WelcomeScreenMenuHintTunnel.In>
|
<WelcomeScreenMenuHintTunnel.In>
|
||||||
<div className="excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--menu">
|
<div className="virgil welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--menu">
|
||||||
{WelcomeScreenMenuArrow}
|
{WelcomeScreenMenuArrow}
|
||||||
<div className="welcome-screen-decor-hint__label">
|
<div className="welcome-screen-decor-hint__label">
|
||||||
{children || t("welcomeScreen.defaults.menuHint")}
|
{children || t("welcomeScreen.defaults.menuHint")}
|
||||||
@@ -25,7 +25,7 @@ const ToolbarHint = ({ children }: { children?: React.ReactNode }) => {
|
|||||||
const { WelcomeScreenToolbarHintTunnel } = useTunnels();
|
const { WelcomeScreenToolbarHintTunnel } = useTunnels();
|
||||||
return (
|
return (
|
||||||
<WelcomeScreenToolbarHintTunnel.In>
|
<WelcomeScreenToolbarHintTunnel.In>
|
||||||
<div className="excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--toolbar">
|
<div className="virgil welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--toolbar">
|
||||||
<div className="welcome-screen-decor-hint__label">
|
<div className="welcome-screen-decor-hint__label">
|
||||||
{children || t("welcomeScreen.defaults.toolbarHint")}
|
{children || t("welcomeScreen.defaults.toolbarHint")}
|
||||||
</div>
|
</div>
|
||||||
@@ -40,7 +40,7 @@ const HelpHint = ({ children }: { children?: React.ReactNode }) => {
|
|||||||
const { WelcomeScreenHelpHintTunnel } = useTunnels();
|
const { WelcomeScreenHelpHintTunnel } = useTunnels();
|
||||||
return (
|
return (
|
||||||
<WelcomeScreenHelpHintTunnel.In>
|
<WelcomeScreenHelpHintTunnel.In>
|
||||||
<div className="excalifont welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--help">
|
<div className="virgil welcome-screen-decor welcome-screen-decor-hint welcome-screen-decor-hint--help">
|
||||||
<div>{children || t("welcomeScreen.defaults.helpHint")}</div>
|
<div>{children || t("welcomeScreen.defaults.helpHint")}</div>
|
||||||
{WelcomeScreenHelpArrow}
|
{WelcomeScreenHelpArrow}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.excalidraw {
|
.excalidraw {
|
||||||
.excalifont {
|
.virgil {
|
||||||
font-family: "Excalifont";
|
font-family: "Virgil";
|
||||||
}
|
}
|
||||||
|
|
||||||
// WelcomeSreen common
|
// WelcomeSreen common
|
||||||
|
|||||||
@@ -25,11 +25,6 @@ export const supportsResizeObserver =
|
|||||||
|
|
||||||
export const APP_NAME = "Excalidraw";
|
export const APP_NAME = "Excalidraw";
|
||||||
|
|
||||||
// distance when creating text before it's considered `autoResize: false`
|
|
||||||
// we're using higher threshold so that clicks that end up being drags
|
|
||||||
// don't unintentionally create text elements that are wrapped to a few chars
|
|
||||||
// (happens a lot with fast clicks with the text tool)
|
|
||||||
export const TEXT_AUTOWRAP_THRESHOLD = 36; // px
|
|
||||||
export const DRAGGING_THRESHOLD = 10; // px
|
export const DRAGGING_THRESHOLD = 10; // 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;
|
||||||
@@ -114,24 +109,12 @@ export const CLASSES = {
|
|||||||
SHAPE_ACTIONS_MENU: "App-menu__left",
|
SHAPE_ACTIONS_MENU: "App-menu__left",
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// 1-based in case we ever do `if(element.fontFamily)`
|
||||||
* // TODO: shouldn't be really `const`, likely neither have integers as values, due to value for the custom fonts, which should likely be some hash.
|
|
||||||
*
|
|
||||||
* Let's think this through and consider:
|
|
||||||
* - https://developer.mozilla.org/en-US/docs/Web/CSS/generic-family
|
|
||||||
* - https://drafts.csswg.org/css-fonts-4/#font-family-prop
|
|
||||||
* - https://learn.microsoft.com/en-us/typography/opentype/spec/ibmfc
|
|
||||||
*/
|
|
||||||
export const FONT_FAMILY = {
|
export const FONT_FAMILY = {
|
||||||
Virgil: 1,
|
Virgil: 1,
|
||||||
Helvetica: 2,
|
Helvetica: 2,
|
||||||
Cascadia: 3,
|
Cascadia: 3,
|
||||||
// leave 4 unused as it was historically used for Assistant (which we don't use anymore) or custom font (Obsidian)
|
Assistant: 4,
|
||||||
Excalifont: 5,
|
|
||||||
Nunito: 6,
|
|
||||||
"Lilita One": 7,
|
|
||||||
"Comic Shanns": 8,
|
|
||||||
"Liberation Sans": 9,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const THEME = {
|
export const THEME = {
|
||||||
@@ -159,7 +142,7 @@ export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
|
|||||||
|
|
||||||
export const MIN_FONT_SIZE = 1;
|
export const MIN_FONT_SIZE = 1;
|
||||||
export const DEFAULT_FONT_SIZE = 20;
|
export const DEFAULT_FONT_SIZE = 20;
|
||||||
export const DEFAULT_FONT_FAMILY: FontFamilyValues = FONT_FAMILY.Excalifont;
|
export const DEFAULT_FONT_FAMILY: FontFamilyValues = FONT_FAMILY.Virgil;
|
||||||
export const DEFAULT_TEXT_ALIGN = "left";
|
export const DEFAULT_TEXT_ALIGN = "left";
|
||||||
export const DEFAULT_VERTICAL_ALIGN = "top";
|
export const DEFAULT_VERTICAL_ALIGN = "top";
|
||||||
export const DEFAULT_VERSION = "{version}";
|
export const DEFAULT_VERSION = "{version}";
|
||||||
@@ -286,7 +269,7 @@ export const DEFAULT_EXPORT_PADDING = 10; // px
|
|||||||
|
|
||||||
export const DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT = 1440;
|
export const DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT = 1440;
|
||||||
|
|
||||||
export const MAX_ALLOWED_FILE_BYTES = 4 * 1024 * 1024;
|
export const MAX_ALLOWED_FILE_BYTES = 2 * 1024 * 1024;
|
||||||
|
|
||||||
export const SVG_NS = "http://www.w3.org/2000/svg";
|
export const SVG_NS = "http://www.w3.org/2000/svg";
|
||||||
|
|
||||||
@@ -417,7 +400,3 @@ export const EDITOR_LS_KEYS = {
|
|||||||
* where filename is optional and we can't retrieve name from app state
|
* where filename is optional and we can't retrieve name from app state
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_FILENAME = "Untitled";
|
export const DEFAULT_FILENAME = "Untitled";
|
||||||
|
|
||||||
export const STATS_PANELS = { generalStats: 1, elementProperties: 2 } as const;
|
|
||||||
|
|
||||||
export const MIN_WIDTH_OR_HEIGHT = 1;
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
--sat: env(safe-area-inset-top);
|
--sat: env(safe-area-inset-top);
|
||||||
}
|
}
|
||||||
|
|
||||||
body.excalidraw-cursor-resize,
|
body.dragResize,
|
||||||
body.excalidraw-cursor-resize a:hover,
|
body.dragResize a:hover,
|
||||||
body.excalidraw-cursor-resize * {
|
body.dragResize * {
|
||||||
cursor: ew-resize;
|
cursor: ew-resize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ body.excalidraw-cursor-resize * {
|
|||||||
margin-bottom: 0.25rem;
|
margin-bottom: 0.25rem;
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
color: var(--text-primary-color);
|
color: var(--text-primary-color);
|
||||||
font-weight: 400;
|
font-weight: normal;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +227,14 @@ body.excalidraw-cursor-resize * {
|
|||||||
label,
|
label,
|
||||||
button,
|
button,
|
||||||
.zIndexButton {
|
.zIndexButton {
|
||||||
@include outlineButtonIconStyles;
|
@include outlineButtonStyles;
|
||||||
|
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: var(--default-icon-size);
|
||||||
|
height: var(--default-icon-size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,7 +394,7 @@ body.excalidraw-cursor-resize * {
|
|||||||
.App-menu__left {
|
.App-menu__left {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: 0.75rem;
|
padding: 0.75rem;
|
||||||
width: 200px;
|
width: 202px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
@@ -578,7 +585,7 @@ body.excalidraw-cursor-resize * {
|
|||||||
// use custom, minimalistic scrollbar
|
// use custom, minimalistic scrollbar
|
||||||
// (doesn't work in Firefox)
|
// (doesn't work in Firefox)
|
||||||
::-webkit-scrollbar {
|
::-webkit-scrollbar {
|
||||||
width: 4px;
|
width: 3px;
|
||||||
height: 3px;
|
height: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,10 +664,6 @@ body.excalidraw-cursor-resize * {
|
|||||||
--button-hover-bg: #363541;
|
--button-hover-bg: #363541;
|
||||||
--button-bg: var(--color-surface-high);
|
--button-bg: var(--color-surface-high);
|
||||||
}
|
}
|
||||||
|
|
||||||
.buttonList {
|
|
||||||
padding: 0.25rem 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.excalidraw__paragraph {
|
.excalidraw__paragraph {
|
||||||
@@ -754,7 +757,7 @@ body.excalidraw-cursor-resize * {
|
|||||||
padding: 1rem 1.6rem;
|
padding: 1rem 1.6rem;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
letter-spacing: 0.6px;
|
letter-spacing: 0.6px;
|
||||||
font-family: "Assistant";
|
font-family: "Assistant";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,9 +151,6 @@
|
|||||||
--color-border-outline-variant: #c5c5d0;
|
--color-border-outline-variant: #c5c5d0;
|
||||||
--color-surface-primary-container: #e0dfff;
|
--color-surface-primary-container: #e0dfff;
|
||||||
|
|
||||||
--color-badge: #0b6513;
|
|
||||||
--background-color-badge: #d3ffd2;
|
|
||||||
|
|
||||||
&.theme--dark {
|
&.theme--dark {
|
||||||
&.theme--dark-background-none {
|
&.theme--dark-background-none {
|
||||||
background: none;
|
background: none;
|
||||||
|
|||||||
@@ -124,16 +124,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin outlineButtonIconStyles {
|
|
||||||
@include outlineButtonStyles;
|
|
||||||
padding: 0;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: var(--default-icon-size);
|
|
||||||
height: var(--default-icon-size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@mixin avatarStyles {
|
@mixin avatarStyles {
|
||||||
width: var(--avatar-size, 1.5rem);
|
width: var(--avatar-size, 1.5rem);
|
||||||
height: var(--avatar-size, 1.5rem);
|
height: var(--avatar-size, 1.5rem);
|
||||||
@@ -145,7 +135,7 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
font-weight: 700;
|
font-weight: 800;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
color: var(--color-gray-90);
|
color: var(--color-gray-90);
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
|
|||||||
"containerId": null,
|
"containerId": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -285,7 +285,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
|
|||||||
"containerId": null,
|
"containerId": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -386,7 +386,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to existing t
|
|||||||
"containerId": "id48",
|
"containerId": "id48",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -487,7 +487,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to shapes whe
|
|||||||
"containerId": "id37",
|
"containerId": "id37",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -662,7 +662,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
|
|||||||
"containerId": "id41",
|
"containerId": "id41",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -708,7 +708,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
|
|||||||
"containerId": null,
|
"containerId": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -754,7 +754,7 @@ exports[`Test Transform > Test arrow bindings > should bind arrows to text when
|
|||||||
"containerId": null,
|
"containerId": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -1207,7 +1207,7 @@ exports[`Test Transform > should transform text element 1`] = `
|
|||||||
"containerId": null,
|
"containerId": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -1248,7 +1248,7 @@ exports[`Test Transform > should transform text element 2`] = `
|
|||||||
"containerId": null,
|
"containerId": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -1581,7 +1581,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"containerId": "B",
|
"containerId": "B",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [
|
"groupIds": [
|
||||||
@@ -1624,7 +1624,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"containerId": "A",
|
"containerId": "A",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [
|
"groupIds": [
|
||||||
@@ -1667,7 +1667,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"containerId": "Alice",
|
"containerId": "Alice",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [
|
"groupIds": [
|
||||||
@@ -1710,7 +1710,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"containerId": "Bob",
|
"containerId": "Bob",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [
|
"groupIds": [
|
||||||
@@ -1753,7 +1753,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"containerId": "Bob_Alice",
|
"containerId": "Bob_Alice",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -1794,7 +1794,7 @@ exports[`Test Transform > should transform the elements correctly when linear el
|
|||||||
"containerId": "Bob_B",
|
"containerId": "Bob_B",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2043,7 +2043,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"containerId": "id25",
|
"containerId": "id25",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2084,7 +2084,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"containerId": "id26",
|
"containerId": "id26",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2125,7 +2125,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"containerId": "id27",
|
"containerId": "id27",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2167,7 +2167,7 @@ exports[`Test Transform > should transform to labelled arrows when label provide
|
|||||||
"containerId": "id28",
|
"containerId": "id28",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2431,7 +2431,7 @@ exports[`Test Transform > should transform to text containers when label provide
|
|||||||
"containerId": "id13",
|
"containerId": "id13",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2472,7 +2472,7 @@ exports[`Test Transform > should transform to text containers when label provide
|
|||||||
"containerId": "id14",
|
"containerId": "id14",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2514,7 +2514,7 @@ exports[`Test Transform > should transform to text containers when label provide
|
|||||||
"containerId": "id15",
|
"containerId": "id15",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2558,7 +2558,7 @@ exports[`Test Transform > should transform to text containers when label provide
|
|||||||
"containerId": "id16",
|
"containerId": "id16",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2600,7 +2600,7 @@ exports[`Test Transform > should transform to text containers when label provide
|
|||||||
"containerId": "id17",
|
"containerId": "id17",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@@ -2643,7 +2643,7 @@ exports[`Test Transform > should transform to text containers when label provide
|
|||||||
"containerId": "id18",
|
"containerId": "id18",
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"fontFamily": 5,
|
"fontFamily": 1,
|
||||||
"fontSize": 20,
|
"fontSize": 20,
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
|
|||||||
@@ -154,11 +154,7 @@ export const loadSceneOrLibraryFromBlob = async (
|
|||||||
},
|
},
|
||||||
localAppState,
|
localAppState,
|
||||||
localElements,
|
localElements,
|
||||||
{
|
{ repairBindings: true, refreshDimensions: false },
|
||||||
repairBindings: true,
|
|
||||||
normalizeIndices: true,
|
|
||||||
refreshDimensions: false,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else if (isValidLibrary(data)) {
|
} else if (isValidLibrary(data)) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawElementType,
|
ExcalidrawElementType,
|
||||||
ExcalidrawLinearElement,
|
|
||||||
ExcalidrawSelectionElement,
|
ExcalidrawSelectionElement,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
FontFamilyValues,
|
FontFamilyValues,
|
||||||
@@ -22,12 +21,7 @@ import {
|
|||||||
isInvisiblySmallElement,
|
isInvisiblySmallElement,
|
||||||
refreshTextDimensions,
|
refreshTextDimensions,
|
||||||
} from "../element";
|
} from "../element";
|
||||||
import {
|
import { isTextElement, isUsingAdaptiveRadius } from "../element/typeChecks";
|
||||||
isArrowElement,
|
|
||||||
isLinearElement,
|
|
||||||
isTextElement,
|
|
||||||
isUsingAdaptiveRadius,
|
|
||||||
} from "../element/typeChecks";
|
|
||||||
import { randomId } from "../random";
|
import { randomId } from "../random";
|
||||||
import {
|
import {
|
||||||
DEFAULT_FONT_FAMILY,
|
DEFAULT_FONT_FAMILY,
|
||||||
@@ -44,11 +38,13 @@ import { bumpVersion } from "../element/mutateElement";
|
|||||||
import { getUpdatedTimestamp, updateActiveTool } from "../utils";
|
import { getUpdatedTimestamp, updateActiveTool } from "../utils";
|
||||||
import { arrayToMap } from "../utils";
|
import { arrayToMap } from "../utils";
|
||||||
import type { MarkOptional, Mutable } from "../utility-types";
|
import type { MarkOptional, Mutable } from "../utility-types";
|
||||||
import { detectLineHeight, getContainerElement } from "../element/textElement";
|
import {
|
||||||
|
detectLineHeight,
|
||||||
|
getContainerElement,
|
||||||
|
getDefaultLineHeight,
|
||||||
|
} from "../element/textElement";
|
||||||
import { normalizeLink } from "./url";
|
import { normalizeLink } from "./url";
|
||||||
import { getSizeFromPoints } from "../points";
|
import { syncInvalidIndices } from "../fractionalIndex";
|
||||||
import { getLineHeight } from "../fonts";
|
|
||||||
import { normalizeIndices, syncInvalidIndices } from "../fractionalIndex";
|
|
||||||
|
|
||||||
type RestoredAppState = Omit<
|
type RestoredAppState = Omit<
|
||||||
AppState,
|
AppState,
|
||||||
@@ -203,7 +199,7 @@ const restoreElement = (
|
|||||||
detectLineHeight(element)
|
detectLineHeight(element)
|
||||||
: // no element height likely means programmatic use, so default
|
: // no element height likely means programmatic use, so default
|
||||||
// to a fixed line height
|
// to a fixed line height
|
||||||
getLineHeight(element.fontFamily));
|
getDefaultLineHeight(element.fontFamily));
|
||||||
element = restoreElementWithProperties(element, {
|
element = restoreElementWithProperties(element, {
|
||||||
fontSize,
|
fontSize,
|
||||||
fontFamily,
|
fontFamily,
|
||||||
@@ -274,7 +270,6 @@ const restoreElement = (
|
|||||||
points,
|
points,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
...getSizeFromPoints(points),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,41 +400,36 @@ 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;
|
|
||||||
normalizeIndices?: 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>();
|
||||||
const localElementsMap = localElements ? arrayToMap(localElements) : null;
|
const localElementsMap = localElements ? arrayToMap(localElements) : null;
|
||||||
const restoredElementsTemp = (elements || []).reduce((elements, element) => {
|
const restoredElements = syncInvalidIndices(
|
||||||
// filtering out selection, which is legacy, no longer kept in elements,
|
(elements || []).reduce((elements, element) => {
|
||||||
// and causing issues if retained
|
// filtering out selection, which is legacy, no longer kept in elements,
|
||||||
if (element.type !== "selection" && !isInvisiblySmallElement(element)) {
|
// and causing issues if retained
|
||||||
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
if (element.type !== "selection" && !isInvisiblySmallElement(element)) {
|
||||||
if (migratedElement) {
|
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
||||||
const localElement = localElementsMap?.get(element.id);
|
if (migratedElement) {
|
||||||
if (localElement && localElement.version > migratedElement.version) {
|
const localElement = localElementsMap?.get(element.id);
|
||||||
migratedElement = bumpVersion(migratedElement, localElement.version);
|
if (localElement && localElement.version > migratedElement.version) {
|
||||||
}
|
migratedElement = bumpVersion(
|
||||||
if (existingIds.has(migratedElement.id)) {
|
migratedElement,
|
||||||
migratedElement = { ...migratedElement, id: randomId() };
|
localElement.version,
|
||||||
}
|
);
|
||||||
existingIds.add(migratedElement.id);
|
}
|
||||||
|
if (existingIds.has(migratedElement.id)) {
|
||||||
|
migratedElement = { ...migratedElement, id: randomId() };
|
||||||
|
}
|
||||||
|
existingIds.add(migratedElement.id);
|
||||||
|
|
||||||
elements.push(migratedElement);
|
elements.push(migratedElement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return elements;
|
||||||
return elements;
|
}, [] as ExcalidrawElement[]),
|
||||||
}, [] as ExcalidrawElement[]);
|
);
|
||||||
|
|
||||||
const restoredElements = opts?.normalizeIndices
|
|
||||||
? normalizeIndices(restoredElementsTemp)
|
|
||||||
: syncInvalidIndices(restoredElementsTemp);
|
|
||||||
|
|
||||||
if (!opts?.repairBindings) {
|
if (!opts?.repairBindings) {
|
||||||
return restoredElements;
|
return restoredElements;
|
||||||
@@ -468,23 +458,6 @@ export const restoreElements = (
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLinearElement(element)) {
|
|
||||||
if (
|
|
||||||
element.startBinding &&
|
|
||||||
(!restoredElementsMap.has(element.startBinding.elementId) ||
|
|
||||||
!isArrowElement(element))
|
|
||||||
) {
|
|
||||||
(element as Mutable<ExcalidrawLinearElement>).startBinding = null;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
element.endBinding &&
|
|
||||||
(!restoredElementsMap.has(element.endBinding.elementId) ||
|
|
||||||
!isArrowElement(element))
|
|
||||||
) {
|
|
||||||
(element as Mutable<ExcalidrawLinearElement>).endBinding = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return restoredElements;
|
return restoredElements;
|
||||||
@@ -606,11 +579,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;
|
|
||||||
normalizeIndices?: boolean;
|
|
||||||
},
|
|
||||||
): RestoredDataState => {
|
): RestoredDataState => {
|
||||||
return {
|
return {
|
||||||
elements: restoreElements(data?.elements, localElements, elementsConfig),
|
elements: restoreElements(data?.elements, localElements, elementsConfig),
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ import {
|
|||||||
newMagicFrameElement,
|
newMagicFrameElement,
|
||||||
newTextElement,
|
newTextElement,
|
||||||
} from "../element/newElement";
|
} from "../element/newElement";
|
||||||
import { measureText, normalizeText } from "../element/textElement";
|
import {
|
||||||
|
getDefaultLineHeight,
|
||||||
|
measureText,
|
||||||
|
normalizeText,
|
||||||
|
} from "../element/textElement";
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
ExcalidrawArrowElement,
|
ExcalidrawArrowElement,
|
||||||
@@ -50,7 +54,6 @@ import {
|
|||||||
import { getSizeFromPoints } from "../points";
|
import { getSizeFromPoints } from "../points";
|
||||||
import { randomId } from "../random";
|
import { randomId } from "../random";
|
||||||
import { syncInvalidIndices } from "../fractionalIndex";
|
import { syncInvalidIndices } from "../fractionalIndex";
|
||||||
import { getLineHeight } from "../fonts";
|
|
||||||
|
|
||||||
export type ValidLinearElement = {
|
export type ValidLinearElement = {
|
||||||
type: "arrow" | "line";
|
type: "arrow" | "line";
|
||||||
@@ -565,7 +568,8 @@ export const convertToExcalidrawElements = (
|
|||||||
case "text": {
|
case "text": {
|
||||||
const fontFamily = element?.fontFamily || DEFAULT_FONT_FAMILY;
|
const fontFamily = element?.fontFamily || DEFAULT_FONT_FAMILY;
|
||||||
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE;
|
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE;
|
||||||
const lineHeight = element?.lineHeight || getLineHeight(fontFamily);
|
const lineHeight =
|
||||||
|
element?.lineHeight || getDefaultLineHeight(fontFamily);
|
||||||
const text = element.text ?? "";
|
const text = element.text ?? "";
|
||||||
const normalizedText = normalizeText(text);
|
const normalizedText = normalizeText(text);
|
||||||
const metrics = measureText(
|
const metrics = measureText(
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user