mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 13:11:17 +02:00
fix react-placeholder decoration format, add decoration.mark deprecation, fixes #2750
This commit is contained in:
@@ -16,11 +16,6 @@ let instanceCounter = 0
|
||||
|
||||
function SlateReactPlaceholder(options = {}) {
|
||||
const instanceId = instanceCounter++
|
||||
const placeholderMark = {
|
||||
type: 'placeholder',
|
||||
data: { key: instanceId },
|
||||
}
|
||||
|
||||
const { placeholder, when, style = {} } = options
|
||||
|
||||
invariant(
|
||||
@@ -53,13 +48,14 @@ function SlateReactPlaceholder(options = {}) {
|
||||
const [firstNode, firstPath] = first
|
||||
const [lastNode, lastPath] = last
|
||||
const decoration = {
|
||||
type: 'placeholder',
|
||||
data: { key: instanceId },
|
||||
anchor: { key: firstNode.key, offset: 0, path: firstPath },
|
||||
focus: {
|
||||
key: lastNode.key,
|
||||
offset: lastNode.text.length,
|
||||
path: lastPath,
|
||||
},
|
||||
mark: placeholderMark,
|
||||
}
|
||||
|
||||
return [...others, decoration]
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import warning from 'tiny-warning'
|
||||
import { List, Record } from 'immutable'
|
||||
|
||||
import Mark from './mark'
|
||||
@@ -109,7 +110,18 @@ class Decoration extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
static fromJSON(object) {
|
||||
const { type, data, anchor, focus } = object
|
||||
const { anchor, focus } = object
|
||||
let { type, data } = object
|
||||
|
||||
if (object.mark && !type) {
|
||||
warning(
|
||||
false,
|
||||
'As of slate@0.47 the `decoration.mark` property has been changed to `decoration.type` and `decoration.data` directly.'
|
||||
)
|
||||
|
||||
type = object.mark.type
|
||||
data = object.mark.data
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
throw new Error(
|
||||
|
Reference in New Issue
Block a user