1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 08:34:28 +02: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 return
} }
let child = node.getFirstInvalidDescendant(schema) let child = node.getFirstInvalidNode(schema)
let path = change.value.document.getPath(node.key) let path = change.value.document.getPath(node.key)
while (node && child) { while (node && child) {
@@ -136,7 +136,7 @@ function normalizeNodeAndChildren(change, node, schema) {
child = null child = null
} else { } else {
path = change.value.document.refindPath(path, node.key) 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} * @return {Node|Text|Null}
*/ */
getFirstInvalidDescendant(schema) { getFirstInvalidNode(schema) {
let result = null let result = null
this.nodes.find(n => { this.nodes.find(n => {
result = n.validate(schema) ? n : n.getFirstInvalidDescendant(schema) result = n.validate(schema) ? n : n.getFirstInvalidNode(schema)
return result return result
}) })
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. * Get the first child text node.
* *
@@ -2164,7 +2173,7 @@ memoize(NodeInterface.prototype, [
'getBlocksAtRangeAsArray', 'getBlocksAtRangeAsArray',
'getBlocksByTypeAsArray', 'getBlocksByTypeAsArray',
'getDecorations', 'getDecorations',
'getFirstInvalidDescendant', 'getFirstInvalidNode',
'getFirstText', 'getFirstText',
'getFragmentAtRange', 'getFragmentAtRange',
'getInlinesAsArray', 'getInlinesAsArray',

View File

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