Skip to content

Commit

Permalink
[*] Chore: Fix all new lint warnings, plus manual exports clean-up (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed May 10, 2024
1 parent b5fa87d commit 081188c
Show file tree
Hide file tree
Showing 95 changed files with 557 additions and 626 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = {
// @lexical/yjs
'createBinding',
],
isLexicalProvider: ['updateEditor'],
isSafeDollarFunction: '$createRootNode',
}),
],
Expand Down
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
80 changes: 0 additions & 80 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -324,15 +324,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 @@ -346,7 +346,7 @@ function convertDivElement(domNode: Node): DOMConversionOutput {
};
}

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

Expand Down
Loading

0 comments on commit 081188c

Please sign in to comment.