mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-08-22 09:47:01 +02:00
Compare commits
96 Commits
aakansha-h
...
fix-collab
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5542e4528a | ||
![]() |
fdd8552637 | ||
![]() |
c8370b394c | ||
![]() |
5fcf6a4845 | ||
![]() |
af3b93c410 | ||
![]() |
2595e0de82 | ||
![]() |
8ec5f7b982 | ||
![]() |
9086674b27 | ||
![]() |
6273d56524 | ||
![]() |
7e135c4e22 | ||
![]() |
b704705ed8 | ||
![]() |
d2e371cdf0 | ||
![]() |
6ab3f0eb74 | ||
![]() |
539505affd | ||
![]() |
95d669390f | ||
![]() |
73a45e1988 | ||
![]() |
88c2812949 | ||
![]() |
bdb14723b3 | ||
![]() |
cc9e764585 | ||
![]() |
8466eb0eef | ||
![]() |
0ebe6292a3 | ||
![]() |
5854ac3eed | ||
![]() |
65d84a5d5a | ||
![]() |
808366d112 | ||
![]() |
9311c99d3c | ||
![]() |
d131b31084 | ||
![]() |
0111ca2050 | ||
![]() |
a1dcd6d984 | ||
![]() |
fffd4957db | ||
![]() |
760fd7b3a6 | ||
![]() |
1933116261 | ||
![]() |
8b33ca3a1a | ||
![]() |
a86224c797 | ||
![]() |
66bbfda460 | ||
![]() |
88b2f4707d | ||
![]() |
25c6056b03 | ||
![]() |
baf9651d34 | ||
![]() |
d2181847be | ||
![]() |
1f117995d9 | ||
![]() |
52c96a6870 | ||
![]() |
81fd2350a9 | ||
![]() |
8ed0fc2c87 | ||
![]() |
96a5d6548b | ||
![]() |
4709b953e7 | ||
![]() |
bbe0c35f66 | ||
![]() |
d273acb7e4 | ||
![]() |
3c0b29d85f | ||
![]() |
bfbaeae67f | ||
![]() |
74b9885955 | ||
![]() |
2cbe869a13 | ||
![]() |
a48607eb25 | ||
![]() |
7831b6e74b | ||
![]() |
640affe7c0 | ||
![]() |
335aff8838 | ||
![]() |
dc97dc30bf | ||
![]() |
a0ecfed4cd | ||
![]() |
e201e79cd0 | ||
![]() |
e1c5c706c6 | ||
![]() |
bdc56090d7 | ||
![]() |
58accc9310 | ||
![]() |
b91158198e | ||
![]() |
938ce241ff | ||
![]() |
0228646507 | ||
![]() |
25ea97d0f9 | ||
![]() |
8d5d68e589 | ||
![]() |
6c15d9948b | ||
![]() |
e8fba43cf6 | ||
![]() |
2e5c798c71 | ||
![]() |
8c298336fc | ||
![]() |
7f91cdc0c9 | ||
![]() |
6334bd832f | ||
![]() |
4d26993c8f | ||
![]() |
1e69609ce4 | ||
![]() |
f5379d1563 | ||
![]() |
c8f6e3faa8 | ||
![]() |
36bf17cf59 | ||
![]() |
75458c3192 | ||
![]() |
4cd25253bf | ||
![]() |
78e254fb30 | ||
![]() |
79bd3b8cda | ||
![]() |
55110bf1b8 | ||
![]() |
941b2d7042 | ||
![]() |
e9067de173 | ||
![]() |
fdc462ec01 | ||
![]() |
d1441afec9 | ||
![]() |
3298aaf0c7 | ||
![]() |
e9a224a0de | ||
![]() |
76cf560914 | ||
![]() |
6c1246ef77 | ||
![]() |
b477c2ad6b | ||
![]() |
4cb6f09559 | ||
![]() |
8636ef1017 | ||
![]() |
3a776f8795 | ||
![]() |
9929a2be6f | ||
![]() |
9cccac1458 | ||
![]() |
7eaf47c9d4 |
@@ -1,5 +1,6 @@
|
|||||||
*
|
*
|
||||||
!.env
|
!.env.development
|
||||||
|
!.env.production
|
||||||
!.eslintrc.json
|
!.eslintrc.json
|
||||||
!.npmrc
|
!.npmrc
|
||||||
!.prettierrc
|
!.prettierrc
|
||||||
|
@@ -20,3 +20,5 @@ REACT_APP_DEV_ENABLE_SW=
|
|||||||
# whether to disable live reload / HMR. Usuaully what you want to do when
|
# whether to disable live reload / HMR. Usuaully what you want to do when
|
||||||
# debugging Service Workers.
|
# debugging Service Workers.
|
||||||
REACT_APP_DEV_DISABLE_LIVE_RELOAD=
|
REACT_APP_DEV_DISABLE_LIVE_RELOAD=
|
||||||
|
|
||||||
|
FAST_REFRESH=false
|
||||||
|
2
.github/workflows/autorelease-excalidraw.yml
vendored
2
.github/workflows/autorelease-excalidraw.yml
vendored
@@ -2,7 +2,7 @@ name: Auto release excalidraw next
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- release
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Auto-release-excalidraw-next:
|
Auto-release-excalidraw-next:
|
||||||
|
2
.github/workflows/build-docker.yml
vendored
2
.github/workflows/build-docker.yml
vendored
@@ -3,7 +3,7 @@ name: Build Docker image
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- release
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-docker:
|
build-docker:
|
||||||
|
2
.github/workflows/cancel.yml
vendored
2
.github/workflows/cancel.yml
vendored
@@ -3,7 +3,7 @@ name: Cancel previous runs
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- release
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
2
.github/workflows/publish-docker.yml
vendored
2
.github/workflows/publish-docker.yml
vendored
@@ -3,7 +3,7 @@ name: Publish Docker
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- release
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-docker:
|
publish-docker:
|
||||||
|
2
.github/workflows/sentry-production.yml
vendored
2
.github/workflows/sentry-production.yml
vendored
@@ -3,7 +3,7 @@ name: New Sentry production release
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- release
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sentry:
|
sentry:
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,4 +25,3 @@ 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
|
||||||
|
|
||||||
|
@@ -4755,9 +4755,9 @@ loader-runner@^4.2.0:
|
|||||||
integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==
|
integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==
|
||||||
|
|
||||||
loader-utils@^2.0.0:
|
loader-utils@^2.0.0:
|
||||||
version "2.0.2"
|
version "2.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.2.tgz#d6e3b4fb81870721ae4e0868ab11dd638368c129"
|
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c"
|
||||||
integrity sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==
|
integrity sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==
|
||||||
dependencies:
|
dependencies:
|
||||||
big.js "^5.2.2"
|
big.js "^5.2.2"
|
||||||
emojis-list "^3.0.0"
|
emojis-list "^3.0.0"
|
||||||
|
29
package.json
29
package.json
@@ -31,6 +31,7 @@
|
|||||||
"@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",
|
||||||
"i18next-browser-languagedetector": "6.1.4",
|
"i18next-browser-languagedetector": "6.1.4",
|
||||||
@@ -41,7 +42,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.0.16",
|
"perfect-freehand": "1.2.0",
|
||||||
"pica": "7.1.1",
|
"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",
|
||||||
@@ -50,11 +51,23 @@
|
|||||||
"pwacompat": "2.0.17",
|
"pwacompat": "2.0.17",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-scripts": "4.0.3",
|
"react-scripts": "5.0.1",
|
||||||
"roughjs": "4.5.2",
|
"roughjs": "4.5.2",
|
||||||
"sass": "1.51.0",
|
"sass": "1.51.0",
|
||||||
"socket.io-client": "2.3.1",
|
"socket.io-client": "2.3.1",
|
||||||
"typescript": "4.5.5"
|
"typescript": "4.9.4",
|
||||||
|
"workbox-background-sync": "^6.5.4",
|
||||||
|
"workbox-broadcast-update": "^6.5.4",
|
||||||
|
"workbox-cacheable-response": "^6.5.4",
|
||||||
|
"workbox-core": "^6.5.4",
|
||||||
|
"workbox-expiration": "^6.5.4",
|
||||||
|
"workbox-google-analytics": "^6.5.4",
|
||||||
|
"workbox-navigation-preload": "^6.5.4",
|
||||||
|
"workbox-precaching": "^6.5.4",
|
||||||
|
"workbox-range-requests": "^6.5.4",
|
||||||
|
"workbox-routing": "^6.5.4",
|
||||||
|
"workbox-strategies": "^6.5.4",
|
||||||
|
"workbox-streams": "^6.5.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@excalidraw/eslint-config": "1.0.0",
|
"@excalidraw/eslint-config": "1.0.0",
|
||||||
@@ -67,6 +80,7 @@
|
|||||||
"dotenv": "16.0.1",
|
"dotenv": "16.0.1",
|
||||||
"eslint-config-prettier": "8.5.0",
|
"eslint-config-prettier": "8.5.0",
|
||||||
"eslint-plugin-prettier": "3.3.1",
|
"eslint-plugin-prettier": "3.3.1",
|
||||||
|
"http-server": "14.1.1",
|
||||||
"husky": "7.0.4",
|
"husky": "7.0.4",
|
||||||
"jest-canvas-mock": "2.4.0",
|
"jest-canvas-mock": "2.4.0",
|
||||||
"lint-staged": "12.3.7",
|
"lint-staged": "12.3.7",
|
||||||
@@ -74,9 +88,6 @@
|
|||||||
"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"
|
||||||
},
|
},
|
||||||
@@ -93,10 +104,9 @@
|
|||||||
"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": "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": "yarn build:app && yarn build:version",
|
||||||
"build": "yarn build:prebuild && yarn build:app && yarn build:version",
|
|
||||||
"eject": "react-scripts eject",
|
"eject": "react-scripts eject",
|
||||||
"fix:code": "yarn test:code --fix",
|
"fix:code": "yarn test:code --fix",
|
||||||
"fix:other": "yarn prettier --write",
|
"fix:other": "yarn prettier --write",
|
||||||
@@ -106,6 +116,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:production": "npm run build && npx http-server build -a localhost -p 5001 -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 .",
|
||||||
|
BIN
public/Assistant-Bold.woff2
Normal file
BIN
public/Assistant-Bold.woff2
Normal file
Binary file not shown.
BIN
public/Assistant-Medium.woff2
Normal file
BIN
public/Assistant-Medium.woff2
Normal file
Binary file not shown.
BIN
public/Assistant-Regular.woff2
Normal file
BIN
public/Assistant-Regular.woff2
Normal file
Binary file not shown.
BIN
public/Assistant-SemiBold.woff2
Normal file
BIN
public/Assistant-SemiBold.woff2
Normal file
Binary file not shown.
@@ -11,3 +11,28 @@
|
|||||||
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;
|
||||||
|
}
|
||||||
|
@@ -8,49 +8,76 @@
|
|||||||
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" />
|
||||||
|
|
||||||
<meta name="theme-color" content="#000" />
|
<!-- Primary Meta Tags -->
|
||||||
|
<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 -->
|
<!------------------------------------------------------------------------->
|
||||||
<meta property="og:url" content="https://excalidraw.com" />
|
<!-- to minimize white flash on load when user has dark mode enabled -->
|
||||||
<meta property="og:site_name" content="Excalidraw" />
|
<script>
|
||||||
<meta property="og:type" content="website" />
|
try {
|
||||||
<meta property="og:title" content="Excalidraw" />
|
//
|
||||||
<meta
|
const theme = window.localStorage.getItem("excalidraw-theme");
|
||||||
property="og:description"
|
if (theme === "dark") {
|
||||||
content="Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
document.documentElement.classList.add("dark");
|
||||||
/>
|
}
|
||||||
<!-- OG tags require an absolute url for images -->
|
} catch {}
|
||||||
<meta
|
</script>
|
||||||
property="og:image"
|
<style>
|
||||||
name="twitter:image"
|
html.dark {
|
||||||
content="https://excalidraw.com/og-image.png"
|
background-color: #121212;
|
||||||
/>
|
color: #fff;
|
||||||
<meta
|
}
|
||||||
property="og:image:secure_url"
|
</style>
|
||||||
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.
|
||||||
@@ -98,7 +125,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;
|
||||||
@@ -139,8 +166,8 @@
|
|||||||
body,
|
body,
|
||||||
html {
|
html {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
--ui-font: system-ui, BlinkMacSystemFont, -apple-system, Segoe UI,
|
--ui-font: Assistant, system-ui, BlinkMacSystemFont, -apple-system,
|
||||||
Roboto, Helvetica, Arial, sans-serif;
|
Segoe UI, 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%;
|
||||||
|
|
||||||
@@ -155,7 +182,7 @@
|
|||||||
width: 1px;
|
width: 1px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
clip: rect(1px, 1px, 1px, 1px);
|
clip: rect(1px, 1px, 1px, 1px);
|
||||||
white-space: nowrap; /* added line */
|
white-space: nowrap;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
public/og-fb-v1.png
Normal file
BIN
public/og-fb-v1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
public/og-general-v1.png
Normal file
BIN
public/og-general-v1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
public/og-twitter-v1.png
Normal file
BIN
public/og-twitter-v1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
@@ -1,3 +1,9 @@
|
|||||||
|
User-agent: Twitterbot
|
||||||
|
Disallow:
|
||||||
|
|
||||||
|
User-agent: facebookexternalhit
|
||||||
|
Disallow:
|
||||||
|
|
||||||
user-agent: *
|
user-agent: *
|
||||||
Allow: /$
|
Allow: /$
|
||||||
Disallow: /
|
Disallow: /
|
||||||
|
@@ -1,81 +0,0 @@
|
|||||||
// eslint-disable-next-line no-restricted-globals
|
|
||||||
// eslint-disable-next-line no-unused-expressions
|
|
||||||
|
|
||||||
/* eslint-disable no-restricted-globals */
|
|
||||||
/* global importScripts, workbox */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Welcome to your Workbox-powered service worker!
|
|
||||||
*
|
|
||||||
* You'll need to register this file in your web app and you should
|
|
||||||
* disable HTTP caching for this file too.
|
|
||||||
* See https://goo.gl/nhQhGp
|
|
||||||
*
|
|
||||||
* The rest of the code is auto-generated. Please don't update this file
|
|
||||||
* directly; instead, make changes to your Workbox build configuration
|
|
||||||
* and re-run your build process.
|
|
||||||
* See https://goo.gl/2aRDsh
|
|
||||||
*/
|
|
||||||
|
|
||||||
// in dev, `process` is undefined because this file is not compiled until build
|
|
||||||
const IS_DEVELOPMENT =
|
|
||||||
typeof process === "undefined" || process.env.NODE_ENV !== "production";
|
|
||||||
|
|
||||||
if (IS_DEVELOPMENT) {
|
|
||||||
importScripts(
|
|
||||||
"https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js",
|
|
||||||
);
|
|
||||||
workbox.setConfig({
|
|
||||||
debug: true,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
importScripts("/workbox/workbox-sw.js");
|
|
||||||
workbox.setConfig({
|
|
||||||
modulePathPrefix: "/workbox/",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addEventListener("message", (event) => {
|
|
||||||
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
||||||
self.skipWaiting();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
workbox.core.clientsClaim();
|
|
||||||
|
|
||||||
if (!IS_DEVELOPMENT) {
|
|
||||||
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST);
|
|
||||||
|
|
||||||
workbox.routing.registerNavigationRoute(
|
|
||||||
workbox.precaching.getCacheKeyForURL("./index.html"),
|
|
||||||
{
|
|
||||||
blacklist: [/^\/_/, /\/[^/?]+\.[^/]+$/],
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cache relevant font files
|
|
||||||
workbox.routing.registerRoute(
|
|
||||||
new RegExp("/(fonts.css|.+.(ttf|woff2|otf))"),
|
|
||||||
new workbox.strategies.StaleWhileRevalidate({
|
|
||||||
cacheName: "fonts",
|
|
||||||
plugins: [new workbox.expiration.Plugin({ maxEntries: 10 })],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.addEventListener("fetch", (event) => {
|
|
||||||
if (
|
|
||||||
event.request.method === "POST" &&
|
|
||||||
event.request.url.endsWith("/web-share-target")
|
|
||||||
) {
|
|
||||||
return event.respondWith(
|
|
||||||
(async () => {
|
|
||||||
const formData = await event.request.formData();
|
|
||||||
const file = formData.get("file");
|
|
||||||
const webShareTargetCache = await caches.open("web-share-target");
|
|
||||||
await webShareTargetCache.put("shared-file", new Response(file));
|
|
||||||
return Response.redirect("/?web-share-target", 303);
|
|
||||||
})(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
@@ -15,6 +15,7 @@ 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",
|
||||||
@@ -23,6 +24,7 @@ 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",
|
||||||
@@ -48,8 +50,8 @@ const crowdinMap = {
|
|||||||
"lv-LV": "en-lv",
|
"lv-LV": "en-lv",
|
||||||
"cs-CZ": "en-cs",
|
"cs-CZ": "en-cs",
|
||||||
"kk-KZ": "en-kk",
|
"kk-KZ": "en-kk",
|
||||||
"vi-vn": "en-vi",
|
"vi-VN": "en-vi",
|
||||||
"mr-in": "en-mr",
|
"mr-IN": "en-mr",
|
||||||
};
|
};
|
||||||
|
|
||||||
const flags = {
|
const flags = {
|
||||||
@@ -65,6 +67,7 @@ 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": "🇭🇺",
|
||||||
@@ -74,6 +77,7 @@ 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": "🇲🇲",
|
||||||
@@ -116,6 +120,7 @@ const languages = {
|
|||||||
"fa-IR": "فارسی",
|
"fa-IR": "فارسی",
|
||||||
"fi-FI": "Suomi",
|
"fi-FI": "Suomi",
|
||||||
"fr-FR": "Français",
|
"fr-FR": "Français",
|
||||||
|
"gl-ES": "Galego",
|
||||||
"he-IL": "עברית",
|
"he-IL": "עברית",
|
||||||
"hi-IN": "हिन्दी",
|
"hi-IN": "हिन्दी",
|
||||||
"hu-HU": "Magyar",
|
"hu-HU": "Magyar",
|
||||||
@@ -125,6 +130,7 @@ const languages = {
|
|||||||
"kab-KAB": "Taqbaylit",
|
"kab-KAB": "Taqbaylit",
|
||||||
"kk-KZ": "Қазақ тілі",
|
"kk-KZ": "Қазақ тілі",
|
||||||
"ko-KR": "한국어",
|
"ko-KR": "한국어",
|
||||||
|
"ku-TR": "Kurdî",
|
||||||
"lt-LT": "Lietuvių",
|
"lt-LT": "Lietuvių",
|
||||||
"lv-LV": "Latviešu",
|
"lv-LV": "Latviešu",
|
||||||
"my-MM": "Burmese",
|
"my-MM": "Burmese",
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
const fs = require("fs");
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
// for development purposes we want to have the service-worker.js file
|
|
||||||
// accessible from the public folder. On build though, we need to compile it
|
|
||||||
// and CRA expects that file to be in src/ folder.
|
|
||||||
const moveServiceWorkerScript = () => {
|
|
||||||
const oldPath = path.resolve(__dirname, "../public/service-worker.js");
|
|
||||||
const newPath = path.resolve(__dirname, "../src/service-worker.js");
|
|
||||||
|
|
||||||
fs.rename(oldPath, newPath, (error) => {
|
|
||||||
if (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
console.info("public/service-worker.js moved to src/");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
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 theme={appState.theme} />}
|
icon={AlignTopIcon}
|
||||||
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 theme={appState.theme} />}
|
icon={AlignBottomIcon}
|
||||||
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 theme={appState.theme} />}
|
icon={AlignLeftIcon}
|
||||||
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 theme={appState.theme} />}
|
icon={AlignRightIcon}
|
||||||
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 theme={appState.theme} />}
|
icon={CenterVerticallyIcon}
|
||||||
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 theme={appState.theme} />}
|
icon={CenterHorizontallyIcon}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
title={t("labels.centerHorizontally")}
|
title={t("labels.centerHorizontally")}
|
||||||
aria-label={t("labels.centerHorizontally")}
|
aria-label={t("labels.centerHorizontally")}
|
||||||
|
@@ -6,6 +6,10 @@ import {
|
|||||||
measureText,
|
measureText,
|
||||||
redrawTextBoundingBox,
|
redrawTextBoundingBox,
|
||||||
} from "../element/textElement";
|
} from "../element/textElement";
|
||||||
|
import {
|
||||||
|
getOriginalContainerHeightFromCache,
|
||||||
|
resetOriginalContainerCache,
|
||||||
|
} from "../element/textWysiwyg";
|
||||||
import {
|
import {
|
||||||
hasBoundTextElement,
|
hasBoundTextElement,
|
||||||
isTextBindableContainer,
|
isTextBindableContainer,
|
||||||
@@ -38,6 +42,11 @@ export const actionUnbindText = register({
|
|||||||
boundTextElement.originalText,
|
boundTextElement.originalText,
|
||||||
getFontString(boundTextElement),
|
getFontString(boundTextElement),
|
||||||
);
|
);
|
||||||
|
const originalContainerHeight = getOriginalContainerHeightFromCache(
|
||||||
|
element.id,
|
||||||
|
);
|
||||||
|
resetOriginalContainerCache(element.id);
|
||||||
|
|
||||||
mutateElement(boundTextElement as ExcalidrawTextElement, {
|
mutateElement(boundTextElement as ExcalidrawTextElement, {
|
||||||
containerId: null,
|
containerId: null,
|
||||||
width,
|
width,
|
||||||
@@ -49,6 +58,9 @@ export const actionUnbindText = register({
|
|||||||
boundElements: element.boundElements?.filter(
|
boundElements: element.boundElements?.filter(
|
||||||
(ele) => ele.id !== boundTextElement.id,
|
(ele) => ele.id !== boundTextElement.id,
|
||||||
),
|
),
|
||||||
|
height: originalContainerHeight
|
||||||
|
? originalContainerHeight
|
||||||
|
: element.height,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,8 +1,13 @@
|
|||||||
import { ColorPicker } from "../components/ColorPicker";
|
import { ColorPicker } from "../components/ColorPicker";
|
||||||
import { eraser, zoomIn, zoomOut } from "../components/icons";
|
import {
|
||||||
|
eraser,
|
||||||
|
MoonIcon,
|
||||||
|
SunIcon,
|
||||||
|
ZoomInIcon,
|
||||||
|
ZoomOutIcon,
|
||||||
|
} from "../components/icons";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import { DarkModeToggle } from "../components/DarkModeToggle";
|
import { MIN_ZOOM, THEME, ZOOM_STEP } from "../constants";
|
||||||
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";
|
||||||
@@ -18,6 +23,8 @@ 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",
|
||||||
@@ -83,6 +90,7 @@ export const actionClearCanvas = register({
|
|||||||
|
|
||||||
export const actionZoomIn = register({
|
export const actionZoomIn = register({
|
||||||
name: "zoomIn",
|
name: "zoomIn",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
perform: (_elements, appState, _, app) => {
|
perform: (_elements, appState, _, app) => {
|
||||||
return {
|
return {
|
||||||
@@ -103,13 +111,13 @@ export const actionZoomIn = register({
|
|||||||
PanelComponent: ({ updateData }) => (
|
PanelComponent: ({ updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={zoomIn}
|
className="zoom-in-button zoom-button"
|
||||||
|
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) =>
|
||||||
@@ -119,6 +127,7 @@ export const actionZoomIn = register({
|
|||||||
|
|
||||||
export const actionZoomOut = register({
|
export const actionZoomOut = register({
|
||||||
name: "zoomOut",
|
name: "zoomOut",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
perform: (_elements, appState, _, app) => {
|
perform: (_elements, appState, _, app) => {
|
||||||
return {
|
return {
|
||||||
@@ -139,13 +148,13 @@ export const actionZoomOut = register({
|
|||||||
PanelComponent: ({ updateData }) => (
|
PanelComponent: ({ updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={zoomOut}
|
className="zoom-out-button zoom-button"
|
||||||
|
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) =>
|
||||||
@@ -155,6 +164,7 @@ export const actionZoomOut = register({
|
|||||||
|
|
||||||
export const actionResetZoom = register({
|
export const actionResetZoom = register({
|
||||||
name: "resetZoom",
|
name: "resetZoom",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
perform: (_elements, appState, _, app) => {
|
perform: (_elements, appState, _, app) => {
|
||||||
return {
|
return {
|
||||||
@@ -176,13 +186,12 @@ 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"
|
className="reset-zoom-button 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>
|
||||||
@@ -206,7 +215,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, ZOOM_STEP),
|
Math.max(zoomAdjustedToSteps, MIN_ZOOM),
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
return clampedZoomValueToFitElements as NormalizedZoomValue;
|
return clampedZoomValueToFitElements as NormalizedZoomValue;
|
||||||
@@ -265,6 +274,7 @@ export const actionZoomToSelected = register({
|
|||||||
|
|
||||||
export const actionZoomToFit = register({
|
export const actionZoomToFit = register({
|
||||||
name: "zoomToFit",
|
name: "zoomToFit",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
perform: (elements, appState) => zoomToFitElements(elements, appState, false),
|
perform: (elements, appState) => zoomToFitElements(elements, appState, false),
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
@@ -276,6 +286,7 @@ export const actionZoomToFit = register({
|
|||||||
|
|
||||||
export const actionToggleTheme = register({
|
export const actionToggleTheme = register({
|
||||||
name: "toggleTheme",
|
name: "toggleTheme",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
perform: (_, appState, value) => {
|
perform: (_, appState, value) => {
|
||||||
return {
|
return {
|
||||||
@@ -288,14 +299,19 @@ export const actionToggleTheme = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ appState, updateData }) => (
|
PanelComponent: ({ appState, updateData }) => (
|
||||||
<div style={{ marginInlineStart: "0.25rem" }}>
|
<MenuItem
|
||||||
<DarkModeToggle
|
label={
|
||||||
value={appState.theme}
|
appState.theme === "dark"
|
||||||
onChange={(theme) => {
|
? t("buttons.lightMode")
|
||||||
updateData(theme);
|
: t("buttons.darkMode")
|
||||||
}}
|
}
|
||||||
/>
|
onClick={() => {
|
||||||
</div>
|
updateData(appState.theme === THEME.LIGHT ? THEME.DARK : THEME.LIGHT);
|
||||||
|
}}
|
||||||
|
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,
|
||||||
});
|
});
|
||||||
|
@@ -3,6 +3,7 @@ import { register } from "./register";
|
|||||||
import {
|
import {
|
||||||
copyTextToSystemClipboard,
|
copyTextToSystemClipboard,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
|
probablySupportsClipboardBlob,
|
||||||
probablySupportsClipboardWriteText,
|
probablySupportsClipboardWriteText,
|
||||||
} from "../clipboard";
|
} from "../clipboard";
|
||||||
import { actionDeleteSelected } from "./actionDeleteSelected";
|
import { actionDeleteSelected } from "./actionDeleteSelected";
|
||||||
@@ -23,11 +24,31 @@ export const actionCopy = register({
|
|||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
contextItemPredicate: (elements, appState, appProps, app) => {
|
||||||
|
return app.device.isMobile && !!navigator.clipboard;
|
||||||
|
},
|
||||||
contextItemLabel: "labels.copy",
|
contextItemLabel: "labels.copy",
|
||||||
// don't supply a shortcut since we handle this conditionally via onCopy event
|
// don't supply a shortcut since we handle this conditionally via onCopy event
|
||||||
keyTest: undefined,
|
keyTest: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const actionPaste = register({
|
||||||
|
name: "paste",
|
||||||
|
trackEvent: { category: "element" },
|
||||||
|
perform: (elements: any, appStates: any, data, app) => {
|
||||||
|
app.pasteFromClipboard(null);
|
||||||
|
return {
|
||||||
|
commitToHistory: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
contextItemPredicate: (elements, appState, appProps, app) => {
|
||||||
|
return app.device.isMobile && !!navigator.clipboard;
|
||||||
|
},
|
||||||
|
contextItemLabel: "labels.paste",
|
||||||
|
// don't supply a shortcut since we handle this conditionally via onCopy event
|
||||||
|
keyTest: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
export const actionCut = register({
|
export const actionCut = register({
|
||||||
name: "cut",
|
name: "cut",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
@@ -35,8 +56,11 @@ export const actionCut = register({
|
|||||||
actionCopy.perform(elements, appState, data, app);
|
actionCopy.perform(elements, appState, data, app);
|
||||||
return actionDeleteSelected.perform(elements, appState);
|
return actionDeleteSelected.perform(elements, appState);
|
||||||
},
|
},
|
||||||
|
contextItemPredicate: (elements, appState, appProps, app) => {
|
||||||
|
return app.device.isMobile && !!navigator.clipboard;
|
||||||
|
},
|
||||||
contextItemLabel: "labels.cut",
|
contextItemLabel: "labels.cut",
|
||||||
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.X,
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.X,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionCopyAsSvg = register({
|
export const actionCopyAsSvg = register({
|
||||||
@@ -77,6 +101,9 @@ export const actionCopyAsSvg = register({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
contextItemPredicate: (elements) => {
|
||||||
|
return probablySupportsClipboardWriteText && elements.length > 0;
|
||||||
|
},
|
||||||
contextItemLabel: "labels.copyAsSvg",
|
contextItemLabel: "labels.copyAsSvg",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -131,6 +158,9 @@ export const actionCopyAsPng = register({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
contextItemPredicate: (elements) => {
|
||||||
|
return probablySupportsClipboardBlob && elements.length > 0;
|
||||||
|
},
|
||||||
contextItemLabel: "labels.copyAsPng",
|
contextItemLabel: "labels.copyAsPng",
|
||||||
keyTest: (event) => event.code === CODES.C && event.altKey && event.shiftKey,
|
keyTest: (event) => event.code === CODES.C && event.altKey && event.shiftKey,
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
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";
|
||||||
@@ -13,6 +12,7 @@ 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,13 +72,22 @@ export const actionDeleteSelected = register({
|
|||||||
if (!element) {
|
if (!element) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (
|
// case: no point selected → do nothing, as deleting the whole element
|
||||||
// case: no point selected → delete whole element
|
// is most likely a mistake, where you wanted to delete a specific point
|
||||||
selectedPointsIndices == null ||
|
// but failed to select it (or you thought it's selected, while it was
|
||||||
// case: deleting last remaining point
|
// only in a hover state)
|
||||||
element.points.length < 2
|
if (selectedPointsIndices == null) {
|
||||||
) {
|
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 {
|
||||||
@@ -149,7 +158,7 @@ export const actionDeleteSelected = register({
|
|||||||
PanelComponent: ({ elements, appState, updateData }) => (
|
PanelComponent: ({ elements, appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={trash}
|
icon={TrashIcon}
|
||||||
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 theme={appState.theme} />}
|
icon={DistributeHorizontallyIcon}
|
||||||
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 theme={appState.theme} />}
|
icon={DistributeVerticallyIcon}
|
||||||
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,7 +4,6 @@ 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";
|
||||||
@@ -19,6 +18,7 @@ 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={clone}
|
icon={DuplicateIcon}
|
||||||
title={`${t("labels.duplicateSelection")} — ${getShortcutKey(
|
title={`${t("labels.duplicateSelection")} — ${getShortcutKey(
|
||||||
"CtrlOrCmd+D",
|
"CtrlOrCmd+D",
|
||||||
)}`}
|
)}`}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { load, questionCircle, saveAs } from "../components/icons";
|
import { LoadIcon, 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,6 +19,8 @@ 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",
|
||||||
@@ -177,6 +179,7 @@ export const actionSaveToActiveFile = register({
|
|||||||
|
|
||||||
export const actionSaveFileToDisk = register({
|
export const actionSaveFileToDisk = register({
|
||||||
name: "saveFileToDisk",
|
name: "saveFileToDisk",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "export" },
|
trackEvent: { category: "export" },
|
||||||
perform: async (elements, appState, value, app) => {
|
perform: async (elements, appState, value, app) => {
|
||||||
try {
|
try {
|
||||||
@@ -245,14 +248,12 @@ 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 }) => (
|
||||||
<ToolButton
|
<MenuItem
|
||||||
type="button"
|
label={t("buttons.load")}
|
||||||
icon={load}
|
icon={LoadIcon}
|
||||||
title={t("buttons.load")}
|
|
||||||
aria-label={t("buttons.load")}
|
|
||||||
showAriaLabel={useDevice().isMobile}
|
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
data-testid="load-button"
|
dataTestId="load-button"
|
||||||
|
shortcut={getShortcutFromShortcutName("loadScene")}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
@@ -33,9 +33,6 @@ export const actionFinalize = register({
|
|||||||
endBindingElement,
|
endBindingElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const selectedLinearElement = appState.selectedLinearElement
|
|
||||||
? new LinearElementEditor(element, scene, appState)
|
|
||||||
: null;
|
|
||||||
return {
|
return {
|
||||||
elements:
|
elements:
|
||||||
element.points.length < 2 || isInvisiblySmallElement(element)
|
element.points.length < 2 || isInvisiblySmallElement(element)
|
||||||
@@ -45,7 +42,6 @@ export const actionFinalize = register({
|
|||||||
...appState,
|
...appState,
|
||||||
cursorButton: "up",
|
cursorButton: "up",
|
||||||
editingLinearElement: null,
|
editingLinearElement: null,
|
||||||
selectedLinearElement,
|
|
||||||
},
|
},
|
||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
@@ -188,7 +184,7 @@ export const actionFinalize = register({
|
|||||||
// To select the linear element when user has finished mutipoint editing
|
// To select the linear element when user has finished mutipoint editing
|
||||||
selectedLinearElement:
|
selectedLinearElement:
|
||||||
multiPointElement && isLinearElement(multiPointElement)
|
multiPointElement && isLinearElement(multiPointElement)
|
||||||
? new LinearElementEditor(multiPointElement, scene, appState)
|
? new LinearElementEditor(multiPointElement, scene)
|
||||||
: appState.selectedLinearElement,
|
: appState.selectedLinearElement,
|
||||||
pendingImageElementId: null,
|
pendingImageElementId: null,
|
||||||
},
|
},
|
||||||
|
@@ -6,10 +6,15 @@ 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 { LinearElementEditor } from "../element/linearElementEditor";
|
|
||||||
import { arrayToMap } from "../utils";
|
import { arrayToMap } from "../utils";
|
||||||
|
import {
|
||||||
|
getElementAbsoluteCoords,
|
||||||
|
getElementPointsCoords,
|
||||||
|
} from "../element/bounds";
|
||||||
|
import { isLinearElement } from "../element/typeChecks";
|
||||||
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||||
|
import { KEYS } from "../keys";
|
||||||
|
|
||||||
const enableActionFlipHorizontal = (
|
const enableActionFlipHorizontal = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
@@ -59,7 +64,8 @@ export const actionFlipVertical = register({
|
|||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) => event.shiftKey && event.code === "KeyV",
|
keyTest: (event) =>
|
||||||
|
event.shiftKey && event.code === "KeyV" && !event[KEYS.CTRL_OR_CMD],
|
||||||
contextItemLabel: "labels.flipVertical",
|
contextItemLabel: "labels.flipVertical",
|
||||||
contextItemPredicate: (elements, appState) =>
|
contextItemPredicate: (elements, appState) =>
|
||||||
enableActionFlipVertical(elements, appState),
|
enableActionFlipVertical(elements, appState),
|
||||||
@@ -118,13 +124,6 @@ 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),
|
||||||
@@ -132,7 +131,6 @@ 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
|
||||||
@@ -146,30 +144,47 @@ 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);
|
||||||
|
}
|
||||||
|
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 {
|
||||||
// calculate new x-coord for transformation
|
const elWidth = initialPointsCoords
|
||||||
newNCoordsX = usingNWHandle ? element.x + 2 * width : element.x - 2 * width;
|
? initialPointsCoords[2] - initialPointsCoords[0]
|
||||||
|
: 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),
|
||||||
true,
|
false,
|
||||||
element,
|
element,
|
||||||
usingNWHandle ? "nw" : "ne",
|
usingNWHandle ? "nw" : "ne",
|
||||||
false,
|
true,
|
||||||
newNCoordsX,
|
usingNWHandle ? startPoint[0] + elWidth : startPoint[0] - elWidth,
|
||||||
nHandle[1],
|
startPoint[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)
|
||||||
@@ -186,9 +201,30 @@ 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);
|
||||||
|
|
||||||
|
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 { CODES, KEYS } from "../keys";
|
import { 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.code === CODES.G,
|
!event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.key === KEYS.G,
|
||||||
PanelComponent: ({ elements, appState, updateData }) => (
|
PanelComponent: ({ elements, appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
@@ -189,7 +189,9 @@ export const actionUngroup = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.code === CODES.G,
|
event.shiftKey &&
|
||||||
|
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 { undo, redo } from "../components/icons";
|
import { UndoIcon, RedoIcon } 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={undo}
|
icon={UndoIcon}
|
||||||
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={redo}
|
icon={RedoIcon}
|
||||||
aria-label={t("buttons.redo")}
|
aria-label={t("buttons.redo")}
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
size={data?.size || "medium"}
|
size={data?.size || "medium"}
|
||||||
|
49
src/actions/actionLinearEditor.ts
Normal file
49
src/actions/actionLinearEditor.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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";
|
||||||
|
},
|
||||||
|
});
|
@@ -1,11 +1,12 @@
|
|||||||
import { menu, palette } from "../components/icons";
|
import { HamburgerMenuIcon, HelpIcon, 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 { CODES, KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { HelpIcon } from "../components/HelpIcon";
|
import { HelpButton } from "../components/HelpButton";
|
||||||
|
import MenuItem from "../components/MenuItem";
|
||||||
|
|
||||||
export const actionToggleCanvasMenu = register({
|
export const actionToggleCanvasMenu = register({
|
||||||
name: "toggleCanvasMenu",
|
name: "toggleCanvasMenu",
|
||||||
@@ -20,7 +21,7 @@ export const actionToggleCanvasMenu = register({
|
|||||||
PanelComponent: ({ appState, updateData }) => (
|
PanelComponent: ({ appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={menu}
|
icon={HamburgerMenuIcon}
|
||||||
aria-label={t("buttons.menu")}
|
aria-label={t("buttons.menu")}
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
selected={appState.openMenu === "canvas"}
|
selected={appState.openMenu === "canvas"}
|
||||||
@@ -55,6 +56,7 @@ export const actionToggleEditMenu = register({
|
|||||||
|
|
||||||
export const actionFullScreen = register({
|
export const actionFullScreen = register({
|
||||||
name: "toggleFullScreen",
|
name: "toggleFullScreen",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "canvas", predicate: (appState) => !isFullScreen() },
|
trackEvent: { category: "canvas", predicate: (appState) => !isFullScreen() },
|
||||||
perform: () => {
|
perform: () => {
|
||||||
if (!isFullScreen()) {
|
if (!isFullScreen()) {
|
||||||
@@ -67,26 +69,36 @@ export const actionFullScreen = register({
|
|||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) => event.code === CODES.F && !event[KEYS.CTRL_OR_CMD],
|
keyTest: (event) => event.key === KEYS.F && !event[KEYS.CTRL_OR_CMD],
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionShortcuts = register({
|
export const actionShortcuts = register({
|
||||||
name: "toggleShortcuts",
|
name: "toggleShortcuts",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "menu", action: "toggleHelpDialog" },
|
trackEvent: { category: "menu", action: "toggleHelpDialog" },
|
||||||
perform: (_elements, appState, _, { focusContainer }) => {
|
perform: (_elements, appState, _, { focusContainer }) => {
|
||||||
if (appState.showHelpDialog) {
|
if (appState.openDialog === "help") {
|
||||||
focusContainer();
|
focusContainer();
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
showHelpDialog: !appState.showHelpDialog,
|
openDialog: appState.openDialog === "help" ? null : "help",
|
||||||
},
|
},
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ updateData }) => (
|
PanelComponent: ({ updateData, isInHamburgerMenu }) =>
|
||||||
<HelpIcon title={t("helpDialog.title")} onClick={updateData} />
|
isInHamburgerMenu ? (
|
||||||
),
|
<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,
|
||||||
});
|
});
|
||||||
|
@@ -6,6 +6,7 @@ import { register } from "./register";
|
|||||||
|
|
||||||
export const actionGoToCollaborator = register({
|
export const actionGoToCollaborator = register({
|
||||||
name: "goToCollaborator",
|
name: "goToCollaborator",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "collab" },
|
trackEvent: { category: "collab" },
|
||||||
perform: (_elements, appState, value) => {
|
perform: (_elements, appState, value) => {
|
||||||
const point = value as Collaborator["pointer"];
|
const point = value as Collaborator["pointer"];
|
||||||
|
@@ -2,42 +2,47 @@ 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,
|
||||||
EdgeRoundIcon,
|
|
||||||
EdgeSharpIcon,
|
|
||||||
FillCrossHatchIcon,
|
|
||||||
FillHachureIcon,
|
|
||||||
FillSolidIcon,
|
|
||||||
FontFamilyCodeIcon,
|
|
||||||
FontFamilyHandDrawnIcon,
|
|
||||||
FontFamilyNormalIcon,
|
|
||||||
FontSizeExtraLargeIcon,
|
|
||||||
FontSizeLargeIcon,
|
|
||||||
FontSizeMediumIcon,
|
|
||||||
FontSizeSmallIcon,
|
|
||||||
SloppinessArchitectIcon,
|
|
||||||
SloppinessArtistIcon,
|
|
||||||
SloppinessCartoonistIcon,
|
|
||||||
StrokeStyleDashedIcon,
|
StrokeStyleDashedIcon,
|
||||||
StrokeStyleDottedIcon,
|
StrokeStyleDottedIcon,
|
||||||
StrokeStyleSolidIcon,
|
|
||||||
StrokeWidthIcon,
|
|
||||||
TextAlignCenterIcon,
|
|
||||||
TextAlignLeftIcon,
|
|
||||||
TextAlignRightIcon,
|
|
||||||
TextAlignTopIcon,
|
TextAlignTopIcon,
|
||||||
TextAlignBottomIcon,
|
TextAlignBottomIcon,
|
||||||
TextAlignMiddleIcon,
|
TextAlignMiddleIcon,
|
||||||
|
FillHachureIcon,
|
||||||
|
FillCrossHatchIcon,
|
||||||
|
FillSolidIcon,
|
||||||
|
SloppinessArchitectIcon,
|
||||||
|
SloppinessArtistIcon,
|
||||||
|
SloppinessCartoonistIcon,
|
||||||
|
StrokeWidthBaseIcon,
|
||||||
|
StrokeWidthBoldIcon,
|
||||||
|
StrokeWidthExtraBoldIcon,
|
||||||
|
FontSizeSmallIcon,
|
||||||
|
FontSizeMediumIcon,
|
||||||
|
FontSizeLargeIcon,
|
||||||
|
FontSizeExtraLargeIcon,
|
||||||
|
EdgeSharpIcon,
|
||||||
|
EdgeRoundIcon,
|
||||||
|
FreedrawIcon,
|
||||||
|
FontFamilyNormalIcon,
|
||||||
|
FontFamilyCodeIcon,
|
||||||
|
TextAlignLeftIcon,
|
||||||
|
TextAlignCenterIcon,
|
||||||
|
TextAlignRightIcon,
|
||||||
} from "../components/icons";
|
} from "../components/icons";
|
||||||
import {
|
import {
|
||||||
DEFAULT_FONT_FAMILY,
|
DEFAULT_FONT_FAMILY,
|
||||||
DEFAULT_FONT_SIZE,
|
DEFAULT_FONT_SIZE,
|
||||||
FONT_FAMILY,
|
FONT_FAMILY,
|
||||||
|
ROUNDNESS,
|
||||||
VERTICAL_ALIGN,
|
VERTICAL_ALIGN,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import {
|
import {
|
||||||
@@ -53,7 +58,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
isBoundToContainer,
|
isBoundToContainer,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isLinearElementType,
|
isUsingAdaptiveRadius,
|
||||||
} from "../element/typeChecks";
|
} from "../element/typeChecks";
|
||||||
import {
|
import {
|
||||||
Arrowhead,
|
Arrowhead,
|
||||||
@@ -68,7 +73,7 @@ import { getLanguage, t } from "../i18n";
|
|||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { randomInteger } from "../random";
|
import { randomInteger } from "../random";
|
||||||
import {
|
import {
|
||||||
canChangeSharpness,
|
canChangeRoundness,
|
||||||
canHaveArrowheads,
|
canHaveArrowheads,
|
||||||
getCommonAttributeOfSelectedElements,
|
getCommonAttributeOfSelectedElements,
|
||||||
getSelectedElements,
|
getSelectedElements,
|
||||||
@@ -307,17 +312,17 @@ export const actionChangeFillStyle = register({
|
|||||||
{
|
{
|
||||||
value: "hachure",
|
value: "hachure",
|
||||||
text: t("labels.hachure"),
|
text: t("labels.hachure"),
|
||||||
icon: <FillHachureIcon theme={appState.theme} />,
|
icon: FillHachureIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "cross-hatch",
|
value: "cross-hatch",
|
||||||
text: t("labels.crossHatch"),
|
text: t("labels.crossHatch"),
|
||||||
icon: <FillCrossHatchIcon theme={appState.theme} />,
|
icon: FillCrossHatchIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "solid",
|
value: "solid",
|
||||||
text: t("labels.solid"),
|
text: t("labels.solid"),
|
||||||
icon: <FillSolidIcon theme={appState.theme} />,
|
icon: FillSolidIcon,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
group="fill"
|
group="fill"
|
||||||
@@ -358,17 +363,17 @@ export const actionChangeStrokeWidth = register({
|
|||||||
{
|
{
|
||||||
value: 1,
|
value: 1,
|
||||||
text: t("labels.thin"),
|
text: t("labels.thin"),
|
||||||
icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={2} />,
|
icon: StrokeWidthBaseIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 2,
|
value: 2,
|
||||||
text: t("labels.bold"),
|
text: t("labels.bold"),
|
||||||
icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={6} />,
|
icon: StrokeWidthBoldIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 4,
|
value: 4,
|
||||||
text: t("labels.extraBold"),
|
text: t("labels.extraBold"),
|
||||||
icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={10} />,
|
icon: StrokeWidthExtraBoldIcon,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -407,17 +412,17 @@ export const actionChangeSloppiness = register({
|
|||||||
{
|
{
|
||||||
value: 0,
|
value: 0,
|
||||||
text: t("labels.architect"),
|
text: t("labels.architect"),
|
||||||
icon: <SloppinessArchitectIcon theme={appState.theme} />,
|
icon: SloppinessArchitectIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 1,
|
value: 1,
|
||||||
text: t("labels.artist"),
|
text: t("labels.artist"),
|
||||||
icon: <SloppinessArtistIcon theme={appState.theme} />,
|
icon: SloppinessArtistIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 2,
|
value: 2,
|
||||||
text: t("labels.cartoonist"),
|
text: t("labels.cartoonist"),
|
||||||
icon: <SloppinessCartoonistIcon theme={appState.theme} />,
|
icon: SloppinessCartoonistIcon,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -455,17 +460,17 @@ export const actionChangeStrokeStyle = register({
|
|||||||
{
|
{
|
||||||
value: "solid",
|
value: "solid",
|
||||||
text: t("labels.strokeStyle_solid"),
|
text: t("labels.strokeStyle_solid"),
|
||||||
icon: <StrokeStyleSolidIcon theme={appState.theme} />,
|
icon: StrokeWidthBaseIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dashed",
|
value: "dashed",
|
||||||
text: t("labels.strokeStyle_dashed"),
|
text: t("labels.strokeStyle_dashed"),
|
||||||
icon: <StrokeStyleDashedIcon theme={appState.theme} />,
|
icon: StrokeStyleDashedIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dotted",
|
value: "dotted",
|
||||||
text: t("labels.strokeStyle_dotted"),
|
text: t("labels.strokeStyle_dotted"),
|
||||||
icon: <StrokeStyleDottedIcon theme={appState.theme} />,
|
icon: StrokeStyleDottedIcon,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -535,25 +540,25 @@ export const actionChangeFontSize = register({
|
|||||||
{
|
{
|
||||||
value: 16,
|
value: 16,
|
||||||
text: t("labels.small"),
|
text: t("labels.small"),
|
||||||
icon: <FontSizeSmallIcon theme={appState.theme} />,
|
icon: FontSizeSmallIcon,
|
||||||
testId: "fontSize-small",
|
testId: "fontSize-small",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 20,
|
value: 20,
|
||||||
text: t("labels.medium"),
|
text: t("labels.medium"),
|
||||||
icon: <FontSizeMediumIcon theme={appState.theme} />,
|
icon: FontSizeMediumIcon,
|
||||||
testId: "fontSize-medium",
|
testId: "fontSize-medium",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 28,
|
value: 28,
|
||||||
text: t("labels.large"),
|
text: t("labels.large"),
|
||||||
icon: <FontSizeLargeIcon theme={appState.theme} />,
|
icon: FontSizeLargeIcon,
|
||||||
testId: "fontSize-large",
|
testId: "fontSize-large",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 36,
|
value: 36,
|
||||||
text: t("labels.veryLarge"),
|
text: t("labels.veryLarge"),
|
||||||
icon: <FontSizeExtraLargeIcon theme={appState.theme} />,
|
icon: FontSizeExtraLargeIcon,
|
||||||
testId: "fontSize-veryLarge",
|
testId: "fontSize-veryLarge",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
@@ -658,17 +663,17 @@ export const actionChangeFontFamily = register({
|
|||||||
{
|
{
|
||||||
value: FONT_FAMILY.Virgil,
|
value: FONT_FAMILY.Virgil,
|
||||||
text: t("labels.handDrawn"),
|
text: t("labels.handDrawn"),
|
||||||
icon: <FontFamilyHandDrawnIcon theme={appState.theme} />,
|
icon: FreedrawIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: FONT_FAMILY.Helvetica,
|
value: FONT_FAMILY.Helvetica,
|
||||||
text: t("labels.normal"),
|
text: t("labels.normal"),
|
||||||
icon: <FontFamilyNormalIcon theme={appState.theme} />,
|
icon: FontFamilyNormalIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: FONT_FAMILY.Cascadia,
|
value: FONT_FAMILY.Cascadia,
|
||||||
text: t("labels.code"),
|
text: t("labels.code"),
|
||||||
icon: <FontFamilyCodeIcon theme={appState.theme} />,
|
icon: FontFamilyCodeIcon,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -739,17 +744,17 @@ export const actionChangeTextAlign = register({
|
|||||||
{
|
{
|
||||||
value: "left",
|
value: "left",
|
||||||
text: t("labels.left"),
|
text: t("labels.left"),
|
||||||
icon: <TextAlignLeftIcon theme={appState.theme} />,
|
icon: TextAlignLeftIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "center",
|
value: "center",
|
||||||
text: t("labels.center"),
|
text: t("labels.center"),
|
||||||
icon: <TextAlignCenterIcon theme={appState.theme} />,
|
icon: TextAlignCenterIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "right",
|
value: "right",
|
||||||
text: t("labels.right"),
|
text: t("labels.right"),
|
||||||
icon: <TextAlignRightIcon theme={appState.theme} />,
|
icon: TextAlignRightIcon,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
@@ -812,16 +817,19 @@ export const actionChangeVerticalAlign = register({
|
|||||||
value: VERTICAL_ALIGN.TOP,
|
value: VERTICAL_ALIGN.TOP,
|
||||||
text: t("labels.alignTop"),
|
text: t("labels.alignTop"),
|
||||||
icon: <TextAlignTopIcon theme={appState.theme} />,
|
icon: <TextAlignTopIcon theme={appState.theme} />,
|
||||||
|
testId: "align-top",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: VERTICAL_ALIGN.MIDDLE,
|
value: VERTICAL_ALIGN.MIDDLE,
|
||||||
text: t("labels.centerVertically"),
|
text: t("labels.centerVertically"),
|
||||||
icon: <TextAlignMiddleIcon theme={appState.theme} />,
|
icon: <TextAlignMiddleIcon theme={appState.theme} />,
|
||||||
|
testId: "align-middle",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: VERTICAL_ALIGN.BOTTOM,
|
value: VERTICAL_ALIGN.BOTTOM,
|
||||||
text: t("labels.alignBottom"),
|
text: t("labels.alignBottom"),
|
||||||
icon: <TextAlignBottomIcon theme={appState.theme} />,
|
icon: <TextAlignBottomIcon theme={appState.theme} />,
|
||||||
|
testId: "align-bottom",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(elements, appState, (element) => {
|
value={getFormValue(elements, appState, (element) => {
|
||||||
@@ -841,69 +849,71 @@ export const actionChangeVerticalAlign = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeSharpness = register({
|
export const actionChangeRoundness = register({
|
||||||
name: "changeSharpness",
|
name: "changeRoundness",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value) => {
|
perform: (elements, appState, value) => {
|
||||||
const targetElements = getTargetElements(
|
|
||||||
getNonDeletedElements(elements),
|
|
||||||
appState,
|
|
||||||
);
|
|
||||||
const shouldUpdateForNonLinearElements = targetElements.length
|
|
||||||
? targetElements.every((el) => !isLinearElement(el))
|
|
||||||
: !isLinearElementType(appState.activeTool.type);
|
|
||||||
const shouldUpdateForLinearElements = targetElements.length
|
|
||||||
? targetElements.every(isLinearElement)
|
|
||||||
: isLinearElementType(appState.activeTool.type);
|
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) =>
|
elements: changeProperty(elements, appState, (el) =>
|
||||||
newElementWith(el, {
|
newElementWith(el, {
|
||||||
strokeSharpness: value,
|
roundness:
|
||||||
|
value === "round"
|
||||||
|
? {
|
||||||
|
type: isUsingAdaptiveRadius(el.type)
|
||||||
|
? ROUNDNESS.ADAPTIVE_RADIUS
|
||||||
|
: ROUNDNESS.PROPORTIONAL_RADIUS,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
currentItemStrokeSharpness: shouldUpdateForNonLinearElements
|
currentItemRoundness: value,
|
||||||
? value
|
|
||||||
: appState.currentItemStrokeSharpness,
|
|
||||||
currentItemLinearStrokeSharpness: shouldUpdateForLinearElements
|
|
||||||
? value
|
|
||||||
: appState.currentItemLinearStrokeSharpness,
|
|
||||||
},
|
},
|
||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData }) => (
|
PanelComponent: ({ elements, appState, updateData }) => {
|
||||||
<fieldset>
|
const targetElements = getTargetElements(
|
||||||
<legend>{t("labels.edges")}</legend>
|
getNonDeletedElements(elements),
|
||||||
<ButtonIconSelect
|
appState,
|
||||||
group="edges"
|
);
|
||||||
options={[
|
|
||||||
{
|
const hasLegacyRoundness = targetElements.some(
|
||||||
value: "sharp",
|
(el) => el.roundness?.type === ROUNDNESS.LEGACY,
|
||||||
text: t("labels.sharp"),
|
);
|
||||||
icon: <EdgeSharpIcon theme={appState.theme} />,
|
|
||||||
},
|
return (
|
||||||
{
|
<fieldset>
|
||||||
value: "round",
|
<legend>{t("labels.edges")}</legend>
|
||||||
text: t("labels.round"),
|
<ButtonIconSelect
|
||||||
icon: <EdgeRoundIcon theme={appState.theme} />,
|
group="edges"
|
||||||
},
|
options={[
|
||||||
]}
|
{
|
||||||
value={getFormValue(
|
value: "sharp",
|
||||||
elements,
|
text: t("labels.sharp"),
|
||||||
appState,
|
icon: EdgeSharpIcon,
|
||||||
(element) => element.strokeSharpness,
|
},
|
||||||
(canChangeSharpness(appState.activeTool.type) &&
|
{
|
||||||
(isLinearElementType(appState.activeTool.type)
|
value: "round",
|
||||||
? appState.currentItemLinearStrokeSharpness
|
text: t("labels.round"),
|
||||||
: appState.currentItemStrokeSharpness)) ||
|
icon: EdgeRoundIcon,
|
||||||
null,
|
},
|
||||||
)}
|
]}
|
||||||
onChange={(value) => updateData(value)}
|
value={getFormValue(
|
||||||
/>
|
elements,
|
||||||
</fieldset>
|
appState,
|
||||||
),
|
(element) =>
|
||||||
|
hasLegacyRoundness ? null : element.roundness ? "round" : "sharp",
|
||||||
|
(canChangeRoundness(appState.activeTool.type) &&
|
||||||
|
appState.currentItemRoundness) ||
|
||||||
|
null,
|
||||||
|
)}
|
||||||
|
onChange={(value) => updateData(value)}
|
||||||
|
/>
|
||||||
|
</fieldset>
|
||||||
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionChangeArrowhead = register({
|
export const actionChangeArrowhead = register({
|
||||||
@@ -949,42 +959,38 @@ export const actionChangeArrowhead = register({
|
|||||||
return (
|
return (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.arrowheads")}</legend>
|
<legend>{t("labels.arrowheads")}</legend>
|
||||||
<div className="iconSelectList">
|
<div className="iconSelectList buttonList">
|
||||||
<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 theme={appState.theme} />,
|
icon: ArrowheadNoneIcon,
|
||||||
keyBinding: "q",
|
keyBinding: "q",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "arrow",
|
value: "arrow",
|
||||||
text: t("labels.arrowhead_arrow"),
|
text: t("labels.arrowhead_arrow"),
|
||||||
icon: (
|
icon: <ArrowheadArrowIcon flip={!isRTL} />,
|
||||||
<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 theme={appState.theme} flip={!isRTL} />,
|
icon: <ArrowheadBarIcon flip={!isRTL} />,
|
||||||
keyBinding: "e",
|
keyBinding: "e",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dot",
|
value: "dot",
|
||||||
text: t("labels.arrowhead_dot"),
|
text: t("labels.arrowhead_dot"),
|
||||||
icon: <ArrowheadDotIcon theme={appState.theme} flip={!isRTL} />,
|
icon: <ArrowheadDotIcon flip={!isRTL} />,
|
||||||
keyBinding: "r",
|
keyBinding: "r",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "triangle",
|
value: "triangle",
|
||||||
text: t("labels.arrowhead_triangle"),
|
text: t("labels.arrowhead_triangle"),
|
||||||
icon: (
|
icon: <ArrowheadTriangleIcon flip={!isRTL} />,
|
||||||
<ArrowheadTriangleIcon theme={appState.theme} flip={!isRTL} />
|
|
||||||
),
|
|
||||||
keyBinding: "t",
|
keyBinding: "t",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
@@ -1007,34 +1013,30 @@ export const actionChangeArrowhead = register({
|
|||||||
value: null,
|
value: null,
|
||||||
text: t("labels.arrowhead_none"),
|
text: t("labels.arrowhead_none"),
|
||||||
keyBinding: "q",
|
keyBinding: "q",
|
||||||
icon: <ArrowheadNoneIcon theme={appState.theme} />,
|
icon: ArrowheadNoneIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "arrow",
|
value: "arrow",
|
||||||
text: t("labels.arrowhead_arrow"),
|
text: t("labels.arrowhead_arrow"),
|
||||||
keyBinding: "w",
|
keyBinding: "w",
|
||||||
icon: (
|
icon: <ArrowheadArrowIcon flip={isRTL} />,
|
||||||
<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 theme={appState.theme} flip={isRTL} />,
|
icon: <ArrowheadBarIcon flip={isRTL} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "dot",
|
value: "dot",
|
||||||
text: t("labels.arrowhead_dot"),
|
text: t("labels.arrowhead_dot"),
|
||||||
keyBinding: "r",
|
keyBinding: "r",
|
||||||
icon: <ArrowheadDotIcon theme={appState.theme} flip={isRTL} />,
|
icon: <ArrowheadDotIcon flip={isRTL} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "triangle",
|
value: "triangle",
|
||||||
text: t("labels.arrowhead_triangle"),
|
text: t("labels.arrowhead_triangle"),
|
||||||
icon: (
|
icon: <ArrowheadTriangleIcon flip={isRTL} />,
|
||||||
<ArrowheadTriangleIcon theme={appState.theme} flip={isRTL} />
|
|
||||||
),
|
|
||||||
keyBinding: "t",
|
keyBinding: "t",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
@@ -35,7 +35,7 @@ export const actionSelectAll = register({
|
|||||||
// single linear element selected
|
// single linear element selected
|
||||||
Object.keys(selectedElementIds).length === 1 &&
|
Object.keys(selectedElementIds).length === 1 &&
|
||||||
isLinearElement(elements[0])
|
isLinearElement(elements[0])
|
||||||
? new LinearElementEditor(elements[0], app.scene, appState)
|
? new LinearElementEditor(elements[0], app.scene)
|
||||||
: null,
|
: null,
|
||||||
editingGroupId: null,
|
editingGroupId: null,
|
||||||
selectedElementIds,
|
selectedElementIds,
|
||||||
|
@@ -13,7 +13,11 @@ import {
|
|||||||
DEFAULT_TEXT_ALIGN,
|
DEFAULT_TEXT_ALIGN,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import { getBoundTextElement } from "../element/textElement";
|
import { getBoundTextElement } from "../element/textElement";
|
||||||
import { hasBoundTextElement } from "../element/typeChecks";
|
import {
|
||||||
|
hasBoundTextElement,
|
||||||
|
canApplyRoundnessTypeToElement,
|
||||||
|
getDefaultRoundnessTypeForElement,
|
||||||
|
} from "../element/typeChecks";
|
||||||
import { getSelectedElements } from "../scene";
|
import { getSelectedElements } from "../scene";
|
||||||
|
|
||||||
// `copiedStyles` is exported only for tests.
|
// `copiedStyles` is exported only for tests.
|
||||||
@@ -77,6 +81,14 @@ export const actionPasteStyles = register({
|
|||||||
fillStyle: elementStylesToCopyFrom?.fillStyle,
|
fillStyle: elementStylesToCopyFrom?.fillStyle,
|
||||||
opacity: elementStylesToCopyFrom?.opacity,
|
opacity: elementStylesToCopyFrom?.opacity,
|
||||||
roughness: elementStylesToCopyFrom?.roughness,
|
roughness: elementStylesToCopyFrom?.roughness,
|
||||||
|
roundness: elementStylesToCopyFrom.roundness
|
||||||
|
? canApplyRoundnessTypeToElement(
|
||||||
|
elementStylesToCopyFrom.roundness.type,
|
||||||
|
element,
|
||||||
|
)
|
||||||
|
? elementStylesToCopyFrom.roundness
|
||||||
|
: getDefaultRoundnessTypeForElement(element)
|
||||||
|
: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isTextElement(newElement)) {
|
if (isTextElement(newElement)) {
|
||||||
|
@@ -5,6 +5,7 @@ import { AppState } from "../types";
|
|||||||
|
|
||||||
export const actionToggleGridMode = register({
|
export const actionToggleGridMode = register({
|
||||||
name: "gridMode",
|
name: "gridMode",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: {
|
trackEvent: {
|
||||||
category: "canvas",
|
category: "canvas",
|
||||||
predicate: (appState) => !appState.gridSize,
|
predicate: (appState) => !appState.gridSize,
|
||||||
@@ -19,6 +20,9 @@ export const actionToggleGridMode = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
checked: (appState: AppState) => appState.gridSize !== null,
|
checked: (appState: AppState) => appState.gridSize !== null,
|
||||||
|
contextItemPredicate: (element, appState, props) => {
|
||||||
|
return typeof props.gridModeEnabled === "undefined";
|
||||||
|
},
|
||||||
contextItemLabel: "labels.showGrid",
|
contextItemLabel: "labels.showGrid",
|
||||||
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.QUOTE,
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.QUOTE,
|
||||||
});
|
});
|
||||||
|
@@ -41,15 +41,9 @@ export const actionToggleLock = register({
|
|||||||
: "labels.elementLock.lock";
|
: "labels.elementLock.lock";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected.length > 1) {
|
return getOperation(selected) === "lock"
|
||||||
return getOperation(selected) === "lock"
|
? "labels.elementLock.lockAll"
|
||||||
? "labels.elementLock.lockAll"
|
: "labels.elementLock.unlockAll";
|
||||||
: "labels.elementLock.unlockAll";
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(
|
|
||||||
"Unexpected zero elements to lock/unlock. This should never happen.",
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
keyTest: (event, appState, elements) => {
|
keyTest: (event, appState, elements) => {
|
||||||
return (
|
return (
|
||||||
|
@@ -3,6 +3,7 @@ import { CODES, KEYS } from "../keys";
|
|||||||
|
|
||||||
export const actionToggleStats = register({
|
export const actionToggleStats = register({
|
||||||
name: "stats",
|
name: "stats",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: { category: "menu" },
|
trackEvent: { category: "menu" },
|
||||||
perform(elements, appState) {
|
perform(elements, appState) {
|
||||||
return {
|
return {
|
||||||
|
@@ -3,6 +3,7 @@ import { register } from "./register";
|
|||||||
|
|
||||||
export const actionToggleViewMode = register({
|
export const actionToggleViewMode = register({
|
||||||
name: "viewMode",
|
name: "viewMode",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: {
|
trackEvent: {
|
||||||
category: "canvas",
|
category: "canvas",
|
||||||
predicate: (appState) => !appState.viewModeEnabled,
|
predicate: (appState) => !appState.viewModeEnabled,
|
||||||
@@ -17,6 +18,9 @@ export const actionToggleViewMode = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
checked: (appState) => appState.viewModeEnabled,
|
checked: (appState) => appState.viewModeEnabled,
|
||||||
|
contextItemPredicate: (elements, appState, appProps) => {
|
||||||
|
return typeof appProps.viewModeEnabled === "undefined";
|
||||||
|
},
|
||||||
contextItemLabel: "labels.viewMode",
|
contextItemLabel: "labels.viewMode",
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.R,
|
!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.R,
|
||||||
|
@@ -3,6 +3,7 @@ import { register } from "./register";
|
|||||||
|
|
||||||
export const actionToggleZenMode = register({
|
export const actionToggleZenMode = register({
|
||||||
name: "zenMode",
|
name: "zenMode",
|
||||||
|
viewMode: true,
|
||||||
trackEvent: {
|
trackEvent: {
|
||||||
category: "canvas",
|
category: "canvas",
|
||||||
predicate: (appState) => !appState.zenModeEnabled,
|
predicate: (appState) => !appState.zenModeEnabled,
|
||||||
@@ -17,6 +18,9 @@ export const actionToggleZenMode = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
checked: (appState) => appState.zenModeEnabled,
|
checked: (appState) => appState.zenModeEnabled,
|
||||||
|
contextItemPredicate: (elements, appState, appProps) => {
|
||||||
|
return typeof appProps.zenModeEnabled === "undefined";
|
||||||
|
},
|
||||||
contextItemLabel: "buttons.zenMode",
|
contextItemLabel: "buttons.zenMode",
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.Z,
|
!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.Z,
|
||||||
|
@@ -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 {
|
||||||
SendBackwardIcon,
|
|
||||||
BringToFrontIcon,
|
|
||||||
SendToBackIcon,
|
|
||||||
BringForwardIcon,
|
BringForwardIcon,
|
||||||
|
BringToFrontIcon,
|
||||||
|
SendBackwardIcon,
|
||||||
|
SendToBackIcon,
|
||||||
} 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 theme={appState.theme} />
|
{SendBackwardIcon}
|
||||||
</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 theme={appState.theme} />
|
{BringForwardIcon}
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@@ -102,7 +102,7 @@ export const actionSendToBack = register({
|
|||||||
: getShortcutKey("CtrlOrCmd+Shift+[")
|
: getShortcutKey("CtrlOrCmd+Shift+[")
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<SendToBackIcon theme={appState.theme} />
|
{SendToBackIcon}
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
@@ -138,7 +138,7 @@ export const actionBringToFront = register({
|
|||||||
: getShortcutKey("CtrlOrCmd+Shift+]")
|
: getShortcutKey("CtrlOrCmd+Shift+]")
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<BringToFrontIcon theme={appState.theme} />
|
{BringToFrontIcon}
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
@@ -85,3 +85,4 @@ 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";
|
||||||
|
@@ -9,7 +9,6 @@ import {
|
|||||||
} from "./types";
|
} from "./types";
|
||||||
import { ExcalidrawElement } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
import { AppClassProperties, AppState } from "../types";
|
import { AppClassProperties, AppState } from "../types";
|
||||||
import { MODES } from "../constants";
|
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
|
|
||||||
const trackAction = (
|
const trackAction = (
|
||||||
@@ -103,11 +102,8 @@ export class ActionManager {
|
|||||||
|
|
||||||
const action = data[0];
|
const action = data[0];
|
||||||
|
|
||||||
const { viewModeEnabled } = this.getAppState();
|
if (this.getAppState().viewModeEnabled && action.viewMode !== true) {
|
||||||
if (viewModeEnabled) {
|
return false;
|
||||||
if (!Object.values(MODES).includes(data[0].name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const elements = this.getElementsIncludingDeleted();
|
const elements = this.getElementsIncludingDeleted();
|
||||||
@@ -135,7 +131,11 @@ export class ActionManager {
|
|||||||
/**
|
/**
|
||||||
* @param data additional data sent to the PanelComponent
|
* @param data additional data sent to the PanelComponent
|
||||||
*/
|
*/
|
||||||
renderAction = (name: ActionName, data?: PanelComponentProps["data"]) => {
|
renderAction = (
|
||||||
|
name: ActionName,
|
||||||
|
data?: PanelComponentProps["data"],
|
||||||
|
isInHamburgerMenu = false,
|
||||||
|
) => {
|
||||||
const canvasActions = this.app.props.UIOptions.canvasActions;
|
const canvasActions = this.app.props.UIOptions.canvasActions;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -170,6 +170,7 @@ export class ActionManager {
|
|||||||
updateData={updateData}
|
updateData={updateData}
|
||||||
appProps={this.app.props}
|
appProps={this.app.props}
|
||||||
data={data}
|
data={data}
|
||||||
|
isInHamburgerMenu={isInHamburgerMenu}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -3,43 +3,52 @@ import { isDarwin } from "../keys";
|
|||||||
import { getShortcutKey } from "../utils";
|
import { getShortcutKey } from "../utils";
|
||||||
import { ActionName } from "./types";
|
import { ActionName } from "./types";
|
||||||
|
|
||||||
export type ShortcutName = SubtypeOf<
|
export type ShortcutName =
|
||||||
ActionName,
|
| SubtypeOf<
|
||||||
| "cut"
|
ActionName,
|
||||||
| "copy"
|
| "toggleTheme"
|
||||||
| "paste"
|
| "loadScene"
|
||||||
| "copyStyles"
|
| "cut"
|
||||||
| "pasteStyles"
|
| "copy"
|
||||||
| "selectAll"
|
| "paste"
|
||||||
| "deleteSelectedElements"
|
| "copyStyles"
|
||||||
| "duplicateSelection"
|
| "pasteStyles"
|
||||||
| "sendBackward"
|
| "selectAll"
|
||||||
| "bringForward"
|
| "deleteSelectedElements"
|
||||||
| "sendToBack"
|
| "duplicateSelection"
|
||||||
| "bringToFront"
|
| "sendBackward"
|
||||||
| "copyAsPng"
|
| "bringForward"
|
||||||
| "copyAsSvg"
|
| "sendToBack"
|
||||||
| "group"
|
| "bringToFront"
|
||||||
| "ungroup"
|
| "copyAsPng"
|
||||||
| "gridMode"
|
| "copyAsSvg"
|
||||||
| "zenMode"
|
| "group"
|
||||||
| "stats"
|
| "ungroup"
|
||||||
| "addToLibrary"
|
| "gridMode"
|
||||||
| "viewMode"
|
| "zenMode"
|
||||||
| "flipHorizontal"
|
| "stats"
|
||||||
| "flipVertical"
|
| "addToLibrary"
|
||||||
| "hyperlink"
|
| "viewMode"
|
||||||
| "toggleLock"
|
| "flipHorizontal"
|
||||||
>;
|
| "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")],
|
||||||
copyStyles: [getShortcutKey("CtrlOrCmd+Alt+C")],
|
copyStyles: [getShortcutKey("CtrlOrCmd+Alt+C")],
|
||||||
pasteStyles: [getShortcutKey("CtrlOrCmd+Alt+V")],
|
pasteStyles: [getShortcutKey("CtrlOrCmd+Alt+V")],
|
||||||
selectAll: [getShortcutKey("CtrlOrCmd+A")],
|
selectAll: [getShortcutKey("CtrlOrCmd+A")],
|
||||||
deleteSelectedElements: [getShortcutKey("Del")],
|
deleteSelectedElements: [getShortcutKey("Delete")],
|
||||||
duplicateSelection: [
|
duplicateSelection: [
|
||||||
getShortcutKey("CtrlOrCmd+D"),
|
getShortcutKey("CtrlOrCmd+D"),
|
||||||
getShortcutKey(`Alt+${t("helpDialog.drag")}`),
|
getShortcutKey(`Alt+${t("helpDialog.drag")}`),
|
||||||
|
@@ -91,7 +91,7 @@ export type ActionName =
|
|||||||
| "ungroup"
|
| "ungroup"
|
||||||
| "goToCollaborator"
|
| "goToCollaborator"
|
||||||
| "addToLibrary"
|
| "addToLibrary"
|
||||||
| "changeSharpness"
|
| "changeRoundness"
|
||||||
| "alignTop"
|
| "alignTop"
|
||||||
| "alignBottom"
|
| "alignBottom"
|
||||||
| "alignLeft"
|
| "alignLeft"
|
||||||
@@ -111,7 +111,8 @@ export type ActionName =
|
|||||||
| "hyperlink"
|
| "hyperlink"
|
||||||
| "eraser"
|
| "eraser"
|
||||||
| "bindText"
|
| "bindText"
|
||||||
| "toggleLock";
|
| "toggleLock"
|
||||||
|
| "toggleLinearEditor";
|
||||||
|
|
||||||
export type PanelComponentProps = {
|
export type PanelComponentProps = {
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
@@ -123,7 +124,9 @@ export type PanelComponentProps = {
|
|||||||
|
|
||||||
export interface Action {
|
export interface Action {
|
||||||
name: ActionName;
|
name: ActionName;
|
||||||
PanelComponent?: React.FC<PanelComponentProps>;
|
PanelComponent?: React.FC<
|
||||||
|
PanelComponentProps & { isInHamburgerMenu: boolean }
|
||||||
|
>;
|
||||||
perform: ActionFn;
|
perform: ActionFn;
|
||||||
keyPriority?: number;
|
keyPriority?: number;
|
||||||
keyTest?: (
|
keyTest?: (
|
||||||
@@ -140,6 +143,8 @@ export interface Action {
|
|||||||
contextItemPredicate?: (
|
contextItemPredicate?: (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
|
appProps: ExcalidrawProps,
|
||||||
|
app: AppClassProperties,
|
||||||
) => boolean;
|
) => boolean;
|
||||||
checked?: (appState: Readonly<AppState>) => boolean;
|
checked?: (appState: Readonly<AppState>) => boolean;
|
||||||
trackEvent:
|
trackEvent:
|
||||||
@@ -161,4 +166,7 @@ export interface Action {
|
|||||||
value: any,
|
value: any,
|
||||||
) => boolean;
|
) => boolean;
|
||||||
};
|
};
|
||||||
|
/** if set to `true`, allow action to be performed in viewMode.
|
||||||
|
* Defaults to `false` */
|
||||||
|
viewMode?: boolean;
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ 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",
|
||||||
@@ -27,12 +28,11 @@ export const getDefaultAppState = (): Omit<
|
|||||||
currentItemFillStyle: "hachure",
|
currentItemFillStyle: "hachure",
|
||||||
currentItemFontFamily: DEFAULT_FONT_FAMILY,
|
currentItemFontFamily: DEFAULT_FONT_FAMILY,
|
||||||
currentItemFontSize: DEFAULT_FONT_SIZE,
|
currentItemFontSize: DEFAULT_FONT_SIZE,
|
||||||
currentItemLinearStrokeSharpness: "round",
|
|
||||||
currentItemOpacity: 100,
|
currentItemOpacity: 100,
|
||||||
currentItemRoughness: 1,
|
currentItemRoughness: 1,
|
||||||
currentItemStartArrowhead: null,
|
currentItemStartArrowhead: null,
|
||||||
currentItemStrokeColor: oc.black,
|
currentItemStrokeColor: oc.black,
|
||||||
currentItemStrokeSharpness: "sharp",
|
currentItemRoundness: "round",
|
||||||
currentItemStrokeStyle: "solid",
|
currentItemStrokeStyle: "solid",
|
||||||
currentItemStrokeWidth: 1,
|
currentItemStrokeWidth: 1,
|
||||||
currentItemTextAlign: DEFAULT_TEXT_ALIGN,
|
currentItemTextAlign: DEFAULT_TEXT_ALIGN,
|
||||||
@@ -57,16 +57,18 @@ export const getDefaultAppState = (): Omit<
|
|||||||
fileHandle: null,
|
fileHandle: null,
|
||||||
gridSize: null,
|
gridSize: null,
|
||||||
isBindingEnabled: true,
|
isBindingEnabled: true,
|
||||||
isLibraryOpen: false,
|
isSidebarDocked: false,
|
||||||
isLibraryMenuDocked: false,
|
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isResizing: false,
|
isResizing: false,
|
||||||
isRotating: false,
|
isRotating: false,
|
||||||
lastPointerDownWith: "mouse",
|
lastPointerDownWith: "mouse",
|
||||||
multiElement: null,
|
multiElement: null,
|
||||||
name: `${t("labels.untitled")}-${getDateTime()}`,
|
name: `${t("labels.untitled")}-${getDateTime()}`,
|
||||||
|
contextMenu: null,
|
||||||
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,
|
||||||
@@ -77,7 +79,6 @@ 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: [],
|
||||||
@@ -110,6 +111,7 @@ 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 },
|
||||||
@@ -118,7 +120,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
currentItemFillStyle: { browser: true, export: false, server: false },
|
currentItemFillStyle: { browser: true, export: false, server: false },
|
||||||
currentItemFontFamily: { browser: true, export: false, server: false },
|
currentItemFontFamily: { browser: true, export: false, server: false },
|
||||||
currentItemFontSize: { browser: true, export: false, server: false },
|
currentItemFontSize: { browser: true, export: false, server: false },
|
||||||
currentItemLinearStrokeSharpness: {
|
currentItemRoundness: {
|
||||||
browser: true,
|
browser: true,
|
||||||
export: false,
|
export: false,
|
||||||
server: false,
|
server: false,
|
||||||
@@ -127,7 +129,6 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
currentItemRoughness: { browser: true, export: false, server: false },
|
currentItemRoughness: { browser: true, export: false, server: false },
|
||||||
currentItemStartArrowhead: { browser: true, export: false, server: false },
|
currentItemStartArrowhead: { browser: true, export: false, server: false },
|
||||||
currentItemStrokeColor: { browser: true, export: false, server: false },
|
currentItemStrokeColor: { browser: true, export: false, server: false },
|
||||||
currentItemStrokeSharpness: { browser: true, export: false, server: false },
|
|
||||||
currentItemStrokeStyle: { browser: true, export: false, server: false },
|
currentItemStrokeStyle: { browser: true, export: false, server: false },
|
||||||
currentItemStrokeWidth: { browser: true, export: false, server: false },
|
currentItemStrokeWidth: { browser: true, export: false, server: false },
|
||||||
currentItemTextAlign: { browser: true, export: false, server: false },
|
currentItemTextAlign: { browser: true, export: false, server: false },
|
||||||
@@ -148,8 +149,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
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 },
|
||||||
isLibraryOpen: { browser: true, export: false, server: false },
|
isSidebarDocked: { 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 },
|
||||||
@@ -158,8 +158,11 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
name: { browser: true, export: false, server: false },
|
name: { browser: true, export: false, server: false },
|
||||||
offsetLeft: { browser: false, export: false, server: false },
|
offsetLeft: { browser: false, export: false, server: false },
|
||||||
offsetTop: { browser: false, export: false, server: false },
|
offsetTop: { browser: false, export: false, server: false },
|
||||||
|
contextMenu: { 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 },
|
||||||
@@ -170,7 +173,6 @@ 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 },
|
||||||
|
@@ -172,7 +172,7 @@ const commonProps = {
|
|||||||
opacity: 100,
|
opacity: 100,
|
||||||
roughness: 1,
|
roughness: 1,
|
||||||
strokeColor: colors.elementStroke[0],
|
strokeColor: colors.elementStroke[0],
|
||||||
strokeSharpness: "sharp",
|
roundness: null,
|
||||||
strokeStyle: "solid",
|
strokeStyle: "solid",
|
||||||
strokeWidth: 1,
|
strokeWidth: 1,
|
||||||
verticalAlign: VERTICAL_ALIGN.MIDDLE,
|
verticalAlign: VERTICAL_ALIGN.MIDDLE,
|
||||||
@@ -322,7 +322,7 @@ const chartBaseElements = (
|
|||||||
text: spreadsheet.title,
|
text: spreadsheet.title,
|
||||||
x: x + chartWidth / 2,
|
x: x + chartWidth / 2,
|
||||||
y: y - BAR_HEIGHT - BAR_GAP * 2 - DEFAULT_FONT_SIZE,
|
y: y - BAR_HEIGHT - BAR_GAP * 2 - DEFAULT_FONT_SIZE,
|
||||||
strokeSharpness: "sharp",
|
roundness: null,
|
||||||
strokeStyle: "solid",
|
strokeStyle: "solid",
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
})
|
})
|
||||||
|
@@ -11,27 +11,18 @@ 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 background.
|
// Skip transparent & gray colors
|
||||||
const backgrounds = colors.elementBackground.slice(1);
|
const backgrounds = colors.elementBackground.slice(3);
|
||||||
const strokes = colors.elementStroke.slice(1);
|
const strokes = colors.elementStroke.slice(3);
|
||||||
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 "?";
|
||||||
}
|
}
|
||||||
const names = username.trim().split(" ");
|
return userName.trim()[0].toUpperCase();
|
||||||
|
|
||||||
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();
|
|
||||||
};
|
};
|
||||||
|
27
src/clipboard.test.ts
Normal file
27
src/clipboard.test.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { parseClipboard } from "./clipboard";
|
||||||
|
|
||||||
|
describe("Test parseClipboard", () => {
|
||||||
|
it("should parse valid json correctly", async () => {
|
||||||
|
let text = "123";
|
||||||
|
|
||||||
|
let clipboardData = await parseClipboard({
|
||||||
|
//@ts-ignore
|
||||||
|
clipboardData: {
|
||||||
|
getData: () => text,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(clipboardData.text).toBe(text);
|
||||||
|
|
||||||
|
text = "[123]";
|
||||||
|
|
||||||
|
clipboardData = await parseClipboard({
|
||||||
|
//@ts-ignore
|
||||||
|
clipboardData: {
|
||||||
|
getData: () => text,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(clipboardData.text).toBe(text);
|
||||||
|
});
|
||||||
|
});
|
@@ -109,16 +109,16 @@ const parsePotentialSpreadsheet = (
|
|||||||
* Retrieves content from system clipboard (either from ClipboardEvent or
|
* Retrieves content from system clipboard (either from ClipboardEvent or
|
||||||
* via async clipboard API if supported)
|
* via async clipboard API if supported)
|
||||||
*/
|
*/
|
||||||
const getSystemClipboard = async (
|
export const getSystemClipboard = async (
|
||||||
event: ClipboardEvent | null,
|
event: ClipboardEvent | null,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
try {
|
try {
|
||||||
const text = event
|
const text = event
|
||||||
? event.clipboardData?.getData("text/plain").trim()
|
? event.clipboardData?.getData("text/plain")
|
||||||
: probablySupportsClipboardReadText &&
|
: probablySupportsClipboardReadText &&
|
||||||
(await navigator.clipboard.readText());
|
(await navigator.clipboard.readText());
|
||||||
|
|
||||||
return text || "";
|
return (text || "").trim();
|
||||||
} catch {
|
} catch {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -129,19 +129,25 @@ const getSystemClipboard = async (
|
|||||||
*/
|
*/
|
||||||
export const parseClipboard = async (
|
export const parseClipboard = async (
|
||||||
event: ClipboardEvent | null,
|
event: ClipboardEvent | null,
|
||||||
|
isPlainPaste = false,
|
||||||
): Promise<ClipboardData> => {
|
): Promise<ClipboardData> => {
|
||||||
const systemClipboard = await getSystemClipboard(event);
|
const systemClipboard = await getSystemClipboard(event);
|
||||||
|
|
||||||
// if system clipboard empty, couldn't be resolved, or contains previously
|
// if system clipboard empty, couldn't be resolved, or contains previously
|
||||||
// copied excalidraw scene as SVG, fall back to previously copied excalidraw
|
// copied excalidraw scene as SVG, fall back to previously copied excalidraw
|
||||||
// elements
|
// elements
|
||||||
if (!systemClipboard || systemClipboard.includes(SVG_EXPORT_TAG)) {
|
if (
|
||||||
|
!systemClipboard ||
|
||||||
|
(!isPlainPaste && systemClipboard.includes(SVG_EXPORT_TAG))
|
||||||
|
) {
|
||||||
return getAppClipboard();
|
return getAppClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if system clipboard contains spreadsheet, use it even though it's
|
// if system clipboard contains spreadsheet, use it even though it's
|
||||||
// technically possible it's staler than in-app clipboard
|
// technically possible it's staler than in-app clipboard
|
||||||
const spreadsheetResult = parsePotentialSpreadsheet(systemClipboard);
|
const spreadsheetResult =
|
||||||
|
!isPlainPaste && parsePotentialSpreadsheet(systemClipboard);
|
||||||
|
|
||||||
if (spreadsheetResult) {
|
if (spreadsheetResult) {
|
||||||
return spreadsheetResult;
|
return spreadsheetResult;
|
||||||
}
|
}
|
||||||
@@ -154,17 +160,23 @@ export const parseClipboard = async (
|
|||||||
return {
|
return {
|
||||||
elements: systemClipboardData.elements,
|
elements: systemClipboardData.elements,
|
||||||
files: systemClipboardData.files,
|
files: systemClipboardData.files,
|
||||||
|
text: isPlainPaste
|
||||||
|
? JSON.stringify(systemClipboardData.elements, null, 2)
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return appClipboardData;
|
} catch (e) {}
|
||||||
} catch {
|
// system clipboard doesn't contain excalidraw elements → return plaintext
|
||||||
// system clipboard doesn't contain excalidraw elements → return plaintext
|
// unless we set a flag to prefer in-app clipboard because browser didn't
|
||||||
// unless we set a flag to prefer in-app clipboard because browser didn't
|
// support storing to system clipboard on copy
|
||||||
// support storing to system clipboard on copy
|
return PREFER_APP_CLIPBOARD && appClipboardData.elements
|
||||||
return PREFER_APP_CLIPBOARD && appClipboardData.elements
|
? {
|
||||||
? appClipboardData
|
...appClipboardData,
|
||||||
: { text: systemClipboard };
|
text: isPlainPaste
|
||||||
}
|
? JSON.stringify(appClipboardData.elements, null, 2)
|
||||||
|
: undefined,
|
||||||
|
}
|
||||||
|
: { text: systemClipboard };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
||||||
|
92
src/components/Actions.scss
Normal file
92
src/components/Actions.scss
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -5,7 +5,7 @@ import { ExcalidrawElement, PointerType } from "../element/types";
|
|||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "../components/App";
|
import { useDevice } from "../components/App";
|
||||||
import {
|
import {
|
||||||
canChangeSharpness,
|
canChangeRoundness,
|
||||||
canHaveArrowheads,
|
canHaveArrowheads,
|
||||||
getTargetElements,
|
getTargetElements,
|
||||||
hasBackground,
|
hasBackground,
|
||||||
@@ -25,9 +25,12 @@ import Stack from "./Stack";
|
|||||||
import { ToolButton } from "./ToolButton";
|
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 } from "../element/typeChecks";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { actionToggleZenMode } from "../actions";
|
import { actionToggleZenMode } from "../actions";
|
||||||
|
import "./Actions.scss";
|
||||||
|
import { Tooltip } from "./Tooltip";
|
||||||
|
import { shouldAllowVerticalAlign } from "../element/textElement";
|
||||||
|
|
||||||
export const SelectedShapeActions = ({
|
export const SelectedShapeActions = ({
|
||||||
appState,
|
appState,
|
||||||
@@ -79,12 +82,16 @@ export const SelectedShapeActions = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="panelColumn">
|
<div className="panelColumn">
|
||||||
{((hasStrokeColor(appState.activeTool.type) &&
|
<div>
|
||||||
appState.activeTool.type !== "image" &&
|
{((hasStrokeColor(appState.activeTool.type) &&
|
||||||
commonSelectedType !== "image") ||
|
appState.activeTool.type !== "image" &&
|
||||||
targetElements.some((element) => hasStrokeColor(element.type))) &&
|
commonSelectedType !== "image") ||
|
||||||
renderAction("changeStrokeColor")}
|
targetElements.some((element) => hasStrokeColor(element.type))) &&
|
||||||
{showChangeBackgroundIcons && renderAction("changeBackgroundColor")}
|
renderAction("changeStrokeColor")}
|
||||||
|
</div>
|
||||||
|
{showChangeBackgroundIcons && (
|
||||||
|
<div>{renderAction("changeBackgroundColor")}</div>
|
||||||
|
)}
|
||||||
{showFillIcons && renderAction("changeFillStyle")}
|
{showFillIcons && renderAction("changeFillStyle")}
|
||||||
|
|
||||||
{(hasStrokeWidth(appState.activeTool.type) ||
|
{(hasStrokeWidth(appState.activeTool.type) ||
|
||||||
@@ -103,9 +110,9 @@ export const SelectedShapeActions = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(canChangeSharpness(appState.activeTool.type) ||
|
{(canChangeRoundness(appState.activeTool.type) ||
|
||||||
targetElements.some((element) => canChangeSharpness(element.type))) && (
|
targetElements.some((element) => canChangeRoundness(element.type))) && (
|
||||||
<>{renderAction("changeSharpness")}</>
|
<>{renderAction("changeRoundness")}</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(hasText(appState.activeTool.type) ||
|
{(hasText(appState.activeTool.type) ||
|
||||||
@@ -119,10 +126,8 @@ export const SelectedShapeActions = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{targetElements.some(
|
{shouldAllowVerticalAlign(targetElements) &&
|
||||||
(element) =>
|
renderAction("changeVerticalAlign")}
|
||||||
hasBoundTextElement(element) || isBoundToContainer(element),
|
|
||||||
) && renderAction("changeVerticalAlign")}
|
|
||||||
{(canHaveArrowheads(appState.activeTool.type) ||
|
{(canHaveArrowheads(appState.activeTool.type) ||
|
||||||
targetElements.some((element) => canHaveArrowheads(element.type))) && (
|
targetElements.some((element) => canHaveArrowheads(element.type))) && (
|
||||||
<>{renderAction("changeArrowhead")}</>
|
<>{renderAction("changeArrowhead")}</>
|
||||||
@@ -163,7 +168,16 @@ export const SelectedShapeActions = ({
|
|||||||
)}
|
)}
|
||||||
{targetElements.length > 2 &&
|
{targetElements.length > 2 &&
|
||||||
renderAction("distributeHorizontally")}
|
renderAction("distributeHorizontally")}
|
||||||
<div className="iconRow">
|
{/* breaks the row ˇˇ */}
|
||||||
|
<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")}
|
||||||
@@ -203,25 +217,25 @@ export const ShapesSwitcher = ({
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
}) => (
|
}) => (
|
||||||
<>
|
<>
|
||||||
{SHAPES.map(({ value, icon, key }, index) => {
|
{SHAPES.map(({ value, icon, key, numericKey, fillable }, index) => {
|
||||||
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")} ${index + 1}`
|
? `${capitalizeString(letter)} ${t("helpDialog.or")} ${numericKey}`
|
||||||
: `${index + 1}`;
|
: `${numericKey}`;
|
||||||
return (
|
return (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
className="Shape"
|
className={clsx("Shape", { fillable })}
|
||||||
key={value}
|
key={value}
|
||||||
type="radio"
|
type="radio"
|
||||||
icon={icon}
|
icon={icon}
|
||||||
checked={activeTool.type === value}
|
checked={activeTool.type === value}
|
||||||
name="editor-current-shape"
|
name="editor-current-shape"
|
||||||
title={`${capitalizeString(label)} — ${shortcut}`}
|
title={`${capitalizeString(label)} — ${shortcut}`}
|
||||||
keyBindingLabel={`${index + 1}`}
|
keyBindingLabel={numericKey}
|
||||||
aria-label={capitalizeString(label)}
|
aria-label={capitalizeString(label)}
|
||||||
aria-keyshortcuts={shortcut}
|
aria-keyshortcuts={shortcut}
|
||||||
data-testid={value}
|
data-testid={`toolbar-${value}`}
|
||||||
onPointerDown={({ pointerType }) => {
|
onPointerDown={({ pointerType }) => {
|
||||||
if (!appState.penDetected && pointerType === "pen") {
|
if (!appState.penDetected && pointerType === "pen") {
|
||||||
setAppState({
|
setAppState({
|
||||||
@@ -263,11 +277,11 @@ export const ZoomActions = ({
|
|||||||
renderAction: ActionManager["renderAction"];
|
renderAction: ActionManager["renderAction"];
|
||||||
zoom: Zoom;
|
zoom: Zoom;
|
||||||
}) => (
|
}) => (
|
||||||
<Stack.Col gap={1}>
|
<Stack.Col gap={1} className="zoom-actions">
|
||||||
<Stack.Row gap={1} align="center">
|
<Stack.Row align="center">
|
||||||
{renderAction("zoomOut")}
|
{renderAction("zoomOut")}
|
||||||
{renderAction("zoomIn")}
|
|
||||||
{renderAction("resetZoom")}
|
{renderAction("resetZoom")}
|
||||||
|
{renderAction("zoomIn")}
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
);
|
);
|
||||||
@@ -280,8 +294,12 @@ export const UndoRedoActions = ({
|
|||||||
className?: string;
|
className?: string;
|
||||||
}) => (
|
}) => (
|
||||||
<div className={`undo-redo-buttons ${className}`}>
|
<div className={`undo-redo-buttons ${className}`}>
|
||||||
{renderAction("undo", { size: "small" })}
|
<div className="undo-button-container">
|
||||||
{renderAction("redo", { size: "small" })}
|
<Tooltip label={t("buttons.undo")}>{renderAction("undo")}</Tooltip>
|
||||||
|
</div>
|
||||||
|
<div className="redo-button-container">
|
||||||
|
<Tooltip label={t("buttons.redo")}> {renderAction("redo")}</Tooltip>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
import Stack from "../components/Stack";
|
// TODO barnabasmolnar/editor-redesign
|
||||||
import { ToolButton } from "../components/ToolButton";
|
// this icon is not great
|
||||||
import { save, file } from "../components/icons";
|
import { getShortcutFromShortcutName } from "../actions/shortcuts";
|
||||||
|
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;
|
||||||
@@ -11,18 +13,11 @@ type ActiveFileProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ActiveFile = ({ fileName, onSave }: ActiveFileProps) => (
|
export const ActiveFile = ({ fileName, onSave }: ActiveFileProps) => (
|
||||||
<Stack.Row className="ActiveFile" gap={1} align="center">
|
<MenuItem
|
||||||
<span className="ActiveFile__fileName">
|
label={`${t("buttons.save")}`}
|
||||||
{file}
|
shortcut={getShortcutFromShortcutName("saveScene")}
|
||||||
<span>{fileName}</span>
|
dataTestId="save-button"
|
||||||
</span>
|
onClick={onSave}
|
||||||
<ToolButton
|
icon={save}
|
||||||
type="icon"
|
/>
|
||||||
icon={save}
|
|
||||||
title={t("buttons.save")}
|
|
||||||
aria-label={t("buttons.save")}
|
|
||||||
onClick={onSave}
|
|
||||||
data-testid="save-button"
|
|
||||||
/>
|
|
||||||
</Stack.Row>
|
|
||||||
);
|
);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -2,21 +2,35 @@
|
|||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.Avatar {
|
.Avatar {
|
||||||
width: 2.5rem;
|
width: 1.25rem;
|
||||||
height: 2.5rem;
|
height: 1.25rem;
|
||||||
border-radius: 1.25rem;
|
position: relative;
|
||||||
|
border-radius: 100%;
|
||||||
|
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.8rem;
|
font-size: 0.625rem;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
line-height: 1;
|
||||||
|
|
||||||
&-img {
|
&-img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: -3px;
|
||||||
|
right: -3px;
|
||||||
|
bottom: -3px;
|
||||||
|
left: -3px;
|
||||||
|
border: 1px solid var(--avatar-border-color);
|
||||||
|
border-radius: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,13 +11,11 @@ type AvatarProps = {
|
|||||||
src?: string;
|
src?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Avatar = ({ color, border, onClick, name, src }: AvatarProps) => {
|
export const Avatar = ({ color, 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
|
const style = loadImg ? undefined : { background: color };
|
||||||
? 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 ? (
|
||||||
|
@@ -1,20 +0,0 @@
|
|||||||
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,6 +64,8 @@
|
|||||||
|
|
||||||
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,10 +1,9 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "./App";
|
import { TrashIcon } from "./icons";
|
||||||
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);
|
||||||
@@ -14,14 +13,11 @@ const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ToolButton
|
<MenuItem
|
||||||
type="button"
|
label={t("buttons.clearReset")}
|
||||||
icon={trash}
|
icon={TrashIcon}
|
||||||
title={t("buttons.clearReset")}
|
|
||||||
aria-label={t("buttons.clearReset")}
|
|
||||||
showAriaLabel={useDevice().isMobile}
|
|
||||||
onClick={toggleDialog}
|
onClick={toggleDialog}
|
||||||
data-testid="clear-canvas-button"
|
dataTestId="clear-canvas-button"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{showDialog && (
|
{showDialog && (
|
||||||
|
@@ -1,6 +1,51 @@
|
|||||||
@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);
|
||||||
|
|
||||||
@@ -24,9 +69,9 @@
|
|||||||
bottom: -5px;
|
bottom: -5px;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: $oc-green-6;
|
background-color: $oc-green-2;
|
||||||
color: $oc-white;
|
color: $oc-green-9;
|
||||||
font-size: 0.6em;
|
font-size: 0.6rem;
|
||||||
font-family: "Cascadia";
|
font-family: "Cascadia";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,37 +1,47 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import { ToolButton } from "./ToolButton";
|
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "../components/App";
|
import { UsersIcon } from "./icons";
|
||||||
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 (
|
||||||
<>
|
<>
|
||||||
<ToolButton
|
{isInHamburgerMenu ? (
|
||||||
className={clsx("CollabButton", {
|
<MenuItem
|
||||||
"is-collaborating": isCollaborating,
|
label={t("labels.liveCollaboration")}
|
||||||
})}
|
dataTestId="collab-button"
|
||||||
onClick={onClick}
|
icon={UsersIcon}
|
||||||
icon={users}
|
onClick={onClick}
|
||||||
type="button"
|
isCollaborating={isCollaborating}
|
||||||
title={t("labels.liveCollaboration")}
|
/>
|
||||||
aria-label={t("labels.liveCollaboration")}
|
) : (
|
||||||
showAriaLabel={useDevice().isMobile}
|
<button
|
||||||
>
|
className={clsx("collab-button", { active: isCollaborating })}
|
||||||
{isCollaborating && (
|
type="button"
|
||||||
<div className="CollabButton-collaborators">{collaboratorCount}</div>
|
onClick={onClick}
|
||||||
)}
|
style={{ position: "relative" }}
|
||||||
</ToolButton>
|
title={t("labels.liveCollaboration")}
|
||||||
|
>
|
||||||
|
{UsersIcon}
|
||||||
|
{collaboratorCount > 0 && (
|
||||||
|
<div className="CollabButton-collaborators">
|
||||||
|
{collaboratorCount}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -21,6 +21,23 @@
|
|||||||
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 {
|
||||||
@@ -30,20 +47,29 @@
|
|||||||
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"] & {
|
||||||
left: 12px;
|
transform: rotate(270deg);
|
||||||
|
left: -14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
:root[dir="rtl"] & {
|
||||||
right: 12px;
|
transform: rotate(90deg);
|
||||||
|
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 {
|
||||||
@@ -119,16 +145,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-hash {
|
.color-picker-hash {
|
||||||
background: var(--input-border-color);
|
height: var(--default-button-size);
|
||||||
height: 1.875rem;
|
flex-shrink: 0;
|
||||||
width: 1.875rem;
|
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
|
||||||
|
border: 1px solid var(--default-border-color);
|
||||||
|
border-right: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
:root[dir="ltr"] & {
|
||||||
border-radius: 4px 0 0 4px;
|
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
:root[dir="rtl"] & {
|
||||||
border-radius: 0 4px 4px 0;
|
border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
|
||||||
|
border-right: 1px solid var(--default-border-color);
|
||||||
|
border-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
color: var(--input-label-color);
|
color: var(--input-label-color);
|
||||||
@@ -138,81 +169,64 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-input-container:focus-within .color-picker-hash {
|
|
||||||
box-shadow: 0 0 0 2px var(--focus-highlight-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-input-container:focus-within .color-picker-hash::before,
|
|
||||||
.color-input-container:focus-within .color-picker-hash::after {
|
|
||||||
content: "";
|
|
||||||
width: 1px;
|
|
||||||
height: 100%;
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-input-container:focus-within .color-picker-hash::before {
|
|
||||||
background: var(--input-border-color);
|
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
|
||||||
right: -1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
left: -1px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-input-container:focus-within .color-picker-hash::after {
|
|
||||||
background: var(--input-bg-color);
|
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
|
||||||
right: -2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
|
||||||
left: -2px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-input-container {
|
.color-input-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
|
&:focus-within {
|
||||||
|
box-shadow: 0 0 0 1px var(--color-primary-darkest);
|
||||||
|
border-radius: var(--border-radius-lg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-input {
|
.color-picker-input {
|
||||||
width: 11ch; /* length of `transparent` */
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 1rem;
|
font-size: 0.875rem;
|
||||||
background-color: var(--input-bg-color);
|
background-color: transparent;
|
||||||
color: var(--text-primary-color);
|
color: var(--text-primary-color);
|
||||||
border: 0;
|
border: 0;
|
||||||
outline: none;
|
outline: none;
|
||||||
height: 1.75em;
|
height: var(--default-button-size);
|
||||||
box-shadow: var(--input-border-color) 0 0 0 1px inset;
|
border: 1px solid var(--default-border-color);
|
||||||
|
border-left: 0;
|
||||||
|
letter-spacing: 0.4px;
|
||||||
|
|
||||||
:root[dir="ltr"] & {
|
:root[dir="ltr"] & {
|
||||||
border-radius: 0 4px 4px 0;
|
border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
:root[dir="rtl"] & {
|
||||||
border-radius: 4px 0 0 4px;
|
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
||||||
|
border-left: 1px solid var(--default-border-color);
|
||||||
|
border-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float: left;
|
padding: 0.5rem;
|
||||||
padding: 1px;
|
padding-left: 0.25rem;
|
||||||
padding-inline-start: 0.5em;
|
|
||||||
appearance: none;
|
appearance: none;
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-picker-label-swatch-container {
|
||||||
|
border: 1px solid var(--default-border-color);
|
||||||
|
border-radius: var(--border-radius-lg);
|
||||||
|
width: var(--default-button-size);
|
||||||
|
height: var(--default-button-size);
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker-label-swatch {
|
.color-picker-label-swatch {
|
||||||
height: 1.875rem;
|
@include outlineButtonStyles;
|
||||||
width: 1.875rem;
|
background-color: var(--swatch-color) !important;
|
||||||
margin-inline-end: 0.25rem;
|
|
||||||
border: 1px solid $oc-gray-3;
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: transparent !important;
|
position: relative;
|
||||||
filter: var(--theme-filter);
|
filter: var(--theme-filter);
|
||||||
|
border: 0 !important;
|
||||||
|
|
||||||
&:after {
|
&:after {
|
||||||
content: "";
|
content: "";
|
||||||
|
@@ -66,10 +66,13 @@ const getColor = (color: string): string | null => {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isValidColor(color)
|
// testing for `#` first fixes a bug on Electron (more specfically, an
|
||||||
? color
|
// Obsidian popout window), where a hex color without `#` is (incorrectly)
|
||||||
: isValidColor(`#${color}`)
|
// considered valid
|
||||||
|
return isValidColor(`#${color}`)
|
||||||
? `#${color}`
|
? `#${color}`
|
||||||
|
: isValidColor(color)
|
||||||
|
? color
|
||||||
: null;
|
: null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -365,17 +368,20 @@ 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">
|
||||||
<button
|
<div className="color-picker-label-swatch-container">
|
||||||
className="color-picker-label-swatch"
|
<button
|
||||||
aria-label={label}
|
className="color-picker-label-swatch"
|
||||||
style={color ? { "--swatch-color": color } : undefined}
|
aria-label={label}
|
||||||
onClick={() => setActive(!isActive)}
|
style={color ? { "--swatch-color": color } : undefined}
|
||||||
ref={pickerButton}
|
onClick={() => setActive(!isActive)}
|
||||||
/>
|
ref={pickerButton}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<ColorInput
|
<ColorInput
|
||||||
color={color}
|
color={color}
|
||||||
label={label}
|
label={label}
|
||||||
@@ -386,27 +392,37 @@ export const ColorPicker = ({
|
|||||||
</div>
|
</div>
|
||||||
<React.Suspense fallback="">
|
<React.Suspense fallback="">
|
||||||
{isActive ? (
|
{isActive ? (
|
||||||
<Popover
|
<div
|
||||||
onCloseRequest={(event) =>
|
className="color-picker-popover-container"
|
||||||
event.target !== pickerButton.current && setActive(false)
|
style={{
|
||||||
}
|
position: "fixed",
|
||||||
|
top: coords?.top,
|
||||||
|
left: coords?.right,
|
||||||
|
zIndex: 1,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Picker
|
<Popover
|
||||||
colors={colors[type]}
|
onCloseRequest={(event) =>
|
||||||
color={color || null}
|
event.target !== pickerButton.current && setActive(false)
|
||||||
onChange={(changedColor) => {
|
}
|
||||||
onChange(changedColor);
|
>
|
||||||
}}
|
<Picker
|
||||||
onClose={() => {
|
colors={colors[type]}
|
||||||
setActive(false);
|
color={color || null}
|
||||||
pickerButton.current?.focus();
|
onChange={(changedColor) => {
|
||||||
}}
|
onChange(changedColor);
|
||||||
label={label}
|
}}
|
||||||
showInput={false}
|
onClose={() => {
|
||||||
type={type}
|
setActive(false);
|
||||||
elements={elements}
|
pickerButton.current?.focus();
|
||||||
/>
|
}}
|
||||||
</Popover>
|
label={label}
|
||||||
|
showInput={false}
|
||||||
|
type={type}
|
||||||
|
elements={elements}
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -4,34 +4,8 @@
|
|||||||
.confirm-dialog {
|
.confirm-dialog {
|
||||||
&-buttons {
|
&-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0.2rem 0;
|
column-gap: 0.5rem;
|
||||||
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,8 +1,11 @@
|
|||||||
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;
|
||||||
@@ -20,6 +23,10 @@ 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}
|
||||||
@@ -29,21 +36,22 @@ const ConfirmDialog = (props: Props) => {
|
|||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<div className="confirm-dialog-buttons">
|
<div className="confirm-dialog-buttons">
|
||||||
<ToolButton
|
<DialogActionButton
|
||||||
type="button"
|
|
||||||
title={cancelText}
|
|
||||||
aria-label={cancelText}
|
|
||||||
label={cancelText}
|
label={cancelText}
|
||||||
onClick={onCancel}
|
onClick={() => {
|
||||||
className="confirm-dialog--cancel"
|
setIsMenuOpen(false);
|
||||||
|
setIsDropdownOpen(false);
|
||||||
|
onCancel();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<ToolButton
|
<DialogActionButton
|
||||||
type="button"
|
|
||||||
title={confirmText}
|
|
||||||
aria-label={confirmText}
|
|
||||||
label={confirmText}
|
label={confirmText}
|
||||||
onClick={onConfirm}
|
onClick={() => {
|
||||||
className="confirm-dialog--confirm"
|
setIsMenuOpen(false);
|
||||||
|
setIsDropdownOpen(false);
|
||||||
|
onConfirm();
|
||||||
|
}}
|
||||||
|
actionType="danger"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
color: var(--popup-text-color);
|
color: var(--popup-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.context-menu-option {
|
.context-menu-item {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-width: 9.5rem;
|
min-width: 9.5rem;
|
||||||
@@ -43,16 +43,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.dangerous {
|
&.dangerous {
|
||||||
.context-menu-option__label {
|
.context-menu-item__label {
|
||||||
color: $oc-red-7;
|
color: $oc-red-7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.context-menu-option__label {
|
.context-menu-item__label {
|
||||||
justify-self: start;
|
justify-self: start;
|
||||||
margin-inline-end: 20px;
|
margin-inline-end: 20px;
|
||||||
}
|
}
|
||||||
.context-menu-option__shortcut {
|
.context-menu-item__shortcut {
|
||||||
justify-self: end;
|
justify-self: end;
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
@@ -60,37 +60,37 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.context-menu-option:hover {
|
.context-menu-item:hover {
|
||||||
color: var(--popup-bg-color);
|
color: var(--popup-bg-color);
|
||||||
background-color: var(--select-highlight-color);
|
background-color: var(--select-highlight-color);
|
||||||
|
|
||||||
&.dangerous {
|
&.dangerous {
|
||||||
.context-menu-option__label {
|
.context-menu-item__label {
|
||||||
color: var(--popup-bg-color);
|
color: var(--popup-bg-color);
|
||||||
}
|
}
|
||||||
background-color: $oc-red-6;
|
background-color: $oc-red-6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.context-menu-option:focus {
|
.context-menu-item:focus {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@include isMobile {
|
@include isMobile {
|
||||||
.context-menu-option {
|
.context-menu-item {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
.context-menu-option__label {
|
.context-menu-item__label {
|
||||||
margin-inline-end: 0;
|
margin-inline-end: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.context-menu-option__shortcut {
|
.context-menu-item__shortcut {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.context-menu-option-separator {
|
.context-menu-item-separator {
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid $oc-gray-5;
|
border-top: 1px solid $oc-gray-5;
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import { render, unmountComponentAtNode } from "react-dom";
|
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { Popover } from "./Popover";
|
import { Popover } from "./Popover";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
@@ -10,140 +9,116 @@ import {
|
|||||||
} from "../actions/shortcuts";
|
} from "../actions/shortcuts";
|
||||||
import { Action } from "../actions/types";
|
import { Action } from "../actions/types";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { AppState } from "../types";
|
import {
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
useExcalidrawAppState,
|
||||||
|
useExcalidrawElements,
|
||||||
|
useExcalidrawSetAppState,
|
||||||
|
} from "./App";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
export type ContextMenuOption = "separator" | Action;
|
export type ContextMenuItem = typeof CONTEXT_MENU_SEPARATOR | Action;
|
||||||
|
|
||||||
|
export type ContextMenuItems = (ContextMenuItem | false | null | undefined)[];
|
||||||
|
|
||||||
type ContextMenuProps = {
|
type ContextMenuProps = {
|
||||||
options: ContextMenuOption[];
|
actionManager: ActionManager;
|
||||||
onCloseRequest?(): void;
|
items: ContextMenuItems;
|
||||||
top: number;
|
top: number;
|
||||||
left: number;
|
left: number;
|
||||||
actionManager: ActionManager;
|
|
||||||
appState: Readonly<AppState>;
|
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ContextMenu = ({
|
export const CONTEXT_MENU_SEPARATOR = "separator";
|
||||||
options,
|
|
||||||
onCloseRequest,
|
|
||||||
top,
|
|
||||||
left,
|
|
||||||
actionManager,
|
|
||||||
appState,
|
|
||||||
elements,
|
|
||||||
}: ContextMenuProps) => {
|
|
||||||
return (
|
|
||||||
<Popover
|
|
||||||
onCloseRequest={onCloseRequest}
|
|
||||||
top={top}
|
|
||||||
left={left}
|
|
||||||
fitInViewport={true}
|
|
||||||
offsetLeft={appState.offsetLeft}
|
|
||||||
offsetTop={appState.offsetTop}
|
|
||||||
viewportWidth={appState.width}
|
|
||||||
viewportHeight={appState.height}
|
|
||||||
>
|
|
||||||
<ul
|
|
||||||
className="context-menu"
|
|
||||||
onContextMenu={(event) => event.preventDefault()}
|
|
||||||
>
|
|
||||||
{options.map((option, idx) => {
|
|
||||||
if (option === "separator") {
|
|
||||||
return <hr key={idx} className="context-menu-option-separator" />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const actionName = option.name;
|
export const ContextMenu = React.memo(
|
||||||
let label = "";
|
({ actionManager, items, top, left }: ContextMenuProps) => {
|
||||||
if (option.contextItemLabel) {
|
const appState = useExcalidrawAppState();
|
||||||
if (typeof option.contextItemLabel === "function") {
|
const setAppState = useExcalidrawSetAppState();
|
||||||
label = t(option.contextItemLabel(elements, appState));
|
const elements = useExcalidrawElements();
|
||||||
} else {
|
|
||||||
label = t(option.contextItemLabel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<li key={idx} data-testid={actionName} onClick={onCloseRequest}>
|
|
||||||
<button
|
|
||||||
className={clsx("context-menu-option", {
|
|
||||||
dangerous: actionName === "deleteSelectedElements",
|
|
||||||
checkmark: option.checked?.(appState),
|
|
||||||
})}
|
|
||||||
onClick={() =>
|
|
||||||
actionManager.executeAction(option, "contextMenu")
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className="context-menu-option__label">{label}</div>
|
|
||||||
<kbd className="context-menu-option__shortcut">
|
|
||||||
{actionName
|
|
||||||
? getShortcutFromShortcutName(actionName as ShortcutName)
|
|
||||||
: ""}
|
|
||||||
</kbd>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</ul>
|
|
||||||
</Popover>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const contextMenuNodeByContainer = new WeakMap<HTMLElement, HTMLDivElement>();
|
const filteredItems = items.reduce((acc: ContextMenuItem[], item) => {
|
||||||
|
if (
|
||||||
const getContextMenuNode = (container: HTMLElement): HTMLDivElement => {
|
item &&
|
||||||
let contextMenuNode = contextMenuNodeByContainer.get(container);
|
(item === CONTEXT_MENU_SEPARATOR ||
|
||||||
if (contextMenuNode) {
|
!item.contextItemPredicate ||
|
||||||
return contextMenuNode;
|
item.contextItemPredicate(
|
||||||
}
|
elements,
|
||||||
contextMenuNode = document.createElement("div");
|
appState,
|
||||||
container
|
actionManager.app.props,
|
||||||
.querySelector(".excalidraw-contextMenuContainer")!
|
actionManager.app,
|
||||||
.appendChild(contextMenuNode);
|
))
|
||||||
contextMenuNodeByContainer.set(container, contextMenuNode);
|
) {
|
||||||
return contextMenuNode;
|
acc.push(item);
|
||||||
};
|
|
||||||
|
|
||||||
type ContextMenuParams = {
|
|
||||||
options: (ContextMenuOption | false | null | undefined)[];
|
|
||||||
top: ContextMenuProps["top"];
|
|
||||||
left: ContextMenuProps["left"];
|
|
||||||
actionManager: ContextMenuProps["actionManager"];
|
|
||||||
appState: Readonly<AppState>;
|
|
||||||
container: HTMLElement;
|
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClose = (container: HTMLElement) => {
|
|
||||||
const contextMenuNode = contextMenuNodeByContainer.get(container);
|
|
||||||
if (contextMenuNode) {
|
|
||||||
unmountComponentAtNode(contextMenuNode);
|
|
||||||
contextMenuNode.remove();
|
|
||||||
contextMenuNodeByContainer.delete(container);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
|
||||||
push(params: ContextMenuParams) {
|
|
||||||
const options = Array.of<ContextMenuOption>();
|
|
||||||
params.options.forEach((option) => {
|
|
||||||
if (option) {
|
|
||||||
options.push(option);
|
|
||||||
}
|
}
|
||||||
});
|
return acc;
|
||||||
if (options.length) {
|
}, []);
|
||||||
render(
|
|
||||||
<ContextMenu
|
return (
|
||||||
top={params.top}
|
<Popover
|
||||||
left={params.left}
|
onCloseRequest={() => setAppState({ contextMenu: null })}
|
||||||
options={options}
|
top={top}
|
||||||
onCloseRequest={() => handleClose(params.container)}
|
left={left}
|
||||||
actionManager={params.actionManager}
|
fitInViewport={true}
|
||||||
appState={params.appState}
|
offsetLeft={appState.offsetLeft}
|
||||||
elements={params.elements}
|
offsetTop={appState.offsetTop}
|
||||||
/>,
|
viewportWidth={appState.width}
|
||||||
getContextMenuNode(params.container),
|
viewportHeight={appState.height}
|
||||||
);
|
>
|
||||||
}
|
<ul
|
||||||
|
className="context-menu"
|
||||||
|
onContextMenu={(event) => event.preventDefault()}
|
||||||
|
>
|
||||||
|
{filteredItems.map((item, idx) => {
|
||||||
|
if (item === CONTEXT_MENU_SEPARATOR) {
|
||||||
|
if (
|
||||||
|
!filteredItems[idx - 1] ||
|
||||||
|
filteredItems[idx - 1] === CONTEXT_MENU_SEPARATOR
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return <hr key={idx} className="context-menu-item-separator" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionName = item.name;
|
||||||
|
let label = "";
|
||||||
|
if (item.contextItemLabel) {
|
||||||
|
if (typeof item.contextItemLabel === "function") {
|
||||||
|
label = t(item.contextItemLabel(elements, appState));
|
||||||
|
} else {
|
||||||
|
label = t(item.contextItemLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
key={idx}
|
||||||
|
data-testid={actionName}
|
||||||
|
onClick={() => {
|
||||||
|
// we need update state before executing the action in case
|
||||||
|
// the action uses the appState it's being passed (that still
|
||||||
|
// contains a defined contextMenu) to return the next state.
|
||||||
|
setAppState({ contextMenu: null }, () => {
|
||||||
|
actionManager.executeAction(item, "contextMenu");
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
className={clsx("context-menu-item", {
|
||||||
|
dangerous: actionName === "deleteSelectedElements",
|
||||||
|
checkmark: item.checked?.(appState),
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<div className="context-menu-item__label">{label}</div>
|
||||||
|
<kbd className="context-menu-item__shortcut">
|
||||||
|
{actionName
|
||||||
|
? getShortcutFromShortcutName(actionName as ShortcutName)
|
||||||
|
: ""}
|
||||||
|
</kbd>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
};
|
);
|
||||||
|
@@ -7,68 +7,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.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;
|
||||||
.Dialog__content {
|
border-bottom: 1px solid var(--dialog-border-color);
|
||||||
padding: 0 16px 16px;
|
padding: 0 0 0.75rem;
|
||||||
}
|
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,11 +5,13 @@ 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, close } from "./icons";
|
import { back, CloseIcon } 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;
|
||||||
@@ -65,7 +67,12 @@ 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();
|
||||||
};
|
};
|
||||||
@@ -88,7 +95,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 : close}
|
{useDevice().isMobile ? back : CloseIcon}
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div className="Dialog__content">{props.children}</div>
|
<div className="Dialog__content">{props.children}</div>
|
||||||
|
47
src/components/DialogActionButton.scss
Normal file
47
src/components/DialogActionButton.scss
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
src/components/DialogActionButton.tsx
Normal file
46
src/components/DialogActionButton.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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;
|
@@ -91,6 +91,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,9 +9,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.FixedSideContainer_side_top {
|
.FixedSideContainer_side_top {
|
||||||
left: var(--space-factor);
|
left: 1rem;
|
||||||
top: var(--space-factor);
|
top: 1rem;
|
||||||
right: var(--space-factor);
|
right: 1rem;
|
||||||
|
bottom: 1rem;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
import { questionCircle } from "../components/icons";
|
import { HelpIcon } from "./icons";
|
||||||
|
|
||||||
type HelpIconProps = {
|
type HelpButtonProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
id?: string;
|
id?: string;
|
||||||
onClick?(): void;
|
onClick?(): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const HelpIcon = (props: HelpIconProps) => (
|
export const HelpButton = (props: HelpButtonProps) => (
|
||||||
<button
|
<button
|
||||||
className="help-icon"
|
className="help-icon"
|
||||||
onClick={props.onClick}
|
onClick={props.onClick}
|
||||||
@@ -15,6 +15,6 @@ export const HelpIcon = (props: HelpIconProps) => (
|
|||||||
title={`${props.title} — ?`}
|
title={`${props.title} — ?`}
|
||||||
aria-label={props.title}
|
aria-label={props.title}
|
||||||
>
|
>
|
||||||
{questionCircle}
|
{HelpIcon}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
@@ -1,56 +1,115 @@
|
|||||||
@import "../css/variables.module";
|
@import "../css/variables.module";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.HelpDialog h3 {
|
.HelpDialog {
|
||||||
border-bottom: 1px solid var(--button-gray-2);
|
.Modal__content {
|
||||||
padding-bottom: 4px;
|
max-width: 960px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.HelpDialog--island {
|
h3 {
|
||||||
border: 1px solid var(--button-gray-2);
|
margin: 1.5rem 0;
|
||||||
margin-bottom: 16px;
|
font-weight: bold;
|
||||||
}
|
font-size: 1.125rem;
|
||||||
|
}
|
||||||
|
|
||||||
.HelpDialog--island-title {
|
&__header {
|
||||||
margin: 0;
|
display: flex;
|
||||||
padding: 4px;
|
flex-wrap: wrap;
|
||||||
background-color: var(--button-gray-1);
|
gap: 0.75rem;
|
||||||
text-align: center;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.HelpDialog--shortcut {
|
&__btn {
|
||||||
border-top: 1px solid var(--button-gray-2);
|
display: flex;
|
||||||
}
|
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;
|
||||||
|
|
||||||
.HelpDialog--key {
|
&:hover {
|
||||||
word-break: keep-all;
|
text-decoration: none;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.HelpDialog--header {
|
&__link-icon {
|
||||||
display: flex;
|
line-height: 0;
|
||||||
flex-direction: row;
|
svg {
|
||||||
justify-content: space-evenly;
|
width: 1rem;
|
||||||
margin-bottom: 32px;
|
height: 1rem;
|
||||||
padding-bottom: 16px;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.HelpDialog--btn {
|
&__islands-container {
|
||||||
border: 1px solid var(--link-color);
|
display: grid;
|
||||||
padding: 8px 32px;
|
@media screen and (min-width: 1024px) {
|
||||||
border-radius: 4px;
|
grid-template-columns: 1fr 1fr;
|
||||||
}
|
}
|
||||||
.HelpDialog--btn:hover {
|
grid-column-gap: 1.5rem;
|
||||||
text-decoration: none;
|
grid-row-gap: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,35 +1,39 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { isDarwin, isWindows } from "../keys";
|
import { isDarwin, isWindows, KEYS } 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>
|
||||||
);
|
);
|
||||||
@@ -37,88 +41,61 @@ 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>
|
||||||
{props.children}
|
<div className="HelpDialog__islands-container">{props.children}</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
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">
|
<div className={`HelpDialog__island ${props.className}`}>
|
||||||
<h3 className="HelpDialog--island-title">{props.caption}</h3>
|
<h4 className="HelpDialog__island-title">{props.caption}</h4>
|
||||||
{props.children}
|
<div className="HelpDialog__island-content">{props.children}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const Shortcut = (props: {
|
function* intersperse(as: JSX.Element[][], delim: string | null) {
|
||||||
|
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
|
<div>{label}</div>
|
||||||
style={{
|
<div className="HelpDialog__key-container">
|
||||||
display: "flex",
|
{[...intersperse(splitShortcutKeys, isOr ? t("helpDialog.or") : null)]}
|
||||||
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 }) => {
|
||||||
@@ -137,286 +114,311 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
|||||||
>
|
>
|
||||||
<Header />
|
<Header />
|
||||||
<Section title={t("helpDialog.shortcuts")}>
|
<Section title={t("helpDialog.shortcuts")}>
|
||||||
<Columns>
|
<ShortcutIsland
|
||||||
<Column>
|
className="HelpDialog__island--tools"
|
||||||
<ShortcutIsland caption={t("helpDialog.tools")}>
|
caption={t("helpDialog.tools")}
|
||||||
<Shortcut
|
>
|
||||||
label={t("toolBar.selection")}
|
<Shortcut
|
||||||
shortcuts={["V", "1"]}
|
label={t("toolBar.selection")}
|
||||||
/>
|
shortcuts={[KEYS.V, KEYS["1"]]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("toolBar.rectangle")}
|
<Shortcut
|
||||||
shortcuts={["R", "2"]}
|
label={t("toolBar.rectangle")}
|
||||||
/>
|
shortcuts={[KEYS.R, KEYS["2"]]}
|
||||||
<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.diamond")}
|
||||||
<Shortcut label={t("toolBar.line")} shortcuts={["P", "6"]} />
|
shortcuts={[KEYS.D, KEYS["3"]]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("toolBar.freedraw")}
|
<Shortcut
|
||||||
shortcuts={["Shift + P", "X", "7"]}
|
label={t("toolBar.ellipse")}
|
||||||
/>
|
shortcuts={[KEYS.O, KEYS["4"]]}
|
||||||
<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("toolBar.arrow")}
|
||||||
<Shortcut
|
shortcuts={[KEYS.A, KEYS["5"]]}
|
||||||
label={t("toolBar.eraser")}
|
/>
|
||||||
shortcuts={[getShortcutKey("E")]}
|
<Shortcut
|
||||||
/>
|
label={t("toolBar.line")}
|
||||||
<Shortcut
|
shortcuts={[KEYS.P, KEYS["6"]]}
|
||||||
label={t("helpDialog.editSelectedShape")}
|
/>
|
||||||
shortcuts={[
|
<Shortcut
|
||||||
getShortcutKey("Enter"),
|
label={t("toolBar.freedraw")}
|
||||||
t("helpDialog.doubleClick"),
|
shortcuts={["Shift + P", KEYS["7"]]}
|
||||||
]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("toolBar.text")}
|
||||||
label={t("helpDialog.textNewLine")}
|
shortcuts={[KEYS.T, KEYS["8"]]}
|
||||||
shortcuts={[
|
/>
|
||||||
getShortcutKey("Enter"),
|
<Shortcut label={t("toolBar.image")} shortcuts={[KEYS["9"]]} />
|
||||||
getShortcutKey("Shift+Enter"),
|
<Shortcut
|
||||||
]}
|
label={t("toolBar.eraser")}
|
||||||
/>
|
shortcuts={[KEYS.E, KEYS["0"]]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.textFinish")}
|
<Shortcut
|
||||||
shortcuts={[
|
label={t("helpDialog.editSelectedShape")}
|
||||||
getShortcutKey("Esc"),
|
shortcuts={[
|
||||||
getShortcutKey("CtrlOrCmd+Enter"),
|
getShortcutKey("CtrlOrCmd+Enter"),
|
||||||
]}
|
getShortcutKey(`CtrlOrCmd + ${t("helpDialog.doubleClick")}`),
|
||||||
/>
|
]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.curvedArrow")}
|
<Shortcut
|
||||||
shortcuts={[
|
label={t("helpDialog.textNewLine")}
|
||||||
"A",
|
shortcuts={[
|
||||||
t("helpDialog.click"),
|
getShortcutKey("Enter"),
|
||||||
t("helpDialog.click"),
|
getShortcutKey("Shift+Enter"),
|
||||||
t("helpDialog.click"),
|
]}
|
||||||
]}
|
/>
|
||||||
isOr={false}
|
<Shortcut
|
||||||
/>
|
label={t("helpDialog.textFinish")}
|
||||||
<Shortcut
|
shortcuts={[
|
||||||
label={t("helpDialog.curvedLine")}
|
getShortcutKey("Esc"),
|
||||||
shortcuts={[
|
getShortcutKey("CtrlOrCmd+Enter"),
|
||||||
"L",
|
]}
|
||||||
t("helpDialog.click"),
|
/>
|
||||||
t("helpDialog.click"),
|
<Shortcut
|
||||||
t("helpDialog.click"),
|
label={t("helpDialog.curvedArrow")}
|
||||||
]}
|
shortcuts={[
|
||||||
isOr={false}
|
"A",
|
||||||
/>
|
t("helpDialog.click"),
|
||||||
<Shortcut label={t("toolBar.lock")} shortcuts={["Q"]} />
|
t("helpDialog.click"),
|
||||||
<Shortcut
|
t("helpDialog.click"),
|
||||||
label={t("helpDialog.preventBinding")}
|
]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd")]}
|
isOr={false}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("toolBar.link")}
|
label={t("helpDialog.curvedLine")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+K")]}
|
shortcuts={[
|
||||||
/>
|
"L",
|
||||||
</ShortcutIsland>
|
t("helpDialog.click"),
|
||||||
<ShortcutIsland caption={t("helpDialog.view")}>
|
t("helpDialog.click"),
|
||||||
<Shortcut
|
t("helpDialog.click"),
|
||||||
label={t("buttons.zoomIn")}
|
]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd++")]}
|
isOr={false}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut label={t("toolBar.lock")} shortcuts={[KEYS.Q]} />
|
||||||
label={t("buttons.zoomOut")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+-")]}
|
label={t("helpDialog.preventBinding")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("buttons.resetZoom")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+0")]}
|
label={t("toolBar.link")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+K")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("helpDialog.zoomToFit")}
|
</ShortcutIsland>
|
||||||
shortcuts={["Shift+1"]}
|
<ShortcutIsland
|
||||||
/>
|
className="HelpDialog__island--view"
|
||||||
<Shortcut
|
caption={t("helpDialog.view")}
|
||||||
label={t("helpDialog.zoomToSelection")}
|
>
|
||||||
shortcuts={["Shift+2"]}
|
<Shortcut
|
||||||
/>
|
label={t("buttons.zoomIn")}
|
||||||
<Shortcut label={t("buttons.fullScreen")} shortcuts={["F"]} />
|
shortcuts={[getShortcutKey("CtrlOrCmd++")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("buttons.zenMode")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Alt+Z")]}
|
label={t("buttons.zoomOut")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+-")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("labels.showGrid")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
|
label={t("buttons.resetZoom")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+0")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("labels.viewMode")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Alt+R")]}
|
label={t("helpDialog.zoomToFit")}
|
||||||
/>
|
shortcuts={["Shift+1"]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("labels.toggleTheme")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Alt+Shift+D")]}
|
label={t("helpDialog.zoomToSelection")}
|
||||||
/>
|
shortcuts={["Shift+2"]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("stats.title")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("Alt+/")]}
|
label={t("helpDialog.movePageUpDown")}
|
||||||
/>
|
shortcuts={["PgUp/PgDn"]}
|
||||||
</ShortcutIsland>
|
/>
|
||||||
</Column>
|
<Shortcut
|
||||||
<Column>
|
label={t("helpDialog.movePageLeftRight")}
|
||||||
<ShortcutIsland caption={t("helpDialog.editor")}>
|
shortcuts={["Shift+PgUp/PgDn"]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("labels.selectAll")}
|
<Shortcut label={t("buttons.fullScreen")} shortcuts={["F"]} />
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+A")]}
|
<Shortcut
|
||||||
/>
|
label={t("buttons.zenMode")}
|
||||||
<Shortcut
|
shortcuts={[getShortcutKey("Alt+Z")]}
|
||||||
label={t("labels.multiSelect")}
|
/>
|
||||||
shortcuts={[getShortcutKey(`Shift+${t("helpDialog.click")}`)]}
|
<Shortcut
|
||||||
/>
|
label={t("labels.showGrid")}
|
||||||
<Shortcut
|
shortcuts={[getShortcutKey("CtrlOrCmd+'")]}
|
||||||
label={t("helpDialog.deepSelect")}
|
/>
|
||||||
shortcuts={[
|
<Shortcut
|
||||||
getShortcutKey(`CtrlOrCmd+${t("helpDialog.click")}`),
|
label={t("labels.viewMode")}
|
||||||
]}
|
shortcuts={[getShortcutKey("Alt+R")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("helpDialog.deepBoxSelect")}
|
label={t("labels.toggleTheme")}
|
||||||
shortcuts={[
|
shortcuts={[getShortcutKey("Alt+Shift+D")]}
|
||||||
getShortcutKey(`CtrlOrCmd+${t("helpDialog.drag")}`),
|
/>
|
||||||
]}
|
<Shortcut
|
||||||
/>
|
label={t("stats.title")}
|
||||||
<Shortcut
|
shortcuts={[getShortcutKey("Alt+/")]}
|
||||||
label={t("labels.moveCanvas")}
|
/>
|
||||||
shortcuts={[
|
</ShortcutIsland>
|
||||||
getShortcutKey(`Space+${t("helpDialog.drag")}`),
|
<ShortcutIsland
|
||||||
getShortcutKey(`Wheel+${t("helpDialog.drag")}`),
|
className="HelpDialog__island--editor"
|
||||||
]}
|
caption={t("helpDialog.editor")}
|
||||||
isOr={true}
|
>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.selectAll")}
|
||||||
label={t("labels.cut")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+A")]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+X")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.multiSelect")}
|
||||||
label={t("labels.copy")}
|
shortcuts={[getShortcutKey(`Shift+${t("helpDialog.click")}`)]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+C")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("helpDialog.deepSelect")}
|
||||||
label={t("labels.paste")}
|
shortcuts={[getShortcutKey(`CtrlOrCmd+${t("helpDialog.click")}`)]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+V")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("helpDialog.deepBoxSelect")}
|
||||||
label={t("labels.copyAsPng")}
|
shortcuts={[getShortcutKey(`CtrlOrCmd+${t("helpDialog.drag")}`)]}
|
||||||
shortcuts={[getShortcutKey("Shift+Alt+C")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.moveCanvas")}
|
||||||
label={t("labels.copyStyles")}
|
shortcuts={[
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+C")]}
|
getShortcutKey(`Space+${t("helpDialog.drag")}`),
|
||||||
/>
|
getShortcutKey(`Wheel+${t("helpDialog.drag")}`),
|
||||||
<Shortcut
|
]}
|
||||||
label={t("labels.pasteStyles")}
|
isOr={true}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+V")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.cut")}
|
||||||
label={t("labels.delete")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+X")]}
|
||||||
shortcuts={[getShortcutKey("Del")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.copy")}
|
||||||
label={t("labels.sendToBack")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+C")]}
|
||||||
shortcuts={[
|
/>
|
||||||
isDarwin
|
<Shortcut
|
||||||
? getShortcutKey("CtrlOrCmd+Alt+[")
|
label={t("labels.paste")}
|
||||||
: getShortcutKey("CtrlOrCmd+Shift+["),
|
shortcuts={[getShortcutKey("CtrlOrCmd+V")]}
|
||||||
]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.pasteAsPlaintext")}
|
||||||
label={t("labels.bringToFront")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+V")]}
|
||||||
shortcuts={[
|
/>
|
||||||
isDarwin
|
<Shortcut
|
||||||
? getShortcutKey("CtrlOrCmd+Alt+]")
|
label={t("labels.copyAsPng")}
|
||||||
: getShortcutKey("CtrlOrCmd+Shift+]"),
|
shortcuts={[getShortcutKey("Shift+Alt+C")]}
|
||||||
]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.copyStyles")}
|
||||||
label={t("labels.sendBackward")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+C")]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+[")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.pasteStyles")}
|
||||||
label={t("labels.bringForward")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Alt+V")]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+]")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.delete")}
|
||||||
label={t("labels.alignTop")}
|
shortcuts={[getShortcutKey("Delete")]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Up")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.sendToBack")}
|
||||||
label={t("labels.alignBottom")}
|
shortcuts={[
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Down")]}
|
isDarwin
|
||||||
/>
|
? getShortcutKey("CtrlOrCmd+Alt+[")
|
||||||
<Shortcut
|
: getShortcutKey("CtrlOrCmd+Shift+["),
|
||||||
label={t("labels.alignLeft")}
|
]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Left")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.bringToFront")}
|
||||||
label={t("labels.alignRight")}
|
shortcuts={[
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Right")]}
|
isDarwin
|
||||||
/>
|
? getShortcutKey("CtrlOrCmd+Alt+]")
|
||||||
<Shortcut
|
: getShortcutKey("CtrlOrCmd+Shift+]"),
|
||||||
label={t("labels.duplicateSelection")}
|
]}
|
||||||
shortcuts={[
|
/>
|
||||||
getShortcutKey("CtrlOrCmd+D"),
|
<Shortcut
|
||||||
getShortcutKey(`Alt+${t("helpDialog.drag")}`),
|
label={t("labels.sendBackward")}
|
||||||
]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+[")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("helpDialog.toggleElementLock")}
|
label={t("labels.bringForward")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+L")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+]")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("buttons.undo")}
|
label={t("labels.alignTop")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Z")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Up")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("buttons.redo")}
|
label={t("labels.alignBottom")}
|
||||||
shortcuts={
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Down")]}
|
||||||
isWindows
|
/>
|
||||||
? [
|
<Shortcut
|
||||||
getShortcutKey("CtrlOrCmd+Y"),
|
label={t("labels.alignLeft")}
|
||||||
getShortcutKey("CtrlOrCmd+Shift+Z"),
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Left")]}
|
||||||
]
|
/>
|
||||||
: [getShortcutKey("CtrlOrCmd+Shift+Z")]
|
<Shortcut
|
||||||
}
|
label={t("labels.alignRight")}
|
||||||
/>
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+Right")]}
|
||||||
<Shortcut
|
/>
|
||||||
label={t("labels.group")}
|
<Shortcut
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+G")]}
|
label={t("labels.duplicateSelection")}
|
||||||
/>
|
shortcuts={[
|
||||||
<Shortcut
|
getShortcutKey("CtrlOrCmd+D"),
|
||||||
label={t("labels.ungroup")}
|
getShortcutKey(`Alt+${t("helpDialog.drag")}`),
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+G")]}
|
]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.flipHorizontal")}
|
label={t("helpDialog.toggleElementLock")}
|
||||||
shortcuts={[getShortcutKey("Shift+H")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+L")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.flipVertical")}
|
label={t("buttons.undo")}
|
||||||
shortcuts={[getShortcutKey("Shift+V")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd+Z")]}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("labels.showStroke")}
|
label={t("buttons.redo")}
|
||||||
shortcuts={[getShortcutKey("S")]}
|
shortcuts={
|
||||||
/>
|
isWindows
|
||||||
<Shortcut
|
? [
|
||||||
label={t("labels.showBackground")}
|
getShortcutKey("CtrlOrCmd+Y"),
|
||||||
shortcuts={[getShortcutKey("G")]}
|
getShortcutKey("CtrlOrCmd+Shift+Z"),
|
||||||
/>
|
]
|
||||||
<Shortcut
|
: [getShortcutKey("CtrlOrCmd+Shift+Z")]
|
||||||
label={t("labels.decreaseFontSize")}
|
}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+<")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
<Shortcut
|
label={t("labels.group")}
|
||||||
label={t("labels.increaseFontSize")}
|
shortcuts={[getShortcutKey("CtrlOrCmd+G")]}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+>")]}
|
/>
|
||||||
/>
|
<Shortcut
|
||||||
</ShortcutIsland>
|
label={t("labels.ungroup")}
|
||||||
</Column>
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+G")]}
|
||||||
</Columns>
|
/>
|
||||||
|
<Shortcut
|
||||||
|
label={t("labels.flipHorizontal")}
|
||||||
|
shortcuts={[getShortcutKey("Shift+H")]}
|
||||||
|
/>
|
||||||
|
<Shortcut
|
||||||
|
label={t("labels.flipVertical")}
|
||||||
|
shortcuts={[getShortcutKey("Shift+V")]}
|
||||||
|
/>
|
||||||
|
<Shortcut
|
||||||
|
label={t("labels.showStroke")}
|
||||||
|
shortcuts={[getShortcutKey("S")]}
|
||||||
|
/>
|
||||||
|
<Shortcut
|
||||||
|
label={t("labels.showBackground")}
|
||||||
|
shortcuts={[getShortcutKey("G")]}
|
||||||
|
/>
|
||||||
|
<Shortcut
|
||||||
|
label={t("labels.decreaseFontSize")}
|
||||||
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+<")]}
|
||||||
|
/>
|
||||||
|
<Shortcut
|
||||||
|
label={t("labels.increaseFontSize")}
|
||||||
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+>")]}
|
||||||
|
/>
|
||||||
|
</ShortcutIsland>
|
||||||
</Section>
|
</Section>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
|
@@ -14,20 +14,24 @@ $wide-viewport-width: 1000px;
|
|||||||
top: 100%;
|
top: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 6px;
|
margin-top: 0.5rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: $oc-gray-6;
|
color: var(--color-gray-40);
|
||||||
font-size: 0.8rem;
|
font-size: 0.75rem;
|
||||||
|
|
||||||
@include isMobile {
|
@include isMobile {
|
||||||
position: static;
|
position: static;
|
||||||
padding-right: 2em;
|
padding-right: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
> span {
|
> span {
|
||||||
padding: 0.2rem 0.4rem;
|
padding: 0.25rem;
|
||||||
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 } from "../types";
|
import { AppState, Device } from "../types";
|
||||||
import {
|
import {
|
||||||
isImageElement,
|
isImageElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
@@ -17,13 +17,19 @@ interface HintViewerProps {
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
|
device: Device;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getHints = ({ appState, elements, isMobile }: HintViewerProps) => {
|
const getHints = ({
|
||||||
|
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.isLibraryOpen) {
|
if (appState.openSidebar === "library" && !device.canDeviceFitSidebar) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,11 +117,13 @@ 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,7 +10,8 @@
|
|||||||
.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);
|
||||||
box-shadow: transparentize($oc-black, 0.75) 0 1px 4px;
|
// ˇˇ yeah, i dunno, open to suggestions here :D
|
||||||
|
box-shadow: rgb(0 0 0 / 25%) 2px 2px 4px 2px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,6 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
width: 36px;
|
width: 36px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
opacity: 0.6;
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ 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,
|
||||||
@@ -102,7 +103,9 @@ 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="picker-option"
|
className={clsx("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);
|
||||||
@@ -150,7 +153,7 @@ export function IconPicker<T>({
|
|||||||
const isRTL = getLanguage().rtl;
|
const isRTL = getLanguage().rtl;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label className={"picker-container"}>
|
<div>
|
||||||
<button
|
<button
|
||||||
name={group}
|
name={group}
|
||||||
className={isActive ? "active" : ""}
|
className={isActive ? "active" : ""}
|
||||||
@@ -184,6 +187,6 @@ export function IconPicker<T>({
|
|||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</label>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { render, unmountComponentAtNode } from "react-dom";
|
|
||||||
import { probablySupportsClipboardBlob } from "../clipboard";
|
import { probablySupportsClipboardBlob } from "../clipboard";
|
||||||
import { canvasToBlob } from "../data/blob";
|
import { canvasToBlob } from "../data/blob";
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
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, exportImage } from "./icons";
|
import { clipboard } 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";
|
||||||
@@ -35,19 +31,6 @@ export const ErrorCanvasPreview = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderPreview = (
|
|
||||||
content: HTMLCanvasElement | Error,
|
|
||||||
previewNode: HTMLDivElement,
|
|
||||||
) => {
|
|
||||||
unmountComponentAtNode(previewNode);
|
|
||||||
previewNode.innerHTML = "";
|
|
||||||
if (content instanceof HTMLCanvasElement) {
|
|
||||||
previewNode.appendChild(content);
|
|
||||||
} else {
|
|
||||||
render(<ErrorCanvasPreview />, previewNode);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ExportCB = (
|
export type ExportCB = (
|
||||||
elements: readonly NonDeletedExcalidrawElement[],
|
elements: readonly NonDeletedExcalidrawElement[],
|
||||||
scale?: number,
|
scale?: number,
|
||||||
@@ -101,6 +84,7 @@ const ImageExportModal = ({
|
|||||||
const [exportSelected, setExportSelected] = useState(someElementIsSelected);
|
const [exportSelected, setExportSelected] = useState(someElementIsSelected);
|
||||||
const previewRef = useRef<HTMLDivElement>(null);
|
const previewRef = useRef<HTMLDivElement>(null);
|
||||||
const { exportBackground, viewBackgroundColor } = appState;
|
const { exportBackground, viewBackgroundColor } = appState;
|
||||||
|
const [renderError, setRenderError] = useState<Error | null>(null);
|
||||||
|
|
||||||
const exportedElements = exportSelected
|
const exportedElements = exportSelected
|
||||||
? getSelectedElements(elements, appState, true)
|
? getSelectedElements(elements, appState, true)
|
||||||
@@ -121,15 +105,16 @@ const ImageExportModal = ({
|
|||||||
exportPadding,
|
exportPadding,
|
||||||
})
|
})
|
||||||
.then((canvas) => {
|
.then((canvas) => {
|
||||||
|
setRenderError(null);
|
||||||
// if converting to blob fails, there's some problem that will
|
// if converting to blob fails, there's some problem that will
|
||||||
// likely prevent preview and export (e.g. canvas too big)
|
// likely prevent preview and export (e.g. canvas too big)
|
||||||
return canvasToBlob(canvas).then(() => {
|
return canvasToBlob(canvas).then(() => {
|
||||||
renderPreview(canvas, previewNode);
|
previewNode.replaceChildren(canvas);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
renderPreview(new CanvasError(), previewNode);
|
setRenderError(error);
|
||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
appState,
|
appState,
|
||||||
@@ -142,7 +127,9 @@ const ImageExportModal = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ExportDialog">
|
<div className="ExportDialog">
|
||||||
<div className="ExportDialog__preview" ref={previewRef} />
|
<div className="ExportDialog__preview" ref={previewRef}>
|
||||||
|
{renderError && <ErrorCanvasPreview />}
|
||||||
|
</div>
|
||||||
{supportsContextFilters &&
|
{supportsContextFilters &&
|
||||||
actionManager.renderAction("exportWithDarkMode")}
|
actionManager.renderAction("exportWithDarkMode")}
|
||||||
<div style={{ display: "grid", gridTemplateColumns: "1fr" }}>
|
<div style={{ display: "grid", gridTemplateColumns: "1fr" }}>
|
||||||
@@ -221,6 +208,7 @@ const ImageExportModal = ({
|
|||||||
export const ImageExportDialog = ({
|
export const ImageExportDialog = ({
|
||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
|
setAppState,
|
||||||
files,
|
files,
|
||||||
exportPadding = DEFAULT_EXPORT_PADDING,
|
exportPadding = DEFAULT_EXPORT_PADDING,
|
||||||
actionManager,
|
actionManager,
|
||||||
@@ -229,6 +217,7 @@ export const ImageExportDialog = ({
|
|||||||
onExportToClipboard,
|
onExportToClipboard,
|
||||||
}: {
|
}: {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
files: BinaryFiles;
|
files: BinaryFiles;
|
||||||
exportPadding?: number;
|
exportPadding?: number;
|
||||||
@@ -237,26 +226,13 @@ export const ImageExportDialog = ({
|
|||||||
onExportToSvg: ExportCB;
|
onExportToSvg: ExportCB;
|
||||||
onExportToClipboard: ExportCB;
|
onExportToClipboard: ExportCB;
|
||||||
}) => {
|
}) => {
|
||||||
const [modalIsShown, setModalIsShown] = useState(false);
|
|
||||||
|
|
||||||
const handleClose = React.useCallback(() => {
|
const handleClose = React.useCallback(() => {
|
||||||
setModalIsShown(false);
|
setAppState({ openDialog: null });
|
||||||
}, []);
|
}, [setAppState]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ToolButton
|
{appState.openDialog === "imageExport" && (
|
||||||
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}
|
||||||
|
@@ -2,10 +2,12 @@ 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) => {
|
||||||
@@ -21,5 +23,5 @@ export const InitializeApp = (props: Props) => {
|
|||||||
updateLang();
|
updateLang();
|
||||||
}, [props.langCode]);
|
}, [props.langCode]);
|
||||||
|
|
||||||
return loading ? <LoadingMessage /> : props.children;
|
return loading ? <LoadingMessage theme={props.theme} /> : props.children;
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
.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 { exportFile, exportToFileIcon, link } from "./icons";
|
import { ExportIcon, exportToFileIcon, LinkIcon } 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,6 +14,7 @@ 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[],
|
||||||
@@ -63,7 +64,7 @@ const JSONExportModal = ({
|
|||||||
)}
|
)}
|
||||||
{onExportToBackend && (
|
{onExportToBackend && (
|
||||||
<Card color="pink">
|
<Card color="pink">
|
||||||
<div className="Card-icon">{link}</div>
|
<div className="Card-icon">{LinkIcon}</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
|
||||||
@@ -109,16 +110,13 @@ export const JSONExportDialog = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ToolButton
|
<MenuItem
|
||||||
|
icon={ExportIcon}
|
||||||
|
label={t("buttons.export")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setModalIsShown(true);
|
setModalIsShown(true);
|
||||||
}}
|
}}
|
||||||
data-testid="json-export-button"
|
dataTestId="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,48 +1,6 @@
|
|||||||
@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;
|
||||||
@@ -58,8 +16,10 @@
|
|||||||
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 {
|
||||||
@@ -90,13 +50,6 @@
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@@ -132,6 +85,10 @@
|
|||||||
& > * {
|
& > * {
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
.layer-ui__wrapper__footer-left,
|
.layer-ui__wrapper__footer-left,
|
||||||
.layer-ui__wrapper__footer-right,
|
.layer-ui__wrapper__footer-right,
|
||||||
@@ -139,14 +96,9 @@
|
|||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,22 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React, { useCallback } from "react";
|
import React 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, getSelectedElements } from "../scene";
|
import { calculateScrollCenter } from "../scene";
|
||||||
import { ExportType } from "../scene/types";
|
import { ExportType } from "../scene/types";
|
||||||
import { AppProps, AppState, ExcalidrawProps, BinaryFiles } from "../types";
|
import {
|
||||||
import { muteFSAbortError } from "../utils";
|
AppProps,
|
||||||
|
AppState,
|
||||||
|
ExcalidrawProps,
|
||||||
|
BinaryFiles,
|
||||||
|
UIChildrenComponents,
|
||||||
|
} from "../types";
|
||||||
|
import { muteFSAbortError, ReactChildrenToObject } from "../utils";
|
||||||
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
import { SelectedShapeActions, ShapesSwitcher } 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";
|
||||||
@@ -26,7 +31,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, { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
import Library 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";
|
||||||
@@ -36,10 +41,26 @@ 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 { useDevice } from "../components/App";
|
import { isMenuOpenAtom, 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 Footer from "./footer/Footer";
|
||||||
|
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;
|
||||||
@@ -53,19 +74,21 @@ 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"];
|
|
||||||
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;
|
||||||
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LayerUI = ({
|
const LayerUI = ({
|
||||||
actionManager,
|
actionManager,
|
||||||
appState,
|
appState,
|
||||||
@@ -78,20 +101,25 @@ const LayerUI = ({
|
|||||||
onPenModeToggle,
|
onPenModeToggle,
|
||||||
onInsertElements,
|
onInsertElements,
|
||||||
showExitZenModeBtn,
|
showExitZenModeBtn,
|
||||||
showThemeBtn,
|
|
||||||
isCollaborating,
|
isCollaborating,
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomFooter,
|
|
||||||
renderCustomStats,
|
renderCustomStats,
|
||||||
|
renderCustomSidebar,
|
||||||
libraryReturnUrl,
|
libraryReturnUrl,
|
||||||
UIOptions,
|
UIOptions,
|
||||||
focusContainer,
|
focusContainer,
|
||||||
library,
|
library,
|
||||||
id,
|
id,
|
||||||
onImageAction,
|
onImageAction,
|
||||||
|
renderWelcomeScreen,
|
||||||
|
children,
|
||||||
}: LayerUIProps) => {
|
}: LayerUIProps) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
|
|
||||||
|
const childrenComponents =
|
||||||
|
ReactChildrenToObject<UIChildrenComponents>(children);
|
||||||
|
|
||||||
const renderJSONExportDialog = () => {
|
const renderJSONExportDialog = () => {
|
||||||
if (!UIOptions.canvasActions.export) {
|
if (!UIOptions.canvasActions.export) {
|
||||||
return null;
|
return null;
|
||||||
@@ -148,6 +176,7 @@ 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")}
|
||||||
@@ -157,76 +186,107 @@ const LayerUI = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Separator = () => {
|
const [isMenuOpen, setIsMenuOpen] = useAtom(isMenuOpenAtom);
|
||||||
return <div style={{ width: ".625em" }} />;
|
const menuRef = useOutsideClickHook(() => setIsMenuOpen(false));
|
||||||
};
|
|
||||||
|
|
||||||
const renderViewModeCanvasActions = () => {
|
|
||||||
return (
|
|
||||||
<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">
|
|
||||||
{renderJSONExportDialog()}
|
|
||||||
{renderImageExportDialog()}
|
|
||||||
</Stack.Row>
|
|
||||||
</Stack.Col>
|
|
||||||
</Island>
|
|
||||||
</Section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderCanvasActions = () => (
|
const renderCanvasActions = () => (
|
||||||
<Section
|
<div style={{ position: "relative" }}>
|
||||||
heading="canvasActions"
|
<WelcomeScreenDecor
|
||||||
className={clsx("zen-mode-transition", {
|
shouldRender={renderWelcomeScreen && !appState.isLoading}
|
||||||
"transition-left": appState.zenModeEnabled,
|
>
|
||||||
})}
|
<div className="virgil WelcomeScreen-decor WelcomeScreen-decor--menu-pointer">
|
||||||
>
|
{WelcomeScreenMenuArrow}
|
||||||
{/* the zIndex ensures this menu has higher stacking order,
|
<div>{t("welcomeScreen.menuHints")}</div>
|
||||||
|
</div>
|
||||||
|
</WelcomeScreenDecor>
|
||||||
|
|
||||||
|
<button
|
||||||
|
data-prevent-outside-click
|
||||||
|
className={clsx("menu-button", "zen-mode-transition", {
|
||||||
|
"transition-left": appState.zenModeEnabled,
|
||||||
|
})}
|
||||||
|
onClick={() => setIsMenuOpen(!isMenuOpen)}
|
||||||
|
type="button"
|
||||||
|
data-testid="menu-button"
|
||||||
|
>
|
||||||
|
{HamburgerMenuIcon}
|
||||||
|
</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 padding={2} style={{ zIndex: 1 }}>
|
<Island
|
||||||
<Stack.Col gap={4}>
|
className="menu-container"
|
||||||
<Stack.Row gap={1} justifyContent="space-between">
|
padding={2}
|
||||||
{actionManager.renderAction("clearCanvas")}
|
style={{ zIndex: 1 }}
|
||||||
<Separator />
|
>
|
||||||
{actionManager.renderAction("loadScene")}
|
{!appState.viewModeEnabled &&
|
||||||
{renderJSONExportDialog()}
|
actionManager.renderAction("loadScene")}
|
||||||
{renderImageExportDialog()}
|
{/* // TODO barnabasmolnar/editor-redesign */}
|
||||||
<Separator />
|
{/* is this fine here? */}
|
||||||
{onCollabButtonClick && (
|
{appState.fileHandle &&
|
||||||
<CollabButton
|
actionManager.renderAction("saveToActiveFile")}
|
||||||
isCollaborating={isCollaborating}
|
{renderJSONExportDialog()}
|
||||||
collaboratorCount={appState.collaborators.size}
|
{UIOptions.canvasActions.saveAsImage && (
|
||||||
onClick={onCollabButtonClick}
|
<MenuItem
|
||||||
/>
|
label={t("buttons.exportImage")}
|
||||||
)}
|
icon={ExportImageIcon}
|
||||||
</Stack.Row>
|
dataTestId="image-export-button"
|
||||||
<BackgroundPickerAndDarkModeToggle
|
onClick={() => setAppState({ openDialog: "imageExport" })}
|
||||||
appState={appState}
|
shortcut={getShortcutFromShortcutName("imageExport")}
|
||||||
actionManager={actionManager}
|
/>
|
||||||
setAppState={setAppState}
|
)}
|
||||||
showThemeBtn={showThemeBtn}
|
{onCollabButtonClick && (
|
||||||
/>
|
<CollabButton
|
||||||
{appState.fileHandle && (
|
isCollaborating={isCollaborating}
|
||||||
<>{actionManager.renderAction("saveToActiveFile")}</>
|
collaboratorCount={appState.collaborators.size}
|
||||||
)}
|
onClick={onCollabButtonClick}
|
||||||
</Stack.Col>
|
/>
|
||||||
</Island>
|
)}
|
||||||
</Section>
|
{actionManager.renderAction("toggleShortcuts", undefined, true)}
|
||||||
|
{!appState.viewModeEnabled &&
|
||||||
|
actionManager.renderAction("clearCanvas")}
|
||||||
|
<Separator />
|
||||||
|
<MenuLinks />
|
||||||
|
<Separator />
|
||||||
|
<div
|
||||||
|
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("zen-mode-transition", {
|
className={clsx("selected-shape-actions zen-mode-transition", {
|
||||||
"transition-left": appState.zenModeEnabled,
|
"transition-left": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
@@ -234,10 +294,9 @@ 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 200
|
// we want to make sure this doesn't overflow so subtracting the
|
||||||
// which is approximately height of zoom footer and top left menu items with some buffer
|
// approximate height of hamburgerMenu + footer
|
||||||
// if active file name is displayed, subtracting 248 to account for its height
|
maxHeight: `${appState.height - 166}px`,
|
||||||
maxHeight: `${appState.height - (appState.fileHandle ? 248 : 200)}px`,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SelectedShapeActions
|
<SelectedShapeActions
|
||||||
@@ -249,41 +308,6 @@ const LayerUI = ({
|
|||||||
</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}
|
|
||||||
files={files}
|
|
||||||
id={id}
|
|
||||||
appState={appState}
|
|
||||||
/>
|
|
||||||
) : null;
|
|
||||||
|
|
||||||
const renderFixedSideContainer = () => {
|
const renderFixedSideContainer = () => {
|
||||||
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
||||||
appState,
|
appState,
|
||||||
@@ -292,73 +316,89 @@ 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={4}
|
gap={6}
|
||||||
className={clsx({
|
className={clsx("App-menu_top__left", {
|
||||||
"disable-pointerEvents": appState.zenModeEnabled,
|
"disable-pointerEvents": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{appState.viewModeEnabled
|
{renderCanvasActions()}
|
||||||
? renderViewModeCanvasActions()
|
|
||||||
: renderCanvasActions()}
|
|
||||||
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
{!appState.viewModeEnabled && (
|
{!appState.viewModeEnabled && (
|
||||||
<Section heading="shapes">
|
<Section heading="shapes" className="shapes-section">
|
||||||
{(heading: React.ReactNode) => (
|
{(heading: React.ReactNode) => (
|
||||||
<Stack.Col gap={4} align="start">
|
<div style={{ position: "relative" }}>
|
||||||
<Stack.Row
|
<WelcomeScreenDecor
|
||||||
gap={1}
|
shouldRender={renderWelcomeScreen && !appState.isLoading}
|
||||||
className={clsx("App-toolbar-container", {
|
|
||||||
"zen-mode": appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
<PenModeButton
|
<div className="virgil WelcomeScreen-decor WelcomeScreen-decor--top-toolbar-pointer">
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
<div className="WelcomeScreen-decor--top-toolbar-pointer__label">
|
||||||
checked={appState.penMode}
|
{t("welcomeScreen.toolbarHints")}
|
||||||
onChange={onPenModeToggle}
|
</div>
|
||||||
title={t("toolBar.penMode")}
|
{WelcomeScreenTopToolbarArrow}
|
||||||
penDetected={appState.penDetected}
|
</div>
|
||||||
/>
|
</WelcomeScreenDecor>
|
||||||
<LockButton
|
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
<Stack.Col gap={4} align="start">
|
||||||
checked={appState.activeTool.locked}
|
<Stack.Row
|
||||||
onChange={() => onLockToggle()}
|
gap={1}
|
||||||
title={t("toolBar.lock")}
|
className={clsx("App-toolbar-container", {
|
||||||
/>
|
|
||||||
<Island
|
|
||||||
padding={1}
|
|
||||||
className={clsx("App-toolbar", {
|
|
||||||
"zen-mode": appState.zenModeEnabled,
|
"zen-mode": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<HintViewer
|
<Island
|
||||||
appState={appState}
|
padding={1}
|
||||||
elements={elements}
|
className={clsx("App-toolbar", {
|
||||||
isMobile={device.isMobile}
|
"zen-mode": appState.zenModeEnabled,
|
||||||
/>
|
})}
|
||||||
{heading}
|
>
|
||||||
<Stack.Row gap={1}>
|
<HintViewer
|
||||||
<ShapesSwitcher
|
|
||||||
appState={appState}
|
appState={appState}
|
||||||
canvas={canvas}
|
elements={elements}
|
||||||
activeTool={appState.activeTool}
|
isMobile={device.isMobile}
|
||||||
setAppState={setAppState}
|
device={device}
|
||||||
onImageAction={({ pointerType }) => {
|
|
||||||
onImageAction({
|
|
||||||
insertOnCanvasDirectly: pointerType !== "mouse",
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Stack.Row>
|
{heading}
|
||||||
</Island>
|
<Stack.Row gap={1}>
|
||||||
<LibraryButton
|
<PenModeButton
|
||||||
appState={appState}
|
zenModeEnabled={appState.zenModeEnabled}
|
||||||
setAppState={setAppState}
|
checked={appState.penMode}
|
||||||
/>
|
onChange={onPenModeToggle}
|
||||||
</Stack.Row>
|
title={t("toolBar.penMode")}
|
||||||
</Stack.Col>
|
penDetected={appState.penDetected}
|
||||||
|
/>
|
||||||
|
<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>
|
||||||
)}
|
)}
|
||||||
@@ -374,13 +414,41 @@ 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 = () => {
|
||||||
|
return appState.openSidebar === "customSidebar" ? (
|
||||||
|
renderCustomSidebar?.() || null
|
||||||
|
) : appState.openSidebar === "library" ? (
|
||||||
|
<LibraryMenu
|
||||||
|
appState={appState}
|
||||||
|
onInsertElements={onInsertElements}
|
||||||
|
libraryReturnUrl={libraryReturnUrl}
|
||||||
|
focusContainer={focusContainer}
|
||||||
|
library={library}
|
||||||
|
id={id}
|
||||||
|
/>
|
||||||
|
) : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const [hostSidebarCounters] = useAtom(hostSidebarCountersAtom, jotaiScope);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{appState.isLoading && <LoadingMessage delay={250} />}
|
{appState.isLoading && <LoadingMessage delay={250} />}
|
||||||
@@ -390,13 +458,14 @@ const LayerUI = ({
|
|||||||
onClose={() => setAppState({ errorMessage: null })}
|
onClose={() => setAppState({ errorMessage: null })}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{appState.showHelpDialog && (
|
{appState.openDialog === "help" && (
|
||||||
<HelpDialog
|
<HelpDialog
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setAppState({ showHelpDialog: false });
|
setAppState({ openDialog: null });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{renderImageExportDialog()}
|
||||||
{appState.pasteDialog.shown && (
|
{appState.pasteDialog.shown && (
|
||||||
<PasteChartDialog
|
<PasteChartDialog
|
||||||
setAppState={setAppState}
|
setAppState={setAppState}
|
||||||
@@ -411,10 +480,10 @@ const LayerUI = ({
|
|||||||
)}
|
)}
|
||||||
{device.isMobile && (
|
{device.isMobile && (
|
||||||
<MobileMenu
|
<MobileMenu
|
||||||
|
renderWelcomeScreen={renderWelcomeScreen}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
elements={elements}
|
elements={elements}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
libraryMenu={libraryMenu}
|
|
||||||
renderJSONExportDialog={renderJSONExportDialog}
|
renderJSONExportDialog={renderJSONExportDialog}
|
||||||
renderImageExportDialog={renderImageExportDialog}
|
renderImageExportDialog={renderImageExportDialog}
|
||||||
setAppState={setAppState}
|
setAppState={setAppState}
|
||||||
@@ -423,11 +492,11 @@ const LayerUI = ({
|
|||||||
onPenModeToggle={onPenModeToggle}
|
onPenModeToggle={onPenModeToggle}
|
||||||
canvas={canvas}
|
canvas={canvas}
|
||||||
isCollaborating={isCollaborating}
|
isCollaborating={isCollaborating}
|
||||||
renderCustomFooter={renderCustomFooter}
|
|
||||||
showThemeBtn={showThemeBtn}
|
|
||||||
onImageAction={onImageAction}
|
onImageAction={onImageAction}
|
||||||
renderTopRightUI={renderTopRightUI}
|
renderTopRightUI={renderTopRightUI}
|
||||||
renderCustomStats={renderCustomStats}
|
renderCustomStats={renderCustomStats}
|
||||||
|
renderSidebars={renderSidebars}
|
||||||
|
device={device}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -442,8 +511,9 @@ const LayerUI = ({
|
|||||||
!isTextElement(appState.editingElement)),
|
!isTextElement(appState.editingElement)),
|
||||||
})}
|
})}
|
||||||
style={
|
style={
|
||||||
appState.isLibraryOpen &&
|
((appState.openSidebar === "library" &&
|
||||||
appState.isLibraryMenuDocked &&
|
appState.isSidebarDocked) ||
|
||||||
|
hostSidebarCounters.docked) &&
|
||||||
device.canDeviceFitSidebar
|
device.canDeviceFitSidebar
|
||||||
? { width: `calc(100% - ${LIBRARY_SIDEBAR_WIDTH}px)` }
|
? { width: `calc(100% - ${LIBRARY_SIDEBAR_WIDTH}px)` }
|
||||||
: {}
|
: {}
|
||||||
@@ -451,11 +521,14 @@ const LayerUI = ({
|
|||||||
>
|
>
|
||||||
{renderFixedSideContainer()}
|
{renderFixedSideContainer()}
|
||||||
<Footer
|
<Footer
|
||||||
|
renderWelcomeScreen={renderWelcomeScreen}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
renderCustomFooter={renderCustomFooter}
|
|
||||||
showExitZenModeBtn={showExitZenModeBtn}
|
showExitZenModeBtn={showExitZenModeBtn}
|
||||||
/>
|
>
|
||||||
|
{childrenComponents.FooterCenter}
|
||||||
|
</Footer>
|
||||||
|
|
||||||
{appState.showStats && (
|
{appState.showStats && (
|
||||||
<Stats
|
<Stats
|
||||||
appState={appState}
|
appState={appState}
|
||||||
@@ -480,9 +553,7 @@ const LayerUI = ({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{appState.isLibraryOpen && (
|
{renderSidebars()}
|
||||||
<div className="layer-ui__sidebar">{libraryMenu}</div>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
@@ -502,8 +573,11 @@ 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.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 &&
|
||||||
|
32
src/components/LibraryButton.scss
Normal file
32
src/components/LibraryButton.scss
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
@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,19 +1,11 @@
|
|||||||
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";
|
||||||
const LIBRARY_ICON = (
|
import { LibraryIcon } from "./icons";
|
||||||
<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;
|
||||||
@@ -21,17 +13,16 @@ 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
|
<label title={`${capitalizeString(t("toolBar.library"))}`}>
|
||||||
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"
|
||||||
@@ -40,10 +31,10 @@ export const LibraryButton: React.FC<{
|
|||||||
document
|
document
|
||||||
.querySelector(".layer-ui__wrapper")
|
.querySelector(".layer-ui__wrapper")
|
||||||
?.classList.remove("animate");
|
?.classList.remove("animate");
|
||||||
const nextState = event.target.checked;
|
const isOpen = event.target.checked;
|
||||||
setAppState({ isLibraryOpen: nextState });
|
setAppState({ openSidebar: isOpen ? "library" : null });
|
||||||
// track only openings
|
// track only openings
|
||||||
if (nextState) {
|
if (isOpen) {
|
||||||
trackEvent(
|
trackEvent(
|
||||||
"library",
|
"library",
|
||||||
"toggleLibrary (open)",
|
"toggleLibrary (open)",
|
||||||
@@ -51,11 +42,16 @@ export const LibraryButton: React.FC<{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
checked={appState.isLibraryOpen}
|
checked={appState.openSidebar === "library"}
|
||||||
aria-label={capitalizeString(t("toolBar.library"))}
|
aria-label={capitalizeString(t("toolBar.library"))}
|
||||||
aria-keyshortcuts="0"
|
aria-keyshortcuts="0"
|
||||||
/>
|
/>
|
||||||
<div className="ToolIcon__icon">{LIBRARY_ICON}</div>
|
<div className="library-button">
|
||||||
|
<div>{LibraryIcon}</div>
|
||||||
|
{showLabel && (
|
||||||
|
<div className="library-button__label">{t("toolBar.library")}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -1,10 +1,16 @@
|
|||||||
@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;
|
||||||
align-items: center;
|
flex-direction: column;
|
||||||
justify-content: center;
|
|
||||||
|
flex: 1 1 auto;
|
||||||
|
|
||||||
.layer-ui__library-header {
|
.layer-ui__library-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -23,25 +29,38 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.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: 2em 4em;
|
padding: 2rem;
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
.Spinner {
|
flex-grow: 1;
|
||||||
margin-bottom: 1em;
|
justify-content: center;
|
||||||
}
|
|
||||||
span {
|
span {
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
@@ -69,11 +88,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.library-menu-browse-button {
|
.library-menu-browse-button {
|
||||||
width: 80%;
|
margin: 1rem auto;
|
||||||
min-height: 22px;
|
|
||||||
margin: 0 auto;
|
padding: 0.875rem 1rem;
|
||||||
margin-top: 1rem;
|
|
||||||
padding: 10px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -86,6 +104,10 @@
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@@ -94,6 +116,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.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;
|
||||||
|
@@ -6,20 +6,13 @@ import {
|
|||||||
RefObject,
|
RefObject,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
} from "react";
|
} from "react";
|
||||||
import Library, { libraryItemsAtom } from "../data/library";
|
import Library, {
|
||||||
|
distributeLibraryItemsOnSquareGrid,
|
||||||
|
libraryItemsAtom,
|
||||||
|
} from "../data/library";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { randomId } from "../random";
|
import { randomId } from "../random";
|
||||||
import {
|
import { LibraryItems, LibraryItem, AppState, ExcalidrawProps } from "../types";
|
||||||
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";
|
||||||
@@ -29,7 +22,16 @@ 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 { useDevice } from "./App";
|
import {
|
||||||
|
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>,
|
||||||
@@ -59,110 +61,42 @@ 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 (
|
||||||
<Island padding={1} ref={ref} className="layer-ui__library">
|
<div ref={ref} className="layer-ui__library">
|
||||||
{children}
|
{children}
|
||||||
</Island>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const LibraryMenu = ({
|
export const LibraryMenuContent = ({
|
||||||
onClose,
|
|
||||||
onInsertLibraryItems,
|
onInsertLibraryItems,
|
||||||
pendingElements,
|
pendingElements,
|
||||||
onAddToLibrary,
|
onAddToLibrary,
|
||||||
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;
|
||||||
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 so that LibraryButton
|
|
||||||
// can toggle library menu
|
|
||||||
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");
|
||||||
@@ -188,114 +122,188 @@ export const LibraryMenu = ({
|
|||||||
[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 ref={ref}>
|
<LibraryMenuWrapper>
|
||||||
<div className="layer-ui__library-message">
|
<div className="layer-ui__library-message">
|
||||||
<Spinner size="2em" />
|
<div>
|
||||||
<span>{t("labels.libraryLoadingMessage")}</span>
|
<Spinner size="2em" />
|
||||||
|
<span>{t("labels.libraryLoadingMessage")}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</LibraryMenuWrapper>
|
</LibraryMenuWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showBtn =
|
||||||
|
libraryItemsData.libraryItems.length > 0 || pendingElements.length > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LibraryMenuWrapper ref={ref}>
|
<LibraryMenuWrapper>
|
||||||
{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}
|
||||||
setAppState={setAppState}
|
|
||||||
appState={appState}
|
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
|
||||||
library={library}
|
|
||||||
theme={appState.theme}
|
|
||||||
files={files}
|
|
||||||
id={id}
|
|
||||||
selectedItems={selectedItems}
|
selectedItems={selectedItems}
|
||||||
onSelectItems={(ids) => setSelectedItems(ids)}
|
onSelectItems={onSelectItems}
|
||||||
onPublish={() => setShowPublishLibraryDialog(true)}
|
id={id}
|
||||||
resetLibrary={resetLibrary}
|
libraryReturnUrl={libraryReturnUrl}
|
||||||
|
theme={appState.theme}
|
||||||
/>
|
/>
|
||||||
|
{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>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
31
src/components/LibraryMenuBrowseButton.tsx
Normal file
31
src/components/LibraryMenuBrowseButton.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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;
|
257
src/components/LibraryMenuHeaderContent.tsx
Normal file
257
src/components/LibraryMenuHeaderContent.tsx
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
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,107 +1,70 @@
|
|||||||
@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%;
|
||||||
padding: 0.5rem;
|
justify-content: center;
|
||||||
box-sizing: border-box;
|
margin: 0;
|
||||||
|
border-bottom: 1px solid var(--sidebar-border-color);
|
||||||
|
|
||||||
.library-actions {
|
position: relative;
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
margin-right: auto;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
button .library-actions-counter {
|
&__row {
|
||||||
position: absolute;
|
display: grid;
|
||||||
right: 2px;
|
grid-template-columns: repeat(4, 1fr);
|
||||||
bottom: 2px;
|
gap: 1rem;
|
||||||
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,225 +1,43 @@
|
|||||||
import React, { useCallback, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { saveLibraryAsJSON, serializeLibraryAsJSON } from "../data/json";
|
import { 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 {
|
import { AppState, ExcalidrawProps, LibraryItem, LibraryItems } from "../types";
|
||||||
AppState,
|
import { arrayToMap, chunk } from "../utils";
|
||||||
BinaryFiles,
|
|
||||||
ExcalidrawProps,
|
|
||||||
LibraryItem,
|
|
||||||
LibraryItems,
|
|
||||||
} from "../types";
|
|
||||||
import { arrayToMap, chunk, 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, VERSIONS } from "../constants";
|
import { MIME_TYPES } from "../constants";
|
||||||
import Spinner from "./Spinner";
|
import Spinner from "./Spinner";
|
||||||
import { fileOpen } from "../data/filesystem";
|
import LibraryMenuBrowseButton from "./LibraryMenuBrowseButton";
|
||||||
|
import clsx from "clsx";
|
||||||
|
|
||||||
import { SidebarLockButton } from "./SidebarLockButton";
|
const CELLS_PER_ROW = 4;
|
||||||
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,
|
||||||
onPublish,
|
theme,
|
||||||
resetLibrary,
|
id,
|
||||||
|
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;
|
||||||
onPublish: () => void;
|
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
||||||
resetLibrary: () => void;
|
theme: AppState["theme"];
|
||||||
|
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);
|
||||||
@@ -296,7 +114,6 @@ 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}
|
||||||
@@ -358,7 +175,11 @@ const LibraryMenuItems = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Stack.Row align="center" gap={1} key={index}>
|
<Stack.Row
|
||||||
|
align="center"
|
||||||
|
key={index}
|
||||||
|
className="library-menu-items-container__row"
|
||||||
|
>
|
||||||
{rowItems}
|
{rowItems}
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
);
|
);
|
||||||
@@ -372,56 +193,23 @@ const LibraryMenuItems = ({
|
|||||||
(item) => item.status === "published",
|
(item) => item.status === "published",
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderLibraryHeader = () => {
|
const showBtn =
|
||||||
return (
|
!libraryItems.length &&
|
||||||
<>
|
!unpublishedItems.length &&
|
||||||
<div className="layer-ui__library-header" key="library-header">
|
!publishedItems.length &&
|
||||||
{renderLibraryActions()}
|
!pendingElements.length;
|
||||||
{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>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderLibraryMenuItems = () => {
|
return (
|
||||||
return (
|
<div
|
||||||
|
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"
|
||||||
@@ -432,49 +220,37 @@ const LibraryMenuItems = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<div className="separator">
|
<div>
|
||||||
{(pendingElements.length > 0 ||
|
{(pendingElements.length > 0 ||
|
||||||
unpublishedItems.length > 0 ||
|
unpublishedItems.length > 0 ||
|
||||||
publishedItems.length > 0) && (
|
publishedItems.length > 0) && (
|
||||||
<div>{t("labels.personalLib")}</div>
|
<div className="library-menu-items-container__header">
|
||||||
|
{t("labels.personalLib")}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
marginLeft: "auto",
|
position: "absolute",
|
||||||
marginRight: "1rem",
|
top: "var(--container-padding-y)",
|
||||||
display: "flex",
|
right: "var(--container-padding-x)",
|
||||||
alignItems: "center",
|
transform: "translateY(50%)",
|
||||||
fontWeight: "normal",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ transform: "translateY(2px)" }}>
|
<Spinner />
|
||||||
<Spinner />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!pendingElements.length && !unpublishedItems.length ? (
|
{!pendingElements.length && !unpublishedItems.length ? (
|
||||||
<div
|
<div className="library-menu-items__no-items">
|
||||||
style={{
|
|
||||||
height: 65,
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
width: "100%",
|
|
||||||
fontSize: ".9rem",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("library.noItems")}
|
|
||||||
<div
|
<div
|
||||||
style={{
|
className={clsx({
|
||||||
margin: ".6rem 0",
|
"library-menu-items__no-items__label": showBtn,
|
||||||
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")}
|
||||||
@@ -493,9 +269,11 @@ const LibraryMenuItems = ({
|
|||||||
|
|
||||||
<>
|
<>
|
||||||
{(publishedItems.length > 0 ||
|
{(publishedItems.length > 0 ||
|
||||||
(!device.isMobile &&
|
pendingElements.length > 0 ||
|
||||||
(pendingElements.length > 0 || unpublishedItems.length > 0))) && (
|
unpublishedItems.length > 0) && (
|
||||||
<div className="separator">{t("labels.excalidrawLib")}</div>
|
<div className="library-menu-items-container__header library-menu-items-container__header--excal">
|
||||||
|
{t("labels.excalidrawLib")}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
{publishedItems.length > 0 ? (
|
{publishedItems.length > 0 ? (
|
||||||
renderLibrarySection(publishedItems)
|
renderLibrarySection(publishedItems)
|
||||||
@@ -515,42 +293,15 @@ 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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user