Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace async arrow with function #5870

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading