@portabletext/editor 1.48.5 → 1.48.7
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/editor-provider.cjs +109 -112
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +110 -113
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +5 -0
- package/lib/plugins/index.d.ts +5 -0
- package/lib/plugins/index.js.map +1 -1
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.delete.ts +21 -1
- package/src/behavior-actions/behavior.actions.ts +0 -6
- package/src/behaviors/behavior.perform-event.ts +38 -67
- package/src/behaviors/behavior.types.event.ts +12 -4
- package/src/plugins/plugin.decorator-shortcut.ts +1 -0
- package/src/plugins/plugin.markdown.tsx +2 -0
- package/src/plugins/plugin.one-line.tsx +2 -0
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
import {debugWithName} from '../internal-utils/debug'
|
|
10
10
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
11
11
|
import {defaultBehaviors} from './behavior.default'
|
|
12
|
-
import type {InternalBehaviorAction} from './behavior.types.action'
|
|
13
12
|
import {
|
|
14
13
|
isAbstractBehaviorEvent,
|
|
15
14
|
isCustomBehaviorEvent,
|
|
16
15
|
isNativeBehaviorEvent,
|
|
16
|
+
isSyntheticBehaviorEvent,
|
|
17
17
|
} from './behavior.types.event'
|
|
18
18
|
|
|
19
19
|
const debug = debugWithName('behaviors:event')
|
|
@@ -55,16 +55,6 @@ export function performEvent({
|
|
|
55
55
|
}) {
|
|
56
56
|
debug(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2))
|
|
57
57
|
|
|
58
|
-
const defaultAction =
|
|
59
|
-
isCustomBehaviorEvent(event) ||
|
|
60
|
-
isNativeBehaviorEvent(event) ||
|
|
61
|
-
isAbstractBehaviorEvent(event)
|
|
62
|
-
? undefined
|
|
63
|
-
: ({
|
|
64
|
-
...event,
|
|
65
|
-
editor,
|
|
66
|
-
} satisfies InternalBehaviorAction)
|
|
67
|
-
|
|
68
58
|
const eventBehaviors = [
|
|
69
59
|
...remainingEventBehaviors,
|
|
70
60
|
...defaultBehaviors,
|
|
@@ -105,24 +95,30 @@ export function performEvent({
|
|
|
105
95
|
return behavior.on === event.type
|
|
106
96
|
})
|
|
107
97
|
|
|
108
|
-
if (eventBehaviors.length === 0) {
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
}
|
|
98
|
+
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
99
|
+
nativeEvent?.preventDefault()
|
|
112
100
|
|
|
113
101
|
withApplyingBehaviorActions(editor, () => {
|
|
114
102
|
try {
|
|
103
|
+
debug(
|
|
104
|
+
`(execute:${eventCategory(event)})`,
|
|
105
|
+
JSON.stringify(event, null, 2),
|
|
106
|
+
)
|
|
107
|
+
|
|
115
108
|
performAction({
|
|
116
109
|
context: {
|
|
117
110
|
keyGenerator,
|
|
118
111
|
schema,
|
|
119
112
|
},
|
|
120
|
-
action:
|
|
113
|
+
action: {
|
|
114
|
+
...event,
|
|
115
|
+
editor,
|
|
116
|
+
},
|
|
121
117
|
})
|
|
122
118
|
} catch (error) {
|
|
123
119
|
console.error(
|
|
124
120
|
new Error(
|
|
125
|
-
`
|
|
121
|
+
`Executing "${event.type}" failed due to: ${error.message}`,
|
|
126
122
|
),
|
|
127
123
|
)
|
|
128
124
|
}
|
|
@@ -234,54 +230,21 @@ export function performEvent({
|
|
|
234
230
|
continue
|
|
235
231
|
}
|
|
236
232
|
|
|
237
|
-
|
|
238
|
-
nativeEventPrevented = true
|
|
233
|
+
nativeEventPrevented = true
|
|
239
234
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const internalAction = {
|
|
255
|
-
...action.event,
|
|
256
|
-
editor,
|
|
257
|
-
}
|
|
258
|
-
let actionFailed = false
|
|
259
|
-
|
|
260
|
-
withApplyingBehaviorActions(editor, () => {
|
|
261
|
-
try {
|
|
262
|
-
performAction({
|
|
263
|
-
context: {
|
|
264
|
-
keyGenerator,
|
|
265
|
-
schema,
|
|
266
|
-
},
|
|
267
|
-
action: internalAction,
|
|
268
|
-
})
|
|
269
|
-
} catch (error) {
|
|
270
|
-
console.error(
|
|
271
|
-
new Error(
|
|
272
|
-
`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`,
|
|
273
|
-
),
|
|
274
|
-
)
|
|
275
|
-
actionFailed = true
|
|
276
|
-
}
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
if (actionFailed) {
|
|
280
|
-
break
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
editor.onChange()
|
|
284
|
-
}
|
|
235
|
+
performEvent({
|
|
236
|
+
mode: 'execute',
|
|
237
|
+
behaviors,
|
|
238
|
+
remainingEventBehaviors: isAbstractBehaviorEvent(action.event)
|
|
239
|
+
? behaviors
|
|
240
|
+
: [],
|
|
241
|
+
event: action.event,
|
|
242
|
+
editor,
|
|
243
|
+
keyGenerator,
|
|
244
|
+
schema,
|
|
245
|
+
getSnapshot,
|
|
246
|
+
nativeEvent: undefined,
|
|
247
|
+
})
|
|
285
248
|
}
|
|
286
249
|
})
|
|
287
250
|
|
|
@@ -353,19 +316,27 @@ export function performEvent({
|
|
|
353
316
|
break
|
|
354
317
|
}
|
|
355
318
|
|
|
356
|
-
if (!defaultBehaviorOverwritten &&
|
|
319
|
+
if (!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event)) {
|
|
357
320
|
nativeEvent?.preventDefault()
|
|
358
321
|
|
|
359
322
|
withApplyingBehaviorActions(editor, () => {
|
|
360
323
|
try {
|
|
324
|
+
debug(
|
|
325
|
+
`(execute:${eventCategory(event)})`,
|
|
326
|
+
JSON.stringify(event, null, 2),
|
|
327
|
+
)
|
|
328
|
+
|
|
361
329
|
performAction({
|
|
362
330
|
context: {keyGenerator, schema},
|
|
363
|
-
action:
|
|
331
|
+
action: {
|
|
332
|
+
...event,
|
|
333
|
+
editor,
|
|
334
|
+
},
|
|
364
335
|
})
|
|
365
336
|
} catch (error) {
|
|
366
337
|
console.error(
|
|
367
338
|
new Error(
|
|
368
|
-
`
|
|
339
|
+
`Executing "${event.type}" failed due to: ${error.message}`,
|
|
369
340
|
),
|
|
370
341
|
)
|
|
371
342
|
}
|
|
@@ -2,7 +2,7 @@ import type {KeyedSegment, PortableTextBlock} from '@sanity/types'
|
|
|
2
2
|
import type {TextUnit} from 'slate'
|
|
3
3
|
import type {EventPosition} from '../internal-utils/event-position'
|
|
4
4
|
import type {MIMEType} from '../internal-utils/mime-type'
|
|
5
|
-
import type {PickFromUnion, StrictExtract} from '../type-utils'
|
|
5
|
+
import type {OmitFromUnion, PickFromUnion, StrictExtract} from '../type-utils'
|
|
6
6
|
import type {BlockOffset} from '../types/block-offset'
|
|
7
7
|
import type {BlockWithOptionalKey} from '../types/block-with-optional-key'
|
|
8
8
|
import type {EditorSelection} from '../types/editor'
|
|
@@ -197,10 +197,18 @@ export type SyntheticBehaviorEvent =
|
|
|
197
197
|
|
|
198
198
|
export type InsertPlacement = 'auto' | 'after' | 'before'
|
|
199
199
|
|
|
200
|
-
export function
|
|
200
|
+
export function isSyntheticBehaviorEvent(
|
|
201
201
|
event: BehaviorEvent,
|
|
202
|
-
): event is
|
|
203
|
-
|
|
202
|
+
): event is OmitFromUnion<
|
|
203
|
+
SyntheticBehaviorEvent,
|
|
204
|
+
'type',
|
|
205
|
+
AbstractBehaviorEventType
|
|
206
|
+
> {
|
|
207
|
+
return (
|
|
208
|
+
!isCustomBehaviorEvent(event) &&
|
|
209
|
+
!isNativeBehaviorEvent(event) &&
|
|
210
|
+
!isAbstractBehaviorEvent(event)
|
|
211
|
+
)
|
|
204
212
|
}
|
|
205
213
|
|
|
206
214
|
/**************************************
|
|
@@ -18,6 +18,7 @@ import * as utils from '../utils'
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @beta
|
|
21
|
+
* @deprecated Install the plugin from `@portabletext/plugin-character-pair-decorator`
|
|
21
22
|
*/
|
|
22
23
|
export function DecoratorShortcutPlugin(config: {
|
|
23
24
|
decorator: ({schema}: {schema: EditorSchema}) => string | undefined
|
|
@@ -68,6 +68,8 @@ export type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
|
|
|
68
68
|
* )
|
|
69
69
|
* }
|
|
70
70
|
* ```
|
|
71
|
+
*
|
|
72
|
+
* @deprecated Install the plugin from `@portabletext/plugin-markdown-shortcuts`
|
|
71
73
|
*/
|
|
72
74
|
export function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {
|
|
73
75
|
const editor = useEditor()
|
|
@@ -115,6 +115,8 @@ const oneLineBehaviors = [
|
|
|
115
115
|
*
|
|
116
116
|
* Place it with as high priority as possible to make sure other plugins don't
|
|
117
117
|
* overwrite `insert.*` events before this plugin gets a chance to do so.
|
|
118
|
+
*
|
|
119
|
+
* @deprecated Install the plugin from `@portabletext/plugin-one-line`
|
|
118
120
|
*/
|
|
119
121
|
export function OneLinePlugin() {
|
|
120
122
|
return <BehaviorPlugin behaviors={oneLineBehaviors} />
|