@lofcz/platejs-excalidraw 52.0.11 → 52.3.6

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.
@@ -11,5 +11,4 @@ const BaseExcalidrawPlugin = createSlatePlugin({
11
11
  });
12
12
 
13
13
  //#endregion
14
- export { BaseExcalidrawPlugin as t };
15
- //# sourceMappingURL=BaseExcalidrawPlugin-oKI6R2oh.js.map
14
+ export { BaseExcalidrawPlugin as t };
@@ -1,3 +1,4 @@
1
+ import * as platejs0 from "platejs";
1
2
  import { InsertNodesOptions, NodeProps, SlateEditor, TElement } from "platejs";
2
3
  import { ImportedDataState } from "@excalidraw/excalidraw/data/types";
3
4
  import { ExcalidrawElement } from "@excalidraw/excalidraw/element/types";
@@ -15,10 +16,9 @@ interface TExcalidrawElement extends TElement {
15
16
  } | null;
16
17
  }
17
18
  /** Enables support for Excalidraw drawing tool within a Slate document */
18
- declare const BaseExcalidrawPlugin: any;
19
+ declare const BaseExcalidrawPlugin: platejs0.SlatePlugin<platejs0.PluginConfig<"excalidraw", {}, {}, {}, {}>>;
19
20
  //#endregion
20
21
  //#region src/lib/transforms/insertExcalidraw.d.ts
21
22
  declare const insertExcalidraw: (editor: SlateEditor, props?: NodeProps<TExcalidrawElement>, options?: InsertNodesOptions) => void;
22
23
  //#endregion
23
- export { ExcalidrawDataState as i, BaseExcalidrawPlugin as n, TExcalidrawElement as r, insertExcalidraw as t };
24
- //# sourceMappingURL=index-B5LkMtZs.d.ts.map
24
+ export { ExcalidrawDataState as i, BaseExcalidrawPlugin as n, TExcalidrawElement as r, insertExcalidraw as t };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as ExcalidrawDataState, n as BaseExcalidrawPlugin, r as TExcalidrawElement, t as insertExcalidraw } from "./index-B5LkMtZs";
1
+ import { i as ExcalidrawDataState, n as BaseExcalidrawPlugin, r as TExcalidrawElement, t as insertExcalidraw } from "./index-C9mWUAI4";
2
2
  export { BaseExcalidrawPlugin, ExcalidrawDataState, TExcalidrawElement, insertExcalidraw };
package/dist/index.js CHANGED
@@ -19,5 +19,4 @@ const insertExcalidraw = (editor, props = {}, options = {}) => {
19
19
  };
20
20
 
21
21
  //#endregion
22
- export { BaseExcalidrawPlugin, insertExcalidraw };
23
- //# sourceMappingURL=index.js.map
22
+ export { BaseExcalidrawPlugin, insertExcalidraw };
@@ -1,8 +1,10 @@
1
- import { i as ExcalidrawDataState, r as TExcalidrawElement } from "../index-B5LkMtZs";
1
+ import { i as ExcalidrawDataState, r as TExcalidrawElement } from "../index-C9mWUAI4";
2
+ import * as platejs0 from "platejs";
3
+ import * as platejs_react0 from "platejs/react";
2
4
  import { ExcalidrawProps, LibraryItems } from "@excalidraw/excalidraw/types";
3
5
 
4
6
  //#region src/react/ExcalidrawPlugin.d.ts
5
- declare const ExcalidrawPlugin: any;
7
+ declare const ExcalidrawPlugin: platejs_react0.PlatePlugin<platejs0.PluginConfig<"excalidraw", {}, {}, {}, {}>>;
6
8
  //#endregion
7
9
  //#region src/react/types.d.ts
8
10
  interface TExcalidrawProps extends Omit<ExcalidrawProps, 'initialData'> {
@@ -23,5 +25,4 @@ declare const useExcalidrawElement: ({
23
25
  excalidrawProps: TExcalidrawProps;
24
26
  };
25
27
  //#endregion
26
- export { ExcalidrawPlugin, TExcalidrawProps, useExcalidrawElement };
27
- //# sourceMappingURL=index.d.ts.map
28
+ export { ExcalidrawPlugin, TExcalidrawProps, useExcalidrawElement };
@@ -62,5 +62,4 @@ const useExcalidrawElement = ({ element, libraryItems = [], scrollToContent = tr
62
62
  };
63
63
 
64
64
  //#endregion
65
- export { ExcalidrawPlugin, useExcalidrawElement };
66
- //# sourceMappingURL=index.js.map
65
+ export { ExcalidrawPlugin, useExcalidrawElement };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lofcz/platejs-excalidraw",
3
- "version": "52.0.11",
3
+ "version": "52.3.6",
4
4
  "description": "Excalidraw plugin for Plate",
5
5
  "keywords": [
6
6
  "plate",
@@ -35,7 +35,8 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/lodash": "^4.17.13",
38
- "@plate/scripts": "1.0.0"
38
+ "@plate/scripts": "1.0.0",
39
+ "platejs": "npm:@lofcz/platejs@52.3.6"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "platejs": ">=52.0.11",
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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,0BAA0B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