Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ae88ea555c | |||
| 14eecf651f | |||
| c951a001f7 | |||
| 7c9cf30909 | |||
| 1e37dbd60e | |||
| f8d5c2a1b6 | |||
| 25ab75cb9b | |||
| 23b24ea5c3 | |||
| a528769b68 | |||
| ddb7585057 | |||
| 111a48ffb1 | |||
| 54153629c0 | |||
| 9c425224c7 | |||
| 9d1d45a8ea | |||
| 029c3c48ba | |||
| adfd95be33 | |||
| ceb255e8ee | |||
| ae5b9a4ffd | |||
| 3d4ff59f40 | |||
| 7b00089314 | |||
| af6b81df40 | |||
| 02cc8440c4 | |||
| 6363492cee | |||
| 900b317bf3 | |||
| 68179356e6 | |||
| 3ed15e95da | |||
| 798e1fd858 | |||
| f66c93633c | |||
| cee00767df | |||
| 864c0b3ea8 | |||
| a9a6f8eafb | |||
| 3c96943db3 | |||
| 9006caff39 | |||
| ce7a847668 | |||
| b1037b342d | |||
| 18a7b97515 | |||
| e8def8da8d | |||
| a7db41c5ba | |||
| d8166d9e1d | |||
| 81c0259041 | |||
| f5c91c3a0f | |||
| 9b8de8a12e | |||
| ea677d4581 | |||
| ec2de7205f | |||
| d5e3f436dc | |||
| dcf4592e79 | |||
| d1f8eec174 | |||
| 0f81c30276 | |||
| f098789d16 | |||
| f794b0bb90 | |||
| 104f64f1dc | |||
| 71ad3c5356 | |||
| afea0df141 | |||
| d2a508104e | |||
| 3697618266 | |||
| e7cc2337ea | |||
| 9eb89f9960 | |||
| ab1bcc7615 | |||
| b1cac35269 | |||
| 83f86e2b86 | |||
| 7e38cab76e | |||
| 2cabb1f1f4 | |||
| 63650f82d1 | |||
| dde3dac931 | |||
| 5b94cffc74 | |||
| aaf73c8ff3 | |||
| 44d9d5fcac | |||
| 89a3bbddb7 | |||
| b86184a849 | |||
| b552166924 | |||
| 26ff3993bb | |||
| 7ad02c359a | |||
| 2523fe82e3 | |||
| 4ea079eb85 | |||
| f20ba90ffa | |||
| 03da9112cf | |||
| a249f332a2 |
@@ -1,3 +0,0 @@
|
|||||||
## 2020-10-13
|
|
||||||
|
|
||||||
- Added ability to embed scene source into exported PNG/SVG files so you can import the scene from them (open via `Load` button or drag & drop). #2219
|
|
||||||
@@ -25,6 +25,9 @@
|
|||||||
<a href="https://github.com/excalidraw/excalidraw/blob/master/LICENSE">
|
<a href="https://github.com/excalidraw/excalidraw/blob/master/LICENSE">
|
||||||
<img alt="Excalidraw is released under the MIT license." src="https://img.shields.io/badge/license-MIT-blue.svg" />
|
<img alt="Excalidraw is released under the MIT license." src="https://img.shields.io/badge/license-MIT-blue.svg" />
|
||||||
</a>
|
</a>
|
||||||
|
<a href="https://www.npmjs.com/package/@excalidraw/excalidraw">
|
||||||
|
<img alt="npm downloads/month" src="https://img.shields.io/npm/dm/@excalidraw/excalidraw" />
|
||||||
|
</a>
|
||||||
<a href="https://docs.excalidraw.com/docs/introduction/contributing">
|
<a href="https://docs.excalidraw.com/docs/introduction/contributing">
|
||||||
<img alt="PRs welcome!" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" />
|
<img alt="PRs welcome!" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" />
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ Open the `Menu` in the below playground and you will see the `custom footer` ren
|
|||||||
```jsx live noInline
|
```jsx live noInline
|
||||||
const MobileFooter = ({}) => {
|
const MobileFooter = ({}) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
if (device.isMobile) {
|
if (device.editor.isMobile) {
|
||||||
return (
|
return (
|
||||||
<Footer>
|
<Footer>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ A given tab trigger button that switches to a given sidebar tab. It must be rend
|
|||||||
| `className` | `string` | No | |
|
| `className` | `string` | No | |
|
||||||
| `style` | `React.CSSProperties` | No | |
|
| `style` | `React.CSSProperties` | No | |
|
||||||
|
|
||||||
You can use the [`ref.toggleSidebar({ name: "custom" })`](/docs/@excalidraw/excalidraw/api/props/ref#toggleSidebar) api to control the sidebar, but we export a trigger button to make UI use cases easier.
|
You can use the [`ref.toggleSidebar({ name: "custom" })`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api#toggleSidebar) api to control the sidebar, but we export a trigger button to make UI use cases easier.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,17 @@ The [`ExcalidrawElementSkeleton`](https://github.com/excalidraw/excalidraw/blob/
|
|||||||
|
|
||||||
**_Signature_**
|
**_Signature_**
|
||||||
|
|
||||||
<pre>
|
```ts
|
||||||
convertToExcalidrawElements(elements:{" "}
|
convertToExcalidrawElements(
|
||||||
<a href="https://github.com/excalidraw/excalidraw/blob/master/src/data/transform.ts#L133">
|
elements: ExcalidrawElementSkeleton,
|
||||||
ExcalidrawElementSkeleton
|
opts?: { regenerateIds: boolean }
|
||||||
</a>
|
): ExcalidrawElement[]
|
||||||
)
|
```
|
||||||
</pre>
|
|
||||||
|
| Name | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `elements` | [ExcalidrawElementSkeleton](https://github.com/excalidraw/excalidraw/blob/master/src/data/transform.ts#L137) | | The Excalidraw element Skeleton which needs to be converted to Excalidraw elements. |
|
||||||
|
| `opts` | `{ regenerateIds: boolean }` | ` {regenerateIds: true}` | By default `id` will be regenerated for all the elements irrespective of whether you pass the `id` so if you don't want the ids to regenerated, you can set this attribute to `false`. |
|
||||||
|
|
||||||
**_How to use_**
|
**_How to use_**
|
||||||
|
|
||||||
@@ -24,13 +28,13 @@ The [`ExcalidrawElementSkeleton`](https://github.com/excalidraw/excalidraw/blob/
|
|||||||
import { convertToExcalidrawElements } from "@excalidraw/excalidraw";
|
import { convertToExcalidrawElements } from "@excalidraw/excalidraw";
|
||||||
```
|
```
|
||||||
|
|
||||||
This function converts the Excalidraw Element Skeleton to excalidraw elements which could be then rendered on the canvas. Hence calling this function is necessary before passing it to APIs like [`initialData`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/initialdata), [`updateScene`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/ref#updatescene) if you are using the Skeleton API
|
This function converts the Excalidraw Element Skeleton to excalidraw elements which could be then rendered on the canvas. Hence calling this function is necessary before passing it to APIs like [`initialData`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/initialdata), [`updateScene`](https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/excalidraw-api#updatescene) if you are using the Skeleton API
|
||||||
|
|
||||||
## Supported Features
|
## Supported Features
|
||||||
|
|
||||||
### Rectangle, Ellipse, and Diamond
|
### Rectangle, Ellipse, and Diamond
|
||||||
|
|
||||||
To create these shapes you need to pass its `type` and `x` and `y` coordinates for position. The rest of the attributes are optional_.
|
To create these shapes you need to pass its `type` and `x` and `y` coordinates for position. The rest of the attributes are optional\_.
|
||||||
|
|
||||||
For the Skeleton API to work, `convertToExcalidrawElements` needs to be called before passing it to Excalidraw Component via initialData, updateScene or any such API.
|
For the Skeleton API to work, `convertToExcalidrawElements` needs to be called before passing it to Excalidraw Component via initialData, updateScene or any such API.
|
||||||
|
|
||||||
@@ -427,3 +431,45 @@ convertToExcalidrawElements([
|
|||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### Frames
|
||||||
|
|
||||||
|
To create a frame, you need to pass `type`, `children` (list of Excalidraw element ids). The rest of the attributes are optional.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
{
|
||||||
|
type: "frame";
|
||||||
|
children: readonly ExcalidrawElement["id"][];
|
||||||
|
name?: string;
|
||||||
|
} & Partial<ExcalidrawFrameElement>);
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
convertToExcalidrawElements([
|
||||||
|
{
|
||||||
|
"type": "rectangle",
|
||||||
|
"x": 10,
|
||||||
|
"y": 10,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"id": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "diamond",
|
||||||
|
"x": 120,
|
||||||
|
"y": 20,
|
||||||
|
"backgroundColor": "#fff3bf",
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"label": {
|
||||||
|
"text": "HELLO EXCALIDRAW",
|
||||||
|
"strokeColor": "#099268",
|
||||||
|
"fontSize": 30
|
||||||
|
},
|
||||||
|
"id": "2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "frame",
|
||||||
|
"children": ["1", "2"],
|
||||||
|
"name": "My frame"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
+89
-70
@@ -1,27 +1,26 @@
|
|||||||
# ref
|
# excalidrawAPI
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<a href="https://reactjs.org/docs/refs-and-the-dom.html#creating-refs">
|
(api:{" "}
|
||||||
createRef
|
<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L616">
|
||||||
</a>{" "}
|
ExcalidrawAPI
|
||||||
|{" "}
|
</a>
|
||||||
<a href="https://reactjs.org/docs/hooks-reference.html#useref">useRef</a>{" "}
|
) => void;
|
||||||
|{" "}
|
|
||||||
<a href="https://reactjs.org/docs/refs-and-the-dom.html#callback-refs">
|
|
||||||
callbackRef
|
|
||||||
</a>{" "}
|
|
||||||
| <br />
|
|
||||||
{ current: { readyPromise: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L460">
|
|
||||||
resolvablePromise
|
|
||||||
</a> } }
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
You can pass a `ref` when you want to access some excalidraw APIs. We expose the below APIs:
|
Once the callback is triggered, you will need to store the api in state to access it later.
|
||||||
|
|
||||||
|
```jsx showLineNumbers
|
||||||
|
export default function App() {
|
||||||
|
const [excalidrawAPI, setExcalidrawAPI] = useState(null);
|
||||||
|
return <Excalidraw excalidrawAPI={{(api)=> setExcalidrawAPI(api)}} />;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use this prop when you want to access some [Excalidraw APIs](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L616). We expose the below APIs :point_down:
|
||||||
|
|
||||||
| API | Signature | Usage |
|
| API | Signature | Usage |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| ready | `boolean` | This is set to true once Excalidraw is rendered |
|
|
||||||
| [readyPromise](#readypromise) | `function` | This promise will be resolved with the api once excalidraw has rendered. This will be helpful when you want do some action on the host app once this promise resolves. For this to work you will have to pass ref as shown [here](#readypromise) |
|
|
||||||
| [updateScene](#updatescene) | `function` | updates the scene with the sceneData |
|
| [updateScene](#updatescene) | `function` | updates the scene with the sceneData |
|
||||||
| [updateLibrary](#updatelibrary) | `function` | updates the scene with the sceneData |
|
| [updateLibrary](#updatelibrary) | `function` | updates the scene with the sceneData |
|
||||||
| [addFiles](#addfiles) | `function` | add files data to the appState |
|
| [addFiles](#addfiles) | `function` | add files data to the appState |
|
||||||
@@ -39,54 +38,15 @@ You can pass a `ref` when you want to access some excalidraw APIs. We expose the
|
|||||||
| [setCursor](#setcursor) | `function` | This API can be used to set customise the mouse cursor on the canvas |
|
| [setCursor](#setcursor) | `function` | This API can be used to set customise the mouse cursor on the canvas |
|
||||||
| [resetCursor](#resetcursor) | `function` | This API can be used to reset to default mouse cursor on the canvas |
|
| [resetCursor](#resetcursor) | `function` | This API can be used to reset to default mouse cursor on the canvas |
|
||||||
| [toggleMenu](#togglemenu) | `function` | Toggles specific menus on/off |
|
| [toggleMenu](#togglemenu) | `function` | Toggles specific menus on/off |
|
||||||
|
| [onChange](#onChange) | `function` | Subscribes to change events |
|
||||||
|
| [onPointerDown](#onPointerDown) | `function` | Subscribes to `pointerdown` events |
|
||||||
|
| [onPointerUp](#onPointerUp) | `function` | Subscribes to `pointerup` events |
|
||||||
|
|
||||||
## readyPromise
|
:::info The `Ref` support has been removed in v0.17.0 so if you are using refs, please update the integration to use the `excalidrawAPI`.
|
||||||
|
|
||||||
<pre>
|
Additionally `ready` and `readyPromise` from the API have been discontinued. These APIs were found to be superfluous, and as part of the effort to streamline the APIs and maintain simplicity, they were removed in version v0.17.0.
|
||||||
const excalidrawRef = { current:{ readyPromise:
|
|
||||||
<a href="https://github.com/excalidraw/excalidraw/blob/master/src/utils.ts#L460">
|
|
||||||
resolvablePromise
|
|
||||||
</a>
|
|
||||||
} }
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
Since plain object is passed as a `ref`, the `readyPromise` is resolved as soon as the component is mounted. Most of the time you will not need this unless you have a specific use case where you can't pass the `ref` in the react way and want to do some action on the host when this promise resolves.
|
:::
|
||||||
|
|
||||||
```jsx showLineNumbers
|
|
||||||
const resolvablePromise = () => {
|
|
||||||
let resolve;
|
|
||||||
let reject;
|
|
||||||
const promise = new Promise((_resolve, _reject) => {
|
|
||||||
resolve = _resolve;
|
|
||||||
reject = _reject;
|
|
||||||
});
|
|
||||||
promise.resolve = resolve;
|
|
||||||
promise.reject = reject;
|
|
||||||
return promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
const App = () => {
|
|
||||||
const excalidrawRef = useMemo(
|
|
||||||
() => ({
|
|
||||||
current: {
|
|
||||||
readyPromise: resolvablePromise(),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
excalidrawRef.current.readyPromise.then((api) => {
|
|
||||||
console.log("loaded", api);
|
|
||||||
});
|
|
||||||
}, [excalidrawRef]);
|
|
||||||
return (
|
|
||||||
<div style={{ height: "500px" }}>
|
|
||||||
<Excalidraw ref={excalidrawRef} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## updateScene
|
## updateScene
|
||||||
|
|
||||||
@@ -387,14 +347,25 @@ This API can be used to get the files present in the scene. It may contain files
|
|||||||
|
|
||||||
This API has the below signature. It sets the `tool` passed in param as the active tool.
|
This API has the below signature. It sets the `tool` passed in param as the active tool.
|
||||||
|
|
||||||
<pre>
|
```ts
|
||||||
(tool: <br /> { type:{" "}
|
(
|
||||||
<a href="https://github.com/excalidraw/excalidraw/blob/master/src/shapes.tsx#L15">
|
tool: (
|
||||||
SHAPES
|
| (
|
||||||
</a>
|
| { type: Exclude<ToolType, "image"> }
|
||||||
[number]["value"]| "eraser" } |
|
| {
|
||||||
<br /> { type: "custom"; customType: string }) => void
|
type: Extract<ToolType, "image">;
|
||||||
</pre>
|
insertOnCanvasDirectly?: boolean;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
| { type: "custom"; customType: string }
|
||||||
|
) & { locked?: boolean },
|
||||||
|
) => {};
|
||||||
|
```
|
||||||
|
|
||||||
|
| Name | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| `type` | [ToolType](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L91) | `selection` | The tool type which should be set as active tool. When setting `image` as active tool, the insertion onto canvas when using image tool is disabled by default, so you can enable it by setting `insertOnCanvasDirectly` to `true` |
|
||||||
|
| `locked` | `boolean` | `false` | Indicates whether the the active tool should be locked. It behaves the same way when using the `lock` tool in the editor interface |
|
||||||
|
|
||||||
## setCursor
|
## setCursor
|
||||||
|
|
||||||
@@ -421,3 +392,51 @@ This API is especially useful when you render a custom [`<Sidebar/>`](/docs/@exc
|
|||||||
```
|
```
|
||||||
|
|
||||||
This API can be used to reset to default mouse cursor.
|
This API can be used to reset to default mouse cursor.
|
||||||
|
|
||||||
|
## onChange
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
(
|
||||||
|
callback: (
|
||||||
|
elements: readonly ExcalidrawElement[],
|
||||||
|
appState: AppState,
|
||||||
|
files: BinaryFiles,
|
||||||
|
) => void
|
||||||
|
) => () => void
|
||||||
|
```
|
||||||
|
|
||||||
|
Subscribes to change events, similar to [`props.onChange`](/docs/@excalidraw/excalidraw/api/props#onchange).
|
||||||
|
|
||||||
|
Returns an unsubscribe function.
|
||||||
|
|
||||||
|
## onPointerDown
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
(
|
||||||
|
callback: (
|
||||||
|
activeTool: AppState["activeTool"],
|
||||||
|
pointerDownState: PointerDownState,
|
||||||
|
event: React.PointerEvent<HTMLElement>,
|
||||||
|
) => void,
|
||||||
|
) => () => void
|
||||||
|
```
|
||||||
|
|
||||||
|
Subscribes to canvas `pointerdown` events.
|
||||||
|
|
||||||
|
Returns an unsubscribe function.
|
||||||
|
|
||||||
|
## onPointerUp
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
(
|
||||||
|
callback: (
|
||||||
|
activeTool: AppState["activeTool"],
|
||||||
|
pointerDownState: PointerDownState,
|
||||||
|
event: PointerEvent,
|
||||||
|
) => void,
|
||||||
|
) => () => void
|
||||||
|
```
|
||||||
|
|
||||||
|
Subscribes to canvas `pointerup` events.
|
||||||
|
|
||||||
|
Returns an unsubscribe function.
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
# Props
|
# Props
|
||||||
|
|
||||||
All `props` are *optional*.
|
All `props` are _optional_.
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| [`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata) | `object` | `null` | <code>Promise<object | null></code> | `null` | The initial data with which app loads. |
|
| [`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata) | `object` | `null` | <code>Promise<object | null></code> | `null` | The initial data with which app loads. |
|
||||||
| [`ref`](/docs/@excalidraw/excalidraw/api/props/ref) | `object` | _ | `Ref` to be passed to Excalidraw |
|
| [`excalidrawAPI`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api) | `function` | _ | Callback triggered with the excalidraw api once rendered |
|
||||||
| [`isCollaborating`](#iscollaborating) | `boolean` | _ | This indicates if the app is in `collaboration` mode |
|
| [`isCollaborating`](#iscollaborating) | `boolean` | _ | This indicates if the app is in `collaboration` mode |
|
||||||
| [`onChange`](#onchange) | `function` | _ | This callback is triggered whenever the component updates due to any change. This callback will receive the excalidraw `elements` and the current `app state`. |
|
| [`onChange`](#onchange) | `function` | _ | This callback is triggered whenever the component updates due to any change. This callback will receive the excalidraw `elements` and the current `app state`. |
|
||||||
| [`onPointerUpdate`](#onpointerupdate) | `function` | _ | Callback triggered when mouse pointer is updated. |
|
| [`onPointerUpdate`](#onpointerupdate) | `function` | _ | Callback triggered when mouse pointer is updated. |
|
||||||
@@ -37,7 +37,7 @@ Beyond attributes that Excalidraw elements already support, you can store `custo
|
|||||||
|
|
||||||
You can use this to add any extra information you need to keep track of.
|
You can use this to add any extra information you need to keep track of.
|
||||||
|
|
||||||
You can add `customData` to elements when passing them as [`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata), or using [`updateScene`](/docs/@excalidraw/excalidraw/api/props/ref#updatescene) / [`updateLibrary`](/docs/@excalidraw/excalidraw/api/props/ref#updatelibrary) afterwards.
|
You can add `customData` to elements when passing them as [`initialData`](/docs/@excalidraw/excalidraw/api/props/initialdata), or using [`updateScene`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api#updatescene) / [`updateLibrary`](/docs/@excalidraw/excalidraw/api/props/excalidraw-api#updatelibrary) afterwards.
|
||||||
|
|
||||||
```js showLineNumbers
|
```js showLineNumbers
|
||||||
{
|
{
|
||||||
@@ -93,8 +93,16 @@ This callback is triggered when mouse pointer is updated.
|
|||||||
|
|
||||||
This prop if passed will be triggered on pointer down events and has the below signature.
|
This prop if passed will be triggered on pointer down events and has the below signature.
|
||||||
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
(activeTool: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L115"> AppState["activeTool"]</a>, pointerDownState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L424">PointerDownState</a>) => void
|
(activeTool:{" "}
|
||||||
|
<a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L115">
|
||||||
|
{" "}
|
||||||
|
AppState["activeTool"]
|
||||||
|
</a>
|
||||||
|
, pointerDownState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L424">
|
||||||
|
PointerDownState
|
||||||
|
</a>) => void
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
### onScrollChange
|
### onScrollChange
|
||||||
@@ -110,7 +118,11 @@ This prop if passed will be triggered when canvas is scrolled and has the below
|
|||||||
This callback is triggered if passed when something is pasted into the scene. You can use this callback in case you want to do something additional when the paste event occurs.
|
This callback is triggered if passed when something is pasted into the scene. You can use this callback in case you want to do something additional when the paste event occurs.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
(data: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/clipboard.ts#L18">ClipboardData</a>, event: ClipboardEvent | null) => boolean
|
(data:{" "}
|
||||||
|
<a href="https://github.com/excalidraw/excalidraw/blob/master/src/clipboard.ts#L18">
|
||||||
|
ClipboardData
|
||||||
|
</a>
|
||||||
|
, event: ClipboardEvent | null) => boolean
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
This callback must return a `boolean` value or a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise) which resolves to a boolean value.
|
This callback must return a `boolean` value or a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise) which resolves to a boolean value.
|
||||||
@@ -136,8 +148,11 @@ It is invoked with empty items when user clears the library. You can use this ca
|
|||||||
This prop if passed will be triggered when clicked on `link`. To handle the redirect yourself (such as when using your own router for internal links), you must call `event.preventDefault()`.
|
This prop if passed will be triggered when clicked on `link`. To handle the redirect yourself (such as when using your own router for internal links), you must call `event.preventDefault()`.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
(element: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement</a>,
|
(element:{" "}
|
||||||
event: CustomEvent<{ nativeEvent: MouseEvent }>) => void
|
<a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">
|
||||||
|
ExcalidrawElement
|
||||||
|
</a>
|
||||||
|
, event: CustomEvent<{ nativeEvent: MouseEvent }>) => void
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@@ -180,30 +195,30 @@ import { defaultLang, languages } from "@excalidraw/excalidraw";
|
|||||||
|
|
||||||
### viewModeEnabled
|
### viewModeEnabled
|
||||||
|
|
||||||
This prop indicates whether the app is in `view mode`. When supplied, the value takes precedence over *intialData.appState.viewModeEnabled*, the `view mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
|
This prop indicates whether the app is in `view mode`. When supplied, the value takes precedence over _intialData.appState.viewModeEnabled_, the `view mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
|
||||||
|
|
||||||
### zenModeEnabled
|
### zenModeEnabled
|
||||||
|
|
||||||
This prop indicates whether the app is in `zen mode`. When supplied, the value takes precedence over *intialData.appState.zenModeEnabled*, the `zen mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
|
This prop indicates whether the app is in `zen mode`. When supplied, the value takes precedence over _intialData.appState.zenModeEnabled_, the `zen mode` will be fully controlled by the host app, and users won't be able to toggle it from within the app.
|
||||||
|
|
||||||
### gridModeEnabled
|
### gridModeEnabled
|
||||||
|
|
||||||
This prop indicates whether the shows the grid. When supplied, the value takes precedence over *intialData.appState.gridModeEnabled*, the grid will be fully controlled by the host app, and users won't be able to toggle it from within the app.
|
This prop indicates whether the shows the grid. When supplied, the value takes precedence over _intialData.appState.gridModeEnabled_, the grid will be fully controlled by the host app, and users won't be able to toggle it from within the app.
|
||||||
|
|
||||||
### libraryReturnUrl
|
### libraryReturnUrl
|
||||||
|
|
||||||
If supplied, this URL will be used when user tries to install a library from [libraries.excalidraw.com](https://libraries.excalidraw.com).
|
If supplied, this URL will be used when user tries to install a library from [libraries.excalidraw.com](https://libraries.excalidraw.com).
|
||||||
Defaults to *window.location.origin + window.location.pathname*. To install the libraries in the same tab from which it was opened, you need to set `window.name` (to any alphanumeric string) — if it's not set it will open in a new tab.
|
Defaults to _window.location.origin + window.location.pathname_. To install the libraries in the same tab from which it was opened, you need to set `window.name` (to any alphanumeric string) — if it's not set it will open in a new tab.
|
||||||
|
|
||||||
### theme
|
### theme
|
||||||
|
|
||||||
This prop controls Excalidraw's theme. When supplied, the value takes precedence over *intialData.appState.theme*, the theme will be fully controlled by the host app, and users won't be able to toggle it from within the app unless *UIOptions.canvasActions.toggleTheme* is set to `true`, in which case the `theme` prop will control Excalidraw's default theme with ability to allow theme switching (you must take care of updating the `theme` prop when you detect a change to `appState.theme` from the [onChange](#onchange) callback).
|
This prop controls Excalidraw's theme. When supplied, the value takes precedence over _intialData.appState.theme_, the theme will be fully controlled by the host app, and users won't be able to toggle it from within the app unless _UIOptions.canvasActions.toggleTheme_ is set to `true`, in which case the `theme` prop will control Excalidraw's default theme with ability to allow theme switching (you must take care of updating the `theme` prop when you detect a change to `appState.theme` from the [onChange](#onchange) callback).
|
||||||
|
|
||||||
You can use [`THEME`](/docs/@excalidraw/excalidraw/api/utils#theme) to specify the theme.
|
You can use [`THEME`](/docs/@excalidraw/excalidraw/api/utils#theme) to specify the theme.
|
||||||
|
|
||||||
### name
|
### name
|
||||||
|
|
||||||
This prop sets the `name` of the drawing which will be used when exporting the drawing. When supplied, the value takes precedence over *intialData.appState.name*, the `name` will be fully controlled by host app and the users won't be able to edit from within Excalidraw.
|
This prop sets the `name` of the drawing which will be used when exporting the drawing. When supplied, the value takes precedence over _intialData.appState.name_, the `name` will be fully controlled by host app and the users won't be able to edit from within Excalidraw.
|
||||||
|
|
||||||
|
|
||||||
### detectScroll
|
### detectScroll
|
||||||
@@ -236,4 +251,4 @@ validateEmbeddable?: boolean | string[] | RegExp | RegExp[] | ((link: string) =>
|
|||||||
|
|
||||||
This is an optional property. By default we support a handful of well-known sites. You may allow additional sites or disallow the default ones by supplying a custom validator. If you pass `true`, all URLs will be allowed. You can also supply a list of hostnames, RegExp (or list of RegExp objects), or a function. If the function returns `undefined`, the built-in validator will be used.
|
This is an optional property. By default we support a handful of well-known sites. You may allow additional sites or disallow the default ones by supplying a custom validator. If you pass `true`, all URLs will be allowed. You can also supply a list of hostnames, RegExp (or list of RegExp objects), or a function. If the function returns `undefined`, the built-in validator will be used.
|
||||||
|
|
||||||
Supplying a list of hostnames (with or without `www.`) is the preferred way to allow a specific list of domains.
|
Supplying a list of hostnames (with or without `www.`) is the preferred way to allow a specific list of domains.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# UIOptions
|
# UIOptions
|
||||||
|
|
||||||
This prop can be used to customise UI of Excalidraw. Currently we support customising [`canvasActions`](#canvasactions), [`dockedSidebarBreakpoint`](#dockedsidebarbreakpoint) and [`welcomeScreen`](#welcmescreen).
|
This prop can be used to customise UI of Excalidraw. Currently we support customising [`canvasActions`](#canvasactions), [`dockedSidebarBreakpoint`](#dockedsidebarbreakpoint) [`welcomeScreen`](#welcmescreen) and [`tools`](#tools).
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
{
|
{
|
||||||
@@ -70,3 +70,12 @@ function App() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## tools
|
||||||
|
|
||||||
|
This `prop ` controls the visibility of the tools in the editor.
|
||||||
|
Currently you can control the visibility of `image` tool via this prop.
|
||||||
|
|
||||||
|
| Prop | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| image | boolean | true | Decides whether `image` tool should be visible.
|
||||||
@@ -129,7 +129,7 @@ if (contents.type === MIME_TYPES.excalidraw) {
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
loadSceneOrLibraryFromBlob(<br/>
|
loadSceneOrLibraryFromBlob(<br/>
|
||||||
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,
|
blob: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a>,<br/>
|
||||||
localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L95">AppState</a> | null,<br/>
|
localAppState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L95">AppState</a> | null,<br/>
|
||||||
localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement[]</a> | null,<br/>
|
localElements: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L114">ExcalidrawElement[]</a> | null,<br/>
|
||||||
fileHandle?: FileSystemHandle | null<br/>
|
fileHandle?: FileSystemHandle | null<br/>
|
||||||
@@ -164,9 +164,9 @@ import { isLinearElement } from "@excalidraw/excalidraw";
|
|||||||
|
|
||||||
**Signature**
|
**Signature**
|
||||||
|
|
||||||
```tsx
|
<pre>
|
||||||
isLinearElement(elementType?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L80">ExcalidrawElement</a>): boolean
|
isLinearElement(elementType?: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/element/types.ts#L80">ExcalidrawElement</a>): boolean
|
||||||
```
|
</pre>
|
||||||
|
|
||||||
### getNonDeletedElements
|
### getNonDeletedElements
|
||||||
|
|
||||||
@@ -195,8 +195,10 @@ import { mergeLibraryItems } from "@excalidraw/excalidraw";
|
|||||||
**_Signature_**
|
**_Signature_**
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
mergeLibraryItems(localItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L250">LibraryItems</a>,<br/>
|
mergeLibraryItems(<br/>
|
||||||
otherItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a>) => <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L250">LibraryItems</a>
|
localItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L250">LibraryItems</a>,<br/>
|
||||||
|
otherItems: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L200">LibraryItems</a><br/>
|
||||||
|
): <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L250">LibraryItems</a>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
### parseLibraryTokensFromUrl
|
### parseLibraryTokensFromUrl
|
||||||
@@ -299,7 +301,7 @@ Open the `main menu` in the below example to view the footer.
|
|||||||
```jsx live noInline
|
```jsx live noInline
|
||||||
const MobileFooter = ({}) => {
|
const MobileFooter = ({}) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
if (device.isMobile) {
|
if (device.editor.isMobile) {
|
||||||
return (
|
return (
|
||||||
<Footer>
|
<Footer>
|
||||||
<button
|
<button
|
||||||
@@ -331,14 +333,15 @@ const App = () => (
|
|||||||
render(<App />);
|
render(<App />);
|
||||||
```
|
```
|
||||||
|
|
||||||
The `device` has the following `attributes`
|
The `device` has the following `attributes`, some grouped into `viewport` and `editor` objects, per context.
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `isSmScreen` | `boolean` | Set to `true` when the device small screen is small (Width < `640px` ) |
|
| `viewport.isMobile` | `boolean` | Set to `true` when viewport is in `mobile` breakpoint |
|
||||||
| `isMobile` | `boolean` | Set to `true` when the device is `mobile` |
|
| `viewport.isLandscape` | `boolean` | Set to `true` when the viewport is in `landscape` mode |
|
||||||
| `isTouchScreen` | `boolean` | Set to `true` for `touch` devices |
|
| `editor.canFitSidebar` | `boolean` | Set to `true` if there's enough space to fit the `sidebar` |
|
||||||
| `canDeviceFitSidebar` | `boolean` | Implies whether there is enough space to fit the `sidebar` |
|
| `editor.isMobile` | `boolean` | Set to `true` when editor container is in `mobile` breakpoint |
|
||||||
|
| `isTouchScreen` | `boolean` | Set to `true` for `touch` when touch event detected |
|
||||||
|
|
||||||
### i18n
|
### i18n
|
||||||
|
|
||||||
@@ -383,3 +386,94 @@ function App() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### getCommonBounds
|
||||||
|
|
||||||
|
This util can be used to get the common bounds of the passed elements.
|
||||||
|
|
||||||
|
**_Signature_**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
getCommonBounds(
|
||||||
|
elements: readonly ExcalidrawElement[]
|
||||||
|
): readonly [
|
||||||
|
minX: number,
|
||||||
|
minY: number,
|
||||||
|
maxX: number,
|
||||||
|
maxY: number,
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
**_How to use_**
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { getCommonBounds } from "@excalidraw/excalidraw";
|
||||||
|
```
|
||||||
|
|
||||||
|
### elementsOverlappingBBox
|
||||||
|
|
||||||
|
To filter `elements` that are inside, overlap, or contain the `bounds` rectangle.
|
||||||
|
|
||||||
|
The bounds check is approximate and does not precisely follow the element's shape. You can also supply `errorMargin` which effectively makes the `bounds` larger by that amount.
|
||||||
|
|
||||||
|
This API has 3 `type`s of operation: `overlap`, `contain`, and `inside`:
|
||||||
|
|
||||||
|
- `overlap` - filters elements that are overlapping or inside bounds.
|
||||||
|
- `contain` - filters elements that are inside bounds or bounds inside elements.
|
||||||
|
- `inside` - filters elements that are inside bounds.
|
||||||
|
|
||||||
|
**_Signature_**
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
elementsOverlappingBBox(<br/>
|
||||||
|
elements: readonly NonDeletedExcalidrawElement[];<br/>
|
||||||
|
bounds: <a href="https://github.com/excalidraw/excalidraw/blob/9c425224c789d083bf16e0597ce4a429b9ee008e/src/element/bounds.ts#L37-L42">Bounds</a> | ExcalidrawElement;<br/>
|
||||||
|
errorMargin?: number;<br/>
|
||||||
|
type: "overlap" | "contain" | "inside";<br/>
|
||||||
|
): NonDeletedExcalidrawElement[];
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
**_How to use_**
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { elementsOverlappingBBox } from "@excalidraw/excalidraw";
|
||||||
|
```
|
||||||
|
|
||||||
|
### isElementInsideBBox
|
||||||
|
|
||||||
|
Lower-level API than `elementsOverlappingBBox` to check if a single `element` is inside `bounds`. If `eitherDirection=true`, returns `true` if `element` is fully inside `bounds` rectangle, or vice versa. When `false`, it returns `true` only for the former case.
|
||||||
|
|
||||||
|
**_Signature_**
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
isElementInsideBBox(<br/>
|
||||||
|
element: NonDeletedExcalidrawElement,<br/>
|
||||||
|
bounds: <a href="https://github.com/excalidraw/excalidraw/blob/9c425224c789d083bf16e0597ce4a429b9ee008e/src/element/bounds.ts#L37-L42">Bounds</a>,<br/>
|
||||||
|
eitherDirection = false,<br/>
|
||||||
|
): boolean
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
**_How to use_**
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { isElementInsideBBox } from "@excalidraw/excalidraw";
|
||||||
|
```
|
||||||
|
|
||||||
|
### elementPartiallyOverlapsWithOrContainsBBox
|
||||||
|
|
||||||
|
Checks if `element` is overlapping the `bounds` rectangle, or is fully inside.
|
||||||
|
|
||||||
|
**_Signature_**
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
elementPartiallyOverlapsWithOrContainsBBox(<br/>
|
||||||
|
element: NonDeletedExcalidrawElement,<br/>
|
||||||
|
bounds: <a href="https://github.com/excalidraw/excalidraw/blob/9c425224c789d083bf16e0597ce4a429b9ee008e/src/element/bounds.ts#L37-L42">Bounds</a>,<br/>
|
||||||
|
): boolean
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
**_How to use_**
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { elementPartiallyOverlapsWithOrContainsBBox } from "@excalidraw/excalidraw";
|
||||||
|
```
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ Once the version is released `@excalibot` will post a comment with the release v
|
|||||||
To release the next stable version follow the below steps:
|
To release the next stable version follow the below steps:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn prerelease version
|
yarn prerelease:excalidraw
|
||||||
```
|
```
|
||||||
|
|
||||||
You need to pass the `version` for which you want to create the release. This will make the changes needed before making the release like updating `package.json`, `changelog` and more.
|
You need to pass the `version` for which you want to create the release. This will make the changes needed before making the release like updating `package.json`, `changelog` and more.
|
||||||
@@ -51,7 +51,7 @@ You need to pass the `version` for which you want to create the release. This wi
|
|||||||
The next step is to run the `release` script:
|
The next step is to run the `release` script:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn release
|
yarn release:excalidraw
|
||||||
```
|
```
|
||||||
|
|
||||||
This will publish the package.
|
This will publish the package.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Does this package support collaboration ?
|
### Does this package support collaboration ?
|
||||||
|
|
||||||
No, Excalidraw package doesn't come with collaboration built in, since the implementation is specific to each host app. We expose APIs which you can use to communicate with Excalidraw which you can use to implement it. You can check our own implementation [here](https://github.com/excalidraw/excalidraw/blob/master/src/excalidraw-app/index.tsx). Here is a [detailed answer](https://github.com/excalidraw/excalidraw/discussions/3879#discussioncomment-1110524) on how you can achieve the same.
|
No, Excalidraw package doesn't come with collaboration built in, since the implementation is specific to each host app. We expose APIs which you can use to communicate with Excalidraw which you can use to implement it. You can check our own implementation [here](https://github.com/excalidraw/excalidraw/blob/master/excalidraw-app/index.tsx). Here is a [detailed answer](https://github.com/excalidraw/excalidraw/discussions/3879#discussioncomment-1110524) on how you can achieve the same.
|
||||||
|
|
||||||
### Turning off Aggressive Anti-Fingerprinting in Brave browser
|
### Turning off Aggressive Anti-Fingerprinting in Brave browser
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ We strongly recommend turning it off. You can follow the steps below on how to d
|
|||||||
|
|
||||||
2. Once opened, look for **Aggressively Block Fingerprinting**
|
2. Once opened, look for **Aggressively Block Fingerprinting**
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
3. Switch to **Block Fingerprinting**
|
3. Switch to **Block Fingerprinting**
|
||||||
|
|
||||||
@@ -31,6 +31,17 @@ We strongly recommend turning it off. You can follow the steps below on how to d
|
|||||||
If disabling this setting doesn't fix the display of text elements, please consider opening an [issue](https://github.com/excalidraw/excalidraw/issues/new) on our GitHub, or message us on [Discord](https://discord.gg/UexuTaE).
|
If disabling this setting doesn't fix the display of text elements, please consider opening an [issue](https://github.com/excalidraw/excalidraw/issues/new) on our GitHub, or message us on [Discord](https://discord.gg/UexuTaE).
|
||||||
|
|
||||||
|
|
||||||
|
### ReferenceError: process is not defined
|
||||||
|
|
||||||
|
When using `vite` or any build tools, you will have to make sure the `process` is accessible as we are accessing `process.env.IS_PREACT` to decide whether to use `preact` build.
|
||||||
|
|
||||||
|
Since Vite removes env variables by default, you can update the vite config to ensure its available :point_down:
|
||||||
|
|
||||||
|
```
|
||||||
|
define: {
|
||||||
|
"process.env.IS_PREACT": process.env.IS_PREACT,
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
## Need help?
|
## Need help?
|
||||||
|
|
||||||
|
|||||||
@@ -30,25 +30,74 @@ function App() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Rendering Excalidraw only on client
|
### Next.js
|
||||||
|
|
||||||
Since _Excalidraw_ doesn't support server side rendering, you should render the component once the host is `mounted`.
|
Since _Excalidraw_ doesn't support server side rendering, you should render the component once the host is `mounted`.
|
||||||
|
|
||||||
The following workflow shows one way how to render Excalidraw on Next.js. We'll add more detailed and alternative Next.js examples, soon.
|
Here are two ways on how you can render **Excalidraw** on **Next.js**.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1. Using **Next.js Dynamic** import [Recommended].
|
||||||
|
|
||||||
|
Since Excalidraw doesn't support server side rendering so you can also use `dynamic import` to render by setting `ssr` to `false`.
|
||||||
|
|
||||||
|
```jsx showLineNumbers
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
|
const Excalidraw = dynamic(
|
||||||
|
async () => (await import("@excalidraw/excalidraw")).Excalidraw,
|
||||||
|
{
|
||||||
|
ssr: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
export default function App() {
|
||||||
|
return <Excalidraw />;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Here is a working [demo](https://codesandbox.io/p/sandbox/excalidraw-with-next-dynamic-k8yjq2).
|
||||||
|
|
||||||
|
|
||||||
|
2. Importing Excalidraw once **client** is rendered.
|
||||||
|
|
||||||
```jsx showLineNumbers
|
```jsx showLineNumbers
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [Excalidraw, setExcalidraw] = useState(null);
|
const [Excalidraw, setExcalidraw] = useState(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
import("@excalidraw/excalidraw").then((comp) => setExcalidraw(comp.Excalidraw));
|
import("@excalidraw/excalidraw").then((comp) =>
|
||||||
|
setExcalidraw(comp.Excalidraw),
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
return <>{Excalidraw && <Excalidraw />}</>;
|
return <>{Excalidraw && <Excalidraw />}</>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Here is a working [demo](https://codesandbox.io/p/sandbox/excalidraw-with-next-5xb3d)
|
||||||
|
|
||||||
The `types` are available at `@excalidraw/excalidraw/types`, you can view [example for typescript](https://codesandbox.io/s/excalidraw-types-9h2dm)
|
The `types` are available at `@excalidraw/excalidraw/types`, you can view [example for typescript](https://codesandbox.io/s/excalidraw-types-9h2dm)
|
||||||
|
|
||||||
|
### Preact
|
||||||
|
|
||||||
|
Since we support `umd` build ships with `react/jsx-runtime` and `react-dom/client` inlined with the package. This conflicts with `Preact` and hence the build doesn't work directly with `Preact`.
|
||||||
|
|
||||||
|
However we have shipped a separate build for `Preact` so if you are using `Preact` you need to set `process.env.IS_PREACT` to `true` to use the `Preact` build.
|
||||||
|
|
||||||
|
Once the above `env` variable is set, you will be able to use the package in `Preact` as well.
|
||||||
|
|
||||||
|
:::info
|
||||||
|
|
||||||
|
When using `vite` or any build tools, you will have to make sure the `process` is accessible as we are accessing `process.env.IS_PREACT` to decide whether to use `preact` build.
|
||||||
|
|
||||||
|
Since Vite removes env variables by default, you can update the vite config to ensure its available :point_down:
|
||||||
|
|
||||||
|
```
|
||||||
|
define: {
|
||||||
|
"process.env.IS_PREACT": process.env.IS_PREACT,
|
||||||
|
},
|
||||||
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
## Browser
|
## Browser
|
||||||
|
|
||||||
To use it in a browser directly:
|
To use it in a browser directly:
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Frames
|
||||||
|
|
||||||
|
## Ordering
|
||||||
|
|
||||||
|
Frames should be ordered where frame children come first, followed by the frame element itself:
|
||||||
|
|
||||||
|
```
|
||||||
|
[
|
||||||
|
other_element,
|
||||||
|
frame1_child1,
|
||||||
|
frame1_child2,
|
||||||
|
frame1,
|
||||||
|
other_element,
|
||||||
|
frame2_child1,
|
||||||
|
frame2_child2,
|
||||||
|
frame2,
|
||||||
|
other_element,
|
||||||
|
...
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
If not ordered correctly, the editor will still function, but the elements may not be rendered and clipped correctly. Further, the renderer relies on this ordering for performance optimizations.
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
// Note: type annotations allow type checking and IDEs autocompletion
|
// Note: type annotations allow type checking and IDEs autocompletion
|
||||||
|
|
||||||
|
// Set the env variable to false so the excalidraw npm package doesn't throw
|
||||||
|
// process undefined as docusaurus doesn't expose env variables by default
|
||||||
|
|
||||||
|
process.env.IS_PREACT = "false";
|
||||||
|
|
||||||
/** @type {import('@docusaurus/types').Config} */
|
/** @type {import('@docusaurus/types').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
title: "Excalidraw developer docs",
|
title: "Excalidraw developer docs",
|
||||||
@@ -139,7 +144,15 @@ const config = {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
themes: ["@docusaurus/theme-live-codeblock"],
|
themes: ["@docusaurus/theme-live-codeblock"],
|
||||||
plugins: ["docusaurus-plugin-sass"],
|
plugins: [
|
||||||
|
"docusaurus-plugin-sass",
|
||||||
|
[
|
||||||
|
"docusaurus2-dotenv",
|
||||||
|
{
|
||||||
|
systemvars: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"@docusaurus/core": "2.2.0",
|
"@docusaurus/core": "2.2.0",
|
||||||
"@docusaurus/preset-classic": "2.2.0",
|
"@docusaurus/preset-classic": "2.2.0",
|
||||||
"@docusaurus/theme-live-codeblock": "2.2.0",
|
"@docusaurus/theme-live-codeblock": "2.2.0",
|
||||||
"@excalidraw/excalidraw": "0.15.2-eb020d0",
|
"@excalidraw/excalidraw": "0.17.0",
|
||||||
"@mdx-js/react": "^1.6.22",
|
"@mdx-js/react": "^1.6.22",
|
||||||
"clsx": "^1.2.1",
|
"clsx": "^1.2.1",
|
||||||
"docusaurus-plugin-sass": "0.2.3",
|
"docusaurus-plugin-sass": "0.2.3",
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@docusaurus/module-type-aliases": "2.0.0-rc.1",
|
"@docusaurus/module-type-aliases": "2.0.0-rc.1",
|
||||||
"@tsconfig/docusaurus": "^1.0.5",
|
"@tsconfig/docusaurus": "^1.0.5",
|
||||||
|
"docusaurus2-dotenv": "1.4.0",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
"browserslist": {
|
"browserslist": {
|
||||||
|
|||||||
@@ -23,7 +23,11 @@ const sidebars = {
|
|||||||
},
|
},
|
||||||
items: ["introduction/development", "introduction/contributing"],
|
items: ["introduction/development", "introduction/contributing"],
|
||||||
},
|
},
|
||||||
{ type: "category", label: "Codebase", items: ["codebase/json-schema"] },
|
{
|
||||||
|
type: "category",
|
||||||
|
label: "Codebase",
|
||||||
|
items: ["codebase/json-schema", "codebase/frames"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "category",
|
type: "category",
|
||||||
label: "@excalidraw/excalidraw",
|
label: "@excalidraw/excalidraw",
|
||||||
@@ -49,7 +53,7 @@ const sidebars = {
|
|||||||
},
|
},
|
||||||
items: [
|
items: [
|
||||||
"@excalidraw/excalidraw/api/props/initialdata",
|
"@excalidraw/excalidraw/api/props/initialdata",
|
||||||
"@excalidraw/excalidraw/api/props/ref",
|
"@excalidraw/excalidraw/api/props/excalidraw-api",
|
||||||
"@excalidraw/excalidraw/api/props/render-props",
|
"@excalidraw/excalidraw/api/props/render-props",
|
||||||
"@excalidraw/excalidraw/api/props/ui-options",
|
"@excalidraw/excalidraw/api/props/ui-options",
|
||||||
],
|
],
|
||||||
|
|||||||
+147
-16
@@ -145,6 +145,14 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@babel/highlight" "^7.18.6"
|
"@babel/highlight" "^7.18.6"
|
||||||
|
|
||||||
|
"@babel/code-frame@^7.22.13":
|
||||||
|
version "7.22.13"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.22.13.tgz#e3c1c099402598483b7a8c46a721d1038803755e"
|
||||||
|
integrity sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==
|
||||||
|
dependencies:
|
||||||
|
"@babel/highlight" "^7.22.13"
|
||||||
|
chalk "^2.4.2"
|
||||||
|
|
||||||
"@babel/compat-data@^7.17.7", "@babel/compat-data@^7.18.8":
|
"@babel/compat-data@^7.17.7", "@babel/compat-data@^7.18.8":
|
||||||
version "7.18.8"
|
version "7.18.8"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.18.8.tgz#2483f565faca607b8535590e84e7de323f27764d"
|
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.18.8.tgz#2483f565faca607b8535590e84e7de323f27764d"
|
||||||
@@ -202,6 +210,16 @@
|
|||||||
"@jridgewell/gen-mapping" "^0.3.2"
|
"@jridgewell/gen-mapping" "^0.3.2"
|
||||||
jsesc "^2.5.1"
|
jsesc "^2.5.1"
|
||||||
|
|
||||||
|
"@babel/generator@^7.23.0":
|
||||||
|
version "7.23.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.23.0.tgz#df5c386e2218be505b34837acbcb874d7a983420"
|
||||||
|
integrity sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==
|
||||||
|
dependencies:
|
||||||
|
"@babel/types" "^7.23.0"
|
||||||
|
"@jridgewell/gen-mapping" "^0.3.2"
|
||||||
|
"@jridgewell/trace-mapping" "^0.3.17"
|
||||||
|
jsesc "^2.5.1"
|
||||||
|
|
||||||
"@babel/helper-annotate-as-pure@^7.18.6":
|
"@babel/helper-annotate-as-pure@^7.18.6":
|
||||||
version "7.18.6"
|
version "7.18.6"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.18.6.tgz#eaa49f6f80d5a33f9a5dd2276e6d6e451be0a6bb"
|
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.18.6.tgz#eaa49f6f80d5a33f9a5dd2276e6d6e451be0a6bb"
|
||||||
@@ -265,6 +283,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz#0c0cee9b35d2ca190478756865bb3528422f51be"
|
resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz#0c0cee9b35d2ca190478756865bb3528422f51be"
|
||||||
integrity sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==
|
integrity sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==
|
||||||
|
|
||||||
|
"@babel/helper-environment-visitor@^7.22.20":
|
||||||
|
version "7.22.20"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz#96159db61d34a29dba454c959f5ae4a649ba9167"
|
||||||
|
integrity sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==
|
||||||
|
|
||||||
"@babel/helper-explode-assignable-expression@^7.18.6":
|
"@babel/helper-explode-assignable-expression@^7.18.6":
|
||||||
version "7.18.6"
|
version "7.18.6"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.18.6.tgz#41f8228ef0a6f1a036b8dfdfec7ce94f9a6bc096"
|
resolved "https://registry.yarnpkg.com/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.18.6.tgz#41f8228ef0a6f1a036b8dfdfec7ce94f9a6bc096"
|
||||||
@@ -280,6 +303,14 @@
|
|||||||
"@babel/template" "^7.18.6"
|
"@babel/template" "^7.18.6"
|
||||||
"@babel/types" "^7.18.9"
|
"@babel/types" "^7.18.9"
|
||||||
|
|
||||||
|
"@babel/helper-function-name@^7.23.0":
|
||||||
|
version "7.23.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz#1f9a3cdbd5b2698a670c30d2735f9af95ed52759"
|
||||||
|
integrity sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==
|
||||||
|
dependencies:
|
||||||
|
"@babel/template" "^7.22.15"
|
||||||
|
"@babel/types" "^7.23.0"
|
||||||
|
|
||||||
"@babel/helper-hoist-variables@^7.18.6":
|
"@babel/helper-hoist-variables@^7.18.6":
|
||||||
version "7.18.6"
|
version "7.18.6"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz#d4d2c8fb4baeaa5c68b99cc8245c56554f926678"
|
resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz#d4d2c8fb4baeaa5c68b99cc8245c56554f926678"
|
||||||
@@ -287,6 +318,13 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@babel/types" "^7.18.6"
|
"@babel/types" "^7.18.6"
|
||||||
|
|
||||||
|
"@babel/helper-hoist-variables@^7.22.5":
|
||||||
|
version "7.22.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz#c01a007dac05c085914e8fb652b339db50d823bb"
|
||||||
|
integrity sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==
|
||||||
|
dependencies:
|
||||||
|
"@babel/types" "^7.22.5"
|
||||||
|
|
||||||
"@babel/helper-member-expression-to-functions@^7.18.9":
|
"@babel/helper-member-expression-to-functions@^7.18.9":
|
||||||
version "7.18.9"
|
version "7.18.9"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.18.9.tgz#1531661e8375af843ad37ac692c132841e2fd815"
|
resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.18.9.tgz#1531661e8375af843ad37ac692c132841e2fd815"
|
||||||
@@ -374,11 +412,28 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@babel/types" "^7.18.6"
|
"@babel/types" "^7.18.6"
|
||||||
|
|
||||||
|
"@babel/helper-split-export-declaration@^7.22.6":
|
||||||
|
version "7.22.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz#322c61b7310c0997fe4c323955667f18fcefb91c"
|
||||||
|
integrity sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==
|
||||||
|
dependencies:
|
||||||
|
"@babel/types" "^7.22.5"
|
||||||
|
|
||||||
|
"@babel/helper-string-parser@^7.22.5":
|
||||||
|
version "7.22.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f"
|
||||||
|
integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==
|
||||||
|
|
||||||
"@babel/helper-validator-identifier@^7.18.6":
|
"@babel/helper-validator-identifier@^7.18.6":
|
||||||
version "7.18.6"
|
version "7.18.6"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.18.6.tgz#9c97e30d31b2b8c72a1d08984f2ca9b574d7a076"
|
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.18.6.tgz#9c97e30d31b2b8c72a1d08984f2ca9b574d7a076"
|
||||||
integrity sha512-MmetCkz9ej86nJQV+sFCxoGGrUbU3q02kgLciwkrt9QqEB7cP39oKEY0PakknEO0Gu20SskMRi+AYZ3b1TpN9g==
|
integrity sha512-MmetCkz9ej86nJQV+sFCxoGGrUbU3q02kgLciwkrt9QqEB7cP39oKEY0PakknEO0Gu20SskMRi+AYZ3b1TpN9g==
|
||||||
|
|
||||||
|
"@babel/helper-validator-identifier@^7.22.20":
|
||||||
|
version "7.22.20"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz#c4ae002c61d2879e724581d96665583dbc1dc0e0"
|
||||||
|
integrity sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==
|
||||||
|
|
||||||
"@babel/helper-validator-option@^7.18.6":
|
"@babel/helper-validator-option@^7.18.6":
|
||||||
version "7.18.6"
|
version "7.18.6"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.18.6.tgz#bf0d2b5a509b1f336099e4ff36e1a63aa5db4db8"
|
resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.18.6.tgz#bf0d2b5a509b1f336099e4ff36e1a63aa5db4db8"
|
||||||
@@ -412,11 +467,25 @@
|
|||||||
chalk "^2.0.0"
|
chalk "^2.0.0"
|
||||||
js-tokens "^4.0.0"
|
js-tokens "^4.0.0"
|
||||||
|
|
||||||
|
"@babel/highlight@^7.22.13":
|
||||||
|
version "7.22.20"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.22.20.tgz#4ca92b71d80554b01427815e06f2df965b9c1f54"
|
||||||
|
integrity sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==
|
||||||
|
dependencies:
|
||||||
|
"@babel/helper-validator-identifier" "^7.22.20"
|
||||||
|
chalk "^2.4.2"
|
||||||
|
js-tokens "^4.0.0"
|
||||||
|
|
||||||
"@babel/parser@^7.12.7", "@babel/parser@^7.18.6", "@babel/parser@^7.18.8", "@babel/parser@^7.18.9":
|
"@babel/parser@^7.12.7", "@babel/parser@^7.18.6", "@babel/parser@^7.18.8", "@babel/parser@^7.18.9":
|
||||||
version "7.18.9"
|
version "7.18.9"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.18.9.tgz#f2dde0c682ccc264a9a8595efd030a5cc8fd2539"
|
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.18.9.tgz#f2dde0c682ccc264a9a8595efd030a5cc8fd2539"
|
||||||
integrity sha512-9uJveS9eY9DJ0t64YbIBZICtJy8a5QrDEVdiLCG97fVLpDTpGX7t8mMSb6OWw6Lrnjqj4O8zwjELX3dhoMgiBg==
|
integrity sha512-9uJveS9eY9DJ0t64YbIBZICtJy8a5QrDEVdiLCG97fVLpDTpGX7t8mMSb6OWw6Lrnjqj4O8zwjELX3dhoMgiBg==
|
||||||
|
|
||||||
|
"@babel/parser@^7.22.15", "@babel/parser@^7.23.0":
|
||||||
|
version "7.23.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.0.tgz#da950e622420bf96ca0d0f2909cdddac3acd8719"
|
||||||
|
integrity sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==
|
||||||
|
|
||||||
"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@^7.18.6":
|
"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@^7.18.6":
|
||||||
version "7.18.6"
|
version "7.18.6"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.18.6.tgz#da5b8f9a580acdfbe53494dba45ea389fb09a4d2"
|
resolved "https://registry.yarnpkg.com/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.18.6.tgz#da5b8f9a580acdfbe53494dba45ea389fb09a4d2"
|
||||||
@@ -1147,19 +1216,28 @@
|
|||||||
"@babel/parser" "^7.18.6"
|
"@babel/parser" "^7.18.6"
|
||||||
"@babel/types" "^7.18.6"
|
"@babel/types" "^7.18.6"
|
||||||
|
|
||||||
"@babel/traverse@^7.12.9", "@babel/traverse@^7.18.8", "@babel/traverse@^7.18.9":
|
"@babel/template@^7.22.15":
|
||||||
version "7.18.9"
|
version "7.22.15"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.18.9.tgz#deeff3e8f1bad9786874cb2feda7a2d77a904f98"
|
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38"
|
||||||
integrity sha512-LcPAnujXGwBgv3/WHv01pHtb2tihcyW1XuL9wd7jqh1Z8AQkTd+QVjMrMijrln0T7ED3UXLIy36P9Ao7W75rYg==
|
integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/code-frame" "^7.18.6"
|
"@babel/code-frame" "^7.22.13"
|
||||||
"@babel/generator" "^7.18.9"
|
"@babel/parser" "^7.22.15"
|
||||||
"@babel/helper-environment-visitor" "^7.18.9"
|
"@babel/types" "^7.22.15"
|
||||||
"@babel/helper-function-name" "^7.18.9"
|
|
||||||
"@babel/helper-hoist-variables" "^7.18.6"
|
"@babel/traverse@^7.12.9", "@babel/traverse@^7.18.8", "@babel/traverse@^7.18.9":
|
||||||
"@babel/helper-split-export-declaration" "^7.18.6"
|
version "7.23.2"
|
||||||
"@babel/parser" "^7.18.9"
|
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.2.tgz#329c7a06735e144a506bdb2cad0268b7f46f4ad8"
|
||||||
"@babel/types" "^7.18.9"
|
integrity sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==
|
||||||
|
dependencies:
|
||||||
|
"@babel/code-frame" "^7.22.13"
|
||||||
|
"@babel/generator" "^7.23.0"
|
||||||
|
"@babel/helper-environment-visitor" "^7.22.20"
|
||||||
|
"@babel/helper-function-name" "^7.23.0"
|
||||||
|
"@babel/helper-hoist-variables" "^7.22.5"
|
||||||
|
"@babel/helper-split-export-declaration" "^7.22.6"
|
||||||
|
"@babel/parser" "^7.23.0"
|
||||||
|
"@babel/types" "^7.23.0"
|
||||||
debug "^4.1.0"
|
debug "^4.1.0"
|
||||||
globals "^11.1.0"
|
globals "^11.1.0"
|
||||||
|
|
||||||
@@ -1171,6 +1249,15 @@
|
|||||||
"@babel/helper-validator-identifier" "^7.18.6"
|
"@babel/helper-validator-identifier" "^7.18.6"
|
||||||
to-fast-properties "^2.0.0"
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
|
"@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0":
|
||||||
|
version "7.23.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.0.tgz#8c1f020c9df0e737e4e247c0619f58c68458aaeb"
|
||||||
|
integrity sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==
|
||||||
|
dependencies:
|
||||||
|
"@babel/helper-string-parser" "^7.22.5"
|
||||||
|
"@babel/helper-validator-identifier" "^7.22.20"
|
||||||
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
"@colors/colors@1.5.0":
|
"@colors/colors@1.5.0":
|
||||||
version "1.5.0"
|
version "1.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
|
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
|
||||||
@@ -1631,10 +1718,10 @@
|
|||||||
url-loader "^4.1.1"
|
url-loader "^4.1.1"
|
||||||
webpack "^5.73.0"
|
webpack "^5.73.0"
|
||||||
|
|
||||||
"@excalidraw/excalidraw@0.15.2-eb020d0":
|
"@excalidraw/excalidraw@0.17.0":
|
||||||
version "0.15.2-eb020d0"
|
version "0.17.0"
|
||||||
resolved "https://registry.yarnpkg.com/@excalidraw/excalidraw/-/excalidraw-0.15.2-eb020d0.tgz#25bd61e6f23da7c084fb16a3e0fe0dd9ad8e6533"
|
resolved "https://registry.yarnpkg.com/@excalidraw/excalidraw/-/excalidraw-0.17.0.tgz#3c64aa8e36406ac171b008cfecbdce5bb0755725"
|
||||||
integrity sha512-TKGLzpOVqFQcwK1GFKTDXgg1s2U6tc5KE3qXuv87osbzOtftQn3x4+VH61vwdj11l00nEN80SMdXUC43T9uJqQ==
|
integrity sha512-NzP22v5xMqxYW27ZtTHhiGFe7kE8NeBk45aoeM/mDSkXiOXPDH+PcvwzHRN/Ei+Vj/0sTPHxejn8bZyRWKGjXg==
|
||||||
|
|
||||||
"@hapi/hoek@^9.0.0":
|
"@hapi/hoek@^9.0.0":
|
||||||
version "9.3.0"
|
version "9.3.0"
|
||||||
@@ -1670,6 +1757,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78"
|
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78"
|
||||||
integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==
|
integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==
|
||||||
|
|
||||||
|
"@jridgewell/resolve-uri@^3.1.0":
|
||||||
|
version "3.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721"
|
||||||
|
integrity sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==
|
||||||
|
|
||||||
"@jridgewell/set-array@^1.0.0", "@jridgewell/set-array@^1.0.1":
|
"@jridgewell/set-array@^1.0.0", "@jridgewell/set-array@^1.0.1":
|
||||||
version "1.1.2"
|
version "1.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
|
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
|
||||||
@@ -1688,6 +1780,19 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24"
|
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24"
|
||||||
integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==
|
integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==
|
||||||
|
|
||||||
|
"@jridgewell/sourcemap-codec@^1.4.14":
|
||||||
|
version "1.4.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
|
||||||
|
integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==
|
||||||
|
|
||||||
|
"@jridgewell/trace-mapping@^0.3.17":
|
||||||
|
version "0.3.20"
|
||||||
|
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz#72e45707cf240fa6b081d0366f8265b0cd10197f"
|
||||||
|
integrity sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==
|
||||||
|
dependencies:
|
||||||
|
"@jridgewell/resolve-uri" "^3.1.0"
|
||||||
|
"@jridgewell/sourcemap-codec" "^1.4.14"
|
||||||
|
|
||||||
"@jridgewell/trace-mapping@^0.3.7", "@jridgewell/trace-mapping@^0.3.9":
|
"@jridgewell/trace-mapping@^0.3.7", "@jridgewell/trace-mapping@^0.3.9":
|
||||||
version "0.3.14"
|
version "0.3.14"
|
||||||
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz#b231a081d8f66796e475ad588a1ef473112701ed"
|
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz#b231a081d8f66796e475ad588a1ef473112701ed"
|
||||||
@@ -3462,6 +3567,13 @@ docusaurus-plugin-sass@0.2.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
sass-loader "^10.1.1"
|
sass-loader "^10.1.1"
|
||||||
|
|
||||||
|
docusaurus2-dotenv@1.4.0:
|
||||||
|
version "1.4.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/docusaurus2-dotenv/-/docusaurus2-dotenv-1.4.0.tgz#9ab900e29de9081f9f1f28f7224ff63760385641"
|
||||||
|
integrity sha512-iWqem5fnBAyeBBtX75Fxp71uUAnwFaXzOmade8zAhN4vL3RG9m27sLSRwjJGVVgIkEo3esjGyCcTGTiCjfi+sg==
|
||||||
|
dependencies:
|
||||||
|
dotenv-webpack "1.7.0"
|
||||||
|
|
||||||
dom-converter@^0.2.0:
|
dom-converter@^0.2.0:
|
||||||
version "0.2.0"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768"
|
resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768"
|
||||||
@@ -3547,6 +3659,25 @@ dot-prop@^5.2.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
is-obj "^2.0.0"
|
is-obj "^2.0.0"
|
||||||
|
|
||||||
|
dotenv-defaults@^1.0.2:
|
||||||
|
version "1.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/dotenv-defaults/-/dotenv-defaults-1.1.1.tgz#032c024f4b5906d9990eb06d722dc74cc60ec1bd"
|
||||||
|
integrity sha512-6fPRo9o/3MxKvmRZBD3oNFdxODdhJtIy1zcJeUSCs6HCy4tarUpd+G67UTU9tF6OWXeSPqsm4fPAB+2eY9Rt9Q==
|
||||||
|
dependencies:
|
||||||
|
dotenv "^6.2.0"
|
||||||
|
|
||||||
|
dotenv-webpack@1.7.0:
|
||||||
|
version "1.7.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/dotenv-webpack/-/dotenv-webpack-1.7.0.tgz#4384d8c57ee6f405c296278c14a9f9167856d3a1"
|
||||||
|
integrity sha512-wwNtOBW/6gLQSkb8p43y0Wts970A3xtNiG/mpwj9MLUhtPCQG6i+/DSXXoNN7fbPCU/vQ7JjwGmgOeGZSSZnsw==
|
||||||
|
dependencies:
|
||||||
|
dotenv-defaults "^1.0.2"
|
||||||
|
|
||||||
|
dotenv@^6.2.0:
|
||||||
|
version "6.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
|
||||||
|
integrity sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==
|
||||||
|
|
||||||
duplexer3@^0.1.4:
|
duplexer3@^0.1.4:
|
||||||
version "0.1.5"
|
version "0.1.5"
|
||||||
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.5.tgz#0b5e4d7bad5de8901ea4440624c8e1d20099217e"
|
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.5.tgz#0b5e4d7bad5de8901ea4440624c8e1d20099217e"
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ export const ExportToExcalidrawPlus: React.FC<{
|
|||||||
appState: Partial<AppState>;
|
appState: Partial<AppState>;
|
||||||
files: BinaryFiles;
|
files: BinaryFiles;
|
||||||
onError: (error: Error) => void;
|
onError: (error: Error) => void;
|
||||||
}> = ({ elements, appState, files, onError }) => {
|
onSuccess: () => void;
|
||||||
|
}> = ({ elements, appState, files, onError, onSuccess }) => {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
return (
|
return (
|
||||||
<Card color="primary">
|
<Card color="primary">
|
||||||
@@ -107,6 +108,7 @@ export const ExportToExcalidrawPlus: React.FC<{
|
|||||||
try {
|
try {
|
||||||
trackEvent("export", "eplus", `ui (${getFrame()})`);
|
trackEvent("export", "eplus", `ui (${getFrame()})`);
|
||||||
await exportToExcalidrawPlus(elements, appState, files);
|
await exportToExcalidrawPlus(elements, appState, files);
|
||||||
|
onSuccess();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (error.name !== "AbortError") {
|
if (error.name !== "AbortError") {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* - DataState refers to full state of the app: appState, elements, images,
|
* - DataState refers to full state of the app: appState, elements, images,
|
||||||
* though some state is saved separately (collab username, library) for one
|
* though some state is saved separately (collab username, library) for one
|
||||||
* reason or another. We also save different data to different sotrage
|
* reason or another. We also save different data to different storage
|
||||||
* (localStorage, indexedDB).
|
* (localStorage, indexedDB).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -131,5 +131,5 @@ export class Debug {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
//@ts-ignore
|
||||||
window.debug = Debug;
|
window.debug = Debug;
|
||||||
|
|||||||
@@ -608,7 +608,7 @@ const ExcalidrawWrapper = () => {
|
|||||||
canvas: HTMLCanvasElement,
|
canvas: HTMLCanvasElement,
|
||||||
) => {
|
) => {
|
||||||
if (exportedElements.length === 0) {
|
if (exportedElements.length === 0) {
|
||||||
return window.alert(t("alerts.cannotExportEmptyCanvas"));
|
throw new Error(t("alerts.cannotExportEmptyCanvas"));
|
||||||
}
|
}
|
||||||
if (canvas) {
|
if (canvas) {
|
||||||
try {
|
try {
|
||||||
@@ -624,7 +624,7 @@ const ExcalidrawWrapper = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
setErrorMessage(errorMessage);
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
@@ -634,7 +634,7 @@ const ExcalidrawWrapper = () => {
|
|||||||
if (error.name !== "AbortError") {
|
if (error.name !== "AbortError") {
|
||||||
const { width, height } = canvas;
|
const { width, height } = canvas;
|
||||||
console.error(error, { width, height });
|
console.error(error, { width, height });
|
||||||
setErrorMessage(error.message);
|
throw new Error(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -691,7 +691,7 @@ const ExcalidrawWrapper = () => {
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Excalidraw
|
<Excalidraw
|
||||||
ref={excalidrawRefCallback}
|
excalidrawAPI={excalidrawRefCallback}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
initialData={initialStatePromiseRef.current.promise}
|
initialData={initialStatePromiseRef.current.promise}
|
||||||
isCollaborating={isCollaborating}
|
isCollaborating={isCollaborating}
|
||||||
@@ -714,6 +714,11 @@ const ExcalidrawWrapper = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
onSuccess={() => {
|
||||||
|
excalidrawAPI?.updateScene({
|
||||||
|
appState: { openDialog: null },
|
||||||
|
});
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ describe("Test MobileMenu", () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await render(<ExcalidrawApp />);
|
await render(<ExcalidrawApp />);
|
||||||
//@ts-ignore
|
// @ts-ignore
|
||||||
h.app.refreshDeviceState(h.app.excalidrawContainerRef.current!);
|
h.app.refreshViewportBreakpoints();
|
||||||
|
// @ts-ignore
|
||||||
|
h.app.refreshEditorBreakpoints();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
@@ -28,11 +30,15 @@ describe("Test MobileMenu", () => {
|
|||||||
it("should set device correctly", () => {
|
it("should set device correctly", () => {
|
||||||
expect(h.app.device).toMatchInlineSnapshot(`
|
expect(h.app.device).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"canDeviceFitSidebar": false,
|
"editor": {
|
||||||
"isLandscape": true,
|
"canFitSidebar": false,
|
||||||
"isMobile": true,
|
"isMobile": true,
|
||||||
"isSmScreen": false,
|
},
|
||||||
"isTouchScreen": false,
|
"isTouchScreen": false,
|
||||||
|
"viewport": {
|
||||||
|
"isLandscape": false,
|
||||||
|
"isMobile": true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from "../../excalidraw-app/collab/reconciliation";
|
} from "../../excalidraw-app/collab/reconciliation";
|
||||||
import { randomInteger } from "../../src/random";
|
import { randomInteger } from "../../src/random";
|
||||||
import { AppState } from "../../src/types";
|
import { AppState } from "../../src/types";
|
||||||
|
import { cloneJSON } from "../../src/utils";
|
||||||
|
|
||||||
type Id = string;
|
type Id = string;
|
||||||
type ElementLike = {
|
type ElementLike = {
|
||||||
@@ -93,8 +94,6 @@ const cleanElements = (elements: ReconciledElements) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const cloneDeep = (data: any) => JSON.parse(JSON.stringify(data));
|
|
||||||
|
|
||||||
const test = <U extends `${string}:${"L" | "R"}`>(
|
const test = <U extends `${string}:${"L" | "R"}`>(
|
||||||
local: (Id | ElementLike)[],
|
local: (Id | ElementLike)[],
|
||||||
remote: (Id | ElementLike)[],
|
remote: (Id | ElementLike)[],
|
||||||
@@ -115,15 +114,15 @@ const test = <U extends `${string}:${"L" | "R"}`>(
|
|||||||
"remote reconciliation",
|
"remote reconciliation",
|
||||||
);
|
);
|
||||||
|
|
||||||
const __local = cleanElements(cloneDeep(_remote));
|
const __local = cleanElements(cloneJSON(_remote) as ReconciledElements);
|
||||||
const __remote = addParents(cleanElements(cloneDeep(remoteReconciled)));
|
const __remote = addParents(cleanElements(cloneJSON(remoteReconciled)));
|
||||||
if (bidirectional) {
|
if (bidirectional) {
|
||||||
try {
|
try {
|
||||||
expect(
|
expect(
|
||||||
cleanElements(
|
cleanElements(
|
||||||
reconcileElements(
|
reconcileElements(
|
||||||
cloneDeep(__local),
|
cloneJSON(__local),
|
||||||
cloneDeep(__remote),
|
cloneJSON(__remote),
|
||||||
{} as AppState,
|
{} as AppState,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
+8
-7
@@ -21,7 +21,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braintree/sanitize-url": "6.0.2",
|
"@braintree/sanitize-url": "6.0.2",
|
||||||
"@excalidraw/laser-pointer": "1.2.0",
|
"@excalidraw/laser-pointer": "1.2.0",
|
||||||
"@excalidraw/random-username": "1.0.0",
|
"@excalidraw/mermaid-to-excalidraw": "0.1.2",
|
||||||
|
"@excalidraw/random-username": "1.1.0",
|
||||||
"@radix-ui/react-popover": "1.0.3",
|
"@radix-ui/react-popover": "1.0.3",
|
||||||
"@radix-ui/react-tabs": "1.0.2",
|
"@radix-ui/react-tabs": "1.0.2",
|
||||||
"@sentry/browser": "6.2.5",
|
"@sentry/browser": "6.2.5",
|
||||||
@@ -49,11 +50,11 @@
|
|||||||
"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": "1.0.1",
|
||||||
"pwacompat": "2.0.17",
|
"pwacompat": "2.0.17",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"roughjs": "4.5.2",
|
"roughjs": "4.6.4",
|
||||||
"sass": "1.51.0",
|
"sass": "1.51.0",
|
||||||
"socket.io-client": "2.3.1",
|
"socket.io-client": "2.3.1",
|
||||||
"tunnel-rat": "0.1.2"
|
"tunnel-rat": "0.1.2"
|
||||||
@@ -95,7 +96,7 @@
|
|||||||
"vitest-canvas-mock": "0.3.2"
|
"vitest-canvas-mock": "0.3.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": "18.0.0 - 20.x.x"
|
||||||
},
|
},
|
||||||
"homepage": ".",
|
"homepage": ".",
|
||||||
"name": "excalidraw",
|
"name": "excalidraw",
|
||||||
@@ -125,10 +126,10 @@
|
|||||||
"test": "yarn test:app",
|
"test": "yarn test:app",
|
||||||
"test:coverage": "vitest --coverage",
|
"test:coverage": "vitest --coverage",
|
||||||
"test:coverage:watch": "vitest --coverage --watch",
|
"test:coverage:watch": "vitest --coverage --watch",
|
||||||
"test:ui": "yarn test --ui",
|
"test:ui": "yarn test --ui --coverage.enabled=true",
|
||||||
"autorelease": "node scripts/autorelease.js",
|
"autorelease": "node scripts/autorelease.js",
|
||||||
"prerelease": "node scripts/prerelease.js",
|
"prerelease:excalidraw": "node scripts/prerelease.js",
|
||||||
"build:preview": "yarn build && vite preview --port 5000",
|
"build:preview": "yarn build && vite preview --port 5000",
|
||||||
"release": "node scripts/release.js"
|
"release:excalidraw": "node scripts/release.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { getNormalizedZoom } 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, setCursor, updateActiveTool } from "../utils";
|
import { getShortcutKey, updateActiveTool } 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";
|
||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
} from "../appState";
|
} from "../appState";
|
||||||
import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors";
|
import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors";
|
||||||
import { Bounds } from "../element/bounds";
|
import { Bounds } from "../element/bounds";
|
||||||
|
import { setCursor } from "../cursor";
|
||||||
|
|
||||||
export const actionChangeViewBackgroundColor = register({
|
export const actionChangeViewBackgroundColor = register({
|
||||||
name: "changeViewBackgroundColor",
|
name: "changeViewBackgroundColor",
|
||||||
@@ -264,7 +265,21 @@ export const zoomToFit = ({
|
|||||||
30.0,
|
30.0,
|
||||||
) as NormalizedZoomValue;
|
) as NormalizedZoomValue;
|
||||||
|
|
||||||
scrollX = (appState.width / 2) * (1 / newZoomValue) - centerX;
|
let appStateWidth = appState.width;
|
||||||
|
|
||||||
|
if (appState.openSidebar) {
|
||||||
|
const sidebarDOMElem = document.querySelector(
|
||||||
|
".sidebar",
|
||||||
|
) as HTMLElement | null;
|
||||||
|
const sidebarWidth = sidebarDOMElem?.offsetWidth ?? 0;
|
||||||
|
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
||||||
|
|
||||||
|
appStateWidth = !isRTL
|
||||||
|
? appState.width - sidebarWidth
|
||||||
|
: appState.width + sidebarWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollX = (appStateWidth / 2) * (1 / newZoomValue) - centerX;
|
||||||
scrollY = (appState.height / 2) * (1 / newZoomValue) - centerY;
|
scrollY = (appState.height / 2) * (1 / newZoomValue) - centerY;
|
||||||
} else {
|
} else {
|
||||||
newZoomValue = zoomValueToFitBoundsOnViewport(commonBounds, {
|
newZoomValue = zoomValueToFitBoundsOnViewport(commonBounds, {
|
||||||
@@ -437,5 +452,6 @@ export const actionToggleHandTool = register({
|
|||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
keyTest: (event) => event.key === KEYS.H,
|
keyTest: (event) =>
|
||||||
|
!event.altKey && !event[KEYS.CTRL_OR_CMD] && event.key === KEYS.H,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,33 +3,43 @@ import { register } from "./register";
|
|||||||
import {
|
import {
|
||||||
copyTextToSystemClipboard,
|
copyTextToSystemClipboard,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
|
createPasteEvent,
|
||||||
probablySupportsClipboardBlob,
|
probablySupportsClipboardBlob,
|
||||||
probablySupportsClipboardWriteText,
|
probablySupportsClipboardWriteText,
|
||||||
|
readSystemClipboard,
|
||||||
} from "../clipboard";
|
} from "../clipboard";
|
||||||
import { actionDeleteSelected } from "./actionDeleteSelected";
|
import { actionDeleteSelected } from "./actionDeleteSelected";
|
||||||
import { exportCanvas } from "../data/index";
|
import { exportCanvas, prepareElementsForExport } from "../data/index";
|
||||||
import { getNonDeletedElements, isTextElement } from "../element";
|
import { isTextElement } from "../element";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
import { isFirefox } from "../constants";
|
||||||
|
|
||||||
export const actionCopy = register({
|
export const actionCopy = register({
|
||||||
name: "copy",
|
name: "copy",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements, appState, _, app) => {
|
perform: async (elements, appState, event: ClipboardEvent | null, app) => {
|
||||||
const elementsToCopy = app.scene.getSelectedElements({
|
const elementsToCopy = app.scene.getSelectedElements({
|
||||||
selectedElementIds: appState.selectedElementIds,
|
selectedElementIds: appState.selectedElementIds,
|
||||||
includeBoundTextElement: true,
|
includeBoundTextElement: true,
|
||||||
includeElementsInFrames: true,
|
includeElementsInFrames: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
copyToClipboard(elementsToCopy, app.files);
|
try {
|
||||||
|
await copyToClipboard(elementsToCopy, app.files, event);
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
commitToHistory: false,
|
||||||
|
appState: {
|
||||||
|
...appState,
|
||||||
|
errorMessage: error.message,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
predicate: (elements, appState, appProps, app) => {
|
|
||||||
return app.device.isMobile && !!navigator.clipboard;
|
|
||||||
},
|
|
||||||
contextItemLabel: "labels.copy",
|
contextItemLabel: "labels.copy",
|
||||||
// don't supply a shortcut since we handle this conditionally via onCopy event
|
// don't supply a shortcut since we handle this conditionally via onCopy event
|
||||||
keyTest: undefined,
|
keyTest: undefined,
|
||||||
@@ -38,15 +48,55 @@ export const actionCopy = register({
|
|||||||
export const actionPaste = register({
|
export const actionPaste = register({
|
||||||
name: "paste",
|
name: "paste",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements: any, appStates: any, data, app) => {
|
perform: async (elements, appState, data, app) => {
|
||||||
app.pasteFromClipboard(null);
|
let types;
|
||||||
|
try {
|
||||||
|
types = await readSystemClipboard();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.name === "AbortError" || error.name === "NotAllowedError") {
|
||||||
|
// user probably aborted the action. Though not 100% sure, it's best
|
||||||
|
// to not annoy them with an error message.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(`actionPaste ${error.name}: ${error.message}`);
|
||||||
|
|
||||||
|
if (isFirefox) {
|
||||||
|
return {
|
||||||
|
commitToHistory: false,
|
||||||
|
appState: {
|
||||||
|
...appState,
|
||||||
|
errorMessage: t("hints.firefox_clipboard_write"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
commitToHistory: false,
|
||||||
|
appState: {
|
||||||
|
...appState,
|
||||||
|
errorMessage: t("errors.asyncPasteFailedOnRead"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
app.pasteFromClipboard(createPasteEvent({ types }));
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(error);
|
||||||
|
return {
|
||||||
|
commitToHistory: false,
|
||||||
|
appState: {
|
||||||
|
...appState,
|
||||||
|
errorMessage: t("errors.asyncPasteFailedOnParse"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
predicate: (elements, appState, appProps, app) => {
|
|
||||||
return app.device.isMobile && !!navigator.clipboard;
|
|
||||||
},
|
|
||||||
contextItemLabel: "labels.paste",
|
contextItemLabel: "labels.paste",
|
||||||
// don't supply a shortcut since we handle this conditionally via onCopy event
|
// don't supply a shortcut since we handle this conditionally via onCopy event
|
||||||
keyTest: undefined,
|
keyTest: undefined,
|
||||||
@@ -55,13 +105,10 @@ export const actionPaste = register({
|
|||||||
export const actionCut = register({
|
export const actionCut = register({
|
||||||
name: "cut",
|
name: "cut",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements, appState, data, app) => {
|
perform: (elements, appState, event: ClipboardEvent | null, app) => {
|
||||||
actionCopy.perform(elements, appState, data, app);
|
actionCopy.perform(elements, appState, event, app);
|
||||||
return actionDeleteSelected.perform(elements, appState);
|
return actionDeleteSelected.perform(elements, appState);
|
||||||
},
|
},
|
||||||
predicate: (elements, appState, appProps, app) => {
|
|
||||||
return app.device.isMobile && !!navigator.clipboard;
|
|
||||||
},
|
|
||||||
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.key === KEYS.X,
|
||||||
});
|
});
|
||||||
@@ -75,20 +122,23 @@ export const actionCopyAsSvg = register({
|
|||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const selectedElements = app.scene.getSelectedElements({
|
|
||||||
selectedElementIds: appState.selectedElementIds,
|
const { exportedElements, exportingFrame } = prepareElementsForExport(
|
||||||
includeBoundTextElement: true,
|
elements,
|
||||||
includeElementsInFrames: true,
|
appState,
|
||||||
});
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await exportCanvas(
|
await exportCanvas(
|
||||||
"clipboard-svg",
|
"clipboard-svg",
|
||||||
selectedElements.length
|
exportedElements,
|
||||||
? selectedElements
|
|
||||||
: getNonDeletedElements(elements),
|
|
||||||
appState,
|
appState,
|
||||||
app.files,
|
app.files,
|
||||||
appState,
|
{
|
||||||
|
...appState,
|
||||||
|
exportingFrame,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
@@ -124,16 +174,17 @@ export const actionCopyAsPng = register({
|
|||||||
includeBoundTextElement: true,
|
includeBoundTextElement: true,
|
||||||
includeElementsInFrames: true,
|
includeElementsInFrames: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { exportedElements, exportingFrame } = prepareElementsForExport(
|
||||||
|
elements,
|
||||||
|
appState,
|
||||||
|
true,
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
await exportCanvas(
|
await exportCanvas("clipboard", exportedElements, appState, app.files, {
|
||||||
"clipboard",
|
...appState,
|
||||||
selectedElements.length
|
exportingFrame,
|
||||||
? selectedElements
|
});
|
||||||
: getNonDeletedElements(elements),
|
|
||||||
appState,
|
|
||||||
app.files,
|
|
||||||
appState,
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ const deleteSelectedElements = (
|
|||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
selectedElementIds: {},
|
selectedElementIds: {},
|
||||||
|
selectedGroupIds: {},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { normalizeElementOrder } from "../element/sortElements";
|
|||||||
import { DuplicateIcon } from "../components/icons";
|
import { DuplicateIcon } from "../components/icons";
|
||||||
import {
|
import {
|
||||||
bindElementsToFramesAfterDuplication,
|
bindElementsToFramesAfterDuplication,
|
||||||
getFrameElements,
|
getFrameChildren,
|
||||||
} from "../frame";
|
} from "../frame";
|
||||||
import {
|
import {
|
||||||
excludeElementsInFramesFromSelection,
|
excludeElementsInFramesFromSelection,
|
||||||
@@ -155,7 +155,7 @@ const duplicateElements = (
|
|||||||
groupId,
|
groupId,
|
||||||
).flatMap((element) =>
|
).flatMap((element) =>
|
||||||
isFrameElement(element)
|
isFrameElement(element)
|
||||||
? [...getFrameElements(elements, element.id), element]
|
? [...getFrameChildren(elements, element.id), element]
|
||||||
: [element],
|
: [element],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ const duplicateElements = (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isElementAFrame) {
|
if (isElementAFrame) {
|
||||||
const elementsInFrame = getFrameElements(sortedElements, element.id);
|
const elementsInFrame = getFrameChildren(sortedElements, element.id);
|
||||||
|
|
||||||
elementsWithClones.push(
|
elementsWithClones.push(
|
||||||
...markAsProcessed([
|
...markAsProcessed([
|
||||||
|
|||||||
@@ -191,7 +191,15 @@ export const actionSaveFileToDisk = register({
|
|||||||
},
|
},
|
||||||
app.files,
|
app.files,
|
||||||
);
|
);
|
||||||
return { commitToHistory: false, appState: { ...appState, fileHandle } };
|
return {
|
||||||
|
commitToHistory: false,
|
||||||
|
appState: {
|
||||||
|
...appState,
|
||||||
|
openDialog: null,
|
||||||
|
fileHandle,
|
||||||
|
toast: { message: t("toast.fileSaved") },
|
||||||
|
},
|
||||||
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error?.name !== "AbortError") {
|
if (error?.name !== "AbortError") {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -209,7 +217,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={useDevice().editor.isMobile}
|
||||||
hidden={!nativeFileSystemSupported}
|
hidden={!nativeFileSystemSupported}
|
||||||
onClick={() => updateData(null)}
|
onClick={() => updateData(null)}
|
||||||
data-testid="save-as-button"
|
data-testid="save-as-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 { updateActiveTool } 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";
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
} from "../element/binding";
|
} from "../element/binding";
|
||||||
import { isBindingElement, isLinearElement } from "../element/typeChecks";
|
import { isBindingElement, isLinearElement } from "../element/typeChecks";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
|
import { resetCursor } from "../cursor";
|
||||||
|
|
||||||
export const actionFinalize = register({
|
export const actionFinalize = register({
|
||||||
name: "finalize",
|
name: "finalize",
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { getNonDeletedElements } from "../element";
|
import { getNonDeletedElements } from "../element";
|
||||||
import { ExcalidrawElement } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
import { removeAllElementsFromFrame } from "../frame";
|
import { removeAllElementsFromFrame } from "../frame";
|
||||||
import { getFrameElements } from "../frame";
|
import { getFrameChildren } from "../frame";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { AppClassProperties, AppState } from "../types";
|
import { AppClassProperties, AppState } from "../types";
|
||||||
import { setCursorForShape, updateActiveTool } from "../utils";
|
import { updateActiveTool } from "../utils";
|
||||||
|
import { setCursorForShape } from "../cursor";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
|
|
||||||
const isSingleFrameSelected = (appState: AppState, app: AppClassProperties) => {
|
const isSingleFrameSelected = (appState: AppState, app: AppClassProperties) => {
|
||||||
@@ -20,7 +21,7 @@ export const actionSelectAllElementsInFrame = register({
|
|||||||
const selectedFrame = app.scene.getSelectedElements(appState)[0];
|
const selectedFrame = app.scene.getSelectedElements(appState)[0];
|
||||||
|
|
||||||
if (selectedFrame && selectedFrame.type === "frame") {
|
if (selectedFrame && selectedFrame.type === "frame") {
|
||||||
const elementsInFrame = getFrameElements(
|
const elementsInFrame = getFrameChildren(
|
||||||
getNonDeletedElements(elements),
|
getNonDeletedElements(elements),
|
||||||
selectedFrame.id,
|
selectedFrame.id,
|
||||||
).filter((element) => !(element.type === "text" && element.containerId));
|
).filter((element) => !(element.type === "text" && element.containerId));
|
||||||
|
|||||||
+15
-13
@@ -17,15 +17,12 @@ import {
|
|||||||
import { getNonDeletedElements } from "../element";
|
import { getNonDeletedElements } from "../element";
|
||||||
import { randomId } from "../random";
|
import { randomId } from "../random";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
import {
|
import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types";
|
||||||
ExcalidrawElement,
|
|
||||||
ExcalidrawFrameElement,
|
|
||||||
ExcalidrawTextElement,
|
|
||||||
} from "../element/types";
|
|
||||||
import { AppClassProperties, AppState } from "../types";
|
import { AppClassProperties, AppState } from "../types";
|
||||||
import { isBoundToContainer } from "../element/typeChecks";
|
import { isBoundToContainer } from "../element/typeChecks";
|
||||||
import {
|
import {
|
||||||
getElementsInResizingFrame,
|
getElementsInResizingFrame,
|
||||||
|
getFrameElements,
|
||||||
groupByFrames,
|
groupByFrames,
|
||||||
removeElementsFromFrame,
|
removeElementsFromFrame,
|
||||||
replaceAllElementsInFrame,
|
replaceAllElementsInFrame,
|
||||||
@@ -190,13 +187,6 @@ export const actionUngroup = register({
|
|||||||
|
|
||||||
let nextElements = [...elements];
|
let nextElements = [...elements];
|
||||||
|
|
||||||
const selectedElements = app.scene.getSelectedElements(appState);
|
|
||||||
const frames = selectedElements
|
|
||||||
.filter((element) => element.frameId)
|
|
||||||
.map((element) =>
|
|
||||||
app.scene.getElement(element.frameId!),
|
|
||||||
) as ExcalidrawFrameElement[];
|
|
||||||
|
|
||||||
const boundTextElementIds: ExcalidrawTextElement["id"][] = [];
|
const boundTextElementIds: ExcalidrawTextElement["id"][] = [];
|
||||||
nextElements = nextElements.map((element) => {
|
nextElements = nextElements.map((element) => {
|
||||||
if (isBoundToContainer(element)) {
|
if (isBoundToContainer(element)) {
|
||||||
@@ -221,7 +211,19 @@ export const actionUngroup = register({
|
|||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
frames.forEach((frame) => {
|
const selectedElements = app.scene.getSelectedElements(appState);
|
||||||
|
|
||||||
|
const selectedElementFrameIds = new Set(
|
||||||
|
selectedElements
|
||||||
|
.filter((element) => element.frameId)
|
||||||
|
.map((element) => element.frameId!),
|
||||||
|
);
|
||||||
|
|
||||||
|
const targetFrames = getFrameElements(elements).filter((frame) =>
|
||||||
|
selectedElementFrameIds.has(frame.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
targetFrames.forEach((frame) => {
|
||||||
if (frame) {
|
if (frame) {
|
||||||
nextElements = replaceAllElementsInFrame(
|
nextElements = replaceAllElementsInFrame(
|
||||||
nextElements,
|
nextElements,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { ToolButton } from "../components/ToolButton";
|
|||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { showSelectedShapeActions, getNonDeletedElements } from "../element";
|
import { showSelectedShapeActions, getNonDeletedElements } from "../element";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { allowFullScreen, exitFullScreen, isFullScreen } from "../utils";
|
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
|
|
||||||
export const actionToggleCanvasMenu = register({
|
export const actionToggleCanvasMenu = register({
|
||||||
@@ -52,23 +51,6 @@ export const actionToggleEditMenu = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionFullScreen = register({
|
|
||||||
name: "toggleFullScreen",
|
|
||||||
viewMode: true,
|
|
||||||
trackEvent: { category: "canvas", predicate: (appState) => !isFullScreen() },
|
|
||||||
perform: () => {
|
|
||||||
if (!isFullScreen()) {
|
|
||||||
allowFullScreen();
|
|
||||||
}
|
|
||||||
if (isFullScreen()) {
|
|
||||||
exitFullScreen();
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
commitToHistory: false,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const actionShortcuts = register({
|
export const actionShortcuts = register({
|
||||||
name: "toggleShortcuts",
|
name: "toggleShortcuts",
|
||||||
viewMode: true,
|
viewMode: true,
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
import { Excalidraw } from "../packages/excalidraw/index";
|
||||||
|
import { queryByTestId } from "@testing-library/react";
|
||||||
|
import { render } from "../tests/test-utils";
|
||||||
|
import { UI } from "../tests/helpers/ui";
|
||||||
|
import { API } from "../tests/helpers/api";
|
||||||
|
import { COLOR_PALETTE, DEFAULT_ELEMENT_BACKGROUND_PICKS } from "../colors";
|
||||||
|
import { FONT_FAMILY, STROKE_WIDTH } from "../constants";
|
||||||
|
|
||||||
|
const { h } = window;
|
||||||
|
|
||||||
|
describe("element locking", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await render(<Excalidraw />);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("properties when tool selected", () => {
|
||||||
|
it("should show active background top picks", () => {
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
|
||||||
|
const color = DEFAULT_ELEMENT_BACKGROUND_PICKS[1];
|
||||||
|
|
||||||
|
// just in case we change it in the future
|
||||||
|
expect(color).not.toBe(COLOR_PALETTE.transparent);
|
||||||
|
|
||||||
|
h.setState({
|
||||||
|
currentItemBackgroundColor: color,
|
||||||
|
});
|
||||||
|
const activeColor = queryByTestId(
|
||||||
|
document.body,
|
||||||
|
`color-top-pick-${color}`,
|
||||||
|
);
|
||||||
|
expect(activeColor).toHaveClass("active");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show fill style when background non-transparent", () => {
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
|
||||||
|
const color = DEFAULT_ELEMENT_BACKGROUND_PICKS[1];
|
||||||
|
|
||||||
|
// just in case we change it in the future
|
||||||
|
expect(color).not.toBe(COLOR_PALETTE.transparent);
|
||||||
|
|
||||||
|
h.setState({
|
||||||
|
currentItemBackgroundColor: color,
|
||||||
|
currentItemFillStyle: "hachure",
|
||||||
|
});
|
||||||
|
const hachureFillButton = queryByTestId(document.body, `fill-hachure`);
|
||||||
|
|
||||||
|
expect(hachureFillButton).toHaveClass("active");
|
||||||
|
h.setState({
|
||||||
|
currentItemFillStyle: "solid",
|
||||||
|
});
|
||||||
|
const solidFillStyle = queryByTestId(document.body, `fill-solid`);
|
||||||
|
expect(solidFillStyle).toHaveClass("active");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not show fill style when background transparent", () => {
|
||||||
|
UI.clickTool("rectangle");
|
||||||
|
|
||||||
|
h.setState({
|
||||||
|
currentItemBackgroundColor: COLOR_PALETTE.transparent,
|
||||||
|
currentItemFillStyle: "hachure",
|
||||||
|
});
|
||||||
|
const hachureFillButton = queryByTestId(document.body, `fill-hachure`);
|
||||||
|
|
||||||
|
expect(hachureFillButton).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show horizontal text align for text tool", () => {
|
||||||
|
UI.clickTool("text");
|
||||||
|
|
||||||
|
h.setState({
|
||||||
|
currentItemTextAlign: "right",
|
||||||
|
});
|
||||||
|
|
||||||
|
const centerTextAlign = queryByTestId(document.body, `align-right`);
|
||||||
|
expect(centerTextAlign).toBeChecked();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("properties when elements selected", () => {
|
||||||
|
it("should show active styles when single element selected", () => {
|
||||||
|
const rect = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
backgroundColor: "red",
|
||||||
|
fillStyle: "cross-hatch",
|
||||||
|
});
|
||||||
|
h.elements = [rect];
|
||||||
|
API.setSelectedElements([rect]);
|
||||||
|
|
||||||
|
const crossHatchButton = queryByTestId(document.body, `fill-cross-hatch`);
|
||||||
|
expect(crossHatchButton).toHaveClass("active");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not show fill style selected element's background is transparent", () => {
|
||||||
|
const rect = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
backgroundColor: COLOR_PALETTE.transparent,
|
||||||
|
fillStyle: "cross-hatch",
|
||||||
|
});
|
||||||
|
h.elements = [rect];
|
||||||
|
API.setSelectedElements([rect]);
|
||||||
|
|
||||||
|
const crossHatchButton = queryByTestId(document.body, `fill-cross-hatch`);
|
||||||
|
expect(crossHatchButton).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should highlight common stroke width of selected elements", () => {
|
||||||
|
const rect1 = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
strokeWidth: STROKE_WIDTH.thin,
|
||||||
|
});
|
||||||
|
const rect2 = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
strokeWidth: STROKE_WIDTH.thin,
|
||||||
|
});
|
||||||
|
h.elements = [rect1, rect2];
|
||||||
|
API.setSelectedElements([rect1, rect2]);
|
||||||
|
|
||||||
|
const thinStrokeWidthButton = queryByTestId(
|
||||||
|
document.body,
|
||||||
|
`strokeWidth-thin`,
|
||||||
|
);
|
||||||
|
expect(thinStrokeWidthButton).toBeChecked();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not highlight any stroke width button if no common style", () => {
|
||||||
|
const rect1 = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
strokeWidth: STROKE_WIDTH.thin,
|
||||||
|
});
|
||||||
|
const rect2 = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
strokeWidth: STROKE_WIDTH.bold,
|
||||||
|
});
|
||||||
|
h.elements = [rect1, rect2];
|
||||||
|
API.setSelectedElements([rect1, rect2]);
|
||||||
|
|
||||||
|
expect(queryByTestId(document.body, `strokeWidth-thin`)).not.toBe(null);
|
||||||
|
expect(
|
||||||
|
queryByTestId(document.body, `strokeWidth-thin`),
|
||||||
|
).not.toBeChecked();
|
||||||
|
expect(
|
||||||
|
queryByTestId(document.body, `strokeWidth-bold`),
|
||||||
|
).not.toBeChecked();
|
||||||
|
expect(
|
||||||
|
queryByTestId(document.body, `strokeWidth-extraBold`),
|
||||||
|
).not.toBeChecked();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show properties of different element types when selected", () => {
|
||||||
|
const rect = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
strokeWidth: STROKE_WIDTH.bold,
|
||||||
|
});
|
||||||
|
const text = API.createElement({
|
||||||
|
type: "text",
|
||||||
|
fontFamily: FONT_FAMILY.Cascadia,
|
||||||
|
});
|
||||||
|
h.elements = [rect, text];
|
||||||
|
API.setSelectedElements([rect, text]);
|
||||||
|
|
||||||
|
expect(queryByTestId(document.body, `strokeWidth-bold`)).toBeChecked();
|
||||||
|
expect(queryByTestId(document.body, `font-family-code`)).toBeChecked();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AppState } from "../../src/types";
|
import { AppState, Primitive } from "../../src/types";
|
||||||
import {
|
import {
|
||||||
DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE,
|
DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE,
|
||||||
DEFAULT_ELEMENT_BACKGROUND_PICKS,
|
DEFAULT_ELEMENT_BACKGROUND_PICKS,
|
||||||
@@ -51,6 +51,7 @@ import {
|
|||||||
DEFAULT_FONT_SIZE,
|
DEFAULT_FONT_SIZE,
|
||||||
FONT_FAMILY,
|
FONT_FAMILY,
|
||||||
ROUNDNESS,
|
ROUNDNESS,
|
||||||
|
STROKE_WIDTH,
|
||||||
VERTICAL_ALIGN,
|
VERTICAL_ALIGN,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import {
|
import {
|
||||||
@@ -82,7 +83,6 @@ import { getLanguage, t } from "../i18n";
|
|||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { randomInteger } from "../random";
|
import { randomInteger } from "../random";
|
||||||
import {
|
import {
|
||||||
canChangeRoundness,
|
|
||||||
canHaveArrowheads,
|
canHaveArrowheads,
|
||||||
getCommonAttributeOfSelectedElements,
|
getCommonAttributeOfSelectedElements,
|
||||||
getSelectedElements,
|
getSelectedElements,
|
||||||
@@ -118,25 +118,44 @@ export const changeProperty = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFormValue = function <T>(
|
export const getFormValue = function <T extends Primitive>(
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
getAttribute: (element: ExcalidrawElement) => T,
|
getAttribute: (element: ExcalidrawElement) => T,
|
||||||
defaultValue: T,
|
isRelevantElement: true | ((element: ExcalidrawElement) => boolean),
|
||||||
|
defaultValue: T | ((isSomeElementSelected: boolean) => T),
|
||||||
): T {
|
): T {
|
||||||
const editingElement = appState.editingElement;
|
const editingElement = appState.editingElement;
|
||||||
const nonDeletedElements = getNonDeletedElements(elements);
|
const nonDeletedElements = getNonDeletedElements(elements);
|
||||||
return (
|
|
||||||
(editingElement && getAttribute(editingElement)) ??
|
let ret: T | null = null;
|
||||||
(isSomeElementSelected(nonDeletedElements, appState)
|
|
||||||
? getCommonAttributeOfSelectedElements(
|
if (editingElement) {
|
||||||
nonDeletedElements,
|
ret = getAttribute(editingElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
const hasSelection = isSomeElementSelected(nonDeletedElements, appState);
|
||||||
|
|
||||||
|
if (hasSelection) {
|
||||||
|
ret =
|
||||||
|
getCommonAttributeOfSelectedElements(
|
||||||
|
isRelevantElement === true
|
||||||
|
? nonDeletedElements
|
||||||
|
: nonDeletedElements.filter((el) => isRelevantElement(el)),
|
||||||
appState,
|
appState,
|
||||||
getAttribute,
|
getAttribute,
|
||||||
)
|
) ??
|
||||||
: defaultValue) ??
|
(typeof defaultValue === "function"
|
||||||
defaultValue
|
? defaultValue(true)
|
||||||
);
|
: defaultValue);
|
||||||
|
} else {
|
||||||
|
ret =
|
||||||
|
typeof defaultValue === "function" ? defaultValue(false) : defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
const offsetElementAfterFontResize = (
|
const offsetElementAfterFontResize = (
|
||||||
@@ -247,6 +266,7 @@ export const actionChangeStrokeColor = register({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => element.strokeColor,
|
(element) => element.strokeColor,
|
||||||
|
true,
|
||||||
appState.currentItemStrokeColor,
|
appState.currentItemStrokeColor,
|
||||||
)}
|
)}
|
||||||
onChange={(color) => updateData({ currentItemStrokeColor: color })}
|
onChange={(color) => updateData({ currentItemStrokeColor: color })}
|
||||||
@@ -289,6 +309,7 @@ export const actionChangeBackgroundColor = register({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => element.backgroundColor,
|
(element) => element.backgroundColor,
|
||||||
|
true,
|
||||||
appState.currentItemBackgroundColor,
|
appState.currentItemBackgroundColor,
|
||||||
)}
|
)}
|
||||||
onChange={(color) => updateData({ currentItemBackgroundColor: color })}
|
onChange={(color) => updateData({ currentItemBackgroundColor: color })}
|
||||||
@@ -307,7 +328,7 @@ export const actionChangeFillStyle = register({
|
|||||||
trackEvent(
|
trackEvent(
|
||||||
"element",
|
"element",
|
||||||
"changeFillStyle",
|
"changeFillStyle",
|
||||||
`${value} (${app.device.isMobile ? "mobile" : "desktop"})`,
|
`${value} (${app.device.editor.isMobile ? "mobile" : "desktop"})`,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) =>
|
elements: changeProperty(elements, appState, (el) =>
|
||||||
@@ -338,23 +359,28 @@ export const actionChangeFillStyle = register({
|
|||||||
} (${getShortcutKey("Alt-Click")})`,
|
} (${getShortcutKey("Alt-Click")})`,
|
||||||
icon: allElementsZigZag ? FillZigZagIcon : FillHachureIcon,
|
icon: allElementsZigZag ? FillZigZagIcon : FillHachureIcon,
|
||||||
active: allElementsZigZag ? true : undefined,
|
active: allElementsZigZag ? true : undefined,
|
||||||
|
testId: `fill-hachure`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "cross-hatch",
|
value: "cross-hatch",
|
||||||
text: t("labels.crossHatch"),
|
text: t("labels.crossHatch"),
|
||||||
icon: FillCrossHatchIcon,
|
icon: FillCrossHatchIcon,
|
||||||
|
testId: `fill-cross-hatch`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "solid",
|
value: "solid",
|
||||||
text: t("labels.solid"),
|
text: t("labels.solid"),
|
||||||
icon: FillSolidIcon,
|
icon: FillSolidIcon,
|
||||||
|
testId: `fill-solid`,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => element.fillStyle,
|
(element) => element.fillStyle,
|
||||||
appState.currentItemFillStyle,
|
(element) => element.hasOwnProperty("fillStyle"),
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemFillStyle,
|
||||||
)}
|
)}
|
||||||
onClick={(value, event) => {
|
onClick={(value, event) => {
|
||||||
const nextValue =
|
const nextValue =
|
||||||
@@ -393,26 +419,31 @@ export const actionChangeStrokeWidth = register({
|
|||||||
group="stroke-width"
|
group="stroke-width"
|
||||||
options={[
|
options={[
|
||||||
{
|
{
|
||||||
value: 1,
|
value: STROKE_WIDTH.thin,
|
||||||
text: t("labels.thin"),
|
text: t("labels.thin"),
|
||||||
icon: StrokeWidthBaseIcon,
|
icon: StrokeWidthBaseIcon,
|
||||||
|
testId: "strokeWidth-thin",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 2,
|
value: STROKE_WIDTH.bold,
|
||||||
text: t("labels.bold"),
|
text: t("labels.bold"),
|
||||||
icon: StrokeWidthBoldIcon,
|
icon: StrokeWidthBoldIcon,
|
||||||
|
testId: "strokeWidth-bold",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 4,
|
value: STROKE_WIDTH.extraBold,
|
||||||
text: t("labels.extraBold"),
|
text: t("labels.extraBold"),
|
||||||
icon: StrokeWidthExtraBoldIcon,
|
icon: StrokeWidthExtraBoldIcon,
|
||||||
|
testId: "strokeWidth-extraBold",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={getFormValue(
|
value={getFormValue(
|
||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => element.strokeWidth,
|
(element) => element.strokeWidth,
|
||||||
appState.currentItemStrokeWidth,
|
(element) => element.hasOwnProperty("strokeWidth"),
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemStrokeWidth,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -461,7 +492,9 @@ export const actionChangeSloppiness = register({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => element.roughness,
|
(element) => element.roughness,
|
||||||
appState.currentItemRoughness,
|
(element) => element.hasOwnProperty("roughness"),
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemRoughness,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -509,7 +542,9 @@ export const actionChangeStrokeStyle = register({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => element.strokeStyle,
|
(element) => element.strokeStyle,
|
||||||
appState.currentItemStrokeStyle,
|
(element) => element.hasOwnProperty("strokeStyle"),
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemStrokeStyle,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -549,6 +584,7 @@ export const actionChangeOpacity = register({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
(element) => element.opacity,
|
(element) => element.opacity,
|
||||||
|
true,
|
||||||
appState.currentItemOpacity,
|
appState.currentItemOpacity,
|
||||||
) ?? undefined
|
) ?? undefined
|
||||||
}
|
}
|
||||||
@@ -607,7 +643,12 @@ export const actionChangeFontSize = register({
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
appState.currentItemFontSize || DEFAULT_FONT_SIZE,
|
(element) =>
|
||||||
|
isTextElement(element) || getBoundTextElement(element) !== null,
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection
|
||||||
|
? null
|
||||||
|
: appState.currentItemFontSize || DEFAULT_FONT_SIZE,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -692,21 +733,25 @@ export const actionChangeFontFamily = register({
|
|||||||
value: FontFamilyValues;
|
value: FontFamilyValues;
|
||||||
text: string;
|
text: string;
|
||||||
icon: JSX.Element;
|
icon: JSX.Element;
|
||||||
|
testId: string;
|
||||||
}[] = [
|
}[] = [
|
||||||
{
|
{
|
||||||
value: FONT_FAMILY.Virgil,
|
value: FONT_FAMILY.Virgil,
|
||||||
text: t("labels.handDrawn"),
|
text: t("labels.handDrawn"),
|
||||||
icon: FreedrawIcon,
|
icon: FreedrawIcon,
|
||||||
|
testId: "font-family-virgil",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: FONT_FAMILY.Helvetica,
|
value: FONT_FAMILY.Helvetica,
|
||||||
text: t("labels.normal"),
|
text: t("labels.normal"),
|
||||||
icon: FontFamilyNormalIcon,
|
icon: FontFamilyNormalIcon,
|
||||||
|
testId: "font-family-normal",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: FONT_FAMILY.Cascadia,
|
value: FONT_FAMILY.Cascadia,
|
||||||
text: t("labels.code"),
|
text: t("labels.code"),
|
||||||
icon: FontFamilyCodeIcon,
|
icon: FontFamilyCodeIcon,
|
||||||
|
testId: "font-family-code",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -729,7 +774,12 @@ export const actionChangeFontFamily = register({
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
appState.currentItemFontFamily || DEFAULT_FONT_FAMILY,
|
(element) =>
|
||||||
|
isTextElement(element) || getBoundTextElement(element) !== null,
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection
|
||||||
|
? null
|
||||||
|
: appState.currentItemFontFamily || DEFAULT_FONT_FAMILY,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -806,7 +856,10 @@ export const actionChangeTextAlign = register({
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
appState.currentItemTextAlign,
|
(element) =>
|
||||||
|
isTextElement(element) || getBoundTextElement(element) !== null,
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemTextAlign,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -882,7 +935,9 @@ export const actionChangeVerticalAlign = register({
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
VERTICAL_ALIGN.MIDDLE,
|
(element) =>
|
||||||
|
isTextElement(element) || getBoundTextElement(element) !== null,
|
||||||
|
(hasSelection) => (hasSelection ? null : VERTICAL_ALIGN.MIDDLE),
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -947,9 +1002,9 @@ export const actionChangeRoundness = register({
|
|||||||
appState,
|
appState,
|
||||||
(element) =>
|
(element) =>
|
||||||
hasLegacyRoundness ? null : element.roundness ? "round" : "sharp",
|
hasLegacyRoundness ? null : element.roundness ? "round" : "sharp",
|
||||||
(canChangeRoundness(appState.activeTool.type) &&
|
(element) => element.hasOwnProperty("roundness"),
|
||||||
appState.currentItemRoundness) ||
|
(hasSelection) =>
|
||||||
null,
|
hasSelection ? null : appState.currentItemRoundness,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => updateData(value)}
|
||||||
/>
|
/>
|
||||||
@@ -1043,6 +1098,7 @@ export const actionChangeArrowhead = register({
|
|||||||
isLinearElement(element) && canHaveArrowheads(element.type)
|
isLinearElement(element) && canHaveArrowheads(element.type)
|
||||||
? element.startArrowhead
|
? element.startArrowhead
|
||||||
: appState.currentItemStartArrowhead,
|
: appState.currentItemStartArrowhead,
|
||||||
|
true,
|
||||||
appState.currentItemStartArrowhead,
|
appState.currentItemStartArrowhead,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData({ position: "start", type: value })}
|
onChange={(value) => updateData({ position: "start", type: value })}
|
||||||
@@ -1089,6 +1145,7 @@ export const actionChangeArrowhead = register({
|
|||||||
isLinearElement(element) && canHaveArrowheads(element.type)
|
isLinearElement(element) && canHaveArrowheads(element.type)
|
||||||
? element.endArrowhead
|
? element.endArrowhead
|
||||||
: appState.currentItemEndArrowhead,
|
: appState.currentItemEndArrowhead,
|
||||||
|
true,
|
||||||
appState.currentItemEndArrowhead,
|
appState.currentItemEndArrowhead,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData({ position: "end", type: value })}
|
onChange={(value) => updateData({ position: "end", type: value })}
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ import {
|
|||||||
canApplyRoundnessTypeToElement,
|
canApplyRoundnessTypeToElement,
|
||||||
getDefaultRoundnessTypeForElement,
|
getDefaultRoundnessTypeForElement,
|
||||||
isFrameElement,
|
isFrameElement,
|
||||||
|
isArrowElement,
|
||||||
} from "../element/typeChecks";
|
} from "../element/typeChecks";
|
||||||
import { getSelectedElements } from "../scene";
|
import { getSelectedElements } from "../scene";
|
||||||
|
import { ExcalidrawTextElement } from "../element/types";
|
||||||
|
|
||||||
// `copiedStyles` is exported only for tests.
|
// `copiedStyles` is exported only for tests.
|
||||||
export let copiedStyles: string = "{}";
|
export let copiedStyles: string = "{}";
|
||||||
@@ -99,16 +101,19 @@ export const actionPasteStyles = register({
|
|||||||
|
|
||||||
if (isTextElement(newElement)) {
|
if (isTextElement(newElement)) {
|
||||||
const fontSize =
|
const fontSize =
|
||||||
elementStylesToCopyFrom?.fontSize || DEFAULT_FONT_SIZE;
|
(elementStylesToCopyFrom as ExcalidrawTextElement).fontSize ||
|
||||||
|
DEFAULT_FONT_SIZE;
|
||||||
const fontFamily =
|
const fontFamily =
|
||||||
elementStylesToCopyFrom?.fontFamily || DEFAULT_FONT_FAMILY;
|
(elementStylesToCopyFrom as ExcalidrawTextElement).fontFamily ||
|
||||||
|
DEFAULT_FONT_FAMILY;
|
||||||
newElement = newElementWith(newElement, {
|
newElement = newElementWith(newElement, {
|
||||||
fontSize,
|
fontSize,
|
||||||
fontFamily,
|
fontFamily,
|
||||||
textAlign:
|
textAlign:
|
||||||
elementStylesToCopyFrom?.textAlign || DEFAULT_TEXT_ALIGN,
|
(elementStylesToCopyFrom as ExcalidrawTextElement).textAlign ||
|
||||||
|
DEFAULT_TEXT_ALIGN,
|
||||||
lineHeight:
|
lineHeight:
|
||||||
elementStylesToCopyFrom.lineHeight ||
|
(elementStylesToCopyFrom as ExcalidrawTextElement).lineHeight ||
|
||||||
getDefaultLineHeight(fontFamily),
|
getDefaultLineHeight(fontFamily),
|
||||||
});
|
});
|
||||||
let container = null;
|
let container = null;
|
||||||
@@ -123,7 +128,10 @@ export const actionPasteStyles = register({
|
|||||||
redrawTextBoundingBox(newElement, container);
|
redrawTextBoundingBox(newElement, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newElement.type === "arrow") {
|
if (
|
||||||
|
newElement.type === "arrow" &&
|
||||||
|
isArrowElement(elementStylesToCopyFrom)
|
||||||
|
) {
|
||||||
newElement = newElementWith(newElement, {
|
newElement = newElementWith(newElement, {
|
||||||
startArrowhead: elementStylesToCopyFrom.startArrowhead,
|
startArrowhead: elementStylesToCopyFrom.startArrowhead,
|
||||||
endArrowhead: elementStylesToCopyFrom.endArrowhead,
|
endArrowhead: elementStylesToCopyFrom.endArrowhead,
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ export { actionCopyStyles, actionPasteStyles } from "./actionStyles";
|
|||||||
export {
|
export {
|
||||||
actionToggleCanvasMenu,
|
actionToggleCanvasMenu,
|
||||||
actionToggleEditMenu,
|
actionToggleEditMenu,
|
||||||
actionFullScreen,
|
|
||||||
actionShortcuts,
|
actionShortcuts,
|
||||||
} from "./actionMenu";
|
} from "./actionMenu";
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,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.device.editor.isMobile ? "mobile" : "desktop"})`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,10 +119,10 @@ export class ActionManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
executeAction(
|
executeAction<T extends Action>(
|
||||||
action: Action,
|
action: T,
|
||||||
source: ActionSource = "api",
|
source: ActionSource = "api",
|
||||||
value: any = null,
|
value: Parameters<T["perform"]>[2] = null,
|
||||||
) {
|
) {
|
||||||
const elements = this.getElementsIncludingDeleted();
|
const elements = this.getElementsIncludingDeleted();
|
||||||
const appState = this.getAppState();
|
const appState = this.getAppState();
|
||||||
|
|||||||
+186
-17
@@ -1,27 +1,196 @@
|
|||||||
import { parseClipboard } from "./clipboard";
|
import {
|
||||||
|
createPasteEvent,
|
||||||
|
parseClipboard,
|
||||||
|
serializeAsClipboardJSON,
|
||||||
|
} from "./clipboard";
|
||||||
|
import { API } from "./tests/helpers/api";
|
||||||
|
|
||||||
describe("Test parseClipboard", () => {
|
describe("parseClipboard()", () => {
|
||||||
it("should parse valid json correctly", async () => {
|
it("should parse JSON as plaintext if not excalidraw-api/clipboard data", async () => {
|
||||||
let text = "123";
|
let text;
|
||||||
|
let clipboardData;
|
||||||
let clipboardData = await parseClipboard({
|
// -------------------------------------------------------------------------
|
||||||
//@ts-ignore
|
|
||||||
clipboardData: {
|
|
||||||
getData: () => text,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
text = "123";
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({ types: { "text/plain": text } }),
|
||||||
|
);
|
||||||
expect(clipboardData.text).toBe(text);
|
expect(clipboardData.text).toBe(text);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
text = "[123]";
|
text = "[123]";
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({ types: { "text/plain": text } }),
|
||||||
|
);
|
||||||
|
expect(clipboardData.text).toBe(text);
|
||||||
|
|
||||||
clipboardData = await parseClipboard({
|
// -------------------------------------------------------------------------
|
||||||
//@ts-ignore
|
|
||||||
clipboardData: {
|
|
||||||
getData: () => text,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
text = JSON.stringify({ val: 42 });
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({ types: { "text/plain": text } }),
|
||||||
|
);
|
||||||
expect(clipboardData.text).toBe(text);
|
expect(clipboardData.text).toBe(text);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should parse valid excalidraw JSON if inside text/plain", async () => {
|
||||||
|
const rect = API.createElement({ type: "rectangle" });
|
||||||
|
|
||||||
|
const json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||||
|
const clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/plain": json,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.elements).toEqual([rect]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse valid excalidraw JSON if inside text/html", async () => {
|
||||||
|
const rect = API.createElement({ type: "rectangle" });
|
||||||
|
|
||||||
|
let json;
|
||||||
|
let clipboardData;
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/html": json,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.elements).toEqual([rect]);
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/html": `<div> ${json}</div>`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.elements).toEqual([rect]);
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse <image> `src` urls out of text/html", async () => {
|
||||||
|
let clipboardData;
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/html": `<img src="https://example.com/image.png" />`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.mixedContent).toEqual([
|
||||||
|
{
|
||||||
|
type: "imageUrl",
|
||||||
|
value: "https://example.com/image.png",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/html": `<div><img src="https://example.com/image.png" /></div><a><img src="https://example.com/image2.png" /></a>`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.mixedContent).toEqual([
|
||||||
|
{
|
||||||
|
type: "imageUrl",
|
||||||
|
value: "https://example.com/image.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "imageUrl",
|
||||||
|
value: "https://example.com/image2.png",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse text content alongside <image> `src` urls out of text/html", async () => {
|
||||||
|
const clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/html": `<a href="https://example.com">hello </a><div><img src="https://example.com/image.png" /></div><b>my friend!</b>`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.mixedContent).toEqual([
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
// trimmed
|
||||||
|
value: "hello",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "imageUrl",
|
||||||
|
value: "https://example.com/image.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
value: "my friend!",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should parse spreadsheet from either text/plain and text/html", async () => {
|
||||||
|
let clipboardData;
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/plain": `a b
|
||||||
|
1 2
|
||||||
|
4 5
|
||||||
|
7 10`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.spreadsheet).toEqual({
|
||||||
|
title: "b",
|
||||||
|
labels: ["1", "4", "7"],
|
||||||
|
values: [2, 5, 10],
|
||||||
|
});
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/html": `a b
|
||||||
|
1 2
|
||||||
|
4 5
|
||||||
|
7 10`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.spreadsheet).toEqual({
|
||||||
|
title: "b",
|
||||||
|
labels: ["1", "4", "7"],
|
||||||
|
values: [2, 5, 10],
|
||||||
|
});
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
clipboardData = await parseClipboard(
|
||||||
|
createPasteEvent({
|
||||||
|
types: {
|
||||||
|
"text/html": `<html>
|
||||||
|
<body>
|
||||||
|
<!--StartFragment--><google-sheets-html-origin><style type="text/css"><!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="100"/><col width="100"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"a"}">a</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"b"}">b</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":1}">1</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":2}">2</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":4}">4</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":5}">5</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":7}">7</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":10}">10</td></tr></tbody></table><!--EndFragment-->
|
||||||
|
</body>
|
||||||
|
</html>`,
|
||||||
|
"text/plain": `a b
|
||||||
|
1 2
|
||||||
|
4 5
|
||||||
|
7 10`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(clipboardData.spreadsheet).toEqual({
|
||||||
|
title: "b",
|
||||||
|
labels: ["1", "4", "7"],
|
||||||
|
values: [2, 5, 10],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+263
-91
@@ -3,14 +3,18 @@ import {
|
|||||||
NonDeletedExcalidrawElement,
|
NonDeletedExcalidrawElement,
|
||||||
} from "./element/types";
|
} from "./element/types";
|
||||||
import { BinaryFiles } from "./types";
|
import { BinaryFiles } from "./types";
|
||||||
import { SVG_EXPORT_TAG } from "./scene/export";
|
|
||||||
import { tryParseSpreadsheet, Spreadsheet, VALID_SPREADSHEET } from "./charts";
|
import { tryParseSpreadsheet, Spreadsheet, VALID_SPREADSHEET } from "./charts";
|
||||||
import { EXPORT_DATA_TYPES, MIME_TYPES } from "./constants";
|
import {
|
||||||
|
ALLOWED_PASTE_MIME_TYPES,
|
||||||
|
EXPORT_DATA_TYPES,
|
||||||
|
MIME_TYPES,
|
||||||
|
} from "./constants";
|
||||||
import { isInitializedImageElement } from "./element/typeChecks";
|
import { isInitializedImageElement } from "./element/typeChecks";
|
||||||
import { deepCopyElement } from "./element/newElement";
|
import { deepCopyElement } from "./element/newElement";
|
||||||
import { mutateElement } from "./element/mutateElement";
|
import { mutateElement } from "./element/mutateElement";
|
||||||
import { getContainingFrame } from "./frame";
|
import { getContainingFrame } from "./frame";
|
||||||
import { isPromiseLike, isTestEnv } from "./utils";
|
import { isMemberOf, isPromiseLike } from "./utils";
|
||||||
|
import { t } from "./i18n";
|
||||||
|
|
||||||
type ElementsClipboard = {
|
type ElementsClipboard = {
|
||||||
type: typeof EXPORT_DATA_TYPES.excalidrawClipboard;
|
type: typeof EXPORT_DATA_TYPES.excalidrawClipboard;
|
||||||
@@ -18,17 +22,23 @@ type ElementsClipboard = {
|
|||||||
files: BinaryFiles | undefined;
|
files: BinaryFiles | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type PastedMixedContent = { type: "text" | "imageUrl"; value: string }[];
|
||||||
|
|
||||||
export interface ClipboardData {
|
export interface ClipboardData {
|
||||||
spreadsheet?: Spreadsheet;
|
spreadsheet?: Spreadsheet;
|
||||||
elements?: readonly ExcalidrawElement[];
|
elements?: readonly ExcalidrawElement[];
|
||||||
files?: BinaryFiles;
|
files?: BinaryFiles;
|
||||||
text?: string;
|
text?: string;
|
||||||
|
mixedContent?: PastedMixedContent;
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
programmaticAPI?: boolean;
|
programmaticAPI?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let CLIPBOARD = "";
|
type AllowedPasteMimeTypes = typeof ALLOWED_PASTE_MIME_TYPES[number];
|
||||||
let PREFER_APP_CLIPBOARD = false;
|
|
||||||
|
type ParsedClipboardEvent =
|
||||||
|
| { type: "text"; value: string }
|
||||||
|
| { type: "mixedContent"; value: PastedMixedContent };
|
||||||
|
|
||||||
export const probablySupportsClipboardReadText =
|
export const probablySupportsClipboardReadText =
|
||||||
"clipboard" in navigator && "readText" in navigator.clipboard;
|
"clipboard" in navigator && "readText" in navigator.clipboard;
|
||||||
@@ -58,10 +68,61 @@ const clipboardContainsElements = (
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyToClipboard = async (
|
export const createPasteEvent = ({
|
||||||
elements: readonly NonDeletedExcalidrawElement[],
|
types,
|
||||||
files: BinaryFiles | null,
|
files,
|
||||||
) => {
|
}: {
|
||||||
|
types?: { [key in AllowedPasteMimeTypes]?: string };
|
||||||
|
files?: File[];
|
||||||
|
}) => {
|
||||||
|
if (!types && !files) {
|
||||||
|
console.warn("createPasteEvent: no types or files provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
const event = new ClipboardEvent("paste", {
|
||||||
|
clipboardData: new DataTransfer(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (types) {
|
||||||
|
for (const [type, value] of Object.entries(types)) {
|
||||||
|
try {
|
||||||
|
event.clipboardData?.setData(type, value);
|
||||||
|
if (event.clipboardData?.getData(type) !== value) {
|
||||||
|
throw new Error(`Failed to set "${type}" as clipboardData item`);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files) {
|
||||||
|
let idx = -1;
|
||||||
|
for (const file of files) {
|
||||||
|
idx++;
|
||||||
|
try {
|
||||||
|
event.clipboardData?.items.add(file);
|
||||||
|
if (event.clipboardData?.files[idx] !== file) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to set file "${file.name}" as clipboardData item`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return event;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const serializeAsClipboardJSON = ({
|
||||||
|
elements,
|
||||||
|
files,
|
||||||
|
}: {
|
||||||
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
|
files: BinaryFiles | null;
|
||||||
|
}) => {
|
||||||
const framesToCopy = new Set(
|
const framesToCopy = new Set(
|
||||||
elements.filter((element) => element.type === "frame"),
|
elements.filter((element) => element.type === "frame"),
|
||||||
);
|
);
|
||||||
@@ -83,7 +144,7 @@ export const copyToClipboard = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// select binded text elements when copying
|
// select bound text elements when copying
|
||||||
const contents: ElementsClipboard = {
|
const contents: ElementsClipboard = {
|
||||||
type: EXPORT_DATA_TYPES.excalidrawClipboard,
|
type: EXPORT_DATA_TYPES.excalidrawClipboard,
|
||||||
elements: elements.map((element) => {
|
elements: elements.map((element) => {
|
||||||
@@ -102,34 +163,20 @@ export const copyToClipboard = async (
|
|||||||
}),
|
}),
|
||||||
files: files ? _files : undefined,
|
files: files ? _files : undefined,
|
||||||
};
|
};
|
||||||
const json = JSON.stringify(contents);
|
|
||||||
|
|
||||||
if (isTestEnv()) {
|
return JSON.stringify(contents);
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
CLIPBOARD = json;
|
|
||||||
|
|
||||||
try {
|
|
||||||
PREFER_APP_CLIPBOARD = false;
|
|
||||||
await copyTextToSystemClipboard(json);
|
|
||||||
} catch (error: any) {
|
|
||||||
PREFER_APP_CLIPBOARD = true;
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAppClipboard = (): Partial<ElementsClipboard> => {
|
export const copyToClipboard = async (
|
||||||
if (!CLIPBOARD) {
|
elements: readonly NonDeletedExcalidrawElement[],
|
||||||
return {};
|
files: BinaryFiles | null,
|
||||||
}
|
/** supply if available to make the operation more certain to succeed */
|
||||||
|
clipboardEvent?: ClipboardEvent | null,
|
||||||
try {
|
) => {
|
||||||
return JSON.parse(CLIPBOARD);
|
await copyTextToSystemClipboard(
|
||||||
} catch (error: any) {
|
serializeAsClipboardJSON({ elements, files }),
|
||||||
console.error(error);
|
clipboardEvent,
|
||||||
return {};
|
);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const parsePotentialSpreadsheet = (
|
const parsePotentialSpreadsheet = (
|
||||||
@@ -142,22 +189,137 @@ const parsePotentialSpreadsheet = (
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/** internal, specific to parsing paste events. Do not reuse. */
|
||||||
* Retrieves content from system clipboard (either from ClipboardEvent or
|
function parseHTMLTree(el: ChildNode) {
|
||||||
* via async clipboard API if supported)
|
let result: PastedMixedContent = [];
|
||||||
*/
|
for (const node of el.childNodes) {
|
||||||
export const getSystemClipboard = async (
|
if (node.nodeType === 3) {
|
||||||
event: ClipboardEvent | null,
|
const text = node.textContent?.trim();
|
||||||
): Promise<string> => {
|
if (text) {
|
||||||
try {
|
result.push({ type: "text", value: text });
|
||||||
const text = event
|
}
|
||||||
? event.clipboardData?.getData("text/plain")
|
} else if (node instanceof HTMLImageElement) {
|
||||||
: probablySupportsClipboardReadText &&
|
const url = node.getAttribute("src");
|
||||||
(await navigator.clipboard.readText());
|
if (url && url.startsWith("http")) {
|
||||||
|
result.push({ type: "imageUrl", value: url });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = result.concat(parseHTMLTree(node));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return (text || "").trim();
|
const maybeParseHTMLPaste = (
|
||||||
|
event: ClipboardEvent,
|
||||||
|
): { type: "mixedContent"; value: PastedMixedContent } | null => {
|
||||||
|
const html = event.clipboardData?.getData("text/html");
|
||||||
|
|
||||||
|
if (!html) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const doc = new DOMParser().parseFromString(html, "text/html");
|
||||||
|
|
||||||
|
const content = parseHTMLTree(doc.body);
|
||||||
|
|
||||||
|
if (content.length) {
|
||||||
|
return { type: "mixedContent", value: content };
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(`error in parseHTMLFromPaste: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const readSystemClipboard = async () => {
|
||||||
|
const types: { [key in AllowedPasteMimeTypes]?: string } = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (navigator.clipboard?.readText) {
|
||||||
|
return { "text/plain": await navigator.clipboard?.readText() };
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
// @ts-ignore
|
||||||
|
if (navigator.clipboard?.read) {
|
||||||
|
console.warn(
|
||||||
|
`navigator.clipboard.readText() failed (${error.message}). Failling back to navigator.clipboard.read()`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let clipboardItems: ClipboardItems;
|
||||||
|
|
||||||
|
try {
|
||||||
|
clipboardItems = await navigator.clipboard?.read();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.name === "DataError") {
|
||||||
|
console.warn(
|
||||||
|
`navigator.clipboard.read() error, clipboard is probably empty: ${error.message}`,
|
||||||
|
);
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const item of clipboardItems) {
|
||||||
|
for (const type of item.types) {
|
||||||
|
if (!isMemberOf(ALLOWED_PASTE_MIME_TYPES, type)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
types[type] = await (await item.getType(type)).text();
|
||||||
|
} catch (error: any) {
|
||||||
|
console.warn(
|
||||||
|
`Cannot retrieve ${type} from clipboardItem: ${error.message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(types).length === 0) {
|
||||||
|
console.warn("No clipboard data found from clipboard.read().");
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
return types;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses "paste" ClipboardEvent.
|
||||||
|
*/
|
||||||
|
const parseClipboardEvent = async (
|
||||||
|
event: ClipboardEvent,
|
||||||
|
isPlainPaste = false,
|
||||||
|
): Promise<ParsedClipboardEvent> => {
|
||||||
|
try {
|
||||||
|
const mixedContent = !isPlainPaste && event && maybeParseHTMLPaste(event);
|
||||||
|
|
||||||
|
if (mixedContent) {
|
||||||
|
if (mixedContent.value.every((item) => item.type === "text")) {
|
||||||
|
return {
|
||||||
|
type: "text",
|
||||||
|
value:
|
||||||
|
event.clipboardData?.getData("text/plain") ||
|
||||||
|
mixedContent.value
|
||||||
|
.map((item) => item.value)
|
||||||
|
.join("\n")
|
||||||
|
.trim(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return mixedContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = event.clipboardData?.getData("text/plain");
|
||||||
|
|
||||||
|
return { type: "text", value: (text || "").trim() };
|
||||||
} catch {
|
} catch {
|
||||||
return "";
|
return { type: "text", value: "" };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -165,34 +327,32 @@ export const getSystemClipboard = async (
|
|||||||
* Attempts to parse clipboard. Prefers system clipboard.
|
* Attempts to parse clipboard. Prefers system clipboard.
|
||||||
*/
|
*/
|
||||||
export const parseClipboard = async (
|
export const parseClipboard = async (
|
||||||
event: ClipboardEvent | null,
|
event: ClipboardEvent,
|
||||||
isPlainPaste = false,
|
isPlainPaste = false,
|
||||||
): Promise<ClipboardData> => {
|
): Promise<ClipboardData> => {
|
||||||
const systemClipboard = await getSystemClipboard(event);
|
const parsedEventData = await parseClipboardEvent(event, isPlainPaste);
|
||||||
|
|
||||||
// if system clipboard empty, couldn't be resolved, or contains previously
|
if (parsedEventData.type === "mixedContent") {
|
||||||
// copied excalidraw scene as SVG, fall back to previously copied excalidraw
|
return {
|
||||||
// elements
|
mixedContent: parsedEventData.value,
|
||||||
if (
|
};
|
||||||
!systemClipboard ||
|
|
||||||
(!isPlainPaste && systemClipboard.includes(SVG_EXPORT_TAG))
|
|
||||||
) {
|
|
||||||
return getAppClipboard();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if system clipboard contains spreadsheet, use it even though it's
|
|
||||||
// technically possible it's staler than in-app clipboard
|
|
||||||
const spreadsheetResult =
|
|
||||||
!isPlainPaste && parsePotentialSpreadsheet(systemClipboard);
|
|
||||||
|
|
||||||
if (spreadsheetResult) {
|
|
||||||
return spreadsheetResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
const appClipboardData = getAppClipboard();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const systemClipboardData = JSON.parse(systemClipboard);
|
// if system clipboard contains spreadsheet, use it even though it's
|
||||||
|
// technically possible it's staler than in-app clipboard
|
||||||
|
const spreadsheetResult =
|
||||||
|
!isPlainPaste && parsePotentialSpreadsheet(parsedEventData.value);
|
||||||
|
|
||||||
|
if (spreadsheetResult) {
|
||||||
|
return spreadsheetResult;
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const systemClipboardData = JSON.parse(parsedEventData.value);
|
||||||
const programmaticAPI =
|
const programmaticAPI =
|
||||||
systemClipboardData.type === EXPORT_DATA_TYPES.excalidrawClipboardWithAPI;
|
systemClipboardData.type === EXPORT_DATA_TYPES.excalidrawClipboardWithAPI;
|
||||||
if (clipboardContainsElements(systemClipboardData)) {
|
if (clipboardContainsElements(systemClipboardData)) {
|
||||||
@@ -205,18 +365,9 @@ export const parseClipboard = async (
|
|||||||
programmaticAPI,
|
programmaticAPI,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch {}
|
||||||
// system clipboard doesn't contain excalidraw elements → return plaintext
|
|
||||||
// unless we set a flag to prefer in-app clipboard because browser didn't
|
return { text: parsedEventData.value };
|
||||||
// support storing to system clipboard on copy
|
|
||||||
return PREFER_APP_CLIPBOARD && appClipboardData.elements
|
|
||||||
? {
|
|
||||||
...appClipboardData,
|
|
||||||
text: isPlainPaste
|
|
||||||
? JSON.stringify(appClipboardData.elements, null, 2)
|
|
||||||
: undefined,
|
|
||||||
}
|
|
||||||
: { text: systemClipboard };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
||||||
@@ -249,28 +400,49 @@ export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyTextToSystemClipboard = async (text: string | null) => {
|
export const copyTextToSystemClipboard = async (
|
||||||
let copied = false;
|
text: string | null,
|
||||||
|
clipboardEvent?: ClipboardEvent | null,
|
||||||
|
) => {
|
||||||
|
// (1) first try using Async Clipboard API
|
||||||
if (probablySupportsClipboardWriteText) {
|
if (probablySupportsClipboardWriteText) {
|
||||||
try {
|
try {
|
||||||
// NOTE: doesn't work on FF on non-HTTPS domains, or when document
|
// NOTE: doesn't work on FF on non-HTTPS domains, or when document
|
||||||
// not focused
|
// not focused
|
||||||
await navigator.clipboard.writeText(text || "");
|
await navigator.clipboard.writeText(text || "");
|
||||||
copied = true;
|
return;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that execCommand doesn't allow copying empty strings, so if we're
|
// (2) if fails and we have access to ClipboardEvent, use plain old setData()
|
||||||
// clearing clipboard using this API, we must copy at least an empty char
|
try {
|
||||||
if (!copied && !copyTextViaExecCommand(text || " ")) {
|
if (clipboardEvent) {
|
||||||
throw new Error("couldn't copy");
|
clipboardEvent.clipboardData?.setData("text/plain", text || "");
|
||||||
|
if (clipboardEvent.clipboardData?.getData("text/plain") !== text) {
|
||||||
|
throw new Error("Failed to setData on clipboardEvent");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (3) if that fails, use document.execCommand
|
||||||
|
if (!copyTextViaExecCommand(text)) {
|
||||||
|
throw new Error(t("errors.copyToSystemClipboardFailed"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// adapted from https://github.com/zenorocha/clipboard.js/blob/ce79f170aa655c408b6aab33c9472e8e4fa52e19/src/clipboard-action.js#L48
|
// adapted from https://github.com/zenorocha/clipboard.js/blob/ce79f170aa655c408b6aab33c9472e8e4fa52e19/src/clipboard-action.js#L48
|
||||||
const copyTextViaExecCommand = (text: string) => {
|
const copyTextViaExecCommand = (text: string | null) => {
|
||||||
|
// execCommand doesn't allow copying empty strings, so if we're
|
||||||
|
// clearing clipboard using this API, we must copy at least an empty char
|
||||||
|
if (!text) {
|
||||||
|
text = " ";
|
||||||
|
}
|
||||||
|
|
||||||
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
||||||
|
|
||||||
const textarea = document.createElement("textarea");
|
const textarea = document.createElement("textarea");
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
.undo-redo-buttons {
|
.undo-redo-buttons {
|
||||||
background-color: var(--island-bg-color);
|
background-color: var(--island-bg-color);
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
|
box-shadow: 0 0 0 1px var(--color-surface-lowest);
|
||||||
}
|
}
|
||||||
|
|
||||||
.zoom-button,
|
.zoom-button,
|
||||||
.undo-redo-buttons button {
|
.undo-redo-buttons button {
|
||||||
border: 1px solid var(--default-border-color) !important;
|
|
||||||
border-radius: 0 !important;
|
border-radius: 0 !important;
|
||||||
background-color: transparent !important;
|
background-color: var(--color-surface-low) !important;
|
||||||
font-size: 0.875rem !important;
|
font-size: 0.875rem !important;
|
||||||
width: var(--lg-button-size);
|
width: var(--lg-button-size);
|
||||||
height: var(--lg-button-size);
|
height: var(--lg-button-size);
|
||||||
|
|||||||
+81
-118
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { getNonDeletedElements } from "../element";
|
import { getNonDeletedElements } from "../element";
|
||||||
import { ExcalidrawElement, PointerType } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { useDevice } from "../components/App";
|
import { useDevice } from "../components/App";
|
||||||
import {
|
import {
|
||||||
@@ -11,16 +11,15 @@ import {
|
|||||||
hasBackground,
|
hasBackground,
|
||||||
hasStrokeStyle,
|
hasStrokeStyle,
|
||||||
hasStrokeWidth,
|
hasStrokeWidth,
|
||||||
hasText,
|
|
||||||
} from "../scene";
|
} from "../scene";
|
||||||
import { SHAPES } from "../shapes";
|
import { SHAPES } from "../shapes";
|
||||||
import { AppClassProperties, UIAppState, Zoom } from "../types";
|
import { AppClassProperties, AppProps, UIAppState, Zoom } from "../types";
|
||||||
import { capitalizeString, isTransparent } from "../utils";
|
import { capitalizeString, isTransparent } 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 } from "../element/typeChecks";
|
import { hasBoundTextElement, isTextElement } from "../element/typeChecks";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { actionToggleZenMode } from "../actions";
|
import { actionToggleZenMode } from "../actions";
|
||||||
import { Tooltip } from "./Tooltip";
|
import { Tooltip } from "./Tooltip";
|
||||||
@@ -35,6 +34,7 @@ import {
|
|||||||
EmbedIcon,
|
EmbedIcon,
|
||||||
extraToolsIcon,
|
extraToolsIcon,
|
||||||
frameToolIcon,
|
frameToolIcon,
|
||||||
|
mermaidLogoIcon,
|
||||||
laserPointerToolIcon,
|
laserPointerToolIcon,
|
||||||
} from "./icons";
|
} from "./icons";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
@@ -66,7 +66,8 @@ export const SelectedShapeActions = ({
|
|||||||
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
||||||
|
|
||||||
const showFillIcons =
|
const showFillIcons =
|
||||||
hasBackground(appState.activeTool.type) ||
|
(hasBackground(appState.activeTool.type) &&
|
||||||
|
!isTransparent(appState.currentItemBackgroundColor)) ||
|
||||||
targetElements.some(
|
targetElements.some(
|
||||||
(element) =>
|
(element) =>
|
||||||
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
||||||
@@ -123,14 +124,15 @@ export const SelectedShapeActions = ({
|
|||||||
<>{renderAction("changeRoundness")}</>
|
<>{renderAction("changeRoundness")}</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(hasText(appState.activeTool.type) ||
|
{(appState.activeTool.type === "text" ||
|
||||||
targetElements.some((element) => hasText(element.type))) && (
|
targetElements.some(isTextElement)) && (
|
||||||
<>
|
<>
|
||||||
{renderAction("changeFontSize")}
|
{renderAction("changeFontSize")}
|
||||||
|
|
||||||
{renderAction("changeFontFamily")}
|
{renderAction("changeFontFamily")}
|
||||||
|
|
||||||
{suppportsHorizontalAlign(targetElements) &&
|
{(appState.activeTool.type === "text" ||
|
||||||
|
suppportsHorizontalAlign(targetElements)) &&
|
||||||
renderAction("changeTextAlign")}
|
renderAction("changeTextAlign")}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -200,8 +202,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")}
|
{!device.editor.isMobile && renderAction("duplicateSelection")}
|
||||||
{!device.isMobile && renderAction("deleteSelectedElements")}
|
{!device.editor.isMobile && renderAction("deleteSelectedElements")}
|
||||||
{renderAction("group")}
|
{renderAction("group")}
|
||||||
{renderAction("ungroup")}
|
{renderAction("ungroup")}
|
||||||
{showLinkIcon && renderAction("hyperlink")}
|
{showLinkIcon && renderAction("hyperlink")}
|
||||||
@@ -213,20 +215,17 @@ export const SelectedShapeActions = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ShapesSwitcher = ({
|
export const ShapesSwitcher = ({
|
||||||
interactiveCanvas,
|
|
||||||
activeTool,
|
activeTool,
|
||||||
onImageAction,
|
|
||||||
appState,
|
appState,
|
||||||
app,
|
app,
|
||||||
|
UIOptions,
|
||||||
}: {
|
}: {
|
||||||
interactiveCanvas: HTMLCanvasElement | null;
|
|
||||||
activeTool: UIAppState["activeTool"];
|
activeTool: UIAppState["activeTool"];
|
||||||
onImageAction: (data: { pointerType: PointerType | null }) => void;
|
|
||||||
appState: UIAppState;
|
appState: UIAppState;
|
||||||
app: AppClassProperties;
|
app: AppClassProperties;
|
||||||
|
UIOptions: AppProps["UIOptions"];
|
||||||
}) => {
|
}) => {
|
||||||
const [isExtraToolsMenuOpen, setIsExtraToolsMenuOpen] = useState(false);
|
const [isExtraToolsMenuOpen, setIsExtraToolsMenuOpen] = useState(false);
|
||||||
const device = useDevice();
|
|
||||||
|
|
||||||
const frameToolSelected = activeTool.type === "frame";
|
const frameToolSelected = activeTool.type === "frame";
|
||||||
const laserToolSelected = activeTool.type === "laser";
|
const laserToolSelected = activeTool.type === "laser";
|
||||||
@@ -235,6 +234,14 @@ export const ShapesSwitcher = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{SHAPES.map(({ value, icon, key, numericKey, fillable }, index) => {
|
{SHAPES.map(({ value, icon, key, numericKey, fillable }, index) => {
|
||||||
|
if (
|
||||||
|
UIOptions.tools?.[
|
||||||
|
value as Extract<typeof value, keyof AppProps["UIOptions"]["tools"]>
|
||||||
|
] === false
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const label = t(`toolBar.${value}`);
|
const label = t(`toolBar.${value}`);
|
||||||
const letter =
|
const letter =
|
||||||
key && capitalizeString(typeof key === "string" ? key : key[0]);
|
key && capitalizeString(typeof key === "string" ? key : key[0]);
|
||||||
@@ -263,120 +270,76 @@ export const ShapesSwitcher = ({
|
|||||||
if (appState.activeTool.type !== value) {
|
if (appState.activeTool.type !== value) {
|
||||||
trackEvent("toolbar", value, "ui");
|
trackEvent("toolbar", value, "ui");
|
||||||
}
|
}
|
||||||
app.setActiveTool({ type: value });
|
|
||||||
if (value === "image") {
|
if (value === "image") {
|
||||||
onImageAction({ pointerType });
|
app.setActiveTool({
|
||||||
|
type: value,
|
||||||
|
insertOnCanvasDirectly: pointerType !== "mouse",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
app.setActiveTool({ type: value });
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<div className="App-toolbar__divider" />
|
<div className="App-toolbar__divider" />
|
||||||
{/* TEMP HACK because dropdown doesn't work well inside mobile toolbar */}
|
|
||||||
{device.isMobile ? (
|
<DropdownMenu open={isExtraToolsMenuOpen}>
|
||||||
<>
|
<DropdownMenu.Trigger
|
||||||
<ToolButton
|
className={clsx("App-toolbar__extra-tools-trigger", {
|
||||||
className={clsx("Shape", { fillable: false })}
|
"App-toolbar__extra-tools-trigger--selected":
|
||||||
type="radio"
|
frameToolSelected ||
|
||||||
|
embeddableToolSelected ||
|
||||||
|
// in collab we're already highlighting the laser button
|
||||||
|
// outside toolbar, so let's not highlight extra-tools button
|
||||||
|
// on top of it
|
||||||
|
(laserToolSelected && !app.props.isCollaborating),
|
||||||
|
})}
|
||||||
|
onToggle={() => setIsExtraToolsMenuOpen(!isExtraToolsMenuOpen)}
|
||||||
|
title={t("toolBar.extraTools")}
|
||||||
|
>
|
||||||
|
{extraToolsIcon}
|
||||||
|
</DropdownMenu.Trigger>
|
||||||
|
<DropdownMenu.Content
|
||||||
|
onClickOutside={() => setIsExtraToolsMenuOpen(false)}
|
||||||
|
onSelect={() => setIsExtraToolsMenuOpen(false)}
|
||||||
|
className="App-toolbar__extra-tools-dropdown"
|
||||||
|
>
|
||||||
|
<DropdownMenu.Item
|
||||||
|
onSelect={() => app.setActiveTool({ type: "frame" })}
|
||||||
icon={frameToolIcon}
|
icon={frameToolIcon}
|
||||||
checked={activeTool.type === "frame"}
|
shortcut={KEYS.F.toLocaleUpperCase()}
|
||||||
name="editor-current-shape"
|
data-testid="toolbar-frame"
|
||||||
title={`${capitalizeString(
|
selected={frameToolSelected}
|
||||||
t("toolBar.frame"),
|
>
|
||||||
)} — ${KEYS.F.toLocaleUpperCase()}`}
|
{t("toolBar.frame")}
|
||||||
keyBindingLabel={KEYS.F.toLocaleUpperCase()}
|
</DropdownMenu.Item>
|
||||||
aria-label={capitalizeString(t("toolBar.frame"))}
|
<DropdownMenu.Item
|
||||||
aria-keyshortcuts={KEYS.F.toLocaleUpperCase()}
|
onSelect={() => app.setActiveTool({ type: "embeddable" })}
|
||||||
data-testid={`toolbar-frame`}
|
|
||||||
onPointerDown={({ pointerType }) => {
|
|
||||||
if (!appState.penDetected && pointerType === "pen") {
|
|
||||||
app.togglePenMode(true);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onChange={({ pointerType }) => {
|
|
||||||
trackEvent("toolbar", "frame", "ui");
|
|
||||||
app.setActiveTool({ type: "frame" });
|
|
||||||
}}
|
|
||||||
selected={activeTool.type === "frame"}
|
|
||||||
/>
|
|
||||||
<ToolButton
|
|
||||||
className={clsx("Shape", { fillable: false })}
|
|
||||||
type="radio"
|
|
||||||
icon={EmbedIcon}
|
icon={EmbedIcon}
|
||||||
checked={activeTool.type === "embeddable"}
|
data-testid="toolbar-embeddable"
|
||||||
name="editor-current-shape"
|
selected={embeddableToolSelected}
|
||||||
title={capitalizeString(t("toolBar.embeddable"))}
|
|
||||||
aria-label={capitalizeString(t("toolBar.embeddable"))}
|
|
||||||
data-testid={`toolbar-embeddable`}
|
|
||||||
onPointerDown={({ pointerType }) => {
|
|
||||||
if (!appState.penDetected && pointerType === "pen") {
|
|
||||||
app.togglePenMode(true);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onChange={({ pointerType }) => {
|
|
||||||
trackEvent("toolbar", "embeddable", "ui");
|
|
||||||
app.setActiveTool({ type: "embeddable" });
|
|
||||||
}}
|
|
||||||
selected={activeTool.type === "embeddable"}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<DropdownMenu open={isExtraToolsMenuOpen}>
|
|
||||||
<DropdownMenu.Trigger
|
|
||||||
className={clsx("App-toolbar__extra-tools-trigger", {
|
|
||||||
"App-toolbar__extra-tools-trigger--selected":
|
|
||||||
frameToolSelected ||
|
|
||||||
embeddableToolSelected ||
|
|
||||||
// in collab we're already highlighting the laser button
|
|
||||||
// outside toolbar, so let's not highlight extra-tools button
|
|
||||||
// on top of it
|
|
||||||
(laserToolSelected && !app.props.isCollaborating),
|
|
||||||
})}
|
|
||||||
onToggle={() => setIsExtraToolsMenuOpen(!isExtraToolsMenuOpen)}
|
|
||||||
title={t("toolBar.extraTools")}
|
|
||||||
>
|
>
|
||||||
{extraToolsIcon}
|
{t("toolBar.embeddable")}
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Item>
|
||||||
<DropdownMenu.Content
|
<DropdownMenu.Item
|
||||||
onClickOutside={() => setIsExtraToolsMenuOpen(false)}
|
onSelect={() => app.setActiveTool({ type: "laser" })}
|
||||||
onSelect={() => setIsExtraToolsMenuOpen(false)}
|
icon={laserPointerToolIcon}
|
||||||
className="App-toolbar__extra-tools-dropdown"
|
data-testid="toolbar-laser"
|
||||||
|
selected={laserToolSelected}
|
||||||
|
shortcut={KEYS.K.toLocaleUpperCase()}
|
||||||
>
|
>
|
||||||
<DropdownMenu.Item
|
{t("toolBar.laser")}
|
||||||
onSelect={() => {
|
</DropdownMenu.Item>
|
||||||
app.setActiveTool({ type: "frame" });
|
<DropdownMenu.Item
|
||||||
}}
|
onSelect={() => app.setOpenDialog("mermaid")}
|
||||||
icon={frameToolIcon}
|
icon={mermaidLogoIcon}
|
||||||
shortcut={KEYS.F.toLocaleUpperCase()}
|
data-testid="toolbar-embeddable"
|
||||||
data-testid="toolbar-frame"
|
>
|
||||||
selected={frameToolSelected}
|
{t("toolBar.mermaidToExcalidraw")}
|
||||||
>
|
</DropdownMenu.Item>
|
||||||
{t("toolBar.frame")}
|
</DropdownMenu.Content>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu>
|
||||||
<DropdownMenu.Item
|
|
||||||
onSelect={() => {
|
|
||||||
app.setActiveTool({ type: "embeddable" });
|
|
||||||
}}
|
|
||||||
icon={EmbedIcon}
|
|
||||||
data-testid="toolbar-embeddable"
|
|
||||||
selected={embeddableToolSelected}
|
|
||||||
>
|
|
||||||
{t("toolBar.embeddable")}
|
|
||||||
</DropdownMenu.Item>
|
|
||||||
<DropdownMenu.Item
|
|
||||||
onSelect={() => {
|
|
||||||
app.setActiveTool({ type: "laser" });
|
|
||||||
}}
|
|
||||||
icon={laserPointerToolIcon}
|
|
||||||
data-testid="toolbar-laser"
|
|
||||||
selected={laserToolSelected}
|
|
||||||
shortcut={KEYS.K.toLocaleUpperCase()}
|
|
||||||
>
|
|
||||||
{t("toolBar.laser")}
|
|
||||||
</DropdownMenu.Item>
|
|
||||||
</DropdownMenu.Content>
|
|
||||||
</DropdownMenu>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
+423
-228
File diff suppressed because it is too large
Load Diff
@@ -98,7 +98,7 @@ export const ColorInput = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/* TODO reenable on mobile with a better UX */}
|
{/* TODO reenable on mobile with a better UX */}
|
||||||
{!device.isMobile && (
|
{!device.editor.isMobile && (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const ColorPickerPopupContent = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { container } = useExcalidrawContainer();
|
const { container } = useExcalidrawContainer();
|
||||||
const { isMobile, isLandscape } = useDevice();
|
const device = useDevice();
|
||||||
|
|
||||||
const colorInputJSX = (
|
const colorInputJSX = (
|
||||||
<div>
|
<div>
|
||||||
@@ -136,8 +136,16 @@ const ColorPickerPopupContent = ({
|
|||||||
updateData({ openPopup: null });
|
updateData({ openPopup: null });
|
||||||
setActiveColorPickerSection(null);
|
setActiveColorPickerSection(null);
|
||||||
}}
|
}}
|
||||||
side={isMobile && !isLandscape ? "bottom" : "right"}
|
side={
|
||||||
align={isMobile && !isLandscape ? "center" : "start"}
|
device.editor.isMobile && !device.viewport.isLandscape
|
||||||
|
? "bottom"
|
||||||
|
: "right"
|
||||||
|
}
|
||||||
|
align={
|
||||||
|
device.editor.isMobile && !device.viewport.isLandscape
|
||||||
|
? "center"
|
||||||
|
: "start"
|
||||||
|
}
|
||||||
alignOffset={-16}
|
alignOffset={-16}
|
||||||
sideOffset={20}
|
sideOffset={20}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export const TopPicks = ({
|
|||||||
type="button"
|
type="button"
|
||||||
title={color}
|
title={color}
|
||||||
onClick={() => onChange(color)}
|
onClick={() => onChange(color)}
|
||||||
|
data-testid={`color-top-pick-${color}`}
|
||||||
>
|
>
|
||||||
<div className="color-picker__button-outline" />
|
<div className="color-picker__button-outline" />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -9,11 +9,7 @@ import {
|
|||||||
} from "../actions/shortcuts";
|
} from "../actions/shortcuts";
|
||||||
import { Action } from "../actions/types";
|
import { Action } from "../actions/types";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import {
|
import { useExcalidrawAppState, useExcalidrawElements } from "./App";
|
||||||
useExcalidrawAppState,
|
|
||||||
useExcalidrawElements,
|
|
||||||
useExcalidrawSetAppState,
|
|
||||||
} from "./App";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
export type ContextMenuItem = typeof CONTEXT_MENU_SEPARATOR | Action;
|
export type ContextMenuItem = typeof CONTEXT_MENU_SEPARATOR | Action;
|
||||||
@@ -25,14 +21,14 @@ type ContextMenuProps = {
|
|||||||
items: ContextMenuItems;
|
items: ContextMenuItems;
|
||||||
top: number;
|
top: number;
|
||||||
left: number;
|
left: number;
|
||||||
|
onClose: (callback?: () => void) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CONTEXT_MENU_SEPARATOR = "separator";
|
export const CONTEXT_MENU_SEPARATOR = "separator";
|
||||||
|
|
||||||
export const ContextMenu = React.memo(
|
export const ContextMenu = React.memo(
|
||||||
({ actionManager, items, top, left }: ContextMenuProps) => {
|
({ actionManager, items, top, left, onClose }: ContextMenuProps) => {
|
||||||
const appState = useExcalidrawAppState();
|
const appState = useExcalidrawAppState();
|
||||||
const setAppState = useExcalidrawSetAppState();
|
|
||||||
const elements = useExcalidrawElements();
|
const elements = useExcalidrawElements();
|
||||||
|
|
||||||
const filteredItems = items.reduce((acc: ContextMenuItem[], item) => {
|
const filteredItems = items.reduce((acc: ContextMenuItem[], item) => {
|
||||||
@@ -54,7 +50,9 @@ export const ContextMenu = React.memo(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
onCloseRequest={() => setAppState({ contextMenu: null })}
|
onCloseRequest={() => {
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
top={top}
|
top={top}
|
||||||
left={left}
|
left={left}
|
||||||
fitInViewport={true}
|
fitInViewport={true}
|
||||||
@@ -102,7 +100,7 @@ export const ContextMenu = React.memo(
|
|||||||
// we need update state before executing the action in case
|
// we need update state before executing the action in case
|
||||||
// the action uses the appState it's being passed (that still
|
// the action uses the appState it's being passed (that still
|
||||||
// contains a defined contextMenu) to return the next state.
|
// contains a defined contextMenu) to return the next state.
|
||||||
setAppState({ contextMenu: null }, () => {
|
onClose(() => {
|
||||||
actionManager.executeAction(item, "contextMenu");
|
actionManager.executeAction(item, "contextMenu");
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -33,14 +33,16 @@
|
|||||||
color: var(--color-gray-40);
|
color: var(--color-gray-40);
|
||||||
}
|
}
|
||||||
|
|
||||||
@include isMobile {
|
|
||||||
top: 1.25rem;
|
|
||||||
right: 1.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: 1.5rem;
|
width: 1.5rem;
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Dialog--fullscreen {
|
||||||
|
.Dialog__close {
|
||||||
|
top: 1.25rem;
|
||||||
|
right: 1.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export const Dialog = (props: DialogProps) => {
|
|||||||
const [islandNode, setIslandNode] = useCallbackRefState<HTMLDivElement>();
|
const [islandNode, setIslandNode] = useCallbackRefState<HTMLDivElement>();
|
||||||
const [lastActiveElement] = useState(document.activeElement);
|
const [lastActiveElement] = useState(document.activeElement);
|
||||||
const { id } = useExcalidrawContainer();
|
const { id } = useExcalidrawContainer();
|
||||||
const device = useDevice();
|
const isFullscreen = useDevice().viewport.isMobile;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!islandNode) {
|
if (!islandNode) {
|
||||||
@@ -101,7 +101,9 @@ export const Dialog = (props: DialogProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
className={clsx("Dialog", props.className)}
|
className={clsx("Dialog", props.className, {
|
||||||
|
"Dialog--fullscreen": isFullscreen,
|
||||||
|
})}
|
||||||
labelledBy="dialog-title"
|
labelledBy="dialog-title"
|
||||||
maxWidth={getDialogSize(props.size)}
|
maxWidth={getDialogSize(props.size)}
|
||||||
onCloseRequest={onClose}
|
onCloseRequest={onClose}
|
||||||
@@ -119,7 +121,7 @@ export const Dialog = (props: DialogProps) => {
|
|||||||
title={t("buttons.close")}
|
title={t("buttons.close")}
|
||||||
aria-label={t("buttons.close")}
|
aria-label={t("buttons.close")}
|
||||||
>
|
>
|
||||||
{device.isMobile ? back : CloseIcon}
|
{isFullscreen ? back : CloseIcon}
|
||||||
</button>
|
</button>
|
||||||
<div className="Dialog__content">{props.children}</div>
|
<div className="Dialog__content">{props.children}</div>
|
||||||
</Island>
|
</Island>
|
||||||
|
|||||||
@@ -12,32 +12,32 @@
|
|||||||
|
|
||||||
&--color-primary {
|
&--color-primary {
|
||||||
&.ExcButton--variant-filled {
|
&.ExcButton--variant-filled {
|
||||||
--text-color: var(--input-bg-color);
|
--text-color: var(--color-surface-lowest);
|
||||||
--back-color: var(--color-primary);
|
--back-color: var(--color-primary);
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
--back-color: var(--color-primary-darker);
|
--back-color: var(--color-brand-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
--back-color: var(--color-primary-darkest);
|
--back-color: var(--color-brand-active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.ExcButton--variant-outlined,
|
&.ExcButton--variant-outlined,
|
||||||
&.ExcButton--variant-icon {
|
&.ExcButton--variant-icon {
|
||||||
--text-color: var(--color-primary);
|
--text-color: var(--color-primary);
|
||||||
--border-color: var(--color-primary);
|
--border-color: var(--color-border-outline);
|
||||||
--back-color: var(--input-bg-color);
|
--back-color: transparent;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
--text-color: var(--color-primary-darker);
|
--text-color: var(--color-brand-hover);
|
||||||
--border-color: var(--color-primary-darker);
|
--border-color: var(--color-brand-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
--text-color: var(--color-primary-darkest);
|
--text-color: var(--color-brand-active);
|
||||||
--border-color: var(--color-primary-darkest);
|
--border-color: var(--color-brand-active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,20 +19,35 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__btn {
|
&__btn {
|
||||||
|
--background: var(--color-surface-mid);
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
column-gap: 0.5rem;
|
column-gap: 0.5rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border: 1px solid var(--default-border-color);
|
background-color: var(--background);
|
||||||
padding: 0.625rem 1rem;
|
padding: 0.625rem 1rem;
|
||||||
|
border: 1px solid var(--background);
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
color: var(--text-primary-color);
|
color: var(--text-primary-color);
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
letter-spacing: 0.4px;
|
letter-spacing: 0.4px;
|
||||||
|
|
||||||
|
@at-root .excalidraw.theme--dark#{&} {
|
||||||
|
--background: var(--color-surface-high);
|
||||||
|
&:hover {
|
||||||
|
--background: #363541;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
--background: var(--color-surface-high);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
border-color: var(--color-primary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__link-icon {
|
&__link-icon {
|
||||||
|
|||||||
@@ -254,7 +254,6 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
|||||||
label={t("helpDialog.movePageLeftRight")}
|
label={t("helpDialog.movePageLeftRight")}
|
||||||
shortcuts={["Shift+PgUp/PgDn"]}
|
shortcuts={["Shift+PgUp/PgDn"]}
|
||||||
/>
|
/>
|
||||||
<Shortcut label={t("buttons.fullScreen")} shortcuts={["F"]} />
|
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("buttons.zenMode")}
|
label={t("buttons.zenMode")}
|
||||||
shortcuts={[getShortcutKey("Alt+Z")]}
|
shortcuts={[getShortcutKey("Alt+Z")]}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const getHints = ({ appState, isMobile, device, app }: 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 && !device.canDeviceFitSidebar) {
|
if (appState.openSidebar && !device.editor.canFitSidebar) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import { canvasToBlob } from "../data/blob";
|
|||||||
import { nativeFileSystemSupported } from "../data/filesystem";
|
import { nativeFileSystemSupported } from "../data/filesystem";
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { getSelectedElements, isSomeElementSelected } from "../scene";
|
import { isSomeElementSelected } from "../scene";
|
||||||
import { exportToCanvas } from "../packages/utils";
|
import { exportToCanvas } from "../packages/utils";
|
||||||
|
|
||||||
import { copyIcon, downloadIcon, helpIcon } from "./icons";
|
import { copyIcon, downloadIcon, helpIcon } from "./icons";
|
||||||
@@ -34,6 +34,8 @@ import { Tooltip } from "./Tooltip";
|
|||||||
import "./ImageExportDialog.scss";
|
import "./ImageExportDialog.scss";
|
||||||
import { useAppProps } from "./App";
|
import { useAppProps } from "./App";
|
||||||
import { FilledButton } from "./FilledButton";
|
import { FilledButton } from "./FilledButton";
|
||||||
|
import { cloneJSON } from "../utils";
|
||||||
|
import { prepareElementsForExport } from "../data";
|
||||||
|
|
||||||
const supportsContextFilters =
|
const supportsContextFilters =
|
||||||
"filter" in document.createElement("canvas").getContext("2d")!;
|
"filter" in document.createElement("canvas").getContext("2d")!;
|
||||||
@@ -51,44 +53,47 @@ export const ErrorCanvasPreview = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type ImageExportModalProps = {
|
type ImageExportModalProps = {
|
||||||
appState: UIAppState;
|
appStateSnapshot: Readonly<UIAppState>;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elementsSnapshot: readonly NonDeletedExcalidrawElement[];
|
||||||
files: BinaryFiles;
|
files: BinaryFiles;
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
onExportImage: AppClassProperties["onExportImage"];
|
onExportImage: AppClassProperties["onExportImage"];
|
||||||
};
|
};
|
||||||
|
|
||||||
const ImageExportModal = ({
|
const ImageExportModal = ({
|
||||||
appState,
|
appStateSnapshot,
|
||||||
elements,
|
elementsSnapshot,
|
||||||
files,
|
files,
|
||||||
actionManager,
|
actionManager,
|
||||||
onExportImage,
|
onExportImage,
|
||||||
}: ImageExportModalProps) => {
|
}: ImageExportModalProps) => {
|
||||||
|
const hasSelection = isSomeElementSelected(
|
||||||
|
elementsSnapshot,
|
||||||
|
appStateSnapshot,
|
||||||
|
);
|
||||||
|
|
||||||
const appProps = useAppProps();
|
const appProps = useAppProps();
|
||||||
const [projectName, setProjectName] = useState(appState.name);
|
const [projectName, setProjectName] = useState(appStateSnapshot.name);
|
||||||
|
const [exportSelectionOnly, setExportSelectionOnly] = useState(hasSelection);
|
||||||
const someElementIsSelected = isSomeElementSelected(elements, appState);
|
|
||||||
|
|
||||||
const [exportSelected, setExportSelected] = useState(someElementIsSelected);
|
|
||||||
const [exportWithBackground, setExportWithBackground] = useState(
|
const [exportWithBackground, setExportWithBackground] = useState(
|
||||||
appState.exportBackground,
|
appStateSnapshot.exportBackground,
|
||||||
);
|
);
|
||||||
const [exportDarkMode, setExportDarkMode] = useState(
|
const [exportDarkMode, setExportDarkMode] = useState(
|
||||||
appState.exportWithDarkMode,
|
appStateSnapshot.exportWithDarkMode,
|
||||||
);
|
);
|
||||||
const [embedScene, setEmbedScene] = useState(appState.exportEmbedScene);
|
const [embedScene, setEmbedScene] = useState(
|
||||||
const [exportScale, setExportScale] = useState(appState.exportScale);
|
appStateSnapshot.exportEmbedScene,
|
||||||
|
);
|
||||||
|
const [exportScale, setExportScale] = useState(appStateSnapshot.exportScale);
|
||||||
|
|
||||||
const previewRef = useRef<HTMLDivElement>(null);
|
const previewRef = useRef<HTMLDivElement>(null);
|
||||||
const [renderError, setRenderError] = useState<Error | null>(null);
|
const [renderError, setRenderError] = useState<Error | null>(null);
|
||||||
|
|
||||||
const exportedElements = exportSelected
|
const { exportedElements, exportingFrame } = prepareElementsForExport(
|
||||||
? getSelectedElements(elements, appState, {
|
elementsSnapshot,
|
||||||
includeBoundTextElement: true,
|
appStateSnapshot,
|
||||||
includeElementsInFrames: true,
|
exportSelectionOnly,
|
||||||
})
|
);
|
||||||
: elements;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const previewNode = previewRef.current;
|
const previewNode = previewRef.current;
|
||||||
@@ -102,10 +107,18 @@ const ImageExportModal = ({
|
|||||||
}
|
}
|
||||||
exportToCanvas({
|
exportToCanvas({
|
||||||
elements: exportedElements,
|
elements: exportedElements,
|
||||||
appState,
|
appState: {
|
||||||
|
...appStateSnapshot,
|
||||||
|
name: projectName,
|
||||||
|
exportBackground: exportWithBackground,
|
||||||
|
exportWithDarkMode: exportDarkMode,
|
||||||
|
exportScale,
|
||||||
|
exportEmbedScene: embedScene,
|
||||||
|
},
|
||||||
files,
|
files,
|
||||||
exportPadding: DEFAULT_EXPORT_PADDING,
|
exportPadding: DEFAULT_EXPORT_PADDING,
|
||||||
maxWidthOrHeight: Math.max(maxWidth, maxHeight),
|
maxWidthOrHeight: Math.max(maxWidth, maxHeight),
|
||||||
|
exportingFrame,
|
||||||
})
|
})
|
||||||
.then((canvas) => {
|
.then((canvas) => {
|
||||||
setRenderError(null);
|
setRenderError(null);
|
||||||
@@ -119,7 +132,17 @@ const ImageExportModal = ({
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
setRenderError(error);
|
setRenderError(error);
|
||||||
});
|
});
|
||||||
}, [appState, files, exportedElements]);
|
}, [
|
||||||
|
appStateSnapshot,
|
||||||
|
files,
|
||||||
|
exportedElements,
|
||||||
|
exportingFrame,
|
||||||
|
projectName,
|
||||||
|
exportWithBackground,
|
||||||
|
exportDarkMode,
|
||||||
|
exportScale,
|
||||||
|
embedScene,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ImageExportModal">
|
<div className="ImageExportModal">
|
||||||
@@ -136,7 +159,8 @@ const ImageExportModal = ({
|
|||||||
value={projectName}
|
value={projectName}
|
||||||
style={{ width: "30ch" }}
|
style={{ width: "30ch" }}
|
||||||
disabled={
|
disabled={
|
||||||
typeof appProps.name !== "undefined" || appState.viewModeEnabled
|
typeof appProps.name !== "undefined" ||
|
||||||
|
appStateSnapshot.viewModeEnabled
|
||||||
}
|
}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setProjectName(event.target.value);
|
setProjectName(event.target.value);
|
||||||
@@ -152,16 +176,16 @@ const ImageExportModal = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="ImageExportModal__settings">
|
<div className="ImageExportModal__settings">
|
||||||
<h3>{t("imageExportDialog.header")}</h3>
|
<h3>{t("imageExportDialog.header")}</h3>
|
||||||
{someElementIsSelected && (
|
{hasSelection && (
|
||||||
<ExportSetting
|
<ExportSetting
|
||||||
label={t("imageExportDialog.label.onlySelected")}
|
label={t("imageExportDialog.label.onlySelected")}
|
||||||
name="exportOnlySelected"
|
name="exportOnlySelected"
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
name="exportOnlySelected"
|
name="exportOnlySelected"
|
||||||
checked={exportSelected}
|
checked={exportSelectionOnly}
|
||||||
onChange={(checked) => {
|
onChange={(checked) => {
|
||||||
setExportSelected(checked);
|
setExportSelectionOnly(checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ExportSetting>
|
</ExportSetting>
|
||||||
@@ -243,7 +267,9 @@ const ImageExportModal = ({
|
|||||||
className="ImageExportModal__settings__buttons__button"
|
className="ImageExportModal__settings__buttons__button"
|
||||||
label={t("imageExportDialog.title.exportToPng")}
|
label={t("imageExportDialog.title.exportToPng")}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onExportImage(EXPORT_IMAGE_TYPES.png, exportedElements)
|
onExportImage(EXPORT_IMAGE_TYPES.png, exportedElements, {
|
||||||
|
exportingFrame,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
startIcon={downloadIcon}
|
startIcon={downloadIcon}
|
||||||
>
|
>
|
||||||
@@ -253,7 +279,9 @@ const ImageExportModal = ({
|
|||||||
className="ImageExportModal__settings__buttons__button"
|
className="ImageExportModal__settings__buttons__button"
|
||||||
label={t("imageExportDialog.title.exportToSvg")}
|
label={t("imageExportDialog.title.exportToSvg")}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onExportImage(EXPORT_IMAGE_TYPES.svg, exportedElements)
|
onExportImage(EXPORT_IMAGE_TYPES.svg, exportedElements, {
|
||||||
|
exportingFrame,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
startIcon={downloadIcon}
|
startIcon={downloadIcon}
|
||||||
>
|
>
|
||||||
@@ -264,7 +292,9 @@ const ImageExportModal = ({
|
|||||||
className="ImageExportModal__settings__buttons__button"
|
className="ImageExportModal__settings__buttons__button"
|
||||||
label={t("imageExportDialog.title.copyPngToClipboard")}
|
label={t("imageExportDialog.title.copyPngToClipboard")}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onExportImage(EXPORT_IMAGE_TYPES.clipboard, exportedElements)
|
onExportImage(EXPORT_IMAGE_TYPES.clipboard, exportedElements, {
|
||||||
|
exportingFrame,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
startIcon={copyIcon}
|
startIcon={copyIcon}
|
||||||
>
|
>
|
||||||
@@ -325,15 +355,20 @@ export const ImageExportDialog = ({
|
|||||||
onExportImage: AppClassProperties["onExportImage"];
|
onExportImage: AppClassProperties["onExportImage"];
|
||||||
onCloseRequest: () => void;
|
onCloseRequest: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
if (appState.openDialog !== "imageExport") {
|
// we need to take a snapshot so that the exported state can't be modified
|
||||||
return null;
|
// while the dialog is open
|
||||||
}
|
const [{ appStateSnapshot, elementsSnapshot }] = useState(() => {
|
||||||
|
return {
|
||||||
|
appStateSnapshot: cloneJSON(appState),
|
||||||
|
elementsSnapshot: cloneJSON(elements),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog onCloseRequest={onCloseRequest} size="wide" title={false}>
|
<Dialog onCloseRequest={onCloseRequest} size="wide" title={false}>
|
||||||
<ImageExportModal
|
<ImageExportModal
|
||||||
elements={elements}
|
elementsSnapshot={elementsSnapshot}
|
||||||
appState={appState}
|
appStateSnapshot={appStateSnapshot}
|
||||||
files={files}
|
files={files}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
onExportImage={onExportImage}
|
onExportImage={onExportImage}
|
||||||
|
|||||||
@@ -23,12 +23,15 @@ export type ExportCB = (
|
|||||||
const JSONExportModal = ({
|
const JSONExportModal = ({
|
||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
|
setAppState,
|
||||||
files,
|
files,
|
||||||
actionManager,
|
actionManager,
|
||||||
exportOpts,
|
exportOpts,
|
||||||
canvas,
|
canvas,
|
||||||
|
onCloseRequest,
|
||||||
}: {
|
}: {
|
||||||
appState: UIAppState;
|
appState: UIAppState;
|
||||||
|
setAppState: React.Component<any, UIAppState>["setState"];
|
||||||
files: BinaryFiles;
|
files: BinaryFiles;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
@@ -72,9 +75,14 @@ const JSONExportModal = ({
|
|||||||
title={t("exportDialog.link_button")}
|
title={t("exportDialog.link_button")}
|
||||||
aria-label={t("exportDialog.link_button")}
|
aria-label={t("exportDialog.link_button")}
|
||||||
showAriaLabel={true}
|
showAriaLabel={true}
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
onExportToBackend(elements, appState, files, canvas);
|
try {
|
||||||
trackEvent("export", "link", `ui (${getFrame()})`);
|
trackEvent("export", "link", `ui (${getFrame()})`);
|
||||||
|
await onExportToBackend(elements, appState, files, canvas);
|
||||||
|
onCloseRequest();
|
||||||
|
} catch (error: any) {
|
||||||
|
setAppState({ errorMessage: error.message });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -114,6 +122,7 @@ export const JSONExportDialog = ({
|
|||||||
<JSONExportModal
|
<JSONExportModal
|
||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
|
setAppState={setAppState}
|
||||||
files={files}
|
files={files}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
onCloseRequest={handleClose}
|
onCloseRequest={handleClose}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export class LaserPathManager {
|
|||||||
private collaboratorsState: Map<string, CollabolatorState> = new Map();
|
private collaboratorsState: Map<string, CollabolatorState> = new Map();
|
||||||
|
|
||||||
private rafId: number | undefined;
|
private rafId: number | undefined;
|
||||||
private lastUpdate = 0;
|
private isDrawing = false;
|
||||||
private container: SVGSVGElement | undefined;
|
private container: SVGSVGElement | undefined;
|
||||||
|
|
||||||
constructor(private app: App) {
|
constructor(private app: App) {
|
||||||
@@ -100,7 +100,7 @@ export class LaserPathManager {
|
|||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.stop();
|
this.stop();
|
||||||
this.lastUpdate = 0;
|
this.isDrawing = false;
|
||||||
this.ownState = instantiateCollabolatorState();
|
this.ownState = instantiateCollabolatorState();
|
||||||
this.collaboratorsState = new Map();
|
this.collaboratorsState = new Map();
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ export class LaserPathManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updatePath(state: CollabolatorState) {
|
private updatePath(state: CollabolatorState) {
|
||||||
this.lastUpdate = performance.now();
|
this.isDrawing = true;
|
||||||
|
|
||||||
if (!this.isRunning) {
|
if (!this.isRunning) {
|
||||||
this.start();
|
this.start();
|
||||||
@@ -160,7 +160,7 @@ export class LaserPathManager {
|
|||||||
|
|
||||||
this.updateCollabolatorsState();
|
this.updateCollabolatorsState();
|
||||||
|
|
||||||
if (performance.now() - this.lastUpdate < DECAY_TIME * 2) {
|
if (this.isDrawing) {
|
||||||
this.update();
|
this.update();
|
||||||
} else {
|
} else {
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
@@ -250,6 +250,8 @@ export class LaserPathManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let somePathsExist = false;
|
||||||
|
|
||||||
for (const [key, state] of this.collaboratorsState.entries()) {
|
for (const [key, state] of this.collaboratorsState.entries()) {
|
||||||
if (!this.app.state.collaborators.has(key)) {
|
if (!this.app.state.collaborators.has(key)) {
|
||||||
state.svg.remove();
|
state.svg.remove();
|
||||||
@@ -269,6 +271,10 @@ export class LaserPathManager {
|
|||||||
paths += ` ${this.draw(state.currentPath)}`;
|
paths += ` ${this.draw(state.currentPath)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (paths.trim()) {
|
||||||
|
somePathsExist = true;
|
||||||
|
}
|
||||||
|
|
||||||
state.svg.setAttribute("d", paths);
|
state.svg.setAttribute("d", paths);
|
||||||
state.svg.setAttribute("fill", getClientColor(key));
|
state.svg.setAttribute("fill", getClientColor(key));
|
||||||
}
|
}
|
||||||
@@ -287,7 +293,17 @@ export class LaserPathManager {
|
|||||||
paths += ` ${this.draw(this.ownState.currentPath)}`;
|
paths += ` ${this.draw(this.ownState.currentPath)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paths = paths.trim();
|
||||||
|
|
||||||
|
if (paths) {
|
||||||
|
somePathsExist = true;
|
||||||
|
}
|
||||||
|
|
||||||
this.ownState.svg.setAttribute("d", paths);
|
this.ownState.svg.setAttribute("d", paths);
|
||||||
this.ownState.svg.setAttribute("fill", "red");
|
this.ownState.svg.setAttribute("fill", "red");
|
||||||
|
|
||||||
|
if (!somePathsExist) {
|
||||||
|
this.isDrawing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-35
@@ -62,18 +62,16 @@ interface LayerUIProps {
|
|||||||
appState: UIAppState;
|
appState: UIAppState;
|
||||||
files: BinaryFiles;
|
files: BinaryFiles;
|
||||||
canvas: HTMLCanvasElement;
|
canvas: HTMLCanvasElement;
|
||||||
interactiveCanvas: HTMLCanvasElement | null;
|
|
||||||
setAppState: React.Component<any, AppState>["setState"];
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
onLockToggle: () => void;
|
onLockToggle: () => void;
|
||||||
onHandToolToggle: () => void;
|
onHandToolToggle: () => void;
|
||||||
onPenModeToggle: () => void;
|
onPenModeToggle: AppClassProperties["togglePenMode"];
|
||||||
showExitZenModeBtn: boolean;
|
showExitZenModeBtn: boolean;
|
||||||
langCode: Language["code"];
|
langCode: Language["code"];
|
||||||
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
||||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
||||||
UIOptions: AppProps["UIOptions"];
|
UIOptions: AppProps["UIOptions"];
|
||||||
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
|
||||||
onExportImage: AppClassProperties["onExportImage"];
|
onExportImage: AppClassProperties["onExportImage"];
|
||||||
renderWelcomeScreen: boolean;
|
renderWelcomeScreen: boolean;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
@@ -123,7 +121,6 @@ const LayerUI = ({
|
|||||||
setAppState,
|
setAppState,
|
||||||
elements,
|
elements,
|
||||||
canvas,
|
canvas,
|
||||||
interactiveCanvas,
|
|
||||||
onLockToggle,
|
onLockToggle,
|
||||||
onHandToolToggle,
|
onHandToolToggle,
|
||||||
onPenModeToggle,
|
onPenModeToggle,
|
||||||
@@ -131,7 +128,6 @@ const LayerUI = ({
|
|||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomStats,
|
renderCustomStats,
|
||||||
UIOptions,
|
UIOptions,
|
||||||
onImageAction,
|
|
||||||
onExportImage,
|
onExportImage,
|
||||||
renderWelcomeScreen,
|
renderWelcomeScreen,
|
||||||
children,
|
children,
|
||||||
@@ -165,7 +161,10 @@ const LayerUI = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderImageExportDialog = () => {
|
const renderImageExportDialog = () => {
|
||||||
if (!UIOptions.canvasActions.saveAsImage) {
|
if (
|
||||||
|
!UIOptions.canvasActions.saveAsImage ||
|
||||||
|
appState.openDialog !== "imageExport"
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +249,7 @@ const LayerUI = ({
|
|||||||
>
|
>
|
||||||
<HintViewer
|
<HintViewer
|
||||||
appState={appState}
|
appState={appState}
|
||||||
isMobile={device.isMobile}
|
isMobile={device.editor.isMobile}
|
||||||
device={device}
|
device={device}
|
||||||
app={app}
|
app={app}
|
||||||
/>
|
/>
|
||||||
@@ -259,7 +258,7 @@ const LayerUI = ({
|
|||||||
<PenModeButton
|
<PenModeButton
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
zenModeEnabled={appState.zenModeEnabled}
|
||||||
checked={appState.penMode}
|
checked={appState.penMode}
|
||||||
onChange={onPenModeToggle}
|
onChange={() => onPenModeToggle(null)}
|
||||||
title={t("toolBar.penMode")}
|
title={t("toolBar.penMode")}
|
||||||
penDetected={appState.penDetected}
|
penDetected={appState.penDetected}
|
||||||
/>
|
/>
|
||||||
@@ -280,14 +279,9 @@ const LayerUI = ({
|
|||||||
|
|
||||||
<ShapesSwitcher
|
<ShapesSwitcher
|
||||||
appState={appState}
|
appState={appState}
|
||||||
interactiveCanvas={interactiveCanvas}
|
|
||||||
activeTool={appState.activeTool}
|
activeTool={appState.activeTool}
|
||||||
|
UIOptions={UIOptions}
|
||||||
app={app}
|
app={app}
|
||||||
onImageAction={({ pointerType }) => {
|
|
||||||
onImageAction({
|
|
||||||
insertOnCanvasDirectly: pointerType !== "mouse",
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Island>
|
</Island>
|
||||||
@@ -324,7 +318,7 @@ const LayerUI = ({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<UserList collaborators={appState.collaborators} />
|
<UserList collaborators={appState.collaborators} />
|
||||||
{renderTopRightUI?.(device.isMobile, appState)}
|
{renderTopRightUI?.(device.editor.isMobile, appState)}
|
||||||
{!appState.viewModeEnabled &&
|
{!appState.viewModeEnabled &&
|
||||||
// hide button when sidebar docked
|
// hide button when sidebar docked
|
||||||
(!isSidebarDocked ||
|
(!isSidebarDocked ||
|
||||||
@@ -345,7 +339,7 @@ const LayerUI = ({
|
|||||||
trackEvent(
|
trackEvent(
|
||||||
"sidebar",
|
"sidebar",
|
||||||
`toggleDock (${docked ? "dock" : "undock"})`,
|
`toggleDock (${docked ? "dock" : "undock"})`,
|
||||||
`(${device.isMobile ? "mobile" : "desktop"})`,
|
`(${device.editor.isMobile ? "mobile" : "desktop"})`,
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -373,7 +367,7 @@ const LayerUI = ({
|
|||||||
trackEvent(
|
trackEvent(
|
||||||
"sidebar",
|
"sidebar",
|
||||||
`${DEFAULT_SIDEBAR.name} (open)`,
|
`${DEFAULT_SIDEBAR.name} (open)`,
|
||||||
`button (${device.isMobile ? "mobile" : "desktop"})`,
|
`button (${device.editor.isMobile ? "mobile" : "desktop"})`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -390,7 +384,7 @@ const LayerUI = ({
|
|||||||
{appState.errorMessage}
|
{appState.errorMessage}
|
||||||
</ErrorDialog>
|
</ErrorDialog>
|
||||||
)}
|
)}
|
||||||
{eyeDropperState && !device.isMobile && (
|
{eyeDropperState && !device.editor.isMobile && (
|
||||||
<EyeDropper
|
<EyeDropper
|
||||||
colorPickerType={eyeDropperState.colorPickerType}
|
colorPickerType={eyeDropperState.colorPickerType}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
@@ -460,7 +454,7 @@ const LayerUI = ({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{device.isMobile && (
|
{device.editor.isMobile && (
|
||||||
<MobileMenu
|
<MobileMenu
|
||||||
app={app}
|
app={app}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
@@ -472,23 +466,22 @@ const LayerUI = ({
|
|||||||
onLockToggle={onLockToggle}
|
onLockToggle={onLockToggle}
|
||||||
onHandToolToggle={onHandToolToggle}
|
onHandToolToggle={onHandToolToggle}
|
||||||
onPenModeToggle={onPenModeToggle}
|
onPenModeToggle={onPenModeToggle}
|
||||||
interactiveCanvas={interactiveCanvas}
|
|
||||||
onImageAction={onImageAction}
|
|
||||||
renderTopRightUI={renderTopRightUI}
|
renderTopRightUI={renderTopRightUI}
|
||||||
renderCustomStats={renderCustomStats}
|
renderCustomStats={renderCustomStats}
|
||||||
renderSidebars={renderSidebars}
|
renderSidebars={renderSidebars}
|
||||||
device={device}
|
device={device}
|
||||||
renderWelcomeScreen={renderWelcomeScreen}
|
renderWelcomeScreen={renderWelcomeScreen}
|
||||||
|
UIOptions={UIOptions}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{!device.isMobile && (
|
{!device.editor.isMobile && (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className="layer-ui__wrapper"
|
className="layer-ui__wrapper"
|
||||||
style={
|
style={
|
||||||
appState.openSidebar &&
|
appState.openSidebar &&
|
||||||
isSidebarDocked &&
|
isSidebarDocked &&
|
||||||
device.canDeviceFitSidebar
|
device.editor.canFitSidebar
|
||||||
? { width: `calc(100% - ${LIBRARY_SIDEBAR_WIDTH}px)` }
|
? { width: `calc(100% - ${LIBRARY_SIDEBAR_WIDTH}px)` }
|
||||||
: {}
|
: {}
|
||||||
}
|
}
|
||||||
@@ -560,18 +553,8 @@ const areEqual = (prevProps: LayerUIProps, nextProps: LayerUIProps) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const { canvas: _pC, appState: prevAppState, ...prev } = prevProps;
|
||||||
canvas: _pC,
|
const { canvas: _nC, appState: nextAppState, ...next } = nextProps;
|
||||||
interactiveCanvas: _pIC,
|
|
||||||
appState: prevAppState,
|
|
||||||
...prev
|
|
||||||
} = prevProps;
|
|
||||||
const {
|
|
||||||
canvas: _nC,
|
|
||||||
interactiveCanvas: _nIC,
|
|
||||||
appState: nextAppState,
|
|
||||||
...next
|
|
||||||
} = nextProps;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
isShallowEqual(
|
isShallowEqual(
|
||||||
|
|||||||
@@ -99,10 +99,10 @@
|
|||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--color-primary-darker);
|
background-color: var(--color-brand-hover);
|
||||||
}
|
}
|
||||||
&:active {
|
&:active {
|
||||||
background-color: var(--color-primary-darkest);
|
background-color: var(--color-brand-active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export const LibraryUnit = memo(
|
|||||||
}, [svg]);
|
}, [svg]);
|
||||||
|
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const isMobile = useDevice().isMobile;
|
const isMobile = useDevice().editor.isMobile;
|
||||||
const adder = isPending && (
|
const adder = isPending && (
|
||||||
<div className="library-unit__adder">{PlusIcon}</div>
|
<div className="library-unit__adder">{PlusIcon}</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,221 @@
|
|||||||
|
@import "../css/variables.module";
|
||||||
|
|
||||||
|
$verticalBreakpoint: 860px;
|
||||||
|
|
||||||
|
.excalidraw {
|
||||||
|
.dialog-mermaid {
|
||||||
|
&-title {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
&-desc {
|
||||||
|
font-size: 15px;
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Modal__content .Island {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@at-root .excalidraw:not(.excalidraw--mobile)#{&} {
|
||||||
|
padding: 1.25rem;
|
||||||
|
|
||||||
|
.Modal__content {
|
||||||
|
height: 100%;
|
||||||
|
max-height: 750px;
|
||||||
|
|
||||||
|
@media screen and (max-width: $verticalBreakpoint) {
|
||||||
|
height: auto;
|
||||||
|
// When vertical, we want the height to span whole viewport.
|
||||||
|
// This is also important for the children not to overflow the
|
||||||
|
// modal/viewport (for some reason).
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Island {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
|
||||||
|
.Dialog__content {
|
||||||
|
display: flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-mermaid-body {
|
||||||
|
width: 100%;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
grid-template-rows: 1fr auto;
|
||||||
|
height: 100%;
|
||||||
|
column-gap: 4rem;
|
||||||
|
|
||||||
|
@media screen and (max-width: $verticalBreakpoint) {
|
||||||
|
flex-direction: column;
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-mermaid-panels {
|
||||||
|
display: grid;
|
||||||
|
width: 100%;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 4rem;
|
||||||
|
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: 1 / 3;
|
||||||
|
|
||||||
|
@media screen and (max-width: $verticalBreakpoint) {
|
||||||
|
flex-direction: column;
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
font-size: 14px;
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
margin-left: 4px;
|
||||||
|
|
||||||
|
@media screen and (max-width: $verticalBreakpoint) {
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-text {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 20rem;
|
||||||
|
height: 100%;
|
||||||
|
resize: none;
|
||||||
|
border-radius: var(--border-radius-lg);
|
||||||
|
border: 1px solid var(--dialog-border-color);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
padding: 0.85rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
|
font-family: monospace;
|
||||||
|
|
||||||
|
@media screen and (max-width: $verticalBreakpoint) {
|
||||||
|
width: auto;
|
||||||
|
height: 10rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-preview-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0.85rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
|
// acts as min-height
|
||||||
|
height: 200px;
|
||||||
|
flex-grow: 1;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==")
|
||||||
|
left center;
|
||||||
|
border-radius: var(--border-radius-lg);
|
||||||
|
border: 1px solid var(--dialog-border-color);
|
||||||
|
|
||||||
|
@media screen and (max-width: $verticalBreakpoint) {
|
||||||
|
// acts as min-height
|
||||||
|
height: 400px;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-preview-canvas-container {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-preview {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mermaid-error {
|
||||||
|
color: red;
|
||||||
|
font-weight: 800;
|
||||||
|
font-size: 30px;
|
||||||
|
word-break: break-word;
|
||||||
|
overflow: auto;
|
||||||
|
max-height: 100%;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
position: absolute;
|
||||||
|
z-index: 10;
|
||||||
|
|
||||||
|
p {
|
||||||
|
font-weight: 500;
|
||||||
|
font-family: Cascadia;
|
||||||
|
text-align: left;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
padding: 0 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-mermaid-buttons {
|
||||||
|
grid-column: 2;
|
||||||
|
|
||||||
|
.dialog-mermaid-insert {
|
||||||
|
&.excalidraw-button {
|
||||||
|
font-family: "Assistant";
|
||||||
|
font-weight: 600;
|
||||||
|
height: 2.5rem;
|
||||||
|
margin-top: 1em;
|
||||||
|
margin-bottom: 0.3em;
|
||||||
|
width: 7.5rem;
|
||||||
|
font-size: 12px;
|
||||||
|
color: $oc-white;
|
||||||
|
background-color: var(--color-primary);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--color-primary-darker);
|
||||||
|
}
|
||||||
|
&:active {
|
||||||
|
background-color: var(--color-primary-darkest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: $verticalBreakpoint) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@at-root .excalidraw.theme--dark#{&} {
|
||||||
|
color: var(--color-gray-100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,243 @@
|
|||||||
|
import { useState, useRef, useEffect, useDeferredValue } from "react";
|
||||||
|
import { BinaryFiles } from "../types";
|
||||||
|
import { useApp } from "./App";
|
||||||
|
import { Button } from "./Button";
|
||||||
|
import { Dialog } from "./Dialog";
|
||||||
|
import { DEFAULT_EXPORT_PADDING, DEFAULT_FONT_SIZE } from "../constants";
|
||||||
|
import {
|
||||||
|
convertToExcalidrawElements,
|
||||||
|
exportToCanvas,
|
||||||
|
} from "../packages/excalidraw/index";
|
||||||
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
|
import { canvasToBlob } from "../data/blob";
|
||||||
|
import { ArrowRightIcon } from "./icons";
|
||||||
|
import Spinner from "./Spinner";
|
||||||
|
import "./MermaidToExcalidraw.scss";
|
||||||
|
|
||||||
|
import { MermaidToExcalidrawResult } from "@excalidraw/mermaid-to-excalidraw/dist/interfaces";
|
||||||
|
import type { MermaidOptions } from "@excalidraw/mermaid-to-excalidraw";
|
||||||
|
import { t } from "../i18n";
|
||||||
|
import Trans from "./Trans";
|
||||||
|
|
||||||
|
const LOCAL_STORAGE_KEY_MERMAID_TO_EXCALIDRAW = "mermaid-to-excalidraw";
|
||||||
|
const MERMAID_EXAMPLE =
|
||||||
|
"flowchart TD\n A[Christmas] -->|Get money| B(Go shopping)\n B --> C{Let me think}\n C -->|One| D[Laptop]\n C -->|Two| E[iPhone]\n C -->|Three| F[Car]";
|
||||||
|
|
||||||
|
const saveMermaidDataToStorage = (data: string) => {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(LOCAL_STORAGE_KEY_MERMAID_TO_EXCALIDRAW, data);
|
||||||
|
} catch (error: any) {
|
||||||
|
// Unable to access window.localStorage
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const importMermaidDataFromStorage = () => {
|
||||||
|
try {
|
||||||
|
const data = localStorage.getItem(LOCAL_STORAGE_KEY_MERMAID_TO_EXCALIDRAW);
|
||||||
|
if (data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
// Unable to access localStorage
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ErrorComp = ({ error }: { error: string }) => {
|
||||||
|
return (
|
||||||
|
<div data-testid="mermaid-error" className="mermaid-error">
|
||||||
|
Error! <p>{error}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const MermaidToExcalidraw = () => {
|
||||||
|
const [mermaidToExcalidrawLib, setMermaidToExcalidrawLib] = useState<{
|
||||||
|
loaded: boolean;
|
||||||
|
api: {
|
||||||
|
parseMermaidToExcalidraw: (
|
||||||
|
defination: string,
|
||||||
|
options: MermaidOptions,
|
||||||
|
) => Promise<MermaidToExcalidrawResult>;
|
||||||
|
} | null;
|
||||||
|
}>({ loaded: false, api: null });
|
||||||
|
|
||||||
|
const [text, setText] = useState("");
|
||||||
|
const deferredText = useDeferredValue(text.trim());
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const canvasRef = useRef<HTMLDivElement>(null);
|
||||||
|
const data = useRef<{
|
||||||
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
|
files: BinaryFiles | null;
|
||||||
|
}>({ elements: [], files: null });
|
||||||
|
|
||||||
|
const app = useApp();
|
||||||
|
|
||||||
|
const resetPreview = () => {
|
||||||
|
const canvasNode = canvasRef.current;
|
||||||
|
|
||||||
|
if (!canvasNode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parent = canvasNode.parentElement;
|
||||||
|
if (!parent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
parent.style.background = "";
|
||||||
|
setError(null);
|
||||||
|
canvasNode.replaceChildren();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadMermaidToExcalidrawLib = async () => {
|
||||||
|
const api = await import(
|
||||||
|
/* webpackChunkName:"mermaid-to-excalidraw" */ "@excalidraw/mermaid-to-excalidraw"
|
||||||
|
);
|
||||||
|
setMermaidToExcalidrawLib({ loaded: true, api });
|
||||||
|
};
|
||||||
|
loadMermaidToExcalidrawLib();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const data = importMermaidDataFromStorage() || MERMAID_EXAMPLE;
|
||||||
|
setText(data);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const renderExcalidrawPreview = async () => {
|
||||||
|
const canvasNode = canvasRef.current;
|
||||||
|
const parent = canvasNode?.parentElement;
|
||||||
|
if (
|
||||||
|
!mermaidToExcalidrawLib.loaded ||
|
||||||
|
!canvasNode ||
|
||||||
|
!parent ||
|
||||||
|
!mermaidToExcalidrawLib.api
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!deferredText) {
|
||||||
|
resetPreview();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const { elements, files } =
|
||||||
|
await mermaidToExcalidrawLib.api.parseMermaidToExcalidraw(
|
||||||
|
deferredText,
|
||||||
|
{
|
||||||
|
fontSize: DEFAULT_FONT_SIZE,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
data.current = {
|
||||||
|
elements: convertToExcalidrawElements(elements, {
|
||||||
|
regenerateIds: true,
|
||||||
|
}),
|
||||||
|
files,
|
||||||
|
};
|
||||||
|
|
||||||
|
const canvas = await exportToCanvas({
|
||||||
|
elements: data.current.elements,
|
||||||
|
files: data.current.files,
|
||||||
|
exportPadding: DEFAULT_EXPORT_PADDING,
|
||||||
|
maxWidthOrHeight:
|
||||||
|
Math.max(parent.offsetWidth, parent.offsetHeight) *
|
||||||
|
window.devicePixelRatio,
|
||||||
|
});
|
||||||
|
// if converting to blob fails, there's some problem that will
|
||||||
|
// likely prevent preview and export (e.g. canvas too big)
|
||||||
|
await canvasToBlob(canvas);
|
||||||
|
parent.style.background = "var(--default-bg-color)";
|
||||||
|
canvasNode.replaceChildren(canvas);
|
||||||
|
} catch (e: any) {
|
||||||
|
parent.style.background = "var(--default-bg-color)";
|
||||||
|
if (deferredText) {
|
||||||
|
setError(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
renderExcalidrawPreview();
|
||||||
|
}, [deferredText, mermaidToExcalidrawLib]);
|
||||||
|
|
||||||
|
const onClose = () => {
|
||||||
|
app.setOpenDialog(null);
|
||||||
|
saveMermaidDataToStorage(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSelect = () => {
|
||||||
|
const { elements: newElements, files } = data.current;
|
||||||
|
app.addElementsFromPasteOrLibrary({
|
||||||
|
elements: newElements,
|
||||||
|
files,
|
||||||
|
position: "center",
|
||||||
|
fitToContent: true,
|
||||||
|
});
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
className="dialog-mermaid"
|
||||||
|
onCloseRequest={onClose}
|
||||||
|
size={1200}
|
||||||
|
title={
|
||||||
|
<>
|
||||||
|
<p className="dialog-mermaid-title">{t("mermaid.title")}</p>
|
||||||
|
<span className="dialog-mermaid-desc">
|
||||||
|
<Trans
|
||||||
|
i18nKey="mermaid.description"
|
||||||
|
flowchartLink={(el) => (
|
||||||
|
<a href="https://mermaid.js.org/syntax/flowchart.html">{el}</a>
|
||||||
|
)}
|
||||||
|
sequenceLink={(el) => (
|
||||||
|
<a href="https://mermaid.js.org/syntax/sequenceDiagram.html">
|
||||||
|
{el}
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<br />
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="dialog-mermaid-body">
|
||||||
|
<div className="dialog-mermaid-panels">
|
||||||
|
<div className="dialog-mermaid-panels-text">
|
||||||
|
<label>{t("mermaid.syntax")}</label>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
onChange={(event) => setText(event.target.value)}
|
||||||
|
value={text}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="dialog-mermaid-panels-preview">
|
||||||
|
<label>{t("mermaid.preview")}</label>
|
||||||
|
<div className="dialog-mermaid-panels-preview-wrapper">
|
||||||
|
{error && <ErrorComp error={error} />}
|
||||||
|
{mermaidToExcalidrawLib.loaded ? (
|
||||||
|
<div
|
||||||
|
ref={canvasRef}
|
||||||
|
style={{ opacity: error ? "0.15" : 1 }}
|
||||||
|
className="dialog-mermaid-panels-preview-canvas-container"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Spinner size="2rem" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="dialog-mermaid-buttons">
|
||||||
|
<Button className="dialog-mermaid-insert" onSelect={onSelect}>
|
||||||
|
{t("mermaid.button")}
|
||||||
|
<span>{ArrowRightIcon}</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default MermaidToExcalidraw;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {
|
import {
|
||||||
AppClassProperties,
|
AppClassProperties,
|
||||||
|
AppProps,
|
||||||
AppState,
|
AppState,
|
||||||
Device,
|
Device,
|
||||||
ExcalidrawProps,
|
ExcalidrawProps,
|
||||||
@@ -35,10 +36,8 @@ type MobileMenuProps = {
|
|||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
onLockToggle: () => void;
|
onLockToggle: () => void;
|
||||||
onHandToolToggle: () => void;
|
onHandToolToggle: () => void;
|
||||||
onPenModeToggle: () => void;
|
onPenModeToggle: AppClassProperties["togglePenMode"];
|
||||||
interactiveCanvas: HTMLCanvasElement | null;
|
|
||||||
|
|
||||||
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
|
||||||
renderTopRightUI?: (
|
renderTopRightUI?: (
|
||||||
isMobile: boolean,
|
isMobile: boolean,
|
||||||
appState: UIAppState,
|
appState: UIAppState,
|
||||||
@@ -47,6 +46,7 @@ type MobileMenuProps = {
|
|||||||
renderSidebars: () => JSX.Element | null;
|
renderSidebars: () => JSX.Element | null;
|
||||||
device: Device;
|
device: Device;
|
||||||
renderWelcomeScreen: boolean;
|
renderWelcomeScreen: boolean;
|
||||||
|
UIOptions: AppProps["UIOptions"];
|
||||||
app: AppClassProperties;
|
app: AppClassProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,13 +58,13 @@ export const MobileMenu = ({
|
|||||||
onLockToggle,
|
onLockToggle,
|
||||||
onHandToolToggle,
|
onHandToolToggle,
|
||||||
onPenModeToggle,
|
onPenModeToggle,
|
||||||
interactiveCanvas,
|
|
||||||
onImageAction,
|
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomStats,
|
renderCustomStats,
|
||||||
renderSidebars,
|
renderSidebars,
|
||||||
device,
|
device,
|
||||||
renderWelcomeScreen,
|
renderWelcomeScreen,
|
||||||
|
UIOptions,
|
||||||
app,
|
app,
|
||||||
}: MobileMenuProps) => {
|
}: MobileMenuProps) => {
|
||||||
const {
|
const {
|
||||||
@@ -85,14 +85,9 @@ export const MobileMenu = ({
|
|||||||
<Stack.Row gap={1}>
|
<Stack.Row gap={1}>
|
||||||
<ShapesSwitcher
|
<ShapesSwitcher
|
||||||
appState={appState}
|
appState={appState}
|
||||||
interactiveCanvas={interactiveCanvas}
|
|
||||||
activeTool={appState.activeTool}
|
activeTool={appState.activeTool}
|
||||||
|
UIOptions={UIOptions}
|
||||||
app={app}
|
app={app}
|
||||||
onImageAction={({ pointerType }) => {
|
|
||||||
onImageAction({
|
|
||||||
insertOnCanvasDirectly: pointerType !== "mouse",
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Island>
|
</Island>
|
||||||
@@ -103,7 +98,7 @@ export const MobileMenu = ({
|
|||||||
)}
|
)}
|
||||||
<PenModeButton
|
<PenModeButton
|
||||||
checked={appState.penMode}
|
checked={appState.penMode}
|
||||||
onChange={onPenModeToggle}
|
onChange={() => onPenModeToggle(null)}
|
||||||
title={t("toolBar.penMode")}
|
title={t("toolBar.penMode")}
|
||||||
isMobile
|
isMobile
|
||||||
penDetected={appState.penDetected}
|
penDetected={appState.penDetected}
|
||||||
|
|||||||
@@ -59,12 +59,6 @@
|
|||||||
&:focus {
|
&:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@include isMobile {
|
|
||||||
max-width: 100%;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes Modal__background__fade-in {
|
@keyframes Modal__background__fade-in {
|
||||||
@@ -105,7 +99,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@include isMobile {
|
.Dialog--fullscreen {
|
||||||
.Modal {
|
.Modal {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
@@ -116,6 +110,9 @@
|
|||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,18 @@
|
|||||||
@import "../css/variables.module";
|
@import "../css/variables.module";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
--RadioGroup-background: #ffffff;
|
--RadioGroup-background: var(--island-bg-color);
|
||||||
--RadioGroup-border: var(--color-gray-30);
|
--RadioGroup-border: var(--color-surface-high);
|
||||||
|
|
||||||
--RadioGroup-choice-color-off: var(--color-primary);
|
--RadioGroup-choice-color-off: var(--color-primary);
|
||||||
--RadioGroup-choice-color-off-hover: var(--color-primary-darkest);
|
--RadioGroup-choice-color-off-hover: var(--color-brand-hover);
|
||||||
--RadioGroup-choice-background-off: white;
|
--RadioGroup-choice-background-off: var(--island-bg-color);
|
||||||
--RadioGroup-choice-background-off-active: var(--color-gray-20);
|
--RadioGroup-choice-background-off-active: var(--color-surface-high);
|
||||||
|
|
||||||
--RadioGroup-choice-color-on: white;
|
--RadioGroup-choice-color-on: var(--color-surface-lowest);
|
||||||
--RadioGroup-choice-background-on: var(--color-primary);
|
--RadioGroup-choice-background-on: var(--color-primary);
|
||||||
--RadioGroup-choice-background-on-hover: var(--color-primary-darker);
|
--RadioGroup-choice-background-on-hover: var(--color-brand-hover);
|
||||||
--RadioGroup-choice-background-on-active: var(--color-primary-darkest);
|
--RadioGroup-choice-background-on-active: var(--color-brand-active);
|
||||||
|
|
||||||
&.theme--dark {
|
|
||||||
--RadioGroup-background: var(--color-gray-85);
|
|
||||||
--RadioGroup-border: var(--color-gray-70);
|
|
||||||
|
|
||||||
--RadioGroup-choice-background-off: var(--color-gray-85);
|
|
||||||
--RadioGroup-choice-background-off-active: var(--color-gray-70);
|
|
||||||
--RadioGroup-choice-color-on: var(--color-gray-85);
|
|
||||||
}
|
|
||||||
|
|
||||||
.RadioGroup {
|
.RadioGroup {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|||||||
@@ -113,11 +113,11 @@ export const SidebarInner = forwardRef(
|
|||||||
if ((event.target as Element).closest(".sidebar-trigger")) {
|
if ((event.target as Element).closest(".sidebar-trigger")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!docked || !device.canDeviceFitSidebar) {
|
if (!docked || !device.editor.canFitSidebar) {
|
||||||
closeLibrary();
|
closeLibrary();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[closeLibrary, docked, device.canDeviceFitSidebar],
|
[closeLibrary, docked, device.editor.canFitSidebar],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ export const SidebarInner = forwardRef(
|
|||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
if (
|
if (
|
||||||
event.key === KEYS.ESCAPE &&
|
event.key === KEYS.ESCAPE &&
|
||||||
(!docked || !device.canDeviceFitSidebar)
|
(!docked || !device.editor.canFitSidebar)
|
||||||
) {
|
) {
|
||||||
closeLibrary();
|
closeLibrary();
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ export const SidebarInner = forwardRef(
|
|||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener(EVENT.KEYDOWN, handleKeyDown);
|
document.removeEventListener(EVENT.KEYDOWN, handleKeyDown);
|
||||||
};
|
};
|
||||||
}, [closeLibrary, docked, device.canDeviceFitSidebar]);
|
}, [closeLibrary, docked, device.editor.canFitSidebar]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Island
|
<Island
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const SidebarHeader = ({
|
|||||||
const props = useContext(SidebarPropsContext);
|
const props = useContext(SidebarPropsContext);
|
||||||
|
|
||||||
const renderDockButton = !!(
|
const renderDockButton = !!(
|
||||||
device.canDeviceFitSidebar && props.shouldRenderDockButton
|
device.editor.canFitSidebar && props.shouldRenderDockButton
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
.excalidraw {
|
.excalidraw {
|
||||||
.sidebar-trigger {
|
.sidebar-trigger {
|
||||||
@include outlineButtonStyles;
|
@include outlineButtonStyles;
|
||||||
|
@include filledButtonOnCanvas;
|
||||||
background-color: var(--island-bg-color);
|
|
||||||
|
|
||||||
width: auto;
|
width: auto;
|
||||||
height: var(--lg-button-size);
|
height: var(--lg-button-size);
|
||||||
|
|||||||
+16
-14
@@ -1,15 +1,13 @@
|
|||||||
@import "../css/variables.module";
|
@import "../css/variables.module";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
--Switch-disabled-color: #d6d6d6;
|
--Switch-disabled-color: var(--color-border-outline);
|
||||||
--Switch-track-background: white;
|
--Switch-disabled-toggled-background: var(--color-border-outline-variant);
|
||||||
--Switch-thumb-background: #3d3d3d;
|
--Switch-disabled-border: var(--color-border-outline-variant);
|
||||||
|
--Switch-track-background: var(--island-bg-color);
|
||||||
&.theme--dark {
|
--Switch-thumb-background: var(--color-on-surface);
|
||||||
--Switch-disabled-color: #5c5c5c;
|
--Switch-hover-background: var(--color-brand-hover);
|
||||||
--Switch-track-background: #242424;
|
--Switch-active-background: var(--color-brand-active);
|
||||||
--Switch-thumb-background: #b8b8b8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.Switch {
|
.Switch {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -28,7 +26,11 @@
|
|||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: var(--Switch-track-background);
|
background: var(--Switch-track-background);
|
||||||
border: 1px solid #999999;
|
border: 1px solid var(--Switch-hover-background);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
border: 1px solid var(--Switch-active-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.toggled {
|
&.toggled {
|
||||||
@@ -43,11 +45,11 @@
|
|||||||
|
|
||||||
&.disabled {
|
&.disabled {
|
||||||
background: var(--Switch-track-background);
|
background: var(--Switch-track-background);
|
||||||
border: 1px solid var(--Switch-disabled-color);
|
border: 1px solid var(--Switch-disabled-border);
|
||||||
|
|
||||||
&.toggled {
|
&.toggled {
|
||||||
background: var(--Switch-disabled-color);
|
background: var(--Switch-disabled-toggled-background);
|
||||||
border: 1px solid var(--Switch-disabled-color);
|
border: 1px solid var(--Switch-disabled-toggled-background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +94,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.disabled.toggled:before {
|
&.disabled.toggled:before {
|
||||||
background: var(--color-gray-50);
|
background: var(--Switch-disabled-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
& input {
|
& input {
|
||||||
|
|||||||
@@ -1,25 +1,16 @@
|
|||||||
@import "../css/variables.module";
|
@import "../css/variables.module";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
--ExcTextField--color: var(--color-gray-80);
|
--ExcTextField--color: var(--color-on-surface);
|
||||||
--ExcTextField--label-color: var(--color-gray-80);
|
--ExcTextField--label-color: var(--color-on-surface);
|
||||||
--ExcTextField--background: white;
|
--ExcTextField--background: transparent;
|
||||||
--ExcTextField--readonly--background: var(--color-gray-10);
|
--ExcTextField--readonly--background: var(--color-surface-high);
|
||||||
--ExcTextField--readonly--color: var(--color-gray-80);
|
--ExcTextField--readonly--color: var(--color-on-surface);
|
||||||
--ExcTextField--border: var(--color-gray-40);
|
--ExcTextField--border: var(--color-border-outline);
|
||||||
--ExcTextField--border-hover: var(--color-gray-50);
|
--ExcTextField--readonly--border: var(--color-border-outline-variant);
|
||||||
--ExcTextField--placeholder: var(--color-gray-40);
|
--ExcTextField--border-hover: var(--color-brand-hover);
|
||||||
|
--ExcTextField--border-active: var(--color-brand-active);
|
||||||
&.theme--dark {
|
--ExcTextField--placeholder: var(--color-border-outline-variant);
|
||||||
--ExcTextField--color: var(--color-gray-10);
|
|
||||||
--ExcTextField--label-color: var(--color-gray-20);
|
|
||||||
--ExcTextField--background: var(--color-gray-85);
|
|
||||||
--ExcTextField--readonly--background: var(--color-gray-80);
|
|
||||||
--ExcTextField--readonly--color: var(--color-gray-40);
|
|
||||||
--ExcTextField--border: var(--color-gray-70);
|
|
||||||
--ExcTextField--border-hover: var(--color-gray-60);
|
|
||||||
--ExcTextField--placeholder: var(--color-gray-80);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ExcTextField {
|
.ExcTextField {
|
||||||
&--fullWidth {
|
&--fullWidth {
|
||||||
@@ -61,7 +52,7 @@
|
|||||||
|
|
||||||
&:active,
|
&:active,
|
||||||
&:focus-within {
|
&:focus-within {
|
||||||
border-color: var(--color-primary);
|
border-color: var(--ExcTextField--border-active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +98,7 @@
|
|||||||
|
|
||||||
&--readonly {
|
&--readonly {
|
||||||
background: var(--ExcTextField--readonly--background);
|
background: var(--ExcTextField--readonly--background);
|
||||||
border-color: transparent;
|
border-color: var(--ExcTextField--readonly--border);
|
||||||
|
|
||||||
& input {
|
& input {
|
||||||
color: var(--ExcTextField--readonly--color);
|
color: var(--ExcTextField--readonly--color);
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(
|
useEffect(() => {
|
||||||
() => () => {
|
isMountedRef.current = true;
|
||||||
|
return () => {
|
||||||
isMountedRef.current = false;
|
isMountedRef.current = false;
|
||||||
},
|
};
|
||||||
[],
|
}, []);
|
||||||
);
|
|
||||||
|
|
||||||
const lastPointerTypeRef = useRef<PointerType | null>(null);
|
const lastPointerTypeRef = useRef<PointerType | null>(null);
|
||||||
|
|
||||||
|
|||||||
@@ -97,10 +97,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// &:hover {
|
|
||||||
// background-color: var(--button-gray-2);
|
|
||||||
// }
|
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
background-color: var(--button-gray-3);
|
background-color: var(--button-gray-3);
|
||||||
}
|
}
|
||||||
@@ -110,7 +106,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&--hide {
|
&--hide {
|
||||||
// visibility: hidden;
|
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,6 +160,15 @@
|
|||||||
width: var(--lg-button-size);
|
width: var(--lg-button-size);
|
||||||
height: var(--lg-button-size);
|
height: var(--lg-button-size);
|
||||||
|
|
||||||
|
@media screen and (max-width: 450px) {
|
||||||
|
width: 1.8rem;
|
||||||
|
height: 1.8rem;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 379px) {
|
||||||
|
width: 1.5rem;
|
||||||
|
height: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: var(--lg-icon-size);
|
width: var(--lg-icon-size);
|
||||||
height: var(--lg-icon-size);
|
height: var(--lg-icon-size);
|
||||||
|
|||||||
@@ -16,12 +16,17 @@
|
|||||||
align-self: center;
|
align-self: center;
|
||||||
background-color: var(--default-border-color);
|
background-color: var(--default-border-color);
|
||||||
margin: 0 0.25rem;
|
margin: 0 0.25rem;
|
||||||
|
|
||||||
|
@include isMobile {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.App-toolbar__extra-tools-trigger {
|
.App-toolbar__extra-tools-trigger {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
background-color: transparent;
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
background-color: var(--button-hover-bg);
|
background-color: var(--button-hover-bg);
|
||||||
@@ -40,5 +45,6 @@
|
|||||||
margin-top: 0.375rem;
|
margin-top: 0.375rem;
|
||||||
right: 0;
|
right: 0;
|
||||||
min-width: 11.875rem;
|
min-width: 11.875rem;
|
||||||
|
z-index: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,11 +114,13 @@ const areEqual = (
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isShallowEqual(
|
return (
|
||||||
// asserting AppState because we're being passed the whole AppState
|
isShallowEqual(
|
||||||
// but resolve to only the StaticCanvas-relevant props
|
// asserting AppState because we're being passed the whole AppState
|
||||||
getRelevantAppStateProps(prevProps.appState as AppState),
|
// but resolve to only the StaticCanvas-relevant props
|
||||||
getRelevantAppStateProps(nextProps.appState as AppState),
|
getRelevantAppStateProps(prevProps.appState as AppState),
|
||||||
|
getRelevantAppStateProps(nextProps.appState as AppState),
|
||||||
|
) && isShallowEqual(prevProps.renderConfig, nextProps.renderConfig)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
margin-top: 0.25rem;
|
margin-top: 0.25rem;
|
||||||
|
|
||||||
&--mobile {
|
&--mobile {
|
||||||
bottom: 55px;
|
|
||||||
top: auto;
|
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
row-gap: 0.75rem;
|
row-gap: 0.75rem;
|
||||||
@@ -16,7 +14,7 @@
|
|||||||
.dropdown-menu-container {
|
.dropdown-menu-container {
|
||||||
padding: 8px 8px;
|
padding: 8px 8px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background-color: var(--island-bg-color);
|
// background-color: var(--island-bg-color);
|
||||||
box-shadow: var(--shadow-island);
|
box-shadow: var(--shadow-island);
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -29,7 +27,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.dropdown-menu-container {
|
.dropdown-menu-container {
|
||||||
background-color: #fff !important;
|
background-color: var(--island-bg-color);
|
||||||
max-height: calc(100vh - 150px);
|
max-height: calc(100vh - 150px);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
--gap: 2;
|
--gap: 2;
|
||||||
@@ -40,7 +38,7 @@
|
|||||||
padding: 0 0.625rem;
|
padding: 0 0.625rem;
|
||||||
column-gap: 0.625rem;
|
column-gap: 0.625rem;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
color: var(--color-gray-100);
|
color: var(--color-on-surface);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
@@ -49,7 +47,7 @@
|
|||||||
|
|
||||||
.dropdown-menu-item {
|
.dropdown-menu-item {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: 0;
|
border: 1px solid transparent;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 2rem;
|
height: 2rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -80,6 +78,11 @@
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background-color: var(--button-hover-bg);
|
||||||
|
border-color: var(--color-brand-active);
|
||||||
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: 1rem;
|
width: 1rem;
|
||||||
height: 1rem;
|
height: 1rem;
|
||||||
@@ -98,22 +101,33 @@
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&.theme--dark {
|
|
||||||
.dropdown-menu-item {
|
|
||||||
color: var(--color-gray-40);
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu-container {
|
|
||||||
background-color: var(--color-gray-90) !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu-button {
|
.dropdown-menu-button {
|
||||||
@include outlineButtonStyles;
|
@include outlineButtonStyles;
|
||||||
background-color: var(--island-bg-color);
|
|
||||||
width: var(--lg-button-size);
|
width: var(--lg-button-size);
|
||||||
height: var(--lg-button-size);
|
height: var(--lg-button-size);
|
||||||
|
|
||||||
|
--background: var(--color-surface-mid);
|
||||||
|
|
||||||
|
background-color: var(--background);
|
||||||
|
|
||||||
|
@at-root .excalidraw.theme--dark#{&} {
|
||||||
|
--background: var(--color-surface-high);
|
||||||
|
&:hover {
|
||||||
|
--background: #363541;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
--background: var(--color-surface-high);
|
||||||
|
background-color: var(--background);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
border-color: var(--color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: var(--lg-icon-size);
|
width: var(--lg-icon-size);
|
||||||
height: var(--lg-icon-size);
|
height: var(--lg-icon-size);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const MenuContent = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const classNames = clsx(`dropdown-menu ${className}`, {
|
const classNames = clsx(`dropdown-menu ${className}`, {
|
||||||
"dropdown-menu--mobile": device.isMobile,
|
"dropdown-menu--mobile": device.editor.isMobile,
|
||||||
}).trim();
|
}).trim();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -43,7 +43,7 @@ const MenuContent = ({
|
|||||||
>
|
>
|
||||||
{/* the zIndex ensures this menu has higher stacking order,
|
{/* the zIndex ensures this menu has higher stacking order,
|
||||||
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
||||||
{device.isMobile ? (
|
{device.editor.isMobile ? (
|
||||||
<Stack.Col className="dropdown-menu-container">{children}</Stack.Col>
|
<Stack.Col className="dropdown-menu-container">{children}</Stack.Col>
|
||||||
) : (
|
) : (
|
||||||
<Island
|
<Island
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const MenuItemContent = ({
|
|||||||
<>
|
<>
|
||||||
<div className="dropdown-menu-item__icon">{icon}</div>
|
<div className="dropdown-menu-item__icon">{icon}</div>
|
||||||
<div className="dropdown-menu-item__text">{children}</div>
|
<div className="dropdown-menu-item__text">{children}</div>
|
||||||
{shortcut && !device.isMobile && (
|
{shortcut && !device.editor.isMobile && (
|
||||||
<div className="dropdown-menu-item__shortcut">{shortcut}</div>
|
<div className="dropdown-menu-item__shortcut">{shortcut}</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const MenuTrigger = ({
|
|||||||
`dropdown-menu-button ${className}`,
|
`dropdown-menu-button ${className}`,
|
||||||
"zen-mode-transition",
|
"zen-mode-transition",
|
||||||
{
|
{
|
||||||
"dropdown-menu-button--mobile": device.isMobile,
|
"dropdown-menu-button--mobile": device.editor.isMobile,
|
||||||
},
|
},
|
||||||
).trim();
|
).trim();
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1654,6 +1654,22 @@ export const frameToolIcon = createIcon(
|
|||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const mermaidLogoIcon = createIcon(
|
||||||
|
<path
|
||||||
|
fill="currentColor"
|
||||||
|
d="M407.48,111.18C335.587,108.103 269.573,152.338 245.08,220C220.587,152.338 154.573,108.103 82.68,111.18C80.285,168.229 107.577,222.632 154.74,254.82C178.908,271.419 193.35,298.951 193.27,328.27L193.27,379.13L296.9,379.13L296.9,328.27C296.816,298.953 311.255,271.42 335.42,254.82C382.596,222.644 409.892,168.233 407.48,111.18Z"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ArrowRightIcon = createIcon(
|
||||||
|
<g strokeWidth="1.25">
|
||||||
|
<path d="M4.16602 10H15.8327" />
|
||||||
|
<path d="M12.5 13.3333L15.8333 10" />
|
||||||
|
<path d="M12.5 6.66666L15.8333 9.99999" />
|
||||||
|
</g>,
|
||||||
|
modifiedTablerIconProps,
|
||||||
|
);
|
||||||
|
|
||||||
export const laserPointerToolIcon = createIcon(
|
export const laserPointerToolIcon = createIcon(
|
||||||
<g
|
<g
|
||||||
fill="none"
|
fill="none"
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
--button-active-bg: var(--color-primary-darker);
|
--button-active-bg: var(--color-primary-darker);
|
||||||
|
|
||||||
|
box-shadow: 0 0 0 1px var(--color-surface-lowest);
|
||||||
|
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
|
||||||
// double .active to force specificity
|
// double .active to force specificity
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const MainMenu = Object.assign(
|
|||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
const appState = useUIAppState();
|
const appState = useUIAppState();
|
||||||
const setAppState = useExcalidrawSetAppState();
|
const setAppState = useExcalidrawSetAppState();
|
||||||
const onClickOutside = device.isMobile
|
const onClickOutside = device.editor.isMobile
|
||||||
? undefined
|
? undefined
|
||||||
: () => setAppState({ openMenu: null });
|
: () => setAppState({ openMenu: null });
|
||||||
|
|
||||||
@@ -43,6 +43,7 @@ const MainMenu = Object.assign(
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
data-testid="main-menu-trigger"
|
data-testid="main-menu-trigger"
|
||||||
|
className="main-menu-trigger"
|
||||||
>
|
>
|
||||||
{HamburgerMenuIcon}
|
{HamburgerMenuIcon}
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
@@ -53,7 +54,7 @@ const MainMenu = Object.assign(
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{device.isMobile && appState.collaborators.size > 0 && (
|
{device.editor.isMobile && appState.collaborators.size > 0 && (
|
||||||
<fieldset className="UserList-Wrapper">
|
<fieldset className="UserList-Wrapper">
|
||||||
<legend>{t("labels.collaborators")}</legend>
|
<legend>{t("labels.collaborators")}</legend>
|
||||||
<UserList
|
<UserList
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const WelcomeScreenMenuItemContent = ({
|
|||||||
<>
|
<>
|
||||||
<div className="welcome-screen-menu-item__icon">{icon}</div>
|
<div className="welcome-screen-menu-item__icon">{icon}</div>
|
||||||
<div className="welcome-screen-menu-item__text">{children}</div>
|
<div className="welcome-screen-menu-item__text">{children}</div>
|
||||||
{shortcut && !device.isMobile && (
|
{shortcut && !device.editor.isMobile && (
|
||||||
<div className="welcome-screen-menu-item__shortcut">{shortcut}</div>
|
<div className="welcome-screen-menu-item__shortcut">{shortcut}</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -174,7 +174,7 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: 1px solid transparent;
|
||||||
|
|
||||||
padding: 0.75rem;
|
padding: 0.75rem;
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
|
|
||||||
.welcome-screen-menu-item:hover {
|
.welcome-screen-menu-item:hover {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
background: var(--color-gray-10);
|
background: var(--button-hover-bg);
|
||||||
|
|
||||||
.welcome-screen-menu-item__shortcut {
|
.welcome-screen-menu-item__shortcut {
|
||||||
color: var(--color-gray-50);
|
color: var(--color-gray-50);
|
||||||
@@ -216,7 +216,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.welcome-screen-menu-item:active {
|
.welcome-screen-menu-item:active {
|
||||||
background: var(--color-gray-20);
|
background: var(--button-hover-bg);
|
||||||
|
border-color: var(--color-brand-active);
|
||||||
|
|
||||||
.welcome-screen-menu-item__shortcut {
|
.welcome-screen-menu-item__shortcut {
|
||||||
color: var(--color-gray-50);
|
color: var(--color-gray-50);
|
||||||
@@ -247,8 +248,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.welcome-screen-menu-item:hover {
|
.welcome-screen-menu-item:hover {
|
||||||
background: var(--color-gray-85);
|
background-color: var(--color-surface-low);
|
||||||
|
|
||||||
.welcome-screen-menu-item__shortcut {
|
.welcome-screen-menu-item__shortcut {
|
||||||
color: var(--color-gray-50);
|
color: var(--color-gray-50);
|
||||||
}
|
}
|
||||||
@@ -259,7 +259,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.welcome-screen-menu-item:active {
|
.welcome-screen-menu-item:active {
|
||||||
background-color: var(--color-gray-90);
|
|
||||||
.welcome-screen-menu-item__text {
|
.welcome-screen-menu-item__text {
|
||||||
color: var(--color-gray-10);
|
color: var(--color-gray-10);
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-6
@@ -105,6 +105,7 @@ export const FONT_FAMILY = {
|
|||||||
Virgil: 1,
|
Virgil: 1,
|
||||||
Helvetica: 2,
|
Helvetica: 2,
|
||||||
Cascadia: 3,
|
Cascadia: 3,
|
||||||
|
Assistant: 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const THEME = {
|
export const THEME = {
|
||||||
@@ -114,13 +115,18 @@ export const THEME = {
|
|||||||
|
|
||||||
export const FRAME_STYLE = {
|
export const FRAME_STYLE = {
|
||||||
strokeColor: "#bbb" as ExcalidrawElement["strokeColor"],
|
strokeColor: "#bbb" as ExcalidrawElement["strokeColor"],
|
||||||
strokeWidth: 1 as ExcalidrawElement["strokeWidth"],
|
strokeWidth: 2 as ExcalidrawElement["strokeWidth"],
|
||||||
strokeStyle: "solid" as ExcalidrawElement["strokeStyle"],
|
strokeStyle: "solid" as ExcalidrawElement["strokeStyle"],
|
||||||
fillStyle: "solid" as ExcalidrawElement["fillStyle"],
|
fillStyle: "solid" as ExcalidrawElement["fillStyle"],
|
||||||
roughness: 0 as ExcalidrawElement["roughness"],
|
roughness: 0 as ExcalidrawElement["roughness"],
|
||||||
roundness: null as ExcalidrawElement["roundness"],
|
roundness: null as ExcalidrawElement["roundness"],
|
||||||
backgroundColor: "transparent" as ExcalidrawElement["backgroundColor"],
|
backgroundColor: "transparent" as ExcalidrawElement["backgroundColor"],
|
||||||
radius: 8,
|
radius: 8,
|
||||||
|
nameOffsetY: 3,
|
||||||
|
nameColorLightTheme: "#999999",
|
||||||
|
nameColorDarkTheme: "#7a7a7a",
|
||||||
|
nameFontSize: 14,
|
||||||
|
nameLineHeight: 1.25,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
|
export const WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
|
||||||
@@ -148,6 +154,8 @@ export const IMAGE_MIME_TYPES = {
|
|||||||
jfif: "image/jfif",
|
jfif: "image/jfif",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const ALLOWED_PASTE_MIME_TYPES = ["text/plain", "text/html"] as const;
|
||||||
|
|
||||||
export const MIME_TYPES = {
|
export const MIME_TYPES = {
|
||||||
json: "application/json",
|
json: "application/json",
|
||||||
// excalidraw data
|
// excalidraw data
|
||||||
@@ -214,12 +222,13 @@ export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
|
|||||||
toggleTheme: null,
|
toggleTheme: null,
|
||||||
saveAsImage: true,
|
saveAsImage: true,
|
||||||
},
|
},
|
||||||
|
tools: {
|
||||||
|
image: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// breakpoints
|
// breakpoints
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// sm screen
|
|
||||||
export const MQ_SM_MAX_WIDTH = 640;
|
|
||||||
// md screen
|
// md screen
|
||||||
export const MQ_MAX_WIDTH_PORTRAIT = 730;
|
export const MQ_MAX_WIDTH_PORTRAIT = 730;
|
||||||
export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
|
export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
|
||||||
@@ -296,6 +305,18 @@ export const ROUNDNESS = {
|
|||||||
* collaboration */
|
* collaboration */
|
||||||
export const PRECEDING_ELEMENT_KEY = "__precedingElement__";
|
export const PRECEDING_ELEMENT_KEY = "__precedingElement__";
|
||||||
|
|
||||||
|
export const ROUGHNESS = {
|
||||||
|
architect: 0,
|
||||||
|
artist: 1,
|
||||||
|
cartoonist: 2,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const STROKE_WIDTH = {
|
||||||
|
thin: 1,
|
||||||
|
bold: 2,
|
||||||
|
extraBold: 4,
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const DEFAULT_ELEMENT_PROPS: {
|
export const DEFAULT_ELEMENT_PROPS: {
|
||||||
strokeColor: ExcalidrawElement["strokeColor"];
|
strokeColor: ExcalidrawElement["strokeColor"];
|
||||||
backgroundColor: ExcalidrawElement["backgroundColor"];
|
backgroundColor: ExcalidrawElement["backgroundColor"];
|
||||||
@@ -308,10 +329,10 @@ export const DEFAULT_ELEMENT_PROPS: {
|
|||||||
} = {
|
} = {
|
||||||
strokeColor: COLOR_PALETTE.black,
|
strokeColor: COLOR_PALETTE.black,
|
||||||
backgroundColor: COLOR_PALETTE.transparent,
|
backgroundColor: COLOR_PALETTE.transparent,
|
||||||
fillStyle: "hachure",
|
fillStyle: "solid",
|
||||||
strokeWidth: 1,
|
strokeWidth: 2,
|
||||||
strokeStyle: "solid",
|
strokeStyle: "solid",
|
||||||
roughness: 1,
|
roughness: ROUGHNESS.artist,
|
||||||
opacity: 100,
|
opacity: 100,
|
||||||
locked: false,
|
locked: false,
|
||||||
};
|
};
|
||||||
|
|||||||
+29
-7
@@ -195,7 +195,7 @@
|
|||||||
.buttonList label:focus-within,
|
.buttonList label:focus-within,
|
||||||
input:focus-visible {
|
input:focus-visible {
|
||||||
outline: transparent;
|
outline: transparent;
|
||||||
box-shadow: 0 0 0 2px var(--focus-highlight-color);
|
box-shadow: 0 0 0 1px var(--color-brand-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
.buttonList {
|
.buttonList {
|
||||||
@@ -280,6 +280,11 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
|
||||||
|
.dropdown-menu--mobile {
|
||||||
|
bottom: 55px;
|
||||||
|
top: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.App-mobile-menu {
|
.App-mobile-menu {
|
||||||
@@ -444,13 +449,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
border: 1px solid var(--color-primary-darkest);
|
border: 1px solid var(--button-active-border);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.help-icon {
|
.help-icon {
|
||||||
@include outlineButtonStyles;
|
@include outlineButtonStyles;
|
||||||
background-color: var(--island-bg-color);
|
@include filledButtonOnCanvas;
|
||||||
|
|
||||||
width: var(--lg-button-size);
|
width: var(--lg-button-size);
|
||||||
height: var(--lg-button-size);
|
height: var(--lg-button-size);
|
||||||
|
|
||||||
@@ -536,13 +542,13 @@
|
|||||||
|
|
||||||
&:not(:focus) {
|
&:not(:focus) {
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--input-hover-bg-color);
|
border-color: var(--color-brand-hover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
box-shadow: 0 0 0 2px var(--focus-highlight-color);
|
border-color: var(--color-brand-hover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,6 +597,8 @@
|
|||||||
background-color: var(--island-bg-color);
|
background-color: var(--island-bg-color);
|
||||||
|
|
||||||
.ToolIcon__icon {
|
.ToolIcon__icon {
|
||||||
|
width: 2rem;
|
||||||
|
height: 2rem;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,8 +608,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.App-toolbar--mobile {
|
.App-toolbar--mobile {
|
||||||
overflow-x: auto;
|
overflow: visible;
|
||||||
max-width: 90vw;
|
max-width: 98vw;
|
||||||
|
|
||||||
.ToolIcon__keybinding {
|
.ToolIcon__keybinding {
|
||||||
display: none;
|
display: none;
|
||||||
@@ -621,6 +629,20 @@
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.main-menu-trigger {
|
||||||
|
@include filledButtonOnCanvas;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-menu__left {
|
||||||
|
--button-border: transparent;
|
||||||
|
--button-bg: var(--color-surface-mid);
|
||||||
|
|
||||||
|
@at-root .excalidraw.theme--dark#{&} {
|
||||||
|
--button-hover-bg: #363541;
|
||||||
|
--button-bg: var(--color-surface-high);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ErrorSplash.excalidraw {
|
.ErrorSplash.excalidraw {
|
||||||
|
|||||||
+45
-23
@@ -12,27 +12,30 @@
|
|||||||
--dialog-border-color: var(--color-gray-20);
|
--dialog-border-color: var(--color-gray-20);
|
||||||
--dropdown-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="292.4" height="292.4" viewBox="0 0 292 292"><path d="M287 197L159 69c-4-3-8-5-13-5s-9 2-13 5L5 197c-3 4-5 8-5 13s2 9 5 13c4 4 8 5 13 5h256c5 0 9-1 13-5s5-8 5-13-1-9-5-13z"/></svg>');
|
--dropdown-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="292.4" height="292.4" viewBox="0 0 292 292"><path d="M287 197L159 69c-4-3-8-5-13-5s-9 2-13 5L5 197c-3 4-5 8-5 13s2 9 5 13c4 4 8 5 13 5h256c5 0 9-1 13-5s5-8 5-13-1-9-5-13z"/></svg>');
|
||||||
--focus-highlight-color: #{$oc-blue-2};
|
--focus-highlight-color: #{$oc-blue-2};
|
||||||
--icon-fill-color: var(--color-gray-80);
|
--icon-fill-color: var(--color-on-surface);
|
||||||
--icon-green-fill-color: #{$oc-green-9};
|
--icon-green-fill-color: #{$oc-green-9};
|
||||||
--default-bg-color: #{$oc-white};
|
--default-bg-color: #{$oc-white};
|
||||||
--input-bg-color: #{$oc-white};
|
--input-bg-color: #{$oc-white};
|
||||||
--input-border-color: #{$oc-gray-4};
|
--input-border-color: #{$oc-gray-4};
|
||||||
--input-hover-bg-color: #{$oc-gray-1};
|
--input-hover-bg-color: #{$oc-gray-1};
|
||||||
--input-label-color: #{$oc-gray-7};
|
--input-label-color: #{$oc-gray-7};
|
||||||
--island-bg-color: rgba(255, 255, 255, 0.96);
|
--island-bg-color: #ffffff;
|
||||||
--keybinding-color: var(--color-gray-40);
|
--keybinding-color: var(--color-gray-40);
|
||||||
--link-color: #{$oc-blue-7};
|
--link-color: #{$oc-blue-7};
|
||||||
--overlay-bg-color: #{transparentize($oc-white, 0.12)};
|
--overlay-bg-color: #{transparentize($oc-white, 0.12)};
|
||||||
--popup-bg-color: #{$oc-white};
|
--popup-bg-color: var(--island-bg-color);
|
||||||
--popup-secondary-bg-color: #{$oc-gray-1};
|
--popup-secondary-bg-color: #{$oc-gray-1};
|
||||||
--popup-text-color: #{$oc-black};
|
--popup-text-color: #{$oc-black};
|
||||||
--popup-text-inverted-color: #{$oc-white};
|
--popup-text-inverted-color: #{$oc-white};
|
||||||
--select-highlight-color: #{$oc-blue-5};
|
--select-highlight-color: #{$oc-blue-5};
|
||||||
--shadow-island: 0px 7px 14px rgba(0, 0, 0, 0.05),
|
--shadow-island: 0px 0px 0.9310142993927002px 0px rgba(0, 0, 0, 0.17),
|
||||||
0px 0px 3.12708px rgba(0, 0, 0, 0.0798),
|
0px 0px 3.1270833015441895px 0px rgba(0, 0, 0, 0.08),
|
||||||
0px 0px 0.931014px rgba(0, 0, 0, 0.1702);
|
0px 7px 14px 0px rgba(0, 0, 0, 0.05);
|
||||||
--button-hover-bg: var(--color-gray-10);
|
|
||||||
--default-border-color: var(--color-gray-30);
|
--button-hover-bg: var(--color-surface-high);
|
||||||
|
--button-active-bg: var(--color-surface-high);
|
||||||
|
--button-active-border: var(--color-brand-active);
|
||||||
|
--default-border-color: var(--color-surface-high);
|
||||||
|
|
||||||
--default-button-size: 2rem;
|
--default-button-size: 2rem;
|
||||||
--default-icon-size: 1rem;
|
--default-icon-size: 1rem;
|
||||||
@@ -63,14 +66,14 @@
|
|||||||
0px 12.5216px 10.0172px rgba(0, 0, 0, 0.035),
|
0px 12.5216px 10.0172px rgba(0, 0, 0, 0.035),
|
||||||
0px 6.6501px 5.32008px rgba(0, 0, 0, 0.0282725),
|
0px 6.6501px 5.32008px rgba(0, 0, 0, 0.0282725),
|
||||||
0px 2.76726px 2.21381px rgba(0, 0, 0, 0.0196802);
|
0px 2.76726px 2.21381px rgba(0, 0, 0, 0.0196802);
|
||||||
--sidebar-border-color: var(--color-gray-20);
|
--sidebar-border-color: var(--color-surface-high);
|
||||||
--sidebar-bg-color: #fff;
|
--sidebar-bg-color: var(--island-bg-color);
|
||||||
--library-dropdown-shadow: 0px 15px 6px rgba(0, 0, 0, 0.01),
|
--library-dropdown-shadow: 0px 15px 6px rgba(0, 0, 0, 0.01),
|
||||||
0px 8px 5px rgba(0, 0, 0, 0.05), 0px 4px 4px rgba(0, 0, 0, 0.09),
|
0px 8px 5px rgba(0, 0, 0, 0.05), 0px 4px 4px rgba(0, 0, 0, 0.09),
|
||||||
0px 1px 2px rgba(0, 0, 0, 0.1), 0px 0px 0px rgba(0, 0, 0, 0.1);
|
0px 1px 2px rgba(0, 0, 0, 0.1), 0px 0px 0px rgba(0, 0, 0, 0.1);
|
||||||
|
|
||||||
--space-factor: 0.25rem;
|
--space-factor: 0.25rem;
|
||||||
--text-primary-color: var(--color-gray-80);
|
--text-primary-color: var(--color-on-surface);
|
||||||
|
|
||||||
--color-selection: #6965db;
|
--color-selection: #6965db;
|
||||||
|
|
||||||
@@ -132,6 +135,19 @@
|
|||||||
--border-radius-md: 0.375rem;
|
--border-radius-md: 0.375rem;
|
||||||
--border-radius-lg: 0.5rem;
|
--border-radius-lg: 0.5rem;
|
||||||
|
|
||||||
|
--color-surface-high: hsl(244, 100%, 97%);
|
||||||
|
--color-surface-mid: hsl(240 25% 96%);
|
||||||
|
--color-surface-low: hsl(240 25% 94%);
|
||||||
|
--color-surface-lowest: #ffffff;
|
||||||
|
--color-on-surface: #1b1b1f;
|
||||||
|
--color-brand-hover: #5753d0;
|
||||||
|
--color-on-primary-container: #030064;
|
||||||
|
--color-surface-primary-container: #e0dfff;
|
||||||
|
--color-brand-active: #4440bf;
|
||||||
|
--color-border-outline: #767680;
|
||||||
|
--color-border-outline-variant: #c5c5d0;
|
||||||
|
--color-surface-primary-container: #e0dfff;
|
||||||
|
|
||||||
&.theme--dark {
|
&.theme--dark {
|
||||||
&.theme--dark-background-none {
|
&.theme--dark-background-none {
|
||||||
background: none;
|
background: none;
|
||||||
@@ -150,29 +166,24 @@
|
|||||||
--dialog-border-color: var(--color-gray-80);
|
--dialog-border-color: var(--color-gray-80);
|
||||||
--dropdown-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="292.4" height="292.4" viewBox="0 0 292 292"><path fill="%23ced4da" d="M287 197L159 69c-4-3-8-5-13-5s-9 2-13 5L5 197c-3 4-5 8-5 13s2 9 5 13c4 4 8 5 13 5h256c5 0 9-1 13-5s5-8 5-13-1-9-5-13z"/></svg>');
|
--dropdown-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="292.4" height="292.4" viewBox="0 0 292 292"><path fill="%23ced4da" d="M287 197L159 69c-4-3-8-5-13-5s-9 2-13 5L5 197c-3 4-5 8-5 13s2 9 5 13c4 4 8 5 13 5h256c5 0 9-1 13-5s5-8 5-13-1-9-5-13z"/></svg>');
|
||||||
--focus-highlight-color: #{$oc-blue-6};
|
--focus-highlight-color: #{$oc-blue-6};
|
||||||
--icon-fill-color: var(--color-gray-40);
|
|
||||||
--icon-green-fill-color: #{$oc-green-4};
|
--icon-green-fill-color: #{$oc-green-4};
|
||||||
--default-bg-color: #121212;
|
--default-bg-color: #121212;
|
||||||
--input-bg-color: #121212;
|
--input-bg-color: #121212;
|
||||||
--input-border-color: #2e2e2e;
|
--input-border-color: #2e2e2e;
|
||||||
--input-hover-bg-color: #181818;
|
--input-hover-bg-color: #181818;
|
||||||
--input-label-color: #{$oc-gray-2};
|
--input-label-color: #{$oc-gray-2};
|
||||||
--island-bg-color: #262627;
|
--island-bg-color: #232329;
|
||||||
--keybinding-color: var(--color-gray-60);
|
--keybinding-color: var(--color-gray-60);
|
||||||
--link-color: #{$oc-blue-4};
|
--link-color: #{$oc-blue-4};
|
||||||
--overlay-bg-color: #{transparentize($oc-gray-8, 0.88)};
|
--overlay-bg-color: #{transparentize($oc-gray-8, 0.88)};
|
||||||
--popup-bg-color: #2c2c2c;
|
|
||||||
--popup-secondary-bg-color: #222;
|
--popup-secondary-bg-color: #222;
|
||||||
--popup-text-color: #{$oc-gray-4};
|
--popup-text-color: #{$oc-gray-4};
|
||||||
--popup-text-inverted-color: #2c2c2c;
|
--popup-text-inverted-color: #2c2c2c;
|
||||||
--select-highlight-color: #{$oc-blue-4};
|
--select-highlight-color: #{$oc-blue-4};
|
||||||
--text-primary-color: var(--color-gray-40);
|
--shadow-island: 0px 0px 0.9310142993927002px 0px rgba(0, 0, 0, 0.17),
|
||||||
--button-hover-bg: var(--color-gray-80);
|
0px 0px 3.1270833015441895px 0px rgba(0, 0, 0, 0.08),
|
||||||
--default-border-color: var(--color-gray-80);
|
0px 7px 14px 0px rgba(0, 0, 0, 0.05);
|
||||||
--shadow-island: 0px 13px 33px rgba(0, 0, 0, 0.07),
|
|
||||||
0px 4.13px 9.94853px rgba(0, 0, 0, 0.0456112),
|
|
||||||
0px 1.13px 4.13211px rgba(0, 0, 0, 0.035),
|
|
||||||
0px 0.769896px 1.4945px rgba(0, 0, 0, 0.0243888);
|
|
||||||
--modal-shadow: 0px 100px 80px rgba(0, 0, 0, 0.07),
|
--modal-shadow: 0px 100px 80px rgba(0, 0, 0, 0.07),
|
||||||
0px 41.7776px 33.4221px rgba(0, 0, 0, 0.0503198),
|
0px 41.7776px 33.4221px rgba(0, 0, 0, 0.0503198),
|
||||||
0px 22.3363px 17.869px rgba(0, 0, 0, 0.0417275),
|
0px 22.3363px 17.869px rgba(0, 0, 0, 0.0417275),
|
||||||
@@ -180,8 +191,6 @@
|
|||||||
0px 6.6501px 5.32008px rgba(0, 0, 0, 0.0282725),
|
0px 6.6501px 5.32008px rgba(0, 0, 0, 0.0282725),
|
||||||
0px 2.76726px 2.21381px rgba(0, 0, 0, 0.0196802);
|
0px 2.76726px 2.21381px rgba(0, 0, 0, 0.0196802);
|
||||||
--avatar-border-color: var(--color-gray-85);
|
--avatar-border-color: var(--color-gray-85);
|
||||||
--sidebar-border-color: var(--color-gray-85);
|
|
||||||
--sidebar-bg-color: #191919;
|
|
||||||
|
|
||||||
--scrollbar-thumb: #{$oc-gray-8};
|
--scrollbar-thumb: #{$oc-gray-8};
|
||||||
--scrollbar-thumb-hover: #{$oc-gray-7};
|
--scrollbar-thumb-hover: #{$oc-gray-7};
|
||||||
@@ -224,5 +233,18 @@
|
|||||||
--color-promo: #d297ff;
|
--color-promo: #d297ff;
|
||||||
|
|
||||||
--color-logo-text: #e2dfff;
|
--color-logo-text: #e2dfff;
|
||||||
|
|
||||||
|
--color-surface-high: hsl(245, 10%, 21%);
|
||||||
|
--color-surface-low: hsl(240, 8%, 15%);
|
||||||
|
--color-surface-mid: hsl(240 6% 10%);
|
||||||
|
--color-surface-lowest: hsl(0, 0%, 7%);
|
||||||
|
--color-on-surface: #e3e3e8;
|
||||||
|
--color-brand-hover: #bbb8ff;
|
||||||
|
--color-on-primary-container: #e0dfff;
|
||||||
|
--color-surface-primary-container: #403e6a;
|
||||||
|
--color-brand-active: #d0ccff;
|
||||||
|
--color-border-outline: #8e8d9c;
|
||||||
|
--color-border-outline-variant: #46464f;
|
||||||
|
--color-surface-primary-container: #403e6a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
.ToolIcon_type_radio,
|
.ToolIcon_type_radio,
|
||||||
.ToolIcon_type_checkbox {
|
.ToolIcon_type_checkbox {
|
||||||
&:checked + .ToolIcon__icon {
|
&:checked + .ToolIcon__icon {
|
||||||
--icon-fill-color: var(--color-primary-darker);
|
--icon-fill-color: var(--color-on-primary-container);
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
fill: var(--icon-fill-color);
|
fill: var(--icon-fill-color);
|
||||||
@@ -23,11 +23,11 @@
|
|||||||
.ToolIcon_type_radio,
|
.ToolIcon_type_radio,
|
||||||
.ToolIcon_type_checkbox {
|
.ToolIcon_type_checkbox {
|
||||||
&:checked + .ToolIcon__icon {
|
&:checked + .ToolIcon__icon {
|
||||||
background: var(--color-primary-light);
|
background: var(--color-surface-primary-container);
|
||||||
--keybinding-color: var(--color-gray-60);
|
--keybinding-color: var(--color-on-primary-container);
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
color: var(--color-primary-darker);
|
color: var(--color-on-primary-container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,11 @@
|
|||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
background: var(--button-hover-bg);
|
background: var(--button-hover-bg);
|
||||||
border: 1px solid var(--color-primary-darkest);
|
border: 1px solid var(--button-active-border);
|
||||||
|
|
||||||
|
svg {
|
||||||
|
color: var(--color-on-primary-container);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +67,7 @@
|
|||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-color: var(--button-bg, var(--island-bg-color));
|
background-color: var(--button-bg, var(--island-bg-color));
|
||||||
color: var(--button-color, var(--text-primary-color));
|
color: var(--button-color, var(--color-on-surface));
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: var(--button-width, var(--lg-icon-size));
|
width: var(--button-width, var(--lg-icon-size));
|
||||||
@@ -88,22 +92,38 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
background-color: var(--button-selected-bg, var(--color-primary-light));
|
background-color: var(
|
||||||
border-color: var(--button-selected-border, var(--color-primary-light));
|
--button-selected-bg,
|
||||||
|
var(--color-surface-primary-container)
|
||||||
|
);
|
||||||
|
border-color: var(
|
||||||
|
--button-selected-border,
|
||||||
|
var(--color-surface-primary-container)
|
||||||
|
);
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(
|
background-color: var(
|
||||||
--button-selected-hover-bg,
|
--button-selected-hover-bg,
|
||||||
var(--color-primary-light)
|
var(--color-surface-primary-container)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
color: var(--button-color, var(--color-primary-darker));
|
color: var(--button-color, var(--color-on-primary-container));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@mixin filledButtonOnCanvas {
|
||||||
|
border: none;
|
||||||
|
box-shadow: 0 0 0 1px var(--color-surface-lowest);
|
||||||
|
background-color: var(--color-surface-low);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
box-shadow: 0 0 0 1px var(--color-brand-active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$theme-filter: "invert(93%) hue-rotate(180deg)";
|
$theme-filter: "invert(93%) hue-rotate(180deg)";
|
||||||
$right-sidebar-width: "302px";
|
$right-sidebar-width: "302px";
|
||||||
|
|
||||||
|
|||||||
+105
@@ -0,0 +1,105 @@
|
|||||||
|
import { CURSOR_TYPE, MIME_TYPES, THEME } from "./constants";
|
||||||
|
import OpenColor from "open-color";
|
||||||
|
import { AppState, DataURL } from "./types";
|
||||||
|
import { isHandToolActive, isEraserActive } from "./appState";
|
||||||
|
|
||||||
|
const laserPointerCursorSVG_tag = `<svg viewBox="0 0 24 24" stroke-width="1" width="28" height="28" xmlns="http://www.w3.org/2000/svg">`;
|
||||||
|
const laserPointerCursorBackgroundSVG = `<path d="M6.164 11.755a5.314 5.314 0 0 1-4.932-5.298 5.314 5.314 0 0 1 5.311-5.311 5.314 5.314 0 0 1 5.307 5.113l8.773 8.773a3.322 3.322 0 0 1 0 4.696l-.895.895a3.322 3.322 0 0 1-4.696 0l-8.868-8.868Z" style="fill:#fff"/>`;
|
||||||
|
const laserPointerCursorIconSVG = `<path stroke="#1b1b1f" fill="#fff" d="m7.868 11.113 7.773 7.774a2.359 2.359 0 0 0 1.667.691 2.368 2.368 0 0 0 2.357-2.358c0-.625-.248-1.225-.69-1.667L11.201 7.78 9.558 9.469l-1.69 1.643v.001Zm10.273 3.606-3.333 3.333m-3.25-6.583 2 2m-7-7 3 3M3.664 3.625l1 1M2.529 6.922l1.407-.144m5.735-2.932-1.118.866M4.285 9.823l.758-1.194m1.863-6.207-.13 1.408"/>`;
|
||||||
|
|
||||||
|
const laserPointerCursorDataURL_lightMode = `data:${
|
||||||
|
MIME_TYPES.svg
|
||||||
|
},${encodeURIComponent(
|
||||||
|
`${laserPointerCursorSVG_tag}${laserPointerCursorIconSVG}</svg>`,
|
||||||
|
)}`;
|
||||||
|
const laserPointerCursorDataURL_darkMode = `data:${
|
||||||
|
MIME_TYPES.svg
|
||||||
|
},${encodeURIComponent(
|
||||||
|
`${laserPointerCursorSVG_tag}${laserPointerCursorBackgroundSVG}${laserPointerCursorIconSVG}</svg>`,
|
||||||
|
)}`;
|
||||||
|
|
||||||
|
export const resetCursor = (interactiveCanvas: HTMLCanvasElement | null) => {
|
||||||
|
if (interactiveCanvas) {
|
||||||
|
interactiveCanvas.style.cursor = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setCursor = (
|
||||||
|
interactiveCanvas: HTMLCanvasElement | null,
|
||||||
|
cursor: string,
|
||||||
|
) => {
|
||||||
|
if (interactiveCanvas) {
|
||||||
|
interactiveCanvas.style.cursor = cursor;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let eraserCanvasCache: any;
|
||||||
|
let previewDataURL: string;
|
||||||
|
export const setEraserCursor = (
|
||||||
|
interactiveCanvas: HTMLCanvasElement | null,
|
||||||
|
theme: AppState["theme"],
|
||||||
|
) => {
|
||||||
|
const cursorImageSizePx = 20;
|
||||||
|
|
||||||
|
const drawCanvas = () => {
|
||||||
|
const isDarkTheme = theme === THEME.DARK;
|
||||||
|
eraserCanvasCache = document.createElement("canvas");
|
||||||
|
eraserCanvasCache.theme = theme;
|
||||||
|
eraserCanvasCache.height = cursorImageSizePx;
|
||||||
|
eraserCanvasCache.width = cursorImageSizePx;
|
||||||
|
const context = eraserCanvasCache.getContext("2d")!;
|
||||||
|
context.lineWidth = 1;
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(
|
||||||
|
eraserCanvasCache.width / 2,
|
||||||
|
eraserCanvasCache.height / 2,
|
||||||
|
5,
|
||||||
|
0,
|
||||||
|
2 * Math.PI,
|
||||||
|
);
|
||||||
|
context.fillStyle = isDarkTheme ? OpenColor.black : OpenColor.white;
|
||||||
|
context.fill();
|
||||||
|
context.strokeStyle = isDarkTheme ? OpenColor.white : OpenColor.black;
|
||||||
|
context.stroke();
|
||||||
|
previewDataURL = eraserCanvasCache.toDataURL(MIME_TYPES.svg) as DataURL;
|
||||||
|
};
|
||||||
|
if (!eraserCanvasCache || eraserCanvasCache.theme !== theme) {
|
||||||
|
drawCanvas();
|
||||||
|
}
|
||||||
|
|
||||||
|
setCursor(
|
||||||
|
interactiveCanvas,
|
||||||
|
`url(${previewDataURL}) ${cursorImageSizePx / 2} ${
|
||||||
|
cursorImageSizePx / 2
|
||||||
|
}, auto`,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setCursorForShape = (
|
||||||
|
interactiveCanvas: HTMLCanvasElement | null,
|
||||||
|
appState: Pick<AppState, "activeTool" | "theme">,
|
||||||
|
) => {
|
||||||
|
if (!interactiveCanvas) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (appState.activeTool.type === "selection") {
|
||||||
|
resetCursor(interactiveCanvas);
|
||||||
|
} else if (isHandToolActive(appState)) {
|
||||||
|
interactiveCanvas.style.cursor = CURSOR_TYPE.GRAB;
|
||||||
|
} else if (isEraserActive(appState)) {
|
||||||
|
setEraserCursor(interactiveCanvas, appState.theme);
|
||||||
|
// do nothing if image tool is selected which suggests there's
|
||||||
|
// a image-preview set as the cursor
|
||||||
|
// Ignore custom type as well and let host decide
|
||||||
|
} else if (appState.activeTool.type === "laser") {
|
||||||
|
const url =
|
||||||
|
appState.theme === THEME.LIGHT
|
||||||
|
? laserPointerCursorDataURL_lightMode
|
||||||
|
: laserPointerCursorDataURL_darkMode;
|
||||||
|
interactiveCanvas.style.cursor = `url(${url}), auto`;
|
||||||
|
} else if (!["image", "custom"].includes(appState.activeTool.type)) {
|
||||||
|
interactiveCanvas.style.cursor = CURSOR_TYPE.CROSSHAIR;
|
||||||
|
} else if (appState.activeTool.type !== "image") {
|
||||||
|
interactiveCanvas.style.cursor = CURSOR_TYPE.AUTO;
|
||||||
|
}
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
+53
-18
@@ -3,12 +3,12 @@ import { cleanAppStateForExport } from "../appState";
|
|||||||
import { IMAGE_MIME_TYPES, MIME_TYPES } from "../constants";
|
import { IMAGE_MIME_TYPES, MIME_TYPES } from "../constants";
|
||||||
import { clearElementsForExport } from "../element";
|
import { clearElementsForExport } from "../element";
|
||||||
import { ExcalidrawElement, FileId } from "../element/types";
|
import { ExcalidrawElement, FileId } from "../element/types";
|
||||||
import { CanvasError } from "../errors";
|
import { CanvasError, ImageSceneDataError } from "../errors";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { calculateScrollCenter } from "../scene";
|
import { calculateScrollCenter } from "../scene";
|
||||||
import { AppState, DataURL, LibraryItem } from "../types";
|
import { AppState, DataURL, LibraryItem } from "../types";
|
||||||
import { ValueOf } from "../utility-types";
|
import { ValueOf } from "../utility-types";
|
||||||
import { bytesToHexString } from "../utils";
|
import { bytesToHexString, isPromiseLike } from "../utils";
|
||||||
import { FileSystemHandle, nativeFileSystemSupported } from "./filesystem";
|
import { FileSystemHandle, nativeFileSystemSupported } from "./filesystem";
|
||||||
import { isValidExcalidrawData, isValidLibrary } from "./json";
|
import { isValidExcalidrawData, isValidLibrary } from "./json";
|
||||||
import { restore, restoreLibraryItems } from "./restore";
|
import { restore, restoreLibraryItems } from "./restore";
|
||||||
@@ -24,15 +24,12 @@ const parseFileContents = async (blob: Blob | File) => {
|
|||||||
).decodePngMetadata(blob);
|
).decodePngMetadata(blob);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error.message === "INVALID") {
|
if (error.message === "INVALID") {
|
||||||
throw new DOMException(
|
throw new ImageSceneDataError(
|
||||||
t("alerts.imageDoesNotContainScene"),
|
t("alerts.imageDoesNotContainScene"),
|
||||||
"EncodingError",
|
"IMAGE_NOT_CONTAINS_SCENE_DATA",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new DOMException(
|
throw new ImageSceneDataError(t("alerts.cannotRestoreFromImage"));
|
||||||
t("alerts.cannotRestoreFromImage"),
|
|
||||||
"EncodingError",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -58,15 +55,12 @@ const parseFileContents = async (blob: Blob | File) => {
|
|||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error.message === "INVALID") {
|
if (error.message === "INVALID") {
|
||||||
throw new DOMException(
|
throw new ImageSceneDataError(
|
||||||
t("alerts.imageDoesNotContainScene"),
|
t("alerts.imageDoesNotContainScene"),
|
||||||
"EncodingError",
|
"IMAGE_NOT_CONTAINS_SCENE_DATA",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new DOMException(
|
throw new ImageSceneDataError(t("alerts.cannotRestoreFromImage"));
|
||||||
t("alerts.cannotRestoreFromImage"),
|
|
||||||
"EncodingError",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,8 +125,19 @@ export const loadSceneOrLibraryFromBlob = async (
|
|||||||
fileHandle?: FileSystemHandle | null,
|
fileHandle?: FileSystemHandle | null,
|
||||||
) => {
|
) => {
|
||||||
const contents = await parseFileContents(blob);
|
const contents = await parseFileContents(blob);
|
||||||
|
let data;
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(contents);
|
try {
|
||||||
|
data = JSON.parse(contents);
|
||||||
|
} catch (error: any) {
|
||||||
|
if (isSupportedImageFile(blob)) {
|
||||||
|
throw new ImageSceneDataError(
|
||||||
|
t("alerts.imageDoesNotContainScene"),
|
||||||
|
"IMAGE_NOT_CONTAINS_SCENE_DATA",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
if (isValidExcalidrawData(data)) {
|
if (isValidExcalidrawData(data)) {
|
||||||
return {
|
return {
|
||||||
type: MIME_TYPES.excalidraw,
|
type: MIME_TYPES.excalidraw,
|
||||||
@@ -162,7 +167,9 @@ export const loadSceneOrLibraryFromBlob = async (
|
|||||||
}
|
}
|
||||||
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error.message);
|
if (error instanceof ImageSceneDataError) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -207,10 +214,13 @@ export const loadLibraryFromBlob = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const canvasToBlob = async (
|
export const canvasToBlob = async (
|
||||||
canvas: HTMLCanvasElement,
|
canvas: HTMLCanvasElement | Promise<HTMLCanvasElement>,
|
||||||
): Promise<Blob> => {
|
): Promise<Blob> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
|
if (isPromiseLike(canvas)) {
|
||||||
|
canvas = await canvas;
|
||||||
|
}
|
||||||
canvas.toBlob((blob) => {
|
canvas.toBlob((blob) => {
|
||||||
if (!blob) {
|
if (!blob) {
|
||||||
return reject(
|
return reject(
|
||||||
@@ -324,6 +334,31 @@ export const SVGStringToFile = (SVGString: string, filename: string = "") => {
|
|||||||
}) as File & { type: typeof MIME_TYPES.svg };
|
}) as File & { type: typeof MIME_TYPES.svg };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ImageURLToFile = async (
|
||||||
|
imageUrl: string,
|
||||||
|
filename: string = "",
|
||||||
|
): Promise<File | undefined> => {
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await fetch(imageUrl);
|
||||||
|
} catch (error: any) {
|
||||||
|
throw new Error(t("errors.failedToFetchImage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(t("errors.failedToFetchImage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = await response.blob();
|
||||||
|
|
||||||
|
if (blob.type && isSupportedImageFile(blob)) {
|
||||||
|
const name = filename || blob.name || "";
|
||||||
|
return new File([blob], name, { type: blob.type });
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(t("errors.unsupportedFileType"));
|
||||||
|
};
|
||||||
|
|
||||||
export const getFileFromEvent = async (
|
export const getFileFromEvent = async (
|
||||||
event: React.DragEvent<HTMLDivElement>,
|
event: React.DragEvent<HTMLDivElement>,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
+67
-9
@@ -3,11 +3,19 @@ import {
|
|||||||
copyTextToSystemClipboard,
|
copyTextToSystemClipboard,
|
||||||
} from "../clipboard";
|
} from "../clipboard";
|
||||||
import { DEFAULT_EXPORT_PADDING, isFirefox, MIME_TYPES } from "../constants";
|
import { DEFAULT_EXPORT_PADDING, isFirefox, MIME_TYPES } from "../constants";
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { getNonDeletedElements, isFrameElement } from "../element";
|
||||||
|
import {
|
||||||
|
ExcalidrawElement,
|
||||||
|
ExcalidrawFrameElement,
|
||||||
|
NonDeletedExcalidrawElement,
|
||||||
|
} from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
import { elementsOverlappingBBox } from "../packages/withinBounds";
|
||||||
|
import { isSomeElementSelected, getSelectedElements } from "../scene";
|
||||||
import { exportToCanvas, exportToSvg } from "../scene/export";
|
import { exportToCanvas, exportToSvg } from "../scene/export";
|
||||||
import { ExportType } from "../scene/types";
|
import { ExportType } from "../scene/types";
|
||||||
import { AppState, BinaryFiles } from "../types";
|
import { AppState, BinaryFiles } from "../types";
|
||||||
|
import { cloneJSON } from "../utils";
|
||||||
import { canvasToBlob } from "./blob";
|
import { canvasToBlob } from "./blob";
|
||||||
import { fileSave, FileSystemHandle } from "./filesystem";
|
import { fileSave, FileSystemHandle } from "./filesystem";
|
||||||
import { serializeAsJSON } from "./json";
|
import { serializeAsJSON } from "./json";
|
||||||
@@ -15,9 +23,61 @@ import { serializeAsJSON } from "./json";
|
|||||||
export { loadFromBlob } from "./blob";
|
export { loadFromBlob } from "./blob";
|
||||||
export { loadFromJSON, saveAsJSON } from "./json";
|
export { loadFromJSON, saveAsJSON } from "./json";
|
||||||
|
|
||||||
|
export type ExportedElements = readonly NonDeletedExcalidrawElement[] & {
|
||||||
|
_brand: "exportedElements";
|
||||||
|
};
|
||||||
|
|
||||||
|
export const prepareElementsForExport = (
|
||||||
|
elements: readonly ExcalidrawElement[],
|
||||||
|
{ selectedElementIds }: Pick<AppState, "selectedElementIds">,
|
||||||
|
exportSelectionOnly: boolean,
|
||||||
|
) => {
|
||||||
|
elements = getNonDeletedElements(elements);
|
||||||
|
|
||||||
|
const isExportingSelection =
|
||||||
|
exportSelectionOnly &&
|
||||||
|
isSomeElementSelected(elements, { selectedElementIds });
|
||||||
|
|
||||||
|
let exportingFrame: ExcalidrawFrameElement | null = null;
|
||||||
|
let exportedElements = isExportingSelection
|
||||||
|
? getSelectedElements(
|
||||||
|
elements,
|
||||||
|
{ selectedElementIds },
|
||||||
|
{
|
||||||
|
includeBoundTextElement: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: elements;
|
||||||
|
|
||||||
|
if (isExportingSelection) {
|
||||||
|
if (exportedElements.length === 1 && isFrameElement(exportedElements[0])) {
|
||||||
|
exportingFrame = exportedElements[0];
|
||||||
|
exportedElements = elementsOverlappingBBox({
|
||||||
|
elements,
|
||||||
|
bounds: exportingFrame,
|
||||||
|
type: "overlap",
|
||||||
|
});
|
||||||
|
} else if (exportedElements.length > 1) {
|
||||||
|
exportedElements = getSelectedElements(
|
||||||
|
elements,
|
||||||
|
{ selectedElementIds },
|
||||||
|
{
|
||||||
|
includeBoundTextElement: true,
|
||||||
|
includeElementsInFrames: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
exportingFrame,
|
||||||
|
exportedElements: cloneJSON(exportedElements) as ExportedElements,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const exportCanvas = async (
|
export const exportCanvas = async (
|
||||||
type: Omit<ExportType, "backend">,
|
type: Omit<ExportType, "backend">,
|
||||||
elements: readonly NonDeletedExcalidrawElement[],
|
elements: ExportedElements,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
files: BinaryFiles,
|
files: BinaryFiles,
|
||||||
{
|
{
|
||||||
@@ -26,12 +86,14 @@ export const exportCanvas = async (
|
|||||||
viewBackgroundColor,
|
viewBackgroundColor,
|
||||||
name,
|
name,
|
||||||
fileHandle = null,
|
fileHandle = null,
|
||||||
|
exportingFrame = null,
|
||||||
}: {
|
}: {
|
||||||
exportBackground: boolean;
|
exportBackground: boolean;
|
||||||
exportPadding?: number;
|
exportPadding?: number;
|
||||||
viewBackgroundColor: string;
|
viewBackgroundColor: string;
|
||||||
name: string;
|
name: string;
|
||||||
fileHandle?: FileSystemHandle | null;
|
fileHandle?: FileSystemHandle | null;
|
||||||
|
exportingFrame: ExcalidrawFrameElement | null;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
if (elements.length === 0) {
|
if (elements.length === 0) {
|
||||||
@@ -49,6 +111,7 @@ export const exportCanvas = async (
|
|||||||
exportEmbedScene: appState.exportEmbedScene && type === "svg",
|
exportEmbedScene: appState.exportEmbedScene && type === "svg",
|
||||||
},
|
},
|
||||||
files,
|
files,
|
||||||
|
{ exportingFrame },
|
||||||
);
|
);
|
||||||
if (type === "svg") {
|
if (type === "svg") {
|
||||||
return await fileSave(
|
return await fileSave(
|
||||||
@@ -66,17 +129,15 @@ export const exportCanvas = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const tempCanvas = await exportToCanvas(elements, appState, files, {
|
const tempCanvas = exportToCanvas(elements, appState, files, {
|
||||||
exportBackground,
|
exportBackground,
|
||||||
viewBackgroundColor,
|
viewBackgroundColor,
|
||||||
exportPadding,
|
exportPadding,
|
||||||
|
exportingFrame,
|
||||||
});
|
});
|
||||||
tempCanvas.style.display = "none";
|
|
||||||
document.body.appendChild(tempCanvas);
|
|
||||||
|
|
||||||
if (type === "png") {
|
if (type === "png") {
|
||||||
let blob = await canvasToBlob(tempCanvas);
|
let blob = await canvasToBlob(tempCanvas);
|
||||||
tempCanvas.remove();
|
|
||||||
if (appState.exportEmbedScene) {
|
if (appState.exportEmbedScene) {
|
||||||
blob = await (
|
blob = await (
|
||||||
await import(/* webpackChunkName: "image" */ "./image")
|
await import(/* webpackChunkName: "image" */ "./image")
|
||||||
@@ -114,11 +175,8 @@ export const exportCanvas = async (
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(t("alerts.couldNotCopyToClipboard"));
|
throw new Error(t("alerts.couldNotCopyToClipboard"));
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
tempCanvas.remove();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tempCanvas.remove();
|
|
||||||
// shouldn't happen
|
// shouldn't happen
|
||||||
throw new Error("Unsupported export type");
|
throw new Error("Unsupported export type");
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -23,6 +23,7 @@ import {
|
|||||||
LIBRARY_SIDEBAR_TAB,
|
LIBRARY_SIDEBAR_TAB,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import { libraryItemSvgsCache } from "../hooks/useLibraryItemSvg";
|
import { libraryItemSvgsCache } from "../hooks/useLibraryItemSvg";
|
||||||
|
import { cloneJSON } from "../utils";
|
||||||
|
|
||||||
export const libraryItemsAtom = atom<{
|
export const libraryItemsAtom = atom<{
|
||||||
status: "loading" | "loaded";
|
status: "loading" | "loaded";
|
||||||
@@ -31,7 +32,7 @@ export const libraryItemsAtom = atom<{
|
|||||||
}>({ status: "loaded", isInitialized: true, libraryItems: [] });
|
}>({ status: "loaded", isInitialized: true, libraryItems: [] });
|
||||||
|
|
||||||
const cloneLibraryItems = (libraryItems: LibraryItems): LibraryItems =>
|
const cloneLibraryItems = (libraryItems: LibraryItems): LibraryItems =>
|
||||||
JSON.parse(JSON.stringify(libraryItems));
|
cloneJSON(libraryItems);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if library item does not exist already in current library
|
* checks if library item does not exist already in current library
|
||||||
|
|||||||
+12
-12
@@ -1,7 +1,6 @@
|
|||||||
import { ExcalidrawElement } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
import { AppState, BinaryFiles } from "../types";
|
import { AppState, BinaryFiles } from "../types";
|
||||||
import { exportCanvas } from ".";
|
import { exportCanvas, prepareElementsForExport } from ".";
|
||||||
import { getNonDeletedElements } from "../element";
|
|
||||||
import { getFileHandleType, isImageFileHandleType } from "./blob";
|
import { getFileHandleType, isImageFileHandleType } from "./blob";
|
||||||
|
|
||||||
export const resaveAsImageWithScene = async (
|
export const resaveAsImageWithScene = async (
|
||||||
@@ -23,18 +22,19 @@ export const resaveAsImageWithScene = async (
|
|||||||
exportEmbedScene: true,
|
exportEmbedScene: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
await exportCanvas(
|
const { exportedElements, exportingFrame } = prepareElementsForExport(
|
||||||
fileHandleType,
|
elements,
|
||||||
getNonDeletedElements(elements),
|
|
||||||
appState,
|
appState,
|
||||||
files,
|
false,
|
||||||
{
|
|
||||||
exportBackground,
|
|
||||||
viewBackgroundColor,
|
|
||||||
name,
|
|
||||||
fileHandle,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await exportCanvas(fileHandleType, exportedElements, appState, files, {
|
||||||
|
exportBackground,
|
||||||
|
viewBackgroundColor,
|
||||||
|
name,
|
||||||
|
fileHandle,
|
||||||
|
exportingFrame,
|
||||||
|
});
|
||||||
|
|
||||||
return { fileHandle };
|
return { fileHandle };
|
||||||
};
|
};
|
||||||
|
|||||||
+10
-1
@@ -189,7 +189,7 @@ const restoreElement = (
|
|||||||
fontSize = parseFloat(fontPx);
|
fontSize = parseFloat(fontPx);
|
||||||
fontFamily = getFontFamilyByName(_fontFamily);
|
fontFamily = getFontFamilyByName(_fontFamily);
|
||||||
}
|
}
|
||||||
const text = element.text ?? "";
|
const text = (typeof element.text === "string" && element.text) || "";
|
||||||
|
|
||||||
// line-height might not be specified either when creating elements
|
// line-height might not be specified either when creating elements
|
||||||
// programmatically, or when importing old diagrams.
|
// programmatically, or when importing old diagrams.
|
||||||
@@ -222,9 +222,17 @@ const restoreElement = (
|
|||||||
baseline,
|
baseline,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// if empty text, mark as deleted. We keep in array
|
||||||
|
// for data integrity purposes (collab etc.)
|
||||||
|
if (!text && !element.isDeleted) {
|
||||||
|
element = { ...element, originalText: text, isDeleted: true };
|
||||||
|
element = bumpVersion(element);
|
||||||
|
}
|
||||||
|
|
||||||
if (refreshDimensions) {
|
if (refreshDimensions) {
|
||||||
element = { ...element, ...refreshTextDimensions(element) };
|
element = { ...element, ...refreshTextDimensions(element) };
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
case "freedraw": {
|
case "freedraw": {
|
||||||
return restoreElementWithProperties(element, {
|
return restoreElementWithProperties(element, {
|
||||||
@@ -299,6 +307,7 @@ const restoreElement = (
|
|||||||
// We also don't want to throw, but instead return void so we filter
|
// We also don't want to throw, but instead return void so we filter
|
||||||
// out these unsupported elements from the restored array.
|
// out these unsupported elements from the restored array.
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+128
-9
@@ -5,7 +5,31 @@ import {
|
|||||||
} from "./transform";
|
} from "./transform";
|
||||||
import { ExcalidrawArrowElement } from "../element/types";
|
import { ExcalidrawArrowElement } from "../element/types";
|
||||||
|
|
||||||
|
const opts = { regenerateIds: false };
|
||||||
|
|
||||||
describe("Test Transform", () => {
|
describe("Test Transform", () => {
|
||||||
|
it("should generate id unless opts.regenerateIds is set to false explicitly", () => {
|
||||||
|
const elements = [
|
||||||
|
{
|
||||||
|
type: "rectangle",
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
id: "rect-1",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
let data = convertToExcalidrawElements(
|
||||||
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
);
|
||||||
|
expect(data.length).toBe(1);
|
||||||
|
expect(data[0].id).toBe("id0");
|
||||||
|
|
||||||
|
data = convertToExcalidrawElements(
|
||||||
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
expect(data[0].id).toBe("rect-1");
|
||||||
|
});
|
||||||
|
|
||||||
it("should transform regular shapes", () => {
|
it("should transform regular shapes", () => {
|
||||||
const elements = [
|
const elements = [
|
||||||
{
|
{
|
||||||
@@ -59,6 +83,7 @@ describe("Test Transform", () => {
|
|||||||
|
|
||||||
convertToExcalidrawElements(
|
convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
).forEach((ele) => {
|
).forEach((ele) => {
|
||||||
expect(ele).toMatchSnapshot({
|
expect(ele).toMatchSnapshot({
|
||||||
seed: expect.any(Number),
|
seed: expect.any(Number),
|
||||||
@@ -87,6 +112,7 @@ describe("Test Transform", () => {
|
|||||||
];
|
];
|
||||||
convertToExcalidrawElements(
|
convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
).forEach((ele) => {
|
).forEach((ele) => {
|
||||||
expect(ele).toMatchSnapshot({
|
expect(ele).toMatchSnapshot({
|
||||||
seed: expect.any(Number),
|
seed: expect.any(Number),
|
||||||
@@ -128,6 +154,7 @@ describe("Test Transform", () => {
|
|||||||
];
|
];
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(4);
|
expect(excaldrawElements.length).toBe(4);
|
||||||
@@ -210,6 +237,7 @@ describe("Test Transform", () => {
|
|||||||
];
|
];
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(12);
|
expect(excaldrawElements.length).toBe(12);
|
||||||
@@ -267,6 +295,7 @@ describe("Test Transform", () => {
|
|||||||
];
|
];
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(8);
|
expect(excaldrawElements.length).toBe(8);
|
||||||
@@ -280,6 +309,90 @@ describe("Test Transform", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Test Frames", () => {
|
||||||
|
it("should transform frames and update frame ids when regenerated", () => {
|
||||||
|
const elementsSkeleton: ExcalidrawElementSkeleton[] = [
|
||||||
|
{
|
||||||
|
type: "rectangle",
|
||||||
|
x: 10,
|
||||||
|
y: 10,
|
||||||
|
strokeWidth: 2,
|
||||||
|
id: "1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "diamond",
|
||||||
|
x: 120,
|
||||||
|
y: 20,
|
||||||
|
backgroundColor: "#fff3bf",
|
||||||
|
strokeWidth: 2,
|
||||||
|
label: {
|
||||||
|
text: "HELLO EXCALIDRAW",
|
||||||
|
strokeColor: "#099268",
|
||||||
|
fontSize: 30,
|
||||||
|
},
|
||||||
|
id: "2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "frame",
|
||||||
|
children: ["1", "2"],
|
||||||
|
name: "My frame",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
|
elementsSkeleton,
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
expect(excaldrawElements.length).toBe(4);
|
||||||
|
|
||||||
|
excaldrawElements.forEach((ele) => {
|
||||||
|
expect(ele).toMatchObject({
|
||||||
|
seed: expect.any(Number),
|
||||||
|
versionNonce: expect.any(Number),
|
||||||
|
id: expect.any(String),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should consider max of calculated and frame dimensions when provided", () => {
|
||||||
|
const elementsSkeleton: ExcalidrawElementSkeleton[] = [
|
||||||
|
{
|
||||||
|
type: "rectangle",
|
||||||
|
x: 10,
|
||||||
|
y: 10,
|
||||||
|
strokeWidth: 2,
|
||||||
|
id: "1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "diamond",
|
||||||
|
x: 120,
|
||||||
|
y: 20,
|
||||||
|
backgroundColor: "#fff3bf",
|
||||||
|
strokeWidth: 2,
|
||||||
|
label: {
|
||||||
|
text: "HELLO EXCALIDRAW",
|
||||||
|
strokeColor: "#099268",
|
||||||
|
fontSize: 30,
|
||||||
|
},
|
||||||
|
id: "2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "frame",
|
||||||
|
children: ["1", "2"],
|
||||||
|
name: "My frame",
|
||||||
|
width: 800,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
|
elementsSkeleton,
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
const frame = excaldrawElements.find((ele) => ele.type === "frame")!;
|
||||||
|
expect(frame.width).toBe(800);
|
||||||
|
expect(frame.height).toBe(126);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Test arrow bindings", () => {
|
describe("Test arrow bindings", () => {
|
||||||
it("should bind arrows to shapes when start / end provided without ids", () => {
|
it("should bind arrows to shapes when start / end provided without ids", () => {
|
||||||
const elements = [
|
const elements = [
|
||||||
@@ -300,6 +413,7 @@ describe("Test Transform", () => {
|
|||||||
];
|
];
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(4);
|
expect(excaldrawElements.length).toBe(4);
|
||||||
@@ -321,7 +435,7 @@ describe("Test Transform", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(text).toMatchObject({
|
expect(text).toMatchObject({
|
||||||
x: 340,
|
x: 240,
|
||||||
y: 226.5,
|
y: 226.5,
|
||||||
type: "text",
|
type: "text",
|
||||||
text: "HELLO WORLD!!",
|
text: "HELLO WORLD!!",
|
||||||
@@ -341,7 +455,7 @@ describe("Test Transform", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(ellipse).toMatchObject({
|
expect(ellipse).toMatchObject({
|
||||||
x: 555,
|
x: 355,
|
||||||
y: 189,
|
y: 189,
|
||||||
type: "ellipse",
|
type: "ellipse",
|
||||||
boundElements: [
|
boundElements: [
|
||||||
@@ -383,10 +497,10 @@ describe("Test Transform", () => {
|
|||||||
|
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(4);
|
expect(excaldrawElements.length).toBe(4);
|
||||||
|
|
||||||
const [arrow, text1, text2, text3] = excaldrawElements;
|
const [arrow, text1, text2, text3] = excaldrawElements;
|
||||||
|
|
||||||
expect(arrow).toMatchObject({
|
expect(arrow).toMatchObject({
|
||||||
@@ -406,7 +520,7 @@ describe("Test Transform", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(text1).toMatchObject({
|
expect(text1).toMatchObject({
|
||||||
x: 340,
|
x: 240,
|
||||||
y: 226.5,
|
y: 226.5,
|
||||||
type: "text",
|
type: "text",
|
||||||
text: "HELLO WORLD!!",
|
text: "HELLO WORLD!!",
|
||||||
@@ -426,7 +540,7 @@ describe("Test Transform", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(text3).toMatchObject({
|
expect(text3).toMatchObject({
|
||||||
x: 555,
|
x: 355,
|
||||||
y: 226.5,
|
y: 226.5,
|
||||||
type: "text",
|
type: "text",
|
||||||
boundElements: [
|
boundElements: [
|
||||||
@@ -499,6 +613,7 @@ describe("Test Transform", () => {
|
|||||||
|
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(5);
|
expect(excaldrawElements.length).toBe(5);
|
||||||
@@ -547,6 +662,7 @@ describe("Test Transform", () => {
|
|||||||
|
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(4);
|
expect(excaldrawElements.length).toBe(4);
|
||||||
@@ -600,17 +716,18 @@ describe("Test Transform", () => {
|
|||||||
|
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(4);
|
expect(excaldrawElements.length).toBe(4);
|
||||||
const [, , arrow] = excaldrawElements;
|
const [, , arrow, text] = excaldrawElements;
|
||||||
expect(arrow).toMatchObject({
|
expect(arrow).toMatchObject({
|
||||||
type: "arrow",
|
type: "arrow",
|
||||||
x: 255,
|
x: 255,
|
||||||
y: 239,
|
y: 239,
|
||||||
boundElements: [
|
boundElements: [
|
||||||
{
|
{
|
||||||
id: "id46",
|
id: text.id,
|
||||||
type: "text",
|
type: "text",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -650,17 +767,18 @@ describe("Test Transform", () => {
|
|||||||
];
|
];
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
expect(excaldrawElements.length).toBe(2);
|
expect(excaldrawElements.length).toBe(2);
|
||||||
const [arrow, rect] = excaldrawElements;
|
const [arrow, rect] = excaldrawElements;
|
||||||
expect((arrow as ExcalidrawArrowElement).endBinding).toStrictEqual({
|
expect((arrow as ExcalidrawArrowElement).endBinding).toStrictEqual({
|
||||||
elementId: "rect-1",
|
elementId: "rect-1",
|
||||||
focus: 0,
|
focus: 0,
|
||||||
gap: 5,
|
gap: 205,
|
||||||
});
|
});
|
||||||
expect(rect.boundElements).toStrictEqual([
|
expect(rect.boundElements).toStrictEqual([
|
||||||
{
|
{
|
||||||
id: "id47",
|
id: arrow.id,
|
||||||
type: "arrow",
|
type: "arrow",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@@ -692,6 +810,7 @@ describe("Test Transform", () => {
|
|||||||
];
|
];
|
||||||
const excaldrawElements = convertToExcalidrawElements(
|
const excaldrawElements = convertToExcalidrawElements(
|
||||||
elements as ExcalidrawElementSkeleton[],
|
elements as ExcalidrawElementSkeleton[],
|
||||||
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(excaldrawElements.length).toBe(1);
|
expect(excaldrawElements.length).toBe(1);
|
||||||
|
|||||||
+161
-12
@@ -5,6 +5,7 @@ import {
|
|||||||
VERTICAL_ALIGN,
|
VERTICAL_ALIGN,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import {
|
import {
|
||||||
|
getCommonBounds,
|
||||||
newElement,
|
newElement,
|
||||||
newLinearElement,
|
newLinearElement,
|
||||||
redrawTextBoundingBox,
|
redrawTextBoundingBox,
|
||||||
@@ -12,6 +13,7 @@ import {
|
|||||||
import { bindLinearElement } from "../element/binding";
|
import { bindLinearElement } from "../element/binding";
|
||||||
import {
|
import {
|
||||||
ElementConstructorOpts,
|
ElementConstructorOpts,
|
||||||
|
newFrameElement,
|
||||||
newImageElement,
|
newImageElement,
|
||||||
newTextElement,
|
newTextElement,
|
||||||
} from "../element/newElement";
|
} from "../element/newElement";
|
||||||
@@ -38,7 +40,9 @@ import {
|
|||||||
VerticalAlign,
|
VerticalAlign,
|
||||||
} from "../element/types";
|
} from "../element/types";
|
||||||
import { MarkOptional } from "../utility-types";
|
import { MarkOptional } from "../utility-types";
|
||||||
import { assertNever, getFontString } from "../utils";
|
import { assertNever, cloneJSON, getFontString } from "../utils";
|
||||||
|
import { getSizeFromPoints } from "../points";
|
||||||
|
import { randomId } from "../random";
|
||||||
|
|
||||||
export type ValidLinearElement = {
|
export type ValidLinearElement = {
|
||||||
type: "arrow" | "line";
|
type: "arrow" | "line";
|
||||||
@@ -133,9 +137,7 @@ export type ValidContainer =
|
|||||||
export type ExcalidrawElementSkeleton =
|
export type ExcalidrawElementSkeleton =
|
||||||
| Extract<
|
| Extract<
|
||||||
Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
||||||
| ExcalidrawEmbeddableElement
|
ExcalidrawEmbeddableElement | ExcalidrawFreeDrawElement
|
||||||
| ExcalidrawFreeDrawElement
|
|
||||||
| ExcalidrawFrameElement
|
|
||||||
>
|
>
|
||||||
| ({
|
| ({
|
||||||
type: Extract<ExcalidrawLinearElement["type"], "line">;
|
type: Extract<ExcalidrawLinearElement["type"], "line">;
|
||||||
@@ -156,10 +158,15 @@ export type ExcalidrawElementSkeleton =
|
|||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
fileId: FileId;
|
fileId: FileId;
|
||||||
} & Partial<ExcalidrawImageElement>);
|
} & Partial<ExcalidrawImageElement>)
|
||||||
|
| ({
|
||||||
|
type: "frame";
|
||||||
|
children: readonly ExcalidrawElement["id"][];
|
||||||
|
name?: string;
|
||||||
|
} & Partial<ExcalidrawFrameElement>);
|
||||||
|
|
||||||
const DEFAULT_LINEAR_ELEMENT_PROPS = {
|
const DEFAULT_LINEAR_ELEMENT_PROPS = {
|
||||||
width: 300,
|
width: 100,
|
||||||
height: 0,
|
height: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -357,6 +364,49 @@ const bindLinearElementToElement = (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update start/end points by 0.5 so bindings don't overlap with start/end bound element coordinates.
|
||||||
|
const endPointIndex = linearElement.points.length - 1;
|
||||||
|
const delta = 0.5;
|
||||||
|
|
||||||
|
const newPoints = cloneJSON(linearElement.points) as [number, number][];
|
||||||
|
// left to right so shift the arrow towards right
|
||||||
|
if (
|
||||||
|
linearElement.points[endPointIndex][0] >
|
||||||
|
linearElement.points[endPointIndex - 1][0]
|
||||||
|
) {
|
||||||
|
newPoints[0][0] = delta;
|
||||||
|
newPoints[endPointIndex][0] -= delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
// right to left so shift the arrow towards left
|
||||||
|
if (
|
||||||
|
linearElement.points[endPointIndex][0] <
|
||||||
|
linearElement.points[endPointIndex - 1][0]
|
||||||
|
) {
|
||||||
|
newPoints[0][0] = -delta;
|
||||||
|
newPoints[endPointIndex][0] += delta;
|
||||||
|
}
|
||||||
|
// top to bottom so shift the arrow towards top
|
||||||
|
if (
|
||||||
|
linearElement.points[endPointIndex][1] >
|
||||||
|
linearElement.points[endPointIndex - 1][1]
|
||||||
|
) {
|
||||||
|
newPoints[0][1] = delta;
|
||||||
|
newPoints[endPointIndex][1] -= delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
// bottom to top so shift the arrow towards bottom
|
||||||
|
if (
|
||||||
|
linearElement.points[endPointIndex][1] <
|
||||||
|
linearElement.points[endPointIndex - 1][1]
|
||||||
|
) {
|
||||||
|
newPoints[0][1] = -delta;
|
||||||
|
newPoints[endPointIndex][1] += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(linearElement, { points: newPoints });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
linearElement,
|
linearElement,
|
||||||
startBoundElement,
|
startBoundElement,
|
||||||
@@ -384,18 +434,25 @@ class ElementStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const convertToExcalidrawElements = (
|
export const convertToExcalidrawElements = (
|
||||||
elements: ExcalidrawElementSkeleton[] | null,
|
elementsSkeleton: ExcalidrawElementSkeleton[] | null,
|
||||||
|
opts?: { regenerateIds: boolean },
|
||||||
) => {
|
) => {
|
||||||
if (!elements) {
|
if (!elementsSkeleton) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
const elements = cloneJSON(elementsSkeleton);
|
||||||
const elementStore = new ElementStore();
|
const elementStore = new ElementStore();
|
||||||
const elementsWithIds = new Map<string, ExcalidrawElementSkeleton>();
|
const elementsWithIds = new Map<string, ExcalidrawElementSkeleton>();
|
||||||
|
const oldToNewElementIdMap = new Map<string, string>();
|
||||||
|
|
||||||
// Create individual elements
|
// Create individual elements
|
||||||
for (const element of elements) {
|
for (const element of elements) {
|
||||||
let excalidrawElement: ExcalidrawElement;
|
let excalidrawElement: ExcalidrawElement;
|
||||||
|
const originalId = element.id;
|
||||||
|
if (opts?.regenerateIds !== false) {
|
||||||
|
Object.assign(element, { id: randomId() });
|
||||||
|
}
|
||||||
|
|
||||||
switch (element.type) {
|
switch (element.type) {
|
||||||
case "rectangle":
|
case "rectangle":
|
||||||
case "ellipse":
|
case "ellipse":
|
||||||
@@ -444,6 +501,11 @@ export const convertToExcalidrawElements = (
|
|||||||
],
|
],
|
||||||
...element,
|
...element,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Object.assign(
|
||||||
|
excalidrawElement,
|
||||||
|
getSizeFromPoints(excalidrawElement.points),
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "text": {
|
case "text": {
|
||||||
@@ -477,8 +539,15 @@ export const convertToExcalidrawElements = (
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "frame": {
|
||||||
|
excalidrawElement = newFrameElement({
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
...element,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "freedraw":
|
case "freedraw":
|
||||||
case "frame":
|
|
||||||
case "embeddable": {
|
case "embeddable": {
|
||||||
excalidrawElement = element;
|
excalidrawElement = element;
|
||||||
break;
|
break;
|
||||||
@@ -499,6 +568,9 @@ export const convertToExcalidrawElements = (
|
|||||||
} else {
|
} else {
|
||||||
elementStore.add(excalidrawElement);
|
elementStore.add(excalidrawElement);
|
||||||
elementsWithIds.set(excalidrawElement.id, element);
|
elementsWithIds.set(excalidrawElement.id, element);
|
||||||
|
if (originalId) {
|
||||||
|
oldToNewElementIdMap.set(originalId, excalidrawElement.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,6 +596,18 @@ export const convertToExcalidrawElements = (
|
|||||||
element.type === "arrow" ? element?.start : undefined;
|
element.type === "arrow" ? element?.start : undefined;
|
||||||
const originalEnd =
|
const originalEnd =
|
||||||
element.type === "arrow" ? element?.end : undefined;
|
element.type === "arrow" ? element?.end : undefined;
|
||||||
|
if (originalStart && originalStart.id) {
|
||||||
|
const newStartId = oldToNewElementIdMap.get(originalStart.id);
|
||||||
|
if (newStartId) {
|
||||||
|
Object.assign(originalStart, { id: newStartId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (originalEnd && originalEnd.id) {
|
||||||
|
const newEndId = oldToNewElementIdMap.get(originalEnd.id);
|
||||||
|
if (newEndId) {
|
||||||
|
Object.assign(originalEnd, { id: newEndId });
|
||||||
|
}
|
||||||
|
}
|
||||||
const { linearElement, startBoundElement, endBoundElement } =
|
const { linearElement, startBoundElement, endBoundElement } =
|
||||||
bindLinearElementToElement(
|
bindLinearElementToElement(
|
||||||
container as ExcalidrawArrowElement,
|
container as ExcalidrawArrowElement,
|
||||||
@@ -539,13 +623,23 @@ export const convertToExcalidrawElements = (
|
|||||||
} else {
|
} else {
|
||||||
switch (element.type) {
|
switch (element.type) {
|
||||||
case "arrow": {
|
case "arrow": {
|
||||||
|
const { start, end } = element;
|
||||||
|
if (start && start.id) {
|
||||||
|
const newStartId = oldToNewElementIdMap.get(start.id);
|
||||||
|
Object.assign(start, { id: newStartId });
|
||||||
|
}
|
||||||
|
if (end && end.id) {
|
||||||
|
const newEndId = oldToNewElementIdMap.get(end.id);
|
||||||
|
Object.assign(end, { id: newEndId });
|
||||||
|
}
|
||||||
const { linearElement, startBoundElement, endBoundElement } =
|
const { linearElement, startBoundElement, endBoundElement } =
|
||||||
bindLinearElementToElement(
|
bindLinearElementToElement(
|
||||||
excalidrawElement as ExcalidrawArrowElement,
|
excalidrawElement as ExcalidrawArrowElement,
|
||||||
element.start,
|
start,
|
||||||
element.end,
|
end,
|
||||||
elementStore,
|
elementStore,
|
||||||
);
|
);
|
||||||
|
|
||||||
elementStore.add(linearElement);
|
elementStore.add(linearElement);
|
||||||
elementStore.add(startBoundElement);
|
elementStore.add(startBoundElement);
|
||||||
elementStore.add(endBoundElement);
|
elementStore.add(endBoundElement);
|
||||||
@@ -557,5 +651,60 @@ export const convertToExcalidrawElements = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Once all the excalidraw elements are created, we can add frames since we
|
||||||
|
// need to calculate coordinates and dimensions of frame which is possibe after all
|
||||||
|
// frame children are processed.
|
||||||
|
for (const [id, element] of elementsWithIds) {
|
||||||
|
if (element.type !== "frame") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const frame = elementStore.getElement(id);
|
||||||
|
|
||||||
|
if (!frame) {
|
||||||
|
throw new Error(`Excalidraw element with id ${id} doesn't exist`);
|
||||||
|
}
|
||||||
|
const childrenElements: ExcalidrawElement[] = [];
|
||||||
|
|
||||||
|
element.children.forEach((id) => {
|
||||||
|
const newElementId = oldToNewElementIdMap.get(id);
|
||||||
|
if (!newElementId) {
|
||||||
|
throw new Error(`Element with ${id} wasn't mapped correctly`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const elementInFrame = elementStore.getElement(newElementId);
|
||||||
|
if (!elementInFrame) {
|
||||||
|
throw new Error(`Frame element with id ${newElementId} doesn't exist`);
|
||||||
|
}
|
||||||
|
Object.assign(elementInFrame, { frameId: frame.id });
|
||||||
|
|
||||||
|
elementInFrame?.boundElements?.forEach((boundElement) => {
|
||||||
|
const ele = elementStore.getElement(boundElement.id);
|
||||||
|
if (!ele) {
|
||||||
|
throw new Error(
|
||||||
|
`Bound element with id ${boundElement.id} doesn't exist`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Object.assign(ele, { frameId: frame.id });
|
||||||
|
childrenElements.push(ele);
|
||||||
|
});
|
||||||
|
|
||||||
|
childrenElements.push(elementInFrame);
|
||||||
|
});
|
||||||
|
|
||||||
|
let [minX, minY, maxX, maxY] = getCommonBounds(childrenElements);
|
||||||
|
|
||||||
|
const PADDING = 10;
|
||||||
|
minX = minX - PADDING;
|
||||||
|
minY = minY - PADDING;
|
||||||
|
maxX = maxX + PADDING;
|
||||||
|
maxY = maxY + PADDING;
|
||||||
|
|
||||||
|
// Take the max of calculated and provided frame dimensions, whichever is higher
|
||||||
|
const width = Math.max(frame?.width, maxX - minX);
|
||||||
|
const height = Math.max(frame?.height, maxY - minY);
|
||||||
|
Object.assign(frame, { x: minX, y: minY, width, height });
|
||||||
|
}
|
||||||
|
|
||||||
return elementStore.getElements();
|
return elementStore.getElements();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ export const getLinkHandleFromCoords = (
|
|||||||
[x1, y1, x2, y2]: Bounds,
|
[x1, y1, x2, y2]: Bounds,
|
||||||
angle: number,
|
angle: number,
|
||||||
appState: Pick<UIAppState, "zoom">,
|
appState: Pick<UIAppState, "zoom">,
|
||||||
): [x: number, y: number, width: number, height: number] => {
|
): Bounds => {
|
||||||
const size = DEFAULT_LINK_SIZE;
|
const size = DEFAULT_LINK_SIZE;
|
||||||
const linkWidth = size / appState.zoom.value;
|
const linkWidth = size / appState.zoom.value;
|
||||||
const linkHeight = size / appState.zoom.value;
|
const linkHeight = size / appState.zoom.value;
|
||||||
|
|||||||
+16
-16
@@ -34,7 +34,12 @@ export type RectangleBox = {
|
|||||||
type MaybeQuadraticSolution = [number | null, number | null] | false;
|
type MaybeQuadraticSolution = [number | null, number | null] | false;
|
||||||
|
|
||||||
// x and y position of top left corner, x and y position of bottom right corner
|
// x and y position of top left corner, x and y position of bottom right corner
|
||||||
export type Bounds = readonly [x1: number, y1: number, x2: number, y2: number];
|
export type Bounds = readonly [
|
||||||
|
minX: number,
|
||||||
|
minY: number,
|
||||||
|
maxX: number,
|
||||||
|
maxY: number,
|
||||||
|
];
|
||||||
|
|
||||||
export class ElementBounds {
|
export class ElementBounds {
|
||||||
private static boundsCache = new WeakMap<
|
private static boundsCache = new WeakMap<
|
||||||
@@ -63,7 +68,7 @@ export class ElementBounds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static calculateBounds(element: ExcalidrawElement): Bounds {
|
private static calculateBounds(element: ExcalidrawElement): Bounds {
|
||||||
let bounds: [number, number, number, number];
|
let bounds: Bounds;
|
||||||
|
|
||||||
const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(element);
|
const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(element);
|
||||||
|
|
||||||
@@ -387,7 +392,7 @@ const getCubicBezierCurveBound = (
|
|||||||
export const getMinMaxXYFromCurvePathOps = (
|
export const getMinMaxXYFromCurvePathOps = (
|
||||||
ops: Op[],
|
ops: Op[],
|
||||||
transformXY?: (x: number, y: number) => [number, number],
|
transformXY?: (x: number, y: number) => [number, number],
|
||||||
): [number, number, number, number] => {
|
): Bounds => {
|
||||||
let currentP: Point = [0, 0];
|
let currentP: Point = [0, 0];
|
||||||
|
|
||||||
const { minX, minY, maxX, maxY } = ops.reduce(
|
const { minX, minY, maxX, maxY } = ops.reduce(
|
||||||
@@ -435,9 +440,9 @@ export const getMinMaxXYFromCurvePathOps = (
|
|||||||
return [minX, minY, maxX, maxY];
|
return [minX, minY, maxX, maxY];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getBoundsFromPoints = (
|
export const getBoundsFromPoints = (
|
||||||
points: ExcalidrawFreeDrawElement["points"],
|
points: ExcalidrawFreeDrawElement["points"],
|
||||||
): [number, number, number, number] => {
|
): Bounds => {
|
||||||
let minX = Infinity;
|
let minX = Infinity;
|
||||||
let minY = Infinity;
|
let minY = Infinity;
|
||||||
let maxX = -Infinity;
|
let maxX = -Infinity;
|
||||||
@@ -589,7 +594,7 @@ const getLinearElementRotatedBounds = (
|
|||||||
element: ExcalidrawLinearElement,
|
element: ExcalidrawLinearElement,
|
||||||
cx: number,
|
cx: number,
|
||||||
cy: number,
|
cy: number,
|
||||||
): [number, number, number, number] => {
|
): Bounds => {
|
||||||
if (element.points.length < 2) {
|
if (element.points.length < 2) {
|
||||||
const [pointX, pointY] = element.points[0];
|
const [pointX, pointY] = element.points[0];
|
||||||
const [x, y] = rotate(
|
const [x, y] = rotate(
|
||||||
@@ -600,7 +605,7 @@ const getLinearElementRotatedBounds = (
|
|||||||
element.angle,
|
element.angle,
|
||||||
);
|
);
|
||||||
|
|
||||||
let coords: [number, number, number, number] = [x, y, x, y];
|
let coords: Bounds = [x, y, x, y];
|
||||||
const boundTextElement = getBoundTextElement(element);
|
const boundTextElement = getBoundTextElement(element);
|
||||||
if (boundTextElement) {
|
if (boundTextElement) {
|
||||||
const coordsWithBoundText = LinearElementEditor.getMinMaxXYWithBoundText(
|
const coordsWithBoundText = LinearElementEditor.getMinMaxXYWithBoundText(
|
||||||
@@ -625,12 +630,7 @@ const getLinearElementRotatedBounds = (
|
|||||||
const transformXY = (x: number, y: number) =>
|
const transformXY = (x: number, y: number) =>
|
||||||
rotate(element.x + x, element.y + y, cx, cy, element.angle);
|
rotate(element.x + x, element.y + y, cx, cy, element.angle);
|
||||||
const res = getMinMaxXYFromCurvePathOps(ops, transformXY);
|
const res = getMinMaxXYFromCurvePathOps(ops, transformXY);
|
||||||
let coords: [number, number, number, number] = [
|
let coords: Bounds = [res[0], res[1], res[2], res[3]];
|
||||||
res[0],
|
|
||||||
res[1],
|
|
||||||
res[2],
|
|
||||||
res[3],
|
|
||||||
];
|
|
||||||
const boundTextElement = getBoundTextElement(element);
|
const boundTextElement = getBoundTextElement(element);
|
||||||
if (boundTextElement) {
|
if (boundTextElement) {
|
||||||
const coordsWithBoundText = LinearElementEditor.getMinMaxXYWithBoundText(
|
const coordsWithBoundText = LinearElementEditor.getMinMaxXYWithBoundText(
|
||||||
@@ -692,7 +692,7 @@ export const getResizedElementAbsoluteCoords = (
|
|||||||
nextWidth: number,
|
nextWidth: number,
|
||||||
nextHeight: number,
|
nextHeight: number,
|
||||||
normalizePoints: boolean,
|
normalizePoints: boolean,
|
||||||
): [number, number, number, number] => {
|
): Bounds => {
|
||||||
if (!(isLinearElement(element) || isFreeDrawElement(element))) {
|
if (!(isLinearElement(element) || isFreeDrawElement(element))) {
|
||||||
return [
|
return [
|
||||||
element.x,
|
element.x,
|
||||||
@@ -709,7 +709,7 @@ export const getResizedElementAbsoluteCoords = (
|
|||||||
normalizePoints,
|
normalizePoints,
|
||||||
);
|
);
|
||||||
|
|
||||||
let bounds: [number, number, number, number];
|
let bounds: Bounds;
|
||||||
|
|
||||||
if (isFreeDrawElement(element)) {
|
if (isFreeDrawElement(element)) {
|
||||||
// Free Draw
|
// Free Draw
|
||||||
@@ -740,7 +740,7 @@ export const getResizedElementAbsoluteCoords = (
|
|||||||
export const getElementPointsCoords = (
|
export const getElementPointsCoords = (
|
||||||
element: ExcalidrawLinearElement,
|
element: ExcalidrawLinearElement,
|
||||||
points: readonly (readonly [number, number])[],
|
points: readonly (readonly [number, number])[],
|
||||||
): [number, number, number, number] => {
|
): Bounds => {
|
||||||
// This might be computationally heavey
|
// This might be computationally heavey
|
||||||
const gen = rough.generator();
|
const gen = rough.generator();
|
||||||
const curve =
|
const curve =
|
||||||
|
|||||||
@@ -494,7 +494,9 @@ const hitTestFreeDrawElement = (
|
|||||||
// for filled freedraw shapes, support
|
// for filled freedraw shapes, support
|
||||||
// selecting from inside
|
// selecting from inside
|
||||||
if (shape && shape.sets.length) {
|
if (shape && shape.sets.length) {
|
||||||
return hitTestRoughShape(shape, x, y, threshold);
|
return element.fillStyle === "solid"
|
||||||
|
? hitTestCurveInside(shape, x, y, "round")
|
||||||
|
: hitTestRoughShape(shape, x, y, threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+51
-37
@@ -1,5 +1,5 @@
|
|||||||
import { updateBoundElements } from "./binding";
|
import { updateBoundElements } from "./binding";
|
||||||
import { getCommonBounds } from "./bounds";
|
import { Bounds, getCommonBounds } from "./bounds";
|
||||||
import { mutateElement } from "./mutateElement";
|
import { mutateElement } from "./mutateElement";
|
||||||
import { getPerfectElementSize } from "./sizeHelpers";
|
import { getPerfectElementSize } from "./sizeHelpers";
|
||||||
import { NonDeletedExcalidrawElement } from "./types";
|
import { NonDeletedExcalidrawElement } from "./types";
|
||||||
@@ -8,7 +8,11 @@ import { getBoundTextElement } from "./textElement";
|
|||||||
import { isSelectedViaGroup } from "../groups";
|
import { isSelectedViaGroup } from "../groups";
|
||||||
import { getGridPoint } from "../math";
|
import { getGridPoint } from "../math";
|
||||||
import Scene from "../scene/Scene";
|
import Scene from "../scene/Scene";
|
||||||
import { isFrameElement } from "./typeChecks";
|
import {
|
||||||
|
isArrowElement,
|
||||||
|
isBoundToContainer,
|
||||||
|
isFrameElement,
|
||||||
|
} from "./typeChecks";
|
||||||
|
|
||||||
export const dragSelectedElements = (
|
export const dragSelectedElements = (
|
||||||
pointerDownState: PointerDownState,
|
pointerDownState: PointerDownState,
|
||||||
@@ -35,44 +39,41 @@ export const dragSelectedElements = (
|
|||||||
if (frames.length > 0) {
|
if (frames.length > 0) {
|
||||||
const elementsInFrames = scene
|
const elementsInFrames = scene
|
||||||
.getNonDeletedElements()
|
.getNonDeletedElements()
|
||||||
|
.filter((e) => !isBoundToContainer(e))
|
||||||
.filter((e) => e.frameId !== null)
|
.filter((e) => e.frameId !== null)
|
||||||
.filter((e) => frames.includes(e.frameId!));
|
.filter((e) => frames.includes(e.frameId!));
|
||||||
|
|
||||||
elementsInFrames.forEach((element) => elementsToUpdate.add(element));
|
elementsInFrames.forEach((element) => elementsToUpdate.add(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commonBounds = getCommonBounds(
|
||||||
|
Array.from(elementsToUpdate).map(
|
||||||
|
(el) => pointerDownState.originalElements.get(el.id) ?? el,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const adjustedOffset = calculateOffset(
|
||||||
|
commonBounds,
|
||||||
|
offset,
|
||||||
|
snapOffset,
|
||||||
|
gridSize,
|
||||||
|
);
|
||||||
|
|
||||||
elementsToUpdate.forEach((element) => {
|
elementsToUpdate.forEach((element) => {
|
||||||
updateElementCoords(
|
updateElementCoords(pointerDownState, element, adjustedOffset);
|
||||||
pointerDownState,
|
|
||||||
element,
|
|
||||||
offset,
|
|
||||||
snapOffset,
|
|
||||||
gridSize,
|
|
||||||
);
|
|
||||||
// update coords of bound text only if we're dragging the container directly
|
// update coords of bound text only if we're dragging the container directly
|
||||||
// (we don't drag the group that it's part of)
|
// (we don't drag the group that it's part of)
|
||||||
if (
|
if (
|
||||||
|
// Don't update coords of arrow label since we calculate its position during render
|
||||||
|
!isArrowElement(element) &&
|
||||||
// container isn't part of any group
|
// container isn't part of any group
|
||||||
// (perf optim so we don't check `isSelectedViaGroup()` in every case)
|
// (perf optim so we don't check `isSelectedViaGroup()` in every case)
|
||||||
!element.groupIds.length ||
|
(!element.groupIds.length ||
|
||||||
// container is part of a group, but we're dragging the container directly
|
// container is part of a group, but we're dragging the container directly
|
||||||
(appState.editingGroupId && !isSelectedViaGroup(appState, element))
|
(appState.editingGroupId && !isSelectedViaGroup(appState, element)))
|
||||||
) {
|
) {
|
||||||
const textElement = getBoundTextElement(element);
|
const textElement = getBoundTextElement(element);
|
||||||
if (
|
if (textElement) {
|
||||||
textElement &&
|
updateElementCoords(pointerDownState, textElement, adjustedOffset);
|
||||||
// when container is added to a frame, so will its bound text
|
|
||||||
// so the text is already in `elementsToUpdate` and we should avoid
|
|
||||||
// updating its coords again
|
|
||||||
(!textElement.frameId || !frames.includes(textElement.frameId))
|
|
||||||
) {
|
|
||||||
updateElementCoords(
|
|
||||||
pointerDownState,
|
|
||||||
textElement,
|
|
||||||
offset,
|
|
||||||
snapOffset,
|
|
||||||
gridSize,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateBoundElements(element, {
|
updateBoundElements(element, {
|
||||||
@@ -81,23 +82,20 @@ export const dragSelectedElements = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateElementCoords = (
|
const calculateOffset = (
|
||||||
pointerDownState: PointerDownState,
|
commonBounds: Bounds,
|
||||||
element: NonDeletedExcalidrawElement,
|
|
||||||
dragOffset: { x: number; y: number },
|
dragOffset: { x: number; y: number },
|
||||||
snapOffset: { x: number; y: number },
|
snapOffset: { x: number; y: number },
|
||||||
gridSize: AppState["gridSize"],
|
gridSize: AppState["gridSize"],
|
||||||
) => {
|
): { x: number; y: number } => {
|
||||||
const originalElement =
|
const [x, y] = commonBounds;
|
||||||
pointerDownState.originalElements.get(element.id) ?? element;
|
let nextX = x + dragOffset.x + snapOffset.x;
|
||||||
|
let nextY = y + dragOffset.y + snapOffset.y;
|
||||||
let nextX = originalElement.x + dragOffset.x + snapOffset.x;
|
|
||||||
let nextY = originalElement.y + dragOffset.y + snapOffset.y;
|
|
||||||
|
|
||||||
if (snapOffset.x === 0 || snapOffset.y === 0) {
|
if (snapOffset.x === 0 || snapOffset.y === 0) {
|
||||||
const [nextGridX, nextGridY] = getGridPoint(
|
const [nextGridX, nextGridY] = getGridPoint(
|
||||||
originalElement.x + dragOffset.x,
|
x + dragOffset.x,
|
||||||
originalElement.y + dragOffset.y,
|
y + dragOffset.y,
|
||||||
gridSize,
|
gridSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -109,6 +107,22 @@ const updateElementCoords = (
|
|||||||
nextY = nextGridY;
|
nextY = nextGridY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
x: nextX - x,
|
||||||
|
y: nextY - y,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateElementCoords = (
|
||||||
|
pointerDownState: PointerDownState,
|
||||||
|
element: NonDeletedExcalidrawElement,
|
||||||
|
dragOffset: { x: number; y: number },
|
||||||
|
) => {
|
||||||
|
const originalElement =
|
||||||
|
pointerDownState.originalElements.get(element.id) ?? element;
|
||||||
|
|
||||||
|
const nextX = originalElement.x + dragOffset.x;
|
||||||
|
const nextY = originalElement.y + dragOffset.y;
|
||||||
|
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
x: nextX,
|
x: nextX,
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { register } from "../actions/register";
|
|||||||
import { FONT_FAMILY, VERTICAL_ALIGN } from "../constants";
|
import { FONT_FAMILY, VERTICAL_ALIGN } from "../constants";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { ExcalidrawProps } from "../types";
|
import { ExcalidrawProps } from "../types";
|
||||||
import { getFontString, setCursorForShape, updateActiveTool } from "../utils";
|
import { getFontString, updateActiveTool } from "../utils";
|
||||||
|
import { setCursorForShape } from "../cursor";
|
||||||
import { newTextElement } from "./newElement";
|
import { newTextElement } from "./newElement";
|
||||||
import { getContainerElement, wrapText } from "./textElement";
|
import { getContainerElement, wrapText } from "./textElement";
|
||||||
import { isEmbeddableElement } from "./typeChecks";
|
import { isEmbeddableElement } from "./typeChecks";
|
||||||
@@ -27,6 +28,7 @@ const embeddedLinkCache = new Map<string, EmbeddedLink>();
|
|||||||
|
|
||||||
const RE_YOUTUBE =
|
const RE_YOUTUBE =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
|
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
|
||||||
|
|
||||||
const RE_VIMEO =
|
const RE_VIMEO =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
||||||
const RE_FIGMA = /^https:\/\/(?:www\.)?figma\.com/;
|
const RE_FIGMA = /^https:\/\/(?:www\.)?figma\.com/;
|
||||||
@@ -46,6 +48,9 @@ const RE_VALTOWN =
|
|||||||
const RE_GENERIC_EMBED =
|
const RE_GENERIC_EMBED =
|
||||||
/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i;
|
/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i;
|
||||||
|
|
||||||
|
const RE_GIPHY =
|
||||||
|
/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/;
|
||||||
|
|
||||||
const ALLOWED_DOMAINS = new Set([
|
const ALLOWED_DOMAINS = new Set([
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
"youtu.be",
|
"youtu.be",
|
||||||
@@ -58,6 +63,8 @@ const ALLOWED_DOMAINS = new Set([
|
|||||||
"*.simplepdf.eu",
|
"*.simplepdf.eu",
|
||||||
"stackblitz.com",
|
"stackblitz.com",
|
||||||
"val.town",
|
"val.town",
|
||||||
|
"giphy.com",
|
||||||
|
"dddice.com",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const createSrcDoc = (body: string) => {
|
const createSrcDoc = (body: string) => {
|
||||||
@@ -194,7 +201,7 @@ export const getEmbedLink = (link: string | null | undefined): EmbeddedLink => {
|
|||||||
return { link, aspectRatio, type };
|
return { link, aspectRatio, type };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isEmbeddableOrFrameLabel = (
|
export const isEmbeddableOrLabel = (
|
||||||
element: NonDeletedExcalidrawElement,
|
element: NonDeletedExcalidrawElement,
|
||||||
): Boolean => {
|
): Boolean => {
|
||||||
if (isEmbeddableElement(element)) {
|
if (isEmbeddableElement(element)) {
|
||||||
@@ -307,6 +314,10 @@ export const extractSrc = (htmlString: string): string => {
|
|||||||
return gistMatch[1];
|
return gistMatch[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RE_GIPHY.test(htmlString)) {
|
||||||
|
return `https://giphy.com/embed/${RE_GIPHY.exec(htmlString)![1]}`;
|
||||||
|
}
|
||||||
|
|
||||||
const match = htmlString.match(RE_GENERIC_EMBED);
|
const match = htmlString.match(RE_GENERIC_EMBED);
|
||||||
if (match && match.length === 2) {
|
if (match && match.length === 2) {
|
||||||
return match[1];
|
return match[1];
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user