@portabletext/editor 1.1.0 → 1.1.2
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/README.md +3 -0
- package/lib/index.d.mts +1680 -12
- package/lib/index.d.ts +1680 -12
- package/lib/index.esm.js +310 -162
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +310 -163
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +310 -162
- package/lib/index.mjs.map +1 -1
- package/package.json +25 -38
- package/src/editor/Editable.tsx +51 -50
- package/src/editor/PortableTextEditor.tsx +42 -26
- package/src/editor/__tests__/PortableTextEditor.test.tsx +11 -12
- package/src/editor/__tests__/PortableTextEditorTester.tsx +2 -5
- package/src/editor/__tests__/RangeDecorations.test.tsx +6 -7
- package/src/editor/__tests__/handleClick.test.tsx +27 -7
- package/src/editor/__tests__/insert-block.test.tsx +6 -6
- package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +8 -8
- package/src/editor/__tests__/self-solving.test.tsx +176 -0
- package/src/editor/components/Element.tsx +15 -17
- package/src/editor/components/Leaf.tsx +40 -35
- package/src/editor/components/SlateContainer.tsx +2 -2
- package/src/editor/components/Synchronizer.tsx +62 -34
- package/src/editor/editor-machine.ts +195 -0
- package/src/editor/hooks/usePortableTextEditor.ts +1 -1
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +12 -14
- package/src/editor/hooks/useSyncValue.test.tsx +9 -9
- package/src/editor/hooks/useSyncValue.ts +16 -19
- package/src/editor/nodes/DefaultAnnotation.tsx +1 -2
- package/src/editor/nodes/DefaultObject.tsx +1 -1
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +2 -5
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +28 -28
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +17 -17
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +8 -8
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +6 -6
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +2 -2
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +47 -49
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +22 -11
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +9 -9
- package/src/editor/plugins/createWithEditableAPI.ts +8 -8
- package/src/editor/plugins/createWithHotKeys.ts +8 -12
- package/src/editor/plugins/createWithInsertBreak.ts +4 -4
- package/src/editor/plugins/createWithInsertData.ts +11 -16
- package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +10 -3
- package/src/editor/plugins/createWithPatches.ts +9 -12
- package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +13 -5
- package/src/editor/plugins/createWithPortableTextLists.ts +3 -4
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +24 -10
- package/src/editor/plugins/createWithPortableTextSelections.ts +9 -10
- package/src/editor/plugins/createWithSchemaTypes.ts +13 -4
- package/src/editor/plugins/createWithUndoRedo.ts +3 -7
- package/src/editor/plugins/createWithUtils.ts +6 -6
- package/src/editor/plugins/index.ts +21 -11
- package/src/index.ts +9 -3
- package/src/types/editor.ts +33 -33
- package/src/types/options.ts +3 -3
- package/src/types/slate.ts +4 -4
- package/src/utils/__tests__/dmpToOperations.test.ts +4 -4
- package/src/utils/__tests__/operationToPatches.test.ts +62 -62
- package/src/utils/__tests__/patchToOperations.test.ts +40 -40
- package/src/utils/__tests__/ranges.test.ts +2 -2
- package/src/utils/__tests__/valueNormalization.test.tsx +14 -2
- package/src/utils/__tests__/values.test.ts +17 -17
- package/src/utils/applyPatch.ts +10 -12
- package/src/utils/getPortableTextMemberSchemaTypes.ts +8 -8
- package/src/utils/operationToPatches.ts +5 -9
- package/src/utils/paths.ts +5 -5
- package/src/utils/ranges.ts +4 -5
- package/src/utils/selection.ts +2 -2
- package/src/utils/ucs2Indices.ts +2 -2
- package/src/utils/validateValue.ts +3 -25
- package/src/utils/values.ts +7 -8
- package/src/utils/weakMaps.ts +2 -2
- package/src/utils/withChanges.ts +1 -1
- package/src/utils/withUndoRedo.ts +1 -1
- package/src/utils/withoutPatching.ts +1 -1
- package/src/editor/__tests__/utils.ts +0 -45
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {noop} from 'lodash'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import type {BaseOperation, Editor, Node, NodeEntry} from 'slate'
|
|
3
|
+
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
4
|
+
import type {createEditorOptions} from '../../types/options'
|
|
5
5
|
import {createOperationToPatches} from '../../utils/operationToPatches'
|
|
6
6
|
import {createWithEditableAPI} from './createWithEditableAPI'
|
|
7
7
|
import {createWithInsertBreak} from './createWithInsertBreak'
|
|
@@ -49,7 +49,7 @@ export const withPlugins = <T extends Editor>(
|
|
|
49
49
|
const e = editor as T & PortableTextSlateEditor
|
|
50
50
|
const {keyGenerator, portableTextEditor, patches$, readOnly, maxBlocks} =
|
|
51
51
|
options
|
|
52
|
-
const {
|
|
52
|
+
const {editorActor, schemaTypes} = portableTextEditor
|
|
53
53
|
e.subscriptions = []
|
|
54
54
|
if (e.destroy) {
|
|
55
55
|
e.destroy()
|
|
@@ -63,15 +63,23 @@ export const withPlugins = <T extends Editor>(
|
|
|
63
63
|
})
|
|
64
64
|
}
|
|
65
65
|
const operationToPatches = createOperationToPatches(schemaTypes)
|
|
66
|
-
const withObjectKeys = createWithObjectKeys(
|
|
67
|
-
|
|
66
|
+
const withObjectKeys = createWithObjectKeys(
|
|
67
|
+
editorActor,
|
|
68
|
+
schemaTypes,
|
|
69
|
+
keyGenerator,
|
|
70
|
+
)
|
|
71
|
+
const withSchemaTypes = createWithSchemaTypes({
|
|
72
|
+
editorActor,
|
|
73
|
+
schemaTypes,
|
|
74
|
+
keyGenerator,
|
|
75
|
+
})
|
|
68
76
|
const withEditableAPI = createWithEditableAPI(
|
|
69
77
|
portableTextEditor,
|
|
70
78
|
schemaTypes,
|
|
71
79
|
keyGenerator,
|
|
72
80
|
)
|
|
73
81
|
const withPatches = createWithPatches({
|
|
74
|
-
|
|
82
|
+
editorActor,
|
|
75
83
|
keyGenerator,
|
|
76
84
|
patches$,
|
|
77
85
|
patchFunctions: operationToPatches,
|
|
@@ -86,12 +94,14 @@ export const withPlugins = <T extends Editor>(
|
|
|
86
94
|
blockSchemaType: schemaTypes.block,
|
|
87
95
|
})
|
|
88
96
|
const withPortableTextMarkModel = createWithPortableTextMarkModel(
|
|
97
|
+
editorActor,
|
|
89
98
|
schemaTypes,
|
|
90
|
-
change$,
|
|
91
99
|
keyGenerator,
|
|
92
100
|
)
|
|
93
|
-
const withPortableTextBlockStyle =
|
|
94
|
-
|
|
101
|
+
const withPortableTextBlockStyle = createWithPortableTextBlockStyle(
|
|
102
|
+
editorActor,
|
|
103
|
+
schemaTypes,
|
|
104
|
+
)
|
|
95
105
|
|
|
96
106
|
const withPlaceholderBlock = createWithPlaceholderBlock()
|
|
97
107
|
|
|
@@ -103,7 +113,7 @@ export const withPlugins = <T extends Editor>(
|
|
|
103
113
|
portableTextEditor,
|
|
104
114
|
})
|
|
105
115
|
const withPortableTextSelections = createWithPortableTextSelections(
|
|
106
|
-
|
|
116
|
+
editorActor,
|
|
107
117
|
schemaTypes,
|
|
108
118
|
)
|
|
109
119
|
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export {type Patch} from '@portabletext/patches'
|
|
2
2
|
export {PortableTextEditable} from './editor/Editable'
|
|
3
|
+
export type {PortableTextEditableProps} from './editor/Editable'
|
|
4
|
+
export {
|
|
5
|
+
editorMachine,
|
|
6
|
+
type EditorActor,
|
|
7
|
+
type MutationEvent,
|
|
8
|
+
type PatchEvent,
|
|
9
|
+
} from './editor/editor-machine'
|
|
3
10
|
export {usePortableTextEditor} from './editor/hooks/usePortableTextEditor'
|
|
4
11
|
export {defaultKeyGenerator as keyGenerator} from './editor/hooks/usePortableTextEditorKeyGenerator'
|
|
5
12
|
export {usePortableTextEditorSelection} from './editor/hooks/usePortableTextEditorSelection'
|
|
6
|
-
export type {PortableTextEditorProps} from './editor/PortableTextEditor'
|
|
7
13
|
export {PortableTextEditor} from './editor/PortableTextEditor'
|
|
14
|
+
export type {PortableTextEditorProps} from './editor/PortableTextEditor'
|
|
8
15
|
export * from './types/editor'
|
|
9
16
|
export * from './types/options'
|
|
10
|
-
export {type Patch} from '@portabletext/patches'
|
package/src/types/editor.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import type {Patch} from '@portabletext/patches'
|
|
2
|
+
import type {
|
|
3
|
+
ArraySchemaType,
|
|
4
|
+
BlockDecoratorDefinition,
|
|
5
|
+
BlockListDefinition,
|
|
6
|
+
BlockSchemaType,
|
|
7
|
+
BlockStyleDefinition,
|
|
8
|
+
ObjectSchemaType,
|
|
9
|
+
Path,
|
|
10
|
+
PortableTextBlock,
|
|
11
|
+
PortableTextChild,
|
|
12
|
+
PortableTextListBlock,
|
|
13
|
+
PortableTextObject,
|
|
14
|
+
PortableTextSpan,
|
|
15
|
+
PortableTextTextBlock,
|
|
16
|
+
SpanSchemaType,
|
|
17
|
+
TypedObject,
|
|
18
18
|
} from '@sanity/types'
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
import type {
|
|
20
|
+
ClipboardEvent,
|
|
21
|
+
FocusEvent,
|
|
22
|
+
KeyboardEvent,
|
|
23
|
+
PropsWithChildren,
|
|
24
|
+
ReactElement,
|
|
25
|
+
RefObject,
|
|
26
26
|
} from 'react'
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
import type {Observable, Subject} from 'rxjs'
|
|
28
|
+
import type {
|
|
29
|
+
Descendant,
|
|
30
|
+
Node as SlateNode,
|
|
31
|
+
Operation as SlateOperation,
|
|
32
32
|
} from 'slate'
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
33
|
+
import type {ReactEditor} from 'slate-react'
|
|
34
|
+
import type {DOMNode} from 'slate-react/dist/utils/dom'
|
|
35
|
+
import type {PortableTextEditableProps} from '../editor/Editable'
|
|
36
|
+
import type {PortableTextEditor} from '../editor/PortableTextEditor'
|
|
37
37
|
|
|
38
38
|
/** @beta */
|
|
39
39
|
export interface EditableAPIDeleteOptions {
|
package/src/types/options.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import type {BaseSyntheticEvent} from 'react'
|
|
2
|
+
import type {PortableTextEditor} from '../editor/PortableTextEditor'
|
|
3
|
+
import type {PatchObservable} from './editor'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
package/src/types/slate.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import type {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
|
|
2
|
+
import type {BaseEditor, Descendant} from 'slate'
|
|
3
|
+
import type {ReactEditor} from 'slate-react'
|
|
4
|
+
import type {PortableTextSlateEditor} from '..'
|
|
5
5
|
|
|
6
6
|
export interface VoidElement {
|
|
7
7
|
_type: string
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {type DiffMatchPatch} from '@portabletext/patches'
|
|
1
|
+
import type {DiffMatchPatch} from '@portabletext/patches'
|
|
3
2
|
import {makeDiff, makePatches, stringifyPatches} from '@sanity/diff-match-patch'
|
|
4
3
|
import {
|
|
5
4
|
isPortableTextSpan,
|
|
@@ -9,8 +8,9 @@ import {
|
|
|
9
8
|
type PortableTextSpan,
|
|
10
9
|
type PortableTextTextBlock,
|
|
11
10
|
} from '@sanity/types'
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
11
|
+
import type {Descendant, Operation} from 'slate'
|
|
12
|
+
import {describe, expect, test} from 'vitest'
|
|
13
|
+
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
14
14
|
import {diffMatchPatch} from '../applyPatch'
|
|
15
15
|
|
|
16
16
|
describe('operationToPatches: diffMatchPatch', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {type PortableTextTextBlock} from '@sanity/types'
|
|
1
|
+
import type {PortableTextTextBlock} from '@sanity/types'
|
|
3
2
|
import {createEditor, type Descendant} from 'slate'
|
|
3
|
+
import {beforeEach, describe, expect, it} from 'vitest'
|
|
4
4
|
import {PortableTextEditor, type PortableTextEditorProps} from '../..'
|
|
5
5
|
import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
|
|
6
6
|
import {defaultKeyGenerator} from '../../editor/hooks/usePortableTextEditorKeyGenerator'
|
|
@@ -61,34 +61,34 @@ describe('operationToPatches', () => {
|
|
|
61
61
|
createDefaultValue(),
|
|
62
62
|
),
|
|
63
63
|
).toMatchInlineSnapshot(`
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"items":
|
|
67
|
-
|
|
64
|
+
[
|
|
65
|
+
{
|
|
66
|
+
"items": [
|
|
67
|
+
{
|
|
68
68
|
"_key": "773866318fa8",
|
|
69
69
|
"_type": "someObject",
|
|
70
70
|
"title": "The Object",
|
|
71
71
|
},
|
|
72
72
|
],
|
|
73
|
-
"path":
|
|
74
|
-
|
|
73
|
+
"path": [
|
|
74
|
+
{
|
|
75
75
|
"_key": "1f2e64b47787",
|
|
76
76
|
},
|
|
77
77
|
"children",
|
|
78
|
-
|
|
78
|
+
{
|
|
79
79
|
"_key": "c130395c640c",
|
|
80
80
|
},
|
|
81
81
|
],
|
|
82
82
|
"position": "after",
|
|
83
83
|
"type": "insert",
|
|
84
84
|
},
|
|
85
|
-
|
|
86
|
-
"path":
|
|
87
|
-
|
|
85
|
+
{
|
|
86
|
+
"path": [
|
|
87
|
+
{
|
|
88
88
|
"_key": "1f2e64b47787",
|
|
89
89
|
},
|
|
90
90
|
"children",
|
|
91
|
-
|
|
91
|
+
{
|
|
92
92
|
"_key": "c130395c640c",
|
|
93
93
|
},
|
|
94
94
|
"text",
|
|
@@ -118,17 +118,17 @@ describe('operationToPatches', () => {
|
|
|
118
118
|
createDefaultValue(),
|
|
119
119
|
),
|
|
120
120
|
).toMatchInlineSnapshot(`
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"items":
|
|
124
|
-
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
"items": [
|
|
124
|
+
{
|
|
125
125
|
"_key": "c130395c640c",
|
|
126
126
|
"_type": "someObject",
|
|
127
127
|
"title": "The Object",
|
|
128
128
|
},
|
|
129
129
|
],
|
|
130
|
-
"path":
|
|
131
|
-
|
|
130
|
+
"path": [
|
|
131
|
+
{
|
|
132
132
|
"_key": "1f2e64b47787",
|
|
133
133
|
},
|
|
134
134
|
],
|
|
@@ -160,20 +160,20 @@ describe('operationToPatches', () => {
|
|
|
160
160
|
[],
|
|
161
161
|
),
|
|
162
162
|
).toMatchInlineSnapshot(`
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
"path":
|
|
163
|
+
[
|
|
164
|
+
{
|
|
165
|
+
"path": [],
|
|
166
166
|
"type": "setIfMissing",
|
|
167
|
-
"value":
|
|
167
|
+
"value": [],
|
|
168
168
|
},
|
|
169
|
-
|
|
170
|
-
"items":
|
|
171
|
-
|
|
169
|
+
{
|
|
170
|
+
"items": [
|
|
171
|
+
{
|
|
172
172
|
"_key": "c130395c640c",
|
|
173
173
|
"_type": "someObject",
|
|
174
174
|
},
|
|
175
175
|
],
|
|
176
|
-
"path":
|
|
176
|
+
"path": [
|
|
177
177
|
0,
|
|
178
178
|
],
|
|
179
179
|
"position": "before",
|
|
@@ -202,21 +202,21 @@ describe('operationToPatches', () => {
|
|
|
202
202
|
createDefaultValue(),
|
|
203
203
|
),
|
|
204
204
|
).toMatchInlineSnapshot(`
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
"items":
|
|
208
|
-
|
|
205
|
+
[
|
|
206
|
+
{
|
|
207
|
+
"items": [
|
|
208
|
+
{
|
|
209
209
|
"_key": "c130395c640c",
|
|
210
210
|
"_type": "someObject",
|
|
211
211
|
"title": "The Object",
|
|
212
212
|
},
|
|
213
213
|
],
|
|
214
|
-
"path":
|
|
215
|
-
|
|
214
|
+
"path": [
|
|
215
|
+
{
|
|
216
216
|
"_key": "1f2e64b47787",
|
|
217
217
|
},
|
|
218
218
|
"children",
|
|
219
|
-
|
|
219
|
+
{
|
|
220
220
|
"_key": "fd9b4a4e6c0b",
|
|
221
221
|
},
|
|
222
222
|
],
|
|
@@ -243,14 +243,14 @@ describe('operationToPatches', () => {
|
|
|
243
243
|
createDefaultValue(),
|
|
244
244
|
),
|
|
245
245
|
).toMatchInlineSnapshot(`
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
"path":
|
|
249
|
-
|
|
246
|
+
[
|
|
247
|
+
{
|
|
248
|
+
"path": [
|
|
249
|
+
{
|
|
250
250
|
"_key": "1f2e64b47787",
|
|
251
251
|
},
|
|
252
252
|
"children",
|
|
253
|
-
|
|
253
|
+
{
|
|
254
254
|
"_key": "fd9b4a4e6c0b",
|
|
255
255
|
},
|
|
256
256
|
"text",
|
|
@@ -280,14 +280,14 @@ describe('operationToPatches', () => {
|
|
|
280
280
|
before,
|
|
281
281
|
),
|
|
282
282
|
).toMatchInlineSnapshot(`
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
"path":
|
|
286
|
-
|
|
283
|
+
[
|
|
284
|
+
{
|
|
285
|
+
"path": [
|
|
286
|
+
{
|
|
287
287
|
"_key": "1f2e64b47787",
|
|
288
288
|
},
|
|
289
289
|
"children",
|
|
290
|
-
|
|
290
|
+
{
|
|
291
291
|
"_key": "fd9b4a4e6c0b",
|
|
292
292
|
},
|
|
293
293
|
"text",
|
|
@@ -320,14 +320,14 @@ describe('operationToPatches', () => {
|
|
|
320
320
|
createDefaultValue(),
|
|
321
321
|
),
|
|
322
322
|
).toMatchInlineSnapshot(`
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
"path":
|
|
326
|
-
|
|
323
|
+
[
|
|
324
|
+
{
|
|
325
|
+
"path": [
|
|
326
|
+
{
|
|
327
327
|
"_key": "1f2e64b47787",
|
|
328
328
|
},
|
|
329
329
|
"children",
|
|
330
|
-
|
|
330
|
+
{
|
|
331
331
|
"_key": "773866318fa8",
|
|
332
332
|
},
|
|
333
333
|
],
|
|
@@ -351,10 +351,10 @@ describe('operationToPatches', () => {
|
|
|
351
351
|
val,
|
|
352
352
|
),
|
|
353
353
|
).toMatchInlineSnapshot(`
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
"path":
|
|
357
|
-
|
|
354
|
+
[
|
|
355
|
+
{
|
|
356
|
+
"path": [
|
|
357
|
+
{
|
|
358
358
|
"_key": "1f2e64b47787",
|
|
359
359
|
},
|
|
360
360
|
],
|
|
@@ -389,14 +389,14 @@ describe('operationToPatches', () => {
|
|
|
389
389
|
val,
|
|
390
390
|
),
|
|
391
391
|
).toMatchInlineSnapshot(`
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
"path":
|
|
395
|
-
|
|
392
|
+
[
|
|
393
|
+
{
|
|
394
|
+
"path": [
|
|
395
|
+
{
|
|
396
396
|
"_key": "1f2e64b47787",
|
|
397
397
|
},
|
|
398
398
|
"children",
|
|
399
|
-
|
|
399
|
+
{
|
|
400
400
|
"_key": "fd9b4a4e6c0b",
|
|
401
401
|
},
|
|
402
402
|
"text",
|
|
@@ -404,13 +404,13 @@ describe('operationToPatches', () => {
|
|
|
404
404
|
"type": "set",
|
|
405
405
|
"value": "1234",
|
|
406
406
|
},
|
|
407
|
-
|
|
408
|
-
"path":
|
|
409
|
-
|
|
407
|
+
{
|
|
408
|
+
"path": [
|
|
409
|
+
{
|
|
410
410
|
"_key": "1f2e64b47787",
|
|
411
411
|
},
|
|
412
412
|
"children",
|
|
413
|
-
|
|
413
|
+
{
|
|
414
414
|
"_key": "r4wr323432",
|
|
415
415
|
},
|
|
416
416
|
],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {type Patch} from '@portabletext/patches'
|
|
1
|
+
import type {Patch} from '@portabletext/patches'
|
|
3
2
|
import {noop} from 'lodash'
|
|
4
3
|
import {createEditor, type Descendant} from 'slate'
|
|
4
|
+
import {beforeEach, describe, expect, it} from 'vitest'
|
|
5
5
|
import {keyGenerator, PortableTextEditor} from '../..'
|
|
6
6
|
import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
|
|
7
7
|
import {withPlugins} from '../../editor/plugins'
|
|
@@ -70,21 +70,21 @@ describe('operationToPatches', () => {
|
|
|
70
70
|
patchToOperations(editor, p)
|
|
71
71
|
})
|
|
72
72
|
expect(editor.children).toMatchInlineSnapshot(`
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
[
|
|
74
|
+
{
|
|
75
75
|
"__inline": false,
|
|
76
76
|
"_key": "c01739b0d03b",
|
|
77
77
|
"_type": "image",
|
|
78
|
-
"children":
|
|
79
|
-
|
|
78
|
+
"children": [
|
|
79
|
+
{
|
|
80
80
|
"_key": "${VOID_CHILD_KEY}",
|
|
81
81
|
"_type": "span",
|
|
82
|
-
"marks":
|
|
82
|
+
"marks": [],
|
|
83
83
|
"text": "",
|
|
84
84
|
},
|
|
85
85
|
],
|
|
86
|
-
"value":
|
|
87
|
-
"asset":
|
|
86
|
+
"value": {
|
|
87
|
+
"asset": {
|
|
88
88
|
"_ref": "image-f52f71bc1df46e080dabe43a8effe8ccfb5f21de-4032x3024-png",
|
|
89
89
|
"_type": "reference",
|
|
90
90
|
},
|
|
@@ -93,7 +93,7 @@ describe('operationToPatches', () => {
|
|
|
93
93
|
]
|
|
94
94
|
`)
|
|
95
95
|
})
|
|
96
|
-
it('will not create operations for insertion inside
|
|
96
|
+
it('will not create operations for insertion inside blocks', () => {
|
|
97
97
|
editor.children = [
|
|
98
98
|
{
|
|
99
99
|
_type: 'someType',
|
|
@@ -127,31 +127,31 @@ describe('operationToPatches', () => {
|
|
|
127
127
|
patchToOperations(editor, p)
|
|
128
128
|
})
|
|
129
129
|
expect(editor.children).toMatchInlineSnapshot(`
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
[
|
|
131
|
+
{
|
|
132
132
|
"__inline": false,
|
|
133
133
|
"_key": "c01739b0d03b",
|
|
134
134
|
"_type": "someType",
|
|
135
|
-
"children":
|
|
136
|
-
|
|
135
|
+
"children": [
|
|
136
|
+
{
|
|
137
137
|
"_key": "${VOID_CHILD_KEY}",
|
|
138
138
|
"_type": "span",
|
|
139
|
-
"marks":
|
|
139
|
+
"marks": [],
|
|
140
140
|
"text": "",
|
|
141
141
|
},
|
|
142
142
|
],
|
|
143
|
-
"value":
|
|
144
|
-
"asset":
|
|
143
|
+
"value": {
|
|
144
|
+
"asset": {
|
|
145
145
|
"_ref": "image-f52f71bc1df46e080dabe43a8effe8ccfb5f21de-4032x3024-png",
|
|
146
146
|
"_type": "reference",
|
|
147
147
|
},
|
|
148
|
-
"nestedArray":
|
|
148
|
+
"nestedArray": [],
|
|
149
149
|
},
|
|
150
150
|
},
|
|
151
151
|
]
|
|
152
152
|
`)
|
|
153
153
|
})
|
|
154
|
-
it('will not create operations for removal inside
|
|
154
|
+
it('will not create operations for removal inside blocks', () => {
|
|
155
155
|
editor.children = [
|
|
156
156
|
{
|
|
157
157
|
_type: 'someType',
|
|
@@ -190,26 +190,26 @@ describe('operationToPatches', () => {
|
|
|
190
190
|
patchToOperations(editor, p)
|
|
191
191
|
})
|
|
192
192
|
expect(editor.children).toMatchInlineSnapshot(`
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
[
|
|
194
|
+
{
|
|
195
195
|
"__inline": false,
|
|
196
196
|
"_key": "c01739b0d03b",
|
|
197
197
|
"_type": "someType",
|
|
198
|
-
"children":
|
|
199
|
-
|
|
198
|
+
"children": [
|
|
199
|
+
{
|
|
200
200
|
"_key": "${VOID_CHILD_KEY}",
|
|
201
201
|
"_type": "span",
|
|
202
|
-
"marks":
|
|
202
|
+
"marks": [],
|
|
203
203
|
"text": "",
|
|
204
204
|
},
|
|
205
205
|
],
|
|
206
|
-
"value":
|
|
207
|
-
"asset":
|
|
206
|
+
"value": {
|
|
207
|
+
"asset": {
|
|
208
208
|
"_ref": "image-f52f71bc1df46e080dabe43a8effe8ccfb5f21de-4032x3024-png",
|
|
209
209
|
"_type": "reference",
|
|
210
210
|
},
|
|
211
|
-
"nestedArray":
|
|
212
|
-
|
|
211
|
+
"nestedArray": [
|
|
212
|
+
{
|
|
213
213
|
"_key": "foo",
|
|
214
214
|
"_type": "nestedValue",
|
|
215
215
|
},
|
|
@@ -219,7 +219,7 @@ describe('operationToPatches', () => {
|
|
|
219
219
|
]
|
|
220
220
|
`)
|
|
221
221
|
})
|
|
222
|
-
it('will not create operations for setting data inside
|
|
222
|
+
it('will not create operations for setting data inside blocks', () => {
|
|
223
223
|
editor.children = [
|
|
224
224
|
{
|
|
225
225
|
_key: '1335959d4d03',
|
|
@@ -265,34 +265,34 @@ describe('operationToPatches', () => {
|
|
|
265
265
|
patchToOperations(editor, p)
|
|
266
266
|
})
|
|
267
267
|
expect(editor.children).toMatchInlineSnapshot(`
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
[
|
|
269
|
+
{
|
|
270
270
|
"_key": "1335959d4d03",
|
|
271
271
|
"_type": "block",
|
|
272
|
-
"children":
|
|
273
|
-
|
|
272
|
+
"children": [
|
|
273
|
+
{
|
|
274
274
|
"_key": "9bd868adcd6b",
|
|
275
275
|
"_type": "span",
|
|
276
|
-
"marks":
|
|
276
|
+
"marks": [],
|
|
277
277
|
"text": "1 ",
|
|
278
278
|
},
|
|
279
|
-
|
|
279
|
+
{
|
|
280
280
|
"_key": "6f75d593f3fc",
|
|
281
281
|
"_type": "span",
|
|
282
|
-
"marks":
|
|
282
|
+
"marks": [
|
|
283
283
|
"11de7fcea659",
|
|
284
284
|
],
|
|
285
285
|
"text": "2",
|
|
286
286
|
},
|
|
287
|
-
|
|
287
|
+
{
|
|
288
288
|
"_key": "033618a7f081",
|
|
289
289
|
"_type": "span",
|
|
290
|
-
"marks":
|
|
290
|
+
"marks": [],
|
|
291
291
|
"text": " 3",
|
|
292
292
|
},
|
|
293
293
|
],
|
|
294
|
-
"markDefs":
|
|
295
|
-
|
|
294
|
+
"markDefs": [
|
|
295
|
+
{
|
|
296
296
|
"_key": "11de7fcea659",
|
|
297
297
|
"_type": "link",
|
|
298
298
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type {InsertTextOperation, Range} from 'slate'
|
|
2
|
+
import {describe, expect, it} from 'vitest'
|
|
3
3
|
import {moveRangeByOperation} from '../ranges'
|
|
4
4
|
|
|
5
5
|
describe('moveRangeByOperation', () => {
|