@portabletext/editor 1.41.1 → 1.41.3

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 (35) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  2. package/lib/_chunks-cjs/editor-provider.cjs +19 -5
  3. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  4. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +11 -0
  5. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -0
  6. package/lib/_chunks-es/behavior.core.js.map +1 -1
  7. package/lib/_chunks-es/editor-provider.js +19 -5
  8. package/lib/_chunks-es/editor-provider.js.map +1 -1
  9. package/lib/_chunks-es/selector.get-focus-inline-object.js +13 -0
  10. package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -0
  11. package/lib/behaviors/index.d.cts +3093 -3071
  12. package/lib/behaviors/index.d.ts +3093 -3071
  13. package/lib/index.cjs +14 -7
  14. package/lib/index.cjs.map +1 -1
  15. package/lib/index.d.cts +2795 -2772
  16. package/lib/index.d.ts +2795 -2772
  17. package/lib/index.js +14 -6
  18. package/lib/index.js.map +1 -1
  19. package/lib/plugins/index.d.cts +2795 -2772
  20. package/lib/plugins/index.d.ts +2795 -2772
  21. package/lib/selectors/index.cjs +2 -8
  22. package/lib/selectors/index.cjs.map +1 -1
  23. package/lib/selectors/index.d.cts +2782 -2759
  24. package/lib/selectors/index.d.ts +2782 -2759
  25. package/lib/selectors/index.js +3 -8
  26. package/lib/selectors/index.js.map +1 -1
  27. package/lib/utils/index.d.cts +2782 -2759
  28. package/lib/utils/index.d.ts +2782 -2759
  29. package/package.json +1 -1
  30. package/src/behaviors/behavior.types.ts +151 -108
  31. package/src/editor/create-editor.ts +2 -2
  32. package/src/editor/editor-machine.ts +16 -6
  33. package/src/internal-utils/drag-selection.test.ts +1 -1
  34. package/src/internal-utils/drag-selection.ts +23 -6
  35. package/src/internal-utils/slate-utils.ts +7 -3
@@ -3,6 +3,11 @@ import * as selectors from '../selectors'
3
3
  import * as utils from '../utils'
4
4
  import type {EventPosition} from './event-position'
5
5
 
6
+ /**
7
+ * Given the current editor `snapshot` and an `eventSelection` representing
8
+ * where the drag event origins from, this function calculates the selection
9
+ * in the editor that should be dragged.
10
+ */
6
11
  export function getDragSelection({
7
12
  eventSelection,
8
13
  snapshot,
@@ -12,21 +17,33 @@ export function getDragSelection({
12
17
  }) {
13
18
  let dragSelection = eventSelection
14
19
 
15
- const collapsedSelection = selectors.isSelectionCollapsed({
20
+ const draggedInlineObject = selectors.getFocusInlineObject({
16
21
  ...snapshot,
17
22
  context: {
18
23
  ...snapshot.context,
19
24
  selection: eventSelection,
20
25
  },
21
26
  })
22
- const focusTextBlock = selectors.getFocusTextBlock({
27
+
28
+ if (draggedInlineObject) {
29
+ return dragSelection
30
+ }
31
+
32
+ const draggingCollapsedSelection = selectors.isSelectionCollapsed({
33
+ ...snapshot,
34
+ context: {
35
+ ...snapshot.context,
36
+ selection: eventSelection,
37
+ },
38
+ })
39
+ const draggedTextBlock = selectors.getFocusTextBlock({
23
40
  ...snapshot,
24
41
  context: {
25
42
  ...snapshot.context,
26
43
  selection: eventSelection,
27
44
  },
28
45
  })
29
- const focusSpan = selectors.getFocusSpan({
46
+ const draggedSpan = selectors.getFocusSpan({
30
47
  ...snapshot,
31
48
  context: {
32
49
  ...snapshot.context,
@@ -34,12 +51,12 @@ export function getDragSelection({
34
51
  },
35
52
  })
36
53
 
37
- if (collapsedSelection && focusTextBlock && focusSpan) {
54
+ if (draggingCollapsedSelection && draggedTextBlock && draggedSpan) {
38
55
  // Looks like we are dragging an empty span
39
56
  // Let's drag the entire block instead
40
57
  dragSelection = {
41
- anchor: utils.getBlockStartPoint(focusTextBlock),
42
- focus: utils.getBlockEndPoint(focusTextBlock),
58
+ anchor: utils.getBlockStartPoint(draggedTextBlock),
59
+ focus: utils.getBlockEndPoint(draggedTextBlock),
43
60
  }
44
61
  }
45
62
 
@@ -79,7 +79,7 @@ export function getNodeBlock({
79
79
  return undefined
80
80
  }
81
81
 
82
- if (isBlockElement(schema, node)) {
82
+ if (isBlockElement({editor, schema}, node)) {
83
83
  return elementToBlock({schema, element: node})
84
84
  }
85
85
 
@@ -88,7 +88,7 @@ export function getNodeBlock({
88
88
  mode: 'highest',
89
89
  at: [],
90
90
  match: (n) =>
91
- isBlockElement(schema, n) &&
91
+ isBlockElement({editor, schema}, n) &&
92
92
  n.children.some((child) => child._key === node._key),
93
93
  }),
94
94
  )
@@ -113,9 +113,13 @@ function elementToBlock({
113
113
  return fromSlateValue([element], schema.block.name)?.at(0)
114
114
  }
115
115
 
116
- function isBlockElement(schema: EditorSchema, node: Node): node is Element {
116
+ function isBlockElement(
117
+ {editor, schema}: {editor: PortableTextSlateEditor; schema: EditorSchema},
118
+ node: Node,
119
+ ): node is Element {
117
120
  return (
118
121
  Element.isElement(node) &&
122
+ !editor.isInline(node) &&
119
123
  (schema.block.name === node._type ||
120
124
  schema.blockObjects.some(
121
125
  (blockObject) => blockObject.name === node._type,