1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

Remove needless transform = transform.method()

This commit is contained in:
Soreine
2016-11-10 15:18:52 +01:00
parent d57f51e6c8
commit 944adc27fe
12 changed files with 65 additions and 65 deletions

View File

@@ -140,7 +140,7 @@ The `decorate` property allows you define a function that will apply extra marks
{
normalize: (transform, node, invalidChildren) => {
invalidChildren.forEach((child) => {
transform = transform.removeNodeByKey(child.key)
transform.removeNodeByKey(child.key)
})
return transform

View File

@@ -134,7 +134,7 @@ class AutoMarkdown extends React.Component {
.transform()
.setBlock(type)
if (type == 'list-item') transform = transform.wrapBlock('bulleted-list')
if (type == 'list-item') transform.wrapBlock('bulleted-list')
state = transform
.extendToStartOf(startBlock)
@@ -165,7 +165,7 @@ class AutoMarkdown extends React.Component {
.transform()
.setBlock('paragraph')
if (startBlock.type == 'list-item') transform = transform.unwrapBlock('bulleted-list')
if (startBlock.type == 'list-item') transform.unwrapBlock('bulleted-list')
state = transform.apply()
return state

View File

@@ -154,8 +154,8 @@ class CodeHighlighting extends React.Component {
if (startBlock.type != 'code') return
let transform = state.transform()
if (state.isExpanded) transform = transform.delete()
transform = transform.insertText('\n')
if (state.isExpanded) transform.delete()
transform.insertText('\n')
return transform.apply()
}

View File

@@ -173,11 +173,11 @@ class RichText extends React.Component {
// Handle the extra wrapping required for list buttons.
if (type == 'bulleted-list' || type == 'numbered-list') {
if (this.hasBlock('list-item')) {
transform = transform
transform
.setBlock(DEFAULT_NODE)
.unwrapBlock(type)
} else {
transform = transform
transform
.setBlock('list-item')
.wrapBlock(type)
}
@@ -185,7 +185,7 @@ class RichText extends React.Component {
// Handle everything but list buttons.
else {
transform = transform.setBlock(isActive ? DEFAULT_NODE : type)
transform.setBlock(isActive ? DEFAULT_NODE : type)
}
state = transform.apply()

View File

@@ -125,7 +125,7 @@ class Links extends React.Component {
let transform = state.transform()
if (this.hasLinks()) {
transform = transform.unwrapInline('link')
transform.unwrapInline('link')
}
return transform

View File

@@ -172,14 +172,14 @@ class RichText extends React.Component {
const isList = this.hasBlock('list-item')
if (isList) {
transform = transform
transform
.setBlock(isActive ? DEFAULT_NODE : type)
.unwrapBlock('bulleted-list')
.unwrapBlock('numbered-list')
}
else {
transform = transform
transform
.setBlock(isActive ? DEFAULT_NODE : type)
}
}
@@ -192,16 +192,16 @@ class RichText extends React.Component {
})
if (isList && isType) {
transform = transform
transform
.setBlock(DEFAULT_NODE)
.unwrapBlock('bulleted-list')
.unwrapBlock('numbered-list')
} else if (isList) {
transform = transform
transform
.unwrapBlock(type == 'bulleted-list' ? 'numbered-list' : 'bulleted-list')
.wrapBlock(type)
} else {
transform = transform
transform
.setBlock('list-item')
.wrapBlock(type)
}

View File

@@ -58,7 +58,7 @@ class Transform {
let { merge, save, isNative = false } = options
// Ensure that the selection is normalized.
transform = transform.normalizeSelection()
transform.normalizeSelection()
let { state, operations } = transform
let { history } = state

View File

@@ -298,7 +298,7 @@ function Plugin(options = {}) {
let transform = state.transform()
if (isInternal) transform = transform.delete()
if (isInternal) transform.delete()
return transform
.moveTo(target)
@@ -326,8 +326,8 @@ function Plugin(options = {}) {
text
.split('\n')
.forEach((line, i) => {
if (i > 0) transform = transform.splitBlock()
transform = transform.insertText(line)
if (i > 0) transform.splitBlock()
transform.insertText(line)
})
return transform.apply()
@@ -668,8 +668,8 @@ function Plugin(options = {}) {
data.text
.split('\n')
.forEach((line, i) => {
if (i > 0) transform = transform.splitBlock()
transform = transform.insertText(line)
if (i > 0) transform.splitBlock()
transform.insertText(line)
})
return transform.apply()

View File

@@ -131,7 +131,7 @@ const INLINE_VOID_TEXT_RULE = {
return node.text !== ' ' || node.nodes.size !== 1
},
normalize: (transform, node, result) => {
transform = node.nodes.reduce((t, child) => {
node.nodes.reduce((t, child) => {
return t.removeNodeByKey(child.key, { normalize: false })
}, transform)

View File

@@ -74,8 +74,8 @@ export function deleteAtRange(transform, range, options = {}) {
const startOff = (startChild.kind == 'text' ? 0 : startChild.getOffset(startKey)) + startOffset
const endOff = (endChild.kind == 'text' ? 0 : endChild.getOffset(endKey)) + endOffset
transform = transform.splitNodeByKey(startChild.key, startOff, { normalize: false })
transform = transform.splitNodeByKey(endChild.key, endOff, { normalize: false })
transform.splitNodeByKey(startChild.key, startOff, { normalize: false })
transform.splitNodeByKey(endChild.key, endOff, { normalize: false })
state = transform.state
document = state.document
@@ -319,7 +319,7 @@ export function insertFragmentAtRange(transform, range, fragment, options = {})
const { normalize = true } = options
if (range.isExpanded) {
transform = transform.deleteAtRange(range, { normalize: false })
transform.deleteAtRange(range, { normalize: false })
range = range.collapseToStart()
}
@@ -353,7 +353,7 @@ export function insertFragmentAtRange(transform, range, fragment, options = {})
fragment.nodes.forEach((node, i) => {
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) {
transform = transform.deleteAtRange(range, { normalize: false })
transform.deleteAtRange(range, { normalize: false })
}
// 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
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
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) {
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
}
return transform
@@ -955,7 +955,7 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
})
if (normalize) {
transform = transform.normalizeNodeByKey(startBlock.key)
transform.normalizeNodeByKey(startBlock.key)
}
}
@@ -985,7 +985,7 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
})
if (normalize) {
transform = transform
transform
.normalizeNodeByKey(startBlock.key)
.normalizeNodeByKey(endBlock.key)
}
@@ -999,7 +999,7 @@ export function wrapInlineAtRange(transform, range, inline, options = {}) {
})
if (normalize) {
transform = transform.normalizeNodeByKey(block.key)
transform.normalizeNodeByKey(block.key)
}
})
}

View File

@@ -20,10 +20,10 @@ export function addMarkByKey(transform, key, offset, length, mark, options = {})
const { document } = state
const path = document.getPath(key)
transform = transform.addMarkOperation(path, offset, length, mark)
transform.addMarkOperation(path, offset, length, mark)
if (normalize) {
const parent = document.getParent(key)
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
}
return transform
@@ -47,9 +47,9 @@ export function insertNodeByKey(transform, key, index, node, options = {}) {
const { document } = state
const path = document.getPath(key)
transform = transform.insertNodeOperation(path, index, node)
transform.insertNodeOperation(path, index, node)
if (normalize) {
transform = transform.normalizeNodeByKey(key)
transform.normalizeNodeByKey(key)
}
return transform
@@ -74,10 +74,10 @@ export function insertTextByKey(transform, key, offset, text, marks, options = {
const { document } = state
const path = document.getPath(key)
transform = transform.insertTextOperation(path, offset, text, marks)
transform.insertTextOperation(path, offset, text, marks)
if (normalize) {
const parent = document.getParent(key)
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
}
return transform
@@ -101,14 +101,14 @@ export function joinNodeByKey(transform, key, withKey, options = {}) {
const path = document.getPath(key)
const withPath = document.getPath(withKey)
transform = transform.joinNodeOperation(path, withPath)
transform.joinNodeOperation(path, withPath)
if (normalize) {
const parent = document.getCommonAncestor(key, withKey)
if (parent) {
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
} else {
transform = transform.normalizeDocument()
transform.normalizeDocument()
}
}
@@ -135,11 +135,11 @@ export function moveNodeByKey(transform, key, newKey, newIndex, options = {}) {
const path = document.getPath(key)
const newPath = document.getPath(newKey)
transform = transform.moveNodeOperation(path, newPath, newIndex)
transform.moveNodeOperation(path, newPath, newIndex)
if (normalize) {
const parent = document.key == newKey ? document : document.getCommonAncestor(key, newKey)
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
}
return transform
@@ -165,10 +165,10 @@ export function removeMarkByKey(transform, key, offset, length, mark, options =
const { document } = state
const path = document.getPath(key)
transform = transform.removeMarkOperation(path, offset, length, mark)
transform.removeMarkOperation(path, offset, length, mark)
if (normalize) {
const parent = document.getParent(key)
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
}
return transform
@@ -190,14 +190,14 @@ export function removeNodeByKey(transform, key, options = {}) {
let { document } = state
const path = document.getPath(key)
transform = transform.removeNodeOperation(path)
transform.removeNodeOperation(path)
if (normalize) {
const parent = document.getParent(key)
if (parent) {
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
} else {
transform = transform.normalizeDocument()
transform.normalizeDocument()
}
}
@@ -222,10 +222,10 @@ export function removeTextByKey(transform, key, offset, length, options = {}) {
let { document } = state
const path = document.getPath(key)
transform = transform.removeTextOperation(path, offset, length)
transform.removeTextOperation(path, offset, length)
if (normalize) {
const parent = document.getParent(key)
transform = transform.normalizeParentsByKey(parent.key)
transform.normalizeParentsByKey(parent.key)
}
return transform
@@ -253,10 +253,10 @@ export function setMarkByKey(transform, key, offset, length, mark, properties, o
const { document } = state
const path = document.getPath(key)
transform = transform.setMarkOperation(path, offset, length, mark, newMark)
transform.setMarkOperation(path, offset, length, mark, newMark)
if (normalize) {
const parent = document.getParent(key)
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
}
return transform
@@ -280,14 +280,14 @@ export function setNodeByKey(transform, key, properties, options = {}) {
const { document } = state
const path = document.getPath(key)
transform = transform.setNodeOperation(path, properties)
transform.setNodeOperation(path, properties)
if (normalize) {
const parent = document.getParent(key)
if (parent) {
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
} else {
transform = transform.normalizeDocument()
transform.normalizeDocument()
}
}
@@ -311,14 +311,14 @@ export function splitNodeByKey(transform, key, offset, options = {}) {
let { document } = state
const path = document.getPath(key)
transform = transform.splitNodeOperation(path, offset)
transform.splitNodeOperation(path, offset)
if (normalize) {
const parent = document.getParent(key)
if (parent) {
transform = transform.normalizeNodeByKey(parent.key)
transform.normalizeNodeByKey(parent.key)
} else {
transform = transform.normalizeDocument()
transform.normalizeDocument()
}
}

View File

@@ -26,7 +26,7 @@ export function normalizeNodeWith(transform, schema, node, prevNode) {
const opCount = transform.operations.length
// Iterate over its children
transform = normalizeChildrenWith(transform, schema, node, prevNode)
normalizeChildrenWith(transform, schema, node, prevNode)
const hasChanged = transform.operations.length != opCount
if (hasChanged) {
@@ -36,7 +36,7 @@ export function normalizeNodeWith(transform, schema, node, prevNode) {
// Now normalize the node itself if it still exist
if (node) {
transform = normalizeNodeOnly(transform, schema, node)
normalizeNodeOnly(transform, schema, node)
}
return transform
@@ -52,7 +52,7 @@ export function normalizeNodeWith(transform, schema, node, prevNode) {
*/
export function normalizeParentsWith(transform, schema, node) {
transform = normalizeNodeOnly(transform, schema, node)
normalizeNodeOnly(transform, schema, node)
// Normalize went back up to the document
if (node.kind == 'document') {
@@ -101,7 +101,7 @@ export function normalizeWith(transform, schema, prevDocument) {
*/
export function normalize(transform) {
transform = transform
transform
.normalizeDocument()
.normalizeSelection()
return transform
@@ -138,7 +138,7 @@ export function normalizeNodeByKey(transform, key) {
const node = document.key == key ? document : document.assertDescendant(key)
const prevNode = document.key == key ? prevDocument : prevDocument.getDescendant(key)
transform = transform.normalizeNodeWith(defaultSchema, node, prevNode)
transform.normalizeNodeWith(defaultSchema, node, prevNode)
return transform
}
@@ -158,7 +158,7 @@ export function normalizeParentsByKey(transform, key) {
const node = document.key == key ? document : document.assertDescendant(key)
const prevNode = document.key == key ? prevDocument : prevDocument.getDescendant(key)
transform = transform.normalizeParentsWith(defaultSchema, node, prevNode)
transform.normalizeParentsWith(defaultSchema, node, prevNode)
return transform
}
@@ -270,7 +270,7 @@ function normalizeNodeOnly(transform, schema, node) {
const { value, rule } = failure
// 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
const newNode = refreshNode(_transform, _node)