@bagelink/vue 0.0.398 → 0.0.400

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
@@ -317,7 +317,7 @@ async function detectOverflow$1(state2, options) {
317
317
  right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
318
318
  };
319
319
  }
320
- const arrow$3 = (options) => ({
320
+ const arrow$4 = (options) => ({
321
321
  name: "arrow",
322
322
  options,
323
323
  async fn(state2) {
@@ -1508,7 +1508,7 @@ const q = "__floating-vue__popper", Q = () => vue.defineComponent({
1508
1508
  })), !t && this.flip && e.middleware.push(flip$2({
1509
1509
  padding: this.overflowPadding,
1510
1510
  boundary: this.boundary
1511
- }))), e.middleware.push(arrow$3({
1511
+ }))), e.middleware.push(arrow$4({
1512
1512
  element: this.$_arrowNode,
1513
1513
  padding: this.arrowPadding
1514
1514
  })), this.arrowOverflow && e.middleware.push({
@@ -17945,7 +17945,7 @@ const _sfc_main$g = /* @__PURE__ */ vue.defineComponent({
17945
17945
  rows[index2][fieldname] = value;
17946
17946
  emits("update:modelValue", rows);
17947
17947
  }
17948
- function addRow() {
17948
+ function addRow2() {
17949
17949
  const rows = [...props2.modelValue];
17950
17950
  const entry = {
17951
17951
  idx: rows.length
@@ -17962,7 +17962,7 @@ const _sfc_main$g = /* @__PURE__ */ vue.defineComponent({
17962
17962
  rows.push(entry);
17963
17963
  emits("update:modelValue", rows);
17964
17964
  }
17965
- function removeRow(idx) {
17965
+ function removeRow2(idx) {
17966
17966
  const rows = [...props2.modelValue];
17967
17967
  rows.splice(idx, 1);
17968
17968
  emits("update:modelValue", rows);
@@ -18034,7 +18034,7 @@ const _sfc_main$g = /* @__PURE__ */ vue.defineComponent({
18034
18034
  vue.createElementVNode("div", _hoisted_6$4, [
18035
18035
  vue.createVNode(vue.unref(_sfc_main$H), {
18036
18036
  icon: "delete",
18037
- onClick: ($event) => removeRow(index2)
18037
+ onClick: ($event) => removeRow2(index2)
18038
18038
  }, null, 8, ["onClick"])
18039
18039
  ])
18040
18040
  ]);
@@ -18051,7 +18051,7 @@ const _sfc_main$g = /* @__PURE__ */ vue.defineComponent({
18051
18051
  flat: "",
18052
18052
  icon: "add",
18053
18053
  color: "light",
18054
- onClick: addRow
18054
+ onClick: addRow2
18055
18055
  }, {
18056
18056
  default: vue.withCtx(() => [
18057
18057
  vue.createTextVNode(" New ")
@@ -27413,7 +27413,7 @@ function handleSingleClick(view, pos, inside, event, selectNode) {
27413
27413
  function handleDoubleClick(view, pos, inside, event) {
27414
27414
  return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) || view.someProp("handleDoubleClick", (f2) => f2(view, pos, event));
27415
27415
  }
27416
- function handleTripleClick(view, pos, inside, event) {
27416
+ function handleTripleClick$1(view, pos, inside, event) {
27417
27417
  return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || view.someProp("handleTripleClick", (f2) => f2(view, pos, event)) || defaultTripleClick(view, inside, event);
27418
27418
  }
27419
27419
  function defaultTripleClick(view, inside, event) {
@@ -27463,7 +27463,7 @@ handlers.mousedown = (view, _event) => {
27463
27463
  if (view.input.mouseDown)
27464
27464
  view.input.mouseDown.done();
27465
27465
  view.input.mouseDown = new MouseDown(view, pos, event, !!flushed);
27466
- } else if ((type3 == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event)) {
27466
+ } else if ((type3 == "doubleClick" ? handleDoubleClick : handleTripleClick$1)(view, pos.pos, pos.inside, event)) {
27467
27467
  event.preventDefault();
27468
27468
  } else {
27469
27469
  setSelectionOrigin(view, "pointer");
@@ -32974,8 +32974,8 @@ const Keymap = Extension.create({
32974
32974
  if (empty2 || !allWasSelected) {
32975
32975
  return;
32976
32976
  }
32977
- const isEmpty = newState.doc.textBetween(0, newState.doc.content.size, " ", " ").length === 0;
32978
- if (!isEmpty) {
32977
+ const isEmpty2 = newState.doc.textBetween(0, newState.doc.content.size, " ", " ").length === 0;
32978
+ if (!isEmpty2) {
32979
32979
  return;
32980
32980
  }
32981
32981
  const tr2 = newState.tr;
@@ -34711,18 +34711,18 @@ function gapCursor() {
34711
34711
  return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null;
34712
34712
  },
34713
34713
  handleClick,
34714
- handleKeyDown,
34714
+ handleKeyDown: handleKeyDown$1,
34715
34715
  handleDOMEvents: { beforeinput }
34716
34716
  }
34717
34717
  });
34718
34718
  }
34719
- const handleKeyDown = keydownHandler({
34720
- "ArrowLeft": arrow$2("horiz", -1),
34721
- "ArrowRight": arrow$2("horiz", 1),
34722
- "ArrowUp": arrow$2("vert", -1),
34723
- "ArrowDown": arrow$2("vert", 1)
34719
+ const handleKeyDown$1 = keydownHandler({
34720
+ "ArrowLeft": arrow$3("horiz", -1),
34721
+ "ArrowRight": arrow$3("horiz", 1),
34722
+ "ArrowUp": arrow$3("vert", -1),
34723
+ "ArrowDown": arrow$3("vert", 1)
34724
34724
  });
34725
- function arrow$2(axis2, dir) {
34725
+ function arrow$3(axis2, dir) {
34726
34726
  const dirStr = axis2 == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
34727
34727
  return function(state2, dispatch, view) {
34728
34728
  let sel = state2.selection;
@@ -36255,7 +36255,7 @@ var toPaddingObject = function toPaddingObject2(padding, state2) {
36255
36255
  })) : padding;
36256
36256
  return mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
36257
36257
  };
36258
- function arrow(_ref) {
36258
+ function arrow$1(_ref) {
36259
36259
  var _state$modifiersData$;
36260
36260
  var state2 = _ref.state, name = _ref.name, options = _ref.options;
36261
36261
  var arrowElement = state2.elements.arrow;
@@ -36300,11 +36300,11 @@ function effect$1(_ref2) {
36300
36300
  }
36301
36301
  state2.elements.arrow = arrowElement;
36302
36302
  }
36303
- const arrow$1 = {
36303
+ const arrow$2 = {
36304
36304
  name: "arrow",
36305
36305
  enabled: true,
36306
36306
  phase: "main",
36307
- fn: arrow,
36307
+ fn: arrow$1,
36308
36308
  effect: effect$1,
36309
36309
  requires: ["popperOffsets"],
36310
36310
  requiresIfExists: ["preventOverflow"]
@@ -37296,7 +37296,7 @@ function popperGenerator(generatorOptions) {
37296
37296
  return instance;
37297
37297
  };
37298
37298
  }
37299
- var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$1];
37299
+ var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$2, hide$1];
37300
37300
  var createPopper = /* @__PURE__ */ popperGenerator({
37301
37301
  defaultModifiers
37302
37302
  });
@@ -39442,6 +39442,2633 @@ const Youtube = Node$2.create({
39442
39442
  ];
39443
39443
  }
39444
39444
  });
39445
+ var readFromCache;
39446
+ var addToCache;
39447
+ if (typeof WeakMap != "undefined") {
39448
+ let cache = /* @__PURE__ */ new WeakMap();
39449
+ readFromCache = (key) => cache.get(key);
39450
+ addToCache = (key, value) => {
39451
+ cache.set(key, value);
39452
+ return value;
39453
+ };
39454
+ } else {
39455
+ const cache = [];
39456
+ const cacheSize = 10;
39457
+ let cachePos = 0;
39458
+ readFromCache = (key) => {
39459
+ for (let i2 = 0; i2 < cache.length; i2 += 2)
39460
+ if (cache[i2] == key)
39461
+ return cache[i2 + 1];
39462
+ };
39463
+ addToCache = (key, value) => {
39464
+ if (cachePos == cacheSize)
39465
+ cachePos = 0;
39466
+ cache[cachePos++] = key;
39467
+ return cache[cachePos++] = value;
39468
+ };
39469
+ }
39470
+ var TableMap = class {
39471
+ constructor(width, height, map4, problems) {
39472
+ this.width = width;
39473
+ this.height = height;
39474
+ this.map = map4;
39475
+ this.problems = problems;
39476
+ }
39477
+ // Find the dimensions of the cell at the given position.
39478
+ findCell(pos) {
39479
+ for (let i2 = 0; i2 < this.map.length; i2++) {
39480
+ const curPos = this.map[i2];
39481
+ if (curPos != pos)
39482
+ continue;
39483
+ const left2 = i2 % this.width;
39484
+ const top2 = i2 / this.width | 0;
39485
+ let right2 = left2 + 1;
39486
+ let bottom2 = top2 + 1;
39487
+ for (let j = 1; right2 < this.width && this.map[i2 + j] == curPos; j++) {
39488
+ right2++;
39489
+ }
39490
+ for (let j = 1; bottom2 < this.height && this.map[i2 + this.width * j] == curPos; j++) {
39491
+ bottom2++;
39492
+ }
39493
+ return { left: left2, top: top2, right: right2, bottom: bottom2 };
39494
+ }
39495
+ throw new RangeError(`No cell with offset ${pos} found`);
39496
+ }
39497
+ // Find the left side of the cell at the given position.
39498
+ colCount(pos) {
39499
+ for (let i2 = 0; i2 < this.map.length; i2++) {
39500
+ if (this.map[i2] == pos) {
39501
+ return i2 % this.width;
39502
+ }
39503
+ }
39504
+ throw new RangeError(`No cell with offset ${pos} found`);
39505
+ }
39506
+ // Find the next cell in the given direction, starting from the cell
39507
+ // at `pos`, if any.
39508
+ nextCell(pos, axis2, dir) {
39509
+ const { left: left2, right: right2, top: top2, bottom: bottom2 } = this.findCell(pos);
39510
+ if (axis2 == "horiz") {
39511
+ if (dir < 0 ? left2 == 0 : right2 == this.width)
39512
+ return null;
39513
+ return this.map[top2 * this.width + (dir < 0 ? left2 - 1 : right2)];
39514
+ } else {
39515
+ if (dir < 0 ? top2 == 0 : bottom2 == this.height)
39516
+ return null;
39517
+ return this.map[left2 + this.width * (dir < 0 ? top2 - 1 : bottom2)];
39518
+ }
39519
+ }
39520
+ // Get the rectangle spanning the two given cells.
39521
+ rectBetween(a2, b2) {
39522
+ const {
39523
+ left: leftA,
39524
+ right: rightA,
39525
+ top: topA,
39526
+ bottom: bottomA
39527
+ } = this.findCell(a2);
39528
+ const {
39529
+ left: leftB,
39530
+ right: rightB,
39531
+ top: topB,
39532
+ bottom: bottomB
39533
+ } = this.findCell(b2);
39534
+ return {
39535
+ left: Math.min(leftA, leftB),
39536
+ top: Math.min(topA, topB),
39537
+ right: Math.max(rightA, rightB),
39538
+ bottom: Math.max(bottomA, bottomB)
39539
+ };
39540
+ }
39541
+ // Return the position of all cells that have the top left corner in
39542
+ // the given rectangle.
39543
+ cellsInRect(rect) {
39544
+ const result = [];
39545
+ const seen = {};
39546
+ for (let row = rect.top; row < rect.bottom; row++) {
39547
+ for (let col = rect.left; col < rect.right; col++) {
39548
+ const index2 = row * this.width + col;
39549
+ const pos = this.map[index2];
39550
+ if (seen[pos])
39551
+ continue;
39552
+ seen[pos] = true;
39553
+ if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) {
39554
+ continue;
39555
+ }
39556
+ result.push(pos);
39557
+ }
39558
+ }
39559
+ return result;
39560
+ }
39561
+ // Return the position at which the cell at the given row and column
39562
+ // starts, or would start, if a cell started there.
39563
+ positionAt(row, col, table) {
39564
+ for (let i2 = 0, rowStart = 0; ; i2++) {
39565
+ const rowEnd = rowStart + table.child(i2).nodeSize;
39566
+ if (i2 == row) {
39567
+ let index2 = col + row * this.width;
39568
+ const rowEndIndex = (row + 1) * this.width;
39569
+ while (index2 < rowEndIndex && this.map[index2] < rowStart)
39570
+ index2++;
39571
+ return index2 == rowEndIndex ? rowEnd - 1 : this.map[index2];
39572
+ }
39573
+ rowStart = rowEnd;
39574
+ }
39575
+ }
39576
+ // Find the table map for the given table node.
39577
+ static get(table) {
39578
+ return readFromCache(table) || addToCache(table, computeMap(table));
39579
+ }
39580
+ };
39581
+ function computeMap(table) {
39582
+ if (table.type.spec.tableRole != "table")
39583
+ throw new RangeError("Not a table node: " + table.type.name);
39584
+ const width = findWidth(table), height = table.childCount;
39585
+ const map4 = [];
39586
+ let mapPos = 0;
39587
+ let problems = null;
39588
+ const colWidths = [];
39589
+ for (let i2 = 0, e = width * height; i2 < e; i2++)
39590
+ map4[i2] = 0;
39591
+ for (let row = 0, pos = 0; row < height; row++) {
39592
+ const rowNode = table.child(row);
39593
+ pos++;
39594
+ for (let i2 = 0; ; i2++) {
39595
+ while (mapPos < map4.length && map4[mapPos] != 0)
39596
+ mapPos++;
39597
+ if (i2 == rowNode.childCount)
39598
+ break;
39599
+ const cellNode = rowNode.child(i2);
39600
+ const { colspan, rowspan, colwidth } = cellNode.attrs;
39601
+ for (let h2 = 0; h2 < rowspan; h2++) {
39602
+ if (h2 + row >= height) {
39603
+ (problems || (problems = [])).push({
39604
+ type: "overlong_rowspan",
39605
+ pos,
39606
+ n: rowspan - h2
39607
+ });
39608
+ break;
39609
+ }
39610
+ const start2 = mapPos + h2 * width;
39611
+ for (let w2 = 0; w2 < colspan; w2++) {
39612
+ if (map4[start2 + w2] == 0)
39613
+ map4[start2 + w2] = pos;
39614
+ else
39615
+ (problems || (problems = [])).push({
39616
+ type: "collision",
39617
+ row,
39618
+ pos,
39619
+ n: colspan - w2
39620
+ });
39621
+ const colW = colwidth && colwidth[w2];
39622
+ if (colW) {
39623
+ const widthIndex = (start2 + w2) % width * 2, prev = colWidths[widthIndex];
39624
+ if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
39625
+ colWidths[widthIndex] = colW;
39626
+ colWidths[widthIndex + 1] = 1;
39627
+ } else if (prev == colW) {
39628
+ colWidths[widthIndex + 1]++;
39629
+ }
39630
+ }
39631
+ }
39632
+ }
39633
+ mapPos += colspan;
39634
+ pos += cellNode.nodeSize;
39635
+ }
39636
+ const expectedPos = (row + 1) * width;
39637
+ let missing = 0;
39638
+ while (mapPos < expectedPos)
39639
+ if (map4[mapPos++] == 0)
39640
+ missing++;
39641
+ if (missing)
39642
+ (problems || (problems = [])).push({ type: "missing", row, n: missing });
39643
+ pos++;
39644
+ }
39645
+ const tableMap = new TableMap(width, height, map4, problems);
39646
+ let badWidths = false;
39647
+ for (let i2 = 0; !badWidths && i2 < colWidths.length; i2 += 2)
39648
+ if (colWidths[i2] != null && colWidths[i2 + 1] < height)
39649
+ badWidths = true;
39650
+ if (badWidths)
39651
+ findBadColWidths(tableMap, colWidths, table);
39652
+ return tableMap;
39653
+ }
39654
+ function findWidth(table) {
39655
+ let width = -1;
39656
+ let hasRowSpan = false;
39657
+ for (let row = 0; row < table.childCount; row++) {
39658
+ const rowNode = table.child(row);
39659
+ let rowWidth = 0;
39660
+ if (hasRowSpan)
39661
+ for (let j = 0; j < row; j++) {
39662
+ const prevRow = table.child(j);
39663
+ for (let i2 = 0; i2 < prevRow.childCount; i2++) {
39664
+ const cell = prevRow.child(i2);
39665
+ if (j + cell.attrs.rowspan > row)
39666
+ rowWidth += cell.attrs.colspan;
39667
+ }
39668
+ }
39669
+ for (let i2 = 0; i2 < rowNode.childCount; i2++) {
39670
+ const cell = rowNode.child(i2);
39671
+ rowWidth += cell.attrs.colspan;
39672
+ if (cell.attrs.rowspan > 1)
39673
+ hasRowSpan = true;
39674
+ }
39675
+ if (width == -1)
39676
+ width = rowWidth;
39677
+ else if (width != rowWidth)
39678
+ width = Math.max(width, rowWidth);
39679
+ }
39680
+ return width;
39681
+ }
39682
+ function findBadColWidths(map4, colWidths, table) {
39683
+ if (!map4.problems)
39684
+ map4.problems = [];
39685
+ const seen = {};
39686
+ for (let i2 = 0; i2 < map4.map.length; i2++) {
39687
+ const pos = map4.map[i2];
39688
+ if (seen[pos])
39689
+ continue;
39690
+ seen[pos] = true;
39691
+ const node = table.nodeAt(pos);
39692
+ if (!node) {
39693
+ throw new RangeError(`No cell with offset ${pos} found`);
39694
+ }
39695
+ let updated = null;
39696
+ const attrs = node.attrs;
39697
+ for (let j = 0; j < attrs.colspan; j++) {
39698
+ const col = (i2 + j) % map4.width;
39699
+ const colWidth = colWidths[col * 2];
39700
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth))
39701
+ (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
39702
+ }
39703
+ if (updated)
39704
+ map4.problems.unshift({
39705
+ type: "colwidth mismatch",
39706
+ pos,
39707
+ colwidth: updated
39708
+ });
39709
+ }
39710
+ }
39711
+ function freshColWidth(attrs) {
39712
+ if (attrs.colwidth)
39713
+ return attrs.colwidth.slice();
39714
+ const result = [];
39715
+ for (let i2 = 0; i2 < attrs.colspan; i2++)
39716
+ result.push(0);
39717
+ return result;
39718
+ }
39719
+ function tableNodeTypes(schema) {
39720
+ let result = schema.cached.tableNodeTypes;
39721
+ if (!result) {
39722
+ result = schema.cached.tableNodeTypes = {};
39723
+ for (const name in schema.nodes) {
39724
+ const type3 = schema.nodes[name], role = type3.spec.tableRole;
39725
+ if (role)
39726
+ result[role] = type3;
39727
+ }
39728
+ }
39729
+ return result;
39730
+ }
39731
+ var tableEditingKey = new PluginKey("selectingCells");
39732
+ function cellAround($pos) {
39733
+ for (let d2 = $pos.depth - 1; d2 > 0; d2--)
39734
+ if ($pos.node(d2).type.spec.tableRole == "row")
39735
+ return $pos.node(0).resolve($pos.before(d2 + 1));
39736
+ return null;
39737
+ }
39738
+ function cellWrapping($pos) {
39739
+ for (let d2 = $pos.depth; d2 > 0; d2--) {
39740
+ const role = $pos.node(d2).type.spec.tableRole;
39741
+ if (role === "cell" || role === "header_cell")
39742
+ return $pos.node(d2);
39743
+ }
39744
+ return null;
39745
+ }
39746
+ function isInTable(state2) {
39747
+ const $head = state2.selection.$head;
39748
+ for (let d2 = $head.depth; d2 > 0; d2--)
39749
+ if ($head.node(d2).type.spec.tableRole == "row")
39750
+ return true;
39751
+ return false;
39752
+ }
39753
+ function selectionCell(state2) {
39754
+ const sel = state2.selection;
39755
+ if ("$anchorCell" in sel && sel.$anchorCell) {
39756
+ return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
39757
+ } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
39758
+ return sel.$anchor;
39759
+ }
39760
+ const $cell = cellAround(sel.$head) || cellNear(sel.$head);
39761
+ if ($cell) {
39762
+ return $cell;
39763
+ }
39764
+ throw new RangeError(`No cell found around position ${sel.head}`);
39765
+ }
39766
+ function cellNear($pos) {
39767
+ for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
39768
+ const role = after.type.spec.tableRole;
39769
+ if (role == "cell" || role == "header_cell")
39770
+ return $pos.doc.resolve(pos);
39771
+ }
39772
+ for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
39773
+ const role = before.type.spec.tableRole;
39774
+ if (role == "cell" || role == "header_cell")
39775
+ return $pos.doc.resolve(pos - before.nodeSize);
39776
+ }
39777
+ }
39778
+ function pointsAtCell($pos) {
39779
+ return $pos.parent.type.spec.tableRole == "row" && !!$pos.nodeAfter;
39780
+ }
39781
+ function moveCellForward($pos) {
39782
+ return $pos.node(0).resolve($pos.pos + $pos.nodeAfter.nodeSize);
39783
+ }
39784
+ function inSameTable($cellA, $cellB) {
39785
+ return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);
39786
+ }
39787
+ function nextCell($pos, axis2, dir) {
39788
+ const table = $pos.node(-1);
39789
+ const map4 = TableMap.get(table);
39790
+ const tableStart = $pos.start(-1);
39791
+ const moved2 = map4.nextCell($pos.pos - tableStart, axis2, dir);
39792
+ return moved2 == null ? null : $pos.node(0).resolve(tableStart + moved2);
39793
+ }
39794
+ function removeColSpan(attrs, pos, n2 = 1) {
39795
+ const result = { ...attrs, colspan: attrs.colspan - n2 };
39796
+ if (result.colwidth) {
39797
+ result.colwidth = result.colwidth.slice();
39798
+ result.colwidth.splice(pos, n2);
39799
+ if (!result.colwidth.some((w2) => w2 > 0))
39800
+ result.colwidth = null;
39801
+ }
39802
+ return result;
39803
+ }
39804
+ function addColSpan(attrs, pos, n2 = 1) {
39805
+ const result = { ...attrs, colspan: attrs.colspan + n2 };
39806
+ if (result.colwidth) {
39807
+ result.colwidth = result.colwidth.slice();
39808
+ for (let i2 = 0; i2 < n2; i2++)
39809
+ result.colwidth.splice(pos, 0, 0);
39810
+ }
39811
+ return result;
39812
+ }
39813
+ function columnIsHeader(map4, table, col) {
39814
+ const headerCell = tableNodeTypes(table.type.schema).header_cell;
39815
+ for (let row = 0; row < map4.height; row++)
39816
+ if (table.nodeAt(map4.map[col + row * map4.width]).type != headerCell)
39817
+ return false;
39818
+ return true;
39819
+ }
39820
+ var CellSelection = class _CellSelection extends Selection$1 {
39821
+ // A table selection is identified by its anchor and head cells. The
39822
+ // positions given to this constructor should point _before_ two
39823
+ // cells in the same table. They may be the same, to select a single
39824
+ // cell.
39825
+ constructor($anchorCell, $headCell = $anchorCell) {
39826
+ const table = $anchorCell.node(-1);
39827
+ const map4 = TableMap.get(table);
39828
+ const tableStart = $anchorCell.start(-1);
39829
+ const rect = map4.rectBetween(
39830
+ $anchorCell.pos - tableStart,
39831
+ $headCell.pos - tableStart
39832
+ );
39833
+ const doc2 = $anchorCell.node(0);
39834
+ const cells = map4.cellsInRect(rect).filter((p2) => p2 != $headCell.pos - tableStart);
39835
+ cells.unshift($headCell.pos - tableStart);
39836
+ const ranges = cells.map((pos) => {
39837
+ const cell = table.nodeAt(pos);
39838
+ if (!cell) {
39839
+ throw RangeError(`No cell with offset ${pos} found`);
39840
+ }
39841
+ const from2 = tableStart + pos + 1;
39842
+ return new SelectionRange(
39843
+ doc2.resolve(from2),
39844
+ doc2.resolve(from2 + cell.content.size)
39845
+ );
39846
+ });
39847
+ super(ranges[0].$from, ranges[0].$to, ranges);
39848
+ this.$anchorCell = $anchorCell;
39849
+ this.$headCell = $headCell;
39850
+ }
39851
+ map(doc2, mapping) {
39852
+ const $anchorCell = doc2.resolve(mapping.map(this.$anchorCell.pos));
39853
+ const $headCell = doc2.resolve(mapping.map(this.$headCell.pos));
39854
+ if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
39855
+ const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
39856
+ if (tableChanged && this.isRowSelection())
39857
+ return _CellSelection.rowSelection($anchorCell, $headCell);
39858
+ else if (tableChanged && this.isColSelection())
39859
+ return _CellSelection.colSelection($anchorCell, $headCell);
39860
+ else
39861
+ return new _CellSelection($anchorCell, $headCell);
39862
+ }
39863
+ return TextSelection.between($anchorCell, $headCell);
39864
+ }
39865
+ // Returns a rectangular slice of table rows containing the selected
39866
+ // cells.
39867
+ content() {
39868
+ const table = this.$anchorCell.node(-1);
39869
+ const map4 = TableMap.get(table);
39870
+ const tableStart = this.$anchorCell.start(-1);
39871
+ const rect = map4.rectBetween(
39872
+ this.$anchorCell.pos - tableStart,
39873
+ this.$headCell.pos - tableStart
39874
+ );
39875
+ const seen = {};
39876
+ const rows = [];
39877
+ for (let row = rect.top; row < rect.bottom; row++) {
39878
+ const rowContent = [];
39879
+ for (let index2 = row * map4.width + rect.left, col = rect.left; col < rect.right; col++, index2++) {
39880
+ const pos = map4.map[index2];
39881
+ if (seen[pos])
39882
+ continue;
39883
+ seen[pos] = true;
39884
+ const cellRect = map4.findCell(pos);
39885
+ let cell = table.nodeAt(pos);
39886
+ if (!cell) {
39887
+ throw RangeError(`No cell with offset ${pos} found`);
39888
+ }
39889
+ const extraLeft = rect.left - cellRect.left;
39890
+ const extraRight = cellRect.right - rect.right;
39891
+ if (extraLeft > 0 || extraRight > 0) {
39892
+ let attrs = cell.attrs;
39893
+ if (extraLeft > 0) {
39894
+ attrs = removeColSpan(attrs, 0, extraLeft);
39895
+ }
39896
+ if (extraRight > 0) {
39897
+ attrs = removeColSpan(
39898
+ attrs,
39899
+ attrs.colspan - extraRight,
39900
+ extraRight
39901
+ );
39902
+ }
39903
+ if (cellRect.left < rect.left) {
39904
+ cell = cell.type.createAndFill(attrs);
39905
+ if (!cell) {
39906
+ throw RangeError(
39907
+ `Could not create cell with attrs ${JSON.stringify(attrs)}`
39908
+ );
39909
+ }
39910
+ } else {
39911
+ cell = cell.type.create(attrs, cell.content);
39912
+ }
39913
+ }
39914
+ if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
39915
+ const attrs = {
39916
+ ...cell.attrs,
39917
+ rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
39918
+ };
39919
+ if (cellRect.top < rect.top) {
39920
+ cell = cell.type.createAndFill(attrs);
39921
+ } else {
39922
+ cell = cell.type.create(attrs, cell.content);
39923
+ }
39924
+ }
39925
+ rowContent.push(cell);
39926
+ }
39927
+ rows.push(table.child(row).copy(Fragment.from(rowContent)));
39928
+ }
39929
+ const fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
39930
+ return new Slice(Fragment.from(fragment), 1, 1);
39931
+ }
39932
+ replace(tr2, content = Slice.empty) {
39933
+ const mapFrom = tr2.steps.length, ranges = this.ranges;
39934
+ for (let i2 = 0; i2 < ranges.length; i2++) {
39935
+ const { $from, $to } = ranges[i2], mapping = tr2.mapping.slice(mapFrom);
39936
+ tr2.replace(
39937
+ mapping.map($from.pos),
39938
+ mapping.map($to.pos),
39939
+ i2 ? Slice.empty : content
39940
+ );
39941
+ }
39942
+ const sel = Selection$1.findFrom(
39943
+ tr2.doc.resolve(tr2.mapping.slice(mapFrom).map(this.to)),
39944
+ -1
39945
+ );
39946
+ if (sel)
39947
+ tr2.setSelection(sel);
39948
+ }
39949
+ replaceWith(tr2, node) {
39950
+ this.replace(tr2, new Slice(Fragment.from(node), 0, 0));
39951
+ }
39952
+ forEachCell(f2) {
39953
+ const table = this.$anchorCell.node(-1);
39954
+ const map4 = TableMap.get(table);
39955
+ const tableStart = this.$anchorCell.start(-1);
39956
+ const cells = map4.cellsInRect(
39957
+ map4.rectBetween(
39958
+ this.$anchorCell.pos - tableStart,
39959
+ this.$headCell.pos - tableStart
39960
+ )
39961
+ );
39962
+ for (let i2 = 0; i2 < cells.length; i2++) {
39963
+ f2(table.nodeAt(cells[i2]), tableStart + cells[i2]);
39964
+ }
39965
+ }
39966
+ // True if this selection goes all the way from the top to the
39967
+ // bottom of the table.
39968
+ isColSelection() {
39969
+ const anchorTop = this.$anchorCell.index(-1);
39970
+ const headTop = this.$headCell.index(-1);
39971
+ if (Math.min(anchorTop, headTop) > 0)
39972
+ return false;
39973
+ const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
39974
+ const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
39975
+ return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
39976
+ }
39977
+ // Returns the smallest column selection that covers the given anchor
39978
+ // and head cell.
39979
+ static colSelection($anchorCell, $headCell = $anchorCell) {
39980
+ const table = $anchorCell.node(-1);
39981
+ const map4 = TableMap.get(table);
39982
+ const tableStart = $anchorCell.start(-1);
39983
+ const anchorRect = map4.findCell($anchorCell.pos - tableStart);
39984
+ const headRect = map4.findCell($headCell.pos - tableStart);
39985
+ const doc2 = $anchorCell.node(0);
39986
+ if (anchorRect.top <= headRect.top) {
39987
+ if (anchorRect.top > 0)
39988
+ $anchorCell = doc2.resolve(tableStart + map4.map[anchorRect.left]);
39989
+ if (headRect.bottom < map4.height)
39990
+ $headCell = doc2.resolve(
39991
+ tableStart + map4.map[map4.width * (map4.height - 1) + headRect.right - 1]
39992
+ );
39993
+ } else {
39994
+ if (headRect.top > 0)
39995
+ $headCell = doc2.resolve(tableStart + map4.map[headRect.left]);
39996
+ if (anchorRect.bottom < map4.height)
39997
+ $anchorCell = doc2.resolve(
39998
+ tableStart + map4.map[map4.width * (map4.height - 1) + anchorRect.right - 1]
39999
+ );
40000
+ }
40001
+ return new _CellSelection($anchorCell, $headCell);
40002
+ }
40003
+ // True if this selection goes all the way from the left to the
40004
+ // right of the table.
40005
+ isRowSelection() {
40006
+ const table = this.$anchorCell.node(-1);
40007
+ const map4 = TableMap.get(table);
40008
+ const tableStart = this.$anchorCell.start(-1);
40009
+ const anchorLeft = map4.colCount(this.$anchorCell.pos - tableStart);
40010
+ const headLeft = map4.colCount(this.$headCell.pos - tableStart);
40011
+ if (Math.min(anchorLeft, headLeft) > 0)
40012
+ return false;
40013
+ const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
40014
+ const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
40015
+ return Math.max(anchorRight, headRight) == map4.width;
40016
+ }
40017
+ eq(other) {
40018
+ return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
40019
+ }
40020
+ // Returns the smallest row selection that covers the given anchor
40021
+ // and head cell.
40022
+ static rowSelection($anchorCell, $headCell = $anchorCell) {
40023
+ const table = $anchorCell.node(-1);
40024
+ const map4 = TableMap.get(table);
40025
+ const tableStart = $anchorCell.start(-1);
40026
+ const anchorRect = map4.findCell($anchorCell.pos - tableStart);
40027
+ const headRect = map4.findCell($headCell.pos - tableStart);
40028
+ const doc2 = $anchorCell.node(0);
40029
+ if (anchorRect.left <= headRect.left) {
40030
+ if (anchorRect.left > 0)
40031
+ $anchorCell = doc2.resolve(
40032
+ tableStart + map4.map[anchorRect.top * map4.width]
40033
+ );
40034
+ if (headRect.right < map4.width)
40035
+ $headCell = doc2.resolve(
40036
+ tableStart + map4.map[map4.width * (headRect.top + 1) - 1]
40037
+ );
40038
+ } else {
40039
+ if (headRect.left > 0)
40040
+ $headCell = doc2.resolve(tableStart + map4.map[headRect.top * map4.width]);
40041
+ if (anchorRect.right < map4.width)
40042
+ $anchorCell = doc2.resolve(
40043
+ tableStart + map4.map[map4.width * (anchorRect.top + 1) - 1]
40044
+ );
40045
+ }
40046
+ return new _CellSelection($anchorCell, $headCell);
40047
+ }
40048
+ toJSON() {
40049
+ return {
40050
+ type: "cell",
40051
+ anchor: this.$anchorCell.pos,
40052
+ head: this.$headCell.pos
40053
+ };
40054
+ }
40055
+ static fromJSON(doc2, json) {
40056
+ return new _CellSelection(doc2.resolve(json.anchor), doc2.resolve(json.head));
40057
+ }
40058
+ static create(doc2, anchorCell, headCell = anchorCell) {
40059
+ return new _CellSelection(doc2.resolve(anchorCell), doc2.resolve(headCell));
40060
+ }
40061
+ getBookmark() {
40062
+ return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
40063
+ }
40064
+ };
40065
+ CellSelection.prototype.visible = false;
40066
+ Selection$1.jsonID("cell", CellSelection);
40067
+ var CellBookmark = class _CellBookmark {
40068
+ constructor(anchor, head) {
40069
+ this.anchor = anchor;
40070
+ this.head = head;
40071
+ }
40072
+ map(mapping) {
40073
+ return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
40074
+ }
40075
+ resolve(doc2) {
40076
+ const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head);
40077
+ if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell))
40078
+ return new CellSelection($anchorCell, $headCell);
40079
+ else
40080
+ return Selection$1.near($headCell, 1);
40081
+ }
40082
+ };
40083
+ function drawCellSelection(state2) {
40084
+ if (!(state2.selection instanceof CellSelection))
40085
+ return null;
40086
+ const cells = [];
40087
+ state2.selection.forEachCell((node, pos) => {
40088
+ cells.push(
40089
+ Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
40090
+ );
40091
+ });
40092
+ return DecorationSet.create(state2.doc, cells);
40093
+ }
40094
+ function isCellBoundarySelection({ $from, $to }) {
40095
+ if ($from.pos == $to.pos || $from.pos < $from.pos - 6)
40096
+ return false;
40097
+ let afterFrom = $from.pos;
40098
+ let beforeTo = $to.pos;
40099
+ let depth = $from.depth;
40100
+ for (; depth >= 0; depth--, afterFrom++)
40101
+ if ($from.after(depth + 1) < $from.end(depth))
40102
+ break;
40103
+ for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--)
40104
+ if ($to.before(d2 + 1) > $to.start(d2))
40105
+ break;
40106
+ return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
40107
+ }
40108
+ function isTextSelectionAcrossCells({ $from, $to }) {
40109
+ let fromCellBoundaryNode;
40110
+ let toCellBoundaryNode;
40111
+ for (let i2 = $from.depth; i2 > 0; i2--) {
40112
+ const node = $from.node(i2);
40113
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
40114
+ fromCellBoundaryNode = node;
40115
+ break;
40116
+ }
40117
+ }
40118
+ for (let i2 = $to.depth; i2 > 0; i2--) {
40119
+ const node = $to.node(i2);
40120
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
40121
+ toCellBoundaryNode = node;
40122
+ break;
40123
+ }
40124
+ }
40125
+ return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
40126
+ }
40127
+ function normalizeSelection(state2, tr2, allowTableNodeSelection) {
40128
+ const sel = (tr2 || state2).selection;
40129
+ const doc2 = (tr2 || state2).doc;
40130
+ let normalize2;
40131
+ let role;
40132
+ if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
40133
+ if (role == "cell" || role == "header_cell") {
40134
+ normalize2 = CellSelection.create(doc2, sel.from);
40135
+ } else if (role == "row") {
40136
+ const $cell = doc2.resolve(sel.from + 1);
40137
+ normalize2 = CellSelection.rowSelection($cell, $cell);
40138
+ } else if (!allowTableNodeSelection) {
40139
+ const map4 = TableMap.get(sel.node);
40140
+ const start2 = sel.from + 1;
40141
+ const lastCell = start2 + map4.map[map4.width * map4.height - 1];
40142
+ normalize2 = CellSelection.create(doc2, start2 + 1, lastCell);
40143
+ }
40144
+ } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
40145
+ normalize2 = TextSelection.create(doc2, sel.from);
40146
+ } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
40147
+ normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
40148
+ }
40149
+ if (normalize2)
40150
+ (tr2 || (tr2 = state2.tr)).setSelection(normalize2);
40151
+ return tr2;
40152
+ }
40153
+ var fixTablesKey = new PluginKey("fix-tables");
40154
+ function changedDescendants(old, cur, offset2, f2) {
40155
+ const oldSize = old.childCount, curSize = cur.childCount;
40156
+ outer:
40157
+ for (let i2 = 0, j = 0; i2 < curSize; i2++) {
40158
+ const child = cur.child(i2);
40159
+ for (let scan = j, e = Math.min(oldSize, i2 + 3); scan < e; scan++) {
40160
+ if (old.child(scan) == child) {
40161
+ j = scan + 1;
40162
+ offset2 += child.nodeSize;
40163
+ continue outer;
40164
+ }
40165
+ }
40166
+ f2(child, offset2);
40167
+ if (j < oldSize && old.child(j).sameMarkup(child))
40168
+ changedDescendants(old.child(j), child, offset2 + 1, f2);
40169
+ else
40170
+ child.nodesBetween(0, child.content.size, f2, offset2 + 1);
40171
+ offset2 += child.nodeSize;
40172
+ }
40173
+ }
40174
+ function fixTables(state2, oldState) {
40175
+ let tr2;
40176
+ const check = (node, pos) => {
40177
+ if (node.type.spec.tableRole == "table")
40178
+ tr2 = fixTable(state2, node, pos, tr2);
40179
+ };
40180
+ if (!oldState)
40181
+ state2.doc.descendants(check);
40182
+ else if (oldState.doc != state2.doc)
40183
+ changedDescendants(oldState.doc, state2.doc, 0, check);
40184
+ return tr2;
40185
+ }
40186
+ function fixTable(state2, table, tablePos, tr2) {
40187
+ const map4 = TableMap.get(table);
40188
+ if (!map4.problems)
40189
+ return tr2;
40190
+ if (!tr2)
40191
+ tr2 = state2.tr;
40192
+ const mustAdd = [];
40193
+ for (let i2 = 0; i2 < map4.height; i2++)
40194
+ mustAdd.push(0);
40195
+ for (let i2 = 0; i2 < map4.problems.length; i2++) {
40196
+ const prob = map4.problems[i2];
40197
+ if (prob.type == "collision") {
40198
+ const cell = table.nodeAt(prob.pos);
40199
+ if (!cell)
40200
+ continue;
40201
+ const attrs = cell.attrs;
40202
+ for (let j = 0; j < attrs.rowspan; j++)
40203
+ mustAdd[prob.row + j] += prob.n;
40204
+ tr2.setNodeMarkup(
40205
+ tr2.mapping.map(tablePos + 1 + prob.pos),
40206
+ null,
40207
+ removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
40208
+ );
40209
+ } else if (prob.type == "missing") {
40210
+ mustAdd[prob.row] += prob.n;
40211
+ } else if (prob.type == "overlong_rowspan") {
40212
+ const cell = table.nodeAt(prob.pos);
40213
+ if (!cell)
40214
+ continue;
40215
+ tr2.setNodeMarkup(tr2.mapping.map(tablePos + 1 + prob.pos), null, {
40216
+ ...cell.attrs,
40217
+ rowspan: cell.attrs.rowspan - prob.n
40218
+ });
40219
+ } else if (prob.type == "colwidth mismatch") {
40220
+ const cell = table.nodeAt(prob.pos);
40221
+ if (!cell)
40222
+ continue;
40223
+ tr2.setNodeMarkup(tr2.mapping.map(tablePos + 1 + prob.pos), null, {
40224
+ ...cell.attrs,
40225
+ colwidth: prob.colwidth
40226
+ });
40227
+ }
40228
+ }
40229
+ let first2, last;
40230
+ for (let i2 = 0; i2 < mustAdd.length; i2++)
40231
+ if (mustAdd[i2]) {
40232
+ if (first2 == null)
40233
+ first2 = i2;
40234
+ last = i2;
40235
+ }
40236
+ for (let i2 = 0, pos = tablePos + 1; i2 < map4.height; i2++) {
40237
+ const row = table.child(i2);
40238
+ const end2 = pos + row.nodeSize;
40239
+ const add2 = mustAdd[i2];
40240
+ if (add2 > 0) {
40241
+ let role = "cell";
40242
+ if (row.firstChild) {
40243
+ role = row.firstChild.type.spec.tableRole;
40244
+ }
40245
+ const nodes = [];
40246
+ for (let j = 0; j < add2; j++) {
40247
+ const node = tableNodeTypes(state2.schema)[role].createAndFill();
40248
+ if (node)
40249
+ nodes.push(node);
40250
+ }
40251
+ const side = (i2 == 0 || first2 == i2 - 1) && last == i2 ? pos + 1 : end2 - 1;
40252
+ tr2.insert(tr2.mapping.map(side), nodes);
40253
+ }
40254
+ pos = end2;
40255
+ }
40256
+ return tr2.setMeta(fixTablesKey, { fixTables: true });
40257
+ }
40258
+ function pastedCells(slice4) {
40259
+ if (!slice4.size)
40260
+ return null;
40261
+ let { content, openStart, openEnd } = slice4;
40262
+ while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
40263
+ openStart--;
40264
+ openEnd--;
40265
+ content = content.child(0).content;
40266
+ }
40267
+ const first2 = content.child(0);
40268
+ const role = first2.type.spec.tableRole;
40269
+ const schema = first2.type.schema, rows = [];
40270
+ if (role == "row") {
40271
+ for (let i2 = 0; i2 < content.childCount; i2++) {
40272
+ let cells = content.child(i2).content;
40273
+ const left2 = i2 ? 0 : Math.max(0, openStart - 1);
40274
+ const right2 = i2 < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
40275
+ if (left2 || right2)
40276
+ cells = fitSlice(
40277
+ tableNodeTypes(schema).row,
40278
+ new Slice(cells, left2, right2)
40279
+ ).content;
40280
+ rows.push(cells);
40281
+ }
40282
+ } else if (role == "cell" || role == "header_cell") {
40283
+ rows.push(
40284
+ openStart || openEnd ? fitSlice(
40285
+ tableNodeTypes(schema).row,
40286
+ new Slice(content, openStart, openEnd)
40287
+ ).content : content
40288
+ );
40289
+ } else {
40290
+ return null;
40291
+ }
40292
+ return ensureRectangular(schema, rows);
40293
+ }
40294
+ function ensureRectangular(schema, rows) {
40295
+ const widths = [];
40296
+ for (let i2 = 0; i2 < rows.length; i2++) {
40297
+ const row = rows[i2];
40298
+ for (let j = row.childCount - 1; j >= 0; j--) {
40299
+ const { rowspan, colspan } = row.child(j).attrs;
40300
+ for (let r2 = i2; r2 < i2 + rowspan; r2++)
40301
+ widths[r2] = (widths[r2] || 0) + colspan;
40302
+ }
40303
+ }
40304
+ let width = 0;
40305
+ for (let r2 = 0; r2 < widths.length; r2++)
40306
+ width = Math.max(width, widths[r2]);
40307
+ for (let r2 = 0; r2 < widths.length; r2++) {
40308
+ if (r2 >= rows.length)
40309
+ rows.push(Fragment.empty);
40310
+ if (widths[r2] < width) {
40311
+ const empty2 = tableNodeTypes(schema).cell.createAndFill();
40312
+ const cells = [];
40313
+ for (let i2 = widths[r2]; i2 < width; i2++) {
40314
+ cells.push(empty2);
40315
+ }
40316
+ rows[r2] = rows[r2].append(Fragment.from(cells));
40317
+ }
40318
+ }
40319
+ return { height: rows.length, width, rows };
40320
+ }
40321
+ function fitSlice(nodeType, slice4) {
40322
+ const node = nodeType.createAndFill();
40323
+ const tr2 = new Transform(node).replace(0, node.content.size, slice4);
40324
+ return tr2.doc;
40325
+ }
40326
+ function clipCells({ width, height, rows }, newWidth, newHeight) {
40327
+ if (width != newWidth) {
40328
+ const added = [];
40329
+ const newRows = [];
40330
+ for (let row = 0; row < rows.length; row++) {
40331
+ const frag = rows[row], cells = [];
40332
+ for (let col = added[row] || 0, i2 = 0; col < newWidth; i2++) {
40333
+ let cell = frag.child(i2 % frag.childCount);
40334
+ if (col + cell.attrs.colspan > newWidth)
40335
+ cell = cell.type.createChecked(
40336
+ removeColSpan(
40337
+ cell.attrs,
40338
+ cell.attrs.colspan,
40339
+ col + cell.attrs.colspan - newWidth
40340
+ ),
40341
+ cell.content
40342
+ );
40343
+ cells.push(cell);
40344
+ col += cell.attrs.colspan;
40345
+ for (let j = 1; j < cell.attrs.rowspan; j++)
40346
+ added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
40347
+ }
40348
+ newRows.push(Fragment.from(cells));
40349
+ }
40350
+ rows = newRows;
40351
+ width = newWidth;
40352
+ }
40353
+ if (height != newHeight) {
40354
+ const newRows = [];
40355
+ for (let row = 0, i2 = 0; row < newHeight; row++, i2++) {
40356
+ const cells = [], source = rows[i2 % height];
40357
+ for (let j = 0; j < source.childCount; j++) {
40358
+ let cell = source.child(j);
40359
+ if (row + cell.attrs.rowspan > newHeight)
40360
+ cell = cell.type.create(
40361
+ {
40362
+ ...cell.attrs,
40363
+ rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
40364
+ },
40365
+ cell.content
40366
+ );
40367
+ cells.push(cell);
40368
+ }
40369
+ newRows.push(Fragment.from(cells));
40370
+ }
40371
+ rows = newRows;
40372
+ height = newHeight;
40373
+ }
40374
+ return { width, height, rows };
40375
+ }
40376
+ function growTable(tr2, map4, table, start2, width, height, mapFrom) {
40377
+ const schema = tr2.doc.type.schema;
40378
+ const types = tableNodeTypes(schema);
40379
+ let empty2;
40380
+ let emptyHead;
40381
+ if (width > map4.width) {
40382
+ for (let row = 0, rowEnd = 0; row < map4.height; row++) {
40383
+ const rowNode = table.child(row);
40384
+ rowEnd += rowNode.nodeSize;
40385
+ const cells = [];
40386
+ let add2;
40387
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)
40388
+ add2 = empty2 || (empty2 = types.cell.createAndFill());
40389
+ else
40390
+ add2 = emptyHead || (emptyHead = types.header_cell.createAndFill());
40391
+ for (let i2 = map4.width; i2 < width; i2++)
40392
+ cells.push(add2);
40393
+ tr2.insert(tr2.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
40394
+ }
40395
+ }
40396
+ if (height > map4.height) {
40397
+ const cells = [];
40398
+ for (let i2 = 0, start22 = (map4.height - 1) * map4.width; i2 < Math.max(map4.width, width); i2++) {
40399
+ const header = i2 >= map4.width ? false : table.nodeAt(map4.map[start22 + i2]).type == types.header_cell;
40400
+ cells.push(
40401
+ header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill())
40402
+ );
40403
+ }
40404
+ const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
40405
+ for (let i2 = map4.height; i2 < height; i2++)
40406
+ rows.push(emptyRow);
40407
+ tr2.insert(tr2.mapping.slice(mapFrom).map(start2 + table.nodeSize - 2), rows);
40408
+ }
40409
+ return !!(empty2 || emptyHead);
40410
+ }
40411
+ function isolateHorizontal(tr2, map4, table, start2, left2, right2, top2, mapFrom) {
40412
+ if (top2 == 0 || top2 == map4.height)
40413
+ return false;
40414
+ let found2 = false;
40415
+ for (let col = left2; col < right2; col++) {
40416
+ const index2 = top2 * map4.width + col, pos = map4.map[index2];
40417
+ if (map4.map[index2 - map4.width] == pos) {
40418
+ found2 = true;
40419
+ const cell = table.nodeAt(pos);
40420
+ const { top: cellTop, left: cellLeft } = map4.findCell(pos);
40421
+ tr2.setNodeMarkup(tr2.mapping.slice(mapFrom).map(pos + start2), null, {
40422
+ ...cell.attrs,
40423
+ rowspan: top2 - cellTop
40424
+ });
40425
+ tr2.insert(
40426
+ tr2.mapping.slice(mapFrom).map(map4.positionAt(top2, cellLeft, table)),
40427
+ cell.type.createAndFill({
40428
+ ...cell.attrs,
40429
+ rowspan: cellTop + cell.attrs.rowspan - top2
40430
+ })
40431
+ );
40432
+ col += cell.attrs.colspan - 1;
40433
+ }
40434
+ }
40435
+ return found2;
40436
+ }
40437
+ function isolateVertical(tr2, map4, table, start2, top2, bottom2, left2, mapFrom) {
40438
+ if (left2 == 0 || left2 == map4.width)
40439
+ return false;
40440
+ let found2 = false;
40441
+ for (let row = top2; row < bottom2; row++) {
40442
+ const index2 = row * map4.width + left2, pos = map4.map[index2];
40443
+ if (map4.map[index2 - 1] == pos) {
40444
+ found2 = true;
40445
+ const cell = table.nodeAt(pos);
40446
+ const cellLeft = map4.colCount(pos);
40447
+ const updatePos = tr2.mapping.slice(mapFrom).map(pos + start2);
40448
+ tr2.setNodeMarkup(
40449
+ updatePos,
40450
+ null,
40451
+ removeColSpan(
40452
+ cell.attrs,
40453
+ left2 - cellLeft,
40454
+ cell.attrs.colspan - (left2 - cellLeft)
40455
+ )
40456
+ );
40457
+ tr2.insert(
40458
+ updatePos + cell.nodeSize,
40459
+ cell.type.createAndFill(
40460
+ removeColSpan(cell.attrs, 0, left2 - cellLeft)
40461
+ )
40462
+ );
40463
+ row += cell.attrs.rowspan - 1;
40464
+ }
40465
+ }
40466
+ return found2;
40467
+ }
40468
+ function insertCells(state2, dispatch, tableStart, rect, cells) {
40469
+ let table = tableStart ? state2.doc.nodeAt(tableStart - 1) : state2.doc;
40470
+ if (!table) {
40471
+ throw new Error("No table found");
40472
+ }
40473
+ let map4 = TableMap.get(table);
40474
+ const { top: top2, left: left2 } = rect;
40475
+ const right2 = left2 + cells.width, bottom2 = top2 + cells.height;
40476
+ const tr2 = state2.tr;
40477
+ let mapFrom = 0;
40478
+ function recomp() {
40479
+ table = tableStart ? tr2.doc.nodeAt(tableStart - 1) : tr2.doc;
40480
+ if (!table) {
40481
+ throw new Error("No table found");
40482
+ }
40483
+ map4 = TableMap.get(table);
40484
+ mapFrom = tr2.mapping.maps.length;
40485
+ }
40486
+ if (growTable(tr2, map4, table, tableStart, right2, bottom2, mapFrom))
40487
+ recomp();
40488
+ if (isolateHorizontal(tr2, map4, table, tableStart, left2, right2, top2, mapFrom))
40489
+ recomp();
40490
+ if (isolateHorizontal(tr2, map4, table, tableStart, left2, right2, bottom2, mapFrom))
40491
+ recomp();
40492
+ if (isolateVertical(tr2, map4, table, tableStart, top2, bottom2, left2, mapFrom))
40493
+ recomp();
40494
+ if (isolateVertical(tr2, map4, table, tableStart, top2, bottom2, right2, mapFrom))
40495
+ recomp();
40496
+ for (let row = top2; row < bottom2; row++) {
40497
+ const from2 = map4.positionAt(row, left2, table), to2 = map4.positionAt(row, right2, table);
40498
+ tr2.replace(
40499
+ tr2.mapping.slice(mapFrom).map(from2 + tableStart),
40500
+ tr2.mapping.slice(mapFrom).map(to2 + tableStart),
40501
+ new Slice(cells.rows[row - top2], 0, 0)
40502
+ );
40503
+ }
40504
+ recomp();
40505
+ tr2.setSelection(
40506
+ new CellSelection(
40507
+ tr2.doc.resolve(tableStart + map4.positionAt(top2, left2, table)),
40508
+ tr2.doc.resolve(tableStart + map4.positionAt(bottom2 - 1, right2 - 1, table))
40509
+ )
40510
+ );
40511
+ dispatch(tr2);
40512
+ }
40513
+ var handleKeyDown = keydownHandler({
40514
+ ArrowLeft: arrow("horiz", -1),
40515
+ ArrowRight: arrow("horiz", 1),
40516
+ ArrowUp: arrow("vert", -1),
40517
+ ArrowDown: arrow("vert", 1),
40518
+ "Shift-ArrowLeft": shiftArrow("horiz", -1),
40519
+ "Shift-ArrowRight": shiftArrow("horiz", 1),
40520
+ "Shift-ArrowUp": shiftArrow("vert", -1),
40521
+ "Shift-ArrowDown": shiftArrow("vert", 1),
40522
+ Backspace: deleteCellSelection,
40523
+ "Mod-Backspace": deleteCellSelection,
40524
+ Delete: deleteCellSelection,
40525
+ "Mod-Delete": deleteCellSelection
40526
+ });
40527
+ function maybeSetSelection(state2, dispatch, selection) {
40528
+ if (selection.eq(state2.selection))
40529
+ return false;
40530
+ if (dispatch)
40531
+ dispatch(state2.tr.setSelection(selection).scrollIntoView());
40532
+ return true;
40533
+ }
40534
+ function arrow(axis2, dir) {
40535
+ return (state2, dispatch, view) => {
40536
+ if (!view)
40537
+ return false;
40538
+ const sel = state2.selection;
40539
+ if (sel instanceof CellSelection) {
40540
+ return maybeSetSelection(
40541
+ state2,
40542
+ dispatch,
40543
+ Selection$1.near(sel.$headCell, dir)
40544
+ );
40545
+ }
40546
+ if (axis2 != "horiz" && !sel.empty)
40547
+ return false;
40548
+ const end2 = atEndOfCell(view, axis2, dir);
40549
+ if (end2 == null)
40550
+ return false;
40551
+ if (axis2 == "horiz") {
40552
+ return maybeSetSelection(
40553
+ state2,
40554
+ dispatch,
40555
+ Selection$1.near(state2.doc.resolve(sel.head + dir), dir)
40556
+ );
40557
+ } else {
40558
+ const $cell = state2.doc.resolve(end2);
40559
+ const $next = nextCell($cell, axis2, dir);
40560
+ let newSel;
40561
+ if ($next)
40562
+ newSel = Selection$1.near($next, 1);
40563
+ else if (dir < 0)
40564
+ newSel = Selection$1.near(state2.doc.resolve($cell.before(-1)), -1);
40565
+ else
40566
+ newSel = Selection$1.near(state2.doc.resolve($cell.after(-1)), 1);
40567
+ return maybeSetSelection(state2, dispatch, newSel);
40568
+ }
40569
+ };
40570
+ }
40571
+ function shiftArrow(axis2, dir) {
40572
+ return (state2, dispatch, view) => {
40573
+ if (!view)
40574
+ return false;
40575
+ const sel = state2.selection;
40576
+ let cellSel;
40577
+ if (sel instanceof CellSelection) {
40578
+ cellSel = sel;
40579
+ } else {
40580
+ const end2 = atEndOfCell(view, axis2, dir);
40581
+ if (end2 == null)
40582
+ return false;
40583
+ cellSel = new CellSelection(state2.doc.resolve(end2));
40584
+ }
40585
+ const $head = nextCell(cellSel.$headCell, axis2, dir);
40586
+ if (!$head)
40587
+ return false;
40588
+ return maybeSetSelection(
40589
+ state2,
40590
+ dispatch,
40591
+ new CellSelection(cellSel.$anchorCell, $head)
40592
+ );
40593
+ };
40594
+ }
40595
+ function deleteCellSelection(state2, dispatch) {
40596
+ const sel = state2.selection;
40597
+ if (!(sel instanceof CellSelection))
40598
+ return false;
40599
+ if (dispatch) {
40600
+ const tr2 = state2.tr;
40601
+ const baseContent = tableNodeTypes(state2.schema).cell.createAndFill().content;
40602
+ sel.forEachCell((cell, pos) => {
40603
+ if (!cell.content.eq(baseContent))
40604
+ tr2.replace(
40605
+ tr2.mapping.map(pos + 1),
40606
+ tr2.mapping.map(pos + cell.nodeSize - 1),
40607
+ new Slice(baseContent, 0, 0)
40608
+ );
40609
+ });
40610
+ if (tr2.docChanged)
40611
+ dispatch(tr2);
40612
+ }
40613
+ return true;
40614
+ }
40615
+ function handleTripleClick(view, pos) {
40616
+ const doc2 = view.state.doc, $cell = cellAround(doc2.resolve(pos));
40617
+ if (!$cell)
40618
+ return false;
40619
+ view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
40620
+ return true;
40621
+ }
40622
+ function handlePaste(view, _2, slice4) {
40623
+ if (!isInTable(view.state))
40624
+ return false;
40625
+ let cells = pastedCells(slice4);
40626
+ const sel = view.state.selection;
40627
+ if (sel instanceof CellSelection) {
40628
+ if (!cells)
40629
+ cells = {
40630
+ width: 1,
40631
+ height: 1,
40632
+ rows: [
40633
+ Fragment.from(
40634
+ fitSlice(tableNodeTypes(view.state.schema).cell, slice4)
40635
+ )
40636
+ ]
40637
+ };
40638
+ const table = sel.$anchorCell.node(-1);
40639
+ const start2 = sel.$anchorCell.start(-1);
40640
+ const rect = TableMap.get(table).rectBetween(
40641
+ sel.$anchorCell.pos - start2,
40642
+ sel.$headCell.pos - start2
40643
+ );
40644
+ cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
40645
+ insertCells(view.state, view.dispatch, start2, rect, cells);
40646
+ return true;
40647
+ } else if (cells) {
40648
+ const $cell = selectionCell(view.state);
40649
+ const start2 = $cell.start(-1);
40650
+ insertCells(
40651
+ view.state,
40652
+ view.dispatch,
40653
+ start2,
40654
+ TableMap.get($cell.node(-1)).findCell($cell.pos - start2),
40655
+ cells
40656
+ );
40657
+ return true;
40658
+ } else {
40659
+ return false;
40660
+ }
40661
+ }
40662
+ function handleMouseDown(view, startEvent) {
40663
+ var _a2;
40664
+ if (startEvent.ctrlKey || startEvent.metaKey)
40665
+ return;
40666
+ const startDOMCell = domInCell(view, startEvent.target);
40667
+ let $anchor;
40668
+ if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
40669
+ setCellSelection(view.state.selection.$anchorCell, startEvent);
40670
+ startEvent.preventDefault();
40671
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a2 = cellUnderMouse(view, startEvent)) == null ? void 0 : _a2.pos) != $anchor.pos) {
40672
+ setCellSelection($anchor, startEvent);
40673
+ startEvent.preventDefault();
40674
+ } else if (!startDOMCell) {
40675
+ return;
40676
+ }
40677
+ function setCellSelection($anchor2, event) {
40678
+ let $head = cellUnderMouse(view, event);
40679
+ const starting = tableEditingKey.getState(view.state) == null;
40680
+ if (!$head || !inSameTable($anchor2, $head)) {
40681
+ if (starting)
40682
+ $head = $anchor2;
40683
+ else
40684
+ return;
40685
+ }
40686
+ const selection = new CellSelection($anchor2, $head);
40687
+ if (starting || !view.state.selection.eq(selection)) {
40688
+ const tr2 = view.state.tr.setSelection(selection);
40689
+ if (starting)
40690
+ tr2.setMeta(tableEditingKey, $anchor2.pos);
40691
+ view.dispatch(tr2);
40692
+ }
40693
+ }
40694
+ function stop() {
40695
+ view.root.removeEventListener("mouseup", stop);
40696
+ view.root.removeEventListener("dragstart", stop);
40697
+ view.root.removeEventListener("mousemove", move);
40698
+ if (tableEditingKey.getState(view.state) != null)
40699
+ view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
40700
+ }
40701
+ function move(_event) {
40702
+ const event = _event;
40703
+ const anchor = tableEditingKey.getState(view.state);
40704
+ let $anchor2;
40705
+ if (anchor != null) {
40706
+ $anchor2 = view.state.doc.resolve(anchor);
40707
+ } else if (domInCell(view, event.target) != startDOMCell) {
40708
+ $anchor2 = cellUnderMouse(view, startEvent);
40709
+ if (!$anchor2)
40710
+ return stop();
40711
+ }
40712
+ if ($anchor2)
40713
+ setCellSelection($anchor2, event);
40714
+ }
40715
+ view.root.addEventListener("mouseup", stop);
40716
+ view.root.addEventListener("dragstart", stop);
40717
+ view.root.addEventListener("mousemove", move);
40718
+ }
40719
+ function atEndOfCell(view, axis2, dir) {
40720
+ if (!(view.state.selection instanceof TextSelection))
40721
+ return null;
40722
+ const { $head } = view.state.selection;
40723
+ for (let d2 = $head.depth - 1; d2 >= 0; d2--) {
40724
+ const parent = $head.node(d2), index2 = dir < 0 ? $head.index(d2) : $head.indexAfter(d2);
40725
+ if (index2 != (dir < 0 ? 0 : parent.childCount))
40726
+ return null;
40727
+ if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
40728
+ const cellPos = $head.before(d2);
40729
+ const dirStr = axis2 == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
40730
+ return view.endOfTextblock(dirStr) ? cellPos : null;
40731
+ }
40732
+ }
40733
+ return null;
40734
+ }
40735
+ function domInCell(view, dom) {
40736
+ for (; dom && dom != view.dom; dom = dom.parentNode) {
40737
+ if (dom.nodeName == "TD" || dom.nodeName == "TH") {
40738
+ return dom;
40739
+ }
40740
+ }
40741
+ return null;
40742
+ }
40743
+ function cellUnderMouse(view, event) {
40744
+ const mousePos = view.posAtCoords({
40745
+ left: event.clientX,
40746
+ top: event.clientY
40747
+ });
40748
+ if (!mousePos)
40749
+ return null;
40750
+ return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
40751
+ }
40752
+ var TableView$1 = class TableView2 {
40753
+ constructor(node, cellMinWidth) {
40754
+ this.node = node;
40755
+ this.cellMinWidth = cellMinWidth;
40756
+ this.dom = document.createElement("div");
40757
+ this.dom.className = "tableWrapper";
40758
+ this.table = this.dom.appendChild(document.createElement("table"));
40759
+ this.colgroup = this.table.appendChild(document.createElement("colgroup"));
40760
+ updateColumnsOnResize(node, this.colgroup, this.table, cellMinWidth);
40761
+ this.contentDOM = this.table.appendChild(document.createElement("tbody"));
40762
+ }
40763
+ update(node) {
40764
+ if (node.type != this.node.type)
40765
+ return false;
40766
+ this.node = node;
40767
+ updateColumnsOnResize(node, this.colgroup, this.table, this.cellMinWidth);
40768
+ return true;
40769
+ }
40770
+ ignoreMutation(record) {
40771
+ return record.type == "attributes" && (record.target == this.table || this.colgroup.contains(record.target));
40772
+ }
40773
+ };
40774
+ function updateColumnsOnResize(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
40775
+ var _a2;
40776
+ let totalWidth = 0;
40777
+ let fixedWidth = true;
40778
+ let nextDOM = colgroup.firstChild;
40779
+ const row = node.firstChild;
40780
+ if (!row)
40781
+ return;
40782
+ for (let i2 = 0, col = 0; i2 < row.childCount; i2++) {
40783
+ const { colspan, colwidth } = row.child(i2).attrs;
40784
+ for (let j = 0; j < colspan; j++, col++) {
40785
+ const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j];
40786
+ const cssWidth = hasWidth ? hasWidth + "px" : "";
40787
+ totalWidth += hasWidth || cellMinWidth;
40788
+ if (!hasWidth)
40789
+ fixedWidth = false;
40790
+ if (!nextDOM) {
40791
+ colgroup.appendChild(document.createElement("col")).style.width = cssWidth;
40792
+ } else {
40793
+ if (nextDOM.style.width != cssWidth)
40794
+ nextDOM.style.width = cssWidth;
40795
+ nextDOM = nextDOM.nextSibling;
40796
+ }
40797
+ }
40798
+ }
40799
+ while (nextDOM) {
40800
+ const after = nextDOM.nextSibling;
40801
+ (_a2 = nextDOM.parentNode) == null ? void 0 : _a2.removeChild(nextDOM);
40802
+ nextDOM = after;
40803
+ }
40804
+ if (fixedWidth) {
40805
+ table.style.width = totalWidth + "px";
40806
+ table.style.minWidth = "";
40807
+ } else {
40808
+ table.style.width = "";
40809
+ table.style.minWidth = totalWidth + "px";
40810
+ }
40811
+ }
40812
+ var columnResizingPluginKey = new PluginKey(
40813
+ "tableColumnResizing"
40814
+ );
40815
+ function columnResizing({
40816
+ handleWidth = 5,
40817
+ cellMinWidth = 25,
40818
+ View = TableView$1,
40819
+ lastColumnResizable = true
40820
+ } = {}) {
40821
+ const plugin = new Plugin({
40822
+ key: columnResizingPluginKey,
40823
+ state: {
40824
+ init(_2, state2) {
40825
+ plugin.spec.props.nodeViews[tableNodeTypes(state2.schema).table.name] = (node, view) => new View(node, cellMinWidth, view);
40826
+ return new ResizeState(-1, false);
40827
+ },
40828
+ apply(tr2, prev) {
40829
+ return prev.apply(tr2);
40830
+ }
40831
+ },
40832
+ props: {
40833
+ attributes: (state2) => {
40834
+ const pluginState = columnResizingPluginKey.getState(state2);
40835
+ return pluginState && pluginState.activeHandle > -1 ? { class: "resize-cursor" } : {};
40836
+ },
40837
+ handleDOMEvents: {
40838
+ mousemove: (view, event) => {
40839
+ handleMouseMove(
40840
+ view,
40841
+ event,
40842
+ handleWidth,
40843
+ cellMinWidth,
40844
+ lastColumnResizable
40845
+ );
40846
+ },
40847
+ mouseleave: (view) => {
40848
+ handleMouseLeave(view);
40849
+ },
40850
+ mousedown: (view, event) => {
40851
+ handleMouseDown2(view, event, cellMinWidth);
40852
+ }
40853
+ },
40854
+ decorations: (state2) => {
40855
+ const pluginState = columnResizingPluginKey.getState(state2);
40856
+ if (pluginState && pluginState.activeHandle > -1) {
40857
+ return handleDecorations(state2, pluginState.activeHandle);
40858
+ }
40859
+ },
40860
+ nodeViews: {}
40861
+ }
40862
+ });
40863
+ return plugin;
40864
+ }
40865
+ var ResizeState = class _ResizeState {
40866
+ constructor(activeHandle, dragging) {
40867
+ this.activeHandle = activeHandle;
40868
+ this.dragging = dragging;
40869
+ }
40870
+ apply(tr2) {
40871
+ const state2 = this;
40872
+ const action = tr2.getMeta(columnResizingPluginKey);
40873
+ if (action && action.setHandle != null)
40874
+ return new _ResizeState(action.setHandle, false);
40875
+ if (action && action.setDragging !== void 0)
40876
+ return new _ResizeState(state2.activeHandle, action.setDragging);
40877
+ if (state2.activeHandle > -1 && tr2.docChanged) {
40878
+ let handle = tr2.mapping.map(state2.activeHandle, -1);
40879
+ if (!pointsAtCell(tr2.doc.resolve(handle))) {
40880
+ handle = -1;
40881
+ }
40882
+ return new _ResizeState(handle, state2.dragging);
40883
+ }
40884
+ return state2;
40885
+ }
40886
+ };
40887
+ function handleMouseMove(view, event, handleWidth, cellMinWidth, lastColumnResizable) {
40888
+ const pluginState = columnResizingPluginKey.getState(view.state);
40889
+ if (!pluginState)
40890
+ return;
40891
+ if (!pluginState.dragging) {
40892
+ const target = domCellAround(event.target);
40893
+ let cell = -1;
40894
+ if (target) {
40895
+ const { left: left2, right: right2 } = target.getBoundingClientRect();
40896
+ if (event.clientX - left2 <= handleWidth)
40897
+ cell = edgeCell(view, event, "left", handleWidth);
40898
+ else if (right2 - event.clientX <= handleWidth)
40899
+ cell = edgeCell(view, event, "right", handleWidth);
40900
+ }
40901
+ if (cell != pluginState.activeHandle) {
40902
+ if (!lastColumnResizable && cell !== -1) {
40903
+ const $cell = view.state.doc.resolve(cell);
40904
+ const table = $cell.node(-1);
40905
+ const map4 = TableMap.get(table);
40906
+ const tableStart = $cell.start(-1);
40907
+ const col = map4.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1;
40908
+ if (col == map4.width - 1) {
40909
+ return;
40910
+ }
40911
+ }
40912
+ updateHandle(view, cell);
40913
+ }
40914
+ }
40915
+ }
40916
+ function handleMouseLeave(view) {
40917
+ const pluginState = columnResizingPluginKey.getState(view.state);
40918
+ if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
40919
+ updateHandle(view, -1);
40920
+ }
40921
+ function handleMouseDown2(view, event, cellMinWidth) {
40922
+ var _a2;
40923
+ const win = (_a2 = view.dom.ownerDocument.defaultView) != null ? _a2 : window;
40924
+ const pluginState = columnResizingPluginKey.getState(view.state);
40925
+ if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
40926
+ return false;
40927
+ const cell = view.state.doc.nodeAt(pluginState.activeHandle);
40928
+ const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
40929
+ view.dispatch(
40930
+ view.state.tr.setMeta(columnResizingPluginKey, {
40931
+ setDragging: { startX: event.clientX, startWidth: width }
40932
+ })
40933
+ );
40934
+ function finish(event2) {
40935
+ win.removeEventListener("mouseup", finish);
40936
+ win.removeEventListener("mousemove", move);
40937
+ const pluginState2 = columnResizingPluginKey.getState(view.state);
40938
+ if (pluginState2 == null ? void 0 : pluginState2.dragging) {
40939
+ updateColumnWidth(
40940
+ view,
40941
+ pluginState2.activeHandle,
40942
+ draggedWidth(pluginState2.dragging, event2, cellMinWidth)
40943
+ );
40944
+ view.dispatch(
40945
+ view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
40946
+ );
40947
+ }
40948
+ }
40949
+ function move(event2) {
40950
+ if (!event2.which)
40951
+ return finish(event2);
40952
+ const pluginState2 = columnResizingPluginKey.getState(view.state);
40953
+ if (!pluginState2)
40954
+ return;
40955
+ if (pluginState2.dragging) {
40956
+ const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth);
40957
+ displayColumnWidth(view, pluginState2.activeHandle, dragged, cellMinWidth);
40958
+ }
40959
+ }
40960
+ win.addEventListener("mouseup", finish);
40961
+ win.addEventListener("mousemove", move);
40962
+ event.preventDefault();
40963
+ return true;
40964
+ }
40965
+ function currentColWidth(view, cellPos, { colspan, colwidth }) {
40966
+ const width = colwidth && colwidth[colwidth.length - 1];
40967
+ if (width)
40968
+ return width;
40969
+ const dom = view.domAtPos(cellPos);
40970
+ const node = dom.node.childNodes[dom.offset];
40971
+ let domWidth = node.offsetWidth, parts = colspan;
40972
+ if (colwidth) {
40973
+ for (let i2 = 0; i2 < colspan; i2++)
40974
+ if (colwidth[i2]) {
40975
+ domWidth -= colwidth[i2];
40976
+ parts--;
40977
+ }
40978
+ }
40979
+ return domWidth / parts;
40980
+ }
40981
+ function domCellAround(target) {
40982
+ while (target && target.nodeName != "TD" && target.nodeName != "TH")
40983
+ target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
40984
+ return target;
40985
+ }
40986
+ function edgeCell(view, event, side, handleWidth) {
40987
+ const offset2 = side == "right" ? -handleWidth : handleWidth;
40988
+ const found2 = view.posAtCoords({
40989
+ left: event.clientX + offset2,
40990
+ top: event.clientY
40991
+ });
40992
+ if (!found2)
40993
+ return -1;
40994
+ const { pos } = found2;
40995
+ const $cell = cellAround(view.state.doc.resolve(pos));
40996
+ if (!$cell)
40997
+ return -1;
40998
+ if (side == "right")
40999
+ return $cell.pos;
41000
+ const map4 = TableMap.get($cell.node(-1)), start2 = $cell.start(-1);
41001
+ const index2 = map4.map.indexOf($cell.pos - start2);
41002
+ return index2 % map4.width == 0 ? -1 : start2 + map4.map[index2 - 1];
41003
+ }
41004
+ function draggedWidth(dragging, event, cellMinWidth) {
41005
+ const offset2 = event.clientX - dragging.startX;
41006
+ return Math.max(cellMinWidth, dragging.startWidth + offset2);
41007
+ }
41008
+ function updateHandle(view, value) {
41009
+ view.dispatch(
41010
+ view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
41011
+ );
41012
+ }
41013
+ function updateColumnWidth(view, cell, width) {
41014
+ const $cell = view.state.doc.resolve(cell);
41015
+ const table = $cell.node(-1), map4 = TableMap.get(table), start2 = $cell.start(-1);
41016
+ const col = map4.colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
41017
+ const tr2 = view.state.tr;
41018
+ for (let row = 0; row < map4.height; row++) {
41019
+ const mapIndex = row * map4.width + col;
41020
+ if (row && map4.map[mapIndex] == map4.map[mapIndex - map4.width])
41021
+ continue;
41022
+ const pos = map4.map[mapIndex];
41023
+ const attrs = table.nodeAt(pos).attrs;
41024
+ const index2 = attrs.colspan == 1 ? 0 : col - map4.colCount(pos);
41025
+ if (attrs.colwidth && attrs.colwidth[index2] == width)
41026
+ continue;
41027
+ const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
41028
+ colwidth[index2] = width;
41029
+ tr2.setNodeMarkup(start2 + pos, null, { ...attrs, colwidth });
41030
+ }
41031
+ if (tr2.docChanged)
41032
+ view.dispatch(tr2);
41033
+ }
41034
+ function displayColumnWidth(view, cell, width, cellMinWidth) {
41035
+ const $cell = view.state.doc.resolve(cell);
41036
+ const table = $cell.node(-1), start2 = $cell.start(-1);
41037
+ const col = TableMap.get(table).colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
41038
+ let dom = view.domAtPos($cell.start(-1)).node;
41039
+ while (dom && dom.nodeName != "TABLE") {
41040
+ dom = dom.parentNode;
41041
+ }
41042
+ if (!dom)
41043
+ return;
41044
+ updateColumnsOnResize(
41045
+ table,
41046
+ dom.firstChild,
41047
+ dom,
41048
+ cellMinWidth,
41049
+ col,
41050
+ width
41051
+ );
41052
+ }
41053
+ function zeroes(n2) {
41054
+ return Array(n2).fill(0);
41055
+ }
41056
+ function handleDecorations(state2, cell) {
41057
+ const decorations = [];
41058
+ const $cell = state2.doc.resolve(cell);
41059
+ const table = $cell.node(-1);
41060
+ if (!table) {
41061
+ return DecorationSet.empty;
41062
+ }
41063
+ const map4 = TableMap.get(table);
41064
+ const start2 = $cell.start(-1);
41065
+ const col = map4.colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan;
41066
+ for (let row = 0; row < map4.height; row++) {
41067
+ const index2 = col + row * map4.width - 1;
41068
+ if ((col == map4.width || map4.map[index2] != map4.map[index2 + 1]) && (row == 0 || map4.map[index2] != map4.map[index2 - map4.width])) {
41069
+ const cellPos = map4.map[index2];
41070
+ const pos = start2 + cellPos + table.nodeAt(cellPos).nodeSize - 1;
41071
+ const dom = document.createElement("div");
41072
+ dom.className = "column-resize-handle";
41073
+ decorations.push(Decoration.widget(pos, dom));
41074
+ }
41075
+ }
41076
+ return DecorationSet.create(state2.doc, decorations);
41077
+ }
41078
+ function selectedRect(state2) {
41079
+ const sel = state2.selection;
41080
+ const $pos = selectionCell(state2);
41081
+ const table = $pos.node(-1);
41082
+ const tableStart = $pos.start(-1);
41083
+ const map4 = TableMap.get(table);
41084
+ const rect = sel instanceof CellSelection ? map4.rectBetween(
41085
+ sel.$anchorCell.pos - tableStart,
41086
+ sel.$headCell.pos - tableStart
41087
+ ) : map4.findCell($pos.pos - tableStart);
41088
+ return { ...rect, tableStart, map: map4, table };
41089
+ }
41090
+ function addColumn(tr2, { map: map4, tableStart, table }, col) {
41091
+ let refColumn = col > 0 ? -1 : 0;
41092
+ if (columnIsHeader(map4, table, col + refColumn)) {
41093
+ refColumn = col == 0 || col == map4.width ? null : 0;
41094
+ }
41095
+ for (let row = 0; row < map4.height; row++) {
41096
+ const index2 = row * map4.width + col;
41097
+ if (col > 0 && col < map4.width && map4.map[index2 - 1] == map4.map[index2]) {
41098
+ const pos = map4.map[index2];
41099
+ const cell = table.nodeAt(pos);
41100
+ tr2.setNodeMarkup(
41101
+ tr2.mapping.map(tableStart + pos),
41102
+ null,
41103
+ addColSpan(cell.attrs, col - map4.colCount(pos))
41104
+ );
41105
+ row += cell.attrs.rowspan - 1;
41106
+ } else {
41107
+ const type3 = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map4.map[index2 + refColumn]).type;
41108
+ const pos = map4.positionAt(row, col, table);
41109
+ tr2.insert(tr2.mapping.map(tableStart + pos), type3.createAndFill());
41110
+ }
41111
+ }
41112
+ return tr2;
41113
+ }
41114
+ function addColumnBefore(state2, dispatch) {
41115
+ if (!isInTable(state2))
41116
+ return false;
41117
+ if (dispatch) {
41118
+ const rect = selectedRect(state2);
41119
+ dispatch(addColumn(state2.tr, rect, rect.left));
41120
+ }
41121
+ return true;
41122
+ }
41123
+ function addColumnAfter(state2, dispatch) {
41124
+ if (!isInTable(state2))
41125
+ return false;
41126
+ if (dispatch) {
41127
+ const rect = selectedRect(state2);
41128
+ dispatch(addColumn(state2.tr, rect, rect.right));
41129
+ }
41130
+ return true;
41131
+ }
41132
+ function removeColumn(tr2, { map: map4, table, tableStart }, col) {
41133
+ const mapStart = tr2.mapping.maps.length;
41134
+ for (let row = 0; row < map4.height; ) {
41135
+ const index2 = row * map4.width + col;
41136
+ const pos = map4.map[index2];
41137
+ const cell = table.nodeAt(pos);
41138
+ const attrs = cell.attrs;
41139
+ if (col > 0 && map4.map[index2 - 1] == pos || col < map4.width - 1 && map4.map[index2 + 1] == pos) {
41140
+ tr2.setNodeMarkup(
41141
+ tr2.mapping.slice(mapStart).map(tableStart + pos),
41142
+ null,
41143
+ removeColSpan(attrs, col - map4.colCount(pos))
41144
+ );
41145
+ } else {
41146
+ const start2 = tr2.mapping.slice(mapStart).map(tableStart + pos);
41147
+ tr2.delete(start2, start2 + cell.nodeSize);
41148
+ }
41149
+ row += attrs.rowspan;
41150
+ }
41151
+ }
41152
+ function deleteColumn(state2, dispatch) {
41153
+ if (!isInTable(state2))
41154
+ return false;
41155
+ if (dispatch) {
41156
+ const rect = selectedRect(state2);
41157
+ const tr2 = state2.tr;
41158
+ if (rect.left == 0 && rect.right == rect.map.width)
41159
+ return false;
41160
+ for (let i2 = rect.right - 1; ; i2--) {
41161
+ removeColumn(tr2, rect, i2);
41162
+ if (i2 == rect.left)
41163
+ break;
41164
+ const table = rect.tableStart ? tr2.doc.nodeAt(rect.tableStart - 1) : tr2.doc;
41165
+ if (!table) {
41166
+ throw RangeError("No table found");
41167
+ }
41168
+ rect.table = table;
41169
+ rect.map = TableMap.get(table);
41170
+ }
41171
+ dispatch(tr2);
41172
+ }
41173
+ return true;
41174
+ }
41175
+ function rowIsHeader(map4, table, row) {
41176
+ var _a2;
41177
+ const headerCell = tableNodeTypes(table.type.schema).header_cell;
41178
+ for (let col = 0; col < map4.width; col++)
41179
+ if (((_a2 = table.nodeAt(map4.map[col + row * map4.width])) == null ? void 0 : _a2.type) != headerCell)
41180
+ return false;
41181
+ return true;
41182
+ }
41183
+ function addRow(tr2, { map: map4, tableStart, table }, row) {
41184
+ var _a2;
41185
+ let rowPos = tableStart;
41186
+ for (let i2 = 0; i2 < row; i2++)
41187
+ rowPos += table.child(i2).nodeSize;
41188
+ const cells = [];
41189
+ let refRow = row > 0 ? -1 : 0;
41190
+ if (rowIsHeader(map4, table, row + refRow))
41191
+ refRow = row == 0 || row == map4.height ? null : 0;
41192
+ for (let col = 0, index2 = map4.width * row; col < map4.width; col++, index2++) {
41193
+ if (row > 0 && row < map4.height && map4.map[index2] == map4.map[index2 - map4.width]) {
41194
+ const pos = map4.map[index2];
41195
+ const attrs = table.nodeAt(pos).attrs;
41196
+ tr2.setNodeMarkup(tableStart + pos, null, {
41197
+ ...attrs,
41198
+ rowspan: attrs.rowspan + 1
41199
+ });
41200
+ col += attrs.colspan - 1;
41201
+ } else {
41202
+ const type3 = refRow == null ? tableNodeTypes(table.type.schema).cell : (_a2 = table.nodeAt(map4.map[index2 + refRow * map4.width])) == null ? void 0 : _a2.type;
41203
+ const node = type3 == null ? void 0 : type3.createAndFill();
41204
+ if (node)
41205
+ cells.push(node);
41206
+ }
41207
+ }
41208
+ tr2.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
41209
+ return tr2;
41210
+ }
41211
+ function addRowBefore(state2, dispatch) {
41212
+ if (!isInTable(state2))
41213
+ return false;
41214
+ if (dispatch) {
41215
+ const rect = selectedRect(state2);
41216
+ dispatch(addRow(state2.tr, rect, rect.top));
41217
+ }
41218
+ return true;
41219
+ }
41220
+ function addRowAfter(state2, dispatch) {
41221
+ if (!isInTable(state2))
41222
+ return false;
41223
+ if (dispatch) {
41224
+ const rect = selectedRect(state2);
41225
+ dispatch(addRow(state2.tr, rect, rect.bottom));
41226
+ }
41227
+ return true;
41228
+ }
41229
+ function removeRow(tr2, { map: map4, table, tableStart }, row) {
41230
+ let rowPos = 0;
41231
+ for (let i2 = 0; i2 < row; i2++)
41232
+ rowPos += table.child(i2).nodeSize;
41233
+ const nextRow = rowPos + table.child(row).nodeSize;
41234
+ const mapFrom = tr2.mapping.maps.length;
41235
+ tr2.delete(rowPos + tableStart, nextRow + tableStart);
41236
+ const seen = /* @__PURE__ */ new Set();
41237
+ for (let col = 0, index2 = row * map4.width; col < map4.width; col++, index2++) {
41238
+ const pos = map4.map[index2];
41239
+ if (seen.has(pos))
41240
+ continue;
41241
+ seen.add(pos);
41242
+ if (row > 0 && pos == map4.map[index2 - map4.width]) {
41243
+ const attrs = table.nodeAt(pos).attrs;
41244
+ tr2.setNodeMarkup(tr2.mapping.slice(mapFrom).map(pos + tableStart), null, {
41245
+ ...attrs,
41246
+ rowspan: attrs.rowspan - 1
41247
+ });
41248
+ col += attrs.colspan - 1;
41249
+ } else if (row < map4.height && pos == map4.map[index2 + map4.width]) {
41250
+ const cell = table.nodeAt(pos);
41251
+ const attrs = cell.attrs;
41252
+ const copy2 = cell.type.create(
41253
+ { ...attrs, rowspan: cell.attrs.rowspan - 1 },
41254
+ cell.content
41255
+ );
41256
+ const newPos = map4.positionAt(row + 1, col, table);
41257
+ tr2.insert(tr2.mapping.slice(mapFrom).map(tableStart + newPos), copy2);
41258
+ col += attrs.colspan - 1;
41259
+ }
41260
+ }
41261
+ }
41262
+ function deleteRow(state2, dispatch) {
41263
+ if (!isInTable(state2))
41264
+ return false;
41265
+ if (dispatch) {
41266
+ const rect = selectedRect(state2), tr2 = state2.tr;
41267
+ if (rect.top == 0 && rect.bottom == rect.map.height)
41268
+ return false;
41269
+ for (let i2 = rect.bottom - 1; ; i2--) {
41270
+ removeRow(tr2, rect, i2);
41271
+ if (i2 == rect.top)
41272
+ break;
41273
+ const table = rect.tableStart ? tr2.doc.nodeAt(rect.tableStart - 1) : tr2.doc;
41274
+ if (!table) {
41275
+ throw RangeError("No table found");
41276
+ }
41277
+ rect.table = table;
41278
+ rect.map = TableMap.get(rect.table);
41279
+ }
41280
+ dispatch(tr2);
41281
+ }
41282
+ return true;
41283
+ }
41284
+ function isEmpty(cell) {
41285
+ const c2 = cell.content;
41286
+ return c2.childCount == 1 && c2.child(0).isTextblock && c2.child(0).childCount == 0;
41287
+ }
41288
+ function cellsOverlapRectangle({ width, height, map: map4 }, rect) {
41289
+ let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
41290
+ let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
41291
+ for (let i2 = rect.top; i2 < rect.bottom; i2++) {
41292
+ if (rect.left > 0 && map4[indexLeft] == map4[indexLeft - 1] || rect.right < width && map4[indexRight] == map4[indexRight + 1])
41293
+ return true;
41294
+ indexLeft += width;
41295
+ indexRight += width;
41296
+ }
41297
+ for (let i2 = rect.left; i2 < rect.right; i2++) {
41298
+ if (rect.top > 0 && map4[indexTop] == map4[indexTop - width] || rect.bottom < height && map4[indexBottom] == map4[indexBottom + width])
41299
+ return true;
41300
+ indexTop++;
41301
+ indexBottom++;
41302
+ }
41303
+ return false;
41304
+ }
41305
+ function mergeCells(state2, dispatch) {
41306
+ const sel = state2.selection;
41307
+ if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
41308
+ return false;
41309
+ const rect = selectedRect(state2), { map: map4 } = rect;
41310
+ if (cellsOverlapRectangle(map4, rect))
41311
+ return false;
41312
+ if (dispatch) {
41313
+ const tr2 = state2.tr;
41314
+ const seen = {};
41315
+ let content = Fragment.empty;
41316
+ let mergedPos;
41317
+ let mergedCell;
41318
+ for (let row = rect.top; row < rect.bottom; row++) {
41319
+ for (let col = rect.left; col < rect.right; col++) {
41320
+ const cellPos = map4.map[row * map4.width + col];
41321
+ const cell = rect.table.nodeAt(cellPos);
41322
+ if (seen[cellPos] || !cell)
41323
+ continue;
41324
+ seen[cellPos] = true;
41325
+ if (mergedPos == null) {
41326
+ mergedPos = cellPos;
41327
+ mergedCell = cell;
41328
+ } else {
41329
+ if (!isEmpty(cell))
41330
+ content = content.append(cell.content);
41331
+ const mapped = tr2.mapping.map(cellPos + rect.tableStart);
41332
+ tr2.delete(mapped, mapped + cell.nodeSize);
41333
+ }
41334
+ }
41335
+ }
41336
+ if (mergedPos == null || mergedCell == null) {
41337
+ return true;
41338
+ }
41339
+ tr2.setNodeMarkup(mergedPos + rect.tableStart, null, {
41340
+ ...addColSpan(
41341
+ mergedCell.attrs,
41342
+ mergedCell.attrs.colspan,
41343
+ rect.right - rect.left - mergedCell.attrs.colspan
41344
+ ),
41345
+ rowspan: rect.bottom - rect.top
41346
+ });
41347
+ if (content.size) {
41348
+ const end2 = mergedPos + 1 + mergedCell.content.size;
41349
+ const start2 = isEmpty(mergedCell) ? mergedPos + 1 : end2;
41350
+ tr2.replaceWith(start2 + rect.tableStart, end2 + rect.tableStart, content);
41351
+ }
41352
+ tr2.setSelection(
41353
+ new CellSelection(tr2.doc.resolve(mergedPos + rect.tableStart))
41354
+ );
41355
+ dispatch(tr2);
41356
+ }
41357
+ return true;
41358
+ }
41359
+ function splitCell(state2, dispatch) {
41360
+ const nodeTypes = tableNodeTypes(state2.schema);
41361
+ return splitCellWithType(({ node }) => {
41362
+ return nodeTypes[node.type.spec.tableRole];
41363
+ })(state2, dispatch);
41364
+ }
41365
+ function splitCellWithType(getCellType) {
41366
+ return (state2, dispatch) => {
41367
+ var _a2;
41368
+ const sel = state2.selection;
41369
+ let cellNode;
41370
+ let cellPos;
41371
+ if (!(sel instanceof CellSelection)) {
41372
+ cellNode = cellWrapping(sel.$from);
41373
+ if (!cellNode)
41374
+ return false;
41375
+ cellPos = (_a2 = cellAround(sel.$from)) == null ? void 0 : _a2.pos;
41376
+ } else {
41377
+ if (sel.$anchorCell.pos != sel.$headCell.pos)
41378
+ return false;
41379
+ cellNode = sel.$anchorCell.nodeAfter;
41380
+ cellPos = sel.$anchorCell.pos;
41381
+ }
41382
+ if (cellNode == null || cellPos == null) {
41383
+ return false;
41384
+ }
41385
+ if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
41386
+ return false;
41387
+ }
41388
+ if (dispatch) {
41389
+ let baseAttrs = cellNode.attrs;
41390
+ const attrs = [];
41391
+ const colwidth = baseAttrs.colwidth;
41392
+ if (baseAttrs.rowspan > 1)
41393
+ baseAttrs = { ...baseAttrs, rowspan: 1 };
41394
+ if (baseAttrs.colspan > 1)
41395
+ baseAttrs = { ...baseAttrs, colspan: 1 };
41396
+ const rect = selectedRect(state2), tr2 = state2.tr;
41397
+ for (let i2 = 0; i2 < rect.right - rect.left; i2++)
41398
+ attrs.push(
41399
+ colwidth ? {
41400
+ ...baseAttrs,
41401
+ colwidth: colwidth && colwidth[i2] ? [colwidth[i2]] : null
41402
+ } : baseAttrs
41403
+ );
41404
+ let lastCell;
41405
+ for (let row = rect.top; row < rect.bottom; row++) {
41406
+ let pos = rect.map.positionAt(row, rect.left, rect.table);
41407
+ if (row == rect.top)
41408
+ pos += cellNode.nodeSize;
41409
+ for (let col = rect.left, i2 = 0; col < rect.right; col++, i2++) {
41410
+ if (col == rect.left && row == rect.top)
41411
+ continue;
41412
+ tr2.insert(
41413
+ lastCell = tr2.mapping.map(pos + rect.tableStart, 1),
41414
+ getCellType({ node: cellNode, row, col }).createAndFill(attrs[i2])
41415
+ );
41416
+ }
41417
+ }
41418
+ tr2.setNodeMarkup(
41419
+ cellPos,
41420
+ getCellType({ node: cellNode, row: rect.top, col: rect.left }),
41421
+ attrs[0]
41422
+ );
41423
+ if (sel instanceof CellSelection)
41424
+ tr2.setSelection(
41425
+ new CellSelection(
41426
+ tr2.doc.resolve(sel.$anchorCell.pos),
41427
+ lastCell ? tr2.doc.resolve(lastCell) : void 0
41428
+ )
41429
+ );
41430
+ dispatch(tr2);
41431
+ }
41432
+ return true;
41433
+ };
41434
+ }
41435
+ function setCellAttr(name, value) {
41436
+ return function(state2, dispatch) {
41437
+ if (!isInTable(state2))
41438
+ return false;
41439
+ const $cell = selectionCell(state2);
41440
+ if ($cell.nodeAfter.attrs[name] === value)
41441
+ return false;
41442
+ if (dispatch) {
41443
+ const tr2 = state2.tr;
41444
+ if (state2.selection instanceof CellSelection)
41445
+ state2.selection.forEachCell((node, pos) => {
41446
+ if (node.attrs[name] !== value)
41447
+ tr2.setNodeMarkup(pos, null, {
41448
+ ...node.attrs,
41449
+ [name]: value
41450
+ });
41451
+ });
41452
+ else
41453
+ tr2.setNodeMarkup($cell.pos, null, {
41454
+ ...$cell.nodeAfter.attrs,
41455
+ [name]: value
41456
+ });
41457
+ dispatch(tr2);
41458
+ }
41459
+ return true;
41460
+ };
41461
+ }
41462
+ function deprecated_toggleHeader(type3) {
41463
+ return function(state2, dispatch) {
41464
+ if (!isInTable(state2))
41465
+ return false;
41466
+ if (dispatch) {
41467
+ const types = tableNodeTypes(state2.schema);
41468
+ const rect = selectedRect(state2), tr2 = state2.tr;
41469
+ const cells = rect.map.cellsInRect(
41470
+ type3 == "column" ? {
41471
+ left: rect.left,
41472
+ top: 0,
41473
+ right: rect.right,
41474
+ bottom: rect.map.height
41475
+ } : type3 == "row" ? {
41476
+ left: 0,
41477
+ top: rect.top,
41478
+ right: rect.map.width,
41479
+ bottom: rect.bottom
41480
+ } : rect
41481
+ );
41482
+ const nodes = cells.map((pos) => rect.table.nodeAt(pos));
41483
+ for (let i2 = 0; i2 < cells.length; i2++)
41484
+ if (nodes[i2].type == types.header_cell)
41485
+ tr2.setNodeMarkup(
41486
+ rect.tableStart + cells[i2],
41487
+ types.cell,
41488
+ nodes[i2].attrs
41489
+ );
41490
+ if (tr2.steps.length == 0)
41491
+ for (let i2 = 0; i2 < cells.length; i2++)
41492
+ tr2.setNodeMarkup(
41493
+ rect.tableStart + cells[i2],
41494
+ types.header_cell,
41495
+ nodes[i2].attrs
41496
+ );
41497
+ dispatch(tr2);
41498
+ }
41499
+ return true;
41500
+ };
41501
+ }
41502
+ function isHeaderEnabledByType(type3, rect, types) {
41503
+ const cellPositions = rect.map.cellsInRect({
41504
+ left: 0,
41505
+ top: 0,
41506
+ right: type3 == "row" ? rect.map.width : 1,
41507
+ bottom: type3 == "column" ? rect.map.height : 1
41508
+ });
41509
+ for (let i2 = 0; i2 < cellPositions.length; i2++) {
41510
+ const cell = rect.table.nodeAt(cellPositions[i2]);
41511
+ if (cell && cell.type !== types.header_cell) {
41512
+ return false;
41513
+ }
41514
+ }
41515
+ return true;
41516
+ }
41517
+ function toggleHeader(type3, options) {
41518
+ options = options || { useDeprecatedLogic: false };
41519
+ if (options.useDeprecatedLogic)
41520
+ return deprecated_toggleHeader(type3);
41521
+ return function(state2, dispatch) {
41522
+ if (!isInTable(state2))
41523
+ return false;
41524
+ if (dispatch) {
41525
+ const types = tableNodeTypes(state2.schema);
41526
+ const rect = selectedRect(state2), tr2 = state2.tr;
41527
+ const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types);
41528
+ const isHeaderColumnEnabled = isHeaderEnabledByType(
41529
+ "column",
41530
+ rect,
41531
+ types
41532
+ );
41533
+ const isHeaderEnabled = type3 === "column" ? isHeaderRowEnabled : type3 === "row" ? isHeaderColumnEnabled : false;
41534
+ const selectionStartsAt = isHeaderEnabled ? 1 : 0;
41535
+ const cellsRect = type3 == "column" ? {
41536
+ left: 0,
41537
+ top: selectionStartsAt,
41538
+ right: 1,
41539
+ bottom: rect.map.height
41540
+ } : type3 == "row" ? {
41541
+ left: selectionStartsAt,
41542
+ top: 0,
41543
+ right: rect.map.width,
41544
+ bottom: 1
41545
+ } : rect;
41546
+ const newType = type3 == "column" ? isHeaderColumnEnabled ? types.cell : types.header_cell : type3 == "row" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell;
41547
+ rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
41548
+ const cellPos = relativeCellPos + rect.tableStart;
41549
+ const cell = tr2.doc.nodeAt(cellPos);
41550
+ if (cell) {
41551
+ tr2.setNodeMarkup(cellPos, newType, cell.attrs);
41552
+ }
41553
+ });
41554
+ dispatch(tr2);
41555
+ }
41556
+ return true;
41557
+ };
41558
+ }
41559
+ toggleHeader("row", {
41560
+ useDeprecatedLogic: true
41561
+ });
41562
+ toggleHeader("column", {
41563
+ useDeprecatedLogic: true
41564
+ });
41565
+ var toggleHeaderCell = toggleHeader("cell", {
41566
+ useDeprecatedLogic: true
41567
+ });
41568
+ function findNextCell($cell, dir) {
41569
+ if (dir < 0) {
41570
+ const before = $cell.nodeBefore;
41571
+ if (before)
41572
+ return $cell.pos - before.nodeSize;
41573
+ for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
41574
+ const rowNode = $cell.node(-1).child(row);
41575
+ const lastChild2 = rowNode.lastChild;
41576
+ if (lastChild2) {
41577
+ return rowEnd - 1 - lastChild2.nodeSize;
41578
+ }
41579
+ rowEnd -= rowNode.nodeSize;
41580
+ }
41581
+ } else {
41582
+ if ($cell.index() < $cell.parent.childCount - 1) {
41583
+ return $cell.pos + $cell.nodeAfter.nodeSize;
41584
+ }
41585
+ const table = $cell.node(-1);
41586
+ for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
41587
+ const rowNode = table.child(row);
41588
+ if (rowNode.childCount)
41589
+ return rowStart + 1;
41590
+ rowStart += rowNode.nodeSize;
41591
+ }
41592
+ }
41593
+ return null;
41594
+ }
41595
+ function goToNextCell(direction) {
41596
+ return function(state2, dispatch) {
41597
+ if (!isInTable(state2))
41598
+ return false;
41599
+ const cell = findNextCell(selectionCell(state2), direction);
41600
+ if (cell == null)
41601
+ return false;
41602
+ if (dispatch) {
41603
+ const $cell = state2.doc.resolve(cell);
41604
+ dispatch(
41605
+ state2.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()
41606
+ );
41607
+ }
41608
+ return true;
41609
+ };
41610
+ }
41611
+ function deleteTable(state2, dispatch) {
41612
+ const $pos = state2.selection.$anchor;
41613
+ for (let d2 = $pos.depth; d2 > 0; d2--) {
41614
+ const node = $pos.node(d2);
41615
+ if (node.type.spec.tableRole == "table") {
41616
+ if (dispatch)
41617
+ dispatch(
41618
+ state2.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView()
41619
+ );
41620
+ return true;
41621
+ }
41622
+ }
41623
+ return false;
41624
+ }
41625
+ function tableEditing({
41626
+ allowTableNodeSelection = false
41627
+ } = {}) {
41628
+ return new Plugin({
41629
+ key: tableEditingKey,
41630
+ // This piece of state is used to remember when a mouse-drag
41631
+ // cell-selection is happening, so that it can continue even as
41632
+ // transactions (which might move its anchor cell) come in.
41633
+ state: {
41634
+ init() {
41635
+ return null;
41636
+ },
41637
+ apply(tr2, cur) {
41638
+ const set2 = tr2.getMeta(tableEditingKey);
41639
+ if (set2 != null)
41640
+ return set2 == -1 ? null : set2;
41641
+ if (cur == null || !tr2.docChanged)
41642
+ return cur;
41643
+ const { deleted, pos } = tr2.mapping.mapResult(cur);
41644
+ return deleted ? null : pos;
41645
+ }
41646
+ },
41647
+ props: {
41648
+ decorations: drawCellSelection,
41649
+ handleDOMEvents: {
41650
+ mousedown: handleMouseDown
41651
+ },
41652
+ createSelectionBetween(view) {
41653
+ return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
41654
+ },
41655
+ handleTripleClick,
41656
+ handleKeyDown,
41657
+ handlePaste
41658
+ },
41659
+ appendTransaction(_2, oldState, state2) {
41660
+ return normalizeSelection(
41661
+ state2,
41662
+ fixTables(state2, oldState),
41663
+ allowTableNodeSelection
41664
+ );
41665
+ }
41666
+ });
41667
+ }
41668
+ function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
41669
+ let totalWidth = 0;
41670
+ let fixedWidth = true;
41671
+ let nextDOM = colgroup.firstChild;
41672
+ const row = node.firstChild;
41673
+ for (let i2 = 0, col = 0; i2 < row.childCount; i2 += 1) {
41674
+ const { colspan, colwidth } = row.child(i2).attrs;
41675
+ for (let j = 0; j < colspan; j += 1, col += 1) {
41676
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
41677
+ const cssWidth = hasWidth ? `${hasWidth}px` : "";
41678
+ totalWidth += hasWidth || cellMinWidth;
41679
+ if (!hasWidth) {
41680
+ fixedWidth = false;
41681
+ }
41682
+ if (!nextDOM) {
41683
+ colgroup.appendChild(document.createElement("col")).style.width = cssWidth;
41684
+ } else {
41685
+ if (nextDOM.style.width !== cssWidth) {
41686
+ nextDOM.style.width = cssWidth;
41687
+ }
41688
+ nextDOM = nextDOM.nextSibling;
41689
+ }
41690
+ }
41691
+ }
41692
+ while (nextDOM) {
41693
+ const after = nextDOM.nextSibling;
41694
+ nextDOM.parentNode.removeChild(nextDOM);
41695
+ nextDOM = after;
41696
+ }
41697
+ if (fixedWidth) {
41698
+ table.style.width = `${totalWidth}px`;
41699
+ table.style.minWidth = "";
41700
+ } else {
41701
+ table.style.width = "";
41702
+ table.style.minWidth = `${totalWidth}px`;
41703
+ }
41704
+ }
41705
+ class TableView {
41706
+ constructor(node, cellMinWidth) {
41707
+ this.node = node;
41708
+ this.cellMinWidth = cellMinWidth;
41709
+ this.dom = document.createElement("div");
41710
+ this.dom.className = "tableWrapper";
41711
+ this.table = this.dom.appendChild(document.createElement("table"));
41712
+ this.colgroup = this.table.appendChild(document.createElement("colgroup"));
41713
+ updateColumns(node, this.colgroup, this.table, cellMinWidth);
41714
+ this.contentDOM = this.table.appendChild(document.createElement("tbody"));
41715
+ }
41716
+ update(node) {
41717
+ if (node.type !== this.node.type) {
41718
+ return false;
41719
+ }
41720
+ this.node = node;
41721
+ updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
41722
+ return true;
41723
+ }
41724
+ ignoreMutation(mutation) {
41725
+ return mutation.type === "attributes" && (mutation.target === this.table || this.colgroup.contains(mutation.target));
41726
+ }
41727
+ }
41728
+ function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
41729
+ let totalWidth = 0;
41730
+ let fixedWidth = true;
41731
+ const cols = [];
41732
+ const row = node.firstChild;
41733
+ if (!row) {
41734
+ return {};
41735
+ }
41736
+ for (let i2 = 0, col = 0; i2 < row.childCount; i2 += 1) {
41737
+ const { colspan, colwidth } = row.child(i2).attrs;
41738
+ for (let j = 0; j < colspan; j += 1, col += 1) {
41739
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
41740
+ const cssWidth = hasWidth ? `${hasWidth}px` : "";
41741
+ totalWidth += hasWidth || cellMinWidth;
41742
+ if (!hasWidth) {
41743
+ fixedWidth = false;
41744
+ }
41745
+ cols.push(["col", cssWidth ? { style: `width: ${cssWidth}` } : {}]);
41746
+ }
41747
+ }
41748
+ const tableWidth = fixedWidth ? `${totalWidth}px` : "";
41749
+ const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
41750
+ const colgroup = ["colgroup", {}, ...cols];
41751
+ return { colgroup, tableWidth, tableMinWidth };
41752
+ }
41753
+ function createCell(cellType, cellContent) {
41754
+ if (cellContent) {
41755
+ return cellType.createChecked(null, cellContent);
41756
+ }
41757
+ return cellType.createAndFill();
41758
+ }
41759
+ function getTableNodeTypes(schema) {
41760
+ if (schema.cached.tableNodeTypes) {
41761
+ return schema.cached.tableNodeTypes;
41762
+ }
41763
+ const roles = {};
41764
+ Object.keys(schema.nodes).forEach((type3) => {
41765
+ const nodeType = schema.nodes[type3];
41766
+ if (nodeType.spec.tableRole) {
41767
+ roles[nodeType.spec.tableRole] = nodeType;
41768
+ }
41769
+ });
41770
+ schema.cached.tableNodeTypes = roles;
41771
+ return roles;
41772
+ }
41773
+ function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
41774
+ const types = getTableNodeTypes(schema);
41775
+ const headerCells = [];
41776
+ const cells = [];
41777
+ for (let index2 = 0; index2 < colsCount; index2 += 1) {
41778
+ const cell = createCell(types.cell, cellContent);
41779
+ if (cell) {
41780
+ cells.push(cell);
41781
+ }
41782
+ if (withHeaderRow) {
41783
+ const headerCell = createCell(types.header_cell, cellContent);
41784
+ if (headerCell) {
41785
+ headerCells.push(headerCell);
41786
+ }
41787
+ }
41788
+ }
41789
+ const rows = [];
41790
+ for (let index2 = 0; index2 < rowsCount; index2 += 1) {
41791
+ rows.push(types.row.createChecked(null, withHeaderRow && index2 === 0 ? headerCells : cells));
41792
+ }
41793
+ return types.table.createChecked(null, rows);
41794
+ }
41795
+ function isCellSelection(value) {
41796
+ return value instanceof CellSelection;
41797
+ }
41798
+ const deleteTableWhenAllCellsSelected = ({ editor }) => {
41799
+ const { selection } = editor.state;
41800
+ if (!isCellSelection(selection)) {
41801
+ return false;
41802
+ }
41803
+ let cellCount = 0;
41804
+ const table = findParentNodeClosestToPos(selection.ranges[0].$from, (node) => {
41805
+ return node.type.name === "table";
41806
+ });
41807
+ table === null || table === void 0 ? void 0 : table.node.descendants((node) => {
41808
+ if (node.type.name === "table") {
41809
+ return false;
41810
+ }
41811
+ if (["tableCell", "tableHeader"].includes(node.type.name)) {
41812
+ cellCount += 1;
41813
+ }
41814
+ });
41815
+ const allCellsSelected = cellCount === selection.ranges.length;
41816
+ if (!allCellsSelected) {
41817
+ return false;
41818
+ }
41819
+ editor.commands.deleteTable();
41820
+ return true;
41821
+ };
41822
+ const Table = Node$2.create({
41823
+ name: "table",
41824
+ // @ts-ignore
41825
+ addOptions() {
41826
+ return {
41827
+ HTMLAttributes: {},
41828
+ resizable: false,
41829
+ handleWidth: 5,
41830
+ cellMinWidth: 25,
41831
+ // TODO: fix
41832
+ View: TableView,
41833
+ lastColumnResizable: true,
41834
+ allowTableNodeSelection: false
41835
+ };
41836
+ },
41837
+ content: "tableRow+",
41838
+ tableRole: "table",
41839
+ isolating: true,
41840
+ group: "block",
41841
+ parseHTML() {
41842
+ return [{ tag: "table" }];
41843
+ },
41844
+ renderHTML({ node, HTMLAttributes }) {
41845
+ const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
41846
+ const table = [
41847
+ "table",
41848
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
41849
+ style: tableWidth ? `width: ${tableWidth}` : `minWidth: ${tableMinWidth}`
41850
+ }),
41851
+ colgroup,
41852
+ ["tbody", 0]
41853
+ ];
41854
+ return table;
41855
+ },
41856
+ addCommands() {
41857
+ return {
41858
+ insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr: tr2, dispatch, editor }) => {
41859
+ const node = createTable(editor.schema, rows, cols, withHeaderRow);
41860
+ if (dispatch) {
41861
+ const offset2 = tr2.selection.anchor + 1;
41862
+ tr2.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection.near(tr2.doc.resolve(offset2)));
41863
+ }
41864
+ return true;
41865
+ },
41866
+ addColumnBefore: () => ({ state: state2, dispatch }) => {
41867
+ return addColumnBefore(state2, dispatch);
41868
+ },
41869
+ addColumnAfter: () => ({ state: state2, dispatch }) => {
41870
+ return addColumnAfter(state2, dispatch);
41871
+ },
41872
+ deleteColumn: () => ({ state: state2, dispatch }) => {
41873
+ return deleteColumn(state2, dispatch);
41874
+ },
41875
+ addRowBefore: () => ({ state: state2, dispatch }) => {
41876
+ return addRowBefore(state2, dispatch);
41877
+ },
41878
+ addRowAfter: () => ({ state: state2, dispatch }) => {
41879
+ return addRowAfter(state2, dispatch);
41880
+ },
41881
+ deleteRow: () => ({ state: state2, dispatch }) => {
41882
+ return deleteRow(state2, dispatch);
41883
+ },
41884
+ deleteTable: () => ({ state: state2, dispatch }) => {
41885
+ return deleteTable(state2, dispatch);
41886
+ },
41887
+ mergeCells: () => ({ state: state2, dispatch }) => {
41888
+ return mergeCells(state2, dispatch);
41889
+ },
41890
+ splitCell: () => ({ state: state2, dispatch }) => {
41891
+ return splitCell(state2, dispatch);
41892
+ },
41893
+ toggleHeaderColumn: () => ({ state: state2, dispatch }) => {
41894
+ return toggleHeader("column")(state2, dispatch);
41895
+ },
41896
+ toggleHeaderRow: () => ({ state: state2, dispatch }) => {
41897
+ return toggleHeader("row")(state2, dispatch);
41898
+ },
41899
+ toggleHeaderCell: () => ({ state: state2, dispatch }) => {
41900
+ return toggleHeaderCell(state2, dispatch);
41901
+ },
41902
+ mergeOrSplit: () => ({ state: state2, dispatch }) => {
41903
+ if (mergeCells(state2, dispatch)) {
41904
+ return true;
41905
+ }
41906
+ return splitCell(state2, dispatch);
41907
+ },
41908
+ setCellAttribute: (name, value) => ({ state: state2, dispatch }) => {
41909
+ return setCellAttr(name, value)(state2, dispatch);
41910
+ },
41911
+ goToNextCell: () => ({ state: state2, dispatch }) => {
41912
+ return goToNextCell(1)(state2, dispatch);
41913
+ },
41914
+ goToPreviousCell: () => ({ state: state2, dispatch }) => {
41915
+ return goToNextCell(-1)(state2, dispatch);
41916
+ },
41917
+ fixTables: () => ({ state: state2, dispatch }) => {
41918
+ if (dispatch) {
41919
+ fixTables(state2);
41920
+ }
41921
+ return true;
41922
+ },
41923
+ setCellSelection: (position) => ({ tr: tr2, dispatch }) => {
41924
+ if (dispatch) {
41925
+ const selection = CellSelection.create(tr2.doc, position.anchorCell, position.headCell);
41926
+ tr2.setSelection(selection);
41927
+ }
41928
+ return true;
41929
+ }
41930
+ };
41931
+ },
41932
+ addKeyboardShortcuts() {
41933
+ return {
41934
+ Tab: () => {
41935
+ if (this.editor.commands.goToNextCell()) {
41936
+ return true;
41937
+ }
41938
+ if (!this.editor.can().addRowAfter()) {
41939
+ return false;
41940
+ }
41941
+ return this.editor.chain().addRowAfter().goToNextCell().run();
41942
+ },
41943
+ "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
41944
+ Backspace: deleteTableWhenAllCellsSelected,
41945
+ "Mod-Backspace": deleteTableWhenAllCellsSelected,
41946
+ Delete: deleteTableWhenAllCellsSelected,
41947
+ "Mod-Delete": deleteTableWhenAllCellsSelected
41948
+ };
41949
+ },
41950
+ addProseMirrorPlugins() {
41951
+ const isResizable = this.options.resizable && this.editor.isEditable;
41952
+ return [
41953
+ ...isResizable ? [
41954
+ columnResizing({
41955
+ handleWidth: this.options.handleWidth,
41956
+ cellMinWidth: this.options.cellMinWidth,
41957
+ // @ts-ignore (incorrect type)
41958
+ View: this.options.View,
41959
+ // TODO: PR for @types/prosemirror-tables
41960
+ // @ts-ignore (incorrect type)
41961
+ lastColumnResizable: this.options.lastColumnResizable
41962
+ })
41963
+ ] : [],
41964
+ tableEditing({
41965
+ allowTableNodeSelection: this.options.allowTableNodeSelection
41966
+ })
41967
+ ];
41968
+ },
41969
+ extendNodeSchema(extension) {
41970
+ const context = {
41971
+ name: extension.name,
41972
+ options: extension.options,
41973
+ storage: extension.storage
41974
+ };
41975
+ return {
41976
+ tableRole: callOrReturn(getExtensionField(extension, "tableRole", context))
41977
+ };
41978
+ }
41979
+ });
41980
+ const TableRow = Node$2.create({
41981
+ name: "tableRow",
41982
+ addOptions() {
41983
+ return {
41984
+ HTMLAttributes: {}
41985
+ };
41986
+ },
41987
+ content: "(tableCell | tableHeader)*",
41988
+ tableRole: "row",
41989
+ parseHTML() {
41990
+ return [
41991
+ { tag: "tr" }
41992
+ ];
41993
+ },
41994
+ renderHTML({ HTMLAttributes }) {
41995
+ return ["tr", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
41996
+ }
41997
+ });
41998
+ const TableCell = Node$2.create({
41999
+ name: "tableCell",
42000
+ addOptions() {
42001
+ return {
42002
+ HTMLAttributes: {}
42003
+ };
42004
+ },
42005
+ content: "block+",
42006
+ addAttributes() {
42007
+ return {
42008
+ colspan: {
42009
+ default: 1
42010
+ },
42011
+ rowspan: {
42012
+ default: 1
42013
+ },
42014
+ colwidth: {
42015
+ default: null,
42016
+ parseHTML: (element) => {
42017
+ const colwidth = element.getAttribute("colwidth");
42018
+ const value = colwidth ? [parseInt(colwidth, 10)] : null;
42019
+ return value;
42020
+ }
42021
+ }
42022
+ };
42023
+ },
42024
+ tableRole: "cell",
42025
+ isolating: true,
42026
+ parseHTML() {
42027
+ return [
42028
+ { tag: "td" }
42029
+ ];
42030
+ },
42031
+ renderHTML({ HTMLAttributes }) {
42032
+ return ["td", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
42033
+ }
42034
+ });
42035
+ const TableHeader = Node$2.create({
42036
+ name: "tableHeader",
42037
+ addOptions() {
42038
+ return {
42039
+ HTMLAttributes: {}
42040
+ };
42041
+ },
42042
+ content: "block+",
42043
+ addAttributes() {
42044
+ return {
42045
+ colspan: {
42046
+ default: 1
42047
+ },
42048
+ rowspan: {
42049
+ default: 1
42050
+ },
42051
+ colwidth: {
42052
+ default: null,
42053
+ parseHTML: (element) => {
42054
+ const colwidth = element.getAttribute("colwidth");
42055
+ const value = colwidth ? [parseInt(colwidth, 10)] : null;
42056
+ return value;
42057
+ }
42058
+ }
42059
+ };
42060
+ },
42061
+ tableRole: "header_cell",
42062
+ isolating: true,
42063
+ parseHTML() {
42064
+ return [
42065
+ { tag: "th" }
42066
+ ];
42067
+ },
42068
+ renderHTML({ HTMLAttributes }) {
42069
+ return ["th", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
42070
+ }
42071
+ });
39445
42072
  const _hoisted_1$d = { class: "RichText" };
39446
42073
  const _hoisted_2$a = {
39447
42074
  key: 0,
@@ -39632,12 +42259,25 @@ const _sfc_main$8 = /* @__PURE__ */ vue.defineComponent({
39632
42259
  var _a2;
39633
42260
  return !((_a2 = editor.value) == null ? void 0 : _a2.can().chain().focus().redo().run());
39634
42261
  }
42262
+ },
42263
+ {
42264
+ name: "Table",
42265
+ command: () => editor.value.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
42266
+ icon: "table"
39635
42267
  }
39636
42268
  ];
39637
42269
  const emit2 = __emit;
39638
42270
  function initEditor() {
39639
42271
  editor.value = new Editor({
39640
- extensions: [StarterKit, Image, Youtube],
42272
+ extensions: [
42273
+ StarterKit,
42274
+ Image,
42275
+ Youtube,
42276
+ Table,
42277
+ TableRow,
42278
+ TableCell,
42279
+ TableHeader
42280
+ ],
39641
42281
  content: props2.modelValue,
39642
42282
  onUpdate: ({ editor: editor2 }) => emit2("update:modelValue", editor2.getHTML())
39643
42283
  });