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

Fix editor #686

Merged
merged 1 commit into from
Nov 9, 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
6 changes: 6 additions & 0 deletions .changeset/clever-ads-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@jpmorganchase/mosaic-content-editor-plugin': patch
---

- Fixed LinkEditor not working when editing existing links.
- Fixed InsertBlockDropdown not updating correctly.
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { mergeRegister } from '@lexical/utils';
import {
$getSelection,
$isRangeSelection,
COMMAND_PRIORITY_LOW,
RangeSelection,
SELECTION_CHANGE_COMMAND
} from 'lexical';
import { ChangeEvent, useCallback, useEffect, useRef, useState } from 'react';
import { $getSelection, $isRangeSelection, RangeSelection } from 'lexical';
import { ChangeEvent, useCallback, useEffect, useState } from 'react';
import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { useFloatingUI, Input } from '@salt-ds/core';
Expand All @@ -20,7 +13,6 @@ import { getSelectedNode } from '../../utils/getSelectedNode';

export function LinkEditor() {
const [editor] = useLexicalComposerContext();
const inputRef = useRef<HTMLInputElement>(null);
const [linkUrl, setLinkUrl] = useState('');
const [isEdit, setIsEdit] = useState(false);
const [lastSelection, setLastSelection] = useState<RangeSelection | null>(null);
Expand Down Expand Up @@ -67,22 +59,11 @@ export function LinkEditor() {

useEffect(
() =>
mergeRegister(
editor.registerUpdateListener(({ editorState }) => {
editorState.read(() => {
updateLinkEditor();
});
}),

editor.registerCommand(
SELECTION_CHANGE_COMMAND,
() => {
updateLinkEditor();
return true;
},
COMMAND_PRIORITY_LOW
)
),
editor.registerUpdateListener(({ editorState }) => {
editorState.read(() => {
updateLinkEditor();
});
}),
[editor, updateLinkEditor]
);

Expand Down Expand Up @@ -116,7 +97,6 @@ export function LinkEditor() {
) : (
<Input
endAdornment={<SaveAdornment onSave={handleSave} />}
ref={inputRef}
value={linkUrl}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
setLinkUrl(event.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function InsertBlockDropdown({
const selectedBlockSourceIndex = source.findIndex(item => item.type === blockSourceType);
return (
<Dropdown<BlockSourceType>
defaultSelected={[source[selectedBlockSourceIndex]]}
selected={[source[selectedBlockSourceIndex]]}
valueToString={itemToString}
onSelectionChange={handleSelect}
style={{ width: 132 }}
Expand Down
Loading