Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d65536360 | |||
| d731a6463c | |||
| 9f325a626e | |||
| 41200ea28d |
@@ -1,43 +0,0 @@
|
|||||||
{
|
|
||||||
// These tasks will run in order when initializing your CodeSandbox project.
|
|
||||||
"setupTasks": [
|
|
||||||
{
|
|
||||||
"name": "Install Dependencies",
|
|
||||||
"command": "yarn install"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
// These tasks can be run from CodeSandbox. Running one will open a log in the app.
|
|
||||||
"tasks": {
|
|
||||||
"build": {
|
|
||||||
"name": "Build",
|
|
||||||
"command": "yarn build",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"fix": {
|
|
||||||
"name": "Fix",
|
|
||||||
"command": "yarn fix",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"prettier": {
|
|
||||||
"name": "Prettify",
|
|
||||||
"command": "yarn prettier",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"start": {
|
|
||||||
"name": "Start Excalidraw",
|
|
||||||
"command": "yarn start",
|
|
||||||
"runAtStart": true
|
|
||||||
},
|
|
||||||
"test": {
|
|
||||||
"name": "Run Tests",
|
|
||||||
"command": "yarn test",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"install-deps": {
|
|
||||||
"name": "Install Dependencies",
|
|
||||||
"command": "yarn install",
|
|
||||||
"restartOn": { "files": ["yarn.lock"] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,3 +25,4 @@ src/packages/excalidraw/types
|
|||||||
src/packages/excalidraw/example/public/bundle.js
|
src/packages/excalidraw/example/public/bundle.js
|
||||||
src/packages/excalidraw/example/public/excalidraw-assets-dev
|
src/packages/excalidraw/example/public/excalidraw-assets-dev
|
||||||
src/packages/excalidraw/example/public/excalidraw.development.js
|
src/packages/excalidraw/example/public/excalidraw.development.js
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ Try out [`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/exc
|
|||||||
|
|
||||||
### Code Sandbox
|
### Code Sandbox
|
||||||
|
|
||||||
- Go to https://codesandbox.io/p/github/excalidraw/excalidraw
|
- Go to https://codesandbox.io/s/github/excalidraw/excalidraw
|
||||||
- You may need to sign in with GitHub and reload the page
|
- You may need to sign in with GitHub and reload the page
|
||||||
- You can start coding instantly, and even send PRs from there!
|
- You can start coding instantly, and even send PRs from there!
|
||||||
|
|
||||||
|
|||||||
+9
-4
@@ -31,8 +31,10 @@
|
|||||||
"@types/socket.io-client": "1.4.36",
|
"@types/socket.io-client": "1.4.36",
|
||||||
"browser-fs-access": "0.29.1",
|
"browser-fs-access": "0.29.1",
|
||||||
"clsx": "1.1.1",
|
"clsx": "1.1.1",
|
||||||
|
"cross-env": "7.0.3",
|
||||||
"fake-indexeddb": "3.1.7",
|
"fake-indexeddb": "3.1.7",
|
||||||
"firebase": "8.3.3",
|
"firebase": "8.3.3",
|
||||||
|
"http-server": "14.1.1",
|
||||||
"i18next-browser-languagedetector": "6.1.4",
|
"i18next-browser-languagedetector": "6.1.4",
|
||||||
"idb-keyval": "6.0.3",
|
"idb-keyval": "6.0.3",
|
||||||
"image-blob-reduce": "3.0.1",
|
"image-blob-reduce": "3.0.1",
|
||||||
@@ -41,8 +43,7 @@
|
|||||||
"nanoid": "3.3.3",
|
"nanoid": "3.3.3",
|
||||||
"open-color": "1.9.1",
|
"open-color": "1.9.1",
|
||||||
"pako": "1.0.11",
|
"pako": "1.0.11",
|
||||||
"perfect-freehand": "1.2.0",
|
"perfect-freehand": "1.0.16",
|
||||||
"pica": "7.1.1",
|
|
||||||
"png-chunk-text": "1.0.0",
|
"png-chunk-text": "1.0.0",
|
||||||
"png-chunks-encode": "1.0.0",
|
"png-chunks-encode": "1.0.0",
|
||||||
"png-chunks-extract": "1.0.0",
|
"png-chunks-extract": "1.0.0",
|
||||||
@@ -74,6 +75,9 @@
|
|||||||
"prettier": "2.6.2",
|
"prettier": "2.6.2",
|
||||||
"rewire": "6.0.0"
|
"rewire": "6.0.0"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"@typescript-eslint/typescript-estree": "5.10.2"
|
||||||
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
},
|
},
|
||||||
@@ -89,8 +93,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build-node": "node ./scripts/build-node.js",
|
"build-node": "node ./scripts/build-node.js",
|
||||||
"build:app:docker": "REACT_APP_DISABLE_SENTRY=true react-scripts build",
|
"build:app:docker": "cross-env REACT_APP_DISABLE_SENTRY=true react-scripts build",
|
||||||
"build:app": "REACT_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA react-scripts build",
|
"build:app": "cross-env REACT_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA react-scripts build",
|
||||||
"build:version": "node ./scripts/build-version.js",
|
"build:version": "node ./scripts/build-version.js",
|
||||||
"build:prebuild": "node ./scripts/prebuild.js",
|
"build:prebuild": "node ./scripts/prebuild.js",
|
||||||
"build": "yarn build:prebuild && yarn build:app && yarn build:version",
|
"build": "yarn build:prebuild && yarn build:app && yarn build:version",
|
||||||
@@ -103,6 +107,7 @@
|
|||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"prettier": "prettier \"**/*.{css,scss,json,md,html,yml}\" --ignore-path=.eslintignore",
|
"prettier": "prettier \"**/*.{css,scss,json,md,html,yml}\" --ignore-path=.eslintignore",
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
"start:build": "npm run build && npx http-server build -a localhost -p 3001 -o",
|
||||||
"test:all": "yarn test:typecheck && yarn test:code && yarn test:other && yarn test:app --watchAll=false",
|
"test:all": "yarn test:typecheck && yarn test:code && yarn test:other && yarn test:app --watchAll=false",
|
||||||
"test:app": "react-scripts test --passWithNoTests",
|
"test:app": "react-scripts test --passWithNoTests",
|
||||||
"test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .",
|
"test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .",
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,28 +11,3 @@
|
|||||||
src: url("Cascadia.woff2");
|
src: url("Cascadia.woff2");
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
|
||||||
font-family: "Assistant";
|
|
||||||
src: url("Assistant-Regular.woff2");
|
|
||||||
font-display: swap;
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Assistant";
|
|
||||||
src: url("Assistant-Medium.woff2");
|
|
||||||
font-display: swap;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Assistant";
|
|
||||||
src: url("Assistant-SemiBold.woff2");
|
|
||||||
font-display: swap;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Assistant";
|
|
||||||
src: url("Assistant-Bold.woff2");
|
|
||||||
font-display: swap;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|||||||
+38
-65
@@ -8,76 +8,49 @@
|
|||||||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no"
|
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no"
|
||||||
/>
|
/>
|
||||||
<meta name="referrer" content="origin" />
|
<meta name="referrer" content="origin" />
|
||||||
|
|
||||||
<meta name="mobile-web-app-capable" content="yes" />
|
<meta name="mobile-web-app-capable" content="yes" />
|
||||||
<meta name="theme-color" content="#121212" />
|
|
||||||
|
|
||||||
<!-- Primary Meta Tags -->
|
<meta name="theme-color" content="#000" />
|
||||||
<meta
|
|
||||||
name="title"
|
|
||||||
content="Excalidraw — Collaborative whiteboarding made easy"
|
|
||||||
/>
|
|
||||||
<meta
|
|
||||||
name="description"
|
|
||||||
content="Excalidraw is a virtual collaborative whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
|
||||||
/>
|
|
||||||
<meta name="image" content="https://excalidraw.com/og-general-v1.png" />
|
|
||||||
|
|
||||||
<!-- Open Graph / Facebook -->
|
|
||||||
<meta property="og:site_name" content="Excalidraw" />
|
|
||||||
<meta property="og:type" content="website" />
|
|
||||||
<meta property="og:url" content="https://excalidraw.com" />
|
|
||||||
<meta
|
|
||||||
property="og:title"
|
|
||||||
content="Excalidraw — Collaborative whiteboarding made easy"
|
|
||||||
/>
|
|
||||||
<meta property="og:image:alt" content="Excalidraw logo" />
|
|
||||||
<meta
|
|
||||||
property="og:description"
|
|
||||||
content="Excalidraw is a virtual collaborative whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
|
||||||
/>
|
|
||||||
<meta property="og:image" content="https://excalidraw.com/og-fb-v1.png" />
|
|
||||||
|
|
||||||
<!-- Twitter -->
|
|
||||||
<meta property="twitter:card" content="summary_large_image" />
|
|
||||||
<meta property="twitter:site" content="@excalidraw" />
|
|
||||||
<meta property="twitter:url" content="https://excalidraw.com" />
|
|
||||||
<meta
|
|
||||||
property="twitter:title"
|
|
||||||
content="Excalidraw — Collaborative whiteboarding made easy"
|
|
||||||
/>
|
|
||||||
<meta
|
|
||||||
property="twitter:description"
|
|
||||||
content="Excalidraw is a virtual collaborative whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
|
||||||
/>
|
|
||||||
<meta
|
|
||||||
property="twitter:image"
|
|
||||||
content="https://excalidraw.com/og-twitter-v1.png"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- General tags -->
|
<!-- General tags -->
|
||||||
<meta
|
<meta
|
||||||
name="description"
|
name="description"
|
||||||
content="Excalidraw is a virtual collaborative whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
content="Excalidraw is a virtual collaborative whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
||||||
/>
|
/>
|
||||||
|
<meta name="image" content="og-image.png" />
|
||||||
|
|
||||||
<!------------------------------------------------------------------------->
|
<!-- OpenGraph tags -->
|
||||||
<!-- to minimize white flash on load when user has dark mode enabled -->
|
<meta property="og:url" content="https://excalidraw.com" />
|
||||||
<script>
|
<meta property="og:site_name" content="Excalidraw" />
|
||||||
try {
|
<meta property="og:type" content="website" />
|
||||||
//
|
<meta property="og:title" content="Excalidraw" />
|
||||||
const theme = window.localStorage.getItem("excalidraw-theme");
|
<meta
|
||||||
if (theme === "dark") {
|
property="og:description"
|
||||||
document.documentElement.classList.add("dark");
|
content="Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
||||||
}
|
/>
|
||||||
} catch {}
|
<!-- OG tags require an absolute url for images -->
|
||||||
</script>
|
<meta
|
||||||
<style>
|
property="og:image"
|
||||||
html.dark {
|
name="twitter:image"
|
||||||
background-color: #121212;
|
content="https://excalidraw.com/og-image.png"
|
||||||
color: #fff;
|
/>
|
||||||
}
|
<meta
|
||||||
</style>
|
property="og:image:secure_url"
|
||||||
<!------------------------------------------------------------------------->
|
name="twitter:image"
|
||||||
|
content="https://excalidraw.com/og-image.png"
|
||||||
|
/>
|
||||||
|
<meta property="og:image:width" content="1280" />
|
||||||
|
<meta property="og:image:height" content="669" />
|
||||||
|
<meta property="og:image:alt" content="Excalidraw logo with byline." />
|
||||||
|
|
||||||
|
<!-- Twitter Card tags -->
|
||||||
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
|
<meta name="twitter:title" content="Excalidraw" />
|
||||||
|
<meta
|
||||||
|
name="twitter:description"
|
||||||
|
content="Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
||||||
|
/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Redirect Excalidraw+ users which have auto-redirect enabled.
|
// Redirect Excalidraw+ users which have auto-redirect enabled.
|
||||||
@@ -125,7 +98,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<link rel="stylesheet" href="fonts.css" type="text/css" />
|
<link rel="stylesheet" href="fonts.css" type="text/css" />
|
||||||
<% if (process.env.REACT_APP_DEV_DISABLE_LIVE_RELOAD==="true" ) { %>
|
<% if (process.env.REACT_APP_DEV_DISABLE_LIVE_RELOAD === "true") { %>
|
||||||
<script>
|
<script>
|
||||||
{
|
{
|
||||||
const _WebSocket = window.WebSocket;
|
const _WebSocket = window.WebSocket;
|
||||||
@@ -166,8 +139,8 @@
|
|||||||
body,
|
body,
|
||||||
html {
|
html {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
--ui-font: Assistant, system-ui, BlinkMacSystemFont, -apple-system,
|
--ui-font: system-ui, BlinkMacSystemFont, -apple-system, Segoe UI,
|
||||||
Segoe UI, Roboto, Helvetica, Arial, sans-serif;
|
Roboto, Helvetica, Arial, sans-serif;
|
||||||
font-family: var(--ui-font);
|
font-family: var(--ui-font);
|
||||||
-webkit-text-size-adjust: 100%;
|
-webkit-text-size-adjust: 100%;
|
||||||
|
|
||||||
@@ -182,7 +155,7 @@
|
|||||||
width: 1px;
|
width: 1px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
clip: rect(1px, 1px, 1px, 1px);
|
clip: rect(1px, 1px, 1px, 1px);
|
||||||
white-space: nowrap;
|
white-space: nowrap; /* added line */
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB |
@@ -1,9 +1,3 @@
|
|||||||
User-agent: Twitterbot
|
|
||||||
Disallow:
|
|
||||||
|
|
||||||
User-agent: facebookexternalhit
|
|
||||||
Disallow:
|
|
||||||
|
|
||||||
user-agent: *
|
user-agent: *
|
||||||
Allow: /$
|
Allow: /$
|
||||||
Disallow: /
|
Disallow: /
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ const crowdinMap = {
|
|||||||
"fa-IR": "en-fa",
|
"fa-IR": "en-fa",
|
||||||
"fi-FI": "en-fi",
|
"fi-FI": "en-fi",
|
||||||
"fr-FR": "en-fr",
|
"fr-FR": "en-fr",
|
||||||
"gl-ES": "en-gl",
|
|
||||||
"he-IL": "en-he",
|
"he-IL": "en-he",
|
||||||
"hi-IN": "en-hi",
|
"hi-IN": "en-hi",
|
||||||
"hu-HU": "en-hu",
|
"hu-HU": "en-hu",
|
||||||
@@ -24,7 +23,6 @@ const crowdinMap = {
|
|||||||
"ja-JP": "en-ja",
|
"ja-JP": "en-ja",
|
||||||
"kab-KAB": "en-kab",
|
"kab-KAB": "en-kab",
|
||||||
"ko-KR": "en-ko",
|
"ko-KR": "en-ko",
|
||||||
"ku-TR": "en-ku",
|
|
||||||
"my-MM": "en-my",
|
"my-MM": "en-my",
|
||||||
"nb-NO": "en-nb",
|
"nb-NO": "en-nb",
|
||||||
"nl-NL": "en-nl",
|
"nl-NL": "en-nl",
|
||||||
@@ -67,7 +65,6 @@ const flags = {
|
|||||||
"fa-IR": "🇮🇷",
|
"fa-IR": "🇮🇷",
|
||||||
"fi-FI": "🇫🇮",
|
"fi-FI": "🇫🇮",
|
||||||
"fr-FR": "🇫🇷",
|
"fr-FR": "🇫🇷",
|
||||||
"gl-ES": "🇪🇸",
|
|
||||||
"he-IL": "🇮🇱",
|
"he-IL": "🇮🇱",
|
||||||
"hi-IN": "🇮🇳",
|
"hi-IN": "🇮🇳",
|
||||||
"hu-HU": "🇭🇺",
|
"hu-HU": "🇭🇺",
|
||||||
@@ -77,7 +74,6 @@ const flags = {
|
|||||||
"kab-KAB": "🏳",
|
"kab-KAB": "🏳",
|
||||||
"kk-KZ": "🇰🇿",
|
"kk-KZ": "🇰🇿",
|
||||||
"ko-KR": "🇰🇷",
|
"ko-KR": "🇰🇷",
|
||||||
"ku-TR": "🏳",
|
|
||||||
"lt-LT": "🇱🇹",
|
"lt-LT": "🇱🇹",
|
||||||
"lv-LV": "🇱🇻",
|
"lv-LV": "🇱🇻",
|
||||||
"my-MM": "🇲🇲",
|
"my-MM": "🇲🇲",
|
||||||
|
|||||||
+3
-1
@@ -18,4 +18,6 @@ const moveServiceWorkerScript = () => {
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
moveServiceWorkerScript();
|
if (process.env.CI) {
|
||||||
|
moveServiceWorkerScript();
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export const actionAlignTop = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={AlignTopIcon}
|
icon={<AlignTopIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.alignTop")} — ${getShortcutKey(
|
title={`${t("labels.alignTop")} — ${getShortcutKey(
|
||||||
"CtrlOrCmd+Shift+Up",
|
"CtrlOrCmd+Shift+Up",
|
||||||
@@ -90,7 +90,7 @@ export const actionAlignBottom = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={AlignBottomIcon}
|
icon={<AlignBottomIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.alignBottom")} — ${getShortcutKey(
|
title={`${t("labels.alignBottom")} — ${getShortcutKey(
|
||||||
"CtrlOrCmd+Shift+Down",
|
"CtrlOrCmd+Shift+Down",
|
||||||
@@ -120,7 +120,7 @@ export const actionAlignLeft = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={AlignLeftIcon}
|
icon={<AlignLeftIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.alignLeft")} — ${getShortcutKey(
|
title={`${t("labels.alignLeft")} — ${getShortcutKey(
|
||||||
"CtrlOrCmd+Shift+Left",
|
"CtrlOrCmd+Shift+Left",
|
||||||
@@ -151,7 +151,7 @@ export const actionAlignRight = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={AlignRightIcon}
|
icon={<AlignRightIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.alignRight")} — ${getShortcutKey(
|
title={`${t("labels.alignRight")} — ${getShortcutKey(
|
||||||
"CtrlOrCmd+Shift+Right",
|
"CtrlOrCmd+Shift+Right",
|
||||||
@@ -180,7 +180,7 @@ export const actionAlignVerticallyCentered = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={CenterVerticallyIcon}
|
icon={<CenterVerticallyIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={t("labels.centerVertically")}
|
title={t("labels.centerVertically")}
|
||||||
aria-label={t("labels.centerVertically")}
|
aria-label={t("labels.centerVertically")}
|
||||||
@@ -206,7 +206,7 @@ export const actionAlignHorizontallyCentered = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={CenterHorizontallyIcon}
|
icon={<CenterHorizontallyIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={t("labels.centerHorizontally")}
|
title={t("labels.centerHorizontally")}
|
||||||
aria-label={t("labels.centerHorizontally")}
|
aria-label={t("labels.centerHorizontally")}
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import { ColorPicker } from "../components/ColorPicker";
|
import { ColorPicker } from "../components/ColorPicker";
|
||||||
import {
|
import { eraser, zoomIn, zoomOut } from "../components/icons";
|
||||||
eraser,
|
|
||||||
MoonIcon,
|
|
||||||
SunIcon,
|
|
||||||
ZoomInIcon,
|
|
||||||
ZoomOutIcon,
|
|
||||||
} from "../components/icons";
|
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import { MIN_ZOOM, THEME, ZOOM_STEP } from "../constants";
|
import { DarkModeToggle } from "../components/DarkModeToggle";
|
||||||
|
import { THEME, ZOOM_STEP } from "../constants";
|
||||||
import { getCommonBounds, getNonDeletedElements } from "../element";
|
import { getCommonBounds, getNonDeletedElements } from "../element";
|
||||||
import { ExcalidrawElement } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
@@ -23,8 +18,6 @@ import { newElementWith } from "../element/mutateElement";
|
|||||||
import { getDefaultAppState, isEraserActive } from "../appState";
|
import { getDefaultAppState, isEraserActive } from "../appState";
|
||||||
import ClearCanvas from "../components/ClearCanvas";
|
import ClearCanvas from "../components/ClearCanvas";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import MenuItem from "../components/MenuItem";
|
|
||||||
import { getShortcutFromShortcutName } from "./shortcuts";
|
|
||||||
|
|
||||||
export const actionChangeViewBackgroundColor = register({
|
export const actionChangeViewBackgroundColor = register({
|
||||||
name: "changeViewBackgroundColor",
|
name: "changeViewBackgroundColor",
|
||||||
@@ -110,13 +103,13 @@ export const actionZoomIn = register({
|
|||||||
PanelComponent: ({ updateData }) => (
|
PanelComponent: ({ updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
className="zoom-in-button zoom-button"
|
icon={zoomIn}
|
||||||
icon={ZoomInIcon}
|
|
||||||
title={`${t("buttons.zoomIn")} — ${getShortcutKey("CtrlOrCmd++")}`}
|
title={`${t("buttons.zoomIn")} — ${getShortcutKey("CtrlOrCmd++")}`}
|
||||||
aria-label={t("buttons.zoomIn")}
|
aria-label={t("buttons.zoomIn")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateData(null);
|
updateData(null);
|
||||||
}}
|
}}
|
||||||
|
size="small"
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
@@ -146,13 +139,13 @@ export const actionZoomOut = register({
|
|||||||
PanelComponent: ({ updateData }) => (
|
PanelComponent: ({ updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
className="zoom-out-button zoom-button"
|
icon={zoomOut}
|
||||||
icon={ZoomOutIcon}
|
|
||||||
title={`${t("buttons.zoomOut")} — ${getShortcutKey("CtrlOrCmd+-")}`}
|
title={`${t("buttons.zoomOut")} — ${getShortcutKey("CtrlOrCmd+-")}`}
|
||||||
aria-label={t("buttons.zoomOut")}
|
aria-label={t("buttons.zoomOut")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateData(null);
|
updateData(null);
|
||||||
}}
|
}}
|
||||||
|
size="small"
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
@@ -183,12 +176,13 @@ export const actionResetZoom = register({
|
|||||||
<Tooltip label={t("buttons.resetZoom")} style={{ height: "100%" }}>
|
<Tooltip label={t("buttons.resetZoom")} style={{ height: "100%" }}>
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
className="reset-zoom-button zoom-button"
|
className="reset-zoom-button"
|
||||||
title={t("buttons.resetZoom")}
|
title={t("buttons.resetZoom")}
|
||||||
aria-label={t("buttons.resetZoom")}
|
aria-label={t("buttons.resetZoom")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateData(null);
|
updateData(null);
|
||||||
}}
|
}}
|
||||||
|
size="small"
|
||||||
>
|
>
|
||||||
{(appState.zoom.value * 100).toFixed(0)}%
|
{(appState.zoom.value * 100).toFixed(0)}%
|
||||||
</ToolButton>
|
</ToolButton>
|
||||||
@@ -212,7 +206,7 @@ const zoomValueToFitBoundsOnViewport = (
|
|||||||
const zoomAdjustedToSteps =
|
const zoomAdjustedToSteps =
|
||||||
Math.floor(smallestZoomValue / ZOOM_STEP) * ZOOM_STEP;
|
Math.floor(smallestZoomValue / ZOOM_STEP) * ZOOM_STEP;
|
||||||
const clampedZoomValueToFitElements = Math.min(
|
const clampedZoomValueToFitElements = Math.min(
|
||||||
Math.max(zoomAdjustedToSteps, MIN_ZOOM),
|
Math.max(zoomAdjustedToSteps, ZOOM_STEP),
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
return clampedZoomValueToFitElements as NormalizedZoomValue;
|
return clampedZoomValueToFitElements as NormalizedZoomValue;
|
||||||
@@ -294,19 +288,14 @@ export const actionToggleTheme = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ appState, updateData }) => (
|
PanelComponent: ({ appState, updateData }) => (
|
||||||
<MenuItem
|
<div style={{ marginInlineStart: "0.25rem" }}>
|
||||||
label={
|
<DarkModeToggle
|
||||||
appState.theme === "dark"
|
value={appState.theme}
|
||||||
? t("buttons.lightMode")
|
onChange={(theme) => {
|
||||||
: t("buttons.darkMode")
|
updateData(theme);
|
||||||
}
|
}}
|
||||||
onClick={() => {
|
/>
|
||||||
updateData(appState.theme === THEME.LIGHT ? THEME.DARK : THEME.LIGHT);
|
</div>
|
||||||
}}
|
|
||||||
icon={appState.theme === "dark" ? SunIcon : MoonIcon}
|
|
||||||
dataTestId="toggle-dark-mode"
|
|
||||||
shortcut={getShortcutFromShortcutName("toggleTheme")}
|
|
||||||
/>
|
|
||||||
),
|
),
|
||||||
keyTest: (event) => event.altKey && event.shiftKey && event.code === CODES.D,
|
keyTest: (event) => event.altKey && event.shiftKey && event.code === CODES.D,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export const actionCut = register({
|
|||||||
return actionDeleteSelected.perform(elements, appState);
|
return actionDeleteSelected.perform(elements, appState);
|
||||||
},
|
},
|
||||||
contextItemLabel: "labels.cut",
|
contextItemLabel: "labels.cut",
|
||||||
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.X,
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.X,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionCopyAsSvg = register({
|
export const actionCopyAsSvg = register({
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { isSomeElementSelected } from "../scene";
|
import { isSomeElementSelected } from "../scene";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
|
import { trash } from "../components/icons";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { getNonDeletedElements } from "../element";
|
import { getNonDeletedElements } from "../element";
|
||||||
@@ -12,7 +13,6 @@ import { LinearElementEditor } from "../element/linearElementEditor";
|
|||||||
import { fixBindingsAfterDeletion } from "../element/binding";
|
import { fixBindingsAfterDeletion } from "../element/binding";
|
||||||
import { isBoundToContainer } from "../element/typeChecks";
|
import { isBoundToContainer } from "../element/typeChecks";
|
||||||
import { updateActiveTool } from "../utils";
|
import { updateActiveTool } from "../utils";
|
||||||
import { TrashIcon } from "../components/icons";
|
|
||||||
|
|
||||||
const deleteSelectedElements = (
|
const deleteSelectedElements = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
@@ -72,22 +72,13 @@ export const actionDeleteSelected = register({
|
|||||||
if (!element) {
|
if (!element) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// case: no point selected → do nothing, as deleting the whole element
|
if (
|
||||||
// is most likely a mistake, where you wanted to delete a specific point
|
// case: no point selected → delete whole element
|
||||||
// but failed to select it (or you thought it's selected, while it was
|
selectedPointsIndices == null ||
|
||||||
// only in a hover state)
|
// case: deleting last remaining point
|
||||||
if (selectedPointsIndices == null) {
|
element.points.length < 2
|
||||||
return false;
|
) {
|
||||||
}
|
const nextElements = elements.filter((el) => el.id !== element.id);
|
||||||
|
|
||||||
// case: deleting last remaining point
|
|
||||||
if (element.points.length < 2) {
|
|
||||||
const nextElements = elements.map((el) => {
|
|
||||||
if (el.id === element.id) {
|
|
||||||
return newElementWith(el, { isDeleted: true });
|
|
||||||
}
|
|
||||||
return el;
|
|
||||||
});
|
|
||||||
const nextAppState = handleGroupEditingState(appState, nextElements);
|
const nextAppState = handleGroupEditingState(appState, nextElements);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -158,7 +149,7 @@ export const actionDeleteSelected = register({
|
|||||||
PanelComponent: ({ elements, appState, updateData }) => (
|
PanelComponent: ({ elements, appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={TrashIcon}
|
icon={trash}
|
||||||
title={t("labels.delete")}
|
title={t("labels.delete")}
|
||||||
aria-label={t("labels.delete")}
|
aria-label={t("labels.delete")}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export const distributeHorizontally = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={DistributeHorizontallyIcon}
|
icon={<DistributeHorizontallyIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.distributeHorizontally")} — ${getShortcutKey(
|
title={`${t("labels.distributeHorizontally")} — ${getShortcutKey(
|
||||||
"Alt+H",
|
"Alt+H",
|
||||||
@@ -86,7 +86,7 @@ export const distributeVertically = register({
|
|||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
type="button"
|
type="button"
|
||||||
icon={DistributeVerticallyIcon}
|
icon={<DistributeVerticallyIcon theme={appState.theme} />}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.distributeVertically")} — ${getShortcutKey("Alt+V")}`}
|
title={`${t("labels.distributeVertically")} — ${getShortcutKey("Alt+V")}`}
|
||||||
aria-label={t("labels.distributeVertically")}
|
aria-label={t("labels.distributeVertically")}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ExcalidrawElement } from "../element/types";
|
|||||||
import { duplicateElement, getNonDeletedElements } from "../element";
|
import { duplicateElement, getNonDeletedElements } from "../element";
|
||||||
import { getSelectedElements, isSomeElementSelected } from "../scene";
|
import { getSelectedElements, isSomeElementSelected } from "../scene";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
|
import { clone } from "../components/icons";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { arrayToMap, getShortcutKey } from "../utils";
|
import { arrayToMap, getShortcutKey } from "../utils";
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||||
@@ -18,7 +19,6 @@ import { ActionResult } from "./types";
|
|||||||
import { GRID_SIZE } from "../constants";
|
import { GRID_SIZE } from "../constants";
|
||||||
import { bindTextToShapeAfterDuplication } from "../element/textElement";
|
import { bindTextToShapeAfterDuplication } from "../element/textElement";
|
||||||
import { isBoundToContainer } from "../element/typeChecks";
|
import { isBoundToContainer } from "../element/typeChecks";
|
||||||
import { DuplicateIcon } from "../components/icons";
|
|
||||||
|
|
||||||
export const actionDuplicateSelection = register({
|
export const actionDuplicateSelection = register({
|
||||||
name: "duplicateSelection",
|
name: "duplicateSelection",
|
||||||
@@ -49,7 +49,7 @@ export const actionDuplicateSelection = register({
|
|||||||
PanelComponent: ({ elements, appState, updateData }) => (
|
PanelComponent: ({ elements, appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={DuplicateIcon}
|
icon={clone}
|
||||||
title={`${t("labels.duplicateSelection")} — ${getShortcutKey(
|
title={`${t("labels.duplicateSelection")} — ${getShortcutKey(
|
||||||
"CtrlOrCmd+D",
|
"CtrlOrCmd+D",
|
||||||
)}`}
|
)}`}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LoadIcon, questionCircle, saveAs } from "../components/icons";
|
import { load, questionCircle, saveAs } from "../components/icons";
|
||||||
import { ProjectName } from "../components/ProjectName";
|
import { ProjectName } from "../components/ProjectName";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import "../components/ToolIcon.scss";
|
import "../components/ToolIcon.scss";
|
||||||
@@ -19,8 +19,6 @@ import { ActiveFile } from "../components/ActiveFile";
|
|||||||
import { isImageFileHandle } from "../data/blob";
|
import { isImageFileHandle } from "../data/blob";
|
||||||
import { nativeFileSystemSupported } from "../data/filesystem";
|
import { nativeFileSystemSupported } from "../data/filesystem";
|
||||||
import { Theme } from "../element/types";
|
import { Theme } from "../element/types";
|
||||||
import MenuItem from "../components/MenuItem";
|
|
||||||
import { getShortcutFromShortcutName } from "./shortcuts";
|
|
||||||
|
|
||||||
export const actionChangeProjectName = register({
|
export const actionChangeProjectName = register({
|
||||||
name: "changeProjectName",
|
name: "changeProjectName",
|
||||||
@@ -89,28 +87,6 @@ export const actionChangeExportScale = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeExportPadding = register({
|
|
||||||
name: "changeExportPadding",
|
|
||||||
trackEvent: { category: "export", action: "togglePadding" },
|
|
||||||
perform: (_elements, appState, value) => {
|
|
||||||
return {
|
|
||||||
appState: {
|
|
||||||
...appState,
|
|
||||||
exportPadding: value ? DEFAULT_EXPORT_PADDING : 0,
|
|
||||||
},
|
|
||||||
commitToHistory: false,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
PanelComponent: ({ appState, updateData }) => (
|
|
||||||
<CheckboxItem
|
|
||||||
checked={!!appState.exportPadding}
|
|
||||||
onChange={(checked) => updateData(checked)}
|
|
||||||
>
|
|
||||||
{"Padding"}
|
|
||||||
</CheckboxItem>
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const actionChangeExportBackground = register({
|
export const actionChangeExportBackground = register({
|
||||||
name: "changeExportBackground",
|
name: "changeExportBackground",
|
||||||
trackEvent: { category: "export", action: "toggleBackground" },
|
trackEvent: { category: "export", action: "toggleBackground" },
|
||||||
@@ -268,13 +244,15 @@ export const actionLoadScene = register({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.O,
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.O,
|
||||||
PanelComponent: ({ updateData }) => (
|
PanelComponent: ({ updateData, appState }) => (
|
||||||
<MenuItem
|
<ToolButton
|
||||||
label={t("buttons.load")}
|
type="button"
|
||||||
icon={LoadIcon}
|
icon={load}
|
||||||
|
title={t("buttons.load")}
|
||||||
|
aria-label={t("buttons.load")}
|
||||||
|
showAriaLabel={useDevice().isMobile}
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
dataTestId="load-button"
|
data-testid="load-button"
|
||||||
shortcut={getShortcutFromShortcutName("loadScene")}
|
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
+22
-64
@@ -6,14 +6,10 @@ import { ExcalidrawElement, NonDeleted } from "../element/types";
|
|||||||
import { normalizeAngle, resizeSingleElement } from "../element/resizeElements";
|
import { normalizeAngle, resizeSingleElement } from "../element/resizeElements";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { getTransformHandles } from "../element/transformHandles";
|
import { getTransformHandles } from "../element/transformHandles";
|
||||||
|
import { isFreeDrawElement, isLinearElement } from "../element/typeChecks";
|
||||||
import { updateBoundElements } from "../element/binding";
|
import { updateBoundElements } from "../element/binding";
|
||||||
import { arrayToMap } from "../utils";
|
|
||||||
import {
|
|
||||||
getElementAbsoluteCoords,
|
|
||||||
getElementPointsCoords,
|
|
||||||
} from "../element/bounds";
|
|
||||||
import { isLinearElement } from "../element/typeChecks";
|
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||||
|
import { arrayToMap } from "../utils";
|
||||||
|
|
||||||
const enableActionFlipHorizontal = (
|
const enableActionFlipHorizontal = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
@@ -122,6 +118,13 @@ const flipElement = (
|
|||||||
const height = element.height;
|
const height = element.height;
|
||||||
const originalAngle = normalizeAngle(element.angle);
|
const originalAngle = normalizeAngle(element.angle);
|
||||||
|
|
||||||
|
let finalOffsetX = 0;
|
||||||
|
if (isLinearElement(element) || isFreeDrawElement(element)) {
|
||||||
|
finalOffsetX =
|
||||||
|
element.points.reduce((max, point) => Math.max(max, point[0]), 0) * 2 -
|
||||||
|
element.width;
|
||||||
|
}
|
||||||
|
|
||||||
// Rotate back to zero, if necessary
|
// Rotate back to zero, if necessary
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
angle: normalizeAngle(0),
|
angle: normalizeAngle(0),
|
||||||
@@ -129,6 +132,7 @@ const flipElement = (
|
|||||||
// Flip unrotated by pulling TransformHandle to opposite side
|
// Flip unrotated by pulling TransformHandle to opposite side
|
||||||
const transformHandles = getTransformHandles(element, appState.zoom);
|
const transformHandles = getTransformHandles(element, appState.zoom);
|
||||||
let usingNWHandle = true;
|
let usingNWHandle = true;
|
||||||
|
let newNCoordsX = 0;
|
||||||
let nHandle = transformHandles.nw;
|
let nHandle = transformHandles.nw;
|
||||||
if (!nHandle) {
|
if (!nHandle) {
|
||||||
// Use ne handle instead
|
// Use ne handle instead
|
||||||
@@ -142,51 +146,30 @@ const flipElement = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let finalOffsetX = 0;
|
|
||||||
if (isLinearElement(element) && element.points.length < 3) {
|
|
||||||
finalOffsetX =
|
|
||||||
element.points.reduce((max, point) => Math.max(max, point[0]), 0) * 2 -
|
|
||||||
element.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
let initialPointsCoords;
|
|
||||||
if (isLinearElement(element)) {
|
if (isLinearElement(element)) {
|
||||||
initialPointsCoords = getElementPointsCoords(
|
|
||||||
element,
|
|
||||||
element.points,
|
|
||||||
element.strokeSharpness,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const initialElementAbsoluteCoords = getElementAbsoluteCoords(element);
|
|
||||||
|
|
||||||
if (isLinearElement(element) && element.points.length < 3) {
|
|
||||||
for (let index = 1; index < element.points.length; index++) {
|
for (let index = 1; index < element.points.length; index++) {
|
||||||
LinearElementEditor.movePoints(element, [
|
LinearElementEditor.movePoints(element, [
|
||||||
{
|
{ index, point: [-element.points[index][0], element.points[index][1]] },
|
||||||
index,
|
|
||||||
point: [-element.points[index][0], element.points[index][1]],
|
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
LinearElementEditor.normalizePoints(element);
|
LinearElementEditor.normalizePoints(element);
|
||||||
} else {
|
} else {
|
||||||
const elWidth = initialPointsCoords
|
// calculate new x-coord for transformation
|
||||||
? initialPointsCoords[2] - initialPointsCoords[0]
|
newNCoordsX = usingNWHandle ? element.x + 2 * width : element.x - 2 * width;
|
||||||
: initialElementAbsoluteCoords[2] - initialElementAbsoluteCoords[0];
|
|
||||||
|
|
||||||
const startPoint = initialPointsCoords
|
|
||||||
? [initialPointsCoords[0], initialPointsCoords[1]]
|
|
||||||
: [initialElementAbsoluteCoords[0], initialElementAbsoluteCoords[1]];
|
|
||||||
|
|
||||||
resizeSingleElement(
|
resizeSingleElement(
|
||||||
new Map().set(element.id, element),
|
new Map().set(element.id, element),
|
||||||
false,
|
true,
|
||||||
element,
|
element,
|
||||||
usingNWHandle ? "nw" : "ne",
|
usingNWHandle ? "nw" : "ne",
|
||||||
true,
|
false,
|
||||||
usingNWHandle ? startPoint[0] + elWidth : startPoint[0] - elWidth,
|
newNCoordsX,
|
||||||
startPoint[1],
|
nHandle[1],
|
||||||
);
|
);
|
||||||
|
// fix the size to account for handle sizes
|
||||||
|
mutateElement(element, {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate by (360 degrees - original angle)
|
// Rotate by (360 degrees - original angle)
|
||||||
@@ -203,34 +186,9 @@ const flipElement = (
|
|||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
x: originalX + finalOffsetX,
|
x: originalX + finalOffsetX,
|
||||||
y: originalY,
|
y: originalY,
|
||||||
width,
|
|
||||||
height,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
updateBoundElements(element);
|
updateBoundElements(element);
|
||||||
|
|
||||||
if (initialPointsCoords && isLinearElement(element)) {
|
|
||||||
// Adjusting origin because when a beizer curve path exceeds min/max points it offsets the origin.
|
|
||||||
// There's still room for improvement since when the line roughness is > 1
|
|
||||||
// we still have a small offset of the origin when fliipping the element.
|
|
||||||
const finalPointsCoords = getElementPointsCoords(
|
|
||||||
element,
|
|
||||||
element.points,
|
|
||||||
element.strokeSharpness,
|
|
||||||
);
|
|
||||||
|
|
||||||
const topLeftCoordsDiff = initialPointsCoords[0] - finalPointsCoords[0];
|
|
||||||
const topRightCoordDiff = initialPointsCoords[2] - finalPointsCoords[2];
|
|
||||||
|
|
||||||
const coordsDiff = topLeftCoordsDiff + topRightCoordDiff;
|
|
||||||
|
|
||||||
mutateElement(element, {
|
|
||||||
x: element.x + coordsDiff * 0.5,
|
|
||||||
y: element.y,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const rotateElement = (element: ExcalidrawElement, rotationAngle: number) => {
|
const rotateElement = (element: ExcalidrawElement, rotationAngle: number) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { KEYS } from "../keys";
|
import { CODES, KEYS } from "../keys";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { arrayToMap, getShortcutKey } from "../utils";
|
import { arrayToMap, getShortcutKey } from "../utils";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
@@ -132,7 +132,7 @@ export const actionGroup = register({
|
|||||||
contextItemPredicate: (elements, appState) =>
|
contextItemPredicate: (elements, appState) =>
|
||||||
enableActionGroup(elements, appState),
|
enableActionGroup(elements, appState),
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
!event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.key === KEYS.G,
|
!event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.code === CODES.G,
|
||||||
PanelComponent: ({ elements, appState, updateData }) => (
|
PanelComponent: ({ elements, appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
@@ -189,9 +189,7 @@ export const actionUngroup = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
event.shiftKey &&
|
event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.code === CODES.G,
|
||||||
event[KEYS.CTRL_OR_CMD] &&
|
|
||||||
event.key === KEYS.G.toUpperCase(),
|
|
||||||
contextItemLabel: "labels.ungroup",
|
contextItemLabel: "labels.ungroup",
|
||||||
contextItemPredicate: (elements, appState) =>
|
contextItemPredicate: (elements, appState) =>
|
||||||
getSelectedGroupIds(appState).length > 0,
|
getSelectedGroupIds(appState).length > 0,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Action, ActionResult } from "./types";
|
import { Action, ActionResult } from "./types";
|
||||||
import { UndoIcon, RedoIcon } from "../components/icons";
|
import { undo, redo } from "../components/icons";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import History, { HistoryEntry } from "../history";
|
import History, { HistoryEntry } from "../history";
|
||||||
@@ -72,7 +72,7 @@ export const createUndoAction: ActionCreator = (history) => ({
|
|||||||
PanelComponent: ({ updateData, data }) => (
|
PanelComponent: ({ updateData, data }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={UndoIcon}
|
icon={undo}
|
||||||
aria-label={t("buttons.undo")}
|
aria-label={t("buttons.undo")}
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
size={data?.size || "medium"}
|
size={data?.size || "medium"}
|
||||||
@@ -94,7 +94,7 @@ export const createRedoAction: ActionCreator = (history) => ({
|
|||||||
PanelComponent: ({ updateData, data }) => (
|
PanelComponent: ({ updateData, data }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={RedoIcon}
|
icon={redo}
|
||||||
aria-label={t("buttons.redo")}
|
aria-label={t("buttons.redo")}
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
size={data?.size || "medium"}
|
size={data?.size || "medium"}
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
import { getNonDeletedElements } from "../element";
|
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
|
||||||
import { isLinearElement } from "../element/typeChecks";
|
|
||||||
import { ExcalidrawLinearElement } from "../element/types";
|
|
||||||
import { getSelectedElements } from "../scene";
|
|
||||||
import { register } from "./register";
|
|
||||||
|
|
||||||
export const actionToggleLinearEditor = register({
|
|
||||||
name: "toggleLinearEditor",
|
|
||||||
trackEvent: {
|
|
||||||
category: "element",
|
|
||||||
},
|
|
||||||
contextItemPredicate: (elements, appState) => {
|
|
||||||
const selectedElements = getSelectedElements(elements, appState);
|
|
||||||
if (selectedElements.length === 1 && isLinearElement(selectedElements[0])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
perform(elements, appState, _, app) {
|
|
||||||
const selectedElement = getSelectedElements(
|
|
||||||
getNonDeletedElements(elements),
|
|
||||||
appState,
|
|
||||||
true,
|
|
||||||
)[0] as ExcalidrawLinearElement;
|
|
||||||
|
|
||||||
const editingLinearElement =
|
|
||||||
appState.editingLinearElement?.elementId === selectedElement.id
|
|
||||||
? null
|
|
||||||
: new LinearElementEditor(selectedElement, app.scene);
|
|
||||||
return {
|
|
||||||
appState: {
|
|
||||||
...appState,
|
|
||||||
editingLinearElement,
|
|
||||||
},
|
|
||||||
commitToHistory: false,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
contextItemLabel: (elements, appState) => {
|
|
||||||
const selectedElement = getSelectedElements(
|
|
||||||
getNonDeletedElements(elements),
|
|
||||||
appState,
|
|
||||||
true,
|
|
||||||
)[0] as ExcalidrawLinearElement;
|
|
||||||
return appState.editingLinearElement?.elementId === selectedElement.id
|
|
||||||
? "labels.lineEditor.exit"
|
|
||||||
: "labels.lineEditor.edit";
|
|
||||||
},
|
|
||||||
});
|
|
||||||
+10
-20
@@ -1,12 +1,11 @@
|
|||||||
import { HamburgerMenuIcon, HelpIcon, palette } from "../components/icons";
|
import { menu, palette } from "../components/icons";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { showSelectedShapeActions, getNonDeletedElements } from "../element";
|
import { showSelectedShapeActions, getNonDeletedElements } from "../element";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils";
|
import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils";
|
||||||
import { KEYS } from "../keys";
|
import { CODES, KEYS } from "../keys";
|
||||||
import { HelpButton } from "../components/HelpButton";
|
import { HelpIcon } from "../components/HelpIcon";
|
||||||
import MenuItem from "../components/MenuItem";
|
|
||||||
|
|
||||||
export const actionToggleCanvasMenu = register({
|
export const actionToggleCanvasMenu = register({
|
||||||
name: "toggleCanvasMenu",
|
name: "toggleCanvasMenu",
|
||||||
@@ -21,7 +20,7 @@ export const actionToggleCanvasMenu = register({
|
|||||||
PanelComponent: ({ appState, updateData }) => (
|
PanelComponent: ({ appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={HamburgerMenuIcon}
|
icon={menu}
|
||||||
aria-label={t("buttons.menu")}
|
aria-label={t("buttons.menu")}
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
selected={appState.openMenu === "canvas"}
|
selected={appState.openMenu === "canvas"}
|
||||||
@@ -68,35 +67,26 @@ export const actionFullScreen = register({
|
|||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) => event.key === KEYS.F && !event[KEYS.CTRL_OR_CMD],
|
keyTest: (event) => event.code === CODES.F && !event[KEYS.CTRL_OR_CMD],
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionShortcuts = register({
|
export const actionShortcuts = register({
|
||||||
name: "toggleShortcuts",
|
name: "toggleShortcuts",
|
||||||
trackEvent: { category: "menu", action: "toggleHelpDialog" },
|
trackEvent: { category: "menu", action: "toggleHelpDialog" },
|
||||||
perform: (_elements, appState, _, { focusContainer }) => {
|
perform: (_elements, appState, _, { focusContainer }) => {
|
||||||
if (appState.openDialog === "help") {
|
if (appState.showHelpDialog) {
|
||||||
focusContainer();
|
focusContainer();
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
openDialog: appState.openDialog === "help" ? null : "help",
|
showHelpDialog: !appState.showHelpDialog,
|
||||||
},
|
},
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ updateData, isInHamburgerMenu }) =>
|
PanelComponent: ({ updateData }) => (
|
||||||
isInHamburgerMenu ? (
|
<HelpIcon title={t("helpDialog.title")} onClick={updateData} />
|
||||||
<MenuItem
|
),
|
||||||
label={t("helpDialog.title")}
|
|
||||||
dataTestId="help-menu-item"
|
|
||||||
icon={HelpIcon}
|
|
||||||
onClick={updateData}
|
|
||||||
shortcut="?"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<HelpButton title={t("helpDialog.title")} onClick={updateData} />
|
|
||||||
),
|
|
||||||
keyTest: (event) => event.key === KEYS.QUESTION_MARK,
|
keyTest: (event) => event.key === KEYS.QUESTION_MARK,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,41 +2,37 @@ import { AppState } from "../../src/types";
|
|||||||
import { ButtonIconSelect } from "../components/ButtonIconSelect";
|
import { ButtonIconSelect } from "../components/ButtonIconSelect";
|
||||||
import { ColorPicker } from "../components/ColorPicker";
|
import { ColorPicker } from "../components/ColorPicker";
|
||||||
import { IconPicker } from "../components/IconPicker";
|
import { IconPicker } from "../components/IconPicker";
|
||||||
// TODO barnabasmolnar/editor-redesign
|
|
||||||
// TextAlignTopIcon, TextAlignBottomIcon,TextAlignMiddleIcon,
|
|
||||||
// ArrowHead icons
|
|
||||||
import {
|
import {
|
||||||
ArrowheadArrowIcon,
|
ArrowheadArrowIcon,
|
||||||
ArrowheadBarIcon,
|
ArrowheadBarIcon,
|
||||||
ArrowheadDotIcon,
|
ArrowheadDotIcon,
|
||||||
ArrowheadTriangleIcon,
|
ArrowheadTriangleIcon,
|
||||||
ArrowheadNoneIcon,
|
ArrowheadNoneIcon,
|
||||||
StrokeStyleDashedIcon,
|
EdgeRoundIcon,
|
||||||
StrokeStyleDottedIcon,
|
EdgeSharpIcon,
|
||||||
TextAlignTopIcon,
|
|
||||||
TextAlignBottomIcon,
|
|
||||||
TextAlignMiddleIcon,
|
|
||||||
FillHachureIcon,
|
|
||||||
FillCrossHatchIcon,
|
FillCrossHatchIcon,
|
||||||
|
FillHachureIcon,
|
||||||
FillSolidIcon,
|
FillSolidIcon,
|
||||||
|
FontFamilyCodeIcon,
|
||||||
|
FontFamilyHandDrawnIcon,
|
||||||
|
FontFamilyNormalIcon,
|
||||||
|
FontSizeExtraLargeIcon,
|
||||||
|
FontSizeLargeIcon,
|
||||||
|
FontSizeMediumIcon,
|
||||||
|
FontSizeSmallIcon,
|
||||||
SloppinessArchitectIcon,
|
SloppinessArchitectIcon,
|
||||||
SloppinessArtistIcon,
|
SloppinessArtistIcon,
|
||||||
SloppinessCartoonistIcon,
|
SloppinessCartoonistIcon,
|
||||||
StrokeWidthBaseIcon,
|
StrokeStyleDashedIcon,
|
||||||
StrokeWidthBoldIcon,
|
StrokeStyleDottedIcon,
|
||||||
StrokeWidthExtraBoldIcon,
|
StrokeStyleSolidIcon,
|
||||||
FontSizeSmallIcon,
|
StrokeWidthIcon,
|
||||||
FontSizeMediumIcon,
|
|
||||||
FontSizeLargeIcon,
|
|
||||||
FontSizeExtraLargeIcon,
|
|
||||||
EdgeSharpIcon,
|
|
||||||
EdgeRoundIcon,
|
|
||||||
FreedrawIcon,
|
|
||||||
FontFamilyNormalIcon,
|
|
||||||
FontFamilyCodeIcon,
|
|
||||||
TextAlignLeftIcon,
|
|
||||||
TextAlignCenterIcon,
|
TextAlignCenterIcon,
|
||||||
|
TextAlignLeftIcon,
|
||||||
TextAlignRightIcon,
|
TextAlignRightIcon,
|
||||||
|
TextAlignTopIcon,
|
||||||
|
TextAlignBottomIcon,
|
||||||
|
TextAlignMiddleIcon,
|
||||||
} from "../components/icons";
|
} from "../components/icons";
|
||||||
import {
|
import {
|
||||||
DEFAULT_FONT_FAMILY,
|
DEFAULT_FONT_FAMILY,
|
||||||
@@ -311,17 +307,17 @@ export const actionChangeFillStyle = register({
|
|||||||
{
|
{
|
||||||
value: "hachure",
|
value: "hachure",
|
||||||
text: t("labels.hachure"),
|
text: t("labels.hachure"),
|
||||||
icon: FillHachureIcon,
|
icon: <FillHachureIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "cross-hatch",
|
value: "cross-hatch",
|
||||||
text: t("labels.crossHatch"),
|
text: t("labels.crossHatch"),
|
||||||
icon: FillCrossHatchIcon,
|
icon: <FillCrossHatchIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "solid",
|
value: "solid",
|
||||||
text: t("labels.solid"),
|
text: t("labels.solid"),
|
||||||
icon: FillSolidIcon,
|
icon: <FillSolidIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
group="fill"
|
group="fill"
|
||||||
@@ -362,17 +358,17 @@ export const actionChangeStrokeWidth = register({
|
|||||||
{
|
{
|
||||||
value: 1,
|
value: 1,
|
||||||
text: t("labels.thin"),
|
text: t("labels.thin"),
|
||||||
icon: StrokeWidthBaseIcon,
|
icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={2} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 2,
|
value: 2,
|
||||||
text: t("labels.bold"),
|
text: t("labels.bold"),
|
||||||
icon: StrokeWidthBoldIcon,
|
icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={6} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 4,
|
value: 4,
|
||||||
text: t("labels.extraBold"),
|
text: t("labels.extraBold"),
|
||||||
icon: StrokeWidthExtraBoldIcon,
|
icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={10} />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -411,17 +407,17 @@ export const actionChangeSloppiness = register({
|
|||||||
{
|
{
|
||||||
value: 0,
|
value: 0,
|
||||||
text: t("labels.architect"),
|
text: t("labels.architect"),
|
||||||
icon: SloppinessArchitectIcon,
|
icon: <SloppinessArchitectIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 1,
|
value: 1,
|
||||||
text: t("labels.artist"),
|
text: t("labels.artist"),
|
||||||
icon: SloppinessArtistIcon,
|
icon: <SloppinessArtistIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 2,
|
value: 2,
|
||||||
text: t("labels.cartoonist"),
|
text: t("labels.cartoonist"),
|
||||||
icon: SloppinessCartoonistIcon,
|
icon: <SloppinessCartoonistIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -459,17 +455,17 @@ export const actionChangeStrokeStyle = register({
|
|||||||
{
|
{
|
||||||
value: "solid",
|
value: "solid",
|
||||||
text: t("labels.strokeStyle_solid"),
|
text: t("labels.strokeStyle_solid"),
|
||||||
icon: StrokeWidthBaseIcon,
|
icon: <StrokeStyleSolidIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dashed",
|
value: "dashed",
|
||||||
text: t("labels.strokeStyle_dashed"),
|
text: t("labels.strokeStyle_dashed"),
|
||||||
icon: StrokeStyleDashedIcon,
|
icon: <StrokeStyleDashedIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dotted",
|
value: "dotted",
|
||||||
text: t("labels.strokeStyle_dotted"),
|
text: t("labels.strokeStyle_dotted"),
|
||||||
icon: StrokeStyleDottedIcon,
|
icon: <StrokeStyleDottedIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -539,25 +535,25 @@ export const actionChangeFontSize = register({
|
|||||||
{
|
{
|
||||||
value: 16,
|
value: 16,
|
||||||
text: t("labels.small"),
|
text: t("labels.small"),
|
||||||
icon: FontSizeSmallIcon,
|
icon: <FontSizeSmallIcon theme={appState.theme} />,
|
||||||
testId: "fontSize-small",
|
testId: "fontSize-small",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 20,
|
value: 20,
|
||||||
text: t("labels.medium"),
|
text: t("labels.medium"),
|
||||||
icon: FontSizeMediumIcon,
|
icon: <FontSizeMediumIcon theme={appState.theme} />,
|
||||||
testId: "fontSize-medium",
|
testId: "fontSize-medium",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 28,
|
value: 28,
|
||||||
text: t("labels.large"),
|
text: t("labels.large"),
|
||||||
icon: FontSizeLargeIcon,
|
icon: <FontSizeLargeIcon theme={appState.theme} />,
|
||||||
testId: "fontSize-large",
|
testId: "fontSize-large",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 36,
|
value: 36,
|
||||||
text: t("labels.veryLarge"),
|
text: t("labels.veryLarge"),
|
||||||
icon: FontSizeExtraLargeIcon,
|
icon: <FontSizeExtraLargeIcon theme={appState.theme} />,
|
||||||
testId: "fontSize-veryLarge",
|
testId: "fontSize-veryLarge",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
@@ -662,17 +658,17 @@ export const actionChangeFontFamily = register({
|
|||||||
{
|
{
|
||||||
value: FONT_FAMILY.Virgil,
|
value: FONT_FAMILY.Virgil,
|
||||||
text: t("labels.handDrawn"),
|
text: t("labels.handDrawn"),
|
||||||
icon: FreedrawIcon,
|
icon: <FontFamilyHandDrawnIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: FONT_FAMILY.Helvetica,
|
value: FONT_FAMILY.Helvetica,
|
||||||
text: t("labels.normal"),
|
text: t("labels.normal"),
|
||||||
icon: FontFamilyNormalIcon,
|
icon: <FontFamilyNormalIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: FONT_FAMILY.Cascadia,
|
value: FONT_FAMILY.Cascadia,
|
||||||
text: t("labels.code"),
|
text: t("labels.code"),
|
||||||
icon: FontFamilyCodeIcon,
|
icon: <FontFamilyCodeIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -743,17 +739,17 @@ export const actionChangeTextAlign = register({
|
|||||||
{
|
{
|
||||||
value: "left",
|
value: "left",
|
||||||
text: t("labels.left"),
|
text: t("labels.left"),
|
||||||
icon: TextAlignLeftIcon,
|
icon: <TextAlignLeftIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "center",
|
value: "center",
|
||||||
text: t("labels.center"),
|
text: t("labels.center"),
|
||||||
icon: TextAlignCenterIcon,
|
icon: <TextAlignCenterIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "right",
|
value: "right",
|
||||||
text: t("labels.right"),
|
text: t("labels.right"),
|
||||||
icon: TextAlignRightIcon,
|
icon: <TextAlignRightIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -886,12 +882,12 @@ export const actionChangeSharpness = register({
|
|||||||
{
|
{
|
||||||
value: "sharp",
|
value: "sharp",
|
||||||
text: t("labels.sharp"),
|
text: t("labels.sharp"),
|
||||||
icon: EdgeSharpIcon,
|
icon: <EdgeSharpIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "round",
|
value: "round",
|
||||||
text: t("labels.round"),
|
text: t("labels.round"),
|
||||||
icon: EdgeRoundIcon,
|
icon: <EdgeRoundIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -953,38 +949,42 @@ export const actionChangeArrowhead = register({
|
|||||||
return (
|
return (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.arrowheads")}</legend>
|
<legend>{t("labels.arrowheads")}</legend>
|
||||||
<div className="iconSelectList buttonList">
|
<div className="iconSelectList">
|
||||||
<IconPicker
|
<IconPicker
|
||||||
label="arrowhead_start"
|
label="arrowhead_start"
|
||||||
options={[
|
options={[
|
||||||
{
|
{
|
||||||
value: null,
|
value: null,
|
||||||
text: t("labels.arrowhead_none"),
|
text: t("labels.arrowhead_none"),
|
||||||
icon: ArrowheadNoneIcon,
|
icon: <ArrowheadNoneIcon theme={appState.theme} />,
|
||||||
keyBinding: "q",
|
keyBinding: "q",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "arrow",
|
value: "arrow",
|
||||||
text: t("labels.arrowhead_arrow"),
|
text: t("labels.arrowhead_arrow"),
|
||||||
icon: <ArrowheadArrowIcon flip={!isRTL} />,
|
icon: (
|
||||||
|
<ArrowheadArrowIcon theme={appState.theme} flip={!isRTL} />
|
||||||
|
),
|
||||||
keyBinding: "w",
|
keyBinding: "w",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "bar",
|
value: "bar",
|
||||||
text: t("labels.arrowhead_bar"),
|
text: t("labels.arrowhead_bar"),
|
||||||
icon: <ArrowheadBarIcon flip={!isRTL} />,
|
icon: <ArrowheadBarIcon theme={appState.theme} flip={!isRTL} />,
|
||||||
keyBinding: "e",
|
keyBinding: "e",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dot",
|
value: "dot",
|
||||||
text: t("labels.arrowhead_dot"),
|
text: t("labels.arrowhead_dot"),
|
||||||
icon: <ArrowheadDotIcon flip={!isRTL} />,
|
icon: <ArrowheadDotIcon theme={appState.theme} flip={!isRTL} />,
|
||||||
keyBinding: "r",
|
keyBinding: "r",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "triangle",
|
value: "triangle",
|
||||||
text: t("labels.arrowhead_triangle"),
|
text: t("labels.arrowhead_triangle"),
|
||||||
icon: <ArrowheadTriangleIcon flip={!isRTL} />,
|
icon: (
|
||||||
|
<ArrowheadTriangleIcon theme={appState.theme} flip={!isRTL} />
|
||||||
|
),
|
||||||
keyBinding: "t",
|
keyBinding: "t",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
@@ -1007,30 +1007,34 @@ export const actionChangeArrowhead = register({
|
|||||||
value: null,
|
value: null,
|
||||||
text: t("labels.arrowhead_none"),
|
text: t("labels.arrowhead_none"),
|
||||||
keyBinding: "q",
|
keyBinding: "q",
|
||||||
icon: ArrowheadNoneIcon,
|
icon: <ArrowheadNoneIcon theme={appState.theme} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "arrow",
|
value: "arrow",
|
||||||
text: t("labels.arrowhead_arrow"),
|
text: t("labels.arrowhead_arrow"),
|
||||||
keyBinding: "w",
|
keyBinding: "w",
|
||||||
icon: <ArrowheadArrowIcon flip={isRTL} />,
|
icon: (
|
||||||
|
<ArrowheadArrowIcon theme={appState.theme} flip={isRTL} />
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "bar",
|
value: "bar",
|
||||||
text: t("labels.arrowhead_bar"),
|
text: t("labels.arrowhead_bar"),
|
||||||
keyBinding: "e",
|
keyBinding: "e",
|
||||||
icon: <ArrowheadBarIcon flip={isRTL} />,
|
icon: <ArrowheadBarIcon theme={appState.theme} flip={isRTL} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dot",
|
value: "dot",
|
||||||
text: t("labels.arrowhead_dot"),
|
text: t("labels.arrowhead_dot"),
|
||||||
keyBinding: "r",
|
keyBinding: "r",
|
||||||
icon: <ArrowheadDotIcon flip={isRTL} />,
|
icon: <ArrowheadDotIcon theme={appState.theme} flip={isRTL} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "triangle",
|
value: "triangle",
|
||||||
text: t("labels.arrowhead_triangle"),
|
text: t("labels.arrowhead_triangle"),
|
||||||
icon: <ArrowheadTriangleIcon flip={isRTL} />,
|
icon: (
|
||||||
|
<ArrowheadTriangleIcon theme={appState.theme} flip={isRTL} />
|
||||||
|
),
|
||||||
keyBinding: "t",
|
keyBinding: "t",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import { t } from "../i18n";
|
|||||||
import { getShortcutKey } from "../utils";
|
import { getShortcutKey } from "../utils";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import {
|
import {
|
||||||
BringForwardIcon,
|
|
||||||
BringToFrontIcon,
|
|
||||||
SendBackwardIcon,
|
SendBackwardIcon,
|
||||||
|
BringToFrontIcon,
|
||||||
SendToBackIcon,
|
SendToBackIcon,
|
||||||
|
BringForwardIcon,
|
||||||
} from "../components/icons";
|
} from "../components/icons";
|
||||||
|
|
||||||
export const actionSendBackward = register({
|
export const actionSendBackward = register({
|
||||||
@@ -39,7 +39,7 @@ export const actionSendBackward = register({
|
|||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.sendBackward")} — ${getShortcutKey("CtrlOrCmd+[")}`}
|
title={`${t("labels.sendBackward")} — ${getShortcutKey("CtrlOrCmd+[")}`}
|
||||||
>
|
>
|
||||||
{SendBackwardIcon}
|
<SendBackwardIcon theme={appState.theme} />
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@@ -67,7 +67,7 @@ export const actionBringForward = register({
|
|||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={`${t("labels.bringForward")} — ${getShortcutKey("CtrlOrCmd+]")}`}
|
title={`${t("labels.bringForward")} — ${getShortcutKey("CtrlOrCmd+]")}`}
|
||||||
>
|
>
|
||||||
{BringForwardIcon}
|
<BringForwardIcon theme={appState.theme} />
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@@ -102,7 +102,7 @@ export const actionSendToBack = register({
|
|||||||
: getShortcutKey("CtrlOrCmd+Shift+[")
|
: getShortcutKey("CtrlOrCmd+Shift+[")
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{SendToBackIcon}
|
<SendToBackIcon theme={appState.theme} />
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@@ -138,7 +138,7 @@ export const actionBringToFront = register({
|
|||||||
: getShortcutKey("CtrlOrCmd+Shift+]")
|
: getShortcutKey("CtrlOrCmd+Shift+]")
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{BringToFrontIcon}
|
<BringToFrontIcon theme={appState.theme} />
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -85,4 +85,3 @@ export { actionToggleStats } from "./actionToggleStats";
|
|||||||
export { actionUnbindText, actionBindText } from "./actionBoundText";
|
export { actionUnbindText, actionBindText } from "./actionBoundText";
|
||||||
export { actionLink } from "../element/Hyperlink";
|
export { actionLink } from "../element/Hyperlink";
|
||||||
export { actionToggleLock } from "./actionToggleLock";
|
export { actionToggleLock } from "./actionToggleLock";
|
||||||
export { actionToggleLinearEditor } from "./actionLinearEditor";
|
|
||||||
|
|||||||
@@ -135,11 +135,7 @@ export class ActionManager {
|
|||||||
/**
|
/**
|
||||||
* @param data additional data sent to the PanelComponent
|
* @param data additional data sent to the PanelComponent
|
||||||
*/
|
*/
|
||||||
renderAction = (
|
renderAction = (name: ActionName, data?: PanelComponentProps["data"]) => {
|
||||||
name: ActionName,
|
|
||||||
data?: PanelComponentProps["data"],
|
|
||||||
isInHamburgerMenu = false,
|
|
||||||
) => {
|
|
||||||
const canvasActions = this.app.props.UIOptions.canvasActions;
|
const canvasActions = this.app.props.UIOptions.canvasActions;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -151,7 +147,6 @@ export class ActionManager {
|
|||||||
) {
|
) {
|
||||||
const action = this.actions[name];
|
const action = this.actions[name];
|
||||||
const PanelComponent = action.PanelComponent!;
|
const PanelComponent = action.PanelComponent!;
|
||||||
PanelComponent.displayName = "PanelComponent";
|
|
||||||
const elements = this.getElementsIncludingDeleted();
|
const elements = this.getElementsIncludingDeleted();
|
||||||
const appState = this.getAppState();
|
const appState = this.getAppState();
|
||||||
const updateData = (formState?: any) => {
|
const updateData = (formState?: any) => {
|
||||||
@@ -174,7 +169,6 @@ export class ActionManager {
|
|||||||
updateData={updateData}
|
updateData={updateData}
|
||||||
appProps={this.app.props}
|
appProps={this.app.props}
|
||||||
data={data}
|
data={data}
|
||||||
isInHamburgerMenu={isInHamburgerMenu}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-37
@@ -3,45 +3,36 @@ import { isDarwin } from "../keys";
|
|||||||
import { getShortcutKey } from "../utils";
|
import { getShortcutKey } from "../utils";
|
||||||
import { ActionName } from "./types";
|
import { ActionName } from "./types";
|
||||||
|
|
||||||
export type ShortcutName =
|
export type ShortcutName = SubtypeOf<
|
||||||
| SubtypeOf<
|
ActionName,
|
||||||
ActionName,
|
| "cut"
|
||||||
| "toggleTheme"
|
| "copy"
|
||||||
| "loadScene"
|
| "paste"
|
||||||
| "cut"
|
| "copyStyles"
|
||||||
| "copy"
|
| "pasteStyles"
|
||||||
| "paste"
|
| "selectAll"
|
||||||
| "copyStyles"
|
| "deleteSelectedElements"
|
||||||
| "pasteStyles"
|
| "duplicateSelection"
|
||||||
| "selectAll"
|
| "sendBackward"
|
||||||
| "deleteSelectedElements"
|
| "bringForward"
|
||||||
| "duplicateSelection"
|
| "sendToBack"
|
||||||
| "sendBackward"
|
| "bringToFront"
|
||||||
| "bringForward"
|
| "copyAsPng"
|
||||||
| "sendToBack"
|
| "copyAsSvg"
|
||||||
| "bringToFront"
|
| "group"
|
||||||
| "copyAsPng"
|
| "ungroup"
|
||||||
| "copyAsSvg"
|
| "gridMode"
|
||||||
| "group"
|
| "zenMode"
|
||||||
| "ungroup"
|
| "stats"
|
||||||
| "gridMode"
|
| "addToLibrary"
|
||||||
| "zenMode"
|
| "viewMode"
|
||||||
| "stats"
|
| "flipHorizontal"
|
||||||
| "addToLibrary"
|
| "flipVertical"
|
||||||
| "viewMode"
|
| "hyperlink"
|
||||||
| "flipHorizontal"
|
| "toggleLock"
|
||||||
| "flipVertical"
|
>;
|
||||||
| "hyperlink"
|
|
||||||
| "toggleLock"
|
|
||||||
>
|
|
||||||
| "saveScene"
|
|
||||||
| "imageExport";
|
|
||||||
|
|
||||||
const shortcutMap: Record<ShortcutName, string[]> = {
|
const shortcutMap: Record<ShortcutName, string[]> = {
|
||||||
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
|
||||||
saveScene: [getShortcutKey("CtrlOrCmd+S")],
|
|
||||||
loadScene: [getShortcutKey("CtrlOrCmd+O")],
|
|
||||||
imageExport: [getShortcutKey("CtrlOrCmd+Shift+E")],
|
|
||||||
cut: [getShortcutKey("CtrlOrCmd+X")],
|
cut: [getShortcutKey("CtrlOrCmd+X")],
|
||||||
copy: [getShortcutKey("CtrlOrCmd+C")],
|
copy: [getShortcutKey("CtrlOrCmd+C")],
|
||||||
paste: [getShortcutKey("CtrlOrCmd+V")],
|
paste: [getShortcutKey("CtrlOrCmd+V")],
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ export type ActionName =
|
|||||||
| "finalize"
|
| "finalize"
|
||||||
| "changeProjectName"
|
| "changeProjectName"
|
||||||
| "changeExportBackground"
|
| "changeExportBackground"
|
||||||
| "changeExportPadding"
|
|
||||||
| "changeExportEmbedScene"
|
| "changeExportEmbedScene"
|
||||||
| "changeExportScale"
|
| "changeExportScale"
|
||||||
| "saveToActiveFile"
|
| "saveToActiveFile"
|
||||||
@@ -112,8 +111,7 @@ export type ActionName =
|
|||||||
| "hyperlink"
|
| "hyperlink"
|
||||||
| "eraser"
|
| "eraser"
|
||||||
| "bindText"
|
| "bindText"
|
||||||
| "toggleLock"
|
| "toggleLock";
|
||||||
| "toggleLinearEditor";
|
|
||||||
|
|
||||||
export type PanelComponentProps = {
|
export type PanelComponentProps = {
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
@@ -125,9 +123,7 @@ export type PanelComponentProps = {
|
|||||||
|
|
||||||
export interface Action {
|
export interface Action {
|
||||||
name: ActionName;
|
name: ActionName;
|
||||||
PanelComponent?: React.FC<
|
PanelComponent?: React.FC<PanelComponentProps>;
|
||||||
PanelComponentProps & { isInHamburgerMenu: boolean }
|
|
||||||
>;
|
|
||||||
perform: ActionFn;
|
perform: ActionFn;
|
||||||
keyPriority?: number;
|
keyPriority?: number;
|
||||||
keyTest?: (
|
keyTest?: (
|
||||||
|
|||||||
+6
-11
@@ -1,6 +1,5 @@
|
|||||||
import oc from "open-color";
|
import oc from "open-color";
|
||||||
import {
|
import {
|
||||||
DEFAULT_EXPORT_PADDING,
|
|
||||||
DEFAULT_FONT_FAMILY,
|
DEFAULT_FONT_FAMILY,
|
||||||
DEFAULT_FONT_SIZE,
|
DEFAULT_FONT_SIZE,
|
||||||
DEFAULT_TEXT_ALIGN,
|
DEFAULT_TEXT_ALIGN,
|
||||||
@@ -20,7 +19,6 @@ export const getDefaultAppState = (): Omit<
|
|||||||
"offsetTop" | "offsetLeft" | "width" | "height"
|
"offsetTop" | "offsetLeft" | "width" | "height"
|
||||||
> => {
|
> => {
|
||||||
return {
|
return {
|
||||||
showWelcomeScreen: false,
|
|
||||||
theme: THEME.LIGHT,
|
theme: THEME.LIGHT,
|
||||||
collaborators: new Map(),
|
collaborators: new Map(),
|
||||||
currentChartType: "bar",
|
currentChartType: "bar",
|
||||||
@@ -56,11 +54,11 @@ export const getDefaultAppState = (): Omit<
|
|||||||
exportScale: defaultExportScale,
|
exportScale: defaultExportScale,
|
||||||
exportEmbedScene: false,
|
exportEmbedScene: false,
|
||||||
exportWithDarkMode: false,
|
exportWithDarkMode: false,
|
||||||
exportPadding: DEFAULT_EXPORT_PADDING,
|
|
||||||
fileHandle: null,
|
fileHandle: null,
|
||||||
gridSize: null,
|
gridSize: null,
|
||||||
isBindingEnabled: true,
|
isBindingEnabled: true,
|
||||||
isSidebarDocked: false,
|
isLibraryOpen: false,
|
||||||
|
isLibraryMenuDocked: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isResizing: false,
|
isResizing: false,
|
||||||
isRotating: false,
|
isRotating: false,
|
||||||
@@ -69,8 +67,6 @@ export const getDefaultAppState = (): Omit<
|
|||||||
name: `${t("labels.untitled")}-${getDateTime()}`,
|
name: `${t("labels.untitled")}-${getDateTime()}`,
|
||||||
openMenu: null,
|
openMenu: null,
|
||||||
openPopup: null,
|
openPopup: null,
|
||||||
openSidebar: null,
|
|
||||||
openDialog: null,
|
|
||||||
pasteDialog: { shown: false, data: null },
|
pasteDialog: { shown: false, data: null },
|
||||||
previousSelectedElementIds: {},
|
previousSelectedElementIds: {},
|
||||||
resizingElement: null,
|
resizingElement: null,
|
||||||
@@ -81,6 +77,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
selectedGroupIds: {},
|
selectedGroupIds: {},
|
||||||
selectionElement: null,
|
selectionElement: null,
|
||||||
shouldCacheIgnoreZoom: false,
|
shouldCacheIgnoreZoom: false,
|
||||||
|
showHelpDialog: false,
|
||||||
showStats: false,
|
showStats: false,
|
||||||
startBoundElement: null,
|
startBoundElement: null,
|
||||||
suggestedBindings: [],
|
suggestedBindings: [],
|
||||||
@@ -113,7 +110,6 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
T extends Record<keyof AppState, Values>,
|
T extends Record<keyof AppState, Values>,
|
||||||
>(config: { [K in keyof T]: K extends keyof AppState ? T[K] : never }) =>
|
>(config: { [K in keyof T]: K extends keyof AppState ? T[K] : never }) =>
|
||||||
config)({
|
config)({
|
||||||
showWelcomeScreen: { browser: true, export: false, server: false },
|
|
||||||
theme: { browser: true, export: false, server: false },
|
theme: { browser: true, export: false, server: false },
|
||||||
collaborators: { browser: false, export: false, server: false },
|
collaborators: { browser: false, export: false, server: false },
|
||||||
currentChartType: { browser: true, export: false, server: false },
|
currentChartType: { browser: true, export: false, server: false },
|
||||||
@@ -147,13 +143,13 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
exportBackground: { browser: true, export: false, server: false },
|
exportBackground: { browser: true, export: false, server: false },
|
||||||
exportEmbedScene: { browser: true, export: false, server: false },
|
exportEmbedScene: { browser: true, export: false, server: false },
|
||||||
exportScale: { browser: true, export: false, server: false },
|
exportScale: { browser: true, export: false, server: false },
|
||||||
exportPadding: { browser: true, export: false, server: false },
|
|
||||||
exportWithDarkMode: { browser: true, export: false, server: false },
|
exportWithDarkMode: { browser: true, export: false, server: false },
|
||||||
fileHandle: { browser: false, export: false, server: false },
|
fileHandle: { browser: false, export: false, server: false },
|
||||||
gridSize: { browser: true, export: true, server: true },
|
gridSize: { browser: true, export: true, server: true },
|
||||||
height: { browser: false, export: false, server: false },
|
height: { browser: false, export: false, server: false },
|
||||||
isBindingEnabled: { browser: false, export: false, server: false },
|
isBindingEnabled: { browser: false, export: false, server: false },
|
||||||
isSidebarDocked: { browser: true, export: false, server: false },
|
isLibraryOpen: { browser: true, export: false, server: false },
|
||||||
|
isLibraryMenuDocked: { browser: true, export: false, server: false },
|
||||||
isLoading: { browser: false, export: false, server: false },
|
isLoading: { browser: false, export: false, server: false },
|
||||||
isResizing: { browser: false, export: false, server: false },
|
isResizing: { browser: false, export: false, server: false },
|
||||||
isRotating: { browser: false, export: false, server: false },
|
isRotating: { browser: false, export: false, server: false },
|
||||||
@@ -164,8 +160,6 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
offsetTop: { browser: false, export: false, server: false },
|
offsetTop: { browser: false, export: false, server: false },
|
||||||
openMenu: { browser: true, export: false, server: false },
|
openMenu: { browser: true, export: false, server: false },
|
||||||
openPopup: { browser: false, export: false, server: false },
|
openPopup: { browser: false, export: false, server: false },
|
||||||
openSidebar: { browser: true, export: false, server: false },
|
|
||||||
openDialog: { browser: false, export: false, server: false },
|
|
||||||
pasteDialog: { browser: false, export: false, server: false },
|
pasteDialog: { browser: false, export: false, server: false },
|
||||||
previousSelectedElementIds: { browser: true, export: false, server: false },
|
previousSelectedElementIds: { browser: true, export: false, server: false },
|
||||||
resizingElement: { browser: false, export: false, server: false },
|
resizingElement: { browser: false, export: false, server: false },
|
||||||
@@ -176,6 +170,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
selectedGroupIds: { browser: true, export: false, server: false },
|
selectedGroupIds: { browser: true, export: false, server: false },
|
||||||
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 },
|
||||||
|
showHelpDialog: { browser: false, export: false, server: false },
|
||||||
showStats: { 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 },
|
||||||
|
|||||||
+15
-6
@@ -11,18 +11,27 @@ export const getClientColors = (clientId: string, appState: AppState) => {
|
|||||||
// Naive way of getting an integer out of the clientId
|
// Naive way of getting an integer out of the clientId
|
||||||
const sum = clientId.split("").reduce((a, str) => a + str.charCodeAt(0), 0);
|
const sum = clientId.split("").reduce((a, str) => a + str.charCodeAt(0), 0);
|
||||||
|
|
||||||
// Skip transparent & gray colors
|
// Skip transparent background.
|
||||||
const backgrounds = colors.elementBackground.slice(3);
|
const backgrounds = colors.elementBackground.slice(1);
|
||||||
const strokes = colors.elementStroke.slice(3);
|
const strokes = colors.elementStroke.slice(1);
|
||||||
return {
|
return {
|
||||||
background: backgrounds[sum % backgrounds.length],
|
background: backgrounds[sum % backgrounds.length],
|
||||||
stroke: strokes[sum % strokes.length],
|
stroke: strokes[sum % strokes.length],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getClientInitials = (userName?: string | null) => {
|
export const getClientInitials = (username?: string | null) => {
|
||||||
if (!userName) {
|
if (!username) {
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
return userName.trim()[0].toUpperCase();
|
const names = username.trim().split(" ");
|
||||||
|
|
||||||
|
if (names.length < 2) {
|
||||||
|
return names[0].substring(0, 2).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstName = names[0];
|
||||||
|
const lastName = names[names.length - 1];
|
||||||
|
|
||||||
|
return (firstName[0] + lastName[0]).toUpperCase();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
.zoom-actions,
|
|
||||||
.undo-redo-buttons {
|
|
||||||
background-color: var(--island-bg-color);
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.zoom-button,
|
|
||||||
.undo-redo-buttons button {
|
|
||||||
border: 1px solid var(--default-border-color) !important;
|
|
||||||
border-radius: 0 !important;
|
|
||||||
background-color: transparent !important;
|
|
||||||
font-size: 0.875rem !important;
|
|
||||||
width: var(--lg-button-size);
|
|
||||||
height: var(--lg-button-size);
|
|
||||||
svg {
|
|
||||||
width: var(--lg-icon-size) !important;
|
|
||||||
height: var(--lg-icon-size) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ToolIcon__icon {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.reset-zoom-button {
|
|
||||||
border-left: 0 !important;
|
|
||||||
border-right: 0 !important;
|
|
||||||
padding: 0 0.625rem !important;
|
|
||||||
width: 3.75rem !important;
|
|
||||||
justify-content: center;
|
|
||||||
color: var(--text-primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.zoom-out-button {
|
|
||||||
border-top-left-radius: var(--border-radius-lg) !important;
|
|
||||||
border-bottom-left-radius: var(--border-radius-lg) !important;
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
transform: scaleX(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ToolIcon__icon {
|
|
||||||
border-top-right-radius: 0 !important;
|
|
||||||
border-bottom-right-radius: 0 !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.zoom-in-button {
|
|
||||||
border-top-right-radius: var(--border-radius-lg) !important;
|
|
||||||
border-bottom-right-radius: var(--border-radius-lg) !important;
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
transform: scaleX(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ToolIcon__icon {
|
|
||||||
border-top-left-radius: 0 !important;
|
|
||||||
border-bottom-left-radius: 0 !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.undo-redo-buttons {
|
|
||||||
.undo-button-container button {
|
|
||||||
border-top-left-radius: var(--border-radius-lg) !important;
|
|
||||||
border-bottom-left-radius: var(--border-radius-lg) !important;
|
|
||||||
border-right: 0 !important;
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
transform: scaleX(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ToolIcon__icon {
|
|
||||||
border-top-right-radius: 0 !important;
|
|
||||||
border-bottom-right-radius: 0 !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.redo-button-container button {
|
|
||||||
border-top-right-radius: var(--border-radius-lg) !important;
|
|
||||||
border-bottom-right-radius: var(--border-radius-lg) !important;
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
transform: scaleX(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ToolIcon__icon {
|
|
||||||
border-top-left-radius: 0 !important;
|
|
||||||
border-bottom-left-radius: 0 !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+26
-88
@@ -26,19 +26,17 @@ import { ToolButton } from "./ToolButton";
|
|||||||
import { hasStrokeColor } from "../scene/comparisons";
|
import { hasStrokeColor } from "../scene/comparisons";
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import { hasBoundTextElement, isBoundToContainer } from "../element/typeChecks";
|
import { hasBoundTextElement, isBoundToContainer } from "../element/typeChecks";
|
||||||
import clsx from "clsx";
|
|
||||||
import { actionToggleZenMode } from "../actions";
|
|
||||||
import "./Actions.scss";
|
|
||||||
import { Tooltip } from "./Tooltip";
|
|
||||||
|
|
||||||
export const SelectedShapeActions = ({
|
export const SelectedShapeActions = ({
|
||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
renderAction,
|
renderAction,
|
||||||
|
activeTool,
|
||||||
}: {
|
}: {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
renderAction: ActionManager["renderAction"];
|
renderAction: ActionManager["renderAction"];
|
||||||
|
activeTool: AppState["activeTool"]["type"];
|
||||||
}) => {
|
}) => {
|
||||||
const targetElements = getTargetElements(
|
const targetElements = getTargetElements(
|
||||||
getNonDeletedElements(elements),
|
getNonDeletedElements(elements),
|
||||||
@@ -58,13 +56,13 @@ export const SelectedShapeActions = ({
|
|||||||
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
||||||
|
|
||||||
const showFillIcons =
|
const showFillIcons =
|
||||||
hasBackground(appState.activeTool.type) ||
|
hasBackground(activeTool) ||
|
||||||
targetElements.some(
|
targetElements.some(
|
||||||
(element) =>
|
(element) =>
|
||||||
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
||||||
);
|
);
|
||||||
const showChangeBackgroundIcons =
|
const showChangeBackgroundIcons =
|
||||||
hasBackground(appState.activeTool.type) ||
|
hasBackground(activeTool) ||
|
||||||
targetElements.some((element) => hasBackground(element.type));
|
targetElements.some((element) => hasBackground(element.type));
|
||||||
|
|
||||||
const showLinkIcon =
|
const showLinkIcon =
|
||||||
@@ -81,27 +79,23 @@ export const SelectedShapeActions = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="panelColumn">
|
<div className="panelColumn">
|
||||||
<div>
|
{((hasStrokeColor(activeTool) &&
|
||||||
{((hasStrokeColor(appState.activeTool.type) &&
|
activeTool !== "image" &&
|
||||||
appState.activeTool.type !== "image" &&
|
commonSelectedType !== "image") ||
|
||||||
commonSelectedType !== "image") ||
|
targetElements.some((element) => hasStrokeColor(element.type))) &&
|
||||||
targetElements.some((element) => hasStrokeColor(element.type))) &&
|
renderAction("changeStrokeColor")}
|
||||||
renderAction("changeStrokeColor")}
|
{showChangeBackgroundIcons && renderAction("changeBackgroundColor")}
|
||||||
</div>
|
|
||||||
{showChangeBackgroundIcons && (
|
|
||||||
<div>{renderAction("changeBackgroundColor")}</div>
|
|
||||||
)}
|
|
||||||
{showFillIcons && renderAction("changeFillStyle")}
|
{showFillIcons && renderAction("changeFillStyle")}
|
||||||
|
|
||||||
{(hasStrokeWidth(appState.activeTool.type) ||
|
{(hasStrokeWidth(activeTool) ||
|
||||||
targetElements.some((element) => hasStrokeWidth(element.type))) &&
|
targetElements.some((element) => hasStrokeWidth(element.type))) &&
|
||||||
renderAction("changeStrokeWidth")}
|
renderAction("changeStrokeWidth")}
|
||||||
|
|
||||||
{(appState.activeTool.type === "freedraw" ||
|
{(activeTool === "freedraw" ||
|
||||||
targetElements.some((element) => element.type === "freedraw")) &&
|
targetElements.some((element) => element.type === "freedraw")) &&
|
||||||
renderAction("changeStrokeShape")}
|
renderAction("changeStrokeShape")}
|
||||||
|
|
||||||
{(hasStrokeStyle(appState.activeTool.type) ||
|
{(hasStrokeStyle(activeTool) ||
|
||||||
targetElements.some((element) => hasStrokeStyle(element.type))) && (
|
targetElements.some((element) => hasStrokeStyle(element.type))) && (
|
||||||
<>
|
<>
|
||||||
{renderAction("changeStrokeStyle")}
|
{renderAction("changeStrokeStyle")}
|
||||||
@@ -109,12 +103,12 @@ export const SelectedShapeActions = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(canChangeSharpness(appState.activeTool.type) ||
|
{(canChangeSharpness(activeTool) ||
|
||||||
targetElements.some((element) => canChangeSharpness(element.type))) && (
|
targetElements.some((element) => canChangeSharpness(element.type))) && (
|
||||||
<>{renderAction("changeSharpness")}</>
|
<>{renderAction("changeSharpness")}</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(hasText(appState.activeTool.type) ||
|
{(hasText(activeTool) ||
|
||||||
targetElements.some((element) => hasText(element.type))) && (
|
targetElements.some((element) => hasText(element.type))) && (
|
||||||
<>
|
<>
|
||||||
{renderAction("changeFontSize")}
|
{renderAction("changeFontSize")}
|
||||||
@@ -129,7 +123,7 @@ export const SelectedShapeActions = ({
|
|||||||
(element) =>
|
(element) =>
|
||||||
hasBoundTextElement(element) || isBoundToContainer(element),
|
hasBoundTextElement(element) || isBoundToContainer(element),
|
||||||
) && renderAction("changeVerticalAlign")}
|
) && renderAction("changeVerticalAlign")}
|
||||||
{(canHaveArrowheads(appState.activeTool.type) ||
|
{(canHaveArrowheads(activeTool) ||
|
||||||
targetElements.some((element) => canHaveArrowheads(element.type))) && (
|
targetElements.some((element) => canHaveArrowheads(element.type))) && (
|
||||||
<>{renderAction("changeArrowhead")}</>
|
<>{renderAction("changeArrowhead")}</>
|
||||||
)}
|
)}
|
||||||
@@ -169,16 +163,7 @@ export const SelectedShapeActions = ({
|
|||||||
)}
|
)}
|
||||||
{targetElements.length > 2 &&
|
{targetElements.length > 2 &&
|
||||||
renderAction("distributeHorizontally")}
|
renderAction("distributeHorizontally")}
|
||||||
{/* breaks the row ˇˇ */}
|
<div className="iconRow">
|
||||||
<div style={{ flexBasis: "100%", height: 0 }} />
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
flexWrap: "wrap",
|
|
||||||
gap: ".5rem",
|
|
||||||
marginTop: "-0.5rem",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{renderAction("alignTop")}
|
{renderAction("alignTop")}
|
||||||
{renderAction("alignVerticallyCentered")}
|
{renderAction("alignVerticallyCentered")}
|
||||||
{renderAction("alignBottom")}
|
{renderAction("alignBottom")}
|
||||||
@@ -218,26 +203,25 @@ export const ShapesSwitcher = ({
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
}) => (
|
}) => (
|
||||||
<>
|
<>
|
||||||
{SHAPES.map(({ value, icon, key, fillable }, index) => {
|
{SHAPES.map(({ value, icon, key }, index) => {
|
||||||
const numberKey = value === "eraser" ? 0 : index + 1;
|
|
||||||
const label = t(`toolBar.${value}`);
|
const label = t(`toolBar.${value}`);
|
||||||
const letter = key && (typeof key === "string" ? key : key[0]);
|
const letter = key && (typeof key === "string" ? key : key[0]);
|
||||||
const shortcut = letter
|
const shortcut = letter
|
||||||
? `${capitalizeString(letter)} ${t("helpDialog.or")} ${numberKey}`
|
? `${capitalizeString(letter)} ${t("helpDialog.or")} ${index + 1}`
|
||||||
: `${numberKey}`;
|
: `${index + 1}`;
|
||||||
return (
|
return (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
className={clsx("Shape", { fillable })}
|
className="Shape"
|
||||||
key={value}
|
key={value}
|
||||||
type="radio"
|
type="radio"
|
||||||
icon={icon}
|
icon={icon}
|
||||||
checked={activeTool.type === value}
|
checked={activeTool.type === value}
|
||||||
name="editor-current-shape"
|
name="editor-current-shape"
|
||||||
title={`${capitalizeString(label)} — ${shortcut}`}
|
title={`${capitalizeString(label)} — ${shortcut}`}
|
||||||
keyBindingLabel={`${numberKey}`}
|
keyBindingLabel={`${index + 1}`}
|
||||||
aria-label={capitalizeString(label)}
|
aria-label={capitalizeString(label)}
|
||||||
aria-keyshortcuts={shortcut}
|
aria-keyshortcuts={shortcut}
|
||||||
data-testid={`toolbar-${value}`}
|
data-testid={value}
|
||||||
onPointerDown={({ pointerType }) => {
|
onPointerDown={({ pointerType }) => {
|
||||||
if (!appState.penDetected && pointerType === "pen") {
|
if (!appState.penDetected && pointerType === "pen") {
|
||||||
setAppState({
|
setAppState({
|
||||||
@@ -279,57 +263,11 @@ export const ZoomActions = ({
|
|||||||
renderAction: ActionManager["renderAction"];
|
renderAction: ActionManager["renderAction"];
|
||||||
zoom: Zoom;
|
zoom: Zoom;
|
||||||
}) => (
|
}) => (
|
||||||
<Stack.Col gap={1} className="zoom-actions">
|
<Stack.Col gap={1}>
|
||||||
<Stack.Row align="center">
|
<Stack.Row gap={1} align="center">
|
||||||
{renderAction("zoomOut")}
|
{renderAction("zoomOut")}
|
||||||
{renderAction("resetZoom")}
|
|
||||||
{renderAction("zoomIn")}
|
{renderAction("zoomIn")}
|
||||||
|
{renderAction("resetZoom")}
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const UndoRedoActions = ({
|
|
||||||
renderAction,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
renderAction: ActionManager["renderAction"];
|
|
||||||
className?: string;
|
|
||||||
}) => (
|
|
||||||
<div className={`undo-redo-buttons ${className}`}>
|
|
||||||
<div className="undo-button-container">
|
|
||||||
<Tooltip label={t("buttons.undo")}>{renderAction("undo")}</Tooltip>
|
|
||||||
</div>
|
|
||||||
<div className="redo-button-container">
|
|
||||||
<Tooltip label={t("buttons.redo")}> {renderAction("redo")}</Tooltip>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const ExitZenModeAction = ({
|
|
||||||
actionManager,
|
|
||||||
showExitZenModeBtn,
|
|
||||||
}: {
|
|
||||||
actionManager: ActionManager;
|
|
||||||
showExitZenModeBtn: boolean;
|
|
||||||
}) => (
|
|
||||||
<button
|
|
||||||
className={clsx("disable-zen-mode", {
|
|
||||||
"disable-zen-mode--visible": showExitZenModeBtn,
|
|
||||||
})}
|
|
||||||
onClick={() => actionManager.executeAction(actionToggleZenMode)}
|
|
||||||
>
|
|
||||||
{t("buttons.exitZenMode")}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const FinalizeAction = ({
|
|
||||||
renderAction,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
renderAction: ActionManager["renderAction"];
|
|
||||||
className?: string;
|
|
||||||
}) => (
|
|
||||||
<div className={`finalize-button ${className}`}>
|
|
||||||
{renderAction("finalize", { size: "small" })}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
// TODO barnabasmolnar/editor-redesign
|
import Stack from "../components/Stack";
|
||||||
// this icon is not great
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import { getShortcutFromShortcutName } from "../actions/shortcuts";
|
import { save, file } from "../components/icons";
|
||||||
import { save } from "../components/icons";
|
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
|
||||||
import "./ActiveFile.scss";
|
import "./ActiveFile.scss";
|
||||||
import MenuItem from "./MenuItem";
|
|
||||||
|
|
||||||
type ActiveFileProps = {
|
type ActiveFileProps = {
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
@@ -13,11 +11,18 @@ type ActiveFileProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ActiveFile = ({ fileName, onSave }: ActiveFileProps) => (
|
export const ActiveFile = ({ fileName, onSave }: ActiveFileProps) => (
|
||||||
<MenuItem
|
<Stack.Row className="ActiveFile" gap={1} align="center">
|
||||||
label={`${t("buttons.save")}`}
|
<span className="ActiveFile__fileName">
|
||||||
shortcut={getShortcutFromShortcutName("saveScene")}
|
{file}
|
||||||
dataTestId="save-button"
|
<span>{fileName}</span>
|
||||||
onClick={onSave}
|
</span>
|
||||||
icon={save}
|
<ToolButton
|
||||||
/>
|
type="icon"
|
||||||
|
icon={save}
|
||||||
|
title={t("buttons.save")}
|
||||||
|
aria-label={t("buttons.save")}
|
||||||
|
onClick={onSave}
|
||||||
|
data-testid="save-button"
|
||||||
|
/>
|
||||||
|
</Stack.Row>
|
||||||
);
|
);
|
||||||
|
|||||||
+216
-211
@@ -34,7 +34,6 @@ import {
|
|||||||
actionUngroup,
|
actionUngroup,
|
||||||
actionLink,
|
actionLink,
|
||||||
actionToggleLock,
|
actionToggleLock,
|
||||||
actionToggleLinearEditor,
|
|
||||||
} from "../actions";
|
} from "../actions";
|
||||||
import { createRedoAction, createUndoAction } from "../actions/actionHistory";
|
import { createRedoAction, createUndoAction } from "../actions/actionHistory";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
@@ -76,7 +75,6 @@ import {
|
|||||||
THEME,
|
THEME,
|
||||||
TOUCH_CTX_MENU_TIMEOUT,
|
TOUCH_CTX_MENU_TIMEOUT,
|
||||||
VERTICAL_ALIGN,
|
VERTICAL_ALIGN,
|
||||||
ZOOM_STEP,
|
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import { loadFromBlob } from "../data";
|
import { loadFromBlob } from "../data";
|
||||||
import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
||||||
@@ -254,7 +252,6 @@ import {
|
|||||||
getApproxMinLineHeight,
|
getApproxMinLineHeight,
|
||||||
getApproxMinLineWidth,
|
getApproxMinLineWidth,
|
||||||
getBoundTextElement,
|
getBoundTextElement,
|
||||||
getContainerDims,
|
|
||||||
} from "../element/textElement";
|
} from "../element/textElement";
|
||||||
import { isHittingElementNotConsideringBoundingBox } from "../element/collision";
|
import { isHittingElementNotConsideringBoundingBox } from "../element/collision";
|
||||||
import {
|
import {
|
||||||
@@ -266,10 +263,101 @@ import {
|
|||||||
isLocalLink,
|
isLocalLink,
|
||||||
} from "../element/Hyperlink";
|
} from "../element/Hyperlink";
|
||||||
import { shouldShowBoundingBox } from "../element/transformHandles";
|
import { shouldShowBoundingBox } from "../element/transformHandles";
|
||||||
import { atom } from "jotai";
|
|
||||||
|
|
||||||
export const isMenuOpenAtom = atom(false);
|
let TIMES_AGGR: Record<string, { t: number; times: number[] }> = {};
|
||||||
export const isDropdownOpenAtom = atom(false);
|
let TIMES_AVG: Record<
|
||||||
|
string,
|
||||||
|
{ t: number; times: number[]; avg: number | null }
|
||||||
|
> = {};
|
||||||
|
|
||||||
|
window.DEBUG_LOG_TIMES = true;
|
||||||
|
|
||||||
|
let lastDebugLogCall = 0;
|
||||||
|
let DEBUG_LOG_INTERVAL_ID: null | number = null;
|
||||||
|
|
||||||
|
const setupInterval = () => {
|
||||||
|
if (DEBUG_LOG_INTERVAL_ID === null) {
|
||||||
|
console.info("%c(starting perf recording)", "color: lime");
|
||||||
|
DEBUG_LOG_INTERVAL_ID = window.setInterval(debugLogger, 1000);
|
||||||
|
}
|
||||||
|
lastDebugLogCall = Date.now();
|
||||||
|
};
|
||||||
|
|
||||||
|
const lessPrecise = (num: number, precision = 5) =>
|
||||||
|
parseFloat(num.toPrecision(precision));
|
||||||
|
|
||||||
|
const getAvgFrameTime = (times: number[]) =>
|
||||||
|
lessPrecise(times.reduce((a, b) => a + b) / times.length);
|
||||||
|
|
||||||
|
const getFps = (frametime: number) => lessPrecise(1000 / frametime);
|
||||||
|
|
||||||
|
const debugLogger = () => {
|
||||||
|
if (Date.now() - lastDebugLogCall > 600 && DEBUG_LOG_INTERVAL_ID !== null) {
|
||||||
|
window.clearInterval(DEBUG_LOG_INTERVAL_ID);
|
||||||
|
DEBUG_LOG_INTERVAL_ID = null;
|
||||||
|
for (const [name, { avg }] of Object.entries(TIMES_AVG)) {
|
||||||
|
if (avg != null) {
|
||||||
|
console.info(
|
||||||
|
`%c${name} run avg: ${avg}ms (${getFps(avg)} fps)`,
|
||||||
|
"color: blue",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.info("%c(stopping perf recording)", "color: red");
|
||||||
|
TIMES_AGGR = {};
|
||||||
|
TIMES_AVG = {};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (window.DEBUG_LOG_TIMES) {
|
||||||
|
for (const [name, { t, times }] of Object.entries(TIMES_AGGR)) {
|
||||||
|
if (times.length) {
|
||||||
|
console.info(
|
||||||
|
name,
|
||||||
|
lessPrecise(times.reduce((a, b) => a + b) / times.length),
|
||||||
|
times.sort((a, b) => a - b).map((x) => lessPrecise(x)),
|
||||||
|
);
|
||||||
|
TIMES_AGGR[name] = { t, times: [] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const [name, { t, times, avg }] of Object.entries(TIMES_AVG)) {
|
||||||
|
if (times.length) {
|
||||||
|
const avgFrameTime = getAvgFrameTime(times);
|
||||||
|
console.info(name, `${avgFrameTime}ms (${getFps(avgFrameTime)} fps)`);
|
||||||
|
TIMES_AVG[name] = {
|
||||||
|
t,
|
||||||
|
times: [],
|
||||||
|
avg:
|
||||||
|
avg != null ? getAvgFrameTime([avg, avgFrameTime]) : avgFrameTime,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.logTime = (name: string, time?: number) => {
|
||||||
|
setupInterval();
|
||||||
|
const now = performance.now();
|
||||||
|
const { t, times } = (TIMES_AGGR[name] = TIMES_AGGR[name] || {
|
||||||
|
t: 0,
|
||||||
|
times: [],
|
||||||
|
});
|
||||||
|
if (t) {
|
||||||
|
times.push(time != null ? time : now - t);
|
||||||
|
}
|
||||||
|
TIMES_AGGR[name].t = now;
|
||||||
|
};
|
||||||
|
window.logTimeAverage = (name: string, time?: number) => {
|
||||||
|
setupInterval();
|
||||||
|
const now = performance.now();
|
||||||
|
const { t, times } = (TIMES_AVG[name] = TIMES_AVG[name] || {
|
||||||
|
t: 0,
|
||||||
|
times: [],
|
||||||
|
});
|
||||||
|
if (t) {
|
||||||
|
times.push(time != null ? time : now - t);
|
||||||
|
}
|
||||||
|
TIMES_AVG[name].t = now;
|
||||||
|
};
|
||||||
|
|
||||||
const deviceContextInitialValue = {
|
const deviceContextInitialValue = {
|
||||||
isSmScreen: false,
|
isSmScreen: false,
|
||||||
@@ -279,7 +367,6 @@ const deviceContextInitialValue = {
|
|||||||
};
|
};
|
||||||
const DeviceContext = React.createContext<Device>(deviceContextInitialValue);
|
const DeviceContext = React.createContext<Device>(deviceContextInitialValue);
|
||||||
export const useDevice = () => useContext<Device>(DeviceContext);
|
export const useDevice = () => useContext<Device>(DeviceContext);
|
||||||
|
|
||||||
const ExcalidrawContainerContext = React.createContext<{
|
const ExcalidrawContainerContext = React.createContext<{
|
||||||
container: HTMLDivElement | null;
|
container: HTMLDivElement | null;
|
||||||
id: string | null;
|
id: string | null;
|
||||||
@@ -287,29 +374,6 @@ const ExcalidrawContainerContext = React.createContext<{
|
|||||||
export const useExcalidrawContainer = () =>
|
export const useExcalidrawContainer = () =>
|
||||||
useContext(ExcalidrawContainerContext);
|
useContext(ExcalidrawContainerContext);
|
||||||
|
|
||||||
const ExcalidrawElementsContext = React.createContext<
|
|
||||||
readonly NonDeletedExcalidrawElement[]
|
|
||||||
>([]);
|
|
||||||
|
|
||||||
const ExcalidrawAppStateContext = React.createContext<AppState>({
|
|
||||||
...getDefaultAppState(),
|
|
||||||
width: 0,
|
|
||||||
height: 0,
|
|
||||||
offsetLeft: 0,
|
|
||||||
offsetTop: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const ExcalidrawSetAppStateContent = React.createContext<
|
|
||||||
React.Component<any, AppState>["setState"]
|
|
||||||
>(() => {});
|
|
||||||
|
|
||||||
export const useExcalidrawElements = () =>
|
|
||||||
useContext(ExcalidrawElementsContext);
|
|
||||||
export const useExcalidrawAppState = () =>
|
|
||||||
useContext(ExcalidrawAppStateContext);
|
|
||||||
export const useExcalidrawSetAppState = () =>
|
|
||||||
useContext(ExcalidrawSetAppStateContent);
|
|
||||||
|
|
||||||
let didTapTwice: boolean = false;
|
let didTapTwice: boolean = false;
|
||||||
let tappedTwiceTimer = 0;
|
let tappedTwiceTimer = 0;
|
||||||
let cursorX = 0;
|
let cursorX = 0;
|
||||||
@@ -392,7 +456,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
width: window.innerWidth,
|
width: window.innerWidth,
|
||||||
height: window.innerHeight,
|
height: window.innerHeight,
|
||||||
showHyperlinkPopup: false,
|
showHyperlinkPopup: false,
|
||||||
isSidebarDocked: false,
|
isLibraryMenuDocked: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.id = nanoid();
|
this.id = nanoid();
|
||||||
@@ -424,7 +488,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
setActiveTool: this.setActiveTool,
|
setActiveTool: this.setActiveTool,
|
||||||
setCursor: this.setCursor,
|
setCursor: this.setCursor,
|
||||||
resetCursor: this.resetCursor,
|
resetCursor: this.resetCursor,
|
||||||
toggleMenu: this.toggleMenu,
|
|
||||||
} as const;
|
} as const;
|
||||||
if (typeof excalidrawRef === "function") {
|
if (typeof excalidrawRef === "function") {
|
||||||
excalidrawRef(api);
|
excalidrawRef(api);
|
||||||
@@ -508,6 +571,26 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private __renderUI = true;
|
||||||
|
|
||||||
|
private perfTest = (runs = 180, initial = true) => {
|
||||||
|
if (initial) {
|
||||||
|
console.time("perfTest");
|
||||||
|
} else if (!runs) {
|
||||||
|
console.timeEnd("perfTest");
|
||||||
|
}
|
||||||
|
if (runs) {
|
||||||
|
requestAnimationFrame((id) => {
|
||||||
|
for (const element of this.scene.getNonDeletedElements()) {
|
||||||
|
mutateElement(element, {
|
||||||
|
x: element.x + 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.perfTest(runs - 1, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const selectedElement = getSelectedElements(
|
const selectedElement = getSelectedElements(
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
@@ -537,73 +620,65 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
value={this.excalidrawContainerValue}
|
value={this.excalidrawContainerValue}
|
||||||
>
|
>
|
||||||
<DeviceContext.Provider value={this.device}>
|
<DeviceContext.Provider value={this.device}>
|
||||||
<ExcalidrawSetAppStateContent.Provider value={this.setAppState}>
|
{this.__renderUI && (
|
||||||
<ExcalidrawAppStateContext.Provider value={this.state}>
|
<LayerUI
|
||||||
<ExcalidrawElementsContext.Provider
|
canvas={this.canvas}
|
||||||
value={this.scene.getNonDeletedElements()}
|
appState={this.state}
|
||||||
>
|
files={this.files}
|
||||||
<LayerUI
|
setAppState={this.setAppState}
|
||||||
canvas={this.canvas}
|
actionManager={this.actionManager}
|
||||||
appState={this.state}
|
elements={this.scene.getNonDeletedElements()}
|
||||||
files={this.files}
|
onCollabButtonClick={onCollabButtonClick}
|
||||||
setAppState={this.setAppState}
|
onLockToggle={this.toggleLock}
|
||||||
actionManager={this.actionManager}
|
onPenModeToggle={this.togglePenMode}
|
||||||
elements={this.scene.getNonDeletedElements()}
|
onInsertElements={(elements) =>
|
||||||
onCollabButtonClick={onCollabButtonClick}
|
this.addElementsFromPasteOrLibrary({
|
||||||
onLockToggle={this.toggleLock}
|
elements,
|
||||||
onPenModeToggle={this.togglePenMode}
|
position: "center",
|
||||||
onInsertElements={(elements) =>
|
files: null,
|
||||||
this.addElementsFromPasteOrLibrary({
|
})
|
||||||
elements,
|
}
|
||||||
position: "center",
|
langCode={getLanguage().code}
|
||||||
files: null,
|
isCollaborating={this.props.isCollaborating}
|
||||||
})
|
renderTopRightUI={renderTopRightUI}
|
||||||
}
|
renderCustomFooter={renderFooter}
|
||||||
langCode={getLanguage().code}
|
renderCustomStats={renderCustomStats}
|
||||||
isCollaborating={this.props.isCollaborating}
|
showExitZenModeBtn={
|
||||||
renderTopRightUI={renderTopRightUI}
|
typeof this.props?.zenModeEnabled === "undefined" &&
|
||||||
renderCustomFooter={renderFooter}
|
this.state.zenModeEnabled
|
||||||
renderCustomStats={renderCustomStats}
|
}
|
||||||
renderCustomSidebar={this.props.renderSidebar}
|
showThemeBtn={
|
||||||
showExitZenModeBtn={
|
typeof this.props?.theme === "undefined" &&
|
||||||
typeof this.props?.zenModeEnabled === "undefined" &&
|
this.props.UIOptions.canvasActions.theme
|
||||||
this.state.zenModeEnabled
|
}
|
||||||
}
|
libraryReturnUrl={this.props.libraryReturnUrl}
|
||||||
libraryReturnUrl={this.props.libraryReturnUrl}
|
UIOptions={this.props.UIOptions}
|
||||||
UIOptions={this.props.UIOptions}
|
focusContainer={this.focusContainer}
|
||||||
focusContainer={this.focusContainer}
|
library={this.library}
|
||||||
library={this.library}
|
id={this.id}
|
||||||
id={this.id}
|
onImageAction={this.onImageAction}
|
||||||
onImageAction={this.onImageAction}
|
/>
|
||||||
renderWelcomeScreen={
|
)}
|
||||||
this.state.showWelcomeScreen &&
|
<div className="excalidraw-textEditorContainer" />
|
||||||
this.state.activeTool.type === "selection" &&
|
<div className="excalidraw-contextMenuContainer" />
|
||||||
!this.scene.getElementsIncludingDeleted().length
|
{selectedElement.length === 1 && this.state.showHyperlinkPopup && (
|
||||||
}
|
<Hyperlink
|
||||||
/>
|
key={selectedElement[0].id}
|
||||||
<div className="excalidraw-textEditorContainer" />
|
element={selectedElement[0]}
|
||||||
<div className="excalidraw-contextMenuContainer" />
|
appState={this.state}
|
||||||
{selectedElement.length === 1 &&
|
setAppState={this.setAppState}
|
||||||
this.state.showHyperlinkPopup && (
|
onLinkOpen={this.props.onLinkOpen}
|
||||||
<Hyperlink
|
/>
|
||||||
key={selectedElement[0].id}
|
)}
|
||||||
element={selectedElement[0]}
|
{this.state.toast !== null && (
|
||||||
setAppState={this.setAppState}
|
<Toast
|
||||||
onLinkOpen={this.props.onLinkOpen}
|
message={this.state.toast.message}
|
||||||
/>
|
onClose={() => this.setToast(null)}
|
||||||
)}
|
duration={this.state.toast.duration}
|
||||||
{this.state.toast !== null && (
|
closable={this.state.toast.closable}
|
||||||
<Toast
|
/>
|
||||||
message={this.state.toast.message}
|
)}
|
||||||
onClose={() => this.setToast(null)}
|
<main>{this.renderCanvas()}</main>
|
||||||
duration={this.state.toast.duration}
|
|
||||||
closable={this.state.toast.closable}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<main>{this.renderCanvas()}</main>
|
|
||||||
</ExcalidrawElementsContext.Provider>{" "}
|
|
||||||
</ExcalidrawAppStateContext.Provider>
|
|
||||||
</ExcalidrawSetAppStateContent.Provider>
|
|
||||||
</DeviceContext.Provider>
|
</DeviceContext.Provider>
|
||||||
</ExcalidrawContainerContext.Provider>
|
</ExcalidrawContainerContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
@@ -664,8 +739,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
let viewModeEnabled = actionResult?.appState?.viewModeEnabled || false;
|
let viewModeEnabled = actionResult?.appState?.viewModeEnabled || false;
|
||||||
let zenModeEnabled = actionResult?.appState?.zenModeEnabled || false;
|
let zenModeEnabled = actionResult?.appState?.zenModeEnabled || false;
|
||||||
let gridSize = actionResult?.appState?.gridSize || null;
|
let gridSize = actionResult?.appState?.gridSize || null;
|
||||||
const theme =
|
let theme = actionResult?.appState?.theme || THEME.LIGHT;
|
||||||
actionResult?.appState?.theme || this.props.theme || THEME.LIGHT;
|
|
||||||
let name = actionResult?.appState?.name ?? this.state.name;
|
let name = actionResult?.appState?.name ?? this.state.name;
|
||||||
if (typeof this.props.viewModeEnabled !== "undefined") {
|
if (typeof this.props.viewModeEnabled !== "undefined") {
|
||||||
viewModeEnabled = this.props.viewModeEnabled;
|
viewModeEnabled = this.props.viewModeEnabled;
|
||||||
@@ -679,6 +753,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
gridSize = this.props.gridModeEnabled ? GRID_SIZE : null;
|
gridSize = this.props.gridModeEnabled ? GRID_SIZE : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof this.props.theme !== "undefined") {
|
||||||
|
theme = this.props.theme;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof this.props.name !== "undefined") {
|
if (typeof this.props.name !== "undefined") {
|
||||||
name = this.props.name;
|
name = this.props.name;
|
||||||
}
|
}
|
||||||
@@ -771,9 +849,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.theme) {
|
|
||||||
this.setState({ theme: this.props.theme });
|
|
||||||
}
|
|
||||||
if (!this.state.isLoading) {
|
if (!this.state.isLoading) {
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
}
|
}
|
||||||
@@ -803,12 +878,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const scene = restore(initialData, null, null);
|
const scene = restore(initialData, null, null);
|
||||||
scene.appState = {
|
scene.appState = {
|
||||||
...scene.appState,
|
...scene.appState,
|
||||||
theme: this.props.theme || scene.appState.theme,
|
|
||||||
// we're falling back to current (pre-init) state when deciding
|
// we're falling back to current (pre-init) state when deciding
|
||||||
// whether to open the library, to handle a case where we
|
// whether to open the library, to handle a case where we
|
||||||
// update the state outside of initialData (e.g. when loading the app
|
// update the state outside of initialData (e.g. when loading the app
|
||||||
// with a library install link, which should auto-open the library)
|
// with a library install link, which should auto-open the library)
|
||||||
openSidebar: scene.appState?.openSidebar || this.state.openSidebar,
|
isLibraryOpen:
|
||||||
|
initialData?.appState?.isLibraryOpen || this.state.isLibraryOpen,
|
||||||
activeTool:
|
activeTool:
|
||||||
scene.appState.activeTool.type === "image"
|
scene.appState.activeTool.type === "image"
|
||||||
? { ...scene.appState.activeTool, type: "selection" }
|
? { ...scene.appState.activeTool, type: "selection" }
|
||||||
@@ -862,7 +937,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
process.env.NODE_ENV === ENV.TEST ||
|
process.env.NODE_ENV === ENV.TEST ||
|
||||||
process.env.NODE_ENV === ENV.DEVELOPMENT
|
process.env.NODE_ENV === ENV.DEVELOPMENT ||
|
||||||
|
process.env.REACT_APP_VERCEL_ENV === "preview"
|
||||||
) {
|
) {
|
||||||
const setState = this.setState.bind(this);
|
const setState = this.setState.bind(this);
|
||||||
Object.defineProperties(window.h, {
|
Object.defineProperties(window.h, {
|
||||||
@@ -1094,13 +1170,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: AppProps, prevState: AppState) {
|
componentDidUpdate(prevProps: AppProps, prevState: AppState) {
|
||||||
if (
|
|
||||||
!this.state.showWelcomeScreen &&
|
|
||||||
!this.scene.getElementsIncludingDeleted().length
|
|
||||||
) {
|
|
||||||
this.setState({ showWelcomeScreen: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.excalidrawContainerRef.current &&
|
this.excalidrawContainerRef.current &&
|
||||||
prevProps.UIOptions.dockedSidebarBreakpoint !==
|
prevProps.UIOptions.dockedSidebarBreakpoint !==
|
||||||
@@ -1182,11 +1251,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
) {
|
) {
|
||||||
// defer so that the commitToHistory flag isn't reset via current update
|
// defer so that the commitToHistory flag isn't reset via current update
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// execute only if the condition still holds when the deferred callback
|
this.actionManager.executeAction(actionFinalize);
|
||||||
// executes (it can be scheduled multiple times depending on how
|
|
||||||
// many times the component renders)
|
|
||||||
this.state.editingLinearElement &&
|
|
||||||
this.actionManager.executeAction(actionFinalize);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1292,10 +1357,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectionColor = getComputedStyle(
|
|
||||||
document.querySelector(".excalidraw")!,
|
|
||||||
).getPropertyValue("--color-selection");
|
|
||||||
|
|
||||||
renderScene(
|
renderScene(
|
||||||
{
|
{
|
||||||
elements: renderingElements,
|
elements: renderingElements,
|
||||||
@@ -1304,7 +1365,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
rc: this.rc!,
|
rc: this.rc!,
|
||||||
canvas: this.canvas!,
|
canvas: this.canvas!,
|
||||||
renderConfig: {
|
renderConfig: {
|
||||||
selectionColor,
|
|
||||||
scrollX: this.state.scrollX,
|
scrollX: this.state.scrollX,
|
||||||
scrollY: this.state.scrollY,
|
scrollY: this.state.scrollY,
|
||||||
viewBackgroundColor: this.state.viewBackgroundColor,
|
viewBackgroundColor: this.state.viewBackgroundColor,
|
||||||
@@ -1594,17 +1654,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
selectGroupsForSelectedElements(
|
selectGroupsForSelectedElements(
|
||||||
{
|
{
|
||||||
...this.state,
|
...this.state,
|
||||||
// keep sidebar (presumably the library) open if it's docked and
|
isLibraryOpen:
|
||||||
// can fit.
|
this.state.isLibraryOpen && this.device.canDeviceFitSidebar
|
||||||
//
|
? this.state.isLibraryMenuDocked
|
||||||
// Note, we should close the sidebar only if we're dropping items
|
: false,
|
||||||
// from library, not when pasting from clipboard. Alas.
|
|
||||||
openSidebar:
|
|
||||||
this.state.openSidebar &&
|
|
||||||
this.device.canDeviceFitSidebar &&
|
|
||||||
this.state.isSidebarDocked
|
|
||||||
? this.state.openSidebar
|
|
||||||
: null,
|
|
||||||
selectedElementIds: newElements.reduce(
|
selectedElementIds: newElements.reduce(
|
||||||
(acc: Record<ExcalidrawElement["id"], true>, element) => {
|
(acc: Record<ExcalidrawElement["id"], true>, element) => {
|
||||||
if (!isBoundToContainer(element)) {
|
if (!isBoundToContainer(element)) {
|
||||||
@@ -1662,8 +1715,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
// Collaboration
|
// Collaboration
|
||||||
|
|
||||||
setAppState: React.Component<any, AppState>["setState"] = (state) => {
|
setAppState = (obj: any) => {
|
||||||
this.setState(state);
|
this.setState(obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
removePointer = (event: React.PointerEvent<HTMLElement> | PointerEvent) => {
|
removePointer = (event: React.PointerEvent<HTMLElement> | PointerEvent) => {
|
||||||
@@ -1801,35 +1854,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.setState({});
|
this.setState({});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns whether the menu was toggled on or off
|
|
||||||
*/
|
|
||||||
public toggleMenu = (
|
|
||||||
type: "library" | "customSidebar",
|
|
||||||
force?: boolean,
|
|
||||||
): boolean => {
|
|
||||||
if (type === "customSidebar" && !this.props.renderSidebar) {
|
|
||||||
console.warn(
|
|
||||||
`attempting to toggle "customSidebar", but no "props.renderSidebar" is defined`,
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === "library" || type === "customSidebar") {
|
|
||||||
let nextValue;
|
|
||||||
if (force === undefined) {
|
|
||||||
nextValue = this.state.openSidebar === type ? null : type;
|
|
||||||
} else {
|
|
||||||
nextValue = force ? type : null;
|
|
||||||
}
|
|
||||||
this.setState({ openSidebar: nextValue });
|
|
||||||
|
|
||||||
return !!nextValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
private updateCurrentCursorPosition = withBatchedUpdates(
|
private updateCurrentCursorPosition = withBatchedUpdates(
|
||||||
(event: MouseEvent) => {
|
(event: MouseEvent) => {
|
||||||
cursorX = event.clientX;
|
cursorX = event.clientX;
|
||||||
@@ -1888,16 +1912,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
if (event.key === KEYS.QUESTION_MARK) {
|
if (event.key === KEYS.QUESTION_MARK) {
|
||||||
this.setState({
|
this.setState({
|
||||||
openDialog: "help",
|
showHelpDialog: true,
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
} else if (
|
|
||||||
event.key.toLowerCase() === KEYS.E &&
|
|
||||||
event.shiftKey &&
|
|
||||||
event[KEYS.CTRL_OR_CMD]
|
|
||||||
) {
|
|
||||||
this.setState({ openDialog: "imageExport" });
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.actionManager.handleKeyDown(event)) {
|
if (this.actionManager.handleKeyDown(event)) {
|
||||||
@@ -1913,7 +1929,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.code === CODES.ZERO) {
|
if (event.code === CODES.ZERO) {
|
||||||
const nextState = this.toggleMenu("library");
|
const nextState = !this.state.isLibraryOpen;
|
||||||
|
this.setState({ isLibraryOpen: nextState });
|
||||||
// track only openings
|
// track only openings
|
||||||
if (nextState) {
|
if (nextState) {
|
||||||
trackEvent(
|
trackEvent(
|
||||||
@@ -2462,9 +2479,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
};
|
};
|
||||||
const minWidth = getApproxMinLineWidth(getFontString(fontString));
|
const minWidth = getApproxMinLineWidth(getFontString(fontString));
|
||||||
const minHeight = getApproxMinLineHeight(getFontString(fontString));
|
const minHeight = getApproxMinLineHeight(getFontString(fontString));
|
||||||
const containerDims = getContainerDims(container);
|
const newHeight = Math.max(container.height, minHeight);
|
||||||
const newHeight = Math.max(containerDims.height, minHeight);
|
const newWidth = Math.max(container.width, minWidth);
|
||||||
const newWidth = Math.max(containerDims.width, minWidth);
|
|
||||||
mutateElement(container, { height: newHeight, width: newWidth });
|
mutateElement(container, { height: newHeight, width: newWidth });
|
||||||
sceneX = container.x + newWidth / 2;
|
sceneX = container.x + newWidth / 2;
|
||||||
sceneY = container.y + newHeight / 2;
|
sceneY = container.y + newHeight / 2;
|
||||||
@@ -2797,23 +2813,18 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
event,
|
event,
|
||||||
scenePointerX,
|
scenePointerX,
|
||||||
scenePointerY,
|
scenePointerY,
|
||||||
this.state,
|
this.state.editingLinearElement,
|
||||||
|
this.state.gridSize,
|
||||||
);
|
);
|
||||||
|
if (editingLinearElement !== this.state.editingLinearElement) {
|
||||||
if (
|
|
||||||
editingLinearElement &&
|
|
||||||
editingLinearElement !== this.state.editingLinearElement
|
|
||||||
) {
|
|
||||||
// Since we are reading from previous state which is not possible with
|
// Since we are reading from previous state which is not possible with
|
||||||
// automatic batching in React 18 hence using flush sync to synchronously
|
// automatic batching in React 18 hence using flush sync to synchronously
|
||||||
// update the state. Check https://github.com/excalidraw/excalidraw/pull/5508 for more details.
|
// update the state. Check https://github.com/excalidraw/excalidraw/pull/5508 for more details.
|
||||||
flushSync(() => {
|
flushSync(() => {
|
||||||
this.setState({
|
this.setState({ editingLinearElement });
|
||||||
editingLinearElement,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (editingLinearElement?.lastUncommittedPoint != null) {
|
if (editingLinearElement.lastUncommittedPoint != null) {
|
||||||
this.maybeSuggestBindingAtCursor(scenePointer);
|
this.maybeSuggestBindingAtCursor(scenePointer);
|
||||||
} else {
|
} else {
|
||||||
this.setState({ suggestedBindings: [] });
|
this.setState({ suggestedBindings: [] });
|
||||||
@@ -3142,7 +3153,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
if (this.state.selectedLinearElement) {
|
if (this.state.selectedLinearElement) {
|
||||||
let hoverPointIndex = -1;
|
let hoverPointIndex = -1;
|
||||||
let segmentMidPointHoveredCoords = null;
|
let midPointHovered = false;
|
||||||
if (
|
if (
|
||||||
isHittingElementNotConsideringBoundingBox(element, this.state, [
|
isHittingElementNotConsideringBoundingBox(element, this.state, [
|
||||||
scenePointerX,
|
scenePointerX,
|
||||||
@@ -3155,14 +3166,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
scenePointerX,
|
scenePointerX,
|
||||||
scenePointerY,
|
scenePointerY,
|
||||||
);
|
);
|
||||||
segmentMidPointHoveredCoords =
|
midPointHovered = LinearElementEditor.isHittingMidPoint(
|
||||||
LinearElementEditor.getSegmentMidpointHitCoords(
|
linearElementEditor,
|
||||||
linearElementEditor,
|
{ x: scenePointerX, y: scenePointerY },
|
||||||
{ x: scenePointerX, y: scenePointerY },
|
this.state,
|
||||||
this.state,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (hoverPointIndex >= 0 || segmentMidPointHoveredCoords) {
|
if (hoverPointIndex >= 0 || midPointHovered) {
|
||||||
setCursor(this.canvas, CURSOR_TYPE.POINTER);
|
setCursor(this.canvas, CURSOR_TYPE.POINTER);
|
||||||
} else {
|
} else {
|
||||||
setCursor(this.canvas, CURSOR_TYPE.MOVE);
|
setCursor(this.canvas, CURSOR_TYPE.MOVE);
|
||||||
@@ -3191,15 +3201,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!LinearElementEditor.arePointsEqual(
|
this.state.selectedLinearElement.midPointHovered !== midPointHovered
|
||||||
this.state.selectedLinearElement.segmentMidPointHoveredCoords,
|
|
||||||
segmentMidPointHoveredCoords,
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedLinearElement: {
|
selectedLinearElement: {
|
||||||
...this.state.selectedLinearElement,
|
...this.state.selectedLinearElement,
|
||||||
segmentMidPointHoveredCoords,
|
midPointHovered,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -4836,6 +4843,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
} else {
|
} else {
|
||||||
this.setState((prevState) => ({
|
this.setState((prevState) => ({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
|
selectedElementIds: {
|
||||||
|
...prevState.selectedElementIds,
|
||||||
|
[draggingElement.id]: true,
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5948,12 +5959,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.actionManager.getAppState(),
|
this.actionManager.getAppState(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const mayBeAllowToggleLineEditing =
|
|
||||||
actionToggleLinearEditor.contextItemPredicate(
|
|
||||||
this.actionManager.getElementsIncludingDeleted(),
|
|
||||||
this.actionManager.getAppState(),
|
|
||||||
);
|
|
||||||
|
|
||||||
const separator = "separator";
|
const separator = "separator";
|
||||||
|
|
||||||
const elements = this.scene.getNonDeletedElements();
|
const elements = this.scene.getNonDeletedElements();
|
||||||
@@ -6095,7 +6100,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
maybeFlipHorizontal && actionFlipHorizontal,
|
maybeFlipHorizontal && actionFlipHorizontal,
|
||||||
maybeFlipVertical && actionFlipVertical,
|
maybeFlipVertical && actionFlipVertical,
|
||||||
(maybeFlipHorizontal || maybeFlipVertical) && separator,
|
(maybeFlipHorizontal || maybeFlipVertical) && separator,
|
||||||
mayBeAllowToggleLineEditing && actionToggleLinearEditor,
|
|
||||||
actionLink.contextItemPredicate(elements, this.state) && actionLink,
|
actionLink.contextItemPredicate(elements, this.state) && actionLink,
|
||||||
actionDuplicateSelection,
|
actionDuplicateSelection,
|
||||||
actionToggleLock,
|
actionToggleLock,
|
||||||
@@ -6123,7 +6127,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
// note that event.ctrlKey is necessary to handle pinch zooming
|
// note that event.ctrlKey is necessary to handle pinch zooming
|
||||||
if (event.metaKey || event.ctrlKey) {
|
if (event.metaKey || event.ctrlKey) {
|
||||||
const sign = Math.sign(deltaY);
|
const sign = Math.sign(deltaY);
|
||||||
const MAX_STEP = ZOOM_STEP * 100;
|
const MAX_STEP = 10;
|
||||||
const absDelta = Math.abs(deltaY);
|
const absDelta = Math.abs(deltaY);
|
||||||
let delta = deltaY;
|
let delta = deltaY;
|
||||||
if (absDelta > MAX_STEP) {
|
if (absDelta > MAX_STEP) {
|
||||||
@@ -6317,7 +6321,8 @@ declare global {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
process.env.NODE_ENV === ENV.TEST ||
|
process.env.NODE_ENV === ENV.TEST ||
|
||||||
process.env.NODE_ENV === ENV.DEVELOPMENT
|
process.env.NODE_ENV === ENV.DEVELOPMENT ||
|
||||||
|
process.env.REACT_APP_VERCEL_ENV === "preview"
|
||||||
) {
|
) {
|
||||||
window.h = window.h || ({} as Window["h"]);
|
window.h = window.h || ({} as Window["h"]);
|
||||||
|
|
||||||
|
|||||||
@@ -2,19 +2,16 @@
|
|||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.Avatar {
|
.Avatar {
|
||||||
width: 1.25rem;
|
width: 2.5rem;
|
||||||
height: 1.25rem;
|
height: 2.5rem;
|
||||||
border-radius: 100%;
|
border-radius: 1.25rem;
|
||||||
outline: 2px solid var(--avatar-border-color);
|
|
||||||
outline-offset: 2px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: $oc-white;
|
color: $oc-white;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 0.625rem;
|
font-size: 0.8rem;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
line-height: 1;
|
|
||||||
|
|
||||||
&-img {
|
&-img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ type AvatarProps = {
|
|||||||
src?: string;
|
src?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Avatar = ({ color, onClick, name, src }: AvatarProps) => {
|
export const Avatar = ({ color, border, onClick, name, src }: AvatarProps) => {
|
||||||
const shortName = getClientInitials(name);
|
const shortName = getClientInitials(name);
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const loadImg = !error && src;
|
const loadImg = !error && src;
|
||||||
const style = loadImg ? undefined : { background: color };
|
const style = loadImg
|
||||||
|
? undefined
|
||||||
|
: { background: color, border: `1px solid ${border}` };
|
||||||
return (
|
return (
|
||||||
<div className="Avatar" style={style} onClick={onClick}>
|
<div className="Avatar" style={style} onClick={onClick}>
|
||||||
{loadImg ? (
|
{loadImg ? (
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { ActionManager } from "../actions/manager";
|
||||||
|
import { AppState } from "../types";
|
||||||
|
|
||||||
|
export const BackgroundPickerAndDarkModeToggle = ({
|
||||||
|
appState,
|
||||||
|
setAppState,
|
||||||
|
actionManager,
|
||||||
|
showThemeBtn,
|
||||||
|
}: {
|
||||||
|
actionManager: ActionManager;
|
||||||
|
appState: AppState;
|
||||||
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
|
showThemeBtn: boolean;
|
||||||
|
}) => (
|
||||||
|
<div style={{ display: "flex" }}>
|
||||||
|
{actionManager.renderAction("changeViewBackgroundColor")}
|
||||||
|
{showThemeBtn && actionManager.renderAction("toggleTheme")}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -64,8 +64,6 @@
|
|||||||
|
|
||||||
color: #{$oc-blue-7};
|
color: #{$oc-blue-7};
|
||||||
|
|
||||||
border: 0;
|
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
box-shadow: 0 0 0 3px #{$oc-blue-7};
|
box-shadow: 0 0 0 3px #{$oc-blue-7};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { TrashIcon } from "./icons";
|
import { useDevice } from "./App";
|
||||||
|
import { trash } from "./icons";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
|
|
||||||
import ConfirmDialog from "./ConfirmDialog";
|
import ConfirmDialog from "./ConfirmDialog";
|
||||||
import MenuItem from "./MenuItem";
|
|
||||||
|
|
||||||
const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => {
|
const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => {
|
||||||
const [showDialog, setShowDialog] = useState(false);
|
const [showDialog, setShowDialog] = useState(false);
|
||||||
@@ -13,11 +14,14 @@ const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<MenuItem
|
<ToolButton
|
||||||
label={t("buttons.clearReset")}
|
type="button"
|
||||||
icon={TrashIcon}
|
icon={trash}
|
||||||
|
title={t("buttons.clearReset")}
|
||||||
|
aria-label={t("buttons.clearReset")}
|
||||||
|
showAriaLabel={useDevice().isMobile}
|
||||||
onClick={toggleDialog}
|
onClick={toggleDialog}
|
||||||
dataTestId="clear-canvas-button"
|
data-testid="clear-canvas-button"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{showDialog && (
|
{showDialog && (
|
||||||
|
|||||||
@@ -1,51 +1,6 @@
|
|||||||
@import "../css/variables.module";
|
@import "../css/variables.module";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.collab-button {
|
|
||||||
@include outlineButtonStyles;
|
|
||||||
width: var(--lg-button-size);
|
|
||||||
height: var(--lg-button-size);
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: var(--lg-icon-size);
|
|
||||||
height: var(--lg-icon-size);
|
|
||||||
}
|
|
||||||
background-color: var(--color-primary);
|
|
||||||
border-color: var(--color-primary);
|
|
||||||
color: white;
|
|
||||||
flex-shrink: 0;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--color-primary-darker);
|
|
||||||
border-color: var(--color-primary-darker);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:active {
|
|
||||||
background-color: var(--color-primary-darker);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.active {
|
|
||||||
background-color: #0fb884;
|
|
||||||
border-color: #0fb884;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover,
|
|
||||||
&:active {
|
|
||||||
background-color: #0fb884;
|
|
||||||
border-color: #0fb884;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
.collab-button {
|
|
||||||
color: var(--color-gray-90);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.CollabButton.is-collaborating {
|
.CollabButton.is-collaborating {
|
||||||
background-color: var(--button-special-active-bg-color);
|
background-color: var(--button-special-active-bg-color);
|
||||||
|
|
||||||
@@ -69,9 +24,9 @@
|
|||||||
bottom: -5px;
|
bottom: -5px;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: $oc-green-2;
|
background-color: $oc-green-6;
|
||||||
color: $oc-green-9;
|
color: $oc-white;
|
||||||
font-size: 0.6rem;
|
font-size: 0.6em;
|
||||||
font-family: "Cascadia";
|
font-family: "Cascadia";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,37 @@
|
|||||||
|
import clsx from "clsx";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { UsersIcon } from "./icons";
|
import { useDevice } from "../components/App";
|
||||||
|
import { users } from "./icons";
|
||||||
|
|
||||||
import "./CollabButton.scss";
|
import "./CollabButton.scss";
|
||||||
import MenuItem from "./MenuItem";
|
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
const CollabButton = ({
|
const CollabButton = ({
|
||||||
isCollaborating,
|
isCollaborating,
|
||||||
collaboratorCount,
|
collaboratorCount,
|
||||||
onClick,
|
onClick,
|
||||||
isInHamburgerMenu = true,
|
|
||||||
}: {
|
}: {
|
||||||
isCollaborating: boolean;
|
isCollaborating: boolean;
|
||||||
collaboratorCount: number;
|
collaboratorCount: number;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
isInHamburgerMenu?: boolean;
|
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isInHamburgerMenu ? (
|
<ToolButton
|
||||||
<MenuItem
|
className={clsx("CollabButton", {
|
||||||
label={t("labels.liveCollaboration")}
|
"is-collaborating": isCollaborating,
|
||||||
dataTestId="collab-button"
|
})}
|
||||||
icon={UsersIcon}
|
onClick={onClick}
|
||||||
onClick={onClick}
|
icon={users}
|
||||||
isCollaborating={isCollaborating}
|
type="button"
|
||||||
/>
|
title={t("labels.liveCollaboration")}
|
||||||
) : (
|
aria-label={t("labels.liveCollaboration")}
|
||||||
<button
|
showAriaLabel={useDevice().isMobile}
|
||||||
className={clsx("collab-button", { active: isCollaborating })}
|
>
|
||||||
type="button"
|
{isCollaborating && (
|
||||||
onClick={onClick}
|
<div className="CollabButton-collaborators">{collaboratorCount}</div>
|
||||||
style={{ position: "relative" }}
|
)}
|
||||||
title={t("labels.liveCollaboration")}
|
</ToolButton>
|
||||||
>
|
|
||||||
{UsersIcon}
|
|
||||||
{collaboratorCount > 0 && (
|
|
||||||
<div className="CollabButton-collaborators">
|
|
||||||
{collaboratorCount}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,23 +21,6 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto 1fr;
|
grid-template-columns: auto 1fr;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
column-gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-picker-control-container + .popover {
|
|
||||||
position: static;
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-picker-popover-container {
|
|
||||||
margin-top: -0.25rem;
|
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
|
||||||
margin-left: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
margin-left: -3rem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-triangle {
|
.color-picker-triangle {
|
||||||
@@ -47,29 +30,20 @@
|
|||||||
border-width: 0 9px 10px;
|
border-width: 0 9px 10px;
|
||||||
border-color: transparent transparent var(--popup-bg-color);
|
border-color: transparent transparent var(--popup-bg-color);
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: -10px;
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
:root[dir="ltr"] & {
|
||||||
transform: rotate(270deg);
|
left: 12px;
|
||||||
left: -14px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
:root[dir="rtl"] & {
|
||||||
transform: rotate(90deg);
|
right: 12px;
|
||||||
right: -14px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-triangle-shadow {
|
.color-picker-triangle-shadow {
|
||||||
border-color: transparent transparent transparentize($oc-black, 0.9);
|
border-color: transparent transparent transparentize($oc-black, 0.9);
|
||||||
|
top: -11px;
|
||||||
:root[dir="ltr"] & {
|
|
||||||
left: -14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
right: -16px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-content--default {
|
.color-picker-content--default {
|
||||||
@@ -145,21 +119,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-hash {
|
.color-picker-hash {
|
||||||
height: var(--default-button-size);
|
background: var(--input-border-color);
|
||||||
flex-shrink: 0;
|
height: 1.875rem;
|
||||||
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
|
width: 1.875rem;
|
||||||
border: 1px solid var(--default-border-color);
|
|
||||||
border-right: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
:root[dir="ltr"] & {
|
||||||
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
border-radius: 4px 0 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
:root[dir="rtl"] & {
|
||||||
border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
|
border-radius: 0 4px 4px 0;
|
||||||
border-right: 1px solid var(--default-border-color);
|
|
||||||
border-left: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
color: var(--input-label-color);
|
color: var(--input-label-color);
|
||||||
@@ -169,64 +138,81 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-input-container {
|
.color-input-container:focus-within .color-picker-hash {
|
||||||
display: flex;
|
box-shadow: 0 0 0 2px var(--focus-highlight-color);
|
||||||
|
|
||||||
&:focus-within {
|
|
||||||
box-shadow: 0 0 0 1px var(--color-primary-darkest);
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-input {
|
.color-input-container:focus-within .color-picker-hash::before,
|
||||||
box-sizing: border-box;
|
.color-input-container:focus-within .color-picker-hash::after {
|
||||||
width: 100%;
|
content: "";
|
||||||
margin: 0;
|
width: 1px;
|
||||||
font-size: 0.875rem;
|
height: 100%;
|
||||||
background-color: transparent;
|
position: absolute;
|
||||||
color: var(--text-primary-color);
|
top: 0;
|
||||||
border: 0;
|
}
|
||||||
outline: none;
|
|
||||||
height: var(--default-button-size);
|
.color-input-container:focus-within .color-picker-hash::before {
|
||||||
border: 1px solid var(--default-border-color);
|
background: var(--input-border-color);
|
||||||
border-left: 0;
|
|
||||||
letter-spacing: 0.4px;
|
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
:root[dir="ltr"] & {
|
||||||
border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
|
right: -1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
:root[dir="rtl"] & {
|
||||||
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
left: -1px;
|
||||||
border-left: 1px solid var(--default-border-color);
|
|
||||||
border-right: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
padding: 0.5rem;
|
|
||||||
padding-left: 0.25rem;
|
|
||||||
appearance: none;
|
|
||||||
|
|
||||||
&:focus-visible {
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-label-swatch-container {
|
.color-input-container:focus-within .color-picker-hash::after {
|
||||||
border: 1px solid var(--default-border-color);
|
background: var(--input-bg-color);
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
width: var(--default-button-size);
|
:root[dir="ltr"] & {
|
||||||
height: var(--default-button-size);
|
right: -2px;
|
||||||
box-sizing: border-box;
|
}
|
||||||
overflow: hidden;
|
|
||||||
|
:root[dir="rtl"] & {
|
||||||
|
left: -2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-input-container {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-picker-input {
|
||||||
|
width: 11ch; /* length of `transparent` */
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1rem;
|
||||||
|
background-color: var(--input-bg-color);
|
||||||
|
color: var(--text-primary-color);
|
||||||
|
border: 0;
|
||||||
|
outline: none;
|
||||||
|
height: 1.75em;
|
||||||
|
box-shadow: var(--input-border-color) 0 0 0 1px inset;
|
||||||
|
|
||||||
|
:root[dir="ltr"] & {
|
||||||
|
border-radius: 0 4px 4px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[dir="rtl"] & {
|
||||||
|
border-radius: 4px 0 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
float: left;
|
||||||
|
padding: 1px;
|
||||||
|
padding-inline-start: 0.5em;
|
||||||
|
appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-label-swatch {
|
.color-picker-label-swatch {
|
||||||
@include outlineButtonStyles;
|
height: 1.875rem;
|
||||||
background-color: var(--swatch-color) !important;
|
width: 1.875rem;
|
||||||
overflow: hidden;
|
margin-inline-end: 0.25rem;
|
||||||
|
border: 1px solid $oc-gray-3;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: transparent !important;
|
||||||
filter: var(--theme-filter);
|
filter: var(--theme-filter);
|
||||||
border: 0 !important;
|
|
||||||
|
|
||||||
&:after {
|
&:after {
|
||||||
content: "";
|
content: "";
|
||||||
|
|||||||
@@ -343,8 +343,6 @@ const ColorInput = React.forwardRef(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
ColorInput.displayName = "ColorInput";
|
|
||||||
|
|
||||||
export const ColorPicker = ({
|
export const ColorPicker = ({
|
||||||
type,
|
type,
|
||||||
color,
|
color,
|
||||||
@@ -365,20 +363,17 @@ export const ColorPicker = ({
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
}) => {
|
}) => {
|
||||||
const pickerButton = React.useRef<HTMLButtonElement>(null);
|
const pickerButton = React.useRef<HTMLButtonElement>(null);
|
||||||
const coords = pickerButton.current?.getBoundingClientRect();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="color-picker-control-container">
|
<div className="color-picker-control-container">
|
||||||
<div className="color-picker-label-swatch-container">
|
<button
|
||||||
<button
|
className="color-picker-label-swatch"
|
||||||
className="color-picker-label-swatch"
|
aria-label={label}
|
||||||
aria-label={label}
|
style={color ? { "--swatch-color": color } : undefined}
|
||||||
style={color ? { "--swatch-color": color } : undefined}
|
onClick={() => setActive(!isActive)}
|
||||||
onClick={() => setActive(!isActive)}
|
ref={pickerButton}
|
||||||
ref={pickerButton}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<ColorInput
|
<ColorInput
|
||||||
color={color}
|
color={color}
|
||||||
label={label}
|
label={label}
|
||||||
@@ -389,37 +384,27 @@ export const ColorPicker = ({
|
|||||||
</div>
|
</div>
|
||||||
<React.Suspense fallback="">
|
<React.Suspense fallback="">
|
||||||
{isActive ? (
|
{isActive ? (
|
||||||
<div
|
<Popover
|
||||||
className="color-picker-popover-container"
|
onCloseRequest={(event) =>
|
||||||
style={{
|
event.target !== pickerButton.current && setActive(false)
|
||||||
position: "fixed",
|
}
|
||||||
top: coords?.top,
|
|
||||||
left: coords?.right,
|
|
||||||
zIndex: 1,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Popover
|
<Picker
|
||||||
onCloseRequest={(event) =>
|
colors={colors[type]}
|
||||||
event.target !== pickerButton.current && setActive(false)
|
color={color || null}
|
||||||
}
|
onChange={(changedColor) => {
|
||||||
>
|
onChange(changedColor);
|
||||||
<Picker
|
}}
|
||||||
colors={colors[type]}
|
onClose={() => {
|
||||||
color={color || null}
|
setActive(false);
|
||||||
onChange={(changedColor) => {
|
pickerButton.current?.focus();
|
||||||
onChange(changedColor);
|
}}
|
||||||
}}
|
label={label}
|
||||||
onClose={() => {
|
showInput={false}
|
||||||
setActive(false);
|
type={type}
|
||||||
pickerButton.current?.focus();
|
elements={elements}
|
||||||
}}
|
/>
|
||||||
label={label}
|
</Popover>
|
||||||
showInput={false}
|
|
||||||
type={type}
|
|
||||||
elements={elements}
|
|
||||||
/>
|
|
||||||
</Popover>
|
|
||||||
</div>
|
|
||||||
) : null}
|
) : null}
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,8 +4,34 @@
|
|||||||
.confirm-dialog {
|
.confirm-dialog {
|
||||||
&-buttons {
|
&-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
column-gap: 0.5rem;
|
padding: 0.2rem 0;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
.ToolIcon__icon {
|
||||||
|
min-width: 2.5rem;
|
||||||
|
width: auto;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ToolIcon_type_button {
|
||||||
|
margin-left: 0.8rem;
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--confirm.ToolIcon_type_button {
|
||||||
|
background-color: $oc-red-6;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-red-8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ToolIcon__icon {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { Dialog, DialogProps } from "./Dialog";
|
import { Dialog, DialogProps } from "./Dialog";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
|
|
||||||
import "./ConfirmDialog.scss";
|
import "./ConfirmDialog.scss";
|
||||||
import DialogActionButton from "./DialogActionButton";
|
|
||||||
import { isMenuOpenAtom } from "./App";
|
|
||||||
import { isDropdownOpenAtom } from "./App";
|
|
||||||
import { useSetAtom } from "jotai";
|
|
||||||
|
|
||||||
interface Props extends Omit<DialogProps, "onCloseRequest"> {
|
interface Props extends Omit<DialogProps, "onCloseRequest"> {
|
||||||
onConfirm: () => void;
|
onConfirm: () => void;
|
||||||
@@ -23,10 +20,6 @@ const ConfirmDialog = (props: Props) => {
|
|||||||
className = "",
|
className = "",
|
||||||
...rest
|
...rest
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const setIsMenuOpen = useSetAtom(isMenuOpenAtom);
|
|
||||||
const setIsDropdownOpen = useSetAtom(isDropdownOpenAtom);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
onCloseRequest={onCancel}
|
onCloseRequest={onCancel}
|
||||||
@@ -36,22 +29,21 @@ const ConfirmDialog = (props: Props) => {
|
|||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<div className="confirm-dialog-buttons">
|
<div className="confirm-dialog-buttons">
|
||||||
<DialogActionButton
|
<ToolButton
|
||||||
|
type="button"
|
||||||
|
title={cancelText}
|
||||||
|
aria-label={cancelText}
|
||||||
label={cancelText}
|
label={cancelText}
|
||||||
onClick={() => {
|
onClick={onCancel}
|
||||||
setIsMenuOpen(false);
|
className="confirm-dialog--cancel"
|
||||||
setIsDropdownOpen(false);
|
|
||||||
onCancel();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<DialogActionButton
|
<ToolButton
|
||||||
|
type="button"
|
||||||
|
title={confirmText}
|
||||||
|
aria-label={confirmText}
|
||||||
label={confirmText}
|
label={confirmText}
|
||||||
onClick={() => {
|
onClick={onConfirm}
|
||||||
setIsMenuOpen(false);
|
className="confirm-dialog--confirm"
|
||||||
setIsDropdownOpen(false);
|
|
||||||
onConfirm();
|
|
||||||
}}
|
|
||||||
actionType="danger"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -7,11 +7,68 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.Dialog__title {
|
.Dialog__title {
|
||||||
|
display: grid;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 0;
|
||||||
|
grid-template-columns: 1fr calc(var(--space-factor) * 7);
|
||||||
|
grid-gap: var(--metric);
|
||||||
|
padding: calc(var(--space-factor) * 2);
|
||||||
|
text-align: center;
|
||||||
|
font-variant: small-caps;
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Dialog__titleContent {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Dialog .Modal__close {
|
||||||
|
color: var(--icon-fill-color);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
text-align: left;
|
}
|
||||||
font-size: 1.25rem;
|
|
||||||
border-bottom: 1px solid var(--dialog-border-color);
|
.Dialog__content {
|
||||||
padding: 0 0 0.75rem;
|
padding: 0 16px 16px;
|
||||||
margin-bottom: 1.5rem;
|
}
|
||||||
|
|
||||||
|
@include isMobile {
|
||||||
|
.Dialog {
|
||||||
|
--metric: calc(var(--space-factor) * 4);
|
||||||
|
--inset-left: #{"max(var(--metric), var(--sal))"};
|
||||||
|
--inset-right: #{"max(var(--metric), var(--sar))"};
|
||||||
|
}
|
||||||
|
|
||||||
|
.Dialog__title {
|
||||||
|
grid-template-columns: calc(var(--space-factor) * 7) 1fr calc(
|
||||||
|
var(--space-factor) * 7
|
||||||
|
);
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
padding: calc(var(--space-factor) * 2);
|
||||||
|
background: var(--island-bg-color);
|
||||||
|
font-size: 1.25em;
|
||||||
|
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-bottom: 1px solid var(--button-gray-2);
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Dialog__titleContent {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Dialog .Island {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-left: #{"max(calc(var(--padding) * var(--space-factor)), var(--sal))"};
|
||||||
|
padding-right: #{"max(calc(var(--padding) * var(--space-factor)), var(--sar))"};
|
||||||
|
padding-bottom: #{"max(calc(var(--padding) * var(--space-factor)), var(--sab))"};
|
||||||
|
}
|
||||||
|
|
||||||
|
.Dialog .Modal__close {
|
||||||
|
order: -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ import { t } from "../i18n";
|
|||||||
import { useExcalidrawContainer, useDevice } from "../components/App";
|
import { useExcalidrawContainer, useDevice } from "../components/App";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import "./Dialog.scss";
|
import "./Dialog.scss";
|
||||||
import { back, CloseIcon } from "./icons";
|
import { back, close } from "./icons";
|
||||||
import { Island } from "./Island";
|
import { Island } from "./Island";
|
||||||
import { Modal } from "./Modal";
|
import { Modal } from "./Modal";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { queryFocusableElements } from "../utils";
|
import { queryFocusableElements } from "../utils";
|
||||||
import { isMenuOpenAtom, isDropdownOpenAtom } from "./App";
|
|
||||||
import { useSetAtom } from "jotai";
|
|
||||||
|
|
||||||
export interface DialogProps {
|
export interface DialogProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -67,12 +65,7 @@ export const Dialog = (props: DialogProps) => {
|
|||||||
return () => islandNode.removeEventListener("keydown", handleKeyDown);
|
return () => islandNode.removeEventListener("keydown", handleKeyDown);
|
||||||
}, [islandNode, props.autofocus]);
|
}, [islandNode, props.autofocus]);
|
||||||
|
|
||||||
const setIsMenuOpen = useSetAtom(isMenuOpenAtom);
|
|
||||||
const setIsDropdownOpen = useSetAtom(isDropdownOpenAtom);
|
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
setIsMenuOpen(false);
|
|
||||||
setIsDropdownOpen(false);
|
|
||||||
(lastActiveElement as HTMLElement).focus();
|
(lastActiveElement as HTMLElement).focus();
|
||||||
props.onCloseRequest();
|
props.onCloseRequest();
|
||||||
};
|
};
|
||||||
@@ -95,7 +88,7 @@ export const Dialog = (props: DialogProps) => {
|
|||||||
title={t("buttons.close")}
|
title={t("buttons.close")}
|
||||||
aria-label={t("buttons.close")}
|
aria-label={t("buttons.close")}
|
||||||
>
|
>
|
||||||
{useDevice().isMobile ? back : CloseIcon}
|
{useDevice().isMobile ? back : close}
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div className="Dialog__content">{props.children}</div>
|
<div className="Dialog__content">{props.children}</div>
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
.excalidraw {
|
|
||||||
.Dialog__action-button {
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
column-gap: 0.5rem;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0.5rem 1.5rem;
|
|
||||||
border: 1px solid var(--default-border-color);
|
|
||||||
background-color: transparent;
|
|
||||||
height: 3rem;
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
letter-spacing: 0.4px;
|
|
||||||
color: inherit;
|
|
||||||
font-family: inherit;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
font-weight: 600;
|
|
||||||
user-select: none;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
display: block;
|
|
||||||
width: 1rem;
|
|
||||||
height: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
&--danger {
|
|
||||||
background-color: var(--color-danger);
|
|
||||||
border-color: var(--color-danger);
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
&--primary {
|
|
||||||
background-color: var(--color-primary);
|
|
||||||
border-color: var(--color-primary);
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
.Dialog__action-button--danger {
|
|
||||||
color: var(--color-gray-100);
|
|
||||||
}
|
|
||||||
|
|
||||||
.Dialog__action-button--primary {
|
|
||||||
color: var(--color-gray-100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import { ReactNode } from "react";
|
|
||||||
import "./DialogActionButton.scss";
|
|
||||||
import Spinner from "./Spinner";
|
|
||||||
|
|
||||||
interface DialogActionButtonProps {
|
|
||||||
label: string;
|
|
||||||
children?: ReactNode;
|
|
||||||
actionType?: "primary" | "danger";
|
|
||||||
isLoading?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DialogActionButton = ({
|
|
||||||
label,
|
|
||||||
onClick,
|
|
||||||
className,
|
|
||||||
children,
|
|
||||||
actionType,
|
|
||||||
type = "button",
|
|
||||||
isLoading,
|
|
||||||
...rest
|
|
||||||
}: DialogActionButtonProps & React.ButtonHTMLAttributes<HTMLButtonElement>) => {
|
|
||||||
const cs = actionType ? `Dialog__action-button--${actionType}` : "";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
className={clsx("Dialog__action-button", cs, className)}
|
|
||||||
type={type}
|
|
||||||
aria-label={label}
|
|
||||||
onClick={onClick}
|
|
||||||
{...rest}
|
|
||||||
>
|
|
||||||
{children && (
|
|
||||||
<div style={isLoading ? { visibility: "hidden" } : {}}>{children}</div>
|
|
||||||
)}
|
|
||||||
<div style={isLoading ? { visibility: "hidden" } : {}}>{label}</div>
|
|
||||||
{isLoading && (
|
|
||||||
<div style={{ position: "absolute", inset: 0 }}>
|
|
||||||
<Spinner />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DialogActionButton;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { t } from "../i18n";
|
|
||||||
import { shield } from "./icons";
|
|
||||||
import { Tooltip } from "./Tooltip";
|
|
||||||
|
|
||||||
const EncryptedIcon = () => (
|
|
||||||
<a
|
|
||||||
className="encrypted-icon tooltip"
|
|
||||||
href="https://blog.excalidraw.com/end-to-end-encryption/"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
aria-label={t("encrypted.link")}
|
|
||||||
>
|
|
||||||
<Tooltip label={t("encrypted.tooltip")} long={true}>
|
|
||||||
{shield}
|
|
||||||
</Tooltip>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
|
|
||||||
export default EncryptedIcon;
|
|
||||||
@@ -91,8 +91,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
button.ExportDialog-imageExportButton {
|
button.ExportDialog-imageExportButton {
|
||||||
border: 0;
|
|
||||||
|
|
||||||
width: 5rem;
|
width: 5rem;
|
||||||
height: 5rem;
|
height: 5rem;
|
||||||
margin: 0 0.2em;
|
margin: 0 0.2em;
|
||||||
|
|||||||
@@ -9,10 +9,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.FixedSideContainer_side_top {
|
.FixedSideContainer_side_top {
|
||||||
left: 1rem;
|
left: var(--space-factor);
|
||||||
top: 1rem;
|
top: var(--space-factor);
|
||||||
right: 1rem;
|
right: var(--space-factor);
|
||||||
bottom: 1rem;
|
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import { ActionManager } from "../actions/manager";
|
|
||||||
import { t } from "../i18n";
|
|
||||||
import { AppState, ExcalidrawProps } from "../types";
|
|
||||||
import {
|
|
||||||
ExitZenModeAction,
|
|
||||||
FinalizeAction,
|
|
||||||
UndoRedoActions,
|
|
||||||
ZoomActions,
|
|
||||||
} from "./Actions";
|
|
||||||
import { useDevice } from "./App";
|
|
||||||
import { WelcomeScreenHelpArrow } from "./icons";
|
|
||||||
import { Section } from "./Section";
|
|
||||||
import Stack from "./Stack";
|
|
||||||
import WelcomeScreenDecor from "./WelcomeScreenDecor";
|
|
||||||
|
|
||||||
const Footer = ({
|
|
||||||
appState,
|
|
||||||
actionManager,
|
|
||||||
renderCustomFooter,
|
|
||||||
showExitZenModeBtn,
|
|
||||||
renderWelcomeScreen,
|
|
||||||
}: {
|
|
||||||
appState: AppState;
|
|
||||||
actionManager: ActionManager;
|
|
||||||
renderCustomFooter?: ExcalidrawProps["renderFooter"];
|
|
||||||
showExitZenModeBtn: boolean;
|
|
||||||
renderWelcomeScreen: boolean;
|
|
||||||
}) => {
|
|
||||||
const device = useDevice();
|
|
||||||
const showFinalize =
|
|
||||||
!appState.viewModeEnabled && appState.multiElement && device.isTouchScreen;
|
|
||||||
return (
|
|
||||||
<footer
|
|
||||||
role="contentinfo"
|
|
||||||
className="layer-ui__wrapper__footer App-menu App-menu_bottom"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={clsx("layer-ui__wrapper__footer-left zen-mode-transition", {
|
|
||||||
"layer-ui__wrapper__footer-left--transition-left":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<Stack.Col gap={2}>
|
|
||||||
<Section heading="canvasActions">
|
|
||||||
<ZoomActions
|
|
||||||
renderAction={actionManager.renderAction}
|
|
||||||
zoom={appState.zoom}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{!appState.viewModeEnabled && (
|
|
||||||
<UndoRedoActions
|
|
||||||
renderAction={actionManager.renderAction}
|
|
||||||
className={clsx("zen-mode-transition", {
|
|
||||||
"layer-ui__wrapper__footer-left--transition-bottom":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{showFinalize && (
|
|
||||||
<FinalizeAction
|
|
||||||
renderAction={actionManager.renderAction}
|
|
||||||
className={clsx("zen-mode-transition", {
|
|
||||||
"layer-ui__wrapper__footer-left--transition-left":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Section>
|
|
||||||
</Stack.Col>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={clsx(
|
|
||||||
"layer-ui__wrapper__footer-center zen-mode-transition",
|
|
||||||
{
|
|
||||||
"layer-ui__wrapper__footer-left--transition-bottom":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{renderCustomFooter?.(false, appState)}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={clsx("layer-ui__wrapper__footer-right zen-mode-transition", {
|
|
||||||
"transition-right disable-pointerEvents": appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<div style={{ position: "relative" }}>
|
|
||||||
<WelcomeScreenDecor
|
|
||||||
shouldRender={renderWelcomeScreen && !appState.isLoading}
|
|
||||||
>
|
|
||||||
<div className="virgil WelcomeScreen-decor WelcomeScreen-decor--help-pointer">
|
|
||||||
<div>{t("welcomeScreen.helpHints")}</div>
|
|
||||||
{WelcomeScreenHelpArrow}
|
|
||||||
</div>
|
|
||||||
</WelcomeScreenDecor>
|
|
||||||
|
|
||||||
{actionManager.renderAction("toggleShortcuts")}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ExitZenModeAction
|
|
||||||
actionManager={actionManager}
|
|
||||||
showExitZenModeBtn={showExitZenModeBtn}
|
|
||||||
/>
|
|
||||||
</footer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Footer;
|
|
||||||
+45
-104
@@ -1,115 +1,56 @@
|
|||||||
@import "../css/variables.module";
|
@import "../css/variables.module";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.HelpDialog {
|
.HelpDialog h3 {
|
||||||
.Modal__content {
|
border-bottom: 1px solid var(--button-gray-2);
|
||||||
max-width: 960px;
|
padding-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
.HelpDialog--island {
|
||||||
margin: 1.5rem 0;
|
border: 1px solid var(--button-gray-2);
|
||||||
font-weight: bold;
|
margin-bottom: 16px;
|
||||||
font-size: 1.125rem;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
&__header {
|
.HelpDialog--island-title {
|
||||||
display: flex;
|
margin: 0;
|
||||||
flex-wrap: wrap;
|
padding: 4px;
|
||||||
gap: 0.75rem;
|
background-color: var(--button-gray-1);
|
||||||
}
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
&__btn {
|
.HelpDialog--shortcut {
|
||||||
display: flex;
|
border-top: 1px solid var(--button-gray-2);
|
||||||
column-gap: 0.5rem;
|
}
|
||||||
align-items: center;
|
|
||||||
border: 1px solid var(--default-border-color);
|
|
||||||
padding: 0.625rem 1rem;
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
color: var(--text-primary-color);
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 0.75rem;
|
|
||||||
letter-spacing: 0.4px;
|
|
||||||
|
|
||||||
&:hover {
|
.HelpDialog--key {
|
||||||
text-decoration: none;
|
word-break: keep-all;
|
||||||
}
|
border: 1px solid var(--button-gray-2);
|
||||||
}
|
padding: 2px 8px;
|
||||||
|
margin: auto 4px;
|
||||||
|
background-color: var(--button-gray-1);
|
||||||
|
border-radius: 2px;
|
||||||
|
font-size: 0.8em;
|
||||||
|
min-height: 26px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
&__link-icon {
|
.HelpDialog--header {
|
||||||
line-height: 0;
|
display: flex;
|
||||||
svg {
|
flex-direction: row;
|
||||||
width: 1rem;
|
justify-content: space-evenly;
|
||||||
height: 1rem;
|
margin-bottom: 32px;
|
||||||
}
|
padding-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__islands-container {
|
.HelpDialog--btn {
|
||||||
display: grid;
|
border: 1px solid var(--link-color);
|
||||||
@media screen and (min-width: 1024px) {
|
padding: 8px 32px;
|
||||||
grid-template-columns: 1fr 1fr;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
grid-column-gap: 1.5rem;
|
.HelpDialog--btn:hover {
|
||||||
grid-row-gap: 2rem;
|
text-decoration: none;
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 1024px) {
|
|
||||||
&__island--tools {
|
|
||||||
grid-area: 1 / 1 / 2 / 2;
|
|
||||||
}
|
|
||||||
&__island--view {
|
|
||||||
grid-area: 2 / 1 / 3 / 2;
|
|
||||||
}
|
|
||||||
&__island--editor {
|
|
||||||
grid-area: 1 / 2 / 3 / 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__island {
|
|
||||||
h4 {
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 0;
|
|
||||||
margin-bottom: 0.625rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-content {
|
|
||||||
border: 1px solid var(--dialog-border-color);
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__shortcut {
|
|
||||||
border-bottom: 1px solid var(--dialog-border-color);
|
|
||||||
padding: 0.375rem 0.75rem;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
column-gap: 0.5rem;
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__key-container {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
column-gap: 0.25rem;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__key {
|
|
||||||
display: flex;
|
|
||||||
box-sizing: border-box;
|
|
||||||
font-size: 0.625rem;
|
|
||||||
background-color: var(--color-primary-light);
|
|
||||||
border-radius: var(--border-radius-md);
|
|
||||||
padding: 0.5rem;
|
|
||||||
word-break: keep-all;
|
|
||||||
align-items: center;
|
|
||||||
font-family: inherit;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+346
-313
@@ -4,36 +4,32 @@ import { isDarwin, isWindows } from "../keys";
|
|||||||
import { Dialog } from "./Dialog";
|
import { Dialog } from "./Dialog";
|
||||||
import { getShortcutKey } from "../utils";
|
import { getShortcutKey } from "../utils";
|
||||||
import "./HelpDialog.scss";
|
import "./HelpDialog.scss";
|
||||||
import { ExternalLinkIcon } from "./icons";
|
|
||||||
|
|
||||||
const Header = () => (
|
const Header = () => (
|
||||||
<div className="HelpDialog__header">
|
<div className="HelpDialog--header">
|
||||||
<a
|
<a
|
||||||
className="HelpDialog__btn"
|
className="HelpDialog--btn"
|
||||||
href="https://github.com/excalidraw/excalidraw#documentation"
|
href="https://github.com/excalidraw/excalidraw#documentation"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
{t("helpDialog.documentation")}
|
{t("helpDialog.documentation")}
|
||||||
<div className="HelpDialog__link-icon">{ExternalLinkIcon}</div>
|
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
className="HelpDialog__btn"
|
className="HelpDialog--btn"
|
||||||
href="https://blog.excalidraw.com"
|
href="https://blog.excalidraw.com"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
{t("helpDialog.blog")}
|
{t("helpDialog.blog")}
|
||||||
<div className="HelpDialog__link-icon">{ExternalLinkIcon}</div>
|
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
className="HelpDialog__btn"
|
className="HelpDialog--btn"
|
||||||
href="https://github.com/excalidraw/excalidraw/issues"
|
href="https://github.com/excalidraw/excalidraw/issues"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
{t("helpDialog.github")}
|
{t("helpDialog.github")}
|
||||||
<div className="HelpDialog__link-icon">{ExternalLinkIcon}</div>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -41,61 +37,88 @@ const Header = () => (
|
|||||||
const Section = (props: { title: string; children: React.ReactNode }) => (
|
const Section = (props: { title: string; children: React.ReactNode }) => (
|
||||||
<>
|
<>
|
||||||
<h3>{props.title}</h3>
|
<h3>{props.title}</h3>
|
||||||
<div className="HelpDialog__islands-container">{props.children}</div>
|
{props.children}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const Columns = (props: { children: React.ReactNode }) => (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "row",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const Column = (props: { children: React.ReactNode }) => (
|
||||||
|
<div style={{ width: "49%" }}>{props.children}</div>
|
||||||
|
);
|
||||||
|
|
||||||
const ShortcutIsland = (props: {
|
const ShortcutIsland = (props: {
|
||||||
caption: string;
|
caption: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
|
||||||
}) => (
|
}) => (
|
||||||
<div className={`HelpDialog__island ${props.className}`}>
|
<div className="HelpDialog--island">
|
||||||
<h4 className="HelpDialog__island-title">{props.caption}</h4>
|
<h3 className="HelpDialog--island-title">{props.caption}</h3>
|
||||||
<div className="HelpDialog__island-content">{props.children}</div>
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
function* intersperse(as: JSX.Element[][], delim: string | null) {
|
const Shortcut = (props: {
|
||||||
let first = true;
|
|
||||||
for (const x of as) {
|
|
||||||
if (!first) {
|
|
||||||
yield delim;
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
yield x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Shortcut = ({
|
|
||||||
label,
|
|
||||||
shortcuts,
|
|
||||||
isOr = true,
|
|
||||||
}: {
|
|
||||||
label: string;
|
label: string;
|
||||||
shortcuts: string[];
|
shortcuts: string[];
|
||||||
isOr?: boolean;
|
isOr: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const splitShortcutKeys = shortcuts.map((shortcut) => {
|
|
||||||
const keys = shortcut.endsWith("++")
|
|
||||||
? [...shortcut.slice(0, -2).split("+"), "+"]
|
|
||||||
: shortcut.split("+");
|
|
||||||
|
|
||||||
return keys.map((key) => <ShortcutKey key={key}>{key}</ShortcutKey>);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="HelpDialog__shortcut">
|
<div className="HelpDialog--shortcut">
|
||||||
<div>{label}</div>
|
<div
|
||||||
<div className="HelpDialog__key-container">
|
style={{
|
||||||
{[...intersperse(splitShortcutKeys, isOr ? t("helpDialog.or") : null)]}
|
display: "flex",
|
||||||
|
margin: "0",
|
||||||
|
padding: "4px 8px",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
lineHeight: 1.4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{props.label}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flex: "0 0 auto",
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
marginInlineStart: "auto",
|
||||||
|
minWidth: "30%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{props.shortcuts.map((shortcut, index) => (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
<ShortcutKey>{shortcut}</ShortcutKey>
|
||||||
|
{props.isOr &&
|
||||||
|
index !== props.shortcuts.length - 1 &&
|
||||||
|
t("helpDialog.or")}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Shortcut.defaultProps = {
|
||||||
|
isOr: true,
|
||||||
|
};
|
||||||
|
|
||||||
const ShortcutKey = (props: { children: React.ReactNode }) => (
|
const ShortcutKey = (props: { children: React.ReactNode }) => (
|
||||||
<kbd className="HelpDialog__key" {...props} />
|
<kbd className="HelpDialog--key" {...props} />
|
||||||
);
|
);
|
||||||
|
|
||||||
export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
||||||
@@ -114,276 +137,286 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
|||||||
>
|
>
|
||||||
<Header />
|
<Header />
|
||||||
<Section title={t("helpDialog.shortcuts")}>
|
<Section title={t("helpDialog.shortcuts")}>
|
||||||
<ShortcutIsland
|
<Columns>
|
||||||
className="HelpDialog__island--tools"
|
<Column>
|
||||||
caption={t("helpDialog.tools")}
|
<ShortcutIsland caption={t("helpDialog.tools")}>
|
||||||
>
|
<Shortcut
|
||||||
<Shortcut label={t("toolBar.selection")} shortcuts={["V", "1"]} />
|
label={t("toolBar.selection")}
|
||||||
<Shortcut label={t("toolBar.rectangle")} shortcuts={["R", "2"]} />
|
shortcuts={["V", "1"]}
|
||||||
<Shortcut label={t("toolBar.diamond")} shortcuts={["D", "3"]} />
|
/>
|
||||||
<Shortcut label={t("toolBar.ellipse")} shortcuts={["O", "4"]} />
|
<Shortcut
|
||||||
<Shortcut label={t("toolBar.arrow")} shortcuts={["A", "5"]} />
|
label={t("toolBar.rectangle")}
|
||||||
<Shortcut label={t("toolBar.line")} shortcuts={["P", "6"]} />
|
shortcuts={["R", "2"]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("toolBar.freedraw")}
|
<Shortcut label={t("toolBar.diamond")} shortcuts={["D", "3"]} />
|
||||||
shortcuts={["Shift + P", "X", "7"]}
|
<Shortcut label={t("toolBar.ellipse")} shortcuts={["O", "4"]} />
|
||||||
/>
|
<Shortcut label={t("toolBar.arrow")} shortcuts={["A", "5"]} />
|
||||||
<Shortcut label={t("toolBar.text")} shortcuts={["T", "8"]} />
|
<Shortcut label={t("toolBar.line")} shortcuts={["P", "6"]} />
|
||||||
<Shortcut label={t("toolBar.image")} shortcuts={["9"]} />
|
<Shortcut
|
||||||
<Shortcut label={t("toolBar.library")} shortcuts={["0"]} />
|
label={t("toolBar.freedraw")}
|
||||||
<Shortcut
|
shortcuts={["Shift + P", "X", "7"]}
|
||||||
label={t("toolBar.eraser")}
|
/>
|
||||||
shortcuts={[getShortcutKey("E")]}
|
<Shortcut label={t("toolBar.text")} shortcuts={["T", "8"]} />
|
||||||
/>
|
<Shortcut label={t("toolBar.image")} shortcuts={["9"]} />
|
||||||
<Shortcut
|
<Shortcut label={t("toolBar.library")} shortcuts={["0"]} />
|
||||||
label={t("helpDialog.editSelectedShape")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Enter"), t("helpDialog.doubleClick")]}
|
label={t("toolBar.eraser")}
|
||||||
/>
|
shortcuts={[getShortcutKey("E")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.textNewLine")}
|
<Shortcut
|
||||||
shortcuts={[
|
label={t("helpDialog.editSelectedShape")}
|
||||||
getShortcutKey("Enter"),
|
shortcuts={[
|
||||||
getShortcutKey("Shift+Enter"),
|
getShortcutKey("Enter"),
|
||||||
]}
|
t("helpDialog.doubleClick"),
|
||||||
/>
|
]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.textFinish")}
|
<Shortcut
|
||||||
shortcuts={[
|
label={t("helpDialog.textNewLine")}
|
||||||
getShortcutKey("Esc"),
|
shortcuts={[
|
||||||
getShortcutKey("CtrlOrCmd+Enter"),
|
getShortcutKey("Enter"),
|
||||||
]}
|
getShortcutKey("Shift+Enter"),
|
||||||
/>
|
]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.curvedArrow")}
|
<Shortcut
|
||||||
shortcuts={[
|
label={t("helpDialog.textFinish")}
|
||||||
"A",
|
shortcuts={[
|
||||||
t("helpDialog.click"),
|
getShortcutKey("Esc"),
|
||||||
t("helpDialog.click"),
|
getShortcutKey("CtrlOrCmd+Enter"),
|
||||||
t("helpDialog.click"),
|
]}
|
||||||
]}
|
/>
|
||||||
isOr={false}
|
<Shortcut
|
||||||
/>
|
label={t("helpDialog.curvedArrow")}
|
||||||
<Shortcut
|
shortcuts={[
|
||||||
label={t("helpDialog.curvedLine")}
|
"A",
|
||||||
shortcuts={[
|
t("helpDialog.click"),
|
||||||
"L",
|
t("helpDialog.click"),
|
||||||
t("helpDialog.click"),
|
t("helpDialog.click"),
|
||||||
t("helpDialog.click"),
|
]}
|
||||||
t("helpDialog.click"),
|
isOr={false}
|
||||||
]}
|
/>
|
||||||
isOr={false}
|
<Shortcut
|
||||||
/>
|
label={t("helpDialog.curvedLine")}
|
||||||
<Shortcut label={t("toolBar.lock")} shortcuts={["Q"]} />
|
shortcuts={[
|
||||||
<Shortcut
|
"L",
|
||||||
label={t("helpDialog.preventBinding")}
|
t("helpDialog.click"),
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd")]}
|
t("helpDialog.click"),
|
||||||
/>
|
t("helpDialog.click"),
|
||||||
<Shortcut
|
]}
|
||||||
label={t("toolBar.link")}
|
isOr={false}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+K")]}
|
/>
|
||||||
/>
|
<Shortcut label={t("toolBar.lock")} shortcuts={["Q"]} />
|
||||||
</ShortcutIsland>
|
<Shortcut
|
||||||
<ShortcutIsland
|
label={t("helpDialog.preventBinding")}
|
||||||
className="HelpDialog__island--view"
|
shortcuts={[getShortcutKey("CtrlOrCmd")]}
|
||||||
caption={t("helpDialog.view")}
|
/>
|
||||||
>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("toolBar.link")}
|
||||||
label={t("buttons.zoomIn")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+K")]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd++")]}
|
/>
|
||||||
/>
|
</ShortcutIsland>
|
||||||
<Shortcut
|
<ShortcutIsland caption={t("helpDialog.view")}>
|
||||||
label={t("buttons.zoomOut")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+-")]}
|
label={t("buttons.zoomIn")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd++")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("buttons.resetZoom")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+0")]}
|
label={t("buttons.zoomOut")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+-")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.zoomToFit")}
|
<Shortcut
|
||||||
shortcuts={["Shift+1"]}
|
label={t("buttons.resetZoom")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+0")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.zoomToSelection")}
|
<Shortcut
|
||||||
shortcuts={["Shift+2"]}
|
label={t("helpDialog.zoomToFit")}
|
||||||
/>
|
shortcuts={["Shift+1"]}
|
||||||
<Shortcut label={t("buttons.fullScreen")} shortcuts={["F"]} />
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("buttons.zenMode")}
|
label={t("helpDialog.zoomToSelection")}
|
||||||
shortcuts={[getShortcutKey("Alt+Z")]}
|
shortcuts={["Shift+2"]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut label={t("buttons.fullScreen")} shortcuts={["F"]} />
|
||||||
label={t("labels.showGrid")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
|
label={t("buttons.zenMode")}
|
||||||
/>
|
shortcuts={[getShortcutKey("Alt+Z")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("labels.viewMode")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Alt+R")]}
|
label={t("labels.showGrid")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("labels.toggleTheme")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Alt+Shift+D")]}
|
label={t("labels.viewMode")}
|
||||||
/>
|
shortcuts={[getShortcutKey("Alt+R")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("stats.title")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Alt+/")]}
|
label={t("labels.toggleTheme")}
|
||||||
/>
|
shortcuts={[getShortcutKey("Alt+Shift+D")]}
|
||||||
</ShortcutIsland>
|
/>
|
||||||
<ShortcutIsland
|
<Shortcut
|
||||||
className="HelpDialog__island--editor"
|
label={t("stats.title")}
|
||||||
caption={t("helpDialog.editor")}
|
shortcuts={[getShortcutKey("Alt+/")]}
|
||||||
>
|
/>
|
||||||
<Shortcut
|
</ShortcutIsland>
|
||||||
label={t("labels.selectAll")}
|
</Column>
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+A")]}
|
<Column>
|
||||||
/>
|
<ShortcutIsland caption={t("helpDialog.editor")}>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.multiSelect")}
|
label={t("labels.selectAll")}
|
||||||
shortcuts={[getShortcutKey(`Shift+${t("helpDialog.click")}`)]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+A")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("helpDialog.deepSelect")}
|
label={t("labels.multiSelect")}
|
||||||
shortcuts={[getShortcutKey(`CtrlOrCmd+${t("helpDialog.click")}`)]}
|
shortcuts={[getShortcutKey(`Shift+${t("helpDialog.click")}`)]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("helpDialog.deepBoxSelect")}
|
label={t("helpDialog.deepSelect")}
|
||||||
shortcuts={[getShortcutKey(`CtrlOrCmd+${t("helpDialog.drag")}`)]}
|
shortcuts={[
|
||||||
/>
|
getShortcutKey(`CtrlOrCmd+${t("helpDialog.click")}`),
|
||||||
<Shortcut
|
]}
|
||||||
label={t("labels.moveCanvas")}
|
/>
|
||||||
shortcuts={[
|
<Shortcut
|
||||||
getShortcutKey(`Space+${t("helpDialog.drag")}`),
|
label={t("helpDialog.deepBoxSelect")}
|
||||||
getShortcutKey(`Wheel+${t("helpDialog.drag")}`),
|
shortcuts={[
|
||||||
]}
|
getShortcutKey(`CtrlOrCmd+${t("helpDialog.drag")}`),
|
||||||
isOr={true}
|
]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.cut")}
|
label={t("labels.moveCanvas")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+X")]}
|
shortcuts={[
|
||||||
/>
|
getShortcutKey(`Space+${t("helpDialog.drag")}`),
|
||||||
<Shortcut
|
getShortcutKey(`Wheel+${t("helpDialog.drag")}`),
|
||||||
label={t("labels.copy")}
|
]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+C")]}
|
isOr={true}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.paste")}
|
label={t("labels.cut")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+V")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+X")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.copyAsPng")}
|
label={t("labels.copy")}
|
||||||
shortcuts={[getShortcutKey("Shift+Alt+C")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+C")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.copyStyles")}
|
label={t("labels.paste")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+C")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+V")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.pasteStyles")}
|
label={t("labels.copyAsPng")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+V")]}
|
shortcuts={[getShortcutKey("Shift+Alt+C")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.delete")}
|
label={t("labels.copyStyles")}
|
||||||
shortcuts={[getShortcutKey("Del")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+C")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.sendToBack")}
|
label={t("labels.pasteStyles")}
|
||||||
shortcuts={[
|
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+V")]}
|
||||||
isDarwin
|
/>
|
||||||
? getShortcutKey("CtrlOrCmd+Alt+[")
|
<Shortcut
|
||||||
: getShortcutKey("CtrlOrCmd+Shift+["),
|
label={t("labels.delete")}
|
||||||
]}
|
shortcuts={[getShortcutKey("Del")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.bringToFront")}
|
label={t("labels.sendToBack")}
|
||||||
shortcuts={[
|
shortcuts={[
|
||||||
isDarwin
|
isDarwin
|
||||||
? getShortcutKey("CtrlOrCmd+Alt+]")
|
? getShortcutKey("CtrlOrCmd+Alt+[")
|
||||||
: getShortcutKey("CtrlOrCmd+Shift+]"),
|
: getShortcutKey("CtrlOrCmd+Shift+["),
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.sendBackward")}
|
label={t("labels.bringToFront")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+[")]}
|
shortcuts={[
|
||||||
/>
|
isDarwin
|
||||||
<Shortcut
|
? getShortcutKey("CtrlOrCmd+Alt+]")
|
||||||
label={t("labels.bringForward")}
|
: getShortcutKey("CtrlOrCmd+Shift+]"),
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+]")]}
|
]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.alignTop")}
|
label={t("labels.sendBackward")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Up")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+[")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.alignBottom")}
|
label={t("labels.bringForward")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Down")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+]")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.alignLeft")}
|
label={t("labels.alignTop")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Left")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Up")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.alignRight")}
|
label={t("labels.alignBottom")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Right")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Down")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.duplicateSelection")}
|
label={t("labels.alignLeft")}
|
||||||
shortcuts={[
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Left")]}
|
||||||
getShortcutKey("CtrlOrCmd+D"),
|
/>
|
||||||
getShortcutKey(`Alt+${t("helpDialog.drag")}`),
|
<Shortcut
|
||||||
]}
|
label={t("labels.alignRight")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Right")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.toggleElementLock")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+L")]}
|
label={t("labels.duplicateSelection")}
|
||||||
/>
|
shortcuts={[
|
||||||
<Shortcut
|
getShortcutKey("CtrlOrCmd+D"),
|
||||||
label={t("buttons.undo")}
|
getShortcutKey(`Alt+${t("helpDialog.drag")}`),
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Z")]}
|
]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("buttons.redo")}
|
label={t("helpDialog.toggleElementLock")}
|
||||||
shortcuts={
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+L")]}
|
||||||
isWindows
|
/>
|
||||||
? [
|
<Shortcut
|
||||||
getShortcutKey("CtrlOrCmd+Y"),
|
label={t("buttons.undo")}
|
||||||
getShortcutKey("CtrlOrCmd+Shift+Z"),
|
shortcuts={[getShortcutKey("CtrlOrCmd+Z")]}
|
||||||
]
|
/>
|
||||||
: [getShortcutKey("CtrlOrCmd+Shift+Z")]
|
<Shortcut
|
||||||
}
|
label={t("buttons.redo")}
|
||||||
/>
|
shortcuts={
|
||||||
<Shortcut
|
isWindows
|
||||||
label={t("labels.group")}
|
? [
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+G")]}
|
getShortcutKey("CtrlOrCmd+Y"),
|
||||||
/>
|
getShortcutKey("CtrlOrCmd+Shift+Z"),
|
||||||
<Shortcut
|
]
|
||||||
label={t("labels.ungroup")}
|
: [getShortcutKey("CtrlOrCmd+Shift+Z")]
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+G")]}
|
}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.flipHorizontal")}
|
label={t("labels.group")}
|
||||||
shortcuts={[getShortcutKey("Shift+H")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+G")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.flipVertical")}
|
label={t("labels.ungroup")}
|
||||||
shortcuts={[getShortcutKey("Shift+V")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+G")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.showStroke")}
|
label={t("labels.flipHorizontal")}
|
||||||
shortcuts={[getShortcutKey("S")]}
|
shortcuts={[getShortcutKey("Shift+H")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.showBackground")}
|
label={t("labels.flipVertical")}
|
||||||
shortcuts={[getShortcutKey("G")]}
|
shortcuts={[getShortcutKey("Shift+V")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.decreaseFontSize")}
|
label={t("labels.showStroke")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+<")]}
|
shortcuts={[getShortcutKey("S")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.increaseFontSize")}
|
label={t("labels.showBackground")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+>")]}
|
shortcuts={[getShortcutKey("G")]}
|
||||||
/>
|
/>
|
||||||
</ShortcutIsland>
|
<Shortcut
|
||||||
|
label={t("labels.decreaseFontSize")}
|
||||||
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+<")]}
|
||||||
|
/>
|
||||||
|
<Shortcut
|
||||||
|
label={t("labels.increaseFontSize")}
|
||||||
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+>")]}
|
||||||
|
/>
|
||||||
|
</ShortcutIsland>
|
||||||
|
</Column>
|
||||||
|
</Columns>
|
||||||
</Section>
|
</Section>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { HelpIcon } from "./icons";
|
import { questionCircle } from "../components/icons";
|
||||||
|
|
||||||
type HelpButtonProps = {
|
type HelpIconProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
id?: string;
|
id?: string;
|
||||||
onClick?(): void;
|
onClick?(): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const HelpButton = (props: HelpButtonProps) => (
|
export const HelpIcon = (props: HelpIconProps) => (
|
||||||
<button
|
<button
|
||||||
className="help-icon"
|
className="help-icon"
|
||||||
onClick={props.onClick}
|
onClick={props.onClick}
|
||||||
@@ -15,6 +15,6 @@ export const HelpButton = (props: HelpButtonProps) => (
|
|||||||
title={`${props.title} — ?`}
|
title={`${props.title} — ?`}
|
||||||
aria-label={props.title}
|
aria-label={props.title}
|
||||||
>
|
>
|
||||||
{HelpIcon}
|
{questionCircle}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
@@ -14,24 +14,20 @@ $wide-viewport-width: 1000px;
|
|||||||
top: 100%;
|
top: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 0.5rem;
|
margin-top: 6px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: var(--color-gray-40);
|
color: $oc-gray-6;
|
||||||
font-size: 0.75rem;
|
font-size: 0.8rem;
|
||||||
|
|
||||||
@include isMobile {
|
@include isMobile {
|
||||||
position: static;
|
position: static;
|
||||||
padding-right: 2rem;
|
padding-right: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
> span {
|
> span {
|
||||||
padding: 0.25rem;
|
padding: 0.2rem 0.4rem;
|
||||||
}
|
background-color: var(--overlay-bg-color);
|
||||||
}
|
border-radius: 4px;
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
.HintViewer {
|
|
||||||
color: var(--color-gray-60);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { NonDeletedExcalidrawElement } from "../element/types";
|
|||||||
import { getSelectedElements } from "../scene";
|
import { getSelectedElements } from "../scene";
|
||||||
|
|
||||||
import "./HintViewer.scss";
|
import "./HintViewer.scss";
|
||||||
import { AppState, Device } from "../types";
|
import { AppState } from "../types";
|
||||||
import {
|
import {
|
||||||
isImageElement,
|
isImageElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
@@ -17,19 +17,13 @@ interface HintViewerProps {
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
device: Device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getHints = ({
|
const getHints = ({ appState, elements, isMobile }: HintViewerProps) => {
|
||||||
appState,
|
|
||||||
elements,
|
|
||||||
isMobile,
|
|
||||||
device,
|
|
||||||
}: HintViewerProps) => {
|
|
||||||
const { activeTool, isResizing, isRotating, lastPointerDownWith } = appState;
|
const { activeTool, isResizing, isRotating, lastPointerDownWith } = appState;
|
||||||
const multiMode = appState.multiElement !== null;
|
const multiMode = appState.multiElement !== null;
|
||||||
|
|
||||||
if (appState.openSidebar === "library" && !device.canDeviceFitSidebar) {
|
if (appState.isLibraryOpen) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,13 +111,11 @@ export const HintViewer = ({
|
|||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
isMobile,
|
isMobile,
|
||||||
device,
|
|
||||||
}: HintViewerProps) => {
|
}: HintViewerProps) => {
|
||||||
let hint = getHints({
|
let hint = getHints({
|
||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
isMobile,
|
isMobile,
|
||||||
device,
|
|
||||||
});
|
});
|
||||||
if (!hint) {
|
if (!hint) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -10,8 +10,7 @@
|
|||||||
.picker {
|
.picker {
|
||||||
background: var(--popup-bg-color);
|
background: var(--popup-bg-color);
|
||||||
border: 0 solid transparentize($oc-white, 0.75);
|
border: 0 solid transparentize($oc-white, 0.75);
|
||||||
// ˇˇ yeah, i dunno, open to suggestions here :D
|
box-shadow: transparentize($oc-black, 0.75) 0 1px 4px;
|
||||||
box-shadow: rgb(0 0 0 / 25%) 2px 2px 4px 2px;
|
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
@@ -47,6 +46,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
width: 36px;
|
width: 36px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
|
opacity: 0.6;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { Popover } from "./Popover";
|
|||||||
import "./IconPicker.scss";
|
import "./IconPicker.scss";
|
||||||
import { isArrowKey, KEYS } from "../keys";
|
import { isArrowKey, KEYS } from "../keys";
|
||||||
import { getLanguage } from "../i18n";
|
import { getLanguage } from "../i18n";
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
function Picker<T>({
|
function Picker<T>({
|
||||||
options,
|
options,
|
||||||
@@ -103,9 +102,7 @@ function Picker<T>({
|
|||||||
<div className="picker-content" ref={rGallery}>
|
<div className="picker-content" ref={rGallery}>
|
||||||
{options.map((option, i) => (
|
{options.map((option, i) => (
|
||||||
<button
|
<button
|
||||||
className={clsx("picker-option", {
|
className="picker-option"
|
||||||
active: value === option.value,
|
|
||||||
})}
|
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
(event.currentTarget as HTMLButtonElement).focus();
|
(event.currentTarget as HTMLButtonElement).focus();
|
||||||
onChange(option.value);
|
onChange(option.value);
|
||||||
@@ -153,7 +150,7 @@ export function IconPicker<T>({
|
|||||||
const isRTL = getLanguage().rtl;
|
const isRTL = getLanguage().rtl;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<label className={"picker-container"}>
|
||||||
<button
|
<button
|
||||||
name={group}
|
name={group}
|
||||||
className={isActive ? "active" : ""}
|
className={isActive ? "active" : ""}
|
||||||
@@ -187,6 +184,6 @@ export function IconPicker<T>({
|
|||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</div>
|
</label>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ import { canvasToBlob } from "../data/blob";
|
|||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
import { CanvasError } from "../errors";
|
import { CanvasError } from "../errors";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
import { useDevice } from "./App";
|
||||||
import { getSelectedElements, isSomeElementSelected } from "../scene";
|
import { getSelectedElements, isSomeElementSelected } from "../scene";
|
||||||
import { exportToCanvas } from "../scene/export";
|
import { exportToCanvas } from "../scene/export";
|
||||||
import { AppState, BinaryFiles } from "../types";
|
import { AppState, BinaryFiles } from "../types";
|
||||||
import { Dialog } from "./Dialog";
|
import { Dialog } from "./Dialog";
|
||||||
import { clipboard } from "./icons";
|
import { clipboard, exportImage } from "./icons";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
import "./ExportDialog.scss";
|
import "./ExportDialog.scss";
|
||||||
import OpenColor from "open-color";
|
import OpenColor from "open-color";
|
||||||
import { CheckboxItem } from "./CheckboxItem";
|
import { CheckboxItem } from "./CheckboxItem";
|
||||||
@@ -79,6 +81,7 @@ const ImageExportModal = ({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
files,
|
files,
|
||||||
|
exportPadding = DEFAULT_EXPORT_PADDING,
|
||||||
actionManager,
|
actionManager,
|
||||||
onExportToPng,
|
onExportToPng,
|
||||||
onExportToSvg,
|
onExportToSvg,
|
||||||
@@ -87,6 +90,7 @@ const ImageExportModal = ({
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
files: BinaryFiles;
|
files: BinaryFiles;
|
||||||
|
exportPadding?: number;
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
onExportToPng: ExportCB;
|
onExportToPng: ExportCB;
|
||||||
onExportToSvg: ExportCB;
|
onExportToSvg: ExportCB;
|
||||||
@@ -114,7 +118,7 @@ const ImageExportModal = ({
|
|||||||
exportToCanvas(exportedElements, appState, files, {
|
exportToCanvas(exportedElements, appState, files, {
|
||||||
exportBackground,
|
exportBackground,
|
||||||
viewBackgroundColor,
|
viewBackgroundColor,
|
||||||
exportPadding: appState.exportPadding,
|
exportPadding,
|
||||||
})
|
})
|
||||||
.then((canvas) => {
|
.then((canvas) => {
|
||||||
// if converting to blob fails, there's some problem that will
|
// if converting to blob fails, there's some problem that will
|
||||||
@@ -132,6 +136,7 @@ const ImageExportModal = ({
|
|||||||
files,
|
files,
|
||||||
exportedElements,
|
exportedElements,
|
||||||
exportBackground,
|
exportBackground,
|
||||||
|
exportPadding,
|
||||||
viewBackgroundColor,
|
viewBackgroundColor,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -148,10 +153,8 @@ const ImageExportModal = ({
|
|||||||
// dunno why this is needed, but when the items wrap it creates
|
// dunno why this is needed, but when the items wrap it creates
|
||||||
// an overflow
|
// an overflow
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
gap: ".6rem",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{actionManager.renderAction("changeExportPadding")}
|
|
||||||
{actionManager.renderAction("changeExportBackground")}
|
{actionManager.renderAction("changeExportBackground")}
|
||||||
{someElementIsSelected && (
|
{someElementIsSelected && (
|
||||||
<CheckboxItem
|
<CheckboxItem
|
||||||
@@ -218,34 +221,48 @@ const ImageExportModal = ({
|
|||||||
export const ImageExportDialog = ({
|
export const ImageExportDialog = ({
|
||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
setAppState,
|
|
||||||
files,
|
files,
|
||||||
|
exportPadding = DEFAULT_EXPORT_PADDING,
|
||||||
actionManager,
|
actionManager,
|
||||||
onExportToPng,
|
onExportToPng,
|
||||||
onExportToSvg,
|
onExportToSvg,
|
||||||
onExportToClipboard,
|
onExportToClipboard,
|
||||||
}: {
|
}: {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
setAppState: React.Component<any, AppState>["setState"];
|
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
files: BinaryFiles;
|
files: BinaryFiles;
|
||||||
|
exportPadding?: number;
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
onExportToPng: ExportCB;
|
onExportToPng: ExportCB;
|
||||||
onExportToSvg: ExportCB;
|
onExportToSvg: ExportCB;
|
||||||
onExportToClipboard: ExportCB;
|
onExportToClipboard: ExportCB;
|
||||||
}) => {
|
}) => {
|
||||||
|
const [modalIsShown, setModalIsShown] = useState(false);
|
||||||
|
|
||||||
const handleClose = React.useCallback(() => {
|
const handleClose = React.useCallback(() => {
|
||||||
setAppState({ openDialog: null });
|
setModalIsShown(false);
|
||||||
}, [setAppState]);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{appState.openDialog === "imageExport" && (
|
<ToolButton
|
||||||
|
onClick={() => {
|
||||||
|
setModalIsShown(true);
|
||||||
|
}}
|
||||||
|
data-testid="image-export-button"
|
||||||
|
icon={exportImage}
|
||||||
|
type="button"
|
||||||
|
aria-label={t("buttons.exportImage")}
|
||||||
|
showAriaLabel={useDevice().isMobile}
|
||||||
|
title={t("buttons.exportImage")}
|
||||||
|
/>
|
||||||
|
{modalIsShown && (
|
||||||
<Dialog onCloseRequest={handleClose} title={t("buttons.exportImage")}>
|
<Dialog onCloseRequest={handleClose} title={t("buttons.exportImage")}>
|
||||||
<ImageExportModal
|
<ImageExportModal
|
||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
files={files}
|
files={files}
|
||||||
|
exportPadding={exportPadding}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
onExportToPng={onExportToPng}
|
onExportToPng={onExportToPng}
|
||||||
onExportToSvg={onExportToSvg}
|
onExportToSvg={onExportToSvg}
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ import React, { useEffect, useState } from "react";
|
|||||||
|
|
||||||
import { LoadingMessage } from "./LoadingMessage";
|
import { LoadingMessage } from "./LoadingMessage";
|
||||||
import { defaultLang, Language, languages, setLanguage } from "../i18n";
|
import { defaultLang, Language, languages, setLanguage } from "../i18n";
|
||||||
import { Theme } from "../element/types";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
langCode: Language["code"];
|
langCode: Language["code"];
|
||||||
children: React.ReactElement;
|
children: React.ReactElement;
|
||||||
theme?: Theme;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InitializeApp = (props: Props) => {
|
export const InitializeApp = (props: Props) => {
|
||||||
@@ -23,5 +21,5 @@ export const InitializeApp = (props: Props) => {
|
|||||||
updateLang();
|
updateLang();
|
||||||
}, [props.langCode]);
|
}, [props.langCode]);
|
||||||
|
|
||||||
return loading ? <LoadingMessage theme={props.theme} /> : props.children;
|
return loading ? <LoadingMessage /> : props.children;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
.excalidraw {
|
.excalidraw {
|
||||||
.Island {
|
.Island {
|
||||||
--padding: 0;
|
--padding: 0;
|
||||||
box-sizing: border-box;
|
|
||||||
background-color: var(--island-bg-color);
|
background-color: var(--island-bg-color);
|
||||||
box-shadow: var(--shadow-island);
|
box-shadow: var(--shadow-island);
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
import { useDevice } from "./App";
|
||||||
import { AppState, ExportOpts, BinaryFiles } from "../types";
|
import { AppState, ExportOpts, BinaryFiles } from "../types";
|
||||||
import { Dialog } from "./Dialog";
|
import { Dialog } from "./Dialog";
|
||||||
import { ExportIcon, exportToFileIcon, LinkIcon } from "./icons";
|
import { exportFile, exportToFileIcon, link } from "./icons";
|
||||||
import { ToolButton } from "./ToolButton";
|
import { ToolButton } from "./ToolButton";
|
||||||
import { actionSaveFileToDisk } from "../actions/actionExport";
|
import { actionSaveFileToDisk } from "../actions/actionExport";
|
||||||
import { Card } from "./Card";
|
import { Card } from "./Card";
|
||||||
@@ -14,7 +14,6 @@ import { nativeFileSystemSupported } from "../data/filesystem";
|
|||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { getFrame } from "../utils";
|
import { getFrame } from "../utils";
|
||||||
import MenuItem from "./MenuItem";
|
|
||||||
|
|
||||||
export type ExportCB = (
|
export type ExportCB = (
|
||||||
elements: readonly NonDeletedExcalidrawElement[],
|
elements: readonly NonDeletedExcalidrawElement[],
|
||||||
@@ -64,7 +63,7 @@ const JSONExportModal = ({
|
|||||||
)}
|
)}
|
||||||
{onExportToBackend && (
|
{onExportToBackend && (
|
||||||
<Card color="pink">
|
<Card color="pink">
|
||||||
<div className="Card-icon">{LinkIcon}</div>
|
<div className="Card-icon">{link}</div>
|
||||||
<h2>{t("exportDialog.link_title")}</h2>
|
<h2>{t("exportDialog.link_title")}</h2>
|
||||||
<div className="Card-details">{t("exportDialog.link_details")}</div>
|
<div className="Card-details">{t("exportDialog.link_details")}</div>
|
||||||
<ToolButton
|
<ToolButton
|
||||||
@@ -110,13 +109,16 @@ export const JSONExportDialog = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<MenuItem
|
<ToolButton
|
||||||
icon={ExportIcon}
|
|
||||||
label={t("buttons.export")}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setModalIsShown(true);
|
setModalIsShown(true);
|
||||||
}}
|
}}
|
||||||
dataTestId="json-export-button"
|
data-testid="json-export-button"
|
||||||
|
icon={exportFile}
|
||||||
|
type="button"
|
||||||
|
aria-label={t("buttons.export")}
|
||||||
|
showAriaLabel={useDevice().isMobile}
|
||||||
|
title={t("buttons.export")}
|
||||||
/>
|
/>
|
||||||
{modalIsShown && (
|
{modalIsShown && (
|
||||||
<Dialog onCloseRequest={handleClose} title={t("buttons.export")}>
|
<Dialog onCloseRequest={handleClose} title={t("buttons.export")}>
|
||||||
|
|||||||
@@ -1,6 +1,48 @@
|
|||||||
@import "open-color/open-color";
|
@import "open-color/open-color";
|
||||||
@import "../css/variables.module";
|
@import "../css/variables.module";
|
||||||
|
|
||||||
|
.layer-ui__sidebar {
|
||||||
|
position: absolute;
|
||||||
|
top: var(--sat);
|
||||||
|
bottom: var(--sab);
|
||||||
|
right: var(--sar);
|
||||||
|
z-index: 5;
|
||||||
|
|
||||||
|
box-shadow: var(--shadow-island);
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: var(--border-radius-lg);
|
||||||
|
margin: var(--space-factor);
|
||||||
|
width: calc(#{$right-sidebar-width} - var(--space-factor) * 2);
|
||||||
|
|
||||||
|
.Island {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ToolIcon__icon {
|
||||||
|
border-radius: var(--border-radius-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ToolIcon__icon__close {
|
||||||
|
.Modal__close {
|
||||||
|
width: calc(var(--space-factor) * 7);
|
||||||
|
height: calc(var(--space-factor) * 7);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
color: var(--color-text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.Island {
|
||||||
|
--padding: 0;
|
||||||
|
background-color: var(--island-bg-color);
|
||||||
|
border-radius: var(--border-radius-lg);
|
||||||
|
padding: calc(var(--padding) * var(--space-factor));
|
||||||
|
position: relative;
|
||||||
|
transition: box-shadow 0.5s ease-in-out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.layer-ui__wrapper.animate {
|
.layer-ui__wrapper.animate {
|
||||||
transition: width 0.1s ease-in-out;
|
transition: width 0.1s ease-in-out;
|
||||||
@@ -16,10 +58,8 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: var(--zIndex-layerUI);
|
z-index: var(--zIndex-layerUI);
|
||||||
|
|
||||||
&__top-right {
|
&__top-right {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.75rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__footer {
|
&__footer {
|
||||||
@@ -50,6 +90,13 @@
|
|||||||
transform: translate(-999px, 0);
|
transform: translate(-999px, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:root[dir="ltr"] &.layer-ui__wrapper__footer-left--transition-left {
|
||||||
|
transform: translate(-76px, 0);
|
||||||
|
}
|
||||||
|
:root[dir="rtl"] &.layer-ui__wrapper__footer-left--transition-left {
|
||||||
|
transform: translate(76px, 0);
|
||||||
|
}
|
||||||
|
|
||||||
&.layer-ui__wrapper__footer-left--transition-bottom {
|
&.layer-ui__wrapper__footer-left--transition-bottom {
|
||||||
transform: translate(0, 92px);
|
transform: translate(0, 92px);
|
||||||
}
|
}
|
||||||
@@ -92,9 +139,14 @@
|
|||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.layer-ui__wrapper__footer-left {
|
||||||
|
margin-bottom: 0.2em;
|
||||||
|
}
|
||||||
|
|
||||||
.layer-ui__wrapper__footer-right {
|
.layer-ui__wrapper__footer-right {
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
margin-bottom: auto;
|
margin-bottom: auto;
|
||||||
|
margin-inline-end: 1em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+333
-294
@@ -1,16 +1,17 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React from "react";
|
import React, { useCallback } from "react";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { CLASSES, LIBRARY_SIDEBAR_WIDTH } from "../constants";
|
import { CLASSES, LIBRARY_SIDEBAR_WIDTH } from "../constants";
|
||||||
import { exportCanvas } from "../data";
|
import { exportCanvas } from "../data";
|
||||||
import { isTextElement, showSelectedShapeActions } from "../element";
|
import { isTextElement, showSelectedShapeActions } from "../element";
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
import { Language, t } from "../i18n";
|
import { Language, t } from "../i18n";
|
||||||
import { calculateScrollCenter } from "../scene";
|
import { calculateScrollCenter, getSelectedElements } from "../scene";
|
||||||
import { ExportType } from "../scene/types";
|
import { ExportType } from "../scene/types";
|
||||||
import { AppProps, AppState, ExcalidrawProps, BinaryFiles } from "../types";
|
import { AppProps, AppState, ExcalidrawProps, BinaryFiles } from "../types";
|
||||||
import { muteFSAbortError } from "../utils";
|
import { muteFSAbortError } from "../utils";
|
||||||
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
import { SelectedShapeActions, ShapesSwitcher, ZoomActions } from "./Actions";
|
||||||
|
import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";
|
||||||
import CollabButton from "./CollabButton";
|
import CollabButton from "./CollabButton";
|
||||||
import { ErrorDialog } from "./ErrorDialog";
|
import { ErrorDialog } from "./ErrorDialog";
|
||||||
import { ExportCB, ImageExportDialog } from "./ImageExportDialog";
|
import { ExportCB, ImageExportDialog } from "./ImageExportDialog";
|
||||||
@@ -25,7 +26,7 @@ import { Section } from "./Section";
|
|||||||
import { HelpDialog } from "./HelpDialog";
|
import { HelpDialog } from "./HelpDialog";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
import { UserList } from "./UserList";
|
import { UserList } from "./UserList";
|
||||||
import Library from "../data/library";
|
import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
||||||
import { JSONExportDialog } from "./JSONExportDialog";
|
import { JSONExportDialog } from "./JSONExportDialog";
|
||||||
import { LibraryButton } from "./LibraryButton";
|
import { LibraryButton } from "./LibraryButton";
|
||||||
import { isImageFileHandle } from "../data/blob";
|
import { isImageFileHandle } from "../data/blob";
|
||||||
@@ -35,26 +36,10 @@ import "./LayerUI.scss";
|
|||||||
import "./Toolbar.scss";
|
import "./Toolbar.scss";
|
||||||
import { PenModeButton } from "./PenModeButton";
|
import { PenModeButton } from "./PenModeButton";
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import { isMenuOpenAtom, useDevice } from "../components/App";
|
import { useDevice } from "../components/App";
|
||||||
import { Stats } from "./Stats";
|
import { Stats } from "./Stats";
|
||||||
import { actionToggleStats } from "../actions/actionToggleStats";
|
import { actionToggleStats } from "../actions/actionToggleStats";
|
||||||
import Footer from "./Footer";
|
import { actionToggleZenMode } from "../actions";
|
||||||
import {
|
|
||||||
ExportImageIcon,
|
|
||||||
HamburgerMenuIcon,
|
|
||||||
WelcomeScreenMenuArrow,
|
|
||||||
WelcomeScreenTopToolbarArrow,
|
|
||||||
} from "./icons";
|
|
||||||
import { MenuLinks, Separator } from "./MenuUtils";
|
|
||||||
import { useOutsideClickHook } from "../hooks/useOutsideClick";
|
|
||||||
import WelcomeScreen from "./WelcomeScreen";
|
|
||||||
import { hostSidebarCountersAtom } from "./Sidebar/Sidebar";
|
|
||||||
import { jotaiScope } from "../jotai";
|
|
||||||
import { useAtom } from "jotai";
|
|
||||||
import { LanguageList } from "../excalidraw-app/components/LanguageList";
|
|
||||||
import WelcomeScreenDecor from "./WelcomeScreenDecor";
|
|
||||||
import { getShortcutFromShortcutName } from "../actions/shortcuts";
|
|
||||||
import MenuItem from "./MenuItem";
|
|
||||||
|
|
||||||
interface LayerUIProps {
|
interface LayerUIProps {
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
@@ -68,44 +53,42 @@ interface LayerUIProps {
|
|||||||
onPenModeToggle: () => void;
|
onPenModeToggle: () => void;
|
||||||
onInsertElements: (elements: readonly NonDeletedExcalidrawElement[]) => void;
|
onInsertElements: (elements: readonly NonDeletedExcalidrawElement[]) => void;
|
||||||
showExitZenModeBtn: boolean;
|
showExitZenModeBtn: boolean;
|
||||||
|
showThemeBtn: boolean;
|
||||||
langCode: Language["code"];
|
langCode: Language["code"];
|
||||||
isCollaborating: boolean;
|
isCollaborating: boolean;
|
||||||
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
||||||
renderCustomFooter?: ExcalidrawProps["renderFooter"];
|
renderCustomFooter?: ExcalidrawProps["renderFooter"];
|
||||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
||||||
renderCustomSidebar?: ExcalidrawProps["renderSidebar"];
|
|
||||||
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
||||||
UIOptions: AppProps["UIOptions"];
|
UIOptions: AppProps["UIOptions"];
|
||||||
focusContainer: () => void;
|
focusContainer: () => void;
|
||||||
library: Library;
|
library: Library;
|
||||||
id: string;
|
id: string;
|
||||||
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
||||||
renderWelcomeScreen: boolean;
|
|
||||||
}
|
}
|
||||||
const LayerUI = ({
|
const LayerUI = ({
|
||||||
actionManager,
|
actionManager,
|
||||||
appState,
|
appState,
|
||||||
files,
|
files,
|
||||||
setAppState,
|
setAppState,
|
||||||
elements,
|
|
||||||
canvas,
|
canvas,
|
||||||
|
elements,
|
||||||
onCollabButtonClick,
|
onCollabButtonClick,
|
||||||
onLockToggle,
|
onLockToggle,
|
||||||
onPenModeToggle,
|
onPenModeToggle,
|
||||||
onInsertElements,
|
onInsertElements,
|
||||||
showExitZenModeBtn,
|
showExitZenModeBtn,
|
||||||
|
showThemeBtn,
|
||||||
isCollaborating,
|
isCollaborating,
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomFooter,
|
renderCustomFooter,
|
||||||
renderCustomStats,
|
renderCustomStats,
|
||||||
renderCustomSidebar,
|
|
||||||
libraryReturnUrl,
|
libraryReturnUrl,
|
||||||
UIOptions,
|
UIOptions,
|
||||||
focusContainer,
|
focusContainer,
|
||||||
library,
|
library,
|
||||||
id,
|
id,
|
||||||
onImageAction,
|
onImageAction,
|
||||||
renderWelcomeScreen,
|
|
||||||
}: LayerUIProps) => {
|
}: LayerUIProps) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
|
|
||||||
@@ -144,7 +127,6 @@ const LayerUI = ({
|
|||||||
exportBackground: appState.exportBackground,
|
exportBackground: appState.exportBackground,
|
||||||
name: appState.name,
|
name: appState.name,
|
||||||
viewBackgroundColor: appState.viewBackgroundColor,
|
viewBackgroundColor: appState.viewBackgroundColor,
|
||||||
exportPadding: appState.exportPadding,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.catch(muteFSAbortError)
|
.catch(muteFSAbortError)
|
||||||
@@ -166,7 +148,6 @@ const LayerUI = ({
|
|||||||
<ImageExportDialog
|
<ImageExportDialog
|
||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
setAppState={setAppState}
|
|
||||||
files={files}
|
files={files}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
onExportToPng={createExporter("png")}
|
onExportToPng={createExporter("png")}
|
||||||
@@ -176,104 +157,76 @@ const LayerUI = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [isMenuOpen, setIsMenuOpen] = useAtom(isMenuOpenAtom);
|
const Separator = () => {
|
||||||
const menuRef = useOutsideClickHook(() => setIsMenuOpen(false));
|
return <div style={{ width: ".625em" }} />;
|
||||||
|
};
|
||||||
|
|
||||||
const renderCanvasActions = () => (
|
const renderViewModeCanvasActions = () => {
|
||||||
<div style={{ position: "relative" }}>
|
return (
|
||||||
<WelcomeScreenDecor
|
<Section
|
||||||
shouldRender={renderWelcomeScreen && !appState.isLoading}
|
heading="canvasActions"
|
||||||
>
|
className={clsx("zen-mode-transition", {
|
||||||
<div className="virgil WelcomeScreen-decor WelcomeScreen-decor--menu-pointer">
|
|
||||||
{WelcomeScreenMenuArrow}
|
|
||||||
<div>{t("welcomeScreen.menuHints")}</div>
|
|
||||||
</div>
|
|
||||||
</WelcomeScreenDecor>
|
|
||||||
|
|
||||||
<button
|
|
||||||
data-prevent-outside-click
|
|
||||||
className={clsx("menu-button", "zen-mode-transition", {
|
|
||||||
"transition-left": appState.zenModeEnabled,
|
"transition-left": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
onClick={() => setIsMenuOpen(!isMenuOpen)}
|
|
||||||
type="button"
|
|
||||||
>
|
>
|
||||||
{HamburgerMenuIcon}
|
{/* the zIndex ensures this menu has higher stacking order,
|
||||||
</button>
|
|
||||||
|
|
||||||
{isMenuOpen && (
|
|
||||||
<div
|
|
||||||
ref={menuRef}
|
|
||||||
style={{ position: "absolute", top: "100%", marginTop: ".25rem" }}
|
|
||||||
>
|
|
||||||
<Section heading="canvasActions">
|
|
||||||
{/* the zIndex ensures this menu has higher stacking order,
|
|
||||||
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
||||||
<Island
|
<Island padding={2} style={{ zIndex: 1 }}>
|
||||||
className="menu-container"
|
<Stack.Col gap={4}>
|
||||||
padding={2}
|
<Stack.Row gap={1} justifyContent="space-between">
|
||||||
style={{ zIndex: 1 }}
|
|
||||||
>
|
|
||||||
{!appState.viewModeEnabled &&
|
|
||||||
actionManager.renderAction("loadScene")}
|
|
||||||
{/* // TODO barnabasmolnar/editor-redesign */}
|
|
||||||
{/* is this fine here? */}
|
|
||||||
{appState.fileHandle &&
|
|
||||||
actionManager.renderAction("saveToActiveFile")}
|
|
||||||
{renderJSONExportDialog()}
|
{renderJSONExportDialog()}
|
||||||
<MenuItem
|
{renderImageExportDialog()}
|
||||||
label={t("buttons.exportImage")}
|
</Stack.Row>
|
||||||
icon={ExportImageIcon}
|
</Stack.Col>
|
||||||
dataTestId="image-export-button"
|
</Island>
|
||||||
onClick={() => setAppState({ openDialog: "imageExport" })}
|
</Section>
|
||||||
shortcut={getShortcutFromShortcutName("imageExport")}
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderCanvasActions = () => (
|
||||||
|
<Section
|
||||||
|
heading="canvasActions"
|
||||||
|
className={clsx("zen-mode-transition", {
|
||||||
|
"transition-left": appState.zenModeEnabled,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{/* the zIndex ensures this menu has higher stacking order,
|
||||||
|
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
||||||
|
<Island padding={2} style={{ zIndex: 1 }}>
|
||||||
|
<Stack.Col gap={4}>
|
||||||
|
<Stack.Row gap={1} justifyContent="space-between">
|
||||||
|
{actionManager.renderAction("clearCanvas")}
|
||||||
|
<Separator />
|
||||||
|
{actionManager.renderAction("loadScene")}
|
||||||
|
{renderJSONExportDialog()}
|
||||||
|
{renderImageExportDialog()}
|
||||||
|
<Separator />
|
||||||
|
{onCollabButtonClick && (
|
||||||
|
<CollabButton
|
||||||
|
isCollaborating={isCollaborating}
|
||||||
|
collaboratorCount={appState.collaborators.size}
|
||||||
|
onClick={onCollabButtonClick}
|
||||||
/>
|
/>
|
||||||
{onCollabButtonClick && (
|
)}
|
||||||
<CollabButton
|
</Stack.Row>
|
||||||
isCollaborating={isCollaborating}
|
<BackgroundPickerAndDarkModeToggle
|
||||||
collaboratorCount={appState.collaborators.size}
|
actionManager={actionManager}
|
||||||
onClick={onCollabButtonClick}
|
appState={appState}
|
||||||
/>
|
setAppState={setAppState}
|
||||||
)}
|
showThemeBtn={showThemeBtn}
|
||||||
{actionManager.renderAction("toggleShortcuts", undefined, true)}
|
/>
|
||||||
{!appState.viewModeEnabled &&
|
{appState.fileHandle && (
|
||||||
actionManager.renderAction("clearCanvas")}
|
<>{actionManager.renderAction("saveToActiveFile")}</>
|
||||||
<Separator />
|
)}
|
||||||
<MenuLinks />
|
</Stack.Col>
|
||||||
<Separator />
|
</Island>
|
||||||
<div
|
</Section>
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
rowGap: ".5rem",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>{actionManager.renderAction("toggleTheme")}</div>
|
|
||||||
<div style={{ padding: "0 0.625rem" }}>
|
|
||||||
<LanguageList style={{ width: "100%" }} />
|
|
||||||
</div>
|
|
||||||
{!appState.viewModeEnabled && (
|
|
||||||
<div>
|
|
||||||
<div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}>
|
|
||||||
{t("labels.canvasBackground")}
|
|
||||||
</div>
|
|
||||||
<div style={{ padding: "0 0.625rem" }}>
|
|
||||||
{actionManager.renderAction("changeViewBackgroundColor")}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Island>
|
|
||||||
</Section>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderSelectedShapeActions = () => (
|
const renderSelectedShapeActions = () => (
|
||||||
<Section
|
<Section
|
||||||
heading="selectedShapeActions"
|
heading="selectedShapeActions"
|
||||||
className={clsx("selected-shape-actions zen-mode-transition", {
|
className={clsx("zen-mode-transition", {
|
||||||
"transition-left": appState.zenModeEnabled,
|
"transition-left": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
@@ -281,20 +234,58 @@ const LayerUI = ({
|
|||||||
className={CLASSES.SHAPE_ACTIONS_MENU}
|
className={CLASSES.SHAPE_ACTIONS_MENU}
|
||||||
padding={2}
|
padding={2}
|
||||||
style={{
|
style={{
|
||||||
// we want to make sure this doesn't overflow so subtracting the
|
// we want to make sure this doesn't overflow so subtracting 200
|
||||||
// approximate height of hamburgerMenu + footer
|
// which is approximately height of zoom footer and top left menu items with some buffer
|
||||||
maxHeight: `${appState.height - 166}px`,
|
// if active file name is displayed, subtracting 248 to account for its height
|
||||||
|
maxHeight: `${appState.height - (appState.fileHandle ? 248 : 200)}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SelectedShapeActions
|
<SelectedShapeActions
|
||||||
appState={appState}
|
appState={appState}
|
||||||
elements={elements}
|
elements={elements}
|
||||||
renderAction={actionManager.renderAction}
|
renderAction={actionManager.renderAction}
|
||||||
|
activeTool={appState.activeTool.type}
|
||||||
/>
|
/>
|
||||||
</Island>
|
</Island>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const closeLibrary = useCallback(() => {
|
||||||
|
const isDialogOpen = !!document.querySelector(".Dialog");
|
||||||
|
|
||||||
|
// Prevent closing if any dialog is open
|
||||||
|
if (isDialogOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAppState({ isLibraryOpen: false });
|
||||||
|
}, [setAppState]);
|
||||||
|
|
||||||
|
const deselectItems = useCallback(() => {
|
||||||
|
setAppState({
|
||||||
|
selectedElementIds: {},
|
||||||
|
selectedGroupIds: {},
|
||||||
|
});
|
||||||
|
}, [setAppState]);
|
||||||
|
|
||||||
|
const libraryMenu = appState.isLibraryOpen ? (
|
||||||
|
<LibraryMenu
|
||||||
|
pendingElements={getSelectedElements(elements, appState, true)}
|
||||||
|
onClose={closeLibrary}
|
||||||
|
onInsertLibraryItems={(libraryItems) => {
|
||||||
|
onInsertElements(distributeLibraryItemsOnSquareGrid(libraryItems));
|
||||||
|
}}
|
||||||
|
onAddToLibrary={deselectItems}
|
||||||
|
setAppState={setAppState}
|
||||||
|
libraryReturnUrl={libraryReturnUrl}
|
||||||
|
focusContainer={focusContainer}
|
||||||
|
library={library}
|
||||||
|
theme={appState.theme}
|
||||||
|
files={files}
|
||||||
|
id={id}
|
||||||
|
appState={appState}
|
||||||
|
/>
|
||||||
|
) : null;
|
||||||
|
|
||||||
const renderFixedSideContainer = () => {
|
const renderFixedSideContainer = () => {
|
||||||
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
||||||
appState,
|
appState,
|
||||||
@@ -303,89 +294,73 @@ const LayerUI = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<FixedSideContainer side="top">
|
<FixedSideContainer side="top">
|
||||||
{renderWelcomeScreen && !appState.isLoading && (
|
|
||||||
<WelcomeScreen appState={appState} actionManager={actionManager} />
|
|
||||||
)}
|
|
||||||
<div className="App-menu App-menu_top">
|
<div className="App-menu App-menu_top">
|
||||||
<Stack.Col
|
<Stack.Col
|
||||||
gap={6}
|
gap={4}
|
||||||
className={clsx("App-menu_top__left", {
|
className={clsx({
|
||||||
"disable-pointerEvents": appState.zenModeEnabled,
|
"disable-pointerEvents": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{renderCanvasActions()}
|
{appState.viewModeEnabled
|
||||||
|
? renderViewModeCanvasActions()
|
||||||
|
: renderCanvasActions()}
|
||||||
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
{!appState.viewModeEnabled && (
|
{!appState.viewModeEnabled && (
|
||||||
<Section heading="shapes" className="shapes-section">
|
<Section heading="shapes">
|
||||||
{(heading: React.ReactNode) => (
|
{(heading: React.ReactNode) => (
|
||||||
<div style={{ position: "relative" }}>
|
<Stack.Col gap={4} align="start">
|
||||||
<WelcomeScreenDecor
|
<Stack.Row
|
||||||
shouldRender={renderWelcomeScreen && !appState.isLoading}
|
gap={1}
|
||||||
|
className={clsx("App-toolbar-container", {
|
||||||
|
"zen-mode": appState.zenModeEnabled,
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
<div className="virgil WelcomeScreen-decor WelcomeScreen-decor--top-toolbar-pointer">
|
<PenModeButton
|
||||||
<div className="WelcomeScreen-decor--top-toolbar-pointer__label">
|
zenModeEnabled={appState.zenModeEnabled}
|
||||||
{t("welcomeScreen.toolbarHints")}
|
checked={appState.penMode}
|
||||||
</div>
|
onChange={onPenModeToggle}
|
||||||
{WelcomeScreenTopToolbarArrow}
|
title={t("toolBar.penMode")}
|
||||||
</div>
|
penDetected={appState.penDetected}
|
||||||
</WelcomeScreenDecor>
|
/>
|
||||||
|
<LockButton
|
||||||
<Stack.Col gap={4} align="start">
|
zenModeEnabled={appState.zenModeEnabled}
|
||||||
<Stack.Row
|
checked={appState.activeTool.locked}
|
||||||
gap={1}
|
onChange={() => onLockToggle()}
|
||||||
className={clsx("App-toolbar-container", {
|
title={t("toolBar.lock")}
|
||||||
|
/>
|
||||||
|
<Island
|
||||||
|
padding={1}
|
||||||
|
className={clsx("App-toolbar", {
|
||||||
"zen-mode": appState.zenModeEnabled,
|
"zen-mode": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Island
|
<HintViewer
|
||||||
padding={1}
|
appState={appState}
|
||||||
className={clsx("App-toolbar", {
|
elements={elements}
|
||||||
"zen-mode": appState.zenModeEnabled,
|
isMobile={device.isMobile}
|
||||||
})}
|
/>
|
||||||
>
|
{heading}
|
||||||
<HintViewer
|
<Stack.Row gap={1}>
|
||||||
|
<ShapesSwitcher
|
||||||
appState={appState}
|
appState={appState}
|
||||||
elements={elements}
|
canvas={canvas}
|
||||||
isMobile={device.isMobile}
|
activeTool={appState.activeTool}
|
||||||
device={device}
|
setAppState={setAppState}
|
||||||
|
onImageAction={({ pointerType }) => {
|
||||||
|
onImageAction({
|
||||||
|
insertOnCanvasDirectly: pointerType !== "mouse",
|
||||||
|
});
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{heading}
|
</Stack.Row>
|
||||||
<Stack.Row gap={1}>
|
</Island>
|
||||||
<PenModeButton
|
<LibraryButton
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
appState={appState}
|
||||||
checked={appState.penMode}
|
setAppState={setAppState}
|
||||||
onChange={onPenModeToggle}
|
/>
|
||||||
title={t("toolBar.penMode")}
|
</Stack.Row>
|
||||||
penDetected={appState.penDetected}
|
</Stack.Col>
|
||||||
/>
|
|
||||||
<LockButton
|
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
|
||||||
checked={appState.activeTool.locked}
|
|
||||||
onChange={() => onLockToggle()}
|
|
||||||
title={t("toolBar.lock")}
|
|
||||||
/>
|
|
||||||
<div className="App-toolbar__divider"></div>
|
|
||||||
|
|
||||||
<ShapesSwitcher
|
|
||||||
appState={appState}
|
|
||||||
canvas={canvas}
|
|
||||||
activeTool={appState.activeTool}
|
|
||||||
setAppState={setAppState}
|
|
||||||
onImageAction={({ pointerType }) => {
|
|
||||||
onImageAction({
|
|
||||||
insertOnCanvasDirectly: pointerType !== "mouse",
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{/* {actionManager.renderAction("eraser", {
|
|
||||||
// size: "small",
|
|
||||||
})} */}
|
|
||||||
</Stack.Row>
|
|
||||||
</Island>
|
|
||||||
</Stack.Row>
|
|
||||||
</Stack.Col>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
)}
|
)}
|
||||||
@@ -401,42 +376,107 @@ const LayerUI = ({
|
|||||||
collaborators={appState.collaborators}
|
collaborators={appState.collaborators}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
/>
|
/>
|
||||||
{onCollabButtonClick && (
|
|
||||||
<CollabButton
|
|
||||||
isInHamburgerMenu={false}
|
|
||||||
isCollaborating={isCollaborating}
|
|
||||||
collaboratorCount={appState.collaborators.size}
|
|
||||||
onClick={onCollabButtonClick}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{renderTopRightUI?.(device.isMobile, appState)}
|
{renderTopRightUI?.(device.isMobile, appState)}
|
||||||
{!appState.viewModeEnabled && (
|
|
||||||
<LibraryButton appState={appState} setAppState={setAppState} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</FixedSideContainer>
|
</FixedSideContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderSidebars = () => {
|
const renderBottomAppMenu = () => {
|
||||||
return appState.openSidebar === "customSidebar" ? (
|
return (
|
||||||
renderCustomSidebar?.() || null
|
<footer
|
||||||
) : appState.openSidebar === "library" ? (
|
role="contentinfo"
|
||||||
<LibraryMenu
|
className="layer-ui__wrapper__footer App-menu App-menu_bottom"
|
||||||
appState={appState}
|
>
|
||||||
onInsertElements={onInsertElements}
|
<div
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
className={clsx(
|
||||||
focusContainer={focusContainer}
|
"layer-ui__wrapper__footer-left zen-mode-transition",
|
||||||
library={library}
|
{
|
||||||
id={id}
|
"layer-ui__wrapper__footer-left--transition-left":
|
||||||
/>
|
appState.zenModeEnabled,
|
||||||
) : null;
|
},
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Stack.Col gap={2}>
|
||||||
|
<Section heading="canvasActions">
|
||||||
|
<Island padding={1}>
|
||||||
|
<ZoomActions
|
||||||
|
renderAction={actionManager.renderAction}
|
||||||
|
zoom={appState.zoom}
|
||||||
|
/>
|
||||||
|
</Island>
|
||||||
|
{!appState.viewModeEnabled && (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={clsx("undo-redo-buttons zen-mode-transition", {
|
||||||
|
"layer-ui__wrapper__footer-left--transition-bottom":
|
||||||
|
appState.zenModeEnabled,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("undo", { size: "small" })}
|
||||||
|
{actionManager.renderAction("redo", { size: "small" })}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={clsx("eraser-buttons zen-mode-transition", {
|
||||||
|
"layer-ui__wrapper__footer-left--transition-left":
|
||||||
|
appState.zenModeEnabled,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("eraser", { size: "small" })}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{!appState.viewModeEnabled &&
|
||||||
|
appState.multiElement &&
|
||||||
|
device.isTouchScreen && (
|
||||||
|
<div
|
||||||
|
className={clsx("finalize-button zen-mode-transition", {
|
||||||
|
"layer-ui__wrapper__footer-left--transition-left":
|
||||||
|
appState.zenModeEnabled,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("finalize", { size: "small" })}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Section>
|
||||||
|
</Stack.Col>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={clsx(
|
||||||
|
"layer-ui__wrapper__footer-center zen-mode-transition",
|
||||||
|
{
|
||||||
|
"layer-ui__wrapper__footer-left--transition-bottom":
|
||||||
|
appState.zenModeEnabled,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{renderCustomFooter?.(false, appState)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={clsx(
|
||||||
|
"layer-ui__wrapper__footer-right zen-mode-transition",
|
||||||
|
{
|
||||||
|
"transition-right disable-pointerEvents": appState.zenModeEnabled,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("toggleShortcuts")}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className={clsx("disable-zen-mode", {
|
||||||
|
"disable-zen-mode--visible": showExitZenModeBtn,
|
||||||
|
})}
|
||||||
|
onClick={() => actionManager.executeAction(actionToggleZenMode)}
|
||||||
|
>
|
||||||
|
{t("buttons.exitZenMode")}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [hostSidebarCounters] = useAtom(hostSidebarCountersAtom, jotaiScope);
|
const dialogs = (
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
<>
|
||||||
{appState.isLoading && <LoadingMessage delay={250} />}
|
{appState.isLoading && <LoadingMessage delay={250} />}
|
||||||
{appState.errorMessage && (
|
{appState.errorMessage && (
|
||||||
@@ -445,14 +485,13 @@ const LayerUI = ({
|
|||||||
onClose={() => setAppState({ errorMessage: null })}
|
onClose={() => setAppState({ errorMessage: null })}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{appState.openDialog === "help" && (
|
{appState.showHelpDialog && (
|
||||||
<HelpDialog
|
<HelpDialog
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setAppState({ openDialog: null });
|
setAppState({ showHelpDialog: false });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{renderImageExportDialog()}
|
|
||||||
{appState.pasteDialog.shown && (
|
{appState.pasteDialog.shown && (
|
||||||
<PasteChartDialog
|
<PasteChartDialog
|
||||||
setAppState={setAppState}
|
setAppState={setAppState}
|
||||||
@@ -465,82 +504,86 @@ const LayerUI = ({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{device.isMobile && (
|
</>
|
||||||
<MobileMenu
|
);
|
||||||
renderWelcomeScreen={renderWelcomeScreen}
|
|
||||||
appState={appState}
|
|
||||||
elements={elements}
|
|
||||||
actionManager={actionManager}
|
|
||||||
renderJSONExportDialog={renderJSONExportDialog}
|
|
||||||
renderImageExportDialog={renderImageExportDialog}
|
|
||||||
setAppState={setAppState}
|
|
||||||
onCollabButtonClick={onCollabButtonClick}
|
|
||||||
onLockToggle={() => onLockToggle()}
|
|
||||||
onPenModeToggle={onPenModeToggle}
|
|
||||||
canvas={canvas}
|
|
||||||
isCollaborating={isCollaborating}
|
|
||||||
renderCustomFooter={renderCustomFooter}
|
|
||||||
onImageAction={onImageAction}
|
|
||||||
renderTopRightUI={renderTopRightUI}
|
|
||||||
renderCustomStats={renderCustomStats}
|
|
||||||
renderSidebars={renderSidebars}
|
|
||||||
device={device}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!device.isMobile && (
|
const renderStats = () => {
|
||||||
<>
|
if (!appState.showStats) {
|
||||||
<div
|
return null;
|
||||||
className={clsx("layer-ui__wrapper", {
|
}
|
||||||
"disable-pointerEvents":
|
return (
|
||||||
appState.draggingElement ||
|
<Stats
|
||||||
appState.resizingElement ||
|
appState={appState}
|
||||||
(appState.editingElement &&
|
setAppState={setAppState}
|
||||||
!isTextElement(appState.editingElement)),
|
elements={elements}
|
||||||
})}
|
onClose={() => {
|
||||||
style={
|
actionManager.executeAction(actionToggleStats);
|
||||||
((appState.openSidebar === "library" &&
|
}}
|
||||||
appState.isSidebarDocked) ||
|
renderCustomStats={renderCustomStats}
|
||||||
hostSidebarCounters.docked) &&
|
/>
|
||||||
device.canDeviceFitSidebar
|
);
|
||||||
? { width: `calc(100% - ${LIBRARY_SIDEBAR_WIDTH}px)` }
|
};
|
||||||
: {}
|
|
||||||
}
|
return device.isMobile ? (
|
||||||
|
<>
|
||||||
|
{dialogs}
|
||||||
|
<MobileMenu
|
||||||
|
appState={appState}
|
||||||
|
elements={elements}
|
||||||
|
actionManager={actionManager}
|
||||||
|
libraryMenu={libraryMenu}
|
||||||
|
renderJSONExportDialog={renderJSONExportDialog}
|
||||||
|
renderImageExportDialog={renderImageExportDialog}
|
||||||
|
setAppState={setAppState}
|
||||||
|
onCollabButtonClick={onCollabButtonClick}
|
||||||
|
onLockToggle={() => onLockToggle()}
|
||||||
|
onPenModeToggle={onPenModeToggle}
|
||||||
|
canvas={canvas}
|
||||||
|
isCollaborating={isCollaborating}
|
||||||
|
renderCustomFooter={renderCustomFooter}
|
||||||
|
showThemeBtn={showThemeBtn}
|
||||||
|
onImageAction={onImageAction}
|
||||||
|
renderTopRightUI={renderTopRightUI}
|
||||||
|
renderStats={renderStats}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={clsx("layer-ui__wrapper", {
|
||||||
|
"disable-pointerEvents":
|
||||||
|
appState.draggingElement ||
|
||||||
|
appState.resizingElement ||
|
||||||
|
(appState.editingElement &&
|
||||||
|
!isTextElement(appState.editingElement)),
|
||||||
|
})}
|
||||||
|
style={
|
||||||
|
appState.isLibraryOpen &&
|
||||||
|
appState.isLibraryMenuDocked &&
|
||||||
|
device.canDeviceFitSidebar
|
||||||
|
? { width: `calc(100% - ${LIBRARY_SIDEBAR_WIDTH}px)` }
|
||||||
|
: {}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{dialogs}
|
||||||
|
{renderFixedSideContainer()}
|
||||||
|
{renderBottomAppMenu()}
|
||||||
|
{renderStats()}
|
||||||
|
{appState.scrolledOutside && (
|
||||||
|
<button
|
||||||
|
className="scroll-back-to-content"
|
||||||
|
onClick={() => {
|
||||||
|
setAppState({
|
||||||
|
...calculateScrollCenter(elements, appState, canvas),
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{renderFixedSideContainer()}
|
{t("buttons.scrollBackToContent")}
|
||||||
<Footer
|
</button>
|
||||||
renderWelcomeScreen={renderWelcomeScreen}
|
)}
|
||||||
appState={appState}
|
</div>
|
||||||
actionManager={actionManager}
|
{appState.isLibraryOpen && (
|
||||||
renderCustomFooter={renderCustomFooter}
|
<div className="layer-ui__sidebar">{libraryMenu}</div>
|
||||||
showExitZenModeBtn={showExitZenModeBtn}
|
|
||||||
/>
|
|
||||||
{appState.showStats && (
|
|
||||||
<Stats
|
|
||||||
appState={appState}
|
|
||||||
setAppState={setAppState}
|
|
||||||
elements={elements}
|
|
||||||
onClose={() => {
|
|
||||||
actionManager.executeAction(actionToggleStats);
|
|
||||||
}}
|
|
||||||
renderCustomStats={renderCustomStats}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{appState.scrolledOutside && (
|
|
||||||
<button
|
|
||||||
className="scroll-back-to-content"
|
|
||||||
onClick={() => {
|
|
||||||
setAppState({
|
|
||||||
...calculateScrollCenter(elements, appState, canvas),
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("buttons.scrollBackToContent")}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{renderSidebars()}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -559,12 +602,8 @@ const areEqual = (prev: LayerUIProps, next: LayerUIProps) => {
|
|||||||
const nextAppState = getNecessaryObj(next.appState);
|
const nextAppState = getNecessaryObj(next.appState);
|
||||||
|
|
||||||
const keys = Object.keys(prevAppState) as (keyof Partial<AppState>)[];
|
const keys = Object.keys(prevAppState) as (keyof Partial<AppState>)[];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
prev.renderCustomFooter === next.renderCustomFooter &&
|
prev.renderCustomFooter === next.renderCustomFooter &&
|
||||||
prev.renderTopRightUI === next.renderTopRightUI &&
|
|
||||||
prev.renderCustomStats === next.renderCustomStats &&
|
|
||||||
prev.renderCustomSidebar === next.renderCustomSidebar &&
|
|
||||||
prev.langCode === next.langCode &&
|
prev.langCode === next.langCode &&
|
||||||
prev.elements === next.elements &&
|
prev.elements === next.elements &&
|
||||||
prev.files === next.files &&
|
prev.files === next.files &&
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
@import "../css/variables.module";
|
|
||||||
|
|
||||||
.library-button {
|
|
||||||
@include outlineButtonStyles;
|
|
||||||
|
|
||||||
background-color: var(--island-bg-color);
|
|
||||||
|
|
||||||
width: auto;
|
|
||||||
height: var(--lg-button-size);
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
|
|
||||||
line-height: 0;
|
|
||||||
|
|
||||||
font-size: 0.75rem;
|
|
||||||
letter-spacing: 0.4px;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: var(--lg-icon-size);
|
|
||||||
height: var(--lg-icon-size);
|
|
||||||
}
|
|
||||||
|
|
||||||
&__label {
|
|
||||||
display: none;
|
|
||||||
|
|
||||||
@media screen and (min-width: 1024px) {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
import clsx from "clsx";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { capitalizeString } from "../utils";
|
import { capitalizeString } from "../utils";
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import { useDevice } from "./App";
|
import { useDevice } from "./App";
|
||||||
import "./LibraryButton.scss";
|
|
||||||
import { LibraryIcon } from "./icons";
|
const LIBRARY_ICON = (
|
||||||
|
<svg viewBox="0 0 576 512">
|
||||||
|
<path
|
||||||
|
fill="currentColor"
|
||||||
|
d="M542.22 32.05c-54.8 3.11-163.72 14.43-230.96 55.59-4.64 2.84-7.27 7.89-7.27 13.17v363.87c0 11.55 12.63 18.85 23.28 13.49 69.18-34.82 169.23-44.32 218.7-46.92 16.89-.89 30.02-14.43 30.02-30.66V62.75c.01-17.71-15.35-31.74-33.77-30.7zM264.73 87.64C197.5 46.48 88.58 35.17 33.78 32.05 15.36 31.01 0 45.04 0 62.75V400.6c0 16.24 13.13 29.78 30.02 30.66 49.49 2.6 149.59 12.11 218.77 46.95 10.62 5.35 23.21-1.94 23.21-13.46V100.63c0-5.29-2.62-10.14-7.27-12.99z"
|
||||||
|
></path>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
export const LibraryButton: React.FC<{
|
export const LibraryButton: React.FC<{
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
@@ -13,16 +21,17 @@ export const LibraryButton: React.FC<{
|
|||||||
isMobile?: boolean;
|
isMobile?: boolean;
|
||||||
}> = ({ appState, setAppState, isMobile }) => {
|
}> = ({ appState, setAppState, isMobile }) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
const showLabel = !isMobile;
|
|
||||||
|
|
||||||
// TODO barnabasmolnar/redesign
|
|
||||||
// not great, toolbar jumps in a jarring manner
|
|
||||||
if (appState.isSidebarDocked && appState.openSidebar === "library") {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label title={`${capitalizeString(t("toolBar.library"))} — 0`}>
|
<label
|
||||||
|
className={clsx(
|
||||||
|
"ToolIcon ToolIcon_type_floating ToolIcon__library",
|
||||||
|
`ToolIcon_size_medium`,
|
||||||
|
{
|
||||||
|
"is-mobile": isMobile,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
title={`${capitalizeString(t("toolBar.library"))} — 0`}
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
className="ToolIcon_type_checkbox"
|
className="ToolIcon_type_checkbox"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
@@ -31,10 +40,10 @@ export const LibraryButton: React.FC<{
|
|||||||
document
|
document
|
||||||
.querySelector(".layer-ui__wrapper")
|
.querySelector(".layer-ui__wrapper")
|
||||||
?.classList.remove("animate");
|
?.classList.remove("animate");
|
||||||
const isOpen = event.target.checked;
|
const nextState = event.target.checked;
|
||||||
setAppState({ openSidebar: isOpen ? "library" : null });
|
setAppState({ isLibraryOpen: nextState });
|
||||||
// track only openings
|
// track only openings
|
||||||
if (isOpen) {
|
if (nextState) {
|
||||||
trackEvent(
|
trackEvent(
|
||||||
"library",
|
"library",
|
||||||
"toggleLibrary (open)",
|
"toggleLibrary (open)",
|
||||||
@@ -42,16 +51,11 @@ export const LibraryButton: React.FC<{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
checked={appState.openSidebar === "library"}
|
checked={appState.isLibraryOpen}
|
||||||
aria-label={capitalizeString(t("toolBar.library"))}
|
aria-label={capitalizeString(t("toolBar.library"))}
|
||||||
aria-keyshortcuts="0"
|
aria-keyshortcuts="0"
|
||||||
/>
|
/>
|
||||||
<div className="library-button">
|
<div className="ToolIcon__icon">{LIBRARY_ICON}</div>
|
||||||
<div>{LibraryIcon}</div>
|
|
||||||
{showLabel && (
|
|
||||||
<div className="library-button__label">{t("toolBar.library")}</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
@import "open-color/open-color";
|
@import "open-color/open-color";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.layer-ui__library-sidebar {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.layer-ui__library {
|
.layer-ui__library {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
flex: 1 1 auto;
|
|
||||||
|
|
||||||
.layer-ui__library-header {
|
.layer-ui__library-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -29,38 +23,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.layer-ui__sidebar {
|
.layer-ui__sidebar {
|
||||||
|
.layer-ui__library {
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
.library-menu-items-container {
|
.library-menu-items-container {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.library-actions-counter {
|
|
||||||
background-color: var(--color-primary);
|
|
||||||
color: var(--color-primary-light);
|
|
||||||
font-weight: bold;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
border-radius: 50%;
|
|
||||||
width: 1rem;
|
|
||||||
height: 1rem;
|
|
||||||
position: absolute;
|
|
||||||
bottom: -0.25rem;
|
|
||||||
right: -0.25rem;
|
|
||||||
font-size: 0.625rem;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.layer-ui__library-message {
|
.layer-ui__library-message {
|
||||||
padding: 2rem;
|
padding: 2em 4em;
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-grow: 1;
|
.Spinner {
|
||||||
justify-content: center;
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
span {
|
span {
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
@@ -88,10 +69,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.library-menu-browse-button {
|
.library-menu-browse-button {
|
||||||
margin: 1rem auto;
|
width: 80%;
|
||||||
|
min-height: 22px;
|
||||||
padding: 0.875rem 1rem;
|
margin: 0 auto;
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -104,10 +86,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-decoration: none !important;
|
text-decoration: none !important;
|
||||||
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 0.75rem;
|
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--color-primary-darker);
|
background-color: var(--color-primary-darker);
|
||||||
}
|
}
|
||||||
@@ -116,12 +94,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
.library-menu-browse-button {
|
|
||||||
color: var(--color-gray-100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.library-menu-browse-button--mobile {
|
.library-menu-browse-button--mobile {
|
||||||
min-height: 22px;
|
min-height: 22px;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
|||||||
+176
-182
@@ -6,13 +6,20 @@ import {
|
|||||||
RefObject,
|
RefObject,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
} from "react";
|
} from "react";
|
||||||
import Library, {
|
import Library, { libraryItemsAtom } from "../data/library";
|
||||||
distributeLibraryItemsOnSquareGrid,
|
|
||||||
libraryItemsAtom,
|
|
||||||
} from "../data/library";
|
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { randomId } from "../random";
|
import { randomId } from "../random";
|
||||||
import { LibraryItems, LibraryItem, AppState, ExcalidrawProps } from "../types";
|
import {
|
||||||
|
LibraryItems,
|
||||||
|
LibraryItem,
|
||||||
|
AppState,
|
||||||
|
BinaryFiles,
|
||||||
|
ExcalidrawProps,
|
||||||
|
} from "../types";
|
||||||
|
import { Dialog } from "./Dialog";
|
||||||
|
import { Island } from "./Island";
|
||||||
|
import PublishLibrary from "./PublishLibrary";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
|
|
||||||
import "./LibraryMenu.scss";
|
import "./LibraryMenu.scss";
|
||||||
import LibraryMenuItems from "./LibraryMenuItems";
|
import LibraryMenuItems from "./LibraryMenuItems";
|
||||||
@@ -22,16 +29,7 @@ import { trackEvent } from "../analytics";
|
|||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { jotaiScope } from "../jotai";
|
import { jotaiScope } from "../jotai";
|
||||||
import Spinner from "./Spinner";
|
import Spinner from "./Spinner";
|
||||||
import {
|
import { useDevice } from "./App";
|
||||||
useDevice,
|
|
||||||
useExcalidrawElements,
|
|
||||||
useExcalidrawSetAppState,
|
|
||||||
} from "./App";
|
|
||||||
import { Sidebar } from "./Sidebar/Sidebar";
|
|
||||||
import { getSelectedElements } from "../scene";
|
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
|
||||||
import { LibraryMenuHeader } from "./LibraryMenuHeaderContent";
|
|
||||||
import LibraryMenuBrowseButton from "./LibraryMenuBrowseButton";
|
|
||||||
|
|
||||||
const useOnClickOutside = (
|
const useOnClickOutside = (
|
||||||
ref: RefObject<HTMLElement>,
|
ref: RefObject<HTMLElement>,
|
||||||
@@ -61,42 +59,112 @@ const useOnClickOutside = (
|
|||||||
}, [ref, cb]);
|
}, [ref, cb]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSelectedItems = (
|
||||||
|
libraryItems: LibraryItems,
|
||||||
|
selectedItems: LibraryItem["id"][],
|
||||||
|
) => libraryItems.filter((item) => selectedItems.includes(item.id));
|
||||||
|
|
||||||
const LibraryMenuWrapper = forwardRef<
|
const LibraryMenuWrapper = forwardRef<
|
||||||
HTMLDivElement,
|
HTMLDivElement,
|
||||||
{ children: React.ReactNode }
|
{ children: React.ReactNode }
|
||||||
>(({ children }, ref) => {
|
>(({ children }, ref) => {
|
||||||
return (
|
return (
|
||||||
<div ref={ref} className="layer-ui__library">
|
<Island padding={1} ref={ref} className="layer-ui__library">
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</Island>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const LibraryMenuContent = ({
|
export const LibraryMenu = ({
|
||||||
|
onClose,
|
||||||
onInsertLibraryItems,
|
onInsertLibraryItems,
|
||||||
pendingElements,
|
pendingElements,
|
||||||
onAddToLibrary,
|
onAddToLibrary,
|
||||||
|
theme,
|
||||||
setAppState,
|
setAppState,
|
||||||
|
files,
|
||||||
libraryReturnUrl,
|
libraryReturnUrl,
|
||||||
|
focusContainer,
|
||||||
library,
|
library,
|
||||||
id,
|
id,
|
||||||
appState,
|
appState,
|
||||||
selectedItems,
|
|
||||||
onSelectItems,
|
|
||||||
}: {
|
}: {
|
||||||
pendingElements: LibraryItem["elements"];
|
pendingElements: LibraryItem["elements"];
|
||||||
|
onClose: () => void;
|
||||||
onInsertLibraryItems: (libraryItems: LibraryItems) => void;
|
onInsertLibraryItems: (libraryItems: LibraryItems) => void;
|
||||||
onAddToLibrary: () => void;
|
onAddToLibrary: () => void;
|
||||||
|
theme: AppState["theme"];
|
||||||
|
files: BinaryFiles;
|
||||||
setAppState: React.Component<any, AppState>["setState"];
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
||||||
|
focusContainer: () => void;
|
||||||
library: Library;
|
library: Library;
|
||||||
id: string;
|
id: string;
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
selectedItems: LibraryItem["id"][];
|
|
||||||
onSelectItems: (id: LibraryItem["id"][]) => void;
|
|
||||||
}) => {
|
}) => {
|
||||||
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
|
const device = useDevice();
|
||||||
|
|
||||||
|
useOnClickOutside(
|
||||||
|
ref,
|
||||||
|
useCallback(
|
||||||
|
(event) => {
|
||||||
|
// If click on the library icon, do nothing.
|
||||||
|
if ((event.target as Element).closest(".ToolIcon__library")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!appState.isLibraryMenuDocked || !device.canDeviceFitSidebar) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onClose, appState.isLibraryMenuDocked, device.canDeviceFitSidebar],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (
|
||||||
|
event.key === KEYS.ESCAPE &&
|
||||||
|
(!appState.isLibraryMenuDocked || !device.canDeviceFitSidebar)
|
||||||
|
) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener(EVENT.KEYDOWN, handleKeyDown);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener(EVENT.KEYDOWN, handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [onClose, appState.isLibraryMenuDocked, device.canDeviceFitSidebar]);
|
||||||
|
|
||||||
|
const [selectedItems, setSelectedItems] = useState<LibraryItem["id"][]>([]);
|
||||||
|
const [showPublishLibraryDialog, setShowPublishLibraryDialog] =
|
||||||
|
useState(false);
|
||||||
|
const [publishLibSuccess, setPublishLibSuccess] = useState<null | {
|
||||||
|
url: string;
|
||||||
|
authorName: string;
|
||||||
|
}>(null);
|
||||||
|
|
||||||
const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope);
|
const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope);
|
||||||
|
|
||||||
|
const removeFromLibrary = useCallback(
|
||||||
|
async (libraryItems: LibraryItems) => {
|
||||||
|
const nextItems = libraryItems.filter(
|
||||||
|
(item) => !selectedItems.includes(item.id),
|
||||||
|
);
|
||||||
|
library.setLibrary(nextItems).catch(() => {
|
||||||
|
setAppState({ errorMessage: t("alerts.errorRemovingFromLibrary") });
|
||||||
|
});
|
||||||
|
setSelectedItems([]);
|
||||||
|
},
|
||||||
|
[library, setAppState, selectedItems, setSelectedItems],
|
||||||
|
);
|
||||||
|
|
||||||
|
const resetLibrary = useCallback(() => {
|
||||||
|
library.resetLibrary();
|
||||||
|
focusContainer();
|
||||||
|
}, [library, focusContainer]);
|
||||||
|
|
||||||
const addToLibrary = useCallback(
|
const addToLibrary = useCallback(
|
||||||
async (elements: LibraryItem["elements"], libraryItems: LibraryItems) => {
|
async (elements: LibraryItem["elements"], libraryItems: LibraryItems) => {
|
||||||
trackEvent("element", "addToLibrary", "ui");
|
trackEvent("element", "addToLibrary", "ui");
|
||||||
@@ -122,188 +190,114 @@ export const LibraryMenuContent = ({
|
|||||||
[onAddToLibrary, library, setAppState],
|
[onAddToLibrary, library, setAppState],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const renderPublishSuccess = useCallback(() => {
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
onCloseRequest={() => setPublishLibSuccess(null)}
|
||||||
|
title={t("publishSuccessDialog.title")}
|
||||||
|
className="publish-library-success"
|
||||||
|
small={true}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
{t("publishSuccessDialog.content", {
|
||||||
|
authorName: publishLibSuccess!.authorName,
|
||||||
|
})}{" "}
|
||||||
|
<a
|
||||||
|
href={publishLibSuccess?.url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{t("publishSuccessDialog.link")}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<ToolButton
|
||||||
|
type="button"
|
||||||
|
title={t("buttons.close")}
|
||||||
|
aria-label={t("buttons.close")}
|
||||||
|
label={t("buttons.close")}
|
||||||
|
onClick={() => setPublishLibSuccess(null)}
|
||||||
|
data-testid="publish-library-success-close"
|
||||||
|
className="publish-library-success-close"
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}, [setPublishLibSuccess, publishLibSuccess]);
|
||||||
|
|
||||||
|
const onPublishLibSuccess = useCallback(
|
||||||
|
(data: { url: string; authorName: string }, libraryItems: LibraryItems) => {
|
||||||
|
setShowPublishLibraryDialog(false);
|
||||||
|
setPublishLibSuccess({ url: data.url, authorName: data.authorName });
|
||||||
|
const nextLibItems = libraryItems.slice();
|
||||||
|
nextLibItems.forEach((libItem) => {
|
||||||
|
if (selectedItems.includes(libItem.id)) {
|
||||||
|
libItem.status = "published";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
library.setLibrary(nextLibItems);
|
||||||
|
},
|
||||||
|
[setShowPublishLibraryDialog, setPublishLibSuccess, selectedItems, library],
|
||||||
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
libraryItemsData.status === "loading" &&
|
libraryItemsData.status === "loading" &&
|
||||||
!libraryItemsData.isInitialized
|
!libraryItemsData.isInitialized
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<LibraryMenuWrapper>
|
<LibraryMenuWrapper ref={ref}>
|
||||||
<div className="layer-ui__library-message">
|
<div className="layer-ui__library-message">
|
||||||
<div>
|
<Spinner size="2em" />
|
||||||
<Spinner size="2em" />
|
<span>{t("labels.libraryLoadingMessage")}</span>
|
||||||
<span>{t("labels.libraryLoadingMessage")}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</LibraryMenuWrapper>
|
</LibraryMenuWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const showBtn =
|
|
||||||
libraryItemsData.libraryItems.length > 0 || pendingElements.length > 0;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LibraryMenuWrapper>
|
<LibraryMenuWrapper ref={ref}>
|
||||||
|
{showPublishLibraryDialog && (
|
||||||
|
<PublishLibrary
|
||||||
|
onClose={() => setShowPublishLibraryDialog(false)}
|
||||||
|
libraryItems={getSelectedItems(
|
||||||
|
libraryItemsData.libraryItems,
|
||||||
|
selectedItems,
|
||||||
|
)}
|
||||||
|
appState={appState}
|
||||||
|
onSuccess={(data) =>
|
||||||
|
onPublishLibSuccess(data, libraryItemsData.libraryItems)
|
||||||
|
}
|
||||||
|
onError={(error) => window.alert(error)}
|
||||||
|
updateItemsInStorage={() =>
|
||||||
|
library.setLibrary(libraryItemsData.libraryItems)
|
||||||
|
}
|
||||||
|
onRemove={(id: string) =>
|
||||||
|
setSelectedItems(selectedItems.filter((_id) => _id !== id))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{publishLibSuccess && renderPublishSuccess()}
|
||||||
<LibraryMenuItems
|
<LibraryMenuItems
|
||||||
isLoading={libraryItemsData.status === "loading"}
|
isLoading={libraryItemsData.status === "loading"}
|
||||||
libraryItems={libraryItemsData.libraryItems}
|
libraryItems={libraryItemsData.libraryItems}
|
||||||
|
onRemoveFromLibrary={() =>
|
||||||
|
removeFromLibrary(libraryItemsData.libraryItems)
|
||||||
|
}
|
||||||
onAddToLibrary={(elements) =>
|
onAddToLibrary={(elements) =>
|
||||||
addToLibrary(elements, libraryItemsData.libraryItems)
|
addToLibrary(elements, libraryItemsData.libraryItems)
|
||||||
}
|
}
|
||||||
onInsertLibraryItems={onInsertLibraryItems}
|
onInsertLibraryItems={onInsertLibraryItems}
|
||||||
pendingElements={pendingElements}
|
pendingElements={pendingElements}
|
||||||
selectedItems={selectedItems}
|
setAppState={setAppState}
|
||||||
onSelectItems={onSelectItems}
|
appState={appState}
|
||||||
id={id}
|
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
libraryReturnUrl={libraryReturnUrl}
|
||||||
theme={appState.theme}
|
library={library}
|
||||||
|
theme={theme}
|
||||||
|
files={files}
|
||||||
|
id={id}
|
||||||
|
selectedItems={selectedItems}
|
||||||
|
onSelectItems={(ids) => setSelectedItems(ids)}
|
||||||
|
onPublish={() => setShowPublishLibraryDialog(true)}
|
||||||
|
resetLibrary={resetLibrary}
|
||||||
/>
|
/>
|
||||||
{showBtn && (
|
|
||||||
<LibraryMenuBrowseButton
|
|
||||||
id={id}
|
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
|
||||||
theme={appState.theme}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</LibraryMenuWrapper>
|
</LibraryMenuWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LibraryMenu: React.FC<{
|
|
||||||
appState: AppState;
|
|
||||||
onInsertElements: (elements: readonly NonDeletedExcalidrawElement[]) => void;
|
|
||||||
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
|
||||||
focusContainer: () => void;
|
|
||||||
library: Library;
|
|
||||||
id: string;
|
|
||||||
}> = ({
|
|
||||||
appState,
|
|
||||||
onInsertElements,
|
|
||||||
libraryReturnUrl,
|
|
||||||
focusContainer,
|
|
||||||
library,
|
|
||||||
id,
|
|
||||||
}) => {
|
|
||||||
const setAppState = useExcalidrawSetAppState();
|
|
||||||
const elements = useExcalidrawElements();
|
|
||||||
const device = useDevice();
|
|
||||||
|
|
||||||
const [selectedItems, setSelectedItems] = useState<LibraryItem["id"][]>([]);
|
|
||||||
const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope);
|
|
||||||
|
|
||||||
const ref = useRef<HTMLDivElement | null>(null);
|
|
||||||
|
|
||||||
const closeLibrary = useCallback(() => {
|
|
||||||
const isDialogOpen = !!document.querySelector(".Dialog");
|
|
||||||
|
|
||||||
// Prevent closing if any dialog is open
|
|
||||||
if (isDialogOpen) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setAppState({ openSidebar: null });
|
|
||||||
}, [setAppState]);
|
|
||||||
|
|
||||||
useOnClickOutside(
|
|
||||||
ref,
|
|
||||||
useCallback(
|
|
||||||
(event) => {
|
|
||||||
// If click on the library icon, do nothing so that LibraryButton
|
|
||||||
// can toggle library menu
|
|
||||||
if ((event.target as Element).closest(".ToolIcon__library")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!appState.isSidebarDocked || !device.canDeviceFitSidebar) {
|
|
||||||
closeLibrary();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[closeLibrary, appState.isSidebarDocked, device.canDeviceFitSidebar],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
|
||||||
if (
|
|
||||||
event.key === KEYS.ESCAPE &&
|
|
||||||
(!appState.isSidebarDocked || !device.canDeviceFitSidebar)
|
|
||||||
) {
|
|
||||||
closeLibrary();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
document.addEventListener(EVENT.KEYDOWN, handleKeyDown);
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener(EVENT.KEYDOWN, handleKeyDown);
|
|
||||||
};
|
|
||||||
}, [closeLibrary, appState.isSidebarDocked, device.canDeviceFitSidebar]);
|
|
||||||
|
|
||||||
const deselectItems = useCallback(() => {
|
|
||||||
setAppState({
|
|
||||||
selectedElementIds: {},
|
|
||||||
selectedGroupIds: {},
|
|
||||||
});
|
|
||||||
}, [setAppState]);
|
|
||||||
|
|
||||||
const removeFromLibrary = useCallback(
|
|
||||||
async (libraryItems: LibraryItems) => {
|
|
||||||
const nextItems = libraryItems.filter(
|
|
||||||
(item) => !selectedItems.includes(item.id),
|
|
||||||
);
|
|
||||||
library.setLibrary(nextItems).catch(() => {
|
|
||||||
setAppState({ errorMessage: t("alerts.errorRemovingFromLibrary") });
|
|
||||||
});
|
|
||||||
setSelectedItems([]);
|
|
||||||
},
|
|
||||||
[library, setAppState, selectedItems, setSelectedItems],
|
|
||||||
);
|
|
||||||
|
|
||||||
const resetLibrary = useCallback(() => {
|
|
||||||
library.resetLibrary();
|
|
||||||
focusContainer();
|
|
||||||
}, [library, focusContainer]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Sidebar
|
|
||||||
__isInternal
|
|
||||||
// necessary to remount when switching between internal
|
|
||||||
// and custom (host app) sidebar, so that the `props.onClose`
|
|
||||||
// is colled correctly
|
|
||||||
key="library"
|
|
||||||
className="layer-ui__library-sidebar"
|
|
||||||
initialDockedState={appState.isSidebarDocked}
|
|
||||||
onDock={(docked) => {
|
|
||||||
trackEvent(
|
|
||||||
"library",
|
|
||||||
`toggleLibraryDock (${docked ? "dock" : "undock"})`,
|
|
||||||
`sidebar (${device.isMobile ? "mobile" : "desktop"})`,
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
ref={ref}
|
|
||||||
>
|
|
||||||
<Sidebar.Header className="layer-ui__library-header">
|
|
||||||
<LibraryMenuHeader
|
|
||||||
appState={appState}
|
|
||||||
setAppState={setAppState}
|
|
||||||
selectedItems={selectedItems}
|
|
||||||
onSelectItems={setSelectedItems}
|
|
||||||
library={library}
|
|
||||||
onRemoveFromLibrary={() =>
|
|
||||||
removeFromLibrary(libraryItemsData.libraryItems)
|
|
||||||
}
|
|
||||||
resetLibrary={resetLibrary}
|
|
||||||
/>
|
|
||||||
</Sidebar.Header>
|
|
||||||
<LibraryMenuContent
|
|
||||||
pendingElements={getSelectedElements(elements, appState, true)}
|
|
||||||
onInsertLibraryItems={(libraryItems) => {
|
|
||||||
onInsertElements(distributeLibraryItemsOnSquareGrid(libraryItems));
|
|
||||||
}}
|
|
||||||
onAddToLibrary={deselectItems}
|
|
||||||
setAppState={setAppState}
|
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
|
||||||
library={library}
|
|
||||||
id={id}
|
|
||||||
appState={appState}
|
|
||||||
selectedItems={selectedItems}
|
|
||||||
onSelectItems={setSelectedItems}
|
|
||||||
/>
|
|
||||||
</Sidebar>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
import { VERSIONS } from "../constants";
|
|
||||||
import { t } from "../i18n";
|
|
||||||
import { AppState, ExcalidrawProps } from "../types";
|
|
||||||
|
|
||||||
const LibraryMenuBrowseButton = ({
|
|
||||||
theme,
|
|
||||||
id,
|
|
||||||
libraryReturnUrl,
|
|
||||||
}: {
|
|
||||||
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
|
||||||
theme: AppState["theme"];
|
|
||||||
id: string;
|
|
||||||
}) => {
|
|
||||||
const referrer =
|
|
||||||
libraryReturnUrl || window.location.origin + window.location.pathname;
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
className="library-menu-browse-button"
|
|
||||||
href={`${process.env.REACT_APP_LIBRARY_URL}?target=${
|
|
||||||
window.name || "_blank"
|
|
||||||
}&referrer=${referrer}&useHash=true&token=${id}&theme=${theme}&version=${
|
|
||||||
VERSIONS.excalidrawLibrary
|
|
||||||
}`}
|
|
||||||
target="_excalidraw_libraries"
|
|
||||||
>
|
|
||||||
{t("labels.libraries")}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LibraryMenuBrowseButton;
|
|
||||||
@@ -1,257 +0,0 @@
|
|||||||
import React, { useCallback, useState } from "react";
|
|
||||||
import { saveLibraryAsJSON } from "../data/json";
|
|
||||||
import Library, { libraryItemsAtom } from "../data/library";
|
|
||||||
import { t } from "../i18n";
|
|
||||||
import { AppState, LibraryItem, LibraryItems } from "../types";
|
|
||||||
import {
|
|
||||||
DotsIcon,
|
|
||||||
ExportIcon,
|
|
||||||
LoadIcon,
|
|
||||||
publishIcon,
|
|
||||||
TrashIcon,
|
|
||||||
} from "./icons";
|
|
||||||
import { ToolButton } from "./ToolButton";
|
|
||||||
import { fileOpen } from "../data/filesystem";
|
|
||||||
import { muteFSAbortError } from "../utils";
|
|
||||||
import { useAtom } from "jotai";
|
|
||||||
import { jotaiScope } from "../jotai";
|
|
||||||
import ConfirmDialog from "./ConfirmDialog";
|
|
||||||
import PublishLibrary from "./PublishLibrary";
|
|
||||||
import { Dialog } from "./Dialog";
|
|
||||||
import { useOutsideClickHook } from "../hooks/useOutsideClick";
|
|
||||||
import MenuItem from "./MenuItem";
|
|
||||||
import { isDropdownOpenAtom } from "./App";
|
|
||||||
|
|
||||||
const getSelectedItems = (
|
|
||||||
libraryItems: LibraryItems,
|
|
||||||
selectedItems: LibraryItem["id"][],
|
|
||||||
) => libraryItems.filter((item) => selectedItems.includes(item.id));
|
|
||||||
|
|
||||||
export const LibraryMenuHeader: React.FC<{
|
|
||||||
setAppState: React.Component<any, AppState>["setState"];
|
|
||||||
selectedItems: LibraryItem["id"][];
|
|
||||||
library: Library;
|
|
||||||
onRemoveFromLibrary: () => void;
|
|
||||||
resetLibrary: () => void;
|
|
||||||
onSelectItems: (items: LibraryItem["id"][]) => void;
|
|
||||||
appState: AppState;
|
|
||||||
}> = ({
|
|
||||||
setAppState,
|
|
||||||
selectedItems,
|
|
||||||
library,
|
|
||||||
onRemoveFromLibrary,
|
|
||||||
resetLibrary,
|
|
||||||
onSelectItems,
|
|
||||||
appState,
|
|
||||||
}) => {
|
|
||||||
const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope);
|
|
||||||
|
|
||||||
const renderRemoveLibAlert = useCallback(() => {
|
|
||||||
const content = selectedItems.length
|
|
||||||
? t("alerts.removeItemsFromsLibrary", { count: selectedItems.length })
|
|
||||||
: t("alerts.resetLibrary");
|
|
||||||
const title = selectedItems.length
|
|
||||||
? t("confirmDialog.removeItemsFromLib")
|
|
||||||
: t("confirmDialog.resetLibrary");
|
|
||||||
return (
|
|
||||||
<ConfirmDialog
|
|
||||||
onConfirm={() => {
|
|
||||||
if (selectedItems.length) {
|
|
||||||
onRemoveFromLibrary();
|
|
||||||
} else {
|
|
||||||
resetLibrary();
|
|
||||||
}
|
|
||||||
setShowRemoveLibAlert(false);
|
|
||||||
}}
|
|
||||||
onCancel={() => {
|
|
||||||
setShowRemoveLibAlert(false);
|
|
||||||
}}
|
|
||||||
title={title}
|
|
||||||
>
|
|
||||||
<p>{content}</p>
|
|
||||||
</ConfirmDialog>
|
|
||||||
);
|
|
||||||
}, [selectedItems, onRemoveFromLibrary, resetLibrary]);
|
|
||||||
|
|
||||||
const [showRemoveLibAlert, setShowRemoveLibAlert] = useState(false);
|
|
||||||
|
|
||||||
const itemsSelected = !!selectedItems.length;
|
|
||||||
const items = itemsSelected
|
|
||||||
? libraryItemsData.libraryItems.filter((item) =>
|
|
||||||
selectedItems.includes(item.id),
|
|
||||||
)
|
|
||||||
: libraryItemsData.libraryItems;
|
|
||||||
const resetLabel = itemsSelected
|
|
||||||
? t("buttons.remove")
|
|
||||||
: t("buttons.resetLibrary");
|
|
||||||
|
|
||||||
const [showPublishLibraryDialog, setShowPublishLibraryDialog] =
|
|
||||||
useState(false);
|
|
||||||
const [publishLibSuccess, setPublishLibSuccess] = useState<null | {
|
|
||||||
url: string;
|
|
||||||
authorName: string;
|
|
||||||
}>(null);
|
|
||||||
const renderPublishSuccess = useCallback(() => {
|
|
||||||
return (
|
|
||||||
<Dialog
|
|
||||||
onCloseRequest={() => setPublishLibSuccess(null)}
|
|
||||||
title={t("publishSuccessDialog.title")}
|
|
||||||
className="publish-library-success"
|
|
||||||
small={true}
|
|
||||||
>
|
|
||||||
<p>
|
|
||||||
{t("publishSuccessDialog.content", {
|
|
||||||
authorName: publishLibSuccess!.authorName,
|
|
||||||
})}{" "}
|
|
||||||
<a
|
|
||||||
href={publishLibSuccess?.url}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
{t("publishSuccessDialog.link")}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<ToolButton
|
|
||||||
type="button"
|
|
||||||
title={t("buttons.close")}
|
|
||||||
aria-label={t("buttons.close")}
|
|
||||||
label={t("buttons.close")}
|
|
||||||
onClick={() => setPublishLibSuccess(null)}
|
|
||||||
data-testid="publish-library-success-close"
|
|
||||||
className="publish-library-success-close"
|
|
||||||
/>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}, [setPublishLibSuccess, publishLibSuccess]);
|
|
||||||
|
|
||||||
const onPublishLibSuccess = useCallback(
|
|
||||||
(data: { url: string; authorName: string }, libraryItems: LibraryItems) => {
|
|
||||||
setShowPublishLibraryDialog(false);
|
|
||||||
setPublishLibSuccess({ url: data.url, authorName: data.authorName });
|
|
||||||
const nextLibItems = libraryItems.slice();
|
|
||||||
nextLibItems.forEach((libItem) => {
|
|
||||||
if (selectedItems.includes(libItem.id)) {
|
|
||||||
libItem.status = "published";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
library.setLibrary(nextLibItems);
|
|
||||||
},
|
|
||||||
[setShowPublishLibraryDialog, setPublishLibSuccess, selectedItems, library],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onLibraryImport = async () => {
|
|
||||||
try {
|
|
||||||
await library.updateLibrary({
|
|
||||||
libraryItems: fileOpen({
|
|
||||||
description: "Excalidraw library files",
|
|
||||||
// ToDo: Be over-permissive until https://bugs.webkit.org/show_bug.cgi?id=34442
|
|
||||||
// gets resolved. Else, iOS users cannot open `.excalidraw` files.
|
|
||||||
/*
|
|
||||||
extensions: [".json", ".excalidrawlib"],
|
|
||||||
*/
|
|
||||||
}),
|
|
||||||
merge: true,
|
|
||||||
openLibraryMenu: true,
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error?.name === "AbortError") {
|
|
||||||
console.warn(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setAppState({ errorMessage: t("errors.importLibraryError") });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onLibraryExport = async () => {
|
|
||||||
const libraryItems = itemsSelected
|
|
||||||
? items
|
|
||||||
: await library.getLatestLibrary();
|
|
||||||
saveLibraryAsJSON(libraryItems)
|
|
||||||
.catch(muteFSAbortError)
|
|
||||||
.catch((error) => {
|
|
||||||
setAppState({ errorMessage: error.message });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const [isDropdownOpen, setIsDropdownOpen] = useAtom(isDropdownOpenAtom);
|
|
||||||
const dropdownRef = useOutsideClickHook(() => setIsDropdownOpen(false));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ position: "relative" }}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="Sidebar__dropdown-btn"
|
|
||||||
data-prevent-outside-click
|
|
||||||
onClick={() => setIsDropdownOpen(!isDropdownOpen)}
|
|
||||||
>
|
|
||||||
{DotsIcon}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{selectedItems.length > 0 && (
|
|
||||||
<div className="library-actions-counter">{selectedItems.length}</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{isDropdownOpen && (
|
|
||||||
<div
|
|
||||||
className="Sidebar__dropdown-content menu-container"
|
|
||||||
ref={dropdownRef}
|
|
||||||
>
|
|
||||||
{!itemsSelected && (
|
|
||||||
<MenuItem
|
|
||||||
label={t("buttons.load")}
|
|
||||||
icon={LoadIcon}
|
|
||||||
dataTestId="lib-dropdown--load"
|
|
||||||
onClick={onLibraryImport}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{showRemoveLibAlert && renderRemoveLibAlert()}
|
|
||||||
{showPublishLibraryDialog && (
|
|
||||||
<PublishLibrary
|
|
||||||
onClose={() => setShowPublishLibraryDialog(false)}
|
|
||||||
libraryItems={getSelectedItems(
|
|
||||||
libraryItemsData.libraryItems,
|
|
||||||
selectedItems,
|
|
||||||
)}
|
|
||||||
appState={appState}
|
|
||||||
onSuccess={(data) =>
|
|
||||||
onPublishLibSuccess(data, libraryItemsData.libraryItems)
|
|
||||||
}
|
|
||||||
onError={(error) => window.alert(error)}
|
|
||||||
updateItemsInStorage={() =>
|
|
||||||
library.setLibrary(libraryItemsData.libraryItems)
|
|
||||||
}
|
|
||||||
onRemove={(id: string) =>
|
|
||||||
onSelectItems(selectedItems.filter((_id) => _id !== id))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{publishLibSuccess && renderPublishSuccess()}
|
|
||||||
{!!items.length && (
|
|
||||||
<>
|
|
||||||
<MenuItem
|
|
||||||
label={t("buttons.export")}
|
|
||||||
icon={ExportIcon}
|
|
||||||
onClick={onLibraryExport}
|
|
||||||
dataTestId="lib-dropdown--export"
|
|
||||||
/>
|
|
||||||
<MenuItem
|
|
||||||
label={resetLabel}
|
|
||||||
icon={TrashIcon}
|
|
||||||
onClick={() => setShowRemoveLibAlert(true)}
|
|
||||||
dataTestId="lib-dropdown--remove"
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{itemsSelected && (
|
|
||||||
<MenuItem
|
|
||||||
label={t("buttons.publishLibrary")}
|
|
||||||
icon={publishIcon}
|
|
||||||
dataTestId="lib-dropdown--publish"
|
|
||||||
onClick={() => setShowPublishLibraryDialog(true)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,70 +1,107 @@
|
|||||||
@import "open-color/open-color";
|
@import "open-color/open-color";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
--container-padding-y: 1.5rem;
|
|
||||||
--container-padding-x: 0.75rem;
|
|
||||||
|
|
||||||
.library-menu-items__no-items {
|
|
||||||
text-align: center;
|
|
||||||
color: var(--color-gray-70);
|
|
||||||
line-height: 1.5;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
&__label {
|
|
||||||
color: var(--color-primary);
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 1.125rem;
|
|
||||||
margin-bottom: 0.75rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
.library-menu-items__no-items {
|
|
||||||
color: var(--color-gray-40);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.library-menu-items-container {
|
.library-menu-items-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-grow: 1;
|
|
||||||
flex-shrink: 1;
|
|
||||||
flex-basis: 0;
|
|
||||||
overflow-y: auto;
|
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
justify-content: center;
|
padding: 0.5rem;
|
||||||
margin: 0;
|
box-sizing: border-box;
|
||||||
border-bottom: 1px solid var(--sidebar-border-color);
|
|
||||||
|
|
||||||
position: relative;
|
.library-actions {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
margin-right: auto;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
&__row {
|
button .library-actions-counter {
|
||||||
display: grid;
|
position: absolute;
|
||||||
grid-template-columns: repeat(4, 1fr);
|
right: 2px;
|
||||||
gap: 1rem;
|
bottom: 2px;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
padding: 1px;
|
||||||
|
font-size: 0.7rem;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--remove {
|
||||||
|
background-color: $oc-red-7;
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-red-8;
|
||||||
|
}
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-red-9;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
.library-actions-counter {
|
||||||
|
color: $oc-red-7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--export {
|
||||||
|
background-color: $oc-lime-5;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-lime-7;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-lime-8;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
.library-actions-counter {
|
||||||
|
color: $oc-lime-5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--publish {
|
||||||
|
background-color: $oc-cyan-6;
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-cyan-7;
|
||||||
|
}
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-cyan-9;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
margin-left: -0.2em;
|
||||||
|
margin-right: 1.1em;
|
||||||
|
color: $oc-white;
|
||||||
|
font-size: 0.86em;
|
||||||
|
}
|
||||||
|
.library-actions-counter {
|
||||||
|
color: $oc-cyan-6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--load {
|
||||||
|
background-color: $oc-blue-6;
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-blue-7;
|
||||||
|
}
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-blue-9;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__items {
|
&__items {
|
||||||
row-gap: 0.5rem;
|
|
||||||
padding: var(--container-padding-y) var(--container-padding-x);
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__header {
|
|
||||||
color: var(--color-primary);
|
|
||||||
font-size: 1.125rem;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-bottom: 0.75rem;
|
|
||||||
|
|
||||||
&--excal {
|
|
||||||
margin-top: 2.5rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.separator {
|
.separator {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,43 +1,226 @@
|
|||||||
import React, { useState } from "react";
|
import { chunk } from "lodash";
|
||||||
import { serializeLibraryAsJSON } from "../data/json";
|
import React, { useCallback, useState } from "react";
|
||||||
|
import { saveLibraryAsJSON, serializeLibraryAsJSON } from "../data/json";
|
||||||
|
import Library from "../data/library";
|
||||||
import { ExcalidrawElement, NonDeleted } from "../element/types";
|
import { ExcalidrawElement, NonDeleted } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { AppState, ExcalidrawProps, LibraryItem, LibraryItems } from "../types";
|
import {
|
||||||
import { arrayToMap, chunk } from "../utils";
|
AppState,
|
||||||
|
BinaryFiles,
|
||||||
|
ExcalidrawProps,
|
||||||
|
LibraryItem,
|
||||||
|
LibraryItems,
|
||||||
|
} from "../types";
|
||||||
|
import { arrayToMap, muteFSAbortError } from "../utils";
|
||||||
|
import { useDevice } from "./App";
|
||||||
|
import ConfirmDialog from "./ConfirmDialog";
|
||||||
|
import { close, exportToFileIcon, load, publishIcon, trash } from "./icons";
|
||||||
import { LibraryUnit } from "./LibraryUnit";
|
import { LibraryUnit } from "./LibraryUnit";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
|
import { Tooltip } from "./Tooltip";
|
||||||
|
|
||||||
import "./LibraryMenuItems.scss";
|
import "./LibraryMenuItems.scss";
|
||||||
import { MIME_TYPES } from "../constants";
|
import { MIME_TYPES, VERSIONS } from "../constants";
|
||||||
import Spinner from "./Spinner";
|
import Spinner from "./Spinner";
|
||||||
import LibraryMenuBrowseButton from "./LibraryMenuBrowseButton";
|
import { fileOpen } from "../data/filesystem";
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
const CELLS_PER_ROW = 4;
|
import { SidebarLockButton } from "./SidebarLockButton";
|
||||||
|
import { trackEvent } from "../analytics";
|
||||||
|
|
||||||
const LibraryMenuItems = ({
|
const LibraryMenuItems = ({
|
||||||
isLoading,
|
isLoading,
|
||||||
libraryItems,
|
libraryItems,
|
||||||
|
onRemoveFromLibrary,
|
||||||
onAddToLibrary,
|
onAddToLibrary,
|
||||||
onInsertLibraryItems,
|
onInsertLibraryItems,
|
||||||
pendingElements,
|
pendingElements,
|
||||||
|
theme,
|
||||||
|
setAppState,
|
||||||
|
appState,
|
||||||
|
libraryReturnUrl,
|
||||||
|
library,
|
||||||
|
files,
|
||||||
|
id,
|
||||||
selectedItems,
|
selectedItems,
|
||||||
onSelectItems,
|
onSelectItems,
|
||||||
theme,
|
onPublish,
|
||||||
id,
|
resetLibrary,
|
||||||
libraryReturnUrl,
|
|
||||||
}: {
|
}: {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
libraryItems: LibraryItems;
|
libraryItems: LibraryItems;
|
||||||
pendingElements: LibraryItem["elements"];
|
pendingElements: LibraryItem["elements"];
|
||||||
|
onRemoveFromLibrary: () => void;
|
||||||
onInsertLibraryItems: (libraryItems: LibraryItems) => void;
|
onInsertLibraryItems: (libraryItems: LibraryItems) => void;
|
||||||
onAddToLibrary: (elements: LibraryItem["elements"]) => void;
|
onAddToLibrary: (elements: LibraryItem["elements"]) => void;
|
||||||
|
theme: AppState["theme"];
|
||||||
|
files: BinaryFiles;
|
||||||
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
|
appState: AppState;
|
||||||
|
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
||||||
|
library: Library;
|
||||||
|
id: string;
|
||||||
selectedItems: LibraryItem["id"][];
|
selectedItems: LibraryItem["id"][];
|
||||||
onSelectItems: (id: LibraryItem["id"][]) => void;
|
onSelectItems: (id: LibraryItem["id"][]) => void;
|
||||||
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
onPublish: () => void;
|
||||||
theme: AppState["theme"];
|
resetLibrary: () => void;
|
||||||
id: string;
|
|
||||||
}) => {
|
}) => {
|
||||||
|
const renderRemoveLibAlert = useCallback(() => {
|
||||||
|
const content = selectedItems.length
|
||||||
|
? t("alerts.removeItemsFromsLibrary", { count: selectedItems.length })
|
||||||
|
: t("alerts.resetLibrary");
|
||||||
|
const title = selectedItems.length
|
||||||
|
? t("confirmDialog.removeItemsFromLib")
|
||||||
|
: t("confirmDialog.resetLibrary");
|
||||||
|
return (
|
||||||
|
<ConfirmDialog
|
||||||
|
onConfirm={() => {
|
||||||
|
if (selectedItems.length) {
|
||||||
|
onRemoveFromLibrary();
|
||||||
|
} else {
|
||||||
|
resetLibrary();
|
||||||
|
}
|
||||||
|
setShowRemoveLibAlert(false);
|
||||||
|
}}
|
||||||
|
onCancel={() => {
|
||||||
|
setShowRemoveLibAlert(false);
|
||||||
|
}}
|
||||||
|
title={title}
|
||||||
|
>
|
||||||
|
<p>{content}</p>
|
||||||
|
</ConfirmDialog>
|
||||||
|
);
|
||||||
|
}, [selectedItems, onRemoveFromLibrary, resetLibrary]);
|
||||||
|
|
||||||
|
const [showRemoveLibAlert, setShowRemoveLibAlert] = useState(false);
|
||||||
|
const device = useDevice();
|
||||||
|
const renderLibraryActions = () => {
|
||||||
|
const itemsSelected = !!selectedItems.length;
|
||||||
|
const items = itemsSelected
|
||||||
|
? libraryItems.filter((item) => selectedItems.includes(item.id))
|
||||||
|
: libraryItems;
|
||||||
|
const resetLabel = itemsSelected
|
||||||
|
? t("buttons.remove")
|
||||||
|
: t("buttons.resetLibrary");
|
||||||
|
return (
|
||||||
|
<div className="library-actions">
|
||||||
|
{!itemsSelected && (
|
||||||
|
<ToolButton
|
||||||
|
key="import"
|
||||||
|
type="button"
|
||||||
|
title={t("buttons.load")}
|
||||||
|
aria-label={t("buttons.load")}
|
||||||
|
icon={load}
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
await library.updateLibrary({
|
||||||
|
libraryItems: fileOpen({
|
||||||
|
description: "Excalidraw library files",
|
||||||
|
// ToDo: Be over-permissive until https://bugs.webkit.org/show_bug.cgi?id=34442
|
||||||
|
// gets resolved. Else, iOS users cannot open `.excalidraw` files.
|
||||||
|
/*
|
||||||
|
extensions: [".json", ".excalidrawlib"],
|
||||||
|
*/
|
||||||
|
}),
|
||||||
|
merge: true,
|
||||||
|
openLibraryMenu: true,
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error?.name === "AbortError") {
|
||||||
|
console.warn(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAppState({ errorMessage: t("errors.importLibraryError") });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="library-actions--load"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!!items.length && (
|
||||||
|
<>
|
||||||
|
<ToolButton
|
||||||
|
key="export"
|
||||||
|
type="button"
|
||||||
|
title={t("buttons.export")}
|
||||||
|
aria-label={t("buttons.export")}
|
||||||
|
icon={exportToFileIcon}
|
||||||
|
onClick={async () => {
|
||||||
|
const libraryItems = itemsSelected
|
||||||
|
? items
|
||||||
|
: await library.getLatestLibrary();
|
||||||
|
saveLibraryAsJSON(libraryItems)
|
||||||
|
.catch(muteFSAbortError)
|
||||||
|
.catch((error) => {
|
||||||
|
setAppState({ errorMessage: error.message });
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
className="library-actions--export"
|
||||||
|
>
|
||||||
|
{selectedItems.length > 0 && (
|
||||||
|
<span className="library-actions-counter">
|
||||||
|
{selectedItems.length}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</ToolButton>
|
||||||
|
<ToolButton
|
||||||
|
key="reset"
|
||||||
|
type="button"
|
||||||
|
title={resetLabel}
|
||||||
|
aria-label={resetLabel}
|
||||||
|
icon={trash}
|
||||||
|
onClick={() => setShowRemoveLibAlert(true)}
|
||||||
|
className="library-actions--remove"
|
||||||
|
>
|
||||||
|
{selectedItems.length > 0 && (
|
||||||
|
<span className="library-actions-counter">
|
||||||
|
{selectedItems.length}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</ToolButton>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{itemsSelected && (
|
||||||
|
<Tooltip label={t("hints.publishLibrary")}>
|
||||||
|
<ToolButton
|
||||||
|
type="button"
|
||||||
|
aria-label={t("buttons.publishLibrary")}
|
||||||
|
label={t("buttons.publishLibrary")}
|
||||||
|
icon={publishIcon}
|
||||||
|
className="library-actions--publish"
|
||||||
|
onClick={onPublish}
|
||||||
|
>
|
||||||
|
{!device.isMobile && <label>{t("buttons.publishLibrary")}</label>}
|
||||||
|
{selectedItems.length > 0 && (
|
||||||
|
<span className="library-actions-counter">
|
||||||
|
{selectedItems.length}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</ToolButton>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
{device.isMobile && (
|
||||||
|
<div className="library-menu-browse-button--mobile">
|
||||||
|
<a
|
||||||
|
href={`${process.env.REACT_APP_LIBRARY_URL}?target=${
|
||||||
|
window.name || "_blank"
|
||||||
|
}&referrer=${referrer}&useHash=true&token=${id}&theme=${theme}&version=${
|
||||||
|
VERSIONS.excalidrawLibrary
|
||||||
|
}`}
|
||||||
|
target="_excalidraw_libraries"
|
||||||
|
>
|
||||||
|
{t("labels.libraries")}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const CELLS_PER_ROW = device.isMobile && !device.isSmScreen ? 6 : 4;
|
||||||
|
|
||||||
|
const referrer =
|
||||||
|
libraryReturnUrl || window.location.origin + window.location.pathname;
|
||||||
|
|
||||||
const [lastSelectedItem, setLastSelectedItem] = useState<
|
const [lastSelectedItem, setLastSelectedItem] = useState<
|
||||||
LibraryItem["id"] | null
|
LibraryItem["id"] | null
|
||||||
>(null);
|
>(null);
|
||||||
@@ -114,6 +297,7 @@ const LibraryMenuItems = ({
|
|||||||
<Stack.Col key={params.key}>
|
<Stack.Col key={params.key}>
|
||||||
<LibraryUnit
|
<LibraryUnit
|
||||||
elements={params.item?.elements}
|
elements={params.item?.elements}
|
||||||
|
files={files}
|
||||||
isPending={!params.item?.id && !!params.item?.elements}
|
isPending={!params.item?.id && !!params.item?.elements}
|
||||||
onClick={params.onClick || (() => {})}
|
onClick={params.onClick || (() => {})}
|
||||||
id={params.item?.id || null}
|
id={params.item?.id || null}
|
||||||
@@ -175,11 +359,7 @@ const LibraryMenuItems = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Stack.Row
|
<Stack.Row align="center" gap={1} key={index}>
|
||||||
align="center"
|
|
||||||
key={index}
|
|
||||||
className="library-menu-items-container__row"
|
|
||||||
>
|
|
||||||
{rowItems}
|
{rowItems}
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
);
|
);
|
||||||
@@ -193,23 +373,56 @@ const LibraryMenuItems = ({
|
|||||||
(item) => item.status === "published",
|
(item) => item.status === "published",
|
||||||
);
|
);
|
||||||
|
|
||||||
const showBtn =
|
const renderLibraryHeader = () => {
|
||||||
!libraryItems.length &&
|
return (
|
||||||
!unpublishedItems.length &&
|
<>
|
||||||
!publishedItems.length &&
|
<div className="layer-ui__library-header" key="library-header">
|
||||||
!pendingElements.length;
|
{renderLibraryActions()}
|
||||||
|
{device.canDeviceFitSidebar && (
|
||||||
|
<>
|
||||||
|
<div className="layer-ui__sidebar-lock-button">
|
||||||
|
<SidebarLockButton
|
||||||
|
checked={appState.isLibraryMenuDocked}
|
||||||
|
onChange={() => {
|
||||||
|
document
|
||||||
|
.querySelector(".layer-ui__wrapper")
|
||||||
|
?.classList.add("animate");
|
||||||
|
const nextState = !appState.isLibraryMenuDocked;
|
||||||
|
setAppState({
|
||||||
|
isLibraryMenuDocked: nextState,
|
||||||
|
});
|
||||||
|
trackEvent(
|
||||||
|
"library",
|
||||||
|
`toggleLibraryDock (${nextState ? "dock" : "undock"})`,
|
||||||
|
`sidebar (${device.isMobile ? "mobile" : "desktop"})`,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{!device.isMobile && (
|
||||||
|
<div className="ToolIcon__icon__close">
|
||||||
|
<button
|
||||||
|
className="Modal__close"
|
||||||
|
onClick={() =>
|
||||||
|
setAppState({
|
||||||
|
isLibraryOpen: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
aria-label={t("buttons.close")}
|
||||||
|
>
|
||||||
|
{close}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
const renderLibraryMenuItems = () => {
|
||||||
<div
|
return (
|
||||||
className="library-menu-items-container"
|
|
||||||
style={
|
|
||||||
pendingElements.length ||
|
|
||||||
unpublishedItems.length ||
|
|
||||||
publishedItems.length
|
|
||||||
? { justifyContent: "flex-start" }
|
|
||||||
: {}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Stack.Col
|
<Stack.Col
|
||||||
className="library-menu-items-container__items"
|
className="library-menu-items-container__items"
|
||||||
align="start"
|
align="start"
|
||||||
@@ -220,37 +433,49 @@ const LibraryMenuItems = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<div>
|
<div className="separator">
|
||||||
{(pendingElements.length > 0 ||
|
{(pendingElements.length > 0 ||
|
||||||
unpublishedItems.length > 0 ||
|
unpublishedItems.length > 0 ||
|
||||||
publishedItems.length > 0) && (
|
publishedItems.length > 0) && (
|
||||||
<div className="library-menu-items-container__header">
|
<div>{t("labels.personalLib")}</div>
|
||||||
{t("labels.personalLib")}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
position: "absolute",
|
marginLeft: "auto",
|
||||||
top: "var(--container-padding-y)",
|
marginRight: "1rem",
|
||||||
right: "var(--container-padding-x)",
|
display: "flex",
|
||||||
transform: "translateY(50%)",
|
alignItems: "center",
|
||||||
|
fontWeight: "normal",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Spinner />
|
<div style={{ transform: "translateY(2px)" }}>
|
||||||
|
<Spinner />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!pendingElements.length && !unpublishedItems.length ? (
|
{!pendingElements.length && !unpublishedItems.length ? (
|
||||||
<div className="library-menu-items__no-items">
|
<div
|
||||||
|
style={{
|
||||||
|
height: 65,
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
width: "100%",
|
||||||
|
fontSize: ".9rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("library.noItems")}
|
||||||
<div
|
<div
|
||||||
className={clsx({
|
style={{
|
||||||
"library-menu-items__no-items__label": showBtn,
|
margin: ".6rem 0",
|
||||||
})}
|
fontSize: ".8em",
|
||||||
|
width: "70%",
|
||||||
|
textAlign: "center",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{t("library.noItems")}
|
|
||||||
</div>
|
|
||||||
<div className="library-menu-items__no-items__hint">
|
|
||||||
{publishedItems.length > 0
|
{publishedItems.length > 0
|
||||||
? t("library.hint_emptyPrivateLibrary")
|
? t("library.hint_emptyPrivateLibrary")
|
||||||
: t("library.hint_emptyLibrary")}
|
: t("library.hint_emptyLibrary")}
|
||||||
@@ -269,11 +494,9 @@ const LibraryMenuItems = ({
|
|||||||
|
|
||||||
<>
|
<>
|
||||||
{(publishedItems.length > 0 ||
|
{(publishedItems.length > 0 ||
|
||||||
pendingElements.length > 0 ||
|
(!device.isMobile &&
|
||||||
unpublishedItems.length > 0) && (
|
(pendingElements.length > 0 || unpublishedItems.length > 0))) && (
|
||||||
<div className="library-menu-items-container__header library-menu-items-container__header--excal">
|
<div className="separator">{t("labels.excalidrawLib")}</div>
|
||||||
{t("labels.excalidrawLib")}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
{publishedItems.length > 0 ? (
|
{publishedItems.length > 0 ? (
|
||||||
renderLibrarySection(publishedItems)
|
renderLibrarySection(publishedItems)
|
||||||
@@ -293,15 +516,42 @@ const LibraryMenuItems = ({
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
|
|
||||||
{showBtn && (
|
|
||||||
<LibraryMenuBrowseButton
|
|
||||||
id={id}
|
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
|
||||||
theme={theme}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderLibraryFooter = () => {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
className="library-menu-browse-button"
|
||||||
|
href={`${process.env.REACT_APP_LIBRARY_URL}?target=${
|
||||||
|
window.name || "_blank"
|
||||||
|
}&referrer=${referrer}&useHash=true&token=${id}&theme=${theme}&version=${
|
||||||
|
VERSIONS.excalidrawLibrary
|
||||||
|
}`}
|
||||||
|
target="_excalidraw_libraries"
|
||||||
|
>
|
||||||
|
{t("labels.libraries")}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="library-menu-items-container"
|
||||||
|
style={
|
||||||
|
device.isMobile
|
||||||
|
? {
|
||||||
|
minHeight: "200px",
|
||||||
|
maxHeight: "70vh",
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{showRemoveLibAlert && renderRemoveLibAlert()}
|
||||||
|
{renderLibraryHeader()}
|
||||||
|
{renderLibraryMenuItems()}
|
||||||
|
{!device.isMobile && renderLibraryFooter()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,18 +7,17 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 55px;
|
width: 63px;
|
||||||
height: 55px;
|
height: 63px; // match width
|
||||||
box-sizing: border-box;
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
|
|
||||||
&--hover {
|
&--hover {
|
||||||
border-color: var(--color-primary);
|
box-shadow: inset 0px 0px 0px 2px $oc-blue-5;
|
||||||
|
border-color: $oc-blue-5;
|
||||||
}
|
}
|
||||||
|
|
||||||
&--selected {
|
&--selected {
|
||||||
border-color: var(--color-primary);
|
box-shadow: inset 0px 0px 0px 2px $oc-blue-8;
|
||||||
border-width: 1px;
|
border-color: $oc-blue-8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,34 +59,20 @@
|
|||||||
|
|
||||||
.library-unit__checkbox {
|
.library-unit__checkbox {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0.125rem;
|
left: 2.3rem;
|
||||||
right: 0.125rem;
|
bottom: 2.3rem;
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
.Checkbox-box {
|
.Checkbox-box {
|
||||||
margin: 0;
|
width: 13px;
|
||||||
width: 1rem;
|
height: 13px;
|
||||||
height: 1rem;
|
border-radius: 2px;
|
||||||
border-radius: 4px;
|
margin: 0.5em 0.5em 0.2em 0.2em;
|
||||||
background-color: var(--color-primary-light);
|
background-color: $oc-blue-1;
|
||||||
border: 1px solid var(--color-primary);
|
|
||||||
box-shadow: none !important;
|
|
||||||
padding: 2px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.Checkbox:hover {
|
&.Checkbox:hover {
|
||||||
.Checkbox-box {
|
.Checkbox-box {
|
||||||
background-color: var(--color-primary-light);
|
background-color: $oc-blue-2;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.is-checked {
|
|
||||||
.Checkbox-box {
|
|
||||||
background-color: var(--color-primary) !important;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
color: var(--color-primary-light);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,29 +85,25 @@
|
|||||||
.library-unit__adder {
|
.library-unit__adder {
|
||||||
transform: scale(1);
|
transform: scale(1);
|
||||||
animation: library-unit__adder-animation 1s ease-in infinite;
|
animation: library-unit__adder-animation 1s ease-in infinite;
|
||||||
|
|
||||||
position: absolute;
|
|
||||||
width: 1.5rem;
|
|
||||||
height: 1.5rem;
|
|
||||||
background-color: var(--color-primary);
|
|
||||||
border-radius: var(--border-radius-md);
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
pointer-events: none;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
color: var(--color-primary-light);
|
|
||||||
width: 1rem;
|
|
||||||
height: 1rem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.library-unit__adder {
|
||||||
|
position: absolute;
|
||||||
|
left: 40%;
|
||||||
|
top: 40%;
|
||||||
|
width: 2rem;
|
||||||
|
height: 2rem;
|
||||||
|
margin-left: -10px;
|
||||||
|
margin-top: -10px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.library-unit:hover .library-unit__adder {
|
||||||
|
fill: $oc-blue-7;
|
||||||
|
}
|
||||||
.library-unit:active .library-unit__adder {
|
.library-unit:active .library-unit__adder {
|
||||||
animation: none;
|
animation: none;
|
||||||
transform: scale(0.8);
|
transform: scale(0.8);
|
||||||
|
fill: $oc-black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.library-unit__active {
|
.library-unit__active {
|
||||||
|
|||||||
@@ -3,14 +3,27 @@ import oc from "open-color";
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useDevice } from "../components/App";
|
import { useDevice } from "../components/App";
|
||||||
import { exportToSvg } from "../scene/export";
|
import { exportToSvg } from "../scene/export";
|
||||||
import { LibraryItem } from "../types";
|
import { BinaryFiles, LibraryItem } from "../types";
|
||||||
import "./LibraryUnit.scss";
|
import "./LibraryUnit.scss";
|
||||||
import { CheckboxItem } from "./CheckboxItem";
|
import { CheckboxItem } from "./CheckboxItem";
|
||||||
import { PlusIcon } from "./icons";
|
|
||||||
|
const PLUS_ICON = (
|
||||||
|
<svg viewBox="0 0 1792 1792">
|
||||||
|
<path
|
||||||
|
d="M1600 736v192c0 26.667-9.33 49.333-28 68-18.67 18.67-41.33 28-68 28h-416v416c0 26.67-9.33 49.33-28 68s-41.33 28-68 28H800c-26.667 0-49.333-9.33-68-28s-28-41.33-28-68v-416H288c-26.667 0-49.333-9.33-68-28-18.667-18.667-28-41.333-28-68V736c0-26.667 9.333-49.333 28-68s41.333-28 68-28h416V224c0-26.667 9.333-49.333 28-68s41.333-28 68-28h192c26.67 0 49.33 9.333 68 28s28 41.333 28 68v416h416c26.67 0 49.33 9.333 68 28s28 41.333 28 68Z"
|
||||||
|
style={{
|
||||||
|
stroke: "#fff",
|
||||||
|
strokeWidth: 140,
|
||||||
|
}}
|
||||||
|
transform="translate(0 64)"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
export const LibraryUnit = ({
|
export const LibraryUnit = ({
|
||||||
id,
|
id,
|
||||||
elements,
|
elements,
|
||||||
|
files,
|
||||||
isPending,
|
isPending,
|
||||||
onClick,
|
onClick,
|
||||||
selected,
|
selected,
|
||||||
@@ -19,6 +32,7 @@ export const LibraryUnit = ({
|
|||||||
}: {
|
}: {
|
||||||
id: LibraryItem["id"] | /** for pending item */ null;
|
id: LibraryItem["id"] | /** for pending item */ null;
|
||||||
elements?: LibraryItem["elements"];
|
elements?: LibraryItem["elements"];
|
||||||
|
files: BinaryFiles;
|
||||||
isPending?: boolean;
|
isPending?: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
@@ -42,7 +56,7 @@ export const LibraryUnit = ({
|
|||||||
exportBackground: false,
|
exportBackground: false,
|
||||||
viewBackgroundColor: oc.white,
|
viewBackgroundColor: oc.white,
|
||||||
},
|
},
|
||||||
null,
|
files,
|
||||||
);
|
);
|
||||||
node.innerHTML = svg.outerHTML;
|
node.innerHTML = svg.outerHTML;
|
||||||
})();
|
})();
|
||||||
@@ -50,12 +64,12 @@ export const LibraryUnit = ({
|
|||||||
return () => {
|
return () => {
|
||||||
node.innerHTML = "";
|
node.innerHTML = "";
|
||||||
};
|
};
|
||||||
}, [elements]);
|
}, [elements, files]);
|
||||||
|
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const isMobile = useDevice().isMobile;
|
const isMobile = useDevice().isMobile;
|
||||||
const adder = isPending && (
|
const adder = isPending && (
|
||||||
<div className="library-unit__adder">{PlusIcon}</div>
|
<div className="library-unit__adder">{PLUS_ICON}</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import Spinner from "./Spinner";
|
import Spinner from "./Spinner";
|
||||||
import clsx from "clsx";
|
|
||||||
import { THEME } from "../constants";
|
|
||||||
import { Theme } from "../element/types";
|
|
||||||
|
|
||||||
export const LoadingMessage: React.FC<{ delay?: number; theme?: Theme }> = ({
|
export const LoadingMessage: React.FC<{ delay?: number }> = ({ delay }) => {
|
||||||
delay,
|
|
||||||
theme,
|
|
||||||
}) => {
|
|
||||||
const [isWaiting, setIsWaiting] = useState(!!delay);
|
const [isWaiting, setIsWaiting] = useState(!!delay);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -26,11 +20,7 @@ export const LoadingMessage: React.FC<{ delay?: number; theme?: Theme }> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="LoadingMessage">
|
||||||
className={clsx("LoadingMessage", {
|
|
||||||
"LoadingMessage--dark": theme === THEME.DARK,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<div>
|
<div>
|
||||||
<Spinner />
|
<Spinner />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import "./ToolIcon.scss";
|
import "./ToolIcon.scss";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { ToolButtonSize } from "./ToolButton";
|
import { ToolButtonSize } from "./ToolButton";
|
||||||
import { LockedIcon, UnlockedIcon } from "./icons";
|
|
||||||
|
|
||||||
type LockIconProps = {
|
type LockIconProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -16,15 +16,34 @@ type LockIconProps = {
|
|||||||
const DEFAULT_SIZE: ToolButtonSize = "medium";
|
const DEFAULT_SIZE: ToolButtonSize = "medium";
|
||||||
|
|
||||||
const ICONS = {
|
const ICONS = {
|
||||||
CHECKED: LockedIcon,
|
CHECKED: (
|
||||||
UNCHECKED: UnlockedIcon,
|
<svg
|
||||||
|
width="1792"
|
||||||
|
height="1792"
|
||||||
|
viewBox="0 0 1792 1792"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path d="M640 768h512v-192q0-106-75-181t-181-75-181 75-75 181v192zm832 96v576q0 40-28 68t-68 28h-960q-40 0-68-28t-28-68v-576q0-40 28-68t68-28h32v-192q0-184 132-316t316-132 316 132 132 316v192h32q40 0 68 28t28 68z" />
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
|
UNCHECKED: (
|
||||||
|
<svg
|
||||||
|
width="1792"
|
||||||
|
height="1792"
|
||||||
|
viewBox="0 0 1792 1792"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
className="unlocked-icon rtl-mirror"
|
||||||
|
>
|
||||||
|
<path d="M1728 576v256q0 26-19 45t-45 19h-64q-26 0-45-19t-19-45v-256q0-106-75-181t-181-75-181 75-75 181v192h96q40 0 68 28t28 68v576q0 40-28 68t-68 28h-960q-40 0-68-28t-28-68v-576q0-40 28-68t68-28h672v-192q0-185 131.5-316.5t316.5-131.5 316.5 131.5 131.5 316.5z" />
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LockButton = (props: LockIconProps) => {
|
export const LockButton = (props: LockIconProps) => {
|
||||||
return (
|
return (
|
||||||
<label
|
<label
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"ToolIcon ToolIcon__lock",
|
"ToolIcon ToolIcon__lock ToolIcon_type_floating",
|
||||||
`ToolIcon_size_${DEFAULT_SIZE}`,
|
`ToolIcon_size_${DEFAULT_SIZE}`,
|
||||||
{
|
{
|
||||||
"is-mobile": props.isMobile,
|
"is-mobile": props.isMobile,
|
||||||
@@ -39,7 +58,6 @@ export const LockButton = (props: LockIconProps) => {
|
|||||||
onChange={props.onChange}
|
onChange={props.onChange}
|
||||||
checked={props.checked}
|
checked={props.checked}
|
||||||
aria-label={props.title}
|
aria-label={props.title}
|
||||||
data-testid="toolbar-lock"
|
|
||||||
/>
|
/>
|
||||||
<div className="ToolIcon__icon">
|
<div className="ToolIcon__icon">
|
||||||
{props.checked ? ICONS.CHECKED : ICONS.UNCHECKED}
|
{props.checked ? ICONS.CHECKED : ICONS.UNCHECKED}
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
@import "../css/variables.module";
|
|
||||||
|
|
||||||
.excalidraw {
|
|
||||||
.menu-container {
|
|
||||||
background-color: #fff !important;
|
|
||||||
max-height: calc(100vh - 150px);
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-button {
|
|
||||||
@include outlineButtonStyles;
|
|
||||||
background-color: var(--island-bg-color);
|
|
||||||
width: var(--lg-button-size);
|
|
||||||
height: var(--lg-button-size);
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: var(--lg-icon-size);
|
|
||||||
height: var(--lg-icon-size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-item {
|
|
||||||
display: flex;
|
|
||||||
background-color: transparent;
|
|
||||||
border: 0;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0 0.625rem;
|
|
||||||
height: 2rem;
|
|
||||||
column-gap: 0.625rem;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
color: var(--color-gray-100);
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: var(--border-radius-md);
|
|
||||||
width: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
font-weight: normal;
|
|
||||||
font-family: inherit;
|
|
||||||
|
|
||||||
@media screen and (min-width: 1921px) {
|
|
||||||
height: 2.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__text {
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__shortcut {
|
|
||||||
margin-inline-start: auto;
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--button-hover);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: 1rem;
|
|
||||||
height: 1rem;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.active-collab {
|
|
||||||
background-color: #ecfdf5;
|
|
||||||
color: #064e3c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
.menu-item {
|
|
||||||
color: var(--color-gray-40);
|
|
||||||
|
|
||||||
&.active-collab {
|
|
||||||
background-color: #064e3c;
|
|
||||||
color: #ecfdf5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-container {
|
|
||||||
background-color: var(--color-gray-90) !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import "./Menu.scss";
|
|
||||||
|
|
||||||
interface MenuProps {
|
|
||||||
icon: JSX.Element;
|
|
||||||
onClick: () => void;
|
|
||||||
label: string;
|
|
||||||
dataTestId: string;
|
|
||||||
shortcut?: string;
|
|
||||||
isCollaborating?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MenuItem = ({
|
|
||||||
icon,
|
|
||||||
onClick,
|
|
||||||
label,
|
|
||||||
dataTestId,
|
|
||||||
shortcut,
|
|
||||||
isCollaborating,
|
|
||||||
}: MenuProps) => {
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
className={clsx("menu-item", { "active-collab": isCollaborating })}
|
|
||||||
aria-label={label}
|
|
||||||
onClick={onClick}
|
|
||||||
data-testid={dataTestId}
|
|
||||||
title={label}
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
<div className="menu-item__icon">{icon}</div>
|
|
||||||
<div className="menu-item__text">{label}</div>
|
|
||||||
{shortcut && <div className="menu-item__shortcut">{shortcut}</div>}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MenuItem;
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
import { GithubIcon, DiscordIcon, PlusPromoIcon, TwitterIcon } from "./icons";
|
|
||||||
|
|
||||||
export const MenuLinks = () => (
|
|
||||||
<>
|
|
||||||
<a
|
|
||||||
href="https://plus.excalidraw.com/plus?utm_source=excalidraw&utm_medium=app&utm_content=hamburger"
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
className="menu-item"
|
|
||||||
style={{ color: "var(--color-promo)" }}
|
|
||||||
>
|
|
||||||
<div className="menu-item__icon">{PlusPromoIcon}</div>
|
|
||||||
<div className="menu-item__text">Excalidraw+</div>
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
className="menu-item"
|
|
||||||
href="https://github.com/excalidraw/excalidraw"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<div className="menu-item__icon">{GithubIcon}</div>
|
|
||||||
<div className="menu-item__text">GitHub</div>
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
className="menu-item"
|
|
||||||
target="_blank"
|
|
||||||
href="https://discord.gg/UexuTaE"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<div className="menu-item__icon">{DiscordIcon}</div>
|
|
||||||
<div className="menu-item__text">Discord</div>
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
className="menu-item"
|
|
||||||
target="_blank"
|
|
||||||
href="https://twitter.com/excalidraw"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<div className="menu-item__icon">{TwitterIcon}</div>
|
|
||||||
<div className="menu-item__text">Twitter</div>
|
|
||||||
</a>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const Separator = () => (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: "1px",
|
|
||||||
backgroundColor: "var(--default-border-color)",
|
|
||||||
margin: ".5rem 0",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
+53
-106
@@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { AppState, Device, ExcalidrawProps } from "../types";
|
import { AppState } from "../types";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
@@ -8,21 +8,16 @@ import { NonDeletedExcalidrawElement } from "../element/types";
|
|||||||
import { FixedSideContainer } from "./FixedSideContainer";
|
import { FixedSideContainer } from "./FixedSideContainer";
|
||||||
import { Island } from "./Island";
|
import { Island } from "./Island";
|
||||||
import { HintViewer } from "./HintViewer";
|
import { HintViewer } from "./HintViewer";
|
||||||
import { calculateScrollCenter } from "../scene";
|
import { calculateScrollCenter, getSelectedElements } from "../scene";
|
||||||
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
||||||
import { Section } from "./Section";
|
import { Section } from "./Section";
|
||||||
import CollabButton from "./CollabButton";
|
import CollabButton from "./CollabButton";
|
||||||
import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars";
|
import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars";
|
||||||
import { LockButton } from "./LockButton";
|
import { LockButton } from "./LockButton";
|
||||||
import { UserList } from "./UserList";
|
import { UserList } from "./UserList";
|
||||||
|
import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";
|
||||||
import { LibraryButton } from "./LibraryButton";
|
import { LibraryButton } from "./LibraryButton";
|
||||||
import { PenModeButton } from "./PenModeButton";
|
import { PenModeButton } from "./PenModeButton";
|
||||||
import { Stats } from "./Stats";
|
|
||||||
import { actionToggleStats } from "../actions";
|
|
||||||
import { MenuLinks, Separator } from "./MenuUtils";
|
|
||||||
import WelcomeScreen from "./WelcomeScreen";
|
|
||||||
import MenuItem from "./MenuItem";
|
|
||||||
import { ExportImageIcon } from "./icons";
|
|
||||||
|
|
||||||
type MobileMenuProps = {
|
type MobileMenuProps = {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
@@ -31,6 +26,7 @@ type MobileMenuProps = {
|
|||||||
renderImageExportDialog: () => React.ReactNode;
|
renderImageExportDialog: () => React.ReactNode;
|
||||||
setAppState: React.Component<any, AppState>["setState"];
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
|
libraryMenu: JSX.Element | null;
|
||||||
onCollabButtonClick?: () => void;
|
onCollabButtonClick?: () => void;
|
||||||
onLockToggle: () => void;
|
onLockToggle: () => void;
|
||||||
onPenModeToggle: () => void;
|
onPenModeToggle: () => void;
|
||||||
@@ -40,20 +36,19 @@ type MobileMenuProps = {
|
|||||||
isMobile: boolean,
|
isMobile: boolean,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
) => JSX.Element | null;
|
) => JSX.Element | null;
|
||||||
|
showThemeBtn: boolean;
|
||||||
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
||||||
renderTopRightUI?: (
|
renderTopRightUI?: (
|
||||||
isMobile: boolean,
|
isMobile: boolean,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
) => JSX.Element | null;
|
) => JSX.Element | null;
|
||||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
renderStats: () => JSX.Element | null;
|
||||||
renderSidebars: () => JSX.Element | null;
|
|
||||||
device: Device;
|
|
||||||
renderWelcomeScreen?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MobileMenu = ({
|
export const MobileMenu = ({
|
||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
|
libraryMenu,
|
||||||
actionManager,
|
actionManager,
|
||||||
renderJSONExportDialog,
|
renderJSONExportDialog,
|
||||||
renderImageExportDialog,
|
renderImageExportDialog,
|
||||||
@@ -64,40 +59,21 @@ export const MobileMenu = ({
|
|||||||
canvas,
|
canvas,
|
||||||
isCollaborating,
|
isCollaborating,
|
||||||
renderCustomFooter,
|
renderCustomFooter,
|
||||||
|
showThemeBtn,
|
||||||
onImageAction,
|
onImageAction,
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomStats,
|
renderStats,
|
||||||
renderSidebars,
|
|
||||||
device,
|
|
||||||
renderWelcomeScreen,
|
|
||||||
}: MobileMenuProps) => {
|
}: MobileMenuProps) => {
|
||||||
const renderToolbar = () => {
|
const renderToolbar = () => {
|
||||||
return (
|
return (
|
||||||
<FixedSideContainer side="top" className="App-top-bar">
|
<FixedSideContainer side="top" className="App-top-bar">
|
||||||
{renderWelcomeScreen && !appState.isLoading && (
|
|
||||||
<WelcomeScreen appState={appState} actionManager={actionManager} />
|
|
||||||
)}
|
|
||||||
<Section heading="shapes">
|
<Section heading="shapes">
|
||||||
{(heading: React.ReactNode) => (
|
{(heading: React.ReactNode) => (
|
||||||
<Stack.Col gap={4} align="center">
|
<Stack.Col gap={4} align="center">
|
||||||
<Stack.Row gap={1} className="App-toolbar-container">
|
<Stack.Row gap={1} className="App-toolbar-container">
|
||||||
<Island padding={1} className="App-toolbar App-toolbar--mobile">
|
<Island padding={1} className="App-toolbar">
|
||||||
{heading}
|
{heading}
|
||||||
<Stack.Row gap={1}>
|
<Stack.Row gap={1}>
|
||||||
{/* <PenModeButton
|
|
||||||
checked={appState.penMode}
|
|
||||||
onChange={onPenModeToggle}
|
|
||||||
title={t("toolBar.penMode")}
|
|
||||||
isMobile
|
|
||||||
penDetected={appState.penDetected}
|
|
||||||
/>
|
|
||||||
<LockButton
|
|
||||||
checked={appState.activeTool.locked}
|
|
||||||
onChange={onLockToggle}
|
|
||||||
title={t("toolBar.lock")}
|
|
||||||
isMobile
|
|
||||||
/>
|
|
||||||
<div className="App-toolbar__divider"></div> */}
|
|
||||||
<ShapesSwitcher
|
<ShapesSwitcher
|
||||||
appState={appState}
|
appState={appState}
|
||||||
canvas={canvas}
|
canvas={canvas}
|
||||||
@@ -112,44 +88,41 @@ export const MobileMenu = ({
|
|||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Island>
|
</Island>
|
||||||
{renderTopRightUI && renderTopRightUI(true, appState)}
|
{renderTopRightUI && renderTopRightUI(true, appState)}
|
||||||
<div className="mobile-misc-tools-container">
|
<LockButton
|
||||||
<PenModeButton
|
checked={appState.activeTool.locked}
|
||||||
checked={appState.penMode}
|
onChange={onLockToggle}
|
||||||
onChange={onPenModeToggle}
|
title={t("toolBar.lock")}
|
||||||
title={t("toolBar.penMode")}
|
isMobile
|
||||||
isMobile
|
/>
|
||||||
penDetected={appState.penDetected}
|
<LibraryButton
|
||||||
// penDetected={true}
|
appState={appState}
|
||||||
/>
|
setAppState={setAppState}
|
||||||
<LockButton
|
isMobile
|
||||||
checked={appState.activeTool.locked}
|
/>
|
||||||
onChange={onLockToggle}
|
<PenModeButton
|
||||||
title={t("toolBar.lock")}
|
checked={appState.penMode}
|
||||||
isMobile
|
onChange={onPenModeToggle}
|
||||||
/>
|
title={t("toolBar.penMode")}
|
||||||
{!appState.viewModeEnabled && (
|
isMobile
|
||||||
<LibraryButton
|
penDetected={appState.penDetected}
|
||||||
appState={appState}
|
/>
|
||||||
setAppState={setAppState}
|
|
||||||
isMobile
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
|
{libraryMenu}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
)}
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
<HintViewer
|
<HintViewer appState={appState} elements={elements} isMobile={true} />
|
||||||
appState={appState}
|
|
||||||
elements={elements}
|
|
||||||
isMobile={true}
|
|
||||||
device={device}
|
|
||||||
/>
|
|
||||||
</FixedSideContainer>
|
</FixedSideContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderAppToolbar = () => {
|
const renderAppToolbar = () => {
|
||||||
|
// Render eraser conditionally in mobile
|
||||||
|
const showEraser =
|
||||||
|
!appState.viewModeEnabled &&
|
||||||
|
!appState.editingElement &&
|
||||||
|
getSelectedElements(elements, appState).length === 0;
|
||||||
|
|
||||||
if (appState.viewModeEnabled) {
|
if (appState.viewModeEnabled) {
|
||||||
return (
|
return (
|
||||||
<div className="App-toolbar-content">
|
<div className="App-toolbar-content">
|
||||||
@@ -162,8 +135,11 @@ export const MobileMenu = ({
|
|||||||
<div className="App-toolbar-content">
|
<div className="App-toolbar-content">
|
||||||
{actionManager.renderAction("toggleCanvasMenu")}
|
{actionManager.renderAction("toggleCanvasMenu")}
|
||||||
{actionManager.renderAction("toggleEditMenu")}
|
{actionManager.renderAction("toggleEditMenu")}
|
||||||
|
|
||||||
{actionManager.renderAction("undo")}
|
{actionManager.renderAction("undo")}
|
||||||
{actionManager.renderAction("redo")}
|
{actionManager.renderAction("redo")}
|
||||||
|
{showEraser && actionManager.renderAction("eraser")}
|
||||||
|
|
||||||
{actionManager.renderAction(
|
{actionManager.renderAction(
|
||||||
appState.multiElement ? "finalize" : "duplicateSelection",
|
appState.multiElement ? "finalize" : "duplicateSelection",
|
||||||
)}
|
)}
|
||||||
@@ -177,27 +153,16 @@ export const MobileMenu = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{renderJSONExportDialog()}
|
{renderJSONExportDialog()}
|
||||||
<MenuItem
|
|
||||||
label={t("buttons.exportImage")}
|
|
||||||
icon={ExportImageIcon}
|
|
||||||
dataTestId="image-export-button"
|
|
||||||
onClick={() => setAppState({ openDialog: "imageExport" })}
|
|
||||||
/>
|
|
||||||
{renderImageExportDialog()}
|
{renderImageExportDialog()}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{!appState.viewModeEnabled && actionManager.renderAction("loadScene")}
|
{actionManager.renderAction("clearCanvas")}
|
||||||
|
{actionManager.renderAction("loadScene")}
|
||||||
{renderJSONExportDialog()}
|
{renderJSONExportDialog()}
|
||||||
{renderImageExportDialog()}
|
{renderImageExportDialog()}
|
||||||
<MenuItem
|
|
||||||
label={t("buttons.exportImage")}
|
|
||||||
icon={ExportImageIcon}
|
|
||||||
dataTestId="image-export-button"
|
|
||||||
onClick={() => setAppState({ openDialog: "imageExport" })}
|
|
||||||
/>
|
|
||||||
{onCollabButtonClick && (
|
{onCollabButtonClick && (
|
||||||
<CollabButton
|
<CollabButton
|
||||||
isCollaborating={isCollaborating}
|
isCollaborating={isCollaborating}
|
||||||
@@ -205,40 +170,21 @@ export const MobileMenu = ({
|
|||||||
onClick={onCollabButtonClick}
|
onClick={onCollabButtonClick}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{actionManager.renderAction("toggleShortcuts", undefined, true)}
|
{
|
||||||
{!appState.viewModeEnabled && actionManager.renderAction("clearCanvas")}
|
<BackgroundPickerAndDarkModeToggle
|
||||||
<Separator />
|
actionManager={actionManager}
|
||||||
<MenuLinks />
|
appState={appState}
|
||||||
<Separator />
|
setAppState={setAppState}
|
||||||
{!appState.viewModeEnabled && (
|
showThemeBtn={showThemeBtn}
|
||||||
<div style={{ marginBottom: ".5rem" }}>
|
/>
|
||||||
<div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}>
|
}
|
||||||
{t("labels.canvasBackground")}
|
|
||||||
</div>
|
|
||||||
<div style={{ padding: "0 0.625rem" }}>
|
|
||||||
{actionManager.renderAction("changeViewBackgroundColor")}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{actionManager.renderAction("toggleTheme")}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{renderSidebars()}
|
|
||||||
{!appState.viewModeEnabled && renderToolbar()}
|
{!appState.viewModeEnabled && renderToolbar()}
|
||||||
{!appState.openMenu && appState.showStats && (
|
{renderStats()}
|
||||||
<Stats
|
|
||||||
appState={appState}
|
|
||||||
setAppState={setAppState}
|
|
||||||
elements={elements}
|
|
||||||
onClose={() => {
|
|
||||||
actionManager.executeAction(actionToggleStats);
|
|
||||||
}}
|
|
||||||
renderCustomStats={renderCustomStats}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div
|
<div
|
||||||
className="App-bottom-bar"
|
className="App-bottom-bar"
|
||||||
style={{
|
style={{
|
||||||
@@ -251,7 +197,7 @@ export const MobileMenu = ({
|
|||||||
{appState.openMenu === "canvas" ? (
|
{appState.openMenu === "canvas" ? (
|
||||||
<Section className="App-mobile-menu" heading="canvasActions">
|
<Section className="App-mobile-menu" heading="canvasActions">
|
||||||
<div className="panelColumn">
|
<div className="panelColumn">
|
||||||
<Stack.Col gap={2}>
|
<Stack.Col gap={4}>
|
||||||
{renderCanvasActions()}
|
{renderCanvasActions()}
|
||||||
{renderCustomFooter?.(true, appState)}
|
{renderCustomFooter?.(true, appState)}
|
||||||
{appState.collaborators.size > 0 && (
|
{appState.collaborators.size > 0 && (
|
||||||
@@ -275,6 +221,7 @@ export const MobileMenu = ({
|
|||||||
appState={appState}
|
appState={appState}
|
||||||
elements={elements}
|
elements={elements}
|
||||||
renderAction={actionManager.renderAction}
|
renderAction={actionManager.renderAction}
|
||||||
|
activeTool={appState.activeTool.type}
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -282,7 +229,7 @@ export const MobileMenu = ({
|
|||||||
{renderAppToolbar()}
|
{renderAppToolbar()}
|
||||||
{appState.scrolledOutside &&
|
{appState.scrolledOutside &&
|
||||||
!appState.openMenu &&
|
!appState.openMenu &&
|
||||||
appState.openSidebar !== "library" && (
|
!appState.isLibraryOpen && (
|
||||||
<button
|
<button
|
||||||
className="scroll-back-to-content"
|
className="scroll-back-to-content"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@@ -17,10 +17,6 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
padding: calc(var(--space-factor) * 10);
|
padding: calc(var(--space-factor) * 10);
|
||||||
|
|
||||||
.Island {
|
|
||||||
padding: 2.5rem !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.Modal__background {
|
.Modal__background {
|
||||||
@@ -30,7 +26,7 @@
|
|||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
background-color: rgba(#121212, 0.2);
|
background-color: transparentize($oc-black, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.Modal__content {
|
.Modal__content {
|
||||||
@@ -50,7 +46,7 @@
|
|||||||
background: var(--island-bg-color);
|
background: var(--island-bg-color);
|
||||||
|
|
||||||
border: 1px solid var(--dialog-border-color);
|
border: 1px solid var(--dialog-border-color);
|
||||||
box-shadow: var(--modal-shadow);
|
box-shadow: 0 2px 10px transparentize($oc-black, 0.75);
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
@@ -77,20 +73,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.Modal__close {
|
.Modal__close {
|
||||||
color: var(--icon-fill-color);
|
width: calc(var(--space-factor) * 7);
|
||||||
margin: 0;
|
height: calc(var(--space-factor) * 7);
|
||||||
padding: 0.375rem;
|
display: flex;
|
||||||
position: absolute;
|
align-items: center;
|
||||||
top: 1rem;
|
justify-content: center;
|
||||||
right: 1rem;
|
|
||||||
border: 0;
|
|
||||||
background-color: transparent;
|
|
||||||
line-height: 0;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: 1.5rem;
|
height: calc(var(--space-factor) * 5);
|
||||||
height: 1.5rem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ export const Modal: React.FC<{
|
|||||||
aria-modal="true"
|
aria-modal="true"
|
||||||
onKeyDown={handleKeydown}
|
onKeyDown={handleKeydown}
|
||||||
aria-labelledby={props.labelledBy}
|
aria-labelledby={props.labelledBy}
|
||||||
data-prevent-outside-click
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="Modal__background"
|
className="Modal__background"
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import "./ToolIcon.scss";
|
|||||||
|
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { ToolButtonSize } from "./ToolButton";
|
import { ToolButtonSize } from "./ToolButton";
|
||||||
import { PenModeIcon } from "./icons";
|
|
||||||
|
|
||||||
type PenModeIconProps = {
|
type PenModeIconProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -16,15 +15,59 @@ type PenModeIconProps = {
|
|||||||
|
|
||||||
const DEFAULT_SIZE: ToolButtonSize = "medium";
|
const DEFAULT_SIZE: ToolButtonSize = "medium";
|
||||||
|
|
||||||
|
const ICONS = {
|
||||||
|
CHECKED: (
|
||||||
|
<svg
|
||||||
|
width="205"
|
||||||
|
height="205"
|
||||||
|
viewBox="0 0 205 205"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path d="m35 195-25-29.17V50h50v115l-25 30" />
|
||||||
|
<path d="M10 40V10h50v30H10" />
|
||||||
|
<path d="M125 145h70v50h-70" />
|
||||||
|
<path d="M190 145v-30l-10-20h-40l-10 20v30h15v-30l5-5h20l5 5v30h15" />
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
|
UNCHECKED: (
|
||||||
|
<svg
|
||||||
|
width="205"
|
||||||
|
height="205"
|
||||||
|
viewBox="0 0 205 205"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
className="unlocked-icon rtl-mirror"
|
||||||
|
>
|
||||||
|
<path d="m35 195-25-29.17V50h50v115l-25 30" />
|
||||||
|
<path d="M10 40V10h50v30H10" />
|
||||||
|
<path d="M125 145h70v50h-70" />
|
||||||
|
<path d="M145 145v-30l-10-20H95l-10 20v30h15v-30l5-5h20l5 5v30h15" />
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
export const PenModeButton = (props: PenModeIconProps) => {
|
export const PenModeButton = (props: PenModeIconProps) => {
|
||||||
if (!props.penDetected) {
|
if (!props.penDetected) {
|
||||||
return null;
|
if (props.isMobile) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<label
|
||||||
|
className={clsx(
|
||||||
|
"ToolIcon ToolIcon__penMode ToolIcon_type_floating",
|
||||||
|
`ToolIcon_size_${DEFAULT_SIZE}`,
|
||||||
|
{
|
||||||
|
"is-mobile": props.isMobile,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="ToolIcon__icon ToolIcon__hidden" />
|
||||||
|
</label>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label
|
<label
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"ToolIcon ToolIcon__penMode",
|
"ToolIcon ToolIcon__penMode ToolIcon_type_floating",
|
||||||
`ToolIcon_size_${DEFAULT_SIZE}`,
|
`ToolIcon_size_${DEFAULT_SIZE}`,
|
||||||
{
|
{
|
||||||
"is-mobile": props.isMobile,
|
"is-mobile": props.isMobile,
|
||||||
@@ -40,7 +83,9 @@ export const PenModeButton = (props: PenModeIconProps) => {
|
|||||||
checked={props.checked}
|
checked={props.checked}
|
||||||
aria-label={props.title}
|
aria-label={props.title}
|
||||||
/>
|
/>
|
||||||
<div className="ToolIcon__icon">{PenModeIcon}</div>
|
<div className="ToolIcon__icon">
|
||||||
|
{props.checked ? ICONS.CHECKED : ICONS.UNCHECKED}
|
||||||
|
</div>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
label {
|
label {
|
||||||
padding: 1em 0;
|
padding: 1em;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -34,7 +34,6 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
padding: 0.2rem 0;
|
padding: 0.2rem 0;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
gap: 0.5rem;
|
|
||||||
|
|
||||||
.ToolIcon__icon {
|
.ToolIcon__icon {
|
||||||
min-width: 2.5rem;
|
min-width: 2.5rem;
|
||||||
@@ -75,6 +74,7 @@
|
|||||||
|
|
||||||
.selected-library-items {
|
.selected-library-items {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
padding: 0 0.8rem;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
|
||||||
.single-library-item-wrapper {
|
.single-library-item-wrapper {
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&-note {
|
&-note {
|
||||||
padding: 1em 0;
|
padding: 1em;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import OpenColor from "open-color";
|
|||||||
import { Dialog } from "./Dialog";
|
import { Dialog } from "./Dialog";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
|
|
||||||
import { AppState, LibraryItems, LibraryItem } from "../types";
|
import { AppState, LibraryItems, LibraryItem } from "../types";
|
||||||
import { exportToCanvas } from "../packages/utils";
|
import { exportToCanvas } from "../packages/utils";
|
||||||
import {
|
import {
|
||||||
@@ -18,7 +20,6 @@ import "./PublishLibrary.scss";
|
|||||||
import SingleLibraryItem from "./SingleLibraryItem";
|
import SingleLibraryItem from "./SingleLibraryItem";
|
||||||
import { canvasToBlob, resizeImageFile } from "../data/blob";
|
import { canvasToBlob, resizeImageFile } from "../data/blob";
|
||||||
import { chunk } from "../utils";
|
import { chunk } from "../utils";
|
||||||
import DialogActionButton from "./DialogActionButton";
|
|
||||||
|
|
||||||
interface PublishLibraryDataParams {
|
interface PublishLibraryDataParams {
|
||||||
authorName: string;
|
authorName: string;
|
||||||
@@ -433,15 +434,21 @@ const PublishLibrary = ({
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="publish-library__buttons">
|
<div className="publish-library__buttons">
|
||||||
<DialogActionButton
|
<ToolButton
|
||||||
|
type="button"
|
||||||
|
title={t("buttons.cancel")}
|
||||||
|
aria-label={t("buttons.cancel")}
|
||||||
label={t("buttons.cancel")}
|
label={t("buttons.cancel")}
|
||||||
onClick={onDialogClose}
|
onClick={onDialogClose}
|
||||||
data-testid="cancel-clear-canvas-button"
|
data-testid="cancel-clear-canvas-button"
|
||||||
|
className="publish-library__buttons--cancel"
|
||||||
/>
|
/>
|
||||||
<DialogActionButton
|
<ToolButton
|
||||||
type="submit"
|
type="submit"
|
||||||
|
title={t("buttons.submit")}
|
||||||
|
aria-label={t("buttons.submit")}
|
||||||
label={t("buttons.submit")}
|
label={t("buttons.submit")}
|
||||||
actionType="primary"
|
className="publish-library__buttons--confirm"
|
||||||
isLoading={isSubmitting}
|
isLoading={isSubmitting}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,146 +0,0 @@
|
|||||||
@import "open-color/open-color";
|
|
||||||
@import "../../css/variables.module";
|
|
||||||
|
|
||||||
.excalidraw {
|
|
||||||
.Sidebar {
|
|
||||||
&__dropdown-content {
|
|
||||||
z-index: 1;
|
|
||||||
position: absolute;
|
|
||||||
top: 100%;
|
|
||||||
left: 0;
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
right: 0;
|
|
||||||
left: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
margin-top: 0.25rem;
|
|
||||||
width: 180px;
|
|
||||||
box-shadow: var(--library-dropdown-shadow);
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
padding: 0.25rem 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__close-btn,
|
|
||||||
&__pin-btn,
|
|
||||||
&__dropdown-btn {
|
|
||||||
@include outlineButtonStyles;
|
|
||||||
width: var(--lg-button-size);
|
|
||||||
height: var(--lg-button-size);
|
|
||||||
padding: 0;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
width: var(--lg-icon-size);
|
|
||||||
height: var(--lg-icon-size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__pin-btn {
|
|
||||||
&--pinned {
|
|
||||||
background-color: var(--color-primary);
|
|
||||||
border-color: var(--color-primary);
|
|
||||||
|
|
||||||
svg {
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover,
|
|
||||||
&:active {
|
|
||||||
background-color: var(--color-primary-darker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
.Sidebar {
|
|
||||||
&__pin-btn {
|
|
||||||
&--pinned {
|
|
||||||
svg {
|
|
||||||
color: var(--color-gray-90);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.layer-ui__sidebar {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
right: 0;
|
|
||||||
z-index: 5;
|
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
left: 0;
|
|
||||||
right: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
background-color: var(--sidebar-bg-color);
|
|
||||||
|
|
||||||
box-shadow: var(--sidebar-shadow);
|
|
||||||
|
|
||||||
&--docked {
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
overflow: hidden;
|
|
||||||
border-radius: 0;
|
|
||||||
width: calc(#{$right-sidebar-width} - var(--space-factor) * 2);
|
|
||||||
|
|
||||||
border-left: 1px solid var(--sidebar-border-color);
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
border-right: 1px solid var(--sidebar-border-color);
|
|
||||||
border-left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
.Island {
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ToolIcon__icon {
|
|
||||||
border-radius: var(--border-radius-md);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ToolIcon__icon__close {
|
|
||||||
.Modal__close {
|
|
||||||
width: calc(var(--space-factor) * 7);
|
|
||||||
height: calc(var(--space-factor) * 7);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
color: var(--color-text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.Island {
|
|
||||||
--padding: 0;
|
|
||||||
background-color: var(--island-bg-color);
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
padding: calc(var(--padding) * var(--space-factor));
|
|
||||||
position: relative;
|
|
||||||
transition: box-shadow 0.5s ease-in-out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.layer-ui__sidebar__header {
|
|
||||||
box-sizing: border-box;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1rem;
|
|
||||||
border-bottom: 1px solid var(--sidebar-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.layer-ui__sidebar__header__buttons {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.625rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,355 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { Excalidraw, Sidebar } from "../../packages/excalidraw/index";
|
|
||||||
import {
|
|
||||||
act,
|
|
||||||
fireEvent,
|
|
||||||
queryAllByTestId,
|
|
||||||
queryByTestId,
|
|
||||||
render,
|
|
||||||
waitFor,
|
|
||||||
withExcalidrawDimensions,
|
|
||||||
} from "../../tests/test-utils";
|
|
||||||
|
|
||||||
describe("Sidebar", () => {
|
|
||||||
it("should render custom sidebar", async () => {
|
|
||||||
const { container } = await render(
|
|
||||||
<Excalidraw
|
|
||||||
initialData={{ appState: { openSidebar: "customSidebar" } }}
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar>
|
|
||||||
<div id="test-sidebar-content">42</div>
|
|
||||||
</Sidebar>
|
|
||||||
)}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).not.toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should render custom sidebar header", async () => {
|
|
||||||
const { container } = await render(
|
|
||||||
<Excalidraw
|
|
||||||
initialData={{ appState: { openSidebar: "customSidebar" } }}
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar>
|
|
||||||
<Sidebar.Header>
|
|
||||||
<div id="test-sidebar-header-content">42</div>
|
|
||||||
</Sidebar.Header>
|
|
||||||
</Sidebar>
|
|
||||||
)}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
const node = container.querySelector("#test-sidebar-header-content");
|
|
||||||
expect(node).not.toBe(null);
|
|
||||||
// make sure we don't render the default fallback header,
|
|
||||||
// just the custom one
|
|
||||||
expect(queryAllByTestId(container, "sidebar-header").length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should render only one sidebar and prefer the custom one", async () => {
|
|
||||||
const { container } = await render(
|
|
||||||
<Excalidraw
|
|
||||||
initialData={{ appState: { openSidebar: "customSidebar" } }}
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar>
|
|
||||||
<div id="test-sidebar-content">42</div>
|
|
||||||
</Sidebar>
|
|
||||||
)}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
// make sure the custom sidebar is rendered
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).not.toBe(null);
|
|
||||||
|
|
||||||
// make sure only one sidebar is rendered
|
|
||||||
const sidebars = container.querySelectorAll(".layer-ui__sidebar");
|
|
||||||
expect(sidebars.length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should always render custom sidebar with close button & close on click", async () => {
|
|
||||||
const onClose = jest.fn();
|
|
||||||
const CustomExcalidraw = () => {
|
|
||||||
return (
|
|
||||||
<Excalidraw
|
|
||||||
initialData={{ appState: { openSidebar: "customSidebar" } }}
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar className="test-sidebar" onClose={onClose}>
|
|
||||||
hello
|
|
||||||
</Sidebar>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { container } = await render(<CustomExcalidraw />);
|
|
||||||
|
|
||||||
const sidebar = container.querySelector<HTMLElement>(".test-sidebar");
|
|
||||||
expect(sidebar).not.toBe(null);
|
|
||||||
const closeButton = queryByTestId(sidebar!, "sidebar-close");
|
|
||||||
expect(closeButton).not.toBe(null);
|
|
||||||
|
|
||||||
fireEvent.click(closeButton!.querySelector("button")!);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(container.querySelector<HTMLElement>(".test-sidebar")).toBe(null);
|
|
||||||
expect(onClose).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should render custom sidebar with dock (irrespective of onDock prop)", async () => {
|
|
||||||
const CustomExcalidraw = () => {
|
|
||||||
return (
|
|
||||||
<Excalidraw
|
|
||||||
initialData={{ appState: { openSidebar: "customSidebar" } }}
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar className="test-sidebar">hello</Sidebar>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { container } = await render(<CustomExcalidraw />);
|
|
||||||
|
|
||||||
// should show dock button when the sidebar fits to be docked
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
await withExcalidrawDimensions({ width: 1920, height: 1080 }, () => {
|
|
||||||
const sidebar = container.querySelector<HTMLElement>(".test-sidebar");
|
|
||||||
expect(sidebar).not.toBe(null);
|
|
||||||
const closeButton = queryByTestId(sidebar!, "sidebar-dock");
|
|
||||||
expect(closeButton).not.toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// should not show dock button when the sidebar does not fit to be docked
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
await withExcalidrawDimensions({ width: 400, height: 1080 }, () => {
|
|
||||||
const sidebar = container.querySelector<HTMLElement>(".test-sidebar");
|
|
||||||
expect(sidebar).not.toBe(null);
|
|
||||||
const closeButton = queryByTestId(sidebar!, "sidebar-dock");
|
|
||||||
expect(closeButton).toBe(null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should support controlled docking", async () => {
|
|
||||||
let _setDockable: (dockable: boolean) => void = null!;
|
|
||||||
|
|
||||||
const CustomExcalidraw = () => {
|
|
||||||
const [dockable, setDockable] = React.useState(false);
|
|
||||||
_setDockable = setDockable;
|
|
||||||
return (
|
|
||||||
<Excalidraw
|
|
||||||
initialData={{ appState: { openSidebar: "customSidebar" } }}
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar
|
|
||||||
className="test-sidebar"
|
|
||||||
docked={false}
|
|
||||||
dockable={dockable}
|
|
||||||
>
|
|
||||||
hello
|
|
||||||
</Sidebar>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { container } = await render(<CustomExcalidraw />);
|
|
||||||
|
|
||||||
await withExcalidrawDimensions({ width: 1920, height: 1080 }, async () => {
|
|
||||||
// should not show dock button when `dockable` is `false`
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
act(() => {
|
|
||||||
_setDockable(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const sidebar = container.querySelector<HTMLElement>(".test-sidebar");
|
|
||||||
expect(sidebar).not.toBe(null);
|
|
||||||
const closeButton = queryByTestId(sidebar!, "sidebar-dock");
|
|
||||||
expect(closeButton).toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// should show dock button when `dockable` is `true`, even if `docked`
|
|
||||||
// prop is set
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
act(() => {
|
|
||||||
_setDockable(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const sidebar = container.querySelector<HTMLElement>(".test-sidebar");
|
|
||||||
expect(sidebar).not.toBe(null);
|
|
||||||
const closeButton = queryByTestId(sidebar!, "sidebar-dock");
|
|
||||||
expect(closeButton).not.toBe(null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should support controlled docking", async () => {
|
|
||||||
let _setDocked: (docked?: boolean) => void = null!;
|
|
||||||
|
|
||||||
const CustomExcalidraw = () => {
|
|
||||||
const [docked, setDocked] = React.useState<boolean | undefined>();
|
|
||||||
_setDocked = setDocked;
|
|
||||||
return (
|
|
||||||
<Excalidraw
|
|
||||||
initialData={{ appState: { openSidebar: "customSidebar" } }}
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar className="test-sidebar" docked={docked}>
|
|
||||||
hello
|
|
||||||
</Sidebar>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { container } = await render(<CustomExcalidraw />);
|
|
||||||
|
|
||||||
const { h } = window;
|
|
||||||
|
|
||||||
await withExcalidrawDimensions({ width: 1920, height: 1080 }, async () => {
|
|
||||||
const dockButton = await waitFor(() => {
|
|
||||||
const sidebar = container.querySelector<HTMLElement>(".test-sidebar");
|
|
||||||
expect(sidebar).not.toBe(null);
|
|
||||||
const dockBotton = queryByTestId(sidebar!, "sidebar-dock");
|
|
||||||
expect(dockBotton).not.toBe(null);
|
|
||||||
return dockBotton!;
|
|
||||||
});
|
|
||||||
|
|
||||||
const dockButtonInput = dockButton.querySelector("input")!;
|
|
||||||
|
|
||||||
// should not show dock button when `dockable` is `false`
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
expect(h.state.isSidebarDocked).toBe(false);
|
|
||||||
|
|
||||||
fireEvent.click(dockButtonInput);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(h.state.isSidebarDocked).toBe(true);
|
|
||||||
expect(dockButtonInput).toBeChecked();
|
|
||||||
});
|
|
||||||
|
|
||||||
fireEvent.click(dockButtonInput);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(h.state.isSidebarDocked).toBe(false);
|
|
||||||
expect(dockButtonInput).not.toBeChecked();
|
|
||||||
});
|
|
||||||
|
|
||||||
// shouldn't update `appState.isSidebarDocked` when the sidebar
|
|
||||||
// is controlled (`docked` prop is set), as host apps should handle
|
|
||||||
// the state themselves
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
act(() => {
|
|
||||||
_setDocked(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(dockButtonInput).toBeChecked();
|
|
||||||
expect(h.state.isSidebarDocked).toBe(false);
|
|
||||||
expect(dockButtonInput).toBeChecked();
|
|
||||||
});
|
|
||||||
|
|
||||||
fireEvent.click(dockButtonInput);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(h.state.isSidebarDocked).toBe(false);
|
|
||||||
expect(dockButtonInput).toBeChecked();
|
|
||||||
});
|
|
||||||
|
|
||||||
// the `appState.isSidebarDocked` should remain untouched when
|
|
||||||
// `props.docked` is set to `false`, and user toggles
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
act(() => {
|
|
||||||
_setDocked(false);
|
|
||||||
h.setState({ isSidebarDocked: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(h.state.isSidebarDocked).toBe(true);
|
|
||||||
expect(dockButtonInput).not.toBeChecked();
|
|
||||||
});
|
|
||||||
|
|
||||||
fireEvent.click(dockButtonInput);
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(dockButtonInput).not.toBeChecked();
|
|
||||||
expect(h.state.isSidebarDocked).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should toggle sidebar using props.toggleMenu()", async () => {
|
|
||||||
const { container } = await render(
|
|
||||||
<Excalidraw
|
|
||||||
renderSidebar={() => (
|
|
||||||
<Sidebar>
|
|
||||||
<div id="test-sidebar-content">42</div>
|
|
||||||
</Sidebar>
|
|
||||||
)}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
// sidebar isn't rendered initially
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
await waitFor(() => {
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// toggle sidebar on
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
expect(window.h.app.toggleMenu("customSidebar")).toBe(true);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).not.toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// toggle sidebar off
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
expect(window.h.app.toggleMenu("customSidebar")).toBe(false);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// force-toggle sidebar off (=> still hidden)
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
expect(window.h.app.toggleMenu("customSidebar", false)).toBe(false);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// force-toggle sidebar on
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
expect(window.h.app.toggleMenu("customSidebar", true)).toBe(true);
|
|
||||||
expect(window.h.app.toggleMenu("customSidebar", true)).toBe(true);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).not.toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// toggle library (= hide custom sidebar)
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
expect(window.h.app.toggleMenu("library")).toBe(true);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
const node = container.querySelector("#test-sidebar-content");
|
|
||||||
expect(node).toBe(null);
|
|
||||||
|
|
||||||
// make sure only one sidebar is rendered
|
|
||||||
const sidebars = container.querySelectorAll(".layer-ui__sidebar");
|
|
||||||
expect(sidebars.length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
import {
|
|
||||||
useEffect,
|
|
||||||
useLayoutEffect,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
forwardRef,
|
|
||||||
} from "react";
|
|
||||||
import { Island } from ".././Island";
|
|
||||||
import { atom, useAtom } from "jotai";
|
|
||||||
import { jotaiScope } from "../../jotai";
|
|
||||||
import {
|
|
||||||
SidebarPropsContext,
|
|
||||||
SidebarProps,
|
|
||||||
SidebarPropsContextValue,
|
|
||||||
} from "./common";
|
|
||||||
|
|
||||||
import { SidebarHeaderComponents } from "./SidebarHeader";
|
|
||||||
|
|
||||||
import "./Sidebar.scss";
|
|
||||||
import clsx from "clsx";
|
|
||||||
import { useExcalidrawSetAppState } from "../App";
|
|
||||||
import { updateObject } from "../../utils";
|
|
||||||
|
|
||||||
/** using a counter instead of boolean to handle race conditions where
|
|
||||||
* the host app may render (mount/unmount) multiple different sidebar */
|
|
||||||
export const hostSidebarCountersAtom = atom({ rendered: 0, docked: 0 });
|
|
||||||
|
|
||||||
export const Sidebar = Object.assign(
|
|
||||||
forwardRef(
|
|
||||||
(
|
|
||||||
{
|
|
||||||
children,
|
|
||||||
onClose,
|
|
||||||
onDock,
|
|
||||||
docked,
|
|
||||||
/** Undocumented, may be removed later. Generally should either be
|
|
||||||
* `props.docked` or `appState.isSidebarDocked`. Currently serves to
|
|
||||||
* prevent unwanted animation of the shadow if initially docked. */
|
|
||||||
//
|
|
||||||
// NOTE we'll want to remove this after we sort out how to subscribe to
|
|
||||||
// individual appState properties
|
|
||||||
initialDockedState = docked,
|
|
||||||
dockable = true,
|
|
||||||
className,
|
|
||||||
__isInternal,
|
|
||||||
}: SidebarProps<{
|
|
||||||
// NOTE sidebars we use internally inside the editor must have this flag set.
|
|
||||||
// It indicates that this sidebar should have lower precedence over host
|
|
||||||
// sidebars, if both are open.
|
|
||||||
/** @private internal */
|
|
||||||
__isInternal?: boolean;
|
|
||||||
}>,
|
|
||||||
ref: React.ForwardedRef<HTMLDivElement>,
|
|
||||||
) => {
|
|
||||||
const [hostSidebarCounters, setHostSidebarCounters] = useAtom(
|
|
||||||
hostSidebarCountersAtom,
|
|
||||||
jotaiScope,
|
|
||||||
);
|
|
||||||
|
|
||||||
const setAppState = useExcalidrawSetAppState();
|
|
||||||
|
|
||||||
const [isDockedFallback, setIsDockedFallback] = useState(
|
|
||||||
docked ?? initialDockedState ?? false,
|
|
||||||
);
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
if (docked === undefined) {
|
|
||||||
// ugly hack to get initial state out of AppState without subscribing
|
|
||||||
// to it as a whole (once we have granular subscriptions, we'll move
|
|
||||||
// to that)
|
|
||||||
//
|
|
||||||
// NOTE this means that is updated `state.isSidebarDocked` changes outside
|
|
||||||
// of this compoent, it won't be reflected here. Currently doesn't happen.
|
|
||||||
setAppState((state) => {
|
|
||||||
setIsDockedFallback(state.isSidebarDocked);
|
|
||||||
// bail from update
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [setAppState, docked]);
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
if (!__isInternal) {
|
|
||||||
setHostSidebarCounters((s) => ({
|
|
||||||
rendered: s.rendered + 1,
|
|
||||||
docked: isDockedFallback ? s.docked + 1 : s.docked,
|
|
||||||
}));
|
|
||||||
return () => {
|
|
||||||
setHostSidebarCounters((s) => ({
|
|
||||||
rendered: s.rendered - 1,
|
|
||||||
docked: isDockedFallback ? s.docked - 1 : s.docked,
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [__isInternal, setHostSidebarCounters, isDockedFallback]);
|
|
||||||
|
|
||||||
const onCloseRef = useRef(onClose);
|
|
||||||
onCloseRef.current = onClose;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return () => {
|
|
||||||
onCloseRef.current?.();
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const headerPropsRef = useRef<SidebarPropsContextValue>({});
|
|
||||||
headerPropsRef.current.onClose = () => {
|
|
||||||
setAppState({ openSidebar: null });
|
|
||||||
};
|
|
||||||
headerPropsRef.current.onDock = (isDocked) => {
|
|
||||||
if (docked === undefined) {
|
|
||||||
setAppState({ isSidebarDocked: isDocked });
|
|
||||||
setIsDockedFallback(isDocked);
|
|
||||||
}
|
|
||||||
onDock?.(isDocked);
|
|
||||||
};
|
|
||||||
// renew the ref object if the following props change since we want to
|
|
||||||
// rerender. We can't pass down as component props manually because
|
|
||||||
// the <Sidebar.Header/> can be rendered upsream.
|
|
||||||
headerPropsRef.current = updateObject(headerPropsRef.current, {
|
|
||||||
docked: docked ?? isDockedFallback,
|
|
||||||
dockable,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (hostSidebarCounters.rendered > 0 && __isInternal) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Island
|
|
||||||
className={clsx(
|
|
||||||
"layer-ui__sidebar",
|
|
||||||
{ "layer-ui__sidebar--docked": isDockedFallback },
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
ref={ref}
|
|
||||||
>
|
|
||||||
<SidebarPropsContext.Provider value={headerPropsRef.current}>
|
|
||||||
<SidebarHeaderComponents.Context>
|
|
||||||
<SidebarHeaderComponents.Component __isFallback />
|
|
||||||
{children}
|
|
||||||
</SidebarHeaderComponents.Context>
|
|
||||||
</SidebarPropsContext.Provider>
|
|
||||||
</Island>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
{
|
|
||||||
Header: SidebarHeaderComponents.Component,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import { useContext } from "react";
|
|
||||||
import { t } from "../../i18n";
|
|
||||||
import { useDevice } from "../App";
|
|
||||||
import { SidebarPropsContext } from "./common";
|
|
||||||
import { CloseIcon, PinIcon } from "../icons";
|
|
||||||
import { withUpstreamOverride } from "../hoc/withUpstreamOverride";
|
|
||||||
import { Tooltip } from "../Tooltip";
|
|
||||||
|
|
||||||
export const SidebarDockButton = (props: {
|
|
||||||
checked: boolean;
|
|
||||||
onChange?(): void;
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div className="layer-ui__sidebar-dock-button" data-testid="sidebar-dock">
|
|
||||||
<Tooltip label={t("labels.sidebarLock")}>
|
|
||||||
<label
|
|
||||||
className={clsx(
|
|
||||||
"ToolIcon ToolIcon__lock ToolIcon_type_floating",
|
|
||||||
`ToolIcon_size_medium`,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
className="ToolIcon_type_checkbox"
|
|
||||||
type="checkbox"
|
|
||||||
onChange={props.onChange}
|
|
||||||
checked={props.checked}
|
|
||||||
aria-label={t("labels.sidebarLock")}
|
|
||||||
/>{" "}
|
|
||||||
<div
|
|
||||||
className={clsx("Sidebar__pin-btn", {
|
|
||||||
"Sidebar__pin-btn--pinned": props.checked,
|
|
||||||
})}
|
|
||||||
tabIndex={0}
|
|
||||||
>
|
|
||||||
{PinIcon}
|
|
||||||
</div>{" "}
|
|
||||||
</label>{" "}
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const _SidebarHeader: React.FC<{
|
|
||||||
children?: React.ReactNode;
|
|
||||||
className?: string;
|
|
||||||
}> = ({ children, className }) => {
|
|
||||||
const device = useDevice();
|
|
||||||
const props = useContext(SidebarPropsContext);
|
|
||||||
|
|
||||||
const renderDockButton = !!(device.canDeviceFitSidebar && props.dockable);
|
|
||||||
const renderCloseButton = !!props.onClose;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={clsx("layer-ui__sidebar__header", className)}
|
|
||||||
data-testid="sidebar-header"
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
{(renderDockButton || renderCloseButton) && (
|
|
||||||
<div className="layer-ui__sidebar__header__buttons">
|
|
||||||
{renderDockButton && (
|
|
||||||
<SidebarDockButton
|
|
||||||
checked={!!props.docked}
|
|
||||||
onChange={() => {
|
|
||||||
props.onDock?.(!props.docked);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{renderCloseButton && (
|
|
||||||
<button
|
|
||||||
data-testid="sidebar-close"
|
|
||||||
className="Sidebar__close-btn"
|
|
||||||
onClick={props.onClose}
|
|
||||||
aria-label={t("buttons.close")}
|
|
||||||
>
|
|
||||||
{CloseIcon}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const [Context, Component] = withUpstreamOverride(_SidebarHeader);
|
|
||||||
|
|
||||||
/** @private */
|
|
||||||
export const SidebarHeaderComponents = { Context, Component };
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
|
|
||||||
export type SidebarProps<P = {}> = {
|
|
||||||
children: React.ReactNode;
|
|
||||||
/**
|
|
||||||
* Called on sidebar close (either by user action or by the editor).
|
|
||||||
*/
|
|
||||||
onClose?: () => void | boolean;
|
|
||||||
/** if not supplied, sidebar won't be dockable */
|
|
||||||
onDock?: (docked: boolean) => void;
|
|
||||||
docked?: boolean;
|
|
||||||
initialDockedState?: boolean;
|
|
||||||
dockable?: boolean;
|
|
||||||
className?: string;
|
|
||||||
} & P;
|
|
||||||
|
|
||||||
export type SidebarPropsContextValue = Pick<
|
|
||||||
SidebarProps,
|
|
||||||
"onClose" | "onDock" | "docked" | "dockable"
|
|
||||||
>;
|
|
||||||
|
|
||||||
export const SidebarPropsContext =
|
|
||||||
React.createContext<SidebarPropsContextValue>({});
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
@import "../css/variables.module";
|
||||||
|
|
||||||
|
.excalidraw {
|
||||||
|
.layer-ui__sidebar-lock-button {
|
||||||
|
@include toolbarButtonColorStates;
|
||||||
|
margin-right: 0.2rem;
|
||||||
|
}
|
||||||
|
.ToolIcon_type_floating .side_lock_icon {
|
||||||
|
width: calc(var(--space-factor) * 7);
|
||||||
|
height: calc(var(--space-factor) * 7);
|
||||||
|
svg {
|
||||||
|
// mirror
|
||||||
|
transform: scale(-1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ToolIcon_type_checkbox {
|
||||||
|
&:not(.ToolIcon_toggle_opaque):checked + .side_lock_icon {
|
||||||
|
background-color: var(--color-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import "./ToolIcon.scss";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import clsx from "clsx";
|
||||||
|
import { ToolButtonSize } from "./ToolButton";
|
||||||
|
import { t } from "../i18n";
|
||||||
|
import { Tooltip } from "./Tooltip";
|
||||||
|
|
||||||
|
import "./SidebarLockButton.scss";
|
||||||
|
|
||||||
|
type SidebarLockIconProps = {
|
||||||
|
checked: boolean;
|
||||||
|
onChange?(): void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_SIZE: ToolButtonSize = "medium";
|
||||||
|
|
||||||
|
const SIDE_LIBRARY_TOGGLE_ICON = (
|
||||||
|
<svg viewBox="0 0 24 24" fill="#ffffff">
|
||||||
|
<path d="M19 22H5a3 3 0 01-3-3V5a3 3 0 013-3h14a3 3 0 013 3v14a3 3 0 01-3 3zm0-18h-9v16h9a1.01 1.01 0 001-1V5a1.01 1.01 0 00-1-1z"></path>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
|
export const SidebarLockButton = (props: SidebarLockIconProps) => {
|
||||||
|
return (
|
||||||
|
<Tooltip label={t("labels.sidebarLock")}>
|
||||||
|
<label
|
||||||
|
className={clsx(
|
||||||
|
"ToolIcon ToolIcon__lock ToolIcon_type_floating",
|
||||||
|
`ToolIcon_size_${DEFAULT_SIZE}`,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
className="ToolIcon_type_checkbox"
|
||||||
|
type="checkbox"
|
||||||
|
onChange={props.onChange}
|
||||||
|
checked={props.checked}
|
||||||
|
aria-label={t("labels.sidebarLock")}
|
||||||
|
/>{" "}
|
||||||
|
<div className="ToolIcon__icon side_lock_icon" tabIndex={0}>
|
||||||
|
{SIDE_LIBRARY_TOGGLE_ICON}
|
||||||
|
</div>{" "}
|
||||||
|
</label>{" "}
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user