1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-07 07:46:32 +02:00

Remove deprecations (#1317)

* remove deprecations from slate core

* remove deprecations from slate-html-serializer

* remove deprecations from slate-hyperscript

* remove deprecations from slate-plain-serializer

* remove deprecations from slate-prop-types

* remove deprecations from slate-simulator

* remove deprecations from slate-react

* fix linter, fix tests
This commit is contained in:
Ian Storm Taylor
2017-10-27 14:42:06 -07:00
committed by GitHub
parent 7d69bbade5
commit f6d3c8e32c
21 changed files with 48 additions and 799 deletions

View File

@@ -1,7 +1,6 @@
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import logger from 'slate-dev-logger'
import typeOf from 'type-of'
import { Node, Value } from 'slate'
import { Record } from 'immutable'
@@ -105,11 +104,6 @@ class Html {
rules = [],
} = options
if (options.defaultBlockType) {
logger.deprecate('0.23.0', 'The `options.defaultBlockType` argument of the `Html` serializer is deprecated, use `options.defaultBlock` instead.')
defaultBlock = options.defaultBlockType
}
defaultBlock = Node.createProperties(defaultBlock)
this.rules = [ ...rules, TEXT_RULE ]
@@ -127,13 +121,7 @@ class Html {
*/
deserialize = (html, options = {}) => {
let { toJSON = false } = options
if (options.toRaw) {
logger.deprecate('0.23.0', 'The `options.toRaw` argument of the `Html` serializer is deprecated, use `options.toJSON` instead.')
toJSON = options.toRaw
}
const { toJSON = false } = options
const { defaultBlock, parseHtml } = this
const fragment = parseHtml(html)
const children = Array.from(fragment.childNodes)

View File

@@ -1,7 +1,6 @@
import isEmpty from 'is-empty'
import isPlainObject from 'is-plain-object'
import logger from 'slate-dev-logger'
import {
Block,
@@ -75,11 +74,6 @@ const CREATORS = {
return Range.create(attributes)
},
state(...args) {
logger.deprecate('slate-hyperscript@0.3.0', 'The `<state>` tag has been renamed to `<value>`.')
return CREATORS.value(...args)
},
value(tagName, attributes, children) {
const { data } = attributes
const document = children.find(Document.isDocument)

View File

@@ -1,5 +1,4 @@
import logger from 'slate-dev-logger'
import { Block, Mark, Node, Value } from 'slate'
import { Set } from 'immutable'
@@ -21,11 +20,6 @@ function deserialize(string, options = {}) {
toJSON = false,
} = options
if (options.toRaw) {
logger.deprecate('0.23.0', 'The `options.toRaw` argument of the `Plain` serializer is deprecated, use `options.toJSON` instead.')
toJSON = options.toRaw
}
if (Set.isSet(defaultMarks)) {
defaultMarks = defaultMarks.toArray()
}

View File

@@ -1,6 +1,4 @@
import logger from 'slate-dev-logger'
import {
Block,
Change,
@@ -77,11 +75,6 @@ const Types = {
value: create('Value', v => Value.isValue(v)),
text: create('Text', v => Text.isText(v)),
texts: create('List<Text>', v => Text.isTextList(v)),
state: create('State', (v) => {
logger.deprecate('slate-prop-types@0.3.0', 'The `state` prop type has been renamed to `value`.')
return Value.isValue(v)
})
}
/**

View File

@@ -5,7 +5,7 @@ import React from 'react'
import SlateTypes from 'slate-prop-types'
import Types from 'prop-types'
import logger from 'slate-dev-logger'
import { Schema, Stack, Value } from 'slate'
import { Schema, Stack } from 'slate'
import EVENT_HANDLERS from '../constants/event-handlers'
import PLUGINS_PROPS from '../constants/plugin-props'
@@ -41,8 +41,6 @@ class Editor extends React.Component {
className: Types.string,
onChange: Types.func,
placeholder: Types.any,
placeholderClassName: Types.string,
placeholderStyle: Types.object,
plugins: Types.array,
readOnly: Types.bool,
role: Types.string,
@@ -82,13 +80,6 @@ class Editor extends React.Component {
this.tmp.updates = 0
this.tmp.resolves = 0
let { value } = props
if (!value && props.state) {
logger.deprecate('slate-react@0.9.0', 'The `props.state` prop has been renamed to `props.value`.')
value = props.state
}
// Resolve the plugins and create a stack and schema from them.
const plugins = this.resolvePlugins(props.plugins, props.schema)
const stack = Stack.create({ plugins })
@@ -98,10 +89,9 @@ class Editor extends React.Component {
// Run `onChange` on the passed-in value because we need to ensure that it
// is normalized, and queue the resulting change.
const change = value.change()
const change = props.value.change()
stack.run('onChange', change, this)
this.queueChange(change)
this.cacheValue(change.value)
this.state.value = change.value
// Create a bound event handler for each event.
@@ -110,14 +100,6 @@ class Editor extends React.Component {
this.onEvent(handler, ...args)
}
})
if (props.onDocumentChange) {
logger.deprecate('0.22.10', 'The `onDocumentChange` prop is deprecated because it led to confusing UX issues, see https://github.com/ianstormtaylor/slate/issues/614#issuecomment-327868679')
}
if (props.onSelectionChange) {
logger.deprecate('0.22.10', 'The `onSelectionChange` prop is deprecated because it led to confusing UX issues, see https://github.com/ianstormtaylor/slate/issues/614#issuecomment-327868679')
}
}
/**
@@ -128,13 +110,7 @@ class Editor extends React.Component {
*/
componentWillReceiveProps = (props) => {
let { value } = props
let { schema, stack } = this.state
if (!value && props.state) {
logger.deprecate('slate-react@0.9.0', 'The `props.state` prop has been renamed to `props.value`.')
value = props.state
}
let { schema, stack } = this
// Increment the updates counter as a baseline.
this.tmp.updates++
@@ -153,16 +129,15 @@ class Editor extends React.Component {
// If we've resolved a few times already, and it's exactly in line with
// the updates, then warn the user that they may be doing something wrong.
if (this.tmp.resolves > 5 && this.tmp.resolves == this.tmp.updates) {
logger.warn('A Slate <Editor> is re-resolving its `plugins` or `schema` on each update, which leads to poor performance. This is often due to passing in a new `schema` or `plugins` prop with each render, by declaring them inline in your render function. Do not do this!')
logger.warn('A Slate <Editor> is re-resolving `props.plugins` or `props.schema` on each update, which leads to poor performance. This is often due to passing in a new `schema` or `plugins` prop with each render by declaring them inline in your render function. Do not do this!')
}
}
// Run `onChange` on the passed-in value because we need to ensure that it
// is normalized, and queue the resulting change.
const change = value.change()
const change = props.value.change()
stack.run('onChange', change, this)
this.queueChange(change)
this.cacheValue(change.value)
this.setState({ value: change.value })
}
@@ -182,17 +157,6 @@ class Editor extends React.Component {
this.flushChange()
}
/**
* Cache a `value` object to be able to compare against it later.
*
* @param {Value} value
*/
cacheValue = (value) => {
this.tmp.document = value.document
this.tmp.selection = value.selection
}
/**
* Queue a `change` object, to be able to flush it later. This is required for
* when a change needs to be applied to the value, but because of the React
@@ -269,39 +233,6 @@ class Editor extends React.Component {
return this.state.value
}
/**
* Get the editor's current schema.
*
* @return {Schema}
*/
getSchema = () => {
logger.deprecate('slate-react@0.9.0', 'The `editor.getSchema()` method has been deprecated, use the `editor.schema` property getter instead.')
return this.schema
}
/**
* Get the editor's current stack.
*
* @return {Stack}
*/
getStack = () => {
logger.deprecate('slate-react@0.9.0', 'The `editor.getStack()` method has been deprecated, use the `editor.stack` property getter instead.')
return this.stack
}
/**
* Get the editor's current value.
*
* @return {Value}
*/
getState = () => {
logger.deprecate('slate-react@0.9.0', 'The `editor.getState()` method has been deprecated, use the `editor.value` property getter instead.')
return this.value
}
/**
* On event.
*
@@ -324,20 +255,11 @@ class Editor extends React.Component {
onChange = (change) => {
debug('onChange', { change })
if (Value.isValue(change)) {
throw new Error('As of slate@0.22.0 the `editor.onChange` method must be passed a `Change` object not a `Value` object.')
}
this.stack.run('onChange', change, this)
const { value } = change
const { document, selection } = this.tmp
const { onChange, onDocumentChange, onSelectionChange } = this.props
const { onChange } = this.props
if (value == this.value) return
onChange(change)
if (onDocumentChange && value.document != document) onDocumentChange(value.document, change)
if (onSelectionChange && value.selection != selection) onSelectionChange(value.selection, change)
}
/**

View File

@@ -114,7 +114,7 @@ function getEmbeddedTypes(text) {
try {
return JSON.parse(text.substring(prefix.length))
} catch (err) {
throw new Error('Unable to parse custom embedded drag data')
throw new Error('Unable to parse custom Slate drag event data.')
}
}

View File

@@ -16,7 +16,11 @@ const PARSER = /^(\w+)(?::(\d+))?$/
function parse(string) {
const matches = PARSER.exec(string)
if (!matches) throw new Error(`Invalid offset key string "${string}".`)
if (!matches) {
throw new Error(`Invalid offset key string "${string}".`)
}
const [ original, key, index ] = matches // eslint-disable-line no-unused-vars
return {
key,

View File

@@ -24,7 +24,7 @@ function setEventTransfer(event, type, content) {
const mime = TRANSFER_TYPES[type.toUpperCase()]
if (!mime) {
throw new Error(`Cannot set unknown transfer type "${mime}"`)
throw new Error(`Cannot set unknown transfer type "${mime}".`)
}
if (event.nativeEvent) {

View File

@@ -1,5 +1,4 @@
import logger from 'slate-dev-logger'
import { Stack } from 'slate'
/**
@@ -40,18 +39,6 @@ class Simulator {
this.props = props
this.stack = stack
this.value = value
if (props.state) {
logger.deprecate('slate-simulator@0.3.0', 'The `state` prop has been renamed to `value`.')
this.value = props.state
}
Object.defineProperty(this, 'state', {
get() {
logger.deprecate('slate-simulator@0.3.0', 'The `simulator.state` property has been renamed to `simulator.value`.')
return this.value
}
})
}
}

View File

@@ -1,6 +1,5 @@
import isEmpty from 'is-empty'
import logger from 'slate-dev-logger'
import pick from 'lodash/pick'
import Range from '../models/range'
@@ -324,7 +323,7 @@ const PROXY_TRANSFORMS = [
'moveStart',
'moveStartOffsetTo',
'moveStartTo',
// 'moveTo', Commented out for now, since it conflicts with a deprecated one.
'moveTo',
'moveToEnd',
'moveToEndOf',
'moveToRangeOf',
@@ -411,72 +410,6 @@ PREFIXES.forEach((prefix) => {
})
})
/**
* Set `properties` on the selection.
*
* @param {Mixed} ...args
* @param {Change} change
*/
Changes.moveTo = (change, properties) => {
logger.deprecate('0.17.0', 'The `moveTo()` change is deprecated, please use `select()` instead.')
change.select(properties)
}
/**
* Unset the selection's marks.
*
* @param {Change} change
*/
Changes.unsetMarks = (change) => {
logger.deprecate('0.17.0', 'The `unsetMarks()` change is deprecated.')
change.select({ marks: null })
}
/**
* Unset the selection, removing an association to a node.
*
* @param {Change} change
*/
Changes.unsetSelection = (change) => {
logger.deprecate('0.17.0', 'The `unsetSelection()` change is deprecated, please use `deselect()` instead.')
change.select({
anchorKey: null,
anchorOffset: 0,
focusKey: null,
focusOffset: 0,
isFocused: false,
isBackward: false
})
}
/**
* Mix in deprecated changes with a warning.
*/
const DEPRECATED_TRANSFORMS = [
['extendBackward', 'extend', 'The `extendBackward(n)` change is deprecated, please use `extend(n)` instead with a negative offset.'],
['extendForward', 'extend', 'The `extendForward(n)` change is deprecated, please use `extend(n)` instead.'],
['moveBackward', 'move', 'The `moveBackward(n)` change is deprecated, please use `move(n)` instead with a negative offset.'],
['moveForward', 'move', 'The `moveForward(n)` change is deprecated, please use `move(n)` instead.'],
['moveStartOffset', 'moveStart', 'The `moveStartOffset(n)` change is deprecated, please use `moveStart(n)` instead.'],
['moveEndOffset', 'moveEnd', 'The `moveEndOffset(n)` change is deprecated, please use `moveEnd()` instead.'],
['moveToOffsets', 'moveOffsetsTo', 'The `moveToOffsets()` change is deprecated, please use `moveOffsetsTo()` instead.'],
['flipSelection', 'flip', 'The `flipSelection()` change is deprecated, please use `flip()` instead.'],
]
DEPRECATED_TRANSFORMS.forEach(([ old, current, warning ]) => {
Changes[old] = (change, ...args) => {
logger.deprecate('0.17.0', warning)
const { value } = change
const { document, selection } = value
const sel = selection[current](...args).normalize(document)
change.select(sel)
}
})
/**
* Export.
*

View File

@@ -1,6 +1,4 @@
import logger from 'slate-dev-logger'
import Value from '../models/value'
/**
@@ -29,20 +27,6 @@ Changes.setValue = (change, properties) => {
})
}
/**
* Deprecated.
*/
Changes.setState = (change, ...args) => {
logger.deprecate('0.29.0', 'The `change.setState` method has been renamed to `change.setValue`.')
change.setValue(...args)
}
Changes.setData = (change, data) => {
logger.deprecate('0.26.0', 'The `change.setData` method is deprecated, use `change.setValue` instead.')
change.setValue({ data })
}
/**
* Export.
*

View File

@@ -12,9 +12,7 @@ import Node from './models/node'
import Operations from './operations'
import Range from './models/range'
import Schema from './models/schema'
import Selection from './models/selection'
import Stack from './models/stack'
import State from './models/state'
import Text from './models/text'
import Value from './models/value'
import { resetKeyGenerator, setKeyGenerator } from './utils/generate-key'
@@ -39,9 +37,7 @@ export {
Operations,
Range,
Schema,
Selection,
Stack,
State,
Text,
Value,
resetKeyGenerator,
@@ -62,9 +58,7 @@ export default {
Operations,
Range,
Schema,
Selection,
Stack,
State,
Text,
Value,
resetKeyGenerator,

View File

@@ -1,6 +1,5 @@
import Debug from 'debug'
import logger from 'slate-dev-logger'
import pick from 'lodash/pick'
import MODEL_TYPES from '../constants/model-types'
@@ -42,13 +41,7 @@ class Change {
*/
constructor(attrs) {
let { value } = attrs
if (!value && attrs.state) {
logger.deprecate('0.29.0', 'The `state` attribute to change objects has been renamed to `value`.')
value = attrs.state
}
const { value } = attrs
this.value = value
this.operations = []
this.flags = pick(attrs, ['merge', 'save'])
@@ -156,20 +149,6 @@ class Change {
return this
}
/**
* Deprecated.
*/
get state() {
logger.deprecate('0.29.0', 'The `change.state` property has been renamed to `change.value`.')
return this.value
}
apply(options = {}) {
logger.deprecate('0.22.0', 'The `change.apply()` method is deprecrated and no longer necessary, as all operations are applied immediately when invoked. You can access the change\'s value, which is already pre-computed, directly via `change.value` instead.')
return this.value
}
}
/**
@@ -190,60 +169,6 @@ Object.keys(Changes).forEach((type) => {
}
})
/**
* Add deprecation warnings in case people try to access a change as a value.
*/
;[
'hasUndos',
'hasRedos',
'isBlurred',
'isFocused',
'isCollapsed',
'isExpanded',
'isBackward',
'isForward',
'startKey',
'endKey',
'startOffset',
'endOffset',
'anchorKey',
'focusKey',
'anchorOffset',
'focusOffset',
'startBlock',
'endBlock',
'anchorBlock',
'focusBlock',
'startInline',
'endInline',
'anchorInline',
'focusInline',
'startText',
'endText',
'anchorText',
'focusText',
'characters',
'marks',
'blocks',
'fragment',
'inlines',
'texts',
'isEmpty',
].forEach((getter) => {
Object.defineProperty(Change.prototype, getter, {
get() {
logger.deprecate('0.22.0', `You attempted to access the \`${getter}\` property of what was previously a \`value\` object but is now a \`change\` object. This syntax has been deprecated as plugins are now passed \`change\` objects instead of \`value\` objects.`)
return this.value[getter]
}
})
})
Change.prototype.transform = function () {
logger.deprecate('0.22.0', 'You attempted to call `.transform()` on what was previously a `value` object but is now already a `change` object. This syntax has been deprecated as plugins are now passed `change` objects instead of `value` objects.')
return this
}
/**
* Export.
*

View File

@@ -1,6 +1,5 @@
import isPlainObject from 'is-plain-object'
import logger from 'slate-dev-logger'
import { List, Record, Set } from 'immutable'
import MODEL_TYPES from '../constants/model-types'
@@ -120,15 +119,6 @@ class Character extends Record(DEFAULTS) {
return List.isList(any) && any.every(item => Character.isCharacter(item))
}
/**
* Deprecated.
*/
static createListFromText(string) {
logger.deprecate('0.22.0', 'The `Character.createListFromText(string)` method is deprecated, use `Character.createList(string)` instead.')
return this.createList(string)
}
/**
* Get the kind.
*

View File

@@ -1,7 +1,6 @@
import direction from 'direction'
import isPlainObject from 'is-plain-object'
import logger from 'slate-dev-logger'
import { List, OrderedSet, Set } from 'immutable'
import Block from './block'
@@ -163,8 +162,8 @@ class Node {
*/
areDescendantsSorted(first, second) {
first = normalizeKey(first)
second = normalizeKey(second)
first = assertKey(first)
second = assertKey(second)
const keys = this.getKeysAsArray()
const firstIndex = keys.indexOf(first)
@@ -185,7 +184,7 @@ class Node {
const child = this.getChild(key)
if (!child) {
key = normalizeKey(key)
key = assertKey(key)
throw new Error(`Could not find a child node with key "${key}".`)
}
@@ -203,7 +202,7 @@ class Node {
const descendant = this.getDescendant(key)
if (!descendant) {
key = normalizeKey(key)
key = assertKey(key)
throw new Error(`Could not find a descendant node with key "${key}".`)
}
@@ -221,7 +220,7 @@ class Node {
const node = this.getNode(key)
if (!node) {
key = normalizeKey(key)
key = assertKey(key)
throw new Error(`Could not find a node with key "${key}".`)
}
@@ -315,7 +314,7 @@ class Node {
*/
getAncestors(key) {
key = normalizeKey(key)
key = assertKey(key)
if (key == this.key) return List()
if (this.hasChild(key)) return List([this])
@@ -497,7 +496,7 @@ class Node {
*/
getChild(key) {
key = normalizeKey(key)
key = assertKey(key)
return this.nodes.find(node => node.key == key)
}
@@ -510,7 +509,7 @@ class Node {
*/
getClosest(key, iterator) {
key = normalizeKey(key)
key = assertKey(key)
const ancestors = this.getAncestors(key)
if (!ancestors) {
throw new Error(`Could not find a descendant node with key "${key}".`)
@@ -562,8 +561,8 @@ class Node {
*/
getCommonAncestor(one, two) {
one = normalizeKey(one)
two = normalizeKey(two)
one = assertKey(one)
two = assertKey(two)
if (one == this.key) return this
if (two == this.key) return this
@@ -622,7 +621,7 @@ class Node {
*/
getDescendant(key) {
key = normalizeKey(key)
key = assertKey(key)
let descendantFound = null
const found = this.nodes.find((node) => {
@@ -751,7 +750,7 @@ class Node {
getFurthest(key, iterator) {
const ancestors = this.getAncestors(key)
if (!ancestors) {
key = normalizeKey(key)
key = assertKey(key)
throw new Error(`Could not find a descendant node with key "${key}".`)
}
@@ -789,7 +788,7 @@ class Node {
*/
getFurthestAncestor(key) {
key = normalizeKey(key)
key = assertKey(key)
return this.nodes.find((node) => {
if (node.key == key) return true
if (node.kind == 'text') return false
@@ -808,7 +807,7 @@ class Node {
const ancestors = this.getAncestors(key)
if (!ancestors) {
key = normalizeKey(key)
key = assertKey(key)
throw new Error(`Could not find a descendant node with key "${key}".`)
}
@@ -1181,7 +1180,7 @@ class Node {
*/
getNextSibling(key) {
key = normalizeKey(key)
key = assertKey(key)
const parent = this.getParent(key)
const after = parent.nodes
@@ -1201,7 +1200,7 @@ class Node {
*/
getNextText(key) {
key = normalizeKey(key)
key = assertKey(key)
return this.getTexts()
.skipUntil(text => text.key == key)
.get(1)
@@ -1215,7 +1214,7 @@ class Node {
*/
getNode(key) {
key = normalizeKey(key)
key = assertKey(key)
return this.key == key ? this : this.getDescendant(key)
}
@@ -1362,7 +1361,7 @@ class Node {
*/
getPreviousSibling(key) {
key = normalizeKey(key)
key = assertKey(key)
const parent = this.getParent(key)
const before = parent.nodes
.takeUntil(child => child.key == key)
@@ -1382,7 +1381,7 @@ class Node {
*/
getPreviousText(key) {
key = normalizeKey(key)
key = assertKey(key)
return this.getTexts()
.takeUntil(text => text.key == key)
.last()
@@ -1789,7 +1788,7 @@ class Node {
*/
removeDescendant(key) {
key = normalizeKey(key)
key = assertKey(key)
let node = this
let parent = node.getParent(key)
@@ -1892,181 +1891,18 @@ class Node {
return schema.validateNode(this)
}
/**
* True if the node has both descendants in that order, false otherwise. The
* order is depth-first, post-order.
*
* @param {String} first
* @param {String} second
* @return {Boolean}
*/
areDescendantSorted(first, second) {
logger.deprecate('0.19.0', 'The Node.areDescendantSorted(first, second) method is deprecated, please use `Node.areDescendantsSorted(first, second) instead.')
return this.areDescendantsSorted(first, second)
}
/**
* Concat children `nodes` on to the end of the node.
* Assert a key `arg`.
*
* @param {List<Node>} nodes
* @return {Node}
*/
concatChildren(nodes) {
logger.deprecate('0.19.0', 'The `Node.concatChildren(nodes)` method is deprecated.')
nodes = this.nodes.concat(nodes)
return this.set('nodes', nodes)
}
/**
* Decorate all of the text nodes with a `decorator` function.
*
* @param {Function} decorator
* @return {Node}
*/
decorateTexts(decorator) {
logger.deprecate('0.19.0', 'The `Node.decorateTexts(decorator) method is deprecated.')
return this.mapDescendants((child) => {
return child.kind == 'text'
? child.decorateCharacters(decorator)
: child
})
}
/**
* Recursively filter all descendant nodes with `iterator`, depth-first.
* It is different from `filterDescendants` in regard of the order of results.
*
* @param {Function} iterator
* @return {List<Node>}
*/
filterDescendantsDeep(iterator) {
logger.deprecate('0.19.0', 'The Node.filterDescendantsDeep(iterator) method is deprecated.')
return this.nodes.reduce((matches, child, i, nodes) => {
if (child.kind != 'text') matches = matches.concat(child.filterDescendantsDeep(iterator))
if (iterator(child, i, nodes)) matches = matches.push(child)
return matches
}, new List())
}
/**
* Recursively find all descendant nodes by `iterator`. Depth first.
*
* @param {Function} iterator
* @return {Node|Null}
*/
findDescendantDeep(iterator) {
logger.deprecate('0.19.0', 'The Node.findDescendantDeep(iterator) method is deprecated.')
let found
this.forEachDescendant((node) => {
if (iterator(node)) {
found = node
return false
}
})
return found
}
/**
* Get children between two child keys.
*
* @param {String} start
* @param {String} end
* @return {Node}
*/
getChildrenBetween(start, end) {
logger.deprecate('0.19.0', 'The `Node.getChildrenBetween(start, end)` method is deprecated.')
start = this.assertChild(start)
start = this.nodes.indexOf(start)
end = this.assertChild(end)
end = this.nodes.indexOf(end)
return this.nodes.slice(start + 1, end)
}
/**
* Get children between two child keys, including the two children.
*
* @param {String} start
* @param {String} end
* @return {Node}
*/
getChildrenBetweenIncluding(start, end) {
logger.deprecate('0.19.0', 'The `Node.getChildrenBetweenIncluding(start, end)` method is deprecated.')
start = this.assertChild(start)
start = this.nodes.indexOf(start)
end = this.assertChild(end)
end = this.nodes.indexOf(end)
return this.nodes.slice(start, end + 1)
}
/**
* Get the highest child ancestor of a node by `key`.
*
* @param {String} key
* @return {Node|Null}
*/
getHighestChild(key) {
logger.deprecate('0.19.0', 'The `Node.getHighestChild(key) method is deprecated, please use `Node.getFurthestAncestor(key) instead.')
return this.getFurthestAncestor(key)
}
/**
* Get the highest parent of a node by `key` which has an only child.
*
* @param {String} key
* @return {Node|Null}
*/
getHighestOnlyChildParent(key) {
logger.deprecate('0.19.0', 'The `Node.getHighestOnlyChildParent(key)` method is deprecated, please use `Node.getFurthestOnlyChildAncestor` instead.')
return this.getFurthestOnlyChildAncestor(key)
}
/**
* Check if the inline nodes are split at a `range`.
*
* @param {Range} range
* @return {Boolean}
*/
isInlineSplitAtRange(range) {
logger.deprecate('0.19.0', 'The `Node.isInlineSplitAtRange(range)` method is deprecated.')
range = range.normalize(this)
if (range.isExpanded) throw new Error()
const { startKey } = range
const start = this.getFurthestInline(startKey) || this.getDescendant(startKey)
return range.isAtStartOf(start) || range.isAtEndOf(start)
}
}
/**
* Normalize a key `arg`.
*
* @param {String|Node} arg
* @param {String} arg
* @return {String}
*/
function normalizeKey(arg) {
function assertKey(arg) {
if (typeof arg == 'string') return arg
logger.deprecate('0.14.0', 'An object was passed to a Node method instead of a `key` string. This was previously supported, but is being deprecated because it can have a negative impact on performance. The object in question was:', arg)
if (Node.isNode(arg)) {
return arg.key
}
throw new Error(`Invalid \`key\` argument! It must be either a block, an inline, a text, or a string. You passed: ${arg}`)
throw new Error(`Invalid \`key\` argument! It must be a key string, but you passed: ${arg}`)
}
/**
@@ -2109,8 +1945,6 @@ memoize(Node.prototype, [
'getCharactersAtRange',
'getCharactersAtRangeAsArray',
'getChild',
'getChildrenBetween',
'getChildrenBetweenIncluding',
'getClosestBlock',
'getClosestInline',
'getClosestVoid',
@@ -2154,7 +1988,6 @@ memoize(Node.prototype, [
'hasDescendant',
'hasNode',
'hasVoidParent',
'isInlineSplitAtRange',
'validate',
], {
takesArguments: true

View File

@@ -761,126 +761,6 @@ class Range extends Record(DEFAULTS) {
return this.toJSON()
}
/**
* Unset the range.
*
* @return {Range}
*/
unset() {
logger.deprecate('0.17.0', 'The `Range.unset` method is deprecated, please switch to using `Range.deselect` instead.')
return this.deselect()
}
/**
* Move the range forward `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
moveForward(n = 1) {
logger.deprecate('0.17.0', 'The `Range.moveForward(n)` method is deprecated, please switch to using `Range.move(n)` instead.')
return this.move(n)
}
/**
* Move the range backward `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
moveBackward(n = 1) {
logger.deprecate('0.17.0', 'The `Range.moveBackward(n)` method is deprecated, please switch to using `Range.move(-n)` (with a negative number) instead.')
return this.move(0 - n)
}
/**
* Move the anchor offset `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
moveAnchorOffset(n = 1) {
logger.deprecate('0.17.0', 'The `Range.moveAnchorOffset(n)` method is deprecated, please switch to using `Range.moveAnchor(n)` instead.')
return this.moveAnchor(n)
}
/**
* Move the focus offset `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
moveFocusOffset(n = 1) {
logger.deprecate('0.17.0', 'The `Range.moveFocusOffset(n)` method is deprecated, please switch to using `Range.moveFocus(n)` instead.')
return this.moveFocus(n)
}
/**
* Move the start offset `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
moveStartOffset(n = 1) {
logger.deprecate('0.17.0', 'The `Range.moveStartOffset(n)` method is deprecated, please switch to using `Range.moveStart(n)` instead.')
return this.moveStart(n)
}
/**
* Move the focus offset `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
moveEndOffset(n = 1) {
logger.deprecate('0.17.0', 'The `Range.moveEndOffset(n)` method is deprecated, please switch to using `Range.moveEnd(n)` instead.')
return this.moveEnd(n)
}
/**
* Extend the focus point forward `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
extendForward(n = 1) {
logger.deprecate('0.17.0', 'The `Range.extendForward(n)` method is deprecated, please switch to using `Range.extend(n)` instead.')
return this.extend(n)
}
/**
* Extend the focus point backward `n` characters.
*
* @param {Number} n (optional)
* @return {Range}
*/
extendBackward(n = 1) {
logger.deprecate('0.17.0', 'The `Range.extendBackward(n)` method is deprecated, please switch to using `Range.extend(-n)` (with a negative number) instead.')
return this.extend(0 - n)
}
/**
* Move the range to `anchorOffset` and `focusOffset`.
*
* @param {Number} anchorOffset
* @param {Number} focusOffset (optional)
* @return {Range}
*/
moveToOffsets(anchorOffset, focusOffset = anchorOffset) {
logger.deprecate('0.17.0', 'The `Range.moveToOffsets` method is deprecated, please switch to using `Range.moveOffsetsTo` instead.')
return this.moveOffsetsTo(anchorOffset, focusOffset)
}
}
/**

View File

@@ -1,50 +0,0 @@
import logger from 'slate-dev-logger'
import Range from './range'
/**
* Deprecated.
*/
const Selection = {
create(...args) {
logger.deprecate('0.27.0', 'The `Selection` model has been renamed to `Range`.')
return Range.create(...args)
},
createList(...args) {
logger.deprecate('0.27.0', 'The `Selection` model has been renamed to `Range`.')
return Range.createList(...args)
},
createProperties(...args) {
logger.deprecate('0.27.0', 'The `Selection` model has been renamed to `Range`.')
return Range.createProperties(...args)
},
fromJSON(...args) {
logger.deprecate('0.27.0', 'The `Selection` model has been renamed to `Range`.')
return Range.fromJSON(...args)
},
fromJS(...args) {
logger.deprecate('0.27.0', 'The `Selection` model has been renamed to `Range`.')
return Range.fromJS(...args)
},
isSelection(...args) {
logger.deprecate('0.27.0', 'The `Selection` model has been renamed to `Range`.')
return Range.isRange(...args)
},
}
/**
* Export.
*
* @type {Object}
*/
export default Selection

View File

@@ -1,50 +0,0 @@
import logger from 'slate-dev-logger'
import Value from './value'
/**
* Deprecated.
*/
const State = {
create(...args) {
logger.deprecate('0.29.0', 'The `State` model has been renamed to `Value`.')
return Value.create(...args)
},
createList(...args) {
logger.deprecate('0.29.0', 'The `State` model has been renamed to `Value`.')
return Value.createList(...args)
},
createProperties(...args) {
logger.deprecate('0.29.0', 'The `State` model has been renamed to `Value`.')
return Value.createProperties(...args)
},
fromJSON(...args) {
logger.deprecate('0.29.0', 'The `State` model has been renamed to `Value`.')
return Value.fromJSON(...args)
},
fromJS(...args) {
logger.deprecate('0.29.0', 'The `State` model has been renamed to `Value`.')
return Value.fromJS(...args)
},
isState(...args) {
logger.deprecate('0.29.0', 'The `State` model has been renamed to `Value`.')
return Value.isValue(...args)
},
}
/**
* Export.
*
* @type {Object}
*/
export default State

View File

@@ -1,6 +1,5 @@
import isPlainObject from 'is-plain-object'
import logger from 'slate-dev-logger'
import { List, OrderedSet, Record, Set, is } from 'immutable'
import Character from './character'
@@ -85,21 +84,11 @@ class Text extends Record(DEFAULTS) {
return object
}
let {
const {
leaves = [],
key = generateKey(),
} = object
if (object.ranges) {
logger.deprecate('0.27.0', 'Passing `object.ranges` to `Text.fromJSON` has been renamed to `object.leaves`.')
leaves = object.ranges
}
if (object.text) {
logger.deprecate('0.23.0', 'Passing `object.text` to `Text.fromJSON` has been deprecated, please use `object.leaves` instead.')
leaves = [{ text: object.text }]
}
const characters = leaves
.map(Leaf.fromJSON)
.reduce((l, r) => l.concat(r.getCharacters()), new List())
@@ -140,24 +129,6 @@ class Text extends Record(DEFAULTS) {
return List.isList(any) && any.every(item => Text.isText(item))
}
/**
* Deprecated.
*/
static createFromString(string) {
logger.deprecate('0.22.0', 'The `Text.createFromString(string)` method is deprecated, use `Text.create(string)` instead.')
return Text.create(string)
}
/**
* Deprecated.
*/
static createFromRanges(ranges) {
logger.deprecate('0.22.0', 'The `Text.createFromRanges(ranges)` method is deprecated, use `Text.create(ranges)` instead.')
return Text.create(ranges)
}
/**
* Get the node's kind.
*
@@ -516,15 +487,6 @@ class Text extends Record(DEFAULTS) {
return schema.validateNode(this)
}
/**
* Deprecated.
*/
getRanges(...args) {
logger.deprecate('0.27.0', 'The `Text.getRanges()` method was renamed to `Text.getLeaves`.')
return this.getLeaves(...args)
}
}
/**

View File

@@ -1,6 +1,5 @@
import isPlainObject from 'is-plain-object'
import logger from 'slate-dev-logger'
import { Record, Set, List, Map } from 'immutable'
import MODEL_TYPES from '../constants/model-types'
@@ -620,17 +619,6 @@ class Value extends Record(DEFAULTS) {
return new Change({ ...attrs, value: this })
}
/**
* Deprecated.
*
* @return {Change}
*/
transform(...args) {
logger.deprecate('0.22.0', 'The `value.transform()` method has been deprecated in favor of `value.change()`.')
return this.change(...args)
}
/**
* Return a JSON representation of the value.
*
@@ -644,11 +632,6 @@ class Value extends Record(DEFAULTS) {
document: this.document.toJSON(options),
}
if ('preserveStateData' in options) {
logger.deprecate('0.26.0', 'The `preserveStateData` option to `value.toJSON` has been deprecated in favor of `options.preserveData`.')
options.preserveData = options.preserveStateData
}
if (options.preserveData) {
object.data = this.data.toJSON()
}

View File

@@ -1,6 +1,5 @@
import Debug from 'debug'
import logger from 'slate-dev-logger'
import Node from '../models/node'
import Mark from '../models/mark'
@@ -342,15 +341,9 @@ const APPLIERS = {
let { document } = value
let node = document.assertPath(path)
if ('nodes' in properties) {
logger.warn('Updating a Node\'s `nodes` property via `setNode()` is not allowed. Use the appropriate insertion and removal methods instead. The operation in question was:', operation)
// Delete properties that are not allowed to be updated.
delete properties.nodes
}
if ('key' in properties) {
logger.warn('Updating a Node\'s `key` property via `setNode()` is not allowed. There should be no reason to do this. The operation in question was:', operation)
delete properties.key
}
node = node.merge(properties)
document = document.updateNode(node)
@@ -405,20 +398,10 @@ const APPLIERS = {
set_value(value, operation) {
const { properties } = operation
if ('document' in properties) {
logger.warn('Updating `value.document` property via `setValue()` is not allowed. Use the appropriate document updating methods instead. The operation in question was:', operation)
// Delete properties that are not allowed to be updated.
delete properties.document
}
if ('selection' in properties) {
logger.warn('Updating `value.selection` property via `setValue()` is not allowed. Use the appropriate selection updating methods instead. The operation in question was:', operation)
delete properties.selection
}
if ('history' in properties) {
logger.warn('Updating `value.history` property via `setValue()` is not allowed. Use the appropriate history updating methods instead. The operation in question was:', operation)
delete properties.history
}
value = value.merge(properties)
return value