@portabletext/editor 1.50.5 → 1.50.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.
Files changed (34) hide show
  1. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -1
  2. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  3. package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -1
  4. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  5. package/lib/behaviors/index.d.cts +24 -16
  6. package/lib/behaviors/index.d.ts +24 -16
  7. package/lib/index.cjs +324 -252
  8. package/lib/index.cjs.map +1 -1
  9. package/lib/index.d.cts +24 -16
  10. package/lib/index.d.ts +24 -16
  11. package/lib/index.js +326 -254
  12. package/lib/index.js.map +1 -1
  13. package/lib/plugins/index.d.cts +24 -16
  14. package/lib/plugins/index.d.ts +24 -16
  15. package/lib/selectors/index.d.cts +24 -16
  16. package/lib/selectors/index.d.ts +24 -16
  17. package/lib/utils/index.d.cts +24 -16
  18. package/lib/utils/index.d.ts +24 -16
  19. package/package.json +4 -4
  20. package/src/behaviors/behavior.abstract.delete.ts +60 -0
  21. package/src/behaviors/behavior.abstract.split.ts +23 -13
  22. package/src/behaviors/behavior.types.event.ts +23 -16
  23. package/src/editor/plugins/create-with-event-listeners.ts +41 -1
  24. package/src/editor/sync-machine.ts +26 -20
  25. package/src/internal-utils/applyPatch.ts +298 -207
  26. package/src/internal-utils/slate-utils.ts +31 -0
  27. package/src/internal-utils/test-editor.tsx +45 -0
  28. package/src/operations/behavior.operation.delete.ts +36 -22
  29. package/src/operations/behavior.operations.ts +0 -27
  30. package/src/utils/util.is-selection-collapsed.ts +2 -1
  31. package/src/internal-utils/__tests__/dmpToOperations.test.ts +0 -207
  32. package/src/operations/behavior.operation.delete.backward.ts +0 -8
  33. package/src/operations/behavior.operation.delete.block.ts +0 -24
  34. package/src/operations/behavior.operation.delete.forward.ts +0 -8
@@ -11,7 +11,47 @@ export function createWithEventListeners(editorActor: EditorActor) {
11
11
  return editor
12
12
  }
13
13
 
14
- const {select} = editor
14
+ const {delete: editorDelete, select} = editor
15
+
16
+ editor.delete = (options) => {
17
+ if (isApplyingBehaviorOperations(editor)) {
18
+ editorDelete(options)
19
+ return
20
+ }
21
+
22
+ const at = options?.at ?? editor.selection
23
+
24
+ if (!at) {
25
+ console.error('Unexpected call to .delete(...) without `at` option')
26
+ return
27
+ }
28
+
29
+ const range = Editor.range(editor, at)
30
+
31
+ const selection = slateRangeToSelection({
32
+ schema: editorActor.getSnapshot().context.schema,
33
+ editor,
34
+ range,
35
+ })
36
+
37
+ if (!selection) {
38
+ console.error(
39
+ 'Unexpected call to .delete(...) with invalid `at` option',
40
+ )
41
+ return
42
+ }
43
+
44
+ editorActor.send({
45
+ type: 'behavior event',
46
+ behaviorEvent: {
47
+ type: 'delete',
48
+ at: selection,
49
+ direction: options?.reverse ? 'backward' : 'forward',
50
+ unit: options?.unit,
51
+ },
52
+ editor,
53
+ })
54
+ }
15
55
 
16
56
  editor.deleteBackward = (unit) => {
17
57
  if (isApplyingBehaviorOperations(editor)) {
@@ -428,29 +428,35 @@ async function updateValue({
428
428
  debug('Value is empty')
429
429
  Editor.withoutNormalizing(slateEditor, () => {
430
430
  withoutSaving(slateEditor, () => {
431
- withoutPatching(slateEditor, () => {
432
- if (doneSyncing) {
433
- return
434
- }
431
+ withRemoteChanges(slateEditor, () => {
432
+ withoutPatching(slateEditor, () => {
433
+ if (doneSyncing) {
434
+ return
435
+ }
435
436
 
436
- if (hadSelection) {
437
- Transforms.deselect(slateEditor)
438
- }
439
- const childrenLength = slateEditor.children.length
440
- slateEditor.children.forEach((_, index) => {
441
- Transforms.removeNodes(slateEditor, {
442
- at: [childrenLength - 1 - index],
437
+ if (hadSelection) {
438
+ Transforms.deselect(slateEditor)
439
+ }
440
+
441
+ const childrenLength = slateEditor.children.length
442
+
443
+ slateEditor.children.forEach((_, index) => {
444
+ Transforms.removeNodes(slateEditor, {
445
+ at: [childrenLength - 1 - index],
446
+ })
443
447
  })
448
+
449
+ Transforms.insertNodes(
450
+ slateEditor,
451
+ slateEditor.pteCreateTextBlock({decorators: []}),
452
+ {at: [0]},
453
+ )
454
+
455
+ // Add a new selection in the top of the document
456
+ if (hadSelection) {
457
+ Transforms.select(slateEditor, [0, 0])
458
+ }
444
459
  })
445
- Transforms.insertNodes(
446
- slateEditor,
447
- slateEditor.pteCreateTextBlock({decorators: []}),
448
- {at: [0]},
449
- )
450
- // Add a new selection in the top of the document
451
- if (hadSelection) {
452
- Transforms.select(slateEditor, [0, 0])
453
- }
454
460
  })
455
461
  })
456
462
  })