@portabletext/editor 2.9.1 → 2.9.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/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +9 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +9 -9
- package/lib/_chunks-dts/behavior.types.action.d.ts +3 -3
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +9 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/index.cjs +268 -322
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +269 -323
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/package.json +3 -3
- package/src/behaviors/behavior.perform-event.ts +24 -80
- package/src/editor/plugins/create-with-event-listeners.ts +13 -14
- package/src/editor/sync-machine.ts +9 -0
- package/src/editor/with-performing-behavior-operation.ts +21 -0
- package/src/internal-utils/slate-utils.test.tsx +119 -0
- package/src/internal-utils/slate-utils.ts +14 -1
- package/src/internal-utils/text-marks.ts +1 -1
- package/src/internal-utils/values.ts +1 -55
- package/src/operations/behavior.operation.block.set.ts +17 -36
- package/src/operations/behavior.operations.ts +131 -128
- package/src/selectors/selector.get-mark-state.ts +19 -5
- package/src/editor/with-applying-behavior-operations.ts +0 -18
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {Editor} from 'slate'
|
|
1
2
|
import type {
|
|
2
3
|
AbstractBehaviorEventType,
|
|
3
4
|
SyntheticBehaviorEvent,
|
|
@@ -79,133 +80,135 @@ export function performOperation({
|
|
|
79
80
|
context: BehaviorOperationImplementationContext
|
|
80
81
|
operation: BehaviorOperation
|
|
81
82
|
}) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
83
|
+
Editor.withoutNormalizing(operation.editor, () => {
|
|
84
|
+
try {
|
|
85
|
+
switch (operation.type) {
|
|
86
|
+
case 'annotation.add': {
|
|
87
|
+
behaviorOperationImplementations['annotation.add']({
|
|
88
|
+
context,
|
|
89
|
+
operation: operation,
|
|
90
|
+
})
|
|
91
|
+
break
|
|
92
|
+
}
|
|
93
|
+
case 'annotation.remove': {
|
|
94
|
+
behaviorOperationImplementations['annotation.remove']({
|
|
95
|
+
context,
|
|
96
|
+
operation: operation,
|
|
97
|
+
})
|
|
98
|
+
break
|
|
99
|
+
}
|
|
100
|
+
case 'block.set': {
|
|
101
|
+
behaviorOperationImplementations['block.set']({
|
|
102
|
+
context,
|
|
103
|
+
operation: operation,
|
|
104
|
+
})
|
|
105
|
+
break
|
|
106
|
+
}
|
|
107
|
+
case 'block.unset': {
|
|
108
|
+
behaviorOperationImplementations['block.unset']({
|
|
109
|
+
context,
|
|
110
|
+
operation: operation,
|
|
111
|
+
})
|
|
112
|
+
break
|
|
113
|
+
}
|
|
114
|
+
case 'child.set': {
|
|
115
|
+
behaviorOperationImplementations['child.set']({
|
|
116
|
+
context,
|
|
117
|
+
operation: operation,
|
|
118
|
+
})
|
|
119
|
+
break
|
|
120
|
+
}
|
|
121
|
+
case 'child.unset': {
|
|
122
|
+
behaviorOperationImplementations['child.unset']({
|
|
123
|
+
context,
|
|
124
|
+
operation: operation,
|
|
125
|
+
})
|
|
126
|
+
break
|
|
127
|
+
}
|
|
128
|
+
case 'decorator.add': {
|
|
129
|
+
behaviorOperationImplementations['decorator.add']({
|
|
130
|
+
context,
|
|
131
|
+
operation: operation,
|
|
132
|
+
})
|
|
133
|
+
break
|
|
134
|
+
}
|
|
135
|
+
case 'decorator.remove': {
|
|
136
|
+
behaviorOperationImplementations['decorator.remove']({
|
|
137
|
+
context,
|
|
138
|
+
operation: operation,
|
|
139
|
+
})
|
|
140
|
+
break
|
|
141
|
+
}
|
|
142
|
+
case 'delete': {
|
|
143
|
+
behaviorOperationImplementations.delete({
|
|
144
|
+
context,
|
|
145
|
+
operation: operation,
|
|
146
|
+
})
|
|
147
|
+
break
|
|
148
|
+
}
|
|
149
|
+
case 'history.redo': {
|
|
150
|
+
behaviorOperationImplementations['history.redo']({
|
|
151
|
+
context,
|
|
152
|
+
operation: operation,
|
|
153
|
+
})
|
|
154
|
+
break
|
|
155
|
+
}
|
|
156
|
+
case 'history.undo': {
|
|
157
|
+
behaviorOperationImplementations['history.undo']({
|
|
158
|
+
context,
|
|
159
|
+
operation: operation,
|
|
160
|
+
})
|
|
161
|
+
break
|
|
162
|
+
}
|
|
163
|
+
case 'insert.block': {
|
|
164
|
+
behaviorOperationImplementations['insert.block']({
|
|
165
|
+
context,
|
|
166
|
+
operation: operation,
|
|
167
|
+
})
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
case 'insert.text': {
|
|
171
|
+
behaviorOperationImplementations['insert.text']({
|
|
172
|
+
context,
|
|
173
|
+
operation: operation,
|
|
174
|
+
})
|
|
175
|
+
break
|
|
176
|
+
}
|
|
177
|
+
case 'move.backward': {
|
|
178
|
+
behaviorOperationImplementations['move.backward']({
|
|
179
|
+
context,
|
|
180
|
+
operation: operation,
|
|
181
|
+
})
|
|
182
|
+
break
|
|
183
|
+
}
|
|
184
|
+
case 'move.block': {
|
|
185
|
+
behaviorOperationImplementations['move.block']({
|
|
186
|
+
context,
|
|
187
|
+
operation: operation,
|
|
188
|
+
})
|
|
189
|
+
break
|
|
190
|
+
}
|
|
191
|
+
case 'move.forward': {
|
|
192
|
+
behaviorOperationImplementations['move.forward']({
|
|
193
|
+
context,
|
|
194
|
+
operation: operation,
|
|
195
|
+
})
|
|
196
|
+
break
|
|
197
|
+
}
|
|
198
|
+
default: {
|
|
199
|
+
behaviorOperationImplementations.select({
|
|
200
|
+
context,
|
|
201
|
+
operation: operation,
|
|
202
|
+
})
|
|
203
|
+
break
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error(
|
|
208
|
+
new Error(
|
|
209
|
+
`Executing "${operation.type}" failed due to: ${error.message}`,
|
|
210
|
+
),
|
|
211
|
+
)
|
|
203
212
|
}
|
|
204
|
-
}
|
|
205
|
-
console.error(
|
|
206
|
-
new Error(
|
|
207
|
-
`Executing "${operation.type}" failed due to: ${error.message}`,
|
|
208
|
-
),
|
|
209
|
-
)
|
|
210
|
-
}
|
|
213
|
+
})
|
|
211
214
|
}
|
|
@@ -6,10 +6,16 @@ import {getNextSpan} from './selector.get-next-span'
|
|
|
6
6
|
import {getPreviousSpan} from './selector.get-previous-span'
|
|
7
7
|
import {getSelectedSpans} from './selector.get-selected-spans'
|
|
8
8
|
|
|
9
|
-
export type MarkState =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export type MarkState =
|
|
10
|
+
| {
|
|
11
|
+
state: 'unchanged'
|
|
12
|
+
marks: Array<string>
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
state: 'changed'
|
|
16
|
+
marks: Array<string>
|
|
17
|
+
previousMarks: Array<string>
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* Given that text is inserted at the current position, what marks should
|
|
@@ -106,21 +112,25 @@ export const getMarkState: EditorSelector<MarkState | undefined> = (
|
|
|
106
112
|
if (previousSpanHasSameMarks) {
|
|
107
113
|
return {
|
|
108
114
|
state: 'changed',
|
|
115
|
+
previousMarks: marks,
|
|
109
116
|
marks: previousSpan?.node.marks ?? [],
|
|
110
117
|
}
|
|
111
118
|
} else if (previousSpanHasSameAnnotations) {
|
|
112
119
|
return {
|
|
113
120
|
state: 'changed',
|
|
121
|
+
previousMarks: marks,
|
|
114
122
|
marks: previousSpan?.node.marks ?? [],
|
|
115
123
|
}
|
|
116
124
|
} else if (previousSpanHasSameAnnotation) {
|
|
117
125
|
return {
|
|
118
126
|
state: 'unchanged',
|
|
127
|
+
previousMarks: marks,
|
|
119
128
|
marks: focusSpan.node.marks ?? [],
|
|
120
129
|
}
|
|
121
130
|
} else if (!previousSpan) {
|
|
122
131
|
return {
|
|
123
132
|
state: 'changed',
|
|
133
|
+
previousMarks: marks,
|
|
124
134
|
marks: [],
|
|
125
135
|
}
|
|
126
136
|
}
|
|
@@ -135,6 +145,7 @@ export const getMarkState: EditorSelector<MarkState | undefined> = (
|
|
|
135
145
|
) {
|
|
136
146
|
return {
|
|
137
147
|
state: 'changed',
|
|
148
|
+
previousMarks: marks,
|
|
138
149
|
marks: nextSpan?.node.marks ?? [],
|
|
139
150
|
}
|
|
140
151
|
}
|
|
@@ -142,6 +153,7 @@ export const getMarkState: EditorSelector<MarkState | undefined> = (
|
|
|
142
153
|
if (!nextSpan) {
|
|
143
154
|
return {
|
|
144
155
|
state: 'changed',
|
|
156
|
+
previousMarks: marks,
|
|
145
157
|
marks: [],
|
|
146
158
|
}
|
|
147
159
|
}
|
|
@@ -152,11 +164,13 @@ export const getMarkState: EditorSelector<MarkState | undefined> = (
|
|
|
152
164
|
if (previousSpanHasAnnotations) {
|
|
153
165
|
return {
|
|
154
166
|
state: 'changed',
|
|
167
|
+
previousMarks: marks,
|
|
155
168
|
marks: [],
|
|
156
169
|
}
|
|
157
170
|
} else {
|
|
158
171
|
return {
|
|
159
172
|
state: 'changed',
|
|
173
|
+
previousMarks: marks,
|
|
160
174
|
marks: (previousSpan?.node.marks ?? []).filter((mark) =>
|
|
161
175
|
decorators.includes(mark),
|
|
162
176
|
),
|
|
@@ -166,6 +180,6 @@ export const getMarkState: EditorSelector<MarkState | undefined> = (
|
|
|
166
180
|
|
|
167
181
|
return {
|
|
168
182
|
state: 'unchanged',
|
|
169
|
-
marks
|
|
183
|
+
marks,
|
|
170
184
|
}
|
|
171
185
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {Editor} from 'slate'
|
|
2
|
-
import {defaultKeyGenerator} from './key-generator'
|
|
3
|
-
|
|
4
|
-
const CURRENT_OPERATION_ID: WeakMap<Editor, string | undefined> = new WeakMap()
|
|
5
|
-
|
|
6
|
-
export function withApplyingBehaviorOperations(editor: Editor, fn: () => void) {
|
|
7
|
-
CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator())
|
|
8
|
-
Editor.withoutNormalizing(editor, fn)
|
|
9
|
-
CURRENT_OPERATION_ID.set(editor, undefined)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function getCurrentOperationId(editor: Editor) {
|
|
13
|
-
return CURRENT_OPERATION_ID.get(editor)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function isApplyingBehaviorOperations(editor: Editor) {
|
|
17
|
-
return getCurrentOperationId(editor) !== undefined
|
|
18
|
-
}
|