From f85a177745d7517939de2c1a1a6271ba9349462d Mon Sep 17 00:00:00 2001 From: Gerard Rovira Date: Thu, 11 Apr 2024 01:37:27 +0100 Subject: [PATCH] Replace async arrow with function (#5870) --- .../src/plugins/ContextMenuPlugin/index.tsx | 4 +- .../src/LexicalAutoEmbedPlugin.tsx | 55 ++++++++++--------- .../lexical-react/src/LexicalTreeView.tsx | 6 +- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx index 1dade0fad78..01d660e493b 100644 --- a/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ContextMenuPlugin/index.tsx @@ -119,7 +119,7 @@ export default function ContextMenuPlugin(): JSX.Element { }), new ContextMenuOption(`Paste`, { onSelect: (_node) => { - navigator.clipboard.read().then(async (...args) => { + navigator.clipboard.read().then(async function (...args) { const data = new DataTransfer(); const items = await navigator.clipboard.read(); @@ -149,7 +149,7 @@ export default function ContextMenuPlugin(): JSX.Element { }), new ContextMenuOption(`Paste as Plain Text`, { onSelect: (_node) => { - navigator.clipboard.read().then(async (...args) => { + navigator.clipboard.read().then(async function (...args) { const permission = await navigator.permissions.query({ // @ts-expect-error These types are incorrect. name: 'clipboard-read', diff --git a/packages/lexical-react/src/LexicalAutoEmbedPlugin.tsx b/packages/lexical-react/src/LexicalAutoEmbedPlugin.tsx index fe80122b8a6..2879d1bafff 100644 --- a/packages/lexical-react/src/LexicalAutoEmbedPlugin.tsx +++ b/packages/lexical-react/src/LexicalAutoEmbedPlugin.tsx @@ -106,7 +106,7 @@ export function LexicalAutoEmbedPlugin({ const checkIfLinkNodeIsEmbeddable = useCallback( (key: NodeKey) => { - editor.getEditorState().read(async () => { + editor.getEditorState().read(async function () { const linkNode = $getNodeByKey(key); if ($isLinkNode(linkNode)) { for (let i = 0; i < embedConfigs.length; i++) { @@ -168,34 +168,37 @@ export function LexicalAutoEmbedPlugin({ ); }, [editor, embedConfigs, onOpenEmbedModalForConfig]); - const embedLinkViaActiveEmbedConfig = useCallback(async () => { - if (activeEmbedConfig != null && nodeKey != null) { - const linkNode = editor.getEditorState().read(() => { - const node = $getNodeByKey(nodeKey); - if ($isLinkNode(node)) { - return node; - } - return null; - }); + const embedLinkViaActiveEmbedConfig = useCallback( + async function () { + if (activeEmbedConfig != null && nodeKey != null) { + const linkNode = editor.getEditorState().read(() => { + const node = $getNodeByKey(nodeKey); + if ($isLinkNode(node)) { + return node; + } + return null; + }); - if ($isLinkNode(linkNode)) { - const result = await Promise.resolve( - activeEmbedConfig.parseUrl(linkNode.__url), - ); - if (result != null) { - editor.update(() => { - if (!$getSelection()) { - linkNode.selectEnd(); - } - activeEmbedConfig.insertNode(editor, result); - if (linkNode.isAttached()) { - linkNode.remove(); - } - }); + if ($isLinkNode(linkNode)) { + const result = await Promise.resolve( + activeEmbedConfig.parseUrl(linkNode.__url), + ); + if (result != null) { + editor.update(() => { + if (!$getSelection()) { + linkNode.selectEnd(); + } + activeEmbedConfig.insertNode(editor, result); + if (linkNode.isAttached()) { + linkNode.remove(); + } + }); + } } } - } - }, [activeEmbedConfig, editor, nodeKey]); + }, + [activeEmbedConfig, editor, nodeKey], + ); const options = useMemo(() => { return activeEmbedConfig != null && nodeKey != null diff --git a/packages/lexical-react/src/LexicalTreeView.tsx b/packages/lexical-react/src/LexicalTreeView.tsx index 162ff13dedf..d91563b4d35 100644 --- a/packages/lexical-react/src/LexicalTreeView.tsx +++ b/packages/lexical-react/src/LexicalTreeView.tsx @@ -86,9 +86,9 @@ export function TreeView({ setEditorReadOnly={handleEditorReadOnly} editorState={editorCurrentState} setEditorState={(state) => editor.setEditorState(state)} - generateContent={async (exportDOM) => - generateContent(editor, commandsLog, exportDOM) - } + generateContent={async function (exportDOM) { + return generateContent(editor, commandsLog, exportDOM); + }} ref={treeElementRef} /> );