@portabletext/editor 1.20.0 → 1.21.1
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/behavior.core.cjs +8 -68
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +11 -39
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/util.get-block-start-point.cjs +30 -0
- package/lib/_chunks-cjs/util.get-block-start-point.cjs.map +1 -0
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +71 -0
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs +6 -0
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +7 -66
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +5 -31
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/util.get-block-start-point.js +31 -0
- package/lib/_chunks-es/util.get-block-start-point.js.map +1 -0
- package/lib/_chunks-es/util.is-empty-text-block.js +73 -0
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.is-keyed-segment.js +7 -0
- package/lib/_chunks-es/util.is-keyed-segment.js.map +1 -0
- package/lib/behaviors/index.cjs +7 -7
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +179 -119
- package/lib/behaviors/index.d.ts +179 -119
- package/lib/behaviors/index.js +3 -2
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +112 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +870 -141
- package/lib/index.d.ts +870 -141
- package/lib/index.js +111 -19
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +73 -1
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +14 -0
- package/lib/selectors/index.d.ts +14 -0
- package/lib/selectors/index.js +73 -0
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +11 -0
- package/lib/utils/index.cjs.map +1 -0
- package/lib/utils/index.d.cts +87 -0
- package/lib/utils/index.d.ts +87 -0
- package/lib/utils/index.js +13 -0
- package/lib/utils/index.js.map +1 -0
- package/package.json +15 -9
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +1 -1
- package/src/behavior-actions/behavior.action.insert-block-object.ts +1 -1
- package/src/behavior-actions/behavior.action.insert-inline-object.ts +1 -1
- package/src/behavior-actions/behavior.action.text-block.set.ts +1 -1
- package/src/behavior-actions/behavior.action.text-block.unset.ts +1 -1
- package/src/behavior-actions/behavior.actions.ts +5 -5
- package/src/behaviors/behavior.code-editor.ts +1 -1
- package/src/behaviors/behavior.core.block-objects.ts +2 -2
- package/src/behaviors/behavior.core.decorators.ts +1 -1
- package/src/behaviors/behavior.core.lists.ts +2 -2
- package/src/behaviors/behavior.emoji-picker.ts +1 -1
- package/src/behaviors/behavior.links.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +2 -2
- package/src/behaviors/behavior.types.ts +52 -19
- package/src/behaviors/index.ts +1 -0
- package/src/editor/Editable.tsx +12 -12
- package/src/editor/PortableTextEditor.tsx +2 -2
- package/src/editor/components/DraggableBlock.tsx +2 -2
- package/src/editor/components/Element.tsx +3 -3
- package/src/editor/components/Leaf.tsx +1 -1
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/create-editor.ts +22 -20
- package/src/editor/create-slate-editor.tsx +5 -2
- package/src/editor/editor-machine.ts +115 -23
- package/src/editor/get-value.ts +2 -2
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -1
- package/src/editor/mutation-machine.ts +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +50 -4
- package/src/editor/plugins/createWithEditableAPI.ts +7 -7
- package/src/editor/plugins/createWithHotKeys.ts +2 -2
- package/src/editor/plugins/createWithInsertData.ts +7 -7
- package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
- package/src/editor/plugins/createWithObjectKeys.ts +2 -2
- package/src/editor/plugins/createWithPatches.ts +10 -10
- package/src/editor/plugins/createWithPlaceholderBlock.ts +3 -3
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +1 -1
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +4 -4
- package/src/editor/plugins/createWithPortableTextSelections.ts +6 -6
- package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
- package/src/editor/plugins/createWithUndoRedo.ts +5 -5
- package/src/editor/plugins/createWithUtils.ts +2 -2
- package/src/editor/plugins/with-plugins.ts +1 -1
- package/src/editor/sync-machine.ts +8 -5
- package/src/index.ts +5 -1
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.get-selection-text.test.ts +75 -0
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +7 -4
- package/src/selectors/selector.is-point-after-selection.ts +82 -0
- package/src/selectors/selector.is-point-before-selection.ts +82 -0
- package/src/utils/_exports/index.ts +1 -0
- package/src/utils/index.ts +11 -0
- package/src/{editor/utils/utils.block-offset.test.ts → utils/util.block-offset.test.ts} +1 -1
- package/src/{editor/utils/utils.block-offset.ts → utils/util.block-offset.ts} +23 -7
- package/src/{editor/utils/utils.get-start-point.ts → utils/util.get-block-start-point.ts} +5 -2
- package/src/utils/util.get-text-block-text.ts +8 -0
- package/src/{editor/utils/utils.ts → utils/util.is-empty-text-block.ts} +4 -5
- package/src/{editor/utils/utils.is-keyed-segment.ts → utils/util.is-keyed-segment.ts} +3 -0
- package/src/{editor/utils/utils.reverse-selection.ts → utils/util.reverse-selection.ts} +4 -1
- /package/src/{utils → internal-utils}/__tests__/dmpToOperations.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/operationToPatches.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/patchToOperations.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/ranges.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/valueNormalization.test.tsx +0 -0
- /package/src/{utils → internal-utils}/__tests__/values.test.ts +0 -0
- /package/src/{utils → internal-utils}/applyPatch.ts +0 -0
- /package/src/{utils → internal-utils}/debug.ts +0 -0
- /package/src/{utils → internal-utils}/is-hotkey.test.ts +0 -0
- /package/src/{utils → internal-utils}/is-hotkey.ts +0 -0
- /package/src/{utils → internal-utils}/looks-like-url.test.ts +0 -0
- /package/src/{utils → internal-utils}/looks-like-url.ts +0 -0
- /package/src/{utils → internal-utils}/operationToPatches.ts +0 -0
- /package/src/{utils → internal-utils}/paths.ts +0 -0
- /package/src/{utils → internal-utils}/ranges.ts +0 -0
- /package/src/{utils → internal-utils}/schema.ts +0 -0
- /package/src/{utils → internal-utils}/selection.ts +0 -0
- /package/src/{utils → internal-utils}/sibling-utils.ts +0 -0
- /package/src/{utils → internal-utils}/validateValue.ts +0 -0
- /package/src/{utils → internal-utils}/values.ts +0 -0
- /package/src/{utils → internal-utils}/weakMaps.ts +0 -0
- /package/src/{utils → internal-utils}/withChanges.ts +0 -0
- /package/src/{utils → internal-utils}/withUndoRedo.ts +0 -0
- /package/src/{utils → internal-utils}/withoutPatching.ts +0 -0
|
@@ -12,21 +12,23 @@ import {
|
|
|
12
12
|
} from 'xstate'
|
|
13
13
|
import {performAction} from '../behavior-actions/behavior.actions'
|
|
14
14
|
import {coreBehaviors} from '../behaviors/behavior.core'
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
import {
|
|
16
|
+
isCustomBehaviorEvent,
|
|
17
|
+
type Behavior,
|
|
18
|
+
type BehaviorAction,
|
|
19
|
+
type CustomBehaviorEvent,
|
|
20
|
+
type NativeBehaviorEvent,
|
|
21
|
+
type SyntheticBehaviorEvent,
|
|
20
22
|
} from '../behaviors/behavior.types'
|
|
23
|
+
import {toPortableTextRange} from '../internal-utils/ranges'
|
|
24
|
+
import {fromSlateValue} from '../internal-utils/values'
|
|
25
|
+
import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
|
|
21
26
|
import type {OmitFromUnion, PickFromUnion} from '../type-utils'
|
|
22
27
|
import type {
|
|
23
28
|
EditorSelection,
|
|
24
29
|
InvalidValueResolution,
|
|
25
30
|
PortableTextSlateEditor,
|
|
26
31
|
} from '../types/editor'
|
|
27
|
-
import {toPortableTextRange} from '../utils/ranges'
|
|
28
|
-
import {fromSlateValue} from '../utils/values'
|
|
29
|
-
import {KEY_TO_VALUE_ELEMENT} from '../utils/weakMaps'
|
|
30
32
|
import type {EditorSchema} from './define-schema'
|
|
31
33
|
import type {EditorContext} from './editor-snapshot'
|
|
32
34
|
import {getActiveDecorators} from './get-active-decorators'
|
|
@@ -77,8 +79,16 @@ export type InternalEditorEvent =
|
|
|
77
79
|
type: 'behavior event'
|
|
78
80
|
behaviorEvent: SyntheticBehaviorEvent | NativeBehaviorEvent
|
|
79
81
|
editor: PortableTextSlateEditor
|
|
82
|
+
defaultActionCallback?: () => void
|
|
83
|
+
nativeEvent?: {preventDefault: () => void}
|
|
84
|
+
}
|
|
85
|
+
| {
|
|
86
|
+
type: 'custom behavior event'
|
|
87
|
+
behaviorEvent: CustomBehaviorEvent
|
|
88
|
+
editor: PortableTextSlateEditor
|
|
80
89
|
nativeEvent?: {preventDefault: () => void}
|
|
81
90
|
}
|
|
91
|
+
| CustomBehaviorEvent
|
|
82
92
|
| {
|
|
83
93
|
type: 'add behavior'
|
|
84
94
|
behavior: Behavior
|
|
@@ -182,6 +192,10 @@ export type InternalEditorEmittedEvent =
|
|
|
182
192
|
| 'focus'
|
|
183
193
|
| 'style.toggle'
|
|
184
194
|
>
|
|
195
|
+
| {
|
|
196
|
+
type: 'custom.*'
|
|
197
|
+
event: CustomBehaviorEvent
|
|
198
|
+
}
|
|
185
199
|
|
|
186
200
|
/**
|
|
187
201
|
* @internal
|
|
@@ -264,9 +278,10 @@ export const editorMachine = setup({
|
|
|
264
278
|
pendingEvents: [],
|
|
265
279
|
}),
|
|
266
280
|
'handle behavior event': enqueueActions(({context, event, enqueue}) => {
|
|
267
|
-
assertEvent(event, ['behavior event'])
|
|
281
|
+
assertEvent(event, ['behavior event', 'custom behavior event'])
|
|
268
282
|
|
|
269
283
|
const defaultAction =
|
|
284
|
+
event.type === 'custom behavior event' ||
|
|
270
285
|
event.behaviorEvent.type === 'copy' ||
|
|
271
286
|
event.behaviorEvent.type === 'key.down' ||
|
|
272
287
|
event.behaviorEvent.type === 'key.up' ||
|
|
@@ -276,22 +291,51 @@ export const editorMachine = setup({
|
|
|
276
291
|
...event.behaviorEvent,
|
|
277
292
|
editor: event.editor,
|
|
278
293
|
} satisfies BehaviorAction)
|
|
294
|
+
const defaultActionCallback =
|
|
295
|
+
event.type === 'behavior event'
|
|
296
|
+
? event.defaultActionCallback
|
|
297
|
+
: undefined
|
|
279
298
|
|
|
280
299
|
const eventBehaviors = [...context.behaviors.values()].filter(
|
|
281
300
|
(behavior) => behavior.on === event.behaviorEvent.type,
|
|
282
301
|
)
|
|
283
302
|
|
|
284
303
|
if (eventBehaviors.length === 0) {
|
|
304
|
+
if (defaultActionCallback) {
|
|
305
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
306
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
307
|
+
try {
|
|
308
|
+
defaultActionCallback()
|
|
309
|
+
} catch (error) {
|
|
310
|
+
console.error(
|
|
311
|
+
new Error(
|
|
312
|
+
`Performing action "${event.behaviorEvent.type}" failed due to: ${error.message}`,
|
|
313
|
+
),
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
})
|
|
317
|
+
})
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
|
|
285
321
|
if (!defaultAction) {
|
|
286
322
|
return
|
|
287
323
|
}
|
|
288
324
|
|
|
289
325
|
withApplyingBehaviorActions(event.editor, () => {
|
|
290
326
|
Editor.withoutNormalizing(event.editor, () => {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
327
|
+
try {
|
|
328
|
+
performAction({
|
|
329
|
+
context,
|
|
330
|
+
action: defaultAction,
|
|
331
|
+
})
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error(
|
|
334
|
+
new Error(
|
|
335
|
+
`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`,
|
|
336
|
+
),
|
|
337
|
+
)
|
|
338
|
+
}
|
|
295
339
|
})
|
|
296
340
|
})
|
|
297
341
|
event.editor.onChange()
|
|
@@ -353,11 +397,19 @@ export const editorMachine = setup({
|
|
|
353
397
|
Editor.withoutNormalizing(event.editor, () => {
|
|
354
398
|
for (const actionIntend of actionIntends) {
|
|
355
399
|
if (actionIntend.type === 'raise') {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
400
|
+
if (isCustomBehaviorEvent(actionIntend.event)) {
|
|
401
|
+
enqueue.raise({
|
|
402
|
+
type: 'custom behavior event',
|
|
403
|
+
behaviorEvent: actionIntend.event as CustomBehaviorEvent,
|
|
404
|
+
editor: event.editor,
|
|
405
|
+
})
|
|
406
|
+
} else {
|
|
407
|
+
enqueue.raise({
|
|
408
|
+
type: 'behavior event',
|
|
409
|
+
behaviorEvent: actionIntend.event,
|
|
410
|
+
editor: event.editor,
|
|
411
|
+
})
|
|
412
|
+
}
|
|
361
413
|
continue
|
|
362
414
|
}
|
|
363
415
|
|
|
@@ -366,7 +418,16 @@ export const editorMachine = setup({
|
|
|
366
418
|
editor: event.editor,
|
|
367
419
|
}
|
|
368
420
|
|
|
369
|
-
|
|
421
|
+
try {
|
|
422
|
+
performAction({context, action})
|
|
423
|
+
} catch (error) {
|
|
424
|
+
console.error(
|
|
425
|
+
new Error(
|
|
426
|
+
`Performing action "${action.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`,
|
|
427
|
+
),
|
|
428
|
+
)
|
|
429
|
+
break
|
|
430
|
+
}
|
|
370
431
|
}
|
|
371
432
|
})
|
|
372
433
|
})
|
|
@@ -380,16 +441,41 @@ export const editorMachine = setup({
|
|
|
380
441
|
}
|
|
381
442
|
|
|
382
443
|
if (!behaviorOverwritten) {
|
|
444
|
+
if (defaultActionCallback) {
|
|
445
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
446
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
447
|
+
try {
|
|
448
|
+
defaultActionCallback()
|
|
449
|
+
} catch (error) {
|
|
450
|
+
console.error(
|
|
451
|
+
new Error(
|
|
452
|
+
`Performing "${event.behaviorEvent.type}" failed due to: ${error.message}`,
|
|
453
|
+
),
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
})
|
|
457
|
+
})
|
|
458
|
+
return
|
|
459
|
+
}
|
|
460
|
+
|
|
383
461
|
if (!defaultAction) {
|
|
384
462
|
return
|
|
385
463
|
}
|
|
386
464
|
|
|
387
465
|
withApplyingBehaviorActions(event.editor, () => {
|
|
388
466
|
Editor.withoutNormalizing(event.editor, () => {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
467
|
+
try {
|
|
468
|
+
performAction({
|
|
469
|
+
context,
|
|
470
|
+
action: defaultAction,
|
|
471
|
+
})
|
|
472
|
+
} catch (error) {
|
|
473
|
+
console.error(
|
|
474
|
+
new Error(
|
|
475
|
+
`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`,
|
|
476
|
+
),
|
|
477
|
+
)
|
|
478
|
+
}
|
|
393
479
|
})
|
|
394
480
|
})
|
|
395
481
|
event.editor.onChange()
|
|
@@ -475,12 +561,18 @@ export const editorMachine = setup({
|
|
|
475
561
|
'behavior event': {
|
|
476
562
|
actions: 'handle behavior event',
|
|
477
563
|
},
|
|
564
|
+
'custom behavior event': {
|
|
565
|
+
actions: 'handle behavior event',
|
|
566
|
+
},
|
|
478
567
|
'annotation.*': {
|
|
479
568
|
actions: emit(({event}) => event),
|
|
480
569
|
},
|
|
481
570
|
'blur': {
|
|
482
571
|
actions: emit(({event}) => event),
|
|
483
572
|
},
|
|
573
|
+
'custom.*': {
|
|
574
|
+
actions: emit(({event}) => ({type: 'custom.*', event})),
|
|
575
|
+
},
|
|
484
576
|
'decorator.*': {
|
|
485
577
|
actions: emit(({event}) => event),
|
|
486
578
|
},
|
package/src/editor/get-value.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {fromSlateValue} from '../internal-utils/values'
|
|
2
|
+
import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
|
|
1
3
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
2
|
-
import {fromSlateValue} from '../utils/values'
|
|
3
|
-
import {KEY_TO_VALUE_ELEMENT} from '../utils/weakMaps'
|
|
4
4
|
import type {EditorActor} from './editor-machine'
|
|
5
5
|
|
|
6
6
|
export function getValue({
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
useEffect,
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react'
|
|
8
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
8
9
|
import type {EditorSelection} from '../../types/editor'
|
|
9
|
-
import {debugWithName} from '../../utils/debug'
|
|
10
10
|
import type {EditorActor} from '../editor-machine'
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -2,9 +2,9 @@ import type {Patch} from '@portabletext/patches'
|
|
|
2
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import {Editor} from 'slate'
|
|
4
4
|
import {assign, emit, setup} from 'xstate'
|
|
5
|
+
import {fromSlateValue} from '../internal-utils/values'
|
|
6
|
+
import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
|
|
5
7
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
6
|
-
import {fromSlateValue} from '../utils/values'
|
|
7
|
-
import {KEY_TO_VALUE_ELEMENT} from '../utils/weakMaps'
|
|
8
8
|
import type {EditorSchema} from './define-schema'
|
|
9
9
|
|
|
10
10
|
const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === 'test' ? 500 : 1000
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Editor} from 'slate'
|
|
2
|
-
import {toPortableTextRange} from '../../utils/ranges'
|
|
3
|
-
import {fromSlateValue} from '../../utils/values'
|
|
4
|
-
import {KEY_TO_VALUE_ELEMENT} from '../../utils/weakMaps'
|
|
2
|
+
import {toPortableTextRange} from '../../internal-utils/ranges'
|
|
3
|
+
import {fromSlateValue} from '../../internal-utils/values'
|
|
4
|
+
import {KEY_TO_VALUE_ELEMENT} from '../../internal-utils/weakMaps'
|
|
5
5
|
import type {EditorActor} from '../editor-machine'
|
|
6
6
|
import {isApplyingBehaviorActions} from '../with-applying-behavior-actions'
|
|
7
7
|
|
|
@@ -49,6 +49,14 @@ export function createWithEventListeners(
|
|
|
49
49
|
})
|
|
50
50
|
break
|
|
51
51
|
}
|
|
52
|
+
case 'custom.*': {
|
|
53
|
+
editorActor.send({
|
|
54
|
+
type: 'custom behavior event',
|
|
55
|
+
behaviorEvent: event.event,
|
|
56
|
+
editor,
|
|
57
|
+
})
|
|
58
|
+
break
|
|
59
|
+
}
|
|
52
60
|
case 'decorator.toggle': {
|
|
53
61
|
editorActor.send({
|
|
54
62
|
type: 'behavior event',
|
|
@@ -134,9 +142,21 @@ export function createWithEventListeners(
|
|
|
134
142
|
}
|
|
135
143
|
})
|
|
136
144
|
|
|
137
|
-
const {
|
|
145
|
+
const {
|
|
146
|
+
deleteBackward,
|
|
147
|
+
deleteForward,
|
|
148
|
+
insertBreak,
|
|
149
|
+
insertSoftBreak,
|
|
150
|
+
insertText,
|
|
151
|
+
select,
|
|
152
|
+
} = editor
|
|
138
153
|
|
|
139
154
|
editor.deleteBackward = (unit) => {
|
|
155
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
156
|
+
deleteBackward(unit)
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
140
160
|
editorActor.send({
|
|
141
161
|
type: 'behavior event',
|
|
142
162
|
behaviorEvent: {
|
|
@@ -149,6 +169,11 @@ export function createWithEventListeners(
|
|
|
149
169
|
}
|
|
150
170
|
|
|
151
171
|
editor.deleteForward = (unit) => {
|
|
172
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
173
|
+
deleteForward(unit)
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
|
|
152
177
|
editorActor.send({
|
|
153
178
|
type: 'behavior event',
|
|
154
179
|
behaviorEvent: {
|
|
@@ -161,6 +186,11 @@ export function createWithEventListeners(
|
|
|
161
186
|
}
|
|
162
187
|
|
|
163
188
|
editor.insertBreak = () => {
|
|
189
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
190
|
+
insertBreak()
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
164
194
|
editorActor.send({
|
|
165
195
|
type: 'behavior event',
|
|
166
196
|
behaviorEvent: {
|
|
@@ -172,6 +202,11 @@ export function createWithEventListeners(
|
|
|
172
202
|
}
|
|
173
203
|
|
|
174
204
|
editor.insertSoftBreak = () => {
|
|
205
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
206
|
+
insertSoftBreak()
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
|
|
175
210
|
editorActor.send({
|
|
176
211
|
type: 'behavior event',
|
|
177
212
|
behaviorEvent: {
|
|
@@ -183,6 +218,11 @@ export function createWithEventListeners(
|
|
|
183
218
|
}
|
|
184
219
|
|
|
185
220
|
editor.insertText = (text, options) => {
|
|
221
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
222
|
+
insertText(text, options)
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
|
|
186
226
|
editorActor.send({
|
|
187
227
|
type: 'behavior event',
|
|
188
228
|
behaviorEvent: {
|
|
@@ -191,6 +231,9 @@ export function createWithEventListeners(
|
|
|
191
231
|
options,
|
|
192
232
|
},
|
|
193
233
|
editor,
|
|
234
|
+
defaultActionCallback: () => {
|
|
235
|
+
insertText(text, options)
|
|
236
|
+
},
|
|
194
237
|
})
|
|
195
238
|
return
|
|
196
239
|
}
|
|
@@ -218,6 +261,9 @@ export function createWithEventListeners(
|
|
|
218
261
|
),
|
|
219
262
|
},
|
|
220
263
|
editor,
|
|
264
|
+
defaultActionCallback: () => {
|
|
265
|
+
select(location)
|
|
266
|
+
},
|
|
221
267
|
})
|
|
222
268
|
return
|
|
223
269
|
}
|
|
@@ -21,19 +21,19 @@ import {ReactEditor} from 'slate-react'
|
|
|
21
21
|
import {isListItemActive} from '../../behavior-actions/behavior.action.list-item'
|
|
22
22
|
import {isStyleActive} from '../../behavior-actions/behavior.action.style'
|
|
23
23
|
import type {BehaviorActionImplementation} from '../../behavior-actions/behavior.actions'
|
|
24
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
25
|
+
import {toPortableTextRange, toSlateRange} from '../../internal-utils/ranges'
|
|
26
|
+
import {fromSlateValue, toSlateValue} from '../../internal-utils/values'
|
|
27
|
+
import {
|
|
28
|
+
KEY_TO_VALUE_ELEMENT,
|
|
29
|
+
SLATE_TO_PORTABLE_TEXT_RANGE,
|
|
30
|
+
} from '../../internal-utils/weakMaps'
|
|
24
31
|
import type {
|
|
25
32
|
EditableAPI,
|
|
26
33
|
EditableAPIDeleteOptions,
|
|
27
34
|
EditorSelection,
|
|
28
35
|
PortableTextSlateEditor,
|
|
29
36
|
} from '../../types/editor'
|
|
30
|
-
import {debugWithName} from '../../utils/debug'
|
|
31
|
-
import {toPortableTextRange, toSlateRange} from '../../utils/ranges'
|
|
32
|
-
import {fromSlateValue, toSlateValue} from '../../utils/values'
|
|
33
|
-
import {
|
|
34
|
-
KEY_TO_VALUE_ELEMENT,
|
|
35
|
-
SLATE_TO_PORTABLE_TEXT_RANGE,
|
|
36
|
-
} from '../../utils/weakMaps'
|
|
37
37
|
import type {EditorActor} from '../editor-machine'
|
|
38
38
|
import {isDecoratorActive} from './createWithPortableTextMarkModel'
|
|
39
39
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {KeyboardEvent} from 'react'
|
|
2
2
|
import type {ReactEditor} from 'slate-react'
|
|
3
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
4
|
+
import {isHotkey} from '../../internal-utils/is-hotkey'
|
|
3
5
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
4
6
|
import type {HotkeyOptions} from '../../types/options'
|
|
5
|
-
import {debugWithName} from '../../utils/debug'
|
|
6
|
-
import {isHotkey} from '../../utils/is-hotkey'
|
|
7
7
|
import type {EditorActor} from '../editor-machine'
|
|
8
8
|
import type {PortableTextEditor} from '../PortableTextEditor'
|
|
9
9
|
|
|
@@ -3,17 +3,17 @@ import type {PortableTextBlock, PortableTextChild} from '@sanity/types'
|
|
|
3
3
|
import {isEqual, uniq} from 'lodash'
|
|
4
4
|
import {Editor, Range, Transforms, type Descendant, type Node} from 'slate'
|
|
5
5
|
import {ReactEditor} from 'slate-react'
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
PortableTextSlateEditor,
|
|
9
|
-
} from '../../types/editor'
|
|
10
|
-
import {debugWithName} from '../../utils/debug'
|
|
11
|
-
import {validateValue} from '../../utils/validateValue'
|
|
6
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
7
|
+
import {validateValue} from '../../internal-utils/validateValue'
|
|
12
8
|
import {
|
|
13
9
|
fromSlateValue,
|
|
14
10
|
isEqualToEmptyEditor,
|
|
15
11
|
toSlateValue,
|
|
16
|
-
} from '../../utils/values'
|
|
12
|
+
} from '../../internal-utils/values'
|
|
13
|
+
import type {
|
|
14
|
+
PortableTextMemberSchemaTypes,
|
|
15
|
+
PortableTextSlateEditor,
|
|
16
|
+
} from '../../types/editor'
|
|
17
17
|
import type {EditorActor} from '../editor-machine'
|
|
18
18
|
|
|
19
19
|
const debug = debugWithName('plugin:withInsertData')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isChangingRemotely} from '../../internal-utils/withChanges'
|
|
2
|
+
import {isRedoing, isUndoing} from '../../internal-utils/withUndoRedo'
|
|
1
3
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
2
|
-
import {isChangingRemotely} from '../../utils/withChanges'
|
|
3
|
-
import {isRedoing, isUndoing} from '../../utils/withUndoRedo'
|
|
4
4
|
import type {EditorActor} from '../editor-machine'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {Editor, Element, Node, Transforms} from 'slate'
|
|
2
|
+
import {isChangingRemotely} from '../../internal-utils/withChanges'
|
|
3
|
+
import {isRedoing, isUndoing} from '../../internal-utils/withUndoRedo'
|
|
2
4
|
import type {
|
|
3
5
|
PortableTextMemberSchemaTypes,
|
|
4
6
|
PortableTextSlateEditor,
|
|
5
7
|
} from '../../types/editor'
|
|
6
|
-
import {isChangingRemotely} from '../../utils/withChanges'
|
|
7
|
-
import {isRedoing, isUndoing} from '../../utils/withUndoRedo'
|
|
8
8
|
import type {EditorActor} from '../editor-machine'
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -12,23 +12,23 @@ import {
|
|
|
12
12
|
type SetNodeOperation,
|
|
13
13
|
type SplitNodeOperation,
|
|
14
14
|
} from 'slate'
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from '../../types/editor'
|
|
19
|
-
import {createApplyPatch} from '../../utils/applyPatch'
|
|
20
|
-
import {debugWithName} from '../../utils/debug'
|
|
21
|
-
import {fromSlateValue, isEqualToEmptyEditor} from '../../utils/values'
|
|
15
|
+
import {createApplyPatch} from '../../internal-utils/applyPatch'
|
|
16
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
17
|
+
import {fromSlateValue, isEqualToEmptyEditor} from '../../internal-utils/values'
|
|
22
18
|
import {
|
|
23
19
|
IS_PROCESSING_REMOTE_CHANGES,
|
|
24
20
|
KEY_TO_VALUE_ELEMENT,
|
|
25
|
-
} from '../../utils/weakMaps'
|
|
26
|
-
import {withRemoteChanges} from '../../utils/withChanges'
|
|
21
|
+
} from '../../internal-utils/weakMaps'
|
|
22
|
+
import {withRemoteChanges} from '../../internal-utils/withChanges'
|
|
27
23
|
import {
|
|
28
24
|
isPatching,
|
|
29
25
|
PATCHING,
|
|
30
26
|
withoutPatching,
|
|
31
|
-
} from '../../utils/withoutPatching'
|
|
27
|
+
} from '../../internal-utils/withoutPatching'
|
|
28
|
+
import type {
|
|
29
|
+
PortableTextMemberSchemaTypes,
|
|
30
|
+
PortableTextSlateEditor,
|
|
31
|
+
} from '../../types/editor'
|
|
32
32
|
import type {EditorActor} from '../editor-machine'
|
|
33
33
|
import {withoutSaving} from './createWithUndoRedo'
|
|
34
34
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {Editor, Path} from 'slate'
|
|
2
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
3
|
+
import {isChangingRemotely} from '../../internal-utils/withChanges'
|
|
4
|
+
import {isRedoing, isUndoing} from '../../internal-utils/withUndoRedo'
|
|
2
5
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
3
6
|
import type {SlateTextBlock, VoidElement} from '../../types/slate'
|
|
4
|
-
import {debugWithName} from '../../utils/debug'
|
|
5
|
-
import {isChangingRemotely} from '../../utils/withChanges'
|
|
6
|
-
import {isRedoing, isUndoing} from '../../utils/withUndoRedo'
|
|
7
7
|
import type {EditorActor} from '../editor-machine'
|
|
8
8
|
|
|
9
9
|
const debug = debugWithName('plugin:withPlaceholderBlock')
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {Editor, Path, Text as SlateText, Transforms} from 'slate'
|
|
2
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
2
3
|
import type {
|
|
3
4
|
PortableTextMemberSchemaTypes,
|
|
4
5
|
PortableTextSlateEditor,
|
|
5
6
|
} from '../../types/editor'
|
|
6
|
-
import {debugWithName} from '../../utils/debug'
|
|
7
7
|
import type {EditorActor} from '../editor-machine'
|
|
8
8
|
|
|
9
9
|
const debug = debugWithName('plugin:withPortableTextBlockStyle')
|
|
@@ -9,14 +9,14 @@ import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
|
9
9
|
import {isEqual, uniq} from 'lodash'
|
|
10
10
|
import {Editor, Element, Node, Path, Range, Text, Transforms} from 'slate'
|
|
11
11
|
import type {BehaviorActionImplementation} from '../../behavior-actions/behavior.actions'
|
|
12
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
13
|
+
import {getNextSpan, getPreviousSpan} from '../../internal-utils/sibling-utils'
|
|
14
|
+
import {isChangingRemotely} from '../../internal-utils/withChanges'
|
|
15
|
+
import {isRedoing, isUndoing} from '../../internal-utils/withUndoRedo'
|
|
12
16
|
import type {
|
|
13
17
|
PortableTextMemberSchemaTypes,
|
|
14
18
|
PortableTextSlateEditor,
|
|
15
19
|
} from '../../types/editor'
|
|
16
|
-
import {debugWithName} from '../../utils/debug'
|
|
17
|
-
import {getNextSpan, getPreviousSpan} from '../../utils/sibling-utils'
|
|
18
|
-
import {isChangingRemotely} from '../../utils/withChanges'
|
|
19
|
-
import {isRedoing, isUndoing} from '../../utils/withUndoRedo'
|
|
20
20
|
import type {EditorActor} from '../editor-machine'
|
|
21
21
|
|
|
22
22
|
const debug = debugWithName('plugin:withPortableTextMarkModel')
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type {BaseRange} from 'slate'
|
|
2
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
3
|
+
import {
|
|
4
|
+
toPortableTextRange,
|
|
5
|
+
type ObjectWithKeyAndType,
|
|
6
|
+
} from '../../internal-utils/ranges'
|
|
7
|
+
import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../../internal-utils/weakMaps'
|
|
2
8
|
import type {
|
|
3
9
|
EditorSelection,
|
|
4
10
|
PortableTextMemberSchemaTypes,
|
|
5
11
|
PortableTextSlateEditor,
|
|
6
12
|
} from '../../types/editor'
|
|
7
|
-
import {debugWithName} from '../../utils/debug'
|
|
8
|
-
import {
|
|
9
|
-
toPortableTextRange,
|
|
10
|
-
type ObjectWithKeyAndType,
|
|
11
|
-
} from '../../utils/ranges'
|
|
12
|
-
import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../../utils/weakMaps'
|
|
13
13
|
import type {EditorActor} from '../editor-machine'
|
|
14
14
|
|
|
15
15
|
const debug = debugWithName('plugin:withPortableTextSelections')
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
type PortableTextTextBlock,
|
|
8
8
|
} from '@sanity/types'
|
|
9
9
|
import {Transforms, type Element} from 'slate'
|
|
10
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
10
11
|
import type {
|
|
11
12
|
PortableTextMemberSchemaTypes,
|
|
12
13
|
PortableTextSlateEditor,
|
|
13
14
|
} from '../../types/editor'
|
|
14
|
-
import {debugWithName} from '../../utils/debug'
|
|
15
15
|
import type {EditorActor} from '../editor-machine'
|
|
16
16
|
|
|
17
17
|
const debug = debugWithName('plugin:withSchemaTypes')
|
|
@@ -20,10 +20,9 @@ import {
|
|
|
20
20
|
type Descendant,
|
|
21
21
|
type SelectionOperation,
|
|
22
22
|
} from 'slate'
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {isChangingRemotely} from '../../utils/withChanges'
|
|
23
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
24
|
+
import {fromSlateValue} from '../../internal-utils/values'
|
|
25
|
+
import {isChangingRemotely} from '../../internal-utils/withChanges'
|
|
27
26
|
import {
|
|
28
27
|
isRedoing,
|
|
29
28
|
isUndoing,
|
|
@@ -31,7 +30,8 @@ import {
|
|
|
31
30
|
setIsUndoing,
|
|
32
31
|
withRedoing,
|
|
33
32
|
withUndoing,
|
|
34
|
-
} from '../../utils/withUndoRedo'
|
|
33
|
+
} from '../../internal-utils/withUndoRedo'
|
|
34
|
+
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
35
35
|
import type {EditorActor} from '../editor-machine'
|
|
36
36
|
|
|
37
37
|
const debug = debugWithName('plugin:withUndoRedo')
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {Editor, Range, Text, Transforms} from 'slate'
|
|
2
|
+
import {debugWithName} from '../../internal-utils/debug'
|
|
3
|
+
import {toSlateValue} from '../../internal-utils/values'
|
|
2
4
|
import type {
|
|
3
5
|
PortableTextMemberSchemaTypes,
|
|
4
6
|
PortableTextSlateEditor,
|
|
5
7
|
} from '../../types/editor'
|
|
6
|
-
import {debugWithName} from '../../utils/debug'
|
|
7
|
-
import {toSlateValue} from '../../utils/values'
|
|
8
8
|
import type {EditorActor} from '../editor-machine'
|
|
9
9
|
|
|
10
10
|
const debug = debugWithName('plugin:withUtils')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {BaseOperation, Editor, Node, NodeEntry} from 'slate'
|
|
2
|
+
import {createOperationToPatches} from '../../internal-utils/operationToPatches'
|
|
2
3
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
3
|
-
import {createOperationToPatches} from '../../utils/operationToPatches'
|
|
4
4
|
import type {EditorActor} from '../editor-machine'
|
|
5
5
|
import {createWithEventListeners} from './create-with-event-listeners'
|
|
6
6
|
import {createWithMaxBlocks} from './createWithMaxBlocks'
|
|
@@ -11,16 +11,19 @@ import {
|
|
|
11
11
|
type AnyEventObject,
|
|
12
12
|
type CallbackLogicFunction,
|
|
13
13
|
} from 'xstate'
|
|
14
|
+
import {debugWithName} from '../internal-utils/debug'
|
|
15
|
+
import {validateValue} from '../internal-utils/validateValue'
|
|
16
|
+
import {toSlateValue, VOID_CHILD_KEY} from '../internal-utils/values'
|
|
17
|
+
import {
|
|
18
|
+
isChangingRemotely,
|
|
19
|
+
withRemoteChanges,
|
|
20
|
+
} from '../internal-utils/withChanges'
|
|
21
|
+
import {withoutPatching} from '../internal-utils/withoutPatching'
|
|
14
22
|
import type {PickFromUnion} from '../type-utils'
|
|
15
23
|
import type {
|
|
16
24
|
InvalidValueResolution,
|
|
17
25
|
PortableTextSlateEditor,
|
|
18
26
|
} from '../types/editor'
|
|
19
|
-
import {debugWithName} from '../utils/debug'
|
|
20
|
-
import {validateValue} from '../utils/validateValue'
|
|
21
|
-
import {toSlateValue, VOID_CHILD_KEY} from '../utils/values'
|
|
22
|
-
import {isChangingRemotely, withRemoteChanges} from '../utils/withChanges'
|
|
23
|
-
import {withoutPatching} from '../utils/withoutPatching'
|
|
24
27
|
import type {EditorSchema} from './define-schema'
|
|
25
28
|
import {withoutSaving} from './plugins/createWithUndoRedo'
|
|
26
29
|
|