@lexical/table 0.45.0 → 0.45.1-dev.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.
package/dist/LexicalTable.dev.js
CHANGED
|
@@ -4632,9 +4632,15 @@ function cellTextFormatMask(style) {
|
|
|
4632
4632
|
}
|
|
4633
4633
|
|
|
4634
4634
|
/**
|
|
4635
|
-
* Coalesce inline + line-break runs
|
|
4636
|
-
*
|
|
4637
|
-
*
|
|
4635
|
+
* Coalesce inline + line-break runs inside a `<td>`/`<th>` into their own
|
|
4636
|
+
* `ParagraphNode`s, leaving any pre-existing `ParagraphNode` children
|
|
4637
|
+
* (real `<p>` elements, or the `ParagraphNode` stand-ins that
|
|
4638
|
+
* {@link TransparentBlockRule} lowers `<div>`/`<section>`/… to) in
|
|
4639
|
+
* place as their own paragraph siblings. Mirrors the legacy `<td>`
|
|
4640
|
+
* importer where a bare `<td>789<div>000</div></td>` ended up as two
|
|
4641
|
+
* paragraphs (`<p>789</p><p>000</p>`), and also drops a sole leading
|
|
4642
|
+
* `<br>` that the legacy `removeSingleLineBreakNode` cleanup would have
|
|
4643
|
+
* removed.
|
|
4638
4644
|
*/
|
|
4639
4645
|
function $packageCellChildren(children) {
|
|
4640
4646
|
const result = [];
|
|
@@ -4656,9 +4662,12 @@ function $packageCellChildren(children) {
|
|
|
4656
4662
|
result.push(paragraph);
|
|
4657
4663
|
}
|
|
4658
4664
|
} else {
|
|
4665
|
+
// Block children (paragraphs, nested tables, decorator blocks, …)
|
|
4666
|
+
// start their own sibling — any inline run that was being
|
|
4667
|
+
// accumulated into `paragraph` is closed off here.
|
|
4659
4668
|
flushSingleLineBreak();
|
|
4660
|
-
result.push(child);
|
|
4661
4669
|
paragraph = null;
|
|
4670
|
+
result.push(child);
|
|
4662
4671
|
}
|
|
4663
4672
|
}
|
|
4664
4673
|
flushSingleLineBreak();
|
|
@@ -4765,9 +4774,22 @@ const TableCellRule = html.defineImportRule({
|
|
|
4765
4774
|
if (cellStyle !== inheritedStyle) {
|
|
4766
4775
|
branchContext.push(html.contextValue(html.ImportTextStyle, cellStyle));
|
|
4767
4776
|
}
|
|
4768
|
-
|
|
4777
|
+
// {@link $packageCellChildren} keeps each `ParagraphNode` child
|
|
4778
|
+
// (from a real `<p>`, or from {@link TransparentBlockRule}'s
|
|
4779
|
+
// lowering of `<div>`/`<section>`/…) as its own sibling paragraph
|
|
4780
|
+
// — matching legacy `<td>`'s `<td>789<div>000</div></td>` →
|
|
4781
|
+
// `<p>789</p><p>000</p>` shape.
|
|
4782
|
+
const packaged = $packageCellChildren(ctx.$importChildren(el, {
|
|
4769
4783
|
context: branchContext
|
|
4770
|
-
}))
|
|
4784
|
+
}));
|
|
4785
|
+
// Only `<td>` propagates `text-align` onto its block children —
|
|
4786
|
+
// mirroring legacy `wrapContinuousInlines`, which runs only for
|
|
4787
|
+
// `isBlockDomNode` elements. `<th>` is intentionally absent from
|
|
4788
|
+
// the block-tag set (see `BLOCK_TAG_RE` in `LexicalUtils.ts`), so a
|
|
4789
|
+
// `<th style="text-align: start">` wrapping a bare `<p>` leaves the
|
|
4790
|
+
// paragraph format empty.
|
|
4791
|
+
const children = isHeader ? packaged : html.$propagateTextAlignToBlockChildren(packaged, el);
|
|
4792
|
+
return [cell.splice(0, 0, children)];
|
|
4771
4793
|
},
|
|
4772
4794
|
match: html.sel.tag('td', 'th'),
|
|
4773
4795
|
name: '@lexical/table/cell'
|
|
@@ -4807,13 +4829,16 @@ const TableRowSchema = {
|
|
|
4807
4829
|
const TableImportRules = [TableRule, TableRowRule, TableCellRule];
|
|
4808
4830
|
|
|
4809
4831
|
/**
|
|
4810
|
-
* Bundles {@link TableImportRules}
|
|
4811
|
-
*
|
|
4832
|
+
* Bundles {@link TableImportRules} together with the runtime
|
|
4833
|
+
* {@link TableExtension}. The application is expected to already have
|
|
4834
|
+
* `CoreImportExtension` (or some equivalent) in its dependency graph —
|
|
4835
|
+
* the core/text/paragraph/inline-format rules are a shared baseline,
|
|
4836
|
+
* not something this leaf importer should re-declare.
|
|
4812
4837
|
*
|
|
4813
4838
|
* @experimental
|
|
4814
4839
|
*/
|
|
4815
4840
|
const TableImportExtension = lexical.defineExtension({
|
|
4816
|
-
dependencies: [
|
|
4841
|
+
dependencies: [TableExtension, lexical.configExtension(html.DOMImportExtension, {
|
|
4817
4842
|
rules: TableImportRules
|
|
4818
4843
|
})],
|
|
4819
4844
|
name: '@lexical/table/Import'
|
|
@@ -10,7 +10,7 @@ import { addClassNamesToElement, $descendantsMatching, $findMatchingParent, remo
|
|
|
10
10
|
import { ElementNode, isHTMLElement, $isInlineElementOrDecoratorNode, $isTextNode, $isLineBreakNode, $createParagraphNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $isParagraphNode, $createPoint, $getNodeByKey, $isElementNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, getDOMSelection, $createRangeSelection, $isRootNode, INSERT_PARAGRAPH_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, $getNearestNodeFromDOMNode, isDOMNode, $isRootOrShadowRoot, $getPreviousSelection, $getNodeByKeyOrThrow, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isSiblingCaret, $getSiblingCaret, $setPointFromCaret, $normalizeCaret, $createRangeSelectionFromDom, $isChildCaret, $getChildCaret, $getAdjacentChildCaret, IS_FIREFOX, setDOMStyleFromCSS, setDOMUnmanaged, COMMAND_PRIORITY_EDITOR, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, $getRoot, defineExtension, $fullReconcile, safeCast, configExtension, isHTMLTableRowElement, IS_BOLD, IS_ITALIC, IS_UNDERLINE, IS_STRIKETHROUGH } from 'lexical';
|
|
11
11
|
import { signal, effect, namedSignals } from '@lexical/extension';
|
|
12
12
|
import { copyToClipboard, $getClipboardDataFromSelection } from '@lexical/clipboard';
|
|
13
|
-
import {
|
|
13
|
+
import { DOMImportExtension, defineImportRule, sel, ImportTextFormat, ImportTextStyle, contextValue, $propagateTextAlignToBlockChildren } from '@lexical/html';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -4630,9 +4630,15 @@ function cellTextFormatMask(style) {
|
|
|
4630
4630
|
}
|
|
4631
4631
|
|
|
4632
4632
|
/**
|
|
4633
|
-
* Coalesce inline + line-break runs
|
|
4634
|
-
*
|
|
4635
|
-
*
|
|
4633
|
+
* Coalesce inline + line-break runs inside a `<td>`/`<th>` into their own
|
|
4634
|
+
* `ParagraphNode`s, leaving any pre-existing `ParagraphNode` children
|
|
4635
|
+
* (real `<p>` elements, or the `ParagraphNode` stand-ins that
|
|
4636
|
+
* {@link TransparentBlockRule} lowers `<div>`/`<section>`/… to) in
|
|
4637
|
+
* place as their own paragraph siblings. Mirrors the legacy `<td>`
|
|
4638
|
+
* importer where a bare `<td>789<div>000</div></td>` ended up as two
|
|
4639
|
+
* paragraphs (`<p>789</p><p>000</p>`), and also drops a sole leading
|
|
4640
|
+
* `<br>` that the legacy `removeSingleLineBreakNode` cleanup would have
|
|
4641
|
+
* removed.
|
|
4636
4642
|
*/
|
|
4637
4643
|
function $packageCellChildren(children) {
|
|
4638
4644
|
const result = [];
|
|
@@ -4654,9 +4660,12 @@ function $packageCellChildren(children) {
|
|
|
4654
4660
|
result.push(paragraph);
|
|
4655
4661
|
}
|
|
4656
4662
|
} else {
|
|
4663
|
+
// Block children (paragraphs, nested tables, decorator blocks, …)
|
|
4664
|
+
// start their own sibling — any inline run that was being
|
|
4665
|
+
// accumulated into `paragraph` is closed off here.
|
|
4657
4666
|
flushSingleLineBreak();
|
|
4658
|
-
result.push(child);
|
|
4659
4667
|
paragraph = null;
|
|
4668
|
+
result.push(child);
|
|
4660
4669
|
}
|
|
4661
4670
|
}
|
|
4662
4671
|
flushSingleLineBreak();
|
|
@@ -4763,9 +4772,22 @@ const TableCellRule = defineImportRule({
|
|
|
4763
4772
|
if (cellStyle !== inheritedStyle) {
|
|
4764
4773
|
branchContext.push(contextValue(ImportTextStyle, cellStyle));
|
|
4765
4774
|
}
|
|
4766
|
-
|
|
4775
|
+
// {@link $packageCellChildren} keeps each `ParagraphNode` child
|
|
4776
|
+
// (from a real `<p>`, or from {@link TransparentBlockRule}'s
|
|
4777
|
+
// lowering of `<div>`/`<section>`/…) as its own sibling paragraph
|
|
4778
|
+
// — matching legacy `<td>`'s `<td>789<div>000</div></td>` →
|
|
4779
|
+
// `<p>789</p><p>000</p>` shape.
|
|
4780
|
+
const packaged = $packageCellChildren(ctx.$importChildren(el, {
|
|
4767
4781
|
context: branchContext
|
|
4768
|
-
}))
|
|
4782
|
+
}));
|
|
4783
|
+
// Only `<td>` propagates `text-align` onto its block children —
|
|
4784
|
+
// mirroring legacy `wrapContinuousInlines`, which runs only for
|
|
4785
|
+
// `isBlockDomNode` elements. `<th>` is intentionally absent from
|
|
4786
|
+
// the block-tag set (see `BLOCK_TAG_RE` in `LexicalUtils.ts`), so a
|
|
4787
|
+
// `<th style="text-align: start">` wrapping a bare `<p>` leaves the
|
|
4788
|
+
// paragraph format empty.
|
|
4789
|
+
const children = isHeader ? packaged : $propagateTextAlignToBlockChildren(packaged, el);
|
|
4790
|
+
return [cell.splice(0, 0, children)];
|
|
4769
4791
|
},
|
|
4770
4792
|
match: sel.tag('td', 'th'),
|
|
4771
4793
|
name: '@lexical/table/cell'
|
|
@@ -4805,13 +4827,16 @@ const TableRowSchema = {
|
|
|
4805
4827
|
const TableImportRules = [TableRule, TableRowRule, TableCellRule];
|
|
4806
4828
|
|
|
4807
4829
|
/**
|
|
4808
|
-
* Bundles {@link TableImportRules}
|
|
4809
|
-
*
|
|
4830
|
+
* Bundles {@link TableImportRules} together with the runtime
|
|
4831
|
+
* {@link TableExtension}. The application is expected to already have
|
|
4832
|
+
* `CoreImportExtension` (or some equivalent) in its dependency graph —
|
|
4833
|
+
* the core/text/paragraph/inline-format rules are a shared baseline,
|
|
4834
|
+
* not something this leaf importer should re-declare.
|
|
4810
4835
|
*
|
|
4811
4836
|
* @experimental
|
|
4812
4837
|
*/
|
|
4813
4838
|
const TableImportExtension = defineExtension({
|
|
4814
|
-
dependencies: [
|
|
4839
|
+
dependencies: [TableExtension, configExtension(DOMImportExtension, {
|
|
4815
4840
|
rules: TableImportRules
|
|
4816
4841
|
})],
|
|
4817
4842
|
name: '@lexical/table/Import'
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/extension"),o=require("@lexical/clipboard"),r=require("@lexical/html");const l=/^(\d+(?:\.\d+)?)px$/,s={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class i extends t.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new i(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:c,priority:0}),th:e=>({conversion:c,priority:0})}}static importJSON(e){return u().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=s.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),a(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...a(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=s.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==s.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function a(e){return"middle"===e||"bottom"===e}function c(e){const n=e,o=e.nodeName.toLowerCase();let r;l.test(n.style.width)&&(r=parseFloat(n.style.width));let i=s.NO_STATUS;if("th"===o){const e=n.getAttribute("scope");if("col"===e)i=s.COLUMN;else if("row"===e)i=s.ROW;else{const e=n.parentElement,o=t.isHTMLElement(e)&&"tr"===e.nodeName.toLowerCase()&&t.isHTMLElement(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),r=0===n.cellIndex;o&&(i|=s.ROW),r&&(i|=s.COLUMN),i===s.NO_STATUS&&(i=s.ROW)}}const c=u(i,n.colSpan,r);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;a(h)&&(c.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,p=f.includes("line-through"),C="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:e=>{const n=[];let o=null;const r=()=>{if(o){const e=o.getFirstChild();t.$isLineBreakNode(e)&&1===o.getChildrenSize()&&e.remove()}};for(const l of e)if(t.$isInlineElementOrDecoratorNode(l)||t.$isTextNode(l)||t.$isLineBreakNode(l)){if(t.$isTextNode(l)&&(m&&l.toggleFormat("bold"),p&&l.toggleFormat("strikethrough"),C&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=t.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(t.$createParagraphNode()),n},node:c}}function u(e=s.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new i(e,n,o))}function d(e){return e instanceof i}const h=t.createCommand("INSERT_TABLE_COMMAND");function g(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class f extends t.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new f(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:m,priority:0})}}static importJSON(e){return p().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function m(t){const n=t;let o;return l.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,d),node:p(o)}}function p(e){return t.$applyNodeReplacement(new f(e))}function C(e){return e instanceof f}function _(e,n,o=!0){const r=ze();for(let l=0;l<e;l++){const e=p();for(let r=0;r<n;r++){let n=s.NO_STATUS;"object"==typeof o?(0===l&&o.rows&&(n|=s.ROW),0===r&&o.columns&&(n|=s.COLUMN)):o&&(0===l&&(n|=s.ROW),0===r&&(n|=s.COLUMN));const i=u(n),a=t.$createParagraphNode();a.append(t.$createTextNode()),i.append(a),e.append(i)}r.append(e)}return r}function S(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function N(t){const n=e.$findMatchingParent(t,e=>Ye(e));if(Ye(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(e,t){const n=N(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}const w=(e,t)=>e===s.BOTH||e===t?t:s.NO_STATUS;function y(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||X(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=H(o),[s,,i]=H(r),[,a,c]=k(i,s,l),{startRow:u}=c,{startRow:d}=a;return e?$(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):$(d<u?s:l,!1)}const T=y;function $(e,n=!0){const[,,o]=H(e),[r,l]=k(o,e,e),i=r[0].length,{startRow:a}=l;let c=null;if(n){const n=a+e.__rowSpan-1,l=r[n],d=p();for(let e=0;e<i;e++){const{cell:o,startRow:r}=l[e];if(r+o.__rowSpan-1<=n){const n=l[e].cell.__headerState,o=w(n,s.COLUMN);d.append(u(o).append(t.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const h=o.getChildAtIndex(n);C(h)||g(256),h.insertAfter(d),c=d}else{const e=a,n=r[e],l=p();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===e){const e=n[o].cell.__headerState,r=w(e,s.COLUMN);l.append(u(r).append(t.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(e);C(d)||g(257),d.insertBefore(l),c=l}return c}function R(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||X(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=H(o),[s,,i]=H(r),[,a,c]=k(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return e?E(u+l.__colSpan>d+s.__colSpan?l:s,!0):E(d<u?s:l,!1)}const x=R;function E(e,n=!0,o=!0){const[,,r]=H(e),[l,i]=k(r,e,e),a=l.length,{startColumn:c}=i,d=n?c+e.__colSpan-1:c-1,h=r.getFirstChild();C(h)||g(120);let f=null;function m(e=s.NO_STATUS){const n=u(e).append(t.$createParagraphNode());return null===f&&(f=n),n}let p=h;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||g(121),p=e}const t=l[e],n=t[d<0?0:d].cell.__headerState,o=w(n,s.ROW);if(d<0){P(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&F(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function M(){const e=t.$getSelection();t.$isRangeSelection(e)||X(e)||g(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=H(n),[s]=H(o),[i,a,c]=k(l,r,s),{startRow:u}=a,{startRow:d}=c,h=d+s.__rowSpan-1;if(i.length===h-u+1)return void l.remove();const f=i[0].length,m=i[h+1],p=l.getChildAtIndex(h+1);for(let e=h;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(o<u||o+n.__rowSpan-1>h){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>h&&e===h){null===p&&g(122);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?P(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||g(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];F(e)}else{const e=i[u-1],{cell:t}=e[0];F(t)}}const O=M;function A(){const e=t.$getSelection();t.$isRangeSelection(e)||X(e)||g(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=H(n),[s]=H(o),[i,a,c]=k(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:h}=c,f=Math.min(u,h),m=Math.max(u+r.__colSpan-1,h+s.__colSpan-1),p=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const C=i.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>h?_[u+r.__colSpan]:_[h+s.__colSpan];if(void 0!==S){const{cell:e}=S;F(e)}else{const e=h<u?_[h-1]:_[u-1],{cell:t}=e;F(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}}const v=A;function F(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function P(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function K(e){if(0===e.length)return null;const n=N(e[0]),[o]=L(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const t of o)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!a.has(t)&&e.some(e=>e.is(n.cell))){a.add(t);const e=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,e),l=Math.max(l,e+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);D(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(t.$createParagraphNode()),h}function D(e){if(1!==e.getChildrenSize())return!1;const n=e.getFirstChildOrThrow();return!(!t.$isParagraphNode(n)||!n.isEmpty())}function I(e){const[n,o,r]=H(e),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[a,c]=k(r,n,n),{startColumn:d,startRow:h}=c,f=n.__headerState&s.COLUMN,m=Array.from({length:l},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&s.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+h][e].cell.__headerState;return n});if(l>1){for(let e=1;e<l;e++)n.insertAfter(u(m[e]|_[0]).append(t.$createParagraphNode()));n.setColSpan(1)}if(i>1){let e;for(let n=1;n<i;n++){const r=h+n,s=a[r];e=(e||o).getNextSibling(),C(e)||g(125);let i=null;for(let e=0;e<d;e++){const t=s[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=l-1;o>=0;o--)P(e,u(m[o]|_[n]).append(t.$createParagraphNode()));else for(let e=l-1;e>=0;e--)i.insertAfter(u(m[e]|_[n]).append(t.$createParagraphNode()))}n.setRowSpan(1)}}function k(e,t,n){const[o,r,l]=L(e,t,n);return null===r&&g(207),null===l&&g(208),[o,r,l]}function L(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||g(209);const a=s(e);for(let c=o.getFirstChild(),u=0;null!=c;c=c.getNextSibling()){for(d(c)||g(147);void 0!==a[u];)u++;const o={cell:c,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:f}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[u+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function H(t){let n;if(t instanceof i)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,d);d(o)||g(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),d);d(o)||g(148),n=o}const o=n.getParent();C(o)||g(149);const r=o.getParent();return Ye(r)||g(210),[n,o,r]}function W(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function B(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!d(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function z(e){const[t,,n]=H(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function Y(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,d);d(r)||g(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||g(239,n);const s=l.getParent();return Ye(s)||g(240,n),[o,r,l,s]});return l.is(c)||g(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class U{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=t.$getNodeByKey(this.tableKey),n=t.$getNodeByKey(this.anchor.key),o=t.$getNodeByKey(this.focus.key);return null!==e&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return X(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new U(this.tableKey,t.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),t.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let n=0;this.getNodes().filter(d).forEach(e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=t.TEXT_TYPE_TO_FORMAT[e];return 0!==(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||g(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Y(this),n=z(e);null===n&&g(153);const o=z(t);null===o&&g(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:n,anchorCell:o,focusCell:r}=Y(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&g(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&g(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=k(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:h}=W(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=h;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||g(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||J(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>d(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function X(e){return e instanceof U}function G(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new U("root",e,n)}function q(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=X(r)?r.clone():G();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function J(e,n){const o=[[e]];for(let e=o.at(-1);void 0!==e&&o.length>0;e=o.at(-1)){const r=e.pop();void 0===r?o.pop():!1!==n(r)&&t.$isElementNode(r)&&o.push(r.getChildren())}}function j(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Ye(o)||g(231,e);const r=te(o,n.getElementByKey(e));return null===r&&g(232,e),{tableElement:r,tableNode:o}}class V{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class Q{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return j(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.getEditorState().read(()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=fe(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=fe(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const n=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:o,tableElement:r}=this.$lookup();me(n,fe(o,r),null),e&&null!==t.$getSelection()&&(t.$setSelection(null),n.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&g(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),me(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=t.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=e.x,s=e.y;if(this.focusCell=e,!this.isHighlightingCells){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=Pe(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=i;if(null===e&&n&&(e=r.getCellNodeFromCords(l,s,this.table)),null!==e){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=q(r,n,e),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),me(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&g(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&g(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=Pe(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=q(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();X(n)||g(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(d);s.length>0||g(237);const i=s[0].getFirstChild(),a=t.$isParagraphNode(i)?i.getFormatFlags(e,null):null;s.forEach(t=>{r.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),o.formatText(e,a)}),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!Ye(n))throw new Error("Expected TableNode.");const o=t.$getSelection();X(o)||g(253);const r=o.getNodes().filter(d),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(t.$isRootNode(o)&&o.isEmpty()&&e.dispatchCommand(t.INSERT_PARAGRAPH_COMMAND,void 0))}r.forEach(e=>{if(t.$isElementNode(e)){const n=t.$createParagraphNode(),o=t.$createTextNode();n.append(o),e.append(n),e.getChildren().forEach(e=>{e!==n&&e.remove()})}}),me(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const Z="__lexicalTableSelection";function ee(e){return t.isHTMLElement(e)&&"TABLE"===e.nodeName}function te(e,t){if(!t)return t;const n=ee(t)?t:t.querySelector("table");return ee(n)||g(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function ne(e){return e._window}function oe(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;d(n)&&(o=n)}return null}const re=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],le=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],se=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function ie(e,n){return e.registerRootListener(o=>{if(null===o)return;const r=e._window;if(null===r)return;const l=r=>{const l=r.target;if(0!==r.button||!t.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=he(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&Z in n&&n[Z])return{cellElement:t,tableElement:n,tableObserver:n[Z]};n=n.parentNode}return null}(l);e.update(()=>{if(X(t.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(e,n,o,r,l,s){const i=e._window;if(!i)return;const a=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});const o=()=>{l.isSelecting=!1,i.removeEventListener("pointerup",o),i.removeEventListener("pointermove",a)},a=n=>{if(!(e=>!(1&~e.buttons))(n)&&l.isSelecting)return l.isSelecting=!1,i.removeEventListener("pointerup",o),void i.removeEventListener("pointermove",a);if(!t.isDOMNode(n.target))return;let c=null;const u=!(t.IS_FIREFOX||r.contains(n.target));if(u)c=ge(r,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(c=ge(r,e),c)break;if(c){const n=c;null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&c.elem===l.focusCell.elem||(s.setNextFocus({focusCell:c,override:u,tableKey:l.tableNodeKey}),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}};i.addEventListener("pointerup",o,l.listenerOptions),i.addEventListener("pointermove",a,l.listenerOptions)};l.pointerType=n.pointerType;const c=t.$getNodeByKeyOrThrow(l.tableNodeKey),u=t.$getPreviousSelection();if(t.IS_FIREFOX&&n.shiftKey&&we(u,c)&&(t.$isRangeSelection(u)||X(u))){const e=u.anchor.getNode(),t=oe(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Fe(l,t)),l.$setFocusCellForSelection(o),Oe(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(e,r,i,l,o,n)})};return r.addEventListener("pointerdown",l),()=>{r.removeEventListener("pointerdown",l)}})}function ae(n,r,l,s,i){const a=l.getRootElement(),c=ne(l);null!==a&&null!==c||g(246);const u=new Q(l,n.getKey()),h=te(n,r);!function(e,t){null!==de(e)&&g(205);e[Z]=t}(h,u),u.listenersToRemove.add(()=>function(e,t){de(e)===t&&delete e[Z]}(h,u));const f=e=>{if(e.detail>=3&&t.isDOMNode(e.target)){null!==he(e.target)&&e.preventDefault()}};h.addEventListener("mousedown",f,u.listenerOptions),u.listenersToRemove.add(()=>{h.removeEventListener("mousedown",f)});for(const[e,o]of re)u.listenersToRemove.add(l.registerCommand(e,e=>Me(l,e,o,n,u,i),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,e=>{const o=t.$getSelection();if(X(o)){const t=oe(n,o.focus.getNode());if(null!==t)return Oe(e),t.selectEnd(),!0}return!1},t.COMMAND_PRIORITY_HIGH));const m=o=>()=>{const r=t.$getSelection();if(!we(r,n))return!1;if(X(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!d(oe(n,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=n.isParentOf(l),a=n.isParentOf(s);if(i&&!a||a&&!i)return u.$clearText(),!0;const c=e.$findMatchingParent(r.anchor.getNode(),e=>t.$isElementNode(e)),h=c&&e.$findMatchingParent(c,e=>t.$isElementNode(e)&&d(e.getParent()));if(!t.$isElementNode(h)||!t.$isElementNode(c))return!1;if(o===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of le)u.listenersToRemove.add(l.registerCommand(e,m(e),t.COMMAND_PRIORITY_HIGH));const p=e=>{const o=t.$getSelection();if(!X(o)&&!t.$isRangeSelection(o))return!1;const r=n.isParentOf(o.anchor.getNode());if(r!==n.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=o[t];return n[o[e].isBefore(o[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!we(o,n)&&(!!X(o)&&(e&&(e.preventDefault(),e.stopPropagation()),u.$clearText(),!0))};for(const e of se)u.listenersToRemove.add(l.registerCommand(e,p,t.COMMAND_PRIORITY_HIGH));return u.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,n=>{const r=t.$getSelection();if(r){if(!X(r)&&!t.$isRangeSelection(r))return!1;o.copyToClipboard(l,e.objectKlassEquals(n,ClipboardEvent)?n:null,o.$getClipboardDataFromSelection(r));const s=p(n);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,o=>{const r=t.$getSelection();if(!we(r,n))return!1;if(X(r))return u.$formatCells(o),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),e=>d(e));if(!d(t))return!1}return!1},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,e=>{const o=t.$getSelection();if(!X(o)||!we(o,n))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!d(r)||!d(l))return!1;if(function(e,t){if(X(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=k(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,n))return n.setFormat(e),!0;const[s,i,a]=k(n,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),u=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=c;n++)for(let o=g;o<=u;o++){const r=s[n][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(e);const l=r.getChildren();for(let n=0;n<l.length;n++){const o=l[n];t.$isElementNode(o)&&!o.isInline()&&o.setFormat(e)}}return!0},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,o=>{const r=t.$getSelection();if(!we(r,n))return!1;if(X(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),e=>d(e));if(!d(s))return!1;if("string"==typeof o){const e=ve(l,r,n);if(e)return Ae(e,n,[t.$createTextNode(o)]),!0}}return!1},t.COMMAND_PRIORITY_HIGH)),s&&u.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,o=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!we(r,n))return!1;const l=Re(r.anchor.getNode());return!(null===l||!n.is(xe(l)))&&(Oe(o),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,C);null===i&&g(247);for(let e=i[r]();C(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Ye);null===a&&g(248);"next"===o?a.selectNext():a.selectPrevious()}(l,o.shiftKey?"previous":"next"),!0)},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,e=>n.isSelected(),t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!we(e,n))return!1;const o=ve(l,e,n);return!!o&&(Ae(o,n),!0)},t.COMMAND_PRIORITY_HIGH)),u}function ce(n,o){const r=t.$getSelection(),l=t.$getPreviousSelection(),s=n.getAndClearNextFocus();if(null!==s){const{tableKey:e,focusCell:t}=s,o=n.observers.get(e);o||g(335,e);const[l]=o;if(X(r)&&r.tableKey===l.tableNodeKey)return(t.x!==l.focusX||t.y!==l.focusY)&&(l.$setFocusCellForSelection(t),!0);if(null!==l.anchorCell&&null!==l.anchorCellNodeKey&&t.elem!==l.anchorCell.elem&&null!==l.tableSelection)return l.$setFocusCellForSelection(t,!0),!0}const i=n.getAndClearShouldCheckSelectionForTable();if(i&&t.$isRangeSelection(l)&&t.$isRangeSelection(r)&&r.isCollapsed()){const n=t.$getNodeByKeyOrThrow(i),o=r.anchor.getNode(),l=n.getFirstChild(),s=Re(o);if(null!==s&&C(l)){const t=l.getFirstChild();if(d(t)&&n.is(e.$findMatchingParent(s,e=>e.is(n)||e.is(t))))return t.selectStart(),!0}}X(r)&&function(e,n){const o=ne(e),r=t.$getPreviousSelection();if(!n.is(r))return;const l=t.$getNodeByKeyOrThrow(n.tableKey),s=t.getDOMSelection(o);if(s&&s.anchorNode&&s.focusNode){const o=t.$getNearestNodeFromDOMNode(s.focusNode),r=o&&!l.isParentOf(o),i=t.$getNearestNodeFromDOMNode(s.anchorNode),a=i&&l.isParentOf(i);if(r&&a&&s.rangeCount>0){const o=t.$createRangeSelectionFromDom(s,e);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),t.$setSelection(o))}}}(o,r),t.$isRangeSelection(r)&&function(e,n){const o=t.$getPreviousSelection(),{anchor:r,focus:l}=e,s=r.getNode(),i=l.getNode(),a=Re(s),c=Re(i),u=a?xe(a):null,d=c?xe(c):null,h=e.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),p=u&&(!d||d.isParentOf(u));if(m){const n=e.clone(),[o]=k(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(h?r.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),t.$setSelection(n)}else if(p){const n=e.clone(),[o]=k(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(h?l.getKey():r.getKey(),h?l.getChildrenSize():0,"element"),t.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||g(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Fe(l,a)),l.$setFocusCellForSelection(Fe(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&t.$isRangeSelection(o)&&o.isCollapsed()){const e=Re(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Fe(l,e)),l.$setFocusCellForSelection(Fe(l,c),!0),l.pointerType=null)}}}(r,n);const a=Array.from(n.observers.entries()).map(([e,[n]])=>({tableNode:t.$getNodeByKeyOrThrow(e),tableObserver:n}));for(const{tableNode:e,tableObserver:t}of a)ue(o,e,t);return!1}function ue(e,n,o){const r=t.$getSelection(),l=t.$getPreviousSelection();r&&!r.is(l)&&(X(r)||X(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(X(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!X(r)&&X(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),pe(t.table,t=>{const n=t.elem;t.highlighted=!1,$e(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),pe(t.table,t=>{t.highlighted=!0,Te(e,t)})}(e,o)}function de(e){return e[Z]||null}function he(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function ge(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function fe(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=te(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function me(e,t,n){const o=new Set(n?n.getNodes():[]);pe(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Te(e,t)):(t.highlighted=!1,$e(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function pe(e,n){const{domRows:o}=e;for(let e=0;e<o.length;e++){const r=o[e];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=t.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:e})}}}const Ce=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ye(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ye(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?ye(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ye(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function _e(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function Se([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Ne(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&g(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&g(250,n,String(s)),i}function be(e,t,n,o,r){const l=W(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=_e(e,t);return null===n&&g(249,t.cell.getKey()),n}(l,n),[h,f]=Se(d);let m=l[h],p=l[f];"forward"===r?m+="maxColumn"===h?1:a:"backward"===r?m-="minColumn"===h?1:u:"down"===r?p+="maxRow"===f?1:i:"up"===r&&(p-="minRow"===f?1:c);const C=t[p];if(void 0===C)return!1;const _=C[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=W(e,t,n),r=_e(o,t);if(r)return[Ne(e,o,r),Ne(e,o,Se(r))];const l=_e(o,n);if(l)return[Ne(e,o,Se(l)),Ne(e,o,l)];const s=["minColumn","minRow"];return[Ne(e,o,s),Ne(e,o,Se(s))]}(t,n,_),b=Fe(e,S.cell),w=Fe(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function we(e,n){if(t.$isRangeSelection(e)||X(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function ye(e,t){t?e.selectStart():e.selectEnd()}function Te(n,o){const r=o.elem,l=n._config.theme;d(t.$getNearestNodeFromDOMNode(r))||g(131),e.addClassNamesToElement(r,l.tableCellSelected)}function $e(n,o){const r=o.elem;d(t.$getNearestNodeFromDOMNode(r))||g(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function Re(t){const n=e.$findMatchingParent(t,d);return d(n)?n:null}function xe(t){const n=e.$findMatchingParent(t,Ye);return Ye(n)?n:null}function Ee(n,o,r,l,s,i,a){const c=t.$caretFromPoint(r.focus,s?"previous":"next");if(t.$isExtendableTextPointCaret(c))return!1;let u=c;for(const e of t.$extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!t.$isSiblingCaret(e)||!t.$isElementNode(e.origin))return!1;u=e}const h=u.getParentAtCaret();if(!d(h))return!1;const g=h,f=function(e){for(const n of t.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:o}=n;if(d(o)){if(t.$isChildCaret(n))return t.$getChildCaret(o,e.direction)}else if(!C(o))break}return null}(t.$getSiblingCaret(g,u.direction)),m=e.$findMatchingParent(g,Ye);if(!m||!m.is(i))return!1;const p=n.getElementByKey(g.getKey()),_=he(p);if(!p||!_)return!1;const S=We(n,m);if(a.table=S,f)if("extend"===l){const e=he(n.getElementByKey(f.origin.getKey()));if(!e)return!1;a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(e,!0)}else{const e=t.$normalizeCaret(f);t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}else if("extend"===l)a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(_,!0);else{const e=function(e){const n=t.$getAdjacentChildCaret(e);return t.$isChildCaret(n)?t.$normalizeCaret(n):e}(t.$getSiblingCaret(m,c.direction));t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}return Oe(o),!0}function Me(n,o,r,l,s,i){if(("up"===r||"down"===r)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(n))return!1;const a=t.$getSelection();if(!we(a,l)){if(t.$isRangeSelection(a)){if("backward"===r){if(a.focus.offset>0)return!1;const e=function(e){for(let n=e,o=e;null!==o;n=o,o=o.getParent())if(t.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(a.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Ye(n)&&(Oe(o),o.shiftKey?a.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=a.focus.getNode();if(!a.isCollapsed()&&("up"===r&&!a.isBackward()||"down"===r&&a.isBackward())){let s=e.$findMatchingParent(n,e=>Ye(e));if(d(s)&&(s=e.$findMatchingParent(s,Ye)),s!==l)return!1;if(!s)return!1;const i="down"===r?s.getNextSibling():s.getPreviousSibling();if(!i)return!1;let c=0;"up"===r&&t.$isElementNode(i)&&(c=i.getChildrenSize());let u=i;if("up"===r&&t.$isElementNode(i)){const e=i.getLastChild();u=e||i,c=t.$isTextNode(u)?u.getTextContentSize():0}const h=a.clone();return h.focus.set(u.getKey(),c,t.$isTextNode(u)?"text":"element"),t.$setSelection(h),Oe(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?a.getNodes()[a.getNodes().length-1]:a.getNodes()[0];if(e){if(null!==oe(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=H(e),[o]=H(t),r=l.getCordsFromCellNode(n,s.table),i=l.getCordsFromCellNode(o,s.table),a=l.getDOMCellFromCordsOrThrow(r.x,r.y,s.table),c=l.getDOMCellFromCordsOrThrow(i.x,i.y,s.table);return s.$setAnchorCellForSelection(a),s.$setFocusCellForSelection(c,!0),!0}}return!1}{let l=e.$findMatchingParent(n,e=>t.$isElementNode(e)&&!e.isInline());if(d(l)&&(l=e.$findMatchingParent(l,Ye)),!l)return!1;const i="down"===r?l.getNextSibling():l.getPreviousSibling();if(Ye(i)&&s.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[l]=H(e),[s]=H(n),c=a.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),Oe(o),t.$setSelection(c),!0}}}}return"down"===r&&ke(n)&&i.setShouldCheckSelectionForTable(l.getKey()),!1}if(t.$isRangeSelection(a)){if("backward"===r||"forward"===r){return Ee(n,o,a,o.shiftKey?"extend":"move","backward"===r,l,s)}if(a.isCollapsed()){const{anchor:c,focus:u}=a,h=e.$findMatchingParent(c.getNode(),d),g=e.$findMatchingParent(u.getNode(),d);if(!d(h)||!h.is(g))return!1;const f=xe(h);if(f!==l&&null!=f){const e=te(f,n.getElementByKey(f.getKey()));if(null!=e)return s.table=fe(f,e),Me(n,o,r,f,s,i)}const m=n.getElementByKey(h.__key),p=n.getElementByKey(c.key);if(null==p||null==m)return!1;let C;if("element"===c.type)C=p.getBoundingClientRect();else{const e=t.getDOMSelection(ne(n));if(null===e||0===e.rangeCount)return!1;C=e.getRangeAt(0).getBoundingClientRect()}const _="up"===r?h.getFirstChild():h.getLastChild();if(null==_)return!1;const S=n.getElementByKey(_.__key);if(null==S)return!1;const N=S.getBoundingClientRect();if("up"===r?N.top>C.top-C.height:C.bottom+C.height>N.bottom){Oe(o);const e=l.getCordsFromCellNode(h,s.table);if(!o.shiftKey)return Ce(s,l,e.x,e.y,r);{const t=l.getDOMCellFromCordsOrThrow(e.x,e.y,s.table);s.$setAnchorCellForSelection(t),s.$setFocusCellForSelection(t,!0)}return!0}}}else if(X(a)){const{anchor:t,focus:i,tableKey:c}=a;if(c!==l.getKey())return!1;const u=e.$findMatchingParent(t.getNode(),d),h=e.$findMatchingParent(i.getNode(),d),[f]=a.getNodes();Ye(f)||g(251);const m=te(f,n.getElementByKey(f.getKey()));if(!d(u)||!d(h)||!Ye(f)||null==m)return!1;s.$updateTableTableSelection(a);const p=fe(f,m),C=l.getCordsFromCellNode(u,p),_=l.getDOMCellFromCordsOrThrow(C.x,C.y,p);if(s.$setAnchorCellForSelection(_),Oe(o),o.shiftKey){const[e,t,n]=k(l,u,h);return be(s,e,t,n,r)}return h.selectEnd(),!0}return!1}function Oe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ae(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function ve(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(ne(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),c=te(r,n.getElementByKey(r.getKey()));if(!i||!a||!c||!a.contains(i)||c.contains(i))return;const u=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!u)return;const h=e.$findMatchingParent(u,e=>Ye(e));if(!Ye(h)||!h.is(r))return;const[g,f]=k(r,u,u),m=g[0][0],p=g[g.length-1][g[0].length-1],{startRow:C,startColumn:_}=f,S=C===m.startRow&&_===m.startColumn,N=C===p.startRow&&_===p.startColumn;return S?"first":N?"last":void 0}function Fe(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Pe(e,n,o){return oe(e,t.$getNearestNodeFromDOMNode(n,o))}function Ke(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function De(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const Ie=new WeakSet;function ke(e=t.$getEditor()){return Ie.has(e)}function Le(e,t){t?Ie.add(e):Ie.delete(e)}class He extends t.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new He(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Be,priority:1})}}static importJSON(e){return ze().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=ee(e)?e:e.querySelector("table");return ee(t)||g(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table");this.__style&&t.setDOMStyleFromCSS(r.style,this.__style);const l=document.createElement("colgroup");if(r.appendChild(l),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),this.updateTableElement(null,r,n),ke(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.overflowX="auto",t.appendChild(r),this.updateTableWrapper(null,t,r,n),t}return r}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(n,o,r){this.__style!==(n?n.__style:"")&&t.setDOMStyleFromCSS(o.style,this.__style,n?n.__style:""),this.__rowStriping!==(!!n&&n.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(o,r,this.__rowStriping);const l=n?n.getColumnCount():0,s=n?n.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||Ke(o,this.getColumnCount(),this.getColWidths()),De(o,r,this.getFormatType())}updateDOM(t,n,o){const r=te(this,n);return n===r===ke()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Ke(te(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!ee(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!ee(o))return null;De(o,t._config,this.getFormatType());const[r]=L(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const e=document.createElement("tbody");for(const t of a)e.appendChild(t);o.append(e)}return o},element:!ee(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=Pe(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,n,o){const r=this.getDOMCellFromCords(e,n,o);if(null==r)return null;const l=t.$getNearestNodeFromDOMNode(r.elem);return d(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{d(e)&&(t+=e.getColSpan())}),t}}function We(e,t){const n=e.getElementByKey(t.getKey());return null===n&&g(230),fe(t,n)}function Be(t){const n=ze();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,C),node:n}}function ze(){return t.$applyNodeReplacement(new He)}function Ye(e){return e instanceof He}function Ue(e){C(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Xe(t){Ye(t.getParent())?e.$unwrapAndFilterDescendants(t,d):t.remove()}function Ge(n){e.$unwrapAndFilterDescendants(n,C);const[o]=L(n,null,null),r=o.reduce((e,t)=>Math.max(e,t.length),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;C(n)||g(254,n.constructor.name,n.getType());const s=o[e].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let e=s;e<r;++e){const e=u();e.append(t.$createParagraphNode()),n.append(e)}}const s=n.getColWidths(),i=n.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}n.setColWidths(e)}}function qe(n){if(n.detail<3||!t.isDOMNode(n.target))return!1;const o=t.$getNearestNodeFromDOMNode(n.target);if(null===o)return!1;const r=e.$findMatchingParent(o,e=>t.$isElementNode(e)&&!e.isInline());if(null===r)return!1;return!!d(r.getParent())&&(r.select(0),!0)}function Je(){const e=t.$getSelection();if(!t.$isRangeSelection(e))return!1;const n=xe(e.anchor.getNode());if(null===n)return!1;const o=t.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=L(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=q(n,l.cell,i.cell);return t.$setSelection(a),!0}function je(t){return t.registerNodeTransform(i,t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=H(t),[o]=k(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();C(s)||g(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),C(s)||g(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],a=l.cell;if(l.startRow===t&&l.startColumn===r)n=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){d(a)||g(176);const t=u(a.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Ve(n,o=!0){const r=new V,l=(e,t,l)=>{const s=te(e,l),i=ae(e,s,n,o,r);r.observers.set(t,[i,s])};return e.mergeRegister(ie(n,r),n.registerCommand(t.SELECTION_CHANGE_COMMAND,()=>ce(r,n),t.COMMAND_PRIORITY_HIGH),n.registerMutationListener(He,e=>{n.getEditorState().read(()=>{for(const[t,n]of e){const e=r.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:o}=j(t);void 0===e?l(n,t,o):o!==e[1]&&(e[0].removeListeners(),r.observers.delete(t),l(n,t,o))}else"destroyed"===n&&void 0!==e&&(e[0].removeListeners(),r.observers.delete(t))}},{editor:n})},{skipInitialization:!1}),()=>{for(const[,[e]]of r.observers)e.removeListeners()})}function Qe(o,r){o.hasNodes([He])||g(255);const{hasNestedTables:l=n.signal(!1)}=r??{};return e.mergeRegister(o.registerCommand(h,n=>function({rows:n,columns:o,includeHeaders:r},l){const s=t.$getSelection()||t.$getPreviousSelection();if(!s||!t.$isRangeSelection(s))return!1;if(!l&&xe(s.anchor.getNode()))return!1;const i=_(Number(n),Number(o),r);e.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return t.$isTextNode(a)&&a.select(),!0}(n,l.peek()),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n,r)=>o===r&&function(n,o){const{nodes:r,selection:l}=n;if(!r.some(t=>Ye(t)||e.$dfs(t).some(e=>Ye(e.node))))return!1;const s=X(l),i=t.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>d(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>d(e))||s))return!1;if(1===r.length&&Ye(r[0]))return function(n,o){const r=o.getStartEndPoints(),l=X(o);if(null===r)return!1;const[s,i]=r,[a,c,u]=H(s),h=e.$findMatchingParent(i.getNode(),e=>d(e));if(!(d(a)&&d(h)&&C(c)&&Ye(u)))return!1;const[g,f,m]=k(u,a,h),[p]=L(n,null,null),_=g.length,S=_>0?g[0].length:0;let N=f.startRow,b=f.startColumn,w=p.length,y=w>0?p[0].length:0;if(l){const e=W(g,f,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;N=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let T=!1;const R=Math.min(_,N+w)-1,x=Math.min(S,b+y)-1,M=new Set;for(let e=N;e<=R;e++)for(let t=b;t<=x;t++){const n=g[e][t];M.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(I(n.cell),M.add(n.cell.getKey()),T=!0))}let[O]=L(u.getWritable(),null,null);const A=w-_+N;for(let e=0;e<A;e++){$(O[_-1][0].cell)}const v=y-S+b;for(let e=0;e<v;e++){E(O[0][S-1].cell,!0,!1)}[O]=L(u.getWritable(),null,null);for(let e=N;e<N+w;e++)for(let n=b;n<b+y;n++){const o=e-N,r=n-b,l=p[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const t=[],o=Math.min(e+s.__rowSpan,N+w)-1,r=Math.min(n+s.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=n;e<=r;e++){const n=O[l][e];t.push(n.cell)}K(t),T=!0}const{cell:i}=O[e][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),i.append(e)}else i.append(e)}),c.forEach(e=>e.remove())}if(l&&T){const[e]=L(u.getWritable(),null,null);e[f.startRow][f.startColumn].cell.selectEnd()}return!0}(r[0],l);if(i&&o.peek()&&!function(e){if(X(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(t.$isRangeSelection(e)&&d(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(l))return!1;return!0}(n,l),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECT_ALL_COMMAND,Je,t.COMMAND_PRIORITY_LOW),o.registerCommand(t.CLICK_COMMAND,qe,t.COMMAND_PRIORITY_EDITOR),o.registerNodeTransform(He,Ge),o.registerNodeTransform(f,Xe),o.registerNodeTransform(i,Ue))}const Ze=t.defineExtension({build:(e,t,o)=>n.namedSignals(t),config:t.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[He,f,i],register(o,r,l){const s=l.getOutput();return e.mergeRegister(n.effect(()=>{const e=s.hasHorizontalScroll.value;ke(o)!==e&&(Le(o,e),o.update(t.$fullReconcile))}),Qe(o,s),n.effect(()=>Ve(o,s.hasTabHandler.value)),n.effect(()=>s.hasCellMerge.value?void 0:je(o)),n.effect(()=>s.hasCellBackgroundColor.value?void 0:o.registerNodeTransform(i,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});function et(e){const n=[];let o=null;const r=()=>{if(null!==o){const e=o.getFirstChild();t.$isLineBreakNode(e)&&1===o.getChildrenSize()&&e.remove()}};for(const l of e)t.$isInlineElementOrDecoratorNode(l)||t.$isTextNode(l)||t.$isLineBreakNode(l)?null!==o?o.append(l):(o=t.$createParagraphNode().append(l),n.push(o)):(r(),n.push(l),o=null);return r(),0===n.length&&n.push(t.$createParagraphNode()),n}const tt={$accepts:C,$packageRun:e=>e.every(d)?[p().splice(0,0,e)]:[],name:"TableSchema"},nt={$accepts:d,name:"TableRowSchema"},ot=[r.defineImportRule({$import:(t,n)=>{const o=ze();n.hasAttribute("data-lexical-row-striping")&&o.setRowStriping(!0),n.hasAttribute("data-lexical-frozen-column")&&o.setFrozenColumns(1),n.hasAttribute("data-lexical-frozen-row")&&o.setFrozenRows(1);const r=n.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&o.setColWidths(e)}return[o.splice(0,0,e.$descendantsMatching(t.$importChildren(n),C))]},match:r.sel.tag("table"),name:"@lexical/table/table"}),r.defineImportRule({$import:(t,n)=>[p(l.test(n.style.height)?parseFloat(n.style.height):void 0).splice(0,0,e.$descendantsMatching(t.$importChildren(n),d))],match:r.sel.tag("tr"),name:"@lexical/table/tr"}),r.defineImportRule({$import:(e,n)=>{const o="TH"===n.nodeName,i=l.test(n.style.width)?parseFloat(n.style.width):void 0;let a=s.NO_STATUS;if(o){const e=n.getAttribute("scope");if("col"===e)a=s.COLUMN;else if("row"===e)a=s.ROW;else{const e=n.parentElement,o=t.isHTMLTableRowElement(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),r=0===n.cellIndex;o&&(a|=s.ROW),r&&(a|=s.COLUMN),a===s.NO_STATUS&&(a=s.ROW)}}const c=u(a,n.colSpan,i);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(c.__verticalAlign=h);const g=e.get(r.ImportTextFormat),f=g|function(e){let n=0;const o=e.fontWeight;"700"!==o&&"bold"!==o||(n|=t.IS_BOLD),"italic"===e.fontStyle&&(n|=t.IS_ITALIC);const r=(e.textDecoration||"").split(" ");return r.includes("underline")&&(n|=t.IS_UNDERLINE),r.includes("line-through")&&(n|=t.IS_STRIKETHROUGH),n}(n.style),m=e.get(r.ImportTextStyle),p=n.style.color,C=p?{...m,color:p}:m,_=[];return f!==g&&_.push(r.contextValue(r.ImportTextFormat,f)),C!==m&&_.push(r.contextValue(r.ImportTextStyle,C)),[c.splice(0,0,et(e.$importChildren(n,{context:_})))]},match:r.sel.tag("td","th"),name:"@lexical/table/cell"})],rt=t.defineExtension({dependencies:[r.CoreImportExtension,Ze,t.configExtension(r.DOMImportExtension,{rules:ot})],name:"@lexical/table/Import"});exports.$computeTableMap=k,exports.$computeTableMapSkipCellCheck=L,exports.$createTableCellNode=u,exports.$createTableNode=ze,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=p,exports.$createTableSelection=G,exports.$createTableSelectionFrom=q,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumnAtSelection=A,exports.$deleteTableColumn__EXPERIMENTAL=v,exports.$deleteTableRowAtSelection=M,exports.$deleteTableRow__EXPERIMENTAL=O,exports.$findCellNode=Re,exports.$findTableNode=xe,exports.$getElementForTableNode=We,exports.$getNodeTriplet=H,exports.$getTableAndElementByKey=j,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>d(e));return d(n)?n:null},exports.$getTableCellNodeRect=z,exports.$getTableColumnIndexFromTableCellNode=function(e){return S(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=N,exports.$getTableRowIndexFromTableCellNode=function(e){const t=S(e);return N(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=S,exports.$insertTableColumn=function(e,n,o=!0,r,l){const i=e.getChildren(),a=[];for(let e=0;e<i.length;e++){const o=i[e];if(C(o))for(let e=0;e<r;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const r=e[n];d(r)||g(12);const{left:i,right:c}=b(r,l);let h=s.NO_STATUS;(i&&i.hasHeaderState(s.ROW)||c&&c.hasHeaderState(s.ROW))&&(h|=s.ROW);const f=u(h);f.append(t.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),e},exports.$insertTableColumnAtSelection=R,exports.$insertTableColumn__EXPERIMENTAL=x,exports.$insertTableRow=function(e,n,o=!0,r,l){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let e=0;e<r;e++){const e=a.getChildren(),n=e.length,r=p();for(let o=0;o<n;o++){const n=e[o];d(n)||g(12);const{above:i,below:a}=b(n,l);let c=s.NO_STATUS;const h=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(s.COLUMN)||a&&a.hasHeaderState(s.COLUMN))&&(c|=s.COLUMN);const f=u(c,1,h);f.append(t.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return e},exports.$insertTableRowAtSelection=y,exports.$insertTableRow__EXPERIMENTAL=T,exports.$isScrollableTablesActive=ke,exports.$isSimpleTable=B,exports.$isTableCellNode=d,exports.$isTableNode=Ye,exports.$isTableRowNode=C,exports.$isTableSelection=X,exports.$mergeCells=K,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!B(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const n=t.$getSelection();t.$isRangeSelection(n)||X(n)||g(188);const o=n.anchor.getNode(),r=e.$findMatchingParent(o,d);return d(r)||g(148),I(r)},exports.INSERT_TABLE_COMMAND=h,exports.TableCellHeaderStates=s,exports.TableCellNode=i,exports.TableExtension=Ze,exports.TableImportExtension=rt,exports.TableImportRules=ot,exports.TableNode=He,exports.TableObserver=Q,exports.TableRowNode=f,exports.TableRowSchema=nt,exports.TableSchema=tt,exports.applyTableHandlers=ae,exports.getDOMCellFromTarget=he,exports.getTableElement=te,exports.getTableObserverFromTableElement=de,exports.registerTableCellUnmergeTransform=je,exports.registerTablePlugin=Qe,exports.registerTableSelectionObserver=Ve,exports.setScrollableTablesActive=Le;
|
|
9
|
+
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/extension"),o=require("@lexical/clipboard"),r=require("@lexical/html");const l=/^(\d+(?:\.\d+)?)px$/,s={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class i extends t.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new i(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:c,priority:0}),th:e=>({conversion:c,priority:0})}}static importJSON(e){return u().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=s.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),a(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...a(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=s.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==s.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function a(e){return"middle"===e||"bottom"===e}function c(e){const n=e,o=e.nodeName.toLowerCase();let r;l.test(n.style.width)&&(r=parseFloat(n.style.width));let i=s.NO_STATUS;if("th"===o){const e=n.getAttribute("scope");if("col"===e)i=s.COLUMN;else if("row"===e)i=s.ROW;else{const e=n.parentElement,o=t.isHTMLElement(e)&&"tr"===e.nodeName.toLowerCase()&&t.isHTMLElement(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),r=0===n.cellIndex;o&&(i|=s.ROW),r&&(i|=s.COLUMN),i===s.NO_STATUS&&(i=s.ROW)}}const c=u(i,n.colSpan,r);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;a(h)&&(c.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,p=f.includes("line-through"),C="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:e=>{const n=[];let o=null;const r=()=>{if(o){const e=o.getFirstChild();t.$isLineBreakNode(e)&&1===o.getChildrenSize()&&e.remove()}};for(const l of e)if(t.$isInlineElementOrDecoratorNode(l)||t.$isTextNode(l)||t.$isLineBreakNode(l)){if(t.$isTextNode(l)&&(m&&l.toggleFormat("bold"),p&&l.toggleFormat("strikethrough"),C&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=t.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(t.$createParagraphNode()),n},node:c}}function u(e=s.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new i(e,n,o))}function d(e){return e instanceof i}const h=t.createCommand("INSERT_TABLE_COMMAND");function g(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class f extends t.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new f(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:m,priority:0})}}static importJSON(e){return p().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function m(t){const n=t;let o;return l.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,d),node:p(o)}}function p(e){return t.$applyNodeReplacement(new f(e))}function C(e){return e instanceof f}function _(e,n,o=!0){const r=ze();for(let l=0;l<e;l++){const e=p();for(let r=0;r<n;r++){let n=s.NO_STATUS;"object"==typeof o?(0===l&&o.rows&&(n|=s.ROW),0===r&&o.columns&&(n|=s.COLUMN)):o&&(0===l&&(n|=s.ROW),0===r&&(n|=s.COLUMN));const i=u(n),a=t.$createParagraphNode();a.append(t.$createTextNode()),i.append(a),e.append(i)}r.append(e)}return r}function S(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function N(t){const n=e.$findMatchingParent(t,e=>Ye(e));if(Ye(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(e,t){const n=N(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}const w=(e,t)=>e===s.BOTH||e===t?t:s.NO_STATUS;function y(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||X(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=H(o),[s,,i]=H(r),[,a,c]=k(i,s,l),{startRow:u}=c,{startRow:d}=a;return e?$(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):$(d<u?s:l,!1)}const T=y;function $(e,n=!0){const[,,o]=H(e),[r,l]=k(o,e,e),i=r[0].length,{startRow:a}=l;let c=null;if(n){const n=a+e.__rowSpan-1,l=r[n],d=p();for(let e=0;e<i;e++){const{cell:o,startRow:r}=l[e];if(r+o.__rowSpan-1<=n){const n=l[e].cell.__headerState,o=w(n,s.COLUMN);d.append(u(o).append(t.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const h=o.getChildAtIndex(n);C(h)||g(256),h.insertAfter(d),c=d}else{const e=a,n=r[e],l=p();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===e){const e=n[o].cell.__headerState,r=w(e,s.COLUMN);l.append(u(r).append(t.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(e);C(d)||g(257),d.insertBefore(l),c=l}return c}function R(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||X(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=H(o),[s,,i]=H(r),[,a,c]=k(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return e?M(u+l.__colSpan>d+s.__colSpan?l:s,!0):M(d<u?s:l,!1)}const x=R;function M(e,n=!0,o=!0){const[,,r]=H(e),[l,i]=k(r,e,e),a=l.length,{startColumn:c}=i,d=n?c+e.__colSpan-1:c-1,h=r.getFirstChild();C(h)||g(120);let f=null;function m(e=s.NO_STATUS){const n=u(e).append(t.$createParagraphNode());return null===f&&(f=n),n}let p=h;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||g(121),p=e}const t=l[e],n=t[d<0?0:d].cell.__headerState,o=w(n,s.ROW);if(d<0){P(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&F(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function E(){const e=t.$getSelection();t.$isRangeSelection(e)||X(e)||g(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=H(n),[s]=H(o),[i,a,c]=k(l,r,s),{startRow:u}=a,{startRow:d}=c,h=d+s.__rowSpan-1;if(i.length===h-u+1)return void l.remove();const f=i[0].length,m=i[h+1],p=l.getChildAtIndex(h+1);for(let e=h;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(o<u||o+n.__rowSpan-1>h){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>h&&e===h){null===p&&g(122);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?P(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||g(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];F(e)}else{const e=i[u-1],{cell:t}=e[0];F(t)}}const O=E;function A(){const e=t.$getSelection();t.$isRangeSelection(e)||X(e)||g(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=H(n),[s]=H(o),[i,a,c]=k(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:h}=c,f=Math.min(u,h),m=Math.max(u+r.__colSpan-1,h+s.__colSpan-1),p=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const C=i.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>h?_[u+r.__colSpan]:_[h+s.__colSpan];if(void 0!==S){const{cell:e}=S;F(e)}else{const e=h<u?_[h-1]:_[u-1],{cell:t}=e;F(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}}const v=A;function F(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function P(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function K(e){if(0===e.length)return null;const n=N(e[0]),[o]=L(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const t of o)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!a.has(t)&&e.some(e=>e.is(n.cell))){a.add(t);const e=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,e),l=Math.max(l,e+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);D(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(t.$createParagraphNode()),h}function D(e){if(1!==e.getChildrenSize())return!1;const n=e.getFirstChildOrThrow();return!(!t.$isParagraphNode(n)||!n.isEmpty())}function I(e){const[n,o,r]=H(e),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[a,c]=k(r,n,n),{startColumn:d,startRow:h}=c,f=n.__headerState&s.COLUMN,m=Array.from({length:l},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&s.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+h][e].cell.__headerState;return n});if(l>1){for(let e=1;e<l;e++)n.insertAfter(u(m[e]|_[0]).append(t.$createParagraphNode()));n.setColSpan(1)}if(i>1){let e;for(let n=1;n<i;n++){const r=h+n,s=a[r];e=(e||o).getNextSibling(),C(e)||g(125);let i=null;for(let e=0;e<d;e++){const t=s[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=l-1;o>=0;o--)P(e,u(m[o]|_[n]).append(t.$createParagraphNode()));else for(let e=l-1;e>=0;e--)i.insertAfter(u(m[e]|_[n]).append(t.$createParagraphNode()))}n.setRowSpan(1)}}function k(e,t,n){const[o,r,l]=L(e,t,n);return null===r&&g(207),null===l&&g(208),[o,r,l]}function L(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||g(209);const a=s(e);for(let c=o.getFirstChild(),u=0;null!=c;c=c.getNextSibling()){for(d(c)||g(147);void 0!==a[u];)u++;const o={cell:c,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:f}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[u+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function H(t){let n;if(t instanceof i)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,d);d(o)||g(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),d);d(o)||g(148),n=o}const o=n.getParent();C(o)||g(149);const r=o.getParent();return Ye(r)||g(210),[n,o,r]}function W(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function B(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!d(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function z(e){const[t,,n]=H(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function Y(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,d);d(r)||g(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||g(239,n);const s=l.getParent();return Ye(s)||g(240,n),[o,r,l,s]});return l.is(c)||g(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class U{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=t.$getNodeByKey(this.tableKey),n=t.$getNodeByKey(this.anchor.key),o=t.$getNodeByKey(this.focus.key);return null!==e&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return X(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new U(this.tableKey,t.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),t.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let n=0;this.getNodes().filter(d).forEach(e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=t.TEXT_TYPE_TO_FORMAT[e];return 0!==(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||g(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Y(this),n=z(e);null===n&&g(153);const o=z(t);null===o&&g(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:n,anchorCell:o,focusCell:r}=Y(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&g(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&g(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=k(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:h}=W(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=h;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||g(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||J(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>d(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function X(e){return e instanceof U}function G(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new U("root",e,n)}function q(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=X(r)?r.clone():G();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function J(e,n){const o=[[e]];for(let e=o.at(-1);void 0!==e&&o.length>0;e=o.at(-1)){const r=e.pop();void 0===r?o.pop():!1!==n(r)&&t.$isElementNode(r)&&o.push(r.getChildren())}}function j(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Ye(o)||g(231,e);const r=te(o,n.getElementByKey(e));return null===r&&g(232,e),{tableElement:r,tableNode:o}}class V{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class Q{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return j(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.getEditorState().read(()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=fe(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=fe(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const n=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:o,tableElement:r}=this.$lookup();me(n,fe(o,r),null),e&&null!==t.$getSelection()&&(t.$setSelection(null),n.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&g(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),me(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=t.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=e.x,s=e.y;if(this.focusCell=e,!this.isHighlightingCells){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=Pe(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=i;if(null===e&&n&&(e=r.getCellNodeFromCords(l,s,this.table)),null!==e){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=q(r,n,e),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),me(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&g(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&g(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=Pe(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=q(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();X(n)||g(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(d);s.length>0||g(237);const i=s[0].getFirstChild(),a=t.$isParagraphNode(i)?i.getFormatFlags(e,null):null;s.forEach(t=>{r.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),o.formatText(e,a)}),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!Ye(n))throw new Error("Expected TableNode.");const o=t.$getSelection();X(o)||g(253);const r=o.getNodes().filter(d),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(t.$isRootNode(o)&&o.isEmpty()&&e.dispatchCommand(t.INSERT_PARAGRAPH_COMMAND,void 0))}r.forEach(e=>{if(t.$isElementNode(e)){const n=t.$createParagraphNode(),o=t.$createTextNode();n.append(o),e.append(n),e.getChildren().forEach(e=>{e!==n&&e.remove()})}}),me(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const Z="__lexicalTableSelection";function ee(e){return t.isHTMLElement(e)&&"TABLE"===e.nodeName}function te(e,t){if(!t)return t;const n=ee(t)?t:t.querySelector("table");return ee(n)||g(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function ne(e){return e._window}function oe(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;d(n)&&(o=n)}return null}const re=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],le=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],se=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function ie(e,n){return e.registerRootListener(o=>{if(null===o)return;const r=e._window;if(null===r)return;const l=r=>{const l=r.target;if(0!==r.button||!t.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=he(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&Z in n&&n[Z])return{cellElement:t,tableElement:n,tableObserver:n[Z]};n=n.parentNode}return null}(l);e.update(()=>{if(X(t.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(e,n,o,r,l,s){const i=e._window;if(!i)return;const a=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});const o=()=>{l.isSelecting=!1,i.removeEventListener("pointerup",o),i.removeEventListener("pointermove",a)},a=n=>{if(!(e=>!(1&~e.buttons))(n)&&l.isSelecting)return l.isSelecting=!1,i.removeEventListener("pointerup",o),void i.removeEventListener("pointermove",a);if(!t.isDOMNode(n.target))return;let c=null;const u=!(t.IS_FIREFOX||r.contains(n.target));if(u)c=ge(r,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(c=ge(r,e),c)break;if(c){const n=c;null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&c.elem===l.focusCell.elem||(s.setNextFocus({focusCell:c,override:u,tableKey:l.tableNodeKey}),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}};i.addEventListener("pointerup",o,l.listenerOptions),i.addEventListener("pointermove",a,l.listenerOptions)};l.pointerType=n.pointerType;const c=t.$getNodeByKeyOrThrow(l.tableNodeKey),u=t.$getPreviousSelection();if(t.IS_FIREFOX&&n.shiftKey&&we(u,c)&&(t.$isRangeSelection(u)||X(u))){const e=u.anchor.getNode(),t=oe(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Fe(l,t)),l.$setFocusCellForSelection(o),Oe(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(e,r,i,l,o,n)})};return r.addEventListener("pointerdown",l),()=>{r.removeEventListener("pointerdown",l)}})}function ae(n,r,l,s,i){const a=l.getRootElement(),c=ne(l);null!==a&&null!==c||g(246);const u=new Q(l,n.getKey()),h=te(n,r);!function(e,t){null!==de(e)&&g(205);e[Z]=t}(h,u),u.listenersToRemove.add(()=>function(e,t){de(e)===t&&delete e[Z]}(h,u));const f=e=>{if(e.detail>=3&&t.isDOMNode(e.target)){null!==he(e.target)&&e.preventDefault()}};h.addEventListener("mousedown",f,u.listenerOptions),u.listenersToRemove.add(()=>{h.removeEventListener("mousedown",f)});for(const[e,o]of re)u.listenersToRemove.add(l.registerCommand(e,e=>Ee(l,e,o,n,u,i),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,e=>{const o=t.$getSelection();if(X(o)){const t=oe(n,o.focus.getNode());if(null!==t)return Oe(e),t.selectEnd(),!0}return!1},t.COMMAND_PRIORITY_HIGH));const m=o=>()=>{const r=t.$getSelection();if(!we(r,n))return!1;if(X(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!d(oe(n,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=n.isParentOf(l),a=n.isParentOf(s);if(i&&!a||a&&!i)return u.$clearText(),!0;const c=e.$findMatchingParent(r.anchor.getNode(),e=>t.$isElementNode(e)),h=c&&e.$findMatchingParent(c,e=>t.$isElementNode(e)&&d(e.getParent()));if(!t.$isElementNode(h)||!t.$isElementNode(c))return!1;if(o===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of le)u.listenersToRemove.add(l.registerCommand(e,m(e),t.COMMAND_PRIORITY_HIGH));const p=e=>{const o=t.$getSelection();if(!X(o)&&!t.$isRangeSelection(o))return!1;const r=n.isParentOf(o.anchor.getNode());if(r!==n.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=o[t];return n[o[e].isBefore(o[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!we(o,n)&&(!!X(o)&&(e&&(e.preventDefault(),e.stopPropagation()),u.$clearText(),!0))};for(const e of se)u.listenersToRemove.add(l.registerCommand(e,p,t.COMMAND_PRIORITY_HIGH));return u.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,n=>{const r=t.$getSelection();if(r){if(!X(r)&&!t.$isRangeSelection(r))return!1;o.copyToClipboard(l,e.objectKlassEquals(n,ClipboardEvent)?n:null,o.$getClipboardDataFromSelection(r));const s=p(n);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,o=>{const r=t.$getSelection();if(!we(r,n))return!1;if(X(r))return u.$formatCells(o),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),e=>d(e));if(!d(t))return!1}return!1},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,e=>{const o=t.$getSelection();if(!X(o)||!we(o,n))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!d(r)||!d(l))return!1;if(function(e,t){if(X(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=k(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,n))return n.setFormat(e),!0;const[s,i,a]=k(n,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),u=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=c;n++)for(let o=g;o<=u;o++){const r=s[n][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(e);const l=r.getChildren();for(let n=0;n<l.length;n++){const o=l[n];t.$isElementNode(o)&&!o.isInline()&&o.setFormat(e)}}return!0},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,o=>{const r=t.$getSelection();if(!we(r,n))return!1;if(X(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),e=>d(e));if(!d(s))return!1;if("string"==typeof o){const e=ve(l,r,n);if(e)return Ae(e,n,[t.$createTextNode(o)]),!0}}return!1},t.COMMAND_PRIORITY_HIGH)),s&&u.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,o=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!we(r,n))return!1;const l=Re(r.anchor.getNode());return!(null===l||!n.is(xe(l)))&&(Oe(o),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,C);null===i&&g(247);for(let e=i[r]();C(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Ye);null===a&&g(248);"next"===o?a.selectNext():a.selectPrevious()}(l,o.shiftKey?"previous":"next"),!0)},t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,e=>n.isSelected(),t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!we(e,n))return!1;const o=ve(l,e,n);return!!o&&(Ae(o,n),!0)},t.COMMAND_PRIORITY_HIGH)),u}function ce(n,o){const r=t.$getSelection(),l=t.$getPreviousSelection(),s=n.getAndClearNextFocus();if(null!==s){const{tableKey:e,focusCell:t}=s,o=n.observers.get(e);o||g(335,e);const[l]=o;if(X(r)&&r.tableKey===l.tableNodeKey)return(t.x!==l.focusX||t.y!==l.focusY)&&(l.$setFocusCellForSelection(t),!0);if(null!==l.anchorCell&&null!==l.anchorCellNodeKey&&t.elem!==l.anchorCell.elem&&null!==l.tableSelection)return l.$setFocusCellForSelection(t,!0),!0}const i=n.getAndClearShouldCheckSelectionForTable();if(i&&t.$isRangeSelection(l)&&t.$isRangeSelection(r)&&r.isCollapsed()){const n=t.$getNodeByKeyOrThrow(i),o=r.anchor.getNode(),l=n.getFirstChild(),s=Re(o);if(null!==s&&C(l)){const t=l.getFirstChild();if(d(t)&&n.is(e.$findMatchingParent(s,e=>e.is(n)||e.is(t))))return t.selectStart(),!0}}X(r)&&function(e,n){const o=ne(e),r=t.$getPreviousSelection();if(!n.is(r))return;const l=t.$getNodeByKeyOrThrow(n.tableKey),s=t.getDOMSelection(o);if(s&&s.anchorNode&&s.focusNode){const o=t.$getNearestNodeFromDOMNode(s.focusNode),r=o&&!l.isParentOf(o),i=t.$getNearestNodeFromDOMNode(s.anchorNode),a=i&&l.isParentOf(i);if(r&&a&&s.rangeCount>0){const o=t.$createRangeSelectionFromDom(s,e);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),t.$setSelection(o))}}}(o,r),t.$isRangeSelection(r)&&function(e,n){const o=t.$getPreviousSelection(),{anchor:r,focus:l}=e,s=r.getNode(),i=l.getNode(),a=Re(s),c=Re(i),u=a?xe(a):null,d=c?xe(c):null,h=e.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),p=u&&(!d||d.isParentOf(u));if(m){const n=e.clone(),[o]=k(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(h?r.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),t.$setSelection(n)}else if(p){const n=e.clone(),[o]=k(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(h?l.getKey():r.getKey(),h?l.getChildrenSize():0,"element"),t.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||g(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Fe(l,a)),l.$setFocusCellForSelection(Fe(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&t.$isRangeSelection(o)&&o.isCollapsed()){const e=Re(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Fe(l,e)),l.$setFocusCellForSelection(Fe(l,c),!0),l.pointerType=null)}}}(r,n);const a=Array.from(n.observers.entries()).map(([e,[n]])=>({tableNode:t.$getNodeByKeyOrThrow(e),tableObserver:n}));for(const{tableNode:e,tableObserver:t}of a)ue(o,e,t);return!1}function ue(e,n,o){const r=t.$getSelection(),l=t.$getPreviousSelection();r&&!r.is(l)&&(X(r)||X(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(X(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!X(r)&&X(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),pe(t.table,t=>{const n=t.elem;t.highlighted=!1,$e(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),pe(t.table,t=>{t.highlighted=!0,Te(e,t)})}(e,o)}function de(e){return e[Z]||null}function he(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function ge(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function fe(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=te(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function me(e,t,n){const o=new Set(n?n.getNodes():[]);pe(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Te(e,t)):(t.highlighted=!1,$e(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function pe(e,n){const{domRows:o}=e;for(let e=0;e<o.length;e++){const r=o[e];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=t.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:e})}}}const Ce=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ye(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ye(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?ye(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ye(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function _e(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function Se([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Ne(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&g(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&g(250,n,String(s)),i}function be(e,t,n,o,r){const l=W(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=_e(e,t);return null===n&&g(249,t.cell.getKey()),n}(l,n),[h,f]=Se(d);let m=l[h],p=l[f];"forward"===r?m+="maxColumn"===h?1:a:"backward"===r?m-="minColumn"===h?1:u:"down"===r?p+="maxRow"===f?1:i:"up"===r&&(p-="minRow"===f?1:c);const C=t[p];if(void 0===C)return!1;const _=C[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=W(e,t,n),r=_e(o,t);if(r)return[Ne(e,o,r),Ne(e,o,Se(r))];const l=_e(o,n);if(l)return[Ne(e,o,Se(l)),Ne(e,o,l)];const s=["minColumn","minRow"];return[Ne(e,o,s),Ne(e,o,Se(s))]}(t,n,_),b=Fe(e,S.cell),w=Fe(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function we(e,n){if(t.$isRangeSelection(e)||X(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function ye(e,t){t?e.selectStart():e.selectEnd()}function Te(n,o){const r=o.elem,l=n._config.theme;d(t.$getNearestNodeFromDOMNode(r))||g(131),e.addClassNamesToElement(r,l.tableCellSelected)}function $e(n,o){const r=o.elem;d(t.$getNearestNodeFromDOMNode(r))||g(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function Re(t){const n=e.$findMatchingParent(t,d);return d(n)?n:null}function xe(t){const n=e.$findMatchingParent(t,Ye);return Ye(n)?n:null}function Me(n,o,r,l,s,i,a){const c=t.$caretFromPoint(r.focus,s?"previous":"next");if(t.$isExtendableTextPointCaret(c))return!1;let u=c;for(const e of t.$extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!t.$isSiblingCaret(e)||!t.$isElementNode(e.origin))return!1;u=e}const h=u.getParentAtCaret();if(!d(h))return!1;const g=h,f=function(e){for(const n of t.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:o}=n;if(d(o)){if(t.$isChildCaret(n))return t.$getChildCaret(o,e.direction)}else if(!C(o))break}return null}(t.$getSiblingCaret(g,u.direction)),m=e.$findMatchingParent(g,Ye);if(!m||!m.is(i))return!1;const p=n.getElementByKey(g.getKey()),_=he(p);if(!p||!_)return!1;const S=We(n,m);if(a.table=S,f)if("extend"===l){const e=he(n.getElementByKey(f.origin.getKey()));if(!e)return!1;a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(e,!0)}else{const e=t.$normalizeCaret(f);t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}else if("extend"===l)a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(_,!0);else{const e=function(e){const n=t.$getAdjacentChildCaret(e);return t.$isChildCaret(n)?t.$normalizeCaret(n):e}(t.$getSiblingCaret(m,c.direction));t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}return Oe(o),!0}function Ee(n,o,r,l,s,i){if(("up"===r||"down"===r)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(n))return!1;const a=t.$getSelection();if(!we(a,l)){if(t.$isRangeSelection(a)){if("backward"===r){if(a.focus.offset>0)return!1;const e=function(e){for(let n=e,o=e;null!==o;n=o,o=o.getParent())if(t.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(a.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Ye(n)&&(Oe(o),o.shiftKey?a.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=a.focus.getNode();if(!a.isCollapsed()&&("up"===r&&!a.isBackward()||"down"===r&&a.isBackward())){let s=e.$findMatchingParent(n,e=>Ye(e));if(d(s)&&(s=e.$findMatchingParent(s,Ye)),s!==l)return!1;if(!s)return!1;const i="down"===r?s.getNextSibling():s.getPreviousSibling();if(!i)return!1;let c=0;"up"===r&&t.$isElementNode(i)&&(c=i.getChildrenSize());let u=i;if("up"===r&&t.$isElementNode(i)){const e=i.getLastChild();u=e||i,c=t.$isTextNode(u)?u.getTextContentSize():0}const h=a.clone();return h.focus.set(u.getKey(),c,t.$isTextNode(u)?"text":"element"),t.$setSelection(h),Oe(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?a.getNodes()[a.getNodes().length-1]:a.getNodes()[0];if(e){if(null!==oe(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=H(e),[o]=H(t),r=l.getCordsFromCellNode(n,s.table),i=l.getCordsFromCellNode(o,s.table),a=l.getDOMCellFromCordsOrThrow(r.x,r.y,s.table),c=l.getDOMCellFromCordsOrThrow(i.x,i.y,s.table);return s.$setAnchorCellForSelection(a),s.$setFocusCellForSelection(c,!0),!0}}return!1}{let l=e.$findMatchingParent(n,e=>t.$isElementNode(e)&&!e.isInline());if(d(l)&&(l=e.$findMatchingParent(l,Ye)),!l)return!1;const i="down"===r?l.getNextSibling():l.getPreviousSibling();if(Ye(i)&&s.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[l]=H(e),[s]=H(n),c=a.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),Oe(o),t.$setSelection(c),!0}}}}return"down"===r&&ke(n)&&i.setShouldCheckSelectionForTable(l.getKey()),!1}if(t.$isRangeSelection(a)){if("backward"===r||"forward"===r){return Me(n,o,a,o.shiftKey?"extend":"move","backward"===r,l,s)}if(a.isCollapsed()){const{anchor:c,focus:u}=a,h=e.$findMatchingParent(c.getNode(),d),g=e.$findMatchingParent(u.getNode(),d);if(!d(h)||!h.is(g))return!1;const f=xe(h);if(f!==l&&null!=f){const e=te(f,n.getElementByKey(f.getKey()));if(null!=e)return s.table=fe(f,e),Ee(n,o,r,f,s,i)}const m=n.getElementByKey(h.__key),p=n.getElementByKey(c.key);if(null==p||null==m)return!1;let C;if("element"===c.type)C=p.getBoundingClientRect();else{const e=t.getDOMSelection(ne(n));if(null===e||0===e.rangeCount)return!1;C=e.getRangeAt(0).getBoundingClientRect()}const _="up"===r?h.getFirstChild():h.getLastChild();if(null==_)return!1;const S=n.getElementByKey(_.__key);if(null==S)return!1;const N=S.getBoundingClientRect();if("up"===r?N.top>C.top-C.height:C.bottom+C.height>N.bottom){Oe(o);const e=l.getCordsFromCellNode(h,s.table);if(!o.shiftKey)return Ce(s,l,e.x,e.y,r);{const t=l.getDOMCellFromCordsOrThrow(e.x,e.y,s.table);s.$setAnchorCellForSelection(t),s.$setFocusCellForSelection(t,!0)}return!0}}}else if(X(a)){const{anchor:t,focus:i,tableKey:c}=a;if(c!==l.getKey())return!1;const u=e.$findMatchingParent(t.getNode(),d),h=e.$findMatchingParent(i.getNode(),d),[f]=a.getNodes();Ye(f)||g(251);const m=te(f,n.getElementByKey(f.getKey()));if(!d(u)||!d(h)||!Ye(f)||null==m)return!1;s.$updateTableTableSelection(a);const p=fe(f,m),C=l.getCordsFromCellNode(u,p),_=l.getDOMCellFromCordsOrThrow(C.x,C.y,p);if(s.$setAnchorCellForSelection(_),Oe(o),o.shiftKey){const[e,t,n]=k(l,u,h);return be(s,e,t,n,r)}return h.selectEnd(),!0}return!1}function Oe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ae(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function ve(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(ne(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),c=te(r,n.getElementByKey(r.getKey()));if(!i||!a||!c||!a.contains(i)||c.contains(i))return;const u=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!u)return;const h=e.$findMatchingParent(u,e=>Ye(e));if(!Ye(h)||!h.is(r))return;const[g,f]=k(r,u,u),m=g[0][0],p=g[g.length-1][g[0].length-1],{startRow:C,startColumn:_}=f,S=C===m.startRow&&_===m.startColumn,N=C===p.startRow&&_===p.startColumn;return S?"first":N?"last":void 0}function Fe(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Pe(e,n,o){return oe(e,t.$getNearestNodeFromDOMNode(n,o))}function Ke(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function De(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const Ie=new WeakSet;function ke(e=t.$getEditor()){return Ie.has(e)}function Le(e,t){t?Ie.add(e):Ie.delete(e)}class He extends t.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new He(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Be,priority:1})}}static importJSON(e){return ze().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=ee(e)?e:e.querySelector("table");return ee(t)||g(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table");this.__style&&t.setDOMStyleFromCSS(r.style,this.__style);const l=document.createElement("colgroup");if(r.appendChild(l),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),this.updateTableElement(null,r,n),ke(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.overflowX="auto",t.appendChild(r),this.updateTableWrapper(null,t,r,n),t}return r}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(n,o,r){this.__style!==(n?n.__style:"")&&t.setDOMStyleFromCSS(o.style,this.__style,n?n.__style:""),this.__rowStriping!==(!!n&&n.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(o,r,this.__rowStriping);const l=n?n.getColumnCount():0,s=n?n.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||Ke(o,this.getColumnCount(),this.getColWidths()),De(o,r,this.getFormatType())}updateDOM(t,n,o){const r=te(this,n);return n===r===ke()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Ke(te(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!ee(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!ee(o))return null;De(o,t._config,this.getFormatType());const[r]=L(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const e=document.createElement("tbody");for(const t of a)e.appendChild(t);o.append(e)}return o},element:!ee(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=Pe(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,n,o){const r=this.getDOMCellFromCords(e,n,o);if(null==r)return null;const l=t.$getNearestNodeFromDOMNode(r.elem);return d(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{d(e)&&(t+=e.getColSpan())}),t}}function We(e,t){const n=e.getElementByKey(t.getKey());return null===n&&g(230),fe(t,n)}function Be(t){const n=ze();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,C),node:n}}function ze(){return t.$applyNodeReplacement(new He)}function Ye(e){return e instanceof He}function Ue(e){C(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Xe(t){Ye(t.getParent())?e.$unwrapAndFilterDescendants(t,d):t.remove()}function Ge(n){e.$unwrapAndFilterDescendants(n,C);const[o]=L(n,null,null),r=o.reduce((e,t)=>Math.max(e,t.length),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;C(n)||g(254,n.constructor.name,n.getType());const s=o[e].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let e=s;e<r;++e){const e=u();e.append(t.$createParagraphNode()),n.append(e)}}const s=n.getColWidths(),i=n.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}n.setColWidths(e)}}function qe(n){if(n.detail<3||!t.isDOMNode(n.target))return!1;const o=t.$getNearestNodeFromDOMNode(n.target);if(null===o)return!1;const r=e.$findMatchingParent(o,e=>t.$isElementNode(e)&&!e.isInline());if(null===r)return!1;return!!d(r.getParent())&&(r.select(0),!0)}function Je(){const e=t.$getSelection();if(!t.$isRangeSelection(e))return!1;const n=xe(e.anchor.getNode());if(null===n)return!1;const o=t.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=L(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=q(n,l.cell,i.cell);return t.$setSelection(a),!0}function je(t){return t.registerNodeTransform(i,t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=H(t),[o]=k(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();C(s)||g(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),C(s)||g(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],a=l.cell;if(l.startRow===t&&l.startColumn===r)n=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){d(a)||g(176);const t=u(a.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Ve(n,o=!0){const r=new V,l=(e,t,l)=>{const s=te(e,l),i=ae(e,s,n,o,r);r.observers.set(t,[i,s])};return e.mergeRegister(ie(n,r),n.registerCommand(t.SELECTION_CHANGE_COMMAND,()=>ce(r,n),t.COMMAND_PRIORITY_HIGH),n.registerMutationListener(He,e=>{n.getEditorState().read(()=>{for(const[t,n]of e){const e=r.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:o}=j(t);void 0===e?l(n,t,o):o!==e[1]&&(e[0].removeListeners(),r.observers.delete(t),l(n,t,o))}else"destroyed"===n&&void 0!==e&&(e[0].removeListeners(),r.observers.delete(t))}},{editor:n})},{skipInitialization:!1}),()=>{for(const[,[e]]of r.observers)e.removeListeners()})}function Qe(o,r){o.hasNodes([He])||g(255);const{hasNestedTables:l=n.signal(!1)}=r??{};return e.mergeRegister(o.registerCommand(h,n=>function({rows:n,columns:o,includeHeaders:r},l){const s=t.$getSelection()||t.$getPreviousSelection();if(!s||!t.$isRangeSelection(s))return!1;if(!l&&xe(s.anchor.getNode()))return!1;const i=_(Number(n),Number(o),r);e.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return t.$isTextNode(a)&&a.select(),!0}(n,l.peek()),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n,r)=>o===r&&function(n,o){const{nodes:r,selection:l}=n;if(!r.some(t=>Ye(t)||e.$dfs(t).some(e=>Ye(e.node))))return!1;const s=X(l),i=t.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>d(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>d(e))||s))return!1;if(1===r.length&&Ye(r[0]))return function(n,o){const r=o.getStartEndPoints(),l=X(o);if(null===r)return!1;const[s,i]=r,[a,c,u]=H(s),h=e.$findMatchingParent(i.getNode(),e=>d(e));if(!(d(a)&&d(h)&&C(c)&&Ye(u)))return!1;const[g,f,m]=k(u,a,h),[p]=L(n,null,null),_=g.length,S=_>0?g[0].length:0;let N=f.startRow,b=f.startColumn,w=p.length,y=w>0?p[0].length:0;if(l){const e=W(g,f,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;N=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let T=!1;const R=Math.min(_,N+w)-1,x=Math.min(S,b+y)-1,E=new Set;for(let e=N;e<=R;e++)for(let t=b;t<=x;t++){const n=g[e][t];E.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(I(n.cell),E.add(n.cell.getKey()),T=!0))}let[O]=L(u.getWritable(),null,null);const A=w-_+N;for(let e=0;e<A;e++){$(O[_-1][0].cell)}const v=y-S+b;for(let e=0;e<v;e++){M(O[0][S-1].cell,!0,!1)}[O]=L(u.getWritable(),null,null);for(let e=N;e<N+w;e++)for(let n=b;n<b+y;n++){const o=e-N,r=n-b,l=p[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const t=[],o=Math.min(e+s.__rowSpan,N+w)-1,r=Math.min(n+s.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=n;e<=r;e++){const n=O[l][e];t.push(n.cell)}K(t),T=!0}const{cell:i}=O[e][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),i.append(e)}else i.append(e)}),c.forEach(e=>e.remove())}if(l&&T){const[e]=L(u.getWritable(),null,null);e[f.startRow][f.startColumn].cell.selectEnd()}return!0}(r[0],l);if(i&&o.peek()&&!function(e){if(X(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(t.$isRangeSelection(e)&&d(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(l))return!1;return!0}(n,l),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECT_ALL_COMMAND,Je,t.COMMAND_PRIORITY_LOW),o.registerCommand(t.CLICK_COMMAND,qe,t.COMMAND_PRIORITY_EDITOR),o.registerNodeTransform(He,Ge),o.registerNodeTransform(f,Xe),o.registerNodeTransform(i,Ue))}const Ze=t.defineExtension({build:(e,t,o)=>n.namedSignals(t),config:t.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[He,f,i],register(o,r,l){const s=l.getOutput();return e.mergeRegister(n.effect(()=>{const e=s.hasHorizontalScroll.value;ke(o)!==e&&(Le(o,e),o.update(t.$fullReconcile))}),Qe(o,s),n.effect(()=>Ve(o,s.hasTabHandler.value)),n.effect(()=>s.hasCellMerge.value?void 0:je(o)),n.effect(()=>s.hasCellBackgroundColor.value?void 0:o.registerNodeTransform(i,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});const et={$accepts:C,$packageRun:e=>e.every(d)?[p().splice(0,0,e)]:[],name:"TableSchema"},tt={$accepts:d,name:"TableRowSchema"},nt=[r.defineImportRule({$import:(t,n)=>{const o=ze();n.hasAttribute("data-lexical-row-striping")&&o.setRowStriping(!0),n.hasAttribute("data-lexical-frozen-column")&&o.setFrozenColumns(1),n.hasAttribute("data-lexical-frozen-row")&&o.setFrozenRows(1);const r=n.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&o.setColWidths(e)}return[o.splice(0,0,e.$descendantsMatching(t.$importChildren(n),C))]},match:r.sel.tag("table"),name:"@lexical/table/table"}),r.defineImportRule({$import:(t,n)=>[p(l.test(n.style.height)?parseFloat(n.style.height):void 0).splice(0,0,e.$descendantsMatching(t.$importChildren(n),d))],match:r.sel.tag("tr"),name:"@lexical/table/tr"}),r.defineImportRule({$import:(e,n)=>{const o="TH"===n.nodeName,i=l.test(n.style.width)?parseFloat(n.style.width):void 0;let a=s.NO_STATUS;if(o){const e=n.getAttribute("scope");if("col"===e)a=s.COLUMN;else if("row"===e)a=s.ROW;else{const e=n.parentElement,o=t.isHTMLTableRowElement(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),r=0===n.cellIndex;o&&(a|=s.ROW),r&&(a|=s.COLUMN),a===s.NO_STATUS&&(a=s.ROW)}}const c=u(a,n.colSpan,i);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(c.__verticalAlign=h);const g=e.get(r.ImportTextFormat),f=g|function(e){let n=0;const o=e.fontWeight;"700"!==o&&"bold"!==o||(n|=t.IS_BOLD),"italic"===e.fontStyle&&(n|=t.IS_ITALIC);const r=(e.textDecoration||"").split(" ");return r.includes("underline")&&(n|=t.IS_UNDERLINE),r.includes("line-through")&&(n|=t.IS_STRIKETHROUGH),n}(n.style),m=e.get(r.ImportTextStyle),p=n.style.color,C=p?{...m,color:p}:m,_=[];f!==g&&_.push(r.contextValue(r.ImportTextFormat,f)),C!==m&&_.push(r.contextValue(r.ImportTextStyle,C));const S=function(e){const n=[];let o=null;const r=()=>{if(null!==o){const e=o.getFirstChild();t.$isLineBreakNode(e)&&1===o.getChildrenSize()&&e.remove()}};for(const l of e)t.$isInlineElementOrDecoratorNode(l)||t.$isTextNode(l)||t.$isLineBreakNode(l)?null!==o?o.append(l):(o=t.$createParagraphNode().append(l),n.push(o)):(r(),o=null,n.push(l));return r(),0===n.length&&n.push(t.$createParagraphNode()),n}(e.$importChildren(n,{context:_})),N=o?S:r.$propagateTextAlignToBlockChildren(S,n);return[c.splice(0,0,N)]},match:r.sel.tag("td","th"),name:"@lexical/table/cell"})],ot=t.defineExtension({dependencies:[Ze,t.configExtension(r.DOMImportExtension,{rules:nt})],name:"@lexical/table/Import"});exports.$computeTableMap=k,exports.$computeTableMapSkipCellCheck=L,exports.$createTableCellNode=u,exports.$createTableNode=ze,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=p,exports.$createTableSelection=G,exports.$createTableSelectionFrom=q,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumnAtSelection=A,exports.$deleteTableColumn__EXPERIMENTAL=v,exports.$deleteTableRowAtSelection=E,exports.$deleteTableRow__EXPERIMENTAL=O,exports.$findCellNode=Re,exports.$findTableNode=xe,exports.$getElementForTableNode=We,exports.$getNodeTriplet=H,exports.$getTableAndElementByKey=j,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>d(e));return d(n)?n:null},exports.$getTableCellNodeRect=z,exports.$getTableColumnIndexFromTableCellNode=function(e){return S(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=N,exports.$getTableRowIndexFromTableCellNode=function(e){const t=S(e);return N(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=S,exports.$insertTableColumn=function(e,n,o=!0,r,l){const i=e.getChildren(),a=[];for(let e=0;e<i.length;e++){const o=i[e];if(C(o))for(let e=0;e<r;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const r=e[n];d(r)||g(12);const{left:i,right:c}=b(r,l);let h=s.NO_STATUS;(i&&i.hasHeaderState(s.ROW)||c&&c.hasHeaderState(s.ROW))&&(h|=s.ROW);const f=u(h);f.append(t.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),e},exports.$insertTableColumnAtSelection=R,exports.$insertTableColumn__EXPERIMENTAL=x,exports.$insertTableRow=function(e,n,o=!0,r,l){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let e=0;e<r;e++){const e=a.getChildren(),n=e.length,r=p();for(let o=0;o<n;o++){const n=e[o];d(n)||g(12);const{above:i,below:a}=b(n,l);let c=s.NO_STATUS;const h=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(s.COLUMN)||a&&a.hasHeaderState(s.COLUMN))&&(c|=s.COLUMN);const f=u(c,1,h);f.append(t.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return e},exports.$insertTableRowAtSelection=y,exports.$insertTableRow__EXPERIMENTAL=T,exports.$isScrollableTablesActive=ke,exports.$isSimpleTable=B,exports.$isTableCellNode=d,exports.$isTableNode=Ye,exports.$isTableRowNode=C,exports.$isTableSelection=X,exports.$mergeCells=K,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!B(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const n=t.$getSelection();t.$isRangeSelection(n)||X(n)||g(188);const o=n.anchor.getNode(),r=e.$findMatchingParent(o,d);return d(r)||g(148),I(r)},exports.INSERT_TABLE_COMMAND=h,exports.TableCellHeaderStates=s,exports.TableCellNode=i,exports.TableExtension=Ze,exports.TableImportExtension=ot,exports.TableImportRules=nt,exports.TableNode=He,exports.TableObserver=Q,exports.TableRowNode=f,exports.TableRowSchema=tt,exports.TableSchema=et,exports.applyTableHandlers=ae,exports.getDOMCellFromTarget=he,exports.getTableElement=te,exports.getTableObserverFromTableElement=de,exports.registerTableCellUnmergeTransform=je,exports.registerTablePlugin=Qe,exports.registerTableSelectionObserver=Ve,exports.setScrollableTablesActive=Le;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$dfs as a,$unwrapAndFilterDescendants as u}from"@lexical/utils";import{ElementNode as h,isHTMLElement as d,$isInlineElementOrDecoratorNode as f,$isTextNode as g,$isLineBreakNode as m,$createParagraphNode as p,$applyNodeReplacement as C,createCommand as _,$createTextNode as S,$getSelection as b,$isRangeSelection as w,$isParagraphNode as y,$createPoint as N,$getNodeByKey as v,$isElementNode as x,$normalizeSelection__EXPERIMENTAL as T,isCurrentlyReadOnlyMode as F,TEXT_TYPE_TO_FORMAT as R,$getEditor as O,$setSelection as A,SELECTION_CHANGE_COMMAND as K,getDOMSelection as E,$createRangeSelection as k,$isRootNode as M,INSERT_PARAGRAPH_COMMAND as $,KEY_ARROW_DOWN_COMMAND as W,KEY_ARROW_UP_COMMAND as z,KEY_ARROW_LEFT_COMMAND as L,KEY_ARROW_RIGHT_COMMAND as H,COMMAND_PRIORITY_HIGH as B,KEY_ESCAPE_COMMAND as P,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as I,DELETE_CHARACTER_COMMAND as U,KEY_BACKSPACE_COMMAND as J,KEY_DELETE_COMMAND as X,CUT_COMMAND as Y,FORMAT_TEXT_COMMAND as q,FORMAT_ELEMENT_COMMAND as j,CONTROLLED_TEXT_INSERTION_COMMAND as V,KEY_TAB_COMMAND as G,FOCUS_COMMAND as Q,$getNearestNodeFromDOMNode as Z,isDOMNode as ee,$isRootOrShadowRoot as te,$getPreviousSelection as ne,$getNodeByKeyOrThrow as oe,$caretFromPoint as re,$isExtendableTextPointCaret as le,$extendCaretToRange as se,$isSiblingCaret as ie,$getSiblingCaret as ce,$setPointFromCaret as ae,$normalizeCaret as ue,$createRangeSelectionFromDom as he,$isChildCaret as de,$getChildCaret as fe,$getAdjacentChildCaret as ge,IS_FIREFOX as me,setDOMStyleFromCSS as pe,setDOMUnmanaged as Ce,COMMAND_PRIORITY_EDITOR as _e,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Se,SELECT_ALL_COMMAND as be,COMMAND_PRIORITY_LOW as we,CLICK_COMMAND as ye,$getRoot as Ne,defineExtension as ve,$fullReconcile as xe,safeCast as Te,configExtension as Fe,isHTMLTableRowElement as Re,IS_BOLD as Oe,IS_ITALIC as Ae,IS_UNDERLINE as Ke,IS_STRIKETHROUGH as Ee}from"lexical";import{signal as ke,effect as Me,namedSignals as $e}from"@lexical/extension";import{copyToClipboard as We,$getClipboardDataFromSelection as ze}from"@lexical/clipboard";import{CoreImportExtension as Le,DOMImportExtension as He,defineImportRule as Be,sel as Pe,ImportTextFormat as De,ImportTextStyle as Ie,contextValue as Ue}from"@lexical/html";const Je=/^(\d+(?:\.\d+)?)px$/,Xe={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Ye extends h{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new Ye(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:je,priority:0}),th:e=>({conversion:je,priority:0})}}static importJSON(e){return Ve().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=Xe.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),qe(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(d(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...qe(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=Xe.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Xe.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function qe(e){return"middle"===e||"bottom"===e}function je(e){const t=e,n=e.nodeName.toLowerCase();let o;Je.test(t.style.width)&&(o=parseFloat(t.style.width));let r=Xe.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)r=Xe.COLUMN;else if("row"===e)r=Xe.ROW;else{const e=t.parentElement,n=d(e)&&"tr"===e.nodeName.toLowerCase()&&d(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),o=0===t.cellIndex;n&&(r|=Xe.ROW),o&&(r|=Xe.COLUMN),r===Xe.NO_STATUS&&(r=Xe.ROW)}}const l=Ve(r,t.colSpan,o);l.__rowSpan=t.rowSpan;const s=t.style.backgroundColor;""!==s&&(l.__backgroundColor=s);const i=t.style.verticalAlign;qe(i)&&(l.__verticalAlign=i);const c=t.style,a=(c&&c.textDecoration||"").split(" "),u="700"===c.fontWeight||"bold"===c.fontWeight,h=a.includes("line-through"),C="italic"===c.fontStyle,_=a.includes("underline"),S=c.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();m(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)if(f(r)||g(r)||m(r)){if(g(r)&&(u&&r.toggleFormat("bold"),h&&r.toggleFormat("strikethrough"),C&&r.toggleFormat("italic"),_&&r.toggleFormat("underline"),S)){const e=r.getStyle();e.includes("color:")||r.setStyle(e+`color: ${S};`)}n?n.append(r):(n=p().append(r),t.push(n))}else t.push(r),o(),n=null;return o(),0===t.length&&t.push(p()),t},node:l}}function Ve(e=Xe.NO_STATUS,t=1,n){return C(new Ye(e,t,n))}function Ge(e){return e instanceof Ye}const Qe=_("INSERT_TABLE_COMMAND");function Ze(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class et extends h{__height;static getType(){return"tablerow"}static clone(e){return new et(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:tt,priority:0})}}static importJSON(e){return nt().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function tt(e){const n=e;let o;return Je.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,Ge),node:nt(o)}}function nt(e){return C(new et(e))}function ot(e){return e instanceof et}function rt(e,t,n=!0){const o=Hn();for(let r=0;r<e;r++){const e=nt();for(let o=0;o<t;o++){let t=Xe.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Xe.ROW),0===o&&n.columns&&(t|=Xe.COLUMN)):n&&(0===r&&(t|=Xe.ROW),0===o&&(t|=Xe.COLUMN));const l=Ve(t),s=p();s.append(S()),l.append(s),e.append(l)}o.append(e)}return o}function lt(e){const t=n(e,e=>Ge(e));return Ge(t)?t:null}function st(e){const t=n(e,e=>ot(e));if(ot(t))return t;throw new Error("Expected table cell to be inside of table row.")}function it(e){const t=n(e,e=>Bn(e));if(Bn(t))return t;throw new Error("Expected table cell to be inside of table.")}function ct(e){const t=st(e);return it(t).getChildren().findIndex(e=>e.is(t))}function at(e){return st(e).getChildren().findIndex(t=>t.is(e))}function ut(e,t){const n=it(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function ht(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function dt(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!ot(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=nt();for(let n=0;n<t;n++){const t=e[n];Ge(t)||Ze(12);const{above:l,below:s}=ut(t,r);let i=Xe.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(Xe.COLUMN)||s&&s.hasHeaderState(Xe.COLUMN))&&(i|=Xe.COLUMN);const a=Ve(i,1,c);a.append(p()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}const ft=(e,t)=>e===Xe.BOTH||e===t?t:Xe.NO_STATUS;function gt(e=!0){const t=b();w(t)||Pt(t)||Ze(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Mt(n),[l,,s]=Mt(o),[,i,c]=Et(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?pt(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):pt(u<a?l:r,!1)}const mt=gt;function pt(e,t=!0){const[,,n]=Mt(e),[o,r]=Et(n,e,e),l=o[0].length,{startRow:s}=r;let i=null;if(t){const t=s+e.__rowSpan-1,r=o[t],c=nt();for(let e=0;e<l;e++){const{cell:n,startRow:o}=r[e];if(o+n.__rowSpan-1<=t){const t=r[e].cell.__headerState,n=ft(t,Xe.COLUMN);c.append(Ve(n).append(p()))}else n.setRowSpan(n.__rowSpan+1)}const a=n.getChildAtIndex(t);ot(a)||Ze(256),a.insertAfter(c),i=c}else{const e=s,t=o[e],r=nt();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=ft(e,Xe.COLUMN);r.append(Ve(o).append(p()))}else o.setRowSpan(o.__rowSpan+1)}const c=n.getChildAtIndex(e);ot(c)||Ze(257),c.insertBefore(r),i=r}return i}function Ct(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(ot(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];Ge(o)||Ze(12);const{left:l,right:i}=ut(o,r);let c=Xe.NO_STATUS;(l&&l.hasHeaderState(Xe.ROW)||i&&i.hasHeaderState(Xe.ROW))&&(c|=Xe.ROW);const a=Ve(c);a.append(p()),s.push({newTableCell:a,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function _t(e=!0){const t=b();w(t)||Pt(t)||Ze(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Mt(n),[l,,s]=Mt(o),[,i,c]=Et(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?bt(a+r.__colSpan>u+l.__colSpan?r:l,!0):bt(u<a?l:r,!1)}const St=_t;function bt(e,t=!0,n=!0){const[,,o]=Mt(e),[r,l]=Et(o,e,e),s=r.length,{startColumn:i}=l,c=t?i+e.__colSpan-1:i-1,a=o.getFirstChild();ot(a)||Ze(120);let u=null;function h(e=Xe.NO_STATUS){const t=Ve(e).append(p());return null===u&&(u=t),t}let d=a;e:for(let e=0;e<s;e++){if(0!==e){const e=d.getNextSibling();ot(e)||Ze(121),d=e}const t=r[e],n=t[c<0?0:c].cell.__headerState,o=ft(n,Xe.ROW);if(c<0){Ft(d,h(o));continue}const{cell:l,startColumn:s,startRow:i}=t[c];if(s+l.__colSpan-1<=c){let n=l,r=i,s=c;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){d.append(h(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(h(o))}else l.setColSpan(l.__colSpan+1)}null!==u&&n&&Tt(u);const f=o.getColWidths();if(f){const e=[...f],t=c<0?0:c,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return u}function wt(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ot(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function yt(){const e=b();w(e)||Pt(e)||Ze(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Mt(t),[l]=Mt(n),[s,i,c]=Et(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=s[h+1],g=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>h){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=a&&o+n.__rowSpan-1>h&&e===h){null===g&&Ze(122);let o=null;for(let n=0;n<t;n++){const t=f[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?Ft(g,n):o.insertAfter(n)}}}const t=r.getChildAtIndex(e);ot(t)||Ze(206,String(e)),t.remove()}if(void 0!==f){const{cell:e}=f[0];Tt(e)}else{const e=s[a-1],{cell:t}=e[0];Tt(t)}}const Nt=yt;function vt(){const e=b();w(e)||Pt(e)||Ze(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Mt(t),[l]=Mt(n),[s,i,c]=Et(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e))}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;Tt(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Tt(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}const xt=vt;function Tt(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ft(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Rt(e){if(0===e.length)return null;const t=it(e[0]),[n]=kt(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const i=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!i.has(t)&&e.some(e=>e.is(n.cell))){i.add(t);const e=n.startRow,c=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,c),s=Math.max(s,c+u-1)}}if(o===1/0||l===1/0)return null;const c=r-o+1,a=s-l+1,u=n[o][l];if(!u.cell)return null;const h=u.cell;h.setColSpan(a),h.setRowSpan(c);const d=new Set([h.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!d.has(l)){d.add(l);Ot(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(p()),h}function Ot(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!y(t)||!t.isEmpty())}function At(){const e=b();w(e)||Pt(e)||Ze(188);const t=e.anchor.getNode(),o=n(t,Ge);return Ge(o)||Ze(148),Kt(o)}function Kt(e){const[t,n,o]=Mt(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,i]=Et(o,t,t),{startColumn:c,startRow:a}=i,u=t.__headerState&Xe.COLUMN,h=Array.from({length:r},(e,t)=>{let n=u;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+c].cell.__headerState;return n}),d=t.__headerState&Xe.ROW,f=Array.from({length:l},(e,t)=>{let n=d;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+a][e].cell.__headerState;return n});if(r>1){for(let e=1;e<r;e++)t.insertAfter(Ve(h[e]|f[0]).append(p()));t.setColSpan(1)}if(l>1){let e;for(let t=1;t<l;t++){const o=a+t,l=s[o];e=(e||n).getNextSibling(),ot(e)||Ze(125);let i=null;for(let e=0;e<c;e++){const t=l[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let n=r-1;n>=0;n--)Ft(e,Ve(h[n]|f[t]).append(p()));else for(let e=r-1;e>=0;e--)i.insertAfter(Ve(h[e]|f[t]).append(p()))}t.setRowSpan(1)}}function Et(e,t,n){const[o,r,l]=kt(e,t,n);return null===r&&Ze(207),null===l&&Ze(208),[o,r,l]}function kt(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];ot(o)||Ze(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(Ge(a)||Ze(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o)}}return[o,r,l]}function Mt(e){let t;if(e instanceof Ye)t=e;else if("__type"in e){const o=n(e,Ge);Ge(o)||Ze(148),t=o}else{const o=n(e.getNode(),Ge);Ge(o)||Ze(148),t=o}const o=t.getParent();ot(o)||Ze(149);const r=o.getParent();return Bn(r)||Ze(210),[t,o,r]}function $t(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function Wt(e){const t=e.getChildren();let n=null;for(const e of t){if(!ot(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!Ge(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function zt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Wt(e))return;e.getChildren().filter(ot).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}}function Lt(e){const[t,,n]=Mt(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Ht(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map(t=>{const o=e[t].getNode(),r=n(o,Ge);Ge(r)||Ze(238,t,o.getKey(),o.getType());const l=r.getParent();ot(l)||Ze(239,t);const s=l.getParent();return Bn(s)||Ze(240,t),[o,r,l,s]});return l.is(a)||Ze(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Bt{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=v(this.tableKey),t=v(this.anchor.key),n=v(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Pt(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Bt(this.tableKey,N(this.anchor.key,this.anchor.offset,this.anchor.type),N(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(Ge).forEach(e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())});const n=R[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();x(t)||Ze(151);T(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Ht(this),n=Lt(e);null===n&&Ze(153);const o=Lt(t);null===o&&Ze(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Ht(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Ze(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&Ze(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Et(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=$t(l,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();ot(o)||Ze(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||Ut(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return F()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>Ge(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function Pt(e){return e instanceof Bt}function Dt(){const e=N("root",0,"element"),t=N("root",0,"element");return new Bt("root",e,t)}function It(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=b(),r=Pt(o)?o.clone():Dt();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function Ut(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&x(o)&&n.push(o.getChildren())}}function Jt(e,t=O()){const n=v(e);Bn(n)||Ze(231,e);const o=Vt(n,t.getElementByKey(e));return null===o&&Ze(232,e),{tableElement:o,tableNode:n}}class Xt{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class Yt{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Jt(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.getEditorState().read(()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=un(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=un(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const t=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:n,tableElement:o}=this.$lookup();hn(t,un(n,o),null),e&&null!==b()&&(A(null),t.dispatchCommand(K,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Ze(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),hn(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=E(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==r||this.anchorY!==l||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&r===this.focusX&&l===this.focusY)return!1;if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const s=An(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(r,l,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=It(o,t,e),A(this.tableSelection),n.dispatchCommand(K,void 0),hn(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Ze(234),e}$getFocusTableCell(){return this.focusCellNodeKey?v(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Ze(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=An(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=It(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=b();Pt(t)||Ze(236);const n=k(),o=n.anchor,r=n.focus,l=t.getNodes().filter(Ge);l.length>0||Ze(237);const s=l[0].getFirstChild(),i=y(s)?s.getFormatFlags(e,null):null;l.forEach(t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),A(t),this.editor.dispatchCommand(K,void 0)}$clearText(){const{editor:e}=this,t=v(this.tableNodeKey);if(!Bn(t))throw new Error("Expected TableNode.");const n=b();Pt(n)||Ze(253);const o=n.getNodes().filter(Ge),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&ot(r)&&ot(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(M(n)&&n.isEmpty()&&e.dispatchCommand($,void 0))}o.forEach(e=>{if(x(e)){const t=p(),n=S();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),hn(e,this.table,null),A(null),e.dispatchCommand(K,void 0)}}const qt="__lexicalTableSelection";function jt(e){return d(e)&&"TABLE"===e.nodeName}function Vt(e,t){if(!t)return t;const n=jt(t)?t:t.querySelector("table");return jt(n)||Ze(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function Gt(e){return e._window}function Qt(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;Ge(n)&&(o=n)}return null}const Zt=[[W,"down"],[z,"up"],[L,"backward"],[H,"forward"]],en=[D,I,U],tn=[J,X];function nn(e,t){return e.registerRootListener(n=>{if(null===n)return;const o=e._window;if(null===o)return;const r=o=>{const r=o.target;if(0!==o.button||!ee(r)||!n.contains(r))return;const l=function(e){const t=cn(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&qt in n&&n[qt])return{cellElement:t,tableElement:n,tableObserver:n[qt]};n=n.parentNode}return null}(r);e.update(()=>{if(Pt(b())){for(const[e]of t.observers.values())e.$clearHighlight(!1);A(null),e.dispatchCommand(K,void 0)}if(!l)return;const{tableObserver:n,tableElement:r,cellElement:s}=l;!function(e,t,n,o,r,l){const s=e._window;if(!s)return;const i=t=>{if(r.isSelecting)return;r.isSelecting=!0,null!==t&&null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)});const n=()=>{r.isSelecting=!1,s.removeEventListener("pointerup",n),s.removeEventListener("pointermove",i)},i=t=>{if(!(e=>!(1&~e.buttons))(t)&&r.isSelecting)return r.isSelecting=!1,s.removeEventListener("pointerup",n),void s.removeEventListener("pointermove",i);if(!ee(t.target))return;let c=null;const a=!(me||o.contains(t.target));if(a)c=an(o,t.target);else for(const e of document.elementsFromPoint(t.clientX,t.clientY))if(c=an(o,e),c)break;if(c){const t=c;null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)}),null!==r.focusCell&&c.elem===r.focusCell.elem||(l.setNextFocus({focusCell:c,override:a,tableKey:r.tableNodeKey}),e.dispatchCommand(K,void 0))}};s.addEventListener("pointerup",n,r.listenerOptions),s.addEventListener("pointermove",i,r.listenerOptions)};r.pointerType=t.pointerType;const c=oe(r.tableNodeKey),a=ne();if(me&&t.shiftKey&&_n(a,c)&&(w(a)||Pt(a))){const e=a.anchor.getNode(),o=Qt(c,a.anchor.getNode());if(o)r.$setAnchorCellForSelection(On(r,o)),r.$setFocusCellForSelection(n),Tn(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&r.$setAnchorCellForSelection(n);i(n)}(e,o,s,r,n,t)})};return o.addEventListener("pointerdown",r),()=>{o.removeEventListener("pointerdown",r)}})}function on(e,t,o,l,s){const i=o.getRootElement(),c=Gt(o);null!==i&&null!==c||Ze(246);const a=new Yt(o,e.getKey()),u=Vt(e,t);!function(e,t){null!==sn(e)&&Ze(205);e[qt]=t}(u,a),a.listenersToRemove.add(()=>function(e,t){sn(e)===t&&delete e[qt]}(u,a));const h=e=>{if(e.detail>=3&&ee(e.target)){null!==cn(e.target)&&e.preventDefault()}};u.addEventListener("mousedown",h,a.listenerOptions),a.listenersToRemove.add(()=>{u.removeEventListener("mousedown",h)});for(const[t,n]of Zt)a.listenersToRemove.add(o.registerCommand(t,t=>xn(o,t,n,e,a,s),B));a.listenersToRemove.add(o.registerCommand(P,t=>{const n=b();if(Pt(n)){const o=Qt(e,n.focus.getNode());if(null!==o)return Tn(t),o.selectEnd(),!0}return!1},B));const d=t=>()=>{const o=b();if(!_n(o,e))return!1;if(Pt(o))return a.$clearText(),!0;if(w(o)){if(!Ge(Qt(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return a.$clearText(),!0;const c=n(o.anchor.getNode(),e=>x(e)),u=c&&n(c,e=>x(e)&&Ge(e.getParent()));if(!x(u)||!x(c))return!1;if(t===I&&null===u.getPreviousSibling())return!0}return!1};for(const e of en)a.listenersToRemove.add(o.registerCommand(e,d(e),B));const f=t=>{const n=b();if(!Pt(n)&&!w(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!_n(n,e)&&(!!Pt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),a.$clearText(),!0))};for(const e of tn)a.listenersToRemove.add(o.registerCommand(e,f,B));return a.listenersToRemove.add(o.registerCommand(Y,e=>{const t=b();if(t){if(!Pt(t)&&!w(t))return!1;We(o,r(e,ClipboardEvent)?e:null,ze(t));const n=f(e);return w(t)?(t.removeText(),!0):n}return!1},B)),a.listenersToRemove.add(o.registerCommand(q,t=>{const o=b();if(!_n(o,e))return!1;if(Pt(o))return a.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),e=>Ge(e));if(!Ge(e))return!1}return!1},B)),a.listenersToRemove.add(o.registerCommand(j,t=>{const n=b();if(!Pt(n)||!_n(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Ge(o)||!Ge(r))return!1;if(function(e,t){if(Pt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Et(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[l,s,i]=Et(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];x(n)&&!n.isInline()&&n.setFormat(t)}}return!0},B)),a.listenersToRemove.add(o.registerCommand(V,t=>{const r=b();if(!_n(r,e))return!1;if(Pt(r))return a.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),e=>Ge(e));if(!Ge(l))return!1;if("string"==typeof t){const n=Rn(o,r,e);if(n)return Fn(n,e,[S(t)]),!0}}return!1},B)),l&&a.listenersToRemove.add(o.registerCommand(G,t=>{const o=b();if(!w(o)||!o.isCollapsed()||!_n(o,e))return!1;const r=yn(o.anchor.getNode());return!(null===r||!e.is(Nn(r)))&&(Tn(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(x(l))return l.selectEnd();const s=n(e,ot);null===s&&Ze(247);for(let e=s[o]();ot(e);e=e[o]()){const t=e[r]();if(x(t))return t.selectEnd()}const i=n(s,Bn);null===i&&Ze(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)},B)),a.listenersToRemove.add(o.registerCommand(Q,t=>e.isSelected(),B)),a.listenersToRemove.add(o.registerCommand($,()=>{const t=b();if(!w(t)||!t.isCollapsed()||!_n(t,e))return!1;const n=Rn(o,t,e);return!!n&&(Fn(n,e),!0)},B)),a}function rn(e,t){const o=b(),r=ne(),l=e.getAndClearNextFocus();if(null!==l){const{tableKey:t,focusCell:n}=l,r=e.observers.get(t);r||Ze(335,t);const[s]=r;if(Pt(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=e.getAndClearShouldCheckSelectionForTable();if(s&&w(r)&&w(o)&&o.isCollapsed()){const e=oe(s),t=o.anchor.getNode(),r=e.getFirstChild(),l=yn(t);if(null!==l&&ot(r)){const t=r.getFirstChild();if(Ge(t)&&e.is(n(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}Pt(o)&&function(e,t){const n=Gt(e),o=ne();if(!t.is(o))return;const r=oe(t.tableKey),l=E(n);if(l&&l.anchorNode&&l.focusNode){const n=Z(l.focusNode),o=n&&!r.isParentOf(n),s=Z(l.anchorNode),i=s&&r.isParentOf(s);if(o&&i&&l.rangeCount>0){const n=he(l,e);n&&(n.anchor.set(r.getKey(),t.isBackward()?r.getChildrenSize():0,"element"),l.removeAllRanges(),A(n))}}}(t,o),w(o)&&function(e,t){const n=ne(),{anchor:o,focus:r}=e,l=o.getNode(),s=r.getNode(),i=yn(l),c=yn(s),a=i?Nn(i):null,u=c?Nn(c):null,h=e.isBackward(),d=i&&c&&a&&u&&a.is(u),f=u&&(!a||a.isParentOf(u)),g=a&&(!u||u.isParentOf(a));if(f){const t=e.clone(),[n]=Et(u,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():r.getKey(),h?0:r.getChildrenSize(),"element"),A(t)}else if(g){const t=e.clone(),[n]=Et(a,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(h?r.getKey():o.getKey(),h?r.getChildrenSize():0,"element"),A(t)}else if(d){const o=t.observers.get(a.getKey());o||Ze(335,a.getKey());const[r]=o;if(i.is(c)||(r.$setAnchorCellForSelection(On(r,i)),r.$setFocusCellForSelection(On(r,c),!0)),"touch"===r.pointerType&&r.isSelecting&&e.isCollapsed()&&w(n)&&n.isCollapsed()){const e=yn(n.anchor.getNode());e&&!e.is(c)&&(r.$setAnchorCellForSelection(On(r,e)),r.$setFocusCellForSelection(On(r,c),!0),r.pointerType=null)}}}(o,e);const i=Array.from(e.observers.entries()).map(([e,[t]])=>({tableNode:oe(e),tableObserver:t}));for(const{tableNode:e,tableObserver:n}of i)ln(t,e,n);return!1}function ln(e,t,n){const o=b(),r=ne();o&&!o.is(r)&&(Pt(o)||Pt(r))&&n.tableSelection&&!n.tableSelection.is(r)&&(Pt(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!Pt(o)&&Pt(r)&&r.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),dn(t.table,t=>{const n=t.elem;t.highlighted=!1,wn(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),dn(t.table,t=>{t.highlighted=!0,bn(e,t)})}(e,n)}function sn(e){return e[qt]||null}function cn(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function an(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function un(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=Vt(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function hn(e,t,n){const o=new Set(n?n.getNodes():[]);dn(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,bn(e,t)):(t.highlighted=!1,wn(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function dn(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=Z(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}const fn=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Sn(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Sn(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Sn(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Sn(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function gn(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function mn([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function pn(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Ze(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Ze(250,n,String(s)),i}function Cn(e,t,n,o,r){const l=$t(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=gn(e,t);return null===n&&Ze(249,t.cell.getKey()),n}(l,n),[d,f]=mn(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=$t(e,t,n),r=gn(o,t);if(r)return[pn(e,o,r),pn(e,o,mn(r))];const l=gn(o,n);if(l)return[pn(e,o,mn(l)),pn(e,o,l)];const s=["minColumn","minRow"];return[pn(e,o,s),pn(e,o,mn(s))]}(t,n,C),b=On(e,_.cell),w=On(e,S.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function _n(e,t){if(w(e)||Pt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Sn(e,t){t?e.selectStart():e.selectEnd()}function bn(t,n){const o=n.elem,r=t._config.theme;Ge(Z(o))||Ze(131),e(o,r.tableCellSelected)}function wn(e,t){const n=t.elem;Ge(Z(n))||Ze(131);const r=e._config.theme;o(n,r.tableCellSelected)}function yn(e){const t=n(e,Ge);return Ge(t)?t:null}function Nn(e){const t=n(e,Bn);return Bn(t)?t:null}function vn(e,t,o,r,l,s,i){const c=re(o.focus,l?"previous":"next");if(le(c))return!1;let a=c;for(const e of se(c).iterNodeCarets("shadowRoot")){if(!ie(e)||!x(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!Ge(u))return!1;const h=u,d=function(e){for(const t of se(e).iterNodeCarets("root")){const{origin:n}=t;if(Ge(n)){if(de(t))return fe(n,e.direction)}else if(!ot(n))break}return null}(ce(h,a.direction)),f=n(h,Bn);if(!f||!f.is(s))return!1;const g=e.getElementByKey(h.getKey()),m=cn(g);if(!g||!m)return!1;const p=zn(e,f);if(i.table=p,d)if("extend"===r){const t=cn(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(t,!0)}else{const e=ue(d);ae(o.anchor,e),ae(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=ge(e);return de(t)?ue(t):e}(ce(f,c.direction));ae(o.anchor,e),ae(o.focus,e)}return Tn(t),!0}function xn(e,t,o,r,l,s){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=b();if(!_n(i,r)){if(w(i)){if("backward"===o){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(x(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Bn(n)&&(Tn(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=n(e,e=>Bn(e));if(Ge(l)&&(l=n(l,Bn)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let c=0;"up"===o&&x(s)&&(c=s.getChildrenSize());let a=s;if("up"===o&&x(s)){const e=s.getLastChild();a=e||s,c=g(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,g(a)?"text":"element"),A(u),Tn(t),!0}if(te(e)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==Qt(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Mt(e),[o]=Mt(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,e=>x(e)&&!e.isInline());if(Ge(r)&&(r=n(r,Bn)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Bn(s)&&l.tableNodeKey===s.getKey()){const e=s.getFirstDescendant(),n=s.getLastDescendant();if(!e||!n)return!1;const[r]=Mt(e),[l]=Mt(n),c=i.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Tn(t),A(c),!0}}}}return"down"===o&&Mn(e)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(w(i)){if("backward"===o||"forward"===o){return vn(e,t,i,t.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:c,focus:a}=i,u=n(c.getNode(),Ge),h=n(a.getNode(),Ge);if(!Ge(u)||!u.is(h))return!1;const d=Nn(u);if(d!==r&&null!=d){const n=Vt(d,e.getElementByKey(d.getKey()));if(null!=n)return l.table=un(d,n),xn(e,t,o,d,l,s)}const f=e.getElementByKey(u.__key),g=e.getElementByKey(c.key);if(null==g||null==f)return!1;let m;if("element"===c.type)m=g.getBoundingClientRect();else{const t=E(Gt(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?u.getFirstChild():u.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===o?_.top>m.top-m.height:m.bottom+m.height>_.bottom){Tn(t);const e=r.getCordsFromCellNode(u,l.table);if(!t.shiftKey)return fn(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(Pt(i)){const{anchor:s,focus:c,tableKey:a}=i;if(a!==r.getKey())return!1;const u=n(s.getNode(),Ge),h=n(c.getNode(),Ge),[d]=i.getNodes();Bn(d)||Ze(251);const f=Vt(d,e.getElementByKey(d.getKey()));if(!Ge(u)||!Ge(h)||!Bn(d)||null==f)return!1;l.$updateTableTableSelection(i);const g=un(d,f),m=r.getCordsFromCellNode(u,g),p=r.getDOMCellFromCordsOrThrow(m.x,m.y,g);if(l.$setAnchorCellForSelection(p),Tn(t),t.shiftKey){const[e,t,n]=Et(r,u,h);return Cn(l,e,t,n,o)}return h.selectEnd(),!0}return!1}function Tn(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Fn(e,t,n){const o=p();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Rn(e,t,o){const r=o.getParent();if(!r)return;const l=E(Gt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=Vt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),e=>Ge(e));if(!a)return;const u=n(a,e=>Bn(e));if(!Bn(u)||!u.is(o))return;const[h,d]=Et(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function On(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function An(e,t,n){return Qt(e,Z(t,n))}function Kn(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function En(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t)}o(t,...l),e(t,...s)}const kn=new WeakSet;function Mn(e=O()){return kn.has(e)}function $n(e,t){t?kn.add(e):kn.delete(e)}class Wn extends h{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Wn(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Ln,priority:1})}}static importJSON(e){return Hn().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=jt(e)?e:e.querySelector("table");return jt(t)||Ze(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&pe(o.style,this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),Ce(r),e(o,t.theme.table),this.updateTableElement(null,o,t),Mn(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.overflowX="auto",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,r,l){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(o(t,r.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,r,l,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(o(t,r.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,r,l,this.__frozenRowCount)}updateTableElement(t,n,r){this.__style!==(t?t.__style:"")&&pe(n.style,this.__style,t?t.__style:""),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,r,this.__rowStriping);const l=t?t.getColumnCount():0,s=t?t.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||Kn(n,this.getColumnCount(),this.getColWidths()),En(n,r,this.getFormatType())}updateDOM(e,t,n){const o=Vt(this,t);return t===o===Mn()||(l(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,o,n),this.updateTableElement(e,o,n),!1);var r}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Kn(Vt(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n)),!jt(n)&&l(n)&&(n=n.querySelector("table")),!jt(n))return null;En(n,e._config,this.getFormatType());const[o]=kt(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e)}return n},element:!jt(n)&&l(n)?n.querySelector("table"):n}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=An(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=Z(o.elem);return Ge(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{Ge(e)&&(t+=e.getColSpan())}),t}}function zn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Ze(230),un(t,n)}function Ln(e){const n=Hn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Je.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,ot),node:n}}function Hn(){return C(new Wn)}function Bn(e){return e instanceof Wn}function Pn(e){ot(e.getParent())?e.isEmpty()&&e.append(p()):e.remove()}function Dn(e){Bn(e.getParent())?u(e,Ge):e.remove()}function In(e){u(e,ot);const[t]=kt(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;ot(r)||Ze(254,r.constructor.name,r.getType());const l=t[e].reduce((e,t)=>t?1+e:e,0);if(l!==n)for(let e=l;e<n;++e){const e=Ve();e.append(p()),r.append(e)}}const r=e.getColWidths(),l=e.getColumnCount();if(r&&r.length!==l){let t;if(l<r.length)t=r.slice(0,l);else if(r.length>0){const e=r[r.length-1];t=[...r,...Array(l-r.length).fill(e)]}e.setColWidths(t)}}function Un(e){if(e.detail<3||!ee(e.target))return!1;const t=Z(e.target);if(null===t)return!1;const o=n(t,e=>x(e)&&!e.isInline());if(null===o)return!1;return!!Ge(o.getParent())&&(o.select(0),!0)}function Jn(){const e=b();if(!w(e))return!1;const t=Nn(e.anchor.getNode());if(null===t)return!1;const n=Ne();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=kt(t,null,null);if(0===o.length||0===o[0].length)return!1;const r=o[0][0];if(!r||!r.cell)return!1;const l=o[o.length-1],s=l[l.length-1];if(!s||!s.cell)return!1;const i=It(t,r.cell,s.cell);return A(i),!0}function Xn(e){return e.registerNodeTransform(Ye,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Mt(e),[n]=Et(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();ot(l)||Ze(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),ot(l)||Ze(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){Ge(c)||Ze(176);const e=Ve(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Yn(e,t=!0){const n=new Xt,o=(o,r,l)=>{const s=Vt(o,l),i=on(o,s,e,t,n);n.observers.set(r,[i,s])};return i(nn(e,n),e.registerCommand(K,()=>rn(n,e),B),e.registerMutationListener(Wn,t=>{e.getEditorState().read(()=>{for(const[e,r]of t){const t=n.observers.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=Jt(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.observers.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.observers.delete(e))}},{editor:e})},{skipInitialization:!1}),()=>{for(const[,[e]]of n.observers)e.removeListeners()})}function qn(e,t){e.hasNodes([Wn])||Ze(255);const{hasNestedTables:o=ke(!1)}=t??{};return i(e.registerCommand(Qe,e=>function({rows:e,columns:t,includeHeaders:n},o){const r=b()||ne();if(!r||!w(r))return!1;if(!o&&Nn(r.anchor.getNode()))return!1;const l=rt(Number(e),Number(t),n);c(l);const s=l.getFirstDescendant();return g(s)&&s.select(),!0}(e,o.peek()),_e),e.registerCommand(Se,(t,r)=>e===r&&function(e,t){const{nodes:o,selection:r}=e;if(!o.some(e=>Bn(e)||a(e).some(e=>Bn(e.node))))return!1;const l=Pt(r),s=w(r);if(!(s&&null!==n(r.anchor.getNode(),e=>Ge(e))&&null!==n(r.focus.getNode(),e=>Ge(e))||l))return!1;if(1===o.length&&Bn(o[0]))return function(e,t){const o=t.getStartEndPoints(),r=Pt(t);if(null===o)return!1;const[l,s]=o,[i,c,a]=Mt(l),u=n(s.getNode(),e=>Ge(e));if(!(Ge(i)&&Ge(u)&&ot(c)&&Bn(a)))return!1;const[h,d,f]=Et(a,i,u),[m]=kt(e,null,null),C=h.length,_=C>0?h[0].length:0;let S=d.startRow,b=d.startColumn,w=m.length,y=w>0?m[0].length:0;if(r){const e=$t(h,d,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let N=!1;const v=Math.min(C,S+w)-1,x=Math.min(_,b+y)-1,T=new Set;for(let e=S;e<=v;e++)for(let t=b;t<=x;t++){const n=h[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(Kt(n.cell),T.add(n.cell.getKey()),N=!0))}let[F]=kt(a.getWritable(),null,null);const R=w-C+S;for(let e=0;e<R;e++){pt(F[C-1][0].cell)}const O=y-_+b;for(let e=0;e<O;e++){bt(F[0][_-1].cell,!0,!1)}[F]=kt(a.getWritable(),null,null);for(let e=S;e<S+w;e++)for(let t=b;t<b+y;t++){const n=e-S,o=t-b,r=m[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const l=r.cell;if(1!==l.__rowSpan||1!==l.__colSpan){const n=[],o=Math.min(e+l.__rowSpan,S+w)-1,r=Math.min(t+l.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=F[l][e];n.push(t.cell)}Rt(n),N=!0}const{cell:s}=F[e][t],i=l.getBackgroundColor();null!=i&&s.setBackgroundColor(i);const c=s.getChildren();l.getChildren().forEach(e=>{if(g(e)){p().append(e),s.append(e)}else s.append(e)}),c.forEach(e=>e.remove())}if(r&&N){const[e]=kt(a.getWritable(),null,null);e[d.startRow][d.startColumn].cell.selectEnd()}return!0}(o[0],r);if(s&&t.peek()&&!function(e){if(Pt(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(w(e)&&Ge(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(r))return!1;return!0}(t,o),_e),e.registerCommand(be,Jn,we),e.registerCommand(ye,Un,_e),e.registerNodeTransform(Wn,In),e.registerNodeTransform(et,Dn),e.registerNodeTransform(Ye,Pn))}const jn=ve({build:(e,t,n)=>$e(t),config:Te({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[Wn,et,Ye],register(e,t,n){const o=n.getOutput();return i(Me(()=>{const t=o.hasHorizontalScroll.value;Mn(e)!==t&&($n(e,t),e.update(xe))}),qn(e,o),Me(()=>Yn(e,o.hasTabHandler.value)),Me(()=>o.hasCellMerge.value?void 0:Xn(e)),Me(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(Ye,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});function Vn(e){const t=[];let n=null;const o=()=>{if(null!==n){const e=n.getFirstChild();m(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)f(r)||g(r)||m(r)?null!==n?n.append(r):(n=p().append(r),t.push(n)):(o(),t.push(r),n=null);return o(),0===t.length&&t.push(p()),t}const Gn={$accepts:ot,$packageRun:e=>e.every(Ge)?[nt().splice(0,0,e)]:[],name:"TableSchema"},Qn={$accepts:Ge,name:"TableRowSchema"},Zn=[Be({$import:(e,n)=>{const o=Hn();n.hasAttribute("data-lexical-row-striping")&&o.setRowStriping(!0),n.hasAttribute("data-lexical-frozen-column")&&o.setFrozenColumns(1),n.hasAttribute("data-lexical-frozen-row")&&o.setFrozenRows(1);const r=n.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Je.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&o.setColWidths(e)}return[o.splice(0,0,t(e.$importChildren(n),ot))]},match:Pe.tag("table"),name:"@lexical/table/table"}),Be({$import:(e,n)=>[nt(Je.test(n.style.height)?parseFloat(n.style.height):void 0).splice(0,0,t(e.$importChildren(n),Ge))],match:Pe.tag("tr"),name:"@lexical/table/tr"}),Be({$import:(e,t)=>{const n="TH"===t.nodeName,o=Je.test(t.style.width)?parseFloat(t.style.width):void 0;let r=Xe.NO_STATUS;if(n){const e=t.getAttribute("scope");if("col"===e)r=Xe.COLUMN;else if("row"===e)r=Xe.ROW;else{const e=t.parentElement,n=Re(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),o=0===t.cellIndex;n&&(r|=Xe.ROW),o&&(r|=Xe.COLUMN),r===Xe.NO_STATUS&&(r=Xe.ROW)}}const l=Ve(r,t.colSpan,o);l.__rowSpan=t.rowSpan;const s=t.style.backgroundColor;""!==s&&(l.__backgroundColor=s);const i=t.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(i)&&(l.__verticalAlign=i);const c=e.get(De),a=c|function(e){let t=0;const n=e.fontWeight;"700"!==n&&"bold"!==n||(t|=Oe),"italic"===e.fontStyle&&(t|=Ae);const o=(e.textDecoration||"").split(" ");return o.includes("underline")&&(t|=Ke),o.includes("line-through")&&(t|=Ee),t}(t.style),u=e.get(Ie),h=t.style.color,d=h?{...u,color:h}:u,f=[];return a!==c&&f.push(Ue(De,a)),d!==u&&f.push(Ue(Ie,d)),[l.splice(0,0,Vn(e.$importChildren(t,{context:f})))]},match:Pe.tag("td","th"),name:"@lexical/table/cell"})],eo=ve({dependencies:[Le,jn,Fe(He,{rules:Zn})],name:"@lexical/table/Import"});export{Et as $computeTableMap,kt as $computeTableMapSkipCellCheck,Ve as $createTableCellNode,Hn as $createTableNode,rt as $createTableNodeWithDimensions,nt as $createTableRowNode,Dt as $createTableSelection,It as $createTableSelectionFrom,wt as $deleteTableColumn,vt as $deleteTableColumnAtSelection,xt as $deleteTableColumn__EXPERIMENTAL,yt as $deleteTableRowAtSelection,Nt as $deleteTableRow__EXPERIMENTAL,yn as $findCellNode,Nn as $findTableNode,zn as $getElementForTableNode,Mt as $getNodeTriplet,Jt as $getTableAndElementByKey,lt as $getTableCellNodeFromLexicalNode,Lt as $getTableCellNodeRect,at as $getTableColumnIndexFromTableCellNode,it as $getTableNodeFromLexicalNodeOrThrow,ct as $getTableRowIndexFromTableCellNode,st as $getTableRowNodeFromTableCellNodeOrThrow,Ct as $insertTableColumn,_t as $insertTableColumnAtSelection,St as $insertTableColumn__EXPERIMENTAL,dt as $insertTableRow,gt as $insertTableRowAtSelection,mt as $insertTableRow__EXPERIMENTAL,Mn as $isScrollableTablesActive,Wt as $isSimpleTable,Ge as $isTableCellNode,Bn as $isTableNode,ot as $isTableRowNode,Pt as $isTableSelection,Rt as $mergeCells,zt as $moveTableColumn,ht as $removeTableRowAtIndex,At as $unmergeCell,Qe as INSERT_TABLE_COMMAND,Xe as TableCellHeaderStates,Ye as TableCellNode,jn as TableExtension,eo as TableImportExtension,Zn as TableImportRules,Wn as TableNode,Yt as TableObserver,et as TableRowNode,Qn as TableRowSchema,Gn as TableSchema,on as applyTableHandlers,cn as getDOMCellFromTarget,Vt as getTableElement,sn as getTableObserverFromTableElement,Xn as registerTableCellUnmergeTransform,qn as registerTablePlugin,Yn as registerTableSelectionObserver,$n as setScrollableTablesActive};
|
|
9
|
+
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$dfs as a,$unwrapAndFilterDescendants as u}from"@lexical/utils";import{ElementNode as h,isHTMLElement as d,$isInlineElementOrDecoratorNode as f,$isTextNode as g,$isLineBreakNode as m,$createParagraphNode as p,$applyNodeReplacement as C,createCommand as _,$createTextNode as S,$getSelection as b,$isRangeSelection as w,$isParagraphNode as y,$createPoint as N,$getNodeByKey as v,$isElementNode as x,$normalizeSelection__EXPERIMENTAL as T,isCurrentlyReadOnlyMode as F,TEXT_TYPE_TO_FORMAT as R,$getEditor as O,$setSelection as A,SELECTION_CHANGE_COMMAND as K,getDOMSelection as E,$createRangeSelection as k,$isRootNode as M,INSERT_PARAGRAPH_COMMAND as $,KEY_ARROW_DOWN_COMMAND as W,KEY_ARROW_UP_COMMAND as z,KEY_ARROW_LEFT_COMMAND as L,KEY_ARROW_RIGHT_COMMAND as H,COMMAND_PRIORITY_HIGH as B,KEY_ESCAPE_COMMAND as P,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as I,DELETE_CHARACTER_COMMAND as U,KEY_BACKSPACE_COMMAND as J,KEY_DELETE_COMMAND as X,CUT_COMMAND as Y,FORMAT_TEXT_COMMAND as q,FORMAT_ELEMENT_COMMAND as j,CONTROLLED_TEXT_INSERTION_COMMAND as V,KEY_TAB_COMMAND as G,FOCUS_COMMAND as Q,$getNearestNodeFromDOMNode as Z,isDOMNode as ee,$isRootOrShadowRoot as te,$getPreviousSelection as ne,$getNodeByKeyOrThrow as oe,$caretFromPoint as re,$isExtendableTextPointCaret as le,$extendCaretToRange as se,$isSiblingCaret as ie,$getSiblingCaret as ce,$setPointFromCaret as ae,$normalizeCaret as ue,$createRangeSelectionFromDom as he,$isChildCaret as de,$getChildCaret as fe,$getAdjacentChildCaret as ge,IS_FIREFOX as me,setDOMStyleFromCSS as pe,setDOMUnmanaged as Ce,COMMAND_PRIORITY_EDITOR as _e,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Se,SELECT_ALL_COMMAND as be,COMMAND_PRIORITY_LOW as we,CLICK_COMMAND as ye,$getRoot as Ne,defineExtension as ve,$fullReconcile as xe,safeCast as Te,configExtension as Fe,isHTMLTableRowElement as Re,IS_BOLD as Oe,IS_ITALIC as Ae,IS_UNDERLINE as Ke,IS_STRIKETHROUGH as Ee}from"lexical";import{signal as ke,effect as Me,namedSignals as $e}from"@lexical/extension";import{copyToClipboard as We,$getClipboardDataFromSelection as ze}from"@lexical/clipboard";import{DOMImportExtension as Le,defineImportRule as He,sel as Be,ImportTextFormat as Pe,ImportTextStyle as De,contextValue as Ie,$propagateTextAlignToBlockChildren as Ue}from"@lexical/html";const Je=/^(\d+(?:\.\d+)?)px$/,Xe={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Ye extends h{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new Ye(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:je,priority:0}),th:e=>({conversion:je,priority:0})}}static importJSON(e){return Ve().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=Xe.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),qe(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(d(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...qe(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=Xe.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Xe.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function qe(e){return"middle"===e||"bottom"===e}function je(e){const t=e,n=e.nodeName.toLowerCase();let o;Je.test(t.style.width)&&(o=parseFloat(t.style.width));let r=Xe.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)r=Xe.COLUMN;else if("row"===e)r=Xe.ROW;else{const e=t.parentElement,n=d(e)&&"tr"===e.nodeName.toLowerCase()&&d(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),o=0===t.cellIndex;n&&(r|=Xe.ROW),o&&(r|=Xe.COLUMN),r===Xe.NO_STATUS&&(r=Xe.ROW)}}const l=Ve(r,t.colSpan,o);l.__rowSpan=t.rowSpan;const s=t.style.backgroundColor;""!==s&&(l.__backgroundColor=s);const i=t.style.verticalAlign;qe(i)&&(l.__verticalAlign=i);const c=t.style,a=(c&&c.textDecoration||"").split(" "),u="700"===c.fontWeight||"bold"===c.fontWeight,h=a.includes("line-through"),C="italic"===c.fontStyle,_=a.includes("underline"),S=c.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();m(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)if(f(r)||g(r)||m(r)){if(g(r)&&(u&&r.toggleFormat("bold"),h&&r.toggleFormat("strikethrough"),C&&r.toggleFormat("italic"),_&&r.toggleFormat("underline"),S)){const e=r.getStyle();e.includes("color:")||r.setStyle(e+`color: ${S};`)}n?n.append(r):(n=p().append(r),t.push(n))}else t.push(r),o(),n=null;return o(),0===t.length&&t.push(p()),t},node:l}}function Ve(e=Xe.NO_STATUS,t=1,n){return C(new Ye(e,t,n))}function Ge(e){return e instanceof Ye}const Qe=_("INSERT_TABLE_COMMAND");function Ze(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class et extends h{__height;static getType(){return"tablerow"}static clone(e){return new et(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:tt,priority:0})}}static importJSON(e){return nt().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function tt(e){const n=e;let o;return Je.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,Ge),node:nt(o)}}function nt(e){return C(new et(e))}function ot(e){return e instanceof et}function rt(e,t,n=!0){const o=Hn();for(let r=0;r<e;r++){const e=nt();for(let o=0;o<t;o++){let t=Xe.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Xe.ROW),0===o&&n.columns&&(t|=Xe.COLUMN)):n&&(0===r&&(t|=Xe.ROW),0===o&&(t|=Xe.COLUMN));const l=Ve(t),s=p();s.append(S()),l.append(s),e.append(l)}o.append(e)}return o}function lt(e){const t=n(e,e=>Ge(e));return Ge(t)?t:null}function st(e){const t=n(e,e=>ot(e));if(ot(t))return t;throw new Error("Expected table cell to be inside of table row.")}function it(e){const t=n(e,e=>Bn(e));if(Bn(t))return t;throw new Error("Expected table cell to be inside of table.")}function ct(e){const t=st(e);return it(t).getChildren().findIndex(e=>e.is(t))}function at(e){return st(e).getChildren().findIndex(t=>t.is(e))}function ut(e,t){const n=it(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function ht(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function dt(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!ot(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=nt();for(let n=0;n<t;n++){const t=e[n];Ge(t)||Ze(12);const{above:l,below:s}=ut(t,r);let i=Xe.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(Xe.COLUMN)||s&&s.hasHeaderState(Xe.COLUMN))&&(i|=Xe.COLUMN);const a=Ve(i,1,c);a.append(p()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}const ft=(e,t)=>e===Xe.BOTH||e===t?t:Xe.NO_STATUS;function gt(e=!0){const t=b();w(t)||Pt(t)||Ze(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Mt(n),[l,,s]=Mt(o),[,i,c]=Et(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?pt(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):pt(u<a?l:r,!1)}const mt=gt;function pt(e,t=!0){const[,,n]=Mt(e),[o,r]=Et(n,e,e),l=o[0].length,{startRow:s}=r;let i=null;if(t){const t=s+e.__rowSpan-1,r=o[t],c=nt();for(let e=0;e<l;e++){const{cell:n,startRow:o}=r[e];if(o+n.__rowSpan-1<=t){const t=r[e].cell.__headerState,n=ft(t,Xe.COLUMN);c.append(Ve(n).append(p()))}else n.setRowSpan(n.__rowSpan+1)}const a=n.getChildAtIndex(t);ot(a)||Ze(256),a.insertAfter(c),i=c}else{const e=s,t=o[e],r=nt();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=ft(e,Xe.COLUMN);r.append(Ve(o).append(p()))}else o.setRowSpan(o.__rowSpan+1)}const c=n.getChildAtIndex(e);ot(c)||Ze(257),c.insertBefore(r),i=r}return i}function Ct(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(ot(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];Ge(o)||Ze(12);const{left:l,right:i}=ut(o,r);let c=Xe.NO_STATUS;(l&&l.hasHeaderState(Xe.ROW)||i&&i.hasHeaderState(Xe.ROW))&&(c|=Xe.ROW);const a=Ve(c);a.append(p()),s.push({newTableCell:a,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function _t(e=!0){const t=b();w(t)||Pt(t)||Ze(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Mt(n),[l,,s]=Mt(o),[,i,c]=Et(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?bt(a+r.__colSpan>u+l.__colSpan?r:l,!0):bt(u<a?l:r,!1)}const St=_t;function bt(e,t=!0,n=!0){const[,,o]=Mt(e),[r,l]=Et(o,e,e),s=r.length,{startColumn:i}=l,c=t?i+e.__colSpan-1:i-1,a=o.getFirstChild();ot(a)||Ze(120);let u=null;function h(e=Xe.NO_STATUS){const t=Ve(e).append(p());return null===u&&(u=t),t}let d=a;e:for(let e=0;e<s;e++){if(0!==e){const e=d.getNextSibling();ot(e)||Ze(121),d=e}const t=r[e],n=t[c<0?0:c].cell.__headerState,o=ft(n,Xe.ROW);if(c<0){Ft(d,h(o));continue}const{cell:l,startColumn:s,startRow:i}=t[c];if(s+l.__colSpan-1<=c){let n=l,r=i,s=c;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){d.append(h(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(h(o))}else l.setColSpan(l.__colSpan+1)}null!==u&&n&&Tt(u);const f=o.getColWidths();if(f){const e=[...f],t=c<0?0:c,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return u}function wt(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ot(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function yt(){const e=b();w(e)||Pt(e)||Ze(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Mt(t),[l]=Mt(n),[s,i,c]=Et(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=s[h+1],g=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>h){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=a&&o+n.__rowSpan-1>h&&e===h){null===g&&Ze(122);let o=null;for(let n=0;n<t;n++){const t=f[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?Ft(g,n):o.insertAfter(n)}}}const t=r.getChildAtIndex(e);ot(t)||Ze(206,String(e)),t.remove()}if(void 0!==f){const{cell:e}=f[0];Tt(e)}else{const e=s[a-1],{cell:t}=e[0];Tt(t)}}const Nt=yt;function vt(){const e=b();w(e)||Pt(e)||Ze(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Mt(t),[l]=Mt(n),[s,i,c]=Et(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e))}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;Tt(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Tt(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}const xt=vt;function Tt(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ft(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Rt(e){if(0===e.length)return null;const t=it(e[0]),[n]=kt(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const i=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!i.has(t)&&e.some(e=>e.is(n.cell))){i.add(t);const e=n.startRow,c=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,c),s=Math.max(s,c+u-1)}}if(o===1/0||l===1/0)return null;const c=r-o+1,a=s-l+1,u=n[o][l];if(!u.cell)return null;const h=u.cell;h.setColSpan(a),h.setRowSpan(c);const d=new Set([h.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!d.has(l)){d.add(l);Ot(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(p()),h}function Ot(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!y(t)||!t.isEmpty())}function At(){const e=b();w(e)||Pt(e)||Ze(188);const t=e.anchor.getNode(),o=n(t,Ge);return Ge(o)||Ze(148),Kt(o)}function Kt(e){const[t,n,o]=Mt(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,i]=Et(o,t,t),{startColumn:c,startRow:a}=i,u=t.__headerState&Xe.COLUMN,h=Array.from({length:r},(e,t)=>{let n=u;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+c].cell.__headerState;return n}),d=t.__headerState&Xe.ROW,f=Array.from({length:l},(e,t)=>{let n=d;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+a][e].cell.__headerState;return n});if(r>1){for(let e=1;e<r;e++)t.insertAfter(Ve(h[e]|f[0]).append(p()));t.setColSpan(1)}if(l>1){let e;for(let t=1;t<l;t++){const o=a+t,l=s[o];e=(e||n).getNextSibling(),ot(e)||Ze(125);let i=null;for(let e=0;e<c;e++){const t=l[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let n=r-1;n>=0;n--)Ft(e,Ve(h[n]|f[t]).append(p()));else for(let e=r-1;e>=0;e--)i.insertAfter(Ve(h[e]|f[t]).append(p()))}t.setRowSpan(1)}}function Et(e,t,n){const[o,r,l]=kt(e,t,n);return null===r&&Ze(207),null===l&&Ze(208),[o,r,l]}function kt(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];ot(o)||Ze(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(Ge(a)||Ze(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o)}}return[o,r,l]}function Mt(e){let t;if(e instanceof Ye)t=e;else if("__type"in e){const o=n(e,Ge);Ge(o)||Ze(148),t=o}else{const o=n(e.getNode(),Ge);Ge(o)||Ze(148),t=o}const o=t.getParent();ot(o)||Ze(149);const r=o.getParent();return Bn(r)||Ze(210),[t,o,r]}function $t(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function Wt(e){const t=e.getChildren();let n=null;for(const e of t){if(!ot(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!Ge(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function zt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Wt(e))return;e.getChildren().filter(ot).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}}function Lt(e){const[t,,n]=Mt(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Ht(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map(t=>{const o=e[t].getNode(),r=n(o,Ge);Ge(r)||Ze(238,t,o.getKey(),o.getType());const l=r.getParent();ot(l)||Ze(239,t);const s=l.getParent();return Bn(s)||Ze(240,t),[o,r,l,s]});return l.is(a)||Ze(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Bt{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=v(this.tableKey),t=v(this.anchor.key),n=v(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Pt(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Bt(this.tableKey,N(this.anchor.key,this.anchor.offset,this.anchor.type),N(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(Ge).forEach(e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())});const n=R[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();x(t)||Ze(151);T(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Ht(this),n=Lt(e);null===n&&Ze(153);const o=Lt(t);null===o&&Ze(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Ht(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Ze(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&Ze(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Et(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=$t(l,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();ot(o)||Ze(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||Ut(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return F()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>Ge(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function Pt(e){return e instanceof Bt}function Dt(){const e=N("root",0,"element"),t=N("root",0,"element");return new Bt("root",e,t)}function It(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=b(),r=Pt(o)?o.clone():Dt();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function Ut(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&x(o)&&n.push(o.getChildren())}}function Jt(e,t=O()){const n=v(e);Bn(n)||Ze(231,e);const o=Vt(n,t.getElementByKey(e));return null===o&&Ze(232,e),{tableElement:o,tableNode:n}}class Xt{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class Yt{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Jt(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.getEditorState().read(()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=un(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=un(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const t=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:n,tableElement:o}=this.$lookup();hn(t,un(n,o),null),e&&null!==b()&&(A(null),t.dispatchCommand(K,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Ze(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),hn(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=E(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==r||this.anchorY!==l||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&r===this.focusX&&l===this.focusY)return!1;if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const s=An(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(r,l,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=It(o,t,e),A(this.tableSelection),n.dispatchCommand(K,void 0),hn(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Ze(234),e}$getFocusTableCell(){return this.focusCellNodeKey?v(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Ze(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=An(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=It(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=b();Pt(t)||Ze(236);const n=k(),o=n.anchor,r=n.focus,l=t.getNodes().filter(Ge);l.length>0||Ze(237);const s=l[0].getFirstChild(),i=y(s)?s.getFormatFlags(e,null):null;l.forEach(t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),A(t),this.editor.dispatchCommand(K,void 0)}$clearText(){const{editor:e}=this,t=v(this.tableNodeKey);if(!Bn(t))throw new Error("Expected TableNode.");const n=b();Pt(n)||Ze(253);const o=n.getNodes().filter(Ge),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&ot(r)&&ot(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(M(n)&&n.isEmpty()&&e.dispatchCommand($,void 0))}o.forEach(e=>{if(x(e)){const t=p(),n=S();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),hn(e,this.table,null),A(null),e.dispatchCommand(K,void 0)}}const qt="__lexicalTableSelection";function jt(e){return d(e)&&"TABLE"===e.nodeName}function Vt(e,t){if(!t)return t;const n=jt(t)?t:t.querySelector("table");return jt(n)||Ze(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function Gt(e){return e._window}function Qt(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;Ge(n)&&(o=n)}return null}const Zt=[[W,"down"],[z,"up"],[L,"backward"],[H,"forward"]],en=[D,I,U],tn=[J,X];function nn(e,t){return e.registerRootListener(n=>{if(null===n)return;const o=e._window;if(null===o)return;const r=o=>{const r=o.target;if(0!==o.button||!ee(r)||!n.contains(r))return;const l=function(e){const t=cn(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&qt in n&&n[qt])return{cellElement:t,tableElement:n,tableObserver:n[qt]};n=n.parentNode}return null}(r);e.update(()=>{if(Pt(b())){for(const[e]of t.observers.values())e.$clearHighlight(!1);A(null),e.dispatchCommand(K,void 0)}if(!l)return;const{tableObserver:n,tableElement:r,cellElement:s}=l;!function(e,t,n,o,r,l){const s=e._window;if(!s)return;const i=t=>{if(r.isSelecting)return;r.isSelecting=!0,null!==t&&null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)});const n=()=>{r.isSelecting=!1,s.removeEventListener("pointerup",n),s.removeEventListener("pointermove",i)},i=t=>{if(!(e=>!(1&~e.buttons))(t)&&r.isSelecting)return r.isSelecting=!1,s.removeEventListener("pointerup",n),void s.removeEventListener("pointermove",i);if(!ee(t.target))return;let c=null;const a=!(me||o.contains(t.target));if(a)c=an(o,t.target);else for(const e of document.elementsFromPoint(t.clientX,t.clientY))if(c=an(o,e),c)break;if(c){const t=c;null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)}),null!==r.focusCell&&c.elem===r.focusCell.elem||(l.setNextFocus({focusCell:c,override:a,tableKey:r.tableNodeKey}),e.dispatchCommand(K,void 0))}};s.addEventListener("pointerup",n,r.listenerOptions),s.addEventListener("pointermove",i,r.listenerOptions)};r.pointerType=t.pointerType;const c=oe(r.tableNodeKey),a=ne();if(me&&t.shiftKey&&_n(a,c)&&(w(a)||Pt(a))){const e=a.anchor.getNode(),o=Qt(c,a.anchor.getNode());if(o)r.$setAnchorCellForSelection(On(r,o)),r.$setFocusCellForSelection(n),Tn(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&r.$setAnchorCellForSelection(n);i(n)}(e,o,s,r,n,t)})};return o.addEventListener("pointerdown",r),()=>{o.removeEventListener("pointerdown",r)}})}function on(e,t,o,l,s){const i=o.getRootElement(),c=Gt(o);null!==i&&null!==c||Ze(246);const a=new Yt(o,e.getKey()),u=Vt(e,t);!function(e,t){null!==sn(e)&&Ze(205);e[qt]=t}(u,a),a.listenersToRemove.add(()=>function(e,t){sn(e)===t&&delete e[qt]}(u,a));const h=e=>{if(e.detail>=3&&ee(e.target)){null!==cn(e.target)&&e.preventDefault()}};u.addEventListener("mousedown",h,a.listenerOptions),a.listenersToRemove.add(()=>{u.removeEventListener("mousedown",h)});for(const[t,n]of Zt)a.listenersToRemove.add(o.registerCommand(t,t=>xn(o,t,n,e,a,s),B));a.listenersToRemove.add(o.registerCommand(P,t=>{const n=b();if(Pt(n)){const o=Qt(e,n.focus.getNode());if(null!==o)return Tn(t),o.selectEnd(),!0}return!1},B));const d=t=>()=>{const o=b();if(!_n(o,e))return!1;if(Pt(o))return a.$clearText(),!0;if(w(o)){if(!Ge(Qt(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return a.$clearText(),!0;const c=n(o.anchor.getNode(),e=>x(e)),u=c&&n(c,e=>x(e)&&Ge(e.getParent()));if(!x(u)||!x(c))return!1;if(t===I&&null===u.getPreviousSibling())return!0}return!1};for(const e of en)a.listenersToRemove.add(o.registerCommand(e,d(e),B));const f=t=>{const n=b();if(!Pt(n)&&!w(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!_n(n,e)&&(!!Pt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),a.$clearText(),!0))};for(const e of tn)a.listenersToRemove.add(o.registerCommand(e,f,B));return a.listenersToRemove.add(o.registerCommand(Y,e=>{const t=b();if(t){if(!Pt(t)&&!w(t))return!1;We(o,r(e,ClipboardEvent)?e:null,ze(t));const n=f(e);return w(t)?(t.removeText(),!0):n}return!1},B)),a.listenersToRemove.add(o.registerCommand(q,t=>{const o=b();if(!_n(o,e))return!1;if(Pt(o))return a.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),e=>Ge(e));if(!Ge(e))return!1}return!1},B)),a.listenersToRemove.add(o.registerCommand(j,t=>{const n=b();if(!Pt(n)||!_n(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Ge(o)||!Ge(r))return!1;if(function(e,t){if(Pt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Et(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[l,s,i]=Et(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];x(n)&&!n.isInline()&&n.setFormat(t)}}return!0},B)),a.listenersToRemove.add(o.registerCommand(V,t=>{const r=b();if(!_n(r,e))return!1;if(Pt(r))return a.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),e=>Ge(e));if(!Ge(l))return!1;if("string"==typeof t){const n=Rn(o,r,e);if(n)return Fn(n,e,[S(t)]),!0}}return!1},B)),l&&a.listenersToRemove.add(o.registerCommand(G,t=>{const o=b();if(!w(o)||!o.isCollapsed()||!_n(o,e))return!1;const r=yn(o.anchor.getNode());return!(null===r||!e.is(Nn(r)))&&(Tn(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(x(l))return l.selectEnd();const s=n(e,ot);null===s&&Ze(247);for(let e=s[o]();ot(e);e=e[o]()){const t=e[r]();if(x(t))return t.selectEnd()}const i=n(s,Bn);null===i&&Ze(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)},B)),a.listenersToRemove.add(o.registerCommand(Q,t=>e.isSelected(),B)),a.listenersToRemove.add(o.registerCommand($,()=>{const t=b();if(!w(t)||!t.isCollapsed()||!_n(t,e))return!1;const n=Rn(o,t,e);return!!n&&(Fn(n,e),!0)},B)),a}function rn(e,t){const o=b(),r=ne(),l=e.getAndClearNextFocus();if(null!==l){const{tableKey:t,focusCell:n}=l,r=e.observers.get(t);r||Ze(335,t);const[s]=r;if(Pt(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=e.getAndClearShouldCheckSelectionForTable();if(s&&w(r)&&w(o)&&o.isCollapsed()){const e=oe(s),t=o.anchor.getNode(),r=e.getFirstChild(),l=yn(t);if(null!==l&&ot(r)){const t=r.getFirstChild();if(Ge(t)&&e.is(n(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}Pt(o)&&function(e,t){const n=Gt(e),o=ne();if(!t.is(o))return;const r=oe(t.tableKey),l=E(n);if(l&&l.anchorNode&&l.focusNode){const n=Z(l.focusNode),o=n&&!r.isParentOf(n),s=Z(l.anchorNode),i=s&&r.isParentOf(s);if(o&&i&&l.rangeCount>0){const n=he(l,e);n&&(n.anchor.set(r.getKey(),t.isBackward()?r.getChildrenSize():0,"element"),l.removeAllRanges(),A(n))}}}(t,o),w(o)&&function(e,t){const n=ne(),{anchor:o,focus:r}=e,l=o.getNode(),s=r.getNode(),i=yn(l),c=yn(s),a=i?Nn(i):null,u=c?Nn(c):null,h=e.isBackward(),d=i&&c&&a&&u&&a.is(u),f=u&&(!a||a.isParentOf(u)),g=a&&(!u||u.isParentOf(a));if(f){const t=e.clone(),[n]=Et(u,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():r.getKey(),h?0:r.getChildrenSize(),"element"),A(t)}else if(g){const t=e.clone(),[n]=Et(a,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(h?r.getKey():o.getKey(),h?r.getChildrenSize():0,"element"),A(t)}else if(d){const o=t.observers.get(a.getKey());o||Ze(335,a.getKey());const[r]=o;if(i.is(c)||(r.$setAnchorCellForSelection(On(r,i)),r.$setFocusCellForSelection(On(r,c),!0)),"touch"===r.pointerType&&r.isSelecting&&e.isCollapsed()&&w(n)&&n.isCollapsed()){const e=yn(n.anchor.getNode());e&&!e.is(c)&&(r.$setAnchorCellForSelection(On(r,e)),r.$setFocusCellForSelection(On(r,c),!0),r.pointerType=null)}}}(o,e);const i=Array.from(e.observers.entries()).map(([e,[t]])=>({tableNode:oe(e),tableObserver:t}));for(const{tableNode:e,tableObserver:n}of i)ln(t,e,n);return!1}function ln(e,t,n){const o=b(),r=ne();o&&!o.is(r)&&(Pt(o)||Pt(r))&&n.tableSelection&&!n.tableSelection.is(r)&&(Pt(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!Pt(o)&&Pt(r)&&r.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),dn(t.table,t=>{const n=t.elem;t.highlighted=!1,wn(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),dn(t.table,t=>{t.highlighted=!0,bn(e,t)})}(e,n)}function sn(e){return e[qt]||null}function cn(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function an(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function un(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=Vt(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function hn(e,t,n){const o=new Set(n?n.getNodes():[]);dn(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,bn(e,t)):(t.highlighted=!1,wn(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function dn(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=Z(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}const fn=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Sn(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Sn(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Sn(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Sn(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function gn(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function mn([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function pn(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Ze(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Ze(250,n,String(s)),i}function Cn(e,t,n,o,r){const l=$t(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=gn(e,t);return null===n&&Ze(249,t.cell.getKey()),n}(l,n),[d,f]=mn(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=$t(e,t,n),r=gn(o,t);if(r)return[pn(e,o,r),pn(e,o,mn(r))];const l=gn(o,n);if(l)return[pn(e,o,mn(l)),pn(e,o,l)];const s=["minColumn","minRow"];return[pn(e,o,s),pn(e,o,mn(s))]}(t,n,C),b=On(e,_.cell),w=On(e,S.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function _n(e,t){if(w(e)||Pt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Sn(e,t){t?e.selectStart():e.selectEnd()}function bn(t,n){const o=n.elem,r=t._config.theme;Ge(Z(o))||Ze(131),e(o,r.tableCellSelected)}function wn(e,t){const n=t.elem;Ge(Z(n))||Ze(131);const r=e._config.theme;o(n,r.tableCellSelected)}function yn(e){const t=n(e,Ge);return Ge(t)?t:null}function Nn(e){const t=n(e,Bn);return Bn(t)?t:null}function vn(e,t,o,r,l,s,i){const c=re(o.focus,l?"previous":"next");if(le(c))return!1;let a=c;for(const e of se(c).iterNodeCarets("shadowRoot")){if(!ie(e)||!x(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!Ge(u))return!1;const h=u,d=function(e){for(const t of se(e).iterNodeCarets("root")){const{origin:n}=t;if(Ge(n)){if(de(t))return fe(n,e.direction)}else if(!ot(n))break}return null}(ce(h,a.direction)),f=n(h,Bn);if(!f||!f.is(s))return!1;const g=e.getElementByKey(h.getKey()),m=cn(g);if(!g||!m)return!1;const p=zn(e,f);if(i.table=p,d)if("extend"===r){const t=cn(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(t,!0)}else{const e=ue(d);ae(o.anchor,e),ae(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=ge(e);return de(t)?ue(t):e}(ce(f,c.direction));ae(o.anchor,e),ae(o.focus,e)}return Tn(t),!0}function xn(e,t,o,r,l,s){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=b();if(!_n(i,r)){if(w(i)){if("backward"===o){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(x(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Bn(n)&&(Tn(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=n(e,e=>Bn(e));if(Ge(l)&&(l=n(l,Bn)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let c=0;"up"===o&&x(s)&&(c=s.getChildrenSize());let a=s;if("up"===o&&x(s)){const e=s.getLastChild();a=e||s,c=g(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,g(a)?"text":"element"),A(u),Tn(t),!0}if(te(e)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==Qt(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Mt(e),[o]=Mt(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,e=>x(e)&&!e.isInline());if(Ge(r)&&(r=n(r,Bn)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Bn(s)&&l.tableNodeKey===s.getKey()){const e=s.getFirstDescendant(),n=s.getLastDescendant();if(!e||!n)return!1;const[r]=Mt(e),[l]=Mt(n),c=i.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Tn(t),A(c),!0}}}}return"down"===o&&Mn(e)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(w(i)){if("backward"===o||"forward"===o){return vn(e,t,i,t.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:c,focus:a}=i,u=n(c.getNode(),Ge),h=n(a.getNode(),Ge);if(!Ge(u)||!u.is(h))return!1;const d=Nn(u);if(d!==r&&null!=d){const n=Vt(d,e.getElementByKey(d.getKey()));if(null!=n)return l.table=un(d,n),xn(e,t,o,d,l,s)}const f=e.getElementByKey(u.__key),g=e.getElementByKey(c.key);if(null==g||null==f)return!1;let m;if("element"===c.type)m=g.getBoundingClientRect();else{const t=E(Gt(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?u.getFirstChild():u.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===o?_.top>m.top-m.height:m.bottom+m.height>_.bottom){Tn(t);const e=r.getCordsFromCellNode(u,l.table);if(!t.shiftKey)return fn(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(Pt(i)){const{anchor:s,focus:c,tableKey:a}=i;if(a!==r.getKey())return!1;const u=n(s.getNode(),Ge),h=n(c.getNode(),Ge),[d]=i.getNodes();Bn(d)||Ze(251);const f=Vt(d,e.getElementByKey(d.getKey()));if(!Ge(u)||!Ge(h)||!Bn(d)||null==f)return!1;l.$updateTableTableSelection(i);const g=un(d,f),m=r.getCordsFromCellNode(u,g),p=r.getDOMCellFromCordsOrThrow(m.x,m.y,g);if(l.$setAnchorCellForSelection(p),Tn(t),t.shiftKey){const[e,t,n]=Et(r,u,h);return Cn(l,e,t,n,o)}return h.selectEnd(),!0}return!1}function Tn(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Fn(e,t,n){const o=p();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Rn(e,t,o){const r=o.getParent();if(!r)return;const l=E(Gt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=Vt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),e=>Ge(e));if(!a)return;const u=n(a,e=>Bn(e));if(!Bn(u)||!u.is(o))return;const[h,d]=Et(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function On(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function An(e,t,n){return Qt(e,Z(t,n))}function Kn(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function En(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t)}o(t,...l),e(t,...s)}const kn=new WeakSet;function Mn(e=O()){return kn.has(e)}function $n(e,t){t?kn.add(e):kn.delete(e)}class Wn extends h{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Wn(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Ln,priority:1})}}static importJSON(e){return Hn().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=jt(e)?e:e.querySelector("table");return jt(t)||Ze(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&pe(o.style,this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),Ce(r),e(o,t.theme.table),this.updateTableElement(null,o,t),Mn(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.overflowX="auto",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,r,l){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(o(t,r.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,r,l,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(o(t,r.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,r,l,this.__frozenRowCount)}updateTableElement(t,n,r){this.__style!==(t?t.__style:"")&&pe(n.style,this.__style,t?t.__style:""),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,r,this.__rowStriping);const l=t?t.getColumnCount():0,s=t?t.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||Kn(n,this.getColumnCount(),this.getColWidths()),En(n,r,this.getFormatType())}updateDOM(e,t,n){const o=Vt(this,t);return t===o===Mn()||(l(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,o,n),this.updateTableElement(e,o,n),!1);var r}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Kn(Vt(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n)),!jt(n)&&l(n)&&(n=n.querySelector("table")),!jt(n))return null;En(n,e._config,this.getFormatType());const[o]=kt(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e)}return n},element:!jt(n)&&l(n)?n.querySelector("table"):n}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=An(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=Z(o.elem);return Ge(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{Ge(e)&&(t+=e.getColSpan())}),t}}function zn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Ze(230),un(t,n)}function Ln(e){const n=Hn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Je.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,ot),node:n}}function Hn(){return C(new Wn)}function Bn(e){return e instanceof Wn}function Pn(e){ot(e.getParent())?e.isEmpty()&&e.append(p()):e.remove()}function Dn(e){Bn(e.getParent())?u(e,Ge):e.remove()}function In(e){u(e,ot);const[t]=kt(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;ot(r)||Ze(254,r.constructor.name,r.getType());const l=t[e].reduce((e,t)=>t?1+e:e,0);if(l!==n)for(let e=l;e<n;++e){const e=Ve();e.append(p()),r.append(e)}}const r=e.getColWidths(),l=e.getColumnCount();if(r&&r.length!==l){let t;if(l<r.length)t=r.slice(0,l);else if(r.length>0){const e=r[r.length-1];t=[...r,...Array(l-r.length).fill(e)]}e.setColWidths(t)}}function Un(e){if(e.detail<3||!ee(e.target))return!1;const t=Z(e.target);if(null===t)return!1;const o=n(t,e=>x(e)&&!e.isInline());if(null===o)return!1;return!!Ge(o.getParent())&&(o.select(0),!0)}function Jn(){const e=b();if(!w(e))return!1;const t=Nn(e.anchor.getNode());if(null===t)return!1;const n=Ne();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=kt(t,null,null);if(0===o.length||0===o[0].length)return!1;const r=o[0][0];if(!r||!r.cell)return!1;const l=o[o.length-1],s=l[l.length-1];if(!s||!s.cell)return!1;const i=It(t,r.cell,s.cell);return A(i),!0}function Xn(e){return e.registerNodeTransform(Ye,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Mt(e),[n]=Et(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();ot(l)||Ze(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),ot(l)||Ze(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){Ge(c)||Ze(176);const e=Ve(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Yn(e,t=!0){const n=new Xt,o=(o,r,l)=>{const s=Vt(o,l),i=on(o,s,e,t,n);n.observers.set(r,[i,s])};return i(nn(e,n),e.registerCommand(K,()=>rn(n,e),B),e.registerMutationListener(Wn,t=>{e.getEditorState().read(()=>{for(const[e,r]of t){const t=n.observers.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=Jt(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.observers.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.observers.delete(e))}},{editor:e})},{skipInitialization:!1}),()=>{for(const[,[e]]of n.observers)e.removeListeners()})}function qn(e,t){e.hasNodes([Wn])||Ze(255);const{hasNestedTables:o=ke(!1)}=t??{};return i(e.registerCommand(Qe,e=>function({rows:e,columns:t,includeHeaders:n},o){const r=b()||ne();if(!r||!w(r))return!1;if(!o&&Nn(r.anchor.getNode()))return!1;const l=rt(Number(e),Number(t),n);c(l);const s=l.getFirstDescendant();return g(s)&&s.select(),!0}(e,o.peek()),_e),e.registerCommand(Se,(t,r)=>e===r&&function(e,t){const{nodes:o,selection:r}=e;if(!o.some(e=>Bn(e)||a(e).some(e=>Bn(e.node))))return!1;const l=Pt(r),s=w(r);if(!(s&&null!==n(r.anchor.getNode(),e=>Ge(e))&&null!==n(r.focus.getNode(),e=>Ge(e))||l))return!1;if(1===o.length&&Bn(o[0]))return function(e,t){const o=t.getStartEndPoints(),r=Pt(t);if(null===o)return!1;const[l,s]=o,[i,c,a]=Mt(l),u=n(s.getNode(),e=>Ge(e));if(!(Ge(i)&&Ge(u)&&ot(c)&&Bn(a)))return!1;const[h,d,f]=Et(a,i,u),[m]=kt(e,null,null),C=h.length,_=C>0?h[0].length:0;let S=d.startRow,b=d.startColumn,w=m.length,y=w>0?m[0].length:0;if(r){const e=$t(h,d,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let N=!1;const v=Math.min(C,S+w)-1,x=Math.min(_,b+y)-1,T=new Set;for(let e=S;e<=v;e++)for(let t=b;t<=x;t++){const n=h[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(Kt(n.cell),T.add(n.cell.getKey()),N=!0))}let[F]=kt(a.getWritable(),null,null);const R=w-C+S;for(let e=0;e<R;e++){pt(F[C-1][0].cell)}const O=y-_+b;for(let e=0;e<O;e++){bt(F[0][_-1].cell,!0,!1)}[F]=kt(a.getWritable(),null,null);for(let e=S;e<S+w;e++)for(let t=b;t<b+y;t++){const n=e-S,o=t-b,r=m[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const l=r.cell;if(1!==l.__rowSpan||1!==l.__colSpan){const n=[],o=Math.min(e+l.__rowSpan,S+w)-1,r=Math.min(t+l.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=F[l][e];n.push(t.cell)}Rt(n),N=!0}const{cell:s}=F[e][t],i=l.getBackgroundColor();null!=i&&s.setBackgroundColor(i);const c=s.getChildren();l.getChildren().forEach(e=>{if(g(e)){p().append(e),s.append(e)}else s.append(e)}),c.forEach(e=>e.remove())}if(r&&N){const[e]=kt(a.getWritable(),null,null);e[d.startRow][d.startColumn].cell.selectEnd()}return!0}(o[0],r);if(s&&t.peek()&&!function(e){if(Pt(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(w(e)&&Ge(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(r))return!1;return!0}(t,o),_e),e.registerCommand(be,Jn,we),e.registerCommand(ye,Un,_e),e.registerNodeTransform(Wn,In),e.registerNodeTransform(et,Dn),e.registerNodeTransform(Ye,Pn))}const jn=ve({build:(e,t,n)=>$e(t),config:Te({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[Wn,et,Ye],register(e,t,n){const o=n.getOutput();return i(Me(()=>{const t=o.hasHorizontalScroll.value;Mn(e)!==t&&($n(e,t),e.update(xe))}),qn(e,o),Me(()=>Yn(e,o.hasTabHandler.value)),Me(()=>o.hasCellMerge.value?void 0:Xn(e)),Me(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(Ye,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});const Vn={$accepts:ot,$packageRun:e=>e.every(Ge)?[nt().splice(0,0,e)]:[],name:"TableSchema"},Gn={$accepts:Ge,name:"TableRowSchema"},Qn=[He({$import:(e,n)=>{const o=Hn();n.hasAttribute("data-lexical-row-striping")&&o.setRowStriping(!0),n.hasAttribute("data-lexical-frozen-column")&&o.setFrozenColumns(1),n.hasAttribute("data-lexical-frozen-row")&&o.setFrozenRows(1);const r=n.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Je.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&o.setColWidths(e)}return[o.splice(0,0,t(e.$importChildren(n),ot))]},match:Be.tag("table"),name:"@lexical/table/table"}),He({$import:(e,n)=>[nt(Je.test(n.style.height)?parseFloat(n.style.height):void 0).splice(0,0,t(e.$importChildren(n),Ge))],match:Be.tag("tr"),name:"@lexical/table/tr"}),He({$import:(e,t)=>{const n="TH"===t.nodeName,o=Je.test(t.style.width)?parseFloat(t.style.width):void 0;let r=Xe.NO_STATUS;if(n){const e=t.getAttribute("scope");if("col"===e)r=Xe.COLUMN;else if("row"===e)r=Xe.ROW;else{const e=t.parentElement,n=Re(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),o=0===t.cellIndex;n&&(r|=Xe.ROW),o&&(r|=Xe.COLUMN),r===Xe.NO_STATUS&&(r=Xe.ROW)}}const l=Ve(r,t.colSpan,o);l.__rowSpan=t.rowSpan;const s=t.style.backgroundColor;""!==s&&(l.__backgroundColor=s);const i=t.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(i)&&(l.__verticalAlign=i);const c=e.get(Pe),a=c|function(e){let t=0;const n=e.fontWeight;"700"!==n&&"bold"!==n||(t|=Oe),"italic"===e.fontStyle&&(t|=Ae);const o=(e.textDecoration||"").split(" ");return o.includes("underline")&&(t|=Ke),o.includes("line-through")&&(t|=Ee),t}(t.style),u=e.get(De),h=t.style.color,d=h?{...u,color:h}:u,C=[];a!==c&&C.push(Ie(Pe,a)),d!==u&&C.push(Ie(De,d));const _=function(e){const t=[];let n=null;const o=()=>{if(null!==n){const e=n.getFirstChild();m(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)f(r)||g(r)||m(r)?null!==n?n.append(r):(n=p().append(r),t.push(n)):(o(),n=null,t.push(r));return o(),0===t.length&&t.push(p()),t}(e.$importChildren(t,{context:C})),S=n?_:Ue(_,t);return[l.splice(0,0,S)]},match:Be.tag("td","th"),name:"@lexical/table/cell"})],Zn=ve({dependencies:[jn,Fe(Le,{rules:Qn})],name:"@lexical/table/Import"});export{Et as $computeTableMap,kt as $computeTableMapSkipCellCheck,Ve as $createTableCellNode,Hn as $createTableNode,rt as $createTableNodeWithDimensions,nt as $createTableRowNode,Dt as $createTableSelection,It as $createTableSelectionFrom,wt as $deleteTableColumn,vt as $deleteTableColumnAtSelection,xt as $deleteTableColumn__EXPERIMENTAL,yt as $deleteTableRowAtSelection,Nt as $deleteTableRow__EXPERIMENTAL,yn as $findCellNode,Nn as $findTableNode,zn as $getElementForTableNode,Mt as $getNodeTriplet,Jt as $getTableAndElementByKey,lt as $getTableCellNodeFromLexicalNode,Lt as $getTableCellNodeRect,at as $getTableColumnIndexFromTableCellNode,it as $getTableNodeFromLexicalNodeOrThrow,ct as $getTableRowIndexFromTableCellNode,st as $getTableRowNodeFromTableCellNodeOrThrow,Ct as $insertTableColumn,_t as $insertTableColumnAtSelection,St as $insertTableColumn__EXPERIMENTAL,dt as $insertTableRow,gt as $insertTableRowAtSelection,mt as $insertTableRow__EXPERIMENTAL,Mn as $isScrollableTablesActive,Wt as $isSimpleTable,Ge as $isTableCellNode,Bn as $isTableNode,ot as $isTableRowNode,Pt as $isTableSelection,Rt as $mergeCells,zt as $moveTableColumn,ht as $removeTableRowAtIndex,At as $unmergeCell,Qe as INSERT_TABLE_COMMAND,Xe as TableCellHeaderStates,Ye as TableCellNode,jn as TableExtension,Zn as TableImportExtension,Qn as TableImportRules,Wn as TableNode,Yt as TableObserver,et as TableRowNode,Gn as TableRowSchema,Vn as TableSchema,on as applyTableHandlers,cn as getDOMCellFromTarget,Vt as getTableElement,sn as getTableObserverFromTableElement,Xn as registerTableCellUnmergeTransform,qn as registerTablePlugin,Yn as registerTableSelectionObserver,$n as setScrollableTablesActive};
|
|
@@ -30,8 +30,11 @@ export declare const TableRowSchema: ChildSchema;
|
|
|
30
30
|
*/
|
|
31
31
|
export declare const TableImportRules: (import("@lexical/html").DOMImportRule<import("@lexical/html").ElementSelectorBuilder<HTMLTableElement, Record<string, never>>> | import("@lexical/html").DOMImportRule<import("@lexical/html").ElementSelectorBuilder<HTMLTableCellElement, Record<string, never>>> | import("@lexical/html").DOMImportRule<import("@lexical/html").ElementSelectorBuilder<HTMLTableRowElement, Record<string, never>>>)[];
|
|
32
32
|
/**
|
|
33
|
-
* Bundles {@link TableImportRules}
|
|
34
|
-
*
|
|
33
|
+
* Bundles {@link TableImportRules} together with the runtime
|
|
34
|
+
* {@link TableExtension}. The application is expected to already have
|
|
35
|
+
* `CoreImportExtension` (or some equivalent) in its dependency graph —
|
|
36
|
+
* the core/text/paragraph/inline-format rules are a shared baseline,
|
|
37
|
+
* not something this leaf importer should re-declare.
|
|
35
38
|
*
|
|
36
39
|
* @experimental
|
|
37
40
|
*/
|
package/package.json
CHANGED
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
"table"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.45.0",
|
|
11
|
+
"version": "0.45.1-dev.0",
|
|
12
12
|
"main": "./dist/LexicalTable.js",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/html": "0.45.0",
|
|
18
|
-
"@lexical/internal": "0.45.0",
|
|
19
|
-
"@lexical/utils": "0.45.0",
|
|
20
|
-
"lexical": "0.45.0"
|
|
15
|
+
"@lexical/clipboard": "0.45.1-dev.0",
|
|
16
|
+
"@lexical/extension": "0.45.1-dev.0",
|
|
17
|
+
"@lexical/html": "0.45.1-dev.0",
|
|
18
|
+
"@lexical/internal": "0.45.1-dev.0",
|
|
19
|
+
"@lexical/utils": "0.45.1-dev.0",
|
|
20
|
+
"lexical": "0.45.1-dev.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import type {ChildSchema, ImportContextPairOrUpdater} from '@lexical/html';
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
+
$propagateTextAlignToBlockChildren,
|
|
12
13
|
contextValue,
|
|
13
|
-
CoreImportExtension,
|
|
14
14
|
defineImportRule,
|
|
15
15
|
DOMImportExtension,
|
|
16
16
|
ImportTextFormat,
|
|
@@ -75,9 +75,15 @@ function cellTextFormatMask(style: CSSStyleDeclaration): number {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
* Coalesce inline + line-break runs
|
|
79
|
-
*
|
|
80
|
-
*
|
|
78
|
+
* Coalesce inline + line-break runs inside a `<td>`/`<th>` into their own
|
|
79
|
+
* `ParagraphNode`s, leaving any pre-existing `ParagraphNode` children
|
|
80
|
+
* (real `<p>` elements, or the `ParagraphNode` stand-ins that
|
|
81
|
+
* {@link TransparentBlockRule} lowers `<div>`/`<section>`/… to) in
|
|
82
|
+
* place as their own paragraph siblings. Mirrors the legacy `<td>`
|
|
83
|
+
* importer where a bare `<td>789<div>000</div></td>` ended up as two
|
|
84
|
+
* paragraphs (`<p>789</p><p>000</p>`), and also drops a sole leading
|
|
85
|
+
* `<br>` that the legacy `removeSingleLineBreakNode` cleanup would have
|
|
86
|
+
* removed.
|
|
81
87
|
*/
|
|
82
88
|
function $packageCellChildren(children: LexicalNode[]): LexicalNode[] {
|
|
83
89
|
const result: LexicalNode[] = [];
|
|
@@ -105,9 +111,12 @@ function $packageCellChildren(children: LexicalNode[]): LexicalNode[] {
|
|
|
105
111
|
result.push(paragraph);
|
|
106
112
|
}
|
|
107
113
|
} else {
|
|
114
|
+
// Block children (paragraphs, nested tables, decorator blocks, …)
|
|
115
|
+
// start their own sibling — any inline run that was being
|
|
116
|
+
// accumulated into `paragraph` is closed off here.
|
|
108
117
|
flushSingleLineBreak();
|
|
109
|
-
result.push(child);
|
|
110
118
|
paragraph = null;
|
|
119
|
+
result.push(child);
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
122
|
flushSingleLineBreak();
|
|
@@ -238,13 +247,24 @@ const TableCellRule = defineImportRule({
|
|
|
238
247
|
if (cellStyle !== inheritedStyle) {
|
|
239
248
|
branchContext.push(contextValue(ImportTextStyle, cellStyle));
|
|
240
249
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
250
|
+
// {@link $packageCellChildren} keeps each `ParagraphNode` child
|
|
251
|
+
// (from a real `<p>`, or from {@link TransparentBlockRule}'s
|
|
252
|
+
// lowering of `<div>`/`<section>`/…) as its own sibling paragraph
|
|
253
|
+
// — matching legacy `<td>`'s `<td>789<div>000</div></td>` →
|
|
254
|
+
// `<p>789</p><p>000</p>` shape.
|
|
255
|
+
const packaged = $packageCellChildren(
|
|
256
|
+
ctx.$importChildren(el, {context: branchContext}),
|
|
257
|
+
);
|
|
258
|
+
// Only `<td>` propagates `text-align` onto its block children —
|
|
259
|
+
// mirroring legacy `wrapContinuousInlines`, which runs only for
|
|
260
|
+
// `isBlockDomNode` elements. `<th>` is intentionally absent from
|
|
261
|
+
// the block-tag set (see `BLOCK_TAG_RE` in `LexicalUtils.ts`), so a
|
|
262
|
+
// `<th style="text-align: start">` wrapping a bare `<p>` leaves the
|
|
263
|
+
// paragraph format empty.
|
|
264
|
+
const children = isHeader
|
|
265
|
+
? packaged
|
|
266
|
+
: $propagateTextAlignToBlockChildren(packaged, el);
|
|
267
|
+
return [cell.splice(0, 0, children)];
|
|
248
268
|
},
|
|
249
269
|
match: sel.tag('td', 'th'),
|
|
250
270
|
name: '@lexical/table/cell',
|
|
@@ -287,14 +307,16 @@ export const TableRowSchema: ChildSchema = {
|
|
|
287
307
|
export const TableImportRules = [TableRule, TableRowRule, TableCellRule];
|
|
288
308
|
|
|
289
309
|
/**
|
|
290
|
-
* Bundles {@link TableImportRules}
|
|
291
|
-
*
|
|
310
|
+
* Bundles {@link TableImportRules} together with the runtime
|
|
311
|
+
* {@link TableExtension}. The application is expected to already have
|
|
312
|
+
* `CoreImportExtension` (or some equivalent) in its dependency graph —
|
|
313
|
+
* the core/text/paragraph/inline-format rules are a shared baseline,
|
|
314
|
+
* not something this leaf importer should re-declare.
|
|
292
315
|
*
|
|
293
316
|
* @experimental
|
|
294
317
|
*/
|
|
295
318
|
export const TableImportExtension = defineExtension({
|
|
296
319
|
dependencies: [
|
|
297
|
-
CoreImportExtension,
|
|
298
320
|
TableExtension,
|
|
299
321
|
configExtension(DOMImportExtension, {rules: TableImportRules}),
|
|
300
322
|
],
|