ct-rich-text-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.
@@ -21,6 +21,7 @@ import { ListPlugin } from "@lexical/react/LexicalListPlugin";
21
21
  import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";
22
22
  import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
23
23
  import { TablePlugin } from "@lexical/react/LexicalTablePlugin";
24
+ import { TableNode, TableCellNode, TableRowNode, $createTableNodeWithDimensions, $isTableRowNode, $isTableCellNode, TableCellHeaderStates, $isTableNode, $isTableSelection, $getTableCellNodeFromLexicalNode, $getTableNodeFromLexicalNodeOrThrow, getTableElement, getTableObserverFromTableElement, $insertTableRow__EXPERIMENTAL, $insertTableColumn__EXPERIMENTAL, $getNodeTriplet, $deleteTableRow__EXPERIMENTAL, $deleteTableColumn__EXPERIMENTAL, $getTableRowIndexFromTableCellNode, $getTableColumnIndexFromTableCellNode, $unmergeCell, $computeTableMapSkipCellCheck, getDOMCellFromTarget, $getTableAndElementByKey } from "@lexical/table";
24
25
  import { $findMatchingParent, $getNearestNodeOfType, mergeRegister, $getNearestBlockElementAncestorOrThrow, $insertNodeToNearestRoot, $wrapNodeInElement, $isEditorIsNestedEditor, mediaFileReader, isMimeType, calculateZoomLevel, CAN_USE_DOM } from "@lexical/utils";
25
26
  import Stack from "@mui/material/Stack";
26
27
  import { createCommand, COMMAND_PRIORITY_LOW, $getSelection, $isRangeSelection, $insertNodes, $getNearestNodeFromDOMNode, $setSelection, isHTMLElement as isHTMLElement$1, TextNode, $applyNodeReplacement, $getRoot, $createTextNode, $getNodeByKey, DecoratorNode, createEditor, COMMAND_PRIORITY_EDITOR, $createParagraphNode, $isRootOrShadowRoot, $isParagraphNode, $isTextNode, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, $isElementNode, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, UNDO_COMMAND, REDO_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, KEY_ENTER_COMMAND, $createNodeSelection, $isNodeSelection, getDOMSelection, CLICK_COMMAND, COMMAND_PRIORITY_HIGH, $isLineBreakNode, PASTE_COMMAND, isDOMNode } from "lexical";
@@ -31,7 +32,6 @@ import { LinkNode, $isLinkNode, TOGGLE_LINK_COMMAND, $isAutoLinkNode, $createLin
31
32
  import { ListNode, ListItemNode, $isListNode, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, INSERT_CHECK_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND, $createListNode, $createListItemNode } from "@lexical/list";
32
33
  import { HeadingNode, QuoteNode, $isHeadingNode, $createHeadingNode, $createQuoteNode, DRAG_DROP_PASTE } from "@lexical/rich-text";
33
34
  import { $isAtNodeEnd, $selectAll, $patchStyleText, $setBlocksType, $isParentElementRTL, $getSelectionStyleValueForProperty } from "@lexical/selection";
34
- import { TableNode, TableCellNode, TableRowNode, $createTableNodeWithDimensions, TableCellHeaderStates, $isTableNode, $isTableSelection, $getTableCellNodeFromLexicalNode, $getTableNodeFromLexicalNodeOrThrow, getTableElement, getTableObserverFromTableElement, $isTableCellNode, $insertTableRow__EXPERIMENTAL, $insertTableColumn__EXPERIMENTAL, $getNodeTriplet, $isTableRowNode, $deleteTableRow__EXPERIMENTAL, $deleteTableColumn__EXPERIMENTAL, $getTableRowIndexFromTableCellNode, $getTableColumnIndexFromTableCellNode, $unmergeCell, $computeTableMapSkipCellCheck, getDOMCellFromTarget, $getTableAndElementByKey } from "@lexical/table";
35
35
  import { HorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode";
36
36
  import DescriptionIcon from "@mui/icons-material/Description";
37
37
  import FolderZipIcon from "@mui/icons-material/FolderZip";
@@ -267,7 +267,7 @@ const editorConfig = {
267
267
  "Baskerville",
268
268
  "Gill Sans"
269
269
  ],
270
- mentionUserList: ["mukthar", "nimish", "Anoop", "Jewel", "Ankit", "Nitin"]
270
+ mentionUserList: []
271
271
  };
272
272
  const autocomplete = "";
273
273
  function __insertCSS(code) {
@@ -8069,7 +8069,7 @@ const AIRephrasePlugin = () => {
8069
8069
  }
8070
8070
  );
8071
8071
  };
8072
- const index$7 = "";
8072
+ const index$8 = "";
8073
8073
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
8074
8074
  const freeGlobal$1 = freeGlobal;
8075
8075
  var freeSelf = typeof self == "object" && self && self.Object === Object && self;
@@ -8288,7 +8288,7 @@ function CopyButton({ editor, getCodeDOMNode }) {
8288
8288
  }
8289
8289
  return /* @__PURE__ */ jsx("button", { className: "menu-item", onClick: handleClick, "aria-label": "copy", children: isCopyCompleted ? /* @__PURE__ */ jsx("i", { className: "format success" }) : /* @__PURE__ */ jsx("i", { className: "format copy" }) });
8290
8290
  }
8291
- const index$6 = "";
8291
+ const index$7 = "";
8292
8292
  const PRETTIER_PARSER_MODULES = {
8293
8293
  css: [() => import("./postcss-f084f74d.js")],
8294
8294
  html: [() => import("./html-5586dbf6.js")],
@@ -12031,7 +12031,7 @@ const computePosition = (reference, floating, options) => {
12031
12031
  var isClient = typeof document !== "undefined";
12032
12032
  var noop = function noop2() {
12033
12033
  };
12034
- var index$5 = isClient ? useLayoutEffect$1 : noop;
12034
+ var index$6 = isClient ? useLayoutEffect$1 : noop;
12035
12035
  function deepEqual(a, b2) {
12036
12036
  if (a === b2) {
12037
12037
  return true;
@@ -12093,7 +12093,7 @@ function roundByDPR(element, value) {
12093
12093
  }
12094
12094
  function useLatestRef(value) {
12095
12095
  const ref = React$1.useRef(value);
12096
- index$5(() => {
12096
+ index$6(() => {
12097
12097
  ref.current = value;
12098
12098
  });
12099
12099
  return ref;
@@ -12179,7 +12179,7 @@ function useFloating(options) {
12179
12179
  }
12180
12180
  });
12181
12181
  }, [latestMiddleware, placement, strategy, platformRef, openRef]);
12182
- index$5(() => {
12182
+ index$6(() => {
12183
12183
  if (open === false && dataRef.current.isPositioned) {
12184
12184
  dataRef.current.isPositioned = false;
12185
12185
  setData((data2) => ({
@@ -12189,13 +12189,13 @@ function useFloating(options) {
12189
12189
  }
12190
12190
  }, [open]);
12191
12191
  const isMountedRef = React$1.useRef(false);
12192
- index$5(() => {
12192
+ index$6(() => {
12193
12193
  isMountedRef.current = true;
12194
12194
  return () => {
12195
12195
  isMountedRef.current = false;
12196
12196
  };
12197
12197
  }, []);
12198
- index$5(() => {
12198
+ index$6(() => {
12199
12199
  if (referenceEl)
12200
12200
  referenceRef.current = referenceEl;
12201
12201
  if (floatingEl)
@@ -14395,7 +14395,7 @@ const EmbedComponent = ({ url, displayType, alignment, nodeKey }) => {
14395
14395
  }
14396
14396
  );
14397
14397
  };
14398
- const FileComponent = React$1.lazy(() => import("./index-984a0184.js"));
14398
+ const FileComponent = React$1.lazy(() => import("./index-f0d8f7a8.js"));
14399
14399
  function convertFileElement(domNode) {
14400
14400
  if (domNode instanceof HTMLDivElement) {
14401
14401
  const dataUrl = domNode.getAttribute("data-lexical-file-src");
@@ -14503,7 +14503,7 @@ function $createFileNode({ src, fileName, fileSize, key }) {
14503
14503
  function $isFileNode(node) {
14504
14504
  return node instanceof FileNode;
14505
14505
  }
14506
- const ImageView = React__default.lazy(() => import("./index-4a68b444.js"));
14506
+ const ImageView = React__default.lazy(() => import("./index-308e13ae.js"));
14507
14507
  function isGoogleDocCheckboxImg(img) {
14508
14508
  return img.parentElement != null && img.parentElement.tagName === "LI" && img.previousSibling === null && img.getAttribute("aria-roledescription") === "checkbox";
14509
14509
  }
@@ -17030,9 +17030,6 @@ function TableOptionPlugin() {
17030
17030
  const [columnHeadings, setColumnHeadings] = useState$1([]);
17031
17031
  const [headerColor, setHeaderColor] = useState$1("#4A90E2");
17032
17032
  const [editor] = useLexicalComposerContext();
17033
- const headerCellsMapRef = useRef(
17034
- /* @__PURE__ */ new Map()
17035
- );
17036
17033
  useEffect$1(() => {
17037
17034
  return editor.registerCommand(
17038
17035
  OPEN_TABLE_MODAL_COMMAND,
@@ -17043,77 +17040,6 @@ function TableOptionPlugin() {
17043
17040
  COMMAND_PRIORITY_EDITOR
17044
17041
  );
17045
17042
  }, [editor]);
17046
- useEffect$1(() => {
17047
- const headerCellsMap = headerCellsMapRef.current;
17048
- const reapplyHeaderStyles = () => {
17049
- const rootElement2 = editor.getRootElement();
17050
- if (!rootElement2)
17051
- return;
17052
- const tables = rootElement2.querySelectorAll("table");
17053
- tables.forEach((table) => {
17054
- const rows2 = table.querySelectorAll("tr");
17055
- if (rows2.length > 0) {
17056
- const firstRow = rows2[0];
17057
- const cells = firstRow.querySelectorAll("th, td");
17058
- cells.forEach((cell, index2) => {
17059
- const htmlCell = cell;
17060
- let savedHeaderColor = htmlCell.getAttribute("data-header-color");
17061
- let savedTextColor = htmlCell.getAttribute("data-text-color");
17062
- const cellKey = `${Array.from(tables).indexOf(table)}-${index2}`;
17063
- if (!savedHeaderColor && headerCellsMap.has(cellKey)) {
17064
- const colors = headerCellsMap.get(cellKey);
17065
- savedHeaderColor = colors.bgColor;
17066
- savedTextColor = colors.textColor;
17067
- }
17068
- if (savedHeaderColor && savedTextColor) {
17069
- headerCellsMap.set(cellKey, {
17070
- bgColor: savedHeaderColor,
17071
- textColor: savedTextColor
17072
- });
17073
- htmlCell.setAttribute("data-header-color", savedHeaderColor);
17074
- htmlCell.setAttribute("data-text-color", savedTextColor);
17075
- htmlCell.style.setProperty(
17076
- "background-color",
17077
- savedHeaderColor,
17078
- "important"
17079
- );
17080
- htmlCell.style.setProperty("color", savedTextColor, "important");
17081
- htmlCell.style.setProperty("padding", "8px", "important");
17082
- htmlCell.style.setProperty(
17083
- "border",
17084
- "1px solid #ddd",
17085
- "important"
17086
- );
17087
- htmlCell.style.setProperty("font-weight", "bold", "important");
17088
- htmlCell.style.setProperty("white-space", "nowrap", "important");
17089
- }
17090
- });
17091
- }
17092
- });
17093
- };
17094
- const removeUpdateListener = editor.registerUpdateListener(() => {
17095
- setTimeout(() => {
17096
- reapplyHeaderStyles();
17097
- }, 0);
17098
- });
17099
- const rootElement = editor.getRootElement();
17100
- let observer = null;
17101
- if (rootElement) {
17102
- observer = new MutationObserver(() => {
17103
- reapplyHeaderStyles();
17104
- });
17105
- observer.observe(rootElement, {
17106
- childList: true,
17107
- subtree: true,
17108
- attributes: true,
17109
- attributeFilter: ["style", "width"]
17110
- });
17111
- }
17112
- return () => {
17113
- removeUpdateListener();
17114
- observer == null ? void 0 : observer.disconnect();
17115
- };
17116
- }, [editor]);
17117
17043
  const onAddTable = () => {
17118
17044
  const rowCount = Number(rows);
17119
17045
  const colCount = Number(columns);
@@ -17124,28 +17050,33 @@ function TableOptionPlugin() {
17124
17050
  rowCount,
17125
17051
  colCount,
17126
17052
  false
17053
+ // Don't use built-in headers, we'll set them manually
17127
17054
  );
17128
17055
  if (includeHeaders) {
17129
17056
  const rowsNodes = tableNode.getChildren();
17130
17057
  const headerRow = rowsNodes[0];
17131
- if (headerRow) {
17058
+ if ($isTableRowNode(headerRow)) {
17132
17059
  const cells = headerRow.getChildren();
17133
17060
  for (let i2 = 0; i2 < cells.length; i2++) {
17134
- const headingText = (columnHeadings[i2] || "").trim();
17135
17061
  const cellNode = cells[i2];
17136
- cellNode.clear();
17137
- if (headingText) {
17138
- cellNode.append($createTextNode(headingText));
17062
+ if ($isTableCellNode(cellNode)) {
17063
+ cellNode.clear();
17064
+ const headingText = (columnHeadings[i2] || "").trim();
17065
+ if (headingText) {
17066
+ cellNode.append($createTextNode(headingText));
17067
+ }
17068
+ cellNode.setHeaderStyles(TableCellHeaderStates.COLUMN);
17069
+ cellNode.setBackgroundColor(headerColor);
17139
17070
  }
17140
- cellNode.setHeaderStyles(TableCellHeaderStates.COLUMN);
17141
17071
  }
17142
17072
  }
17143
17073
  }
17144
17074
  $insertNodeToNearestRoot(tableNode);
17145
17075
  });
17146
17076
  if (includeHeaders) {
17077
+ const textColor = getContrastColor(headerColor);
17147
17078
  requestAnimationFrame(() => {
17148
- const applyTextStyles = () => {
17079
+ const applyStyles = () => {
17149
17080
  const rootElement = editor.getRootElement();
17150
17081
  if (!rootElement)
17151
17082
  return false;
@@ -17158,37 +17089,18 @@ function TableOptionPlugin() {
17158
17089
  const cells = firstRow.querySelectorAll("th, td");
17159
17090
  cells.forEach((cell) => {
17160
17091
  const htmlCell = cell;
17161
- const textColor = getContrastColor(headerColor);
17162
- htmlCell.setAttribute("data-header-color", headerColor);
17163
- htmlCell.setAttribute("data-text-color", textColor);
17164
- htmlCell.style.setProperty(
17165
- "background-color",
17166
- headerColor,
17167
- "important"
17168
- );
17092
+ htmlCell.style.setProperty("background-color", headerColor, "important");
17169
17093
  htmlCell.style.setProperty("color", textColor, "important");
17170
- htmlCell.style.setProperty("padding", "8px", "important");
17171
- htmlCell.style.setProperty(
17172
- "border",
17173
- "1px solid #ddd",
17174
- "important"
17175
- );
17176
17094
  htmlCell.style.setProperty("font-weight", "bold", "important");
17177
- htmlCell.style.setProperty(
17178
- "white-space",
17179
- "nowrap",
17180
- "important"
17181
- );
17095
+ htmlCell.style.setProperty("padding", "8px", "important");
17182
17096
  });
17183
17097
  return true;
17184
17098
  }
17185
17099
  }
17186
17100
  return false;
17187
17101
  };
17188
- if (!applyTextStyles()) {
17189
- setTimeout(() => {
17190
- applyTextStyles();
17191
- }, 100);
17102
+ if (!applyStyles()) {
17103
+ setTimeout(applyStyles, 100);
17192
17104
  }
17193
17105
  });
17194
17106
  }
@@ -17868,10 +17780,10 @@ const PDF_CONFIG = {
17868
17780
  };
17869
17781
  const loadHtml2Pdf = async () => {
17870
17782
  try {
17871
- const mod = await import("./html2pdf.bundle.min-5e51c303.js").then((n) => n.h);
17783
+ const mod = await import("./html2pdf.bundle.min-bb81d5dc.js").then((n) => n.h);
17872
17784
  return (mod == null ? void 0 : mod.default) || mod;
17873
17785
  } catch {
17874
- const mod2 = await import("./html2pdf.bundle-9236a762.js").then((n) => n.h);
17786
+ const mod2 = await import("./html2pdf.bundle-40cc5697.js").then((n) => n.h);
17875
17787
  return (mod2 == null ? void 0 : mod2.default) || mod2;
17876
17788
  }
17877
17789
  };
@@ -27485,7 +27397,7 @@ const EmbedPreviewPlugin = ({
27485
27397
  }, [editor]);
27486
27398
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(FloatingEmbedMenuPlugin, { anchorElem: floatingAnchorElem }) });
27487
27399
  };
27488
- const index$4 = "";
27400
+ const index$5 = "";
27489
27401
  function getDOMRangeRect(nativeSelection, rootElement) {
27490
27402
  const domRange = nativeSelection.getRangeAt(0);
27491
27403
  let rect;
@@ -27923,7 +27835,7 @@ function FloatingEnhanceButtonPlugin({
27923
27835
  anchorElem
27924
27836
  );
27925
27837
  }
27926
- const index$3 = "";
27838
+ const index$4 = "";
27927
27839
  const VERTICAL_GAP$1 = 10;
27928
27840
  const HORIZONTAL_OFFSET$1 = 5;
27929
27841
  function setFloatingElemPositionForLinkEditor(targetRect, floatingElem, anchorElem, verticalGap = VERTICAL_GAP$1, horizontalOffset = HORIZONTAL_OFFSET$1) {
@@ -28349,7 +28261,7 @@ function FloatingLinkEditorPlugin({
28349
28261
  setIsLinkEditMode
28350
28262
  );
28351
28263
  }
28352
- const index$2 = "";
28264
+ const index$3 = "";
28353
28265
  const VERTICAL_GAP = 10;
28354
28266
  const HORIZONTAL_OFFSET = 5;
28355
28267
  function setFloatingElemPosition(targetRect, floatingElem, anchorElem, isLink = false, verticalGap = VERTICAL_GAP, horizontalOffset = HORIZONTAL_OFFSET, isEmbed = false) {
@@ -28930,6 +28842,7 @@ const LocalStoragePlugin = ({ namespace }) => {
28930
28842
  return null;
28931
28843
  };
28932
28844
  const LocalStoragePlugin$1 = LocalStoragePlugin;
28845
+ const index$2 = "";
28933
28846
  const PUNCTUATION = `\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;
28934
28847
  const NAME = "\\b[A-Z][^\\s" + PUNCTUATION + "]";
28935
28848
  const DocumentMentionsRegex = {
@@ -30179,8 +30092,12 @@ function $canUnmerge() {
30179
30092
  if ($isRangeSelection(selection) && !selection.isCollapsed() || $isTableSelection(selection) && !selection.anchor.is(selection.focus) || !$isRangeSelection(selection) && !$isTableSelection(selection)) {
30180
30093
  return false;
30181
30094
  }
30182
- const [cell] = $getNodeTriplet(selection.anchor);
30183
- return cell.__colSpan > 1 || cell.__rowSpan > 1;
30095
+ try {
30096
+ const [cell] = $getNodeTriplet(selection.anchor);
30097
+ return cell.__colSpan > 1 || cell.__rowSpan > 1;
30098
+ } catch (error) {
30099
+ return false;
30100
+ }
30184
30101
  }
30185
30102
  function $cellContainsEmptyParagraph(cell) {
30186
30103
  if (cell.getChildrenSize() !== 1) {
@@ -30238,10 +30155,8 @@ function TableActionMenu({
30238
30155
  });
30239
30156
  const [canMergeCells, setCanMergeCells] = useState$1(false);
30240
30157
  const [canUnmergeCell, setCanUnmergeCell] = useState$1(false);
30241
- const [backgroundColor, setBackgroundColor] = useState$1(
30242
- () => currentCellBackgroundColor(editor) || ""
30243
- );
30244
- const [stripingColor, setStripingColor] = useState$1("#f0f0f0");
30158
+ const [backgroundColor, setBackgroundColor] = useState$1("");
30159
+ const [stripingColor, setStripingColor] = useState$1("");
30245
30160
  useEffect$1(() => {
30246
30161
  updateTableCellNode(_tableCellNode);
30247
30162
  }, [_tableCellNode]);
@@ -30569,6 +30484,7 @@ function TableActionMenu({
30569
30484
  });
30570
30485
  }, [editor, onClose]);
30571
30486
  const toggleTableRowIsHeader = useCallback(() => {
30487
+ const cellsToUpdate = [];
30572
30488
  editor.update(() => {
30573
30489
  const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
30574
30490
  const tableRowIndex = $getTableRowIndexFromTableCellNode(tableCellNode);
@@ -30585,13 +30501,39 @@ function TableActionMenu({
30585
30501
  if (!$isTableCellNode(tableCell)) {
30586
30502
  throw new Error("Expected table cell");
30587
30503
  }
30504
+ const bgColor = tableCell.getBackgroundColor();
30588
30505
  tableCell.setHeaderStyles(newStyle, TableCellHeaderStates.ROW);
30506
+ cellsToUpdate.push({ key: tableCell.getKey(), bgColor });
30589
30507
  });
30590
30508
  $clearTableSelectionInline();
30591
30509
  onClose();
30592
30510
  });
30511
+ requestAnimationFrame(() => {
30512
+ cellsToUpdate.forEach(({ key, bgColor }) => {
30513
+ if (bgColor) {
30514
+ const cellElement = editor.getElementByKey(key);
30515
+ if (cellElement instanceof HTMLElement) {
30516
+ const hex = bgColor.replace("#", "");
30517
+ const r2 = parseInt(hex.substr(0, 2), 16);
30518
+ const g2 = parseInt(hex.substr(2, 2), 16);
30519
+ const b2 = parseInt(hex.substr(4, 2), 16);
30520
+ const luminance = (0.299 * r2 + 0.587 * g2 + 0.114 * b2) / 255;
30521
+ const textColor = luminance > 0.5 ? "#000000" : "#FFFFFF";
30522
+ cellElement.style.setProperty("color", textColor, "important");
30523
+ const nestedElements = cellElement.querySelectorAll("*");
30524
+ nestedElements.forEach((elem) => {
30525
+ if (elem instanceof HTMLElement) {
30526
+ elem.style.removeProperty("color");
30527
+ elem.style.setProperty("color", textColor, "important");
30528
+ }
30529
+ });
30530
+ }
30531
+ }
30532
+ });
30533
+ });
30593
30534
  }, [editor, tableCellNode, $clearTableSelectionInline, onClose]);
30594
30535
  const toggleTableColumnIsHeader = useCallback(() => {
30536
+ const cellsToUpdate = [];
30595
30537
  editor.update(() => {
30596
30538
  const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
30597
30539
  const tableColumnIndex = $getTableColumnIndexFromTableCellNode(tableCellNode);
@@ -30616,11 +30558,37 @@ function TableActionMenu({
30616
30558
  if (!$isTableCellNode(tableCell)) {
30617
30559
  throw new Error("Expected table cell");
30618
30560
  }
30561
+ const bgColor = tableCell.getBackgroundColor();
30619
30562
  tableCell.setHeaderStyles(newStyle, TableCellHeaderStates.COLUMN);
30563
+ cellsToUpdate.push({ key: tableCell.getKey(), bgColor });
30564
+ cellsToUpdate.push({ key: tableCell.getKey(), bgColor });
30620
30565
  }
30621
30566
  $clearTableSelectionInline();
30622
30567
  onClose();
30623
30568
  });
30569
+ requestAnimationFrame(() => {
30570
+ cellsToUpdate.forEach(({ key, bgColor }) => {
30571
+ if (bgColor) {
30572
+ const cellElement = editor.getElementByKey(key);
30573
+ if (cellElement instanceof HTMLElement) {
30574
+ const hex = bgColor.replace("#", "");
30575
+ const r2 = parseInt(hex.substr(0, 2), 16);
30576
+ const g2 = parseInt(hex.substr(2, 2), 16);
30577
+ const b2 = parseInt(hex.substr(4, 2), 16);
30578
+ const luminance = (0.299 * r2 + 0.587 * g2 + 0.114 * b2) / 255;
30579
+ const textColor = luminance > 0.5 ? "#000000" : "#FFFFFF";
30580
+ cellElement.style.setProperty("color", textColor, "important");
30581
+ const nestedElements = cellElement.querySelectorAll("*");
30582
+ nestedElements.forEach((elem) => {
30583
+ if (elem instanceof HTMLElement) {
30584
+ elem.style.removeProperty("color");
30585
+ elem.style.setProperty("color", textColor, "important");
30586
+ }
30587
+ });
30588
+ }
30589
+ }
30590
+ });
30591
+ });
30624
30592
  }, [editor, tableCellNode, $clearTableSelectionInline, onClose]);
30625
30593
  const applyRowStriping = useCallback((color) => {
30626
30594
  editor.update(() => {
@@ -30649,14 +30617,11 @@ function TableActionMenu({
30649
30617
  return luminance > 0.5 ? "#000000" : "#FFFFFF";
30650
30618
  };
30651
30619
  const textColor = getContrastColor2(value);
30620
+ const cellKeysToStyle = [];
30652
30621
  editor.update(() => {
30653
30622
  if (tableCellNode.isAttached()) {
30654
30623
  tableCellNode.setBackgroundColor(value);
30655
- const cellElement = editor.getElementByKey(tableCellNode.getKey());
30656
- if (cellElement instanceof HTMLElement) {
30657
- cellElement.style.setProperty("background-color", value, "important");
30658
- cellElement.style.setProperty("color", textColor, "important");
30659
- }
30624
+ cellKeysToStyle.push(tableCellNode.getKey());
30660
30625
  const selection = $getSelection();
30661
30626
  if ($isTableSelection(selection)) {
30662
30627
  const nodes = selection.getNodes();
@@ -30664,16 +30629,28 @@ function TableActionMenu({
30664
30629
  const node = nodes[i2];
30665
30630
  if ($isTableCellNode(node)) {
30666
30631
  node.setBackgroundColor(value);
30667
- const nodeElement = editor.getElementByKey(node.getKey());
30668
- if (nodeElement instanceof HTMLElement) {
30669
- nodeElement.style.setProperty("background-color", value, "important");
30670
- nodeElement.style.setProperty("color", textColor, "important");
30671
- }
30632
+ cellKeysToStyle.push(node.getKey());
30672
30633
  }
30673
30634
  }
30674
30635
  }
30675
30636
  }
30676
30637
  });
30638
+ requestAnimationFrame(() => {
30639
+ cellKeysToStyle.forEach((cellKey) => {
30640
+ const cellElement = editor.getElementByKey(cellKey);
30641
+ if (cellElement instanceof HTMLElement) {
30642
+ cellElement.style.setProperty("background-color", value, "important");
30643
+ cellElement.style.setProperty("color", textColor, "important");
30644
+ const nestedElements = cellElement.querySelectorAll("*");
30645
+ nestedElements.forEach((elem) => {
30646
+ if (elem instanceof HTMLElement) {
30647
+ elem.style.removeProperty("color");
30648
+ elem.style.setProperty("color", textColor, "important");
30649
+ }
30650
+ });
30651
+ }
30652
+ });
30653
+ });
30677
30654
  },
30678
30655
  [editor, tableCellNode]
30679
30656
  );
@@ -30731,16 +30708,13 @@ function TableActionMenu({
30731
30708
  ColorPicker,
30732
30709
  {
30733
30710
  color: backgroundColor,
30734
- onChange: (value) => {
30735
- handleCellBackgroundColor(value);
30736
- },
30737
30711
  onApply: (value) => {
30738
30712
  handleCellBackgroundColor(value);
30739
30713
  closeModal();
30740
30714
  setIsMenuOpen(false);
30741
30715
  }
30742
30716
  }
30743
- ));
30717
+ ), true);
30744
30718
  },
30745
30719
  "data-test-id": "table-background-color",
30746
30720
  children: /* @__PURE__ */ jsx("span", { className: "text", children: "Background color" })
@@ -30757,10 +30731,6 @@ function TableActionMenu({
30757
30731
  ColorPicker,
30758
30732
  {
30759
30733
  color: stripingColor,
30760
- onChange: (value) => {
30761
- setStripingColor(value);
30762
- applyRowStriping(value);
30763
- },
30764
30734
  onApply: (value) => {
30765
30735
  setStripingColor(value);
30766
30736
  applyRowStriping(value);
@@ -30768,7 +30738,7 @@ function TableActionMenu({
30768
30738
  setIsMenuOpen(false);
30769
30739
  }
30770
30740
  }
30771
- ));
30741
+ ), true);
30772
30742
  },
30773
30743
  "data-test-id": "table-row-striping",
30774
30744
  children: /* @__PURE__ */ jsx("span", { className: "text", children: "Row Striping Color" })
@@ -30907,7 +30877,8 @@ function TableActionMenu({
30907
30877
  }
30908
30878
  function TableCellActionMenuContainer({
30909
30879
  anchorElem,
30910
- cellMerge
30880
+ cellMerge,
30881
+ isSmallWidthViewport
30911
30882
  }) {
30912
30883
  const [editor] = useLexicalComposerContext();
30913
30884
  const menuButtonRef = useRef(null);
@@ -30951,6 +30922,9 @@ function TableCellActionMenuContainer({
30951
30922
  if (tableCellParentNodeDOM == null || !tableCellNodeFromSelection.isAttached()) {
30952
30923
  return disable();
30953
30924
  }
30925
+ if (!rootElement.contains(nativeSelection.focusNode)) {
30926
+ return disable();
30927
+ }
30954
30928
  const cellHasContent = tableCellNodeFromSelection.getTextContentSize() > 0;
30955
30929
  if (cellHasContent && !isMenuOpen) {
30956
30930
  return disable();
@@ -31008,7 +30982,7 @@ function TableCellActionMenuContainer({
31008
30982
  menu.classList.add("table-cell-action-button-container--active");
31009
30983
  menu.classList.remove("table-cell-action-button-container--inactive");
31010
30984
  const margin = 4;
31011
- const btnWidth = 28;
30985
+ const btnWidth = 20;
31012
30986
  const top = cellRect.top - anchorRect.top + margin;
31013
30987
  const left = cellRect.right - anchorRect.left - btnWidth - margin;
31014
30988
  menu.style.top = `${top}px`;
@@ -31030,13 +31004,26 @@ function TableCellActionMenuContainer({
31030
31004
  const handleContextMenu = (event) => {
31031
31005
  event.stopPropagation();
31032
31006
  const target = event.target;
31007
+ if (!target || target.classList.contains("TableNode__resizeHandle") || target.classList.contains("table-cell-action-button") || target.closest(".table-cell-action-button-container") || target.closest(".TableNode__resizeHandle")) {
31008
+ return;
31009
+ }
31033
31010
  const tableCell = target.closest("td, th");
31034
- if (tableCell) {
31035
- event.preventDefault();
31036
- event.stopPropagation();
31037
- let foundCellNode = null;
31038
- let isNodeAttached = false;
31039
- setTimeout(() => {
31011
+ if (!tableCell) {
31012
+ return;
31013
+ }
31014
+ const cellRect = tableCell.getBoundingClientRect();
31015
+ const clickX = event.clientX;
31016
+ const clickY = event.clientY;
31017
+ const borderThreshold = 3;
31018
+ if (clickX < cellRect.left + borderThreshold || clickX > cellRect.right - borderThreshold || clickY < cellRect.top + borderThreshold || clickY > cellRect.bottom - borderThreshold) {
31019
+ return;
31020
+ }
31021
+ event.preventDefault();
31022
+ event.stopPropagation();
31023
+ let foundCellNode = null;
31024
+ let isNodeAttached = false;
31025
+ setTimeout(() => {
31026
+ try {
31040
31027
  editor.getEditorState().read(() => {
31041
31028
  try {
31042
31029
  const allNodes = editor._editorState._nodeMap;
@@ -31060,8 +31047,10 @@ function TableCellActionMenuContainer({
31060
31047
  setContextMenuPosition({ x: event.clientX, y: event.clientY });
31061
31048
  setIsMenuOpen(true);
31062
31049
  }
31063
- }, 10);
31064
- }
31050
+ } catch (error) {
31051
+ console.warn("Error handling context menu:", error);
31052
+ }
31053
+ }, 10);
31065
31054
  };
31066
31055
  return mergeRegister(
31067
31056
  editor.registerUpdateListener(delayedCallback),
@@ -31151,8 +31140,8 @@ function TableCellActionMenuContainer({
31151
31140
  }
31152
31141
  function TableActionMenuPlugin({
31153
31142
  anchorElem,
31154
- // Remove default value here
31155
- cellMerge = false
31143
+ cellMerge = false,
31144
+ isSmallWidthViewport = false
31156
31145
  }) {
31157
31146
  const isEditable = useLexicalEditable();
31158
31147
  if (!anchorElem)
@@ -31162,11 +31151,11 @@ function TableActionMenuPlugin({
31162
31151
  TableCellActionMenuContainer,
31163
31152
  {
31164
31153
  anchorElem,
31165
- cellMerge
31154
+ cellMerge,
31155
+ isSmallWidthViewport
31166
31156
  }
31167
31157
  ) : null,
31168
31158
  anchorElem
31169
- // Use the provided anchor element
31170
31159
  );
31171
31160
  }
31172
31161
  const index = "";
@@ -32121,7 +32110,6 @@ const ToolbarWithEditor = (props) => {
32121
32110
  editor,
32122
32111
  activeEditor: editor,
32123
32112
  setActiveEditor: (newEditor) => {
32124
- console.log("Editor change requested");
32125
32113
  }
32126
32114
  }
32127
32115
  );
@@ -32164,6 +32152,64 @@ const InitialContentPlugin = ({ initialContent }) => {
32164
32152
  }, [editor, initialContent]);
32165
32153
  return null;
32166
32154
  };
32155
+ const CellBackgroundPersistencePlugin = () => {
32156
+ const [editor] = useLexicalComposerContext();
32157
+ useEffect$1(() => {
32158
+ const applyCellStyles = () => {
32159
+ const rootElement = editor.getRootElement();
32160
+ if (!rootElement)
32161
+ return;
32162
+ editor.getEditorState().read(() => {
32163
+ const tables = rootElement.querySelectorAll("table");
32164
+ tables.forEach((tableElement) => {
32165
+ const cells = tableElement.querySelectorAll("td, th");
32166
+ cells.forEach((cell) => {
32167
+ const htmlCell = cell;
32168
+ const cellKey = Object.keys(htmlCell).find((key) => key.startsWith("__reactProps")) ? htmlCell["__lexicalKey"] : void 0;
32169
+ if (!cellKey)
32170
+ return;
32171
+ try {
32172
+ const cellNode = $getNodeByKey(cellKey);
32173
+ if ($isTableCellNode(cellNode)) {
32174
+ const bgColor = cellNode.getBackgroundColor();
32175
+ if (bgColor) {
32176
+ const hex = bgColor.replace("#", "");
32177
+ const r2 = parseInt(hex.substr(0, 2), 16);
32178
+ const g2 = parseInt(hex.substr(2, 2), 16);
32179
+ const b2 = parseInt(hex.substr(4, 2), 16);
32180
+ const luminance = (0.299 * r2 + 0.587 * g2 + 0.114 * b2) / 255;
32181
+ const textColor = luminance > 0.5 ? "#000000" : "#FFFFFF";
32182
+ htmlCell.style.setProperty("background-color", bgColor, "important");
32183
+ htmlCell.style.setProperty("color", textColor, "important");
32184
+ const nestedElements = htmlCell.querySelectorAll("*");
32185
+ nestedElements.forEach((elem) => {
32186
+ if (elem instanceof HTMLElement) {
32187
+ elem.style.setProperty("color", textColor, "important");
32188
+ }
32189
+ });
32190
+ const hasHeaderStyles = cellNode.getHeaderStyles();
32191
+ if (hasHeaderStyles) {
32192
+ htmlCell.style.setProperty("font-weight", "bold", "important");
32193
+ htmlCell.style.setProperty("padding", "8px", "important");
32194
+ }
32195
+ }
32196
+ }
32197
+ } catch (error) {
32198
+ }
32199
+ });
32200
+ });
32201
+ });
32202
+ };
32203
+ const removeUpdateListener = editor.registerUpdateListener(() => {
32204
+ requestAnimationFrame(applyCellStyles);
32205
+ });
32206
+ applyCellStyles();
32207
+ return () => {
32208
+ removeUpdateListener();
32209
+ };
32210
+ }, [editor]);
32211
+ return null;
32212
+ };
32167
32213
  const ConfigurableEditor = ({
32168
32214
  config,
32169
32215
  defaultFontFamilies,
@@ -32232,6 +32278,7 @@ const ConfigurableEditor = ({
32232
32278
  /* @__PURE__ */ jsx(NotePanelPlugin, {}),
32233
32279
  /* @__PURE__ */ jsx(CommentPlugin, {}),
32234
32280
  /* @__PURE__ */ jsx(CommentBubblePlugin, {}),
32281
+ /* @__PURE__ */ jsx(CellBackgroundPersistencePlugin, {}),
32235
32282
  /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
32236
32283
  /* @__PURE__ */ jsx(
32237
32284
  RichTextPlugin,
@@ -32287,25 +32334,24 @@ const ConfigurableEditor = ({
32287
32334
  config.htmlViewOption && !config.toolbarOptions.enableHtmlViewToggle && /* @__PURE__ */ jsx(HtmlViewTogglePlugin, {})
32288
32335
  ] }),
32289
32336
  floatingAnchorElem && /* @__PURE__ */ jsxs(Fragment, { children: [
32290
- !isSmallWidthViewport && /* @__PURE__ */ jsxs(Fragment, { children: [
32291
- /* @__PURE__ */ jsx(
32292
- TableActionMenuPlugin,
32293
- {
32294
- anchorElem: floatingAnchorElem,
32295
- cellMerge: true
32296
- }
32297
- ),
32298
- /* @__PURE__ */ jsx(TableHoverActionsPlugin, { anchorElem: floatingAnchorElem }),
32299
- /* @__PURE__ */ jsx(CodeActionMenuPlugin, { anchorElem: floatingAnchorElem }),
32300
- /* @__PURE__ */ jsx(
32301
- FloatingLinkEditorPlugin,
32302
- {
32303
- anchorElem: floatingAnchorElem,
32304
- isLinkEditMode,
32305
- setIsLinkEditMode
32306
- }
32307
- )
32308
- ] }),
32337
+ /* @__PURE__ */ jsx(
32338
+ TableActionMenuPlugin,
32339
+ {
32340
+ anchorElem: floatingAnchorElem,
32341
+ cellMerge: true,
32342
+ isSmallWidthViewport
32343
+ }
32344
+ ),
32345
+ /* @__PURE__ */ jsx(TableHoverActionsPlugin, { anchorElem: floatingAnchorElem }),
32346
+ /* @__PURE__ */ jsx(CodeActionMenuPlugin, { anchorElem: floatingAnchorElem }),
32347
+ /* @__PURE__ */ jsx(
32348
+ FloatingLinkEditorPlugin,
32349
+ {
32350
+ anchorElem: floatingAnchorElem,
32351
+ isLinkEditMode,
32352
+ setIsLinkEditMode
32353
+ }
32354
+ ),
32309
32355
  config.enableFloatingMenu && /* @__PURE__ */ jsx(
32310
32356
  FloatingTextFormatToolbarPlugin,
32311
32357
  {
@@ -32371,7 +32417,6 @@ const ConfigurableEditorWithAuth = ({
32371
32417
  customVerifyKey
32372
32418
  }) => {
32373
32419
  const { isAuthenticated, isLoading, error, editorConfig: editorConfig2, verifyKey } = useEditor();
32374
- console.log(editorConfig2, "editorConfig");
32375
32420
  const successRef = useRef(onAuthSuccess);
32376
32421
  const errorRef = useRef(onAuthError);
32377
32422
  const hasAttemptedAuthRef = useRef(false);
@@ -32387,9 +32432,7 @@ const ConfigurableEditorWithAuth = ({
32387
32432
  var _a, _b, _c;
32388
32433
  try {
32389
32434
  if (customVerifyKey) {
32390
- console.log("Inside");
32391
32435
  const response = await customVerifyKey(apiKey);
32392
- console.log(response, "response");
32393
32436
  if (response.success) {
32394
32437
  (_a = successRef.current) == null ? void 0 : _a.call(successRef);
32395
32438
  } else {
@@ -32399,7 +32442,6 @@ const ConfigurableEditorWithAuth = ({
32399
32442
  await verifyKey(apiKey);
32400
32443
  }
32401
32444
  } catch (err) {
32402
- console.log(err, "error");
32403
32445
  (_c = errorRef.current) == null ? void 0 : _c.call(errorRef, err.message || "Failed to verify API key");
32404
32446
  }
32405
32447
  };
@@ -32461,4 +32503,4 @@ export {
32461
32503
  useHtmlView as u,
32462
32504
  verifyApiKey as v
32463
32505
  };
32464
- //# sourceMappingURL=index-dbc626d0.js.map
32506
+ //# sourceMappingURL=index-a8476eee.js.map