@underverse-ui/underverse 2.0.25 → 2.0.27

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.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  extractImageSrcsFromHtml,
5
5
  normalizeImageUrl,
6
6
  prepareUEditorContentForSave
7
- } from "./chunk-XMAOZQJO.js";
7
+ } from "./chunk-5ODK33CL.js";
8
8
  import {
9
9
  EmojiPicker_default
10
10
  } from "./chunk-F7MX3XXK.js";
@@ -16,7 +16,7 @@ import {
16
16
  import "./chunk-4TYW5K4J.js";
17
17
  import {
18
18
  Modal_default
19
- } from "./chunk-FFVBGTHU.js";
19
+ } from "./chunk-HVJ3R6LP.js";
20
20
  import {
21
21
  DropdownMenuItem,
22
22
  DropdownMenuSeparator,
@@ -31,7 +31,7 @@ import {
31
31
  shadcnAnimationStyles,
32
32
  useShadCNAnimations,
33
33
  useUnderverseUIConfig
34
- } from "./chunk-OJF3XRN7.js";
34
+ } from "./chunk-BDRCOIYR.js";
35
35
  import {
36
36
  ForceInternalTranslationsProvider,
37
37
  NextIntlAdapter,
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  Modal_default
4
- } from "./chunk-FFVBGTHU.js";
4
+ } from "./chunk-HVJ3R6LP.js";
5
5
  import {
6
6
  DEFAULT_TABLE_ROW_HEIGHT,
7
7
  DEFAULT_UEDITOR_IMAGE_MAX_FILE_SIZE,
@@ -21,7 +21,7 @@ import {
21
21
  sanitizeUEditorUrl,
22
22
  useDropdownMenuClose,
23
23
  useSharedEditorUiRenderState
24
- } from "./chunk-OJF3XRN7.js";
24
+ } from "./chunk-BDRCOIYR.js";
25
25
  import {
26
26
  cn,
27
27
  useSmartTranslations
@@ -945,4 +945,4 @@ var MenuBar = ({
945
945
  export {
946
946
  MenuBar
947
947
  };
948
- //# sourceMappingURL=menu-bar-4FM4Y273.js.map
948
+ //# sourceMappingURL=menu-bar-GKJEVLQU.js.map
package/dist/ueditor.cjs CHANGED
@@ -5195,6 +5195,24 @@ var init_clipboard_images = __esm({
5195
5195
  });
5196
5196
 
5197
5197
  // src/components/UEditor/table-dom-utils.ts
5198
+ function isCrossRealmNode(value) {
5199
+ return Boolean(value && typeof value === "object" && value.nodeType != null);
5200
+ }
5201
+ function isCrossRealmElement(value) {
5202
+ return isCrossRealmNode(value) && value.nodeType === 1 && typeof value.closest === "function";
5203
+ }
5204
+ function isCrossRealmHTMLElement(value) {
5205
+ return isCrossRealmElement(value) && typeof value.style === "object";
5206
+ }
5207
+ function isCrossRealmTable(value) {
5208
+ return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TABLE" && "rows" in value;
5209
+ }
5210
+ function isCrossRealmTableRow(value) {
5211
+ return isCrossRealmElement(value) && String(value.tagName).toUpperCase() === "TR" && "cells" in value;
5212
+ }
5213
+ function isCrossRealmTableCell(value) {
5214
+ return isCrossRealmElement(value) && ["TD", "TH"].includes(String(value.tagName).toUpperCase()) && "cellIndex" in value;
5215
+ }
5198
5216
  function findTableRowNodeInfo(view, rowElement) {
5199
5217
  const firstCell = rowElement.querySelector("th,td");
5200
5218
  if (!firstCell) return null;
@@ -5212,10 +5230,8 @@ function findTableRowNodeInfo(view, rowElement) {
5212
5230
  return null;
5213
5231
  }
5214
5232
  function resolveEventElement(target) {
5215
- const ownerDocument = target?.ownerDocument;
5216
- const realm = ownerDocument?.defaultView;
5217
- if (realm && target instanceof realm.Element) return target;
5218
- if (realm && target instanceof realm.Node) return target.parentElement;
5233
+ if (isCrossRealmElement(target)) return target;
5234
+ if (isCrossRealmNode(target)) return target.parentElement;
5219
5235
  return null;
5220
5236
  }
5221
5237
  function isPointOverRenderedText(root, clientX, clientY) {
@@ -5405,8 +5421,8 @@ function applyTableAlignment(editor, tableAlign, anchorPos) {
5405
5421
  const domAtTable = editor.view.domAtPos(Math.min(tableInfo.pos + 1, editor.state.doc.content.size)).node;
5406
5422
  const domAtTableElement = resolveEventElement(domAtTable);
5407
5423
  const tableDom = editor.view.nodeDOM(tableInfo.pos);
5408
- 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);
5409
- if (tableElement instanceof HTMLTableElement) {
5424
+ 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);
5425
+ if (isCrossRealmTable(tableElement)) {
5410
5426
  tableElement.style.tableLayout = "fixed";
5411
5427
  if (tableElement.style.width === "max-content") {
5412
5428
  tableElement.style.removeProperty("width");
@@ -12329,6 +12345,7 @@ var import_tables3 = require("@tiptap/pm/tables");
12329
12345
  var import_state6 = require("@tiptap/pm/state");
12330
12346
  var import_view2 = require("@tiptap/pm/view");
12331
12347
  var import_tables2 = require("@tiptap/pm/tables");
12348
+ init_table_dom_utils();
12332
12349
  var DEFAULT_TABLE_COLUMN_WIDTH = 100;
12333
12350
  var MIN_RESIZED_TABLE_COLUMN_WIDTH = 25;
12334
12351
  function getColumnResizeMinWidth(configuredMinWidth) {
@@ -12345,9 +12362,9 @@ function setColumnStyle(column, width) {
12345
12362
  column.style.minWidth = "";
12346
12363
  }
12347
12364
  function isTableColumnElement(node) {
12348
- return node instanceof HTMLElement && node.tagName.toLowerCase() === "col";
12365
+ return isCrossRealmElement(node) && String(node.tagName).toUpperCase() === "COL";
12349
12366
  }
12350
- function updateDynamicColumns(node, colgroup, table, overrideCol, overrideValue) {
12367
+ function updateDynamicColumns(node, colgroup, table, ownerDocument, overrideCol, overrideValue) {
12351
12368
  let totalWidth = 0;
12352
12369
  let nextDOM = colgroup.firstChild;
12353
12370
  const row = node.firstChild;
@@ -12358,7 +12375,7 @@ function updateDynamicColumns(node, colgroup, table, overrideCol, overrideValue)
12358
12375
  const rawWidth = overrideCol === col ? overrideValue : colwidth?.[spanIndex];
12359
12376
  const width = rawWidth ? Math.max(rawWidth, MIN_RESIZED_TABLE_COLUMN_WIDTH) : null;
12360
12377
  totalWidth += width ?? DEFAULT_TABLE_COLUMN_WIDTH;
12361
- const colElement = isTableColumnElement(nextDOM) ? nextDOM : colgroup.appendChild(document.createElement("col"));
12378
+ const colElement = isTableColumnElement(nextDOM) ? nextDOM : colgroup.appendChild(ownerDocument.createElement("col"));
12362
12379
  setColumnStyle(colElement, width);
12363
12380
  nextDOM = colElement.nextSibling;
12364
12381
  }
@@ -12378,23 +12395,25 @@ function updateDynamicColumns(node, colgroup, table, overrideCol, overrideValue)
12378
12395
  }
12379
12396
  }
12380
12397
  var UEditorTableView = class {
12381
- constructor(node) {
12398
+ constructor(node, _defaultColumnWidth, maybeView) {
12382
12399
  this.node = node;
12383
- this.dom = document.createElement("div");
12400
+ const view = maybeView ?? _defaultColumnWidth;
12401
+ const ownerDocument = view.dom.ownerDocument;
12402
+ this.dom = ownerDocument.createElement("div");
12384
12403
  this.dom.className = "tableWrapper";
12385
- this.table = this.dom.appendChild(document.createElement("table"));
12404
+ this.table = this.dom.appendChild(ownerDocument.createElement("table"));
12386
12405
  if (node.attrs.style) {
12387
12406
  this.table.style.cssText = node.attrs.style;
12388
12407
  }
12389
12408
  this.table.style.tableLayout = "fixed";
12390
- this.colgroup = this.table.appendChild(document.createElement("colgroup"));
12391
- updateDynamicColumns(node, this.colgroup, this.table);
12392
- this.contentDOM = this.table.appendChild(document.createElement("tbody"));
12409
+ this.colgroup = this.table.appendChild(ownerDocument.createElement("colgroup"));
12410
+ updateDynamicColumns(node, this.colgroup, this.table, ownerDocument);
12411
+ this.contentDOM = this.table.appendChild(ownerDocument.createElement("tbody"));
12393
12412
  }
12394
12413
  update(node) {
12395
12414
  if (node.type !== this.node.type) return false;
12396
12415
  this.node = node;
12397
- updateDynamicColumns(node, this.colgroup, this.table);
12416
+ updateDynamicColumns(node, this.colgroup, this.table, this.dom.ownerDocument);
12398
12417
  return true;
12399
12418
  }
12400
12419
  ignoreMutation(mutation) {
@@ -12416,7 +12435,7 @@ function getCurrentColWidth(view, cellPos, { colspan, colwidth }) {
12416
12435
  if (width) return width;
12417
12436
  const dom = view.domAtPos(cellPos);
12418
12437
  const cellElement = dom.node.childNodes[dom.offset];
12419
- let domWidth = cellElement instanceof HTMLElement ? cellElement.offsetWidth : 0;
12438
+ let domWidth = isCrossRealmHTMLElement(cellElement) ? cellElement.offsetWidth : 0;
12420
12439
  let parts = Math.max(1, colspan);
12421
12440
  if (colwidth) {
12422
12441
  for (let index = 0; index < colspan; index += 1) {
@@ -12429,14 +12448,14 @@ function getCurrentColWidth(view, cellPos, { colspan, colwidth }) {
12429
12448
  }
12430
12449
  return domWidth / Math.max(1, parts);
12431
12450
  }
12432
- function domCellAround(target) {
12433
- let node = target instanceof Node ? target : null;
12451
+ function domCellAround(view, target) {
12452
+ let node = isCrossRealmNode(target) ? target : null;
12434
12453
  while (node && node.nodeName !== "TD" && node.nodeName !== "TH") {
12435
- const element = node instanceof Element ? node : null;
12454
+ const element = isCrossRealmElement(node) ? node : null;
12436
12455
  if (element?.classList.contains("ProseMirror")) return null;
12437
12456
  node = node.parentNode;
12438
12457
  }
12439
- return node instanceof HTMLElement ? node : null;
12458
+ return isCrossRealmHTMLElement(node) ? node : null;
12440
12459
  }
12441
12460
  function edgeCell(view, event, side, handleWidth) {
12442
12461
  const offset = side === "right" ? -handleWidth : handleWidth;
@@ -12454,12 +12473,14 @@ function edgeCell(view, event, side, handleWidth) {
12454
12473
  return index % map.width === 0 ? -1 : start + map.map[index - 1];
12455
12474
  }
12456
12475
  var handleHoverTimer = null;
12476
+ var handleHoverWindow = null;
12457
12477
  var pendingHandleCell = -1;
12458
12478
  function clearHandleHoverTimer() {
12459
12479
  if (handleHoverTimer !== null) {
12460
- window.clearTimeout(handleHoverTimer);
12480
+ handleHoverWindow?.clearTimeout(handleHoverTimer);
12461
12481
  handleHoverTimer = null;
12462
12482
  }
12483
+ handleHoverWindow = null;
12463
12484
  pendingHandleCell = -1;
12464
12485
  }
12465
12486
  function updateHandle(view, value) {
@@ -12469,7 +12490,7 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
12469
12490
  if (!view.editable) return;
12470
12491
  const pluginState = import_tables2.columnResizingPluginKey.getState(view.state);
12471
12492
  if (!pluginState || pluginState.dragging) return;
12472
- const target = domCellAround(event.target);
12493
+ const target = domCellAround(view, event.target);
12473
12494
  let cell = -1;
12474
12495
  if (target) {
12475
12496
  const { left, right } = target.getBoundingClientRect();
@@ -12505,7 +12526,10 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
12505
12526
  if (pendingHandleCell === cell) return;
12506
12527
  clearHandleHoverTimer();
12507
12528
  pendingHandleCell = cell;
12508
- handleHoverTimer = window.setTimeout(() => {
12529
+ const ownerWindow = view.dom.ownerDocument.defaultView;
12530
+ if (!ownerWindow) return;
12531
+ handleHoverWindow = ownerWindow;
12532
+ handleHoverTimer = ownerWindow.setTimeout(() => {
12509
12533
  handleHoverTimer = null;
12510
12534
  pendingHandleCell = -1;
12511
12535
  updateHandle(view, cell);
@@ -12577,7 +12601,7 @@ function getTableElementAtCell(view, cell) {
12577
12601
  const $cell = view.state.doc.resolve(cell);
12578
12602
  let dom = view.domAtPos($cell.start(-1)).node;
12579
12603
  while (dom && dom.nodeName !== "TABLE") dom = dom.parentNode;
12580
- return dom instanceof HTMLTableElement ? dom : null;
12604
+ return isCrossRealmTable(dom) ? dom : null;
12581
12605
  }
12582
12606
  function showColumnResizeGhost(view, cell, dragging, width) {
12583
12607
  const table = getTableElementAtCell(view, cell);
@@ -12634,7 +12658,8 @@ function handleMouseDown(view, event, cellMinWidth) {
12634
12658
  event.preventDefault();
12635
12659
  return true;
12636
12660
  }
12637
- function handleDecorations(state, cell) {
12661
+ function handleDecorations(state, cell, ownerDocument) {
12662
+ if (!ownerDocument) return import_view2.DecorationSet.empty;
12638
12663
  const decorations = [];
12639
12664
  const $cell = state.doc.resolve(cell);
12640
12665
  const table = $cell.node(-1);
@@ -12651,7 +12676,7 @@ function handleDecorations(state, cell) {
12651
12676
  const cellNode = table.nodeAt(cellPos);
12652
12677
  if (!cellNode) continue;
12653
12678
  const pos = start + cellPos + cellNode.nodeSize - 1;
12654
- const dom = document.createElement("div");
12679
+ const dom = ownerDocument.createElement("div");
12655
12680
  dom.className = "column-resize-handle";
12656
12681
  if (import_tables2.columnResizingPluginKey.getState(state)?.dragging) {
12657
12682
  decorations.push(import_view2.Decoration.node(start + cellPos, start + cellPos + cellNode.nodeSize, { class: "column-resize-dragging" }));
@@ -12668,6 +12693,7 @@ function dynamicColumnResizing({
12668
12693
  View = UEditorTableView,
12669
12694
  lastColumnResizable = true
12670
12695
  } = {}) {
12696
+ let ownerDocument = null;
12671
12697
  const plugin = new import_state6.Plugin({
12672
12698
  key: import_tables2.columnResizingPluginKey,
12673
12699
  state: {
@@ -12675,7 +12701,10 @@ function dynamicColumnResizing({
12675
12701
  const nodeViews = plugin.spec.props?.nodeViews;
12676
12702
  const tableName = (0, import_tables2.tableNodeTypes)(state.schema).table.name;
12677
12703
  if (View && nodeViews) {
12678
- nodeViews[tableName] = (node, view) => new View(node, defaultCellMinWidth, view);
12704
+ nodeViews[tableName] = (node, view) => {
12705
+ ownerDocument = view.dom.ownerDocument;
12706
+ return new View(node, defaultCellMinWidth, view);
12707
+ };
12679
12708
  }
12680
12709
  return new import_tables2.ResizeState(-1, false);
12681
12710
  },
@@ -12700,7 +12729,7 @@ function dynamicColumnResizing({
12700
12729
  decorations: (state) => {
12701
12730
  const pluginState = import_tables2.columnResizingPluginKey.getState(state);
12702
12731
  if (pluginState && pluginState.activeHandle > -1) {
12703
- return handleDecorations(state, pluginState.activeHandle);
12732
+ return handleDecorations(state, pluginState.activeHandle, ownerDocument);
12704
12733
  }
12705
12734
  return void 0;
12706
12735
  },
@@ -20922,20 +20951,16 @@ init_table_dom_utils();
20922
20951
  var FALLBACK_TABLE_ROW_HEIGHT = DEFAULT_TABLE_ROW_HEIGHT;
20923
20952
  var FALLBACK_TABLE_COLUMN_WIDTH = 160;
20924
20953
  function isTableCellElement(element) {
20925
- const realm = element?.ownerDocument?.defaultView;
20926
- return Boolean(realm && element instanceof realm.HTMLTableCellElement);
20954
+ return isCrossRealmTableCell(element);
20927
20955
  }
20928
20956
  function isTableRowElement(element) {
20929
- const realm = element?.ownerDocument?.defaultView;
20930
- return Boolean(realm && element instanceof realm.HTMLTableRowElement);
20957
+ return isCrossRealmTableRow(element);
20931
20958
  }
20932
20959
  function isTableElement(element) {
20933
- const realm = element?.ownerDocument?.defaultView;
20934
- return Boolean(realm && element instanceof realm.HTMLTableElement);
20960
+ return isCrossRealmTable(element);
20935
20961
  }
20936
20962
  function isHTMLElement(element) {
20937
- const realm = element?.ownerDocument?.defaultView;
20938
- return Boolean(realm && element instanceof realm.HTMLElement);
20963
+ return isCrossRealmHTMLElement(element);
20939
20964
  }
20940
20965
  function getVisibleTableBounds(layout) {
20941
20966
  const left = Math.max(layout.tableLeft, layout.wrapperLeft);
@@ -21219,8 +21244,7 @@ var ADD_COLUMN_HOVER_WIDTH = 24;
21219
21244
  var ADD_ROW_HOVER_HEIGHT = 24;
21220
21245
  var HANDLE_HOVER_RADIUS = 14;
21221
21246
  function isHTMLElement2(element) {
21222
- const realm = element?.ownerDocument?.defaultView;
21223
- return Boolean(realm && element instanceof realm.HTMLElement);
21247
+ return isCrossRealmHTMLElement(element);
21224
21248
  }
21225
21249
  var DEFAULT_TABLE_HOVER_STATE = {
21226
21250
  menuVisible: false,
@@ -21721,7 +21745,7 @@ function TableResizeHandles({
21721
21745
  "data-table-resize-frame": "",
21722
21746
  "data-resizing": active ? "true" : "false",
21723
21747
  className: cn(
21724
- "pointer-events-none absolute z-[38] box-border border border-primary/55",
21748
+ "pointer-events-none absolute z-[38] box-border border border-transparent",
21725
21749
  active && "border-primary bg-primary/3"
21726
21750
  ),
21727
21751
  style: {
@@ -21949,7 +21973,7 @@ function getSelectedCell(editor) {
21949
21973
  const browserSelection = editorWindow?.getSelection();
21950
21974
  const anchorElement = resolveEventElement(browserSelection?.anchorNode ?? null);
21951
21975
  const anchorCell = anchorElement?.closest?.("th,td");
21952
- if (editorWindow && anchorCell instanceof editorWindow.HTMLTableCellElement) {
21976
+ if (isCrossRealmTableCell(anchorCell)) {
21953
21977
  return anchorCell;
21954
21978
  }
21955
21979
  const domAtPos = editor.view.domAtPos(editor.state.selection.from);
@@ -23018,12 +23042,12 @@ function useUEditorTableInteractions(editor, editable = true) {
23018
23042
  return;
23019
23043
  }
23020
23044
  const target = resolveEventElement(event.target);
23021
- if (!(target instanceof editorWindow.Element)) {
23045
+ if (!isCrossRealmElement(target)) {
23022
23046
  clearAllTableResizeHover();
23023
23047
  return;
23024
23048
  }
23025
23049
  const cell = target.closest("th,td");
23026
- if (!(cell instanceof editorWindow.HTMLElement)) {
23050
+ if (!isCrossRealmHTMLElement(cell)) {
23027
23051
  clearHoveredTableCell();
23028
23052
  clearAllTableResizeHover();
23029
23053
  return;
@@ -23031,7 +23055,7 @@ function useUEditorTableInteractions(editor, editable = true) {
23031
23055
  setHoveredTableCell(cell);
23032
23056
  const row = cell.closest("tr");
23033
23057
  const table = cell.closest("table");
23034
- if (!(row instanceof editorWindow.HTMLTableRowElement) || !(table instanceof editorWindow.HTMLTableElement)) {
23058
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTable(table)) {
23035
23059
  clearHoveredTableCell();
23036
23060
  clearAllTableResizeHover();
23037
23061
  return;
@@ -23087,18 +23111,18 @@ function useUEditorTableInteractions(editor, editable = true) {
23087
23111
  const handleEditorMouseDown = (event) => {
23088
23112
  if (event.button !== 0) return;
23089
23113
  const target = resolveEventElement(event.target);
23090
- if (!(target instanceof editorWindow.Element)) {
23114
+ if (!isCrossRealmElement(target)) {
23091
23115
  clearActiveTableCell();
23092
23116
  return;
23093
23117
  }
23094
23118
  const cell = target.closest("th,td");
23095
- if (!(cell instanceof editorWindow.HTMLTableCellElement)) {
23119
+ if (!isCrossRealmTableCell(cell)) {
23096
23120
  clearActiveTableCell();
23097
23121
  return;
23098
23122
  }
23099
23123
  const row = cell.closest("tr");
23100
23124
  const table = cell.closest("table");
23101
- if (!(row instanceof editorWindow.HTMLTableRowElement) || !(table instanceof editorWindow.HTMLTableElement)) return;
23125
+ if (!isCrossRealmTableRow(row) || !isCrossRealmTable(table)) return;
23102
23126
  const rowTarget = resolveRowResizeTarget(cell, event.clientX, event.clientY);
23103
23127
  if (rowTarget) {
23104
23128
  event.preventDefault();