@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.
Files changed (128) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +20 -8
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +121 -90
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
  8. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
  9. package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
  10. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  11. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +63 -47
  12. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
  13. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
  14. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
  16. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  17. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +15 -15
  18. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  19. package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
  20. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  21. package/lib/_chunks-es/behavior.core.js +21 -10
  22. package/lib/_chunks-es/behavior.core.js.map +1 -1
  23. package/lib/_chunks-es/behavior.markdown.js +5 -6
  24. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  25. package/lib/_chunks-es/editor-provider.js +75 -46
  26. package/lib/_chunks-es/editor-provider.js.map +1 -1
  27. package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -2
  28. package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -1
  29. package/lib/_chunks-es/selector.get-text-before.js +7 -4
  30. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  31. package/lib/_chunks-es/selector.is-overlapping-selection.js +61 -46
  32. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
  33. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
  34. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  35. package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
  36. package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
  37. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  38. package/lib/_chunks-es/util.slice-blocks.js +258 -38
  39. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  40. package/lib/behaviors/index.d.cts +2552 -251
  41. package/lib/behaviors/index.d.ts +2552 -251
  42. package/lib/index.cjs +45 -21
  43. package/lib/index.cjs.map +1 -1
  44. package/lib/index.d.cts +2350 -51
  45. package/lib/index.d.ts +2350 -51
  46. package/lib/index.js +44 -21
  47. package/lib/index.js.map +1 -1
  48. package/lib/plugins/index.cjs +16 -7
  49. package/lib/plugins/index.cjs.map +1 -1
  50. package/lib/plugins/index.d.cts +2324 -24
  51. package/lib/plugins/index.d.ts +2324 -24
  52. package/lib/plugins/index.js +16 -7
  53. package/lib/plugins/index.js.map +1 -1
  54. package/lib/selectors/index.cjs +5 -5
  55. package/lib/selectors/index.cjs.map +1 -1
  56. package/lib/selectors/index.d.cts +2321 -28
  57. package/lib/selectors/index.d.ts +2321 -28
  58. package/lib/selectors/index.js +5 -6
  59. package/lib/selectors/index.js.map +1 -1
  60. package/lib/utils/index.cjs +30 -24
  61. package/lib/utils/index.cjs.map +1 -1
  62. package/lib/utils/index.d.cts +2350 -44
  63. package/lib/utils/index.d.ts +2350 -44
  64. package/lib/utils/index.js +30 -24
  65. package/lib/utils/index.js.map +1 -1
  66. package/package.json +1 -2
  67. package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
  68. package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
  69. package/src/behaviors/behavior.abstract.decorator.ts +1 -1
  70. package/src/behaviors/behavior.abstract.delete.ts +1 -1
  71. package/src/behaviors/behavior.abstract.insert.ts +2 -2
  72. package/src/behaviors/behavior.abstract.select.ts +16 -4
  73. package/src/behaviors/behavior.abstract.split.ts +9 -6
  74. package/src/behaviors/behavior.core.block-objects.ts +5 -5
  75. package/src/behaviors/behavior.core.insert-break.ts +16 -4
  76. package/src/behaviors/behavior.core.lists.ts +4 -6
  77. package/src/behaviors/behavior.decorator-pair.ts +13 -4
  78. package/src/behaviors/behavior.default.ts +1 -1
  79. package/src/behaviors/behavior.markdown.ts +5 -5
  80. package/src/converters/converter.portable-text.ts +1 -1
  81. package/src/converters/converter.text-html.ts +1 -1
  82. package/src/converters/converter.text-plain.ts +4 -4
  83. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
  84. package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
  85. package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
  86. package/src/internal-utils/drag-selection.ts +16 -4
  87. package/src/internal-utils/event-position.ts +20 -8
  88. package/src/internal-utils/parse-blocks.ts +17 -5
  89. package/src/internal-utils/validateValue.ts +6 -6
  90. package/src/plugins/plugin.decorator-shortcut.ts +2 -2
  91. package/src/selectors/selector.get-active-annotations.ts +5 -2
  92. package/src/selectors/selector.get-active-list-item.ts +4 -3
  93. package/src/selectors/selector.get-active-style.ts +4 -3
  94. package/src/selectors/selector.get-anchor-text-block.ts +3 -6
  95. package/src/selectors/selector.get-block-offsets.ts +2 -2
  96. package/src/selectors/selector.get-caret-word-selection.ts +11 -5
  97. package/src/selectors/selector.get-selected-slice.ts +1 -1
  98. package/src/selectors/selector.get-selected-spans.ts +11 -15
  99. package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
  100. package/src/selectors/selector.get-selection-text.ts +3 -3
  101. package/src/selectors/selector.get-text-before.ts +5 -2
  102. package/src/selectors/selector.get-trimmed-selection.ts +20 -14
  103. package/src/selectors/selector.is-active-annotation.ts +4 -2
  104. package/src/selectors/selector.is-active-decorator.test.ts +3 -3
  105. package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
  106. package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
  107. package/src/selectors/selector.is-point-after-selection.ts +7 -6
  108. package/src/selectors/selector.is-point-before-selection.ts +7 -6
  109. package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
  110. package/src/selectors/selectors.ts +25 -28
  111. package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
  112. package/src/utils/util.block-offset-to-selection-point.ts +5 -5
  113. package/src/utils/util.block-offset.test.ts +219 -156
  114. package/src/utils/util.block-offset.ts +14 -17
  115. package/src/utils/util.block-offsets-to-selection.ts +5 -5
  116. package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
  117. package/src/utils/util.get-block-end-point.ts +15 -15
  118. package/src/utils/util.get-block-start-point.ts +13 -12
  119. package/src/utils/util.is-empty-text-block.ts +9 -8
  120. package/src/utils/util.selection-point-to-block-offset.ts +4 -4
  121. package/src/utils/util.slice-blocks.test.ts +178 -121
  122. package/src/utils/util.slice-blocks.ts +25 -24
  123. package/src/utils/util.split-text-block.ts +18 -12
  124. package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
  125. package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
  126. package/lib/_chunks-es/parse-blocks.js +0 -206
  127. package/lib/_chunks-es/parse-blocks.js.map +0 -1
  128. package/src/behavior-actions/behavior.guards.ts +0 -24
@@ -1,8 +1,5 @@
1
- import {
2
- isPortableTextSpan,
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
- value,
11
+ context,
15
12
  selectionPoint,
16
13
  }: {
17
- value: Array<PortableTextBlock>
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 (!isPortableTextTextBlock(block)) {
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 (isPortableTextSpan(child)) {
47
+ if (isSpan(context, child)) {
51
48
  offset += child.text.length
52
49
  }
53
50
  }
@@ -1,34 +1,34 @@
1
- import {
2
- isPortableTextSpan,
3
- isPortableTextTextBlock,
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
- node,
14
- path,
10
+ context,
11
+ block,
15
12
  }: {
16
- node: PortableTextBlock
17
- path: [KeyedSegment]
13
+ context: Pick<EditorContext, 'schema'>
14
+ block: {
15
+ node: PortableTextBlock
16
+ path: [KeyedSegment]
17
+ }
18
18
  }): EditorSelectionPoint {
19
- if (isPortableTextTextBlock(node)) {
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: isPortableTextSpan(lastChild) ? lastChild.text.length : 0,
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
- isPortableTextTextBlock,
3
- type KeyedSegment,
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
- node,
13
- path,
10
+ context,
11
+ block,
14
12
  }: {
15
- node: PortableTextBlock
16
- path: [KeyedSegment]
13
+ context: Pick<EditorContext, 'schema'>
14
+ block: {
15
+ node: PortableTextBlock
16
+ path: [KeyedSegment]
17
+ }
17
18
  }): EditorSelectionPoint {
18
- if (isPortableTextTextBlock(node)) {
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
- isPortableTextSpan,
3
- isPortableTextTextBlock,
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(block: PortableTextBlock) {
12
- if (!isPortableTextTextBlock(block)) {
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(isPortableTextSpan)
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 {PortableTextBlock} from '@sanity/types'
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
- value,
11
+ context,
12
12
  selectionPoint,
13
13
  }: {
14
- value: Array<PortableTextBlock>
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
- value,
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(sliceBlocks({blocks: [], selection: null})).toEqual([])
65
- expect(sliceBlocks({blocks, selection: null})).toEqual([])
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
- blocks,
72
- selection: {
73
- anchor: {
74
- path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
75
- offset: 0,
76
- },
77
- focus: {
78
- path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
79
- offset: 3,
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
- blocks,
95
- selection: {
96
- anchor: {
97
- path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
98
- offset: 1,
99
- },
100
- focus: {
101
- path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
102
- offset: 2,
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
- blocks,
123
- selection: {
124
- anchor: {
125
- path: [{_key: b2._key}],
126
- offset: 0,
127
- },
128
- focus: {
129
- path: [{_key: b2._key}],
130
- offset: 0,
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
- blocks,
141
- selection: {
142
- anchor: {
143
- path: [{_key: b2._key}],
144
- offset: 0,
145
- },
146
- focus: {
147
- path: [{_key: b3._key}, 'children', {_key: b3.children[0]._key}],
148
- offset: 3,
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
- blocks,
159
- selection: {
160
- anchor: {
161
- path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
162
- offset: 3,
163
- },
164
- focus: {
165
- path: [{_key: b2._key}],
166
- offset: 0,
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
- blocks,
189
- selection: {
190
- anchor: {
191
- path: [{_key: b1._key}, 'children', {_key: b1.children[0]._key}],
192
- offset: 0,
193
- },
194
- focus: {
195
- path: [{_key: b3._key}, 'children', {_key: b3.children[0]._key}],
196
- offset: 3,
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
- blocks,
207
- selection: {
208
- anchor: {
209
- path: [{_key: b3._key}, 'children', {_key: b3.children[0]._key}],
210
- offset: 2,
211
- },
212
- focus: {
213
- path: [{_key: b4._key}, 'children', {_key: b4.children[0]._key}],
214
- offset: 1,
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
- blocks,
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: 4,
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
- blocks,
280
- selection: {
281
- anchor: {
282
- path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
283
- offset: 0,
284
- },
285
- focus: {
286
- path: [{_key: b4._key}, 'children', {_key: b4.children[2]._key}],
287
- offset: 4,
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
- blocks,
303
- selection: {
304
- anchor: {
305
- path: [{_key: b4._key}, 'children', {_key: b4.children[0]._key}],
306
- offset: 0,
307
- },
308
- focus: {
309
- path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
310
- offset: 0,
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
- blocks,
326
- selection: {
327
- anchor: {
328
- path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
329
- offset: 0,
330
- },
331
- focus: {
332
- path: [{_key: b4._key}, 'children', {_key: b4.children[1]._key}],
333
- offset: 0,
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
  {