/
index.js
74 lines (67 loc) · 2.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Debug from 'debug'
import { IS_ANDROID } from 'slate-dev-environment'
import PlaceholderPlugin from 'slate-react-placeholder'
import EditorPropsPlugin from './editor-props'
import RenderingPlugin from './rendering'
import CommandsPlugin from './commands'
import QueriesPlugin from './queries'
import DOMPlugin from '../dom'
import RestoreDOMPlugin from './restore-dom'
import DebugEventsPlugin from '../debug/debug-events'
import DebugBatchEventsPlugin from '../debug/debug-batch-events'
import DebugMutationsPlugin from '../debug/debug-mutations'
/**
* A plugin that adds the React-specific rendering logic to the editor.
*
* @param {Object} options
* @return {Object}
*/
function ReactPlugin(options = {}) {
const { placeholder = '' } = options
const debugEventsPlugin = Debug.enabled('slate:events')
? DebugEventsPlugin(options)
: null
const debugBatchEventsPlugin = Debug.enabled('slate:batch-events')
? DebugBatchEventsPlugin(options)
: null
const debugMutationsPlugin = Debug.enabled('slate:mutations')
? DebugMutationsPlugin(options)
: null
const renderingPlugin = RenderingPlugin(options)
const commandsPlugin = CommandsPlugin(options)
const queriesPlugin = QueriesPlugin(options)
const editorPropsPlugin = EditorPropsPlugin(options)
const domPlugin = DOMPlugin(options)
const restoreDomPlugin = RestoreDOMPlugin()
// Disable placeholder for Android because it messes with reconciliation
// and doesn't disappear until composition is complete.
// e.g. In empty, type "h" and autocomplete on Android 9 and deletes all text.
const placeholderPlugin = IS_ANDROID
? null
: PlaceholderPlugin({
placeholder,
when: (editor, node) =>
node.object === 'document' &&
node.text === '' &&
node.nodes.size === 1 &&
Array.from(node.texts()).length === 1,
})
return [
debugEventsPlugin,
debugBatchEventsPlugin,
debugMutationsPlugin,
editorPropsPlugin,
domPlugin,
restoreDomPlugin,
placeholderPlugin,
renderingPlugin,
commandsPlugin,
queriesPlugin,
]
}
/**
* Export.
*
* @type {Function}
*/
export default ReactPlugin