@underverse-ui/underverse 2.0.42 → 2.0.43

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.cjs CHANGED
@@ -7166,6 +7166,209 @@ var init_table_width_model = __esm({
7166
7166
  }
7167
7167
  });
7168
7168
 
7169
+ // src/components/UEditor/table-dom-utils.ts
7170
+ function isCrossRealmNode(value) {
7171
+ return Boolean(value && typeof value === "object" && value.nodeType != null);
7172
+ }
7173
+ function isCrossRealmElement(value) {
7174
+ return isCrossRealmNode(value) && value.nodeType === 1 && typeof value.closest === "function";
7175
+ }
7176
+ function isCrossRealmHTMLElement(value) {
7177
+ return isCrossRealmElement(value) && typeof value.style === "object";
7178
+ }
7179
+ function isCrossRealmTable(value) {
7180
+ return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TABLE" && "rows" in value;
7181
+ }
7182
+ function isCrossRealmTableRow(value) {
7183
+ return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TR" && "cells" in value;
7184
+ }
7185
+ function isCrossRealmTableCell(value) {
7186
+ return isCrossRealmElement(value) && ["TD", "TH"].includes(String(value.tagName).toUpperCase()) && "cellIndex" in value;
7187
+ }
7188
+ function isValidProseMirrorPosition(doc, pos) {
7189
+ return Number.isInteger(pos) && pos >= 0 && pos <= doc.content.size;
7190
+ }
7191
+ function findTableRowNodeInfo(view, rowElement) {
7192
+ if (!view.dom.contains(rowElement)) return null;
7193
+ const firstCell = rowElement.querySelector("th,td");
7194
+ if (!isCrossRealmTableCell(firstCell) || !view.dom.contains(firstCell)) return null;
7195
+ const cellPos = view.posAtDOM(firstCell, 0);
7196
+ if (!isValidProseMirrorPosition(view.state.doc, cellPos)) return null;
7197
+ const $pos = view.state.doc.resolve(cellPos);
7198
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
7199
+ const node = $pos.node(depth);
7200
+ if (node.type.name === "tableRow") {
7201
+ return {
7202
+ pos: $pos.before(depth),
7203
+ node
7204
+ };
7205
+ }
7206
+ }
7207
+ return null;
7208
+ }
7209
+ function resolveEventElement(target) {
7210
+ if (isCrossRealmElement(target)) return target;
7211
+ if (isCrossRealmNode(target)) return target.parentElement;
7212
+ return null;
7213
+ }
7214
+ function isPointOverRenderedText(root, clientX, clientY) {
7215
+ const view = root.ownerDocument.defaultView;
7216
+ if (!view) return false;
7217
+ const walker = root.ownerDocument.createTreeWalker(root, view.NodeFilter.SHOW_TEXT);
7218
+ let textNode = walker.nextNode();
7219
+ while (textNode) {
7220
+ if (textNode.textContent?.length) {
7221
+ const range = root.ownerDocument.createRange();
7222
+ range.selectNodeContents(textNode);
7223
+ const textRects = Array.from(range.getClientRects());
7224
+ range.detach?.();
7225
+ if (textRects.some((rect) => clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom)) {
7226
+ return true;
7227
+ }
7228
+ }
7229
+ textNode = walker.nextNode();
7230
+ }
7231
+ return false;
7232
+ }
7233
+ function getSelectionTableCell(view) {
7234
+ const realm = view.dom.ownerDocument.defaultView;
7235
+ const browserSelection = realm?.getSelection();
7236
+ const anchorElement = resolveEventElement(browserSelection?.anchorNode ?? null);
7237
+ const anchorCell = anchorElement?.closest?.("th,td");
7238
+ if (isCrossRealmTableCell(anchorCell) && view.dom.contains(anchorCell)) {
7239
+ return anchorCell;
7240
+ }
7241
+ const { from } = view.state.selection;
7242
+ const domAtPos = view.domAtPos(from);
7243
+ const element = resolveEventElement(domAtPos.node);
7244
+ const cell = element?.closest?.("th,td");
7245
+ return isCrossRealmTableCell(cell) && view.dom.contains(cell) ? cell : null;
7246
+ }
7247
+ function resolveRowResizeTarget(cell, clientX, clientY) {
7248
+ const rect = cell.getBoundingClientRect();
7249
+ const row = cell.closest("tr");
7250
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTableCell(cell)) {
7251
+ return null;
7252
+ }
7253
+ const distToBottom = Math.abs(clientY - rect.bottom);
7254
+ const distToTop = Math.abs(clientY - rect.top);
7255
+ const distToRight = Math.abs(clientX - rect.right);
7256
+ const distToLeft = Math.abs(clientX - rect.left);
7257
+ if (distToRight <= 3 || distToLeft <= 3) {
7258
+ return null;
7259
+ }
7260
+ if (distToBottom <= TABLE_RESIZE_HIT_ZONE) {
7261
+ return { row, cell };
7262
+ }
7263
+ if (distToTop <= TABLE_RESIZE_HIT_ZONE) {
7264
+ const prevRow = row.previousElementSibling;
7265
+ if (isCrossRealmTableRow(prevRow)) {
7266
+ const cellIndex = cell.cellIndex;
7267
+ const prevCell = prevRow.children[cellIndex] ?? prevRow.firstElementChild;
7268
+ if (isCrossRealmTableCell(prevCell)) {
7269
+ return { row: prevRow, cell: prevCell };
7270
+ }
7271
+ }
7272
+ }
7273
+ return null;
7274
+ }
7275
+ function resolveColumnResizeTarget(cell, clientX, clientY) {
7276
+ const rect = cell.getBoundingClientRect();
7277
+ const row = cell.closest("tr");
7278
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTableCell(cell)) {
7279
+ return null;
7280
+ }
7281
+ const distToRight = Math.abs(clientX - rect.right);
7282
+ const distToLeft = Math.abs(clientX - rect.left);
7283
+ const distToBottom = Math.abs(clientY - rect.bottom);
7284
+ const distToTop = Math.abs(clientY - rect.top);
7285
+ if (distToBottom <= 3 || distToTop <= 3) {
7286
+ return null;
7287
+ }
7288
+ if (distToRight <= TABLE_RESIZE_HIT_ZONE) {
7289
+ return { row, cell };
7290
+ }
7291
+ if (distToLeft <= TABLE_RESIZE_HIT_ZONE) {
7292
+ const prevCell = cell.previousElementSibling;
7293
+ if (isCrossRealmTableCell(prevCell)) {
7294
+ return { row, cell: prevCell };
7295
+ }
7296
+ }
7297
+ return null;
7298
+ }
7299
+ function isRowResizeHotspot(cell, clientX, clientY) {
7300
+ return resolveRowResizeTarget(cell, clientX, clientY) !== null;
7301
+ }
7302
+ function getRelativeBoundaryMetrics(surface, table, row, cell) {
7303
+ const surfaceRect = surface.getBoundingClientRect();
7304
+ const originLeft = surfaceRect.left + surface.clientLeft;
7305
+ const originTop = surfaceRect.top + surface.clientTop;
7306
+ const tableRect = table.getBoundingClientRect();
7307
+ const rowRect = row.getBoundingClientRect();
7308
+ const cellRect = cell.getBoundingClientRect();
7309
+ return {
7310
+ left: tableRect.left - originLeft + surface.scrollLeft,
7311
+ top: tableRect.top - originTop + surface.scrollTop,
7312
+ width: tableRect.width,
7313
+ height: tableRect.height,
7314
+ rowBottom: rowRect.bottom - originTop + surface.scrollTop,
7315
+ columnRight: cellRect.right - originLeft + surface.scrollLeft
7316
+ };
7317
+ }
7318
+ function getRelativeCellMetrics(surface, cell) {
7319
+ const surfaceRect = surface.getBoundingClientRect();
7320
+ const originLeft = surfaceRect.left + surface.clientLeft;
7321
+ const originTop = surfaceRect.top + surface.clientTop;
7322
+ const cellRect = cell.getBoundingClientRect();
7323
+ return {
7324
+ left: cellRect.left - originLeft + surface.scrollLeft,
7325
+ top: cellRect.top - originTop + surface.scrollTop,
7326
+ width: cellRect.width,
7327
+ height: cellRect.height
7328
+ };
7329
+ }
7330
+ function getRelativeSelectedCellsMetrics(surface) {
7331
+ const selectedCells = Array.from(
7332
+ surface.querySelectorAll("td.selectedCell, th.selectedCell")
7333
+ );
7334
+ if (selectedCells.length === 0) {
7335
+ return null;
7336
+ }
7337
+ const surfaceRect = surface.getBoundingClientRect();
7338
+ const originLeft = surfaceRect.left + surface.clientLeft;
7339
+ const originTop = surfaceRect.top + surface.clientTop;
7340
+ let left = Number.POSITIVE_INFINITY;
7341
+ let top = Number.POSITIVE_INFINITY;
7342
+ let right = Number.NEGATIVE_INFINITY;
7343
+ let bottom = Number.NEGATIVE_INFINITY;
7344
+ selectedCells.forEach((cell) => {
7345
+ const rect = cell.getBoundingClientRect();
7346
+ left = Math.min(left, rect.left);
7347
+ top = Math.min(top, rect.top);
7348
+ right = Math.max(right, rect.right);
7349
+ bottom = Math.max(bottom, rect.bottom);
7350
+ });
7351
+ return {
7352
+ left: left - originLeft + surface.scrollLeft,
7353
+ top: top - originTop + surface.scrollTop,
7354
+ width: right - left,
7355
+ height: bottom - top
7356
+ };
7357
+ }
7358
+ var DEFAULT_TABLE_ROW_HEIGHT, MIN_TABLE_ROW_HEIGHT, COLUMN_RESIZE_LINE_THICKNESS, ROW_RESIZE_LINE_THICKNESS, UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, isRowResizingGlobal, TABLE_RESIZE_HIT_ZONE;
7359
+ var init_table_dom_utils = __esm({
7360
+ "src/components/UEditor/table-dom-utils.ts"() {
7361
+ "use strict";
7362
+ DEFAULT_TABLE_ROW_HEIGHT = 25;
7363
+ MIN_TABLE_ROW_HEIGHT = DEFAULT_TABLE_ROW_HEIGHT;
7364
+ COLUMN_RESIZE_LINE_THICKNESS = 2;
7365
+ ROW_RESIZE_LINE_THICKNESS = 2;
7366
+ UEDITOR_TABLE_LAYOUT_CHANGE_EVENT = "ueditor:table-layout-change";
7367
+ isRowResizingGlobal = { active: false };
7368
+ TABLE_RESIZE_HIT_ZONE = 5;
7369
+ }
7370
+ });
7371
+
7169
7372
  // src/components/UEditor/clipboard-tables.ts
7170
7373
  function getClipboardData(dataTransfer, type) {
7171
7374
  try {
@@ -7597,7 +7800,7 @@ function getClipboardCellText(node) {
7597
7800
  if (node.nodeType === Node.TEXT_NODE) {
7598
7801
  return node.textContent ?? "";
7599
7802
  }
7600
- if (!(node instanceof HTMLElement)) {
7803
+ if (!isCrossRealmHTMLElement(node)) {
7601
7804
  return "";
7602
7805
  }
7603
7806
  if (node.tagName === "BR") {
@@ -7614,7 +7817,7 @@ function getClipboardCellSegments(node, styleMap, inheritedMarks) {
7614
7817
  if (node.nodeType === Node.TEXT_NODE) {
7615
7818
  return [{ text: node.textContent ?? "", marks: inheritedMarks }];
7616
7819
  }
7617
- if (!(node instanceof HTMLElement)) {
7820
+ if (!isCrossRealmHTMLElement(node)) {
7618
7821
  return [];
7619
7822
  }
7620
7823
  if (node.tagName === "BR") {
@@ -7646,7 +7849,7 @@ function getHtmlTableRows(table, styleMap) {
7646
7849
  const rows = Array.from(table.querySelectorAll("tr")).map(
7647
7850
  (row) => ({
7648
7851
  attrs: getTableRowAttrs(row, getElementStyleDeclarations(row, styleMap)),
7649
- cells: Array.from(row.children).filter((cell) => cell instanceof HTMLTableCellElement).map((cell) => {
7852
+ cells: Array.from(row.children).filter((cell) => isCrossRealmTableCell(cell)).map((cell) => {
7650
7853
  const styles = getElementStyleDeclarations(cell, styleMap);
7651
7854
  const textColor = normalizeTextColorValue(styles.get("color")) ?? DEFAULT_HTML_TABLE_TEXT_COLOR;
7652
7855
  const inheritedMarks = [{ type: "textStyle", attrs: { color: textColor } }];
@@ -7829,7 +8032,7 @@ function getClipboardTableContent(dataTransfer) {
7829
8032
  const tables = sourceBody.querySelectorAll("table");
7830
8033
  if (tables.length !== 1 || hasMeaningfulContentOutsideTable(sourceBody)) return null;
7831
8034
  const table = tables[0];
7832
- if (!(table instanceof HTMLTableElement)) return null;
8035
+ if (!isCrossRealmTable(table)) return null;
7833
8036
  const storedWidthValue = table.getAttribute("data-table-width-bp");
7834
8037
  const storedOffsetValue = table.getAttribute("data-table-offset-bp");
7835
8038
  const storedWidthBp = Number(storedWidthValue);
@@ -7913,6 +8116,7 @@ var init_clipboard_tables = __esm({
7913
8116
  "src/components/UEditor/clipboard-tables.ts"() {
7914
8117
  "use strict";
7915
8118
  init_table_width_model();
8119
+ init_table_dom_utils();
7916
8120
  DEFAULT_HTML_TABLE_CELL_BACKGROUND_COLOR = "#ffffff";
7917
8121
  DEFAULT_HTML_TABLE_TEXT_COLOR = "#000000";
7918
8122
  BORDER_STYLES = /* @__PURE__ */ new Set([
@@ -8133,209 +8337,6 @@ var init_clipboard_images = __esm({
8133
8337
  }
8134
8338
  });
8135
8339
 
8136
- // src/components/UEditor/table-dom-utils.ts
8137
- function isCrossRealmNode(value) {
8138
- return Boolean(value && typeof value === "object" && value.nodeType != null);
8139
- }
8140
- function isCrossRealmElement(value) {
8141
- return isCrossRealmNode(value) && value.nodeType === 1 && typeof value.closest === "function";
8142
- }
8143
- function isCrossRealmHTMLElement(value) {
8144
- return isCrossRealmElement(value) && typeof value.style === "object";
8145
- }
8146
- function isCrossRealmTable(value) {
8147
- return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TABLE" && "rows" in value;
8148
- }
8149
- function isCrossRealmTableRow(value) {
8150
- return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TR" && "cells" in value;
8151
- }
8152
- function isCrossRealmTableCell(value) {
8153
- return isCrossRealmElement(value) && ["TD", "TH"].includes(String(value.tagName).toUpperCase()) && "cellIndex" in value;
8154
- }
8155
- function isValidProseMirrorPosition(doc, pos) {
8156
- return Number.isInteger(pos) && pos >= 0 && pos <= doc.content.size;
8157
- }
8158
- function findTableRowNodeInfo(view, rowElement) {
8159
- if (!view.dom.contains(rowElement)) return null;
8160
- const firstCell = rowElement.querySelector("th,td");
8161
- if (!isCrossRealmTableCell(firstCell) || !view.dom.contains(firstCell)) return null;
8162
- const cellPos = view.posAtDOM(firstCell, 0);
8163
- if (!isValidProseMirrorPosition(view.state.doc, cellPos)) return null;
8164
- const $pos = view.state.doc.resolve(cellPos);
8165
- for (let depth = $pos.depth; depth > 0; depth -= 1) {
8166
- const node = $pos.node(depth);
8167
- if (node.type.name === "tableRow") {
8168
- return {
8169
- pos: $pos.before(depth),
8170
- node
8171
- };
8172
- }
8173
- }
8174
- return null;
8175
- }
8176
- function resolveEventElement(target) {
8177
- if (isCrossRealmElement(target)) return target;
8178
- if (isCrossRealmNode(target)) return target.parentElement;
8179
- return null;
8180
- }
8181
- function isPointOverRenderedText(root, clientX, clientY) {
8182
- const view = root.ownerDocument.defaultView;
8183
- if (!view) return false;
8184
- const walker = root.ownerDocument.createTreeWalker(root, view.NodeFilter.SHOW_TEXT);
8185
- let textNode = walker.nextNode();
8186
- while (textNode) {
8187
- if (textNode.textContent?.length) {
8188
- const range = root.ownerDocument.createRange();
8189
- range.selectNodeContents(textNode);
8190
- const textRects = Array.from(range.getClientRects());
8191
- range.detach?.();
8192
- if (textRects.some((rect) => clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom)) {
8193
- return true;
8194
- }
8195
- }
8196
- textNode = walker.nextNode();
8197
- }
8198
- return false;
8199
- }
8200
- function getSelectionTableCell(view) {
8201
- const realm = view.dom.ownerDocument.defaultView;
8202
- const browserSelection = realm?.getSelection();
8203
- const anchorElement = resolveEventElement(browserSelection?.anchorNode ?? null);
8204
- const anchorCell = anchorElement?.closest?.("th,td");
8205
- if (isCrossRealmTableCell(anchorCell) && view.dom.contains(anchorCell)) {
8206
- return anchorCell;
8207
- }
8208
- const { from } = view.state.selection;
8209
- const domAtPos = view.domAtPos(from);
8210
- const element = resolveEventElement(domAtPos.node);
8211
- const cell = element?.closest?.("th,td");
8212
- return isCrossRealmTableCell(cell) && view.dom.contains(cell) ? cell : null;
8213
- }
8214
- function resolveRowResizeTarget(cell, clientX, clientY) {
8215
- const rect = cell.getBoundingClientRect();
8216
- const row = cell.closest("tr");
8217
- if (!isCrossRealmTableRow(row) || !isCrossRealmTableCell(cell)) {
8218
- return null;
8219
- }
8220
- const distToBottom = Math.abs(clientY - rect.bottom);
8221
- const distToTop = Math.abs(clientY - rect.top);
8222
- const distToRight = Math.abs(clientX - rect.right);
8223
- const distToLeft = Math.abs(clientX - rect.left);
8224
- if (distToRight <= 3 || distToLeft <= 3) {
8225
- return null;
8226
- }
8227
- if (distToBottom <= TABLE_RESIZE_HIT_ZONE) {
8228
- return { row, cell };
8229
- }
8230
- if (distToTop <= TABLE_RESIZE_HIT_ZONE) {
8231
- const prevRow = row.previousElementSibling;
8232
- if (isCrossRealmTableRow(prevRow)) {
8233
- const cellIndex = cell.cellIndex;
8234
- const prevCell = prevRow.children[cellIndex] ?? prevRow.firstElementChild;
8235
- if (isCrossRealmTableCell(prevCell)) {
8236
- return { row: prevRow, cell: prevCell };
8237
- }
8238
- }
8239
- }
8240
- return null;
8241
- }
8242
- function resolveColumnResizeTarget(cell, clientX, clientY) {
8243
- const rect = cell.getBoundingClientRect();
8244
- const row = cell.closest("tr");
8245
- if (!isCrossRealmTableRow(row) || !isCrossRealmTableCell(cell)) {
8246
- return null;
8247
- }
8248
- const distToRight = Math.abs(clientX - rect.right);
8249
- const distToLeft = Math.abs(clientX - rect.left);
8250
- const distToBottom = Math.abs(clientY - rect.bottom);
8251
- const distToTop = Math.abs(clientY - rect.top);
8252
- if (distToBottom <= 3 || distToTop <= 3) {
8253
- return null;
8254
- }
8255
- if (distToRight <= TABLE_RESIZE_HIT_ZONE) {
8256
- return { row, cell };
8257
- }
8258
- if (distToLeft <= TABLE_RESIZE_HIT_ZONE) {
8259
- const prevCell = cell.previousElementSibling;
8260
- if (isCrossRealmTableCell(prevCell)) {
8261
- return { row, cell: prevCell };
8262
- }
8263
- }
8264
- return null;
8265
- }
8266
- function isRowResizeHotspot(cell, clientX, clientY) {
8267
- return resolveRowResizeTarget(cell, clientX, clientY) !== null;
8268
- }
8269
- function getRelativeBoundaryMetrics(surface, table, row, cell) {
8270
- const surfaceRect = surface.getBoundingClientRect();
8271
- const originLeft = surfaceRect.left + surface.clientLeft;
8272
- const originTop = surfaceRect.top + surface.clientTop;
8273
- const tableRect = table.getBoundingClientRect();
8274
- const rowRect = row.getBoundingClientRect();
8275
- const cellRect = cell.getBoundingClientRect();
8276
- return {
8277
- left: tableRect.left - originLeft + surface.scrollLeft,
8278
- top: tableRect.top - originTop + surface.scrollTop,
8279
- width: tableRect.width,
8280
- height: tableRect.height,
8281
- rowBottom: rowRect.bottom - originTop + surface.scrollTop,
8282
- columnRight: cellRect.right - originLeft + surface.scrollLeft
8283
- };
8284
- }
8285
- function getRelativeCellMetrics(surface, cell) {
8286
- const surfaceRect = surface.getBoundingClientRect();
8287
- const originLeft = surfaceRect.left + surface.clientLeft;
8288
- const originTop = surfaceRect.top + surface.clientTop;
8289
- const cellRect = cell.getBoundingClientRect();
8290
- return {
8291
- left: cellRect.left - originLeft + surface.scrollLeft,
8292
- top: cellRect.top - originTop + surface.scrollTop,
8293
- width: cellRect.width,
8294
- height: cellRect.height
8295
- };
8296
- }
8297
- function getRelativeSelectedCellsMetrics(surface) {
8298
- const selectedCells = Array.from(
8299
- surface.querySelectorAll("td.selectedCell, th.selectedCell")
8300
- );
8301
- if (selectedCells.length === 0) {
8302
- return null;
8303
- }
8304
- const surfaceRect = surface.getBoundingClientRect();
8305
- const originLeft = surfaceRect.left + surface.clientLeft;
8306
- const originTop = surfaceRect.top + surface.clientTop;
8307
- let left = Number.POSITIVE_INFINITY;
8308
- let top = Number.POSITIVE_INFINITY;
8309
- let right = Number.NEGATIVE_INFINITY;
8310
- let bottom = Number.NEGATIVE_INFINITY;
8311
- selectedCells.forEach((cell) => {
8312
- const rect = cell.getBoundingClientRect();
8313
- left = Math.min(left, rect.left);
8314
- top = Math.min(top, rect.top);
8315
- right = Math.max(right, rect.right);
8316
- bottom = Math.max(bottom, rect.bottom);
8317
- });
8318
- return {
8319
- left: left - originLeft + surface.scrollLeft,
8320
- top: top - originTop + surface.scrollTop,
8321
- width: right - left,
8322
- height: bottom - top
8323
- };
8324
- }
8325
- var DEFAULT_TABLE_ROW_HEIGHT, MIN_TABLE_ROW_HEIGHT, COLUMN_RESIZE_LINE_THICKNESS, ROW_RESIZE_LINE_THICKNESS, UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, isRowResizingGlobal, TABLE_RESIZE_HIT_ZONE;
8326
- var init_table_dom_utils = __esm({
8327
- "src/components/UEditor/table-dom-utils.ts"() {
8328
- "use strict";
8329
- DEFAULT_TABLE_ROW_HEIGHT = 25;
8330
- MIN_TABLE_ROW_HEIGHT = DEFAULT_TABLE_ROW_HEIGHT;
8331
- COLUMN_RESIZE_LINE_THICKNESS = 2;
8332
- ROW_RESIZE_LINE_THICKNESS = 2;
8333
- UEDITOR_TABLE_LAYOUT_CHANGE_EVENT = "ueditor:table-layout-change";
8334
- isRowResizingGlobal = { active: false };
8335
- TABLE_RESIZE_HIT_ZONE = 5;
8336
- }
8337
- });
8338
-
8339
8340
  // src/components/UEditor/table-column-resize.ts
8340
8341
  function getColumnResizeMinWidth(configuredMinWidth) {
8341
8342
  const normalizedMinWidth = Number.isFinite(configuredMinWidth) && configuredMinWidth > 0 ? Math.round(configuredMinWidth) : MIN_RESIZED_TABLE_COLUMN_WIDTH;
@@ -14431,7 +14432,7 @@ function parsePixelWidth(value) {
14431
14432
  }
14432
14433
  function getDomColumnWidths(editor, rect) {
14433
14434
  const tableDom = editor.view.nodeDOM(rect.tableStart - 1);
14434
- if (!(tableDom instanceof HTMLTableElement)) return null;
14435
+ if (!isCrossRealmTable(tableDom)) return null;
14435
14436
  const cols = Array.from(tableDom.querySelectorAll("colgroup > col"));
14436
14437
  if (cols.length === 0) return null;
14437
14438
  const widths = [];
@@ -43685,7 +43686,7 @@ var UEditorTableRow = import_extension_table_row.TableRow.extend({
43685
43686
  rowHeight: {
43686
43687
  default: DEFAULT_TABLE_ROW_HEIGHT,
43687
43688
  parseHTML: (element) => {
43688
- if (!(element instanceof HTMLElement)) return null;
43689
+ if (!isCrossRealmHTMLElement(element)) return null;
43689
43690
  return parseRowHeight(element.getAttribute("data-row-height")) ?? parseRowHeight(element.style.height);
43690
43691
  },
43691
43692
  renderHTML: (attributes) => {
@@ -44218,7 +44219,7 @@ var UEditorTable = import_extension_table.Table.extend({
44218
44219
  textAlign: {
44219
44220
  default: null,
44220
44221
  parseHTML: (element) => {
44221
- if (!(element instanceof HTMLElement)) return null;
44222
+ if (!isCrossRealmHTMLElement(element)) return null;
44222
44223
  return parseTableAlign(element);
44223
44224
  },
44224
44225
  renderHTML: (attributes) => {
@@ -44232,7 +44233,7 @@ var UEditorTable = import_extension_table.Table.extend({
44232
44233
  widthMode: {
44233
44234
  default: "fixed",
44234
44235
  parseHTML: (element) => {
44235
- if (!(element instanceof HTMLElement)) return "fixed";
44236
+ if (!isCrossRealmHTMLElement(element)) return "fixed";
44236
44237
  return parseTableWidthMode(element);
44237
44238
  },
44238
44239
  renderHTML: (attributes) => {
@@ -44245,7 +44246,7 @@ var UEditorTable = import_extension_table.Table.extend({
44245
44246
  widthBp: {
44246
44247
  default: null,
44247
44248
  parseHTML: (element) => {
44248
- if (!(element instanceof HTMLElement) || parseTableWidthMode(element) !== "responsive") return null;
44249
+ if (!isCrossRealmHTMLElement(element) || parseTableWidthMode(element) !== "responsive") return null;
44249
44250
  const stored = Number(element.getAttribute("data-table-width-bp"));
44250
44251
  if (Number.isFinite(stored) && stored > 0) return clampResponsiveTableWidthBp(stored);
44251
44252
  return parsePercentageToBasisPoints(element.getAttribute("data-table-width") ?? element.style.width) ?? DEFAULT_RESPONSIVE_TABLE_WIDTH_BP;
@@ -44255,7 +44256,7 @@ var UEditorTable = import_extension_table.Table.extend({
44255
44256
  offsetBp: {
44256
44257
  default: null,
44257
44258
  parseHTML: (element) => {
44258
- if (!(element instanceof HTMLElement) || parseTableWidthMode(element) !== "responsive") return null;
44259
+ if (!isCrossRealmHTMLElement(element) || parseTableWidthMode(element) !== "responsive") return null;
44259
44260
  const storedValue = element.getAttribute("data-table-offset-bp");
44260
44261
  const stored = Number(storedValue);
44261
44262
  if (storedValue !== null && Number.isFinite(stored) && stored >= 0) return Math.round(stored);
@@ -44274,7 +44275,7 @@ var UEditorTable = import_extension_table.Table.extend({
44274
44275
  columnRatios: {
44275
44276
  default: null,
44276
44277
  parseHTML: (element) => {
44277
- if (!(element instanceof HTMLElement)) return null;
44278
+ if (!isCrossRealmHTMLElement(element)) return null;
44278
44279
  const storedRatios = parseColumnRatios(
44279
44280
  element.getAttribute("data-table-column-ratios") ?? element.getAttribute("data-column-ratios")
44280
44281
  );
@@ -44470,7 +44471,7 @@ var UEditorTable = import_extension_table.Table.extend({
44470
44471
  if (event.button !== 0) return false;
44471
44472
  const target = resolveEventElement(event.target);
44472
44473
  const cell = target?.closest("th,td");
44473
- if (cell instanceof HTMLElement && isRowResizeHotspot(cell, event.clientX, event.clientY)) {
44474
+ if (isCrossRealmHTMLElement(cell) && isRowResizeHotspot(cell, event.clientX, event.clientY)) {
44474
44475
  isRowResizingGlobal.active = true;
44475
44476
  return true;
44476
44477
  }
@@ -45381,6 +45382,7 @@ var TableFormulaRecalculation = import_core20.Extension.create({
45381
45382
  });
45382
45383
 
45383
45384
  // src/components/UEditor/extensions.ts
45385
+ init_table_dom_utils();
45384
45386
  function getFormulaStateAttributes(attributes) {
45385
45387
  const formula = attributes["data-formula"];
45386
45388
  if (!formula) {
@@ -45700,7 +45702,7 @@ var CustomBulletList = import_extension_bullet_list.BulletList.extend({
45700
45702
  bulletStyle: {
45701
45703
  default: "disc",
45702
45704
  parseHTML: (element) => {
45703
- if (!(element instanceof HTMLElement)) return "disc";
45705
+ if (!isCrossRealmHTMLElement(element)) return "disc";
45704
45706
  const dataStyle = element.getAttribute("data-bullet-style");
45705
45707
  if (dataStyle) return parseBulletStyle(dataStyle);
45706
45708
  const style = element.style.listStyleType;
@@ -49871,8 +49873,11 @@ function useUEditorTableInteractions(editor, editable = true) {
49871
49873
  (0, import_react83.useEffect)(() => {
49872
49874
  if (!editor || !editable) return void 0;
49873
49875
  const proseMirror = editor.view.dom;
49874
- const editorDocument = proseMirror.ownerDocument;
49875
- const editorWindow = editorDocument.defaultView;
49876
+ const editorDocument = editorContentRef.current?.ownerDocument ?? editor?.view.dom.ownerDocument ?? document;
49877
+ const editorWindow = editorDocument.defaultView ?? window;
49878
+ if (editor?.view && editor.view.root !== editorDocument) {
49879
+ editor.view.updateRoot();
49880
+ }
49876
49881
  if (!editorWindow) return void 0;
49877
49882
  const surface = editorContentRef.current;
49878
49883
  let selectionSyncFrameId = 0;