mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 06:53:25 +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)
|
- [`setMarkByKey`](#setmarkbykey)
|
||||||
- [`setNodeByKey`](#setnodebykey)
|
- [`setNodeByKey`](#setnodebykey)
|
||||||
- [`splitNodeByKey`](#splitnodebykey)
|
- [`splitNodeByKey`](#splitnodebykey)
|
||||||
|
- [`unwrapInlineByKey`](#unwrapinlinebykey)
|
||||||
- [Document Transforms](#document-transforms)
|
- [Document Transforms](#document-transforms)
|
||||||
- [`deleteAtRange`](#deleteatrange)
|
- [`deleteAtRange`](#deleteatrange)
|
||||||
- [`deleteBackwardAtRange`](#deletebackwardatrange)
|
- [`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`.
|
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
|
## Document Transforms
|
||||||
|
|
||||||
|
@@ -193,3 +193,20 @@ export function splitNodeByKey(transform, key, offset) {
|
|||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
return transform.splitNodeOperation(path, offset)
|
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,
|
setMarkByKey,
|
||||||
setNodeByKey,
|
setNodeByKey,
|
||||||
splitNodeByKey,
|
splitNodeByKey,
|
||||||
|
unwrapInlineByKey
|
||||||
} from './by-key'
|
} from './by-key'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,6 +239,7 @@ export default {
|
|||||||
setMarkByKey,
|
setMarkByKey,
|
||||||
setNodeByKey,
|
setNodeByKey,
|
||||||
splitNodeByKey,
|
splitNodeByKey,
|
||||||
|
unwrapInlineByKey,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On selection.
|
* 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