mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 09:04:31 +02:00
add unwrapChildrenByPath/Key
command
This commit is contained in:
@@ -643,6 +643,34 @@ Commands.unwrapNodeByPath = (change, path) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unwrap all of the children of a node, by removing the node and replacing it
|
||||||
|
* with the children in the tree.
|
||||||
|
*
|
||||||
|
* @param {Change} change
|
||||||
|
* @param {Array} path
|
||||||
|
*/
|
||||||
|
|
||||||
|
Commands.unwrapChildrenByPath = (change, path) => {
|
||||||
|
path = PathUtils.create(path)
|
||||||
|
const { value } = change
|
||||||
|
const { document } = value
|
||||||
|
const node = document.assertNode(path)
|
||||||
|
const parentPath = PathUtils.lift(path)
|
||||||
|
const index = path.last()
|
||||||
|
const { nodes } = node
|
||||||
|
|
||||||
|
change.withoutNormalizing(() => {
|
||||||
|
nodes.reverse().forEach((child, i) => {
|
||||||
|
const childIndex = nodes.size - i - 1
|
||||||
|
const childPath = path.push(childIndex)
|
||||||
|
change.moveNodeByPath(childPath, parentPath, index + 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
change.removeNodeByPath(path)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap a node in a block with `properties`.
|
* Wrap a node in a block with `properties`.
|
||||||
*
|
*
|
||||||
@@ -713,18 +741,19 @@ const COMMANDS = [
|
|||||||
'insertNode',
|
'insertNode',
|
||||||
'insertText',
|
'insertText',
|
||||||
'mergeNode',
|
'mergeNode',
|
||||||
'removeMark',
|
|
||||||
'removeAllMarks',
|
'removeAllMarks',
|
||||||
|
'removeMark',
|
||||||
'removeNode',
|
'removeNode',
|
||||||
'setText',
|
|
||||||
'replaceText',
|
|
||||||
'removeText',
|
'removeText',
|
||||||
'replaceNode',
|
'replaceNode',
|
||||||
|
'replaceText',
|
||||||
'setMark',
|
'setMark',
|
||||||
'setNode',
|
'setNode',
|
||||||
|
'setText',
|
||||||
'splitNode',
|
'splitNode',
|
||||||
'unwrapInline',
|
|
||||||
'unwrapBlock',
|
'unwrapBlock',
|
||||||
|
'unwrapChildren',
|
||||||
|
'unwrapInline',
|
||||||
'unwrapNode',
|
'unwrapNode',
|
||||||
'wrapBlock',
|
'wrapBlock',
|
||||||
'wrapInline',
|
'wrapInline',
|
||||||
|
@@ -0,0 +1,27 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export default function(change) {
|
||||||
|
change.unwrapChildrenByKey('a')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<quote key="a">
|
||||||
|
<paragraph>one</paragraph>
|
||||||
|
<paragraph>two</paragraph>
|
||||||
|
</quote>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>one</paragraph>
|
||||||
|
<paragraph>two</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
@@ -0,0 +1,25 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export default function(change) {
|
||||||
|
change.unwrapChildrenByKey('a')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<quote key="a">
|
||||||
|
<paragraph>word</paragraph>
|
||||||
|
</quote>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>word</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
Reference in New Issue
Block a user