From 7685e95752016c44d41c469cd6daed191247072e Mon Sep 17 00:00:00 2001 From: wnhlee <2wheeh@gmail.com> Date: Tue, 23 Apr 2024 08:04:36 +0900 Subject: [PATCH] improve typing --- .eslintrc.js | 2 +- packages/lexical-clipboard/src/clipboard.ts | 12 +++--- packages/lexical-code/src/CodeHighlighter.ts | 8 ++-- packages/lexical-code/src/CodeNode.ts | 9 +++-- .../src/generateContent.ts | 6 +-- .../injected/InjectedPegasusService.ts | 6 +-- .../src/serializeEditorState.ts | 6 +-- packages/lexical-html/src/index.ts | 6 +-- .../lexical-list/src/LexicalListItemNode.ts | 9 +++-- packages/lexical-list/src/formatList.ts | 6 +-- packages/lexical-list/src/utils.ts | 8 ++-- packages/lexical-mark/src/index.ts | 2 +- .../lexical-markdown/src/MarkdownExport.ts | 6 +-- .../lexical-markdown/src/MarkdownImport.ts | 18 ++++----- .../lexical-markdown/src/MarkdownShortcuts.ts | 6 ++- packages/lexical-plain-text/src/index.ts | 6 +-- packages/lexical-playground/src/Editor.tsx | 2 +- .../nodes/ExcalidrawNode/ExcalidrawImage.tsx | 2 +- .../src/nodes/StickyComponent.tsx | 2 +- .../src/plugins/AutoEmbedPlugin/index.tsx | 12 +++--- .../plugins/ComponentPickerPlugin/index.tsx | 4 -- .../src/plugins/EmojiPickerPlugin/index.tsx | 24 +++++------- .../src/plugins/ImagesPlugin/index.tsx | 2 +- .../src/plugins/InlineImagePlugin/index.tsx | 2 +- .../src/plugins/MarkdownTransformers/index.ts | 6 +-- .../src/plugins/MentionsPlugin/index.tsx | 2 +- .../plugins/TableActionMenuPlugin/index.tsx | 22 +++++------ .../src/plugins/TableCellResizer/index.tsx | 4 +- .../src/plugins/TestRecorderPlugin/index.tsx | 16 ++++---- .../src/LexicalAutoEmbedPlugin.tsx | 10 ++--- .../src/LexicalCheckListPlugin.tsx | 38 +++++++++++-------- .../src/LexicalClearEditorPlugin.ts | 2 +- .../src/LexicalClickableLinkPlugin.tsx | 2 +- .../src/LexicalCollaborationContext.ts | 4 +- .../src/LexicalCollaborationPlugin.ts | 2 +- .../src/LexicalComposerContext.ts | 8 ++-- .../src/LexicalContextMenuPlugin.tsx | 10 ++--- .../src/LexicalMarkdownShortcutPlugin.tsx | 2 +- .../src/LexicalNestedComposer.tsx | 2 +- .../src/LexicalNodeMenuPlugin.tsx | 12 +++--- .../lexical-react/src/LexicalTreeView.tsx | 2 +- .../src/LexicalTypeaheadMenuPlugin.tsx | 6 +-- .../lexical-react/src/shared/LexicalMenu.ts | 20 +++++----- .../src/shared/useYjsCollaboration.tsx | 12 +----- packages/lexical-rich-text/src/index.ts | 4 +- .../lexical-selection/src/lexical-node.ts | 2 +- packages/lexical-selection/src/utils.ts | 6 +-- .../lexical-table/src/LexicalTableNode.ts | 10 ++--- .../lexical-table/src/LexicalTableObserver.ts | 8 ++-- .../src/LexicalTableSelection.ts | 4 +- .../src/LexicalTableSelectionHelpers.ts | 24 ++++++------ .../lexical-table/src/LexicalTableUtils.ts | 2 +- .../src/registerLexicalTextEntity.ts | 8 ++-- packages/lexical-utils/src/index.ts | 8 ++-- packages/lexical-yjs/src/SyncCursors.ts | 12 ++++-- packages/lexical/src/LexicalEditor.ts | 36 +++++++----------- packages/lexical/src/LexicalEvents.ts | 10 ++--- packages/lexical/src/LexicalMutations.ts | 7 ++-- packages/lexical/src/LexicalNode.ts | 4 +- packages/lexical/src/LexicalReconciler.ts | 12 +++--- packages/lexical/src/LexicalSelection.ts | 28 +++++++------- packages/lexical/src/LexicalUpdates.ts | 6 +-- packages/lexical/src/LexicalUtils.ts | 24 ++++++------ packages/lexical/src/nodes/LexicalTextNode.ts | 6 +-- 64 files changed, 281 insertions(+), 288 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c02e6d2f13ae..ca42a94b7ddf 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -133,7 +133,7 @@ module.exports = { 'dot-notation': [ERROR, {allowPattern: '^(error|warn)$'}], 'eol-last': ERROR, - eqeqeq: [ERROR, 'allow-null'], + eqeqeq: [ERROR, 'always'], // Prettier forces semicolons in a few places 'flowtype/object-type-delimiter': OFF, diff --git a/packages/lexical-clipboard/src/clipboard.ts b/packages/lexical-clipboard/src/clipboard.ts index f9ec8cb80313..14ed8bb28c1f 100644 --- a/packages/lexical-clipboard/src/clipboard.ts +++ b/packages/lexical-clipboard/src/clipboard.ts @@ -49,7 +49,7 @@ const getDOMSelection = (targetWindow: Window | null): Selection | null => export function $getHtmlContent(editor: LexicalEditor): string { const selection = $getSelection(); - if (selection == null) { + if (selection === null) { invariant(false, 'Expected valid LexicalSelection'); } @@ -76,7 +76,7 @@ export function $getHtmlContent(editor: LexicalEditor): string { export function $getLexicalContent(editor: LexicalEditor): null | string { const selection = $getSelection(); - if (selection == null) { + if (selection === null) { invariant(false, 'Expected valid LexicalSelection'); } @@ -106,9 +106,7 @@ export function $insertDataTransferForPlainText( const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list'); - if (text != null) { - selection.insertRawText(text); - } + selection.insertRawText(text); } /** @@ -159,7 +157,7 @@ export function $insertDataTransferForRichText( // Webkit-specific: Supports read 'text/uri-list' in clipboard. const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list'); - if (text != null) { + if (text !== '') { if ($isRangeSelection(selection)) { const parts = text.split(/(\r?\n|\t)/); if (parts[parts.length - 1] === '') { @@ -399,7 +397,7 @@ export async function copyToClipboard( const rootElement = editor.getRootElement(); const windowDocument = - editor._window == null ? window.document : editor._window.document; + editor._window === null ? window.document : editor._window.document; const domSelection = getDOMSelection(editor._window); if (rootElement === null || domSelection === null) { return false; diff --git a/packages/lexical-code/src/CodeHighlighter.ts b/packages/lexical-code/src/CodeHighlighter.ts index bff05ef2315a..ae0850533bdd 100644 --- a/packages/lexical-code/src/CodeHighlighter.ts +++ b/packages/lexical-code/src/CodeHighlighter.ts @@ -695,7 +695,7 @@ function handleShiftLines( start = getFirstCodeNodeOfLine(focusNode); end = getLastCodeNodeOfLine(anchorNode); } - if (start == null || end == null) { + if (start === null || end === null) { return false; } @@ -726,7 +726,7 @@ function handleShiftLines( const sibling = arrowIsUp ? linebreak.getPreviousSibling() : linebreak.getNextSibling(); - if (sibling == null) { + if (sibling === null) { return true; } @@ -739,7 +739,7 @@ function handleShiftLines( : getLastCodeNodeOfLine(sibling) : null; let insertionPoint = - maybeInsertionPoint != null ? maybeInsertionPoint : sibling; + maybeInsertionPoint !== null ? maybeInsertionPoint : sibling; linebreak.remove(); range.forEach((node) => node.remove()); if (type === KEY_ARROW_UP_COMMAND) { @@ -813,7 +813,7 @@ export function registerCodeHighlighting( ); } - if (tokenizer == null) { + if (tokenizer === undefined) { tokenizer = PrismTokenizer; } diff --git a/packages/lexical-code/src/CodeNode.ts b/packages/lexical-code/src/CodeNode.ts index ef2588aa598c..eb08be68a089 100644 --- a/packages/lexical-code/src/CodeNode.ts +++ b/packages/lexical-code/src/CodeNode.ts @@ -51,8 +51,9 @@ export type SerializedCodeNode = Spread< const mapToPrismLanguage = ( language: string | null | undefined, ): string | null | undefined => { - // eslint-disable-next-line no-prototype-builtins - return language != null && window.Prism.languages.hasOwnProperty(language) + return language !== null && + language !== undefined && + Object.hasOwn(window.Prism.languages, language) ? language : undefined; }; @@ -134,7 +135,7 @@ export class CodeNode extends ElementNode { // inline format handled by TextNode otherwise. code: (node: Node) => { const isMultiLine = - node.textContent != null && + node.textContent !== null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR')); return isMultiLine @@ -350,7 +351,7 @@ function convertDivElement(domNode: Node): DOMConversionOutput { return { after: (childLexicalNodes) => { const domParent = domNode.parentNode; - if (domParent != null && domNode !== domParent.lastChild) { + if (domParent !== null && domNode !== domParent.lastChild) { childLexicalNodes.push($createLineBreakNode()); } return childLexicalNodes; diff --git a/packages/lexical-devtools-core/src/generateContent.ts b/packages/lexical-devtools-core/src/generateContent.ts index db702c6ddd02..f6cb39066013 100644 --- a/packages/lexical-devtools-core/src/generateContent.ts +++ b/packages/lexical-devtools-core/src/generateContent.ts @@ -340,7 +340,7 @@ function printFormatProperties(nodeOrSelection: TextNode | RangeSelection) { function printTargetProperties(node: LinkNode) { let str = node.getTarget(); // TODO Fix nullish on LinkNode - if (str != null) { + if (str !== null) { str = 'target: ' + str; } return str; @@ -349,7 +349,7 @@ function printTargetProperties(node: LinkNode) { function printRelProperties(node: LinkNode) { let str = node.getRel(); // TODO Fix nullish on LinkNode - if (str != null) { + if (str !== null) { str = 'rel: ' + str; } return str; @@ -358,7 +358,7 @@ function printRelProperties(node: LinkNode) { function printTitleProperties(node: LinkNode) { let str = node.getTitle(); // TODO Fix nullish on LinkNode - if (str != null) { + if (str !== null) { str = 'title: ' + str; } return str; diff --git a/packages/lexical-devtools/src/entrypoints/injected/InjectedPegasusService.ts b/packages/lexical-devtools/src/entrypoints/injected/InjectedPegasusService.ts index 19f900843f45..4eb523938362 100644 --- a/packages/lexical-devtools/src/entrypoints/injected/InjectedPegasusService.ts +++ b/packages/lexical-devtools/src/entrypoints/injected/InjectedPegasusService.ts @@ -44,7 +44,7 @@ export class InjectedPegasusService isReadonly: boolean, ): void { const editorNode = queryLexicalNodeByKey(editorKey); - if (editorNode == null) { + if (editorNode === undefined) { throw new Error(`Can't find editor with key: ${editorKey}`); } @@ -57,7 +57,7 @@ export class InjectedPegasusService exportDOM: boolean, ): string { const editor = queryLexicalEditorByKey(editorKey); - if (editor == null) { + if (editor === undefined) { throw new Error(`Can't find editor with key: ${editorKey}`); } @@ -72,7 +72,7 @@ export class InjectedPegasusService editorState: SerializedRawEditorState, ): void { const editor = queryLexicalEditorByKey(editorKey); - if (editor == null) { + if (editor === undefined) { throw new Error(`Can't find editor with key: ${editorKey}`); } diff --git a/packages/lexical-devtools/src/serializeEditorState.ts b/packages/lexical-devtools/src/serializeEditorState.ts index 1a7a28dc3072..721a2ae1e139 100644 --- a/packages/lexical-devtools/src/serializeEditorState.ts +++ b/packages/lexical-devtools/src/serializeEditorState.ts @@ -37,7 +37,7 @@ export function deserializeEditorState( typeof editorState.deserealizationID === 'number' ) { const state = deserealizationMap.get(editorState.deserealizationID); - if (state == null) { + if (state === undefined) { throw new Error( `Can't find deserealization ref for state with id ${editorState.deserealizationID}`, ); @@ -64,7 +64,7 @@ export function serializeEditorState( selection && 'anchor' in selection && typeof selection.anchor === 'object' && - selection.anchor != null + selection.anchor !== null ) { // remove _selection.anchor._selection property if present in RangeSelection or GridSelection // otherwise, the recursive structure makes the selection object unserializable @@ -74,7 +74,7 @@ export function serializeEditorState( selection && 'focus' in selection && typeof selection.focus === 'object' && - selection.focus != null + selection.focus !== null ) { // remove _selection.anchor._selection property if present in RangeSelection or GridSelection // otherwise, the recursive structure makes the selection object unserializable diff --git a/packages/lexical-html/src/index.ts b/packages/lexical-html/src/index.ts index 52f946f8057a..85a1508de3ce 100644 --- a/packages/lexical-html/src/index.ts +++ b/packages/lexical-html/src/index.ts @@ -224,7 +224,7 @@ function $createNodesFromDOM( } } - if (transformOutput.forChild != null) { + if (transformOutput.forChild !== undefined) { forChildMap.set(node.nodeName, transformOutput.forChild); } } @@ -245,11 +245,11 @@ function $createNodesFromDOM( ); } - if (postTransform != null) { + if (postTransform !== null && postTransform !== undefined) { childLexicalNodes = postTransform(childLexicalNodes); } - if (currentLexicalNode == null) { + if (currentLexicalNode === null || currentLexicalNode === undefined) { // If it hasn't been converted to a LexicalNode, we hoist its children // up to the same level as it. lexicalNodes = lexicalNodes.concat(childLexicalNodes); diff --git a/packages/lexical-list/src/LexicalListItemNode.ts b/packages/lexical-list/src/LexicalListItemNode.ts index 497583adf887..9e1f4e211622 100644 --- a/packages/lexical-list/src/LexicalListItemNode.ts +++ b/packages/lexical-list/src/LexicalListItemNode.ts @@ -102,12 +102,15 @@ export class ListItemNode extends ElementNode { static transform(): (node: LexicalNode) => void { return (node: LexicalNode) => { invariant($isListItemNode(node), 'node is not a ListItemNode'); - if (node.__checked == null) { + if (node.__checked === undefined) { return; } const parent = node.getParent(); if ($isListNode(parent)) { - if (parent.getListType() !== 'check' && node.getChecked() != null) { + if ( + parent.getListType() !== 'check' && + node.getChecked() !== undefined + ) { node.setChecked(undefined); } } @@ -261,7 +264,7 @@ export class ListItemNode extends ElementNode { restoreSelection = true, ): ListItemNode | ParagraphNode { const newElement = $createListItemNode( - this.__checked == null ? undefined : false, + this.__checked === undefined ? undefined : false, ); this.insertAfter(newElement, restoreSelection); diff --git a/packages/lexical-list/src/formatList.ts b/packages/lexical-list/src/formatList.ts index 2263edfb7575..55d4aa176481 100644 --- a/packages/lexical-list/src/formatList.ts +++ b/packages/lexical-list/src/formatList.ts @@ -115,7 +115,7 @@ export function insertList(editor: LexicalEditor, listType: ListType): void { if ($isLeafNode(node)) { let parent = node.getParent(); - while (parent != null) { + while (parent !== null) { const parentKey = parent.getKey(); if ($isListNode(parent)) { @@ -242,7 +242,7 @@ export function removeList(editor: LexicalEditor): void { if ($isLeafNode(node)) { const listItemNode = $getNearestNodeOfType(node, ListItemNode); - if (listItemNode != null) { + if (listItemNode !== null) { listNodes.add($getTopListNode(listItemNode)); } } @@ -297,7 +297,7 @@ export function updateChildrenListItemValue(list: ListNode): void { if (child.getValue() !== value) { child.setValue(value); } - if (isNotChecklist && child.getChecked() != null) { + if (isNotChecklist && child.getChecked() !== undefined) { child.setChecked(undefined); } if (!$isListNode(child.getFirstChild())) { diff --git a/packages/lexical-list/src/utils.ts b/packages/lexical-list/src/utils.ts index 2ee99e4c08c8..06992bd25410 100644 --- a/packages/lexical-list/src/utils.ts +++ b/packages/lexical-list/src/utils.ts @@ -28,7 +28,7 @@ export function $getListDepth(listNode: ListNode): number { let depth = 1; let parent = listNode.getParent(); - while (parent != null) { + while (parent !== null) { if ($isListItemNode(parent)) { const parentList = parent.getParent(); @@ -176,13 +176,13 @@ export function $removeHighestEmptyListParent( let emptyListPtr = sublist; while ( - emptyListPtr.getNextSibling() == null && - emptyListPtr.getPreviousSibling() == null + emptyListPtr.getNextSibling() === null && + emptyListPtr.getPreviousSibling() === null ) { const parent = emptyListPtr.getParent(); if ( - parent == null || + parent === null || !($isListItemNode(emptyListPtr) || $isListNode(emptyListPtr)) ) { break; diff --git a/packages/lexical-mark/src/index.ts b/packages/lexical-mark/src/index.ts index 5aa46e82ccca..73c2ded18bb6 100644 --- a/packages/lexical-mark/src/index.ts +++ b/packages/lexical-mark/src/index.ts @@ -99,7 +99,7 @@ export function $wrapSelectionInMarkNode( continue; } const parentNode = targetNode.getParent(); - if (parentNode == null || !parentNode.is(currentNodeParent)) { + if (parentNode === null || !parentNode.is(currentNodeParent)) { // If the parent node is not the current node's parent node, we can // clear the last created mark node. lastCreatedMarkNode = undefined; diff --git a/packages/lexical-markdown/src/MarkdownExport.ts b/packages/lexical-markdown/src/MarkdownExport.ts index c0215cdc6265..3343e35f4e65 100644 --- a/packages/lexical-markdown/src/MarkdownExport.ts +++ b/packages/lexical-markdown/src/MarkdownExport.ts @@ -47,7 +47,7 @@ export function createMarkdownExport( byType.textMatch, ); - if (result != null) { + if (result !== null) { output.push(result); } } @@ -67,7 +67,7 @@ function exportTopLevelElements( exportChildren(_node, textTransformersIndex, textMatchTransformers), ); - if (result != null) { + if (result !== null) { return result; } } @@ -103,7 +103,7 @@ function exportChildren( exportTextFormat(textNode, textContent, textTransformersIndex), ); - if (result != null) { + if (result !== null) { output.push(result); continue mainLoop; } diff --git a/packages/lexical-markdown/src/MarkdownImport.ts b/packages/lexical-markdown/src/MarkdownImport.ts index 49df0bddb84b..71507b1d3945 100644 --- a/packages/lexical-markdown/src/MarkdownImport.ts +++ b/packages/lexical-markdown/src/MarkdownImport.ts @@ -36,9 +36,9 @@ import {PUNCTUATION_OR_SPACE, transformersByType} from './utils'; const MARKDOWN_EMPTY_LINE_REG_EXP = /^\s{0,3}$/; const CODE_BLOCK_REG_EXP = /^```(\w{1,10})?\s?$/; type TextFormatTransformersIndex = Readonly<{ - fullMatchRegExpByTag: Readonly>; + fullMatchRegExpByTag: Readonly>>; openTagsRegExp: RegExp; - transformersByTag: Readonly>; + transformersByTag: Readonly>>; }>; export function createMarkdownImport( @@ -63,7 +63,7 @@ export function createMarkdownImport( // Abstract it to be dynamic as other transformers (add multiline match option) const [codeBlockNode, shiftedIndex] = importCodeBlock(lines, i, root); - if (codeBlockNode != null) { + if (codeBlockNode !== null) { i = shiftedIndex; continue; } @@ -99,7 +99,7 @@ function isEmptyParagraph(node: LexicalNode): boolean { const firstChild = node.getFirstChild(); return ( - firstChild == null || + firstChild === null || (node.getChildrenSize() === 1 && $isTextNode(firstChild) && MARKDOWN_EMPTY_LINE_REG_EXP.test(firstChild.getTextContent())) @@ -149,14 +149,14 @@ function importBlocks( if ($isListNode(previousNode)) { const lastDescendant = previousNode.getLastDescendant(); - if (lastDescendant == null) { + if (lastDescendant === null) { targetNode = null; } else { targetNode = $findMatchingParent(lastDescendant, $isListItemNode); } } - if (targetNode != null && targetNode.getTextContentSize() > 0) { + if (targetNode !== null && targetNode.getTextContentSize() > 0) { targetNode.splice(targetNode.getChildrenSize(), 0, [ $createLineBreakNode(), ...elementNode.getChildren(), @@ -319,7 +319,7 @@ function findOutermostMatch( ): RegExpMatchArray | null { const openTagsMatch = textContent.match(textTransformersIndex.openTagsRegExp); - if (openTagsMatch == null) { + if (openTagsMatch === null) { return null; } @@ -328,13 +328,13 @@ function findOutermostMatch( // before using match to find transformer const tag = match.replace(/^\s/, ''); const fullMatchRegExp = textTransformersIndex.fullMatchRegExpByTag[tag]; - if (fullMatchRegExp == null) { + if (fullMatchRegExp === undefined) { continue; } const fullMatch = textContent.match(fullMatchRegExp); const transformer = textTransformersIndex.transformersByTag[tag]; - if (fullMatch != null && transformer != null) { + if (fullMatch !== null && transformer !== undefined) { if (transformer.intraword !== false) { return fullMatch; } diff --git a/packages/lexical-markdown/src/MarkdownShortcuts.ts b/packages/lexical-markdown/src/MarkdownShortcuts.ts index f89af2129e3d..9a96da97e09a 100644 --- a/packages/lexical-markdown/src/MarkdownShortcuts.ts +++ b/packages/lexical-markdown/src/MarkdownShortcuts.ts @@ -77,13 +77,15 @@ function runElementTransformers( function runTextMatchTransformers( anchorNode: TextNode, anchorOffset: number, - transformersByTrigger: Readonly>>, + transformersByTrigger: Readonly< + Partial>> + >, ): boolean { let textContent = anchorNode.getTextContent(); const lastChar = textContent[anchorOffset - 1]; const transformers = transformersByTrigger[lastChar]; - if (transformers == null) { + if (transformers === undefined) { return false; } diff --git a/packages/lexical-plain-text/src/index.ts b/packages/lexical-plain-text/src/index.ts index 1df4cb1c1ca6..0f111b1efb80 100644 --- a/packages/lexical-plain-text/src/index.ts +++ b/packages/lexical-plain-text/src/index.ts @@ -59,7 +59,7 @@ function onCopyForPlainText( : (event as ClipboardEvent).clipboardData; const selection = $getSelection(); - if (selection !== null && clipboardData != null) { + if (selection !== null && clipboardData !== null) { event.preventDefault(); const htmlString = $getHtmlContent(editor); @@ -82,7 +82,7 @@ function onPasteForPlainText( () => { const selection = $getSelection(); const {clipboardData} = event as ClipboardEvent; - if (clipboardData != null && $isRangeSelection(selection)) { + if (clipboardData !== null && $isRangeSelection(selection)) { $insertDataTransferForPlainText(clipboardData, selection); } }, @@ -164,7 +164,7 @@ export function registerPlainText(editor: LexicalEditor): () => void { } else { const dataTransfer = eventOrText.dataTransfer; - if (dataTransfer != null) { + if (dataTransfer !== null) { $insertDataTransferForPlainText(dataTransfer, selection); } else { const data = eventOrText.data; diff --git a/packages/lexical-playground/src/Editor.tsx b/packages/lexical-playground/src/Editor.tsx index 605305127258..30fccf72652b 100644 --- a/packages/lexical-playground/src/Editor.tsx +++ b/packages/lexical-playground/src/Editor.tsx @@ -73,7 +73,7 @@ import Placeholder from './ui/Placeholder'; const skipCollaborationInit = // @ts-expect-error - window.parent != null && window.parent.frames.right === window; + window.parent !== null && window.parent.frames.right === window; export default function Editor(): JSX.Element { const {historyState} = useSharedHistoryContext(); diff --git a/packages/lexical-playground/src/nodes/ExcalidrawNode/ExcalidrawImage.tsx b/packages/lexical-playground/src/nodes/ExcalidrawNode/ExcalidrawImage.tsx index 65ec02f1b066..95414785b050 100644 --- a/packages/lexical-playground/src/nodes/ExcalidrawNode/ExcalidrawImage.tsx +++ b/packages/lexical-playground/src/nodes/ExcalidrawNode/ExcalidrawImage.tsx @@ -64,7 +64,7 @@ const removeStyleFromSvg_HACK = (svg: SVGElement) => { // Generated SVG is getting double-sized by height and width attributes // We want to match the real size of the SVG element const viewBox = svg.getAttribute('viewBox'); - if (viewBox != null) { + if (viewBox !== null) { const viewBoxDimensions = viewBox.split(' '); svg.setAttribute('width', viewBoxDimensions[2]); svg.setAttribute('height', viewBoxDimensions[3]); diff --git a/packages/lexical-playground/src/nodes/StickyComponent.tsx b/packages/lexical-playground/src/nodes/StickyComponent.tsx index 84c5fe731316..b273e65bbe3c 100644 --- a/packages/lexical-playground/src/nodes/StickyComponent.tsx +++ b/packages/lexical-playground/src/nodes/StickyComponent.tsx @@ -205,7 +205,7 @@ export default function StickyComponent({ onPointerDown={(event) => { const stickyContainer = stickyContainerRef.current; if ( - stickyContainer == null || + stickyContainer === null || event.button === 2 || event.target !== stickyContainer.firstChild ) { diff --git a/packages/lexical-playground/src/plugins/AutoEmbedPlugin/index.tsx b/packages/lexical-playground/src/plugins/AutoEmbedPlugin/index.tsx index 808967b3082a..c3e1cb474221 100644 --- a/packages/lexical-playground/src/plugins/AutoEmbedPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/AutoEmbedPlugin/index.tsx @@ -65,7 +65,7 @@ export const YoutubeEmbedConfig: PlaygroundEmbedConfig = { const id = match ? (match?.[2].length === 11 ? match[2] : null) : null; - if (id != null) { + if (id !== null) { return { id, url, @@ -102,7 +102,7 @@ export const TwitterEmbedConfig: PlaygroundEmbedConfig = { text, ); - if (match != null) { + if (match !== null) { return { id: match[5], url: match[1], @@ -135,7 +135,7 @@ export const FigmaEmbedConfig: PlaygroundEmbedConfig = { text, ); - if (match != null) { + if (match !== null) { return { id: match[3], url: match[0], @@ -241,13 +241,13 @@ export function AutoEmbedDialog({ () => debounce((inputText: string) => { const urlMatch = URL_MATCHER.exec(inputText); - if (embedConfig != null && inputText != null && urlMatch != null) { + if (urlMatch !== null) { Promise.resolve(embedConfig.parseUrl(inputText)).then( (parseResult) => { setEmbedResult(parseResult); }, ); - } else if (embedResult != null) { + } else if (embedResult !== null) { setEmbedResult(null); } }, 200), @@ -255,7 +255,7 @@ export function AutoEmbedDialog({ ); const onClick = () => { - if (embedResult != null) { + if (embedResult !== null) { embedConfig.insertNode(editor, embedResult); onClose(); } diff --git a/packages/lexical-playground/src/plugins/ComponentPickerPlugin/index.tsx b/packages/lexical-playground/src/plugins/ComponentPickerPlugin/index.tsx index 194060890566..414b14d4003d 100644 --- a/packages/lexical-playground/src/plugins/ComponentPickerPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ComponentPickerPlugin/index.tsx @@ -114,10 +114,6 @@ function ComponentPickerMenuItem({ function getDynamicOptions(editor: LexicalEditor, queryString: string) { const options: Array = []; - if (queryString == null) { - return options; - } - const tableMatch = queryString.match(/^([1-9]\d?)(?:x([1-9]\d?)?)?$/); if (tableMatch !== null) { diff --git a/packages/lexical-playground/src/plugins/EmojiPickerPlugin/index.tsx b/packages/lexical-playground/src/plugins/EmojiPickerPlugin/index.tsx index 8e930e3a0213..88d728735efd 100644 --- a/packages/lexical-playground/src/plugins/EmojiPickerPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/EmojiPickerPlugin/index.tsx @@ -99,14 +99,12 @@ export default function EmojiPickerPlugin() { const emojiOptions = useMemo( () => - emojis != null - ? emojis.map( - ({emoji, aliases, tags}) => - new EmojiOption(aliases[0], emoji, { - keywords: [...aliases, ...tags], - }), - ) - : [], + emojis.map( + ({emoji, aliases, tags}) => + new EmojiOption(aliases[0], emoji, { + keywords: [...aliases, ...tags], + }), + ), [emojis], ); @@ -117,13 +115,11 @@ export default function EmojiPickerPlugin() { const options: Array = useMemo(() => { return emojiOptions .filter((option: EmojiOption) => { - return queryString != null + return queryString !== null ? new RegExp(queryString, 'gi').exec(option.title) || - option.keywords != null - ? option.keywords.some((keyword: string) => + option.keywords.some((keyword: string) => new RegExp(queryString, 'gi').exec(keyword), ) - : false : emojiOptions; }) .slice(0, MAX_EMOJI_SUGGESTION_COUNT); @@ -138,7 +134,7 @@ export default function EmojiPickerPlugin() { editor.update(() => { const selection = $getSelection(); - if (!$isRangeSelection(selection) || selectedOption == null) { + if (!$isRangeSelection(selection)) { return; } @@ -164,7 +160,7 @@ export default function EmojiPickerPlugin() { anchorElementRef, {selectedIndex, selectOptionAndCleanUp, setHighlightedIndex}, ) => { - if (anchorElementRef.current == null || options.length === 0) { + if (anchorElementRef.current === null || options.length === 0) { return null; } diff --git a/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx b/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx index 32d8ccfbae0c..aba8b1ba67c9 100644 --- a/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx @@ -372,7 +372,7 @@ function getDragSelection(event: DragEvent): Range | null | undefined { let range; const target = event.target as null | Element | Document; const targetWindow = - target == null + target === null ? null : target.nodeType === 9 ? (target as Document).defaultView diff --git a/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx b/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx index f845c78b1818..c1d9a5f4a11e 100644 --- a/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/InlineImagePlugin/index.tsx @@ -324,7 +324,7 @@ function getDragSelection(event: DragEvent): Range | null | undefined { let range; const target = event.target as null | Element | Document; const targetWindow = - target == null + target === null ? null : target.nodeType === 9 ? (target as Document).defaultView diff --git a/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts b/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts index 004eb552811e..2cb11fdcb931 100644 --- a/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts +++ b/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts @@ -60,7 +60,7 @@ export const HR: ElementTransformer = { const line = $createHorizontalRuleNode(); // TODO: Get rid of isImport flag - if (isImport || parentNode.getNextSibling() != null) { + if (isImport || parentNode.getNextSibling() !== null) { parentNode.replace(line); } else { parentNode.insertBefore(line); @@ -221,7 +221,7 @@ export const TABLE: ElementTransformer = { const matchCells = mapToTableCells(match[0]); - if (matchCells == null) { + if (matchCells === null) { return; } @@ -246,7 +246,7 @@ export const TABLE: ElementTransformer = { const cells = mapToTableCells(firstChild.getTextContent()); - if (cells == null) { + if (cells === null) { break; } diff --git a/packages/lexical-playground/src/plugins/MentionsPlugin/index.tsx b/packages/lexical-playground/src/plugins/MentionsPlugin/index.tsx index faaca3496a39..4753a39f3204 100644 --- a/packages/lexical-playground/src/plugins/MentionsPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/MentionsPlugin/index.tsx @@ -508,7 +508,7 @@ function useMentionLookupService(mentionString: string | null) { useEffect(() => { const cachedResults = mentionsCache.get(mentionString); - if (mentionString == null) { + if (mentionString === null) { setResults([]); return; } diff --git a/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx b/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx index cda91323d0ab..93bcc4e3012c 100644 --- a/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx @@ -220,9 +220,9 @@ function TableActionMenu({ const rootElement = editor.getRootElement(); if ( - menuButtonElement != null && - dropDownElement != null && - rootElement != null + menuButtonElement !== null && + dropDownElement !== null && + rootElement !== null ) { const rootEleRect = rootElement.getBoundingClientRect(); const menuButtonRect = menuButtonElement.getBoundingClientRect(); @@ -252,8 +252,8 @@ function TableActionMenu({ useEffect(() => { function handleClickOutside(event: MouseEvent) { if ( - dropDownRef.current != null && - contextRef.current != null && + dropDownRef.current !== null && + contextRef.current !== null && !dropDownRef.current.contains(event.target as Node) && !contextRef.current.contains(event.target as Node) ) { @@ -661,7 +661,7 @@ function TableCellActionMenuContainer({ const nativeSelection = window.getSelection(); const activeElement = document.activeElement; - if (selection == null || menu == null) { + if (selection === null || menu === null) { setTableMenuCellNode(null); return; } @@ -678,7 +678,7 @@ function TableCellActionMenuContainer({ selection.anchor.getNode(), ); - if (tableCellNodeFromSelection == null) { + if (tableCellNodeFromSelection === null) { setTableMenuCellNode(null); return; } @@ -687,7 +687,7 @@ function TableCellActionMenuContainer({ tableCellNodeFromSelection.getKey(), ); - if (tableCellParentNodeDOM == null) { + if (tableCellParentNodeDOM === null) { setTableMenuCellNode(null); return; } @@ -709,10 +709,10 @@ function TableCellActionMenuContainer({ useEffect(() => { const menuButtonDOM = menuButtonRef.current as HTMLButtonElement | null; - if (menuButtonDOM != null && tableCellNode != null) { + if (menuButtonDOM !== null && tableCellNode !== null) { const tableCellNodeDOM = editor.getElementByKey(tableCellNode.getKey()); - if (tableCellNodeDOM != null) { + if (tableCellNodeDOM !== null) { const tableCellRect = tableCellNodeDOM.getBoundingClientRect(); const menuRect = menuButtonDOM.getBoundingClientRect(); const anchorRect = anchorElem.getBoundingClientRect(); @@ -742,7 +742,7 @@ function TableCellActionMenuContainer({ return (
- {tableCellNode != null && ( + {tableCellNode !== null && ( <>