Skip to content

Commit

Permalink
npm run lint -- --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Apr 27, 2024
1 parent f309cc3 commit 095502e
Show file tree
Hide file tree
Showing 79 changed files with 438 additions and 382 deletions.
4 changes: 2 additions & 2 deletions examples/vanilla-js-plugin/src/emoji-plugin/EmojiPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion examples/vanilla-js-plugin/src/prepopulatedRichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/vanilla-js/src/prepopulatedRichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 20 additions & 20 deletions packages/lexical-code/src/CodeHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function getEndOfCodeInLine(
return lastNode;
}

function textNodeTransform(
function $textNodeTransform(
node: TextNode,
editor: LexicalEditor,
tokenizer: Tokenizer,
Expand Down Expand Up @@ -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()) {
Expand All @@ -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,
Expand All @@ -311,7 +311,7 @@ function codeNodeTransform(
);
}

function getHighlightNodes(
function $getHighlightNodes(
tokens: Array<string | Token>,
type?: string,
): LexicalNode[] {
Expand All @@ -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));
}
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -510,7 +510,7 @@ function $getCodeLines(
return lines;
}

function handleTab(shiftKey: boolean): null | LexicalCommand<void> {
function $handleTab(shiftKey: boolean): null | LexicalCommand<void> {
const selection = $getSelection();
if (!$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
return null;
Expand Down Expand Up @@ -564,7 +564,7 @@ function handleTab(shiftKey: boolean): null | LexicalCommand<void> {
return tabOrOutdent;
}

function handleMultilineIndent(type: LexicalCommand<void>): boolean {
function $handleMultilineIndent(type: LexicalCommand<void>): boolean {
const selection = $getSelection();
if (!$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
return false;
Expand Down Expand Up @@ -627,7 +627,7 @@ function handleMultilineIndent(type: LexicalCommand<void>): boolean {
return true;
}

function handleShiftLines(
function $handleShiftLines(
type: LexicalCommand<KeyboardEvent>,
event: KeyboardEvent,
): boolean {
Expand Down Expand Up @@ -759,7 +759,7 @@ function handleShiftLines(
return true;
}

function handleMoveTo(
function $handleMoveTo(
type: LexicalCommand<KeyboardEvent>,
event: KeyboardEvent,
): boolean {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
),
);
Expand Down
14 changes: 7 additions & 7 deletions packages/lexical-code/src/CodeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,25 @@ 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) => {
const table = node;
// domNode is a <table> since we matched it by nodeName
if (isGitHubCodeTable(table as HTMLTableElement)) {
return {
conversion: convertTableElement,
conversion: $convertTableElement,
priority: 3,
};
}
Expand Down Expand Up @@ -330,15 +330,15 @@ 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);
}
return {node: $createCodeNode(language)};
}

function convertDivElement(domNode: Node): DOMConversionOutput {
function $convertDivElement(domNode: Node): DOMConversionOutput {
// domNode is a <div> since we matched it by nodeName
const div = domNode as HTMLDivElement;
const isCode = isCodeElement(div);
Expand All @@ -359,7 +359,7 @@ function convertDivElement(domNode: Node): DOMConversionOutput {
};
}

function convertTableElement(): DOMConversionOutput {
function $convertTableElement(): DOMConversionOutput {
return {node: $createCodeNode()};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-devtools-core/src/generateContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function generateContent(
' ',
)} ${nodeKeyDisplay} ${typeDisplay} ${idsDisplay} ${printNode(node)}\n`;

res += printSelectedCharsLine({
res += $printSelectedCharsLine({
indent,
isSelected,
node,
Expand Down Expand Up @@ -364,7 +364,7 @@ function printTitleProperties(node: LinkNode) {
return str;
}

function printSelectedCharsLine({
function $printSelectedCharsLine({
indent,
isSelected,
node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
});
});
Expand Down Expand Up @@ -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);
});
});
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('LexicalHistory tests', () => {
});
});

const createParagraphNode = (text: string) => {
const $createParagraphNode_ = (text: string) => {
const paragraph = $createParagraphNode();
const textNode = $createTextNode(text);

Expand Down
8 changes: 5 additions & 3 deletions packages/lexical-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class LinkNode extends ElementNode {
static importDOM(): DOMConversionMap | null {
return {
a: (node: Node) => ({
conversion: convertAnchorElement,
conversion: $convertAnchorElement,
priority: 1,
}),
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -523,6 +523,8 @@ export function toggleLink(
});
}
}
/** @deprecated renamed to $toggleLink by @lexical/eslint-plugin rules-of-lexical */
export const toggleLink = $toggleLink;

function $getAncestor<NodeType extends LexicalNode = LexicalNode>(
node: LexicalNode,
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-list/src/LexicalListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class ListItemNode extends ElementNode {
static importDOM(): DOMConversionMap | null {
return {
li: (node: Node) => ({
conversion: convertListItemElement,
conversion: $convertListItemElement,
priority: 0,
}),
};
Expand Down Expand Up @@ -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)};
Expand Down
Loading

0 comments on commit 095502e

Please sign in to comment.