1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-01 05:16:10 +01:00

add deprecations

This commit is contained in:
Ian Storm Taylor 2018-08-22 15:41:04 -07:00
parent ec678540cf
commit 4dcbe1918a
3 changed files with 37 additions and 9 deletions

View File

@ -124,7 +124,7 @@ function normalizeNodeAndChildren(change, node, schema) {
return
}
let child = node.getFirstInvalidDescendant(schema)
let child = node.getFirstInvalidNode(schema)
let path = change.value.document.getPath(node.key)
while (node && child) {
@ -136,7 +136,7 @@ function normalizeNodeAndChildren(change, node, schema) {
child = null
} else {
path = change.value.document.refindPath(path, node.key)
child = node.getFirstInvalidDescendant(schema)
child = node.getFirstInvalidNode(schema)
}
}

View File

@ -501,17 +501,26 @@ class NodeInterface {
* @return {Node|Text|Null}
*/
getFirstInvalidDescendant(schema) {
getFirstInvalidNode(schema) {
let result = null
this.nodes.find(n => {
result = n.validate(schema) ? n : n.getFirstInvalidDescendant(schema)
result = n.validate(schema) ? n : n.getFirstInvalidNode(schema)
return result
})
return result
}
getFirstInvalidDescendant(schema) {
logger.deprecate(
'0.39.0',
'The `Node.getFirstInvalidDescendant` method is deprecated, please use `Node.getFirstInvalidNode` instead.'
)
return this.getFirstInvalidNode(schema)
}
/**
* Get the first child text node.
*
@ -2164,7 +2173,7 @@ memoize(NodeInterface.prototype, [
'getBlocksAtRangeAsArray',
'getBlocksByTypeAsArray',
'getDecorations',
'getFirstInvalidDescendant',
'getFirstInvalidNode',
'getFirstText',
'getFragmentAtRange',
'getInlinesAsArray',

View File

@ -166,6 +166,7 @@ class Text extends Record(DEFAULTS) {
*/
get isEmpty() {
logger.deprecate('0.39.0', 'The `Text.isEmpty` property is deprecated.')
return this.text == ''
}
@ -176,7 +177,7 @@ class Text extends Record(DEFAULTS) {
*/
get text() {
return this.getString()
return this.getText()
}
/**
@ -185,10 +186,19 @@ class Text extends Record(DEFAULTS) {
* @returns {String}
*/
getString() {
getText() {
return this.leaves.reduce((string, leaf) => string + leaf.text, '')
}
getString() {
logger.deprecate(
'0.39.0',
'The `Text.getString` property is deprecated, please use `Text.getText` instead.'
)
return this.getText()
}
/**
* Find the 'first' leaf at offset; By 'first' the alorighthm prefers `endOffset === offset` than `startOffset === offset`
* Corner Cases:
@ -739,10 +749,19 @@ class Text extends Record(DEFAULTS) {
* @returns {Text|Null}
*/
getFirstInvalidDescendant(schema) {
getFirstInvalidNode(schema) {
return this.validate(schema) ? this : null
}
getFirstInvalidDescendant(schema) {
logger.deprecate(
'0.39.0',
'The `Node.getFirstInvalidDescendant` method is deprecated, please use `Node.getFirstInvalidNode` instead.'
)
return this.getFirstInvalidNode(schema)
}
/**
* Set leaves with normalized `leaves`
*
@ -783,7 +802,7 @@ memoize(Text.prototype, [
'getMarksAsArray',
'normalize',
'validate',
'getString',
'getText',
'getKeysToPathsTable',
])