@tarviks/lexical-rich-editor 1.3.6 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3193,24 +3193,21 @@ var FloatingLinkEditor = ({ editor, isLink, setIsLink, isLinkEditMode, setIsLink
3193
3193
  const inputRef = React9.useRef(null);
3194
3194
  const $updateLinkEditor = React9.useCallback(() => {
3195
3195
  const selection = lexical.$getSelection();
3196
+ let hasLink = false;
3196
3197
  if (lexical.$isRangeSelection(selection)) {
3197
3198
  const node = getSelectedNode2(selection);
3198
3199
  const linkParent = utils.$findMatchingParent(node, link.$isLinkNode);
3199
- if (linkParent) {
3200
- setLinkUrl(linkParent.getURL());
3201
- } else if (link.$isLinkNode(node)) {
3202
- setLinkUrl(node.getURL());
3203
- } else {
3204
- setLinkUrl("");
3205
- }
3200
+ hasLink = !!linkParent || link.$isLinkNode(node);
3201
+ const url = linkParent ? linkParent.getURL() : link.$isLinkNode(node) ? node.getURL() : "";
3202
+ setLinkUrl(url);
3206
3203
  if (isLinkEditMode) {
3207
- setEditedLinkUrl(linkUrl);
3204
+ setEditedLinkUrl(url);
3208
3205
  }
3209
3206
  }
3210
3207
  const nativeSelection = lexical.getDOMSelection(editor._window);
3211
3208
  const activeElement = document.activeElement;
3212
3209
  const rootElement = editor.getRootElement();
3213
- if (isLink && selection !== null && nativeSelection !== null && rootElement !== null && rootElement.contains(nativeSelection.anchorNode) && editor.isEditable()) {
3210
+ if (hasLink && selection !== null && nativeSelection !== null && rootElement !== null && rootElement.contains(nativeSelection.anchorNode) && editor.isEditable()) {
3214
3211
  const domRect = nativeSelection.focusNode?.parentElement?.getBoundingClientRect();
3215
3212
  if (domRect) {
3216
3213
  setTarget({ getBoundingClientRect: () => domRect });
@@ -3223,7 +3220,7 @@ var FloatingLinkEditor = ({ editor, isLink, setIsLink, isLinkEditMode, setIsLink
3223
3220
  setLinkUrl("");
3224
3221
  }
3225
3222
  return true;
3226
- }, [editor, setIsLinkEditMode, isLinkEditMode, isLink, linkUrl]);
3223
+ }, [editor, setIsLinkEditMode, isLinkEditMode]);
3227
3224
  React9.useEffect(() => {
3228
3225
  const update = () => {
3229
3226
  editor.getEditorState().read(() => {
@@ -3291,6 +3288,7 @@ var FloatingLinkEditor = ({ editor, isLink, setIsLink, isLinkEditMode, setIsLink
3291
3288
  if (lastSelection !== null) {
3292
3289
  if (linkUrl !== "") {
3293
3290
  editor.update(() => {
3291
+ lexical.$setSelection(lastSelection.clone());
3294
3292
  editor.dispatchCommand(
3295
3293
  link.TOGGLE_LINK_COMMAND,
3296
3294
  sanitizeUrl(editedLinkUrl)
@@ -6559,6 +6557,7 @@ var InsertLinkPlugin = ({
6559
6557
  opacity: disabled ? 0.55 : 1,
6560
6558
  cursor: disabled ? "not-allowed" : "pointer"
6561
6559
  },
6560
+ onMouseDown: (event) => event.preventDefault(),
6562
6561
  onClick: insertLink
6563
6562
  },
6564
6563
  "insert-link"