|
1 | | -import { |
2 | | - $createParagraphNode, |
3 | | - $getRoot, |
4 | | - $getSelection, |
5 | | - COMMAND_PRIORITY_LOW, |
6 | | - createCommand, |
7 | | - createEditor, CreateEditorArgs, |
8 | | -} from 'lexical'; |
| 1 | +import {$getRoot, createEditor, CreateEditorArgs} from 'lexical'; |
9 | 2 | import {createEmptyHistoryState, registerHistory} from '@lexical/history'; |
10 | 3 | import {registerRichText} from '@lexical/rich-text'; |
11 | | -import {$getNearestBlockElementAncestorOrThrow, mergeRegister} from '@lexical/utils'; |
| 4 | +import {mergeRegister} from '@lexical/utils'; |
12 | 5 | import {$generateNodesFromDOM} from '@lexical/html'; |
13 | | -import {$setBlocksType} from '@lexical/selection'; |
14 | 6 | import {getNodesForPageEditor} from './nodes'; |
15 | | -import {$createCalloutNode, $isCalloutNode, CalloutCategory} from './nodes/callout'; |
| 7 | +import {buildEditorUI} from "./ui"; |
16 | 8 |
|
17 | 9 | export function createPageEditorInstance(editArea: HTMLElement) { |
18 | 10 | const config: CreateEditorArgs = { |
@@ -42,25 +34,29 @@ export function createPageEditorInstance(editArea: HTMLElement) { |
42 | 34 | const debugView = document.getElementById('lexical-debug'); |
43 | 35 | editor.registerUpdateListener(({editorState}) => { |
44 | 36 | console.log('editorState', editorState.toJSON()); |
45 | | - debugView.textContent = JSON.stringify(editorState.toJSON(), null, 2); |
| 37 | + if (debugView) { |
| 38 | + debugView.textContent = JSON.stringify(editorState.toJSON(), null, 2); |
| 39 | + } |
46 | 40 | }); |
47 | 41 |
|
48 | | - // Example of creating, registering and using a custom command |
| 42 | + buildEditorUI(editArea, editor); |
49 | 43 |
|
50 | | - const SET_BLOCK_CALLOUT_COMMAND = createCommand(); |
51 | | - editor.registerCommand(SET_BLOCK_CALLOUT_COMMAND, (category: CalloutCategory = 'info') => { |
52 | | - const selection = $getSelection(); |
53 | | - const blockElement = $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]); |
54 | | - if ($isCalloutNode(blockElement)) { |
55 | | - $setBlocksType(selection, $createParagraphNode); |
56 | | - } else { |
57 | | - $setBlocksType(selection, () => $createCalloutNode(category)); |
58 | | - } |
59 | | - return true; |
60 | | - }, COMMAND_PRIORITY_LOW); |
| 44 | + // Example of creating, registering and using a custom command |
61 | 45 |
|
62 | | - const button = document.getElementById('lexical-button'); |
63 | | - button.addEventListener('click', event => { |
64 | | - editor.dispatchCommand(SET_BLOCK_CALLOUT_COMMAND, 'info'); |
65 | | - }); |
| 46 | + // const SET_BLOCK_CALLOUT_COMMAND = createCommand(); |
| 47 | + // editor.registerCommand(SET_BLOCK_CALLOUT_COMMAND, (category: CalloutCategory = 'info') => { |
| 48 | + // const selection = $getSelection(); |
| 49 | + // const blockElement = $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]); |
| 50 | + // if ($isCalloutNode(blockElement)) { |
| 51 | + // $setBlocksType(selection, $createParagraphNode); |
| 52 | + // } else { |
| 53 | + // $setBlocksType(selection, () => $createCalloutNode(category)); |
| 54 | + // } |
| 55 | + // return true; |
| 56 | + // }, COMMAND_PRIORITY_LOW); |
| 57 | + // |
| 58 | + // const button = document.getElementById('lexical-button'); |
| 59 | + // button.addEventListener('click', event => { |
| 60 | + // editor.dispatchCommand(SET_BLOCK_CALLOUT_COMMAND, 'info'); |
| 61 | + // }); |
66 | 62 | } |
0 commit comments