From f34e3535b91aa699a408463c4c3536b527329d1b Mon Sep 17 00:00:00 2001 From: zbeyens Date: Wed, 25 Dec 2024 17:32:21 +0100 Subject: [PATCH] refactor --- apps/www/content/docs/en/editor-methods.mdx | 10 +++++++++- .../excalidraw/src/react/hooks/useExcalidrawElement.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/www/content/docs/en/editor-methods.mdx b/apps/www/content/docs/en/editor-methods.mdx index c052812a38..b379e4d75e 100644 --- a/apps/www/content/docs/en/editor-methods.mdx +++ b/apps/www/content/docs/en/editor-methods.mdx @@ -106,13 +106,21 @@ You can also use `editor.isFallback` to check if the editor is a fallback instan ## API Methods +### findPath + +Find the path of a node. Default is `findNodePath` (traversal). Overridden by `withPlate` to use `ReactEditor.findPath` (memo). + +```ts +const path = editor.findPath(node); +``` + ### getApi Retrieve the typed API for the editor: ```ts const api = editor.getApi(TablePlugin); -api.api.create.cell(); // Type-safe API method +api.api.create.tableCell(); // Type-safe API method ``` ### getTransforms diff --git a/packages/excalidraw/src/react/hooks/useExcalidrawElement.ts b/packages/excalidraw/src/react/hooks/useExcalidrawElement.ts index 6606810165..1078f2bfbe 100644 --- a/packages/excalidraw/src/react/hooks/useExcalidrawElement.ts +++ b/packages/excalidraw/src/react/hooks/useExcalidrawElement.ts @@ -38,7 +38,7 @@ export const useExcalidrawElement = ({ scrollToContent, }, // onChange: (elements: readonly ExcalidrawElementType[], state: AppState) => { - // const path = findNodePath(editor, element); + // const path = editor.findPath(element); // FIXME: setNodes triggers render loop as onChange is triggered on rerender // in the meantime, the prop can be used to save the data outside slate