@trafica/editor 1.0.18 → 1.0.20

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
@@ -7879,6 +7879,11 @@ function EditorCore({
7879
7879
  onJSONChange(jsonSerializer.serialize(state.doc));
7880
7880
  }
7881
7881
  }, [state.doc]);
7882
+ useLayoutEffect(() => {
7883
+ const container = containerRef.current;
7884
+ if (!container || !state.selection) return;
7885
+ restoreSelection(container, state.selection);
7886
+ }, [state.selection]);
7882
7887
  useEffect(() => {
7883
7888
  const container = containerRef.current;
7884
7889
  if (!container || readOnly) return;
@@ -7906,6 +7911,30 @@ function EditorCore({
7906
7911
  }
7907
7912
  }
7908
7913
  }, [tableSelection, state.doc]);
7914
+ useEffect(() => {
7915
+ const container = containerRef.current;
7916
+ if (!container) return;
7917
+ container.querySelectorAll(".editor-cell-active").forEach((el) => {
7918
+ el.classList.remove("editor-cell-active");
7919
+ });
7920
+ if (!inTableCellPos) {
7921
+ setTableSelection(null);
7922
+ return;
7923
+ }
7924
+ if (tableSelection) {
7925
+ const { anchorCell, focusCell, tablePath } = tableSelection;
7926
+ const sameTable = JSON.stringify(tablePath) === JSON.stringify(inTableCellPos.tablePath);
7927
+ const singleCell = anchorCell[0] === focusCell[0] && anchorCell[1] === focusCell[1];
7928
+ if (!sameTable || singleCell) {
7929
+ setTableSelection(null);
7930
+ }
7931
+ }
7932
+ const cellPath = [...inTableCellPos.tablePath, inTableCellPos.row, inTableCellPos.col];
7933
+ const td = container.querySelector(
7934
+ `[data-block-path="${JSON.stringify(cellPath)}"]`
7935
+ );
7936
+ if (td) td.classList.add("editor-cell-active");
7937
+ }, [inTableCellPos, state.doc]);
7909
7938
  useEffect(() => {
7910
7939
  const onSelectionChange = () => {
7911
7940
  if (isRenderingRef.current) return;
@@ -8016,6 +8045,9 @@ function EditorCore({
8016
8045
  }
8017
8046
  return;
8018
8047
  }
8048
+ if (findCellPosition(doc, sel.anchor.path)) {
8049
+ e.preventDefault();
8050
+ }
8019
8051
  }
8020
8052
  }
8021
8053
  const handled = engine.handleKeyDown(
@@ -8549,7 +8581,7 @@ function leafTextNode(el, end) {
8549
8581
  function prettyPrintHTML(html) {
8550
8582
  const blockOpen = new RegExp(`(<(?:${BLOCK_TAGS})(?:\\s[^>]*)?>)`, "gi");
8551
8583
  const blockClose = new RegExp(`(<\\/(?:${BLOCK_TAGS})>)`, "gi");
8552
- const spread = html.replace(blockOpen, "\n$1\n").replace(blockClose, "\n$1\n").replace(/<hr(\s[^>]*)?\/?>(\s*)/gi, "\n<hr />\n");
8584
+ const spread = html.replace(blockOpen, "\n$1").replace(blockClose, "$1\n").replace(/<hr(\s[^>]*)?\/?>(\s*)/gi, "\n<hr />\n");
8553
8585
  let depth = 0;
8554
8586
  const result = [];
8555
8587
  for (const raw of spread.split("\n")) {