mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
Add transform .unwrapInlineByKey with test and documentation
This commit is contained in:
@@ -57,6 +57,7 @@ Transform methods can either operate on the [`Document`](./document.md), the [`S
|
||||
- [`setMarkByKey`](#setmarkbykey)
|
||||
- [`setNodeByKey`](#setnodebykey)
|
||||
- [`splitNodeByKey`](#splitnodebykey)
|
||||
- [`unwrapInlineByKey`](#unwrapinlinebykey)
|
||||
- [Document Transforms](#document-transforms)
|
||||
- [`deleteAtRange`](#deleteatrange)
|
||||
- [`deleteBackwardAtRange`](#deletebackwardatrange)
|
||||
@@ -317,6 +318,11 @@ Set a dictionary of `properties` on a [`Node`](./node.md) by its `key`. For conv
|
||||
|
||||
Split a node by its `key` at an `offset`.
|
||||
|
||||
### `unwrapInlineByKey`
|
||||
`unwrapInlineByKey(key: String, properties: Object) => Transform` <br/>
|
||||
`unwrapInlineByKey(key: String, type: String) => Transform`
|
||||
|
||||
Unwrap all inner content of an [`Inline`](./inline.md) node that match `properties`. For convenience, you can pass a `type` string or `properties` object.
|
||||
|
||||
## Document Transforms
|
||||
|
||||
|
@@ -193,3 +193,20 @@ export function splitNodeByKey(transform, key, offset) {
|
||||
const path = document.getPath(key)
|
||||
return transform.splitNodeOperation(path, offset)
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwrap content from an inline parent with `properties`.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {String} key
|
||||
* @param {Object or String} properties
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function unwrapInlineByKey(transform, key, properties) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const node = document.assertDescendant(key)
|
||||
const range = selection.moveToRangeOf(node)
|
||||
return transform.unwrapInline(range, properties)
|
||||
}
|
||||
|
@@ -92,6 +92,7 @@ import {
|
||||
setMarkByKey,
|
||||
setNodeByKey,
|
||||
splitNodeByKey,
|
||||
unwrapInlineByKey
|
||||
} from './by-key'
|
||||
|
||||
/**
|
||||
@@ -238,6 +239,7 @@ export default {
|
||||
setMarkByKey,
|
||||
setNodeByKey,
|
||||
splitNodeByKey,
|
||||
unwrapInlineByKey,
|
||||
|
||||
/**
|
||||
* On selection.
|
||||
|
@@ -0,0 +1,14 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const inline = document.assertPath([0, 1])
|
||||
|
||||
const next = state
|
||||
.transform()
|
||||
.unwrapInlineByKey(inline.key, 'hashtag')
|
||||
.apply()
|
||||
|
||||
return next
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: w
|
||||
- kind: inline
|
||||
type: hashtag
|
||||
nodes:
|
||||
- kind: text
|
||||
text: or
|
||||
- kind: text
|
||||
text: d
|
@@ -0,0 +1,7 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: word
|
Reference in New Issue
Block a user