@underverse-ui/underverse 2.0.26 → 2.0.28

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.
@@ -41,6 +41,12 @@ import {
41
41
  getRelativeCellMetrics,
42
42
  getRelativeSelectedCellsMetrics,
43
43
  getSelectionTableCell,
44
+ isCrossRealmElement,
45
+ isCrossRealmHTMLElement,
46
+ isCrossRealmNode,
47
+ isCrossRealmTable,
48
+ isCrossRealmTableCell,
49
+ isCrossRealmTableRow,
44
50
  isPointOverRenderedText,
45
51
  isRowResizeHotspot,
46
52
  isRowResizingGlobal,
@@ -55,7 +61,7 @@ import {
55
61
  sanitizeUEditorUrl,
56
62
  useEditorColors,
57
63
  useSharedEditorUiRenderState
58
- } from "./chunk-OJF3XRN7.js";
64
+ } from "./chunk-KTOXCD6J.js";
59
65
  import {
60
66
  Tooltip,
61
67
  UEditorPortalProvider,
@@ -3365,8 +3371,7 @@ function setColumnStyle(column, width) {
3365
3371
  column.style.minWidth = "";
3366
3372
  }
3367
3373
  function isTableColumnElement(node) {
3368
- const realm = node?.ownerDocument?.defaultView;
3369
- return Boolean(realm && node instanceof realm.HTMLTableColElement && node.tagName.toLowerCase() === "col");
3374
+ return isCrossRealmElement(node) && String(node.tagName).toUpperCase() === "COL";
3370
3375
  }
3371
3376
  function updateDynamicColumns(node, colgroup, table, ownerDocument, overrideCol, overrideValue) {
3372
3377
  let totalWidth = 0;
@@ -3439,8 +3444,7 @@ function getCurrentColWidth(view, cellPos, { colspan, colwidth }) {
3439
3444
  if (width) return width;
3440
3445
  const dom = view.domAtPos(cellPos);
3441
3446
  const cellElement = dom.node.childNodes[dom.offset];
3442
- const realm = view.dom.ownerDocument.defaultView;
3443
- let domWidth = realm && cellElement instanceof realm.HTMLElement ? cellElement.offsetWidth : 0;
3447
+ let domWidth = isCrossRealmHTMLElement(cellElement) ? cellElement.offsetWidth : 0;
3444
3448
  let parts = Math.max(1, colspan);
3445
3449
  if (colwidth) {
3446
3450
  for (let index = 0; index < colspan; index += 1) {
@@ -3454,14 +3458,13 @@ function getCurrentColWidth(view, cellPos, { colspan, colwidth }) {
3454
3458
  return domWidth / Math.max(1, parts);
3455
3459
  }
3456
3460
  function domCellAround(view, target) {
3457
- const realm = view.dom.ownerDocument.defaultView;
3458
- let node = realm && target instanceof realm.Node ? target : null;
3461
+ let node = isCrossRealmNode(target) ? target : null;
3459
3462
  while (node && node.nodeName !== "TD" && node.nodeName !== "TH") {
3460
- const element = realm && node instanceof realm.Element ? node : null;
3463
+ const element = isCrossRealmElement(node) ? node : null;
3461
3464
  if (element?.classList.contains("ProseMirror")) return null;
3462
3465
  node = node.parentNode;
3463
3466
  }
3464
- return realm && node instanceof realm.HTMLElement ? node : null;
3467
+ return isCrossRealmHTMLElement(node) ? node : null;
3465
3468
  }
3466
3469
  function edgeCell(view, event, side, handleWidth) {
3467
3470
  const offset = side === "right" ? -handleWidth : handleWidth;
@@ -3607,8 +3610,7 @@ function getTableElementAtCell(view, cell) {
3607
3610
  const $cell = view.state.doc.resolve(cell);
3608
3611
  let dom = view.domAtPos($cell.start(-1)).node;
3609
3612
  while (dom && dom.nodeName !== "TABLE") dom = dom.parentNode;
3610
- const realm = view.dom.ownerDocument.defaultView;
3611
- return realm && dom instanceof realm.HTMLTableElement ? dom : null;
3613
+ return isCrossRealmTable(dom) ? dom : null;
3612
3614
  }
3613
3615
  function showColumnResizeGhost(view, cell, dragging, width) {
3614
3616
  const table = getTableElementAtCell(view, cell);
@@ -11551,20 +11553,16 @@ import {
11551
11553
  var FALLBACK_TABLE_ROW_HEIGHT = DEFAULT_TABLE_ROW_HEIGHT;
11552
11554
  var FALLBACK_TABLE_COLUMN_WIDTH = 160;
11553
11555
  function isTableCellElement(element) {
11554
- const realm = element?.ownerDocument?.defaultView;
11555
- return Boolean(realm && element instanceof realm.HTMLTableCellElement);
11556
+ return isCrossRealmTableCell(element);
11556
11557
  }
11557
11558
  function isTableRowElement(element) {
11558
- const realm = element?.ownerDocument?.defaultView;
11559
- return Boolean(realm && element instanceof realm.HTMLTableRowElement);
11559
+ return isCrossRealmTableRow(element);
11560
11560
  }
11561
11561
  function isTableElement(element) {
11562
- const realm = element?.ownerDocument?.defaultView;
11563
- return Boolean(realm && element instanceof realm.HTMLTableElement);
11562
+ return isCrossRealmTable(element);
11564
11563
  }
11565
11564
  function isHTMLElement(element) {
11566
- const realm = element?.ownerDocument?.defaultView;
11567
- return Boolean(realm && element instanceof realm.HTMLElement);
11565
+ return isCrossRealmHTMLElement(element);
11568
11566
  }
11569
11567
  function getVisibleTableBounds(layout) {
11570
11568
  const left = Math.max(layout.tableLeft, layout.wrapperLeft);
@@ -11658,7 +11656,7 @@ function buildLogicalColumnMetrics({
11658
11656
  if (relativeCellPos == null) continue;
11659
11657
  const cellMapRect = map.findCell(relativeCellPos);
11660
11658
  const cellRect = tableCell.getBoundingClientRect();
11661
- const cellStart = cellRect.width > 0 ? cellRect.left - surfaceRect.left + surface.scrollLeft : tableLeft + cellMapRect.left * fallbackWidth;
11659
+ const cellStart = cellRect.width > 0 ? cellRect.left - surfaceRect.left - surface.clientLeft + surface.scrollLeft : tableLeft + cellMapRect.left * fallbackWidth;
11662
11660
  const size = metricOrFallback(cellRect.width, fallbackWidth * Math.max(1, cellMapRect.right - cellMapRect.left));
11663
11661
  visualColumns.push({
11664
11662
  index: cellMapRect.left,
@@ -11713,7 +11711,7 @@ function buildLogicalRowMetrics({
11713
11711
  const tableCell = isTableCellElement(cellCandidate) ? cellCandidate : null;
11714
11712
  if (tableCell) {
11715
11713
  const cellRect = tableCell.getBoundingClientRect();
11716
- const start = cellRect.height > 0 ? cellRect.top - surfaceRect.top + surface.scrollTop : tableTop + cellMapRect.top * fallbackHeight;
11714
+ const start = cellRect.height > 0 ? cellRect.top - surfaceRect.top - surface.clientTop + surface.scrollTop : tableTop + cellMapRect.top * fallbackHeight;
11717
11715
  const size = metricOrFallback(cellRect.height, fallbackHeight * Math.max(1, cellMapRect.bottom - cellMapRect.top));
11718
11716
  visualRows.push({
11719
11717
  index: cellMapRect.top,
@@ -11730,7 +11728,7 @@ function buildLogicalRowMetrics({
11730
11728
  return rows.map((tableRow, index) => {
11731
11729
  const rowRect = tableRow.getBoundingClientRect();
11732
11730
  const anchorCell = tableRow.cells.item(0) ?? cornerCell;
11733
- const start = rowRect.height > 0 ? rowRect.top - surfaceRect.top + surface.scrollTop : tableTop + index * fallbackHeight;
11731
+ const start = rowRect.height > 0 ? rowRect.top - surfaceRect.top - surface.clientTop + surface.scrollTop : tableTop + index * fallbackHeight;
11734
11732
  const size = metricOrFallback(rowRect.height, fallbackHeight);
11735
11733
  return {
11736
11734
  index,
@@ -11772,6 +11770,8 @@ function buildTableControlLayout(editor, surface, cell) {
11772
11770
  }
11773
11771
  const map = TableMap3.get(tableInfo.node);
11774
11772
  const surfaceRect = surface.getBoundingClientRect();
11773
+ const surfaceOriginLeft = surfaceRect.left + surface.clientLeft;
11774
+ const surfaceOriginTop = surfaceRect.top + surface.clientTop;
11775
11775
  const tableRect = table.getBoundingClientRect();
11776
11776
  const explicitColumnWidths = Array.from(table.querySelectorAll("colgroup > col")).slice(0, map.width).map((column) => parsePixelMetric(column.style.width));
11777
11777
  const explicitTableWidth = parsePixelMetric(table.style.width) ?? (explicitColumnWidths.length === map.width && explicitColumnWidths.every((width) => width !== null) ? explicitColumnWidths.reduce((sum, width) => sum + width, 0) : null);
@@ -11780,14 +11780,14 @@ function buildTableControlLayout(editor, surface, cell) {
11780
11780
  const wrapperElement = table.closest(".tableWrapper");
11781
11781
  const wrapper = isHTMLElement(wrapperElement) ? wrapperElement : null;
11782
11782
  const wrapperRect = wrapper?.getBoundingClientRect() ?? tableRect;
11783
- const tableLeft = tableRect.left - surfaceRect.left + surface.scrollLeft;
11784
- const tableTop = tableRect.top - surfaceRect.top + surface.scrollTop;
11783
+ const tableLeft = tableRect.left - surfaceOriginLeft + surface.scrollLeft;
11784
+ const tableTop = tableRect.top - surfaceOriginTop + surface.scrollTop;
11785
11785
  const tableWidth = metricOrFallback(tableRect.width, explicitTableWidth ?? FALLBACK_TABLE_COLUMN_WIDTH * map.width);
11786
11786
  const tableHeight = metricOrFallback(tableRect.height, explicitTableHeight ?? FALLBACK_TABLE_ROW_HEIGHT * rows.length);
11787
11787
  const avgRowHeight = metricOrFallback(tableHeight / rows.length, FALLBACK_TABLE_ROW_HEIGHT);
11788
11788
  const avgColumnWidth = metricOrFallback(tableWidth / map.width, FALLBACK_TABLE_COLUMN_WIDTH);
11789
- const wrapperLeft = wrapperRect.left - surfaceRect.left + surface.scrollLeft;
11790
- const wrapperTop = wrapperRect.top - surfaceRect.top + surface.scrollTop;
11789
+ const wrapperLeft = wrapperRect.left - surfaceOriginLeft + surface.scrollLeft;
11790
+ const wrapperTop = wrapperRect.top - surfaceOriginTop + surface.scrollTop;
11791
11791
  const wrapperWidth = metricOrFallback(wrapperRect.width, tableWidth);
11792
11792
  const wrapperHeight = metricOrFallback(wrapperRect.height, tableHeight);
11793
11793
  const viewportWidth = metricOrFallback(wrapper?.clientWidth ?? wrapperRect.width, tableWidth);
@@ -11848,8 +11848,7 @@ var ADD_COLUMN_HOVER_WIDTH = 24;
11848
11848
  var ADD_ROW_HOVER_HEIGHT = 24;
11849
11849
  var HANDLE_HOVER_RADIUS = 14;
11850
11850
  function isHTMLElement2(element) {
11851
- const realm = element?.ownerDocument?.defaultView;
11852
- return Boolean(realm && element instanceof realm.HTMLElement);
11851
+ return isCrossRealmHTMLElement(element);
11853
11852
  }
11854
11853
  var DEFAULT_TABLE_HOVER_STATE = {
11855
11854
  menuVisible: false,
@@ -11870,8 +11869,8 @@ function buildTableHoverState({
11870
11869
  return DEFAULT_TABLE_HOVER_STATE;
11871
11870
  }
11872
11871
  const surfaceRect = surface.getBoundingClientRect();
11873
- const relativeX = event.clientX - surfaceRect.left + surface.scrollLeft;
11874
- const relativeY = event.clientY - surfaceRect.top + surface.scrollTop;
11872
+ const relativeX = event.clientX - surfaceRect.left - surface.clientLeft + surface.scrollLeft;
11873
+ const relativeY = event.clientY - surfaceRect.top - surface.clientTop + surface.scrollTop;
11875
11874
  const targetElement = resolveEventElement(event.target);
11876
11875
  const directRowHandle = targetElement?.closest?.("[data-row-handle-index]");
11877
11876
  const directColumnHandle = targetElement?.closest?.("[data-column-handle-index]");
@@ -12568,7 +12567,7 @@ function getSelectedCell(editor) {
12568
12567
  const browserSelection = editorWindow?.getSelection();
12569
12568
  const anchorElement = resolveEventElement(browserSelection?.anchorNode ?? null);
12570
12569
  const anchorCell = anchorElement?.closest?.("th,td");
12571
- if (editorWindow && anchorCell instanceof editorWindow.HTMLTableCellElement) {
12570
+ if (isCrossRealmTableCell(anchorCell)) {
12572
12571
  return anchorCell;
12573
12572
  }
12574
12573
  const domAtPos = editor.view.domAtPos(editor.state.selection.from);
@@ -12769,6 +12768,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
12769
12768
  surface.addEventListener(UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, scheduleCurrentLayoutRefresh);
12770
12769
  if (!editorWindow) return void 0;
12771
12770
  const unsubscribeResize = subscribeSharedGlobalEvent(editorWindow, "resize", scheduleCurrentLayoutRefresh);
12771
+ const unsubscribeWindowScroll = subscribeSharedGlobalEvent(editorWindow, "scroll", scheduleCurrentLayoutRefresh, { passive: true });
12772
12772
  editor.on("selectionUpdate", scheduleSyncFromSelection);
12773
12773
  editor.on("update", scheduleCurrentLayoutRefresh);
12774
12774
  syncFromSelection();
@@ -12784,6 +12784,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
12784
12784
  surface.removeEventListener("scroll", scheduleCurrentLayoutRefresh, scrollListenerOptions);
12785
12785
  surface.removeEventListener(UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, scheduleCurrentLayoutRefresh);
12786
12786
  unsubscribeResize();
12787
+ unsubscribeWindowScroll();
12787
12788
  editor.off("selectionUpdate", scheduleSyncFromSelection);
12788
12789
  editor.off("update", scheduleCurrentLayoutRefresh);
12789
12790
  };
@@ -13631,12 +13632,12 @@ function useUEditorTableInteractions(editor, editable = true) {
13631
13632
  return;
13632
13633
  }
13633
13634
  const target = resolveEventElement(event.target);
13634
- if (!(target instanceof editorWindow.Element)) {
13635
+ if (!isCrossRealmElement(target)) {
13635
13636
  clearAllTableResizeHover();
13636
13637
  return;
13637
13638
  }
13638
13639
  const cell = target.closest("th,td");
13639
- if (!(cell instanceof editorWindow.HTMLElement)) {
13640
+ if (!isCrossRealmHTMLElement(cell)) {
13640
13641
  clearHoveredTableCell();
13641
13642
  clearAllTableResizeHover();
13642
13643
  return;
@@ -13644,7 +13645,7 @@ function useUEditorTableInteractions(editor, editable = true) {
13644
13645
  setHoveredTableCell(cell);
13645
13646
  const row = cell.closest("tr");
13646
13647
  const table = cell.closest("table");
13647
- if (!(row instanceof editorWindow.HTMLTableRowElement) || !(table instanceof editorWindow.HTMLTableElement)) {
13648
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTable(table)) {
13648
13649
  clearHoveredTableCell();
13649
13650
  clearAllTableResizeHover();
13650
13651
  return;
@@ -13700,18 +13701,18 @@ function useUEditorTableInteractions(editor, editable = true) {
13700
13701
  const handleEditorMouseDown = (event) => {
13701
13702
  if (event.button !== 0) return;
13702
13703
  const target = resolveEventElement(event.target);
13703
- if (!(target instanceof editorWindow.Element)) {
13704
+ if (!isCrossRealmElement(target)) {
13704
13705
  clearActiveTableCell();
13705
13706
  return;
13706
13707
  }
13707
13708
  const cell = target.closest("th,td");
13708
- if (!(cell instanceof editorWindow.HTMLTableCellElement)) {
13709
+ if (!isCrossRealmTableCell(cell)) {
13709
13710
  clearActiveTableCell();
13710
13711
  return;
13711
13712
  }
13712
13713
  const row = cell.closest("tr");
13713
13714
  const table = cell.closest("table");
13714
- if (!(row instanceof editorWindow.HTMLTableRowElement) || !(table instanceof editorWindow.HTMLTableElement)) return;
13715
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTable(table)) return;
13715
13716
  const rowTarget = resolveRowResizeTarget(cell, event.clientX, event.clientY);
13716
13717
  if (rowTarget) {
13717
13718
  event.preventDefault();
@@ -14541,7 +14542,7 @@ function useUEditorOutput({
14541
14542
  // src/components/UEditor/UEditor.tsx
14542
14543
  import { jsx as jsx20, jsxs as jsxs17 } from "react/jsx-runtime";
14543
14544
  var LazyMenuBar = React15.lazy(async () => {
14544
- const { MenuBar } = await import("./menu-bar-4FM4Y273.js");
14545
+ const { MenuBar } = await import("./menu-bar-CFIWMBAA.js");
14545
14546
  return { default: MenuBar };
14546
14547
  });
14547
14548
  var UEditor = React15.forwardRef(({
@@ -15010,4 +15011,4 @@ export {
15010
15011
  prepareUEditorContentForSave,
15011
15012
  UEditor_default
15012
15013
  };
15013
- //# sourceMappingURL=chunk-GS24SZVS.js.map
15014
+ //# sourceMappingURL=chunk-QYFXYDBK.js.map