@lofcz/platejs-excalidraw 52.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Ziad Beyens, Dylan Schiemann, Joe Anderson, Felix Feng
4
+
5
+ Unless otherwise specified in a LICENSE file within an individual package directory,
6
+ this license applies to all files in this repository outside of those package directories.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Plate excalidraw plugin
2
+
3
+ This package implements the excalidraw plugin for Plate.
4
+
5
+ ## Documentation
6
+
7
+ Check out
8
+ [Excalidraw](https://platejs.org/docs/excalidraw).
9
+
10
+ ## License
11
+
12
+ [MIT](../../LICENSE)
@@ -0,0 +1,15 @@
1
+ import { KEYS, createSlatePlugin } from "platejs";
2
+
3
+ //#region src/lib/BaseExcalidrawPlugin.ts
4
+ /** Enables support for Excalidraw drawing tool within a Slate document */
5
+ const BaseExcalidrawPlugin = createSlatePlugin({
6
+ key: KEYS.excalidraw,
7
+ node: {
8
+ isElement: true,
9
+ isVoid: true
10
+ }
11
+ });
12
+
13
+ //#endregion
14
+ export { BaseExcalidrawPlugin as t };
15
+ //# sourceMappingURL=BaseExcalidrawPlugin-oKI6R2oh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseExcalidrawPlugin-oKI6R2oh.js","names":["TElement","createSlatePlugin","KEYS","ExcalidrawDataState","TExcalidrawElement","data","elements","state","BaseExcalidrawPlugin","key","excalidraw","node","isElement","isVoid"],"sources":["../src/lib/BaseExcalidrawPlugin.ts"],"sourcesContent":["import { type TElement, createSlatePlugin, KEYS } from 'platejs';\n\nimport type { ExcalidrawDataState } from './types';\n\nexport interface TExcalidrawElement extends TElement {\n data?: {\n elements: ExcalidrawDataState['elements'];\n state: ExcalidrawDataState['appState'];\n } | null;\n}\n\n/** Enables support for Excalidraw drawing tool within a Slate document */\nexport const BaseExcalidrawPlugin = createSlatePlugin({\n key: KEYS.excalidraw,\n node: { isElement: true, isVoid: true },\n});\n"],"mappings":";;;;AAYA,MAAaQ,uBAAuBP,kBAAkB;CACpDQ,KAAKP,KAAKQ;CACVC,MAAM;EAAEC,WAAW;EAAMC,QAAQ;EAAK;CACvC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { InsertNodesOptions, NodeProps, SlateEditor, TElement } from "platejs";
2
+ import { ImportedDataState } from "@excalidraw/excalidraw/data/types";
3
+ import { ExcalidrawElement } from "@excalidraw/excalidraw/element/types";
4
+
5
+ //#region src/lib/types.d.ts
6
+ interface ExcalidrawDataState extends Omit<ImportedDataState, 'elements'> {
7
+ elements?: readonly Partial<ExcalidrawElement>[] | null;
8
+ }
9
+ //#endregion
10
+ //#region src/lib/BaseExcalidrawPlugin.d.ts
11
+ interface TExcalidrawElement extends TElement {
12
+ data?: {
13
+ elements: ExcalidrawDataState['elements'];
14
+ state: ExcalidrawDataState['appState'];
15
+ } | null;
16
+ }
17
+ /** Enables support for Excalidraw drawing tool within a Slate document */
18
+ declare const BaseExcalidrawPlugin: any;
19
+ //#endregion
20
+ //#region src/lib/transforms/insertExcalidraw.d.ts
21
+ declare const insertExcalidraw: (editor: SlateEditor, props?: NodeProps<TExcalidrawElement>, options?: InsertNodesOptions) => void;
22
+ //#endregion
23
+ export { ExcalidrawDataState as i, BaseExcalidrawPlugin as n, TExcalidrawElement as r, insertExcalidraw as t };
24
+ //# sourceMappingURL=index-B5LkMtZs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-B5LkMtZs.d.ts","names":[],"sources":["../src/lib/types.ts","../src/lib/BaseExcalidrawPlugin.ts","../src/lib/transforms/insertExcalidraw.ts"],"sourcesContent":[],"mappings":";;;;;UAGiB,mBAAA,SACP,KAAK;sBACO,QAAQ;;;;UCDb,kBAAA,SAA2B;;cAE9B;IDHG,KAAA,ECIN,mBDHT,CAAA,UAAA,CAAA;EAAa,CAAA,GAAA,IAAA;;;AAAL,cCQG,oBDRH,EAAA,GAAA;;;cEEG,2BACH,qBACD,UAAU,+BACR"}
@@ -0,0 +1,2 @@
1
+ import { i as ExcalidrawDataState, n as BaseExcalidrawPlugin, r as TExcalidrawElement, t as insertExcalidraw } from "./index-B5LkMtZs";
2
+ export { BaseExcalidrawPlugin, ExcalidrawDataState, TExcalidrawElement, insertExcalidraw };
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import { t as BaseExcalidrawPlugin } from "./BaseExcalidrawPlugin-oKI6R2oh.js";
2
+ import { KEYS } from "platejs";
3
+
4
+ //#region src/lib/transforms/insertExcalidraw.ts
5
+ const insertExcalidraw = (editor, props = {}, options = {}) => {
6
+ if (!editor.selection) return;
7
+ const selectionParentEntry = editor.api.parent(editor.selection);
8
+ if (!selectionParentEntry) return;
9
+ const [, path] = selectionParentEntry;
10
+ editor.tf.insertNodes({
11
+ children: [{ text: "" }],
12
+ type: editor.getType(KEYS.excalidraw),
13
+ ...props
14
+ }, {
15
+ at: path,
16
+ nextBlock: true,
17
+ ...options
18
+ });
19
+ };
20
+
21
+ //#endregion
22
+ export { BaseExcalidrawPlugin, insertExcalidraw };
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["InsertNodesOptions","NodeProps","SlateEditor","KEYS","TExcalidrawElement","insertExcalidraw","editor","props","options","selection","selectionParentEntry","api","parent","path","tf","insertNodes","children","text","type","getType","excalidraw","at","nextBlock"],"sources":["../src/lib/transforms/insertExcalidraw.ts"],"sourcesContent":["import type { InsertNodesOptions, NodeProps, SlateEditor } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nimport type { TExcalidrawElement } from '../BaseExcalidrawPlugin';\n\nexport const insertExcalidraw = (\n editor: SlateEditor,\n props: NodeProps<TExcalidrawElement> = {},\n options: InsertNodesOptions = {}\n): void => {\n if (!editor.selection) return;\n\n const selectionParentEntry = editor.api.parent(editor.selection);\n\n if (!selectionParentEntry) return;\n\n const [, path] = selectionParentEntry;\n\n editor.tf.insertNodes<TExcalidrawElement>(\n {\n children: [{ text: '' }],\n type: editor.getType(KEYS.excalidraw),\n ...props,\n },\n { at: path, nextBlock: true, ...(options as any) }\n );\n};\n"],"mappings":";;;;AAMA,MAAaK,oBACXC,QACAC,QAAuC,EAAE,EACzCC,UAA8B,EAAE,KACvB;AACT,KAAI,CAACF,OAAOG,UAAW;CAEvB,MAAMC,uBAAuBJ,OAAOK,IAAIC,OAAON,OAAOG,UAAU;AAEhE,KAAI,CAACC,qBAAsB;CAE3B,MAAM,GAAGG,QAAQH;AAEjBJ,QAAOQ,GAAGC,YACR;EACEC,UAAU,CAAC,EAAEC,MAAM,IAAI,CAAC;EACxBC,MAAMZ,OAAOa,QAAQhB,KAAKiB,WAAW;EACrC,GAAGb;EACJ,EACD;EAAEc,IAAIR;EAAMS,WAAW;EAAM,GAAId;EACnC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { i as ExcalidrawDataState, r as TExcalidrawElement } from "../index-B5LkMtZs";
2
+ import { ExcalidrawProps, LibraryItems } from "@excalidraw/excalidraw/types";
3
+
4
+ //#region src/react/ExcalidrawPlugin.d.ts
5
+ declare const ExcalidrawPlugin: any;
6
+ //#endregion
7
+ //#region src/react/types.d.ts
8
+ interface TExcalidrawProps extends Omit<ExcalidrawProps, 'initialData'> {
9
+ initialData: ExcalidrawDataState | Promise<ExcalidrawDataState | null> | null;
10
+ }
11
+ //#endregion
12
+ //#region src/react/hooks/useExcalidrawElement.d.ts
13
+ declare const useExcalidrawElement: ({
14
+ element,
15
+ libraryItems,
16
+ scrollToContent
17
+ }: {
18
+ element: TExcalidrawElement;
19
+ libraryItems?: LibraryItems;
20
+ scrollToContent?: boolean;
21
+ }) => {
22
+ Excalidraw: any;
23
+ excalidrawProps: TExcalidrawProps;
24
+ };
25
+ //#endregion
26
+ export { ExcalidrawPlugin, TExcalidrawProps, useExcalidrawElement };
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/ExcalidrawPlugin.tsx","../../src/react/types.ts","../../src/react/hooks/useExcalidrawElement.ts"],"sourcesContent":[],"mappings":";;;;cAIa;;;UCCI,gBAAA,SAAyB,KAAK;eAChC,sBAAsB,QAAQ;ADF7C;;;cEWa;;;;;EFXA,OAAA,EEgBF,kBFhBwD;iBEiBlD;;;EDhBA,UAAA,EAAA,GAAA;EAA8B,eAAA,kBAAA;CAChC"}
@@ -0,0 +1,66 @@
1
+ import { t as BaseExcalidrawPlugin } from "../BaseExcalidrawPlugin-oKI6R2oh.js";
2
+ import { toPlatePlugin, useEditorRef, useReadOnly } from "platejs/react";
3
+ import React from "react";
4
+ import { cloneDeep, isEqual } from "lodash";
5
+
6
+ //#region src/react/ExcalidrawPlugin.tsx
7
+ const ExcalidrawPlugin = toPlatePlugin(BaseExcalidrawPlugin);
8
+
9
+ //#endregion
10
+ //#region src/react/hooks/useExcalidrawElement.ts
11
+ const useExcalidrawElement = ({ element, libraryItems = [], scrollToContent = true }) => {
12
+ const [Excalidraw, setExcalidraw] = React.useState(null);
13
+ const editor = useEditorRef();
14
+ const readOnly = useReadOnly();
15
+ const lastSavedDataRef = React.useRef(null);
16
+ React.useEffect(() => {
17
+ import("@excalidraw/excalidraw").then((comp) => setExcalidraw(comp.Excalidraw));
18
+ });
19
+ const _excalidrawRef = React.useRef(null);
20
+ const handleChange = React.useCallback((elements, state) => {
21
+ if (readOnly) return;
22
+ const newData = {
23
+ elements: cloneDeep(elements),
24
+ state: cloneDeep(state)
25
+ };
26
+ if (lastSavedDataRef.current && isEqual(lastSavedDataRef.current, newData)) return;
27
+ try {
28
+ const path = editor.api.findPath(element);
29
+ if (path) {
30
+ lastSavedDataRef.current = newData;
31
+ editor.tf.setNodes({ data: newData }, { at: path });
32
+ }
33
+ } catch (error) {
34
+ console.error("Failed to save Excalidraw data:", error);
35
+ }
36
+ }, [
37
+ editor,
38
+ element,
39
+ readOnly
40
+ ]);
41
+ return {
42
+ Excalidraw,
43
+ excalidrawProps: {
44
+ autoFocus: false,
45
+ initialData: React.useMemo(() => ({
46
+ appState: element.data?.state ? cloneDeep(element.data.state) : void 0,
47
+ elements: element.data?.elements ? cloneDeep(element.data.elements) : [],
48
+ libraryItems: cloneDeep(libraryItems),
49
+ scrollToContent
50
+ }), [
51
+ element.data?.state,
52
+ element.data?.elements,
53
+ libraryItems,
54
+ scrollToContent
55
+ ]),
56
+ excalidrawAPI: (api) => {
57
+ _excalidrawRef.current = api;
58
+ },
59
+ onChange: readOnly ? void 0 : handleChange
60
+ }
61
+ };
62
+ };
63
+
64
+ //#endregion
65
+ export { ExcalidrawPlugin, useExcalidrawElement };
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["toPlatePlugin","BaseExcalidrawPlugin","ExcalidrawPlugin","React","OrderedExcalidrawElement","AppState","ExcalidrawImperativeAPI","LibraryItems","cloneDeep","isEqual","useEditorRef","useReadOnly","TExcalidrawElement","TExcalidrawProps","useExcalidrawElement","element","libraryItems","scrollToContent","Excalidraw","setExcalidraw","useState","editor","readOnly","lastSavedDataRef","useRef","elements","state","useEffect","then","comp","_excalidrawRef","handleChange","useCallback","newData","current","path","api","findPath","tf","setNodes","data","at","error","console","initialData","useMemo","appState","undefined","excalidrawProps","autoFocus","excalidrawAPI","onChange"],"sources":["../../src/react/ExcalidrawPlugin.tsx","../../src/react/hooks/useExcalidrawElement.ts"],"sourcesContent":["import { toPlatePlugin } from 'platejs/react';\n\nimport { BaseExcalidrawPlugin } from '../lib';\n\nexport const ExcalidrawPlugin = toPlatePlugin(BaseExcalidrawPlugin);\n","import React from 'react';\n\nimport type { OrderedExcalidrawElement } from '@excalidraw/excalidraw/element/types';\nimport type {\n AppState,\n ExcalidrawImperativeAPI,\n LibraryItems,\n} from '@excalidraw/excalidraw/types';\n\nimport { cloneDeep, isEqual } from 'lodash';\nimport { useEditorRef, useReadOnly } from 'platejs/react';\n\nimport type { TExcalidrawElement } from '../../lib';\nimport type { TExcalidrawProps } from '../types';\n\nexport const useExcalidrawElement = ({\n element,\n libraryItems = [],\n scrollToContent = true,\n}: {\n element: TExcalidrawElement;\n libraryItems?: LibraryItems;\n scrollToContent?: boolean;\n}) => {\n const [Excalidraw, setExcalidraw] = React.useState<any>(null);\n const editor = useEditorRef();\n const readOnly = useReadOnly();\n\n // Store last saved data for deduplication\n const lastSavedDataRef = React.useRef<{ elements: any; state: any } | null>(\n null\n );\n\n React.useEffect(() => {\n void import('@excalidraw/excalidraw').then((comp) =>\n setExcalidraw(comp.Excalidraw)\n );\n });\n\n const _excalidrawRef = React.useRef<ExcalidrawImperativeAPI>(null);\n\n // Create save function with deduplication only\n const handleChange = React.useCallback(\n (elements: readonly OrderedExcalidrawElement[], state: AppState) => {\n if (readOnly) return;\n\n // Create deep copies to avoid read-only property errors\n const newData = {\n elements: cloneDeep(elements),\n state: cloneDeep(state),\n };\n\n // Use lodash isEqual for deep comparison and deduplication\n if (\n lastSavedDataRef.current &&\n isEqual(lastSavedDataRef.current, newData)\n ) {\n return;\n }\n\n try {\n const path = editor.api.findPath(element);\n if (path) {\n lastSavedDataRef.current = newData;\n editor.tf.setNodes({ data: newData }, { at: path });\n }\n } catch (error) {\n console.error('Failed to save Excalidraw data:', error);\n }\n },\n [editor, element, readOnly]\n );\n\n // Create mutable copies of initial data to ensure Excalidraw can modify them\n const initialData = React.useMemo(\n () => ({\n appState: element.data?.state ? cloneDeep(element.data.state) : undefined,\n elements: element.data?.elements ? cloneDeep(element.data.elements) : [],\n libraryItems: cloneDeep(libraryItems),\n scrollToContent,\n }),\n [element.data?.state, element.data?.elements, libraryItems, scrollToContent]\n );\n\n const excalidrawProps: TExcalidrawProps = {\n autoFocus: false,\n initialData,\n excalidrawAPI: (api) => {\n _excalidrawRef.current = api;\n },\n // Use deduplicated onChange handler without debouncing\n onChange: readOnly ? undefined : handleChange,\n };\n\n return {\n Excalidraw,\n excalidrawProps,\n };\n};\n"],"mappings":";;;;;;AAIA,MAAaE,mBAAmBF,cAAcC,qBAAqB;;;;ACWnE,MAAaa,wBAAwB,EACnCC,SACAC,eAAe,EAAE,EACjBC,kBAAkB,WAKd;CACJ,MAAM,CAACC,YAAYC,iBAAiBhB,MAAMiB,SAAc,KAAK;CAC7D,MAAMC,SAASX,cAAc;CAC7B,MAAMY,WAAWX,aAAa;CAG9B,MAAMY,mBAAmBpB,MAAMqB,OAC7B,KACD;AAEDrB,OAAMwB,gBAAgB;AACpB,EAAK,OAAO,0BAA0BC,MAAMC,SAC1CV,cAAcU,KAAKX,WACrB,CAAC;GACD;CAEF,MAAMY,iBAAiB3B,MAAMqB,OAAgC,KAAK;CAGlE,MAAMO,eAAe5B,MAAM6B,aACxBP,UAA+CC,UAAoB;AAClE,MAAIJ,SAAU;EAGd,MAAMW,UAAU;GACdR,UAAUjB,UAAUiB,SAAS;GAC7BC,OAAOlB,UAAUkB,MAAK;GACvB;AAGD,MACEH,iBAAiBW,WACjBzB,QAAQc,iBAAiBW,SAASD,QAAQ,CAE1C;AAGF,MAAI;GACF,MAAME,OAAOd,OAAOe,IAAIC,SAAStB,QAAQ;AACzC,OAAIoB,MAAM;AACRZ,qBAAiBW,UAAUD;AAC3BZ,WAAOiB,GAAGC,SAAS,EAAEC,MAAMP,SAAS,EAAE,EAAEQ,IAAIN,MAAM,CAAC;;WAE9CO,OAAO;AACdC,WAAQD,MAAM,mCAAmCA,MAAM;;IAG3D;EAACrB;EAAQN;EAASO;EACpB,CAAC;AAuBD,QAAO;EACLJ;EACA8B,iBAZwC;GACxCC,WAAW;GACXL,aAZkBzC,MAAM0C,eACjB;IACLC,UAAU/B,QAAQyB,MAAMd,QAAQlB,UAAUO,QAAQyB,KAAKd,MAAM,GAAGqB;IAChEtB,UAAUV,QAAQyB,MAAMf,WAAWjB,UAAUO,QAAQyB,KAAKf,SAAS,GAAG,EAAE;IACxET,cAAcR,UAAUQ,aAAa;IACrCC;IACD,GACD;IAACF,QAAQyB,MAAMd;IAAOX,QAAQyB,MAAMf;IAAUT;IAAcC;IAC9D,CAAC;GAKCiC,gBAAgBd,QAAQ;AACtBN,mBAAeI,UAAUE;;GAG3Be,UAAU7B,WAAWyB,SAAYhB;GAClC;EAKA"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@lofcz/platejs-excalidraw",
3
+ "version": "52.0.11",
4
+ "description": "Excalidraw plugin for Plate",
5
+ "keywords": [
6
+ "plate",
7
+ "plugin",
8
+ "slate"
9
+ ],
10
+ "homepage": "https://platejs.org",
11
+ "bugs": {
12
+ "url": "https://github.com/udecode/plate/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/lofcz/plate.git",
17
+ "directory": "packages/excalidraw"
18
+ },
19
+ "license": "MIT",
20
+ "sideEffects": false,
21
+ "exports": {
22
+ ".": "./dist/index.js",
23
+ "./react": "./dist/react/index.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist/**/*"
30
+ ],
31
+ "dependencies": {
32
+ "@excalidraw/excalidraw": "0.18.0",
33
+ "lodash": "^4.17.21",
34
+ "react-compiler-runtime": "^1.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/lodash": "^4.17.13",
38
+ "@plate/scripts": "1.0.0"
39
+ },
40
+ "peerDependencies": {
41
+ "platejs": ">=52.0.11",
42
+ "react": ">=18.0.0",
43
+ "react-dom": ">=18.0.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "type": "module",
49
+ "module": "./dist/index.js",
50
+ "scripts": {
51
+ "brl": "plate-pkg p:brl",
52
+ "build": "plate-pkg p:build",
53
+ "build:watch": "plate-pkg p:build:watch",
54
+ "clean": "plate-pkg p:clean",
55
+ "lint": "plate-pkg p:lint",
56
+ "lint:fix": "plate-pkg p:lint:fix",
57
+ "test": "plate-pkg p:test",
58
+ "test:watch": "plate-pkg p:test:watch",
59
+ "typecheck": "plate-pkg p:typecheck"
60
+ }
61
+ }