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