mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 21:21:21 +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 = {}) {
|
function SlateReactPlaceholder(options = {}) {
|
||||||
const instanceId = instanceCounter++
|
const instanceId = instanceCounter++
|
||||||
const placeholderMark = {
|
|
||||||
type: 'placeholder',
|
|
||||||
data: { key: instanceId },
|
|
||||||
}
|
|
||||||
|
|
||||||
const { placeholder, when, style = {} } = options
|
const { placeholder, when, style = {} } = options
|
||||||
|
|
||||||
invariant(
|
invariant(
|
||||||
@@ -53,13 +48,14 @@ function SlateReactPlaceholder(options = {}) {
|
|||||||
const [firstNode, firstPath] = first
|
const [firstNode, firstPath] = first
|
||||||
const [lastNode, lastPath] = last
|
const [lastNode, lastPath] = last
|
||||||
const decoration = {
|
const decoration = {
|
||||||
|
type: 'placeholder',
|
||||||
|
data: { key: instanceId },
|
||||||
anchor: { key: firstNode.key, offset: 0, path: firstPath },
|
anchor: { key: firstNode.key, offset: 0, path: firstPath },
|
||||||
focus: {
|
focus: {
|
||||||
key: lastNode.key,
|
key: lastNode.key,
|
||||||
offset: lastNode.text.length,
|
offset: lastNode.text.length,
|
||||||
path: lastPath,
|
path: lastPath,
|
||||||
},
|
},
|
||||||
mark: placeholderMark,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [...others, decoration]
|
return [...others, decoration]
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import isPlainObject from 'is-plain-object'
|
import isPlainObject from 'is-plain-object'
|
||||||
|
import warning from 'tiny-warning'
|
||||||
import { List, Record } from 'immutable'
|
import { List, Record } from 'immutable'
|
||||||
|
|
||||||
import Mark from './mark'
|
import Mark from './mark'
|
||||||
@@ -109,7 +110,18 @@ class Decoration extends Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static fromJSON(object) {
|
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) {
|
if (!type) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
Reference in New Issue
Block a user