@portabletext/editor 1.41.0 → 1.41.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.
@@ -21,9 +21,9 @@ import {
21
21
  isMouseBehaviorEvent,
22
22
  type Behavior,
23
23
  type CustomBehaviorEvent,
24
- type DataBehaviorEvent,
25
- type ExternalBehaviorEvent,
24
+ type ExternalSyntheticBehaviorEvent,
26
25
  type InternalBehaviorAction,
26
+ type InternalBehaviorEvent,
27
27
  type NativeBehaviorEvent,
28
28
  type SyntheticBehaviorEvent,
29
29
  } from '../behaviors/behavior.types'
@@ -190,7 +190,7 @@ export type InternalEditorEvent =
190
190
  | {
191
191
  type: 'behavior event'
192
192
  behaviorEvent:
193
- | DataBehaviorEvent
193
+ | InternalBehaviorEvent
194
194
  | SyntheticBehaviorEvent
195
195
  | NativeBehaviorEvent
196
196
  editor: PortableTextSlateEditor
@@ -204,7 +204,7 @@ export type InternalEditorEvent =
204
204
  nativeEvent?: {preventDefault: () => void}
205
205
  }
206
206
  | CustomBehaviorEvent
207
- | ExternalBehaviorEvent
207
+ | ExternalSyntheticBehaviorEvent
208
208
  | ExternalEditorEvent
209
209
  | MutationEvent
210
210
  | InternalPatchEvent
@@ -224,7 +224,7 @@ export type InternalEditorEvent =
224
224
  */
225
225
  export type InternalEditorEmittedEvent =
226
226
  | EditorEmittedEvent
227
- | ExternalBehaviorEvent
227
+ | ExternalSyntheticBehaviorEvent
228
228
  | InternalPatchEvent
229
229
  | PatchesEvent
230
230
  | UnsetEvent
@@ -741,7 +741,17 @@ export const editorMachine = setup({
741
741
  exit: [
742
742
  ({context}) => {
743
743
  if (context.internalDrag?.ghost) {
744
- document.body.removeChild(context.internalDrag.ghost)
744
+ try {
745
+ context.internalDrag.ghost.parentNode?.removeChild(
746
+ context.internalDrag.ghost,
747
+ )
748
+ } catch (error) {
749
+ console.error(
750
+ new Error(
751
+ `Removing the internal drag ghost failed due to: ${error.message}`,
752
+ ),
753
+ )
754
+ }
745
755
  }
746
756
  },
747
757
  assign({internalDrag: undefined}),
@@ -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,