Skip to content

Commit

Permalink
Rename types (facebook#1571)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegreatercurve authored and acywatson committed Apr 9, 2022
1 parent ff81c3d commit 6e77bda
Show file tree
Hide file tree
Showing 36 changed files with 305 additions and 273 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ There are a few ways to update an editor instance:
- Trigger an update with `editor.update()`
- Setting the editor state via `editor.setEditorState()`
- Applying a change as part of an existing update via `editor.addNodeTransform()`
- Using a command listener with `editor.registerCommandListener( () => {...}, priority)`
- Using a command listener with `editor.registerCommand( () => {...}, priority)`

The most common way to update the editor is to use `editor.update()`. Calling this function
requires a function to be passed in that will provide access to mutate the underlying
Expand Down
4 changes: 2 additions & 2 deletions examples/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function VideoPlugin(): React$Node {

useEffect(() => {
// Similar with command listener, which returns unlisten callback
const removeListener = editor.registerCommandListener(
const removeListener = editor.registerCommand(
'insertVideo',
(payload) => {
// Adding custom command that will be handled by this plugin
Expand Down Expand Up @@ -99,7 +99,7 @@ function ToolbarVideoButton(): React$Node {
const insertVideo = useCallback(
(url) => {
// Executing command defined in a plugin
editor.execCommand('insertVideo', url);
editor.dispatchCommand('insertVideo', url);
},
[editor],
);
Expand Down
8 changes: 4 additions & 4 deletions packages/lexical-code/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,22 +750,22 @@ export function registerCodeHighlighting(editor: LexicalEditor): () => void {
editor.addNodeTransform(CodeHighlightNode, (node) =>
textNodeTransform(node, editor),
),
editor.registerCommandListener(
editor.registerCommand(
'indentContent',
(payload): boolean => handleMultilineIndent('indentContent'),
1,
),
editor.registerCommandListener(
editor.registerCommand(
'outdentContent',
(payload): boolean => handleMultilineIndent('outdentContent'),
1,
),
editor.registerCommandListener(
editor.registerCommand(
'keyArrowUp',
(payload): boolean => handleShiftLines('keyArrowUp', payload),
1,
),
editor.registerCommandListener(
editor.registerCommand(
'keyArrowDown',
(payload): boolean => handleShiftLines('keyArrowDown', payload),
1,
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical-file/src/fileImportExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function importFile(editor: LexicalEditor) {
JSON.stringify(json.editorState),
);
editor.setEditorState(editorState);
editor.execCommand('clearHistory');
editor.dispatchCommand('clearHistory');
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-history/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ History package handles `undo`, `redo` and `clearHistory` commands. It also trig

```jsx
<Toolbar>
<Button onClick={() => editor.execCommand('undo')}>Undo</Button>
<Button onClick={() => editor.execCommand('redo')}>Redo</Button>
<Button onClick={() => editor.dispatchCommand('undo')}>Undo</Button>
<Button onClick={() => editor.dispatchCommand('redo')}>Redo</Button>
</Toolbar>
```
18 changes: 9 additions & 9 deletions packages/lexical-history/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ function redo(editor: LexicalEditor, historyState: HistoryState): void {
const current = historyState.current;
if (current !== null) {
undoStack.push(current);
editor.execCommand('canUndo', true);
editor.dispatchCommand('canUndo', true);
}
const historyStateEntry = redoStack.pop();
if (redoStack.length === 0) {
editor.execCommand('canRedo', false);
editor.dispatchCommand('canRedo', false);
}
historyState.current = historyStateEntry;
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
Expand All @@ -289,10 +289,10 @@ function undo(editor: LexicalEditor, historyState: HistoryState): void {
const historyStateEntry = undoStack.pop();
if (current !== null) {
redoStack.push(current);
editor.execCommand('canRedo', true);
editor.dispatchCommand('canRedo', true);
}
if (undoStack.length === 0) {
editor.execCommand('canUndo', false);
editor.dispatchCommand('canUndo', false);
}
historyState.current = historyStateEntry;
historyStateEntry.editor.setEditorState(
Expand Down Expand Up @@ -350,7 +350,7 @@ export function registerHistory(
...current,
undoSelection: prevEditorState.read($getSelection),
});
editor.execCommand('canUndo', true);
editor.dispatchCommand('canUndo', true);
}
} else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
return;
Expand All @@ -364,31 +364,31 @@ export function registerHistory(
};

const unregisterCommandListener = mergeRegister(
editor.registerCommandListener(
editor.registerCommand(
'undo',
() => {
undo(editor, historyState);
return true;
},
EditorPriority,
),
editor.registerCommandListener(
editor.registerCommand(
'redo',
() => {
redo(editor, historyState);
return true;
},
EditorPriority,
),
editor.registerCommandListener(
editor.registerCommand(
'clearEditor',
() => {
clearHistory(historyState);
return false;
},
EditorPriority,
),
editor.registerCommandListener(
editor.registerCommand(
'clearHistory',
() => {
clearHistory(historyState);
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical-markdown/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ function transformTextNodeWithLink(scanningContext: ScanningContext) {

$setSelection(newSelectionForLink);

scanningContext.editor.execCommand('toggleLink', url);
scanningContext.editor.dispatchCommand('toggleLink', url);

// Place caret at end of final capture group.
selectAfterFinalCaptureGroup(scanningContext);
Expand Down
54 changes: 27 additions & 27 deletions packages/lexical-plain-text/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function registerPlainText(
initialEditorState?: InitialEditorStateType,
): () => void {
const removeListener = mergeRegister(
editor.registerCommandListener(
editor.registerCommand(
'deleteCharacter',
(payload) => {
const selection = $getSelection();
Expand All @@ -141,7 +141,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'deleteWord',
(payload) => {
const selection = $getSelection();
Expand All @@ -154,7 +154,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'deleteLine',
(payload) => {
const selection = $getSelection();
Expand All @@ -167,7 +167,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'insertText',
(payload) => {
const selection = $getSelection();
Expand All @@ -192,7 +192,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'removeText',
(payload) => {
const selection = $getSelection();
Expand All @@ -204,7 +204,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'insertLineBreak',
(payload) => {
const selection = $getSelection();
Expand All @@ -217,7 +217,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'insertParagraph',
(payload) => {
const selection = $getSelection();
Expand All @@ -229,7 +229,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'indentContent',
(payload) => {
const selection = $getSelection();
Expand All @@ -240,7 +240,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'outdentContent',
(payload) => {
const selection = $getSelection();
Expand All @@ -251,7 +251,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'insertHorizontalRule',
(payload) => {
const selection = $getSelection();
Expand All @@ -262,7 +262,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'insertImage',
(payload) => {
const selection = $getSelection();
Expand All @@ -273,7 +273,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'insertTable',
(payload) => {
const selection = $getSelection();
Expand All @@ -284,7 +284,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'formatElement',
(payload) => {
const selection = $getSelection();
Expand All @@ -295,7 +295,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'formatText',
(payload) => {
const selection = $getSelection();
Expand All @@ -306,7 +306,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'keyArrowLeft',
(payload) => {
const selection = $getSelection();
Expand All @@ -324,7 +324,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'keyArrowRight',
(payload) => {
const selection = $getSelection();
Expand All @@ -342,7 +342,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'keyBackspace',
(payload) => {
const selection = $getSelection();
Expand All @@ -351,11 +351,11 @@ export function registerPlainText(
}
const event: KeyboardEvent = payload;
event.preventDefault();
return editor.execCommand('deleteCharacter', true);
return editor.dispatchCommand('deleteCharacter', true);
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'keyDelete',
(payload) => {
const selection = $getSelection();
Expand All @@ -364,11 +364,11 @@ export function registerPlainText(
}
const event: KeyboardEvent = payload;
event.preventDefault();
return editor.execCommand('deleteCharacter', false);
return editor.dispatchCommand('deleteCharacter', false);
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'keyEnter',
(payload) => {
const selection = $getSelection();
Expand All @@ -377,11 +377,11 @@ export function registerPlainText(
}
const event: KeyboardEvent = payload;
event.preventDefault();
return editor.execCommand('insertLineBreak');
return editor.dispatchCommand('insertLineBreak');
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'copy',
(payload) => {
const selection = $getSelection();
Expand All @@ -394,7 +394,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'cut',
(payload) => {
const selection = $getSelection();
Expand All @@ -407,7 +407,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'paste',
(payload) => {
const selection = $getSelection();
Expand All @@ -420,7 +420,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'drop',
(payload) => {
const selection = $getSelection();
Expand All @@ -434,7 +434,7 @@ export function registerPlainText(
},
0,
),
editor.registerCommandListener(
editor.registerCommand(
'dragstart',
(payload) => {
const selection = $getSelection();
Expand Down
Loading

0 comments on commit 6e77bda

Please sign in to comment.