mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 10:14:02 +02:00
refactor node methods, memoize more, update history
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }],
|
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }],
|
||||||
"arrow-spacing": "error",
|
"arrow-spacing": "error",
|
||||||
"block-spacing": "error",
|
"block-spacing": "error",
|
||||||
"capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }],
|
"capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true, "ignoreInlineComments": true }],
|
||||||
"comma-dangle": ["error", "only-multiline"],
|
"comma-dangle": ["error", "only-multiline"],
|
||||||
"comma-spacing": ["error", { "before": false, "after": true }],
|
"comma-spacing": ["error", { "before": false, "after": true }],
|
||||||
"comma-style": ["error", "last"],
|
"comma-style": ["error", "last"],
|
||||||
|
25
History.md
25
History.md
@@ -2,6 +2,29 @@
|
|||||||
This document maintains a list of changes to Slate with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and non-breaking changes won't be accounted for since the library is moving quickly.
|
This document maintains a list of changes to Slate with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and non-breaking changes won't be accounted for since the library is moving quickly.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### `0.19.0` — March 3, 2017
|
||||||
|
|
||||||
|
###### BREAKING CHANGES
|
||||||
|
|
||||||
|
- **The `filterDescendants` and `findDescendants` methods are now depth-first. This shouldn't affect almost anyone, since they are usually not the best things to be using for performance reasons. If you happen to have a very specific use case that needs breadth-first, (or even likely something better), you'll need to implement it yourself.
|
||||||
|
|
||||||
|
###### DEPRECATION CHANGES
|
||||||
|
|
||||||
|
- **Some `Node` methods have been deprecated!** There were a few methods that had been added over time that were either poorly named that have been deprecated and renamed, and a handful of methods that are no longer useful for the core library that have been deprecated. Here's a full list:
|
||||||
|
- `areDescendantSorted` -> `areDescendantsSorted`
|
||||||
|
- `getHighestChild` -> `getFurthestAncestor`
|
||||||
|
- `getHighestOnlyChildParent` -> `getFurthestOnlyChildAncestor`
|
||||||
|
- `concatChildren`
|
||||||
|
- `decorateTexts`
|
||||||
|
- `filterDescendantsDeep`
|
||||||
|
- `findDescendantDeep`
|
||||||
|
- `getChildrenBetween`
|
||||||
|
- `getChildrenBetweenIncluding`
|
||||||
|
- `isInlineSplitAtRange`
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +42,7 @@ This document maintains a list of changes to Slate with each new version. Until
|
|||||||
|
|
||||||
###### DEPRECATION CHANGES
|
###### DEPRECATION CHANGES
|
||||||
|
|
||||||
- **Some selection methods have been deprecated!** Previously there were many inconsistencies in the naming and handling of selection changes. This has all been cleaned up, but in the process some methods have been deprecated. Here is a full list of the deprecated methods and their new alternatives:
|
- **Some `Selection` methods have been deprecated!** Previously there were many inconsistencies in the naming and handling of selection changes. This has all been cleaned up, but in the process some methods have been deprecated. Here is a full list of the deprecated methods and their new alternatives:
|
||||||
- `moveToOffsets` -> `moveOffsetsTo`
|
- `moveToOffsets` -> `moveOffsetsTo`
|
||||||
- `moveForward` -> `move`
|
- `moveForward` -> `move`
|
||||||
- `moveBackward` -> `move`
|
- `moveBackward` -> `move`
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -601,7 +601,7 @@ class Selection extends new Record(DEFAULTS) {
|
|||||||
if (anchorNode.key === focusNode.key) {
|
if (anchorNode.key === focusNode.key) {
|
||||||
isBackward = anchorOffset > focusOffset
|
isBackward = anchorOffset > focusOffset
|
||||||
} else {
|
} else {
|
||||||
isBackward = !node.areDescendantSorted(anchorNode.key, focusNode.key)
|
isBackward = !node.areDescendantsSorted(anchorNode.key, focusNode.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -378,6 +378,7 @@ class Text extends new Record(DEFAULTS) {
|
|||||||
memoize(Text.prototype, [
|
memoize(Text.prototype, [
|
||||||
'getDecorations',
|
'getDecorations',
|
||||||
'getDecorators',
|
'getDecorators',
|
||||||
|
'getMarksAtIndex',
|
||||||
'getRanges',
|
'getRanges',
|
||||||
'validate'
|
'validate'
|
||||||
])
|
])
|
||||||
|
@@ -82,8 +82,8 @@ Transforms.deleteAtRange = (transform, range, options = {}) => {
|
|||||||
let { state } = transform
|
let { state } = transform
|
||||||
let { document } = state
|
let { document } = state
|
||||||
let ancestor = document.getCommonAncestor(startKey, endKey)
|
let ancestor = document.getCommonAncestor(startKey, endKey)
|
||||||
let startChild = ancestor.getHighestChild(startKey)
|
let startChild = ancestor.getFurthestAncestor(startKey)
|
||||||
let endChild = ancestor.getHighestChild(endKey)
|
let endChild = ancestor.getFurthestAncestor(endKey)
|
||||||
const startOff = (startChild.kind == 'text' ? 0 : startChild.getOffset(startKey)) + startOffset
|
const startOff = (startChild.kind == 'text' ? 0 : startChild.getOffset(startKey)) + startOffset
|
||||||
const endOff = (endChild.kind == 'text' ? 0 : endChild.getOffset(endKey)) + endOffset
|
const endOff = (endChild.kind == 'text' ? 0 : endChild.getOffset(endKey)) + endOffset
|
||||||
|
|
||||||
@@ -94,8 +94,8 @@ Transforms.deleteAtRange = (transform, range, options = {}) => {
|
|||||||
state = transform.state
|
state = transform.state
|
||||||
document = state.document
|
document = state.document
|
||||||
ancestor = document.getCommonAncestor(startKey, endKey)
|
ancestor = document.getCommonAncestor(startKey, endKey)
|
||||||
startChild = ancestor.getHighestChild(startKey)
|
startChild = ancestor.getFurthestAncestor(startKey)
|
||||||
endChild = ancestor.getHighestChild(endKey)
|
endChild = ancestor.getFurthestAncestor(endKey)
|
||||||
const startIndex = ancestor.nodes.indexOf(startChild)
|
const startIndex = ancestor.nodes.indexOf(startChild)
|
||||||
const endIndex = ancestor.nodes.indexOf(endChild)
|
const endIndex = ancestor.nodes.indexOf(endChild)
|
||||||
const middles = ancestor.nodes.slice(startIndex + 1, endIndex + 1)
|
const middles = ancestor.nodes.slice(startIndex + 1, endIndex + 1)
|
||||||
@@ -120,7 +120,7 @@ Transforms.deleteAtRange = (transform, range, options = {}) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Remove parents of endBlock as long as they have a single child
|
// Remove parents of endBlock as long as they have a single child
|
||||||
const lonely = document.getHighestOnlyChildParent(endBlock.key) || endBlock
|
const lonely = document.getFurthestOnlyChildAncestor(endBlock.key) || endBlock
|
||||||
transform.removeNodeByKey(lonely.key, OPTS)
|
transform.removeNodeByKey(lonely.key, OPTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ Transforms.deleteBackwardAtRange = (transform, range, n = 1, options = {}) => {
|
|||||||
|
|
||||||
// If the focus node is inside a void, go up until right after it.
|
// If the focus node is inside a void, go up until right after it.
|
||||||
if (document.hasVoidParent(node.key)) {
|
if (document.hasVoidParent(node.key)) {
|
||||||
const parent = document.getClosest(node.key, p => p.isVoid)
|
const parent = document.getClosestVoid(node.key)
|
||||||
node = document.getNextText(parent.key)
|
node = document.getNextText(parent.key)
|
||||||
offset = 0
|
offset = 0
|
||||||
}
|
}
|
||||||
@@ -483,7 +483,7 @@ Transforms.deleteForwardAtRange = (transform, range, n = 1, options = {}) => {
|
|||||||
|
|
||||||
// If the focus node is inside a void, go up until right before it.
|
// If the focus node is inside a void, go up until right before it.
|
||||||
if (document.hasVoidParent(node.key)) {
|
if (document.hasVoidParent(node.key)) {
|
||||||
const parent = document.getClosest(node.key, p => p.isVoid)
|
const parent = document.getClosestVoid(node.key)
|
||||||
node = document.getPreviousText(parent.key)
|
node = document.getPreviousText(parent.key)
|
||||||
offset = node.length
|
offset = node.length
|
||||||
}
|
}
|
||||||
@@ -585,7 +585,7 @@ Transforms.insertFragmentAtRange = (transform, range, fragment, options = {}) =>
|
|||||||
let { document } = state
|
let { document } = state
|
||||||
let startText = document.getDescendant(startKey)
|
let startText = document.getDescendant(startKey)
|
||||||
let startBlock = document.getClosestBlock(startText.key)
|
let startBlock = document.getClosestBlock(startText.key)
|
||||||
let startChild = startBlock.getHighestChild(startText.key)
|
let startChild = startBlock.getFurthestAncestor(startText.key)
|
||||||
const isAtStart = range.isAtStartOf(startBlock)
|
const isAtStart = range.isAtStartOf(startBlock)
|
||||||
const parent = document.getParent(startBlock.key)
|
const parent = document.getParent(startBlock.key)
|
||||||
const index = parent.nodes.indexOf(startBlock)
|
const index = parent.nodes.indexOf(startBlock)
|
||||||
@@ -621,7 +621,7 @@ Transforms.insertFragmentAtRange = (transform, range, fragment, options = {}) =>
|
|||||||
document = state.document
|
document = state.document
|
||||||
startText = document.getDescendant(startKey)
|
startText = document.getDescendant(startKey)
|
||||||
startBlock = document.getClosestBlock(startKey)
|
startBlock = document.getClosestBlock(startKey)
|
||||||
startChild = startBlock.getHighestChild(startText.key)
|
startChild = startBlock.getFurthestAncestor(startText.key)
|
||||||
|
|
||||||
// If the first and last block aren't the same, we need to move any of the
|
// If the first and last block aren't the same, we need to move any of the
|
||||||
// starting block's children after the split into the last block of the
|
// starting block's children after the split into the last block of the
|
||||||
@@ -647,7 +647,7 @@ Transforms.insertFragmentAtRange = (transform, range, fragment, options = {}) =>
|
|||||||
// Otherwise, we maintain the starting block, and insert all of the first
|
// Otherwise, we maintain the starting block, and insert all of the first
|
||||||
// block's inline nodes into it at the split point.
|
// block's inline nodes into it at the split point.
|
||||||
else {
|
else {
|
||||||
const inlineChild = startBlock.getHighestChild(startText.key)
|
const inlineChild = startBlock.getFurthestAncestor(startText.key)
|
||||||
const inlineIndex = startBlock.nodes.indexOf(inlineChild)
|
const inlineIndex = startBlock.nodes.indexOf(inlineChild)
|
||||||
|
|
||||||
firstBlock.nodes.forEach((inline, i) => {
|
firstBlock.nodes.forEach((inline, i) => {
|
||||||
@@ -1149,8 +1149,8 @@ Transforms.wrapInlineAtRange = (transform, range, inline, options = {}) => {
|
|||||||
const blocks = document.getBlocksAtRange(range)
|
const blocks = document.getBlocksAtRange(range)
|
||||||
let startBlock = document.getClosestBlock(startKey)
|
let startBlock = document.getClosestBlock(startKey)
|
||||||
let endBlock = document.getClosestBlock(endKey)
|
let endBlock = document.getClosestBlock(endKey)
|
||||||
let startChild = startBlock.getHighestChild(startKey)
|
let startChild = startBlock.getFurthestAncestor(startKey)
|
||||||
const endChild = endBlock.getHighestChild(endKey)
|
const endChild = endBlock.getFurthestAncestor(endKey)
|
||||||
const startIndex = startBlock.nodes.indexOf(startChild)
|
const startIndex = startBlock.nodes.indexOf(startChild)
|
||||||
const endIndex = endBlock.nodes.indexOf(endChild)
|
const endIndex = endBlock.nodes.indexOf(endChild)
|
||||||
|
|
||||||
@@ -1174,7 +1174,7 @@ Transforms.wrapInlineAtRange = (transform, range, inline, options = {}) => {
|
|||||||
state = transform.state
|
state = transform.state
|
||||||
document = state.document
|
document = state.document
|
||||||
startBlock = document.getClosestBlock(startKey)
|
startBlock = document.getClosestBlock(startKey)
|
||||||
startChild = startBlock.getHighestChild(startKey)
|
startChild = startBlock.getFurthestAncestor(startKey)
|
||||||
|
|
||||||
const startInner = startOff == 0
|
const startInner = startOff == 0
|
||||||
? startChild
|
? startChild
|
||||||
@@ -1182,7 +1182,7 @@ Transforms.wrapInlineAtRange = (transform, range, inline, options = {}) => {
|
|||||||
|
|
||||||
const startInnerIndex = startBlock.nodes.indexOf(startInner)
|
const startInnerIndex = startBlock.nodes.indexOf(startInner)
|
||||||
|
|
||||||
const endInner = startKey == endKey ? startInner : startBlock.getHighestChild(endKey)
|
const endInner = startKey == endKey ? startInner : startBlock.getFurthestAncestor(endKey)
|
||||||
const inlines = startBlock.nodes
|
const inlines = startBlock.nodes
|
||||||
.skipUntil(n => n == startInner)
|
.skipUntil(n => n == startInner)
|
||||||
.takeUntil(n => n == endInner)
|
.takeUntil(n => n == endInner)
|
||||||
|
Reference in New Issue
Block a user