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

[lexical-link][lexical-react] Chore: Fix deprecated usage of toggleLink with $toggleLink #6081

Merged
merged 1 commit into from
May 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 @@ -9,9 +9,9 @@
import {
$createLinkNode,
$isLinkNode,
$toggleLink,
LinkNode,
SerializedLinkNode,
toggleLink,
} from '@lexical/link';
import {
$getRoot,
Expand Down Expand Up @@ -391,7 +391,7 @@ describe('LexicalLinkNode tests', () => {
});
});

test('toggleLink applies the title attribute when creating', async () => {
test('$toggleLink applies the title attribute when creating', async () => {
const {editor} = testEnv;
await editor.update(() => {
const p = new ParagraphNode();
Expand All @@ -401,7 +401,7 @@ describe('LexicalLinkNode tests', () => {

await editor.update(() => {
$selectAll();
toggleLink('https://lexical.dev/', {title: 'Lexical Website'});
$toggleLink('https://lexical.dev/', {title: 'Lexical Website'});
});

const paragraph = editor!.getEditorState().toJSON().root
Expand Down
8 changes: 4 additions & 4 deletions packages/lexical-react/src/LexicalLinkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

import {LinkNode, TOGGLE_LINK_COMMAND, toggleLink} from '@lexical/link';
import {$toggleLink, LinkNode, TOGGLE_LINK_COMMAND} from '@lexical/link';
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {mergeRegister, objectKlassEquals} from '@lexical/utils';
import {
Expand Down Expand Up @@ -34,17 +34,17 @@ export function LinkPlugin({validateUrl}: Props): null {
TOGGLE_LINK_COMMAND,
(payload) => {
if (payload === null) {
toggleLink(payload);
$toggleLink(payload);
return true;
} else if (typeof payload === 'string') {
if (validateUrl === undefined || validateUrl(payload)) {
toggleLink(payload);
$toggleLink(payload);
return true;
}
return false;
} else {
const {url, target, rel, title} = payload;
toggleLink(url, {rel, target, title});
$toggleLink(url, {rel, target, title});
return true;
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical-website/docs/react/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ React wrapper for `@lexical/history` that adds support for history stack managem

### `LexicalLinkPlugin`

React wrapper for `@lexical/link` that adds support for links, including `toggleLink` command support that toggles link for selected text
React wrapper for `@lexical/link` that adds support for links, including `$toggleLink` command support that toggles link for selected text

```jsx
<LinkPlugin />
Expand Down
Loading