@portabletext/editor 1.50.2 → 1.50.4
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/behaviors/index.d.cts +1 -0
- package/lib/behaviors/index.d.ts +1 -0
- package/lib/index.cjs +577 -286
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +15 -2
- package/lib/index.d.ts +15 -2
- package/lib/index.js +584 -292
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +7 -0
- package/lib/plugins/index.d.ts +7 -0
- package/lib/selectors/index.d.cts +1 -0
- package/lib/selectors/index.d.ts +1 -0
- package/lib/utils/index.d.cts +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/package.json +14 -13
- package/src/editor/PortableTextEditor.tsx +22 -22
- package/src/editor/create-slate-editor.tsx +9 -1
- package/src/editor/editor-selector.ts +1 -5
- package/src/editor/editor-snapshot.ts +1 -3
- package/src/editor/plugins/createWithPatches.ts +37 -75
- package/src/editor/plugins/slate-plugin.update-value.ts +30 -0
- package/src/editor/plugins/with-plugins.ts +8 -4
- package/src/editor/relay-machine.ts +9 -0
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +175 -0
- package/src/internal-utils/apply-operation-to-portable-text.ts +435 -0
- package/src/internal-utils/create-placeholder-block.ts +20 -0
- package/src/internal-utils/{__tests__/operationToPatches.test.ts → operation-to-patches.test.ts} +44 -39
- package/src/internal-utils/operation-to-patches.ts +467 -0
- package/src/internal-utils/portable-text-node.ts +209 -0
- package/src/types/editor.ts +8 -2
- package/src/internal-utils/__tests__/patchToOperations.test.ts +0 -312
- package/src/internal-utils/operationToPatches.ts +0 -489
- package/src/internal-utils/slate-children-to-blocks.ts +0 -49
package/lib/plugins/index.d.cts
CHANGED
|
@@ -617,6 +617,9 @@ declare type EditorEmittedEvent =
|
|
|
617
617
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
618
618
|
}
|
|
619
619
|
| {
|
|
620
|
+
/**
|
|
621
|
+
* @deprecated
|
|
622
|
+
*/
|
|
620
623
|
type: 'done loading'
|
|
621
624
|
}
|
|
622
625
|
| {
|
|
@@ -633,6 +636,9 @@ declare type EditorEmittedEvent =
|
|
|
633
636
|
value: Array<PortableTextBlock> | undefined
|
|
634
637
|
}
|
|
635
638
|
| {
|
|
639
|
+
/**
|
|
640
|
+
* @deprecated
|
|
641
|
+
*/
|
|
636
642
|
type: 'loading'
|
|
637
643
|
}
|
|
638
644
|
| MutationEvent
|
|
@@ -2944,6 +2950,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
2944
2950
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
2945
2951
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
2946
2952
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
2953
|
+
value: Array<PortableTextBlock>
|
|
2947
2954
|
/**
|
|
2948
2955
|
* Use hotkeys
|
|
2949
2956
|
*/
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -617,6 +617,9 @@ declare type EditorEmittedEvent =
|
|
|
617
617
|
event: FocusEvent_2<HTMLDivElement, Element>
|
|
618
618
|
}
|
|
619
619
|
| {
|
|
620
|
+
/**
|
|
621
|
+
* @deprecated
|
|
622
|
+
*/
|
|
620
623
|
type: 'done loading'
|
|
621
624
|
}
|
|
622
625
|
| {
|
|
@@ -633,6 +636,9 @@ declare type EditorEmittedEvent =
|
|
|
633
636
|
value: Array<PortableTextBlock> | undefined
|
|
634
637
|
}
|
|
635
638
|
| {
|
|
639
|
+
/**
|
|
640
|
+
* @deprecated
|
|
641
|
+
*/
|
|
636
642
|
type: 'loading'
|
|
637
643
|
}
|
|
638
644
|
| MutationEvent
|
|
@@ -2944,6 +2950,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
2944
2950
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
2945
2951
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
2946
2952
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
2953
|
+
value: Array<PortableTextBlock>
|
|
2947
2954
|
/**
|
|
2948
2955
|
* Use hotkeys
|
|
2949
2956
|
*/
|
|
@@ -3049,6 +3049,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
3049
3049
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
3050
3050
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
3051
3051
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
3052
|
+
value: Array<PortableTextBlock>
|
|
3052
3053
|
/**
|
|
3053
3054
|
* Use hotkeys
|
|
3054
3055
|
*/
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -3049,6 +3049,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
3049
3049
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
3050
3050
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
3051
3051
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
3052
|
+
value: Array<PortableTextBlock>
|
|
3052
3053
|
/**
|
|
3053
3054
|
* Use hotkeys
|
|
3054
3055
|
*/
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -2810,6 +2810,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
2810
2810
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
2811
2811
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
2812
2812
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
2813
|
+
value: Array<PortableTextBlock>
|
|
2813
2814
|
/**
|
|
2814
2815
|
* Use hotkeys
|
|
2815
2816
|
*/
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -2810,6 +2810,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
2810
2810
|
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
2811
2811
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
2812
2812
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
2813
|
+
value: Array<PortableTextBlock>
|
|
2813
2814
|
/**
|
|
2814
2815
|
* Use hotkeys
|
|
2815
2816
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.50.
|
|
3
|
+
"version": "1.50.4",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -68,9 +68,10 @@
|
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@portabletext/to-html": "^2.0.14",
|
|
71
|
-
"@xstate/react": "^5.0.
|
|
72
|
-
"debug": "^4.4.
|
|
71
|
+
"@xstate/react": "^5.0.4",
|
|
72
|
+
"debug": "^4.4.1",
|
|
73
73
|
"get-random-values-esm": "^1.0.2",
|
|
74
|
+
"immer": "^10.1.1",
|
|
74
75
|
"lodash": "^4.17.21",
|
|
75
76
|
"lodash.startcase": "^4.4.0",
|
|
76
77
|
"react-compiler-runtime": "19.1.0-rc.1",
|
|
@@ -78,23 +79,23 @@
|
|
|
78
79
|
"slate-dom": "^0.114.0",
|
|
79
80
|
"slate-react": "0.114.2",
|
|
80
81
|
"use-effect-event": "^1.0.2",
|
|
81
|
-
"xstate": "^5.19.
|
|
82
|
-
"@portabletext/
|
|
83
|
-
"@portabletext/
|
|
82
|
+
"xstate": "^5.19.3",
|
|
83
|
+
"@portabletext/patches": "1.1.3",
|
|
84
|
+
"@portabletext/block-tools": "1.1.27"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
87
|
"@portabletext/toolkit": "^2.0.17",
|
|
87
88
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
88
89
|
"@sanity/pkg-utils": "^7.2.2",
|
|
89
|
-
"@sanity/schema": "^3.
|
|
90
|
-
"@sanity/types": "^3.
|
|
90
|
+
"@sanity/schema": "^3.89.0",
|
|
91
|
+
"@sanity/types": "^3.89.0",
|
|
91
92
|
"@testing-library/jest-dom": "^6.6.3",
|
|
92
93
|
"@testing-library/react": "^16.3.0",
|
|
93
94
|
"@types/debug": "^4.1.12",
|
|
94
95
|
"@types/lodash": "^4.17.16",
|
|
95
96
|
"@types/lodash.startcase": "^4.4.9",
|
|
96
|
-
"@types/react": "^19.1.
|
|
97
|
-
"@types/react-dom": "^19.1.
|
|
97
|
+
"@types/react": "^19.1.4",
|
|
98
|
+
"@types/react-dom": "^19.1.5",
|
|
98
99
|
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
|
99
100
|
"@typescript-eslint/parser": "^8.32.1",
|
|
100
101
|
"@vitejs/plugin-react": "^4.4.1",
|
|
@@ -110,12 +111,12 @@
|
|
|
110
111
|
"typescript": "5.8.3",
|
|
111
112
|
"vite": "^6.2.5",
|
|
112
113
|
"vitest": "^3.1.3",
|
|
113
|
-
"vitest-browser-react": "^0.
|
|
114
|
+
"vitest-browser-react": "^0.2.0",
|
|
114
115
|
"racejar": "1.2.5"
|
|
115
116
|
},
|
|
116
117
|
"peerDependencies": {
|
|
117
|
-
"@sanity/schema": "^3.
|
|
118
|
-
"@sanity/types": "^3.
|
|
118
|
+
"@sanity/schema": "^3.89.0",
|
|
119
|
+
"@sanity/types": "^3.89.0",
|
|
119
120
|
"react": "^16.9 || ^17 || ^18 || ^19",
|
|
120
121
|
"rxjs": "^7.8.2"
|
|
121
122
|
},
|
|
@@ -138,6 +138,7 @@ export class PortableTextEditor extends Component<
|
|
|
138
138
|
syncActor: SyncActor
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
private subscriptions: Array<() => () => void> = []
|
|
141
142
|
private unsubscribers: Array<() => void> = []
|
|
142
143
|
|
|
143
144
|
constructor(props: PortableTextEditorProps) {
|
|
@@ -160,28 +161,7 @@ export class PortableTextEditor extends Component<
|
|
|
160
161
|
schema: props.schemaType,
|
|
161
162
|
})
|
|
162
163
|
|
|
163
|
-
this.
|
|
164
|
-
(() => {
|
|
165
|
-
const subscription = actors.relayActor.on('*', (event) => {
|
|
166
|
-
const change = eventToChange(event)
|
|
167
|
-
|
|
168
|
-
if (change) {
|
|
169
|
-
props.onChange(change)
|
|
170
|
-
|
|
171
|
-
this.change$.next(change)
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
return () => {
|
|
176
|
-
subscription.unsubscribe()
|
|
177
|
-
}
|
|
178
|
-
})(),
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
for (const subscription of subscriptions) {
|
|
182
|
-
this.unsubscribers.push(subscription())
|
|
183
|
-
}
|
|
184
|
-
|
|
164
|
+
this.subscriptions = subscriptions
|
|
185
165
|
this.actors = actors
|
|
186
166
|
|
|
187
167
|
this.editor = editor
|
|
@@ -198,6 +178,26 @@ export class PortableTextEditor extends Component<
|
|
|
198
178
|
return
|
|
199
179
|
}
|
|
200
180
|
|
|
181
|
+
for (const subscription of this.subscriptions) {
|
|
182
|
+
this.unsubscribers.push(subscription())
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const relayActorSubscription = this.actors.relayActor.on('*', (event) => {
|
|
186
|
+
const change = eventToChange(event)
|
|
187
|
+
|
|
188
|
+
if (!change) {
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!this.props.editor) {
|
|
193
|
+
this.props.onChange(change)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
this.change$.next(change)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
this.unsubscribers.push(relayActorSubscription.unsubscribe)
|
|
200
|
+
|
|
201
201
|
this.actors.editorActor.start()
|
|
202
202
|
this.actors.mutationActor.start()
|
|
203
203
|
this.actors.relayActor.start()
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {createEditor, type Descendant} from 'slate'
|
|
2
2
|
import {withReact} from 'slate-react'
|
|
3
|
+
import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block'
|
|
3
4
|
import {debugWithName} from '../internal-utils/debug'
|
|
5
|
+
import {toSlateValue} from '../internal-utils/values'
|
|
4
6
|
import {
|
|
5
7
|
KEY_TO_SLATE_ELEMENT,
|
|
6
8
|
KEY_TO_VALUE_ELEMENT,
|
|
@@ -35,7 +37,13 @@ export function createSlateEditor(config: SlateEditorConfig): SlateEditor {
|
|
|
35
37
|
KEY_TO_VALUE_ELEMENT.set(instance, {})
|
|
36
38
|
KEY_TO_SLATE_ELEMENT.set(instance, {})
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
instance.value = [
|
|
41
|
+
createPlaceholderBlock(config.editorActor.getSnapshot().context),
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const initialValue = toSlateValue(instance.value, {
|
|
45
|
+
schemaTypes: config.editorActor.getSnapshot().context.schema,
|
|
46
|
+
})
|
|
39
47
|
|
|
40
48
|
const slateEditor: SlateEditor = {
|
|
41
49
|
instance,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {useSelector} from '@xstate/react'
|
|
2
2
|
import type {Editor} from '../editor'
|
|
3
|
-
import {slateChildrenToBlocks} from '../internal-utils/slate-children-to-blocks'
|
|
4
3
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
5
4
|
import type {InternalEditor} from './create-editor'
|
|
6
5
|
import type {EditorActor} from './editor-machine'
|
|
@@ -78,10 +77,7 @@ export function getEditorSnapshot({
|
|
|
78
77
|
readOnly: editorActorSnapshot.matches({'edit mode': 'read only'}),
|
|
79
78
|
schema: editorActorSnapshot.context.schema,
|
|
80
79
|
selection: editorActorSnapshot.context.selection,
|
|
81
|
-
value:
|
|
82
|
-
editorActorSnapshot.context.schema,
|
|
83
|
-
slateEditorInstance.children,
|
|
84
|
-
),
|
|
80
|
+
value: slateEditorInstance.value,
|
|
85
81
|
},
|
|
86
82
|
beta: {
|
|
87
83
|
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import type {Converter} from '../converters/converter.types'
|
|
3
3
|
import type {EventPosition} from '../internal-utils/event-position'
|
|
4
|
-
import {slateChildrenToBlocks} from '../internal-utils/slate-children-to-blocks'
|
|
5
4
|
import {slateRangeToSelection} from '../internal-utils/slate-utils'
|
|
6
5
|
import type {EditorSelection, PortableTextSlateEditor} from '../types/editor'
|
|
7
6
|
import type {HasTag} from './editor-machine'
|
|
@@ -61,7 +60,6 @@ export function createEditorSnapshot({
|
|
|
61
60
|
}
|
|
62
61
|
| undefined
|
|
63
62
|
}) {
|
|
64
|
-
const value = slateChildrenToBlocks(schema, editor.children)
|
|
65
63
|
const selection = editor.selection
|
|
66
64
|
? slateRangeToSelection({
|
|
67
65
|
schema,
|
|
@@ -80,7 +78,7 @@ export function createEditorSnapshot({
|
|
|
80
78
|
readOnly,
|
|
81
79
|
schema,
|
|
82
80
|
selection,
|
|
83
|
-
value,
|
|
81
|
+
value: editor.value,
|
|
84
82
|
} satisfies EditorContext
|
|
85
83
|
|
|
86
84
|
return {
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import {insert, setIfMissing, unset, type Patch} from '@portabletext/patches'
|
|
2
|
-
import {
|
|
3
|
-
Editor,
|
|
4
|
-
type Descendant,
|
|
5
|
-
type InsertNodeOperation,
|
|
6
|
-
type InsertTextOperation,
|
|
7
|
-
type MergeNodeOperation,
|
|
8
|
-
type MoveNodeOperation,
|
|
9
|
-
type Operation,
|
|
10
|
-
type RemoveNodeOperation,
|
|
11
|
-
type RemoveTextOperation,
|
|
12
|
-
type SetNodeOperation,
|
|
13
|
-
type SplitNodeOperation,
|
|
14
|
-
} from 'slate'
|
|
2
|
+
import {Editor, type Descendant, type Operation} from 'slate'
|
|
15
3
|
import {createApplyPatch} from '../../internal-utils/applyPatch'
|
|
16
4
|
import {debugWithName} from '../../internal-utils/debug'
|
|
5
|
+
import {
|
|
6
|
+
insertNodePatch,
|
|
7
|
+
insertTextPatch,
|
|
8
|
+
mergeNodePatch,
|
|
9
|
+
moveNodePatch,
|
|
10
|
+
removeNodePatch,
|
|
11
|
+
removeTextPatch,
|
|
12
|
+
setNodePatch,
|
|
13
|
+
splitNodePatch,
|
|
14
|
+
} from '../../internal-utils/operation-to-patches'
|
|
17
15
|
import {fromSlateValue, isEqualToEmptyEditor} from '../../internal-utils/values'
|
|
18
16
|
import {
|
|
19
17
|
IS_PROCESSING_REMOTE_CHANGES,
|
|
@@ -34,60 +32,15 @@ import {withoutSaving} from './createWithUndoRedo'
|
|
|
34
32
|
const debug = debugWithName('plugin:withPatches')
|
|
35
33
|
const debugVerbose = false
|
|
36
34
|
|
|
37
|
-
export interface PatchFunctions {
|
|
38
|
-
insertNodePatch: (
|
|
39
|
-
editor: PortableTextSlateEditor,
|
|
40
|
-
operation: InsertNodeOperation,
|
|
41
|
-
previousChildren: Descendant[],
|
|
42
|
-
) => Patch[]
|
|
43
|
-
insertTextPatch: (
|
|
44
|
-
editor: PortableTextSlateEditor,
|
|
45
|
-
operation: InsertTextOperation,
|
|
46
|
-
previousChildren: Descendant[],
|
|
47
|
-
) => Patch[]
|
|
48
|
-
mergeNodePatch: (
|
|
49
|
-
editor: PortableTextSlateEditor,
|
|
50
|
-
operation: MergeNodeOperation,
|
|
51
|
-
previousChildren: Descendant[],
|
|
52
|
-
) => Patch[]
|
|
53
|
-
moveNodePatch: (
|
|
54
|
-
editor: PortableTextSlateEditor,
|
|
55
|
-
operation: MoveNodeOperation,
|
|
56
|
-
previousChildren: Descendant[],
|
|
57
|
-
) => Patch[]
|
|
58
|
-
removeNodePatch: (
|
|
59
|
-
editor: PortableTextSlateEditor,
|
|
60
|
-
operation: RemoveNodeOperation,
|
|
61
|
-
previousChildren: Descendant[],
|
|
62
|
-
) => Patch[]
|
|
63
|
-
removeTextPatch: (
|
|
64
|
-
editor: PortableTextSlateEditor,
|
|
65
|
-
operation: RemoveTextOperation,
|
|
66
|
-
previousChildren: Descendant[],
|
|
67
|
-
) => Patch[]
|
|
68
|
-
setNodePatch: (
|
|
69
|
-
editor: PortableTextSlateEditor,
|
|
70
|
-
operation: SetNodeOperation,
|
|
71
|
-
previousChildren: Descendant[],
|
|
72
|
-
) => Patch[]
|
|
73
|
-
splitNodePatch: (
|
|
74
|
-
editor: PortableTextSlateEditor,
|
|
75
|
-
operation: SplitNodeOperation,
|
|
76
|
-
previousChildren: Descendant[],
|
|
77
|
-
) => Patch[]
|
|
78
|
-
}
|
|
79
|
-
|
|
80
35
|
interface Options {
|
|
81
36
|
editorActor: EditorActor
|
|
82
37
|
relayActor: RelayActor
|
|
83
|
-
patchFunctions: PatchFunctions
|
|
84
38
|
subscriptions: Array<() => () => void>
|
|
85
39
|
}
|
|
86
40
|
|
|
87
41
|
export function createWithPatches({
|
|
88
42
|
editorActor,
|
|
89
43
|
relayActor,
|
|
90
|
-
patchFunctions,
|
|
91
44
|
subscriptions,
|
|
92
45
|
}: Options): (editor: PortableTextSlateEditor) => PortableTextSlateEditor {
|
|
93
46
|
// The previous editor children are needed to figure out the _key of deleted nodes
|
|
@@ -197,8 +150,9 @@ export function createWithPatches({
|
|
|
197
150
|
case 'insert_text':
|
|
198
151
|
patches = [
|
|
199
152
|
...patches,
|
|
200
|
-
...
|
|
201
|
-
|
|
153
|
+
...insertTextPatch(
|
|
154
|
+
editorActor.getSnapshot().context.schema,
|
|
155
|
+
editor.children,
|
|
202
156
|
operation,
|
|
203
157
|
previousChildren,
|
|
204
158
|
),
|
|
@@ -207,8 +161,9 @@ export function createWithPatches({
|
|
|
207
161
|
case 'remove_text':
|
|
208
162
|
patches = [
|
|
209
163
|
...patches,
|
|
210
|
-
...
|
|
211
|
-
|
|
164
|
+
...removeTextPatch(
|
|
165
|
+
editorActor.getSnapshot().context.schema,
|
|
166
|
+
editor.children,
|
|
212
167
|
operation,
|
|
213
168
|
previousChildren,
|
|
214
169
|
),
|
|
@@ -217,18 +172,19 @@ export function createWithPatches({
|
|
|
217
172
|
case 'remove_node':
|
|
218
173
|
patches = [
|
|
219
174
|
...patches,
|
|
220
|
-
...
|
|
221
|
-
|
|
222
|
-
operation,
|
|
175
|
+
...removeNodePatch(
|
|
176
|
+
editorActor.getSnapshot().context.schema,
|
|
223
177
|
previousChildren,
|
|
178
|
+
operation,
|
|
224
179
|
),
|
|
225
180
|
]
|
|
226
181
|
break
|
|
227
182
|
case 'split_node':
|
|
228
183
|
patches = [
|
|
229
184
|
...patches,
|
|
230
|
-
...
|
|
231
|
-
|
|
185
|
+
...splitNodePatch(
|
|
186
|
+
editorActor.getSnapshot().context.schema,
|
|
187
|
+
editor.children,
|
|
232
188
|
operation,
|
|
233
189
|
previousChildren,
|
|
234
190
|
),
|
|
@@ -237,8 +193,9 @@ export function createWithPatches({
|
|
|
237
193
|
case 'insert_node':
|
|
238
194
|
patches = [
|
|
239
195
|
...patches,
|
|
240
|
-
...
|
|
241
|
-
|
|
196
|
+
...insertNodePatch(
|
|
197
|
+
editorActor.getSnapshot().context.schema,
|
|
198
|
+
editor.children,
|
|
242
199
|
operation,
|
|
243
200
|
previousChildren,
|
|
244
201
|
),
|
|
@@ -247,14 +204,19 @@ export function createWithPatches({
|
|
|
247
204
|
case 'set_node':
|
|
248
205
|
patches = [
|
|
249
206
|
...patches,
|
|
250
|
-
...
|
|
207
|
+
...setNodePatch(
|
|
208
|
+
editorActor.getSnapshot().context.schema,
|
|
209
|
+
editor.children,
|
|
210
|
+
operation,
|
|
211
|
+
),
|
|
251
212
|
]
|
|
252
213
|
break
|
|
253
214
|
case 'merge_node':
|
|
254
215
|
patches = [
|
|
255
216
|
...patches,
|
|
256
|
-
...
|
|
257
|
-
|
|
217
|
+
...mergeNodePatch(
|
|
218
|
+
editorActor.getSnapshot().context.schema,
|
|
219
|
+
editor.children,
|
|
258
220
|
operation,
|
|
259
221
|
previousChildren,
|
|
260
222
|
),
|
|
@@ -263,10 +225,10 @@ export function createWithPatches({
|
|
|
263
225
|
case 'move_node':
|
|
264
226
|
patches = [
|
|
265
227
|
...patches,
|
|
266
|
-
...
|
|
267
|
-
|
|
268
|
-
operation,
|
|
228
|
+
...moveNodePatch(
|
|
229
|
+
editorActor.getSnapshot().context.schema,
|
|
269
230
|
previousChildren,
|
|
231
|
+
operation,
|
|
270
232
|
),
|
|
271
233
|
]
|
|
272
234
|
break
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {applyOperationToPortableText} from '../../internal-utils/apply-operation-to-portable-text'
|
|
2
|
+
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
3
|
+
import type {EditorContext} from '../editor-snapshot'
|
|
4
|
+
|
|
5
|
+
export function pluginUpdateValue(
|
|
6
|
+
context: Pick<EditorContext, 'keyGenerator' | 'schema'>,
|
|
7
|
+
editor: PortableTextSlateEditor,
|
|
8
|
+
) {
|
|
9
|
+
const {apply} = editor
|
|
10
|
+
|
|
11
|
+
editor.apply = (operation) => {
|
|
12
|
+
if (operation.type === 'set_selection') {
|
|
13
|
+
apply(operation)
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
editor.value = applyOperationToPortableText(
|
|
18
|
+
{
|
|
19
|
+
keyGenerator: context.keyGenerator,
|
|
20
|
+
schema: context.schema,
|
|
21
|
+
},
|
|
22
|
+
editor.value,
|
|
23
|
+
operation,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
apply(operation)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return editor
|
|
30
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {BaseOperation, Editor, Node, NodeEntry} from 'slate'
|
|
2
|
-
import {createOperationToPatches} from '../../internal-utils/operationToPatches'
|
|
3
2
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
4
3
|
import type {EditorActor} from '../editor-machine'
|
|
5
4
|
import type {RelayActor} from '../relay-machine'
|
|
@@ -14,6 +13,7 @@ import {createWithPortableTextSelections} from './createWithPortableTextSelectio
|
|
|
14
13
|
import {createWithSchemaTypes} from './createWithSchemaTypes'
|
|
15
14
|
import {createWithUndoRedo} from './createWithUndoRedo'
|
|
16
15
|
import {createWithUtils} from './createWithUtils'
|
|
16
|
+
import {pluginUpdateValue} from './slate-plugin.update-value'
|
|
17
17
|
|
|
18
18
|
export interface OriginalEditorFunctions {
|
|
19
19
|
apply: (operation: BaseOperation) => void
|
|
@@ -33,7 +33,6 @@ export const withPlugins = <T extends Editor>(
|
|
|
33
33
|
): PortableTextSlateEditor => {
|
|
34
34
|
const e = editor as T & PortableTextSlateEditor
|
|
35
35
|
const {editorActor, relayActor} = options
|
|
36
|
-
const operationToPatches = createOperationToPatches(editorActor)
|
|
37
36
|
const withObjectKeys = createWithObjectKeys(editorActor)
|
|
38
37
|
const withSchemaTypes = createWithSchemaTypes({
|
|
39
38
|
editorActor,
|
|
@@ -41,7 +40,6 @@ export const withPlugins = <T extends Editor>(
|
|
|
41
40
|
const withPatches = createWithPatches({
|
|
42
41
|
editorActor,
|
|
43
42
|
relayActor,
|
|
44
|
-
patchFunctions: operationToPatches,
|
|
45
43
|
subscriptions: options.subscriptions,
|
|
46
44
|
})
|
|
47
45
|
const withMaxBlocks = createWithMaxBlocks(editorActor)
|
|
@@ -71,7 +69,13 @@ export const withPlugins = <T extends Editor>(
|
|
|
71
69
|
withPlaceholderBlock(
|
|
72
70
|
withUtils(
|
|
73
71
|
withMaxBlocks(
|
|
74
|
-
withUndoRedo(
|
|
72
|
+
withUndoRedo(
|
|
73
|
+
withPatches(
|
|
74
|
+
withPortableTextSelections(
|
|
75
|
+
pluginUpdateValue(editorActor.getSnapshot().context, e),
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
),
|
|
75
79
|
),
|
|
76
80
|
),
|
|
77
81
|
),
|
|
@@ -13,6 +13,9 @@ export type EditorEmittedEvent =
|
|
|
13
13
|
event: FocusEvent<HTMLDivElement, Element>
|
|
14
14
|
}
|
|
15
15
|
| {
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
*/
|
|
16
19
|
type: 'done loading'
|
|
17
20
|
}
|
|
18
21
|
| {
|
|
@@ -29,6 +32,9 @@ export type EditorEmittedEvent =
|
|
|
29
32
|
value: Array<PortableTextBlock> | undefined
|
|
30
33
|
}
|
|
31
34
|
| {
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated
|
|
37
|
+
*/
|
|
32
38
|
type: 'loading'
|
|
33
39
|
}
|
|
34
40
|
| MutationEvent
|
|
@@ -79,6 +85,9 @@ export type PatchEvent = {
|
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
export type UnsetEvent = {
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use `'patch'` events instead
|
|
90
|
+
*/
|
|
82
91
|
type: 'unset'
|
|
83
92
|
previousValue: Array<PortableTextBlock>
|
|
84
93
|
}
|