mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
This reverts commit 5948738092
.
This commit is contained in:
@@ -219,7 +219,6 @@ class Editor extends React.Component {
|
|||||||
this.tmp.resolves++
|
this.tmp.resolves++
|
||||||
const react = ReactPlugin({
|
const react = ReactPlugin({
|
||||||
...this.props,
|
...this.props,
|
||||||
__editor__: this,
|
|
||||||
value: this.props.value || this.state.value,
|
value: this.props.value || this.state.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -1,86 +0,0 @@
|
|||||||
import Debug from 'debug'
|
|
||||||
|
|
||||||
const debug = Debug('slate:mutations')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Options for MutationObserver
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const observeOptions = {
|
|
||||||
childList: true,
|
|
||||||
characterData: true,
|
|
||||||
attributes: true,
|
|
||||||
subtree: true,
|
|
||||||
characterDataOldValue: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Properties on a MutationRecord
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const keys = [
|
|
||||||
'type',
|
|
||||||
'oldValue',
|
|
||||||
'target',
|
|
||||||
'addedNodes',
|
|
||||||
'removedNodes',
|
|
||||||
'attributeName',
|
|
||||||
'attributeNamespace',
|
|
||||||
'nextSibling',
|
|
||||||
'previousSibling',
|
|
||||||
]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes a mutation record and turns it into an Object that is easy to log to
|
|
||||||
* the console. Notably, it removes `null` and `undefined` values as well as
|
|
||||||
* values that are a `NodeList` that has no entries.
|
|
||||||
*
|
|
||||||
* @param {MutationRecord} mutationRecord
|
|
||||||
*/
|
|
||||||
|
|
||||||
function normalize(mutationRecord) {
|
|
||||||
const object = {}
|
|
||||||
|
|
||||||
keys.forEach(key => {
|
|
||||||
const value = mutationRecord[key]
|
|
||||||
if (value == null) return
|
|
||||||
if (value instanceof window.NodeList && value.length === 0) return
|
|
||||||
object[key] = value
|
|
||||||
})
|
|
||||||
return object
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A plugin that sends short easy to digest debug info about each dom mutation
|
|
||||||
* to browser.
|
|
||||||
*
|
|
||||||
* More information about mutations here:
|
|
||||||
*
|
|
||||||
* <https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver>
|
|
||||||
* <https://developer.mozilla.org/en-US/docs/Web/API/MutationRecord>
|
|
||||||
*
|
|
||||||
* @param {Object} options
|
|
||||||
*/
|
|
||||||
|
|
||||||
function DebugMutationsPlugin({ __editor__ }) {
|
|
||||||
const observer = new window.MutationObserver(flush)
|
|
||||||
|
|
||||||
function flush(mutations) {
|
|
||||||
const array = Array.from(mutations).map(normalize)
|
|
||||||
debug(`${array.length} MutationRecord`)
|
|
||||||
// Used `console` because `debug` was not easy to view succinctly
|
|
||||||
window.console.log(...array)
|
|
||||||
}
|
|
||||||
|
|
||||||
// `findDOMNode` does not exist until later so we use `setTimeout`
|
|
||||||
setTimeout(() => {
|
|
||||||
const rootEl = __editor__.findDOMNode([])
|
|
||||||
observer.observe(rootEl, observeOptions)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DebugMutationsPlugin
|
|
@@ -9,7 +9,6 @@ import DOMPlugin from '../dom'
|
|||||||
import RestoreDOMPlugin from './restore-dom'
|
import RestoreDOMPlugin from './restore-dom'
|
||||||
import DebugEventsPlugin from '../debug/debug-events'
|
import DebugEventsPlugin from '../debug/debug-events'
|
||||||
import DebugBatchEventsPlugin from '../debug/debug-batch-events'
|
import DebugBatchEventsPlugin from '../debug/debug-batch-events'
|
||||||
import DebugMutationsPlugin from '../debug/debug-mutations'
|
|
||||||
import NoopPlugin from '../debug/noop'
|
import NoopPlugin from '../debug/noop'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,9 +26,6 @@ function ReactPlugin(options = {}) {
|
|||||||
const debugBatchEventsPlugin = Debug.enabled('slate:batch-events')
|
const debugBatchEventsPlugin = Debug.enabled('slate:batch-events')
|
||||||
? DebugBatchEventsPlugin(options)
|
? DebugBatchEventsPlugin(options)
|
||||||
: null
|
: null
|
||||||
const debugMutationsPlugin = Debug.enabled('slate:mutations')
|
|
||||||
? DebugMutationsPlugin(options)
|
|
||||||
: null
|
|
||||||
const noopPlugin = Debug.enabled('slate:noop') ? NoopPlugin(options) : null
|
const noopPlugin = Debug.enabled('slate:noop') ? NoopPlugin(options) : null
|
||||||
const renderingPlugin = RenderingPlugin(options)
|
const renderingPlugin = RenderingPlugin(options)
|
||||||
const commandsPlugin = CommandsPlugin(options)
|
const commandsPlugin = CommandsPlugin(options)
|
||||||
@@ -51,7 +47,6 @@ function ReactPlugin(options = {}) {
|
|||||||
return [
|
return [
|
||||||
debugEventsPlugin,
|
debugEventsPlugin,
|
||||||
debugBatchEventsPlugin,
|
debugBatchEventsPlugin,
|
||||||
debugMutationsPlugin,
|
|
||||||
noopPlugin,
|
noopPlugin,
|
||||||
domPlugin,
|
domPlugin,
|
||||||
restoreDomPlugin,
|
restoreDomPlugin,
|
||||||
|
Reference in New Issue
Block a user