From 04ecbb45c5137156ba8b59d688601a12c275d2c4 Mon Sep 17 00:00:00 2001 From: Dalton Date: Thu, 16 May 2024 11:49:18 -1000 Subject: [PATCH 1/5] [lexical-playground][lexical-react][lexical] Feature: Theme class added to horizontal rule node (#6090) --- .../html/HTMLCopyAndPaste.spec.mjs | 25 +++++++-- .../html/ListsHTMLCopyAndPaste.spec.mjs | 5 +- .../__tests__/e2e/HorizontalRule.spec.mjs | 51 ++++++++++++++----- .../__tests__/e2e/Markdown.spec.mjs | 24 ++++++--- .../__tests__/e2e/Selection.spec.mjs | 2 +- packages/lexical-playground/src/index.css | 20 -------- .../src/themes/PlaygroundEditorTheme.css | 17 +++++++ .../src/themes/PlaygroundEditorTheme.ts | 1 + .../src/LexicalHorizontalRuleNode.tsx | 21 ++++++-- packages/lexical/src/LexicalEditor.ts | 1 + 10 files changed, 118 insertions(+), 49 deletions(-) diff --git a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/HTMLCopyAndPaste.spec.mjs b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/HTMLCopyAndPaste.spec.mjs index cb0a9bed93a..e2543ec0e1e 100644 --- a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/HTMLCopyAndPaste.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/HTMLCopyAndPaste.spec.mjs @@ -208,8 +208,14 @@ test.describe('HTML CopyAndPaste', () => { await assertHTML( page, html` -
-
+
+
{ await assertHTML( page, html` -
+

Text between HRs

-
+
`, ); await assertSelection(page, { @@ -266,7 +278,10 @@ test.describe('HTML CopyAndPaste', () => { dir="ltr"> Hello

-
+

diff --git a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/ListsHTMLCopyAndPaste.spec.mjs b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/ListsHTMLCopyAndPaste.spec.mjs index dbb58e82d3c..34cf35623ab 100644 --- a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/ListsHTMLCopyAndPaste.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/ListsHTMLCopyAndPaste.spec.mjs @@ -391,7 +391,10 @@ test.describe('HTML Lists CopyAndPaste', () => { one -


+
{showTreeView && } diff --git a/packages/lexical-playground/src/Settings.tsx b/packages/lexical-playground/src/Settings.tsx index abfd6005c0e..a8e622dc6b0 100644 --- a/packages/lexical-playground/src/Settings.tsx +++ b/packages/lexical-playground/src/Settings.tsx @@ -30,6 +30,7 @@ export default function Settings(): JSX.Element { disableBeforeInput, showTableOfContents, shouldUseLexicalContextMenu, + shouldPreserveNewLinesInMarkdown, }, } = useSettings(); useEffect(() => { @@ -150,6 +151,16 @@ export default function Settings(): JSX.Element { checked={shouldUseLexicalContextMenu} text="Use Lexical Context Menu" /> + { + setOption( + 'shouldPreserveNewLinesInMarkdown', + !shouldPreserveNewLinesInMarkdown, + ); + }} + checked={shouldPreserveNewLinesInMarkdown} + text="Preserve newlines in Markdown" + /> ) : null} diff --git a/packages/lexical-playground/src/appSettings.ts b/packages/lexical-playground/src/appSettings.ts index 97a34db486f..61892c2946e 100644 --- a/packages/lexical-playground/src/appSettings.ts +++ b/packages/lexical-playground/src/appSettings.ts @@ -21,6 +21,7 @@ export const DEFAULT_SETTINGS = { isMaxLength: false, isRichText: true, measureTypingPerf: false, + shouldPreserveNewLinesInMarkdown: false, shouldUseLexicalContextMenu: false, showNestedEditorTreeView: false, showTableOfContents: false, diff --git a/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx b/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx index 9b06dd8f25c..5fee067b33c 100644 --- a/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx @@ -93,8 +93,10 @@ async function shareDoc(doc: SerializedDocument): Promise { export default function ActionsPlugin({ isRichText, + shouldPreserveNewLinesInMarkdown, }: { isRichText: boolean; + shouldPreserveNewLinesInMarkdown: boolean; }): JSX.Element { const [editor] = useLexicalComposerContext(); const [isEditable, setIsEditable] = useState(() => editor.isEditable()); @@ -172,9 +174,15 @@ export default function ActionsPlugin({ $convertFromMarkdownString( firstChild.getTextContent(), PLAYGROUND_TRANSFORMERS, + undefined, // node + shouldPreserveNewLinesInMarkdown, ); } else { - const markdown = $convertToMarkdownString(PLAYGROUND_TRANSFORMERS); + const markdown = $convertToMarkdownString( + PLAYGROUND_TRANSFORMERS, + undefined, //node + shouldPreserveNewLinesInMarkdown, + ); root .clear() .append( @@ -183,7 +191,7 @@ export default function ActionsPlugin({ } root.selectEnd(); }); - }, [editor]); + }, [editor, shouldPreserveNewLinesInMarkdown]); return (
From d65d142cf299514aa2d73e68be4e1ae74dba3546 Mon Sep 17 00:00:00 2001 From: Sahejkm <163521239+Sahejkm@users.noreply.github.com> Date: Fri, 17 May 2024 14:12:14 +0800 Subject: [PATCH 3/5] [Lexical] Replace code with key to check KeyboardEvents (#6110) --- .../src/plugins/TestRecorderPlugin/index.tsx | 5 +- .../src/plugins/TypingPerfPlugin/index.ts | 4 +- .../src/__tests__/utils/index.ts | 4 +- packages/lexical/src/LexicalEvents.ts | 64 ++++---- packages/lexical/src/LexicalUtils.ts | 147 ++++++++++-------- 5 files changed, 118 insertions(+), 106 deletions(-) diff --git a/packages/lexical-playground/src/plugins/TestRecorderPlugin/index.tsx b/packages/lexical-playground/src/plugins/TestRecorderPlugin/index.tsx index 3af7e33d67a..838568397f3 100644 --- a/packages/lexical-playground/src/plugins/TestRecorderPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/TestRecorderPlugin/index.tsx @@ -95,7 +95,10 @@ const formatStep = (step: Step) => { }; export function isSelectAll(event: KeyboardEvent): boolean { - return event.code === 'KeyA' && (IS_APPLE ? event.metaKey : event.ctrlKey); + return ( + event.key.toLowerCase() === 'a' && + (IS_APPLE ? event.metaKey : event.ctrlKey) + ); } // stolen from LexicalSelection-test diff --git a/packages/lexical-playground/src/plugins/TypingPerfPlugin/index.ts b/packages/lexical-playground/src/plugins/TypingPerfPlugin/index.ts index 01780f7a7ff..535a9dd1bb4 100644 --- a/packages/lexical-playground/src/plugins/TypingPerfPlugin/index.ts +++ b/packages/lexical-playground/src/plugins/TypingPerfPlugin/index.ts @@ -83,9 +83,9 @@ export default function TypingPerfPlugin(): JSX.Element | null { }; const keyDownHandler = function keyDownHandler(event: KeyboardEvent) { - const keyCode = event.code; + const key = event.key; - if (keyCode === 'Backspace' || keyCode === 'Enter') { + if (key === 'Backspace' || key === 'Enter') { measureEventStart(); } }; diff --git a/packages/lexical-selection/src/__tests__/utils/index.ts b/packages/lexical-selection/src/__tests__/utils/index.ts index 648c533c09a..b8317d56b3e 100644 --- a/packages/lexical-selection/src/__tests__/utils/index.ts +++ b/packages/lexical-selection/src/__tests__/utils/index.ts @@ -781,8 +781,8 @@ export async function applySelectionInputs( new KeyboardEvent('keydown', { bubbles: true, cancelable: true, - code: 'KeyZ', ctrlKey: true, + key: 'z', keyCode: 90, }), ); @@ -794,8 +794,8 @@ export async function applySelectionInputs( new KeyboardEvent('keydown', { bubbles: true, cancelable: true, - code: 'KeyZ', ctrlKey: true, + key: 'z', keyCode: 90, shiftKey: true, }), diff --git a/packages/lexical/src/LexicalEvents.ts b/packages/lexical/src/LexicalEvents.ts index 0216eb8d5b2..e81ce0a5124 100644 --- a/packages/lexical/src/LexicalEvents.ts +++ b/packages/lexical/src/LexicalEvents.ts @@ -516,7 +516,7 @@ function $canRemoveText( function isPossiblyAndroidKeyPress(timeStamp: number): boolean { return ( - lastKeyCode === 'Delete' && + lastKeyCode === 'MediaLast' && timeStamp < lastKeyDownTimeStamp + ANDROID_COMPOSITION_LATENCY ); } @@ -994,101 +994,101 @@ function onCompositionEnd( function onKeyDown(event: KeyboardEvent, editor: LexicalEditor): void { lastKeyDownTimeStamp = event.timeStamp; - lastKeyCode = event.code; + lastKeyCode = event.key; if (editor.isComposing()) { return; } - const {code, shiftKey, ctrlKey, metaKey, altKey} = event; + const {key, shiftKey, ctrlKey, metaKey, altKey} = event; if (dispatchCommand(editor, KEY_DOWN_COMMAND, event)) { return; } - if (isMoveForward(code, ctrlKey, altKey, metaKey)) { + if (isMoveForward(key, ctrlKey, altKey, metaKey)) { dispatchCommand(editor, KEY_ARROW_RIGHT_COMMAND, event); - } else if (isMoveToEnd(code, ctrlKey, shiftKey, altKey, metaKey)) { + } else if (isMoveToEnd(key, ctrlKey, shiftKey, altKey, metaKey)) { dispatchCommand(editor, MOVE_TO_END, event); - } else if (isMoveBackward(code, ctrlKey, altKey, metaKey)) { + } else if (isMoveBackward(key, ctrlKey, altKey, metaKey)) { dispatchCommand(editor, KEY_ARROW_LEFT_COMMAND, event); - } else if (isMoveToStart(code, ctrlKey, shiftKey, altKey, metaKey)) { + } else if (isMoveToStart(key, ctrlKey, shiftKey, altKey, metaKey)) { dispatchCommand(editor, MOVE_TO_START, event); - } else if (isMoveUp(code, ctrlKey, metaKey)) { + } else if (isMoveUp(key, ctrlKey, metaKey)) { dispatchCommand(editor, KEY_ARROW_UP_COMMAND, event); - } else if (isMoveDown(code, ctrlKey, metaKey)) { + } else if (isMoveDown(key, ctrlKey, metaKey)) { dispatchCommand(editor, KEY_ARROW_DOWN_COMMAND, event); - } else if (isLineBreak(code, shiftKey)) { + } else if (isLineBreak(key, shiftKey)) { isInsertLineBreak = true; dispatchCommand(editor, KEY_ENTER_COMMAND, event); - } else if (isSpace(code)) { + } else if (isSpace(key)) { dispatchCommand(editor, KEY_SPACE_COMMAND, event); - } else if (isOpenLineBreak(code, ctrlKey)) { + } else if (isOpenLineBreak(key, ctrlKey)) { event.preventDefault(); isInsertLineBreak = true; dispatchCommand(editor, INSERT_LINE_BREAK_COMMAND, true); - } else if (isParagraph(code, shiftKey)) { + } else if (isParagraph(key, shiftKey)) { isInsertLineBreak = false; dispatchCommand(editor, KEY_ENTER_COMMAND, event); - } else if (isDeleteBackward(code, altKey, metaKey, ctrlKey)) { - if (isBackspace(code)) { + } else if (isDeleteBackward(key, altKey, metaKey, ctrlKey)) { + if (isBackspace(key)) { dispatchCommand(editor, KEY_BACKSPACE_COMMAND, event); } else { event.preventDefault(); dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true); } - } else if (isEscape(code)) { + } else if (isEscape(key)) { dispatchCommand(editor, KEY_ESCAPE_COMMAND, event); - } else if (isDeleteForward(code, ctrlKey, shiftKey, altKey, metaKey)) { - if (isDelete(code)) { + } else if (isDeleteForward(key, ctrlKey, shiftKey, altKey, metaKey)) { + if (isDelete(key)) { dispatchCommand(editor, KEY_DELETE_COMMAND, event); } else { event.preventDefault(); dispatchCommand(editor, DELETE_CHARACTER_COMMAND, false); } - } else if (isDeleteWordBackward(code, altKey, ctrlKey)) { + } else if (isDeleteWordBackward(key, altKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, DELETE_WORD_COMMAND, true); - } else if (isDeleteWordForward(code, altKey, ctrlKey)) { + } else if (isDeleteWordForward(key, altKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, DELETE_WORD_COMMAND, false); - } else if (isDeleteLineBackward(code, metaKey)) { + } else if (isDeleteLineBackward(key, metaKey)) { event.preventDefault(); dispatchCommand(editor, DELETE_LINE_COMMAND, true); - } else if (isDeleteLineForward(code, metaKey)) { + } else if (isDeleteLineForward(key, metaKey)) { event.preventDefault(); dispatchCommand(editor, DELETE_LINE_COMMAND, false); - } else if (isBold(code, altKey, metaKey, ctrlKey)) { + } else if (isBold(key, altKey, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'bold'); - } else if (isUnderline(code, altKey, metaKey, ctrlKey)) { + } else if (isUnderline(key, altKey, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'underline'); - } else if (isItalic(code, altKey, metaKey, ctrlKey)) { + } else if (isItalic(key, altKey, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'italic'); - } else if (isTab(code, altKey, ctrlKey, metaKey)) { + } else if (isTab(key, altKey, ctrlKey, metaKey)) { dispatchCommand(editor, KEY_TAB_COMMAND, event); - } else if (isUndo(code, shiftKey, metaKey, ctrlKey)) { + } else if (isUndo(key, shiftKey, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, UNDO_COMMAND, undefined); - } else if (isRedo(code, shiftKey, metaKey, ctrlKey)) { + } else if (isRedo(key, shiftKey, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, REDO_COMMAND, undefined); } else { const prevSelection = editor._editorState._selection; if ($isNodeSelection(prevSelection)) { - if (isCopy(code, shiftKey, metaKey, ctrlKey)) { + if (isCopy(key, shiftKey, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, COPY_COMMAND, event); - } else if (isCut(code, shiftKey, metaKey, ctrlKey)) { + } else if (isCut(key, shiftKey, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, CUT_COMMAND, event); - } else if (isSelectAll(code, metaKey, ctrlKey)) { + } else if (isSelectAll(key, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, SELECT_ALL_COMMAND, event); } // FF does it well (no need to override behavior) - } else if (!IS_FIREFOX && isSelectAll(code, metaKey, ctrlKey)) { + } else if (!IS_FIREFOX && isSelectAll(key, metaKey, ctrlKey)) { event.preventDefault(); dispatchCommand(editor, SELECT_ALL_COMMAND, event); } diff --git a/packages/lexical/src/LexicalUtils.ts b/packages/lexical/src/LexicalUtils.ts index 7fb995868f7..52c5b81ea41 100644 --- a/packages/lexical/src/LexicalUtils.ts +++ b/packages/lexical/src/LexicalUtils.ts @@ -763,82 +763,88 @@ export function $shouldInsertTextAfterOrBeforeTextNode( } export function isTab( - code: string, + key: string, altKey: boolean, ctrlKey: boolean, metaKey: boolean, ): boolean { - return code === 'Tab' && !altKey && !ctrlKey && !metaKey; + return key === 'Tab' && !altKey && !ctrlKey && !metaKey; } export function isBold( - code: string, + key: string, altKey: boolean, metaKey: boolean, ctrlKey: boolean, ): boolean { - return code === 'KeyB' && !altKey && controlOrMeta(metaKey, ctrlKey); + return ( + key.toLowerCase() === 'b' && !altKey && controlOrMeta(metaKey, ctrlKey) + ); } export function isItalic( - code: string, + key: string, altKey: boolean, metaKey: boolean, ctrlKey: boolean, ): boolean { - return code === 'KeyI' && !altKey && controlOrMeta(metaKey, ctrlKey); + return ( + key.toLowerCase() === 'i' && !altKey && controlOrMeta(metaKey, ctrlKey) + ); } export function isUnderline( - code: string, + key: string, altKey: boolean, metaKey: boolean, ctrlKey: boolean, ): boolean { - return code === 'KeyU' && !altKey && controlOrMeta(metaKey, ctrlKey); + return ( + key.toLowerCase() === 'u' && !altKey && controlOrMeta(metaKey, ctrlKey) + ); } -export function isParagraph(code: string, shiftKey: boolean): boolean { - return isReturn(code) && !shiftKey; +export function isParagraph(key: string, shiftKey: boolean): boolean { + return isReturn(key) && !shiftKey; } -export function isLineBreak(keyCode: string, shiftKey: boolean): boolean { - return isReturn(keyCode) && shiftKey; +export function isLineBreak(key: string, shiftKey: boolean): boolean { + return isReturn(key) && shiftKey; } // Inserts a new line after the selection -export function isOpenLineBreak(code: string, ctrlKey: boolean): boolean { +export function isOpenLineBreak(key: string, ctrlKey: boolean): boolean { // 79 = KeyO - return IS_APPLE && ctrlKey && code === 'KeyO'; + return IS_APPLE && ctrlKey && key.toLowerCase() === 'o'; } export function isDeleteWordBackward( - code: string, + key: string, altKey: boolean, ctrlKey: boolean, ): boolean { - return isBackspace(code) && (IS_APPLE ? altKey : ctrlKey); + return isBackspace(key) && (IS_APPLE ? altKey : ctrlKey); } export function isDeleteWordForward( - code: string, + key: string, altKey: boolean, ctrlKey: boolean, ): boolean { - return isDelete(code) && (IS_APPLE ? altKey : ctrlKey); + return isDelete(key) && (IS_APPLE ? altKey : ctrlKey); } -export function isDeleteLineBackward(code: string, metaKey: boolean): boolean { - return IS_APPLE && metaKey && isBackspace(code); +export function isDeleteLineBackward(key: string, metaKey: boolean): boolean { + return IS_APPLE && metaKey && isBackspace(key); } -export function isDeleteLineForward(code: string, metaKey: boolean): boolean { - return IS_APPLE && metaKey && isDelete(code); +export function isDeleteLineForward(key: string, metaKey: boolean): boolean { + return IS_APPLE && metaKey && isDelete(key); } export function isDeleteBackward( - code: string, + key: string, altKey: boolean, metaKey: boolean, ctrlKey: boolean, @@ -847,16 +853,16 @@ export function isDeleteBackward( if (altKey || metaKey) { return false; } - return isBackspace(code) || (code === 'KeyH' && ctrlKey); + return isBackspace(key) || (key.toLowerCase() === 'h' && ctrlKey); } if (ctrlKey || altKey || metaKey) { return false; } - return isBackspace(code); + return isBackspace(key); } export function isDeleteForward( - code: string, + key: string, ctrlKey: boolean, shiftKey: boolean, altKey: boolean, @@ -866,39 +872,42 @@ export function isDeleteForward( if (shiftKey || altKey || metaKey) { return false; } - return isDelete(code) || (code === 'KeyD' && ctrlKey); + return isDelete(key) || (key.toLowerCase() === 'd' && ctrlKey); } if (ctrlKey || altKey || metaKey) { return false; } - return isDelete(code); + return isDelete(key); } export function isUndo( - code: string, + key: string, shiftKey: boolean, metaKey: boolean, ctrlKey: boolean, ): boolean { - return code === 'KeyZ' && !shiftKey && controlOrMeta(metaKey, ctrlKey); + return ( + key.toLowerCase() === 'z' && !shiftKey && controlOrMeta(metaKey, ctrlKey) + ); } export function isRedo( - code: string, + key: string, shiftKey: boolean, metaKey: boolean, ctrlKey: boolean, ): boolean { if (IS_APPLE) { - return code === 'KeyZ' && metaKey && shiftKey; + return key.toLowerCase() === 'z' && metaKey && shiftKey; } return ( - (code === 'KeyY' && ctrlKey) || (code === 'KeyZ' && ctrlKey && shiftKey) + (key.toLowerCase() === 'y' && ctrlKey) || + (key.toLowerCase() === 'z' && ctrlKey && shiftKey) ); } export function isCopy( - code: string, + key: string, shiftKey: boolean, metaKey: boolean, ctrlKey: boolean, @@ -906,7 +915,7 @@ export function isCopy( if (shiftKey) { return false; } - if (code === 'KeyC') { + if (key.toLowerCase() === 'c') { return IS_APPLE ? metaKey : ctrlKey; } @@ -914,7 +923,7 @@ export function isCopy( } export function isCut( - code: string, + key: string, shiftKey: boolean, metaKey: boolean, ctrlKey: boolean, @@ -922,81 +931,81 @@ export function isCut( if (shiftKey) { return false; } - if (code === 'KeyX') { + if (key.toLowerCase() === 'x') { return IS_APPLE ? metaKey : ctrlKey; } return false; } -function isArrowLeft(code: string): boolean { - return code === 'ArrowLeft'; +function isArrowLeft(key: string): boolean { + return key === 'ArrowLeft'; } -function isArrowRight(code: string): boolean { - return code === 'ArrowRight'; +function isArrowRight(key: string): boolean { + return key === 'ArrowRight'; } -function isArrowUp(code: string): boolean { - return code === 'ArrowUp'; +function isArrowUp(key: string): boolean { + return key === 'ArrowUp'; } -function isArrowDown(code: string): boolean { - return code === 'ArrowDown'; +function isArrowDown(key: string): boolean { + return key === 'ArrowDown'; } export function isMoveBackward( - code: string, + key: string, ctrlKey: boolean, altKey: boolean, metaKey: boolean, ): boolean { - return isArrowLeft(code) && !ctrlKey && !metaKey && !altKey; + return isArrowLeft(key) && !ctrlKey && !metaKey && !altKey; } export function isMoveToStart( - code: string, + key: string, ctrlKey: boolean, shiftKey: boolean, altKey: boolean, metaKey: boolean, ): boolean { - return isArrowLeft(code) && !altKey && !shiftKey && (ctrlKey || metaKey); + return isArrowLeft(key) && !altKey && !shiftKey && (ctrlKey || metaKey); } export function isMoveForward( - code: string, + key: string, ctrlKey: boolean, altKey: boolean, metaKey: boolean, ): boolean { - return isArrowRight(code) && !ctrlKey && !metaKey && !altKey; + return isArrowRight(key) && !ctrlKey && !metaKey && !altKey; } export function isMoveToEnd( - code: string, + key: string, ctrlKey: boolean, shiftKey: boolean, altKey: boolean, metaKey: boolean, ): boolean { - return isArrowRight(code) && !altKey && !shiftKey && (ctrlKey || metaKey); + return isArrowRight(key) && !altKey && !shiftKey && (ctrlKey || metaKey); } export function isMoveUp( - code: string, + key: string, ctrlKey: boolean, metaKey: boolean, ): boolean { - return isArrowUp(code) && !ctrlKey && !metaKey; + return isArrowUp(key) && !ctrlKey && !metaKey; } export function isMoveDown( - code: string, + key: string, ctrlKey: boolean, metaKey: boolean, ): boolean { - return isArrowDown(code) && !ctrlKey && !metaKey; + return isArrowDown(key) && !ctrlKey && !metaKey; } export function isModifier( @@ -1008,8 +1017,8 @@ export function isModifier( return ctrlKey || shiftKey || altKey || metaKey; } -export function isSpace(code: string): boolean { - return code === 'Space'; +export function isSpace(key: string): boolean { + return key === ' '; } export function controlOrMeta(metaKey: boolean, ctrlKey: boolean): boolean { @@ -1019,28 +1028,28 @@ export function controlOrMeta(metaKey: boolean, ctrlKey: boolean): boolean { return ctrlKey; } -export function isReturn(code: string): boolean { - return code === 'Enter'; +export function isReturn(key: string): boolean { + return key === 'Enter'; } -export function isBackspace(code: string): boolean { - return code === 'Backspace'; +export function isBackspace(key: string): boolean { + return key === 'Backspace'; } -export function isEscape(code: string): boolean { - return code === 'Escape'; +export function isEscape(key: string): boolean { + return key === 'Escape'; } -export function isDelete(code: string): boolean { - return code === 'Delete'; +export function isDelete(key: string): boolean { + return key === 'Delete'; } export function isSelectAll( - code: string, + key: string, metaKey: boolean, ctrlKey: boolean, ): boolean { - return code === 'KeyA' && controlOrMeta(metaKey, ctrlKey); + return key.toLowerCase() === 'a' && controlOrMeta(metaKey, ctrlKey); } export function $selectAll(): void { From 68f05923e0e55128787fd2f29c35f7ce507c08a9 Mon Sep 17 00:00:00 2001 From: Sahejkm <163521239+Sahejkm@users.noreply.github.com> Date: Sat, 18 May 2024 00:45:10 +0800 Subject: [PATCH 4/5] [Lexical] Add flow for eslint (#6127) --- .../flow/LexicalEslintPlugin.js.flow | 1 + scripts/update-flowconfig.js | 20 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/packages/lexical-eslint-plugin/flow/LexicalEslintPlugin.js.flow b/packages/lexical-eslint-plugin/flow/LexicalEslintPlugin.js.flow index 3b23ff98ce6..55f418a0d83 100644 --- a/packages/lexical-eslint-plugin/flow/LexicalEslintPlugin.js.flow +++ b/packages/lexical-eslint-plugin/flow/LexicalEslintPlugin.js.flow @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict */ /** diff --git a/scripts/update-flowconfig.js b/scripts/update-flowconfig.js index be35f36d393..81c82d4c6c6 100644 --- a/scripts/update-flowconfig.js +++ b/scripts/update-flowconfig.js @@ -23,7 +23,7 @@ const BLOCK_REGEX = function flowTemplate(wwwName) { return ( - headerTemplate.replace(/^( \*\/)$/m, '* @flow strict\n$1') + + headerTemplate.replace(/^( \*\/)$/m, ' * @flow strict\n$1') + ` /** * ${wwwName} @@ -59,22 +59,7 @@ function updateFlowconfig(flowconfigPath = './.flowconfig') { const resolveRelative = (...subPaths) => '/' + path.relative(configDir, pkg.resolve(...subPaths)).replace(/^(?!\.)/, ''); - if (pkg.isPrivate()) { - if (pkg.getDirectoryName() !== 'shared') { - continue; - } - if (process.env.TODO_DOES_WWW_NEED_SHARED_FILES === '1') { - // Do these even work? These .js files aren't on disk and `npm run flow` - // passes without them. Code is left in for demonstration purposes if - // this is needed for www. - for (const {name, sourceFileName} of pkg.getPrivateModuleEntries()) { - emit( - name, - resolveRelative('src', sourceFileName.replace(/\.tsx?$/, '.js')), - ); - } - } - } else { + if (!pkg.isPrivate()) { for (const name of pkg.getExportedNpmModuleNames()) { const wwwName = npmToWwwName(name); const flowFile = `${wwwName}.js.flow`; @@ -85,6 +70,7 @@ function updateFlowconfig(flowconfigPath = './.flowconfig') { console.log( `Creating boilerplate ${resolvedFlowFile.replace(/^[^/]+\//, '')}`, ); + fs.mkdirsSync(path.dirname(flowFilePath)); fs.writeFileSync(flowFilePath, flowTemplate(wwwName)); } } From c1f041649f6c8815fd57c127e1e622d330038492 Mon Sep 17 00:00:00 2001 From: Vlad Fedosov Date: Fri, 17 May 2024 17:44:57 -0400 Subject: [PATCH 5/5] fix(lexical): #6132 react build size regression from #6088 (#6133) --- scripts/build.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 18a8c5681c9..41b8d0ffed6 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -94,13 +94,11 @@ function resolveExternalEsm(id) { * party dependencies or peerDependencies that we do not want to include * in the bundles. */ -const externals = [ - ...Object.entries(wwwMappings).flat(), - 'react-dom', - 'react', - 'yjs', - 'y-websocket', -].sort(); +const monorepoExternalsSet = new Set(Object.entries(wwwMappings).flat()); +const thirdPartyExternals = ['react', 'react-dom', 'yjs', 'y-websocket']; +const thirdPartyExternalsRegExp = new RegExp( + `^(${thirdPartyExternals.join('|')})(\\/|$)`, +); const strictWWWMappings = {}; @@ -131,7 +129,10 @@ async function build(name, inputFile, outputPath, outputFile, isProd, format) { const extensions = ['.js', '.jsx', '.ts', '.tsx']; const inputOptions = { external(modulePath, src) { - return externals.includes(modulePath); + return ( + monorepoExternalsSet.has(modulePath) || + thirdPartyExternalsRegExp.test(modulePath) + ); }, input: inputFile, onwarn(warning) {