@portabletext/editor 1.48.7 → 1.48.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +20 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +121 -90
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +63 -47
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +15 -15
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +21 -10
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +5 -6
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +75 -46
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -2
- package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +7 -4
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +61 -46
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +258 -38
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +2552 -251
- package/lib/behaviors/index.d.ts +2552 -251
- package/lib/index.cjs +45 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2350 -51
- package/lib/index.d.ts +2350 -51
- package/lib/index.js +44 -21
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +2324 -24
- package/lib/plugins/index.d.ts +2324 -24
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +5 -5
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2321 -28
- package/lib/selectors/index.d.ts +2321 -28
- package/lib/selectors/index.js +5 -6
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +30 -24
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2350 -44
- package/lib/utils/index.d.ts +2350 -44
- package/lib/utils/index.js +30 -24
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -2
- package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
- package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
- package/src/behaviors/behavior.abstract.decorator.ts +1 -1
- package/src/behaviors/behavior.abstract.delete.ts +1 -1
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.select.ts +16 -4
- package/src/behaviors/behavior.abstract.split.ts +9 -6
- package/src/behaviors/behavior.core.block-objects.ts +5 -5
- package/src/behaviors/behavior.core.insert-break.ts +16 -4
- package/src/behaviors/behavior.core.lists.ts +4 -6
- package/src/behaviors/behavior.decorator-pair.ts +13 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +5 -5
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-html.ts +1 -1
- package/src/converters/converter.text-plain.ts +4 -4
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
- package/src/internal-utils/drag-selection.ts +16 -4
- package/src/internal-utils/event-position.ts +20 -8
- package/src/internal-utils/parse-blocks.ts +17 -5
- package/src/internal-utils/validateValue.ts +6 -6
- package/src/plugins/plugin.decorator-shortcut.ts +2 -2
- package/src/selectors/selector.get-active-annotations.ts +5 -2
- package/src/selectors/selector.get-active-list-item.ts +4 -3
- package/src/selectors/selector.get-active-style.ts +4 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -6
- package/src/selectors/selector.get-block-offsets.ts +2 -2
- package/src/selectors/selector.get-caret-word-selection.ts +11 -5
- package/src/selectors/selector.get-selected-slice.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +11 -15
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +5 -2
- package/src/selectors/selector.get-trimmed-selection.ts +20 -14
- package/src/selectors/selector.is-active-annotation.ts +4 -2
- package/src/selectors/selector.is-active-decorator.test.ts +3 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
- package/src/selectors/selector.is-point-after-selection.ts +7 -6
- package/src/selectors/selector.is-point-before-selection.ts +7 -6
- package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
- package/src/selectors/selectors.ts +25 -28
- package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
- package/src/utils/util.block-offset-to-selection-point.ts +5 -5
- package/src/utils/util.block-offset.test.ts +219 -156
- package/src/utils/util.block-offset.ts +14 -17
- package/src/utils/util.block-offsets-to-selection.ts +5 -5
- package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
- package/src/utils/util.get-block-end-point.ts +15 -15
- package/src/utils/util.get-block-start-point.ts +13 -12
- package/src/utils/util.is-empty-text-block.ts +9 -8
- package/src/utils/util.selection-point-to-block-offset.ts +4 -4
- package/src/utils/util.slice-blocks.test.ts +178 -121
- package/src/utils/util.slice-blocks.ts +25 -24
- package/src/utils/util.split-text-block.ts +18 -12
- package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js +0 -206
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/behavior-actions/behavior.guards.ts +0 -24
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
isPortableTextTextBlock,
|
|
4
|
-
type PortableTextBlock,
|
|
5
|
-
} from '@sanity/types'
|
|
1
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
2
|
+
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
6
3
|
import type {BlockOffset} from '../types/block-offset'
|
|
7
4
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
8
5
|
import {isKeyedSegment} from './util.is-keyed-segment'
|
|
@@ -11,10 +8,10 @@ import {isKeyedSegment} from './util.is-keyed-segment'
|
|
|
11
8
|
* @public
|
|
12
9
|
*/
|
|
13
10
|
export function childSelectionPointToBlockOffset({
|
|
14
|
-
|
|
11
|
+
context,
|
|
15
12
|
selectionPoint,
|
|
16
13
|
}: {
|
|
17
|
-
|
|
14
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
18
15
|
selectionPoint: EditorSelectionPoint
|
|
19
16
|
}): BlockOffset | undefined {
|
|
20
17
|
let offset = 0
|
|
@@ -30,12 +27,12 @@ export function childSelectionPointToBlockOffset({
|
|
|
30
27
|
return undefined
|
|
31
28
|
}
|
|
32
29
|
|
|
33
|
-
for (const block of value) {
|
|
30
|
+
for (const block of context.value) {
|
|
34
31
|
if (block._key !== blockKey) {
|
|
35
32
|
continue
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
if (!
|
|
35
|
+
if (!isTextBlock(context, block)) {
|
|
39
36
|
continue
|
|
40
37
|
}
|
|
41
38
|
|
|
@@ -47,7 +44,7 @@ export function childSelectionPointToBlockOffset({
|
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
if (
|
|
47
|
+
if (isSpan(context, child)) {
|
|
51
48
|
offset += child.text.length
|
|
52
49
|
}
|
|
53
50
|
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type KeyedSegment,
|
|
5
|
-
type PortableTextBlock,
|
|
6
|
-
} from '@sanity/types'
|
|
1
|
+
import type {KeyedSegment, PortableTextBlock} from '@sanity/types'
|
|
2
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
+
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
7
4
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* @public
|
|
11
8
|
*/
|
|
12
9
|
export function getBlockEndPoint({
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
context,
|
|
11
|
+
block,
|
|
15
12
|
}: {
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
context: Pick<EditorContext, 'schema'>
|
|
14
|
+
block: {
|
|
15
|
+
node: PortableTextBlock
|
|
16
|
+
path: [KeyedSegment]
|
|
17
|
+
}
|
|
18
18
|
}): EditorSelectionPoint {
|
|
19
|
-
if (
|
|
20
|
-
const lastChild = node.children[node.children.length - 1]
|
|
19
|
+
if (isTextBlock(context, block.node)) {
|
|
20
|
+
const lastChild = block.node.children[block.node.children.length - 1]
|
|
21
21
|
|
|
22
22
|
if (lastChild) {
|
|
23
23
|
return {
|
|
24
|
-
path: [...path, 'children', {_key: lastChild._key}],
|
|
25
|
-
offset:
|
|
24
|
+
path: [...block.path, 'children', {_key: lastChild._key}],
|
|
25
|
+
offset: isSpan(context, lastChild) ? lastChild.text.length : 0,
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return {
|
|
31
|
-
path,
|
|
31
|
+
path: block.path,
|
|
32
32
|
offset: 0,
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type PortableTextBlock,
|
|
5
|
-
} from '@sanity/types'
|
|
1
|
+
import type {KeyedSegment, PortableTextBlock} from '@sanity/types'
|
|
2
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
+
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
6
4
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* @public
|
|
10
8
|
*/
|
|
11
9
|
export function getBlockStartPoint({
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
context,
|
|
11
|
+
block,
|
|
14
12
|
}: {
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
context: Pick<EditorContext, 'schema'>
|
|
14
|
+
block: {
|
|
15
|
+
node: PortableTextBlock
|
|
16
|
+
path: [KeyedSegment]
|
|
17
|
+
}
|
|
17
18
|
}): EditorSelectionPoint {
|
|
18
|
-
if (
|
|
19
|
+
if (isTextBlock(context, block.node)) {
|
|
19
20
|
return {
|
|
20
|
-
path: [...path, 'children', {_key: node.children[0]._key}],
|
|
21
|
+
path: [...block.path, 'children', {_key: block.node.children[0]._key}],
|
|
21
22
|
offset: 0,
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
return {
|
|
26
|
-
path,
|
|
27
|
+
path: block.path,
|
|
27
28
|
offset: 0,
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type PortableTextBlock,
|
|
5
|
-
} from '@sanity/types'
|
|
1
|
+
import type {PortableTextBlock} from '@sanity/types'
|
|
2
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
+
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
6
4
|
import {getTextBlockText} from './util.get-text-block-text'
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* @public
|
|
10
8
|
*/
|
|
11
|
-
export function isEmptyTextBlock(
|
|
12
|
-
|
|
9
|
+
export function isEmptyTextBlock(
|
|
10
|
+
context: Pick<EditorContext, 'schema'>,
|
|
11
|
+
block: PortableTextBlock,
|
|
12
|
+
) {
|
|
13
|
+
if (!isTextBlock(context, block)) {
|
|
13
14
|
return false
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
const onlyText = block.children.every(
|
|
17
|
+
const onlyText = block.children.every((child) => isSpan(context, child))
|
|
17
18
|
const blockText = getTextBlockText(block)
|
|
18
19
|
|
|
19
20
|
return onlyText && blockText === ''
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
2
2
|
import type {BlockOffset} from '../types/block-offset'
|
|
3
3
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
4
4
|
import {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'
|
|
@@ -8,10 +8,10 @@ import {isKeyedSegment} from './util.is-keyed-segment'
|
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
10
|
export function selectionPointToBlockOffset({
|
|
11
|
-
|
|
11
|
+
context,
|
|
12
12
|
selectionPoint,
|
|
13
13
|
}: {
|
|
14
|
-
|
|
14
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
15
15
|
selectionPoint: EditorSelectionPoint
|
|
16
16
|
}): BlockOffset | undefined {
|
|
17
17
|
if (
|
|
@@ -25,7 +25,7 @@ export function selectionPointToBlockOffset({
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
return childSelectionPointToBlockOffset({
|
|
28
|
-
|
|
28
|
+
context,
|
|
29
29
|
selectionPoint,
|
|
30
30
|
})
|
|
31
31
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'
|
|
2
2
|
import {describe, expect, test} from 'vitest'
|
|
3
|
+
import {compileSchemaDefinition, defineSchema} from '../editor/editor-schema'
|
|
3
4
|
import {sliceBlocks} from './util.slice-blocks'
|
|
4
5
|
|
|
5
6
|
const b1: PortableTextTextBlock = {
|
|
@@ -57,28 +58,48 @@ const b4: PortableTextTextBlock = {
|
|
|
57
58
|
],
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
const schema = compileSchemaDefinition(defineSchema({}))
|
|
60
62
|
const blocks: Array<PortableTextBlock> = [b1, b2, b3, b4]
|
|
61
63
|
|
|
62
64
|
describe(sliceBlocks.name, () => {
|
|
63
65
|
test('sensible defaults', () => {
|
|
64
|
-
expect(
|
|
65
|
-
|
|
66
|
+
expect(
|
|
67
|
+
sliceBlocks({
|
|
68
|
+
context: {
|
|
69
|
+
schema,
|
|
70
|
+
selection: null,
|
|
71
|
+
},
|
|
72
|
+
blocks: [],
|
|
73
|
+
}),
|
|
74
|
+
).toEqual([])
|
|
75
|
+
expect(
|
|
76
|
+
sliceBlocks({
|
|
77
|
+
context: {
|
|
78
|
+
schema,
|
|
79
|
+
selection: null,
|
|
80
|
+
},
|
|
81
|
+
blocks,
|
|
82
|
+
}),
|
|
83
|
+
).toEqual([])
|
|
66
84
|
})
|
|
67
85
|
|
|
68
86
|
test('slicing a single block', () => {
|
|
69
87
|
expect(
|
|
70
88
|
sliceBlocks({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
context: {
|
|
90
|
+
schema,
|
|
91
|
+
selection: {
|
|
92
|
+
anchor: {
|
|
93
|
+
path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
|
|
94
|
+
offset: 0,
|
|
95
|
+
},
|
|
96
|
+
focus: {
|
|
97
|
+
path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
|
|
98
|
+
offset: 3,
|
|
99
|
+
},
|
|
80
100
|
},
|
|
81
101
|
},
|
|
102
|
+
blocks,
|
|
82
103
|
}),
|
|
83
104
|
).toEqual([
|
|
84
105
|
{
|
|
@@ -91,17 +112,20 @@ describe(sliceBlocks.name, () => {
|
|
|
91
112
|
test('slicing a single span', () => {
|
|
92
113
|
expect(
|
|
93
114
|
sliceBlocks({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
115
|
+
context: {
|
|
116
|
+
schema,
|
|
117
|
+
selection: {
|
|
118
|
+
anchor: {
|
|
119
|
+
path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
|
|
120
|
+
offset: 1,
|
|
121
|
+
},
|
|
122
|
+
focus: {
|
|
123
|
+
path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
|
|
124
|
+
offset: 2,
|
|
125
|
+
},
|
|
103
126
|
},
|
|
104
127
|
},
|
|
128
|
+
blocks,
|
|
105
129
|
}),
|
|
106
130
|
).toEqual([
|
|
107
131
|
{
|
|
@@ -119,17 +143,20 @@ describe(sliceBlocks.name, () => {
|
|
|
119
143
|
test('starting and ending selection on a block object', () => {
|
|
120
144
|
expect(
|
|
121
145
|
sliceBlocks({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
146
|
+
context: {
|
|
147
|
+
schema,
|
|
148
|
+
selection: {
|
|
149
|
+
anchor: {
|
|
150
|
+
path: [{_key: b2._key}],
|
|
151
|
+
offset: 0,
|
|
152
|
+
},
|
|
153
|
+
focus: {
|
|
154
|
+
path: [{_key: b2._key}],
|
|
155
|
+
offset: 0,
|
|
156
|
+
},
|
|
131
157
|
},
|
|
132
158
|
},
|
|
159
|
+
blocks,
|
|
133
160
|
}),
|
|
134
161
|
).toEqual([b2])
|
|
135
162
|
})
|
|
@@ -137,17 +164,20 @@ describe(sliceBlocks.name, () => {
|
|
|
137
164
|
test('starting selection on a block object', () => {
|
|
138
165
|
expect(
|
|
139
166
|
sliceBlocks({
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
167
|
+
context: {
|
|
168
|
+
schema,
|
|
169
|
+
selection: {
|
|
170
|
+
anchor: {
|
|
171
|
+
path: [{_key: b2._key}],
|
|
172
|
+
offset: 0,
|
|
173
|
+
},
|
|
174
|
+
focus: {
|
|
175
|
+
path: [{_key: b3._key}, 'children', {_key: b3.children[0]._key}],
|
|
176
|
+
offset: 3,
|
|
177
|
+
},
|
|
149
178
|
},
|
|
150
179
|
},
|
|
180
|
+
blocks,
|
|
151
181
|
}),
|
|
152
182
|
).toEqual([b2, b3])
|
|
153
183
|
})
|
|
@@ -155,17 +185,20 @@ describe(sliceBlocks.name, () => {
|
|
|
155
185
|
test('ending selection on a block object', () => {
|
|
156
186
|
expect(
|
|
157
187
|
sliceBlocks({
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
188
|
+
context: {
|
|
189
|
+
schema,
|
|
190
|
+
selection: {
|
|
191
|
+
anchor: {
|
|
192
|
+
path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
|
|
193
|
+
offset: 3,
|
|
194
|
+
},
|
|
195
|
+
focus: {
|
|
196
|
+
path: [{_key: b2._key}],
|
|
197
|
+
offset: 0,
|
|
198
|
+
},
|
|
167
199
|
},
|
|
168
200
|
},
|
|
201
|
+
blocks,
|
|
169
202
|
}),
|
|
170
203
|
).toEqual([
|
|
171
204
|
{
|
|
@@ -185,17 +218,20 @@ describe(sliceBlocks.name, () => {
|
|
|
185
218
|
test('slicing across block object', () => {
|
|
186
219
|
expect(
|
|
187
220
|
sliceBlocks({
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
221
|
+
context: {
|
|
222
|
+
schema,
|
|
223
|
+
selection: {
|
|
224
|
+
anchor: {
|
|
225
|
+
path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
|
|
226
|
+
offset: 0,
|
|
227
|
+
},
|
|
228
|
+
focus: {
|
|
229
|
+
path: [{_key: b3._key}, 'children', {_key: b3.children[0]._key}],
|
|
230
|
+
offset: 3,
|
|
231
|
+
},
|
|
197
232
|
},
|
|
198
233
|
},
|
|
234
|
+
blocks,
|
|
199
235
|
}),
|
|
200
236
|
).toEqual([b1, b2, b3])
|
|
201
237
|
})
|
|
@@ -203,17 +239,20 @@ describe(sliceBlocks.name, () => {
|
|
|
203
239
|
test('starting and ending mid-span', () => {
|
|
204
240
|
expect(
|
|
205
241
|
sliceBlocks({
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
242
|
+
context: {
|
|
243
|
+
schema,
|
|
244
|
+
selection: {
|
|
245
|
+
anchor: {
|
|
246
|
+
path: [{_key: b3._key}, 'children', {_key: b3.children[0]._key}],
|
|
247
|
+
offset: 2,
|
|
248
|
+
},
|
|
249
|
+
focus: {
|
|
250
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[0]._key}],
|
|
251
|
+
offset: 1,
|
|
252
|
+
},
|
|
215
253
|
},
|
|
216
254
|
},
|
|
255
|
+
blocks,
|
|
217
256
|
}),
|
|
218
257
|
).toEqual([
|
|
219
258
|
{
|
|
@@ -240,17 +279,20 @@ describe(sliceBlocks.name, () => {
|
|
|
240
279
|
test('starting mid-span and ending end-span', () => {
|
|
241
280
|
expect(
|
|
242
281
|
sliceBlocks({
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
282
|
+
context: {
|
|
283
|
+
schema,
|
|
284
|
+
selection: {
|
|
285
|
+
anchor: {
|
|
286
|
+
path: [{_key: b3._key}, 'children', {_key: b3.children[0]._key}],
|
|
287
|
+
offset: 2,
|
|
288
|
+
},
|
|
289
|
+
focus: {
|
|
290
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[0]._key}],
|
|
291
|
+
offset: 4,
|
|
292
|
+
},
|
|
252
293
|
},
|
|
253
294
|
},
|
|
295
|
+
blocks,
|
|
254
296
|
}),
|
|
255
297
|
).toEqual([
|
|
256
298
|
{
|
|
@@ -276,17 +318,20 @@ describe(sliceBlocks.name, () => {
|
|
|
276
318
|
test('starting on inline object', () => {
|
|
277
319
|
expect(
|
|
278
320
|
sliceBlocks({
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
321
|
+
context: {
|
|
322
|
+
schema,
|
|
323
|
+
selection: {
|
|
324
|
+
anchor: {
|
|
325
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
|
|
326
|
+
offset: 0,
|
|
327
|
+
},
|
|
328
|
+
focus: {
|
|
329
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[2]._key}],
|
|
330
|
+
offset: 4,
|
|
331
|
+
},
|
|
288
332
|
},
|
|
289
333
|
},
|
|
334
|
+
blocks,
|
|
290
335
|
}),
|
|
291
336
|
).toEqual([
|
|
292
337
|
{
|
|
@@ -299,17 +344,20 @@ describe(sliceBlocks.name, () => {
|
|
|
299
344
|
test('ending on inline object', () => {
|
|
300
345
|
expect(
|
|
301
346
|
sliceBlocks({
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
347
|
+
context: {
|
|
348
|
+
schema,
|
|
349
|
+
selection: {
|
|
350
|
+
anchor: {
|
|
351
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[0]._key}],
|
|
352
|
+
offset: 0,
|
|
353
|
+
},
|
|
354
|
+
focus: {
|
|
355
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
|
|
356
|
+
offset: 0,
|
|
357
|
+
},
|
|
311
358
|
},
|
|
312
359
|
},
|
|
360
|
+
blocks,
|
|
313
361
|
}),
|
|
314
362
|
).toEqual([
|
|
315
363
|
{
|
|
@@ -322,17 +370,20 @@ describe(sliceBlocks.name, () => {
|
|
|
322
370
|
test('starting and ending on inline object', () => {
|
|
323
371
|
expect(
|
|
324
372
|
sliceBlocks({
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
373
|
+
context: {
|
|
374
|
+
schema,
|
|
375
|
+
selection: {
|
|
376
|
+
anchor: {
|
|
377
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
|
|
378
|
+
offset: 0,
|
|
379
|
+
},
|
|
380
|
+
focus: {
|
|
381
|
+
path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
|
|
382
|
+
offset: 0,
|
|
383
|
+
},
|
|
334
384
|
},
|
|
335
385
|
},
|
|
386
|
+
blocks,
|
|
336
387
|
}),
|
|
337
388
|
).toEqual([
|
|
338
389
|
{
|
|
@@ -345,6 +396,19 @@ describe(sliceBlocks.name, () => {
|
|
|
345
396
|
test('slicing text block with custom props', () => {
|
|
346
397
|
expect(
|
|
347
398
|
sliceBlocks({
|
|
399
|
+
context: {
|
|
400
|
+
schema,
|
|
401
|
+
selection: {
|
|
402
|
+
anchor: {
|
|
403
|
+
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
404
|
+
offset: 7,
|
|
405
|
+
},
|
|
406
|
+
focus: {
|
|
407
|
+
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
408
|
+
offset: 12,
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
},
|
|
348
412
|
blocks: [
|
|
349
413
|
{
|
|
350
414
|
_key: 'b0',
|
|
@@ -353,16 +417,6 @@ describe(sliceBlocks.name, () => {
|
|
|
353
417
|
_map: {},
|
|
354
418
|
},
|
|
355
419
|
],
|
|
356
|
-
selection: {
|
|
357
|
-
anchor: {
|
|
358
|
-
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
359
|
-
offset: 7,
|
|
360
|
-
},
|
|
361
|
-
focus: {
|
|
362
|
-
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
363
|
-
offset: 12,
|
|
364
|
-
},
|
|
365
|
-
},
|
|
366
420
|
}),
|
|
367
421
|
).toEqual([
|
|
368
422
|
{
|
|
@@ -377,6 +431,19 @@ describe(sliceBlocks.name, () => {
|
|
|
377
431
|
test('slicing span with custom props', () => {
|
|
378
432
|
expect(
|
|
379
433
|
sliceBlocks({
|
|
434
|
+
context: {
|
|
435
|
+
schema,
|
|
436
|
+
selection: {
|
|
437
|
+
anchor: {
|
|
438
|
+
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
439
|
+
offset: 7,
|
|
440
|
+
},
|
|
441
|
+
focus: {
|
|
442
|
+
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
443
|
+
offset: 12,
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
},
|
|
380
447
|
blocks: [
|
|
381
448
|
{
|
|
382
449
|
_key: 'b0',
|
|
@@ -386,16 +453,6 @@ describe(sliceBlocks.name, () => {
|
|
|
386
453
|
],
|
|
387
454
|
},
|
|
388
455
|
],
|
|
389
|
-
selection: {
|
|
390
|
-
anchor: {
|
|
391
|
-
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
392
|
-
offset: 7,
|
|
393
|
-
},
|
|
394
|
-
focus: {
|
|
395
|
-
path: [{_key: 'b0'}, 'children', {_key: 's0'}],
|
|
396
|
-
offset: 12,
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
456
|
}),
|
|
400
457
|
).toEqual([
|
|
401
458
|
{
|