From a69608572705e438ad9120b5a3930354fec862be Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Tue, 30 Aug 2022 15:07:56 +0100 Subject: [PATCH 1/3] Remove read only mode API, make dit mode --- .../src/plugins/ActionsPlugin/index.tsx | 20 +++++----- .../src/LexicalCheckListPlugin.tsx | 4 +- .../lexical-react/src/LexicalComposer.tsx | 8 ++-- .../src/LexicalContentEditable.tsx | 23 ++++++----- .../src/shared/useCanShowPlaceholder.ts | 4 +- packages/lexical-text/src/index.ts | 8 ++-- .../concepts/{read-only.md => editable.md} | 20 +++++----- .../docs/concepts/listeners.md | 16 ++++---- packages/lexical/flow/Lexical.js.flow | 12 +++--- packages/lexical/src/LexicalEditor.ts | 38 +++++++++---------- packages/lexical/src/LexicalEvents.ts | 4 +- packages/lexical/src/LexicalUpdates.ts | 4 +- .../src/__tests__/unit/LexicalEditor.test.tsx | 30 +++++++-------- packages/lexical/src/index.ts | 2 +- 14 files changed, 96 insertions(+), 97 deletions(-) rename packages/lexical-website/docs/concepts/{read-only.md => editable.md} (74%) diff --git a/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx b/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx index b7bc4c4c11d..ac0b3863829 100644 --- a/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ActionsPlugin/index.tsx @@ -80,7 +80,7 @@ export default function ActionsPlugin({ isRichText: boolean; }): JSX.Element { const [editor] = useLexicalComposerContext(); - const [isReadOnly, setIsReadOnly] = useState(() => editor.isReadOnly()); + const [isEditable, setIsEditable] = useState(() => editor.isEditable()); const [isSpeechToText, setIsSpeechToText] = useState(false); const [connected, setConnected] = useState(false); const [isEditorEmpty, setIsEditorEmpty] = useState(true); @@ -89,8 +89,8 @@ export default function ActionsPlugin({ useEffect(() => { return mergeRegister( - editor.registerReadOnlyListener((readOnly) => { - setIsReadOnly(readOnly); + editor.registerEditableListener((editable) => { + setIsEditable(editable); }), editor.registerCommand( CONNECTED_COMMAND, @@ -110,7 +110,7 @@ export default function ActionsPlugin({ // If we are in read only mode, send the editor state // to server and ask for validation if possible. if ( - isReadOnly && + !isEditable && dirtyElements.size > 0 && !tags.has('historic') && !tags.has('collaboration') @@ -134,7 +134,7 @@ export default function ActionsPlugin({ }); }, ); - }, [editor, isReadOnly]); + }, [editor, isEditable]); const handleMarkdownToggle = useCallback(() => { editor.update(() => { @@ -208,17 +208,17 @@ export default function ActionsPlugin({