mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 03:11:44 +02:00
Remove needless transform = transform.method()
This commit is contained in:
@@ -140,7 +140,7 @@ The `decorate` property allows you define a function that will apply extra marks
|
|||||||
{
|
{
|
||||||
normalize: (transform, node, invalidChildren) => {
|
normalize: (transform, node, invalidChildren) => {
|
||||||
invalidChildren.forEach((child) => {
|
invalidChildren.forEach((child) => {
|
||||||
transform = transform.removeNodeByKey(child.key)
|
transform.removeNodeByKey(child.key)
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
|
@@ -134,7 +134,7 @@ class AutoMarkdown extends React.Component {
|
|||||||
.transform()
|
.transform()
|
||||||
.setBlock(type)
|
.setBlock(type)
|
||||||
|
|
||||||
if (type == 'list-item') transform = transform.wrapBlock('bulleted-list')
|
if (type == 'list-item') transform.wrapBlock('bulleted-list')
|
||||||
|
|
||||||
state = transform
|
state = transform
|
||||||
.extendToStartOf(startBlock)
|
.extendToStartOf(startBlock)
|
||||||
@@ -165,7 +165,7 @@ class AutoMarkdown extends React.Component {
|
|||||||
.transform()
|
.transform()
|
||||||
.setBlock('paragraph')
|
.setBlock('paragraph')
|
||||||
|
|
||||||
if (startBlock.type == 'list-item') transform = transform.unwrapBlock('bulleted-list')
|
if (startBlock.type == 'list-item') transform.unwrapBlock('bulleted-list')
|
||||||
|
|
||||||
state = transform.apply()
|
state = transform.apply()
|
||||||
return state
|
return state
|
||||||
|
@@ -154,8 +154,8 @@ class CodeHighlighting extends React.Component {
|
|||||||
if (startBlock.type != 'code') return
|
if (startBlock.type != 'code') return
|
||||||
|
|
||||||
let transform = state.transform()
|
let transform = state.transform()
|
||||||
if (state.isExpanded) transform = transform.delete()
|
if (state.isExpanded) transform.delete()
|
||||||
transform = transform.insertText('\n')
|
transform.insertText('\n')
|
||||||
|
|
||||||
return transform.apply()
|
return transform.apply()
|
||||||
}
|
}
|
||||||
|
@@ -173,11 +173,11 @@ class RichText extends React.Component {
|
|||||||
// Handle the extra wrapping required for list buttons.
|
// Handle the extra wrapping required for list buttons.
|
||||||
if (type == 'bulleted-list' || type == 'numbered-list') {
|
if (type == 'bulleted-list' || type == 'numbered-list') {
|
||||||
if (this.hasBlock('list-item')) {
|
if (this.hasBlock('list-item')) {
|
||||||
transform = transform
|
transform
|
||||||
.setBlock(DEFAULT_NODE)
|
.setBlock(DEFAULT_NODE)
|
||||||
.unwrapBlock(type)
|
.unwrapBlock(type)
|
||||||
} else {
|
} else {
|
||||||
transform = transform
|
transform
|
||||||
.setBlock('list-item')
|
.setBlock('list-item')
|
||||||
.wrapBlock(type)
|
.wrapBlock(type)
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ class RichText extends React.Component {
|
|||||||
|
|
||||||
// Handle everything but list buttons.
|
// Handle everything but list buttons.
|
||||||
else {
|
else {
|
||||||
transform = transform.setBlock(isActive ? DEFAULT_NODE : type)
|
transform.setBlock(isActive ? DEFAULT_NODE : type)
|
||||||
}
|
}
|
||||||
|
|
||||||
state = transform.apply()
|
state = transform.apply()
|
||||||
|
@@ -125,7 +125,7 @@ class Links extends React.Component {
|
|||||||
let transform = state.transform()
|
let transform = state.transform()
|
||||||
|
|
||||||
if (this.hasLinks()) {
|
if (this.hasLinks()) {
|
||||||
transform = transform.unwrapInline('link')
|
transform.unwrapInline('link')
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
|
@@ -172,14 +172,14 @@ class RichText extends React.Component {
|
|||||||
const isList = this.hasBlock('list-item')
|
const isList = this.hasBlock('list-item')
|
||||||
|
|
||||||
if (isList) {
|
if (isList) {
|
||||||
transform = transform
|
transform
|
||||||
.setBlock(isActive ? DEFAULT_NODE : type)
|
.setBlock(isActive ? DEFAULT_NODE : type)
|
||||||
.unwrapBlock('bulleted-list')
|
.unwrapBlock('bulleted-list')
|
||||||
.unwrapBlock('numbered-list')
|
.unwrapBlock('numbered-list')
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
transform = transform
|
transform
|
||||||
.setBlock(isActive ? DEFAULT_NODE : type)
|
.setBlock(isActive ? DEFAULT_NODE : type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,16 +192,16 @@ class RichText extends React.Component {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (isList && isType) {
|
if (isList && isType) {
|
||||||
transform = transform
|
transform
|
||||||
.setBlock(DEFAULT_NODE)
|
.setBlock(DEFAULT_NODE)
|
||||||
.unwrapBlock('bulleted-list')
|
.unwrapBlock('bulleted-list')
|
||||||
.unwrapBlock('numbered-list')
|
.unwrapBlock('numbered-list')
|
||||||
} else if (isList) {
|
} else if (isList) {
|
||||||
transform = transform
|
transform
|
||||||
.unwrapBlock(type == 'bulleted-list' ? 'numbered-list' : 'bulleted-list')
|
.unwrapBlock(type == 'bulleted-list' ? 'numbered-list' : 'bulleted-list')
|
||||||
.wrapBlock(type)
|
.wrapBlock(type)
|
||||||
} else {
|
} else {
|
||||||
transform = transform
|
transform
|
||||||
.setBlock('list-item')
|
.setBlock('list-item')
|
||||||
.wrapBlock(type)
|
.wrapBlock(type)
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,7 @@ class Transform {
|
|||||||
let { merge, save, isNative = false } = options
|
let { merge, save, isNative = false } = options
|
||||||
|
|
||||||
// Ensure that the selection is normalized.
|
// Ensure that the selection is normalized.
|
||||||
transform = transform.normalizeSelection()
|
transform.normalizeSelection()
|
||||||
|
|
||||||
let { state, operations } = transform
|
let { state, operations } = transform
|
||||||
let { history } = state
|
let { history } = state
|
||||||
|
@@ -298,7 +298,7 @@ function Plugin(options = {}) {
|
|||||||
|
|
||||||
let transform = state.transform()
|
let transform = state.transform()
|
||||||
|
|
||||||
if (isInternal) transform = transform.delete()
|
if (isInternal) transform.delete()
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
.moveTo(target)
|
.moveTo(target)
|
||||||
@@ -326,8 +326,8 @@ function Plugin(options = {}) {
|
|||||||
text
|
text
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.forEach((line, i) => {
|
.forEach((line, i) => {
|
||||||
if (i > 0) transform = transform.splitBlock()
|
if (i > 0) transform.splitBlock()
|
||||||
transform = transform.insertText(line)
|
transform.insertText(line)
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform.apply()
|
return transform.apply()
|
||||||
@@ -668,8 +668,8 @@ function Plugin(options = {}) {
|
|||||||
data.text
|
data.text
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.forEach((line, i) => {
|
.forEach((line, i) => {
|
||||||
if (i > 0) transform = transform.splitBlock()
|
if (i > 0) transform.splitBlock()
|
||||||
transform = transform.insertText(line)
|
transform.insertText(line)
|
||||||
})
|
})
|
||||||
|
|
||||||
return transform.apply()
|
return transform.apply()
|
||||||
|
@@ -131,7 +131,7 @@ const INLINE_VOID_TEXT_RULE = {
|
|||||||
return node.text !== ' ' || node.nodes.size !== 1
|
return node.text !== ' ' || node.nodes.size !== 1
|
||||||
},
|
},
|
||||||
normalize: (transform, node, result) => {
|
normalize: (transform, node, result) => {
|
||||||
transform = node.nodes.reduce((t, child) => {
|
node.nodes.reduce((t, child) => {
|
||||||
return t.removeNodeByKey(child.key, { normalize: false })
|
return t.removeNodeByKey(child.key, { normalize: false })
|
||||||
}, transform)
|
}, transform)
|
||||||
|
|
||||||
|
@@ -74,8 +74,8 @@ export function deleteAtRange(transform, range, options = {}) {
|
|||||||
const startOff = (startChild.kind == 'text' ? 0 : startChild.getOffset(startKey)) + startOffset
|
const startOff = (startChild.kind == 'text' ? 0 : startChild.getOffset(startKey)) + startOffset
|
||||||
const endOff = (endChild.kind == 'text' ? 0 : endChild.getOffset(endKey)) + endOffset
|
const endOff = (endChild.kind == 'text' ? 0 : endChild.getOffset(endKey)) + endOffset
|
||||||
|
|
||||||
transform = transform.splitNodeByKey(startChild.key, startOff, { normalize: false })
|
transform.splitNodeByKey(startChild.key, startOff, { normalize: false })
|
||||||
transform = transform.splitNodeByKey(endChild.key, endOff, { normalize: false })
|
transform.splitNodeByKey(endChild.key, endOff, { normalize: false })
|
||||||
|
|
||||||
state = transform.state
|
state = transform.state
|
||||||
document = state.document
|
document = state.document
|
||||||
@@ -319,7 +319,7 @@ export function insertFragmentAtRange(transform, range, fragment, options = {})
|
|||||||
const { normalize = true } = options
|
const { normalize = true } = options
|
||||||
|
|
||||||
if (range.isExpanded) {
|
if (range.isExpanded) {
|
||||||
transform = transform.deleteAtRange(range, { normalize: false })
|
transform.deleteAtRange(range, { normalize: false })
|
||||||
range = range.collapseToStart()
|
range = range.collapseToStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ export function insertFragmentAtRange(transform, range, fragment, options = {})
|
|||||||
|
|
||||||
fragment.nodes.forEach((node, i) => {
|
fragment.nodes.forEach((node, i) => {
|
||||||
const newIndex = startIndex + i + 1
|
const newIndex = startIndex + i + 1
|
||||||
transform = transform.insertNodeByKey(parent.key, newIndex, node, { normalize: false })
|
transform.insertNodeByKey(parent.key, newIndex, node, { normalize: false })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ export function insertTextAtRange(transform, range, text, marks, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (range.isExpanded) {
|
if (range.isExpanded) {
|
||||||
transform = transform.deleteAtRange(range, { normalize: false })
|
transform.deleteAtRange(range, { normalize: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unless specified, don't normalize if only inserting text
|
// Unless specified, don't normalize if only inserting text
|
||||||
@@ -869,15 +869,15 @@ export function wrapBlockAtRange(transform, range, block, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// inject the new block node into the parent
|
// inject the new block node into the parent
|
||||||
transform = transform.insertNodeByKey(parent.key, index, block, { normalize: false })
|
transform.insertNodeByKey(parent.key, index, block, { normalize: false })
|
||||||
|
|
||||||
// move the sibling nodes into the new block node
|
// move the sibling nodes into the new block node
|
||||||
siblings.forEach((node, i) => {
|
siblings.forEach((node, i) => {
|
||||||
transform = transform.moveNodeByKey(node.key, block.key, i, { normalize: false })
|
transform.moveNodeByKey(node.key, block.key, i, { normalize: false })
|
||||||
})
|
})
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -955,7 +955,7 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform = transform.normalizeNodeByKey(startBlock.key)
|
transform.normalizeNodeByKey(startBlock.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -985,7 +985,7 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform = transform
|
transform
|
||||||
.normalizeNodeByKey(startBlock.key)
|
.normalizeNodeByKey(startBlock.key)
|
||||||
.normalizeNodeByKey(endBlock.key)
|
.normalizeNodeByKey(endBlock.key)
|
||||||
}
|
}
|
||||||
@@ -999,7 +999,7 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform = transform.normalizeNodeByKey(block.key)
|
transform.normalizeNodeByKey(block.key)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -20,10 +20,10 @@ export function addMarkByKey(transform, key, offset, length, mark, options = {})
|
|||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.addMarkOperation(path, offset, length, mark)
|
transform.addMarkOperation(path, offset, length, mark)
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -47,9 +47,9 @@ export function insertNodeByKey(transform, key, index, node, options = {}) {
|
|||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.insertNodeOperation(path, index, node)
|
transform.insertNodeOperation(path, index, node)
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
transform = transform.normalizeNodeByKey(key)
|
transform.normalizeNodeByKey(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -74,10 +74,10 @@ export function insertTextByKey(transform, key, offset, text, marks, options = {
|
|||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.insertTextOperation(path, offset, text, marks)
|
transform.insertTextOperation(path, offset, text, marks)
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -101,14 +101,14 @@ export function joinNodeByKey(transform, key, withKey, options = {}) {
|
|||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
const withPath = document.getPath(withKey)
|
const withPath = document.getPath(withKey)
|
||||||
|
|
||||||
transform = transform.joinNodeOperation(path, withPath)
|
transform.joinNodeOperation(path, withPath)
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getCommonAncestor(key, withKey)
|
const parent = document.getCommonAncestor(key, withKey)
|
||||||
if (parent) {
|
if (parent) {
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
} else {
|
} else {
|
||||||
transform = transform.normalizeDocument()
|
transform.normalizeDocument()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,11 +135,11 @@ export function moveNodeByKey(transform, key, newKey, newIndex, options = {}) {
|
|||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
const newPath = document.getPath(newKey)
|
const newPath = document.getPath(newKey)
|
||||||
|
|
||||||
transform = transform.moveNodeOperation(path, newPath, newIndex)
|
transform.moveNodeOperation(path, newPath, newIndex)
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.key == newKey ? document : document.getCommonAncestor(key, newKey)
|
const parent = document.key == newKey ? document : document.getCommonAncestor(key, newKey)
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -165,10 +165,10 @@ export function removeMarkByKey(transform, key, offset, length, mark, options =
|
|||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.removeMarkOperation(path, offset, length, mark)
|
transform.removeMarkOperation(path, offset, length, mark)
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -190,14 +190,14 @@ export function removeNodeByKey(transform, key, options = {}) {
|
|||||||
let { document } = state
|
let { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.removeNodeOperation(path)
|
transform.removeNodeOperation(path)
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
if (parent) {
|
if (parent) {
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
} else {
|
} else {
|
||||||
transform = transform.normalizeDocument()
|
transform.normalizeDocument()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,10 +222,10 @@ export function removeTextByKey(transform, key, offset, length, options = {}) {
|
|||||||
let { document } = state
|
let { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.removeTextOperation(path, offset, length)
|
transform.removeTextOperation(path, offset, length)
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
transform = transform.normalizeParentsByKey(parent.key)
|
transform.normalizeParentsByKey(parent.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -253,10 +253,10 @@ export function setMarkByKey(transform, key, offset, length, mark, properties, o
|
|||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.setMarkOperation(path, offset, length, mark, newMark)
|
transform.setMarkOperation(path, offset, length, mark, newMark)
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -280,14 +280,14 @@ export function setNodeByKey(transform, key, properties, options = {}) {
|
|||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.setNodeOperation(path, properties)
|
transform.setNodeOperation(path, properties)
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
if (parent) {
|
if (parent) {
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
} else {
|
} else {
|
||||||
transform = transform.normalizeDocument()
|
transform.normalizeDocument()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,14 +311,14 @@ export function splitNodeByKey(transform, key, offset, options = {}) {
|
|||||||
let { document } = state
|
let { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
|
|
||||||
transform = transform.splitNodeOperation(path, offset)
|
transform.splitNodeOperation(path, offset)
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
const parent = document.getParent(key)
|
const parent = document.getParent(key)
|
||||||
if (parent) {
|
if (parent) {
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
transform.normalizeNodeByKey(parent.key)
|
||||||
} else {
|
} else {
|
||||||
transform = transform.normalizeDocument()
|
transform.normalizeDocument()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ export function normalizeNodeWith(transform, schema, node, prevNode) {
|
|||||||
const opCount = transform.operations.length
|
const opCount = transform.operations.length
|
||||||
|
|
||||||
// Iterate over its children
|
// Iterate over its children
|
||||||
transform = normalizeChildrenWith(transform, schema, node, prevNode)
|
normalizeChildrenWith(transform, schema, node, prevNode)
|
||||||
|
|
||||||
const hasChanged = transform.operations.length != opCount
|
const hasChanged = transform.operations.length != opCount
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
@@ -36,7 +36,7 @@ export function normalizeNodeWith(transform, schema, node, prevNode) {
|
|||||||
|
|
||||||
// Now normalize the node itself if it still exist
|
// Now normalize the node itself if it still exist
|
||||||
if (node) {
|
if (node) {
|
||||||
transform = normalizeNodeOnly(transform, schema, node)
|
normalizeNodeOnly(transform, schema, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
@@ -52,7 +52,7 @@ export function normalizeNodeWith(transform, schema, node, prevNode) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalizeParentsWith(transform, schema, node) {
|
export function normalizeParentsWith(transform, schema, node) {
|
||||||
transform = normalizeNodeOnly(transform, schema, node)
|
normalizeNodeOnly(transform, schema, node)
|
||||||
|
|
||||||
// Normalize went back up to the document
|
// Normalize went back up to the document
|
||||||
if (node.kind == 'document') {
|
if (node.kind == 'document') {
|
||||||
@@ -101,7 +101,7 @@ export function normalizeWith(transform, schema, prevDocument) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function normalize(transform) {
|
export function normalize(transform) {
|
||||||
transform = transform
|
transform
|
||||||
.normalizeDocument()
|
.normalizeDocument()
|
||||||
.normalizeSelection()
|
.normalizeSelection()
|
||||||
return transform
|
return transform
|
||||||
@@ -138,7 +138,7 @@ export function normalizeNodeByKey(transform, key) {
|
|||||||
const node = document.key == key ? document : document.assertDescendant(key)
|
const node = document.key == key ? document : document.assertDescendant(key)
|
||||||
const prevNode = document.key == key ? prevDocument : prevDocument.getDescendant(key)
|
const prevNode = document.key == key ? prevDocument : prevDocument.getDescendant(key)
|
||||||
|
|
||||||
transform = transform.normalizeNodeWith(defaultSchema, node, prevNode)
|
transform.normalizeNodeWith(defaultSchema, node, prevNode)
|
||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ export function normalizeParentsByKey(transform, key) {
|
|||||||
const node = document.key == key ? document : document.assertDescendant(key)
|
const node = document.key == key ? document : document.assertDescendant(key)
|
||||||
const prevNode = document.key == key ? prevDocument : prevDocument.getDescendant(key)
|
const prevNode = document.key == key ? prevDocument : prevDocument.getDescendant(key)
|
||||||
|
|
||||||
transform = transform.normalizeParentsWith(defaultSchema, node, prevNode)
|
transform.normalizeParentsWith(defaultSchema, node, prevNode)
|
||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ function normalizeNodeOnly(transform, schema, node) {
|
|||||||
const { value, rule } = failure
|
const { value, rule } = failure
|
||||||
|
|
||||||
// Normalize and get the new state
|
// Normalize and get the new state
|
||||||
_transform = rule.normalize(_transform, _node, value)
|
rule.normalize(_transform, _node, value)
|
||||||
|
|
||||||
// Search for the updated node in the new state
|
// Search for the updated node in the new state
|
||||||
const newNode = refreshNode(_transform, _node)
|
const newNode = refreshNode(_transform, _node)
|
||||||
|
Reference in New Issue
Block a user