@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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getPanelBorderRadiusClass,
3
3
  useUnderverseUIConfig
4
- } from "./chunk-OJF3XRN7.js";
4
+ } from "./chunk-KTOXCD6J.js";
5
5
  import {
6
6
  cn,
7
7
  useGlobalI18n
@@ -196,4 +196,4 @@ var Modal_default = Modal;
196
196
  export {
197
197
  Modal_default
198
198
  };
199
- //# sourceMappingURL=chunk-FFVBGTHU.js.map
199
+ //# sourceMappingURL=chunk-Y4X6CAZY.js.map
package/dist/index.cjs CHANGED
@@ -6000,6 +6000,24 @@ var init_clipboard_images = __esm({
6000
6000
  });
6001
6001
 
6002
6002
  // src/components/UEditor/table-dom-utils.ts
6003
+ function isCrossRealmNode(value) {
6004
+ return Boolean(value && typeof value === "object" && value.nodeType != null);
6005
+ }
6006
+ function isCrossRealmElement(value) {
6007
+ return isCrossRealmNode(value) && value.nodeType === 1 && typeof value.closest === "function";
6008
+ }
6009
+ function isCrossRealmHTMLElement(value) {
6010
+ return isCrossRealmElement(value) && typeof value.style === "object";
6011
+ }
6012
+ function isCrossRealmTable(value) {
6013
+ return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TABLE" && "rows" in value;
6014
+ }
6015
+ function isCrossRealmTableRow(value) {
6016
+ return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TR" && "cells" in value;
6017
+ }
6018
+ function isCrossRealmTableCell(value) {
6019
+ return isCrossRealmElement(value) && ["TD", "TH"].includes(String(value.tagName).toUpperCase()) && "cellIndex" in value;
6020
+ }
6003
6021
  function findTableRowNodeInfo(view, rowElement) {
6004
6022
  const firstCell = rowElement.querySelector("th,td");
6005
6023
  if (!firstCell) return null;
@@ -6017,10 +6035,8 @@ function findTableRowNodeInfo(view, rowElement) {
6017
6035
  return null;
6018
6036
  }
6019
6037
  function resolveEventElement(target) {
6020
- const ownerDocument = target?.ownerDocument;
6021
- const realm = ownerDocument?.defaultView;
6022
- if (realm && target instanceof realm.Element) return target;
6023
- if (realm && target instanceof realm.Node) return target.parentElement;
6038
+ if (isCrossRealmElement(target)) return target;
6039
+ if (isCrossRealmNode(target)) return target.parentElement;
6024
6040
  return null;
6025
6041
  }
6026
6042
  function isPointOverRenderedText(root, clientX, clientY) {
@@ -6115,24 +6131,28 @@ function isRowResizeHotspot(cell, clientX, clientY) {
6115
6131
  }
6116
6132
  function getRelativeBoundaryMetrics(surface, table, row, cell) {
6117
6133
  const surfaceRect = surface.getBoundingClientRect();
6134
+ const originLeft = surfaceRect.left + surface.clientLeft;
6135
+ const originTop = surfaceRect.top + surface.clientTop;
6118
6136
  const tableRect = table.getBoundingClientRect();
6119
6137
  const rowRect = row.getBoundingClientRect();
6120
6138
  const cellRect = cell.getBoundingClientRect();
6121
6139
  return {
6122
- left: tableRect.left - surfaceRect.left + surface.scrollLeft,
6123
- top: tableRect.top - surfaceRect.top + surface.scrollTop,
6140
+ left: tableRect.left - originLeft + surface.scrollLeft,
6141
+ top: tableRect.top - originTop + surface.scrollTop,
6124
6142
  width: tableRect.width,
6125
6143
  height: tableRect.height,
6126
- rowBottom: rowRect.bottom - surfaceRect.top + surface.scrollTop,
6127
- columnRight: cellRect.right - surfaceRect.left + surface.scrollLeft
6144
+ rowBottom: rowRect.bottom - originTop + surface.scrollTop,
6145
+ columnRight: cellRect.right - originLeft + surface.scrollLeft
6128
6146
  };
6129
6147
  }
6130
6148
  function getRelativeCellMetrics(surface, cell) {
6131
6149
  const surfaceRect = surface.getBoundingClientRect();
6150
+ const originLeft = surfaceRect.left + surface.clientLeft;
6151
+ const originTop = surfaceRect.top + surface.clientTop;
6132
6152
  const cellRect = cell.getBoundingClientRect();
6133
6153
  return {
6134
- left: cellRect.left - surfaceRect.left + surface.scrollLeft,
6135
- top: cellRect.top - surfaceRect.top + surface.scrollTop,
6154
+ left: cellRect.left - originLeft + surface.scrollLeft,
6155
+ top: cellRect.top - originTop + surface.scrollTop,
6136
6156
  width: cellRect.width,
6137
6157
  height: cellRect.height
6138
6158
  };
@@ -6145,6 +6165,8 @@ function getRelativeSelectedCellsMetrics(surface) {
6145
6165
  return null;
6146
6166
  }
6147
6167
  const surfaceRect = surface.getBoundingClientRect();
6168
+ const originLeft = surfaceRect.left + surface.clientLeft;
6169
+ const originTop = surfaceRect.top + surface.clientTop;
6148
6170
  let left = Number.POSITIVE_INFINITY;
6149
6171
  let top = Number.POSITIVE_INFINITY;
6150
6172
  let right = Number.NEGATIVE_INFINITY;
@@ -6157,8 +6179,8 @@ function getRelativeSelectedCellsMetrics(surface) {
6157
6179
  bottom = Math.max(bottom, rect.bottom);
6158
6180
  });
6159
6181
  return {
6160
- left: left - surfaceRect.left + surface.scrollLeft,
6161
- top: top - surfaceRect.top + surface.scrollTop,
6182
+ left: left - originLeft + surface.scrollLeft,
6183
+ top: top - originTop + surface.scrollTop,
6162
6184
  width: right - left,
6163
6185
  height: bottom - top
6164
6186
  };
@@ -6210,8 +6232,8 @@ function applyTableAlignment(editor, tableAlign, anchorPos) {
6210
6232
  const domAtTable = editor.view.domAtPos(Math.min(tableInfo.pos + 1, editor.state.doc.content.size)).node;
6211
6233
  const domAtTableElement = resolveEventElement(domAtTable);
6212
6234
  const tableDom = editor.view.nodeDOM(tableInfo.pos);
6213
- const tableElement = domAtTableElement?.closest?.("table") ?? (tableDom instanceof HTMLTableElement ? tableDom : tableDom instanceof HTMLElement ? tableDom.querySelector("table") : null) ?? (editor.view.dom.querySelectorAll("table").length === 1 ? editor.view.dom.querySelector("table") : null);
6214
- if (tableElement instanceof HTMLTableElement) {
6235
+ const tableElement = domAtTableElement?.closest?.("table") ?? (isCrossRealmTable(tableDom) ? tableDom : isCrossRealmHTMLElement(tableDom) ? tableDom.querySelector("table") : null) ?? (editor.view.dom.querySelectorAll("table").length === 1 ? editor.view.dom.querySelector("table") : null);
6236
+ if (isCrossRealmTable(tableElement)) {
6215
6237
  tableElement.style.tableLayout = "fixed";
6216
6238
  if (tableElement.style.width === "max-content") {
6217
6239
  tableElement.style.removeProperty("width");
@@ -36840,6 +36862,7 @@ var import_tables3 = require("@tiptap/pm/tables");
36840
36862
  var import_state6 = require("@tiptap/pm/state");
36841
36863
  var import_view2 = require("@tiptap/pm/view");
36842
36864
  var import_tables2 = require("@tiptap/pm/tables");
36865
+ init_table_dom_utils();
36843
36866
  var DEFAULT_TABLE_COLUMN_WIDTH = 100;
36844
36867
  var MIN_RESIZED_TABLE_COLUMN_WIDTH = 25;
36845
36868
  function getColumnResizeMinWidth(configuredMinWidth) {
@@ -36856,8 +36879,7 @@ function setColumnStyle(column, width) {
36856
36879
  column.style.minWidth = "";
36857
36880
  }
36858
36881
  function isTableColumnElement(node) {
36859
- const realm = node?.ownerDocument?.defaultView;
36860
- return Boolean(realm && node instanceof realm.HTMLTableColElement && node.tagName.toLowerCase() === "col");
36882
+ return isCrossRealmElement(node) && String(node.tagName).toUpperCase() === "COL";
36861
36883
  }
36862
36884
  function updateDynamicColumns(node, colgroup, table, ownerDocument, overrideCol, overrideValue) {
36863
36885
  let totalWidth = 0;
@@ -36930,8 +36952,7 @@ function getCurrentColWidth(view, cellPos, { colspan, colwidth }) {
36930
36952
  if (width) return width;
36931
36953
  const dom = view.domAtPos(cellPos);
36932
36954
  const cellElement = dom.node.childNodes[dom.offset];
36933
- const realm = view.dom.ownerDocument.defaultView;
36934
- let domWidth = realm && cellElement instanceof realm.HTMLElement ? cellElement.offsetWidth : 0;
36955
+ let domWidth = isCrossRealmHTMLElement(cellElement) ? cellElement.offsetWidth : 0;
36935
36956
  let parts = Math.max(1, colspan);
36936
36957
  if (colwidth) {
36937
36958
  for (let index = 0; index < colspan; index += 1) {
@@ -36945,14 +36966,13 @@ function getCurrentColWidth(view, cellPos, { colspan, colwidth }) {
36945
36966
  return domWidth / Math.max(1, parts);
36946
36967
  }
36947
36968
  function domCellAround(view, target) {
36948
- const realm = view.dom.ownerDocument.defaultView;
36949
- let node = realm && target instanceof realm.Node ? target : null;
36969
+ let node = isCrossRealmNode(target) ? target : null;
36950
36970
  while (node && node.nodeName !== "TD" && node.nodeName !== "TH") {
36951
- const element = realm && node instanceof realm.Element ? node : null;
36971
+ const element = isCrossRealmElement(node) ? node : null;
36952
36972
  if (element?.classList.contains("ProseMirror")) return null;
36953
36973
  node = node.parentNode;
36954
36974
  }
36955
- return realm && node instanceof realm.HTMLElement ? node : null;
36975
+ return isCrossRealmHTMLElement(node) ? node : null;
36956
36976
  }
36957
36977
  function edgeCell(view, event, side, handleWidth) {
36958
36978
  const offset = side === "right" ? -handleWidth : handleWidth;
@@ -37098,8 +37118,7 @@ function getTableElementAtCell(view, cell) {
37098
37118
  const $cell = view.state.doc.resolve(cell);
37099
37119
  let dom = view.domAtPos($cell.start(-1)).node;
37100
37120
  while (dom && dom.nodeName !== "TABLE") dom = dom.parentNode;
37101
- const realm = view.dom.ownerDocument.defaultView;
37102
- return realm && dom instanceof realm.HTMLTableElement ? dom : null;
37121
+ return isCrossRealmTable(dom) ? dom : null;
37103
37122
  }
37104
37123
  function showColumnResizeGhost(view, cell, dragging, width) {
37105
37124
  const table = getTableElementAtCell(view, cell);
@@ -45449,20 +45468,16 @@ init_table_dom_utils();
45449
45468
  var FALLBACK_TABLE_ROW_HEIGHT = DEFAULT_TABLE_ROW_HEIGHT;
45450
45469
  var FALLBACK_TABLE_COLUMN_WIDTH = 160;
45451
45470
  function isTableCellElement(element) {
45452
- const realm = element?.ownerDocument?.defaultView;
45453
- return Boolean(realm && element instanceof realm.HTMLTableCellElement);
45471
+ return isCrossRealmTableCell(element);
45454
45472
  }
45455
45473
  function isTableRowElement(element) {
45456
- const realm = element?.ownerDocument?.defaultView;
45457
- return Boolean(realm && element instanceof realm.HTMLTableRowElement);
45474
+ return isCrossRealmTableRow(element);
45458
45475
  }
45459
45476
  function isTableElement(element) {
45460
- const realm = element?.ownerDocument?.defaultView;
45461
- return Boolean(realm && element instanceof realm.HTMLTableElement);
45477
+ return isCrossRealmTable(element);
45462
45478
  }
45463
45479
  function isHTMLElement(element) {
45464
- const realm = element?.ownerDocument?.defaultView;
45465
- return Boolean(realm && element instanceof realm.HTMLElement);
45480
+ return isCrossRealmHTMLElement(element);
45466
45481
  }
45467
45482
  function getVisibleTableBounds(layout) {
45468
45483
  const left = Math.max(layout.tableLeft, layout.wrapperLeft);
@@ -45556,7 +45571,7 @@ function buildLogicalColumnMetrics({
45556
45571
  if (relativeCellPos == null) continue;
45557
45572
  const cellMapRect = map.findCell(relativeCellPos);
45558
45573
  const cellRect = tableCell.getBoundingClientRect();
45559
- const cellStart = cellRect.width > 0 ? cellRect.left - surfaceRect.left + surface.scrollLeft : tableLeft + cellMapRect.left * fallbackWidth;
45574
+ const cellStart = cellRect.width > 0 ? cellRect.left - surfaceRect.left - surface.clientLeft + surface.scrollLeft : tableLeft + cellMapRect.left * fallbackWidth;
45560
45575
  const size = metricOrFallback(cellRect.width, fallbackWidth * Math.max(1, cellMapRect.right - cellMapRect.left));
45561
45576
  visualColumns.push({
45562
45577
  index: cellMapRect.left,
@@ -45611,7 +45626,7 @@ function buildLogicalRowMetrics({
45611
45626
  const tableCell = isTableCellElement(cellCandidate) ? cellCandidate : null;
45612
45627
  if (tableCell) {
45613
45628
  const cellRect = tableCell.getBoundingClientRect();
45614
- const start = cellRect.height > 0 ? cellRect.top - surfaceRect.top + surface.scrollTop : tableTop + cellMapRect.top * fallbackHeight;
45629
+ const start = cellRect.height > 0 ? cellRect.top - surfaceRect.top - surface.clientTop + surface.scrollTop : tableTop + cellMapRect.top * fallbackHeight;
45615
45630
  const size = metricOrFallback(cellRect.height, fallbackHeight * Math.max(1, cellMapRect.bottom - cellMapRect.top));
45616
45631
  visualRows.push({
45617
45632
  index: cellMapRect.top,
@@ -45628,7 +45643,7 @@ function buildLogicalRowMetrics({
45628
45643
  return rows.map((tableRow, index) => {
45629
45644
  const rowRect = tableRow.getBoundingClientRect();
45630
45645
  const anchorCell = tableRow.cells.item(0) ?? cornerCell;
45631
- const start = rowRect.height > 0 ? rowRect.top - surfaceRect.top + surface.scrollTop : tableTop + index * fallbackHeight;
45646
+ const start = rowRect.height > 0 ? rowRect.top - surfaceRect.top - surface.clientTop + surface.scrollTop : tableTop + index * fallbackHeight;
45632
45647
  const size = metricOrFallback(rowRect.height, fallbackHeight);
45633
45648
  return {
45634
45649
  index,
@@ -45670,6 +45685,8 @@ function buildTableControlLayout(editor, surface, cell) {
45670
45685
  }
45671
45686
  const map = TableMap4.get(tableInfo.node);
45672
45687
  const surfaceRect = surface.getBoundingClientRect();
45688
+ const surfaceOriginLeft = surfaceRect.left + surface.clientLeft;
45689
+ const surfaceOriginTop = surfaceRect.top + surface.clientTop;
45673
45690
  const tableRect = table.getBoundingClientRect();
45674
45691
  const explicitColumnWidths = Array.from(table.querySelectorAll("colgroup > col")).slice(0, map.width).map((column) => parsePixelMetric(column.style.width));
45675
45692
  const explicitTableWidth = parsePixelMetric(table.style.width) ?? (explicitColumnWidths.length === map.width && explicitColumnWidths.every((width) => width !== null) ? explicitColumnWidths.reduce((sum, width) => sum + width, 0) : null);
@@ -45678,14 +45695,14 @@ function buildTableControlLayout(editor, surface, cell) {
45678
45695
  const wrapperElement = table.closest(".tableWrapper");
45679
45696
  const wrapper = isHTMLElement(wrapperElement) ? wrapperElement : null;
45680
45697
  const wrapperRect = wrapper?.getBoundingClientRect() ?? tableRect;
45681
- const tableLeft = tableRect.left - surfaceRect.left + surface.scrollLeft;
45682
- const tableTop = tableRect.top - surfaceRect.top + surface.scrollTop;
45698
+ const tableLeft = tableRect.left - surfaceOriginLeft + surface.scrollLeft;
45699
+ const tableTop = tableRect.top - surfaceOriginTop + surface.scrollTop;
45683
45700
  const tableWidth = metricOrFallback(tableRect.width, explicitTableWidth ?? FALLBACK_TABLE_COLUMN_WIDTH * map.width);
45684
45701
  const tableHeight = metricOrFallback(tableRect.height, explicitTableHeight ?? FALLBACK_TABLE_ROW_HEIGHT * rows.length);
45685
45702
  const avgRowHeight = metricOrFallback(tableHeight / rows.length, FALLBACK_TABLE_ROW_HEIGHT);
45686
45703
  const avgColumnWidth = metricOrFallback(tableWidth / map.width, FALLBACK_TABLE_COLUMN_WIDTH);
45687
- const wrapperLeft = wrapperRect.left - surfaceRect.left + surface.scrollLeft;
45688
- const wrapperTop = wrapperRect.top - surfaceRect.top + surface.scrollTop;
45704
+ const wrapperLeft = wrapperRect.left - surfaceOriginLeft + surface.scrollLeft;
45705
+ const wrapperTop = wrapperRect.top - surfaceOriginTop + surface.scrollTop;
45689
45706
  const wrapperWidth = metricOrFallback(wrapperRect.width, tableWidth);
45690
45707
  const wrapperHeight = metricOrFallback(wrapperRect.height, tableHeight);
45691
45708
  const viewportWidth = metricOrFallback(wrapper?.clientWidth ?? wrapperRect.width, tableWidth);
@@ -45746,8 +45763,7 @@ var ADD_COLUMN_HOVER_WIDTH = 24;
45746
45763
  var ADD_ROW_HOVER_HEIGHT = 24;
45747
45764
  var HANDLE_HOVER_RADIUS = 14;
45748
45765
  function isHTMLElement2(element) {
45749
- const realm = element?.ownerDocument?.defaultView;
45750
- return Boolean(realm && element instanceof realm.HTMLElement);
45766
+ return isCrossRealmHTMLElement(element);
45751
45767
  }
45752
45768
  var DEFAULT_TABLE_HOVER_STATE = {
45753
45769
  menuVisible: false,
@@ -45768,8 +45784,8 @@ function buildTableHoverState({
45768
45784
  return DEFAULT_TABLE_HOVER_STATE;
45769
45785
  }
45770
45786
  const surfaceRect = surface.getBoundingClientRect();
45771
- const relativeX = event.clientX - surfaceRect.left + surface.scrollLeft;
45772
- const relativeY = event.clientY - surfaceRect.top + surface.scrollTop;
45787
+ const relativeX = event.clientX - surfaceRect.left - surface.clientLeft + surface.scrollLeft;
45788
+ const relativeY = event.clientY - surfaceRect.top - surface.clientTop + surface.scrollTop;
45773
45789
  const targetElement = resolveEventElement(event.target);
45774
45790
  const directRowHandle = targetElement?.closest?.("[data-row-handle-index]");
45775
45791
  const directColumnHandle = targetElement?.closest?.("[data-column-handle-index]");
@@ -46476,7 +46492,7 @@ function getSelectedCell(editor) {
46476
46492
  const browserSelection = editorWindow?.getSelection();
46477
46493
  const anchorElement = resolveEventElement(browserSelection?.anchorNode ?? null);
46478
46494
  const anchorCell = anchorElement?.closest?.("th,td");
46479
- if (editorWindow && anchorCell instanceof editorWindow.HTMLTableCellElement) {
46495
+ if (isCrossRealmTableCell(anchorCell)) {
46480
46496
  return anchorCell;
46481
46497
  }
46482
46498
  const domAtPos = editor.view.domAtPos(editor.state.selection.from);
@@ -46677,6 +46693,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
46677
46693
  surface.addEventListener(UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, scheduleCurrentLayoutRefresh);
46678
46694
  if (!editorWindow) return void 0;
46679
46695
  const unsubscribeResize = subscribeSharedGlobalEvent(editorWindow, "resize", scheduleCurrentLayoutRefresh);
46696
+ const unsubscribeWindowScroll = subscribeSharedGlobalEvent(editorWindow, "scroll", scheduleCurrentLayoutRefresh, { passive: true });
46680
46697
  editor.on("selectionUpdate", scheduleSyncFromSelection);
46681
46698
  editor.on("update", scheduleCurrentLayoutRefresh);
46682
46699
  syncFromSelection();
@@ -46692,6 +46709,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
46692
46709
  surface.removeEventListener("scroll", scheduleCurrentLayoutRefresh, scrollListenerOptions);
46693
46710
  surface.removeEventListener(UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, scheduleCurrentLayoutRefresh);
46694
46711
  unsubscribeResize();
46712
+ unsubscribeWindowScroll();
46695
46713
  editor.off("selectionUpdate", scheduleSyncFromSelection);
46696
46714
  editor.off("update", scheduleCurrentLayoutRefresh);
46697
46715
  };
@@ -47545,12 +47563,12 @@ function useUEditorTableInteractions(editor, editable = true) {
47545
47563
  return;
47546
47564
  }
47547
47565
  const target = resolveEventElement(event.target);
47548
- if (!(target instanceof editorWindow.Element)) {
47566
+ if (!isCrossRealmElement(target)) {
47549
47567
  clearAllTableResizeHover();
47550
47568
  return;
47551
47569
  }
47552
47570
  const cell = target.closest("th,td");
47553
- if (!(cell instanceof editorWindow.HTMLElement)) {
47571
+ if (!isCrossRealmHTMLElement(cell)) {
47554
47572
  clearHoveredTableCell();
47555
47573
  clearAllTableResizeHover();
47556
47574
  return;
@@ -47558,7 +47576,7 @@ function useUEditorTableInteractions(editor, editable = true) {
47558
47576
  setHoveredTableCell(cell);
47559
47577
  const row = cell.closest("tr");
47560
47578
  const table = cell.closest("table");
47561
- if (!(row instanceof editorWindow.HTMLTableRowElement) || !(table instanceof editorWindow.HTMLTableElement)) {
47579
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTable(table)) {
47562
47580
  clearHoveredTableCell();
47563
47581
  clearAllTableResizeHover();
47564
47582
  return;
@@ -47614,18 +47632,18 @@ function useUEditorTableInteractions(editor, editable = true) {
47614
47632
  const handleEditorMouseDown = (event) => {
47615
47633
  if (event.button !== 0) return;
47616
47634
  const target = resolveEventElement(event.target);
47617
- if (!(target instanceof editorWindow.Element)) {
47635
+ if (!isCrossRealmElement(target)) {
47618
47636
  clearActiveTableCell();
47619
47637
  return;
47620
47638
  }
47621
47639
  const cell = target.closest("th,td");
47622
- if (!(cell instanceof editorWindow.HTMLTableCellElement)) {
47640
+ if (!isCrossRealmTableCell(cell)) {
47623
47641
  clearActiveTableCell();
47624
47642
  return;
47625
47643
  }
47626
47644
  const row = cell.closest("tr");
47627
47645
  const table = cell.closest("table");
47628
- if (!(row instanceof editorWindow.HTMLTableRowElement) || !(table instanceof editorWindow.HTMLTableElement)) return;
47646
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTable(table)) return;
47629
47647
  const rowTarget = resolveRowResizeTarget(cell, event.clientX, event.clientY);
47630
47648
  if (rowTarget) {
47631
47649
  event.preventDefault();