@tarviks/lexical-rich-editor 1.3.13 → 1.3.14

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.mjs CHANGED
@@ -5,7 +5,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
6
6
  import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
7
7
  import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
8
- import { createCommand, $isTextNode, DecoratorNode, COMMAND_PRIORITY_HIGH, TextNode, ElementNode, SELECTION_CHANGE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, $getSelection, $isRangeSelection, $findMatchingParent, COMMAND_PRIORITY_LOW, KEY_DOWN_COMMAND, $getNodeByKey, $createRangeSelection, $setSelection, $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR, PASTE_COMMAND, DRAGSTART_COMMAND, DRAGOVER_COMMAND, DROP_COMMAND, $getRoot, $createTextNode, $isElementNode, FORMAT_ELEMENT_COMMAND, CLICK_COMMAND, $isNodeSelection, $applyNodeReplacement, FORMAT_TEXT_COMMAND, $isDecoratorNode, $getNearestNodeFromDOMNode, COMMAND_PRIORITY_CRITICAL, REDO_COMMAND, UNDO_COMMAND, getDOMSelection, KEY_ESCAPE_COMMAND, isHTMLElement, getDOMSelectionFromTarget, $isLineBreakNode, SKIP_SELECTION_FOCUS_TAG, createEditor, KEY_ENTER_COMMAND } from 'lexical';
8
+ import { createCommand, $isTextNode, DecoratorNode, COMMAND_PRIORITY_HIGH, TextNode, ElementNode, SELECTION_CHANGE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, $getSelection, $isRangeSelection, KEY_DOWN_COMMAND, $isNodeSelection, $findMatchingParent, COMMAND_PRIORITY_LOW, $getNodeByKey, $createRangeSelection, $setSelection, $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR, PASTE_COMMAND, DRAGSTART_COMMAND, DRAGOVER_COMMAND, DROP_COMMAND, $getRoot, $createTextNode, $isElementNode, FORMAT_ELEMENT_COMMAND, CLICK_COMMAND, $applyNodeReplacement, FORMAT_TEXT_COMMAND, $isDecoratorNode, $getNearestNodeFromDOMNode, COMMAND_PRIORITY_CRITICAL, REDO_COMMAND, UNDO_COMMAND, getDOMSelection, KEY_ESCAPE_COMMAND, isHTMLElement, getDOMSelectionFromTarget, $isLineBreakNode, SKIP_SELECTION_FOCUS_TAG, createEditor, KEY_ENTER_COMMAND } from 'lexical';
9
9
  import { mergeStyleSets, Stack, css, useTheme, Callout, TextField } from '@fluentui/react';
10
10
  import { makeStyles, FluentProvider, webLightTheme, Menu, MenuTrigger, MenuPopover, MenuList, MenuGroup, MenuGroupHeader, MenuItem, MenuDivider, Dropdown, Option, Button, ToolbarDivider, MenuItemRadio, Field, Input, MessageBar, MessageBarBody, Popover, PopoverSurface, PopoverTrigger } from '@fluentui/react-components';
11
11
  import { CodeHighlightNode, CodeNode, $isCodeHighlightNode } from '@lexical/code';
@@ -4554,6 +4554,44 @@ function RefApiPlugin({
4554
4554
  );
4555
4555
  return null;
4556
4556
  }
4557
+ function RobustCutPlugin() {
4558
+ const [editor] = useLexicalComposerContext();
4559
+ useEffect(() => {
4560
+ return editor.registerCommand(
4561
+ KEY_DOWN_COMMAND,
4562
+ (event) => {
4563
+ const isShiftDelete = event.key === "Delete" && event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey;
4564
+ if (!isShiftDelete) return false;
4565
+ let plainText = null;
4566
+ editor.getEditorState().read(() => {
4567
+ const selection = $getSelection();
4568
+ if ($isRangeSelection(selection) && !selection.isCollapsed()) {
4569
+ plainText = selection.getTextContent();
4570
+ } else if ($isNodeSelection(selection) && selection.getNodes().length > 0) {
4571
+ plainText = "";
4572
+ }
4573
+ });
4574
+ if (plainText === null) return false;
4575
+ event.preventDefault();
4576
+ editor.update(() => {
4577
+ const selection = $getSelection();
4578
+ if ($isRangeSelection(selection)) {
4579
+ selection.removeText();
4580
+ } else if ($isNodeSelection(selection)) {
4581
+ selection.getNodes().forEach((node) => node.remove());
4582
+ }
4583
+ });
4584
+ if (plainText && navigator.clipboard?.writeText) {
4585
+ navigator.clipboard.writeText(plainText).catch(() => {
4586
+ });
4587
+ }
4588
+ return true;
4589
+ },
4590
+ COMMAND_PRIORITY_HIGH
4591
+ );
4592
+ }, [editor]);
4593
+ return null;
4594
+ }
4557
4595
  var CSS_ID = "__sc_styles__";
4558
4596
  function injectCSS() {
4559
4597
  if (document.getElementById(CSS_ID)) return;
@@ -8629,6 +8667,7 @@ var ContentEditorComponent = forwardRef(
8629
8667
  /* @__PURE__ */ jsx(AutoLinkPlugin, { matchers: MATCHERS }),
8630
8668
  /* @__PURE__ */ jsx(TablePlugin, { hasCellMerge: true, hasCellBackgroundColor: true }),
8631
8669
  !isReadOnly && /* @__PURE__ */ jsx(YoutubeDeletePlugin, {}),
8670
+ !isReadOnly && /* @__PURE__ */ jsx(RobustCutPlugin, {}),
8632
8671
  !isReadOnly && floatingAnchorElem && /* @__PURE__ */ jsx(TableActionMenuPlugin, {}),
8633
8672
  !isReadOnly && floatingAnchorElem && /* @__PURE__ */ jsx(TableCellResizerPlugin, { anchorElem: floatingAnchorElem }),
8634
8673
  !isReadOnly && /* @__PURE__ */ jsx(