diff --git a/packages/lexical-code/flow/LexicalCode.js.flow b/packages/lexical-code/flow/LexicalCode.js.flow
index 9c5cf449acd..fb1c16664c3 100644
--- a/packages/lexical-code/flow/LexicalCode.js.flow
+++ b/packages/lexical-code/flow/LexicalCode.js.flow
@@ -130,7 +130,6 @@ declare export class CodeNode extends ElementNode {
selection: RangeSelection,
restoreSelection?: boolean,
): null | ParagraphNode | CodeHighlightNode | TabNode;
- collapseAtStart(): true;
setLanguage(language: string): void;
getLanguage(): string | void;
}
diff --git a/packages/lexical-code/src/CodeNode.ts b/packages/lexical-code/src/CodeNode.ts
index 361accf2cc1..32bcc9ec62c 100644
--- a/packages/lexical-code/src/CodeNode.ts
+++ b/packages/lexical-code/src/CodeNode.ts
@@ -139,17 +139,17 @@ export class CodeNode extends ElementNode {
return isMultiLine
? {
- conversion: convertPreElement,
+ conversion: $convertPreElement,
priority: 1,
}
: null;
},
div: (node: Node) => ({
- conversion: convertDivElement,
+ conversion: $convertDivElement,
priority: 1,
}),
pre: (node: Node) => ({
- conversion: convertPreElement,
+ conversion: $convertPreElement,
priority: 0,
}),
table: (node: Node) => {
@@ -157,7 +157,7 @@ export class CodeNode extends ElementNode {
// domNode is a
since we matched it by nodeName
if (isGitHubCodeTable(table as HTMLTableElement)) {
return {
- conversion: convertTableElement,
+ conversion: $convertTableElement,
priority: 3,
};
}
@@ -294,14 +294,6 @@ export class CodeNode extends ElementNode {
return false;
}
- collapseAtStart(): boolean {
- const paragraph = $createParagraphNode();
- const children = this.getChildren();
- children.forEach((child) => paragraph.append(child));
- this.replace(paragraph);
- return true;
- }
-
setLanguage(language: string): void {
const writable = this.getWritable();
writable.__language = mapToPrismLanguage(language);
@@ -324,7 +316,7 @@ export function $isCodeNode(
return node instanceof CodeNode;
}
-function convertPreElement(domNode: Node): DOMConversionOutput {
+function $convertPreElement(domNode: Node): DOMConversionOutput {
let language;
if (isHTMLElement(domNode)) {
language = domNode.getAttribute(LANGUAGE_DATA_ATTRIBUTE);
@@ -332,7 +324,7 @@ function convertPreElement(domNode: Node): DOMConversionOutput {
return {node: $createCodeNode(language)};
}
-function convertDivElement(domNode: Node): DOMConversionOutput {
+function $convertDivElement(domNode: Node): DOMConversionOutput {
// domNode is a since we matched it by nodeName
const div = domNode as HTMLDivElement;
const isCode = isCodeElement(div);
@@ -346,7 +338,7 @@ function convertDivElement(domNode: Node): DOMConversionOutput {
};
}
-function convertTableElement(): DOMConversionOutput {
+function $convertTableElement(): DOMConversionOutput {
return {node: $createCodeNode()};
}
diff --git a/packages/lexical-rich-text/flow/LexicalRichText.js.flow b/packages/lexical-rich-text/flow/LexicalRichText.js.flow
index 0751c17fc5f..f0af663dd41 100644
--- a/packages/lexical-rich-text/flow/LexicalRichText.js.flow
+++ b/packages/lexical-rich-text/flow/LexicalRichText.js.flow
@@ -30,7 +30,6 @@ declare export class QuoteNode extends ElementNode {
selection: RangeSelection,
restoreSelection?: boolean,
): ParagraphNode;
- collapseAtStart(): true;
}
declare export function $createQuoteNode(): QuoteNode;
declare export function $isQuoteNode(
@@ -50,7 +49,6 @@ declare export class HeadingNode extends ElementNode {
selection: RangeSelection,
restoreSelection?: boolean,
): ParagraphNode;
- collapseAtStart(): true;
}
declare export function $createHeadingNode(
headingTag: HeadingTagType,
diff --git a/packages/lexical-rich-text/src/index.ts b/packages/lexical-rich-text/src/index.ts
index 7229c205302..e6dd51a8247 100644
--- a/packages/lexical-rich-text/src/index.ts
+++ b/packages/lexical-rich-text/src/index.ts
@@ -142,7 +142,7 @@ export class QuoteNode extends ElementNode {
static importDOM(): DOMConversionMap | null {
return {
blockquote: (node: Node) => ({
- conversion: convertBlockquoteElement,
+ conversion: $convertBlockquoteElement,
priority: 0,
}),
};
@@ -194,14 +194,6 @@ export class QuoteNode extends ElementNode {
this.insertAfter(newBlock, restoreSelection);
return newBlock;
}
-
- collapseAtStart(): true {
- const paragraph = $createParagraphNode();
- const children = this.getChildren();
- children.forEach((child) => paragraph.append(child));
- this.replace(paragraph);
- return true;
- }
}
export function $createQuoteNode(): QuoteNode {
@@ -259,27 +251,27 @@ export class HeadingNode extends ElementNode {
static importDOM(): DOMConversionMap | null {
return {
h1: (node: Node) => ({
- conversion: convertHeadingElement,
+ conversion: $convertHeadingElement,
priority: 0,
}),
h2: (node: Node) => ({
- conversion: convertHeadingElement,
+ conversion: $convertHeadingElement,
priority: 0,
}),
h3: (node: Node) => ({
- conversion: convertHeadingElement,
+ conversion: $convertHeadingElement,
priority: 0,
}),
h4: (node: Node) => ({
- conversion: convertHeadingElement,
+ conversion: $convertHeadingElement,
priority: 0,
}),
h5: (node: Node) => ({
- conversion: convertHeadingElement,
+ conversion: $convertHeadingElement,
priority: 0,
}),
h6: (node: Node) => ({
- conversion: convertHeadingElement,
+ conversion: $convertHeadingElement,
priority: 0,
}),
p: (node: Node) => {
@@ -370,16 +362,6 @@ export class HeadingNode extends ElementNode {
return newElement;
}
- collapseAtStart(): true {
- const newElement = !this.isEmpty()
- ? $createHeadingNode(this.getTag())
- : $createParagraphNode();
- const children = this.getChildren();
- children.forEach((child) => newElement.append(child));
- this.replace(newElement);
- return true;
- }
-
extractWithChild(): boolean {
return true;
}
@@ -392,7 +374,7 @@ function isGoogleDocsTitle(domNode: Node): boolean {
return false;
}
-function convertHeadingElement(element: HTMLElement): DOMConversionOutput {
+function $convertHeadingElement(element: HTMLElement): DOMConversionOutput {
const nodeName = element.nodeName.toLowerCase();
let node = null;
if (
@@ -411,7 +393,7 @@ function convertHeadingElement(element: HTMLElement): DOMConversionOutput {
return {node};
}
-function convertBlockquoteElement(element: HTMLElement): DOMConversionOutput {
+function $convertBlockquoteElement(element: HTMLElement): DOMConversionOutput {
const node = $createQuoteNode();
if (element.style !== null) {
node.setFormat(element.style.textAlign as ElementFormatType);
@@ -494,7 +476,7 @@ export function eventFiles(
return [hasFiles, Array.from(dataTransfer.files), hasContent];
}
-function handleIndentAndOutdent(
+function $handleIndentAndOutdent(
indentOrOutdent: (block: ElementNode) => void,
): boolean {
const selection = $getSelection();
@@ -696,7 +678,7 @@ export function registerRichText(editor: LexicalEditor): () => void {
editor.registerCommand(
INDENT_CONTENT_COMMAND,
() => {
- return handleIndentAndOutdent((block) => {
+ return $handleIndentAndOutdent((block) => {
const indent = block.getIndent();
block.setIndent(indent + 1);
});
@@ -706,7 +688,7 @@ export function registerRichText(editor: LexicalEditor): () => void {
editor.registerCommand(
OUTDENT_CONTENT_COMMAND,
() => {
- return handleIndentAndOutdent((block) => {
+ return $handleIndentAndOutdent((block) => {
const indent = block.getIndent();
if (indent > 0) {
block.setIndent(indent - 1);
diff --git a/packages/lexical-table/flow/LexicalTable.js.flow b/packages/lexical-table/flow/LexicalTable.js.flow
index e641b7723c0..1c26fc3bfab 100644
--- a/packages/lexical-table/flow/LexicalTable.js.flow
+++ b/packages/lexical-table/flow/LexicalTable.js.flow
@@ -56,7 +56,6 @@ declare export class TableCellNode extends ElementNode {
insertNewAfter(
selection: RangeSelection,
): null | ParagraphNode | TableCellNode;
- collapseAtStart(): true;
getColSpan(): number;
setColSpan(colSpan: number): this;
getRowSpan(): number;
@@ -71,7 +70,6 @@ declare export class TableCellNode extends ElementNode {
toggleHeaderStyle(headerState: TableCellHeaderState): TableCellNode;
hasHeader(): boolean;
updateDOM(prevNode: TableCellNode): boolean;
- collapseAtStart(): true;
canBeEmpty(): false;
}
declare export function $createTableCellNode(
@@ -101,7 +99,6 @@ declare export class TableNode extends ElementNode {
createDOM(config: EditorConfig): HTMLElement;
updateDOM(prevNode: TableNode, dom: HTMLElement): boolean;
insertNewAfter(selection: RangeSelection): null | ParagraphNode | TableNode;
- collapseAtStart(): true;
getCordsFromCellNode(
tableCellNode: TableCellNode,
table: TableDOMTable,
@@ -132,7 +129,6 @@ declare export class TableRowNode extends ElementNode {
insertNewAfter(
selection: RangeSelection,
): null | ParagraphNode | TableRowNode;
- collapseAtStart(): true;
}
declare export function $createTableRowNode(): TableRowNode;
declare export function $isTableRowNode(
diff --git a/packages/lexical-table/src/LexicalTableCellNode.ts b/packages/lexical-table/src/LexicalTableCellNode.ts
index d800bf7dc35..f903a4729f8 100644
--- a/packages/lexical-table/src/LexicalTableCellNode.ts
+++ b/packages/lexical-table/src/LexicalTableCellNode.ts
@@ -85,11 +85,11 @@ export class TableCellNode extends ElementNode {
static importDOM(): DOMConversionMap | null {
return {
td: (node: Node) => ({
- conversion: convertTableCellNodeElement,
+ conversion: $convertTableCellNodeElement,
priority: 0,
}),
th: (node: Node) => ({
- conversion: convertTableCellNodeElement,
+ conversion: $convertTableCellNodeElement,
priority: 0,
}),
};
@@ -279,10 +279,6 @@ export class TableCellNode extends ElementNode {
return true;
}
- collapseAtStart(): true {
- return true;
- }
-
canBeEmpty(): false {
return false;
}
@@ -292,7 +288,7 @@ export class TableCellNode extends ElementNode {
}
}
-export function convertTableCellNodeElement(
+export function $convertTableCellNodeElement(
domNode: Node,
): DOMConversionOutput {
const domNode_ = domNode as HTMLTableCellElement;
@@ -387,6 +383,8 @@ export function convertTableCellNodeElement(
node: tableCellNode,
};
}
+/** @deprecated renamed to $convertTableCellNodeElement by @lexical/eslint-plugin rules-of-lexical */
+export const convertTableCellNodeElement = $convertTableCellNodeElement;
export function $createTableCellNode(
headerState: TableCellHeaderState,
diff --git a/packages/lexical/flow/Lexical.js.flow b/packages/lexical/flow/Lexical.js.flow
index e5a2605df9e..639d78e1f9b 100644
--- a/packages/lexical/flow/Lexical.js.flow
+++ b/packages/lexical/flow/Lexical.js.flow
@@ -786,7 +786,6 @@ declare export class ParagraphNode extends ElementNode {
selection: RangeSelection,
restoreSelection?: boolean,
): ParagraphNode;
- collapseAtStart(): boolean;
static importJSON(
serializedParagraphNode: SerializedParagraphNode,
): ParagraphNode;
diff --git a/packages/lexical/src/nodes/LexicalParagraphNode.ts b/packages/lexical/src/nodes/LexicalParagraphNode.ts
index 8524af01e30..da54a7a83d8 100644
--- a/packages/lexical/src/nodes/LexicalParagraphNode.ts
+++ b/packages/lexical/src/nodes/LexicalParagraphNode.ts
@@ -32,7 +32,7 @@ import {
isHTMLElement,
} from '../LexicalUtils';
import {ElementNode} from './LexicalElementNode';
-import {$isTextNode, TextFormatType} from './LexicalTextNode';
+import {TextFormatType} from './LexicalTextNode';
export type SerializedParagraphNode = Spread<
{
@@ -98,7 +98,7 @@ export class ParagraphNode extends ElementNode {
static importDOM(): DOMConversionMap | null {
return {
p: (node: Node) => ({
- conversion: convertParagraphElement,
+ conversion: $convertParagraphElement,
priority: 0,
}),
};
@@ -164,33 +164,9 @@ export class ParagraphNode extends ElementNode {
this.insertAfter(newElement, restoreSelection);
return newElement;
}
-
- collapseAtStart(): boolean {
- const children = this.getChildren();
- // If we have an empty (trimmed) first paragraph and try and remove it,
- // delete the paragraph as long as we have another sibling to go to
- if (
- children.length === 0 ||
- ($isTextNode(children[0]) && children[0].getTextContent().trim() === '')
- ) {
- const nextSibling = this.getNextSibling();
- if (nextSibling !== null) {
- this.selectNext();
- this.remove();
- return true;
- }
- const prevSibling = this.getPreviousSibling();
- if (prevSibling !== null) {
- this.selectPrevious();
- this.remove();
- return true;
- }
- }
- return false;
- }
}
-function convertParagraphElement(element: HTMLElement): DOMConversionOutput {
+function $convertParagraphElement(element: HTMLElement): DOMConversionOutput {
const node = $createParagraphNode();
if (element.style) {
node.setFormat(element.style.textAlign as ElementFormatType);
diff --git a/packages/lexical/src/nodes/LexicalRootNode.ts b/packages/lexical/src/nodes/LexicalRootNode.ts
index b99576b8ea4..8ff2bcdf1d3 100644
--- a/packages/lexical/src/nodes/LexicalRootNode.ts
+++ b/packages/lexical/src/nodes/LexicalRootNode.ts
@@ -115,10 +115,6 @@ export class RootNode extends ElementNode {
version: 1,
};
}
-
- collapseAtStart(): true {
- return true;
- }
}
export function $createRootNode(): RootNode {