Skip to content

Commit

Permalink
Replace async arrow with function (#5870)
Browse files Browse the repository at this point in the history
  • Loading branch information
zurfyx authored Apr 11, 2024
1 parent 70c785e commit f85a177
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down
55 changes: 29 additions & 26 deletions packages/lexical-react/src/LexicalAutoEmbedPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>({

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++) {
Expand Down Expand Up @@ -168,34 +168,37 @@ export function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>({
);
}, [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
Expand Down
6 changes: 3 additions & 3 deletions packages/lexical-react/src/LexicalTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
);
Expand Down

0 comments on commit f85a177

Please sign in to comment.