mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-08-30 05:37:13 +02:00
Compare commits
28 Commits
v0.13.0
...
aakansha-c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c4b951a0c5 | ||
![]() |
c93d8f4bd0 | ||
![]() |
645f9a5dc0 | ||
![]() |
128b7741c1 | ||
![]() |
1edde7291c | ||
![]() |
1ca56204b1 | ||
![]() |
f3ae7a8506 | ||
![]() |
5f57daa132 | ||
![]() |
db9c9eb3d2 | ||
![]() |
2e8c4d25f2 | ||
![]() |
4953828d86 | ||
![]() |
6eb0cf6a10 | ||
![]() |
ba48aa24a0 | ||
![]() |
4e75f10b2c | ||
![]() |
d2d3599661 | ||
![]() |
ed3eda3401 | ||
![]() |
d27b32dd2c | ||
![]() |
2337842f57 | ||
![]() |
5b78f50fe3 | ||
![]() |
a4a95a591a | ||
![]() |
3d459076fb | ||
![]() |
14a23c6c50 | ||
![]() |
5f4a5b1789 | ||
![]() |
47498796e0 | ||
![]() |
8706277d14 | ||
![]() |
3d0a1106ff | ||
![]() |
61699ff3c2 | ||
![]() |
39d0084a5e |
@@ -1,43 +0,0 @@
|
|||||||
{
|
|
||||||
// These tasks will run in order when initializing your CodeSandbox project.
|
|
||||||
"setupTasks": [
|
|
||||||
{
|
|
||||||
"name": "Install Dependencies",
|
|
||||||
"command": "yarn install"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
// These tasks can be run from CodeSandbox. Running one will open a log in the app.
|
|
||||||
"tasks": {
|
|
||||||
"build": {
|
|
||||||
"name": "Build",
|
|
||||||
"command": "yarn build",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"fix": {
|
|
||||||
"name": "Fix",
|
|
||||||
"command": "yarn fix",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"prettier": {
|
|
||||||
"name": "Prettify",
|
|
||||||
"command": "yarn prettier",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"start": {
|
|
||||||
"name": "Start Excalidraw",
|
|
||||||
"command": "yarn start",
|
|
||||||
"runAtStart": true
|
|
||||||
},
|
|
||||||
"test": {
|
|
||||||
"name": "Run Tests",
|
|
||||||
"command": "yarn test",
|
|
||||||
"runAtStart": false
|
|
||||||
},
|
|
||||||
"install-deps": {
|
|
||||||
"name": "Install Dependencies",
|
|
||||||
"command": "yarn install",
|
|
||||||
"restartOn": { "files": ["yarn.lock"] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -11,12 +11,3 @@ REACT_APP_WS_SERVER_URL=http://localhost:3002
|
|||||||
REACT_APP_PORTAL_URL=
|
REACT_APP_PORTAL_URL=
|
||||||
|
|
||||||
REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyCMkxA60XIW8KbqMYL7edC4qT5l4qHX2h8","authDomain":"excalidraw-oss-dev.firebaseapp.com","projectId":"excalidraw-oss-dev","storageBucket":"excalidraw-oss-dev.appspot.com","messagingSenderId":"664559512677","appId":"1:664559512677:web:a385181f2928d328a7aa8c"}'
|
REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyCMkxA60XIW8KbqMYL7edC4qT5l4qHX2h8","authDomain":"excalidraw-oss-dev.firebaseapp.com","projectId":"excalidraw-oss-dev","storageBucket":"excalidraw-oss-dev.appspot.com","messagingSenderId":"664559512677","appId":"1:664559512677:web:a385181f2928d328a7aa8c"}'
|
||||||
|
|
||||||
# put these in your .env.local, or make sure you don't commit!
|
|
||||||
# must be lowercase `true` when turned on
|
|
||||||
#
|
|
||||||
# whether to enable Service Workers in development
|
|
||||||
REACT_APP_DEV_ENABLE_SW=
|
|
||||||
# whether to disable live reload / HMR. Usuaully what you want to do when
|
|
||||||
# debugging Service Workers.
|
|
||||||
REACT_APP_DEV_DISABLE_LIVE_RELOAD=
|
|
||||||
|
@@ -13,5 +13,3 @@ REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","
|
|||||||
|
|
||||||
# production-only vars
|
# production-only vars
|
||||||
REACT_APP_GOOGLE_ANALYTICS_ID=UA-387204-13
|
REACT_APP_GOOGLE_ANALYTICS_ID=UA-387204-13
|
||||||
|
|
||||||
REACT_APP_PLUS_APP=https://app.excalidraw.com
|
|
||||||
|
37
.github/dependabot.yml
vendored
Normal file
37
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
day: sunday
|
||||||
|
time: "01:00"
|
||||||
|
reviewers:
|
||||||
|
- lipis
|
||||||
|
assignees:
|
||||||
|
- lipis
|
||||||
|
open-pull-requests-limit: 20
|
||||||
|
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: /src/packages/excalidraw/
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
day: sunday
|
||||||
|
time: "01:00"
|
||||||
|
reviewers:
|
||||||
|
- ad1992
|
||||||
|
assignees:
|
||||||
|
- ad1992
|
||||||
|
open-pull-requests-limit: 20
|
||||||
|
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: /src/packages/utils/
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
day: sunday
|
||||||
|
time: "01:00"
|
||||||
|
reviewers:
|
||||||
|
- ad1992
|
||||||
|
assignees:
|
||||||
|
- ad1992
|
||||||
|
open-pull-requests-limit: 20
|
2
.github/workflows/autorelease-excalidraw.yml
vendored
2
.github/workflows/autorelease-excalidraw.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Auto release excalidraw next
|
name: Auto release @excalidraw/excalidraw-next
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
4
.github/workflows/autorelease-preview.yml
vendored
4
.github/workflows/autorelease-preview.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Auto release excalidraw preview
|
name: Auto release preview @excalidraw/excalidraw-preview
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created, edited]
|
types: [created, edited]
|
||||||
@@ -6,7 +6,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
Auto-release-excalidraw-preview:
|
Auto-release-excalidraw-preview:
|
||||||
name: Auto release preview
|
name: Auto release preview
|
||||||
if: github.event.comment.body == '@excalibot trigger release' && github.event.issue.pull_request
|
if: github.event.comment.body == '@excalibot release package' && github.event.issue.pull_request
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: React to release comment
|
- name: React to release comment
|
||||||
|
15
.github/workflows/publish-docker.yml
vendored
15
.github/workflows/publish-docker.yml
vendored
@@ -10,16 +10,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v2
|
||||||
uses: actions/checkout@v3
|
- uses: docker/build-push-action@v2
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
- name: Build and push
|
repository: excalidraw/excalidraw
|
||||||
uses: docker/build-push-action@v3
|
tag_with_ref: true
|
||||||
with:
|
tag_with_sha: true
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
tags: excalidraw/excalidraw:latest
|
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -19,9 +19,11 @@ logs
|
|||||||
node_modules
|
node_modules
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
static
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
src/packages/excalidraw/types
|
src/packages/excalidraw/types
|
||||||
src/packages/excalidraw/example/public/bundle.js
|
src/packages/excalidraw/example/public/bundle.js
|
||||||
src/packages/excalidraw/example/public/excalidraw-assets-dev
|
src/packages/excalidraw/example/public/excalidraw-assets-dev
|
||||||
src/packages/excalidraw/example/public/excalidraw.development.js
|
src/packages/excalidraw/example/public/excalidraw.development.js
|
||||||
|
|
||||||
|
@@ -88,7 +88,7 @@ Try out [`@excalidraw/excalidraw`](https://www.npmjs.com/package/@excalidraw/exc
|
|||||||
|
|
||||||
### Code Sandbox
|
### Code Sandbox
|
||||||
|
|
||||||
- Go to https://codesandbox.io/p/github/excalidraw/excalidraw
|
- Go to https://codesandbox.io/s/github/excalidraw/excalidraw
|
||||||
- You may need to sign in with GitHub and reload the page
|
- You may need to sign in with GitHub and reload the page
|
||||||
- You can start coding instantly, and even send PRs from there!
|
- You can start coding instantly, and even send PRs from there!
|
||||||
|
|
||||||
|
20
dev-docs/.gitignore
vendored
20
dev-docs/.gitignore
vendored
@@ -1,20 +0,0 @@
|
|||||||
# Dependencies
|
|
||||||
/node_modules
|
|
||||||
|
|
||||||
# Production
|
|
||||||
/build
|
|
||||||
|
|
||||||
# Generated files
|
|
||||||
.docusaurus
|
|
||||||
.cache-loader
|
|
||||||
|
|
||||||
# Misc
|
|
||||||
.DS_Store
|
|
||||||
.env.local
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
@@ -1,41 +0,0 @@
|
|||||||
# Website
|
|
||||||
|
|
||||||
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
```
|
|
||||||
$ yarn
|
|
||||||
```
|
|
||||||
|
|
||||||
### Local Development
|
|
||||||
|
|
||||||
```
|
|
||||||
$ yarn start
|
|
||||||
```
|
|
||||||
|
|
||||||
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
|
|
||||||
|
|
||||||
### Build
|
|
||||||
|
|
||||||
```
|
|
||||||
$ yarn build
|
|
||||||
```
|
|
||||||
|
|
||||||
This command generates static content into the `build` directory and can be served using any static contents hosting service.
|
|
||||||
|
|
||||||
### Deployment
|
|
||||||
|
|
||||||
Using SSH:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ USE_SSH=true yarn deploy
|
|
||||||
```
|
|
||||||
|
|
||||||
Not using SSH:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ GIT_USER=<Your GitHub username> yarn deploy
|
|
||||||
```
|
|
||||||
|
|
||||||
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
|
|
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
presets: [require.resolve("@docusaurus/core/lib/babel/preset")],
|
|
||||||
};
|
|
@@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_position: 1
|
|
||||||
title: Overview
|
|
||||||
---
|
|
||||||
|
|
||||||
In development. For now, refer to [excalidraw Readme](https://github.com/excalidraw/excalidraw/blob/master/README.md).
|
|
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_position: 1
|
|
||||||
title: Introduction
|
|
||||||
---
|
|
||||||
|
|
||||||
Want to integrate Excalidraw into your app? Head over to the [package docs](/docs/package/overview).
|
|
||||||
|
|
||||||
If you're looking into the Excalidraw codebase itself, start [here](/docs/codebase/overview).
|
|
@@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_position: 1
|
|
||||||
title: Overview
|
|
||||||
---
|
|
||||||
|
|
||||||
In development. For now, refer to [excalidraw package readme](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md).
|
|
@@ -1,121 +0,0 @@
|
|||||||
// @ts-check
|
|
||||||
// Note: type annotations allow type checking and IDEs autocompletion
|
|
||||||
|
|
||||||
const lightCodeTheme = require("prism-react-renderer/themes/github");
|
|
||||||
const darkCodeTheme = require("prism-react-renderer/themes/dracula");
|
|
||||||
|
|
||||||
/** @type {import('@docusaurus/types').Config} */
|
|
||||||
const config = {
|
|
||||||
title: "Excalidraw developer docs",
|
|
||||||
tagline:
|
|
||||||
"For Excalidraw contributors or those integrating the Excalidraw editor",
|
|
||||||
url: "https://docs.excalidraw.com.com",
|
|
||||||
baseUrl: "/",
|
|
||||||
onBrokenLinks: "throw",
|
|
||||||
onBrokenMarkdownLinks: "warn",
|
|
||||||
favicon: "img/favicon.ico",
|
|
||||||
organizationName: "Excalidraw", // Usually your GitHub org/user name.
|
|
||||||
projectName: "excalidraw", // Usually your repo name.
|
|
||||||
|
|
||||||
// Even if you don't use internalization, you can use this field to set useful
|
|
||||||
// metadata like html lang. For example, if your site is Chinese, you may want
|
|
||||||
// to replace "en" with "zh-Hans".
|
|
||||||
i18n: {
|
|
||||||
defaultLocale: "en",
|
|
||||||
locales: ["en"],
|
|
||||||
},
|
|
||||||
|
|
||||||
presets: [
|
|
||||||
[
|
|
||||||
"classic",
|
|
||||||
/** @type {import('@docusaurus/preset-classic').Options} */
|
|
||||||
({
|
|
||||||
docs: {
|
|
||||||
sidebarPath: require.resolve("./sidebars.js"),
|
|
||||||
// Please change this to your repo.
|
|
||||||
editUrl: "https://github.com/excalidraw/docs/tree/master/",
|
|
||||||
},
|
|
||||||
theme: {
|
|
||||||
customCss: require.resolve("./src/css/custom.css"),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
|
|
||||||
themeConfig:
|
|
||||||
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
|
|
||||||
({
|
|
||||||
navbar: {
|
|
||||||
title: "Excalidraw Docs",
|
|
||||||
logo: {
|
|
||||||
alt: "Excalidraw Logo",
|
|
||||||
src: "img/logo.svg",
|
|
||||||
},
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
type: "doc",
|
|
||||||
docId: "get-started",
|
|
||||||
position: "left",
|
|
||||||
label: "Get started",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
to: "https://blog.excalidraw.com",
|
|
||||||
label: "Blog",
|
|
||||||
position: "left",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
to: "https://github.com/excalidraw/excalidraw",
|
|
||||||
label: "GitHub",
|
|
||||||
position: "right",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
footer: {
|
|
||||||
style: "dark",
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
title: "Docs",
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
label: "Get Started",
|
|
||||||
to: "/docs/get-started",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Community",
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
label: "Discord",
|
|
||||||
href: "https://discord.gg/UexuTaE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Twitter",
|
|
||||||
href: "https://twitter.com/excalidraw",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "More",
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
label: "Blog",
|
|
||||||
to: "https://blog.excalidraw.com",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "GitHub",
|
|
||||||
to: "https://github.com/excalidraw/excalidraw",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
copyright: `Made with ❤️ Built with Docusaurus`,
|
|
||||||
},
|
|
||||||
prism: {
|
|
||||||
theme: lightCodeTheme,
|
|
||||||
darkTheme: darkCodeTheme,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = config;
|
|
@@ -1,46 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "docs",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"docusaurus": "docusaurus",
|
|
||||||
"start": "docusaurus start --port 3003",
|
|
||||||
"build": "docusaurus build",
|
|
||||||
"swizzle": "docusaurus swizzle",
|
|
||||||
"deploy": "docusaurus deploy",
|
|
||||||
"clear": "docusaurus clear",
|
|
||||||
"serve": "docusaurus serve",
|
|
||||||
"write-translations": "docusaurus write-translations",
|
|
||||||
"write-heading-ids": "docusaurus write-heading-ids",
|
|
||||||
"typecheck": "tsc"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@docusaurus/core": "2.0.0-rc.1",
|
|
||||||
"@docusaurus/preset-classic": "2.0.0-rc.1",
|
|
||||||
"@mdx-js/react": "^1.6.22",
|
|
||||||
"clsx": "^1.2.1",
|
|
||||||
"prism-react-renderer": "^1.3.5",
|
|
||||||
"react": "^17.0.2",
|
|
||||||
"react-dom": "^17.0.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@docusaurus/module-type-aliases": "2.0.0-rc.1",
|
|
||||||
"@tsconfig/docusaurus": "^1.0.5",
|
|
||||||
"typescript": "^4.7.4"
|
|
||||||
},
|
|
||||||
"browserslist": {
|
|
||||||
"production": [
|
|
||||||
">0.5%",
|
|
||||||
"not dead",
|
|
||||||
"not op_mini all"
|
|
||||||
],
|
|
||||||
"development": [
|
|
||||||
"last 1 chrome version",
|
|
||||||
"last 1 firefox version",
|
|
||||||
"last 1 safari version"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.14"
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
/**
|
|
||||||
* Creating a sidebar enables you to:
|
|
||||||
- create an ordered group of docs
|
|
||||||
- render a sidebar for each doc of that group
|
|
||||||
- provide next/previous navigation
|
|
||||||
|
|
||||||
The sidebars can be generated from the filesystem, or explicitly defined here.
|
|
||||||
|
|
||||||
Create as many sidebars as you want.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
|
|
||||||
const sidebars = {
|
|
||||||
// By default, Docusaurus generates a sidebar from the docs folder structure
|
|
||||||
tutorialSidebar: [{ type: "autogenerated", dirName: "." }],
|
|
||||||
|
|
||||||
// But you can create a sidebar manually
|
|
||||||
/*
|
|
||||||
tutorialSidebar: [
|
|
||||||
{
|
|
||||||
type: 'category',
|
|
||||||
label: 'Tutorial',
|
|
||||||
items: ['hello'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = sidebars;
|
|
@@ -1,62 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import clsx from "clsx";
|
|
||||||
import styles from "./styles.module.css";
|
|
||||||
|
|
||||||
const FeatureList = [
|
|
||||||
{
|
|
||||||
title: "Learn how Excalidraw works",
|
|
||||||
Svg: require("@site/static/img/undraw_innovative.svg").default,
|
|
||||||
description: (
|
|
||||||
<>Want to contribute to Excalidraw but got lost in the codebase?</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Integrate Excalidraw",
|
|
||||||
Svg: require("@site/static/img/undraw_blank_canvas.svg").default,
|
|
||||||
description: (
|
|
||||||
<>
|
|
||||||
Want to build your own app powered by Excalidraw by don't know where to
|
|
||||||
start?
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Help us improve",
|
|
||||||
Svg: require("@site/static/img/undraw_add_files.svg").default,
|
|
||||||
description: (
|
|
||||||
<>
|
|
||||||
Are the docs missing something? Anything you had trouble understanding
|
|
||||||
or needs an explanation? Come contribute to the docs to make them even
|
|
||||||
better!
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function Feature({ Svg, title, description }) {
|
|
||||||
return (
|
|
||||||
<div className={clsx("col col--4")}>
|
|
||||||
<div className="text--center">
|
|
||||||
<Svg className={styles.featureSvg} role="img" />
|
|
||||||
</div>
|
|
||||||
<div className="text--center padding-horiz--md">
|
|
||||||
<h3>{title}</h3>
|
|
||||||
<p>{description}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function HomepageFeatures() {
|
|
||||||
return (
|
|
||||||
<section className={styles.features}>
|
|
||||||
<div className="container">
|
|
||||||
<div className="row">
|
|
||||||
{FeatureList.map((props, idx) => (
|
|
||||||
<Feature key={idx} {...props} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
@@ -1,70 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import clsx from "clsx";
|
|
||||||
import styles from "./styles.module.css";
|
|
||||||
|
|
||||||
type FeatureItem = {
|
|
||||||
title: string;
|
|
||||||
Svg: React.ComponentType<React.ComponentProps<"svg">>;
|
|
||||||
description: JSX.Element;
|
|
||||||
};
|
|
||||||
|
|
||||||
const FeatureList: FeatureItem[] = [
|
|
||||||
{
|
|
||||||
title: "Easy to Use",
|
|
||||||
Svg: require("@site/static/img/undraw_docusaurus_mountain.svg").default,
|
|
||||||
description: (
|
|
||||||
<>
|
|
||||||
Docusaurus was designed from the ground up to be easily installed and
|
|
||||||
used to get your website up and running quickly.
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Focus on What Matters",
|
|
||||||
Svg: require("@site/static/img/undraw_docusaurus_tree.svg").default,
|
|
||||||
description: (
|
|
||||||
<>
|
|
||||||
Docusaurus lets you focus on your docs, and we'll do the chores. Go
|
|
||||||
ahead and move your docs into the <code>docs</code> directory.
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Powered by React",
|
|
||||||
Svg: require("@site/static/img/undraw_docusaurus_react.svg").default,
|
|
||||||
description: (
|
|
||||||
<>
|
|
||||||
Extend or customize your website layout by reusing React. Docusaurus can
|
|
||||||
be extended while reusing the same header and footer.
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function Feature({ title, Svg, description }: FeatureItem) {
|
|
||||||
return (
|
|
||||||
<div className={clsx("col col--4")}>
|
|
||||||
<div className="text--center">
|
|
||||||
<Svg className={styles.featureSvg} role="img" />
|
|
||||||
</div>
|
|
||||||
<div className="text--center padding-horiz--md">
|
|
||||||
<h3>{title}</h3>
|
|
||||||
<p>{description}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function HomepageFeatures(): JSX.Element {
|
|
||||||
return (
|
|
||||||
<section className={styles.features}>
|
|
||||||
<div className="container">
|
|
||||||
<div className="row">
|
|
||||||
{FeatureList.map((props, idx) => (
|
|
||||||
<Feature key={idx} {...props} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
.features {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 2rem 0;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.featureSvg {
|
|
||||||
height: 200px;
|
|
||||||
width: 200px;
|
|
||||||
}
|
|
@@ -1,43 +0,0 @@
|
|||||||
/**
|
|
||||||
* Any CSS included here will be global. The classic template
|
|
||||||
* bundles Infima by default. Infima is a CSS framework designed to
|
|
||||||
* work well for content-centric websites.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* You can override the default Infima variables here. */
|
|
||||||
:root {
|
|
||||||
--ifm-color-primary: #6965db;
|
|
||||||
--ifm-color-primary-dark: #5b57d1;
|
|
||||||
--ifm-color-primary-darker: #5b57d1;
|
|
||||||
--ifm-color-primary-darkest: #4a47b1;
|
|
||||||
--ifm-color-primary-light: #5b57d1;
|
|
||||||
--ifm-color-primary-lighter: #5b57d1;
|
|
||||||
--ifm-color-primary-lightest: #5b57d1;
|
|
||||||
--ifm-code-font-size: 95%;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* For readability concerns, you should choose a lighter palette in dark mode. */
|
|
||||||
[data-theme="dark"] {
|
|
||||||
--ifm-color-primary: #5650f0;
|
|
||||||
--ifm-color-primary-dark: #4b46d8;
|
|
||||||
--ifm-color-primary-darker: #4b46d8;
|
|
||||||
--ifm-color-primary-darkest: #3e39be;
|
|
||||||
--ifm-color-primary-light: #3f3d64;
|
|
||||||
--ifm-color-primary-lighter: #3f3d64;
|
|
||||||
--ifm-color-primary-lightest: #3f3d64;
|
|
||||||
}
|
|
||||||
|
|
||||||
.docusaurus-highlight-code-line {
|
|
||||||
background-color: rgba(0, 0, 0, 0.1);
|
|
||||||
display: block;
|
|
||||||
margin: 0 calc(-1 * var(--ifm-pre-padding));
|
|
||||||
padding: 0 var(--ifm-pre-padding);
|
|
||||||
}
|
|
||||||
|
|
||||||
[data-theme="dark"] .docusaurus-highlight-code-line {
|
|
||||||
background-color: rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
|
|
||||||
[data-theme="dark"] .navbar__logo {
|
|
||||||
filter: invert(93%) hue-rotate(180deg);
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import clsx from "clsx";
|
|
||||||
import Layout from "@theme/Layout";
|
|
||||||
import Link from "@docusaurus/Link";
|
|
||||||
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
||||||
import styles from "./index.module.css";
|
|
||||||
import HomepageFeatures from "@site/src/components/Homepage";
|
|
||||||
|
|
||||||
function HomepageHeader() {
|
|
||||||
const { siteConfig } = useDocusaurusContext();
|
|
||||||
return (
|
|
||||||
<header className={clsx("hero hero--primary", styles.heroBanner)}>
|
|
||||||
<div className="container">
|
|
||||||
<h1 className="hero__title">{siteConfig.title}</h1>
|
|
||||||
<p className="hero__subtitle">{siteConfig.tagline}</p>
|
|
||||||
<div className={styles.buttons}>
|
|
||||||
<Link
|
|
||||||
className="button button--secondary button--lg"
|
|
||||||
to="/docs/get-started"
|
|
||||||
>
|
|
||||||
Get started
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Home() {
|
|
||||||
const { siteConfig } = useDocusaurusContext();
|
|
||||||
return (
|
|
||||||
<Layout
|
|
||||||
title={`Hello from ${siteConfig.title}`}
|
|
||||||
description="Description will go into a meta tag in <head />"
|
|
||||||
>
|
|
||||||
<HomepageHeader />
|
|
||||||
<main>
|
|
||||||
<HomepageFeatures />
|
|
||||||
</main>
|
|
||||||
</Layout>
|
|
||||||
);
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* CSS files with the .module.css suffix will be treated as CSS modules
|
|
||||||
* and scoped locally.
|
|
||||||
*/
|
|
||||||
|
|
||||||
.heroBanner {
|
|
||||||
padding: 4rem 0;
|
|
||||||
text-align: center;
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
[data-theme="dark"] .heroBanner {
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (max-width: 996px) {
|
|
||||||
.heroBanner {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.buttons {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import clsx from "clsx";
|
|
||||||
import Layout from "@theme/Layout";
|
|
||||||
import Link from "@docusaurus/Link";
|
|
||||||
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
||||||
import styles from "./index.module.css";
|
|
||||||
import HomepageFeatures from "@site/src/components/Homepage";
|
|
||||||
|
|
||||||
function HomepageHeader() {
|
|
||||||
const { siteConfig } = useDocusaurusContext();
|
|
||||||
return (
|
|
||||||
<header className={clsx("hero hero--primary", styles.heroBanner)}>
|
|
||||||
<div className="container">
|
|
||||||
<h1 className="hero__title">{siteConfig.title}</h1>
|
|
||||||
<p className="hero__subtitle">{siteConfig.tagline}</p>
|
|
||||||
<div className={styles.buttons}>
|
|
||||||
<Link
|
|
||||||
className="button button--secondary button--lg"
|
|
||||||
to="/docs/get-started"
|
|
||||||
>
|
|
||||||
Get started
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Home() {
|
|
||||||
const { siteConfig } = useDocusaurusContext();
|
|
||||||
return (
|
|
||||||
<Layout
|
|
||||||
title={`Hello from ${siteConfig.title}`}
|
|
||||||
description="Description will go into a meta tag in <head />"
|
|
||||||
>
|
|
||||||
<HomepageHeader />
|
|
||||||
<main>
|
|
||||||
<HomepageFeatures />
|
|
||||||
</main>
|
|
||||||
</Layout>
|
|
||||||
);
|
|
||||||
}
|
|
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
title: Markdown page example
|
|
||||||
---
|
|
||||||
|
|
||||||
# Markdown page example
|
|
||||||
|
|
||||||
You don't need React to write simple standalone pages.
|
|
Binary file not shown.
Before Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
@@ -1,4 +0,0 @@
|
|||||||
<svg viewBox="0 0 80 180" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2">
|
|
||||||
<path d="M22.197 150.382c-4.179-3.359-10.618-9.051-15.702-13.946l-4.01-3.813.734-5.009c.396-2.732 1.13-8.083 1.582-11.839.508-3.757 1.017-7.286 1.186-7.798.226-.683 0-1.025-.621-1.025-1.073 0-1.13.285 1.807-9.107a617.602 617.602 0 0 1 2.203-7.229c.113-.398.565-.569 1.073-.398.508.227.791.683.621 1.081-.169.455.113.911.565 1.082.621.227.565.683-.395 2.333-1.525 2.562-5.422 24.419-5.648 31.477-.17 5.009-.17 5.066 1.92 7.912 2.033 2.789 6.721 7.001 13.951 12.351 2.033 1.537 4.067 3.245 4.631 3.814.848 1.024 1.243.74 8.36-6.887 4.123-4.383 8.698-8.88 10.166-10.018l2.711-2.049-2.089-4.44c-1.13-2.391-5.705-11.612-10.223-20.377-9.433-18.442-7.513-16.678-18.47-16.849l-7.117-.056-2.372-2.733c-2.485-2.903-2.824-3.984-1.638-5.805.452-.627.791-1.651.791-2.277 0-1.025.395-1.196 2.655-1.309 1.412-.057 2.711-.228 2.88-.399.17-.171.396-3.7.565-7.855l.226-7.513-3.784-8.197C2.485 39.844 0 33.583 0 31.533c0-1.081.226-1.992.452-1.992.565 0 .565.057 23.553 48.382 10.675 22.426 20.785 43.544 22.479 47.016 1.695 3.472 3.22 6.659 3.333 7.115.113.512-3.785 4.439-9.998 9.961-5.591 5.008-10.505 9.562-10.957 10.074-1.299 1.594-3.219 1.082-6.665-1.707Zm1.921-65.458c-2.599-5.066-2.712-5.123-9.828-5.464-6.27-.342-6.383-.285-6.383.911 0 .683-.226 1.593-.508 2.049-.339.512-.113 1.423.678 2.675l1.242 1.935h5.649c3.106.057 6.664.285 7.907.512 1.243.228 2.316.342 2.429.285.113-.057-.452-1.366-1.186-2.903Zm-4.745-9.107c-.452-1.195-1.638-3.7-2.598-5.578-1.581-3.188-1.751-3.301-2.146-1.992-.226.797-.396 3.13-.452 5.236-.057 4.155-.17 4.098 4.575 4.383l1.525.057-.904-2.106Z" style="fill-rule:nonzero;stroke:#000;stroke-width:2px" transform="matrix(1.01351 0 0 -1 9.088 166.517)" />
|
|
||||||
<path d="M23.892 136.835c-1.017-.74-1.299-1.48-1.299-3.358 0-2.22.169-2.562 1.694-3.188 1.525-.626 1.92-.569 3.671.626 2.316 1.594 2.373 1.992.678 4.554-1.468 2.22-2.937 2.618-4.744 1.366Zm3.219-2.049c.904-1.594.339-2.789-1.355-2.789-1.525 0-2.203 1.536-1.356 3.073.678 1.253 1.977 1.139 2.711-.284ZM59.306 124.028c0-.285-.339-.569-.735-.569-.339 0-1.299-1.594-2.033-3.529-2.259-5.92-24.852-50.943-24.908-49.52 0 .74-.339 1.252-.904 1.252-.791 0-.904-.456-.565-2.675.339-2.562.113-3.131-7.907-18.841-4.519-8.936-9.376-18.271-10.788-20.775-1.469-2.619-2.598-5.465-2.711-6.66-.17-2.049.056-2.334 4.97-6.603 2.824-2.504 6.439-5.635 8.02-7.058C28.862 2.504 32.194-.114 33.098.057c1.356.228 22.31 22.369 22.367 23.622 0 .569-1.017 9.221-2.259 19.238-2.147 17.076-4.18 37.055-3.954 38.99.169 1.196-.678 7.229-1.299 9.847-.509 2.05-.283 2.903 3.784 12.238 2.372 5.521 5.479 12.295 6.834 15.027 1.299 2.732 2.429 5.123 2.429 5.294 0 .17-.395.284-.847.284-.452 0-.847-.228-.847-.569ZM46.315 81.509c.621-3.984 1.864-13.547 2.767-21.231 1.751-14.116 3.785-29.769 4.349-33.753.339-1.993.113-2.391-3.558-6.489-6.382-7.229-13.16-14.344-15.476-16.165l-2.146-1.708-11.014 10.359C11.07 21.971 10.223 22.939 10.844 24.077c.339.626 3.22 5.92 6.383 11.725 3.163 5.806 7.342 13.547 9.263 17.19 1.977 3.7 3.784 6.887 4.123 7.058.395.228.508-5.521.395-17.759-.226-18.271-.169-18.328 1.638-17.929.226 0 .396 9.221.396 20.434v20.377l5.93 11.953c3.276 6.603 5.987 11.896 6.1 11.84.113-.058.678-3.416 1.243-7.457Z" style="fill-rule:nonzero;stroke:#000;stroke-width:2px" transform="matrix(1.01351 0 0 -1 9.088 166.517)" />
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 3.4 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 5.7 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 12 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 5.4 KiB |
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
// This file is not used in compilation. It is here just for a nice editor experience.
|
|
||||||
"extends": "@tsconfig/docusaurus/tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"baseUrl": "."
|
|
||||||
}
|
|
||||||
}
|
|
7489
dev-docs/yarn.lock
7489
dev-docs/yarn.lock
File diff suppressed because it is too large
Load Diff
40
package.json
40
package.json
@@ -22,18 +22,18 @@
|
|||||||
"@sentry/browser": "6.2.5",
|
"@sentry/browser": "6.2.5",
|
||||||
"@sentry/integrations": "6.2.5",
|
"@sentry/integrations": "6.2.5",
|
||||||
"@testing-library/jest-dom": "5.16.2",
|
"@testing-library/jest-dom": "5.16.2",
|
||||||
"@testing-library/react": "12.1.5",
|
"@testing-library/react": "12.1.2",
|
||||||
"@tldraw/vec": "1.7.1",
|
"@tldraw/vec": "1.4.3",
|
||||||
"@types/jest": "27.4.0",
|
"@types/jest": "27.4.0",
|
||||||
"@types/pica": "5.1.3",
|
"@types/pica": "5.1.3",
|
||||||
"@types/react": "18.0.15",
|
"@types/react": "17.0.39",
|
||||||
"@types/react-dom": "18.0.6",
|
"@types/react-dom": "17.0.11",
|
||||||
"@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",
|
||||||
"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.2",
|
||||||
"idb-keyval": "6.0.3",
|
"idb-keyval": "6.0.3",
|
||||||
"image-blob-reduce": "3.0.1",
|
"image-blob-reduce": "3.0.1",
|
||||||
"jotai": "1.6.4",
|
"jotai": "1.6.4",
|
||||||
@@ -41,18 +41,17 @@
|
|||||||
"nanoid": "3.3.3",
|
"nanoid": "3.3.3",
|
||||||
"open-color": "1.9.1",
|
"open-color": "1.9.1",
|
||||||
"pako": "1.0.11",
|
"pako": "1.0.11",
|
||||||
"perfect-freehand": "1.2.0",
|
"perfect-freehand": "1.0.16",
|
||||||
"pica": "7.1.1",
|
|
||||||
"png-chunk-text": "1.0.0",
|
"png-chunk-text": "1.0.0",
|
||||||
"png-chunks-encode": "1.0.0",
|
"png-chunks-encode": "1.0.0",
|
||||||
"png-chunks-extract": "1.0.0",
|
"png-chunks-extract": "1.0.0",
|
||||||
"points-on-curve": "0.2.0",
|
"points-on-curve": "0.2.0",
|
||||||
"pwacompat": "2.0.17",
|
"pwacompat": "2.0.17",
|
||||||
"react": "18.2.0",
|
"react": "17.0.2",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "17.0.2",
|
||||||
"react-scripts": "4.0.3",
|
"react-scripts": "4.0.3",
|
||||||
"roughjs": "4.5.2",
|
"roughjs": "4.5.2",
|
||||||
"sass": "1.51.0",
|
"sass": "1.49.7",
|
||||||
"socket.io-client": "2.3.1",
|
"socket.io-client": "2.3.1",
|
||||||
"typescript": "4.5.5"
|
"typescript": "4.5.5"
|
||||||
},
|
},
|
||||||
@@ -60,19 +59,19 @@
|
|||||||
"@excalidraw/eslint-config": "1.0.0",
|
"@excalidraw/eslint-config": "1.0.0",
|
||||||
"@excalidraw/prettier-config": "1.0.2",
|
"@excalidraw/prettier-config": "1.0.2",
|
||||||
"@types/chai": "4.3.0",
|
"@types/chai": "4.3.0",
|
||||||
"@types/lodash.throttle": "4.1.7",
|
"@types/lodash.throttle": "4.1.6",
|
||||||
"@types/pako": "1.0.3",
|
"@types/pako": "1.0.3",
|
||||||
"@types/resize-observer-browser": "0.1.7",
|
"@types/resize-observer-browser": "0.1.6",
|
||||||
"chai": "4.3.6",
|
"chai": "4.3.6",
|
||||||
"dotenv": "16.0.1",
|
"dotenv": "10.0.0",
|
||||||
"eslint-config-prettier": "8.5.0",
|
"eslint-config-prettier": "8.3.0",
|
||||||
"eslint-plugin-prettier": "3.3.1",
|
"eslint-plugin-prettier": "3.3.1",
|
||||||
"husky": "7.0.4",
|
"husky": "7.0.4",
|
||||||
"jest-canvas-mock": "2.4.0",
|
"jest-canvas-mock": "2.3.1",
|
||||||
"lint-staged": "12.3.7",
|
"lint-staged": "12.3.7",
|
||||||
"pepjs": "0.5.3",
|
"pepjs": "0.5.3",
|
||||||
"prettier": "2.6.2",
|
"prettier": "2.5.1",
|
||||||
"rewire": "6.0.0"
|
"rewire": "5.0.0"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"@typescript-eslint/typescript-estree": "5.10.2"
|
"@typescript-eslint/typescript-estree": "5.10.2"
|
||||||
@@ -95,8 +94,7 @@
|
|||||||
"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": "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",
|
||||||
@@ -114,8 +112,6 @@
|
|||||||
"test:typecheck": "tsc",
|
"test:typecheck": "tsc",
|
||||||
"test:update": "yarn test:app --updateSnapshot --watchAll=false",
|
"test:update": "yarn test:app --updateSnapshot --watchAll=false",
|
||||||
"test": "yarn test:app",
|
"test": "yarn test:app",
|
||||||
"autorelease": "node scripts/autorelease.js",
|
"autorelease": "node scripts/autorelease.js"
|
||||||
"prerelease": "node scripts/prerelease.js",
|
|
||||||
"release": "node scripts/release.js"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,44 +52,6 @@
|
|||||||
content="Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
content="Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them."
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!------------------------------------------------------------------------->
|
|
||||||
<!-- to minimize white flash on load when user has dark mode enabled -->
|
|
||||||
<script>
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
const theme = window.localStorage.getItem("excalidraw-theme");
|
|
||||||
if (theme === "dark") {
|
|
||||||
document.documentElement.classList.add("dark");
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
html.dark {
|
|
||||||
background-color: #121212;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<!------------------------------------------------------------------------->
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// Redirect Excalidraw+ users which have auto-redirect enabled.
|
|
||||||
//
|
|
||||||
// Redirect only the bare root path, so link/room/library urls are not
|
|
||||||
// redirected.
|
|
||||||
//
|
|
||||||
// Putting into index.html for best performance (can't redirect on server
|
|
||||||
// due to location.hash checks).
|
|
||||||
if (
|
|
||||||
window.location.pathname === "/" &&
|
|
||||||
!window.location.hash &&
|
|
||||||
!window.location.search &&
|
|
||||||
// if its present redirect
|
|
||||||
document.cookie.includes("excplus-autoredirect=true")
|
|
||||||
) {
|
|
||||||
window.location.href = "https://app.excalidraw.com";
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||||
|
|
||||||
<!-- Excalidraw version -->
|
<!-- Excalidraw version -->
|
||||||
@@ -117,22 +79,6 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<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" ) { %>
|
|
||||||
<script>
|
|
||||||
{
|
|
||||||
const _WebSocket = window.WebSocket;
|
|
||||||
window.WebSocket = function (url) {
|
|
||||||
if (/ws:\/\/localhost:.+?\/sockjs-node/.test(url)) {
|
|
||||||
console.info(
|
|
||||||
"[!!!] Live reload is disabled via process.env.REACT_APP_DEV_DISABLE_LIVE_RELOAD [!!!]",
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return new _WebSocket(url);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<% } %>
|
|
||||||
<script>
|
<script>
|
||||||
window.EXCALIDRAW_ASSET_PATH = "/";
|
window.EXCALIDRAW_ASSET_PATH = "/";
|
||||||
// setting this so that libraries installation reuses this window tab.
|
// setting this so that libraries installation reuses this window tab.
|
||||||
@@ -174,7 +120,7 @@
|
|||||||
width: 1px;
|
width: 1px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
clip: rect(1px, 1px, 1px, 1px);
|
clip: rect(1px, 1px, 1px, 1px);
|
||||||
white-space: nowrap;
|
white-space: nowrap; /* added line */
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,25 +5,22 @@ const core = require("@actions/core");
|
|||||||
const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
|
const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
|
||||||
const excalidrawPackage = `${excalidrawDir}/package.json`;
|
const excalidrawPackage = `${excalidrawDir}/package.json`;
|
||||||
const pkg = require(excalidrawPackage);
|
const pkg = require(excalidrawPackage);
|
||||||
const isPreview = process.argv.slice(2)[0] === "preview";
|
|
||||||
|
|
||||||
const getShortCommitHash = () => {
|
const getShortCommitHash = () => {
|
||||||
return execSync("git rev-parse --short HEAD").toString().trim();
|
return execSync("git rev-parse --short HEAD").toString().trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
const publish = () => {
|
const publish = () => {
|
||||||
const tag = isPreview ? "preview" : "next";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(`yarn --frozen-lockfile`);
|
execSync(`yarn --frozen-lockfile`);
|
||||||
execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir });
|
execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir });
|
||||||
execSync(`yarn run build:umd`, { cwd: excalidrawDir });
|
execSync(`yarn run build:umd`, { cwd: excalidrawDir });
|
||||||
execSync(`yarn --cwd ${excalidrawDir} publish --tag ${tag}`);
|
execSync(`yarn --cwd ${excalidrawDir} publish`);
|
||||||
console.info(`Published ${pkg.name}@${tag}🎉`);
|
console.info("Published 🎉");
|
||||||
core.setOutput(
|
core.setOutput(
|
||||||
"result",
|
"result",
|
||||||
`**Preview version has been shipped** :rocket:
|
`**Preview version has been shipped** :rocket:
|
||||||
You can use [@excalidraw/excalidraw@${pkg.version}](https://www.npmjs.com/package/@excalidraw/excalidraw/v/${pkg.version}) for testing!`,
|
You can use [@excalidraw/excalidraw-preview@${pkg.version}](https://www.npmjs.com/package/@excalidraw/excalidraw-preview/v/${pkg.version}) for testing!`,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setOutput("result", "package couldn't be published :warning:!");
|
core.setOutput("result", "package couldn't be published :warning:!");
|
||||||
@@ -54,19 +51,27 @@ exec(`git diff --name-only HEAD^ HEAD`, async (error, stdout, stderr) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update package.json
|
// update package.json
|
||||||
|
pkg.name = "@excalidraw/excalidraw-next";
|
||||||
let version = `${pkg.version}-${getShortCommitHash()}`;
|
let version = `${pkg.version}-${getShortCommitHash()}`;
|
||||||
|
|
||||||
// update readme
|
// update readme
|
||||||
|
let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
|
||||||
|
|
||||||
|
const isPreview = process.argv.slice(2)[0] === "preview";
|
||||||
if (isPreview) {
|
if (isPreview) {
|
||||||
// use pullNumber-commithash as the version for preview
|
// use pullNumber-commithash as the version for preview
|
||||||
const pullRequestNumber = process.argv.slice(3)[0];
|
const pullRequestNumber = process.argv.slice(3)[0];
|
||||||
version = `${pkg.version}-${pullRequestNumber}-${getShortCommitHash()}`;
|
version = `${pkg.version}-${pullRequestNumber}-${getShortCommitHash()}`;
|
||||||
|
// replace "excalidraw-next" with "excalidraw-preview"
|
||||||
|
pkg.name = "@excalidraw/excalidraw-preview";
|
||||||
|
data = data.replace(/excalidraw-next/g, "excalidraw-preview");
|
||||||
|
data = data.trim();
|
||||||
}
|
}
|
||||||
pkg.version = version;
|
pkg.version = version;
|
||||||
|
|
||||||
fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
|
fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
|
||||||
|
|
||||||
|
fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
|
||||||
console.info("Publish in progress...");
|
console.info("Publish in progress...");
|
||||||
publish();
|
publish();
|
||||||
});
|
});
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
const { exec } = require("child_process");
|
|
||||||
|
|
||||||
// get files changed between prev and head commit
|
|
||||||
exec(`git diff --name-only HEAD^ HEAD`, async (error, stdout, stderr) => {
|
|
||||||
if (error || stderr) {
|
|
||||||
console.error(error);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
const changedFiles = stdout.trim().split("\n");
|
|
||||||
|
|
||||||
const docFiles = changedFiles.filter((file) => {
|
|
||||||
return file.indexOf("docs") >= 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!docFiles.length) {
|
|
||||||
console.info("Skipping building docs as no valid diff found");
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
// Exit code 1 to build the docs in ignoredBuildStep
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
@@ -15,7 +15,6 @@ const crowdinMap = {
|
|||||||
"fa-IR": "en-fa",
|
"fa-IR": "en-fa",
|
||||||
"fi-FI": "en-fi",
|
"fi-FI": "en-fi",
|
||||||
"fr-FR": "en-fr",
|
"fr-FR": "en-fr",
|
||||||
"gl-ES": "en-gl",
|
|
||||||
"he-IL": "en-he",
|
"he-IL": "en-he",
|
||||||
"hi-IN": "en-hi",
|
"hi-IN": "en-hi",
|
||||||
"hu-HU": "en-hu",
|
"hu-HU": "en-hu",
|
||||||
@@ -24,7 +23,6 @@ const crowdinMap = {
|
|||||||
"ja-JP": "en-ja",
|
"ja-JP": "en-ja",
|
||||||
"kab-KAB": "en-kab",
|
"kab-KAB": "en-kab",
|
||||||
"ko-KR": "en-ko",
|
"ko-KR": "en-ko",
|
||||||
"ku-TR": "en-ku",
|
|
||||||
"my-MM": "en-my",
|
"my-MM": "en-my",
|
||||||
"nb-NO": "en-nb",
|
"nb-NO": "en-nb",
|
||||||
"nl-NL": "en-nl",
|
"nl-NL": "en-nl",
|
||||||
@@ -38,7 +36,6 @@ const crowdinMap = {
|
|||||||
"ru-RU": "en-ru",
|
"ru-RU": "en-ru",
|
||||||
"si-LK": "en-silk",
|
"si-LK": "en-silk",
|
||||||
"sk-SK": "en-sk",
|
"sk-SK": "en-sk",
|
||||||
"sl-SI": "en-sl",
|
|
||||||
"sv-SE": "en-sv",
|
"sv-SE": "en-sv",
|
||||||
"ta-IN": "en-ta",
|
"ta-IN": "en-ta",
|
||||||
"tr-TR": "en-tr",
|
"tr-TR": "en-tr",
|
||||||
@@ -50,8 +47,6 @@ 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",
|
|
||||||
"mr-in": "en-mr",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const flags = {
|
const flags = {
|
||||||
@@ -67,7 +62,6 @@ const flags = {
|
|||||||
"fa-IR": "🇮🇷",
|
"fa-IR": "🇮🇷",
|
||||||
"fi-FI": "🇫🇮",
|
"fi-FI": "🇫🇮",
|
||||||
"fr-FR": "🇫🇷",
|
"fr-FR": "🇫🇷",
|
||||||
"gl-ES": "🇪🇸",
|
|
||||||
"he-IL": "🇮🇱",
|
"he-IL": "🇮🇱",
|
||||||
"hi-IN": "🇮🇳",
|
"hi-IN": "🇮🇳",
|
||||||
"hu-HU": "🇭🇺",
|
"hu-HU": "🇭🇺",
|
||||||
@@ -77,7 +71,6 @@ const flags = {
|
|||||||
"kab-KAB": "🏳",
|
"kab-KAB": "🏳",
|
||||||
"kk-KZ": "🇰🇿",
|
"kk-KZ": "🇰🇿",
|
||||||
"ko-KR": "🇰🇷",
|
"ko-KR": "🇰🇷",
|
||||||
"ku-TR": "🏳",
|
|
||||||
"lt-LT": "🇱🇹",
|
"lt-LT": "🇱🇹",
|
||||||
"lv-LV": "🇱🇻",
|
"lv-LV": "🇱🇻",
|
||||||
"my-MM": "🇲🇲",
|
"my-MM": "🇲🇲",
|
||||||
@@ -93,7 +86,6 @@ const flags = {
|
|||||||
"ru-RU": "🇷🇺",
|
"ru-RU": "🇷🇺",
|
||||||
"si-LK": "🇱🇰",
|
"si-LK": "🇱🇰",
|
||||||
"sk-SK": "🇸🇰",
|
"sk-SK": "🇸🇰",
|
||||||
"sl-SI": "🇸🇮",
|
|
||||||
"sv-SE": "🇸🇪",
|
"sv-SE": "🇸🇪",
|
||||||
"ta-IN": "🇮🇳",
|
"ta-IN": "🇮🇳",
|
||||||
"tr-TR": "🇹🇷",
|
"tr-TR": "🇹🇷",
|
||||||
@@ -101,9 +93,6 @@ const flags = {
|
|||||||
"zh-CN": "🇨🇳",
|
"zh-CN": "🇨🇳",
|
||||||
"zh-HK": "🇭🇰",
|
"zh-HK": "🇭🇰",
|
||||||
"zh-TW": "🇹🇼",
|
"zh-TW": "🇹🇼",
|
||||||
"eu-ES": "🇪🇦",
|
|
||||||
"vi-VN": "🇻🇳",
|
|
||||||
"mr-IN": "🇮🇳",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const languages = {
|
const languages = {
|
||||||
@@ -144,7 +133,6 @@ const languages = {
|
|||||||
"ru-RU": "Русский",
|
"ru-RU": "Русский",
|
||||||
"si-LK": "සිංහල",
|
"si-LK": "සිංහල",
|
||||||
"sk-SK": "Slovenčina",
|
"sk-SK": "Slovenčina",
|
||||||
"sl-SI": "Slovenščina",
|
|
||||||
"sv-SE": "Svenska",
|
"sv-SE": "Svenska",
|
||||||
"ta-IN": "Tamil",
|
"ta-IN": "Tamil",
|
||||||
"tr-TR": "Türkçe",
|
"tr-TR": "Türkçe",
|
||||||
@@ -152,8 +140,6 @@ const languages = {
|
|||||||
"zh-CN": "简体中文",
|
"zh-CN": "简体中文",
|
||||||
"zh-HK": "繁體中文 (香港)",
|
"zh-HK": "繁體中文 (香港)",
|
||||||
"zh-TW": "繁體中文",
|
"zh-TW": "繁體中文",
|
||||||
"vi-VN": "Tiếng Việt",
|
|
||||||
"mr-IN": "मराठी",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const percentages = fs.readFileSync(
|
const percentages = fs.readFileSync(
|
||||||
|
@@ -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();
|
|
@@ -1,37 +0,0 @@
|
|||||||
const fs = require("fs");
|
|
||||||
const util = require("util");
|
|
||||||
const exec = util.promisify(require("child_process").exec);
|
|
||||||
const updateChangelog = require("./updateChangelog");
|
|
||||||
|
|
||||||
const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
|
|
||||||
const excalidrawPackage = `${excalidrawDir}/package.json`;
|
|
||||||
|
|
||||||
const updatePackageVersion = (nextVersion) => {
|
|
||||||
const pkg = require(excalidrawPackage);
|
|
||||||
pkg.version = nextVersion;
|
|
||||||
const content = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
||||||
fs.writeFileSync(excalidrawPackage, content, "utf-8");
|
|
||||||
};
|
|
||||||
|
|
||||||
const prerelease = async (nextVersion) => {
|
|
||||||
try {
|
|
||||||
await updateChangelog(nextVersion);
|
|
||||||
updatePackageVersion(nextVersion);
|
|
||||||
await exec(`git add -u`);
|
|
||||||
await exec(
|
|
||||||
`git commit -m "docs: release @excalidraw/excalidraw@${nextVersion} 🎉"`,
|
|
||||||
);
|
|
||||||
|
|
||||||
console.info("Done!");
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const nextVersion = process.argv.slice(2)[0];
|
|
||||||
if (!nextVersion) {
|
|
||||||
console.error("Pass the next version to release!");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
prerelease(nextVersion);
|
|
@@ -1,44 +1,39 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { execSync } = require("child_process");
|
const util = require("util");
|
||||||
|
const exec = util.promisify(require("child_process").exec);
|
||||||
|
const updateReadme = require("./updateReadme");
|
||||||
|
const updateChangelog = require("./updateChangelog");
|
||||||
|
|
||||||
const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
|
const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
|
||||||
const excalidrawPackage = `${excalidrawDir}/package.json`;
|
const excalidrawPackage = `${excalidrawDir}/package.json`;
|
||||||
const pkg = require(excalidrawPackage);
|
|
||||||
|
|
||||||
const originalReadMe = fs.readFileSync(`${excalidrawDir}/README.md`, "utf8");
|
const updatePackageVersion = (nextVersion) => {
|
||||||
|
const pkg = require(excalidrawPackage);
|
||||||
const updateReadme = () => {
|
pkg.version = nextVersion;
|
||||||
const excalidrawIndex = originalReadMe.indexOf("### Excalidraw");
|
const content = `${JSON.stringify(pkg, null, 2)}\n`;
|
||||||
|
fs.writeFileSync(excalidrawPackage, content, "utf-8");
|
||||||
// remove note for stable readme
|
|
||||||
const data = originalReadMe.slice(excalidrawIndex);
|
|
||||||
|
|
||||||
// update readme
|
|
||||||
fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const publish = () => {
|
const release = async (nextVersion) => {
|
||||||
try {
|
try {
|
||||||
execSync(`yarn --frozen-lockfile`);
|
updateReadme();
|
||||||
execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir });
|
await updateChangelog(nextVersion);
|
||||||
execSync(`yarn run build:umd`, { cwd: excalidrawDir });
|
updatePackageVersion(nextVersion);
|
||||||
execSync(`yarn --cwd ${excalidrawDir} publish`);
|
await exec(`git add -u`);
|
||||||
|
await exec(
|
||||||
|
`git commit -m "docs: release @excalidraw/excalidraw@${nextVersion} 🎉"`,
|
||||||
|
);
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log("Done!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const release = () => {
|
const nextVersion = process.argv.slice(2)[0];
|
||||||
updateReadme();
|
if (!nextVersion) {
|
||||||
console.info("Note for stable readme removed");
|
console.error("Pass the next version to release!");
|
||||||
|
process.exit(1);
|
||||||
publish();
|
}
|
||||||
console.info(`Published ${pkg.version}!`);
|
release(nextVersion);
|
||||||
|
|
||||||
// revert readme after release
|
|
||||||
fs.writeFileSync(`${excalidrawDir}/README.md`, originalReadMe, "utf8");
|
|
||||||
console.info("Readme reverted");
|
|
||||||
};
|
|
||||||
|
|
||||||
release();
|
|
||||||
|
27
scripts/updateReadme.js
Normal file
27
scripts/updateReadme.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const updateReadme = () => {
|
||||||
|
const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
|
||||||
|
let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
|
||||||
|
|
||||||
|
// remove note for unstable release
|
||||||
|
data = data.replace(
|
||||||
|
/<!-- unstable-readme-start-->[\s\S]*?<!-- unstable-readme-end-->/,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
|
// replace "excalidraw-next" with "excalidraw"
|
||||||
|
data = data.replace(/excalidraw-next/g, "excalidraw");
|
||||||
|
data = data.trim();
|
||||||
|
|
||||||
|
const demoIndex = data.indexOf("### Demo");
|
||||||
|
const excalidrawNextNote =
|
||||||
|
"#### Note\n\n**If you don't want to wait for the next stable release and try out the unreleased changes you can use [@excalidraw/excalidraw-next](https://www.npmjs.com/package/@excalidraw/excalidraw-next).**\n\n";
|
||||||
|
// Add excalidraw next note to try out for unreleased changes
|
||||||
|
data = data.slice(0, demoIndex) + excalidrawNextNote + data.slice(demoIndex);
|
||||||
|
|
||||||
|
// update readme
|
||||||
|
fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = updateReadme;
|
@@ -42,7 +42,7 @@ export const actionAddToLibrary = register({
|
|||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
toast: { message: t("toast.addedToLibrary") },
|
toastMessage: t("toast.addedToLibrary"),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
@@ -11,7 +11,7 @@ import { getNormalizedZoom, getSelectedElements } from "../scene";
|
|||||||
import { centerScrollOn } from "../scene/scroll";
|
import { centerScrollOn } from "../scene/scroll";
|
||||||
import { getStateForZoom } from "../scene/zoom";
|
import { getStateForZoom } from "../scene/zoom";
|
||||||
import { AppState, NormalizedZoomValue } from "../types";
|
import { AppState, NormalizedZoomValue } from "../types";
|
||||||
import { getShortcutKey, updateActiveTool } from "../utils";
|
import { getShortcutKey } from "../utils";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { Tooltip } from "../components/Tooltip";
|
import { Tooltip } from "../components/Tooltip";
|
||||||
import { newElementWith } from "../element/mutateElement";
|
import { newElementWith } from "../element/mutateElement";
|
||||||
@@ -304,22 +304,36 @@ export const actionErase = register({
|
|||||||
name: "eraser",
|
name: "eraser",
|
||||||
trackEvent: { category: "toolbar" },
|
trackEvent: { category: "toolbar" },
|
||||||
perform: (elements, appState) => {
|
perform: (elements, appState) => {
|
||||||
let activeTool: AppState["activeTool"];
|
const activeTool: any = { ...appState.activeTool };
|
||||||
|
|
||||||
if (isEraserActive(appState)) {
|
if (appState.activeTool.type !== "eraser") {
|
||||||
activeTool = updateActiveTool(appState, {
|
if (appState.activeTool.type === "custom") {
|
||||||
...(appState.activeTool.lastActiveToolBeforeEraser || {
|
activeTool.lastActiveToolBeforeEraser = {
|
||||||
type: "selection",
|
type: "custom",
|
||||||
}),
|
customType: appState.activeTool.customType,
|
||||||
lastActiveToolBeforeEraser: null,
|
};
|
||||||
});
|
} else {
|
||||||
} else {
|
activeTool.lastActiveToolBeforeEraser = appState.activeTool.type;
|
||||||
activeTool = updateActiveTool(appState, {
|
}
|
||||||
type: "eraser",
|
}
|
||||||
lastActiveToolBeforeEraser: appState.activeTool,
|
if (isEraserActive(appState)) {
|
||||||
});
|
if (appState.activeTool.lastActiveToolBeforeEraser) {
|
||||||
|
if (
|
||||||
|
typeof appState.activeTool.lastActiveToolBeforeEraser === "object" &&
|
||||||
|
appState.activeTool.lastActiveToolBeforeEraser?.type === "custom"
|
||||||
|
) {
|
||||||
|
activeTool.type = "custom";
|
||||||
|
activeTool.customType =
|
||||||
|
appState.activeTool.lastActiveToolBeforeEraser.customType;
|
||||||
|
} else {
|
||||||
|
activeTool.type = appState.activeTool.lastActiveToolBeforeEraser;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
activeTool.type = "selection";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
activeTool.type = "eraser";
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
|
@@ -36,7 +36,7 @@ export const actionCut = register({
|
|||||||
return actionDeleteSelected.perform(elements, appState);
|
return actionDeleteSelected.perform(elements, appState);
|
||||||
},
|
},
|
||||||
contextItemLabel: "labels.cut",
|
contextItemLabel: "labels.cut",
|
||||||
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.X,
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.X,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionCopyAsSvg = register({
|
export const actionCopyAsSvg = register({
|
||||||
@@ -107,16 +107,14 @@ export const actionCopyAsPng = register({
|
|||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
toast: {
|
toastMessage: t("toast.copyToClipboardAsPng", {
|
||||||
message: t("toast.copyToClipboardAsPng", {
|
exportSelection: selectedElements.length
|
||||||
exportSelection: selectedElements.length
|
? t("toast.selection")
|
||||||
? t("toast.selection")
|
: t("toast.canvas"),
|
||||||
: t("toast.canvas"),
|
exportColorScheme: appState.exportWithDarkMode
|
||||||
exportColorScheme: appState.exportWithDarkMode
|
? t("buttons.darkMode")
|
||||||
? t("buttons.darkMode")
|
: t("buttons.lightMode"),
|
||||||
: t("buttons.lightMode"),
|
}),
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
|
@@ -12,7 +12,6 @@ import { getElementsInGroup } from "../groups";
|
|||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
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";
|
|
||||||
|
|
||||||
const deleteSelectedElements = (
|
const deleteSelectedElements = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
@@ -135,7 +134,7 @@ export const actionDeleteSelected = register({
|
|||||||
elements: nextElements,
|
elements: nextElements,
|
||||||
appState: {
|
appState: {
|
||||||
...nextAppState,
|
...nextAppState,
|
||||||
activeTool: updateActiveTool(appState, { type: "selection" }),
|
activeTool: { ...appState.activeTool, type: "selection" },
|
||||||
multiElement: null,
|
multiElement: null,
|
||||||
},
|
},
|
||||||
commitToHistory: isSomeElementSelected(
|
commitToHistory: isSomeElementSelected(
|
||||||
|
@@ -3,7 +3,7 @@ import {
|
|||||||
DistributeVerticallyIcon,
|
DistributeVerticallyIcon,
|
||||||
} from "../components/icons";
|
} from "../components/icons";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import { distributeElements, Distribution } from "../distribute";
|
import { distributeElements, Distribution } from "../disitrubte";
|
||||||
import { getNonDeletedElements } from "../element";
|
import { getNonDeletedElements } from "../element";
|
||||||
import { ExcalidrawElement } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
@@ -128,15 +128,12 @@ const duplicateElements = (
|
|||||||
{
|
{
|
||||||
...appState,
|
...appState,
|
||||||
selectedGroupIds: {},
|
selectedGroupIds: {},
|
||||||
selectedElementIds: newElements.reduce(
|
selectedElementIds: newElements.reduce((acc, element) => {
|
||||||
(acc: Record<ExcalidrawElement["id"], true>, element) => {
|
if (!isBoundToContainer(element)) {
|
||||||
if (!isBoundToContainer(element)) {
|
acc[element.id] = true;
|
||||||
acc[element.id] = true;
|
}
|
||||||
}
|
return acc;
|
||||||
return acc;
|
}, {} as any),
|
||||||
},
|
|
||||||
{},
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
getNonDeletedElements(finalElements),
|
getNonDeletedElements(finalElements),
|
||||||
),
|
),
|
||||||
|
@@ -7,7 +7,7 @@ import { DarkModeToggle } from "../components/DarkModeToggle";
|
|||||||
import { loadFromJSON, saveAsJSON } from "../data";
|
import { loadFromJSON, saveAsJSON } from "../data";
|
||||||
import { resaveAsImageWithScene } from "../data/resave";
|
import { resaveAsImageWithScene } from "../data/resave";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "../components/App";
|
import { useDeviceType } from "../components/App";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { CheckboxItem } from "../components/CheckboxItem";
|
import { CheckboxItem } from "../components/CheckboxItem";
|
||||||
@@ -144,15 +144,13 @@ export const actionSaveToActiveFile = register({
|
|||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
fileHandle,
|
fileHandle,
|
||||||
toast: fileHandleExists
|
toastMessage: fileHandleExists
|
||||||
? {
|
? fileHandle?.name
|
||||||
message: fileHandle?.name
|
? t("toast.fileSavedToFilename").replace(
|
||||||
? t("toast.fileSavedToFilename").replace(
|
"{filename}",
|
||||||
"{filename}",
|
`"${fileHandle.name}"`,
|
||||||
`"${fileHandle.name}"`,
|
)
|
||||||
)
|
: t("toast.fileSaved")
|
||||||
: t("toast.fileSaved"),
|
|
||||||
}
|
|
||||||
: null,
|
: null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -206,7 +204,7 @@ export const actionSaveFileToDisk = register({
|
|||||||
icon={saveAs}
|
icon={saveAs}
|
||||||
title={t("buttons.saveAs")}
|
title={t("buttons.saveAs")}
|
||||||
aria-label={t("buttons.saveAs")}
|
aria-label={t("buttons.saveAs")}
|
||||||
showAriaLabel={useDevice().isMobile}
|
showAriaLabel={useDeviceType().isMobile}
|
||||||
hidden={!nativeFileSystemSupported}
|
hidden={!nativeFileSystemSupported}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
data-testid="save-as-button"
|
data-testid="save-as-button"
|
||||||
@@ -244,13 +242,13 @@ export const actionLoadScene = register({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.O,
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.O,
|
||||||
PanelComponent: ({ updateData }) => (
|
PanelComponent: ({ updateData, appState }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
type="button"
|
type="button"
|
||||||
icon={load}
|
icon={load}
|
||||||
title={t("buttons.load")}
|
title={t("buttons.load")}
|
||||||
aria-label={t("buttons.load")}
|
aria-label={t("buttons.load")}
|
||||||
showAriaLabel={useDevice().isMobile}
|
showAriaLabel={useDeviceType().isMobile}
|
||||||
onClick={updateData}
|
onClick={updateData}
|
||||||
data-testid="load-button"
|
data-testid="load-button"
|
||||||
/>
|
/>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { isInvisiblySmallElement } from "../element";
|
import { isInvisiblySmallElement } from "../element";
|
||||||
import { updateActiveTool, resetCursor } from "../utils";
|
import { resetCursor } from "../utils";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import { done } from "../components/icons";
|
import { done } from "../components/icons";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
@@ -13,13 +13,12 @@ import {
|
|||||||
maybeBindLinearElement,
|
maybeBindLinearElement,
|
||||||
bindOrUnbindLinearElement,
|
bindOrUnbindLinearElement,
|
||||||
} from "../element/binding";
|
} from "../element/binding";
|
||||||
import { isBindingElement, isLinearElement } from "../element/typeChecks";
|
import { isBindingElement } from "../element/typeChecks";
|
||||||
import { AppState } from "../types";
|
|
||||||
|
|
||||||
export const actionFinalize = register({
|
export const actionFinalize = register({
|
||||||
name: "finalize",
|
name: "finalize",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, _, { canvas, focusContainer, scene }) => {
|
perform: (elements, appState, _, { canvas, focusContainer }) => {
|
||||||
if (appState.editingLinearElement) {
|
if (appState.editingLinearElement) {
|
||||||
const { elementId, startBindingElement, endBindingElement } =
|
const { elementId, startBindingElement, endBindingElement } =
|
||||||
appState.editingLinearElement;
|
appState.editingLinearElement;
|
||||||
@@ -50,12 +49,8 @@ export const actionFinalize = register({
|
|||||||
|
|
||||||
let newElements = elements;
|
let newElements = elements;
|
||||||
|
|
||||||
const pendingImageElement =
|
if (appState.pendingImageElement) {
|
||||||
appState.pendingImageElementId &&
|
mutateElement(appState.pendingImageElement, { isDeleted: true }, false);
|
||||||
scene.getElement(appState.pendingImageElementId);
|
|
||||||
|
|
||||||
if (pendingImageElement) {
|
|
||||||
mutateElement(pendingImageElement, { isDeleted: true }, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.document.activeElement instanceof HTMLElement) {
|
if (window.document.activeElement instanceof HTMLElement) {
|
||||||
@@ -141,21 +136,21 @@ export const actionFinalize = register({
|
|||||||
) {
|
) {
|
||||||
resetCursor(canvas);
|
resetCursor(canvas);
|
||||||
}
|
}
|
||||||
|
const activeTool: any = { ...appState.activeTool };
|
||||||
let activeTool: AppState["activeTool"];
|
if (appState.activeTool.lastActiveToolBeforeEraser) {
|
||||||
if (appState.activeTool.type === "eraser") {
|
if (
|
||||||
activeTool = updateActiveTool(appState, {
|
typeof appState.activeTool.lastActiveToolBeforeEraser === "object" &&
|
||||||
...(appState.activeTool.lastActiveToolBeforeEraser || {
|
appState.activeTool.lastActiveToolBeforeEraser.type === "custom"
|
||||||
type: "selection",
|
) {
|
||||||
}),
|
activeTool.type = appState.activeTool.lastActiveToolBeforeEraser.type;
|
||||||
lastActiveToolBeforeEraser: null,
|
activeTool.customType =
|
||||||
});
|
appState.activeTool.lastActiveToolBeforeEraser.customType;
|
||||||
|
} else {
|
||||||
|
activeTool.type = appState.activeTool.lastActiveToolBeforeEraser;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
activeTool = updateActiveTool(appState, {
|
activeTool.type = "selection";
|
||||||
type: "selection",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements: newElements,
|
elements: newElements,
|
||||||
appState: {
|
appState: {
|
||||||
@@ -181,12 +176,7 @@ export const actionFinalize = register({
|
|||||||
[multiPointElement.id]: true,
|
[multiPointElement.id]: true,
|
||||||
}
|
}
|
||||||
: appState.selectedElementIds,
|
: appState.selectedElementIds,
|
||||||
// To select the linear element when user has finished mutipoint editing
|
pendingImageElement: null,
|
||||||
selectedLinearElement:
|
|
||||||
multiPointElement && isLinearElement(multiPointElement)
|
|
||||||
? new LinearElementEditor(multiPointElement, scene)
|
|
||||||
: appState.selectedLinearElement,
|
|
||||||
pendingImageElementId: null,
|
|
||||||
},
|
},
|
||||||
commitToHistory: appState.activeTool.type === "freedraw",
|
commitToHistory: appState.activeTool.type === "freedraw",
|
||||||
};
|
};
|
||||||
|
@@ -6,14 +6,10 @@ import { ExcalidrawElement, NonDeleted } from "../element/types";
|
|||||||
import { normalizeAngle, resizeSingleElement } from "../element/resizeElements";
|
import { normalizeAngle, resizeSingleElement } from "../element/resizeElements";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { getTransformHandles } from "../element/transformHandles";
|
import { getTransformHandles } from "../element/transformHandles";
|
||||||
|
import { isFreeDrawElement, isLinearElement } from "../element/typeChecks";
|
||||||
import { updateBoundElements } from "../element/binding";
|
import { updateBoundElements } from "../element/binding";
|
||||||
import { arrayToMap } from "../utils";
|
|
||||||
import {
|
|
||||||
getElementAbsoluteCoords,
|
|
||||||
getElementPointsCoords,
|
|
||||||
} from "../element/bounds";
|
|
||||||
import { isLinearElement } from "../element/typeChecks";
|
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||||
|
import { arrayToMap } from "../utils";
|
||||||
|
|
||||||
const enableActionFlipHorizontal = (
|
const enableActionFlipHorizontal = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
@@ -122,6 +118,13 @@ const flipElement = (
|
|||||||
const height = element.height;
|
const height = element.height;
|
||||||
const originalAngle = normalizeAngle(element.angle);
|
const originalAngle = normalizeAngle(element.angle);
|
||||||
|
|
||||||
|
let finalOffsetX = 0;
|
||||||
|
if (isLinearElement(element) || isFreeDrawElement(element)) {
|
||||||
|
finalOffsetX =
|
||||||
|
element.points.reduce((max, point) => Math.max(max, point[0]), 0) * 2 -
|
||||||
|
element.width;
|
||||||
|
}
|
||||||
|
|
||||||
// Rotate back to zero, if necessary
|
// Rotate back to zero, if necessary
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
angle: normalizeAngle(0),
|
angle: normalizeAngle(0),
|
||||||
@@ -129,6 +132,7 @@ const flipElement = (
|
|||||||
// Flip unrotated by pulling TransformHandle to opposite side
|
// Flip unrotated by pulling TransformHandle to opposite side
|
||||||
const transformHandles = getTransformHandles(element, appState.zoom);
|
const transformHandles = getTransformHandles(element, appState.zoom);
|
||||||
let usingNWHandle = true;
|
let usingNWHandle = true;
|
||||||
|
let newNCoordsX = 0;
|
||||||
let nHandle = transformHandles.nw;
|
let nHandle = transformHandles.nw;
|
||||||
if (!nHandle) {
|
if (!nHandle) {
|
||||||
// Use ne handle instead
|
// Use ne handle instead
|
||||||
@@ -142,51 +146,30 @@ const flipElement = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let finalOffsetX = 0;
|
|
||||||
if (isLinearElement(element) && element.points.length < 3) {
|
|
||||||
finalOffsetX =
|
|
||||||
element.points.reduce((max, point) => Math.max(max, point[0]), 0) * 2 -
|
|
||||||
element.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
let initialPointsCoords;
|
|
||||||
if (isLinearElement(element)) {
|
if (isLinearElement(element)) {
|
||||||
initialPointsCoords = getElementPointsCoords(
|
|
||||||
element,
|
|
||||||
element.points,
|
|
||||||
element.strokeSharpness,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const initialElementAbsoluteCoords = getElementAbsoluteCoords(element);
|
|
||||||
|
|
||||||
if (isLinearElement(element) && element.points.length < 3) {
|
|
||||||
for (let index = 1; index < element.points.length; index++) {
|
for (let index = 1; index < element.points.length; index++) {
|
||||||
LinearElementEditor.movePoints(element, [
|
LinearElementEditor.movePoints(element, [
|
||||||
{
|
{ index, point: [-element.points[index][0], element.points[index][1]] },
|
||||||
index,
|
|
||||||
point: [-element.points[index][0], element.points[index][1]],
|
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
LinearElementEditor.normalizePoints(element);
|
LinearElementEditor.normalizePoints(element);
|
||||||
} else {
|
} else {
|
||||||
const elWidth = initialPointsCoords
|
// calculate new x-coord for transformation
|
||||||
? initialPointsCoords[2] - initialPointsCoords[0]
|
newNCoordsX = usingNWHandle ? element.x + 2 * width : element.x - 2 * width;
|
||||||
: initialElementAbsoluteCoords[2] - initialElementAbsoluteCoords[0];
|
|
||||||
|
|
||||||
const startPoint = initialPointsCoords
|
|
||||||
? [initialPointsCoords[0], initialPointsCoords[1]]
|
|
||||||
: [initialElementAbsoluteCoords[0], initialElementAbsoluteCoords[1]];
|
|
||||||
|
|
||||||
resizeSingleElement(
|
resizeSingleElement(
|
||||||
new Map().set(element.id, element),
|
new Map().set(element.id, element),
|
||||||
false,
|
true,
|
||||||
element,
|
element,
|
||||||
usingNWHandle ? "nw" : "ne",
|
usingNWHandle ? "nw" : "ne",
|
||||||
true,
|
false,
|
||||||
usingNWHandle ? startPoint[0] + elWidth : startPoint[0] - elWidth,
|
newNCoordsX,
|
||||||
startPoint[1],
|
nHandle[1],
|
||||||
);
|
);
|
||||||
|
// fix the size to account for handle sizes
|
||||||
|
mutateElement(element, {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate by (360 degrees - original angle)
|
// Rotate by (360 degrees - original angle)
|
||||||
@@ -203,34 +186,9 @@ const flipElement = (
|
|||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
x: originalX + finalOffsetX,
|
x: originalX + finalOffsetX,
|
||||||
y: originalY,
|
y: originalY,
|
||||||
width,
|
|
||||||
height,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
updateBoundElements(element);
|
updateBoundElements(element);
|
||||||
|
|
||||||
if (initialPointsCoords && isLinearElement(element)) {
|
|
||||||
// Adjusting origin because when a beizer curve path exceeds min/max points it offsets the origin.
|
|
||||||
// There's still room for improvement since when the line roughness is > 1
|
|
||||||
// we still have a small offset of the origin when fliipping the element.
|
|
||||||
const finalPointsCoords = getElementPointsCoords(
|
|
||||||
element,
|
|
||||||
element.points,
|
|
||||||
element.strokeSharpness,
|
|
||||||
);
|
|
||||||
|
|
||||||
const topLeftCoordsDiff = initialPointsCoords[0] - finalPointsCoords[0];
|
|
||||||
const topRightCoordDiff = initialPointsCoords[2] - finalPointsCoords[2];
|
|
||||||
|
|
||||||
const coordsDiff = topLeftCoordsDiff + topRightCoordDiff;
|
|
||||||
|
|
||||||
mutateElement(element, {
|
|
||||||
x: element.x + coordsDiff * 0.5,
|
|
||||||
y: element.y,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const rotateElement = (element: ExcalidrawElement, rotationAngle: number) => {
|
const rotateElement = (element: ExcalidrawElement, rotationAngle: number) => {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { KEYS } from "../keys";
|
import { CODES, KEYS } from "../keys";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { arrayToMap, getShortcutKey } from "../utils";
|
import { arrayToMap, getShortcutKey } from "../utils";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
@@ -132,7 +132,7 @@ export const actionGroup = register({
|
|||||||
contextItemPredicate: (elements, appState) =>
|
contextItemPredicate: (elements, appState) =>
|
||||||
enableActionGroup(elements, appState),
|
enableActionGroup(elements, appState),
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
!event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.key === KEYS.G,
|
!event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.code === CODES.G,
|
||||||
PanelComponent: ({ elements, appState, updateData }) => (
|
PanelComponent: ({ elements, appState, updateData }) => (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
hidden={!enableActionGroup(elements, appState)}
|
hidden={!enableActionGroup(elements, appState)}
|
||||||
@@ -189,9 +189,7 @@ export const actionUngroup = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) =>
|
keyTest: (event) =>
|
||||||
event.shiftKey &&
|
event.shiftKey && event[KEYS.CTRL_OR_CMD] && event.code === CODES.G,
|
||||||
event[KEYS.CTRL_OR_CMD] &&
|
|
||||||
event.key === KEYS.G.toUpperCase(),
|
|
||||||
contextItemLabel: "labels.ungroup",
|
contextItemLabel: "labels.ungroup",
|
||||||
contextItemPredicate: (elements, appState) =>
|
contextItemPredicate: (elements, appState) =>
|
||||||
getSelectedGroupIds(appState).length > 0,
|
getSelectedGroupIds(appState).length > 0,
|
||||||
|
@@ -1,49 +0,0 @@
|
|||||||
import { getNonDeletedElements } from "../element";
|
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
|
||||||
import { isLinearElement } from "../element/typeChecks";
|
|
||||||
import { ExcalidrawLinearElement } from "../element/types";
|
|
||||||
import { getSelectedElements } from "../scene";
|
|
||||||
import { register } from "./register";
|
|
||||||
|
|
||||||
export const actionToggleLinearEditor = register({
|
|
||||||
name: "toggleLinearEditor",
|
|
||||||
trackEvent: {
|
|
||||||
category: "element",
|
|
||||||
},
|
|
||||||
contextItemPredicate: (elements, appState) => {
|
|
||||||
const selectedElements = getSelectedElements(elements, appState);
|
|
||||||
if (selectedElements.length === 1 && isLinearElement(selectedElements[0])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
perform(elements, appState, _, app) {
|
|
||||||
const selectedElement = getSelectedElements(
|
|
||||||
getNonDeletedElements(elements),
|
|
||||||
appState,
|
|
||||||
true,
|
|
||||||
)[0] as ExcalidrawLinearElement;
|
|
||||||
|
|
||||||
const editingLinearElement =
|
|
||||||
appState.editingLinearElement?.elementId === selectedElement.id
|
|
||||||
? null
|
|
||||||
: new LinearElementEditor(selectedElement, app.scene);
|
|
||||||
return {
|
|
||||||
appState: {
|
|
||||||
...appState,
|
|
||||||
editingLinearElement,
|
|
||||||
},
|
|
||||||
commitToHistory: false,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
contextItemLabel: (elements, appState) => {
|
|
||||||
const selectedElement = getSelectedElements(
|
|
||||||
getNonDeletedElements(elements),
|
|
||||||
appState,
|
|
||||||
true,
|
|
||||||
)[0] as ExcalidrawLinearElement;
|
|
||||||
return appState.editingLinearElement?.elementId === selectedElement.id
|
|
||||||
? "labels.lineEditor.exit"
|
|
||||||
: "labels.lineEditor.edit";
|
|
||||||
},
|
|
||||||
});
|
|
@@ -4,7 +4,7 @@ import { t } from "../i18n";
|
|||||||
import { showSelectedShapeActions, getNonDeletedElements } from "../element";
|
import { showSelectedShapeActions, getNonDeletedElements } from "../element";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils";
|
import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils";
|
||||||
import { KEYS } from "../keys";
|
import { CODES, KEYS } from "../keys";
|
||||||
import { HelpIcon } from "../components/HelpIcon";
|
import { HelpIcon } from "../components/HelpIcon";
|
||||||
|
|
||||||
export const actionToggleCanvasMenu = register({
|
export const actionToggleCanvasMenu = register({
|
||||||
@@ -67,7 +67,7 @@ export const actionFullScreen = register({
|
|||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) => event.key === KEYS.F && !event[KEYS.CTRL_OR_CMD],
|
keyTest: (event) => event.code === CODES.F && !event[KEYS.CTRL_OR_CMD],
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionShortcuts = register({
|
export const actionShortcuts = register({
|
||||||
|
@@ -31,7 +31,16 @@ export const actionGoToCollaborator = register({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ appState, updateData, data }) => {
|
PanelComponent: ({ appState, updateData, data }) => {
|
||||||
const [clientId, collaborator] = data as [string, Collaborator];
|
const clientId: string | undefined = data?.id;
|
||||||
|
if (!clientId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const collaborator = appState.collaborators.get(clientId);
|
||||||
|
|
||||||
|
if (!collaborator) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const { background, stroke } = getClientColors(clientId, appState);
|
const { background, stroke } = getClientColors(clientId, appState);
|
||||||
|
|
||||||
@@ -41,7 +50,7 @@ export const actionGoToCollaborator = register({
|
|||||||
border={stroke}
|
border={stroke}
|
||||||
onClick={() => updateData(collaborator.pointer)}
|
onClick={() => updateData(collaborator.pointer)}
|
||||||
name={collaborator.username || ""}
|
name={collaborator.username || ""}
|
||||||
src={collaborator.avatarUrl}
|
src={collaborator.src}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@@ -485,14 +485,10 @@ export const actionChangeOpacity = register({
|
|||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value) => {
|
perform: (elements, appState, value) => {
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(
|
elements: changeProperty(elements, appState, (el) =>
|
||||||
elements,
|
newElementWith(el, {
|
||||||
appState,
|
opacity: value,
|
||||||
(el) =>
|
}),
|
||||||
newElementWith(el, {
|
|
||||||
opacity: value,
|
|
||||||
}),
|
|
||||||
true,
|
|
||||||
),
|
),
|
||||||
appState: { ...appState, currentItemOpacity: value },
|
appState: { ...appState, currentItemOpacity: value },
|
||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
|
@@ -2,43 +2,29 @@ import { KEYS } from "../keys";
|
|||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { selectGroupsForSelectedElements } from "../groups";
|
import { selectGroupsForSelectedElements } from "../groups";
|
||||||
import { getNonDeletedElements, isTextElement } from "../element";
|
import { getNonDeletedElements, isTextElement } from "../element";
|
||||||
import { ExcalidrawElement } from "../element/types";
|
|
||||||
import { isLinearElement } from "../element/typeChecks";
|
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
|
||||||
|
|
||||||
export const actionSelectAll = register({
|
export const actionSelectAll = register({
|
||||||
name: "selectAll",
|
name: "selectAll",
|
||||||
trackEvent: { category: "canvas" },
|
trackEvent: { category: "canvas" },
|
||||||
perform: (elements, appState, value, app) => {
|
perform: (elements, appState) => {
|
||||||
if (appState.editingLinearElement) {
|
if (appState.editingLinearElement) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const selectedElementIds = elements.reduce(
|
|
||||||
(map: Record<ExcalidrawElement["id"], true>, element) => {
|
|
||||||
if (
|
|
||||||
!element.isDeleted &&
|
|
||||||
!(isTextElement(element) && element.containerId) &&
|
|
||||||
!element.locked
|
|
||||||
) {
|
|
||||||
map[element.id] = true;
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
appState: selectGroupsForSelectedElements(
|
appState: selectGroupsForSelectedElements(
|
||||||
{
|
{
|
||||||
...appState,
|
...appState,
|
||||||
selectedLinearElement:
|
|
||||||
// single linear element selected
|
|
||||||
Object.keys(selectedElementIds).length === 1 &&
|
|
||||||
isLinearElement(elements[0])
|
|
||||||
? new LinearElementEditor(elements[0], app.scene)
|
|
||||||
: null,
|
|
||||||
editingGroupId: null,
|
editingGroupId: null,
|
||||||
selectedElementIds,
|
selectedElementIds: elements.reduce((map, element) => {
|
||||||
|
if (
|
||||||
|
!element.isDeleted &&
|
||||||
|
!(isTextElement(element) && element.containerId) &&
|
||||||
|
element.locked === false
|
||||||
|
) {
|
||||||
|
map[element.id] = true;
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, {} as any),
|
||||||
},
|
},
|
||||||
getNonDeletedElements(elements),
|
getNonDeletedElements(elements),
|
||||||
),
|
),
|
||||||
|
@@ -48,7 +48,7 @@ describe("actionStyles", () => {
|
|||||||
Keyboard.withModifierKeys({ ctrl: true, alt: true }, () => {
|
Keyboard.withModifierKeys({ ctrl: true, alt: true }, () => {
|
||||||
Keyboard.codeDown(CODES.C);
|
Keyboard.codeDown(CODES.C);
|
||||||
});
|
});
|
||||||
const secondRect = JSON.parse(copiedStyles)[0];
|
const secondRect = JSON.parse(copiedStyles);
|
||||||
expect(secondRect.id).toBe(h.elements[1].id);
|
expect(secondRect.id).toBe(h.elements[1].id);
|
||||||
|
|
||||||
mouse.reset();
|
mouse.reset();
|
||||||
|
@@ -6,15 +6,13 @@ import {
|
|||||||
import { CODES, KEYS } from "../keys";
|
import { CODES, KEYS } from "../keys";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { newElementWith } from "../element/mutateElement";
|
import { mutateElement, newElementWith } from "../element/mutateElement";
|
||||||
import {
|
import {
|
||||||
DEFAULT_FONT_SIZE,
|
DEFAULT_FONT_SIZE,
|
||||||
DEFAULT_FONT_FAMILY,
|
DEFAULT_FONT_FAMILY,
|
||||||
DEFAULT_TEXT_ALIGN,
|
DEFAULT_TEXT_ALIGN,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import { getBoundTextElement } from "../element/textElement";
|
import { getContainerElement } from "../element/textElement";
|
||||||
import { hasBoundTextElement } from "../element/typeChecks";
|
|
||||||
import { getSelectedElements } from "../scene";
|
|
||||||
|
|
||||||
// `copiedStyles` is exported only for tests.
|
// `copiedStyles` is exported only for tests.
|
||||||
export let copiedStyles: string = "{}";
|
export let copiedStyles: string = "{}";
|
||||||
@@ -23,20 +21,14 @@ export const actionCopyStyles = register({
|
|||||||
name: "copyStyles",
|
name: "copyStyles",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements, appState) => {
|
perform: (elements, appState) => {
|
||||||
const elementsCopied = [];
|
|
||||||
const element = elements.find((el) => appState.selectedElementIds[el.id]);
|
const element = elements.find((el) => appState.selectedElementIds[el.id]);
|
||||||
elementsCopied.push(element);
|
|
||||||
if (element && hasBoundTextElement(element)) {
|
|
||||||
const boundTextElement = getBoundTextElement(element);
|
|
||||||
elementsCopied.push(boundTextElement);
|
|
||||||
}
|
|
||||||
if (element) {
|
if (element) {
|
||||||
copiedStyles = JSON.stringify(elementsCopied);
|
copiedStyles = JSON.stringify(element);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
toast: { message: t("toast.copyStyles") },
|
toastMessage: t("toast.copyStyles"),
|
||||||
},
|
},
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
@@ -50,62 +42,31 @@ export const actionPasteStyles = register({
|
|||||||
name: "pasteStyles",
|
name: "pasteStyles",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements, appState) => {
|
perform: (elements, appState) => {
|
||||||
const elementsCopied = JSON.parse(copiedStyles);
|
const pastedElement = JSON.parse(copiedStyles);
|
||||||
const pastedElement = elementsCopied[0];
|
|
||||||
const boundTextElement = elementsCopied[1];
|
|
||||||
if (!isExcalidrawElement(pastedElement)) {
|
if (!isExcalidrawElement(pastedElement)) {
|
||||||
return { elements, commitToHistory: false };
|
return { elements, commitToHistory: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedElements = getSelectedElements(elements, appState, true);
|
|
||||||
const selectedElementIds = selectedElements.map((element) => element.id);
|
|
||||||
return {
|
return {
|
||||||
elements: elements.map((element) => {
|
elements: elements.map((element) => {
|
||||||
if (selectedElementIds.includes(element.id)) {
|
if (appState.selectedElementIds[element.id]) {
|
||||||
let elementStylesToCopyFrom = pastedElement;
|
const newElement = newElementWith(element, {
|
||||||
if (isTextElement(element) && element.containerId) {
|
backgroundColor: pastedElement?.backgroundColor,
|
||||||
elementStylesToCopyFrom = boundTextElement;
|
strokeWidth: pastedElement?.strokeWidth,
|
||||||
}
|
strokeColor: pastedElement?.strokeColor,
|
||||||
if (!elementStylesToCopyFrom) {
|
strokeStyle: pastedElement?.strokeStyle,
|
||||||
return element;
|
fillStyle: pastedElement?.fillStyle,
|
||||||
}
|
opacity: pastedElement?.opacity,
|
||||||
let newElement = newElementWith(element, {
|
roughness: pastedElement?.roughness,
|
||||||
backgroundColor: elementStylesToCopyFrom?.backgroundColor,
|
|
||||||
strokeWidth: elementStylesToCopyFrom?.strokeWidth,
|
|
||||||
strokeColor: elementStylesToCopyFrom?.strokeColor,
|
|
||||||
strokeStyle: elementStylesToCopyFrom?.strokeStyle,
|
|
||||||
fillStyle: elementStylesToCopyFrom?.fillStyle,
|
|
||||||
opacity: elementStylesToCopyFrom?.opacity,
|
|
||||||
roughness: elementStylesToCopyFrom?.roughness,
|
|
||||||
});
|
});
|
||||||
|
if (isTextElement(newElement) && isTextElement(element)) {
|
||||||
if (isTextElement(newElement)) {
|
mutateElement(newElement, {
|
||||||
newElement = newElementWith(newElement, {
|
fontSize: pastedElement?.fontSize || DEFAULT_FONT_SIZE,
|
||||||
fontSize: elementStylesToCopyFrom?.fontSize || DEFAULT_FONT_SIZE,
|
fontFamily: pastedElement?.fontFamily || DEFAULT_FONT_FAMILY,
|
||||||
fontFamily:
|
textAlign: pastedElement?.textAlign || DEFAULT_TEXT_ALIGN,
|
||||||
elementStylesToCopyFrom?.fontFamily || DEFAULT_FONT_FAMILY,
|
|
||||||
textAlign:
|
|
||||||
elementStylesToCopyFrom?.textAlign || DEFAULT_TEXT_ALIGN,
|
|
||||||
});
|
});
|
||||||
let container = null;
|
|
||||||
if (newElement.containerId) {
|
|
||||||
container =
|
|
||||||
selectedElements.find(
|
|
||||||
(element) =>
|
|
||||||
isTextElement(newElement) &&
|
|
||||||
element.id === newElement.containerId,
|
|
||||||
) || null;
|
|
||||||
}
|
|
||||||
redrawTextBoundingBox(newElement, container);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newElement.type === "arrow") {
|
redrawTextBoundingBox(newElement, getContainerElement(newElement));
|
||||||
newElement = newElementWith(newElement, {
|
|
||||||
startArrowhead: elementStylesToCopyFrom.startArrowhead,
|
|
||||||
endArrowhead: elementStylesToCopyFrom.endArrowhead,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newElement;
|
return newElement;
|
||||||
}
|
}
|
||||||
return element;
|
return element;
|
||||||
|
@@ -17,19 +17,16 @@ export const actionToggleLock = register({
|
|||||||
|
|
||||||
const operation = getOperation(selectedElements);
|
const operation = getOperation(selectedElements);
|
||||||
const selectedElementsMap = arrayToMap(selectedElements);
|
const selectedElementsMap = arrayToMap(selectedElements);
|
||||||
const lock = operation === "lock";
|
|
||||||
return {
|
return {
|
||||||
elements: elements.map((element) => {
|
elements: elements.map((element) => {
|
||||||
if (!selectedElementsMap.has(element.id)) {
|
if (!selectedElementsMap.has(element.id)) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
return newElementWith(element, { locked: lock });
|
return newElementWith(element, { locked: operation === "lock" });
|
||||||
}),
|
}),
|
||||||
appState: {
|
appState,
|
||||||
...appState,
|
|
||||||
selectedLinearElement: lock ? null : appState.selectedLinearElement,
|
|
||||||
},
|
|
||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@@ -85,4 +85,3 @@ export { actionToggleStats } from "./actionToggleStats";
|
|||||||
export { actionUnbindText, actionBindText } from "./actionBoundText";
|
export { actionUnbindText, actionBindText } from "./actionBoundText";
|
||||||
export { actionLink } from "../element/Hyperlink";
|
export { actionLink } from "../element/Hyperlink";
|
||||||
export { actionToggleLock } from "./actionToggleLock";
|
export { actionToggleLock } from "./actionToggleLock";
|
||||||
export { actionToggleLinearEditor } from "./actionLinearEditor";
|
|
||||||
|
@@ -30,7 +30,7 @@ const trackAction = (
|
|||||||
trackEvent(
|
trackEvent(
|
||||||
action.trackEvent.category,
|
action.trackEvent.category,
|
||||||
action.trackEvent.action || action.name,
|
action.trackEvent.action || action.name,
|
||||||
`${source} (${app.device.isMobile ? "mobile" : "desktop"})`,
|
`${source} (${app.deviceType.isMobile ? "mobile" : "desktop"})`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,6 +137,7 @@ export class ActionManager {
|
|||||||
*/
|
*/
|
||||||
renderAction = (name: ActionName, data?: PanelComponentProps["data"]) => {
|
renderAction = (name: ActionName, data?: PanelComponentProps["data"]) => {
|
||||||
const canvasActions = this.app.props.UIOptions.canvasActions;
|
const canvasActions = this.app.props.UIOptions.canvasActions;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.actions[name] &&
|
this.actions[name] &&
|
||||||
"PanelComponent" in this.actions[name] &&
|
"PanelComponent" in this.actions[name] &&
|
||||||
@@ -146,7 +147,6 @@ export class ActionManager {
|
|||||||
) {
|
) {
|
||||||
const action = this.actions[name];
|
const action = this.actions[name];
|
||||||
const PanelComponent = action.PanelComponent!;
|
const PanelComponent = action.PanelComponent!;
|
||||||
PanelComponent.displayName = "PanelComponent";
|
|
||||||
const elements = this.getElementsIncludingDeleted();
|
const elements = this.getElementsIncludingDeleted();
|
||||||
const appState = this.getAppState();
|
const appState = this.getAppState();
|
||||||
const updateData = (formState?: any) => {
|
const updateData = (formState?: any) => {
|
||||||
|
@@ -6,6 +6,7 @@ import {
|
|||||||
ExcalidrawProps,
|
ExcalidrawProps,
|
||||||
BinaryFiles,
|
BinaryFiles,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
|
import { ToolButtonSize } from "../components/ToolButton";
|
||||||
|
|
||||||
export type ActionSource = "ui" | "keyboard" | "contextMenu" | "api";
|
export type ActionSource = "ui" | "keyboard" | "contextMenu" | "api";
|
||||||
|
|
||||||
@@ -111,15 +112,14 @@ export type ActionName =
|
|||||||
| "hyperlink"
|
| "hyperlink"
|
||||||
| "eraser"
|
| "eraser"
|
||||||
| "bindText"
|
| "bindText"
|
||||||
| "toggleLock"
|
| "toggleLock";
|
||||||
| "toggleLinearEditor";
|
|
||||||
|
|
||||||
export type PanelComponentProps = {
|
export type PanelComponentProps = {
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
updateData: (formData?: any) => void;
|
updateData: (formData?: any) => void;
|
||||||
appProps: ExcalidrawProps;
|
appProps: ExcalidrawProps;
|
||||||
data?: Record<string, any>;
|
data?: Partial<{ id: string; size: ToolButtonSize }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface Action {
|
export interface Action {
|
||||||
|
@@ -43,7 +43,6 @@ export const getDefaultAppState = (): Omit<
|
|||||||
editingLinearElement: null,
|
editingLinearElement: null,
|
||||||
activeTool: {
|
activeTool: {
|
||||||
type: "selection",
|
type: "selection",
|
||||||
customType: null,
|
|
||||||
locked: false,
|
locked: false,
|
||||||
lastActiveToolBeforeEraser: null,
|
lastActiveToolBeforeEraser: null,
|
||||||
},
|
},
|
||||||
@@ -57,7 +56,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
fileHandle: null,
|
fileHandle: null,
|
||||||
gridSize: null,
|
gridSize: null,
|
||||||
isBindingEnabled: true,
|
isBindingEnabled: true,
|
||||||
isSidebarDocked: false,
|
isLibraryOpen: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isResizing: false,
|
isResizing: false,
|
||||||
isRotating: false,
|
isRotating: false,
|
||||||
@@ -66,7 +65,6 @@ export const getDefaultAppState = (): Omit<
|
|||||||
name: `${t("labels.untitled")}-${getDateTime()}`,
|
name: `${t("labels.untitled")}-${getDateTime()}`,
|
||||||
openMenu: null,
|
openMenu: null,
|
||||||
openPopup: null,
|
openPopup: null,
|
||||||
openSidebar: null,
|
|
||||||
pasteDialog: { shown: false, data: null },
|
pasteDialog: { shown: false, data: null },
|
||||||
previousSelectedElementIds: {},
|
previousSelectedElementIds: {},
|
||||||
resizingElement: null,
|
resizingElement: null,
|
||||||
@@ -81,16 +79,15 @@ export const getDefaultAppState = (): Omit<
|
|||||||
showStats: false,
|
showStats: false,
|
||||||
startBoundElement: null,
|
startBoundElement: null,
|
||||||
suggestedBindings: [],
|
suggestedBindings: [],
|
||||||
toast: null,
|
toastMessage: null,
|
||||||
viewBackgroundColor: oc.white,
|
viewBackgroundColor: oc.white,
|
||||||
zenModeEnabled: false,
|
zenModeEnabled: false,
|
||||||
zoom: {
|
zoom: {
|
||||||
value: 1 as NormalizedZoomValue,
|
value: 1 as NormalizedZoomValue,
|
||||||
},
|
},
|
||||||
viewModeEnabled: false,
|
viewModeEnabled: false,
|
||||||
pendingImageElementId: null,
|
pendingImageElement: null,
|
||||||
showHyperlinkPopup: false,
|
showHyperlinkPopup: false,
|
||||||
selectedLinearElement: null,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -148,7 +145,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 },
|
||||||
isSidebarDocked: { browser: true, export: false, server: false },
|
isLibraryOpen: { browser: false, 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 },
|
||||||
@@ -159,7 +156,6 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
offsetTop: { browser: false, export: false, server: false },
|
offsetTop: { browser: false, export: false, server: false },
|
||||||
openMenu: { browser: true, export: false, server: false },
|
openMenu: { browser: true, export: false, server: false },
|
||||||
openPopup: { browser: false, export: false, server: false },
|
openPopup: { browser: false, export: false, server: false },
|
||||||
openSidebar: { browser: true, export: false, server: false },
|
|
||||||
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 },
|
||||||
@@ -174,15 +170,14 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
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 },
|
||||||
toast: { browser: false, export: false, server: false },
|
toastMessage: { browser: false, export: false, server: false },
|
||||||
viewBackgroundColor: { browser: true, export: true, server: true },
|
viewBackgroundColor: { browser: true, export: true, server: true },
|
||||||
width: { browser: false, export: false, server: false },
|
width: { browser: false, export: false, server: false },
|
||||||
zenModeEnabled: { browser: true, export: false, server: false },
|
zenModeEnabled: { browser: true, export: false, server: false },
|
||||||
zoom: { browser: true, export: false, server: false },
|
zoom: { browser: true, export: false, server: false },
|
||||||
viewModeEnabled: { browser: false, export: false, server: false },
|
viewModeEnabled: { browser: false, export: false, server: false },
|
||||||
pendingImageElementId: { browser: false, export: false, server: false },
|
pendingImageElement: { browser: false, export: false, server: false },
|
||||||
showHyperlinkPopup: { browser: false, export: false, server: false },
|
showHyperlinkPopup: { browser: false, export: false, server: false },
|
||||||
selectedLinearElement: { browser: true, export: false, server: false },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const _clearAppStateForStorage = <
|
const _clearAppStateForStorage = <
|
||||||
|
@@ -1,121 +0,0 @@
|
|||||||
import {
|
|
||||||
Spreadsheet,
|
|
||||||
tryParseCells,
|
|
||||||
tryParseNumber,
|
|
||||||
VALID_SPREADSHEET,
|
|
||||||
} from "./charts";
|
|
||||||
|
|
||||||
describe("charts", () => {
|
|
||||||
describe("tryParseNumber", () => {
|
|
||||||
it.each<[string, number]>([
|
|
||||||
["1", 1],
|
|
||||||
["0", 0],
|
|
||||||
["-1", -1],
|
|
||||||
["0.1", 0.1],
|
|
||||||
[".1", 0.1],
|
|
||||||
["1.", 1],
|
|
||||||
["424.", 424],
|
|
||||||
["$1", 1],
|
|
||||||
["-.1", -0.1],
|
|
||||||
["-$1", -1],
|
|
||||||
["$-1", -1],
|
|
||||||
])("should correctly identify %s as numbers", (given, expected) => {
|
|
||||||
expect(tryParseNumber(given)).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each<[string]>([["a"], ["$"], ["$a"], ["-$a"]])(
|
|
||||||
"should correctly identify %s as not a number",
|
|
||||||
(given) => {
|
|
||||||
expect(tryParseNumber(given)).toBeNull();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("tryParseCells", () => {
|
|
||||||
it("Successfully parses a spreadsheet", () => {
|
|
||||||
const spreadsheet = [
|
|
||||||
["time", "value"],
|
|
||||||
["01:00", "61"],
|
|
||||||
["02:00", "-60"],
|
|
||||||
["03:00", "85"],
|
|
||||||
["04:00", "-67"],
|
|
||||||
["05:00", "54"],
|
|
||||||
["06:00", "95"],
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = tryParseCells(spreadsheet);
|
|
||||||
|
|
||||||
expect(result.type).toBe(VALID_SPREADSHEET);
|
|
||||||
|
|
||||||
const { title, labels, values } = (
|
|
||||||
result as { type: typeof VALID_SPREADSHEET; spreadsheet: Spreadsheet }
|
|
||||||
).spreadsheet;
|
|
||||||
|
|
||||||
expect(title).toEqual("value");
|
|
||||||
expect(labels).toEqual([
|
|
||||||
"01:00",
|
|
||||||
"02:00",
|
|
||||||
"03:00",
|
|
||||||
"04:00",
|
|
||||||
"05:00",
|
|
||||||
"06:00",
|
|
||||||
]);
|
|
||||||
expect(values).toEqual([61, -60, 85, -67, 54, 95]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Uses the second column as the label if it is not a number", () => {
|
|
||||||
const spreadsheet = [
|
|
||||||
["time", "value"],
|
|
||||||
["01:00", "61"],
|
|
||||||
["02:00", "-60"],
|
|
||||||
["03:00", "85"],
|
|
||||||
["04:00", "-67"],
|
|
||||||
["05:00", "54"],
|
|
||||||
["06:00", "95"],
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = tryParseCells(spreadsheet);
|
|
||||||
|
|
||||||
expect(result.type).toBe(VALID_SPREADSHEET);
|
|
||||||
|
|
||||||
const { title, labels, values } = (
|
|
||||||
result as { type: typeof VALID_SPREADSHEET; spreadsheet: Spreadsheet }
|
|
||||||
).spreadsheet;
|
|
||||||
|
|
||||||
expect(title).toEqual("value");
|
|
||||||
expect(labels).toEqual([
|
|
||||||
"01:00",
|
|
||||||
"02:00",
|
|
||||||
"03:00",
|
|
||||||
"04:00",
|
|
||||||
"05:00",
|
|
||||||
"06:00",
|
|
||||||
]);
|
|
||||||
expect(values).toEqual([61, -60, 85, -67, 54, 95]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("treats the first column as labels if both columns are numbers", () => {
|
|
||||||
const spreadsheet = [
|
|
||||||
["time", "value"],
|
|
||||||
["01", "61"],
|
|
||||||
["02", "-60"],
|
|
||||||
["03", "85"],
|
|
||||||
["04", "-67"],
|
|
||||||
["05", "54"],
|
|
||||||
["06", "95"],
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = tryParseCells(spreadsheet);
|
|
||||||
|
|
||||||
expect(result.type).toBe(VALID_SPREADSHEET);
|
|
||||||
|
|
||||||
const { title, labels, values } = (
|
|
||||||
result as { type: typeof VALID_SPREADSHEET; spreadsheet: Spreadsheet }
|
|
||||||
).spreadsheet;
|
|
||||||
|
|
||||||
expect(title).toEqual("value");
|
|
||||||
expect(labels).toEqual(["01", "02", "03", "04", "05", "06"]);
|
|
||||||
expect(values).toEqual([61, -60, 85, -67, 54, 95]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -29,24 +29,18 @@ type ParseSpreadsheetResult =
|
|||||||
| { type: typeof NOT_SPREADSHEET; reason: string }
|
| { type: typeof NOT_SPREADSHEET; reason: string }
|
||||||
| { type: typeof VALID_SPREADSHEET; spreadsheet: Spreadsheet };
|
| { type: typeof VALID_SPREADSHEET; spreadsheet: Spreadsheet };
|
||||||
|
|
||||||
/**
|
const tryParseNumber = (s: string): number | null => {
|
||||||
* @private exported for testing
|
const match = /^[$€£¥₩]?([0-9,]+(\.[0-9]+)?)$/.exec(s);
|
||||||
*/
|
|
||||||
export const tryParseNumber = (s: string): number | null => {
|
|
||||||
const match = /^([-+]?)[$€£¥₩]?([-+]?)([\d.,]+)[%]?$/.exec(s);
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return parseFloat(`${(match[1] || match[2]) + match[3]}`.replace(/,/g, ""));
|
return parseFloat(match[1].replace(/,/g, ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
const isNumericColumn = (lines: string[][], columnIndex: number) =>
|
const isNumericColumn = (lines: string[][], columnIndex: number) =>
|
||||||
lines.slice(1).every((line) => tryParseNumber(line[columnIndex]) !== null);
|
lines.slice(1).every((line) => tryParseNumber(line[columnIndex]) !== null);
|
||||||
|
|
||||||
/**
|
const tryParseCells = (cells: string[][]): ParseSpreadsheetResult => {
|
||||||
* @private exported for testing
|
|
||||||
*/
|
|
||||||
export const tryParseCells = (cells: string[][]): ParseSpreadsheetResult => {
|
|
||||||
const numCols = cells[0].length;
|
const numCols = cells[0].length;
|
||||||
|
|
||||||
if (numCols > 2) {
|
if (numCols > 2) {
|
||||||
@@ -77,16 +71,13 @@ export const tryParseCells = (cells: string[][]): ParseSpreadsheetResult => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const labelColumnNumeric = isNumericColumn(cells, 0);
|
const valueColumnIndex = isNumericColumn(cells, 0) ? 0 : 1;
|
||||||
const valueColumnNumeric = isNumericColumn(cells, 1);
|
|
||||||
|
|
||||||
if (!labelColumnNumeric && !valueColumnNumeric) {
|
if (!isNumericColumn(cells, valueColumnIndex)) {
|
||||||
return { type: NOT_SPREADSHEET, reason: "Value is not numeric" };
|
return { type: NOT_SPREADSHEET, reason: "Value is not numeric" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const [labelColumnIndex, valueColumnIndex] = valueColumnNumeric
|
const labelColumnIndex = (valueColumnIndex + 1) % 2;
|
||||||
? [0, 1]
|
|
||||||
: [1, 0];
|
|
||||||
const hasHeader = tryParseNumber(cells[0][valueColumnIndex]) === null;
|
const hasHeader = tryParseNumber(cells[0][valueColumnIndex]) === null;
|
||||||
const rows = hasHeader ? cells.slice(1) : cells;
|
const rows = hasHeader ? cells.slice(1) : cells;
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import { ActionManager } from "../actions/manager";
|
|||||||
import { getNonDeletedElements } from "../element";
|
import { getNonDeletedElements } from "../element";
|
||||||
import { ExcalidrawElement, PointerType } from "../element/types";
|
import { ExcalidrawElement, PointerType } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "../components/App";
|
import { useDeviceType } from "../components/App";
|
||||||
import {
|
import {
|
||||||
canChangeSharpness,
|
canChangeSharpness,
|
||||||
canHaveArrowheads,
|
canHaveArrowheads,
|
||||||
@@ -15,28 +15,23 @@ import {
|
|||||||
} from "../scene";
|
} from "../scene";
|
||||||
import { SHAPES } from "../shapes";
|
import { SHAPES } from "../shapes";
|
||||||
import { AppState, Zoom } from "../types";
|
import { AppState, Zoom } from "../types";
|
||||||
import {
|
import { capitalizeString, isTransparent, setCursorForShape } from "../utils";
|
||||||
capitalizeString,
|
|
||||||
isTransparent,
|
|
||||||
updateActiveTool,
|
|
||||||
setCursorForShape,
|
|
||||||
} from "../utils";
|
|
||||||
import Stack from "./Stack";
|
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, isBoundToContainer } from "../element/typeChecks";
|
||||||
import clsx from "clsx";
|
|
||||||
import { actionToggleZenMode } from "../actions";
|
|
||||||
|
|
||||||
export const SelectedShapeActions = ({
|
export const SelectedShapeActions = ({
|
||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
renderAction,
|
renderAction,
|
||||||
|
activeTool,
|
||||||
}: {
|
}: {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
renderAction: ActionManager["renderAction"];
|
renderAction: ActionManager["renderAction"];
|
||||||
|
activeTool: AppState["activeTool"]["type"];
|
||||||
}) => {
|
}) => {
|
||||||
const targetElements = getTargetElements(
|
const targetElements = getTargetElements(
|
||||||
getNonDeletedElements(elements),
|
getNonDeletedElements(elements),
|
||||||
@@ -52,17 +47,17 @@ export const SelectedShapeActions = ({
|
|||||||
isSingleElementBoundContainer = true;
|
isSingleElementBoundContainer = true;
|
||||||
}
|
}
|
||||||
const isEditing = Boolean(appState.editingElement);
|
const isEditing = Boolean(appState.editingElement);
|
||||||
const device = useDevice();
|
const deviceType = useDeviceType();
|
||||||
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
||||||
|
|
||||||
const showFillIcons =
|
const showFillIcons =
|
||||||
hasBackground(appState.activeTool.type) ||
|
hasBackground(activeTool) ||
|
||||||
targetElements.some(
|
targetElements.some(
|
||||||
(element) =>
|
(element) =>
|
||||||
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
||||||
);
|
);
|
||||||
const showChangeBackgroundIcons =
|
const showChangeBackgroundIcons =
|
||||||
hasBackground(appState.activeTool.type) ||
|
hasBackground(activeTool) ||
|
||||||
targetElements.some((element) => hasBackground(element.type));
|
targetElements.some((element) => hasBackground(element.type));
|
||||||
|
|
||||||
const showLinkIcon =
|
const showLinkIcon =
|
||||||
@@ -79,23 +74,23 @@ export const SelectedShapeActions = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="panelColumn">
|
<div className="panelColumn">
|
||||||
{((hasStrokeColor(appState.activeTool.type) &&
|
{((hasStrokeColor(activeTool) &&
|
||||||
appState.activeTool.type !== "image" &&
|
activeTool !== "image" &&
|
||||||
commonSelectedType !== "image") ||
|
commonSelectedType !== "image") ||
|
||||||
targetElements.some((element) => hasStrokeColor(element.type))) &&
|
targetElements.some((element) => hasStrokeColor(element.type))) &&
|
||||||
renderAction("changeStrokeColor")}
|
renderAction("changeStrokeColor")}
|
||||||
{showChangeBackgroundIcons && renderAction("changeBackgroundColor")}
|
{showChangeBackgroundIcons && renderAction("changeBackgroundColor")}
|
||||||
{showFillIcons && renderAction("changeFillStyle")}
|
{showFillIcons && renderAction("changeFillStyle")}
|
||||||
|
|
||||||
{(hasStrokeWidth(appState.activeTool.type) ||
|
{(hasStrokeWidth(activeTool) ||
|
||||||
targetElements.some((element) => hasStrokeWidth(element.type))) &&
|
targetElements.some((element) => hasStrokeWidth(element.type))) &&
|
||||||
renderAction("changeStrokeWidth")}
|
renderAction("changeStrokeWidth")}
|
||||||
|
|
||||||
{(appState.activeTool.type === "freedraw" ||
|
{(activeTool === "freedraw" ||
|
||||||
targetElements.some((element) => element.type === "freedraw")) &&
|
targetElements.some((element) => element.type === "freedraw")) &&
|
||||||
renderAction("changeStrokeShape")}
|
renderAction("changeStrokeShape")}
|
||||||
|
|
||||||
{(hasStrokeStyle(appState.activeTool.type) ||
|
{(hasStrokeStyle(activeTool) ||
|
||||||
targetElements.some((element) => hasStrokeStyle(element.type))) && (
|
targetElements.some((element) => hasStrokeStyle(element.type))) && (
|
||||||
<>
|
<>
|
||||||
{renderAction("changeStrokeStyle")}
|
{renderAction("changeStrokeStyle")}
|
||||||
@@ -103,12 +98,12 @@ export const SelectedShapeActions = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(canChangeSharpness(appState.activeTool.type) ||
|
{(canChangeSharpness(activeTool) ||
|
||||||
targetElements.some((element) => canChangeSharpness(element.type))) && (
|
targetElements.some((element) => canChangeSharpness(element.type))) && (
|
||||||
<>{renderAction("changeSharpness")}</>
|
<>{renderAction("changeSharpness")}</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(hasText(appState.activeTool.type) ||
|
{(hasText(activeTool) ||
|
||||||
targetElements.some((element) => hasText(element.type))) && (
|
targetElements.some((element) => hasText(element.type))) && (
|
||||||
<>
|
<>
|
||||||
{renderAction("changeFontSize")}
|
{renderAction("changeFontSize")}
|
||||||
@@ -123,7 +118,7 @@ export const SelectedShapeActions = ({
|
|||||||
(element) =>
|
(element) =>
|
||||||
hasBoundTextElement(element) || isBoundToContainer(element),
|
hasBoundTextElement(element) || isBoundToContainer(element),
|
||||||
) && renderAction("changeVerticalAlign")}
|
) && renderAction("changeVerticalAlign")}
|
||||||
{(canHaveArrowheads(appState.activeTool.type) ||
|
{(canHaveArrowheads(activeTool) ||
|
||||||
targetElements.some((element) => canHaveArrowheads(element.type))) && (
|
targetElements.some((element) => canHaveArrowheads(element.type))) && (
|
||||||
<>{renderAction("changeArrowhead")}</>
|
<>{renderAction("changeArrowhead")}</>
|
||||||
)}
|
)}
|
||||||
@@ -177,8 +172,8 @@ export const SelectedShapeActions = ({
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.actions")}</legend>
|
<legend>{t("labels.actions")}</legend>
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
{!device.isMobile && renderAction("duplicateSelection")}
|
{!deviceType.isMobile && renderAction("duplicateSelection")}
|
||||||
{!device.isMobile && renderAction("deleteSelectedElements")}
|
{!deviceType.isMobile && renderAction("deleteSelectedElements")}
|
||||||
{renderAction("group")}
|
{renderAction("group")}
|
||||||
{renderAction("ungroup")}
|
{renderAction("ungroup")}
|
||||||
{showLinkIcon && renderAction("hyperlink")}
|
{showLinkIcon && renderAction("hyperlink")}
|
||||||
@@ -234,9 +229,7 @@ export const ShapesSwitcher = ({
|
|||||||
if (appState.activeTool.type !== value) {
|
if (appState.activeTool.type !== value) {
|
||||||
trackEvent("toolbar", value, "ui");
|
trackEvent("toolbar", value, "ui");
|
||||||
}
|
}
|
||||||
const nextActiveTool = updateActiveTool(appState, {
|
const nextActiveTool = { ...activeTool, type: value };
|
||||||
type: value,
|
|
||||||
});
|
|
||||||
setAppState({
|
setAppState({
|
||||||
activeTool: nextActiveTool,
|
activeTool: nextActiveTool,
|
||||||
multiElement: null,
|
multiElement: null,
|
||||||
@@ -271,45 +264,3 @@ export const ZoomActions = ({
|
|||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const UndoRedoActions = ({
|
|
||||||
renderAction,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
renderAction: ActionManager["renderAction"];
|
|
||||||
className?: string;
|
|
||||||
}) => (
|
|
||||||
<div className={`undo-redo-buttons ${className}`}>
|
|
||||||
{renderAction("undo", { size: "small" })}
|
|
||||||
{renderAction("redo", { size: "small" })}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const ExitZenModeAction = ({
|
|
||||||
actionManager,
|
|
||||||
showExitZenModeBtn,
|
|
||||||
}: {
|
|
||||||
actionManager: ActionManager;
|
|
||||||
showExitZenModeBtn: boolean;
|
|
||||||
}) => (
|
|
||||||
<button
|
|
||||||
className={clsx("disable-zen-mode", {
|
|
||||||
"disable-zen-mode--visible": showExitZenModeBtn,
|
|
||||||
})}
|
|
||||||
onClick={() => actionManager.executeAction(actionToggleZenMode)}
|
|
||||||
>
|
|
||||||
{t("buttons.exitZenMode")}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const FinalizeAction = ({
|
|
||||||
renderAction,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
renderAction: ActionManager["renderAction"];
|
|
||||||
className?: string;
|
|
||||||
}) => (
|
|
||||||
<div className={`finalize-button ${className}`}>
|
|
||||||
{renderAction("finalize", { size: "small" })}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
import "./Avatar.scss";
|
import "./Avatar.scss";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import { getClientInitials } from "../clients";
|
import { getClientInitials } from "../clients";
|
||||||
|
|
||||||
type AvatarProps = {
|
type AvatarProps = {
|
||||||
@@ -13,21 +13,13 @@ type AvatarProps = {
|
|||||||
|
|
||||||
export const Avatar = ({ color, border, onClick, name, src }: AvatarProps) => {
|
export const Avatar = ({ color, border, onClick, name, src }: AvatarProps) => {
|
||||||
const shortName = getClientInitials(name);
|
const shortName = getClientInitials(name);
|
||||||
const [error, setError] = useState(false);
|
const style = src
|
||||||
const loadImg = !error && src;
|
|
||||||
const style = loadImg
|
|
||||||
? undefined
|
? undefined
|
||||||
: { background: color, border: `1px solid ${border}` };
|
: { background: color, border: `1px solid ${border}` };
|
||||||
return (
|
return (
|
||||||
<div className="Avatar" style={style} onClick={onClick}>
|
<div className="Avatar" style={style} onClick={onClick}>
|
||||||
{loadImg ? (
|
{src ? (
|
||||||
<img
|
<img className="Avatar-img" src={src} alt={shortName} />
|
||||||
className="Avatar-img"
|
|
||||||
src={src}
|
|
||||||
alt={shortName}
|
|
||||||
referrerPolicy="no-referrer"
|
|
||||||
onError={() => setError(true)}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
shortName
|
shortName
|
||||||
)}
|
)}
|
||||||
|
@@ -1,12 +1,20 @@
|
|||||||
|
import React from "react";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
|
import { AppState } from "../types";
|
||||||
|
|
||||||
export const BackgroundPickerAndDarkModeToggle = ({
|
export const BackgroundPickerAndDarkModeToggle = ({
|
||||||
|
appState,
|
||||||
|
setAppState,
|
||||||
actionManager,
|
actionManager,
|
||||||
|
showThemeBtn,
|
||||||
}: {
|
}: {
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
|
appState: AppState;
|
||||||
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
|
showThemeBtn: boolean;
|
||||||
}) => (
|
}) => (
|
||||||
<div style={{ display: "flex" }}>
|
<div style={{ display: "flex" }}>
|
||||||
{actionManager.renderAction("changeViewBackgroundColor")}
|
{actionManager.renderAction("changeViewBackgroundColor")}
|
||||||
{actionManager.renderAction("toggleTheme")}
|
{showThemeBtn && actionManager.renderAction("toggleTheme")}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@@ -4,7 +4,6 @@ import "./Card.scss";
|
|||||||
|
|
||||||
export const Card: React.FC<{
|
export const Card: React.FC<{
|
||||||
color: keyof OpenColor | "primary";
|
color: keyof OpenColor | "primary";
|
||||||
children?: React.ReactNode;
|
|
||||||
}> = ({ children, color }) => {
|
}> = ({ children, color }) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@@ -8,7 +8,6 @@ export const CheckboxItem: React.FC<{
|
|||||||
checked: boolean;
|
checked: boolean;
|
||||||
onChange: (checked: boolean, event: React.MouseEvent) => void;
|
onChange: (checked: boolean, event: React.MouseEvent) => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
children?: React.ReactNode;
|
|
||||||
}> = ({ children, checked, onChange, className }) => {
|
}> = ({ children, checked, onChange, className }) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "./App";
|
import { useDeviceType } from "./App";
|
||||||
import { trash } from "./icons";
|
import { trash } from "./icons";
|
||||||
import { ToolButton } from "./ToolButton";
|
import { ToolButton } from "./ToolButton";
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => {
|
|||||||
icon={trash}
|
icon={trash}
|
||||||
title={t("buttons.clearReset")}
|
title={t("buttons.clearReset")}
|
||||||
aria-label={t("buttons.clearReset")}
|
aria-label={t("buttons.clearReset")}
|
||||||
showAriaLabel={useDevice().isMobile}
|
showAriaLabel={useDeviceType().isMobile}
|
||||||
onClick={toggleDialog}
|
onClick={toggleDialog}
|
||||||
data-testid="clear-canvas-button"
|
data-testid="clear-canvas-button"
|
||||||
/>
|
/>
|
||||||
|
@@ -18,15 +18,13 @@
|
|||||||
left: -5px;
|
left: -5px;
|
||||||
}
|
}
|
||||||
min-width: 1em;
|
min-width: 1em;
|
||||||
min-height: 1em;
|
|
||||||
line-height: 1;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: -5px;
|
bottom: -5px;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: $oc-green-6;
|
background-color: $oc-green-6;
|
||||||
color: $oc-white;
|
color: $oc-white;
|
||||||
font-size: 0.6em;
|
font-size: 0.7em;
|
||||||
font-family: "Cascadia";
|
font-family: var(--ui-font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { ToolButton } from "./ToolButton";
|
import { ToolButton } from "./ToolButton";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "../components/App";
|
import { useDeviceType } from "../components/App";
|
||||||
import { users } from "./icons";
|
import { users } from "./icons";
|
||||||
|
|
||||||
import "./CollabButton.scss";
|
import "./CollabButton.scss";
|
||||||
@@ -26,9 +26,9 @@ const CollabButton = ({
|
|||||||
type="button"
|
type="button"
|
||||||
title={t("labels.liveCollaboration")}
|
title={t("labels.liveCollaboration")}
|
||||||
aria-label={t("labels.liveCollaboration")}
|
aria-label={t("labels.liveCollaboration")}
|
||||||
showAriaLabel={useDevice().isMobile}
|
showAriaLabel={useDeviceType().isMobile}
|
||||||
>
|
>
|
||||||
{isCollaborating && (
|
{collaboratorCount > 0 && (
|
||||||
<div className="CollabButton-collaborators">{collaboratorCount}</div>
|
<div className="CollabButton-collaborators">{collaboratorCount}</div>
|
||||||
)}
|
)}
|
||||||
</ToolButton>
|
</ToolButton>
|
||||||
|
@@ -128,33 +128,45 @@ const Picker = ({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleKeyDown = (event: React.KeyboardEvent) => {
|
const handleKeyDown = (event: React.KeyboardEvent) => {
|
||||||
let handled = false;
|
if (event.key === KEYS.TAB) {
|
||||||
if (isArrowKey(event.key)) {
|
const { activeElement } = document;
|
||||||
handled = true;
|
if (event.shiftKey) {
|
||||||
|
if (activeElement === firstItem.current) {
|
||||||
|
colorInput.current?.focus();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
} else if (activeElement === colorInput.current) {
|
||||||
|
firstItem.current?.focus();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
} else if (isArrowKey(event.key)) {
|
||||||
const { activeElement } = document;
|
const { activeElement } = document;
|
||||||
const isRTL = getLanguage().rtl;
|
const isRTL = getLanguage().rtl;
|
||||||
let isCustom = false;
|
let isCustom = false;
|
||||||
let index = Array.prototype.indexOf.call(
|
let index = Array.prototype.indexOf.call(
|
||||||
gallery.current!.querySelector(".color-picker-content--default")
|
gallery!.current!.querySelector(".color-picker-content--default")!
|
||||||
?.children,
|
.children,
|
||||||
activeElement,
|
activeElement,
|
||||||
);
|
);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
index = Array.prototype.indexOf.call(
|
index = Array.prototype.indexOf.call(
|
||||||
gallery.current!.querySelector(".color-picker-content--canvas-colors")
|
gallery!.current!.querySelector(
|
||||||
?.children,
|
".color-picker-content--canvas-colors",
|
||||||
|
)!.children,
|
||||||
activeElement,
|
activeElement,
|
||||||
);
|
);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
isCustom = true;
|
isCustom = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const parentElement = isCustom
|
const parentSelector = isCustom
|
||||||
? gallery.current?.querySelector(".color-picker-content--canvas-colors")
|
? gallery!.current!.querySelector(
|
||||||
: gallery.current?.querySelector(".color-picker-content--default");
|
".color-picker-content--canvas-colors",
|
||||||
|
)!
|
||||||
|
: gallery!.current!.querySelector(".color-picker-content--default")!;
|
||||||
|
|
||||||
if (parentElement && index !== -1) {
|
if (index !== -1) {
|
||||||
const length = parentElement.children.length - (showInput ? 1 : 0);
|
const length = parentSelector!.children.length - (showInput ? 1 : 0);
|
||||||
const nextIndex =
|
const nextIndex =
|
||||||
event.key === (isRTL ? KEYS.ARROW_LEFT : KEYS.ARROW_RIGHT)
|
event.key === (isRTL ? KEYS.ARROW_LEFT : KEYS.ARROW_RIGHT)
|
||||||
? (index + 1) % length
|
? (index + 1) % length
|
||||||
@@ -165,38 +177,30 @@ const Picker = ({
|
|||||||
: !isCustom && event.key === KEYS.ARROW_UP
|
: !isCustom && event.key === KEYS.ARROW_UP
|
||||||
? (length + index - 5) % length
|
? (length + index - 5) % length
|
||||||
: index;
|
: index;
|
||||||
(parentElement.children[nextIndex] as HTMLElement | undefined)?.focus();
|
(parentSelector!.children![nextIndex] as HTMLElement)?.focus();
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (
|
} else if (
|
||||||
keyBindings.includes(event.key.toLowerCase()) &&
|
keyBindings.includes(event.key.toLowerCase()) &&
|
||||||
!event[KEYS.CTRL_OR_CMD] &&
|
|
||||||
!event.altKey &&
|
|
||||||
!isWritableElement(event.target)
|
!isWritableElement(event.target)
|
||||||
) {
|
) {
|
||||||
handled = true;
|
|
||||||
const index = keyBindings.indexOf(event.key.toLowerCase());
|
const index = keyBindings.indexOf(event.key.toLowerCase());
|
||||||
const isCustom = index >= MAX_DEFAULT_COLORS;
|
const isCustom = index >= MAX_DEFAULT_COLORS;
|
||||||
const parentElement = isCustom
|
const parentSelector = isCustom
|
||||||
? gallery?.current?.querySelector(
|
? gallery!.current!.querySelector(
|
||||||
".color-picker-content--canvas-colors",
|
".color-picker-content--canvas-colors",
|
||||||
)
|
)!
|
||||||
: gallery?.current?.querySelector(".color-picker-content--default");
|
: gallery!.current!.querySelector(".color-picker-content--default")!;
|
||||||
const actualIndex = isCustom ? index - MAX_DEFAULT_COLORS : index;
|
const actualIndex = isCustom ? index - MAX_DEFAULT_COLORS : index;
|
||||||
(
|
(parentSelector!.children![actualIndex] as HTMLElement)?.focus();
|
||||||
parentElement?.children[actualIndex] as HTMLElement | undefined
|
|
||||||
)?.focus();
|
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) {
|
} else if (event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) {
|
||||||
handled = true;
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
if (handled) {
|
event.nativeEvent.stopImmediatePropagation();
|
||||||
event.nativeEvent.stopImmediatePropagation();
|
event.stopPropagation();
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderColors = (colors: Array<string>, custom: boolean = false) => {
|
const renderColors = (colors: Array<string>, custom: boolean = false) => {
|
||||||
@@ -260,8 +264,7 @@ const Picker = ({
|
|||||||
gallery.current = el;
|
gallery.current = el;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
// to allow focusing by clicking but not by tabbing
|
tabIndex={0}
|
||||||
tabIndex={-1}
|
|
||||||
>
|
>
|
||||||
<div className="color-picker-content--default">
|
<div className="color-picker-content--default">
|
||||||
{renderColors(colors)}
|
{renderColors(colors)}
|
||||||
@@ -343,8 +346,6 @@ const ColorInput = React.forwardRef(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
ColorInput.displayName = "ColorInput";
|
|
||||||
|
|
||||||
export const ColorPicker = ({
|
export const ColorPicker = ({
|
||||||
type,
|
type,
|
||||||
color,
|
color,
|
||||||
|
@@ -2,14 +2,13 @@ import clsx from "clsx";
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useCallbackRefState } from "../hooks/useCallbackRefState";
|
import { useCallbackRefState } from "../hooks/useCallbackRefState";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useExcalidrawContainer, useDevice } from "../components/App";
|
import { useExcalidrawContainer, useDeviceType } from "../components/App";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import "./Dialog.scss";
|
import "./Dialog.scss";
|
||||||
import { back, close } from "./icons";
|
import { back, close } from "./icons";
|
||||||
import { Island } from "./Island";
|
import { Island } from "./Island";
|
||||||
import { Modal } from "./Modal";
|
import { Modal } from "./Modal";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { queryFocusableElements } from "../utils";
|
|
||||||
|
|
||||||
export interface DialogProps {
|
export interface DialogProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -65,6 +64,14 @@ export const Dialog = (props: DialogProps) => {
|
|||||||
return () => islandNode.removeEventListener("keydown", handleKeyDown);
|
return () => islandNode.removeEventListener("keydown", handleKeyDown);
|
||||||
}, [islandNode, props.autofocus]);
|
}, [islandNode, props.autofocus]);
|
||||||
|
|
||||||
|
const queryFocusableElements = (node: HTMLElement) => {
|
||||||
|
const focusableElements = node.querySelectorAll<HTMLElement>(
|
||||||
|
"button, a, input, select, textarea, div[tabindex]",
|
||||||
|
);
|
||||||
|
|
||||||
|
return focusableElements ? Array.from(focusableElements) : [];
|
||||||
|
};
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
(lastActiveElement as HTMLElement).focus();
|
(lastActiveElement as HTMLElement).focus();
|
||||||
props.onCloseRequest();
|
props.onCloseRequest();
|
||||||
@@ -85,10 +92,9 @@ export const Dialog = (props: DialogProps) => {
|
|||||||
<button
|
<button
|
||||||
className="Modal__close"
|
className="Modal__close"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
title={t("buttons.close")}
|
|
||||||
aria-label={t("buttons.close")}
|
aria-label={t("buttons.close")}
|
||||||
>
|
>
|
||||||
{useDevice().isMobile ? back : close}
|
{useDeviceType().isMobile ? back : close}
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div className="Dialog__content">{props.children}</div>
|
<div className="Dialog__content">{props.children}</div>
|
||||||
|
@@ -1,106 +0,0 @@
|
|||||||
import clsx from "clsx";
|
|
||||||
import { ActionManager } from "../actions/manager";
|
|
||||||
import { AppState, ExcalidrawProps } from "../types";
|
|
||||||
import {
|
|
||||||
ExitZenModeAction,
|
|
||||||
FinalizeAction,
|
|
||||||
UndoRedoActions,
|
|
||||||
ZoomActions,
|
|
||||||
} from "./Actions";
|
|
||||||
import { useDevice } from "./App";
|
|
||||||
import { Island } from "./Island";
|
|
||||||
import { Section } from "./Section";
|
|
||||||
import Stack from "./Stack";
|
|
||||||
|
|
||||||
const Footer = ({
|
|
||||||
appState,
|
|
||||||
actionManager,
|
|
||||||
renderCustomFooter,
|
|
||||||
showExitZenModeBtn,
|
|
||||||
}: {
|
|
||||||
appState: AppState;
|
|
||||||
actionManager: ActionManager;
|
|
||||||
renderCustomFooter?: ExcalidrawProps["renderFooter"];
|
|
||||||
showExitZenModeBtn: boolean;
|
|
||||||
}) => {
|
|
||||||
const device = useDevice();
|
|
||||||
const showFinalize =
|
|
||||||
!appState.viewModeEnabled && appState.multiElement && device.isTouchScreen;
|
|
||||||
return (
|
|
||||||
<footer
|
|
||||||
role="contentinfo"
|
|
||||||
className="layer-ui__wrapper__footer App-menu App-menu_bottom"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={clsx("layer-ui__wrapper__footer-left zen-mode-transition", {
|
|
||||||
"layer-ui__wrapper__footer-left--transition-left":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<Stack.Col gap={2}>
|
|
||||||
<Section heading="canvasActions">
|
|
||||||
<Island padding={1}>
|
|
||||||
<ZoomActions
|
|
||||||
renderAction={actionManager.renderAction}
|
|
||||||
zoom={appState.zoom}
|
|
||||||
/>
|
|
||||||
</Island>
|
|
||||||
{!appState.viewModeEnabled && (
|
|
||||||
<>
|
|
||||||
<UndoRedoActions
|
|
||||||
renderAction={actionManager.renderAction}
|
|
||||||
className={clsx("zen-mode-transition", {
|
|
||||||
"layer-ui__wrapper__footer-left--transition-bottom":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div
|
|
||||||
className={clsx("eraser-buttons zen-mode-transition", {
|
|
||||||
"layer-ui__wrapper__footer-left--transition-left":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{actionManager.renderAction("eraser", { size: "small" })}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{showFinalize && (
|
|
||||||
<FinalizeAction
|
|
||||||
renderAction={actionManager.renderAction}
|
|
||||||
className={clsx("zen-mode-transition", {
|
|
||||||
"layer-ui__wrapper__footer-left--transition-left":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Section>
|
|
||||||
</Stack.Col>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={clsx(
|
|
||||||
"layer-ui__wrapper__footer-center zen-mode-transition",
|
|
||||||
{
|
|
||||||
"layer-ui__wrapper__footer-left--transition-bottom":
|
|
||||||
appState.zenModeEnabled,
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{renderCustomFooter?.(false, appState)}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={clsx("layer-ui__wrapper__footer-right zen-mode-transition", {
|
|
||||||
"transition-right disable-pointerEvents": appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{actionManager.renderAction("toggleShortcuts")}
|
|
||||||
</div>
|
|
||||||
<ExitZenModeAction
|
|
||||||
actionManager={actionManager}
|
|
||||||
showExitZenModeBtn={showExitZenModeBtn}
|
|
||||||
/>
|
|
||||||
</footer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Footer;
|
|
@@ -3,7 +3,7 @@ import { NonDeletedExcalidrawElement } from "../element/types";
|
|||||||
import { getSelectedElements } from "../scene";
|
import { getSelectedElements } from "../scene";
|
||||||
|
|
||||||
import "./HintViewer.scss";
|
import "./HintViewer.scss";
|
||||||
import { AppState, Device } from "../types";
|
import { AppState } from "../types";
|
||||||
import {
|
import {
|
||||||
isImageElement,
|
isImageElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
@@ -17,19 +17,13 @@ interface HintViewerProps {
|
|||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
device: Device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getHints = ({
|
const getHints = ({ appState, elements, isMobile }: HintViewerProps) => {
|
||||||
appState,
|
|
||||||
elements,
|
|
||||||
isMobile,
|
|
||||||
device,
|
|
||||||
}: HintViewerProps) => {
|
|
||||||
const { activeTool, isResizing, isRotating, lastPointerDownWith } = appState;
|
const { activeTool, isResizing, isRotating, lastPointerDownWith } = appState;
|
||||||
const multiMode = appState.multiElement !== null;
|
const multiMode = appState.multiElement !== null;
|
||||||
|
|
||||||
if (appState.openSidebar === "library" && !device.canDeviceFitSidebar) {
|
if (appState.isLibraryOpen) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +45,7 @@ const getHints = ({
|
|||||||
return t("hints.text");
|
return t("hints.text");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appState.activeTool.type === "image" && appState.pendingImageElementId) {
|
if (appState.activeTool.type === "image" && appState.pendingImageElement) {
|
||||||
return t("hints.placeImage");
|
return t("hints.placeImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,13 +111,11 @@ export const HintViewer = ({
|
|||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
isMobile,
|
isMobile,
|
||||||
device,
|
|
||||||
}: HintViewerProps) => {
|
}: HintViewerProps) => {
|
||||||
let hint = getHints({
|
let hint = getHints({
|
||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
isMobile,
|
isMobile,
|
||||||
device,
|
|
||||||
});
|
});
|
||||||
if (!hint) {
|
if (!hint) {
|
||||||
return null;
|
return null;
|
||||||
|
@@ -5,7 +5,7 @@ import { canvasToBlob } from "../data/blob";
|
|||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
import { CanvasError } from "../errors";
|
import { CanvasError } from "../errors";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "./App";
|
import { useDeviceType } 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";
|
||||||
@@ -58,7 +58,6 @@ const ExportButton: React.FC<{
|
|||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
title: string;
|
title: string;
|
||||||
shade?: number;
|
shade?: number;
|
||||||
children?: React.ReactNode;
|
|
||||||
}> = ({ children, title, onClick, color, shade = 6 }) => {
|
}> = ({ children, title, onClick, color, shade = 6 }) => {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
@@ -171,9 +170,7 @@ const ImageExportModal = ({
|
|||||||
<Stack.Row gap={2}>
|
<Stack.Row gap={2}>
|
||||||
{actionManager.renderAction("changeExportScale")}
|
{actionManager.renderAction("changeExportScale")}
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
<p style={{ marginLeft: "1em", userSelect: "none" }}>
|
<p style={{ marginLeft: "1em", userSelect: "none" }}>Scale</p>
|
||||||
{t("buttons.scale")}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -253,7 +250,7 @@ export const ImageExportDialog = ({
|
|||||||
icon={exportImage}
|
icon={exportImage}
|
||||||
type="button"
|
type="button"
|
||||||
aria-label={t("buttons.exportImage")}
|
aria-label={t("buttons.exportImage")}
|
||||||
showAriaLabel={useDevice().isMobile}
|
showAriaLabel={useDeviceType().isMobile}
|
||||||
title={t("buttons.exportImage")}
|
title={t("buttons.exportImage")}
|
||||||
/>
|
/>
|
||||||
{modalIsShown && (
|
{modalIsShown && (
|
||||||
|
@@ -2,12 +2,10 @@ import React, { useEffect, useState } from "react";
|
|||||||
|
|
||||||
import { LoadingMessage } from "./LoadingMessage";
|
import { LoadingMessage } from "./LoadingMessage";
|
||||||
import { defaultLang, Language, languages, setLanguage } from "../i18n";
|
import { defaultLang, Language, languages, setLanguage } from "../i18n";
|
||||||
import { Theme } from "../element/types";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
langCode: Language["code"];
|
langCode: Language["code"];
|
||||||
children: React.ReactElement;
|
children: React.ReactElement;
|
||||||
theme?: Theme;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InitializeApp = (props: Props) => {
|
export const InitializeApp = (props: Props) => {
|
||||||
@@ -16,12 +14,12 @@ export const InitializeApp = (props: Props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateLang = async () => {
|
const updateLang = async () => {
|
||||||
await setLanguage(currentLang);
|
await setLanguage(currentLang);
|
||||||
setLoading(false);
|
|
||||||
};
|
};
|
||||||
const currentLang =
|
const currentLang =
|
||||||
languages.find((lang) => lang.code === props.langCode) || defaultLang;
|
languages.find((lang) => lang.code === props.langCode) || defaultLang;
|
||||||
updateLang();
|
updateLang();
|
||||||
|
setLoading(false);
|
||||||
}, [props.langCode]);
|
}, [props.langCode]);
|
||||||
|
|
||||||
return loading ? <LoadingMessage theme={props.theme} /> : props.children;
|
return loading ? <LoadingMessage /> : props.children;
|
||||||
};
|
};
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
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 { useDeviceType } 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 { exportFile, exportToFileIcon, link } from "./icons";
|
||||||
@@ -117,7 +117,7 @@ export const JSONExportDialog = ({
|
|||||||
icon={exportFile}
|
icon={exportFile}
|
||||||
type="button"
|
type="button"
|
||||||
aria-label={t("buttons.export")}
|
aria-label={t("buttons.export")}
|
||||||
showAriaLabel={useDevice().isMobile}
|
showAriaLabel={useDeviceType().isMobile}
|
||||||
title={t("buttons.export")}
|
title={t("buttons.export")}
|
||||||
/>
|
/>
|
||||||
{modalIsShown && (
|
{modalIsShown && (
|
||||||
|
@@ -1,21 +1,9 @@
|
|||||||
@import "open-color/open-color";
|
@import "open-color/open-color";
|
||||||
@import "../css/variables.module";
|
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.layer-ui__wrapper.animate {
|
|
||||||
transition: width 0.1s ease-in-out;
|
|
||||||
}
|
|
||||||
.layer-ui__wrapper {
|
.layer-ui__wrapper {
|
||||||
// when the rightside sidebar is docked, we need to resize the UI by its
|
|
||||||
// width, making the nested UI content shift to the left. To do this,
|
|
||||||
// we need the UI container to actually have dimensions set, but
|
|
||||||
// then we also need to disable pointer events else the canvas below
|
|
||||||
// wouldn't be interactive.
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: var(--zIndex-layerUI);
|
z-index: var(--zIndex-layerUI);
|
||||||
|
|
||||||
&__top-right {
|
&__top-right {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,16 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React from "react";
|
import React, { useCallback } from "react";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { CLASSES, LIBRARY_SIDEBAR_WIDTH } from "../constants";
|
import { CLASSES } from "../constants";
|
||||||
import { exportCanvas } from "../data";
|
import { exportCanvas } from "../data";
|
||||||
import { isTextElement, showSelectedShapeActions } from "../element";
|
import { isTextElement, showSelectedShapeActions } from "../element";
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
import { Language, t } from "../i18n";
|
import { Language, t } from "../i18n";
|
||||||
import { calculateScrollCenter } from "../scene";
|
import { calculateScrollCenter, getSelectedElements } from "../scene";
|
||||||
import { ExportType } from "../scene/types";
|
import { ExportType } from "../scene/types";
|
||||||
import { AppProps, AppState, ExcalidrawProps, BinaryFiles } from "../types";
|
import { AppProps, AppState, ExcalidrawProps, BinaryFiles } from "../types";
|
||||||
import { muteFSAbortError } from "../utils";
|
import { muteFSAbortError } from "../utils";
|
||||||
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
import { SelectedShapeActions, ShapesSwitcher, ZoomActions } from "./Actions";
|
||||||
import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";
|
import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";
|
||||||
import CollabButton from "./CollabButton";
|
import CollabButton from "./CollabButton";
|
||||||
import { ErrorDialog } from "./ErrorDialog";
|
import { ErrorDialog } from "./ErrorDialog";
|
||||||
@@ -25,6 +25,7 @@ import { PasteChartDialog } from "./PasteChartDialog";
|
|||||||
import { Section } from "./Section";
|
import { Section } from "./Section";
|
||||||
import { HelpDialog } from "./HelpDialog";
|
import { HelpDialog } from "./HelpDialog";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
|
import { Tooltip } from "./Tooltip";
|
||||||
import { UserList } from "./UserList";
|
import { UserList } from "./UserList";
|
||||||
import Library from "../data/library";
|
import Library from "../data/library";
|
||||||
import { JSONExportDialog } from "./JSONExportDialog";
|
import { JSONExportDialog } from "./JSONExportDialog";
|
||||||
@@ -36,13 +37,7 @@ 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 { useDeviceType } from "../components/App";
|
||||||
import { Stats } from "./Stats";
|
|
||||||
import { actionToggleStats } from "../actions/actionToggleStats";
|
|
||||||
import Footer from "./Footer";
|
|
||||||
import { hostSidebarCountersAtom } from "./Sidebar/Sidebar";
|
|
||||||
import { jotaiScope } from "../jotai";
|
|
||||||
import { useAtom } from "jotai";
|
|
||||||
|
|
||||||
interface LayerUIProps {
|
interface LayerUIProps {
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
@@ -55,45 +50,55 @@ interface LayerUIProps {
|
|||||||
onLockToggle: () => void;
|
onLockToggle: () => void;
|
||||||
onPenModeToggle: () => void;
|
onPenModeToggle: () => void;
|
||||||
onInsertElements: (elements: readonly NonDeletedExcalidrawElement[]) => void;
|
onInsertElements: (elements: readonly NonDeletedExcalidrawElement[]) => void;
|
||||||
|
zenModeEnabled: boolean;
|
||||||
showExitZenModeBtn: boolean;
|
showExitZenModeBtn: boolean;
|
||||||
|
showThemeBtn: boolean;
|
||||||
|
toggleZenMode: () => void;
|
||||||
langCode: Language["code"];
|
langCode: Language["code"];
|
||||||
isCollaborating: boolean;
|
isCollaborating: boolean;
|
||||||
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
renderTopRightUI?: (
|
||||||
renderCustomFooter?: ExcalidrawProps["renderFooter"];
|
isMobile: boolean,
|
||||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
appState: AppState,
|
||||||
renderCustomSidebar?: ExcalidrawProps["renderSidebar"];
|
) => JSX.Element | null;
|
||||||
|
renderCustomFooter?: (isMobile: boolean, appState: AppState) => JSX.Element;
|
||||||
|
viewModeEnabled: boolean;
|
||||||
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;
|
||||||
|
renderCustomElementWidget?: (appState: AppState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LayerUI = ({
|
const LayerUI = ({
|
||||||
actionManager,
|
actionManager,
|
||||||
appState,
|
appState,
|
||||||
files,
|
files,
|
||||||
setAppState,
|
setAppState,
|
||||||
elements,
|
|
||||||
canvas,
|
canvas,
|
||||||
|
elements,
|
||||||
onCollabButtonClick,
|
onCollabButtonClick,
|
||||||
onLockToggle,
|
onLockToggle,
|
||||||
onPenModeToggle,
|
onPenModeToggle,
|
||||||
onInsertElements,
|
onInsertElements,
|
||||||
|
zenModeEnabled,
|
||||||
showExitZenModeBtn,
|
showExitZenModeBtn,
|
||||||
|
showThemeBtn,
|
||||||
|
toggleZenMode,
|
||||||
isCollaborating,
|
isCollaborating,
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomFooter,
|
renderCustomFooter,
|
||||||
renderCustomStats,
|
viewModeEnabled,
|
||||||
renderCustomSidebar,
|
|
||||||
libraryReturnUrl,
|
libraryReturnUrl,
|
||||||
UIOptions,
|
UIOptions,
|
||||||
focusContainer,
|
focusContainer,
|
||||||
library,
|
library,
|
||||||
id,
|
id,
|
||||||
onImageAction,
|
onImageAction,
|
||||||
|
renderCustomElementWidget,
|
||||||
}: LayerUIProps) => {
|
}: LayerUIProps) => {
|
||||||
const device = useDevice();
|
const deviceType = useDeviceType();
|
||||||
|
|
||||||
const renderJSONExportDialog = () => {
|
const renderJSONExportDialog = () => {
|
||||||
if (!UIOptions.canvasActions.export) {
|
if (!UIOptions.canvasActions.export) {
|
||||||
@@ -169,7 +174,7 @@ const LayerUI = ({
|
|||||||
<Section
|
<Section
|
||||||
heading="canvasActions"
|
heading="canvasActions"
|
||||||
className={clsx("zen-mode-transition", {
|
className={clsx("zen-mode-transition", {
|
||||||
"transition-left": appState.zenModeEnabled,
|
"transition-left": zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{/* the zIndex ensures this menu has higher stacking order,
|
{/* the zIndex ensures this menu has higher stacking order,
|
||||||
@@ -190,7 +195,7 @@ const LayerUI = ({
|
|||||||
<Section
|
<Section
|
||||||
heading="canvasActions"
|
heading="canvasActions"
|
||||||
className={clsx("zen-mode-transition", {
|
className={clsx("zen-mode-transition", {
|
||||||
"transition-left": appState.zenModeEnabled,
|
"transition-left": zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{/* the zIndex ensures this menu has higher stacking order,
|
{/* the zIndex ensures this menu has higher stacking order,
|
||||||
@@ -212,7 +217,12 @@ const LayerUI = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
<BackgroundPickerAndDarkModeToggle actionManager={actionManager} />
|
<BackgroundPickerAndDarkModeToggle
|
||||||
|
actionManager={actionManager}
|
||||||
|
appState={appState}
|
||||||
|
setAppState={setAppState}
|
||||||
|
showThemeBtn={showThemeBtn}
|
||||||
|
/>
|
||||||
{appState.fileHandle && (
|
{appState.fileHandle && (
|
||||||
<>{actionManager.renderAction("saveToActiveFile")}</>
|
<>{actionManager.renderAction("saveToActiveFile")}</>
|
||||||
)}
|
)}
|
||||||
@@ -225,7 +235,7 @@ const LayerUI = ({
|
|||||||
<Section
|
<Section
|
||||||
heading="selectedShapeActions"
|
heading="selectedShapeActions"
|
||||||
className={clsx("zen-mode-transition", {
|
className={clsx("zen-mode-transition", {
|
||||||
"transition-left": appState.zenModeEnabled,
|
"transition-left": zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Island
|
<Island
|
||||||
@@ -242,11 +252,46 @@ const LayerUI = ({
|
|||||||
appState={appState}
|
appState={appState}
|
||||||
elements={elements}
|
elements={elements}
|
||||||
renderAction={actionManager.renderAction}
|
renderAction={actionManager.renderAction}
|
||||||
|
activeTool={appState.activeTool.type}
|
||||||
/>
|
/>
|
||||||
</Island>
|
</Island>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const closeLibrary = useCallback(() => {
|
||||||
|
const isDialogOpen = !!document.querySelector(".Dialog");
|
||||||
|
|
||||||
|
// Prevent closing if any dialog is open
|
||||||
|
if (isDialogOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAppState({ isLibraryOpen: false });
|
||||||
|
}, [setAppState]);
|
||||||
|
|
||||||
|
const deselectItems = useCallback(() => {
|
||||||
|
setAppState({
|
||||||
|
selectedElementIds: {},
|
||||||
|
selectedGroupIds: {},
|
||||||
|
});
|
||||||
|
}, [setAppState]);
|
||||||
|
|
||||||
|
const libraryMenu = appState.isLibraryOpen ? (
|
||||||
|
<LibraryMenu
|
||||||
|
pendingElements={getSelectedElements(elements, appState, true)}
|
||||||
|
onClose={closeLibrary}
|
||||||
|
onInsertShape={onInsertElements}
|
||||||
|
onAddToLibrary={deselectItems}
|
||||||
|
setAppState={setAppState}
|
||||||
|
libraryReturnUrl={libraryReturnUrl}
|
||||||
|
focusContainer={focusContainer}
|
||||||
|
library={library}
|
||||||
|
theme={appState.theme}
|
||||||
|
files={files}
|
||||||
|
id={id}
|
||||||
|
appState={appState}
|
||||||
|
/>
|
||||||
|
) : null;
|
||||||
|
|
||||||
const renderFixedSideContainer = () => {
|
const renderFixedSideContainer = () => {
|
||||||
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
||||||
appState,
|
appState,
|
||||||
@@ -258,34 +303,32 @@ const LayerUI = ({
|
|||||||
<div className="App-menu App-menu_top">
|
<div className="App-menu App-menu_top">
|
||||||
<Stack.Col
|
<Stack.Col
|
||||||
gap={4}
|
gap={4}
|
||||||
className={clsx({
|
className={clsx({ "disable-pointerEvents": zenModeEnabled })}
|
||||||
"disable-pointerEvents": appState.zenModeEnabled,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
{appState.viewModeEnabled
|
{viewModeEnabled
|
||||||
? renderViewModeCanvasActions()
|
? renderViewModeCanvasActions()
|
||||||
: renderCanvasActions()}
|
: renderCanvasActions()}
|
||||||
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
{!appState.viewModeEnabled && (
|
{!viewModeEnabled && (
|
||||||
<Section heading="shapes">
|
<Section heading="shapes">
|
||||||
{(heading: React.ReactNode) => (
|
{(heading) => (
|
||||||
<Stack.Col gap={4} align="start">
|
<Stack.Col gap={4} align="start">
|
||||||
<Stack.Row
|
<Stack.Row
|
||||||
gap={1}
|
gap={1}
|
||||||
className={clsx("App-toolbar-container", {
|
className={clsx("App-toolbar-container", {
|
||||||
"zen-mode": appState.zenModeEnabled,
|
"zen-mode": zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<PenModeButton
|
<PenModeButton
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
zenModeEnabled={zenModeEnabled}
|
||||||
checked={appState.penMode}
|
checked={appState.penMode}
|
||||||
onChange={onPenModeToggle}
|
onChange={onPenModeToggle}
|
||||||
title={t("toolBar.penMode")}
|
title={t("toolBar.penMode")}
|
||||||
penDetected={appState.penDetected}
|
penDetected={appState.penDetected}
|
||||||
/>
|
/>
|
||||||
<LockButton
|
<LockButton
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
zenModeEnabled={zenModeEnabled}
|
||||||
checked={appState.activeTool.locked}
|
checked={appState.activeTool.locked}
|
||||||
onChange={() => onLockToggle()}
|
onChange={() => onLockToggle()}
|
||||||
title={t("toolBar.lock")}
|
title={t("toolBar.lock")}
|
||||||
@@ -293,14 +336,13 @@ const LayerUI = ({
|
|||||||
<Island
|
<Island
|
||||||
padding={1}
|
padding={1}
|
||||||
className={clsx("App-toolbar", {
|
className={clsx("App-toolbar", {
|
||||||
"zen-mode": appState.zenModeEnabled,
|
"zen-mode": zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<HintViewer
|
<HintViewer
|
||||||
appState={appState}
|
appState={appState}
|
||||||
elements={elements}
|
elements={elements}
|
||||||
isMobile={device.isMobile}
|
isMobile={deviceType.isMobile}
|
||||||
device={device}
|
|
||||||
/>
|
/>
|
||||||
{heading}
|
{heading}
|
||||||
<Stack.Row gap={1}>
|
<Stack.Row gap={1}>
|
||||||
@@ -322,6 +364,7 @@ const LayerUI = ({
|
|||||||
setAppState={setAppState}
|
setAppState={setAppState}
|
||||||
/>
|
/>
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
|
{libraryMenu}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
)}
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
@@ -330,39 +373,128 @@ const LayerUI = ({
|
|||||||
className={clsx(
|
className={clsx(
|
||||||
"layer-ui__wrapper__top-right zen-mode-transition",
|
"layer-ui__wrapper__top-right zen-mode-transition",
|
||||||
{
|
{
|
||||||
"transition-right": appState.zenModeEnabled,
|
"transition-right": zenModeEnabled,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<UserList
|
<UserList>
|
||||||
collaborators={appState.collaborators}
|
{appState.collaborators.size > 0 &&
|
||||||
actionManager={actionManager}
|
Array.from(appState.collaborators)
|
||||||
/>
|
// Collaborator is either not initialized or is actually the current user.
|
||||||
{renderTopRightUI?.(device.isMobile, appState)}
|
.filter(([_, client]) => Object.keys(client).length !== 0)
|
||||||
|
.map(([clientId, client]) => (
|
||||||
|
<Tooltip
|
||||||
|
label={client.username || "Unknown user"}
|
||||||
|
key={clientId}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("goToCollaborator", {
|
||||||
|
id: clientId,
|
||||||
|
})}
|
||||||
|
</Tooltip>
|
||||||
|
))}
|
||||||
|
</UserList>
|
||||||
|
{renderTopRightUI?.(deviceType.isMobile, appState)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</FixedSideContainer>
|
</FixedSideContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderSidebars = () => {
|
const renderBottomAppMenu = () => {
|
||||||
return appState.openSidebar === "customSidebar" ? (
|
return (
|
||||||
renderCustomSidebar?.() || null
|
<footer
|
||||||
) : appState.openSidebar === "library" ? (
|
role="contentinfo"
|
||||||
<LibraryMenu
|
className="layer-ui__wrapper__footer App-menu App-menu_bottom"
|
||||||
appState={appState}
|
>
|
||||||
onInsertElements={onInsertElements}
|
<div
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
className={clsx(
|
||||||
focusContainer={focusContainer}
|
"layer-ui__wrapper__footer-left zen-mode-transition",
|
||||||
library={library}
|
{
|
||||||
id={id}
|
"layer-ui__wrapper__footer-left--transition-left": zenModeEnabled,
|
||||||
/>
|
},
|
||||||
) : null;
|
)}
|
||||||
|
>
|
||||||
|
<Stack.Col gap={2}>
|
||||||
|
<Section heading="canvasActions">
|
||||||
|
<Island padding={1}>
|
||||||
|
<ZoomActions
|
||||||
|
renderAction={actionManager.renderAction}
|
||||||
|
zoom={appState.zoom}
|
||||||
|
/>
|
||||||
|
</Island>
|
||||||
|
{!viewModeEnabled && (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={clsx("undo-redo-buttons zen-mode-transition", {
|
||||||
|
"layer-ui__wrapper__footer-left--transition-bottom":
|
||||||
|
zenModeEnabled,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("undo", { size: "small" })}
|
||||||
|
{actionManager.renderAction("redo", { size: "small" })}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={clsx("eraser-buttons zen-mode-transition", {
|
||||||
|
"layer-ui__wrapper__footer-left--transition-left":
|
||||||
|
zenModeEnabled,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("eraser", { size: "small" })}
|
||||||
|
{renderCustomElementWidget &&
|
||||||
|
renderCustomElementWidget(appState)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{!viewModeEnabled &&
|
||||||
|
appState.multiElement &&
|
||||||
|
deviceType.isTouchScreen && (
|
||||||
|
<div
|
||||||
|
className={clsx("finalize-button zen-mode-transition", {
|
||||||
|
"layer-ui__wrapper__footer-left--transition-left":
|
||||||
|
zenModeEnabled,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("finalize", { size: "small" })}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Section>
|
||||||
|
</Stack.Col>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={clsx(
|
||||||
|
"layer-ui__wrapper__footer-center zen-mode-transition",
|
||||||
|
{
|
||||||
|
"layer-ui__wrapper__footer-left--transition-bottom":
|
||||||
|
zenModeEnabled,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{renderCustomFooter?.(false, appState)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={clsx(
|
||||||
|
"layer-ui__wrapper__footer-right zen-mode-transition",
|
||||||
|
{
|
||||||
|
"transition-right disable-pointerEvents": zenModeEnabled,
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{actionManager.renderAction("toggleShortcuts")}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className={clsx("disable-zen-mode", {
|
||||||
|
"disable-zen-mode--visible": showExitZenModeBtn,
|
||||||
|
})}
|
||||||
|
onClick={toggleZenMode}
|
||||||
|
>
|
||||||
|
{t("buttons.exitZenMode")}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [hostSidebarCounters] = useAtom(hostSidebarCountersAtom, jotaiScope);
|
const dialogs = (
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
<>
|
||||||
{appState.isLoading && <LoadingMessage delay={250} />}
|
{appState.isLoading && <LoadingMessage delay={250} />}
|
||||||
{appState.errorMessage && (
|
{appState.errorMessage && (
|
||||||
@@ -390,83 +522,58 @@ const LayerUI = ({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{device.isMobile && (
|
|
||||||
<MobileMenu
|
|
||||||
appState={appState}
|
|
||||||
elements={elements}
|
|
||||||
actionManager={actionManager}
|
|
||||||
renderJSONExportDialog={renderJSONExportDialog}
|
|
||||||
renderImageExportDialog={renderImageExportDialog}
|
|
||||||
setAppState={setAppState}
|
|
||||||
onCollabButtonClick={onCollabButtonClick}
|
|
||||||
onLockToggle={() => onLockToggle()}
|
|
||||||
onPenModeToggle={onPenModeToggle}
|
|
||||||
canvas={canvas}
|
|
||||||
isCollaborating={isCollaborating}
|
|
||||||
renderCustomFooter={renderCustomFooter}
|
|
||||||
onImageAction={onImageAction}
|
|
||||||
renderTopRightUI={renderTopRightUI}
|
|
||||||
renderCustomStats={renderCustomStats}
|
|
||||||
renderSidebars={renderSidebars}
|
|
||||||
device={device}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!device.isMobile && (
|
|
||||||
<>
|
|
||||||
<div
|
|
||||||
className={clsx("layer-ui__wrapper", {
|
|
||||||
"disable-pointerEvents":
|
|
||||||
appState.draggingElement ||
|
|
||||||
appState.resizingElement ||
|
|
||||||
(appState.editingElement &&
|
|
||||||
!isTextElement(appState.editingElement)),
|
|
||||||
})}
|
|
||||||
style={
|
|
||||||
((appState.openSidebar === "library" &&
|
|
||||||
appState.isSidebarDocked) ||
|
|
||||||
hostSidebarCounters.docked) &&
|
|
||||||
device.canDeviceFitSidebar
|
|
||||||
? { width: `calc(100% - ${LIBRARY_SIDEBAR_WIDTH}px)` }
|
|
||||||
: {}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{renderFixedSideContainer()}
|
|
||||||
<Footer
|
|
||||||
appState={appState}
|
|
||||||
actionManager={actionManager}
|
|
||||||
renderCustomFooter={renderCustomFooter}
|
|
||||||
showExitZenModeBtn={showExitZenModeBtn}
|
|
||||||
/>
|
|
||||||
{appState.showStats && (
|
|
||||||
<Stats
|
|
||||||
appState={appState}
|
|
||||||
setAppState={setAppState}
|
|
||||||
elements={elements}
|
|
||||||
onClose={() => {
|
|
||||||
actionManager.executeAction(actionToggleStats);
|
|
||||||
}}
|
|
||||||
renderCustomStats={renderCustomStats}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{appState.scrolledOutside && (
|
|
||||||
<button
|
|
||||||
className="scroll-back-to-content"
|
|
||||||
onClick={() => {
|
|
||||||
setAppState({
|
|
||||||
...calculateScrollCenter(elements, appState, canvas),
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("buttons.scrollBackToContent")}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{renderSidebars()}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return deviceType.isMobile ? (
|
||||||
|
<>
|
||||||
|
{dialogs}
|
||||||
|
<MobileMenu
|
||||||
|
appState={appState}
|
||||||
|
elements={elements}
|
||||||
|
actionManager={actionManager}
|
||||||
|
libraryMenu={libraryMenu}
|
||||||
|
renderJSONExportDialog={renderJSONExportDialog}
|
||||||
|
renderImageExportDialog={renderImageExportDialog}
|
||||||
|
setAppState={setAppState}
|
||||||
|
onCollabButtonClick={onCollabButtonClick}
|
||||||
|
onLockToggle={() => onLockToggle()}
|
||||||
|
onPenModeToggle={onPenModeToggle}
|
||||||
|
canvas={canvas}
|
||||||
|
isCollaborating={isCollaborating}
|
||||||
|
renderCustomFooter={renderCustomFooter}
|
||||||
|
viewModeEnabled={viewModeEnabled}
|
||||||
|
showThemeBtn={showThemeBtn}
|
||||||
|
onImageAction={onImageAction}
|
||||||
|
renderTopRightUI={renderTopRightUI}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
className={clsx("layer-ui__wrapper", {
|
||||||
|
"disable-pointerEvents":
|
||||||
|
appState.draggingElement ||
|
||||||
|
appState.resizingElement ||
|
||||||
|
(appState.editingElement && !isTextElement(appState.editingElement)),
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{dialogs}
|
||||||
|
{renderFixedSideContainer()}
|
||||||
|
{renderBottomAppMenu()}
|
||||||
|
{appState.scrolledOutside && (
|
||||||
|
<button
|
||||||
|
className="scroll-back-to-content"
|
||||||
|
onClick={() => {
|
||||||
|
setAppState({
|
||||||
|
...calculateScrollCenter(elements, appState, canvas),
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("buttons.scrollBackToContent")}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const areEqual = (prev: LayerUIProps, next: LayerUIProps) => {
|
const areEqual = (prev: LayerUIProps, next: LayerUIProps) => {
|
||||||
@@ -482,12 +589,8 @@ const areEqual = (prev: LayerUIProps, next: LayerUIProps) => {
|
|||||||
const nextAppState = getNecessaryObj(next.appState);
|
const nextAppState = getNecessaryObj(next.appState);
|
||||||
|
|
||||||
const keys = Object.keys(prevAppState) as (keyof Partial<AppState>)[];
|
const keys = Object.keys(prevAppState) as (keyof Partial<AppState>)[];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
prev.renderCustomFooter === next.renderCustomFooter &&
|
prev.renderCustomFooter === next.renderCustomFooter &&
|
||||||
prev.renderTopRightUI === next.renderTopRightUI &&
|
|
||||||
prev.renderCustomStats === next.renderCustomStats &&
|
|
||||||
prev.renderCustomSidebar === next.renderCustomSidebar &&
|
|
||||||
prev.langCode === next.langCode &&
|
prev.langCode === next.langCode &&
|
||||||
prev.elements === next.elements &&
|
prev.elements === next.elements &&
|
||||||
prev.files === next.files &&
|
prev.files === next.files &&
|
||||||
|
@@ -3,8 +3,6 @@ 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 { useDevice } from "./App";
|
|
||||||
|
|
||||||
const LIBRARY_ICON = (
|
const LIBRARY_ICON = (
|
||||||
<svg viewBox="0 0 576 512">
|
<svg viewBox="0 0 576 512">
|
||||||
@@ -20,7 +18,6 @@ export const LibraryButton: React.FC<{
|
|||||||
setAppState: React.Component<any, AppState>["setState"];
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
isMobile?: boolean;
|
isMobile?: boolean;
|
||||||
}> = ({ appState, setAppState, isMobile }) => {
|
}> = ({ appState, setAppState, isMobile }) => {
|
||||||
const device = useDevice();
|
|
||||||
return (
|
return (
|
||||||
<label
|
<label
|
||||||
className={clsx(
|
className={clsx(
|
||||||
@@ -37,21 +34,9 @@ export const LibraryButton: React.FC<{
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="editor-library"
|
name="editor-library"
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
document
|
setAppState({ isLibraryOpen: event.target.checked });
|
||||||
.querySelector(".layer-ui__wrapper")
|
|
||||||
?.classList.remove("animate");
|
|
||||||
const isOpen = event.target.checked;
|
|
||||||
setAppState({ openSidebar: isOpen ? "library" : null });
|
|
||||||
// track only openings
|
|
||||||
if (isOpen) {
|
|
||||||
trackEvent(
|
|
||||||
"library",
|
|
||||||
"toggleLibrary (open)",
|
|
||||||
`toolbar (${device.isMobile ? "mobile" : "desktop"})`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
checked={appState.openSidebar === "library"}
|
checked={appState.isLibraryOpen}
|
||||||
aria-label={capitalizeString(t("toolBar.library"))}
|
aria-label={capitalizeString(t("toolBar.library"))}
|
||||||
aria-keyshortcuts="0"
|
aria-keyshortcuts="0"
|
||||||
/>
|
/>
|
||||||
|
@@ -1,22 +1,18 @@
|
|||||||
@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 {
|
||||||
|
margin: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
flex: 1 1 auto;
|
|
||||||
|
|
||||||
.layer-ui__library-header {
|
.layer-ui__library-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 2px 0 15px 0;
|
margin: 2px 0;
|
||||||
|
|
||||||
.Spinner {
|
.Spinner {
|
||||||
margin-right: 1rem;
|
margin-right: 1rem;
|
||||||
}
|
}
|
||||||
@@ -25,100 +21,12 @@
|
|||||||
// 2px from the left to account for focus border of left-most button
|
// 2px from the left to account for focus border of left-most button
|
||||||
margin: 0 2px;
|
margin: 0 2px;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.layer-ui__sidebar {
|
a {
|
||||||
.library-menu-items-container {
|
margin-inline-start: auto;
|
||||||
height: 100%;
|
// 17px for scrollbar (needed for overlay scrollbars on Big Sur?) + 1px extra
|
||||||
width: 100%;
|
padding-inline-end: 18px;
|
||||||
}
|
white-space: nowrap;
|
||||||
}
|
|
||||||
|
|
||||||
.library-actions {
|
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
margin-right: auto;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
button .library-actions-counter {
|
|
||||||
position: absolute;
|
|
||||||
right: 2px;
|
|
||||||
bottom: 2px;
|
|
||||||
border-radius: 50%;
|
|
||||||
width: 1em;
|
|
||||||
height: 1em;
|
|
||||||
padding: 1px;
|
|
||||||
font-size: 0.7rem;
|
|
||||||
background: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
&--remove {
|
|
||||||
background-color: $oc-red-7;
|
|
||||||
&:hover {
|
|
||||||
background-color: $oc-red-8;
|
|
||||||
}
|
|
||||||
&:active {
|
|
||||||
background-color: $oc-red-9;
|
|
||||||
}
|
|
||||||
svg {
|
|
||||||
color: $oc-white;
|
|
||||||
}
|
|
||||||
.library-actions-counter {
|
|
||||||
color: $oc-red-7;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&--export {
|
|
||||||
background-color: $oc-lime-5;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: $oc-lime-7;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:active {
|
|
||||||
background-color: $oc-lime-8;
|
|
||||||
}
|
|
||||||
svg {
|
|
||||||
color: $oc-white;
|
|
||||||
}
|
|
||||||
.library-actions-counter {
|
|
||||||
color: $oc-lime-5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&--publish {
|
|
||||||
background-color: $oc-cyan-6;
|
|
||||||
&:hover {
|
|
||||||
background-color: $oc-cyan-7;
|
|
||||||
}
|
|
||||||
&:active {
|
|
||||||
background-color: $oc-cyan-9;
|
|
||||||
}
|
|
||||||
svg {
|
|
||||||
color: $oc-white;
|
|
||||||
}
|
|
||||||
label {
|
|
||||||
margin-left: -0.2em;
|
|
||||||
margin-right: 1.1em;
|
|
||||||
color: $oc-white;
|
|
||||||
font-size: 0.86em;
|
|
||||||
}
|
|
||||||
.library-actions-counter {
|
|
||||||
color: $oc-cyan-6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&--load {
|
|
||||||
background-color: $oc-blue-6;
|
|
||||||
&:hover {
|
|
||||||
background-color: $oc-blue-7;
|
|
||||||
}
|
|
||||||
&:active {
|
|
||||||
background-color: $oc-blue-9;
|
|
||||||
}
|
|
||||||
svg {
|
|
||||||
color: $oc-white;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,38 +65,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.library-menu-browse-button {
|
|
||||||
width: 80%;
|
|
||||||
min-height: 22px;
|
|
||||||
margin: 0 auto;
|
|
||||||
margin-top: 1rem;
|
|
||||||
padding: 10px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
border-radius: var(--border-radius-lg);
|
|
||||||
background-color: var(--color-primary);
|
|
||||||
color: $oc-white;
|
|
||||||
text-align: center;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-decoration: none !important;
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--color-primary-darker);
|
|
||||||
}
|
|
||||||
&:active {
|
|
||||||
background-color: var(--color-primary-darkest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.library-menu-browse-button--mobile {
|
|
||||||
min-height: 22px;
|
|
||||||
margin-left: auto;
|
|
||||||
a {
|
|
||||||
padding-right: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -6,31 +6,30 @@ import {
|
|||||||
RefObject,
|
RefObject,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
} from "react";
|
} from "react";
|
||||||
import Library, {
|
import Library, { libraryItemsAtom } from "../data/library";
|
||||||
distributeLibraryItemsOnSquareGrid,
|
|
||||||
libraryItemsAtom,
|
|
||||||
} from "../data/library";
|
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { randomId } from "../random";
|
import { randomId } from "../random";
|
||||||
import { LibraryItems, LibraryItem, AppState, ExcalidrawProps } from "../types";
|
import {
|
||||||
|
LibraryItems,
|
||||||
|
LibraryItem,
|
||||||
|
AppState,
|
||||||
|
BinaryFiles,
|
||||||
|
ExcalidrawProps,
|
||||||
|
} from "../types";
|
||||||
|
import { Dialog } from "./Dialog";
|
||||||
|
import { Island } from "./Island";
|
||||||
|
import PublishLibrary from "./PublishLibrary";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
|
|
||||||
import "./LibraryMenu.scss";
|
import "./LibraryMenu.scss";
|
||||||
import LibraryMenuItems from "./LibraryMenuItems";
|
import LibraryMenuItems from "./LibraryMenuItems";
|
||||||
import { EVENT, VERSIONS } from "../constants";
|
import { EVENT } from "../constants";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
|
import { arrayToMap } from "../utils";
|
||||||
import { trackEvent } from "../analytics";
|
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,
|
|
||||||
useExcalidrawElements,
|
|
||||||
useExcalidrawSetAppState,
|
|
||||||
} from "./App";
|
|
||||||
import { Sidebar } from "./Sidebar/Sidebar";
|
|
||||||
import { getSelectedElements } from "../scene";
|
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
|
||||||
import { LibraryMenuHeader } from "./LibraryMenuHeaderContent";
|
|
||||||
|
|
||||||
const useOnClickOutside = (
|
const useOnClickOutside = (
|
||||||
ref: RefObject<HTMLElement>,
|
ref: RefObject<HTMLElement>,
|
||||||
@@ -60,45 +59,99 @@ const useOnClickOutside = (
|
|||||||
}, [ref, cb]);
|
}, [ref, cb]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSelectedItems = (
|
||||||
|
libraryItems: LibraryItems,
|
||||||
|
selectedItems: LibraryItem["id"][],
|
||||||
|
) => libraryItems.filter((item) => selectedItems.includes(item.id));
|
||||||
|
|
||||||
const LibraryMenuWrapper = forwardRef<
|
const LibraryMenuWrapper = forwardRef<
|
||||||
HTMLDivElement,
|
HTMLDivElement,
|
||||||
{ children: React.ReactNode }
|
{ children: React.ReactNode }
|
||||||
>(({ children }, ref) => {
|
>(({ children }, ref) => {
|
||||||
return (
|
return (
|
||||||
<div ref={ref} className="layer-ui__library">
|
<Island padding={1} ref={ref} className="layer-ui__library">
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</Island>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const LibraryMenuContent = ({
|
export const LibraryMenu = ({
|
||||||
onInsertLibraryItems,
|
onClose,
|
||||||
|
onInsertShape,
|
||||||
pendingElements,
|
pendingElements,
|
||||||
onAddToLibrary,
|
onAddToLibrary,
|
||||||
|
theme,
|
||||||
setAppState,
|
setAppState,
|
||||||
|
files,
|
||||||
libraryReturnUrl,
|
libraryReturnUrl,
|
||||||
|
focusContainer,
|
||||||
library,
|
library,
|
||||||
id,
|
id,
|
||||||
appState,
|
appState,
|
||||||
selectedItems,
|
|
||||||
onSelectItems,
|
|
||||||
}: {
|
}: {
|
||||||
pendingElements: LibraryItem["elements"];
|
pendingElements: LibraryItem["elements"];
|
||||||
onInsertLibraryItems: (libraryItems: LibraryItems) => void;
|
onClose: () => void;
|
||||||
|
onInsertShape: (elements: LibraryItem["elements"]) => void;
|
||||||
onAddToLibrary: () => void;
|
onAddToLibrary: () => void;
|
||||||
|
theme: AppState["theme"];
|
||||||
|
files: BinaryFiles;
|
||||||
setAppState: React.Component<any, AppState>["setState"];
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
||||||
|
focusContainer: () => void;
|
||||||
library: Library;
|
library: Library;
|
||||||
id: string;
|
id: string;
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
selectedItems: LibraryItem["id"][];
|
|
||||||
onSelectItems: (id: LibraryItem["id"][]) => void;
|
|
||||||
}) => {
|
}) => {
|
||||||
const referrer =
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
libraryReturnUrl || window.location.origin + window.location.pathname;
|
|
||||||
|
useOnClickOutside(ref, (event) => {
|
||||||
|
// If click on the library icon, do nothing.
|
||||||
|
if ((event.target as Element).closest(".ToolIcon__library")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onClose();
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === KEYS.ESCAPE) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener(EVENT.KEYDOWN, handleKeyDown);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener(EVENT.KEYDOWN, handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [onClose]);
|
||||||
|
|
||||||
|
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");
|
||||||
@@ -124,12 +177,64 @@ export const LibraryMenuContent = ({
|
|||||||
[onAddToLibrary, library, setAppState],
|
[onAddToLibrary, library, setAppState],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const renderPublishSuccess = useCallback(() => {
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
onCloseRequest={() => setPublishLibSuccess(null)}
|
||||||
|
title={t("publishSuccessDialog.title")}
|
||||||
|
className="publish-library-success"
|
||||||
|
small={true}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
{t("publishSuccessDialog.content", {
|
||||||
|
authorName: publishLibSuccess!.authorName,
|
||||||
|
})}{" "}
|
||||||
|
<a
|
||||||
|
href={publishLibSuccess?.url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{t("publishSuccessDialog.link")}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<ToolButton
|
||||||
|
type="button"
|
||||||
|
title={t("buttons.close")}
|
||||||
|
aria-label={t("buttons.close")}
|
||||||
|
label={t("buttons.close")}
|
||||||
|
onClick={() => setPublishLibSuccess(null)}
|
||||||
|
data-testid="publish-library-success-close"
|
||||||
|
className="publish-library-success-close"
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}, [setPublishLibSuccess, publishLibSuccess]);
|
||||||
|
|
||||||
|
const onPublishLibSuccess = useCallback(
|
||||||
|
(data, 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 [lastSelectedItem, setLastSelectedItem] = useState<
|
||||||
|
LibraryItem["id"] | null
|
||||||
|
>(null);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
libraryItemsData.status === "loading" &&
|
libraryItemsData.status === "loading" &&
|
||||||
!libraryItemsData.isInitialized
|
!libraryItemsData.isInitialized
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<LibraryMenuWrapper>
|
<LibraryMenuWrapper ref={ref}>
|
||||||
<div className="layer-ui__library-message">
|
<div className="layer-ui__library-message">
|
||||||
<Spinner size="2em" />
|
<Spinner size="2em" />
|
||||||
<span>{t("labels.libraryLoadingMessage")}</span>
|
<span>{t("labels.libraryLoadingMessage")}</span>
|
||||||
@@ -139,168 +244,90 @@ export const LibraryMenuContent = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LibraryMenuWrapper>
|
<LibraryMenuWrapper ref={ref}>
|
||||||
|
{showPublishLibraryDialog && (
|
||||||
|
<PublishLibrary
|
||||||
|
onClose={() => setShowPublishLibraryDialog(false)}
|
||||||
|
libraryItems={getSelectedItems(
|
||||||
|
libraryItemsData.libraryItems,
|
||||||
|
selectedItems,
|
||||||
|
)}
|
||||||
|
appState={appState}
|
||||||
|
onSuccess={(data) =>
|
||||||
|
onPublishLibSuccess(data, libraryItemsData.libraryItems)
|
||||||
|
}
|
||||||
|
onError={(error) => window.alert(error)}
|
||||||
|
updateItemsInStorage={() =>
|
||||||
|
library.setLibrary(libraryItemsData.libraryItems)
|
||||||
|
}
|
||||||
|
onRemove={(id: string) =>
|
||||||
|
setSelectedItems(selectedItems.filter((_id) => _id !== id))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{publishLibSuccess && renderPublishSuccess()}
|
||||||
<LibraryMenuItems
|
<LibraryMenuItems
|
||||||
isLoading={libraryItemsData.status === "loading"}
|
isLoading={libraryItemsData.status === "loading"}
|
||||||
libraryItems={libraryItemsData.libraryItems}
|
libraryItems={libraryItemsData.libraryItems}
|
||||||
|
onRemoveFromLibrary={() =>
|
||||||
|
removeFromLibrary(libraryItemsData.libraryItems)
|
||||||
|
}
|
||||||
onAddToLibrary={(elements) =>
|
onAddToLibrary={(elements) =>
|
||||||
addToLibrary(elements, libraryItemsData.libraryItems)
|
addToLibrary(elements, libraryItemsData.libraryItems)
|
||||||
}
|
}
|
||||||
onInsertLibraryItems={onInsertLibraryItems}
|
onInsertShape={onInsertShape}
|
||||||
pendingElements={pendingElements}
|
pendingElements={pendingElements}
|
||||||
selectedItems={selectedItems}
|
|
||||||
onSelectItems={onSelectItems}
|
|
||||||
/>
|
|
||||||
<a
|
|
||||||
className="library-menu-browse-button"
|
|
||||||
href={`${process.env.REACT_APP_LIBRARY_URL}?target=${
|
|
||||||
window.name || "_blank"
|
|
||||||
}&referrer=${referrer}&useHash=true&token=${id}&theme=${
|
|
||||||
appState.theme
|
|
||||||
}&version=${VERSIONS.excalidrawLibrary}`}
|
|
||||||
target="_excalidraw_libraries"
|
|
||||||
>
|
|
||||||
{t("labels.libraries")}
|
|
||||||
</a>
|
|
||||||
</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"
|
|
||||||
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}
|
setAppState={setAppState}
|
||||||
libraryReturnUrl={libraryReturnUrl}
|
libraryReturnUrl={libraryReturnUrl}
|
||||||
library={library}
|
library={library}
|
||||||
|
theme={theme}
|
||||||
|
files={files}
|
||||||
id={id}
|
id={id}
|
||||||
appState={appState}
|
|
||||||
selectedItems={selectedItems}
|
selectedItems={selectedItems}
|
||||||
onSelectItems={setSelectedItems}
|
onToggle={(id, event) => {
|
||||||
|
const shouldSelect = !selectedItems.includes(id);
|
||||||
|
|
||||||
|
if (shouldSelect) {
|
||||||
|
if (event.shiftKey && lastSelectedItem) {
|
||||||
|
const rangeStart = libraryItemsData.libraryItems.findIndex(
|
||||||
|
(item) => item.id === lastSelectedItem,
|
||||||
|
);
|
||||||
|
const rangeEnd = libraryItemsData.libraryItems.findIndex(
|
||||||
|
(item) => item.id === id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rangeStart === -1 || rangeEnd === -1) {
|
||||||
|
setSelectedItems([...selectedItems, id]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedItemsMap = arrayToMap(selectedItems);
|
||||||
|
const nextSelectedIds = libraryItemsData.libraryItems.reduce(
|
||||||
|
(acc: LibraryItem["id"][], item, idx) => {
|
||||||
|
if (
|
||||||
|
(idx >= rangeStart && idx <= rangeEnd) ||
|
||||||
|
selectedItemsMap.has(item.id)
|
||||||
|
) {
|
||||||
|
acc.push(item.id);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
setSelectedItems(nextSelectedIds);
|
||||||
|
} else {
|
||||||
|
setSelectedItems([...selectedItems, id]);
|
||||||
|
}
|
||||||
|
setLastSelectedItem(id);
|
||||||
|
} else {
|
||||||
|
setLastSelectedItem(null);
|
||||||
|
setSelectedItems(selectedItems.filter((_id) => _id !== id));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onPublish={() => setShowPublishLibraryDialog(true)}
|
||||||
|
resetLibrary={resetLibrary}
|
||||||
/>
|
/>
|
||||||
</Sidebar>
|
</LibraryMenuWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -1,258 +0,0 @@
|
|||||||
import React, { useCallback, useState } from "react";
|
|
||||||
import { saveLibraryAsJSON } from "../data/json";
|
|
||||||
import Library, { libraryItemsAtom } from "../data/library";
|
|
||||||
import { t } from "../i18n";
|
|
||||||
import { AppState, LibraryItem, LibraryItems } from "../types";
|
|
||||||
import { exportToFileIcon, load, publishIcon, trash } from "./icons";
|
|
||||||
import { ToolButton } from "./ToolButton";
|
|
||||||
import { Tooltip } from "./Tooltip";
|
|
||||||
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";
|
|
||||||
|
|
||||||
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 });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="library-actions">
|
|
||||||
{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()}
|
|
||||||
{!itemsSelected && (
|
|
||||||
<ToolButton
|
|
||||||
key="import"
|
|
||||||
type="button"
|
|
||||||
title={t("buttons.load")}
|
|
||||||
aria-label={t("buttons.load")}
|
|
||||||
icon={load}
|
|
||||||
onClick={onLibraryImport}
|
|
||||||
className="library-actions--load"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{!!items.length && (
|
|
||||||
<>
|
|
||||||
<ToolButton
|
|
||||||
key="export"
|
|
||||||
type="button"
|
|
||||||
title={t("buttons.export")}
|
|
||||||
aria-label={t("buttons.export")}
|
|
||||||
icon={exportToFileIcon}
|
|
||||||
onClick={onLibraryExport}
|
|
||||||
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={() => setShowPublishLibraryDialog(true)}
|
|
||||||
>
|
|
||||||
<label>{t("buttons.publishLibrary")}</label>
|
|
||||||
{selectedItems.length > 0 && (
|
|
||||||
<span className="library-actions-counter">
|
|
||||||
{selectedItems.length}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</ToolButton>
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
@@ -2,21 +2,97 @@
|
|||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.library-menu-items-container {
|
.library-menu-items-container {
|
||||||
display: flex;
|
.library-actions {
|
||||||
flex-direction: column;
|
display: flex;
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
|
button .library-actions-counter {
|
||||||
|
position: absolute;
|
||||||
|
right: 2px;
|
||||||
|
bottom: 2px;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
padding: 1px;
|
||||||
|
font-size: 0.7rem;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--remove {
|
||||||
|
background-color: $oc-red-7;
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-red-8;
|
||||||
|
}
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-red-9;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
.library-actions-counter {
|
||||||
|
color: $oc-red-7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--export {
|
||||||
|
background-color: $oc-lime-5;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-lime-7;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-lime-8;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
.library-actions-counter {
|
||||||
|
color: $oc-lime-5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--publish {
|
||||||
|
background-color: $oc-cyan-6;
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-cyan-7;
|
||||||
|
}
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-cyan-9;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
margin-left: -0.2em;
|
||||||
|
margin-right: 1.1em;
|
||||||
|
color: $oc-white;
|
||||||
|
font-size: 0.86em;
|
||||||
|
}
|
||||||
|
.library-actions-counter {
|
||||||
|
color: $oc-cyan-6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--load {
|
||||||
|
background-color: $oc-blue-6;
|
||||||
|
&:hover {
|
||||||
|
background-color: $oc-blue-7;
|
||||||
|
}
|
||||||
|
&:active {
|
||||||
|
background-color: $oc-blue-9;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
color: $oc-white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
&__items {
|
&__items {
|
||||||
flex: 1;
|
max-height: 50vh;
|
||||||
overflow-y: auto;
|
overflow: auto;
|
||||||
overflow-x: hidden;
|
margin-top: 0.5rem;
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.separator {
|
.separator {
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
margin: 0.6em 0.2em;
|
margin: 0.6em 0.2em;
|
||||||
|
@@ -1,95 +1,196 @@
|
|||||||
import React, { useState } from "react";
|
import { chunk } from "lodash";
|
||||||
import { serializeLibraryAsJSON } from "../data/json";
|
import { useCallback, useState } from "react";
|
||||||
|
import { importLibraryFromJSON, saveLibraryAsJSON } 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 { LibraryItem, LibraryItems } from "../types";
|
import {
|
||||||
import { arrayToMap, chunk } from "../utils";
|
AppState,
|
||||||
|
BinaryFiles,
|
||||||
|
ExcalidrawProps,
|
||||||
|
LibraryItem,
|
||||||
|
LibraryItems,
|
||||||
|
} from "../types";
|
||||||
|
import { muteFSAbortError } from "../utils";
|
||||||
|
import { useDeviceType } from "./App";
|
||||||
|
import ConfirmDialog from "./ConfirmDialog";
|
||||||
|
import { exportToFileIcon, load, publishIcon, trash } from "./icons";
|
||||||
import { LibraryUnit } from "./LibraryUnit";
|
import { LibraryUnit } from "./LibraryUnit";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
|
import { ToolButton } from "./ToolButton";
|
||||||
|
import { Tooltip } from "./Tooltip";
|
||||||
|
|
||||||
import "./LibraryMenuItems.scss";
|
import "./LibraryMenuItems.scss";
|
||||||
import { MIME_TYPES } from "../constants";
|
import { VERSIONS } from "../constants";
|
||||||
import Spinner from "./Spinner";
|
import Spinner from "./Spinner";
|
||||||
|
|
||||||
const CELLS_PER_ROW = 4;
|
|
||||||
|
|
||||||
const LibraryMenuItems = ({
|
const LibraryMenuItems = ({
|
||||||
isLoading,
|
isLoading,
|
||||||
libraryItems,
|
libraryItems,
|
||||||
|
onRemoveFromLibrary,
|
||||||
onAddToLibrary,
|
onAddToLibrary,
|
||||||
onInsertLibraryItems,
|
onInsertShape,
|
||||||
pendingElements,
|
pendingElements,
|
||||||
|
theme,
|
||||||
|
setAppState,
|
||||||
|
libraryReturnUrl,
|
||||||
|
library,
|
||||||
|
files,
|
||||||
|
id,
|
||||||
selectedItems,
|
selectedItems,
|
||||||
onSelectItems,
|
onToggle,
|
||||||
|
onPublish,
|
||||||
|
resetLibrary,
|
||||||
}: {
|
}: {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
libraryItems: LibraryItems;
|
libraryItems: LibraryItems;
|
||||||
pendingElements: LibraryItem["elements"];
|
pendingElements: LibraryItem["elements"];
|
||||||
onInsertLibraryItems: (libraryItems: LibraryItems) => void;
|
onRemoveFromLibrary: () => void;
|
||||||
|
onInsertShape: (elements: LibraryItem["elements"]) => void;
|
||||||
onAddToLibrary: (elements: LibraryItem["elements"]) => void;
|
onAddToLibrary: (elements: LibraryItem["elements"]) => void;
|
||||||
|
theme: AppState["theme"];
|
||||||
|
files: BinaryFiles;
|
||||||
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
|
libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"];
|
||||||
|
library: Library;
|
||||||
|
id: string;
|
||||||
selectedItems: LibraryItem["id"][];
|
selectedItems: LibraryItem["id"][];
|
||||||
onSelectItems: (id: LibraryItem["id"][]) => void;
|
onToggle: (id: LibraryItem["id"], event: React.MouseEvent) => void;
|
||||||
|
onPublish: () => void;
|
||||||
|
resetLibrary: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const [lastSelectedItem, setLastSelectedItem] = useState<
|
const renderRemoveLibAlert = useCallback(() => {
|
||||||
LibraryItem["id"] | null
|
const content = selectedItems.length
|
||||||
>(null);
|
? 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 onItemSelectToggle = (
|
const [showRemoveLibAlert, setShowRemoveLibAlert] = useState(false);
|
||||||
id: LibraryItem["id"],
|
|
||||||
event: React.MouseEvent,
|
|
||||||
) => {
|
|
||||||
const shouldSelect = !selectedItems.includes(id);
|
|
||||||
|
|
||||||
const orderedItems = [...unpublishedItems, ...publishedItems];
|
const isMobile = useDeviceType().isMobile;
|
||||||
|
|
||||||
if (shouldSelect) {
|
const renderLibraryActions = () => {
|
||||||
if (event.shiftKey && lastSelectedItem) {
|
const itemsSelected = !!selectedItems.length;
|
||||||
const rangeStart = orderedItems.findIndex(
|
const items = itemsSelected
|
||||||
(item) => item.id === lastSelectedItem,
|
? libraryItems.filter((item) => selectedItems.includes(item.id))
|
||||||
);
|
: libraryItems;
|
||||||
const rangeEnd = orderedItems.findIndex((item) => item.id === id);
|
const resetLabel = itemsSelected
|
||||||
|
? t("buttons.remove")
|
||||||
if (rangeStart === -1 || rangeEnd === -1) {
|
: t("buttons.resetLibrary");
|
||||||
onSelectItems([...selectedItems, id]);
|
return (
|
||||||
return;
|
<div className="library-actions">
|
||||||
}
|
{(!itemsSelected || !isMobile) && (
|
||||||
|
<ToolButton
|
||||||
const selectedItemsMap = arrayToMap(selectedItems);
|
key="import"
|
||||||
const nextSelectedIds = orderedItems.reduce(
|
type="button"
|
||||||
(acc: LibraryItem["id"][], item, idx) => {
|
title={t("buttons.load")}
|
||||||
if (
|
aria-label={t("buttons.load")}
|
||||||
(idx >= rangeStart && idx <= rangeEnd) ||
|
icon={load}
|
||||||
selectedItemsMap.has(item.id)
|
onClick={() => {
|
||||||
) {
|
importLibraryFromJSON(library)
|
||||||
acc.push(item.id);
|
.catch(muteFSAbortError)
|
||||||
}
|
.catch((error) => {
|
||||||
return acc;
|
console.error(error);
|
||||||
},
|
setAppState({ errorMessage: t("errors.importLibraryError") });
|
||||||
[],
|
});
|
||||||
);
|
}}
|
||||||
|
className="library-actions--load"
|
||||||
onSelectItems(nextSelectedIds);
|
/>
|
||||||
} else {
|
)}
|
||||||
onSelectItems([...selectedItems, id]);
|
{!!items.length && (
|
||||||
}
|
<>
|
||||||
setLastSelectedItem(id);
|
<ToolButton
|
||||||
} else {
|
key="export"
|
||||||
setLastSelectedItem(null);
|
type="button"
|
||||||
onSelectItems(selectedItems.filter((_id) => _id !== id));
|
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 && !isPublished && (
|
||||||
|
<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}
|
||||||
|
>
|
||||||
|
{!isMobile && <label>{t("buttons.publishLibrary")}</label>}
|
||||||
|
{selectedItems.length > 0 && (
|
||||||
|
<span className="library-actions-counter">
|
||||||
|
{selectedItems.length}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</ToolButton>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getInsertedElements = (id: string) => {
|
const CELLS_PER_ROW = isMobile ? 4 : 6;
|
||||||
let targetElements;
|
|
||||||
if (selectedItems.includes(id)) {
|
const referrer =
|
||||||
targetElements = libraryItems.filter((item) =>
|
libraryReturnUrl || window.location.origin + window.location.pathname;
|
||||||
selectedItems.includes(item.id),
|
const isPublished = selectedItems.some(
|
||||||
);
|
(id) => libraryItems.find((item) => item.id === id)?.status === "published",
|
||||||
} else {
|
);
|
||||||
targetElements = libraryItems.filter((item) => item.id === id);
|
|
||||||
}
|
|
||||||
return targetElements;
|
|
||||||
};
|
|
||||||
|
|
||||||
const createLibraryItemCompo = (params: {
|
const createLibraryItemCompo = (params: {
|
||||||
item:
|
item:
|
||||||
@@ -106,16 +207,13 @@ 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}
|
||||||
selected={!!params.item?.id && selectedItems.includes(params.item.id)}
|
selected={!!params.item?.id && selectedItems.includes(params.item.id)}
|
||||||
onToggle={onItemSelectToggle}
|
onToggle={(id, event) => {
|
||||||
onDrag={(id, event) => {
|
onToggle(id, event);
|
||||||
event.dataTransfer.setData(
|
|
||||||
MIME_TYPES.excalidrawlib,
|
|
||||||
serializeLibraryAsJSON(getInsertedElements(id)),
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
@@ -135,7 +233,7 @@ const LibraryMenuItems = ({
|
|||||||
if (item.id) {
|
if (item.id) {
|
||||||
return createLibraryItemCompo({
|
return createLibraryItemCompo({
|
||||||
item,
|
item,
|
||||||
onClick: () => onInsertLibraryItems(getInsertedElements(item.id)),
|
onClick: () => onInsertShape(item.elements),
|
||||||
key: item.id,
|
key: item.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -174,120 +272,51 @@ const LibraryMenuItems = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const unpublishedItems = libraryItems.filter(
|
|
||||||
(item) => item.status !== "published",
|
|
||||||
);
|
|
||||||
const publishedItems = libraryItems.filter(
|
const publishedItems = libraryItems.filter(
|
||||||
(item) => item.status === "published",
|
(item) => item.status === "published",
|
||||||
);
|
);
|
||||||
|
const unpublishedItems = [
|
||||||
|
// append pending library item
|
||||||
|
...(pendingElements.length
|
||||||
|
? [{ id: null, elements: pendingElements }]
|
||||||
|
: []),
|
||||||
|
...libraryItems.filter((item) => item.status !== "published"),
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="library-menu-items-container">
|
||||||
className="library-menu-items-container"
|
{showRemoveLibAlert && renderRemoveLibAlert()}
|
||||||
style={
|
<div className="layer-ui__library-header" key="library-header">
|
||||||
publishedItems.length || unpublishedItems.length
|
{renderLibraryActions()}
|
||||||
? {
|
{isLoading ? (
|
||||||
flex: "1 1 0",
|
<Spinner />
|
||||||
overflowY: "auto",
|
) : (
|
||||||
}
|
<a
|
||||||
: {
|
href={`${process.env.REACT_APP_LIBRARY_URL}?target=${
|
||||||
marginBottom: "2rem",
|
window.name || "_blank"
|
||||||
flex: 0,
|
}&referrer=${referrer}&useHash=true&token=${id}&theme=${theme}&version=${
|
||||||
}
|
VERSIONS.excalidrawLibrary
|
||||||
}
|
}`}
|
||||||
>
|
target="_excalidraw_libraries"
|
||||||
|
>
|
||||||
|
{t("labels.libraries")}
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Stack.Col
|
<Stack.Col
|
||||||
className="library-menu-items-container__items"
|
className="library-menu-items-container__items"
|
||||||
align="start"
|
align="start"
|
||||||
gap={1}
|
gap={1}
|
||||||
style={{
|
|
||||||
flex: publishedItems.length > 0 ? 1 : "0 1 auto",
|
|
||||||
marginBottom: 0,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<div className="separator">
|
<div className="separator">{t("labels.personalLib")}</div>
|
||||||
{(pendingElements.length > 0 ||
|
{renderLibrarySection(unpublishedItems)}
|
||||||
unpublishedItems.length > 0 ||
|
|
||||||
publishedItems.length > 0) && (
|
|
||||||
<div>{t("labels.personalLib")}</div>
|
|
||||||
)}
|
|
||||||
{isLoading && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
marginLeft: "auto",
|
|
||||||
marginRight: "1rem",
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
fontWeight: "normal",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ transform: "translateY(2px)" }}>
|
|
||||||
<Spinner />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{!pendingElements.length && !unpublishedItems.length ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: 65,
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
width: "100%",
|
|
||||||
fontSize: ".9rem",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("library.noItems")}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: ".6rem 0",
|
|
||||||
fontSize: ".8em",
|
|
||||||
width: "70%",
|
|
||||||
textAlign: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{publishedItems.length > 0
|
|
||||||
? t("library.hint_emptyPrivateLibrary")
|
|
||||||
: t("library.hint_emptyLibrary")}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
renderLibrarySection([
|
|
||||||
// append pending library item
|
|
||||||
...(pendingElements.length
|
|
||||||
? [{ id: null, elements: pendingElements }]
|
|
||||||
: []),
|
|
||||||
...unpublishedItems,
|
|
||||||
])
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
|
|
||||||
<>
|
<>
|
||||||
{(publishedItems.length > 0 ||
|
<div className="separator">{t("labels.excalidrawLib")} </div>
|
||||||
pendingElements.length > 0 ||
|
|
||||||
unpublishedItems.length > 0) && (
|
{renderLibrarySection(publishedItems)}
|
||||||
<div className="separator">{t("labels.excalidrawLib")}</div>
|
|
||||||
)}
|
|
||||||
{publishedItems.length > 0 ? (
|
|
||||||
renderLibrarySection(publishedItems)
|
|
||||||
) : unpublishedItems.length > 0 ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: "1rem 0",
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
width: "100%",
|
|
||||||
fontSize: ".9rem",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("library.noItems")}
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
</>
|
</>
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
.excalidraw {
|
.excalidraw {
|
||||||
.library-unit {
|
.library-unit {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border: 1px solid transparent;
|
border: 1px solid var(--button-gray-2);
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -21,6 +21,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.theme--dark .library-unit {
|
||||||
|
border-color: rgb(48, 48, 48);
|
||||||
|
}
|
||||||
|
|
||||||
.library-unit__dragger {
|
.library-unit__dragger {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import oc from "open-color";
|
import oc from "open-color";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useDevice } from "../components/App";
|
import { MIME_TYPES } from "../constants";
|
||||||
|
import { useDeviceType } from "../components/App";
|
||||||
import { exportToSvg } from "../scene/export";
|
import { exportToSvg } from "../scene/export";
|
||||||
import { LibraryItem } from "../types";
|
import { BinaryFiles, LibraryItem } from "../types";
|
||||||
import "./LibraryUnit.scss";
|
import "./LibraryUnit.scss";
|
||||||
import { CheckboxItem } from "./CheckboxItem";
|
import { CheckboxItem } from "./CheckboxItem";
|
||||||
|
|
||||||
@@ -23,19 +24,19 @@ const PLUS_ICON = (
|
|||||||
export const LibraryUnit = ({
|
export const LibraryUnit = ({
|
||||||
id,
|
id,
|
||||||
elements,
|
elements,
|
||||||
|
files,
|
||||||
isPending,
|
isPending,
|
||||||
onClick,
|
onClick,
|
||||||
selected,
|
selected,
|
||||||
onToggle,
|
onToggle,
|
||||||
onDrag,
|
|
||||||
}: {
|
}: {
|
||||||
id: LibraryItem["id"] | /** for pending item */ null;
|
id: LibraryItem["id"] | /** for pending item */ null;
|
||||||
elements?: LibraryItem["elements"];
|
elements?: LibraryItem["elements"];
|
||||||
|
files: BinaryFiles;
|
||||||
isPending?: boolean;
|
isPending?: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
onToggle: (id: string, event: React.MouseEvent) => void;
|
onToggle: (id: string, event: React.MouseEvent) => void;
|
||||||
onDrag: (id: string, event: React.DragEvent) => void;
|
|
||||||
}) => {
|
}) => {
|
||||||
const ref = useRef<HTMLDivElement | null>(null);
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -54,7 +55,7 @@ export const LibraryUnit = ({
|
|||||||
exportBackground: false,
|
exportBackground: false,
|
||||||
viewBackgroundColor: oc.white,
|
viewBackgroundColor: oc.white,
|
||||||
},
|
},
|
||||||
null,
|
files,
|
||||||
);
|
);
|
||||||
node.innerHTML = svg.outerHTML;
|
node.innerHTML = svg.outerHTML;
|
||||||
})();
|
})();
|
||||||
@@ -62,10 +63,10 @@ export const LibraryUnit = ({
|
|||||||
return () => {
|
return () => {
|
||||||
node.innerHTML = "";
|
node.innerHTML = "";
|
||||||
};
|
};
|
||||||
}, [elements]);
|
}, [elements, files]);
|
||||||
|
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const isMobile = useDevice().isMobile;
|
const isMobile = useDeviceType().isMobile;
|
||||||
const adder = isPending && (
|
const adder = isPending && (
|
||||||
<div className="library-unit__adder">{PLUS_ICON}</div>
|
<div className="library-unit__adder">{PLUS_ICON}</div>
|
||||||
);
|
);
|
||||||
@@ -98,12 +99,11 @@ export const LibraryUnit = ({
|
|||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
onDragStart={(event) => {
|
onDragStart={(event) => {
|
||||||
if (!id) {
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setIsHovered(false);
|
setIsHovered(false);
|
||||||
onDrag(id, event);
|
event.dataTransfer.setData(
|
||||||
|
MIME_TYPES.excalidrawlib,
|
||||||
|
JSON.stringify(elements),
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{adder}
|
{adder}
|
||||||
|
@@ -1,14 +1,8 @@
|
|||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import Spinner from "./Spinner";
|
import Spinner from "./Spinner";
|
||||||
import clsx from "clsx";
|
|
||||||
import { THEME } from "../constants";
|
|
||||||
import { Theme } from "../element/types";
|
|
||||||
|
|
||||||
export const LoadingMessage: React.FC<{ delay?: number; theme?: Theme }> = ({
|
export const LoadingMessage: React.FC<{ delay?: number }> = ({ delay }) => {
|
||||||
delay,
|
|
||||||
theme,
|
|
||||||
}) => {
|
|
||||||
const [isWaiting, setIsWaiting] = useState(!!delay);
|
const [isWaiting, setIsWaiting] = useState(!!delay);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -26,11 +20,7 @@ export const LoadingMessage: React.FC<{ delay?: number; theme?: Theme }> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="LoadingMessage">
|
||||||
className={clsx("LoadingMessage", {
|
|
||||||
"LoadingMessage--dark": theme === THEME.DARK,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<div>
|
<div>
|
||||||
<Spinner />
|
<Spinner />
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { AppState, Device, ExcalidrawProps } from "../types";
|
import { AppState } from "../types";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
@@ -18,8 +18,6 @@ import { UserList } from "./UserList";
|
|||||||
import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";
|
import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";
|
||||||
import { LibraryButton } from "./LibraryButton";
|
import { LibraryButton } from "./LibraryButton";
|
||||||
import { PenModeButton } from "./PenModeButton";
|
import { PenModeButton } from "./PenModeButton";
|
||||||
import { Stats } from "./Stats";
|
|
||||||
import { actionToggleStats } from "../actions";
|
|
||||||
|
|
||||||
type MobileMenuProps = {
|
type MobileMenuProps = {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
@@ -28,28 +26,26 @@ type MobileMenuProps = {
|
|||||||
renderImageExportDialog: () => React.ReactNode;
|
renderImageExportDialog: () => React.ReactNode;
|
||||||
setAppState: React.Component<any, AppState>["setState"];
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
|
libraryMenu: JSX.Element | null;
|
||||||
onCollabButtonClick?: () => void;
|
onCollabButtonClick?: () => void;
|
||||||
onLockToggle: () => void;
|
onLockToggle: () => void;
|
||||||
onPenModeToggle: () => void;
|
onPenModeToggle: () => void;
|
||||||
canvas: HTMLCanvasElement | null;
|
canvas: HTMLCanvasElement | null;
|
||||||
isCollaborating: boolean;
|
isCollaborating: boolean;
|
||||||
renderCustomFooter?: (
|
renderCustomFooter?: (isMobile: boolean, appState: AppState) => JSX.Element;
|
||||||
isMobile: boolean,
|
viewModeEnabled: boolean;
|
||||||
appState: AppState,
|
showThemeBtn: boolean;
|
||||||
) => JSX.Element | null;
|
|
||||||
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
||||||
renderTopRightUI?: (
|
renderTopRightUI?: (
|
||||||
isMobile: boolean,
|
isMobile: boolean,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
) => JSX.Element | null;
|
) => JSX.Element | null;
|
||||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
|
||||||
renderSidebars: () => JSX.Element | null;
|
|
||||||
device: Device;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MobileMenu = ({
|
export const MobileMenu = ({
|
||||||
appState,
|
appState,
|
||||||
elements,
|
elements,
|
||||||
|
libraryMenu,
|
||||||
actionManager,
|
actionManager,
|
||||||
renderJSONExportDialog,
|
renderJSONExportDialog,
|
||||||
renderImageExportDialog,
|
renderImageExportDialog,
|
||||||
@@ -60,17 +56,16 @@ export const MobileMenu = ({
|
|||||||
canvas,
|
canvas,
|
||||||
isCollaborating,
|
isCollaborating,
|
||||||
renderCustomFooter,
|
renderCustomFooter,
|
||||||
|
viewModeEnabled,
|
||||||
|
showThemeBtn,
|
||||||
onImageAction,
|
onImageAction,
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomStats,
|
|
||||||
renderSidebars,
|
|
||||||
device,
|
|
||||||
}: MobileMenuProps) => {
|
}: MobileMenuProps) => {
|
||||||
const renderToolbar = () => {
|
const renderToolbar = () => {
|
||||||
return (
|
return (
|
||||||
<FixedSideContainer side="top" className="App-top-bar">
|
<FixedSideContainer side="top" className="App-top-bar">
|
||||||
<Section heading="shapes">
|
<Section heading="shapes">
|
||||||
{(heading: React.ReactNode) => (
|
{(heading) => (
|
||||||
<Stack.Col gap={4} align="center">
|
<Stack.Col gap={4} align="center">
|
||||||
<Stack.Row gap={1} className="App-toolbar-container">
|
<Stack.Row gap={1} className="App-toolbar-container">
|
||||||
<Island padding={1} className="App-toolbar">
|
<Island padding={1} className="App-toolbar">
|
||||||
@@ -109,15 +104,11 @@ export const MobileMenu = ({
|
|||||||
penDetected={appState.penDetected}
|
penDetected={appState.penDetected}
|
||||||
/>
|
/>
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
|
{libraryMenu}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
)}
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
<HintViewer
|
<HintViewer appState={appState} elements={elements} isMobile={true} />
|
||||||
appState={appState}
|
|
||||||
elements={elements}
|
|
||||||
isMobile={true}
|
|
||||||
device={device}
|
|
||||||
/>
|
|
||||||
</FixedSideContainer>
|
</FixedSideContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -125,10 +116,11 @@ export const MobileMenu = ({
|
|||||||
const renderAppToolbar = () => {
|
const renderAppToolbar = () => {
|
||||||
// Render eraser conditionally in mobile
|
// Render eraser conditionally in mobile
|
||||||
const showEraser =
|
const showEraser =
|
||||||
|
!appState.viewModeEnabled &&
|
||||||
!appState.editingElement &&
|
!appState.editingElement &&
|
||||||
getSelectedElements(elements, appState).length === 0;
|
getSelectedElements(elements, appState).length === 0;
|
||||||
|
|
||||||
if (appState.viewModeEnabled) {
|
if (viewModeEnabled) {
|
||||||
return (
|
return (
|
||||||
<div className="App-toolbar-content">
|
<div className="App-toolbar-content">
|
||||||
{actionManager.renderAction("toggleCanvasMenu")}
|
{actionManager.renderAction("toggleCanvasMenu")}
|
||||||
@@ -143,18 +135,18 @@ export const MobileMenu = ({
|
|||||||
|
|
||||||
{actionManager.renderAction("undo")}
|
{actionManager.renderAction("undo")}
|
||||||
{actionManager.renderAction("redo")}
|
{actionManager.renderAction("redo")}
|
||||||
{showEraser
|
{showEraser && actionManager.renderAction("eraser")}
|
||||||
? actionManager.renderAction("eraser")
|
|
||||||
: actionManager.renderAction(
|
{actionManager.renderAction(
|
||||||
appState.multiElement ? "finalize" : "duplicateSelection",
|
appState.multiElement ? "finalize" : "duplicateSelection",
|
||||||
)}
|
)}
|
||||||
{actionManager.renderAction("deleteSelectedElements")}
|
{actionManager.renderAction("deleteSelectedElements")}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderCanvasActions = () => {
|
const renderCanvasActions = () => {
|
||||||
if (appState.viewModeEnabled) {
|
if (viewModeEnabled) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{renderJSONExportDialog()}
|
{renderJSONExportDialog()}
|
||||||
@@ -175,25 +167,20 @@ export const MobileMenu = ({
|
|||||||
onClick={onCollabButtonClick}
|
onClick={onCollabButtonClick}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{<BackgroundPickerAndDarkModeToggle actionManager={actionManager} />}
|
{
|
||||||
|
<BackgroundPickerAndDarkModeToggle
|
||||||
|
actionManager={actionManager}
|
||||||
|
appState={appState}
|
||||||
|
setAppState={setAppState}
|
||||||
|
showThemeBtn={showThemeBtn}
|
||||||
|
/>
|
||||||
|
}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{renderSidebars()}
|
{!viewModeEnabled && renderToolbar()}
|
||||||
{!appState.viewModeEnabled && renderToolbar()}
|
|
||||||
{!appState.openMenu && appState.showStats && (
|
|
||||||
<Stats
|
|
||||||
appState={appState}
|
|
||||||
setAppState={setAppState}
|
|
||||||
elements={elements}
|
|
||||||
onClose={() => {
|
|
||||||
actionManager.executeAction(actionToggleStats);
|
|
||||||
}}
|
|
||||||
renderCustomStats={renderCustomStats}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div
|
<div
|
||||||
className="App-bottom-bar"
|
className="App-bottom-bar"
|
||||||
style={{
|
style={{
|
||||||
@@ -212,43 +199,51 @@ export const MobileMenu = ({
|
|||||||
{appState.collaborators.size > 0 && (
|
{appState.collaborators.size > 0 && (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.collaborators")}</legend>
|
<legend>{t("labels.collaborators")}</legend>
|
||||||
<UserList
|
<UserList mobile>
|
||||||
mobile
|
{Array.from(appState.collaborators)
|
||||||
collaborators={appState.collaborators}
|
// Collaborator is either not initialized or is actually the current user.
|
||||||
actionManager={actionManager}
|
.filter(
|
||||||
/>
|
([_, client]) => Object.keys(client).length !== 0,
|
||||||
|
)
|
||||||
|
.map(([clientId, client]) => (
|
||||||
|
<React.Fragment key={clientId}>
|
||||||
|
{actionManager.renderAction("goToCollaborator", {
|
||||||
|
id: clientId,
|
||||||
|
})}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</UserList>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
)}
|
)}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
</div>
|
</div>
|
||||||
</Section>
|
</Section>
|
||||||
) : appState.openMenu === "shape" &&
|
) : appState.openMenu === "shape" &&
|
||||||
!appState.viewModeEnabled &&
|
!viewModeEnabled &&
|
||||||
showSelectedShapeActions(appState, elements) ? (
|
showSelectedShapeActions(appState, elements) ? (
|
||||||
<Section className="App-mobile-menu" heading="selectedShapeActions">
|
<Section className="App-mobile-menu" heading="selectedShapeActions">
|
||||||
<SelectedShapeActions
|
<SelectedShapeActions
|
||||||
appState={appState}
|
appState={appState}
|
||||||
elements={elements}
|
elements={elements}
|
||||||
renderAction={actionManager.renderAction}
|
renderAction={actionManager.renderAction}
|
||||||
|
activeTool={appState.activeTool.type}
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
) : null}
|
) : null}
|
||||||
<footer className="App-toolbar">
|
<footer className="App-toolbar">
|
||||||
{renderAppToolbar()}
|
{renderAppToolbar()}
|
||||||
{appState.scrolledOutside &&
|
{appState.scrolledOutside && !appState.openMenu && (
|
||||||
!appState.openMenu &&
|
<button
|
||||||
appState.openSidebar !== "library" && (
|
className="scroll-back-to-content"
|
||||||
<button
|
onClick={() => {
|
||||||
className="scroll-back-to-content"
|
setAppState({
|
||||||
onClick={() => {
|
...calculateScrollCenter(elements, appState, canvas),
|
||||||
setAppState({
|
});
|
||||||
...calculateScrollCenter(elements, appState, canvas),
|
}}
|
||||||
});
|
>
|
||||||
}}
|
{t("buttons.scrollBackToContent")}
|
||||||
>
|
</button>
|
||||||
{t("buttons.scrollBackToContent")}
|
)}
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</footer>
|
</footer>
|
||||||
</Island>
|
</Island>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -4,11 +4,11 @@ import React, { useState, useLayoutEffect, useRef } from "react";
|
|||||||
import { createPortal } from "react-dom";
|
import { createPortal } from "react-dom";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { useExcalidrawContainer, useDevice } from "./App";
|
import { useExcalidrawContainer, useDeviceType } from "./App";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { THEME } from "../constants";
|
import { THEME } from "../constants";
|
||||||
|
|
||||||
export const Modal: React.FC<{
|
export const Modal = (props: {
|
||||||
className?: string;
|
className?: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
maxWidth?: number;
|
maxWidth?: number;
|
||||||
@@ -16,7 +16,7 @@ export const Modal: React.FC<{
|
|||||||
labelledBy: string;
|
labelledBy: string;
|
||||||
theme?: AppState["theme"];
|
theme?: AppState["theme"];
|
||||||
closeOnClickOutside?: boolean;
|
closeOnClickOutside?: boolean;
|
||||||
}> = (props) => {
|
}) => {
|
||||||
const { theme = THEME.LIGHT, closeOnClickOutside = true } = props;
|
const { theme = THEME.LIGHT, closeOnClickOutside = true } = props;
|
||||||
const modalRoot = useBodyRoot(theme);
|
const modalRoot = useBodyRoot(theme);
|
||||||
|
|
||||||
@@ -59,17 +59,17 @@ export const Modal: React.FC<{
|
|||||||
const useBodyRoot = (theme: AppState["theme"]) => {
|
const useBodyRoot = (theme: AppState["theme"]) => {
|
||||||
const [div, setDiv] = useState<HTMLDivElement | null>(null);
|
const [div, setDiv] = useState<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const device = useDevice();
|
const deviceType = useDeviceType();
|
||||||
const isMobileRef = useRef(device.isMobile);
|
const isMobileRef = useRef(deviceType.isMobile);
|
||||||
isMobileRef.current = device.isMobile;
|
isMobileRef.current = deviceType.isMobile;
|
||||||
|
|
||||||
const { container: excalidrawContainer } = useExcalidrawContainer();
|
const { container: excalidrawContainer } = useExcalidrawContainer();
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (div) {
|
if (div) {
|
||||||
div.classList.toggle("excalidraw--mobile", device.isMobile);
|
div.classList.toggle("excalidraw--mobile", deviceType.isMobile);
|
||||||
}
|
}
|
||||||
}, [div, device.isMobile]);
|
}, [div, deviceType.isMobile]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const isDarkTheme =
|
const isDarkTheme =
|
||||||
|
@@ -46,7 +46,7 @@ const ChartPreviewBtn = (props: {
|
|||||||
},
|
},
|
||||||
null, // files
|
null, // files
|
||||||
);
|
);
|
||||||
previewNode.replaceChildren();
|
|
||||||
previewNode.appendChild(svg);
|
previewNode.appendChild(svg);
|
||||||
|
|
||||||
if (props.selected) {
|
if (props.selected) {
|
||||||
@@ -55,7 +55,7 @@ const ChartPreviewBtn = (props: {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
previewNode.replaceChildren();
|
previewNode.removeChild(svg);
|
||||||
};
|
};
|
||||||
}, [props.spreadsheet, props.chartType, props.selected]);
|
}, [props.spreadsheet, props.chartType, props.selected]);
|
||||||
|
|
||||||
|
@@ -2,6 +2,5 @@
|
|||||||
.popover {
|
.popover {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
padding: 5px 0 5px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
import React, { useLayoutEffect, useRef, useEffect } from "react";
|
import React, { useLayoutEffect, useRef, useEffect } from "react";
|
||||||
import "./Popover.scss";
|
import "./Popover.scss";
|
||||||
import { unstable_batchedUpdates } from "react-dom";
|
import { unstable_batchedUpdates } from "react-dom";
|
||||||
import { queryFocusableElements } from "../utils";
|
|
||||||
import { KEYS } from "../keys";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
top?: number;
|
top?: number;
|
||||||
@@ -29,66 +27,17 @@ export const Popover = ({
|
|||||||
}: Props) => {
|
}: Props) => {
|
||||||
const popoverRef = useRef<HTMLDivElement>(null);
|
const popoverRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const container = popoverRef.current;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!container) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
|
||||||
if (event.key === KEYS.TAB) {
|
|
||||||
const focusableElements = queryFocusableElements(container);
|
|
||||||
const { activeElement } = document;
|
|
||||||
const currentIndex = focusableElements.findIndex(
|
|
||||||
(element) => element === activeElement,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentIndex === 0 && event.shiftKey) {
|
|
||||||
focusableElements[focusableElements.length - 1].focus();
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
} else if (
|
|
||||||
currentIndex === focusableElements.length - 1 &&
|
|
||||||
!event.shiftKey
|
|
||||||
) {
|
|
||||||
focusableElements[0].focus();
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
container.addEventListener("keydown", handleKeyDown);
|
|
||||||
|
|
||||||
return () => container.removeEventListener("keydown", handleKeyDown);
|
|
||||||
}, [container]);
|
|
||||||
|
|
||||||
// ensure the popover doesn't overflow the viewport
|
// ensure the popover doesn't overflow the viewport
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (fitInViewport && popoverRef.current) {
|
if (fitInViewport && popoverRef.current) {
|
||||||
const element = popoverRef.current;
|
const element = popoverRef.current;
|
||||||
const { x, y, width, height } = element.getBoundingClientRect();
|
const { x, y, width, height } = element.getBoundingClientRect();
|
||||||
|
|
||||||
//Position correctly when clicked on rightmost part or the bottom part of viewport
|
|
||||||
if (x + width - offsetLeft > viewportWidth) {
|
if (x + width - offsetLeft > viewportWidth) {
|
||||||
element.style.left = `${viewportWidth - width - 10}px`;
|
element.style.left = `${viewportWidth - width}px`;
|
||||||
}
|
}
|
||||||
if (y + height - offsetTop > viewportHeight) {
|
if (y + height - offsetTop > viewportHeight) {
|
||||||
element.style.top = `${viewportHeight - height}px`;
|
element.style.top = `${viewportHeight - height}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Resize to fit viewport on smaller screens
|
|
||||||
if (height >= viewportHeight) {
|
|
||||||
element.style.height = `${viewportHeight - 20}px`;
|
|
||||||
element.style.top = "10px";
|
|
||||||
element.style.overflowY = "scroll";
|
|
||||||
}
|
|
||||||
if (width >= viewportWidth) {
|
|
||||||
element.style.width = `${viewportWidth}px`;
|
|
||||||
element.style.left = "0px";
|
|
||||||
element.style.overflowX = "scroll";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [fitInViewport, viewportWidth, viewportHeight, offsetLeft, offsetTop]);
|
}, [fitInViewport, viewportWidth, viewportHeight, offsetLeft, offsetTop]);
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user