@limetech/lime-elements 37.66.0 → 37.67.0

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.
Files changed (23) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +1471 -9
  3. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -1
  4. package/dist/cjs/limel-text-editor.cjs.entry.js.map +1 -1
  5. package/dist/collection/components/text-editor/prosemirror-adapter/plugins/table-plugin.js +27 -0
  6. package/dist/collection/components/text-editor/prosemirror-adapter/plugins/table-plugin.js.map +1 -0
  7. package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js +5 -0
  8. package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js.map +1 -1
  9. package/dist/collection/components/text-editor/text-editor.js +1 -0
  10. package/dist/collection/components/text-editor/text-editor.js.map +1 -1
  11. package/dist/esm/limel-prosemirror-adapter.entry.js +1471 -9
  12. package/dist/esm/limel-prosemirror-adapter.entry.js.map +1 -1
  13. package/dist/esm/limel-text-editor.entry.js.map +1 -1
  14. package/dist/lime-elements/lime-elements.esm.js +1 -1
  15. package/dist/lime-elements/p-8d388c5c.entry.js.map +1 -1
  16. package/dist/lime-elements/p-fbaa1b19.entry.js +2 -0
  17. package/dist/lime-elements/p-fbaa1b19.entry.js.map +1 -0
  18. package/dist/types/components/text-editor/prosemirror-adapter/plugins/table-plugin.d.ts +4 -0
  19. package/dist/types/components/text-editor/text-editor.d.ts +1 -0
  20. package/dist/types/components.d.ts +4 -0
  21. package/package.json +6 -1
  22. package/dist/lime-elements/p-975f1ee3.entry.js +0 -2
  23. package/dist/lime-elements/p-975f1ee3.entry.js.map +0 -1
@@ -10423,7 +10423,7 @@ function handleDoubleClick(view, pos, inside, event) {
10423
10423
  return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) ||
10424
10424
  view.someProp("handleDoubleClick", f => f(view, pos, event));
10425
10425
  }
10426
- function handleTripleClick(view, pos, inside, event) {
10426
+ function handleTripleClick$1(view, pos, inside, event) {
10427
10427
  return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) ||
10428
10428
  view.someProp("handleTripleClick", f => f(view, pos, event)) ||
10429
10429
  defaultTripleClick(view, inside, event);
@@ -10476,7 +10476,7 @@ handlers.mousedown = (view, _event) => {
10476
10476
  view.input.mouseDown.done();
10477
10477
  view.input.mouseDown = new MouseDown(view, pos, event, !!flushed);
10478
10478
  }
10479
- else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event)) {
10479
+ else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick$1)(view, pos.pos, pos.inside, event)) {
10480
10480
  event.preventDefault();
10481
10481
  }
10482
10482
  else {
@@ -15150,18 +15150,18 @@ function gapCursor() {
15150
15150
  return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null;
15151
15151
  },
15152
15152
  handleClick,
15153
- handleKeyDown,
15153
+ handleKeyDown: handleKeyDown$1,
15154
15154
  handleDOMEvents: { beforeinput: beforeinput }
15155
15155
  }
15156
15156
  });
15157
15157
  }
15158
- const handleKeyDown = keydownHandler({
15159
- "ArrowLeft": arrow("horiz", -1),
15160
- "ArrowRight": arrow("horiz", 1),
15161
- "ArrowUp": arrow("vert", -1),
15162
- "ArrowDown": arrow("vert", 1)
15158
+ const handleKeyDown$1 = keydownHandler({
15159
+ "ArrowLeft": arrow$1("horiz", -1),
15160
+ "ArrowRight": arrow$1("horiz", 1),
15161
+ "ArrowUp": arrow$1("vert", -1),
15162
+ "ArrowDown": arrow$1("vert", 1)
15163
15163
  });
15164
- function arrow(axis, dir) {
15164
+ function arrow$1(axis, dir) {
15165
15165
  const dirStr = axis == "vert" ? (dir > 0 ? "down" : "up") : (dir > 0 ? "right" : "left");
15166
15166
  return function (state, dispatch, view) {
15167
15167
  let sel = state.selection;
@@ -26316,6 +26316,1464 @@ const createTriggerPlugin = (triggerCharacters) => {
26316
26316
  });
26317
26317
  };
26318
26318
 
26319
+ // src/index.ts
26320
+
26321
+ // src/tablemap.ts
26322
+ var readFromCache;
26323
+ var addToCache;
26324
+ if (typeof WeakMap != "undefined") {
26325
+ let cache = /* @__PURE__ */ new WeakMap();
26326
+ readFromCache = (key) => cache.get(key);
26327
+ addToCache = (key, value) => {
26328
+ cache.set(key, value);
26329
+ return value;
26330
+ };
26331
+ } else {
26332
+ const cache = [];
26333
+ const cacheSize = 10;
26334
+ let cachePos = 0;
26335
+ readFromCache = (key) => {
26336
+ for (let i = 0; i < cache.length; i += 2)
26337
+ if (cache[i] == key)
26338
+ return cache[i + 1];
26339
+ };
26340
+ addToCache = (key, value) => {
26341
+ if (cachePos == cacheSize)
26342
+ cachePos = 0;
26343
+ cache[cachePos++] = key;
26344
+ return cache[cachePos++] = value;
26345
+ };
26346
+ }
26347
+ var TableMap = class {
26348
+ constructor(width, height, map, problems) {
26349
+ this.width = width;
26350
+ this.height = height;
26351
+ this.map = map;
26352
+ this.problems = problems;
26353
+ }
26354
+ // Find the dimensions of the cell at the given position.
26355
+ findCell(pos) {
26356
+ for (let i = 0; i < this.map.length; i++) {
26357
+ const curPos = this.map[i];
26358
+ if (curPos != pos)
26359
+ continue;
26360
+ const left = i % this.width;
26361
+ const top = i / this.width | 0;
26362
+ let right = left + 1;
26363
+ let bottom = top + 1;
26364
+ for (let j = 1; right < this.width && this.map[i + j] == curPos; j++) {
26365
+ right++;
26366
+ }
26367
+ for (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) {
26368
+ bottom++;
26369
+ }
26370
+ return { left, top, right, bottom };
26371
+ }
26372
+ throw new RangeError(`No cell with offset ${pos} found`);
26373
+ }
26374
+ // Find the left side of the cell at the given position.
26375
+ colCount(pos) {
26376
+ for (let i = 0; i < this.map.length; i++) {
26377
+ if (this.map[i] == pos) {
26378
+ return i % this.width;
26379
+ }
26380
+ }
26381
+ throw new RangeError(`No cell with offset ${pos} found`);
26382
+ }
26383
+ // Find the next cell in the given direction, starting from the cell
26384
+ // at `pos`, if any.
26385
+ nextCell(pos, axis, dir) {
26386
+ const { left, right, top, bottom } = this.findCell(pos);
26387
+ if (axis == "horiz") {
26388
+ if (dir < 0 ? left == 0 : right == this.width)
26389
+ return null;
26390
+ return this.map[top * this.width + (dir < 0 ? left - 1 : right)];
26391
+ } else {
26392
+ if (dir < 0 ? top == 0 : bottom == this.height)
26393
+ return null;
26394
+ return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
26395
+ }
26396
+ }
26397
+ // Get the rectangle spanning the two given cells.
26398
+ rectBetween(a, b) {
26399
+ const {
26400
+ left: leftA,
26401
+ right: rightA,
26402
+ top: topA,
26403
+ bottom: bottomA
26404
+ } = this.findCell(a);
26405
+ const {
26406
+ left: leftB,
26407
+ right: rightB,
26408
+ top: topB,
26409
+ bottom: bottomB
26410
+ } = this.findCell(b);
26411
+ return {
26412
+ left: Math.min(leftA, leftB),
26413
+ top: Math.min(topA, topB),
26414
+ right: Math.max(rightA, rightB),
26415
+ bottom: Math.max(bottomA, bottomB)
26416
+ };
26417
+ }
26418
+ // Return the position of all cells that have the top left corner in
26419
+ // the given rectangle.
26420
+ cellsInRect(rect) {
26421
+ const result = [];
26422
+ const seen = {};
26423
+ for (let row = rect.top; row < rect.bottom; row++) {
26424
+ for (let col = rect.left; col < rect.right; col++) {
26425
+ const index = row * this.width + col;
26426
+ const pos = this.map[index];
26427
+ if (seen[pos])
26428
+ continue;
26429
+ seen[pos] = true;
26430
+ if (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) {
26431
+ continue;
26432
+ }
26433
+ result.push(pos);
26434
+ }
26435
+ }
26436
+ return result;
26437
+ }
26438
+ // Return the position at which the cell at the given row and column
26439
+ // starts, or would start, if a cell started there.
26440
+ positionAt(row, col, table) {
26441
+ for (let i = 0, rowStart = 0; ; i++) {
26442
+ const rowEnd = rowStart + table.child(i).nodeSize;
26443
+ if (i == row) {
26444
+ let index = col + row * this.width;
26445
+ const rowEndIndex = (row + 1) * this.width;
26446
+ while (index < rowEndIndex && this.map[index] < rowStart)
26447
+ index++;
26448
+ return index == rowEndIndex ? rowEnd - 1 : this.map[index];
26449
+ }
26450
+ rowStart = rowEnd;
26451
+ }
26452
+ }
26453
+ // Find the table map for the given table node.
26454
+ static get(table) {
26455
+ return readFromCache(table) || addToCache(table, computeMap(table));
26456
+ }
26457
+ };
26458
+ function computeMap(table) {
26459
+ if (table.type.spec.tableRole != "table")
26460
+ throw new RangeError("Not a table node: " + table.type.name);
26461
+ const width = findWidth(table), height = table.childCount;
26462
+ const map = [];
26463
+ let mapPos = 0;
26464
+ let problems = null;
26465
+ const colWidths = [];
26466
+ for (let i = 0, e = width * height; i < e; i++)
26467
+ map[i] = 0;
26468
+ for (let row = 0, pos = 0; row < height; row++) {
26469
+ const rowNode = table.child(row);
26470
+ pos++;
26471
+ for (let i = 0; ; i++) {
26472
+ while (mapPos < map.length && map[mapPos] != 0)
26473
+ mapPos++;
26474
+ if (i == rowNode.childCount)
26475
+ break;
26476
+ const cellNode = rowNode.child(i);
26477
+ const { colspan, rowspan, colwidth } = cellNode.attrs;
26478
+ for (let h = 0; h < rowspan; h++) {
26479
+ if (h + row >= height) {
26480
+ (problems || (problems = [])).push({
26481
+ type: "overlong_rowspan",
26482
+ pos,
26483
+ n: rowspan - h
26484
+ });
26485
+ break;
26486
+ }
26487
+ const start = mapPos + h * width;
26488
+ for (let w = 0; w < colspan; w++) {
26489
+ if (map[start + w] == 0)
26490
+ map[start + w] = pos;
26491
+ else
26492
+ (problems || (problems = [])).push({
26493
+ type: "collision",
26494
+ row,
26495
+ pos,
26496
+ n: colspan - w
26497
+ });
26498
+ const colW = colwidth && colwidth[w];
26499
+ if (colW) {
26500
+ const widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex];
26501
+ if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
26502
+ colWidths[widthIndex] = colW;
26503
+ colWidths[widthIndex + 1] = 1;
26504
+ } else if (prev == colW) {
26505
+ colWidths[widthIndex + 1]++;
26506
+ }
26507
+ }
26508
+ }
26509
+ }
26510
+ mapPos += colspan;
26511
+ pos += cellNode.nodeSize;
26512
+ }
26513
+ const expectedPos = (row + 1) * width;
26514
+ let missing = 0;
26515
+ while (mapPos < expectedPos)
26516
+ if (map[mapPos++] == 0)
26517
+ missing++;
26518
+ if (missing)
26519
+ (problems || (problems = [])).push({ type: "missing", row, n: missing });
26520
+ pos++;
26521
+ }
26522
+ const tableMap = new TableMap(width, height, map, problems);
26523
+ let badWidths = false;
26524
+ for (let i = 0; !badWidths && i < colWidths.length; i += 2)
26525
+ if (colWidths[i] != null && colWidths[i + 1] < height)
26526
+ badWidths = true;
26527
+ if (badWidths)
26528
+ findBadColWidths(tableMap, colWidths, table);
26529
+ return tableMap;
26530
+ }
26531
+ function findWidth(table) {
26532
+ let width = -1;
26533
+ let hasRowSpan = false;
26534
+ for (let row = 0; row < table.childCount; row++) {
26535
+ const rowNode = table.child(row);
26536
+ let rowWidth = 0;
26537
+ if (hasRowSpan)
26538
+ for (let j = 0; j < row; j++) {
26539
+ const prevRow = table.child(j);
26540
+ for (let i = 0; i < prevRow.childCount; i++) {
26541
+ const cell = prevRow.child(i);
26542
+ if (j + cell.attrs.rowspan > row)
26543
+ rowWidth += cell.attrs.colspan;
26544
+ }
26545
+ }
26546
+ for (let i = 0; i < rowNode.childCount; i++) {
26547
+ const cell = rowNode.child(i);
26548
+ rowWidth += cell.attrs.colspan;
26549
+ if (cell.attrs.rowspan > 1)
26550
+ hasRowSpan = true;
26551
+ }
26552
+ if (width == -1)
26553
+ width = rowWidth;
26554
+ else if (width != rowWidth)
26555
+ width = Math.max(width, rowWidth);
26556
+ }
26557
+ return width;
26558
+ }
26559
+ function findBadColWidths(map, colWidths, table) {
26560
+ if (!map.problems)
26561
+ map.problems = [];
26562
+ const seen = {};
26563
+ for (let i = 0; i < map.map.length; i++) {
26564
+ const pos = map.map[i];
26565
+ if (seen[pos])
26566
+ continue;
26567
+ seen[pos] = true;
26568
+ const node = table.nodeAt(pos);
26569
+ if (!node) {
26570
+ throw new RangeError(`No cell with offset ${pos} found`);
26571
+ }
26572
+ let updated = null;
26573
+ const attrs = node.attrs;
26574
+ for (let j = 0; j < attrs.colspan; j++) {
26575
+ const col = (i + j) % map.width;
26576
+ const colWidth = colWidths[col * 2];
26577
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth))
26578
+ (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
26579
+ }
26580
+ if (updated)
26581
+ map.problems.unshift({
26582
+ type: "colwidth mismatch",
26583
+ pos,
26584
+ colwidth: updated
26585
+ });
26586
+ }
26587
+ }
26588
+ function freshColWidth(attrs) {
26589
+ if (attrs.colwidth)
26590
+ return attrs.colwidth.slice();
26591
+ const result = [];
26592
+ for (let i = 0; i < attrs.colspan; i++)
26593
+ result.push(0);
26594
+ return result;
26595
+ }
26596
+
26597
+ // src/schema.ts
26598
+ function getCellAttrs(dom, extraAttrs) {
26599
+ if (typeof dom === "string") {
26600
+ return {};
26601
+ }
26602
+ const widthAttr = dom.getAttribute("data-colwidth");
26603
+ const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(",").map((s) => Number(s)) : null;
26604
+ const colspan = Number(dom.getAttribute("colspan") || 1);
26605
+ const result = {
26606
+ colspan,
26607
+ rowspan: Number(dom.getAttribute("rowspan") || 1),
26608
+ colwidth: widths && widths.length == colspan ? widths : null
26609
+ };
26610
+ for (const prop in extraAttrs) {
26611
+ const getter = extraAttrs[prop].getFromDOM;
26612
+ const value = getter && getter(dom);
26613
+ if (value != null) {
26614
+ result[prop] = value;
26615
+ }
26616
+ }
26617
+ return result;
26618
+ }
26619
+ function setCellAttrs(node, extraAttrs) {
26620
+ const attrs = {};
26621
+ if (node.attrs.colspan != 1)
26622
+ attrs.colspan = node.attrs.colspan;
26623
+ if (node.attrs.rowspan != 1)
26624
+ attrs.rowspan = node.attrs.rowspan;
26625
+ if (node.attrs.colwidth)
26626
+ attrs["data-colwidth"] = node.attrs.colwidth.join(",");
26627
+ for (const prop in extraAttrs) {
26628
+ const setter = extraAttrs[prop].setDOMAttr;
26629
+ if (setter)
26630
+ setter(node.attrs[prop], attrs);
26631
+ }
26632
+ return attrs;
26633
+ }
26634
+ function tableNodes(options) {
26635
+ const extraAttrs = options.cellAttributes || {};
26636
+ const cellAttrs = {
26637
+ colspan: { default: 1 },
26638
+ rowspan: { default: 1 },
26639
+ colwidth: { default: null }
26640
+ };
26641
+ for (const prop in extraAttrs)
26642
+ cellAttrs[prop] = { default: extraAttrs[prop].default };
26643
+ return {
26644
+ table: {
26645
+ content: "table_row+",
26646
+ tableRole: "table",
26647
+ isolating: true,
26648
+ group: options.tableGroup,
26649
+ parseDOM: [{ tag: "table" }],
26650
+ toDOM() {
26651
+ return ["table", ["tbody", 0]];
26652
+ }
26653
+ },
26654
+ table_row: {
26655
+ content: "(table_cell | table_header)*",
26656
+ tableRole: "row",
26657
+ parseDOM: [{ tag: "tr" }],
26658
+ toDOM() {
26659
+ return ["tr", 0];
26660
+ }
26661
+ },
26662
+ table_cell: {
26663
+ content: options.cellContent,
26664
+ attrs: cellAttrs,
26665
+ tableRole: "cell",
26666
+ isolating: true,
26667
+ parseDOM: [
26668
+ { tag: "td", getAttrs: (dom) => getCellAttrs(dom, extraAttrs) }
26669
+ ],
26670
+ toDOM(node) {
26671
+ return ["td", setCellAttrs(node, extraAttrs), 0];
26672
+ }
26673
+ },
26674
+ table_header: {
26675
+ content: options.cellContent,
26676
+ attrs: cellAttrs,
26677
+ tableRole: "header_cell",
26678
+ isolating: true,
26679
+ parseDOM: [
26680
+ { tag: "th", getAttrs: (dom) => getCellAttrs(dom, extraAttrs) }
26681
+ ],
26682
+ toDOM(node) {
26683
+ return ["th", setCellAttrs(node, extraAttrs), 0];
26684
+ }
26685
+ }
26686
+ };
26687
+ }
26688
+ function tableNodeTypes(schema) {
26689
+ let result = schema.cached.tableNodeTypes;
26690
+ if (!result) {
26691
+ result = schema.cached.tableNodeTypes = {};
26692
+ for (const name in schema.nodes) {
26693
+ const type = schema.nodes[name], role = type.spec.tableRole;
26694
+ if (role)
26695
+ result[role] = type;
26696
+ }
26697
+ }
26698
+ return result;
26699
+ }
26700
+
26701
+ // src/util.ts
26702
+ var tableEditingKey = new PluginKey("selectingCells");
26703
+ function cellAround($pos) {
26704
+ for (let d = $pos.depth - 1; d > 0; d--)
26705
+ if ($pos.node(d).type.spec.tableRole == "row")
26706
+ return $pos.node(0).resolve($pos.before(d + 1));
26707
+ return null;
26708
+ }
26709
+ function isInTable(state) {
26710
+ const $head = state.selection.$head;
26711
+ for (let d = $head.depth; d > 0; d--)
26712
+ if ($head.node(d).type.spec.tableRole == "row")
26713
+ return true;
26714
+ return false;
26715
+ }
26716
+ function selectionCell(state) {
26717
+ const sel = state.selection;
26718
+ if ("$anchorCell" in sel && sel.$anchorCell) {
26719
+ return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
26720
+ } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
26721
+ return sel.$anchor;
26722
+ }
26723
+ const $cell = cellAround(sel.$head) || cellNear(sel.$head);
26724
+ if ($cell) {
26725
+ return $cell;
26726
+ }
26727
+ throw new RangeError(`No cell found around position ${sel.head}`);
26728
+ }
26729
+ function cellNear($pos) {
26730
+ for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
26731
+ const role = after.type.spec.tableRole;
26732
+ if (role == "cell" || role == "header_cell")
26733
+ return $pos.doc.resolve(pos);
26734
+ }
26735
+ for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
26736
+ const role = before.type.spec.tableRole;
26737
+ if (role == "cell" || role == "header_cell")
26738
+ return $pos.doc.resolve(pos - before.nodeSize);
26739
+ }
26740
+ }
26741
+ function pointsAtCell($pos) {
26742
+ return $pos.parent.type.spec.tableRole == "row" && !!$pos.nodeAfter;
26743
+ }
26744
+ function inSameTable($cellA, $cellB) {
26745
+ return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);
26746
+ }
26747
+ function nextCell($pos, axis, dir) {
26748
+ const table = $pos.node(-1);
26749
+ const map = TableMap.get(table);
26750
+ const tableStart = $pos.start(-1);
26751
+ const moved = map.nextCell($pos.pos - tableStart, axis, dir);
26752
+ return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
26753
+ }
26754
+ function removeColSpan(attrs, pos, n = 1) {
26755
+ const result = { ...attrs, colspan: attrs.colspan - n };
26756
+ if (result.colwidth) {
26757
+ result.colwidth = result.colwidth.slice();
26758
+ result.colwidth.splice(pos, n);
26759
+ if (!result.colwidth.some((w) => w > 0))
26760
+ result.colwidth = null;
26761
+ }
26762
+ return result;
26763
+ }
26764
+
26765
+ // src/cellselection.ts
26766
+ var CellSelection = class _CellSelection extends Selection {
26767
+ // A table selection is identified by its anchor and head cells. The
26768
+ // positions given to this constructor should point _before_ two
26769
+ // cells in the same table. They may be the same, to select a single
26770
+ // cell.
26771
+ constructor($anchorCell, $headCell = $anchorCell) {
26772
+ const table = $anchorCell.node(-1);
26773
+ const map = TableMap.get(table);
26774
+ const tableStart = $anchorCell.start(-1);
26775
+ const rect = map.rectBetween(
26776
+ $anchorCell.pos - tableStart,
26777
+ $headCell.pos - tableStart
26778
+ );
26779
+ const doc = $anchorCell.node(0);
26780
+ const cells = map.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
26781
+ cells.unshift($headCell.pos - tableStart);
26782
+ const ranges = cells.map((pos) => {
26783
+ const cell = table.nodeAt(pos);
26784
+ if (!cell) {
26785
+ throw RangeError(`No cell with offset ${pos} found`);
26786
+ }
26787
+ const from = tableStart + pos + 1;
26788
+ return new SelectionRange(
26789
+ doc.resolve(from),
26790
+ doc.resolve(from + cell.content.size)
26791
+ );
26792
+ });
26793
+ super(ranges[0].$from, ranges[0].$to, ranges);
26794
+ this.$anchorCell = $anchorCell;
26795
+ this.$headCell = $headCell;
26796
+ }
26797
+ map(doc, mapping) {
26798
+ const $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
26799
+ const $headCell = doc.resolve(mapping.map(this.$headCell.pos));
26800
+ if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
26801
+ const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
26802
+ if (tableChanged && this.isRowSelection())
26803
+ return _CellSelection.rowSelection($anchorCell, $headCell);
26804
+ else if (tableChanged && this.isColSelection())
26805
+ return _CellSelection.colSelection($anchorCell, $headCell);
26806
+ else
26807
+ return new _CellSelection($anchorCell, $headCell);
26808
+ }
26809
+ return TextSelection.between($anchorCell, $headCell);
26810
+ }
26811
+ // Returns a rectangular slice of table rows containing the selected
26812
+ // cells.
26813
+ content() {
26814
+ const table = this.$anchorCell.node(-1);
26815
+ const map = TableMap.get(table);
26816
+ const tableStart = this.$anchorCell.start(-1);
26817
+ const rect = map.rectBetween(
26818
+ this.$anchorCell.pos - tableStart,
26819
+ this.$headCell.pos - tableStart
26820
+ );
26821
+ const seen = {};
26822
+ const rows = [];
26823
+ for (let row = rect.top; row < rect.bottom; row++) {
26824
+ const rowContent = [];
26825
+ for (let index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
26826
+ const pos = map.map[index];
26827
+ if (seen[pos])
26828
+ continue;
26829
+ seen[pos] = true;
26830
+ const cellRect = map.findCell(pos);
26831
+ let cell = table.nodeAt(pos);
26832
+ if (!cell) {
26833
+ throw RangeError(`No cell with offset ${pos} found`);
26834
+ }
26835
+ const extraLeft = rect.left - cellRect.left;
26836
+ const extraRight = cellRect.right - rect.right;
26837
+ if (extraLeft > 0 || extraRight > 0) {
26838
+ let attrs = cell.attrs;
26839
+ if (extraLeft > 0) {
26840
+ attrs = removeColSpan(attrs, 0, extraLeft);
26841
+ }
26842
+ if (extraRight > 0) {
26843
+ attrs = removeColSpan(
26844
+ attrs,
26845
+ attrs.colspan - extraRight,
26846
+ extraRight
26847
+ );
26848
+ }
26849
+ if (cellRect.left < rect.left) {
26850
+ cell = cell.type.createAndFill(attrs);
26851
+ if (!cell) {
26852
+ throw RangeError(
26853
+ `Could not create cell with attrs ${JSON.stringify(attrs)}`
26854
+ );
26855
+ }
26856
+ } else {
26857
+ cell = cell.type.create(attrs, cell.content);
26858
+ }
26859
+ }
26860
+ if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
26861
+ const attrs = {
26862
+ ...cell.attrs,
26863
+ rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
26864
+ };
26865
+ if (cellRect.top < rect.top) {
26866
+ cell = cell.type.createAndFill(attrs);
26867
+ } else {
26868
+ cell = cell.type.create(attrs, cell.content);
26869
+ }
26870
+ }
26871
+ rowContent.push(cell);
26872
+ }
26873
+ rows.push(table.child(row).copy(Fragment.from(rowContent)));
26874
+ }
26875
+ const fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
26876
+ return new Slice(Fragment.from(fragment), 1, 1);
26877
+ }
26878
+ replace(tr, content = Slice.empty) {
26879
+ const mapFrom = tr.steps.length, ranges = this.ranges;
26880
+ for (let i = 0; i < ranges.length; i++) {
26881
+ const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
26882
+ tr.replace(
26883
+ mapping.map($from.pos),
26884
+ mapping.map($to.pos),
26885
+ i ? Slice.empty : content
26886
+ );
26887
+ }
26888
+ const sel = Selection.findFrom(
26889
+ tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
26890
+ -1
26891
+ );
26892
+ if (sel)
26893
+ tr.setSelection(sel);
26894
+ }
26895
+ replaceWith(tr, node) {
26896
+ this.replace(tr, new Slice(Fragment.from(node), 0, 0));
26897
+ }
26898
+ forEachCell(f) {
26899
+ const table = this.$anchorCell.node(-1);
26900
+ const map = TableMap.get(table);
26901
+ const tableStart = this.$anchorCell.start(-1);
26902
+ const cells = map.cellsInRect(
26903
+ map.rectBetween(
26904
+ this.$anchorCell.pos - tableStart,
26905
+ this.$headCell.pos - tableStart
26906
+ )
26907
+ );
26908
+ for (let i = 0; i < cells.length; i++) {
26909
+ f(table.nodeAt(cells[i]), tableStart + cells[i]);
26910
+ }
26911
+ }
26912
+ // True if this selection goes all the way from the top to the
26913
+ // bottom of the table.
26914
+ isColSelection() {
26915
+ const anchorTop = this.$anchorCell.index(-1);
26916
+ const headTop = this.$headCell.index(-1);
26917
+ if (Math.min(anchorTop, headTop) > 0)
26918
+ return false;
26919
+ const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
26920
+ const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
26921
+ return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
26922
+ }
26923
+ // Returns the smallest column selection that covers the given anchor
26924
+ // and head cell.
26925
+ static colSelection($anchorCell, $headCell = $anchorCell) {
26926
+ const table = $anchorCell.node(-1);
26927
+ const map = TableMap.get(table);
26928
+ const tableStart = $anchorCell.start(-1);
26929
+ const anchorRect = map.findCell($anchorCell.pos - tableStart);
26930
+ const headRect = map.findCell($headCell.pos - tableStart);
26931
+ const doc = $anchorCell.node(0);
26932
+ if (anchorRect.top <= headRect.top) {
26933
+ if (anchorRect.top > 0)
26934
+ $anchorCell = doc.resolve(tableStart + map.map[anchorRect.left]);
26935
+ if (headRect.bottom < map.height)
26936
+ $headCell = doc.resolve(
26937
+ tableStart + map.map[map.width * (map.height - 1) + headRect.right - 1]
26938
+ );
26939
+ } else {
26940
+ if (headRect.top > 0)
26941
+ $headCell = doc.resolve(tableStart + map.map[headRect.left]);
26942
+ if (anchorRect.bottom < map.height)
26943
+ $anchorCell = doc.resolve(
26944
+ tableStart + map.map[map.width * (map.height - 1) + anchorRect.right - 1]
26945
+ );
26946
+ }
26947
+ return new _CellSelection($anchorCell, $headCell);
26948
+ }
26949
+ // True if this selection goes all the way from the left to the
26950
+ // right of the table.
26951
+ isRowSelection() {
26952
+ const table = this.$anchorCell.node(-1);
26953
+ const map = TableMap.get(table);
26954
+ const tableStart = this.$anchorCell.start(-1);
26955
+ const anchorLeft = map.colCount(this.$anchorCell.pos - tableStart);
26956
+ const headLeft = map.colCount(this.$headCell.pos - tableStart);
26957
+ if (Math.min(anchorLeft, headLeft) > 0)
26958
+ return false;
26959
+ const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
26960
+ const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
26961
+ return Math.max(anchorRight, headRight) == map.width;
26962
+ }
26963
+ eq(other) {
26964
+ return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
26965
+ }
26966
+ // Returns the smallest row selection that covers the given anchor
26967
+ // and head cell.
26968
+ static rowSelection($anchorCell, $headCell = $anchorCell) {
26969
+ const table = $anchorCell.node(-1);
26970
+ const map = TableMap.get(table);
26971
+ const tableStart = $anchorCell.start(-1);
26972
+ const anchorRect = map.findCell($anchorCell.pos - tableStart);
26973
+ const headRect = map.findCell($headCell.pos - tableStart);
26974
+ const doc = $anchorCell.node(0);
26975
+ if (anchorRect.left <= headRect.left) {
26976
+ if (anchorRect.left > 0)
26977
+ $anchorCell = doc.resolve(
26978
+ tableStart + map.map[anchorRect.top * map.width]
26979
+ );
26980
+ if (headRect.right < map.width)
26981
+ $headCell = doc.resolve(
26982
+ tableStart + map.map[map.width * (headRect.top + 1) - 1]
26983
+ );
26984
+ } else {
26985
+ if (headRect.left > 0)
26986
+ $headCell = doc.resolve(tableStart + map.map[headRect.top * map.width]);
26987
+ if (anchorRect.right < map.width)
26988
+ $anchorCell = doc.resolve(
26989
+ tableStart + map.map[map.width * (anchorRect.top + 1) - 1]
26990
+ );
26991
+ }
26992
+ return new _CellSelection($anchorCell, $headCell);
26993
+ }
26994
+ toJSON() {
26995
+ return {
26996
+ type: "cell",
26997
+ anchor: this.$anchorCell.pos,
26998
+ head: this.$headCell.pos
26999
+ };
27000
+ }
27001
+ static fromJSON(doc, json) {
27002
+ return new _CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
27003
+ }
27004
+ static create(doc, anchorCell, headCell = anchorCell) {
27005
+ return new _CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
27006
+ }
27007
+ getBookmark() {
27008
+ return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
27009
+ }
27010
+ };
27011
+ CellSelection.prototype.visible = false;
27012
+ Selection.jsonID("cell", CellSelection);
27013
+ var CellBookmark = class _CellBookmark {
27014
+ constructor(anchor, head) {
27015
+ this.anchor = anchor;
27016
+ this.head = head;
27017
+ }
27018
+ map(mapping) {
27019
+ return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
27020
+ }
27021
+ resolve(doc) {
27022
+ const $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);
27023
+ 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))
27024
+ return new CellSelection($anchorCell, $headCell);
27025
+ else
27026
+ return Selection.near($headCell, 1);
27027
+ }
27028
+ };
27029
+ function drawCellSelection(state) {
27030
+ if (!(state.selection instanceof CellSelection))
27031
+ return null;
27032
+ const cells = [];
27033
+ state.selection.forEachCell((node, pos) => {
27034
+ cells.push(
27035
+ Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
27036
+ );
27037
+ });
27038
+ return DecorationSet.create(state.doc, cells);
27039
+ }
27040
+ function isCellBoundarySelection({ $from, $to }) {
27041
+ if ($from.pos == $to.pos || $from.pos < $from.pos - 6)
27042
+ return false;
27043
+ let afterFrom = $from.pos;
27044
+ let beforeTo = $to.pos;
27045
+ let depth = $from.depth;
27046
+ for (; depth >= 0; depth--, afterFrom++)
27047
+ if ($from.after(depth + 1) < $from.end(depth))
27048
+ break;
27049
+ for (let d = $to.depth; d >= 0; d--, beforeTo--)
27050
+ if ($to.before(d + 1) > $to.start(d))
27051
+ break;
27052
+ return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
27053
+ }
27054
+ function isTextSelectionAcrossCells({ $from, $to }) {
27055
+ let fromCellBoundaryNode;
27056
+ let toCellBoundaryNode;
27057
+ for (let i = $from.depth; i > 0; i--) {
27058
+ const node = $from.node(i);
27059
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
27060
+ fromCellBoundaryNode = node;
27061
+ break;
27062
+ }
27063
+ }
27064
+ for (let i = $to.depth; i > 0; i--) {
27065
+ const node = $to.node(i);
27066
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
27067
+ toCellBoundaryNode = node;
27068
+ break;
27069
+ }
27070
+ }
27071
+ return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
27072
+ }
27073
+ function normalizeSelection(state, tr, allowTableNodeSelection) {
27074
+ const sel = (tr || state).selection;
27075
+ const doc = (tr || state).doc;
27076
+ let normalize;
27077
+ let role;
27078
+ if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
27079
+ if (role == "cell" || role == "header_cell") {
27080
+ normalize = CellSelection.create(doc, sel.from);
27081
+ } else if (role == "row") {
27082
+ const $cell = doc.resolve(sel.from + 1);
27083
+ normalize = CellSelection.rowSelection($cell, $cell);
27084
+ } else if (!allowTableNodeSelection) {
27085
+ const map = TableMap.get(sel.node);
27086
+ const start = sel.from + 1;
27087
+ const lastCell = start + map.map[map.width * map.height - 1];
27088
+ normalize = CellSelection.create(doc, start + 1, lastCell);
27089
+ }
27090
+ } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
27091
+ normalize = TextSelection.create(doc, sel.from);
27092
+ } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
27093
+ normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
27094
+ }
27095
+ if (normalize)
27096
+ (tr || (tr = state.tr)).setSelection(normalize);
27097
+ return tr;
27098
+ }
27099
+ var fixTablesKey = new PluginKey("fix-tables");
27100
+ function changedDescendants(old, cur, offset, f) {
27101
+ const oldSize = old.childCount, curSize = cur.childCount;
27102
+ outer:
27103
+ for (let i = 0, j = 0; i < curSize; i++) {
27104
+ const child = cur.child(i);
27105
+ for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
27106
+ if (old.child(scan) == child) {
27107
+ j = scan + 1;
27108
+ offset += child.nodeSize;
27109
+ continue outer;
27110
+ }
27111
+ }
27112
+ f(child, offset);
27113
+ if (j < oldSize && old.child(j).sameMarkup(child))
27114
+ changedDescendants(old.child(j), child, offset + 1, f);
27115
+ else
27116
+ child.nodesBetween(0, child.content.size, f, offset + 1);
27117
+ offset += child.nodeSize;
27118
+ }
27119
+ }
27120
+ function fixTables(state, oldState) {
27121
+ let tr;
27122
+ const check = (node, pos) => {
27123
+ if (node.type.spec.tableRole == "table")
27124
+ tr = fixTable(state, node, pos, tr);
27125
+ };
27126
+ if (!oldState)
27127
+ state.doc.descendants(check);
27128
+ else if (oldState.doc != state.doc)
27129
+ changedDescendants(oldState.doc, state.doc, 0, check);
27130
+ return tr;
27131
+ }
27132
+ function fixTable(state, table, tablePos, tr) {
27133
+ const map = TableMap.get(table);
27134
+ if (!map.problems)
27135
+ return tr;
27136
+ if (!tr)
27137
+ tr = state.tr;
27138
+ const mustAdd = [];
27139
+ for (let i = 0; i < map.height; i++)
27140
+ mustAdd.push(0);
27141
+ for (let i = 0; i < map.problems.length; i++) {
27142
+ const prob = map.problems[i];
27143
+ if (prob.type == "collision") {
27144
+ const cell = table.nodeAt(prob.pos);
27145
+ if (!cell)
27146
+ continue;
27147
+ const attrs = cell.attrs;
27148
+ for (let j = 0; j < attrs.rowspan; j++)
27149
+ mustAdd[prob.row + j] += prob.n;
27150
+ tr.setNodeMarkup(
27151
+ tr.mapping.map(tablePos + 1 + prob.pos),
27152
+ null,
27153
+ removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
27154
+ );
27155
+ } else if (prob.type == "missing") {
27156
+ mustAdd[prob.row] += prob.n;
27157
+ } else if (prob.type == "overlong_rowspan") {
27158
+ const cell = table.nodeAt(prob.pos);
27159
+ if (!cell)
27160
+ continue;
27161
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
27162
+ ...cell.attrs,
27163
+ rowspan: cell.attrs.rowspan - prob.n
27164
+ });
27165
+ } else if (prob.type == "colwidth mismatch") {
27166
+ const cell = table.nodeAt(prob.pos);
27167
+ if (!cell)
27168
+ continue;
27169
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
27170
+ ...cell.attrs,
27171
+ colwidth: prob.colwidth
27172
+ });
27173
+ }
27174
+ }
27175
+ let first, last;
27176
+ for (let i = 0; i < mustAdd.length; i++)
27177
+ if (mustAdd[i]) {
27178
+ if (first == null)
27179
+ first = i;
27180
+ last = i;
27181
+ }
27182
+ for (let i = 0, pos = tablePos + 1; i < map.height; i++) {
27183
+ const row = table.child(i);
27184
+ const end = pos + row.nodeSize;
27185
+ const add = mustAdd[i];
27186
+ if (add > 0) {
27187
+ let role = "cell";
27188
+ if (row.firstChild) {
27189
+ role = row.firstChild.type.spec.tableRole;
27190
+ }
27191
+ const nodes = [];
27192
+ for (let j = 0; j < add; j++) {
27193
+ const node = tableNodeTypes(state.schema)[role].createAndFill();
27194
+ if (node)
27195
+ nodes.push(node);
27196
+ }
27197
+ const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;
27198
+ tr.insert(tr.mapping.map(side), nodes);
27199
+ }
27200
+ pos = end;
27201
+ }
27202
+ return tr.setMeta(fixTablesKey, { fixTables: true });
27203
+ }
27204
+ function deleteCellSelection(state, dispatch) {
27205
+ const sel = state.selection;
27206
+ if (!(sel instanceof CellSelection))
27207
+ return false;
27208
+ if (dispatch) {
27209
+ const tr = state.tr;
27210
+ const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
27211
+ sel.forEachCell((cell, pos) => {
27212
+ if (!cell.content.eq(baseContent))
27213
+ tr.replace(
27214
+ tr.mapping.map(pos + 1),
27215
+ tr.mapping.map(pos + cell.nodeSize - 1),
27216
+ new Slice(baseContent, 0, 0)
27217
+ );
27218
+ });
27219
+ if (tr.docChanged)
27220
+ dispatch(tr);
27221
+ }
27222
+ return true;
27223
+ }
27224
+ function pastedCells(slice) {
27225
+ if (!slice.size)
27226
+ return null;
27227
+ let { content, openStart, openEnd } = slice;
27228
+ while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
27229
+ openStart--;
27230
+ openEnd--;
27231
+ content = content.child(0).content;
27232
+ }
27233
+ const first = content.child(0);
27234
+ const role = first.type.spec.tableRole;
27235
+ const schema = first.type.schema, rows = [];
27236
+ if (role == "row") {
27237
+ for (let i = 0; i < content.childCount; i++) {
27238
+ let cells = content.child(i).content;
27239
+ const left = i ? 0 : Math.max(0, openStart - 1);
27240
+ const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
27241
+ if (left || right)
27242
+ cells = fitSlice(
27243
+ tableNodeTypes(schema).row,
27244
+ new Slice(cells, left, right)
27245
+ ).content;
27246
+ rows.push(cells);
27247
+ }
27248
+ } else if (role == "cell" || role == "header_cell") {
27249
+ rows.push(
27250
+ openStart || openEnd ? fitSlice(
27251
+ tableNodeTypes(schema).row,
27252
+ new Slice(content, openStart, openEnd)
27253
+ ).content : content
27254
+ );
27255
+ } else {
27256
+ return null;
27257
+ }
27258
+ return ensureRectangular(schema, rows);
27259
+ }
27260
+ function ensureRectangular(schema, rows) {
27261
+ const widths = [];
27262
+ for (let i = 0; i < rows.length; i++) {
27263
+ const row = rows[i];
27264
+ for (let j = row.childCount - 1; j >= 0; j--) {
27265
+ const { rowspan, colspan } = row.child(j).attrs;
27266
+ for (let r = i; r < i + rowspan; r++)
27267
+ widths[r] = (widths[r] || 0) + colspan;
27268
+ }
27269
+ }
27270
+ let width = 0;
27271
+ for (let r = 0; r < widths.length; r++)
27272
+ width = Math.max(width, widths[r]);
27273
+ for (let r = 0; r < widths.length; r++) {
27274
+ if (r >= rows.length)
27275
+ rows.push(Fragment.empty);
27276
+ if (widths[r] < width) {
27277
+ const empty = tableNodeTypes(schema).cell.createAndFill();
27278
+ const cells = [];
27279
+ for (let i = widths[r]; i < width; i++) {
27280
+ cells.push(empty);
27281
+ }
27282
+ rows[r] = rows[r].append(Fragment.from(cells));
27283
+ }
27284
+ }
27285
+ return { height: rows.length, width, rows };
27286
+ }
27287
+ function fitSlice(nodeType, slice) {
27288
+ const node = nodeType.createAndFill();
27289
+ const tr = new Transform(node).replace(0, node.content.size, slice);
27290
+ return tr.doc;
27291
+ }
27292
+ function clipCells({ width, height, rows }, newWidth, newHeight) {
27293
+ if (width != newWidth) {
27294
+ const added = [];
27295
+ const newRows = [];
27296
+ for (let row = 0; row < rows.length; row++) {
27297
+ const frag = rows[row], cells = [];
27298
+ for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
27299
+ let cell = frag.child(i % frag.childCount);
27300
+ if (col + cell.attrs.colspan > newWidth)
27301
+ cell = cell.type.createChecked(
27302
+ removeColSpan(
27303
+ cell.attrs,
27304
+ cell.attrs.colspan,
27305
+ col + cell.attrs.colspan - newWidth
27306
+ ),
27307
+ cell.content
27308
+ );
27309
+ cells.push(cell);
27310
+ col += cell.attrs.colspan;
27311
+ for (let j = 1; j < cell.attrs.rowspan; j++)
27312
+ added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
27313
+ }
27314
+ newRows.push(Fragment.from(cells));
27315
+ }
27316
+ rows = newRows;
27317
+ width = newWidth;
27318
+ }
27319
+ if (height != newHeight) {
27320
+ const newRows = [];
27321
+ for (let row = 0, i = 0; row < newHeight; row++, i++) {
27322
+ const cells = [], source = rows[i % height];
27323
+ for (let j = 0; j < source.childCount; j++) {
27324
+ let cell = source.child(j);
27325
+ if (row + cell.attrs.rowspan > newHeight)
27326
+ cell = cell.type.create(
27327
+ {
27328
+ ...cell.attrs,
27329
+ rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
27330
+ },
27331
+ cell.content
27332
+ );
27333
+ cells.push(cell);
27334
+ }
27335
+ newRows.push(Fragment.from(cells));
27336
+ }
27337
+ rows = newRows;
27338
+ height = newHeight;
27339
+ }
27340
+ return { width, height, rows };
27341
+ }
27342
+ function growTable(tr, map, table, start, width, height, mapFrom) {
27343
+ const schema = tr.doc.type.schema;
27344
+ const types = tableNodeTypes(schema);
27345
+ let empty;
27346
+ let emptyHead;
27347
+ if (width > map.width) {
27348
+ for (let row = 0, rowEnd = 0; row < map.height; row++) {
27349
+ const rowNode = table.child(row);
27350
+ rowEnd += rowNode.nodeSize;
27351
+ const cells = [];
27352
+ let add;
27353
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)
27354
+ add = empty || (empty = types.cell.createAndFill());
27355
+ else
27356
+ add = emptyHead || (emptyHead = types.header_cell.createAndFill());
27357
+ for (let i = map.width; i < width; i++)
27358
+ cells.push(add);
27359
+ tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);
27360
+ }
27361
+ }
27362
+ if (height > map.height) {
27363
+ const cells = [];
27364
+ for (let i = 0, start2 = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {
27365
+ const header = i >= map.width ? false : table.nodeAt(map.map[start2 + i]).type == types.header_cell;
27366
+ cells.push(
27367
+ header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill())
27368
+ );
27369
+ }
27370
+ const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
27371
+ for (let i = map.height; i < height; i++)
27372
+ rows.push(emptyRow);
27373
+ tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);
27374
+ }
27375
+ return !!(empty || emptyHead);
27376
+ }
27377
+ function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
27378
+ if (top == 0 || top == map.height)
27379
+ return false;
27380
+ let found = false;
27381
+ for (let col = left; col < right; col++) {
27382
+ const index = top * map.width + col, pos = map.map[index];
27383
+ if (map.map[index - map.width] == pos) {
27384
+ found = true;
27385
+ const cell = table.nodeAt(pos);
27386
+ const { top: cellTop, left: cellLeft } = map.findCell(pos);
27387
+ tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, {
27388
+ ...cell.attrs,
27389
+ rowspan: top - cellTop
27390
+ });
27391
+ tr.insert(
27392
+ tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)),
27393
+ cell.type.createAndFill({
27394
+ ...cell.attrs,
27395
+ rowspan: cellTop + cell.attrs.rowspan - top
27396
+ })
27397
+ );
27398
+ col += cell.attrs.colspan - 1;
27399
+ }
27400
+ }
27401
+ return found;
27402
+ }
27403
+ function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
27404
+ if (left == 0 || left == map.width)
27405
+ return false;
27406
+ let found = false;
27407
+ for (let row = top; row < bottom; row++) {
27408
+ const index = row * map.width + left, pos = map.map[index];
27409
+ if (map.map[index - 1] == pos) {
27410
+ found = true;
27411
+ const cell = table.nodeAt(pos);
27412
+ const cellLeft = map.colCount(pos);
27413
+ const updatePos = tr.mapping.slice(mapFrom).map(pos + start);
27414
+ tr.setNodeMarkup(
27415
+ updatePos,
27416
+ null,
27417
+ removeColSpan(
27418
+ cell.attrs,
27419
+ left - cellLeft,
27420
+ cell.attrs.colspan - (left - cellLeft)
27421
+ )
27422
+ );
27423
+ tr.insert(
27424
+ updatePos + cell.nodeSize,
27425
+ cell.type.createAndFill(
27426
+ removeColSpan(cell.attrs, 0, left - cellLeft)
27427
+ )
27428
+ );
27429
+ row += cell.attrs.rowspan - 1;
27430
+ }
27431
+ }
27432
+ return found;
27433
+ }
27434
+ function insertCells(state, dispatch, tableStart, rect, cells) {
27435
+ let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
27436
+ if (!table) {
27437
+ throw new Error("No table found");
27438
+ }
27439
+ let map = TableMap.get(table);
27440
+ const { top, left } = rect;
27441
+ const right = left + cells.width, bottom = top + cells.height;
27442
+ const tr = state.tr;
27443
+ let mapFrom = 0;
27444
+ function recomp() {
27445
+ table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
27446
+ if (!table) {
27447
+ throw new Error("No table found");
27448
+ }
27449
+ map = TableMap.get(table);
27450
+ mapFrom = tr.mapping.maps.length;
27451
+ }
27452
+ if (growTable(tr, map, table, tableStart, right, bottom, mapFrom))
27453
+ recomp();
27454
+ if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom))
27455
+ recomp();
27456
+ if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom))
27457
+ recomp();
27458
+ if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom))
27459
+ recomp();
27460
+ if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom))
27461
+ recomp();
27462
+ for (let row = top; row < bottom; row++) {
27463
+ const from = map.positionAt(row, left, table), to = map.positionAt(row, right, table);
27464
+ tr.replace(
27465
+ tr.mapping.slice(mapFrom).map(from + tableStart),
27466
+ tr.mapping.slice(mapFrom).map(to + tableStart),
27467
+ new Slice(cells.rows[row - top], 0, 0)
27468
+ );
27469
+ }
27470
+ recomp();
27471
+ tr.setSelection(
27472
+ new CellSelection(
27473
+ tr.doc.resolve(tableStart + map.positionAt(top, left, table)),
27474
+ tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table))
27475
+ )
27476
+ );
27477
+ dispatch(tr);
27478
+ }
27479
+
27480
+ // src/input.ts
27481
+ var handleKeyDown = keydownHandler({
27482
+ ArrowLeft: arrow("horiz", -1),
27483
+ ArrowRight: arrow("horiz", 1),
27484
+ ArrowUp: arrow("vert", -1),
27485
+ ArrowDown: arrow("vert", 1),
27486
+ "Shift-ArrowLeft": shiftArrow("horiz", -1),
27487
+ "Shift-ArrowRight": shiftArrow("horiz", 1),
27488
+ "Shift-ArrowUp": shiftArrow("vert", -1),
27489
+ "Shift-ArrowDown": shiftArrow("vert", 1),
27490
+ Backspace: deleteCellSelection,
27491
+ "Mod-Backspace": deleteCellSelection,
27492
+ Delete: deleteCellSelection,
27493
+ "Mod-Delete": deleteCellSelection
27494
+ });
27495
+ function maybeSetSelection(state, dispatch, selection) {
27496
+ if (selection.eq(state.selection))
27497
+ return false;
27498
+ if (dispatch)
27499
+ dispatch(state.tr.setSelection(selection).scrollIntoView());
27500
+ return true;
27501
+ }
27502
+ function arrow(axis, dir) {
27503
+ return (state, dispatch, view) => {
27504
+ if (!view)
27505
+ return false;
27506
+ const sel = state.selection;
27507
+ if (sel instanceof CellSelection) {
27508
+ return maybeSetSelection(
27509
+ state,
27510
+ dispatch,
27511
+ Selection.near(sel.$headCell, dir)
27512
+ );
27513
+ }
27514
+ if (axis != "horiz" && !sel.empty)
27515
+ return false;
27516
+ const end = atEndOfCell(view, axis, dir);
27517
+ if (end == null)
27518
+ return false;
27519
+ if (axis == "horiz") {
27520
+ return maybeSetSelection(
27521
+ state,
27522
+ dispatch,
27523
+ Selection.near(state.doc.resolve(sel.head + dir), dir)
27524
+ );
27525
+ } else {
27526
+ const $cell = state.doc.resolve(end);
27527
+ const $next = nextCell($cell, axis, dir);
27528
+ let newSel;
27529
+ if ($next)
27530
+ newSel = Selection.near($next, 1);
27531
+ else if (dir < 0)
27532
+ newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
27533
+ else
27534
+ newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
27535
+ return maybeSetSelection(state, dispatch, newSel);
27536
+ }
27537
+ };
27538
+ }
27539
+ function shiftArrow(axis, dir) {
27540
+ return (state, dispatch, view) => {
27541
+ if (!view)
27542
+ return false;
27543
+ const sel = state.selection;
27544
+ let cellSel;
27545
+ if (sel instanceof CellSelection) {
27546
+ cellSel = sel;
27547
+ } else {
27548
+ const end = atEndOfCell(view, axis, dir);
27549
+ if (end == null)
27550
+ return false;
27551
+ cellSel = new CellSelection(state.doc.resolve(end));
27552
+ }
27553
+ const $head = nextCell(cellSel.$headCell, axis, dir);
27554
+ if (!$head)
27555
+ return false;
27556
+ return maybeSetSelection(
27557
+ state,
27558
+ dispatch,
27559
+ new CellSelection(cellSel.$anchorCell, $head)
27560
+ );
27561
+ };
27562
+ }
27563
+ function handleTripleClick(view, pos) {
27564
+ const doc = view.state.doc, $cell = cellAround(doc.resolve(pos));
27565
+ if (!$cell)
27566
+ return false;
27567
+ view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
27568
+ return true;
27569
+ }
27570
+ function handlePaste(view, _, slice) {
27571
+ if (!isInTable(view.state))
27572
+ return false;
27573
+ let cells = pastedCells(slice);
27574
+ const sel = view.state.selection;
27575
+ if (sel instanceof CellSelection) {
27576
+ if (!cells)
27577
+ cells = {
27578
+ width: 1,
27579
+ height: 1,
27580
+ rows: [
27581
+ Fragment.from(
27582
+ fitSlice(tableNodeTypes(view.state.schema).cell, slice)
27583
+ )
27584
+ ]
27585
+ };
27586
+ const table = sel.$anchorCell.node(-1);
27587
+ const start = sel.$anchorCell.start(-1);
27588
+ const rect = TableMap.get(table).rectBetween(
27589
+ sel.$anchorCell.pos - start,
27590
+ sel.$headCell.pos - start
27591
+ );
27592
+ cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
27593
+ insertCells(view.state, view.dispatch, start, rect, cells);
27594
+ return true;
27595
+ } else if (cells) {
27596
+ const $cell = selectionCell(view.state);
27597
+ const start = $cell.start(-1);
27598
+ insertCells(
27599
+ view.state,
27600
+ view.dispatch,
27601
+ start,
27602
+ TableMap.get($cell.node(-1)).findCell($cell.pos - start),
27603
+ cells
27604
+ );
27605
+ return true;
27606
+ } else {
27607
+ return false;
27608
+ }
27609
+ }
27610
+ function handleMouseDown(view, startEvent) {
27611
+ var _a;
27612
+ if (startEvent.ctrlKey || startEvent.metaKey)
27613
+ return;
27614
+ const startDOMCell = domInCell(view, startEvent.target);
27615
+ let $anchor;
27616
+ if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
27617
+ setCellSelection(view.state.selection.$anchorCell, startEvent);
27618
+ startEvent.preventDefault();
27619
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
27620
+ setCellSelection($anchor, startEvent);
27621
+ startEvent.preventDefault();
27622
+ } else if (!startDOMCell) {
27623
+ return;
27624
+ }
27625
+ function setCellSelection($anchor2, event) {
27626
+ let $head = cellUnderMouse(view, event);
27627
+ const starting = tableEditingKey.getState(view.state) == null;
27628
+ if (!$head || !inSameTable($anchor2, $head)) {
27629
+ if (starting)
27630
+ $head = $anchor2;
27631
+ else
27632
+ return;
27633
+ }
27634
+ const selection = new CellSelection($anchor2, $head);
27635
+ if (starting || !view.state.selection.eq(selection)) {
27636
+ const tr = view.state.tr.setSelection(selection);
27637
+ if (starting)
27638
+ tr.setMeta(tableEditingKey, $anchor2.pos);
27639
+ view.dispatch(tr);
27640
+ }
27641
+ }
27642
+ function stop() {
27643
+ view.root.removeEventListener("mouseup", stop);
27644
+ view.root.removeEventListener("dragstart", stop);
27645
+ view.root.removeEventListener("mousemove", move);
27646
+ if (tableEditingKey.getState(view.state) != null)
27647
+ view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
27648
+ }
27649
+ function move(_event) {
27650
+ const event = _event;
27651
+ const anchor = tableEditingKey.getState(view.state);
27652
+ let $anchor2;
27653
+ if (anchor != null) {
27654
+ $anchor2 = view.state.doc.resolve(anchor);
27655
+ } else if (domInCell(view, event.target) != startDOMCell) {
27656
+ $anchor2 = cellUnderMouse(view, startEvent);
27657
+ if (!$anchor2)
27658
+ return stop();
27659
+ }
27660
+ if ($anchor2)
27661
+ setCellSelection($anchor2, event);
27662
+ }
27663
+ view.root.addEventListener("mouseup", stop);
27664
+ view.root.addEventListener("dragstart", stop);
27665
+ view.root.addEventListener("mousemove", move);
27666
+ }
27667
+ function atEndOfCell(view, axis, dir) {
27668
+ if (!(view.state.selection instanceof TextSelection))
27669
+ return null;
27670
+ const { $head } = view.state.selection;
27671
+ for (let d = $head.depth - 1; d >= 0; d--) {
27672
+ const parent = $head.node(d), index = dir < 0 ? $head.index(d) : $head.indexAfter(d);
27673
+ if (index != (dir < 0 ? 0 : parent.childCount))
27674
+ return null;
27675
+ if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
27676
+ const cellPos = $head.before(d);
27677
+ const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
27678
+ return view.endOfTextblock(dirStr) ? cellPos : null;
27679
+ }
27680
+ }
27681
+ return null;
27682
+ }
27683
+ function domInCell(view, dom) {
27684
+ for (; dom && dom != view.dom; dom = dom.parentNode) {
27685
+ if (dom.nodeName == "TD" || dom.nodeName == "TH") {
27686
+ return dom;
27687
+ }
27688
+ }
27689
+ return null;
27690
+ }
27691
+ function cellUnderMouse(view, event) {
27692
+ const mousePos = view.posAtCoords({
27693
+ left: event.clientX,
27694
+ top: event.clientY
27695
+ });
27696
+ if (!mousePos)
27697
+ return null;
27698
+ return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
27699
+ }
27700
+
27701
+ // src/columnresizing.ts
27702
+ new PluginKey(
27703
+ "tableColumnResizing"
27704
+ );
27705
+
27706
+ // src/index.ts
27707
+ function tableEditing({
27708
+ allowTableNodeSelection = false
27709
+ } = {}) {
27710
+ return new Plugin({
27711
+ key: tableEditingKey,
27712
+ // This piece of state is used to remember when a mouse-drag
27713
+ // cell-selection is happening, so that it can continue even as
27714
+ // transactions (which might move its anchor cell) come in.
27715
+ state: {
27716
+ init() {
27717
+ return null;
27718
+ },
27719
+ apply(tr, cur) {
27720
+ const set = tr.getMeta(tableEditingKey);
27721
+ if (set != null)
27722
+ return set == -1 ? null : set;
27723
+ if (cur == null || !tr.docChanged)
27724
+ return cur;
27725
+ const { deleted, pos } = tr.mapping.mapResult(cur);
27726
+ return deleted ? null : pos;
27727
+ }
27728
+ },
27729
+ props: {
27730
+ decorations: drawCellSelection,
27731
+ handleDOMEvents: {
27732
+ mousedown: handleMouseDown
27733
+ },
27734
+ createSelectionBetween(view) {
27735
+ return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
27736
+ },
27737
+ handleTripleClick,
27738
+ handleKeyDown,
27739
+ handlePaste
27740
+ },
27741
+ appendTransaction(_, oldState, state) {
27742
+ return normalizeSelection(
27743
+ state,
27744
+ fixTables(state, oldState),
27745
+ allowTableNodeSelection
27746
+ );
27747
+ }
27748
+ });
27749
+ }
27750
+
27751
+ const getTableEditingPlugins = (tablesEnabled) => {
27752
+ if (tablesEnabled) {
27753
+ return [tableEditing()];
27754
+ }
27755
+ return [];
27756
+ };
27757
+ const createStyleAttribute = (cssProperty) => ({
27758
+ default: null,
27759
+ getFromDOM: (dom) => dom.style[cssProperty] || null,
27760
+ setDOMAttr: (value, attrs) => {
27761
+ if (value) {
27762
+ attrs.style = (attrs.style || '') + `${cssProperty}: ${value};`;
27763
+ }
27764
+ },
27765
+ });
27766
+ const getTableNodes = () => {
27767
+ return tableNodes({
27768
+ tableGroup: 'block',
27769
+ cellContent: 'block+',
27770
+ cellAttributes: {
27771
+ background: createStyleAttribute('background-color'),
27772
+ color: createStyleAttribute('color'),
27773
+ },
27774
+ });
27775
+ };
27776
+
26319
27777
  const prosemirrorAdapterCss = "@charset \"UTF-8\";:host{--mdc-theme-primary:var(\n --lime-primary-color,\n rgb(var(--color-teal-default))\n );--mdc-theme-secondary:var(\n --lime-secondary-color,\n rgb(var(--contrast-1100))\n );--mdc-theme-on-primary:var(\n --lime-on-primary-color,\n rgb(var(--contrast-100))\n );--mdc-theme-on-secondary:var(\n --lime-on-secondary-color,\n rgb(var(--contrast-100))\n );--mdc-theme-text-disabled-on-background:var(\n --lime-text-disabled-on-background-color,\n rgba(var(--contrast-1700), 0.38)\n );--mdc-theme-text-primary-on-background:var(\n --lime-text-primary-on-background-color,\n rgba(var(--contrast-1700), 0.87)\n );--mdc-theme-text-secondary-on-background:var(\n --lime-text-secondary-on-background-color,\n rgba(var(--contrast-1700), 0.54)\n );--mdc-theme-error:var(\n --lime-error-background-color,\n rgb(var(--color-red-dark))\n );--lime-error-text-color:rgb(var(--color-red-darker));--mdc-theme-surface:var(\n --lime-surface-background-color,\n rgb(var(--contrast-100))\n );--mdc-theme-on-surface:var(\n --lime-on-surface-color,\n rgb(var(--contrast-1500))\n )}:host(limel-prosemirror-adapter){display:flex;flex-direction:column}:host(limel-prosemirror-adapter) .toolbar{order:1}:host(limel-prosemirror-adapter) div#editor{order:2;height:100%;flex-grow:1}:host(limel-prosemirror-adapter) div[contenteditable=true]{height:100%}*{box-sizing:border-box}:host(limel-prosemirror-adapter:hover) .toolbar,:host(limel-prosemirror-adapter:focus-within) .toolbar{will-change:grid-template-rows}:host(limel-prosemirror-adapter:hover) limel-action-bar,:host(limel-prosemirror-adapter:focus-within) limel-action-bar{will-change:opacity, padding}:host(limel-prosemirror-adapter:hover) .ProseMirror,:host(limel-prosemirror-adapter:focus-within) .ProseMirror{will-change:padding}.ProseMirror-menubar-wrapper{display:grid;grid-template-rows:auto 1fr}.ProseMirror-textblock-dropdown{min-width:3em}.ProseMirror-tooltip .ProseMirror-menu{width:-webkit-fit-content;width:fit-content;white-space:pre}.toolbar{--action-bar-border-radius:0.25rem;border-radius:var(--action-bar-border-radius);flex-shrink:0;position:sticky;z-index:1;top:0;width:100%;display:grid;grid-template-rows:var(--limel-prosemirror-adapter-toolbar-grid-template-rows);transition-property:grid-template-rows;transition-duration:var(--limel-prosemirror-adapter-toolbar-grid-template-rows-transition-duration);transition-timing-function:var(--limel-prosemirror-adapter-toolbar-transition-timing-function);background-color:rgba(var(--contrast-200), 0.5);backdrop-filter:blur(0.5rem);-webkit-backdrop-filter:blur(0.5rem)}limel-action-bar{min-width:0;transition-property:padding, opacity;transition-duration:var(--limel-prosemirror-adapter-toolbar-grid-template-rows-transition-duration);transition-timing-function:var(--limel-prosemirror-adapter-toolbar-transition-timing-function);opacity:var(--limel-prosemirror-adapter-toolbar-opacity);padding:var(--limel-prosemirror-adapter-action-bar-padding-top-bottom, 0.125rem) 0.25rem;background-color:transparent;overflow:hidden}.ProseMirror{transition-duration:padding;transition-duration:var(--limel-prosemirror-adapter-toolbar-grid-template-rows-transition-duration);transition-timing-function:var(--limel-prosemirror-adapter-toolbar-transition-timing-function);position:relative;word-wrap:break-word;white-space:pre-wrap;white-space:break-spaces;-webkit-font-variant-ligatures:none;font-variant-ligatures:none;font-feature-settings:\"liga\" 0;padding:var(--limel-text-editor-padding)}.ProseMirror [draggable][contenteditable=false]{user-select:text}.ProseMirror:focus-visible{outline:none}.ProseMirror-hideselection{caret-color:transparent}.ProseMirror-hideselection *::selection{background:transparent}.ProseMirror-hideselection *::-moz-selection{background:transparent}.ProseMirror-selectednode{outline:0.125rem solid rgb(var(--color-sky-light))}li.ProseMirror-selectednode{outline:none}li.ProseMirror-selectednode:after{content:\"\";position:absolute;left:-2rem;right:-0.125rem;top:-0.125rem;bottom:-0.125rem;border:0.125rem solid rgb(var(--color-sky-light));pointer-events:none}img.ProseMirror-separator{display:inline !important;border:none !important;margin:0 !important}limel-portal{width:25rem}blockquote{position:relative;font-weight:100;font-size:0.875rem;max-width:100%;line-height:1.4;margin:0;padding:0.5rem 1.25rem;border-radius:0.05rem 0.75rem;background-color:rgb(var(--contrast-300))}blockquote:before,blockquote:after{position:absolute;font-size:2.75rem;opacity:0.4}blockquote:before{content:\"“\";left:0;top:-0.75rem}blockquote:after{content:\"”\";right:0;bottom:-2rem}:host(limel-markdown.truncate-paragraphs) p{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}p,li{font-size:0.875rem;word-break:break-word;hyphens:auto;-webkit-hyphens:auto}a{word-break:break-all}p{margin-top:0;margin-bottom:0.5rem}p:only-child{margin-bottom:0}a{transition:color 0.2s ease;color:var(--markdown-hyperlink-color, rgb(var(--color-blue-dark)));text-decoration:none}a:hover{color:var(--markdown-hyperlink-color--hovered, rgb(var(--color-blue-default)))}hr{margin:1.75rem 0 2rem 0;border-width:0;border-top:1px solid rgb(var(--contrast-500))}dl{display:grid;grid-template-columns:1fr 2fr;grid-template-rows:1fr;margin-bottom:2rem;border:1px solid rgb(var(--contrast-400));border-radius:0.375rem;background-color:rgb(var(--contrast-200))}dl dt,dl dd{padding:0.375rem 0.5rem;font-size:0.875rem;margin:0}dl dt:nth-of-type(even),dl dd:nth-of-type(even){background-color:rgb(var(--contrast-300))}dl dt:first-child{border-top-left-radius:0.375rem}dl dt:last-child{border-bottom-left-radius:0.375rem}dl dd:first-child{border-top-right-radius:0.375rem}dl dd:last-child{border-bottom-right-radius:0.375rem}h1{font-size:1.5rem}h2{font-size:1.25rem}h3{font-size:1.125rem}h4{font-size:1rem}h5{font-size:0.875rem}h6{font-size:0.75rem}h1,h2{margin-top:0.5rem;margin-bottom:0.5rem;letter-spacing:-0.03125rem;font-weight:500}h3,h4{margin-top:0.75rem;margin-bottom:0.25rem;font-weight:600}h5,h6{margin-top:0.5rem;margin-bottom:0.125rem;font-weight:600}h1,h2,h3,h4,h5,h6{word-break:break-word;hyphens:auto;-webkit-hyphens:auto}:not([contenteditable=true]) h1,:not([contenteditable=true]) h2,:not([contenteditable=true]) h3,:not([contenteditable=true]) h4,:not([contenteditable=true]) h5,:not([contenteditable=true]) h6{text-wrap:balance}[contenteditable=true] h1,[contenteditable=true] h2,[contenteditable=true] h3,[contenteditable=true] h4,[contenteditable=true] h5,[contenteditable=true] h6{text-wrap:initial}ul{list-style:none}ul li{position:relative;margin-left:0.75rem}ul li:before{content:\"\";position:absolute;left:-0.5rem;top:0.5rem;width:0.25rem;height:0.25rem;border-radius:50%;background-color:rgb(var(--contrast-700));display:block}ol{margin-top:0.25rem;padding-left:1rem}ul{margin-top:0.25rem;padding-left:0}ul ul,ul ol,ol ol,ol ul{margin-left:0}li{margin-bottom:0.25rem}code{font-family:ui-monospace, \"Cascadia Code\", \"Source Code Pro\", Menlo, Consolas, \"DejaVu Sans Mono\", monospace;font-size:0.8125rem;letter-spacing:-0.0125rem;color:rgb(var(--contrast-1300));-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;display:inline-block;border-radius:0.25rem;padding:0.03125rem 0.25rem;background-color:rgb(var(--contrast-600))}pre>code{display:block;margin:0.5rem 0;padding:0.5rem 0.75rem;overflow:auto;white-space:pre-wrap}:host(limel-markdown:not(.no-table-styles)) table{table-layout:auto;min-width:100%;border-collapse:collapse;border-spacing:0;background:transparent;margin:0.75rem 0;border:1px solid rgb(var(--contrast-400))}:host(limel-markdown:not(.no-table-styles)) th,:host(limel-markdown:not(.no-table-styles)) td{text-align:left;vertical-align:top;transition:background-color 0.2s ease;font-size:0.875rem}:host(limel-markdown:not(.no-table-styles)) td{padding:0.5rem 0.375rem 0.75rem 0.375rem}:host(limel-markdown:not(.no-table-styles)) tr th{background-color:rgb(var(--contrast-400));padding:0.25rem 0.375rem;font-weight:normal}:host(limel-markdown:not(.no-table-styles)) tr th:only-child{text-align:center}:host(limel-markdown:not(.no-table-styles)) tbody tr:nth-child(odd) td{background-color:rgb(var(--contrast-200))}:host(limel-markdown:not(.no-table-styles)) tbody tr:hover td{background-color:rgb(var(--contrast-300))}";
26320
27778
 
26321
27779
  const DEBOUNCE_TIMEOUT = 300;
@@ -26510,6 +27968,9 @@ const ProsemirrorAdapter = class {
26510
27968
  nodes = nodes.append({ [nodeName]: newNodeSpec });
26511
27969
  });
26512
27970
  nodes = addListNodes(nodes, 'paragraph block*', 'block');
27971
+ if (this.contentType === 'html') {
27972
+ nodes = nodes.append(getTableNodes());
27973
+ }
26513
27974
  return new Schema({
26514
27975
  nodes: nodes,
26515
27976
  marks: schema$1.spec.marks.append({
@@ -26539,6 +28000,7 @@ const ProsemirrorAdapter = class {
26539
28000
  createImageRemoverPlugin(),
26540
28001
  createMenuStateTrackingPlugin(editorMenuTypesArray, this.menuCommandFactory, this.updateActiveActionBarItems),
26541
28002
  createActionBarInteractionPlugin(this.menuCommandFactory),
28003
+ ...getTableEditingPlugins(this.contentType === 'html'),
26542
28004
  ],
26543
28005
  });
26544
28006
  }