Skip to content

Commit

Permalink
Fix editor (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored Nov 9, 2024
1 parent 771e46f commit e2821e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
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

0 comments on commit e2821e1

Please sign in to comment.