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