diff --git a/benchmark/slate/models/get-blocks-at-range.js b/benchmark/slate/models/get-leaf-blocks-at-range.js similarity index 91% rename from benchmark/slate/models/get-blocks-at-range.js rename to benchmark/slate/models/get-leaf-blocks-at-range.js index 21733495c..eff155203 100644 --- a/benchmark/slate/models/get-blocks-at-range.js +++ b/benchmark/slate/models/get-leaf-blocks-at-range.js @@ -4,7 +4,7 @@ const h = require('../../helpers/h') module.exports.default = function(value) { - value.document.getBlocksAtRange(value.selection) + value.document.getLeafBlocksAtRange(value.selection) } const value = ( diff --git a/benchmark/slate/models/get-inlines-at-range.js b/benchmark/slate/models/get-leaf-inlines-at-range.js similarity index 91% rename from benchmark/slate/models/get-inlines-at-range.js rename to benchmark/slate/models/get-leaf-inlines-at-range.js index ea519b625..79b00ce0a 100644 --- a/benchmark/slate/models/get-inlines-at-range.js +++ b/benchmark/slate/models/get-leaf-inlines-at-range.js @@ -4,7 +4,7 @@ const h = require('../../helpers/h') module.exports.default = function(value) { - value.document.getInlinesAtRange(value.selection) + value.document.getLeafInlinesAtRange(value.selection) } const value = ( diff --git a/docs/reference/slate/node.md b/docs/reference/slate/node.md index 250773695..2e759b270 100644 --- a/docs/reference/slate/node.md +++ b/docs/reference/slate/node.md @@ -61,9 +61,9 @@ Get the ancestors of a descendant by `path` or `key`. Get all of the bottom-most [`Block`](./block.md) node descendants. -### `getBlocksAtRange` +### `getLeafBlocksAtRange` -`getBlocksAtRange(range: Range) => List` +`getLeafBlocksAtRange(range: Range) => List` Get all of the bottom-most [`Block`](./block.md) nodes in a `range`. @@ -182,11 +182,11 @@ Get the furthest ancestor of a node by `path` or `key` that has only one child. Get all of the top-most [`Inline`](./inline.md) nodes in a node. -### `getInlinesAtRange` +### `getLeafInlinesAtRange` -`getInlinesAtRange(range: Range) => List` +`getLeafInlinesAtRange(range: Range) => List` -Get all of the top-most [`Inline`](./inline.md) nodes in a `range`. +Get all of the bottom-most [`Inline`](./inline.md) nodes in a `range`. ### `getInlinesByType` @@ -308,6 +308,18 @@ Get the previous sibling of a descendant by `path` or `key`. Get the previous [`Text`](./text.md) node before a descendant by `path` or `key`. +### `getRootBlocksAtRange` + +`getRootBlocksAtRange(range: Range) => List` + +Get all of the top-most [`Block`](./block.md) nodes in a `range`. + +### `getRootInlinesAtRange` + +`getRootInlinesAtRange(range: Range) => List` + +Get all of the top-most [`Inline`](./inline.md) nodes in a `range`. + ### `getTextAtOffset` `getTextAtOffset(offset: Number) => Text || Void` diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index c730a949d..94f16c27b 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -916,7 +916,7 @@ Commands.removeMarkAtRange = (editor, range, mark) => { Commands.setBlocksAtRange = (editor, range, properties) => { const { value } = editor const { document } = value - const blocks = document.getBlocksAtRange(range) + const blocks = document.getLeafBlocksAtRange(range) const { start, end, isCollapsed } = range const isStartVoid = document.hasVoidParent(start.key, editor) @@ -955,7 +955,7 @@ Commands.setBlocksAtRange = (editor, range, properties) => { Commands.setInlinesAtRange = (editor, range, properties) => { const { value } = editor const { document } = value - const inlines = document.getInlinesAtRange(range) + const inlines = document.getLeafInlinesAtRange(range) editor.withoutNormalizing(() => { inlines.forEach(inline => { @@ -1076,7 +1076,7 @@ Commands.unwrapBlockAtRange = (editor, range, properties) => { const { value } = editor let { document } = value - const blocks = document.getBlocksAtRange(range) + const blocks = document.getLeafBlocksAtRange(range) const wrappers = blocks .map(block => { return document.getClosest(block.key, parent => { @@ -1202,7 +1202,7 @@ Commands.wrapBlockAtRange = (editor, range, block) => { const { value } = editor const { document } = value - const blocks = document.getBlocksAtRange(range) + const blocks = document.getLeafBlocksAtRange(range) const firstblock = blocks.first() const lastblock = blocks.last() let parent, siblings, index @@ -1282,7 +1282,7 @@ Commands.wrapInlineAtRange = (editor, range, inline) => { inline = Inline.create(inline) inline = inline.set('nodes', inline.nodes.clear()) - const blocks = document.getBlocksAtRange(range) + const blocks = document.getLeafBlocksAtRange(range) let startBlock = document.getClosestBlock(start.key) let endBlock = document.getClosestBlock(end.key) const startInline = document.getClosestInline(start.key) diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js index d443be5db..8d26005d0 100644 --- a/packages/slate/src/interfaces/element.js +++ b/packages/slate/src/interfaces/element.js @@ -1,5 +1,6 @@ import direction from 'direction' import invariant from 'tiny-invariant' +import warning from 'tiny-warning' import { List, OrderedSet, Set, Stack } from 'immutable' import mixin from '../utils/mixin' @@ -275,34 +276,28 @@ class ElementInterface { */ getBlocksAtRange(range) { - const array = this.getBlocksAtRangeAsArray(range) - // Eliminate duplicates by converting to an `OrderedSet` first. - return List(OrderedSet(array)) + warning( + false, + 'As of slate@0.44 the `node.getBlocksAtRange` method has been renamed to `getLeafBlocksAtRange`.' + ) + + return this.getLeafBlocksAtRange(range) } /** - * Get the leaf block descendants in a `range` as an array + * Get the bottom-most block descendants in a `range` as an array * * @param {Range} range * @return {Array} */ getBlocksAtRangeAsArray(range) { - range = this.resolveRange(range) - if (range.isUnset) return [] + warning( + false, + 'As of slate@0.44 the `node.getBlocksAtRangeAsArray` method has been renamed to `getLeafBlocksAtRangeAsArray`.' + ) - const { start, end } = range - const startBlock = this.getClosestBlock(start.key) - - // PERF: the most common case is when the range is in a single block node, - // where we can avoid a lot of iterating of the tree. - if (start.key === end.key) return [startBlock] - - const endBlock = this.getClosestBlock(end.key) - const blocks = this.getBlocksAsArray() - const startIndex = blocks.indexOf(startBlock) - const endIndex = blocks.indexOf(endBlock) - return blocks.slice(startIndex, endIndex + 1) + return this.getLeafBlocksAtRangeAsArray(range) } /** @@ -640,35 +635,35 @@ class ElementInterface { } /** - * Get the closest inline nodes for each text node in a `range`. + * Get the bottom-most inline nodes for each text node in a `range`. * * @param {Range} range * @return {List} */ getInlinesAtRange(range) { - const array = this.getInlinesAtRangeAsArray(range) - // Remove duplicates by converting it to an `OrderedSet` first. - const list = List(OrderedSet(array)) - return list + warning( + false, + 'As of slate@0.44 the `node.getInlinesAtRange` method has been renamed to `getLeafInlinesAtRange`.' + ) + + return this.getLeafInlinesAtRange(range) } /** - * Get the closest inline nodes for each text node in a `range` as an array. + * Get the bottom-most inline nodes for each text node in a `range` as an array. * * @param {Range} range * @return {Array} */ getInlinesAtRangeAsArray(range) { - range = this.resolveRange(range) - if (range.isUnset) return [] + warning( + false, + 'As of slate@0.44 the `node.getInlinesAtRangeAsArray` method has been renamed to `getLeafInlinesAtRangeAsArray`.' + ) - const array = this.getTextsAtRangeAsArray(range) - .map(text => this.getClosestInline(text.key)) - .filter(exists => exists) - - return array + return this.getLeafInlinesAtRangeAsArray(range) } /** @@ -731,6 +726,76 @@ class ElementInterface { return marks } + /** + * Get the bottom-most block descendants in a `range`. + * + * @param {Range} range + * @return {List} + */ + + getLeafBlocksAtRange(range) { + const array = this.getLeafBlocksAtRangeAsArray(range) + // Eliminate duplicates by converting to an `OrderedSet` first. + return List(OrderedSet(array)) + } + + /** + * Get the bottom-most descendants in a `range` as an array + * + * @param {Range} range + * @return {Array} + */ + + getLeafBlocksAtRangeAsArray(range) { + range = this.resolveRange(range) + if (range.isUnset) return [] + + const { start, end } = range + const startBlock = this.getClosestBlock(start.key) + + // PERF: the most common case is when the range is in a single block node, + // where we can avoid a lot of iterating of the tree. + if (start.key === end.key) return [startBlock] + + const endBlock = this.getClosestBlock(end.key) + const blocks = this.getBlocksAsArray() + const startIndex = blocks.indexOf(startBlock) + const endIndex = blocks.indexOf(endBlock) + return blocks.slice(startIndex, endIndex + 1) + } + + /** + * Get the bottom-most inline nodes for each text node in a `range`. + * + * @param {Range} range + * @return {List} + */ + + getLeafInlinesAtRange(range) { + const array = this.getLeafInlinesAtRangeAsArray(range) + // Remove duplicates by converting it to an `OrderedSet` first. + const list = List(OrderedSet(array)) + return list + } + + /** + * Get the bottom-most inline nodes for each text node in a `range` as an array. + * + * @param {Range} range + * @return {Array} + */ + + getLeafInlinesAtRangeAsArray(range) { + range = this.resolveRange(range) + if (range.isUnset) return [] + + const array = this.getTextsAtRangeAsArray(range) + .map(text => this.getClosestInline(text.key)) + .filter(exists => exists) + + return array + } + /** * Get all of the marks for all of the characters of every text node. * @@ -1154,6 +1219,62 @@ class ElementInterface { return closest } + /** + * Get the highest block descendants in a `range`. + * + * @param {Range} range + * @return {List} + */ + + getRootBlocksAtRange(range) { + range = this.resolveRange(range) + if (range.isUnset) return List() + + const { start, end } = range + const startBlock = this.getFurthestBlock(start.key) + + // PERF: the most common case is when the range is in a single block node, + // where we can avoid a lot of iterating of the tree. + if (start.key === end.key) return List([startBlock]) + + const endBlock = this.getFurthestBlock(end.key) + const startIndex = this.nodes.indexOf(startBlock) + const endIndex = this.nodes.indexOf(endBlock) + return this.nodes.slice(startIndex, endIndex + 1) + } + + /** + * Get the top-most inline nodes for each text node in a `range`. + * + * @param {Range} range + * @return {List} + */ + + getRootInlinesAtRange(range) { + const array = this.getRootInlinesAtRangeAsArray(range) + // Remove duplicates by converting it to an `OrderedSet` first. + const list = List(OrderedSet(array)) + return list + } + + /** + * Get the top-most inline nodes for each text node in a `range` as an array. + * + * @param {Range} range + * @return {Array} + */ + + getRootInlinesAtRangeAsArray(range) { + range = this.resolveRange(range) + if (range.isUnset) return List() + + const array = this.getTextsAtRangeAsArray(range) + .map(text => this.getFurthestInline(text.key)) + .filter(exists => exists) + + return array + } + /** * Get the previous node from a node in the tree. * @@ -1862,8 +1983,9 @@ memoize(ElementInterface.prototype, [ 'getDecorations', 'getFragmentAtRange', 'getInlinesAsArray', - 'getInlinesAtRangeAsArray', 'getInlinesByTypeAsArray', + 'getLeafBlocksAtRangeAsArray', + 'getLeafInlinesAtRangeAsArray', 'getMarksAsArray', 'getMarksAtPosition', 'getNodesAtRange', @@ -1874,6 +1996,8 @@ memoize(ElementInterface.prototype, [ 'getOffset', 'getOffsetAtRange', 'getPreviousBlock', + 'getRootBlocksAtRange', + 'getRootInlinesAtRangeAsArray', 'getTextAtOffset', 'getTextDirection', 'getTextsAsArray', diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index 80da34f47..725a9e60f 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -378,7 +378,7 @@ class Value extends Record(DEFAULTS) { get blocks() { return this.selection.isUnset ? new List() - : this.document.getBlocksAtRange(this.selection) + : this.document.getLeafBlocksAtRange(this.selection) } /** @@ -394,7 +394,7 @@ class Value extends Record(DEFAULTS) { } /** - * Get the inline nodes in the current selection. + * Get the bottom-most inline nodes in the current selection. * * @return {List} */ @@ -402,7 +402,7 @@ class Value extends Record(DEFAULTS) { get inlines() { return this.selection.isUnset ? new List() - : this.document.getInlinesAtRange(this.selection) + : this.document.getLeafInlinesAtRange(this.selection) } /** diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/multiple-blocks.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/multiple-blocks.js new file mode 100644 index 000000000..739b90f21 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/multiple-blocks.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + + + + + + three + + + four + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['c', 'e', 'g'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-first-leaf-of-first-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-first-leaf-of-first-parent.js new file mode 100644 index 000000000..fa8d4fa04 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-first-leaf-of-first-parent.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + + one + + + + + + two + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['c'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-first-leaf-of-second-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-first-leaf-of-second-parent.js new file mode 100644 index 000000000..5a9219c44 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-first-leaf-of-second-parent.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + two + + + + + + three + + + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['h'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-second-leaf-of-first-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-second-leaf-of-first-parent.js new file mode 100644 index 000000000..e2f60715b --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-cursor-in-second-leaf-of-first-parent.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + two + + + + + + three + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['e'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-overlapping-multiple-blocks.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-overlapping-multiple-blocks.js new file mode 100644 index 000000000..df22f0114 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-overlapping-multiple-blocks.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + + two + + + + + three + + + + + four + + + + five + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['a', 'e', 'h', 'j'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-overlapping-texts-in-second-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-overlapping-texts-in-second-parent.js new file mode 100644 index 000000000..5531b416a --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-overlapping-texts-in-second-parent.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + + two + + + + three + + + + four + + + + + + five + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['f', 'h', 'j'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-spanning-first-text.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-spanning-first-text.js new file mode 100644 index 000000000..d7e8d131a --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/nested-blocks-selection-spanning-first-text.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + + one + + + + + + two + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['c'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-block-with-inline.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-block-with-inline.js new file mode 100644 index 000000000..4700826a6 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-block-with-inline.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + two + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['a'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-block.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-block.js new file mode 100644 index 000000000..67eb099b2 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + + two + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['c'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-void-block.js b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-void-block.js new file mode 100644 index 000000000..854021989 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range-as-array/single-void-block.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['a'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/multiple-blocks.js new file mode 100644 index 000000000..3bcf1be18 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/multiple-blocks.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + + + + + + three + + + four + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['c', 'e', 'g']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js new file mode 100644 index 000000000..c9fd28423 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + one + + + + + + two + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js new file mode 100644 index 000000000..634dc2d99 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + two + + + + + + three + + + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['h']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js new file mode 100644 index 000000000..a3c7e4b91 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + two + + + + + + three + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['e']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js new file mode 100644 index 000000000..c00d3b91f --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js @@ -0,0 +1,44 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + + two + + + + + three + + + + + four + + + + five + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a', 'e', 'h', 'j']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js new file mode 100644 index 000000000..456d9a7a8 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js @@ -0,0 +1,42 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + + two + + + + three + + + + four + + + + + + five + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['f', 'h', 'j']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-spanning-first-text.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-spanning-first-text.js new file mode 100644 index 000000000..1710b42e3 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-spanning-first-text.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + one + + + + + + two + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block-with-inline.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block-with-inline.js new file mode 100644 index 000000000..89fc6fe70 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block-with-inline.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + two + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block.js new file mode 100644 index 000000000..8fb9ac68f --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + + two + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js new file mode 100644 index 000000000..ae5e9e188 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + + + + + +) + +export default function({ document, selection }) { + return document.getLeafBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/multiple-blocks-no-inline.js b/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/multiple-blocks-no-inline.js new file mode 100644 index 000000000..6e1c05129 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/multiple-blocks-no-inline.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + + + + + + four + + + + +) + +export default function({ document, selection }) { + return document.getLeafInlinesAtRangeAsArray(selection).map(n => n.key) +} + +export const output = [] diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/multiple-blocks.js b/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/multiple-blocks.js new file mode 100644 index 000000000..b78d0d708 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/multiple-blocks.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + three + + + + + + + + + four + + + five + + + + six + + + + +) + +export default function({ document, selection }) { + return document.getLeafInlinesAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['e', 'k', 'm'] diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/nested-with-text-on-every-level.js b/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/nested-with-text-on-every-level.js new file mode 100644 index 000000000..4a30b32fc --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-inlines-at-range-as-array/nested-with-text-on-every-level.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + + + one + + + + + + two + + three + + + four + + + + + +) + +export default function({ document, selection }) { + return document.getLeafInlinesAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['d', 'g', 'f', 'b'] diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks-no-inline.js b/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks-no-inline.js new file mode 100644 index 000000000..ceb226592 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks-no-inline.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + + + + + + four + + + + +) + +export default function({ document, selection }) { + return document.getLeafInlinesAtRange(selection).map(n => n.key) +} + +export const output = List() diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks.js new file mode 100644 index 000000000..375460407 --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks.js @@ -0,0 +1,44 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + three + + + + + + + + + four + + + five + + + + six + + + + +) + +export default function({ document, selection }) { + return document.getLeafInlinesAtRange(selection).map(n => n.key) +} + +export const output = List(['e', 'k', 'm']) diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range/nested-with-text-on-every-level.js b/packages/slate/test/models/node/get-leaf-inlines-at-range/nested-with-text-on-every-level.js new file mode 100644 index 000000000..0853016cf --- /dev/null +++ b/packages/slate/test/models/node/get-leaf-inlines-at-range/nested-with-text-on-every-level.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + + one + + + + + + two + + three + + + four + + + + + +) + +export default function({ document, selection }) { + return document.getLeafInlinesAtRange(selection).map(n => n.key) +} + +export const output = List(['d', 'g', 'f', 'b']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-root-blocks-at-range/multiple-blocks.js new file mode 100644 index 000000000..417176e15 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/multiple-blocks.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + + + + + + three + + + four + + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['c', 'e', 'g']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js new file mode 100644 index 000000000..3a6549af7 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + one + + + + + + two + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js new file mode 100644 index 000000000..10cfeed69 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + two + + + + + + three + + + + + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js new file mode 100644 index 000000000..727a16d2f --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + two + + + + + + three + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js new file mode 100644 index 000000000..ae0768bd0 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js @@ -0,0 +1,44 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + + two + + + + + three + + + + + four + + + + five + + + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a', 'c']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js new file mode 100644 index 000000000..2ba85b455 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js @@ -0,0 +1,42 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + one + + + + + + two + + + + three + + + + four + + + + + + five + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-spanning-first-text.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-spanning-first-text.js new file mode 100644 index 000000000..30010d31b --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-spanning-first-text.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + one + + + + + + two + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/single-block-with-inline.js b/packages/slate/test/models/node/get-root-blocks-at-range/single-block-with-inline.js new file mode 100644 index 000000000..f12acf367 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/single-block-with-inline.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + two + + + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/single-block.js b/packages/slate/test/models/node/get-root-blocks-at-range/single-block.js new file mode 100644 index 000000000..72c011521 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/single-block.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + + two + + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js b/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js new file mode 100644 index 000000000..502337c53 --- /dev/null +++ b/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + + + + + +) + +export default function({ document, selection }) { + return document.getRootBlocksAtRange(selection).map(n => n.key) +} + +export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-inlines-at-range-as-array/multiple-blocks-no-inline.js b/packages/slate/test/models/node/get-root-inlines-at-range-as-array/multiple-blocks-no-inline.js new file mode 100644 index 000000000..da00c2f14 --- /dev/null +++ b/packages/slate/test/models/node/get-root-inlines-at-range-as-array/multiple-blocks-no-inline.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + + + + + + four + + + + +) + +export default function({ document, selection }) { + return document.getRootInlinesAtRangeAsArray(selection).map(n => n.key) +} + +export const output = [] diff --git a/packages/slate/test/models/node/get-root-inlines-at-range-as-array/multiple-blocks.js b/packages/slate/test/models/node/get-root-inlines-at-range-as-array/multiple-blocks.js new file mode 100644 index 000000000..7c8fdb1e2 --- /dev/null +++ b/packages/slate/test/models/node/get-root-inlines-at-range-as-array/multiple-blocks.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + three + + + + + + + + + four + + + five + + + + six + + + + +) + +export default function({ document, selection }) { + return document.getRootInlinesAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['e', 'j', 'j'] diff --git a/packages/slate/test/models/node/get-root-inlines-at-range-as-array/nested-with-text-on-every-level.js b/packages/slate/test/models/node/get-root-inlines-at-range-as-array/nested-with-text-on-every-level.js new file mode 100644 index 000000000..2b51348f4 --- /dev/null +++ b/packages/slate/test/models/node/get-root-inlines-at-range-as-array/nested-with-text-on-every-level.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export const input = ( + + + + + + + + one + + + + + + two + + three + + + four + + + + + +) + +export default function({ document, selection }) { + return document.getRootInlinesAtRangeAsArray(selection).map(n => n.key) +} + +export const output = ['b', 'b', 'b', 'b'] diff --git a/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks-no-inline.js b/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks-no-inline.js new file mode 100644 index 000000000..23b8e4a80 --- /dev/null +++ b/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks-no-inline.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + + + + + + four + + + + +) + +export default function({ document, selection }) { + return document.getRootInlinesAtRange(selection).map(n => n.key) +} + +export const output = List() diff --git a/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks.js new file mode 100644 index 000000000..125e5d6bb --- /dev/null +++ b/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks.js @@ -0,0 +1,44 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + one + + + + two + + + three + + + + + + + + + four + + + five + + + + six + + + + +) + +export default function({ document, selection }) { + return document.getRootInlinesAtRange(selection).map(n => n.key) +} + +export const output = List(['e', 'j']) diff --git a/packages/slate/test/models/node/get-root-inlines-at-range/nested-with-text-on-every-level.js b/packages/slate/test/models/node/get-root-inlines-at-range/nested-with-text-on-every-level.js new file mode 100644 index 000000000..088a99444 --- /dev/null +++ b/packages/slate/test/models/node/get-root-inlines-at-range/nested-with-text-on-every-level.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import { List } from 'immutable' +import h from '../../../helpers/h' + +export const input = ( + + + + + + + + one + + + + + + two + + three + + + four + + + + + +) + +export default function({ document, selection }) { + return document.getRootInlinesAtRange(selection).map(n => n.key) +} + +export const output = List(['b'])