From 095502e543085b497fa18834c99e6d0eb9331997 Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Sat, 27 Apr 2024 13:56:21 -0700 Subject: [PATCH] npm run lint -- --fix --- .../src/emoji-plugin/EmojiPlugin.ts | 4 +- .../src/prepopulatedRichText.ts | 2 +- .../vanilla-js/src/prepopulatedRichText.ts | 2 +- packages/lexical-code/src/CodeHighlighter.ts | 40 +++++++-------- packages/lexical-code/src/CodeNode.ts | 14 +++--- .../src/generateContent.ts | 4 +- .../__tests__/unit/LexicalHistory.test.tsx | 10 ++-- packages/lexical-link/src/index.ts | 8 +-- .../lexical-list/src/LexicalListItemNode.ts | 4 +- packages/lexical-list/src/LexicalListNode.ts | 12 ++--- packages/lexical-list/src/formatList.ts | 6 +-- packages/lexical-list/src/utils.ts | 8 ++- .../lexical-markdown/src/MarkdownImport.ts | 8 +-- .../lexical-markdown/src/MarkdownShortcuts.ts | 8 +-- packages/lexical-offset/src/index.ts | 8 +-- packages/lexical-playground/src/App.tsx | 4 +- .../src/nodes/EquationNode.tsx | 6 +-- .../src/nodes/ExcalidrawNode/index.tsx | 4 +- .../src/nodes/ImageComponent.tsx | 20 ++++---- .../src/nodes/ImageNode.tsx | 4 +- .../src/nodes/InlineImageComponent.tsx | 20 ++++---- .../src/nodes/InlineImageNode.tsx | 4 +- .../src/nodes/LayoutContainerNode.ts | 4 +- .../src/nodes/MentionNode.ts | 4 +- .../src/nodes/PageBreakNode/index.tsx | 12 ++--- .../src/nodes/PollComponent.tsx | 8 +-- .../lexical-playground/src/nodes/PollNode.tsx | 4 +- .../src/nodes/TweetNode.tsx | 4 +- .../src/nodes/YouTubeNode.tsx | 4 +- .../src/plugins/AutocompletePlugin/index.tsx | 4 +- .../CollapsibleContainerNode.ts | 6 ++- .../CollapsibleContentNode.ts | 7 ++- .../CollapsiblePlugin/CollapsibleTitleNode.ts | 6 ++- .../src/plugins/CollapsiblePlugin/index.ts | 12 ++--- .../plugins/DraggableBlockPlugin/index.tsx | 4 +- .../src/plugins/EmojisPlugin/index.ts | 8 +-- .../FloatingLinkEditorPlugin/index.tsx | 22 ++++---- .../FloatingTextFormatToolbarPlugin/index.tsx | 14 +++--- .../src/plugins/ImagesPlugin/index.tsx | 20 ++++---- .../src/plugins/InlineImagePlugin/index.tsx | 20 ++++---- .../src/plugins/KeywordsPlugin/index.ts | 4 +- .../src/plugins/LayoutPlugin/LayoutPlugin.tsx | 10 ++-- .../plugins/ListMaxIndentLevelPlugin/index.ts | 4 +- .../src/plugins/MarkdownTransformers/index.ts | 6 +-- .../plugins/TableActionMenuPlugin/index.tsx | 4 +- .../src/server/validation.ts | 6 +-- .../src/LexicalAutoLinkPlugin.ts | 8 +-- .../src/LexicalBlockWithAlignableContents.tsx | 8 +-- .../lexical-react/src/LexicalHashtagPlugin.ts | 4 +- .../src/LexicalHorizontalRuleNode.tsx | 12 ++--- .../src/LexicalTabIndentationPlugin.tsx | 4 +- .../src/shared/useCharacterLimit.ts | 6 ++- packages/lexical-rich-text/src/index.ts | 24 ++++----- .../unit/LexicalSelectionHelpers.test.ts | 42 ++++++++-------- .../src/__tests__/utils/index.ts | 12 +++-- .../lexical-selection/src/lexical-node.ts | 4 +- .../lexical-table/src/LexicalTableCellNode.ts | 8 +-- .../lexical-table/src/LexicalTableNode.ts | 6 ++- .../lexical-table/src/LexicalTableRowNode.ts | 6 ++- .../src/LexicalTableSelectionHelpers.ts | 14 +++--- .../src/registerLexicalTextEntity.ts | 24 ++++----- packages/lexical-utils/src/index.ts | 4 +- packages/lexical-yjs/src/CollabTextNode.ts | 4 +- packages/lexical-yjs/src/SyncCursors.ts | 10 ++-- packages/lexical-yjs/src/SyncEditorStates.ts | 4 +- packages/lexical-yjs/src/Utils.ts | 11 ++-- packages/lexical/src/LexicalEvents.ts | 8 +-- packages/lexical/src/LexicalMutations.ts | 8 +-- packages/lexical/src/LexicalNode.ts | 10 ++-- packages/lexical/src/LexicalReconciler.ts | 50 ++++++++++--------- packages/lexical/src/LexicalSelection.ts | 46 +++++++++-------- packages/lexical/src/LexicalUpdates.ts | 26 ++++++---- packages/lexical/src/LexicalUtils.ts | 10 ++-- .../src/__tests__/unit/LexicalEditor.test.tsx | 20 ++++---- .../__tests__/unit/LexicalSelection.test.ts | 14 +++--- .../unit/LexicalSerialization.test.ts | 4 +- .../lexical/src/nodes/LexicalLineBreakNode.ts | 4 +- .../lexical/src/nodes/LexicalParagraphNode.ts | 4 +- packages/lexical/src/nodes/LexicalTextNode.ts | 4 +- 79 files changed, 438 insertions(+), 382 deletions(-) diff --git a/examples/vanilla-js-plugin/src/emoji-plugin/EmojiPlugin.ts b/examples/vanilla-js-plugin/src/emoji-plugin/EmojiPlugin.ts index a7bd6f40e87c..4e787e24ceae 100644 --- a/examples/vanilla-js-plugin/src/emoji-plugin/EmojiPlugin.ts +++ b/examples/vanilla-js-plugin/src/emoji-plugin/EmojiPlugin.ts @@ -11,7 +11,7 @@ import {LexicalEditor, TextNode} from 'lexical'; import {$createEmojiNode} from './EmojiNode'; import findEmoji from './findEmoji'; -function textNodeTransform(node: TextNode): void { +function $textNodeTransform(node: TextNode): void { if (!node.isSimpleText() || node.hasFormat('code')) { return; } @@ -46,5 +46,5 @@ function textNodeTransform(node: TextNode): void { export function registerEmoji(editor: LexicalEditor): () => void { // We don't use editor.registerUpdateListener here as alternative approach where we rely // on update listener is highly discouraged as it triggers an additional render (the most expensive lifecycle operation). - return editor.registerNodeTransform(TextNode, textNodeTransform); + return editor.registerNodeTransform(TextNode, $textNodeTransform); } diff --git a/examples/vanilla-js-plugin/src/prepopulatedRichText.ts b/examples/vanilla-js-plugin/src/prepopulatedRichText.ts index 518a5eba0286..2c9ba96b159e 100644 --- a/examples/vanilla-js-plugin/src/prepopulatedRichText.ts +++ b/examples/vanilla-js-plugin/src/prepopulatedRichText.ts @@ -7,7 +7,7 @@ */ import {$createParagraphNode, $createTextNode, $getRoot} from 'lexical'; -export default function prepopulatedRichText() { +export default function $prepopulatedRichText() { const root = $getRoot(); if (root.getFirstChild() !== null) { return; diff --git a/examples/vanilla-js/src/prepopulatedRichText.ts b/examples/vanilla-js/src/prepopulatedRichText.ts index 35b3e0e3870c..ed7fe8c969c5 100644 --- a/examples/vanilla-js/src/prepopulatedRichText.ts +++ b/examples/vanilla-js/src/prepopulatedRichText.ts @@ -8,7 +8,7 @@ import {$createHeadingNode, $createQuoteNode} from '@lexical/rich-text'; import {$createParagraphNode, $createTextNode, $getRoot} from 'lexical'; -export default function prepopulatedRichText() { +export default function $prepopulatedRichText() { const root = $getRoot(); if (root.getFirstChild() !== null) { return; diff --git a/packages/lexical-code/src/CodeHighlighter.ts b/packages/lexical-code/src/CodeHighlighter.ts index bff05ef2315a..329e2ed19a2d 100644 --- a/packages/lexical-code/src/CodeHighlighter.ts +++ b/packages/lexical-code/src/CodeHighlighter.ts @@ -201,7 +201,7 @@ export function getEndOfCodeInLine( return lastNode; } -function textNodeTransform( +function $textNodeTransform( node: TextNode, editor: LexicalEditor, tokenizer: Tokenizer, @@ -275,7 +275,7 @@ function codeNodeTransform( // in its final state editor.update( () => { - updateAndRetainSelection(nodeKey, () => { + $updateAndRetainSelection(nodeKey, () => { const currentNode = $getNodeByKey(nodeKey); if (!$isCodeNode(currentNode) || !currentNode.isAttached()) { @@ -287,7 +287,7 @@ function codeNodeTransform( code, currentNode.getLanguage() || tokenizer.defaultLanguage, ); - const highlightNodes = getHighlightNodes(tokens); + const highlightNodes = $getHighlightNodes(tokens); const diffRange = getDiffRange( currentNode.getChildren(), highlightNodes, @@ -311,7 +311,7 @@ function codeNodeTransform( ); } -function getHighlightNodes( +function $getHighlightNodes( tokens: Array, type?: string, ): LexicalNode[] { @@ -334,9 +334,9 @@ function getHighlightNodes( } else { const {content} = token; if (typeof content === 'string') { - nodes.push(...getHighlightNodes([content], token.type)); + nodes.push(...$getHighlightNodes([content], token.type)); } else if (Array.isArray(content)) { - nodes.push(...getHighlightNodes(content, token.type)); + nodes.push(...$getHighlightNodes(content, token.type)); } } } @@ -346,7 +346,7 @@ function getHighlightNodes( // Wrapping update function into selection retainer, that tries to keep cursor at the same // position as before. -function updateAndRetainSelection( +function $updateAndRetainSelection( nodeKey: NodeKey, updateFn: () => boolean, ): void { @@ -510,7 +510,7 @@ function $getCodeLines( return lines; } -function handleTab(shiftKey: boolean): null | LexicalCommand { +function $handleTab(shiftKey: boolean): null | LexicalCommand { const selection = $getSelection(); if (!$isRangeSelection(selection) || !$isSelectionInCode(selection)) { return null; @@ -564,7 +564,7 @@ function handleTab(shiftKey: boolean): null | LexicalCommand { return tabOrOutdent; } -function handleMultilineIndent(type: LexicalCommand): boolean { +function $handleMultilineIndent(type: LexicalCommand): boolean { const selection = $getSelection(); if (!$isRangeSelection(selection) || !$isSelectionInCode(selection)) { return false; @@ -627,7 +627,7 @@ function handleMultilineIndent(type: LexicalCommand): boolean { return true; } -function handleShiftLines( +function $handleShiftLines( type: LexicalCommand, event: KeyboardEvent, ): boolean { @@ -759,7 +759,7 @@ function handleShiftLines( return true; } -function handleMoveTo( +function $handleMoveTo( type: LexicalCommand, event: KeyboardEvent, ): boolean { @@ -834,15 +834,15 @@ export function registerCodeHighlighting( codeNodeTransform(node, editor, tokenizer as Tokenizer), ), editor.registerNodeTransform(TextNode, (node) => - textNodeTransform(node, editor, tokenizer as Tokenizer), + $textNodeTransform(node, editor, tokenizer as Tokenizer), ), editor.registerNodeTransform(CodeHighlightNode, (node) => - textNodeTransform(node, editor, tokenizer as Tokenizer), + $textNodeTransform(node, editor, tokenizer as Tokenizer), ), editor.registerCommand( KEY_TAB_COMMAND, (event) => { - const command = handleTab(event.shiftKey); + const command = $handleTab(event.shiftKey); if (command === null) { return false; } @@ -866,32 +866,32 @@ export function registerCodeHighlighting( ), editor.registerCommand( INDENT_CONTENT_COMMAND, - (payload): boolean => handleMultilineIndent(INDENT_CONTENT_COMMAND), + (payload): boolean => $handleMultilineIndent(INDENT_CONTENT_COMMAND), COMMAND_PRIORITY_LOW, ), editor.registerCommand( OUTDENT_CONTENT_COMMAND, - (payload): boolean => handleMultilineIndent(OUTDENT_CONTENT_COMMAND), + (payload): boolean => $handleMultilineIndent(OUTDENT_CONTENT_COMMAND), COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_ARROW_UP_COMMAND, - (payload): boolean => handleShiftLines(KEY_ARROW_UP_COMMAND, payload), + (payload): boolean => $handleShiftLines(KEY_ARROW_UP_COMMAND, payload), COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_ARROW_DOWN_COMMAND, - (payload): boolean => handleShiftLines(KEY_ARROW_DOWN_COMMAND, payload), + (payload): boolean => $handleShiftLines(KEY_ARROW_DOWN_COMMAND, payload), COMMAND_PRIORITY_LOW, ), editor.registerCommand( MOVE_TO_END, - (payload): boolean => handleMoveTo(MOVE_TO_END, payload), + (payload): boolean => $handleMoveTo(MOVE_TO_END, payload), COMMAND_PRIORITY_LOW, ), editor.registerCommand( MOVE_TO_START, - (payload): boolean => handleMoveTo(MOVE_TO_START, payload), + (payload): boolean => $handleMoveTo(MOVE_TO_START, payload), COMMAND_PRIORITY_LOW, ), ); diff --git a/packages/lexical-code/src/CodeNode.ts b/packages/lexical-code/src/CodeNode.ts index ef2588aa598c..1e5c43ac3320 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, }; } @@ -330,7 +330,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); @@ -338,7 +338,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); @@ -359,7 +359,7 @@ function convertDivElement(domNode: Node): DOMConversionOutput { }; } -function convertTableElement(): DOMConversionOutput { +function $convertTableElement(): DOMConversionOutput { return {node: $createCodeNode()}; } diff --git a/packages/lexical-devtools-core/src/generateContent.ts b/packages/lexical-devtools-core/src/generateContent.ts index db702c6ddd02..3e1f63d1e88c 100644 --- a/packages/lexical-devtools-core/src/generateContent.ts +++ b/packages/lexical-devtools-core/src/generateContent.ts @@ -120,7 +120,7 @@ export function generateContent( ' ', )} ${nodeKeyDisplay} ${typeDisplay} ${idsDisplay} ${printNode(node)}\n`; - res += printSelectedCharsLine({ + res += $printSelectedCharsLine({ indent, isSelected, node, @@ -364,7 +364,7 @@ function printTitleProperties(node: LinkNode) { return str; } -function printSelectedCharsLine({ +function $printSelectedCharsLine({ indent, isSelected, node, diff --git a/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx b/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx index c1017b186840..b02845e95549 100644 --- a/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx +++ b/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx @@ -128,8 +128,8 @@ describe('LexicalHistory tests', () => { await ReactTestUtils.act(async () => { await editor.update(() => { const root = $getRoot(); - const paragraph1 = createParagraphNode('AAA'); - const paragraph2 = createParagraphNode('BBB'); + const paragraph1 = $createParagraphNode_('AAA'); + const paragraph2 = $createParagraphNode_('BBB'); // The editor has one child that is an empty // paragraph Node. @@ -223,7 +223,7 @@ describe('LexicalHistory tests', () => { await ReactTestUtils.act(async () => { await editor.update(() => { const root = $getRoot(); - const paragraph = createParagraphNode('foo'); + const paragraph = $createParagraphNode_('foo'); root.append(paragraph); }); }); @@ -261,7 +261,7 @@ describe('LexicalHistory tests', () => { await ReactTestUtils.act(async () => { await editor.update(() => { const root = $getRoot(); - const paragraph = createParagraphNode('foo'); + const paragraph = $createParagraphNode_('foo'); root.append(paragraph); }); }); @@ -315,7 +315,7 @@ describe('LexicalHistory tests', () => { }); }); -const createParagraphNode = (text: string) => { +const $createParagraphNode_ = (text: string) => { const paragraph = $createParagraphNode(); const textNode = $createTextNode(text); diff --git a/packages/lexical-link/src/index.ts b/packages/lexical-link/src/index.ts index 0682ea6f14f0..6425cef8cec5 100644 --- a/packages/lexical-link/src/index.ts +++ b/packages/lexical-link/src/index.ts @@ -140,7 +140,7 @@ export class LinkNode extends ElementNode { static importDOM(): DOMConversionMap | null { return { a: (node: Node) => ({ - conversion: convertAnchorElement, + conversion: $convertAnchorElement, priority: 1, }), }; @@ -270,7 +270,7 @@ export class LinkNode extends ElementNode { } } -function convertAnchorElement(domNode: Node): DOMConversionOutput { +function $convertAnchorElement(domNode: Node): DOMConversionOutput { let node = null; if (isHTMLAnchorElement(domNode)) { const content = domNode.textContent; @@ -407,7 +407,7 @@ export const TOGGLE_LINK_COMMAND: LexicalCommand< * @param url - The URL the link directs to. * @param attributes - Optional HTML a tag attributes. { target, rel, title } */ -export function toggleLink( +export function $toggleLink( url: null | string, attributes: LinkAttributes = {}, ): void { @@ -523,6 +523,8 @@ export function toggleLink( }); } } +/** @deprecated renamed to $toggleLink by @lexical/eslint-plugin rules-of-lexical */ +export const toggleLink = $toggleLink; function $getAncestor( node: LexicalNode, diff --git a/packages/lexical-list/src/LexicalListItemNode.ts b/packages/lexical-list/src/LexicalListItemNode.ts index 497583adf887..c63f24653eae 100644 --- a/packages/lexical-list/src/LexicalListItemNode.ts +++ b/packages/lexical-list/src/LexicalListItemNode.ts @@ -117,7 +117,7 @@ export class ListItemNode extends ElementNode { static importDOM(): DOMConversionMap | null { return { li: (node: Node) => ({ - conversion: convertListItemElement, + conversion: $convertListItemElement, priority: 0, }), }; @@ -491,7 +491,7 @@ function updateListItemChecked( } } -function convertListItemElement(domNode: Node): DOMConversionOutput { +function $convertListItemElement(domNode: Node): DOMConversionOutput { const checked = isHTMLElement(domNode) && domNode.getAttribute('aria-checked') === 'true'; return {node: $createListItemNode(checked)}; diff --git a/packages/lexical-list/src/LexicalListNode.ts b/packages/lexical-list/src/LexicalListNode.ts index 9e3039a3e3f7..923bf48a88f8 100644 --- a/packages/lexical-list/src/LexicalListNode.ts +++ b/packages/lexical-list/src/LexicalListNode.ts @@ -106,7 +106,7 @@ export class ListNode extends ElementNode { } // @ts-expect-error Internal field. dom.__lexicalListType = this.__listType; - setListThemeClassNames(dom, config.theme, this); + $setListThemeClassNames(dom, config.theme, this); return dom; } @@ -120,7 +120,7 @@ export class ListNode extends ElementNode { return true; } - setListThemeClassNames(dom, config.theme, this); + $setListThemeClassNames(dom, config.theme, this); return false; } @@ -136,11 +136,11 @@ export class ListNode extends ElementNode { static importDOM(): DOMConversionMap | null { return { ol: (node: Node) => ({ - conversion: convertListNode, + conversion: $convertListNode, priority: 0, }), ul: (node: Node) => ({ - conversion: convertListNode, + conversion: $convertListNode, priority: 0, }), }; @@ -216,7 +216,7 @@ export class ListNode extends ElementNode { } } -function setListThemeClassNames( +function $setListThemeClassNames( dom: HTMLElement, editorThemeClasses: EditorThemeClasses, node: ListNode, @@ -302,7 +302,7 @@ function normalizeChildren(nodes: Array): Array { return normalizedListItems; } -function convertListNode(domNode: Node): DOMConversionOutput { +function $convertListNode(domNode: Node): DOMConversionOutput { const nodeName = domNode.nodeName.toLowerCase(); let node = null; if (nodeName === 'ol') { diff --git a/packages/lexical-list/src/formatList.ts b/packages/lexical-list/src/formatList.ts index 2263edfb7575..565887c57d53 100644 --- a/packages/lexical-list/src/formatList.ts +++ b/packages/lexical-list/src/formatList.ts @@ -109,7 +109,7 @@ export function insertList(editor: LexicalEditor, listType: ListType): void { !$isListItemNode(node) && !handled.has(node.getKey()) ) { - createListOrMerge(node, listType); + $createListOrMerge(node, listType); continue; } @@ -132,7 +132,7 @@ export function insertList(editor: LexicalEditor, listType: ListType): void { if ($isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) { handled.add(parentKey); - createListOrMerge(parent, listType); + $createListOrMerge(parent, listType); break; } @@ -149,7 +149,7 @@ function append(node: ElementNode, nodesToAppend: Array) { node.splice(node.getChildrenSize(), 0, nodesToAppend); } -function createListOrMerge(node: ElementNode, listType: ListType): ListNode { +function $createListOrMerge(node: ElementNode, listType: ListType): ListNode { if ($isListNode(node)) { return node; } diff --git a/packages/lexical-list/src/utils.ts b/packages/lexical-list/src/utils.ts index 2ee99e4c08c8..01d3a34ab389 100644 --- a/packages/lexical-list/src/utils.ts +++ b/packages/lexical-list/src/utils.ts @@ -148,7 +148,7 @@ export function isNestedListNode( * @param node - Node to start the search. * @returns The first ListItemNode found, or null if none exist. */ -export function findNearestListItemNode( +export function $findNearestListItemNode( node: LexicalNode, ): ListItemNode | null { const matchingParent = $findMatchingParent(node, (parent) => @@ -156,6 +156,8 @@ export function findNearestListItemNode( ); return matchingParent as ListItemNode | null; } +/** @deprecated renamed to $findNearestListItemNode by @lexical/eslint-plugin rules-of-lexical */ +export const findNearestListItemNode = $findNearestListItemNode; /** * Takes a deeply nested ListNode or ListItemNode and traverses up the branch to delete the first @@ -199,7 +201,9 @@ export function $removeHighestEmptyListParent( * @param node - The node to be wrapped into a ListItemNode * @returns The ListItemNode which the passed node is wrapped in. */ -export function wrapInListItem(node: LexicalNode): ListItemNode { +export function $wrapInListItem(node: LexicalNode): ListItemNode { const listItemWrapper = $createListItemNode(); return listItemWrapper.append(node); } +/** @deprecated renamed to $wrapInListItem by @lexical/eslint-plugin rules-of-lexical */ +export const wrapInListItem = $wrapInListItem; diff --git a/packages/lexical-markdown/src/MarkdownImport.ts b/packages/lexical-markdown/src/MarkdownImport.ts index 9461d2fef66a..76e40e2ca5ed 100644 --- a/packages/lexical-markdown/src/MarkdownImport.ts +++ b/packages/lexical-markdown/src/MarkdownImport.ts @@ -61,14 +61,14 @@ export function createMarkdownImport( // is ignored for further processing // TODO: // Abstract it to be dynamic as other transformers (add multiline match option) - const [codeBlockNode, shiftedIndex] = importCodeBlock(lines, i, root); + const [codeBlockNode, shiftedIndex] = $importCodeBlock(lines, i, root); if (codeBlockNode != null) { i = shiftedIndex; continue; } - importBlocks( + $importBlocks( lineText, root, byType.element, @@ -106,7 +106,7 @@ function isEmptyParagraph(node: LexicalNode): boolean { ); } -function importBlocks( +function $importBlocks( lineText: string, rootNode: ElementNode, elementTransformers: Array, @@ -167,7 +167,7 @@ function importBlocks( } } -function importCodeBlock( +function $importCodeBlock( lines: Array, startLineIndex: number, rootNode: ElementNode, diff --git a/packages/lexical-markdown/src/MarkdownShortcuts.ts b/packages/lexical-markdown/src/MarkdownShortcuts.ts index f89af2129e3d..0aee32927201 100644 --- a/packages/lexical-markdown/src/MarkdownShortcuts.ts +++ b/packages/lexical-markdown/src/MarkdownShortcuts.ts @@ -118,7 +118,7 @@ function runTextMatchTransformers( return false; } -function runTextFormatTransformers( +function $runTextFormatTransformers( anchorNode: TextNode, anchorOffset: number, textFormatTransformers: Readonly< @@ -350,7 +350,7 @@ export function registerMarkdownShortcuts( } } - const transform = ( + const $transform = ( parentNode: ElementNode, anchorNode: TextNode, anchorOffset: number, @@ -376,7 +376,7 @@ export function registerMarkdownShortcuts( return; } - runTextFormatTransformers( + $runTextFormatTransformers( anchorNode, anchorOffset, textFormatTransformersIndex, @@ -431,7 +431,7 @@ export function registerMarkdownShortcuts( return; } - transform(parentNode, anchorNode, selection.anchor.offset); + $transform(parentNode, anchorNode, selection.anchor.offset); }); }, ); diff --git a/packages/lexical-offset/src/index.ts b/packages/lexical-offset/src/index.ts index 328dc0d14058..7270d2931060 100644 --- a/packages/lexical-offset/src/index.ts +++ b/packages/lexical-offset/src/index.ts @@ -437,7 +437,7 @@ function $createOffsetNode( const start = state.offset; if ($isElementNode(node)) { - const childKeys = createChildrenArray(node, nodeMap); + const childKeys = $createChildrenArray(node, nodeMap); const blockIsEmpty = childKeys.length === 0; const child = blockIsEmpty ? null @@ -537,7 +537,7 @@ function $createOffsetChild( return firstNode; } -export function createChildrenArray( +export function $createChildrenArray( element: ElementNode, nodeMap: null | NodeMap, ): Array { @@ -554,6 +554,8 @@ export function createChildrenArray( } return children; } +/** @deprecated renamed to $createChildrenArray by @lexical/eslint-plugin rules-of-lexical */ +export const createChildrenArray = $createChildrenArray; export function $createOffsetView( editor: LexicalEditor, @@ -574,7 +576,7 @@ export function $createOffsetView( const node = $createOffsetChild( state, - createChildrenArray(root, nodeMap), + $createChildrenArray(root, nodeMap), null, nodeMap, offsetMap, diff --git a/packages/lexical-playground/src/App.tsx b/packages/lexical-playground/src/App.tsx index 334773dec2cf..af4fc577bdd9 100644 --- a/packages/lexical-playground/src/App.tsx +++ b/packages/lexical-playground/src/App.tsx @@ -32,7 +32,7 @@ console.warn( 'If you are profiling the playground app, please ensure you turn off the debug view. You can disable it by pressing on the settings control in the bottom-left of your screen and toggling the debug view setting.', ); -function prepopulatedRichText() { +function $prepopulatedRichText() { const root = $getRoot(); if (root.getFirstChild() === null) { const heading = $createHeadingNode('h1'); @@ -122,7 +122,7 @@ function App(): JSX.Element { ? null : emptyEditor ? undefined - : prepopulatedRichText, + : $prepopulatedRichText, namespace: 'Playground', nodes: [...PlaygroundNodes], onError: (error: Error) => { diff --git a/packages/lexical-playground/src/nodes/EquationNode.tsx b/packages/lexical-playground/src/nodes/EquationNode.tsx index e00545ebfc27..373b821f9885 100644 --- a/packages/lexical-playground/src/nodes/EquationNode.tsx +++ b/packages/lexical-playground/src/nodes/EquationNode.tsx @@ -31,7 +31,7 @@ export type SerializedEquationNode = Spread< SerializedLexicalNode >; -function convertEquationElement( +function $convertEquationElement( domNode: HTMLElement, ): null | DOMConversionOutput { let equation = domNode.getAttribute('data-lexical-equation'); @@ -112,7 +112,7 @@ export class EquationNode extends DecoratorNode { return null; } return { - conversion: convertEquationElement, + conversion: $convertEquationElement, priority: 2, }; }, @@ -121,7 +121,7 @@ export class EquationNode extends DecoratorNode { return null; } return { - conversion: convertEquationElement, + conversion: $convertEquationElement, priority: 1, }; }, diff --git a/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx b/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx index 303344f55ae8..693a7418cc14 100644 --- a/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx +++ b/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx @@ -35,7 +35,7 @@ export type SerializedExcalidrawNode = Spread< SerializedLexicalNode >; -function convertExcalidrawElement( +function $convertExcalidrawElement( domNode: HTMLElement, ): DOMConversionOutput | null { const excalidrawData = domNode.getAttribute('data-lexical-excalidraw-json'); @@ -135,7 +135,7 @@ export class ExcalidrawNode extends DecoratorNode { return null; } return { - conversion: convertExcalidrawElement, + conversion: $convertExcalidrawElement, priority: 1, }; }, diff --git a/packages/lexical-playground/src/nodes/ImageComponent.tsx b/packages/lexical-playground/src/nodes/ImageComponent.tsx index d0ddbc2b9a6b..64aa336c589e 100644 --- a/packages/lexical-playground/src/nodes/ImageComponent.tsx +++ b/packages/lexical-playground/src/nodes/ImageComponent.tsx @@ -143,7 +143,7 @@ export default function ImageComponent({ const [selection, setSelection] = useState(null); const activeEditorRef = useRef(null); - const onDelete = useCallback( + const $onDelete = useCallback( (payload: KeyboardEvent) => { if (isSelected && $isNodeSelection($getSelection())) { const event: KeyboardEvent = payload; @@ -159,7 +159,7 @@ export default function ImageComponent({ [isSelected, nodeKey], ); - const onEnter = useCallback( + const $onEnter = useCallback( (event: KeyboardEvent) => { const latestSelection = $getSelection(); const buttonElem = buttonRef.current; @@ -188,7 +188,7 @@ export default function ImageComponent({ [caption, isSelected, showCaption], ); - const onEscape = useCallback( + const $onEscape = useCallback( (event: KeyboardEvent) => { if ( activeEditorRef.current === caption || @@ -293,18 +293,18 @@ export default function ImageComponent({ ), editor.registerCommand( KEY_DELETE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_BACKSPACE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), - editor.registerCommand(KEY_ENTER_COMMAND, onEnter, COMMAND_PRIORITY_LOW), + editor.registerCommand(KEY_ENTER_COMMAND, $onEnter, COMMAND_PRIORITY_LOW), editor.registerCommand( KEY_ESCAPE_COMMAND, - onEscape, + $onEscape, COMMAND_PRIORITY_LOW, ), ); @@ -322,9 +322,9 @@ export default function ImageComponent({ isResizing, isSelected, nodeKey, - onDelete, - onEnter, - onEscape, + $onDelete, + $onEnter, + $onEscape, onClick, onRightClick, setSelected, diff --git a/packages/lexical-playground/src/nodes/ImageNode.tsx b/packages/lexical-playground/src/nodes/ImageNode.tsx index 7529187fad9d..4bef828e5202 100644 --- a/packages/lexical-playground/src/nodes/ImageNode.tsx +++ b/packages/lexical-playground/src/nodes/ImageNode.tsx @@ -37,7 +37,7 @@ export interface ImagePayload { captionsEnabled?: boolean; } -function convertImageElement(domNode: Node): null | DOMConversionOutput { +function $convertImageElement(domNode: Node): null | DOMConversionOutput { const img = domNode as HTMLImageElement; if (img.src.startsWith('file:///')) { return null; @@ -120,7 +120,7 @@ export class ImageNode extends DecoratorNode { static importDOM(): DOMConversionMap | null { return { img: (node: Node) => ({ - conversion: convertImageElement, + conversion: $convertImageElement, priority: 0, }), }; diff --git a/packages/lexical-playground/src/nodes/InlineImageComponent.tsx b/packages/lexical-playground/src/nodes/InlineImageComponent.tsx index 671858158794..569b299e2acc 100644 --- a/packages/lexical-playground/src/nodes/InlineImageComponent.tsx +++ b/packages/lexical-playground/src/nodes/InlineImageComponent.tsx @@ -202,7 +202,7 @@ export default function InlineImageComponent({ const [selection, setSelection] = useState(null); const activeEditorRef = useRef(null); - const onDelete = useCallback( + const $onDelete = useCallback( (payload: KeyboardEvent) => { if (isSelected && $isNodeSelection($getSelection())) { const event: KeyboardEvent = payload; @@ -218,7 +218,7 @@ export default function InlineImageComponent({ [isSelected, nodeKey], ); - const onEnter = useCallback( + const $onEnter = useCallback( (event: KeyboardEvent) => { const latestSelection = $getSelection(); const buttonElem = buttonRef.current; @@ -247,7 +247,7 @@ export default function InlineImageComponent({ [caption, isSelected, showCaption], ); - const onEscape = useCallback( + const $onEscape = useCallback( (event: KeyboardEvent) => { if ( activeEditorRef.current === caption || @@ -317,18 +317,18 @@ export default function InlineImageComponent({ ), editor.registerCommand( KEY_DELETE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_BACKSPACE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), - editor.registerCommand(KEY_ENTER_COMMAND, onEnter, COMMAND_PRIORITY_LOW), + editor.registerCommand(KEY_ENTER_COMMAND, $onEnter, COMMAND_PRIORITY_LOW), editor.registerCommand( KEY_ESCAPE_COMMAND, - onEscape, + $onEscape, COMMAND_PRIORITY_LOW, ), ); @@ -341,9 +341,9 @@ export default function InlineImageComponent({ editor, isSelected, nodeKey, - onDelete, - onEnter, - onEscape, + $onDelete, + $onEnter, + $onEscape, setSelected, ]); diff --git a/packages/lexical-playground/src/nodes/InlineImageNode.tsx b/packages/lexical-playground/src/nodes/InlineImageNode.tsx index 37eb56e9d5fa..3ed9eca084b1 100644 --- a/packages/lexical-playground/src/nodes/InlineImageNode.tsx +++ b/packages/lexical-playground/src/nodes/InlineImageNode.tsx @@ -44,7 +44,7 @@ export interface UpdateInlineImagePayload { position?: Position; } -function convertInlineImageElement(domNode: Node): null | DOMConversionOutput { +function $convertInlineImageElement(domNode: Node): null | DOMConversionOutput { if (domNode instanceof HTMLImageElement) { const {alt: altText, src, width, height} = domNode; const node = $createInlineImageNode({altText, height, src, width}); @@ -116,7 +116,7 @@ export class InlineImageNode extends DecoratorNode { static importDOM(): DOMConversionMap | null { return { img: (node: Node) => ({ - conversion: convertInlineImageElement, + conversion: $convertInlineImageElement, priority: 0, }), }; diff --git a/packages/lexical-playground/src/nodes/LayoutContainerNode.ts b/packages/lexical-playground/src/nodes/LayoutContainerNode.ts index 3075d3780358..b89eed53b896 100644 --- a/packages/lexical-playground/src/nodes/LayoutContainerNode.ts +++ b/packages/lexical-playground/src/nodes/LayoutContainerNode.ts @@ -27,7 +27,7 @@ export type SerializedLayoutContainerNode = Spread< SerializedElementNode >; -function convertLayoutContainerElement( +function $convertLayoutContainerElement( domNode: HTMLElement, ): DOMConversionOutput | null { const styleAttributes = window.getComputedStyle(domNode); @@ -87,7 +87,7 @@ export class LayoutContainerNode extends ElementNode { return null; } return { - conversion: convertLayoutContainerElement, + conversion: $convertLayoutContainerElement, priority: 2, }; }, diff --git a/packages/lexical-playground/src/nodes/MentionNode.ts b/packages/lexical-playground/src/nodes/MentionNode.ts index f778d048439e..4ee8c73b70a5 100644 --- a/packages/lexical-playground/src/nodes/MentionNode.ts +++ b/packages/lexical-playground/src/nodes/MentionNode.ts @@ -27,7 +27,7 @@ export type SerializedMentionNode = Spread< SerializedTextNode >; -function convertMentionElement( +function $convertMentionElement( domNode: HTMLElement, ): DOMConversionOutput | null { const textContent = domNode.textContent; @@ -98,7 +98,7 @@ export class MentionNode extends TextNode { return null; } return { - conversion: convertMentionElement, + conversion: $convertMentionElement, priority: 1, }; }, diff --git a/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx b/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx index d67771c30ab5..44f0f84d1076 100644 --- a/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx +++ b/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx @@ -36,7 +36,7 @@ function PageBreakComponent({nodeKey}: {nodeKey: NodeKey}) { const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey); - const onDelete = useCallback( + const $onDelete = useCallback( (event: KeyboardEvent) => { event.preventDefault(); if (isSelected && $isNodeSelection($getSelection())) { @@ -72,16 +72,16 @@ function PageBreakComponent({nodeKey}: {nodeKey: NodeKey}) { ), editor.registerCommand( KEY_DELETE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_BACKSPACE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), ); - }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]); + }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]); useEffect(() => { const pbElem = editor.getElementByKey(nodeKey); @@ -115,7 +115,7 @@ export class PageBreakNode extends DecoratorNode { } return { - conversion: convertPageBreakElement, + conversion: $convertPageBreakElement, priority: COMMAND_PRIORITY_HIGH, }; }, @@ -153,7 +153,7 @@ export class PageBreakNode extends DecoratorNode { } } -function convertPageBreakElement(): DOMConversionOutput { +function $convertPageBreakElement(): DOMConversionOutput { return {node: $createPageBreakNode()}; } diff --git a/packages/lexical-playground/src/nodes/PollComponent.tsx b/packages/lexical-playground/src/nodes/PollComponent.tsx index d016b1b62bd9..45d38ef9d282 100644 --- a/packages/lexical-playground/src/nodes/PollComponent.tsx +++ b/packages/lexical-playground/src/nodes/PollComponent.tsx @@ -144,7 +144,7 @@ export default function PollComponent({ const [selection, setSelection] = useState(null); const ref = useRef(null); - const onDelete = useCallback( + const $onDelete = useCallback( (payload: KeyboardEvent) => { if (isSelected && $isNodeSelection($getSelection())) { const event: KeyboardEvent = payload; @@ -184,16 +184,16 @@ export default function PollComponent({ ), editor.registerCommand( KEY_DELETE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_BACKSPACE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), ); - }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]); + }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]); const withPollNode = ( cb: (node: PollNode) => void, diff --git a/packages/lexical-playground/src/nodes/PollNode.tsx b/packages/lexical-playground/src/nodes/PollNode.tsx index 1bce4ac56712..fd8fe8097e73 100644 --- a/packages/lexical-playground/src/nodes/PollNode.tsx +++ b/packages/lexical-playground/src/nodes/PollNode.tsx @@ -64,7 +64,7 @@ export type SerializedPollNode = Spread< SerializedLexicalNode >; -function convertPollElement(domNode: HTMLElement): DOMConversionOutput | null { +function $convertPollElement(domNode: HTMLElement): DOMConversionOutput | null { const question = domNode.getAttribute('data-lexical-poll-question'); const options = domNode.getAttribute('data-lexical-poll-options'); if (question !== null && options !== null) { @@ -158,7 +158,7 @@ export class PollNode extends DecoratorNode { return null; } return { - conversion: convertPollElement, + conversion: $convertPollElement, priority: 2, }; }, diff --git a/packages/lexical-playground/src/nodes/TweetNode.tsx b/packages/lexical-playground/src/nodes/TweetNode.tsx index 7804a174194a..4ca2c288a408 100644 --- a/packages/lexical-playground/src/nodes/TweetNode.tsx +++ b/packages/lexical-playground/src/nodes/TweetNode.tsx @@ -41,7 +41,7 @@ type TweetComponentProps = Readonly<{ tweetID: string; }>; -function convertTweetElement( +function $convertTweetElement( domNode: HTMLDivElement, ): DOMConversionOutput | null { const id = domNode.getAttribute('data-lexical-tweet-id'); @@ -163,7 +163,7 @@ export class TweetNode extends DecoratorBlockNode { return null; } return { - conversion: convertTweetElement, + conversion: $convertTweetElement, priority: 2, }; }, diff --git a/packages/lexical-playground/src/nodes/YouTubeNode.tsx b/packages/lexical-playground/src/nodes/YouTubeNode.tsx index b9976dbeabda..3c04a0269edc 100644 --- a/packages/lexical-playground/src/nodes/YouTubeNode.tsx +++ b/packages/lexical-playground/src/nodes/YouTubeNode.tsx @@ -66,7 +66,7 @@ export type SerializedYouTubeNode = Spread< SerializedDecoratorBlockNode >; -function convertYoutubeElement( +function $convertYoutubeElement( domNode: HTMLElement, ): null | DOMConversionOutput { const videoID = domNode.getAttribute('data-lexical-youtube'); @@ -134,7 +134,7 @@ export class YouTubeNode extends DecoratorBlockNode { return null; } return { - conversion: convertYoutubeElement, + conversion: $convertYoutubeElement, priority: 1, }; }, diff --git a/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx b/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx index 92f925ede5bd..7e32e1f4fb15 100644 --- a/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx @@ -135,7 +135,7 @@ export default function AutocompletePlugin(): JSX.Element | null { ); } - function handleAutocompleteNodeTransform(node: AutocompleteNode) { + function $handleAutocompleteNodeTransform(node: AutocompleteNode) { const key = node.getKey(); if (node.__uuid === uuid && key !== autocompleteNodeKey) { // Max one Autocomplete node per session @@ -206,7 +206,7 @@ export default function AutocompletePlugin(): JSX.Element | null { return mergeRegister( editor.registerNodeTransform( AutocompleteNode, - handleAutocompleteNodeTransform, + $handleAutocompleteNodeTransform, ), editor.registerUpdateListener(handleUpdate), editor.registerCommand( diff --git a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts index 871f22ff0314..200d406db1f8 100644 --- a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts +++ b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts @@ -26,7 +26,7 @@ type SerializedCollapsibleContainerNode = Spread< SerializedElementNode >; -export function convertDetailsElement( +export function $convertDetailsElement( domNode: HTMLDetailsElement, ): DOMConversionOutput | null { const isOpen = domNode.open !== undefined ? domNode.open : true; @@ -35,6 +35,8 @@ export function convertDetailsElement( node, }; } +/** @deprecated renamed to $convertDetailsElement by @lexical/eslint-plugin rules-of-lexical */ +export const convertDetailsElement = $convertDetailsElement; export class CollapsibleContainerNode extends ElementNode { __open: boolean; @@ -80,7 +82,7 @@ export class CollapsibleContainerNode extends ElementNode { return { details: (domNode: HTMLDetailsElement) => { return { - conversion: convertDetailsElement, + conversion: $convertDetailsElement, priority: 1, }; }, diff --git a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts index 562559af2416..bd4119183d16 100644 --- a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts +++ b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts @@ -18,7 +18,7 @@ import { type SerializedCollapsibleContentNode = SerializedElementNode; -export function convertCollapsibleContentElement( +export function $convertCollapsibleContentElement( domNode: HTMLElement, ): DOMConversionOutput | null { const node = $createCollapsibleContentNode(); @@ -26,6 +26,9 @@ export function convertCollapsibleContentElement( node, }; } +/** @deprecated renamed to $convertCollapsibleContentElement by @lexical/eslint-plugin rules-of-lexical */ +export const convertCollapsibleContentElement = + $convertCollapsibleContentElement; export class CollapsibleContentNode extends ElementNode { static getType(): string { @@ -53,7 +56,7 @@ export class CollapsibleContentNode extends ElementNode { return null; } return { - conversion: convertCollapsibleContentElement, + conversion: $convertCollapsibleContentElement, priority: 2, }; }, diff --git a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts index d581590c2b3e..ef06dcc2f4fa 100644 --- a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts +++ b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts @@ -24,7 +24,7 @@ import {$isCollapsibleContentNode} from './CollapsibleContentNode'; type SerializedCollapsibleTitleNode = SerializedElementNode; -export function convertSummaryElement( +export function $convertSummaryElement( domNode: HTMLElement, ): DOMConversionOutput | null { const node = $createCollapsibleTitleNode(); @@ -32,6 +32,8 @@ export function convertSummaryElement( node, }; } +/** @deprecated renamed to $convertSummaryElement by @lexical/eslint-plugin rules-of-lexical */ +export const convertSummaryElement = $convertSummaryElement; export class CollapsibleTitleNode extends ElementNode { static getType(): string { @@ -56,7 +58,7 @@ export class CollapsibleTitleNode extends ElementNode { return { summary: (domNode: HTMLElement) => { return { - conversion: convertSummaryElement, + conversion: $convertSummaryElement, priority: 1, }; }, diff --git a/packages/lexical-playground/src/plugins/CollapsiblePlugin/index.ts b/packages/lexical-playground/src/plugins/CollapsiblePlugin/index.ts index c981aa06f106..346053dc6ca3 100644 --- a/packages/lexical-playground/src/plugins/CollapsiblePlugin/index.ts +++ b/packages/lexical-playground/src/plugins/CollapsiblePlugin/index.ts @@ -67,7 +67,7 @@ export default function CollapsiblePlugin(): null { ); } - const onEscapeUp = () => { + const $onEscapeUp = () => { const selection = $getSelection(); if ( $isRangeSelection(selection) && @@ -95,7 +95,7 @@ export default function CollapsiblePlugin(): null { return false; }; - const onEscapeDown = () => { + const $onEscapeDown = () => { const selection = $getSelection(); if ($isRangeSelection(selection) && selection.isCollapsed()) { const container = $findMatchingParent( @@ -208,13 +208,13 @@ export default function CollapsiblePlugin(): null { // new content even if trailing paragraph is accidentally deleted editor.registerCommand( KEY_ARROW_DOWN_COMMAND, - onEscapeDown, + $onEscapeDown, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_ARROW_RIGHT_COMMAND, - onEscapeDown, + $onEscapeDown, COMMAND_PRIORITY_LOW, ), @@ -224,13 +224,13 @@ export default function CollapsiblePlugin(): null { // new content even if leading paragraph is accidentally deleted editor.registerCommand( KEY_ARROW_UP_COMMAND, - onEscapeUp, + $onEscapeUp, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_ARROW_LEFT_COMMAND, - onEscapeUp, + $onEscapeUp, COMMAND_PRIORITY_LOW, ), diff --git a/packages/lexical-playground/src/plugins/DraggableBlockPlugin/index.tsx b/packages/lexical-playground/src/plugins/DraggableBlockPlugin/index.tsx index 2224cf7254b1..9eb3b2acf16f 100644 --- a/packages/lexical-playground/src/plugins/DraggableBlockPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/DraggableBlockPlugin/index.tsx @@ -332,7 +332,7 @@ function useDraggableBlockMenu( return true; } - function onDrop(event: DragEvent): boolean { + function $onDrop(event: DragEvent): boolean { if (!isDraggingBlockRef.current) { return false; } @@ -382,7 +382,7 @@ function useDraggableBlockMenu( editor.registerCommand( DROP_COMMAND, (event) => { - return onDrop(event); + return $onDrop(event); }, COMMAND_PRIORITY_HIGH, ), diff --git a/packages/lexical-playground/src/plugins/EmojisPlugin/index.ts b/packages/lexical-playground/src/plugins/EmojisPlugin/index.ts index d2e661cabffa..5fdda1dccbfa 100644 --- a/packages/lexical-playground/src/plugins/EmojisPlugin/index.ts +++ b/packages/lexical-playground/src/plugins/EmojisPlugin/index.ts @@ -25,7 +25,7 @@ const emojis: Map = new Map([ ['❤', ['emoji heart', '❤']], ]); -function findAndTransformEmoji(node: TextNode): null | TextNode { +function $findAndTransformEmoji(node: TextNode): null | TextNode { const text = node.getTextContent(); for (let i = 0; i < text.length; i++) { @@ -50,7 +50,7 @@ function findAndTransformEmoji(node: TextNode): null | TextNode { return null; } -function textNodeTransform(node: TextNode): void { +function $textNodeTransform(node: TextNode): void { let targetNode: TextNode | null = node; while (targetNode !== null) { @@ -58,7 +58,7 @@ function textNodeTransform(node: TextNode): void { return; } - targetNode = findAndTransformEmoji(targetNode); + targetNode = $findAndTransformEmoji(targetNode); } } @@ -68,7 +68,7 @@ function useEmojis(editor: LexicalEditor): void { throw new Error('EmojisPlugin: EmojiNode not registered on editor'); } - return editor.registerNodeTransform(TextNode, textNodeTransform); + return editor.registerNodeTransform(TextNode, $textNodeTransform); }, [editor]); } diff --git a/packages/lexical-playground/src/plugins/FloatingLinkEditorPlugin/index.tsx b/packages/lexical-playground/src/plugins/FloatingLinkEditorPlugin/index.tsx index d91172aa477c..49773b761e50 100644 --- a/packages/lexical-playground/src/plugins/FloatingLinkEditorPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/FloatingLinkEditorPlugin/index.tsx @@ -59,7 +59,7 @@ function FloatingLinkEditor({ null, ); - const updateLinkEditor = useCallback(() => { + const $updateLinkEditor = useCallback(() => { const selection = $getSelection(); if ($isRangeSelection(selection)) { const node = getSelectedNode(selection); @@ -117,7 +117,7 @@ function FloatingLinkEditor({ const update = () => { editor.getEditorState().read(() => { - updateLinkEditor(); + $updateLinkEditor(); }); }; @@ -134,20 +134,20 @@ function FloatingLinkEditor({ scrollerElem.removeEventListener('scroll', update); } }; - }, [anchorElem.parentElement, editor, updateLinkEditor]); + }, [anchorElem.parentElement, editor, $updateLinkEditor]); useEffect(() => { return mergeRegister( editor.registerUpdateListener(({editorState}) => { editorState.read(() => { - updateLinkEditor(); + $updateLinkEditor(); }); }), editor.registerCommand( SELECTION_CHANGE_COMMAND, () => { - updateLinkEditor(); + $updateLinkEditor(); return true; }, COMMAND_PRIORITY_LOW, @@ -164,13 +164,13 @@ function FloatingLinkEditor({ COMMAND_PRIORITY_HIGH, ), ); - }, [editor, updateLinkEditor, setIsLink, isLink]); + }, [editor, $updateLinkEditor, setIsLink, isLink]); useEffect(() => { editor.getEditorState().read(() => { - updateLinkEditor(); + $updateLinkEditor(); }); - }, [editor, updateLinkEditor]); + }, [editor, $updateLinkEditor]); useEffect(() => { if (isLinkEditMode && inputRef.current) { @@ -292,7 +292,7 @@ function useFloatingLinkEditorToolbar( const [isLink, setIsLink] = useState(false); useEffect(() => { - function updateToolbar() { + function $updateToolbar() { const selection = $getSelection(); if ($isRangeSelection(selection)) { const focusNode = getSelectedNode(selection); @@ -328,13 +328,13 @@ function useFloatingLinkEditorToolbar( return mergeRegister( editor.registerUpdateListener(({editorState}) => { editorState.read(() => { - updateToolbar(); + $updateToolbar(); }); }), editor.registerCommand( SELECTION_CHANGE_COMMAND, (_payload, newEditor) => { - updateToolbar(); + $updateToolbar(); setActiveEditor(newEditor); return false; }, diff --git a/packages/lexical-playground/src/plugins/FloatingTextFormatToolbarPlugin/index.tsx b/packages/lexical-playground/src/plugins/FloatingTextFormatToolbarPlugin/index.tsx index 1dc2bb9a4106..8c9795b09ef1 100644 --- a/packages/lexical-playground/src/plugins/FloatingTextFormatToolbarPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/FloatingTextFormatToolbarPlugin/index.tsx @@ -109,7 +109,7 @@ function TextFormatFloatingToolbar({ } }, [popupCharStylesEditorRef]); - const updateTextFormatFloatingToolbar = useCallback(() => { + const $updateTextFormatFloatingToolbar = useCallback(() => { const selection = $getSelection(); const popupCharStylesEditorElem = popupCharStylesEditorRef.current; @@ -143,7 +143,7 @@ function TextFormatFloatingToolbar({ const update = () => { editor.getEditorState().read(() => { - updateTextFormatFloatingToolbar(); + $updateTextFormatFloatingToolbar(); }); }; @@ -158,29 +158,29 @@ function TextFormatFloatingToolbar({ scrollerElem.removeEventListener('scroll', update); } }; - }, [editor, updateTextFormatFloatingToolbar, anchorElem]); + }, [editor, $updateTextFormatFloatingToolbar, anchorElem]); useEffect(() => { editor.getEditorState().read(() => { - updateTextFormatFloatingToolbar(); + $updateTextFormatFloatingToolbar(); }); return mergeRegister( editor.registerUpdateListener(({editorState}) => { editorState.read(() => { - updateTextFormatFloatingToolbar(); + $updateTextFormatFloatingToolbar(); }); }), editor.registerCommand( SELECTION_CHANGE_COMMAND, () => { - updateTextFormatFloatingToolbar(); + $updateTextFormatFloatingToolbar(); return false; }, COMMAND_PRIORITY_LOW, ), ); - }, [editor, updateTextFormatFloatingToolbar]); + }, [editor, $updateTextFormatFloatingToolbar]); return (
diff --git a/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx b/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx index 32d8ccfbae0c..cceabbc52e94 100644 --- a/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx @@ -233,21 +233,21 @@ export default function ImagesPlugin({ editor.registerCommand( DRAGSTART_COMMAND, (event) => { - return onDragStart(event); + return $onDragStart(event); }, COMMAND_PRIORITY_HIGH, ), editor.registerCommand( DRAGOVER_COMMAND, (event) => { - return onDragover(event); + return $onDragover(event); }, COMMAND_PRIORITY_LOW, ), editor.registerCommand( DROP_COMMAND, (event) => { - return onDrop(event, editor); + return $onDrop(event, editor); }, COMMAND_PRIORITY_HIGH, ), @@ -262,8 +262,8 @@ const TRANSPARENT_IMAGE = const img = document.createElement('img'); img.src = TRANSPARENT_IMAGE; -function onDragStart(event: DragEvent): boolean { - const node = getImageNodeInSelection(); +function $onDragStart(event: DragEvent): boolean { + const node = $getImageNodeInSelection(); if (!node) { return false; } @@ -293,8 +293,8 @@ function onDragStart(event: DragEvent): boolean { return true; } -function onDragover(event: DragEvent): boolean { - const node = getImageNodeInSelection(); +function $onDragover(event: DragEvent): boolean { + const node = $getImageNodeInSelection(); if (!node) { return false; } @@ -304,8 +304,8 @@ function onDragover(event: DragEvent): boolean { return true; } -function onDrop(event: DragEvent, editor: LexicalEditor): boolean { - const node = getImageNodeInSelection(); +function $onDrop(event: DragEvent, editor: LexicalEditor): boolean { + const node = $getImageNodeInSelection(); if (!node) { return false; } @@ -327,7 +327,7 @@ function onDrop(event: DragEvent, editor: LexicalEditor): boolean { return true; } -function getImageNodeInSelection(): ImageNode | null { +function $getImageNodeInSelection(): ImageNode | null { const selection = $getSelection(); if (!$isNodeSelection(selection)) { return null; diff --git a/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx b/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx index f845c78b1818..7fa0a3c3da65 100644 --- a/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx @@ -186,21 +186,21 @@ export default function InlineImagePlugin(): JSX.Element | null { editor.registerCommand( DRAGSTART_COMMAND, (event) => { - return onDragStart(event); + return $onDragStart(event); }, COMMAND_PRIORITY_HIGH, ), editor.registerCommand( DRAGOVER_COMMAND, (event) => { - return onDragover(event); + return $onDragover(event); }, COMMAND_PRIORITY_LOW, ), editor.registerCommand( DROP_COMMAND, (event) => { - return onDrop(event, editor); + return $onDrop(event, editor); }, COMMAND_PRIORITY_HIGH, ), @@ -215,8 +215,8 @@ const TRANSPARENT_IMAGE = const img = document.createElement('img'); img.src = TRANSPARENT_IMAGE; -function onDragStart(event: DragEvent): boolean { - const node = getImageNodeInSelection(); +function $onDragStart(event: DragEvent): boolean { + const node = $getImageNodeInSelection(); if (!node) { return false; } @@ -245,8 +245,8 @@ function onDragStart(event: DragEvent): boolean { return true; } -function onDragover(event: DragEvent): boolean { - const node = getImageNodeInSelection(); +function $onDragover(event: DragEvent): boolean { + const node = $getImageNodeInSelection(); if (!node) { return false; } @@ -256,8 +256,8 @@ function onDragover(event: DragEvent): boolean { return true; } -function onDrop(event: DragEvent, editor: LexicalEditor): boolean { - const node = getImageNodeInSelection(); +function $onDrop(event: DragEvent, editor: LexicalEditor): boolean { + const node = $getImageNodeInSelection(); if (!node) { return false; } @@ -279,7 +279,7 @@ function onDrop(event: DragEvent, editor: LexicalEditor): boolean { return true; } -function getImageNodeInSelection(): InlineImageNode | null { +function $getImageNodeInSelection(): InlineImageNode | null { const selection = $getSelection(); if (!$isNodeSelection(selection)) { return null; diff --git a/packages/lexical-playground/src/plugins/KeywordsPlugin/index.ts b/packages/lexical-playground/src/plugins/KeywordsPlugin/index.ts index 27f7e4414e7b..08e3fe912256 100644 --- a/packages/lexical-playground/src/plugins/KeywordsPlugin/index.ts +++ b/packages/lexical-playground/src/plugins/KeywordsPlugin/index.ts @@ -26,7 +26,7 @@ export default function KeywordsPlugin(): JSX.Element | null { } }, [editor]); - const createKeywordNode = useCallback((textNode: TextNode): KeywordNode => { + const $createKeywordNode_ = useCallback((textNode: TextNode): KeywordNode => { return $createKeywordNode(textNode.getTextContent()); }, []); @@ -49,7 +49,7 @@ export default function KeywordsPlugin(): JSX.Element | null { useLexicalTextEntity( getKeywordMatch, KeywordNode, - createKeywordNode, + $createKeywordNode_, ); return null; diff --git a/packages/lexical-playground/src/plugins/LayoutPlugin/LayoutPlugin.tsx b/packages/lexical-playground/src/plugins/LayoutPlugin/LayoutPlugin.tsx index eac19252e638..cbdeee1fe23e 100644 --- a/packages/lexical-playground/src/plugins/LayoutPlugin/LayoutPlugin.tsx +++ b/packages/lexical-playground/src/plugins/LayoutPlugin/LayoutPlugin.tsx @@ -57,7 +57,7 @@ export function LayoutPlugin(): null { ); } - const onEscape = (before: boolean) => { + const $onEscape = (before: boolean) => { const selection = $getSelection(); if ( $isRangeSelection(selection) && @@ -104,12 +104,12 @@ export function LayoutPlugin(): null { // new content even if trailing paragraph is accidentally deleted editor.registerCommand( KEY_ARROW_DOWN_COMMAND, - () => onEscape(false), + () => $onEscape(false), COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_ARROW_RIGHT_COMMAND, - () => onEscape(false), + () => $onEscape(false), COMMAND_PRIORITY_LOW, ), // When layout is the first child pressing up/left arrow will insert paragraph @@ -118,12 +118,12 @@ export function LayoutPlugin(): null { // new content even if leading paragraph is accidentally deleted editor.registerCommand( KEY_ARROW_UP_COMMAND, - () => onEscape(true), + () => $onEscape(true), COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_ARROW_LEFT_COMMAND, - () => onEscape(true), + () => $onEscape(true), COMMAND_PRIORITY_LOW, ), editor.registerCommand( diff --git a/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts b/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts index 3feb82b9f96c..198543784c18 100644 --- a/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts +++ b/packages/lexical-playground/src/plugins/ListMaxIndentLevelPlugin/index.ts @@ -36,7 +36,7 @@ function getElementNodesInSelection( ); } -function shouldPreventIndent(maxDepth: number): boolean { +function $shouldPreventIndent(maxDepth: number): boolean { const selection = $getSelection(); if (!$isRangeSelection(selection)) { @@ -77,7 +77,7 @@ export default function ListMaxIndentLevelPlugin({ useEffect(() => { return editor.registerCommand( INDENT_CONTENT_COMMAND, - () => shouldPreventIndent(maxDepth), + () => $shouldPreventIndent(maxDepth), COMMAND_PRIORITY_CRITICAL, ); }, [editor, maxDepth]); diff --git a/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts b/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts index 004eb552811e..648669cc122f 100644 --- a/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts +++ b/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts @@ -264,7 +264,7 @@ export const TABLE: ElementTransformer = { table.append(tableRow); for (let i = 0; i < maxCells; i++) { - tableRow.append(i < cells.length ? cells[i] : createTableCell('')); + tableRow.append(i < cells.length ? cells[i] : $createTableCell('')); } } @@ -289,7 +289,7 @@ function getTableColumnsSize(table: TableNode) { return $isTableRowNode(row) ? row.getChildrenSize() : 0; } -const createTableCell = (textContent: string): TableCellNode => { +const $createTableCell = (textContent: string): TableCellNode => { textContent = textContent.replace(/\\n/g, '\n'); const cell = $createTableCellNode(TableCellHeaderStates.NO_STATUS); $convertFromMarkdownString(textContent, PLAYGROUND_TRANSFORMERS, cell); @@ -301,7 +301,7 @@ const mapToTableCells = (textContent: string): Array | null => { if (!match || !match[1]) { return null; } - return match[1].split('|').map((text) => createTableCell(text)); + return match[1].split('|').map((text) => $createTableCell(text)); }; export const PLAYGROUND_TRANSFORMERS: Array = [ diff --git a/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx b/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx index cda91323d0ab..b749e720102f 100644 --- a/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx @@ -655,7 +655,7 @@ function TableCellActionMenuContainer({ const [colorPickerModal, showColorPickerModal] = useModal(); - const moveMenu = useCallback(() => { + const $moveMenu = useCallback(() => { const menu = menuButtonRef.current; const selection = $getSelection(); const nativeSelection = window.getSelection(); @@ -701,7 +701,7 @@ function TableCellActionMenuContainer({ useEffect(() => { return editor.registerUpdateListener(() => { editor.getEditorState().read(() => { - moveMenu(); + $moveMenu(); }); }); }); diff --git a/packages/lexical-playground/src/server/validation.ts b/packages/lexical-playground/src/server/validation.ts index 180e49a677cf..d7fb5893b02b 100644 --- a/packages/lexical-playground/src/server/validation.ts +++ b/packages/lexical-playground/src/server/validation.ts @@ -46,7 +46,7 @@ const getJSONData = (req: http.IncomingMessage): Promise => { }); }; -const sanitizeNode = (node: LexicalNode): void => { +const $sanitizeNode = (node: LexicalNode): void => { if ($isMarkNode(node)) { $unwrapMarkNode(node); return; @@ -54,7 +54,7 @@ const sanitizeNode = (node: LexicalNode): void => { if ($isElementNode(node)) { const children = node.getChildren(); for (const child of children) { - sanitizeNode(child); + $sanitizeNode(child); } } }; @@ -70,7 +70,7 @@ const validateEditorState = async ( editor.setEditorState(nextEditorState); editor.update(() => { const root = $getRoot(); - sanitizeNode(root); + $sanitizeNode(root); }); await Promise.resolve().then(); diff --git a/packages/lexical-react/src/LexicalAutoLinkPlugin.ts b/packages/lexical-react/src/LexicalAutoLinkPlugin.ts index 37c080f72f91..a66c19b41a2b 100644 --- a/packages/lexical-react/src/LexicalAutoLinkPlugin.ts +++ b/packages/lexical-react/src/LexicalAutoLinkPlugin.ts @@ -179,7 +179,7 @@ function extractMatchingNodes( ]; } -function createAutoLinkNode( +function $createAutoLinkNode_( nodes: TextNode[], startIndex: number, endIndex: number, @@ -256,7 +256,7 @@ function createAutoLinkNode( return undefined; } -function handleLinkCreation( +function $handleLinkCreation( nodes: TextNode[], matchers: Array, onChange: ChangeHandler, @@ -290,7 +290,7 @@ function handleLinkCreation( const actualMatchStart = invalidMatchEnd + matchStart - matchingOffset; const actualMatchEnd = invalidMatchEnd + matchEnd - matchingOffset; - const remainingTextNode = createAutoLinkNode( + const remainingTextNode = $createAutoLinkNode_( matchingNodes, actualMatchStart, actualMatchEnd, @@ -449,7 +449,7 @@ function useAutoLink( !$isAutoLinkNode(previous)) ) { const textNodesToMatch = getTextNodesToMatch(textNode); - handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped); + $handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped); } handleBadNeighbors(textNode, matchers, onChangeWrapped); diff --git a/packages/lexical-react/src/LexicalBlockWithAlignableContents.tsx b/packages/lexical-react/src/LexicalBlockWithAlignableContents.tsx index ebaf778d7993..35ee3d2d7a02 100644 --- a/packages/lexical-react/src/LexicalBlockWithAlignableContents.tsx +++ b/packages/lexical-react/src/LexicalBlockWithAlignableContents.tsx @@ -52,7 +52,7 @@ export function BlockWithAlignableContents({ useLexicalNodeSelection(nodeKey); const ref = useRef(null); - const onDelete = useCallback( + const $onDelete = useCallback( (event: KeyboardEvent) => { if (isSelected && $isNodeSelection($getSelection())) { event.preventDefault(); @@ -121,16 +121,16 @@ export function BlockWithAlignableContents({ ), editor.registerCommand( KEY_DELETE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_BACKSPACE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), ); - }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]); + }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]); return (
{ + const $createHashtagNode_ = useCallback((textNode: TextNode): HashtagNode => { return $createHashtagNode(textNode.getTextContent()); }, []); @@ -280,7 +280,7 @@ export function HashtagPlugin(): JSX.Element | null { useLexicalTextEntity( getHashtagMatch, HashtagNode, - createHashtagNode, + $createHashtagNode_, ); return null; diff --git a/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx b/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx index 7e63f7c6e318..179518776375 100644 --- a/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx +++ b/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx @@ -44,7 +44,7 @@ function HorizontalRuleComponent({nodeKey}: {nodeKey: NodeKey}) { const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey); - const onDelete = useCallback( + const $onDelete = useCallback( (event: KeyboardEvent) => { if (isSelected && $isNodeSelection($getSelection())) { event.preventDefault(); @@ -80,16 +80,16 @@ function HorizontalRuleComponent({nodeKey}: {nodeKey: NodeKey}) { ), editor.registerCommand( KEY_DELETE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), editor.registerCommand( KEY_BACKSPACE_COMMAND, - onDelete, + $onDelete, COMMAND_PRIORITY_LOW, ), ); - }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]); + }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected]); useEffect(() => { const hrElem = editor.getElementByKey(nodeKey); @@ -119,7 +119,7 @@ export class HorizontalRuleNode extends DecoratorNode { static importDOM(): DOMConversionMap | null { return { hr: () => ({ - conversion: convertHorizontalRuleElement, + conversion: $convertHorizontalRuleElement, priority: 0, }), }; @@ -157,7 +157,7 @@ export class HorizontalRuleNode extends DecoratorNode { } } -function convertHorizontalRuleElement(): DOMConversionOutput { +function $convertHorizontalRuleElement(): DOMConversionOutput { return {node: $createHorizontalRuleNode()}; } diff --git a/packages/lexical-react/src/LexicalTabIndentationPlugin.tsx b/packages/lexical-react/src/LexicalTabIndentationPlugin.tsx index 7289d18ae1c9..7767526244ab 100644 --- a/packages/lexical-react/src/LexicalTabIndentationPlugin.tsx +++ b/packages/lexical-react/src/LexicalTabIndentationPlugin.tsx @@ -24,7 +24,7 @@ import { } from 'lexical'; import {useEffect} from 'react'; -function indentOverTab(selection: RangeSelection): boolean { +function $indentOverTab(selection: RangeSelection): boolean { // const handled = new Set(); const nodes = selection.getNodes(); const canIndentBlockNodes = $filter(nodes, (node) => { @@ -67,7 +67,7 @@ export function registerTabIndentation(editor: LexicalEditor) { } event.preventDefault(); - const command: LexicalCommand = indentOverTab(selection) + const command: LexicalCommand = $indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND diff --git a/packages/lexical-react/src/shared/useCharacterLimit.ts b/packages/lexical-react/src/shared/useCharacterLimit.ts index df592ebf9c65..07198f4fd0ba 100644 --- a/packages/lexical-react/src/shared/useCharacterLimit.ts +++ b/packages/lexical-react/src/shared/useCharacterLimit.ts @@ -216,7 +216,7 @@ function $wrapOverflowedNodes(offset: number): void { $setSelection(previousSelection); } - mergePrevious(overflowNode); + $mergePrevious(overflowNode); } } } @@ -241,7 +241,7 @@ function $unwrapNode(node: OverflowNode): LexicalNode | null { return childrenLength > 0 ? children[childrenLength - 1] : null; } -export function mergePrevious(overflowNode: OverflowNode): void { +export function $mergePrevious(overflowNode: OverflowNode): void { const previousNode = overflowNode.getPreviousSibling(); if (!$isOverflowNode(previousNode)) { @@ -291,3 +291,5 @@ export function mergePrevious(overflowNode: OverflowNode): void { previousNode.remove(); } +/** @deprecated renamed to $mergePrevious by @lexical/eslint-plugin rules-of-lexical */ +export const mergePrevious = $mergePrevious; diff --git a/packages/lexical-rich-text/src/index.ts b/packages/lexical-rich-text/src/index.ts index 7229c2053029..ba984f1d5c89 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, }), }; @@ -259,27 +259,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) => { @@ -392,7 +392,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 +411,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 +494,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 +696,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 +706,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-selection/src/__tests__/unit/LexicalSelectionHelpers.test.ts b/packages/lexical-selection/src/__tests__/unit/LexicalSelectionHelpers.test.ts index 0cda5e661287..a5c044bef080 100644 --- a/packages/lexical-selection/src/__tests__/unit/LexicalSelectionHelpers.test.ts +++ b/packages/lexical-selection/src/__tests__/unit/LexicalSelectionHelpers.test.ts @@ -59,7 +59,7 @@ Range.prototype.getBoundingClientRect = function (): DOMRect { }; }; -function createParagraphWithNodes(editor, nodes) { +function $createParagraphWithNodes(editor, nodes) { const paragraph = $createParagraphNode(); const nodeMap = editor._pendingEditorState._nodeMap; @@ -87,7 +87,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - const element = createParagraphWithNodes(editor, [ + const element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -264,7 +264,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -345,7 +345,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -421,7 +421,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -482,7 +482,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -548,7 +548,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -624,7 +624,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -696,7 +696,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - const element = createParagraphWithNodes(editor, []); + const element = $createParagraphWithNodes(editor, []); root.append(element); @@ -831,7 +831,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - const element = createParagraphWithNodes(editor, [ + const element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -982,7 +982,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - const element = createParagraphWithNodes(editor, [ + const element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -1137,7 +1137,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -1208,7 +1208,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - element = createParagraphWithNodes(editor, [ + element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: true, @@ -1277,7 +1277,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - const element = createParagraphWithNodes(editor, [ + const element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -1452,7 +1452,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - const element = createParagraphWithNodes(editor, [ + const element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -1607,7 +1607,7 @@ describe('LexicalSelectionHelpers tests', () => { editor.update(() => { const root = $getRoot(); - const element = createParagraphWithNodes(editor, [ + const element = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -2674,7 +2674,7 @@ describe('$patchStyleText', () => { await editor.update(() => { const root = $getRoot(); - const paragraph = createParagraphWithNodes(editor, [ + const paragraph = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -2730,14 +2730,14 @@ describe('$patchStyleText', () => { await editor.update(() => { const root = $getRoot(); - const paragraph1 = createParagraphWithNodes(editor, [ + const paragraph1 = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, text: 'a', }, ]); - const paragraph2 = createParagraphWithNodes(editor, [ + const paragraph2 = $createParagraphWithNodes(editor, [ { key: 'b', mergeable: false, @@ -2780,7 +2780,7 @@ describe('$patchStyleText', () => { await editor.update(() => { const root = $getRoot(); - const paragraph = createParagraphWithNodes(editor, [ + const paragraph = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, @@ -2833,7 +2833,7 @@ describe('$patchStyleText', () => { await editor.update(() => { const root = $getRoot(); - const paragraph = createParagraphWithNodes(editor, [ + const paragraph = $createParagraphWithNodes(editor, [ { key: 'a', mergeable: false, diff --git a/packages/lexical-selection/src/__tests__/utils/index.ts b/packages/lexical-selection/src/__tests__/utils/index.ts index 1d35b6e12b77..67e3cc83bdae 100644 --- a/packages/lexical-selection/src/__tests__/utils/index.ts +++ b/packages/lexical-selection/src/__tests__/utils/index.ts @@ -865,13 +865,13 @@ export async function applySelectionInputs(inputs, update, editor) { } } -export function setAnchorPoint(point) { +export function $setAnchorPoint(point) { const selection = $getSelection(); if (!$isRangeSelection(selection)) { const dummyTextNode = $createTextNode(); dummyTextNode.select(); - return setAnchorPoint(point); + return $setAnchorPoint(point); } if ($isNodeSelection(selection)) { @@ -883,14 +883,16 @@ export function setAnchorPoint(point) { anchor.offset = point.offset; anchor.key = point.key; } +/** @deprecated renamed to $setAnchorPoint by @lexical/eslint-plugin rules-of-lexical */ +export const setAnchorPoint = $setAnchorPoint; -export function setFocusPoint(point) { +export function $setFocusPoint(point) { const selection = $getSelection(); if (!$isRangeSelection(selection)) { const dummyTextNode = $createTextNode(); dummyTextNode.select(); - return setFocusPoint(point); + return $setFocusPoint(point); } if ($isNodeSelection(selection)) { @@ -902,3 +904,5 @@ export function setFocusPoint(point) { focus.offset = point.offset; focus.key = point.key; } +/** @deprecated renamed to $setFocusPoint by @lexical/eslint-plugin rules-of-lexical */ +export const setFocusPoint = $setFocusPoint; diff --git a/packages/lexical-selection/src/lexical-node.ts b/packages/lexical-selection/src/lexical-node.ts index 7dcdff84f469..b7e5df7d9e39 100644 --- a/packages/lexical-selection/src/lexical-node.ts +++ b/packages/lexical-selection/src/lexical-node.ts @@ -171,7 +171,7 @@ export function $isAtNodeEnd(point: Point): boolean { * @param anchor - The anchor of the current selection, where the selection should be pointing. * @param delCount - The amount of characters to delete. Useful as a dynamic variable eg. textContentSize - maxLength; */ -export function trimTextContentFromAnchor( +export function $trimTextContentFromAnchor( editor: LexicalEditor, anchor: Point, delCount: number, @@ -289,6 +289,8 @@ export function trimTextContentFromAnchor( } } } +/** @deprecated renamed to $trimTextContentFromAnchor by @lexical/eslint-plugin rules-of-lexical */ +export const trimTextContentFromAnchor = $trimTextContentFromAnchor; /** * Gets the TextNode's style object and adds the styles to the CSS. diff --git a/packages/lexical-table/src/LexicalTableCellNode.ts b/packages/lexical-table/src/LexicalTableCellNode.ts index d800bf7dc359..3079c8f02e57 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, }), }; @@ -292,7 +292,7 @@ export class TableCellNode extends ElementNode { } } -export function convertTableCellNodeElement( +export function $convertTableCellNodeElement( domNode: Node, ): DOMConversionOutput { const domNode_ = domNode as HTMLTableCellElement; @@ -387,6 +387,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-table/src/LexicalTableNode.ts b/packages/lexical-table/src/LexicalTableNode.ts index 76d0a76f4b28..e64105a13deb 100644 --- a/packages/lexical-table/src/LexicalTableNode.ts +++ b/packages/lexical-table/src/LexicalTableNode.ts @@ -45,7 +45,7 @@ export class TableNode extends ElementNode { static importDOM(): DOMConversionMap | null { return { table: (_node: Node) => ({ - conversion: convertTableElement, + conversion: $convertTableElement, priority: 1, }), }; @@ -241,9 +241,11 @@ export function $getElementForTableNode( return getTable(tableElement); } -export function convertTableElement(_domNode: Node): DOMConversionOutput { +export function $convertTableElement(_domNode: Node): DOMConversionOutput { return {node: $createTableNode()}; } +/** @deprecated renamed to $convertTableElement by @lexical/eslint-plugin rules-of-lexical */ +export const convertTableElement = $convertTableElement; export function $createTableNode(): TableNode { return $applyNodeReplacement(new TableNode()); diff --git a/packages/lexical-table/src/LexicalTableRowNode.ts b/packages/lexical-table/src/LexicalTableRowNode.ts index 9f84292ab9f9..80015388ca63 100644 --- a/packages/lexical-table/src/LexicalTableRowNode.ts +++ b/packages/lexical-table/src/LexicalTableRowNode.ts @@ -45,7 +45,7 @@ export class TableRowNode extends ElementNode { static importDOM(): DOMConversionMap | null { return { tr: (node: Node) => ({ - conversion: convertTableRowElement, + conversion: $convertTableRowElement, priority: 0, }), }; @@ -108,7 +108,7 @@ export class TableRowNode extends ElementNode { } } -export function convertTableRowElement(domNode: Node): DOMConversionOutput { +export function $convertTableRowElement(domNode: Node): DOMConversionOutput { const domNode_ = domNode as HTMLTableCellElement; let height: number | undefined = undefined; @@ -118,6 +118,8 @@ export function convertTableRowElement(domNode: Node): DOMConversionOutput { return {node: $createTableRowNode(height)}; } +/** @deprecated renamed to $convertTableRowElement by @lexical/eslint-plugin rules-of-lexical */ +export const convertTableRowElement = $convertTableRowElement; export function $createTableRowNode(height?: number): TableRowNode { return $applyNodeReplacement(new TableRowNode(height)); diff --git a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts index e45c366faa37..fbc1595229fd 100644 --- a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts +++ b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts @@ -302,7 +302,7 @@ export function applyTableHandlers( }, ); - const deleteCellHandler = (event: KeyboardEvent): boolean => { + const $deleteCellHandler = (event: KeyboardEvent): boolean => { const selection = $getSelection(); if (!$isSelectionInTable(selection, tableNode)) { @@ -332,7 +332,7 @@ export function applyTableHandlers( tableObserver.listenersToRemove.add( editor.registerCommand( KEY_BACKSPACE_COMMAND, - deleteCellHandler, + $deleteCellHandler, COMMAND_PRIORITY_CRITICAL, ), ); @@ -340,7 +340,7 @@ export function applyTableHandlers( tableObserver.listenersToRemove.add( editor.registerCommand( KEY_DELETE_COMMAND, - deleteCellHandler, + $deleteCellHandler, COMMAND_PRIORITY_CRITICAL, ), ); @@ -1507,7 +1507,7 @@ function isExitingTableAnchor( ) { return ( isExitingTableElementAnchor(type, anchorNode, direction) || - isExitingTableTextAnchor(type, offset, anchorNode, direction) + $isExitingTableTextAnchor(type, offset, anchorNode, direction) ); } @@ -1524,7 +1524,7 @@ function isExitingTableElementAnchor( ); } -function isExitingTableTextAnchor( +function $isExitingTableTextAnchor( type: string, offset: number, anchorNode: LexicalNode, @@ -1569,7 +1569,7 @@ function $handleTableExit( return false; } - const toNode = getExitingToNode(anchorNode, direction, tableNode); + const toNode = $getExitingToNode(anchorNode, direction, tableNode); if (!toNode || $isTableNode(toNode)) { return false; } @@ -1596,7 +1596,7 @@ function isExitingCell( : startColumn === lastCell.startColumn && startRow === lastCell.startRow; } -function getExitingToNode( +function $getExitingToNode( anchorNode: LexicalNode, direction: 'backward' | 'forward', tableNode: TableNode, diff --git a/packages/lexical-text/src/registerLexicalTextEntity.ts b/packages/lexical-text/src/registerLexicalTextEntity.ts index 80372ec26142..466fcd9398fb 100644 --- a/packages/lexical-text/src/registerLexicalTextEntity.ts +++ b/packages/lexical-text/src/registerLexicalTextEntity.ts @@ -46,7 +46,7 @@ export function registerLexicalTextEntity( return node instanceof targetNode; }; - const replaceWithSimpleText = (node: TextNode): void => { + const $replaceWithSimpleText = (node: TextNode): void => { const textNode = $createTextNode(node.getTextContent()); textNode.setFormat(node.getFormat()); node.replace(textNode); @@ -56,7 +56,7 @@ export function registerLexicalTextEntity( return node.getLatest().__mode; }; - const textNodeTransform = (node: TextNode) => { + const $textNodeTransform = (node: TextNode) => { if (!node.isSimpleText()) { return; } @@ -73,7 +73,7 @@ export function registerLexicalTextEntity( if (isTargetNode(prevSibling)) { if (prevMatch === null || getMode(prevSibling) !== 0) { - replaceWithSimpleText(prevSibling); + $replaceWithSimpleText(prevSibling); return; } else { @@ -116,7 +116,7 @@ export function registerLexicalTextEntity( if (nextMatch === null) { if (isTargetNode(nextSibling)) { - replaceWithSimpleText(nextSibling); + $replaceWithSimpleText(nextSibling); } else { nextSibling.markDirty(); } @@ -167,12 +167,12 @@ export function registerLexicalTextEntity( } }; - const reverseNodeTransform = (node: T) => { + const $reverseNodeTransform = (node: T) => { const text = node.getTextContent(); const match = getMatch(text); if (match === null || match.start !== 0) { - replaceWithSimpleText(node); + $replaceWithSimpleText(node); return; } @@ -187,29 +187,29 @@ export function registerLexicalTextEntity( const prevSibling = node.getPreviousSibling(); if ($isTextNode(prevSibling) && prevSibling.isTextEntity()) { - replaceWithSimpleText(prevSibling); - replaceWithSimpleText(node); + $replaceWithSimpleText(prevSibling); + $replaceWithSimpleText(node); } const nextSibling = node.getNextSibling(); if ($isTextNode(nextSibling) && nextSibling.isTextEntity()) { - replaceWithSimpleText(nextSibling); + $replaceWithSimpleText(nextSibling); // This may have already been converted in the previous block if (isTargetNode(node)) { - replaceWithSimpleText(node); + $replaceWithSimpleText(node); } } }; const removePlainTextTransform = editor.registerNodeTransform( TextNode, - textNodeTransform, + $textNodeTransform, ); const removeReverseNodeTransform = editor.registerNodeTransform( targetNode, - reverseNodeTransform, + $reverseNodeTransform, ); return [removePlainTextTransform, removeReverseNodeTransform]; diff --git a/packages/lexical-utils/src/index.ts b/packages/lexical-utils/src/index.ts index 1d4bd037de06..291b03381138 100644 --- a/packages/lexical-utils/src/index.ts +++ b/packages/lexical-utils/src/index.ts @@ -356,7 +356,7 @@ export function registerNestedElementResolver( return null; }; - const elementNodeTransform = (node: N) => { + const $elementNodeTransform = (node: N) => { const match = $findMatch(node); if (match !== null) { @@ -390,7 +390,7 @@ export function registerNestedElementResolver( } }; - return editor.registerNodeTransform(targetNode, elementNodeTransform); + return editor.registerNodeTransform(targetNode, $elementNodeTransform); } /** diff --git a/packages/lexical-yjs/src/CollabTextNode.ts b/packages/lexical-yjs/src/CollabTextNode.ts index 15514e1b1f4a..0755474c23e9 100644 --- a/packages/lexical-yjs/src/CollabTextNode.ts +++ b/packages/lexical-yjs/src/CollabTextNode.ts @@ -22,7 +22,7 @@ import simpleDiffWithCursor from 'shared/simpleDiffWithCursor'; import {syncPropertiesFromLexical, syncPropertiesFromYjs} from './Utils'; -function diffTextContentAndApplyDelta( +function $diffTextContentAndApplyDelta( collabNode: CollabTextNode, key: NodeKey, prevText: string, @@ -134,7 +134,7 @@ export class CollabTextNode { if (prevText !== nextText) { const key = nextLexicalNode.__key; - diffTextContentAndApplyDelta(this, key, prevText, nextText); + $diffTextContentAndApplyDelta(this, key, prevText, nextText); this._text = nextText; } } diff --git a/packages/lexical-yjs/src/SyncCursors.ts b/packages/lexical-yjs/src/SyncCursors.ts index fc1a75eeb9bc..48e68a549946 100644 --- a/packages/lexical-yjs/src/SyncCursors.ts +++ b/packages/lexical-yjs/src/SyncCursors.ts @@ -295,7 +295,7 @@ function updateCursor( } } -export function syncLocalCursorPosition( +export function $syncLocalCursorPosition( binding: Binding, provider: Provider, ): void { @@ -335,14 +335,16 @@ export function syncLocalCursorPosition( const anchor = selection.anchor; const focus = selection.focus; - setPoint(anchor, anchorKey, anchorOffset); - setPoint(focus, focusKey, focusOffset); + $setPoint(anchor, anchorKey, anchorOffset); + $setPoint(focus, focusKey, focusOffset); } } } } +/** @deprecated renamed to $syncLocalCursorPosition by @lexical/eslint-plugin rules-of-lexical */ +export const syncLocalCursorPosition = $syncLocalCursorPosition; -function setPoint(point: Point, key: NodeKey, offset: number): void { +function $setPoint(point: Point, key: NodeKey, offset: number): void { if (point.key !== key || point.offset !== offset) { let anchorNode = $getNodeByKey(key); if ( diff --git a/packages/lexical-yjs/src/SyncEditorStates.ts b/packages/lexical-yjs/src/SyncEditorStates.ts index cb6bde824545..7230f1fa4fe1 100644 --- a/packages/lexical-yjs/src/SyncEditorStates.ts +++ b/packages/lexical-yjs/src/SyncEditorStates.ts @@ -174,7 +174,7 @@ export function syncYjsChangesToLexical( ); } -function handleNormalizationMergeConflicts( +function $handleNormalizationMergeConflicts( binding: Binding, normalizedNodes: Set, ): void { @@ -244,7 +244,7 @@ export function syncLexicalUpdateToYjs( // when we need to handle normalization merge conflicts. if (tags.has('collaboration') || tags.has('historic')) { if (normalizedNodes.size > 0) { - handleNormalizationMergeConflicts(binding, normalizedNodes); + $handleNormalizationMergeConflicts(binding, normalizedNodes); } return; diff --git a/packages/lexical-yjs/src/Utils.ts b/packages/lexical-yjs/src/Utils.ts index 677905788f8f..5e847853b498 100644 --- a/packages/lexical-yjs/src/Utils.ts +++ b/packages/lexical-yjs/src/Utils.ts @@ -170,7 +170,7 @@ function getNodeTypeFromSharedType( return type; } -export function getOrInitCollabNodeFromSharedType( +export function $getOrInitCollabNodeFromSharedType( binding: Binding, sharedType: XmlText | YMap | XmlElement, parent?: CollabElementNode, @@ -190,7 +190,7 @@ export function getOrInitCollabNodeFromSharedType( const sharedParent = sharedType.parent; const targetParent = parent === undefined && sharedParent !== null - ? getOrInitCollabNodeFromSharedType( + ? $getOrInitCollabNodeFromSharedType( binding, sharedParent as XmlText | YMap | XmlElement, ) @@ -215,6 +215,9 @@ export function getOrInitCollabNodeFromSharedType( return collabNode; } +/** @deprecated renamed to $getOrInitCollabNodeFromSharedType by @lexical/eslint-plugin rules-of-lexical */ +export const getOrInitCollabNodeFromSharedType = + $getOrInitCollabNodeFromSharedType; export function createLexicalNodeFromCollabNode( binding: Binding, @@ -473,7 +476,7 @@ export function syncWithTransaction(binding: Binding, fn: () => void): void { binding.doc.transact(fn, binding); } -export function createChildrenArray( +export function $createChildrenArray( element: ElementNode, nodeMap: null | NodeMap, ): Array { @@ -490,6 +493,8 @@ export function createChildrenArray( } return children; } +/** @deprecated renamed to $createChildrenArray by @lexical/eslint-plugin rules-of-lexical */ +export const createChildrenArray = $createChildrenArray; export function removeFromParent(node: LexicalNode): void { const oldParent = node.getParent(); diff --git a/packages/lexical/src/LexicalEvents.ts b/packages/lexical/src/LexicalEvents.ts index 96cf9ad7c86f..5d3ee6c33245 100644 --- a/packages/lexical/src/LexicalEvents.ts +++ b/packages/lexical/src/LexicalEvents.ts @@ -817,7 +817,7 @@ function onInput(event: InputEvent, editor: LexicalEditor): void { // to ensure to disable composition before dispatching the // insertText command for when changing the sequence for FF. if (isFirefoxEndingComposition) { - onCompositionEndImpl(editor, data); + $onCompositionEndImpl(editor, data); isFirefoxEndingComposition = false; } const anchor = selection.anchor; @@ -873,7 +873,7 @@ function onInput(event: InputEvent, editor: LexicalEditor): void { // onInput always fires after onCompositionEnd for FF. if (isFirefoxEndingComposition) { - onCompositionEndImpl(editor, data || undefined); + $onCompositionEndImpl(editor, data || undefined); isFirefoxEndingComposition = false; } } @@ -923,7 +923,7 @@ function onCompositionStart( }); } -function onCompositionEndImpl(editor: LexicalEditor, data?: string): void { +function $onCompositionEndImpl(editor: LexicalEditor, data?: string): void { const compositionKey = editor._compositionKey; $setCompositionKey(null); @@ -984,7 +984,7 @@ function onCompositionEnd( isFirefoxEndingComposition = true; } else { updateEditor(editor, () => { - onCompositionEndImpl(editor, event.data); + $onCompositionEndImpl(editor, event.data); }); } } diff --git a/packages/lexical/src/LexicalMutations.ts b/packages/lexical/src/LexicalMutations.ts index eb902d5e7a9e..12ec3f7a7279 100644 --- a/packages/lexical/src/LexicalMutations.ts +++ b/packages/lexical/src/LexicalMutations.ts @@ -71,7 +71,7 @@ function getLastSelection(editor: LexicalEditor): null | BaseSelection { }); } -function handleTextMutation( +function $handleTextMutation( target: Text, node: TextNode, editor: LexicalEditor, @@ -153,7 +153,7 @@ export function $flushMutations( $isTextNode(targetNode) && shouldUpdateTextNodeFromMutation(selection, targetDOM, targetNode) ) { - handleTextMutation( + $handleTextMutation( // nodeType === DOM_TEXT_TYPE is a Text DOM node targetDOM as Text, targetNode, @@ -303,7 +303,7 @@ export function $flushMutations( } } -export function flushRootMutations(editor: LexicalEditor): void { +export function $flushRootMutations(editor: LexicalEditor): void { const observer = editor._observer; if (observer !== null) { @@ -311,6 +311,8 @@ export function flushRootMutations(editor: LexicalEditor): void { $flushMutations(editor, mutations, observer); } } +/** @deprecated renamed to $flushRootMutations by @lexical/eslint-plugin rules-of-lexical */ +export const flushRootMutations = $flushRootMutations; export function initMutationObserver(editor: LexicalEditor): void { initTextEntryListener(editor); diff --git a/packages/lexical/src/LexicalNode.ts b/packages/lexical/src/LexicalNode.ts index 0f6178dea414..ca3933c31930 100644 --- a/packages/lexical/src/LexicalNode.ts +++ b/packages/lexical/src/LexicalNode.ts @@ -54,7 +54,7 @@ export type SerializedLexicalNode = { version: number; }; -export function removeNode( +export function $removeNode( nodeToRemove: LexicalNode, restoreSelection: boolean, preserveEmptyParent?: boolean, @@ -113,12 +113,14 @@ export function removeNode( !parent.canBeEmpty() && parent.isEmpty() ) { - removeNode(parent, restoreSelection); + $removeNode(parent, restoreSelection); } if (restoreSelection && $isRootNode(parent) && parent.isEmpty()) { parent.selectEnd(); } } +/** @deprecated renamed to $removeNode by @lexical/eslint-plugin rules-of-lexical */ +export const removeNode = $removeNode; export type DOMConversion = { conversion: DOMConversionFn; @@ -844,7 +846,7 @@ export class LexicalNode { * other node heuristics such as {@link ElementNode#canBeEmpty} * */ remove(preserveEmptyParent?: boolean): void { - removeNode(this, true, preserveEmptyParent); + $removeNode(this, true, preserveEmptyParent); } /** @@ -873,7 +875,7 @@ export class LexicalNode { const prevKey = self.__prev; const nextKey = self.__next; const parentKey = self.__parent; - removeNode(self, false, true); + $removeNode(self, false, true); if (prevSibling === null) { writableParent.__first = key; diff --git a/packages/lexical/src/LexicalReconciler.ts b/packages/lexical/src/LexicalReconciler.ts index 6de81ebc6364..92ac34811611 100644 --- a/packages/lexical/src/LexicalReconciler.ts +++ b/packages/lexical/src/LexicalReconciler.ts @@ -164,7 +164,7 @@ function setElementFormat(dom: HTMLElement, format: number): void { } } -function createNode( +function $createNode( key: NodeKey, parentDOM: null | HTMLElement, insertDOM: null | Node, @@ -196,7 +196,7 @@ function createNode( if (childrenSize !== 0) { const endIndex = childrenSize - 1; const children = createChildrenArray(node, activeNextNodeMap); - createChildrenWithDirection(children, endIndex, node, dom); + $createChildrenWithDirection(children, endIndex, node, dom); } const format = node.__format; @@ -260,7 +260,7 @@ function createNode( return dom; } -function createChildrenWithDirection( +function $createChildrenWithDirection( children: Array, endIndex: number, element: ElementNode, @@ -268,12 +268,12 @@ function createChildrenWithDirection( ): void { const previousSubTreeDirectionedTextContent = subTreeDirectionedTextContent; subTreeDirectionedTextContent = ''; - createChildren(children, element, 0, endIndex, dom, null); + $createChildren(children, element, 0, endIndex, dom, null); reconcileBlockDirection(element, dom); subTreeDirectionedTextContent = previousSubTreeDirectionedTextContent; } -function createChildren( +function $createChildren( children: Array, element: ElementNode, _startIndex: number, @@ -286,7 +286,7 @@ function createChildren( let startIndex = _startIndex; for (; startIndex <= endIndex; ++startIndex) { - createNode(children[startIndex], dom, insertDOM); + $createNode(children[startIndex], dom, insertDOM); const node = activeNextNodeMap.get(children[startIndex]); if (node !== null && subTreeTextFormat === null && $isTextNode(node)) { subTreeTextFormat = node.getFormat(); @@ -431,7 +431,7 @@ function reconcileBlockDirection(element: ElementNode, dom: HTMLElement): void { } } -function reconcileChildrenWithDirection( +function $reconcileChildrenWithDirection( prevElement: ElementNode, nextElement: ElementNode, dom: HTMLElement, @@ -439,7 +439,7 @@ function reconcileChildrenWithDirection( const previousSubTreeDirectionTextContent = subTreeDirectionedTextContent; subTreeDirectionedTextContent = ''; subTreeTextFormat = null; - reconcileChildren(prevElement, nextElement, dom); + $reconcileChildren(prevElement, nextElement, dom); reconcileBlockDirection(nextElement, dom); reconcileParagraphFormat(nextElement); subTreeDirectionedTextContent = previousSubTreeDirectionTextContent; @@ -463,7 +463,7 @@ function createChildrenArray( return children; } -function reconcileChildren( +function $reconcileChildren( prevElement: ElementNode, nextElement: ElementNode, dom: HTMLElement, @@ -477,10 +477,10 @@ function reconcileChildren( const prevFirstChildKey = prevElement.__first as NodeKey; const nextFrstChildKey = nextElement.__first as NodeKey; if (prevFirstChildKey === nextFrstChildKey) { - reconcileNode(prevFirstChildKey, dom); + $reconcileNode(prevFirstChildKey, dom); } else { const lastDOM = getPrevElementByKeyOrThrow(prevFirstChildKey); - const replacementDOM = createNode(nextFrstChildKey, null, null); + const replacementDOM = $createNode(nextFrstChildKey, null, null); dom.replaceChild(replacementDOM, lastDOM); destroyNode(prevFirstChildKey, null); } @@ -494,7 +494,7 @@ function reconcileChildren( if (prevChildrenSize === 0) { if (nextChildrenSize !== 0) { - createChildren( + $createChildren( nextChildren, nextElement, 0, @@ -521,7 +521,7 @@ function reconcileChildren( } } } else { - reconcileNodeChildren( + $reconcileNodeChildren( nextElement, prevChildren, nextChildren, @@ -541,7 +541,7 @@ function reconcileChildren( subTreeTextContent = previousSubTreeTextContent + subTreeTextContent; } -function reconcileNode( +function $reconcileNode( key: NodeKey, parentDOM: HTMLElement | null, ): HTMLElement { @@ -607,7 +607,7 @@ function reconcileNode( // Update node. If it returns true, we need to unmount and re-create the node if (nextNode.updateDOM(prevNode, dom, activeEditorConfig)) { - const replacementDOM = createNode(key, null, null); + const replacementDOM = $createNode(key, null, null); if (parentDOM === null) { invariant(false, 'reconcileNode: parentDOM is null'); @@ -632,7 +632,7 @@ function reconcileNode( setElementFormat(dom, nextFormat); } if (isDirty) { - reconcileChildrenWithDirection(prevNode, nextNode, dom); + $reconcileChildrenWithDirection(prevNode, nextNode, dom); if (!$isRootNode(nextNode) && !nextNode.isInline()) { reconcileElementTerminatingLineBreak(prevNode, nextNode, dom); } @@ -709,7 +709,7 @@ function getNextSibling(element: HTMLElement): Node | null { return nextSibling; } -function reconcileNodeChildren( +function $reconcileNodeChildren( nextElement: ElementNode, prevChildren: Array, nextChildren: Array, @@ -730,7 +730,7 @@ function reconcileNodeChildren( const nextKey = nextChildren[nextIndex]; if (prevKey === nextKey) { - siblingDOM = getNextSibling(reconcileNode(nextKey, dom)); + siblingDOM = getNextSibling($reconcileNode(nextKey, dom)); prevIndex++; nextIndex++; } else { @@ -752,14 +752,14 @@ function reconcileNodeChildren( prevIndex++; } else if (!prevHasNextKey) { // Create next - createNode(nextKey, dom, siblingDOM); + $createNode(nextKey, dom, siblingDOM); nextIndex++; } else { // Move next const childDOM = getElementByKeyOrThrow(activeEditor, nextKey); if (childDOM === siblingDOM) { - siblingDOM = getNextSibling(reconcileNode(nextKey, dom)); + siblingDOM = getNextSibling($reconcileNode(nextKey, dom)); } else { if (siblingDOM != null) { dom.insertBefore(childDOM, siblingDOM); @@ -767,7 +767,7 @@ function reconcileNodeChildren( dom.appendChild(childDOM); } - reconcileNode(nextKey, dom); + $reconcileNode(nextKey, dom); } prevIndex++; @@ -790,7 +790,7 @@ function reconcileNodeChildren( previousNode === undefined ? null : activeEditor.getElementByKey(previousNode); - createChildren( + $createChildren( nextChildren, nextElement, nextIndex, @@ -803,7 +803,7 @@ function reconcileNodeChildren( } } -export function reconcileRoot( +export function $reconcileRoot( prevEditorState: EditorState, nextEditorState: EditorState, editor: LexicalEditor, @@ -834,7 +834,7 @@ export function reconcileRoot( // listeners later in the update cycle. const currentMutatedNodes = new Map(); mutatedNodes = currentMutatedNodes; - reconcileNode('root', null); + $reconcileNode('root', null); // We don't want a bunch of void checks throughout the scope // so instead we make it seem that these values are always set. // We also want to make sure we clear them down, otherwise we @@ -860,6 +860,8 @@ export function reconcileRoot( return currentMutatedNodes; } +/** @deprecated renamed to $reconcileRoot by @lexical/eslint-plugin rules-of-lexical */ +export const reconcileRoot = $reconcileRoot; export function storeDOMWithKey( key: NodeKey, diff --git a/packages/lexical/src/LexicalSelection.ts b/packages/lexical/src/LexicalSelection.ts index 12067bad8e37..61a51c6dc60f 100644 --- a/packages/lexical/src/LexicalSelection.ts +++ b/packages/lexical/src/LexicalSelection.ts @@ -609,7 +609,7 @@ export class RangeSelection implements BaseSelection { const editor = getActiveEditor(); const currentEditorState = editor.getEditorState(); const lastSelection = currentEditorState._selection; - const resolvedSelectionPoints = internalResolveSelectionPoints( + const resolvedSelectionPoints = $internalResolveSelectionPoints( range.startContainer, range.startOffset, range.endContainer, @@ -827,7 +827,7 @@ export class RangeSelection implements BaseSelection { !lastNodeParent.canInsertTextAfter())) ) { this.insertText(''); - normalizeSelectionPointsForBoundaries(this.anchor, this.focus, null); + $normalizeSelectionPointsForBoundaries(this.anchor, this.focus, null); this.insertText(text); return; } @@ -1224,7 +1224,7 @@ export class RangeSelection implements BaseSelection { if ('__language' in nodes[0]) { this.insertText(nodes[0].getTextContent()); } else { - const index = removeTextAndSplitBlock(this); + const index = $removeTextAndSplitBlock(this); firstBlock.splice(index, 0, nodes); last.selectEnd(); } @@ -1240,7 +1240,7 @@ export class RangeSelection implements BaseSelection { $isElementNode(firstBlock), "Expected 'firstBlock' to be an ElementNode", ); - const index = removeTextAndSplitBlock(this); + const index = $removeTextAndSplitBlock(this); firstBlock.splice(index, 0, nodes); last.selectEnd(); return; @@ -1311,7 +1311,7 @@ export class RangeSelection implements BaseSelection { paragraph.select(); return paragraph; } - const index = removeTextAndSplitBlock(this); + const index = $removeTextAndSplitBlock(this); const block = $getAncestor(this.anchor.getNode(), INTERNAL_$isBlock)!; invariant($isElementNode(block), 'Expected ancestor to be an ElementNode'); const firstToAppend = block.getChildAtIndex(index); @@ -1892,7 +1892,7 @@ function shouldResolveAncestor( ); } -function internalResolveSelectionPoint( +function $internalResolveSelectionPoint( dom: Node, offset: number, lastPoint: null | PointType, @@ -2062,7 +2062,7 @@ function resolveSelectionPointOnBoundary( } } -function normalizeSelectionPointsForBoundaries( +function $normalizeSelectionPointsForBoundaries( anchor: PointType, focus: PointType, lastSelection: null | BaseSelection, @@ -2101,7 +2101,7 @@ function normalizeSelectionPointsForBoundaries( } } -function internalResolveSelectionPoints( +function $internalResolveSelectionPoints( anchorDOM: null | Node, anchorOffset: number, focusDOM: null | Node, @@ -2116,7 +2116,7 @@ function internalResolveSelectionPoints( ) { return null; } - const resolvedAnchorPoint = internalResolveSelectionPoint( + const resolvedAnchorPoint = $internalResolveSelectionPoint( anchorDOM, anchorOffset, $isRangeSelection(lastSelection) ? lastSelection.anchor : null, @@ -2125,7 +2125,7 @@ function internalResolveSelectionPoints( if (resolvedAnchorPoint === null) { return null; } - const resolvedFocusPoint = internalResolveSelectionPoint( + const resolvedFocusPoint = $internalResolveSelectionPoint( focusDOM, focusOffset, $isRangeSelection(lastSelection) ? lastSelection.focus : null, @@ -2149,7 +2149,7 @@ function internalResolveSelectionPoints( } // Handle normalization of selection when it is at the boundaries. - normalizeSelectionPointsForBoundaries( + $normalizeSelectionPointsForBoundaries( resolvedAnchorPoint, resolvedFocusPoint, lastSelection, @@ -2168,7 +2168,7 @@ export function $isBlockElementNode( // selection is null, i.e. forcing selection on the editor // when it current exists outside the editor. -export function internalMakeRangeSelection( +export function $internalMakeRangeSelection( anchorKey: NodeKey, anchorOffset: number, focusKey: NodeKey, @@ -2187,6 +2187,8 @@ export function internalMakeRangeSelection( editorState._selection = selection; return selection; } +/** @deprecated renamed to $internalMakeRangeSelection by @lexical/eslint-plugin rules-of-lexical */ +export const internalMakeRangeSelection = $internalMakeRangeSelection; export function $createRangeSelection(): RangeSelection { const anchor = $createPoint('root', 0, 'element'); @@ -2198,7 +2200,7 @@ export function $createNodeSelection(): NodeSelection { return new NodeSelection(new Set()); } -export function internalCreateSelection( +export function $internalCreateSelection( editor: LexicalEditor, ): null | BaseSelection { const currentEditorState = editor.getEditorState(); @@ -2206,7 +2208,7 @@ export function internalCreateSelection( const domSelection = getDOMSelection(editor._window); if ($isRangeSelection(lastSelection) || lastSelection == null) { - return internalCreateRangeSelection( + return $internalCreateRangeSelection( lastSelection, domSelection, editor, @@ -2215,15 +2217,17 @@ export function internalCreateSelection( } return lastSelection.clone(); } +/** @deprecated renamed to $internalCreateSelection by @lexical/eslint-plugin rules-of-lexical */ +export const internalCreateSelection = $internalCreateSelection; export function $createRangeSelectionFromDom( domSelection: Selection | null, editor: LexicalEditor, ): null | RangeSelection { - return internalCreateRangeSelection(null, domSelection, editor, null); + return $internalCreateRangeSelection(null, domSelection, editor, null); } -export function internalCreateRangeSelection( +export function $internalCreateRangeSelection( lastSelection: null | BaseSelection, domSelection: Selection | null, editor: LexicalEditor, @@ -2283,7 +2287,7 @@ export function internalCreateRangeSelection( } // Let's resolve the text nodes from the offsets and DOM nodes we have from // native selection. - const resolvedSelectionPoints = internalResolveSelectionPoints( + const resolvedSelectionPoints = $internalResolveSelectionPoints( anchorDOM, anchorOffset, focusDOM, @@ -2302,6 +2306,8 @@ export function internalCreateRangeSelection( !$isRangeSelection(lastSelection) ? '' : lastSelection.style, ); } +/** @deprecated renamed to $internalCreateRangeSelection by @lexical/eslint-plugin rules-of-lexical */ +export const internalCreateRangeSelection = $internalCreateRangeSelection; export function $getSelection(): null | BaseSelection { const editorState = getActiveEditorState(); @@ -2695,7 +2701,7 @@ export function $getTextContent(): string { return selection.getTextContent(); } -function removeTextAndSplitBlock(selection: RangeSelection): number { +function $removeTextAndSplitBlock(selection: RangeSelection): number { let selection_ = selection; if (!selection.isCollapsed()) { selection_.removeText(); @@ -2717,13 +2723,13 @@ function removeTextAndSplitBlock(selection: RangeSelection): number { let offset = anchor.offset; while (!INTERNAL_$isBlock(node)) { - [node, offset] = splitNodeAtPoint(node, offset); + [node, offset] = $splitNodeAtPoint(node, offset); } return offset; } -function splitNodeAtPoint( +function $splitNodeAtPoint( node: LexicalNode, offset: number, ): [parent: ElementNode, offset: number] { diff --git a/packages/lexical/src/LexicalUpdates.ts b/packages/lexical/src/LexicalUpdates.ts index bb3e602078ed..8b9275cd9e2c 100644 --- a/packages/lexical/src/LexicalUpdates.ts +++ b/packages/lexical/src/LexicalUpdates.ts @@ -433,7 +433,7 @@ function handleDEVOnlyPendingUpdateGuarantees( }; } -export function commitPendingUpdates( +export function $commitPendingUpdates( editor: LexicalEditor, recoveryEditorState?: EditorState, ): void { @@ -494,7 +494,7 @@ export function commitPendingUpdates( initMutationObserver(editor); editor._dirtyType = FULL_RECONCILE; isAttemptingToRecoverFromReconcilerError = true; - commitPendingUpdates(editor, currentEditorState); + $commitPendingUpdates(editor, currentEditorState); isAttemptingToRecoverFromReconcilerError = false; } else { // To avoid a possible situation of infinite loops, lets throw @@ -638,8 +638,10 @@ export function commitPendingUpdates( tags, }); triggerDeferredUpdateCallbacks(editor, deferred); - triggerEnqueuedUpdates(editor); + $triggerEnqueuedUpdates(editor); } +/** @deprecated renamed to $commitPendingUpdates by @lexical/eslint-plugin rules-of-lexical */ +export const commitPendingUpdates = $commitPendingUpdates; function triggerTextContentListeners( editor: LexicalEditor, @@ -740,14 +742,14 @@ export function triggerCommandListeners< return false; } -function triggerEnqueuedUpdates(editor: LexicalEditor): void { +function $triggerEnqueuedUpdates(editor: LexicalEditor): void { const queuedUpdates = editor._updates; if (queuedUpdates.length !== 0) { const queuedUpdate = queuedUpdates.shift(); if (queuedUpdate) { const [updateFn, options] = queuedUpdate; - beginUpdate(editor, updateFn, options); + $beginUpdate(editor, updateFn, options); } } } @@ -814,7 +816,7 @@ function processNestedUpdates( return skipTransforms; } -function beginUpdate( +function $beginUpdate( editor: LexicalEditor, updateFn: () => void, options?: EditorUpdateOptions, @@ -939,7 +941,7 @@ function beginUpdate( editor._dirtyElements.clear(); - commitPendingUpdates(editor); + $commitPendingUpdates(editor); return; } finally { activeEditorState = previousActiveEditorState; @@ -956,10 +958,10 @@ function beginUpdate( if (shouldUpdate) { if (pendingEditorState._flushSync) { pendingEditorState._flushSync = false; - commitPendingUpdates(editor); + $commitPendingUpdates(editor); } else if (editorStateWasCloned) { scheduleMicroTask(() => { - commitPendingUpdates(editor); + $commitPendingUpdates(editor); }); } } else { @@ -973,7 +975,7 @@ function beginUpdate( } } -export function updateEditor( +export function $updateEditor( editor: LexicalEditor, updateFn: () => void, options?: EditorUpdateOptions, @@ -981,6 +983,8 @@ export function updateEditor( if (editor._updating) { editor._updates.push([updateFn, options]); } else { - beginUpdate(editor, updateFn, options); + $beginUpdate(editor, updateFn, options); } } +/** @deprecated renamed to $updateEditor by @lexical/eslint-plugin rules-of-lexical */ +export const updateEditor = $updateEditor; diff --git a/packages/lexical/src/LexicalUtils.ts b/packages/lexical/src/LexicalUtils.ts index f9af189d991d..2f6063e93760 100644 --- a/packages/lexical/src/LexicalUtils.ts +++ b/packages/lexical/src/LexicalUtils.ts @@ -390,7 +390,7 @@ export function $getNodeByKey( return node; } -export function getNodeFromDOMNode( +export function $getNodeFromDOMNode( dom: Node, editorState?: EditorState, ): LexicalNode | null { @@ -402,6 +402,8 @@ export function getNodeFromDOMNode( } return null; } +/** @deprecated renamed to $getNodeFromDOMNode by @lexical/eslint-plugin rules-of-lexical */ +export const getNodeFromDOMNode = $getNodeFromDOMNode; export function $getNearestNodeFromDOMNode( startingDOM: Node, @@ -409,7 +411,7 @@ export function $getNearestNodeFromDOMNode( ): LexicalNode | null { let dom: Node | null = startingDOM; while (dom != null) { - const node = getNodeFromDOMNode(dom, editorState); + const node = $getNodeFromDOMNode(dom, editorState); if (node !== null) { return node; } @@ -489,7 +491,7 @@ export function $flushMutations(): void { flushRootMutations(editor); } -export function getNodeFromDOM(dom: Node): null | LexicalNode { +export function $getNodeFromDOM(dom: Node): null | LexicalNode { const editor = getActiveEditor(); const nodeKey = getNodeKeyFromDOM(dom, editor); if (nodeKey === null) { @@ -501,6 +503,8 @@ export function getNodeFromDOM(dom: Node): null | LexicalNode { } return $getNodeByKey(nodeKey); } +/** @deprecated renamed to $getNodeFromDOM by @lexical/eslint-plugin rules-of-lexical */ +export const getNodeFromDOM = $getNodeFromDOM; export function getTextNodeOffset( node: TextNode, diff --git a/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx b/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx index 8e5d86c9f4f1..64c63019553c 100644 --- a/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx +++ b/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx @@ -1273,7 +1273,7 @@ describe('LexicalEditor tests', () => { } it('moves node to different tree branches', async () => { - function createElementNodeWithText(text: string) { + function $createElementNodeWithText(text: string) { const elementNode = $createTestElementNode(); const textNode = $createTextNode(text); elementNode.append(textNode); @@ -1291,11 +1291,11 @@ describe('LexicalEditor tests', () => { const paragraph = $getRoot().getFirstChild() as ParagraphNode; paragraphNodeKey = paragraph.getKey(); - const [elementNode1, textNode1] = createElementNodeWithText('A'); + const [elementNode1, textNode1] = $createElementNodeWithText('A'); elementNode1Key = elementNode1.getKey(); textNode1Key = textNode1.getKey(); - const [elementNode2, textNode2] = createElementNodeWithText('B'); + const [elementNode2, textNode2] = $createElementNodeWithText('B'); elementNode2Key = elementNode2.getKey(); textNode2Key = textNode2.getKey(); @@ -1328,7 +1328,7 @@ describe('LexicalEditor tests', () => { }); it('moves node to different tree branches (inverse)', async () => { - function createElementNodeWithText(text: string) { + function $createElementNodeWithText(text: string) { const elementNode = $createTestElementNode(); const textNode = $createTextNode(text); elementNode.append(textNode); @@ -1342,10 +1342,10 @@ describe('LexicalEditor tests', () => { await update(() => { const paragraph = $getRoot().getFirstChild() as ParagraphNode; - const elementNode1 = createElementNodeWithText('A'); + const elementNode1 = $createElementNodeWithText('A'); elementNode1Key = elementNode1.getKey(); - const elementNode2 = createElementNodeWithText('B'); + const elementNode2 = $createElementNodeWithText('B'); elementNode2Key = elementNode2.getKey(); paragraph.append(elementNode1, elementNode2); @@ -1363,7 +1363,7 @@ describe('LexicalEditor tests', () => { }); it('moves node to different tree branches (node appended twice in two different branches)', async () => { - function createElementNodeWithText(text: string) { + function $createElementNodeWithText(text: string) { const elementNode = $createTestElementNode(); const textNode = $createTextNode(text); elementNode.append(textNode); @@ -1378,13 +1378,13 @@ describe('LexicalEditor tests', () => { await update(() => { const paragraph = $getRoot().getFirstChild() as ParagraphNode; - const elementNode1 = createElementNodeWithText('A'); + const elementNode1 = $createElementNodeWithText('A'); elementNode1Key = elementNode1.getKey(); - const elementNode2 = createElementNodeWithText('B'); + const elementNode2 = $createElementNodeWithText('B'); elementNode2Key = elementNode2.getKey(); - const elementNode3 = createElementNodeWithText('C'); + const elementNode3 = $createElementNodeWithText('C'); elementNode3Key = elementNode3.getKey(); paragraph.append(elementNode1, elementNode2, elementNode3); diff --git a/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts b/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts index 385c6708db2e..7055f361a966 100644 --- a/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts +++ b/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts @@ -71,7 +71,7 @@ describe('LexicalSelection tests', () => { return {container, editor}; }; - const insertTextOrNodes = ( + const $insertTextOrNodes = ( selection: RangeSelection, method: 'insertText' | 'insertNodes', ) => { @@ -109,7 +109,7 @@ describe('LexicalSelection tests', () => { // For review: is there a way to select "outside" of the link // node? const selection = linkNode.select(0, 0); - insertTextOrNodes(selection, method); + $insertTextOrNodes(selection, method); }); expect(container.innerHTML).toBe( @@ -150,7 +150,7 @@ describe('LexicalSelection tests', () => { // Place the cursor between the link and the first text node by // selecting the end of the text node const selection = textNode.select(1, 1); - insertTextOrNodes(selection, method); + $insertTextOrNodes(selection, method); }); expect(container.innerHTML).toBe( @@ -190,7 +190,7 @@ describe('LexicalSelection tests', () => { // Place the cursor before the link element by selecting the end // of the text node const selection = textNode.select(1, 1); - insertTextOrNodes(selection, method); + $insertTextOrNodes(selection, method); }); expect(container.innerHTML).toBe( @@ -232,7 +232,7 @@ describe('LexicalSelection tests', () => { // Place the cursor between the link and the last text node by // selecting the start of the text node const selection = textNode.select(0, 0); - insertTextOrNodes(selection, method); + $insertTextOrNodes(selection, method); }); expect(container.innerHTML).toBe( @@ -273,7 +273,7 @@ describe('LexicalSelection tests', () => { // Place the cursor between the link and the last text node by // selecting the start of the text node const selection = textNode.select(0, 0); - insertTextOrNodes(selection, method); + $insertTextOrNodes(selection, method); }); expect(container.innerHTML).toBe( @@ -315,7 +315,7 @@ describe('LexicalSelection tests', () => { // For review: not sure if there's a better way to select // "outside" of the link element. const selection = linkNode.select(1, 1); - insertTextOrNodes(selection, method); + $insertTextOrNodes(selection, method); }); expect(container.innerHTML).toBe( diff --git a/packages/lexical/src/__tests__/unit/LexicalSerialization.test.ts b/packages/lexical/src/__tests__/unit/LexicalSerialization.test.ts index cff91af58985..21915802689b 100644 --- a/packages/lexical/src/__tests__/unit/LexicalSerialization.test.ts +++ b/packages/lexical/src/__tests__/unit/LexicalSerialization.test.ts @@ -15,7 +15,7 @@ import {$createParagraphNode, $createTextNode, $getRoot} from 'lexical'; import {initializeUnitTest} from '../utils'; -function createEditorContent() { +function $createEditorContent() { const root = $getRoot(); if (root.getFirstChild() === null) { const heading = $createHeadingNode('h1'); @@ -106,7 +106,7 @@ describe('LexicalSerialization tests', () => { const {editor} = testEnv; await editor.update(() => { - createEditorContent(); + $createEditorContent(); }); const stringifiedEditorState = JSON.stringify(editor.getEditorState()); diff --git a/packages/lexical/src/nodes/LexicalLineBreakNode.ts b/packages/lexical/src/nodes/LexicalLineBreakNode.ts index 1a67826f137e..fc338765022c 100644 --- a/packages/lexical/src/nodes/LexicalLineBreakNode.ts +++ b/packages/lexical/src/nodes/LexicalLineBreakNode.ts @@ -54,7 +54,7 @@ export class LineBreakNode extends LexicalNode { return null; } return { - conversion: convertLineBreakElement, + conversion: $convertLineBreakElement, priority: 0, }; }, @@ -75,7 +75,7 @@ export class LineBreakNode extends LexicalNode { } } -function convertLineBreakElement(node: Node): DOMConversionOutput { +function $convertLineBreakElement(node: Node): DOMConversionOutput { return {node: $createLineBreakNode()}; } diff --git a/packages/lexical/src/nodes/LexicalParagraphNode.ts b/packages/lexical/src/nodes/LexicalParagraphNode.ts index 8524af01e302..e13e6c41efbf 100644 --- a/packages/lexical/src/nodes/LexicalParagraphNode.ts +++ b/packages/lexical/src/nodes/LexicalParagraphNode.ts @@ -98,7 +98,7 @@ export class ParagraphNode extends ElementNode { static importDOM(): DOMConversionMap | null { return { p: (node: Node) => ({ - conversion: convertParagraphElement, + conversion: $convertParagraphElement, priority: 0, }), }; @@ -190,7 +190,7 @@ export class ParagraphNode extends ElementNode { } } -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/LexicalTextNode.ts b/packages/lexical/src/nodes/LexicalTextNode.ts index 26bc0f638494..02375fc63bfe 100644 --- a/packages/lexical/src/nodes/LexicalTextNode.ts +++ b/packages/lexical/src/nodes/LexicalTextNode.ts @@ -543,7 +543,7 @@ export class TextNode extends LexicalNode { static importDOM(): DOMConversionMap | null { return { '#text': () => ({ - conversion: convertTextDOMNode, + conversion: $convertTextDOMNode, priority: 0, }), b: () => ({ @@ -1182,7 +1182,7 @@ export function findParentPreDOMNode(node: Node) { return resultNode; } -function convertTextDOMNode(domNode: Node): DOMConversionOutput { +function $convertTextDOMNode(domNode: Node): DOMConversionOutput { const domNode_ = domNode as Text; const parentDom = domNode.parentElement; invariant(