@portabletext/editor 1.36.0 → 1.36.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.
Files changed (70) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +25 -13
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  4. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  6. package/lib/_chunks-es/editor-provider.js +25 -13
  7. package/lib/_chunks-es/editor-provider.js.map +1 -1
  8. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  9. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
  10. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  11. package/lib/behaviors/index.d.cts +7 -10
  12. package/lib/behaviors/index.d.ts +7 -10
  13. package/lib/index.cjs +140 -104
  14. package/lib/index.cjs.map +1 -1
  15. package/lib/index.d.cts +13 -26
  16. package/lib/index.d.ts +13 -26
  17. package/lib/index.js +142 -106
  18. package/lib/index.js.map +1 -1
  19. package/lib/plugins/index.cjs.map +1 -1
  20. package/lib/plugins/index.d.cts +2 -7
  21. package/lib/plugins/index.d.ts +2 -7
  22. package/lib/plugins/index.js.map +1 -1
  23. package/lib/selectors/index.cjs.map +1 -1
  24. package/lib/selectors/index.d.cts +8 -13
  25. package/lib/selectors/index.d.ts +8 -13
  26. package/lib/selectors/index.js.map +1 -1
  27. package/lib/utils/index.cjs.map +1 -1
  28. package/lib/utils/index.d.cts +3 -6
  29. package/lib/utils/index.d.ts +3 -6
  30. package/lib/utils/index.js.map +1 -1
  31. package/package.json +14 -13
  32. package/src/behavior-actions/behavior.actions.ts +2 -2
  33. package/src/behaviors/behavior.decorator-pair.ts +2 -1
  34. package/src/behaviors/index.ts +0 -8
  35. package/src/converters/converter.text-html.deserialize.test.ts +1 -1
  36. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  37. package/src/converters/converter.text-html.ts +8 -0
  38. package/src/converters/converter.text-plain.test.ts +1 -1
  39. package/src/converters/converter.text-plain.ts +8 -0
  40. package/src/editor/Editable.tsx +1 -1
  41. package/src/editor/__tests__/PortableTextEditor.test.tsx +16 -20
  42. package/src/editor/components/Element.tsx +26 -18
  43. package/src/editor/components/drop-indicator.tsx +14 -0
  44. package/src/editor/components/{DraggableBlock.tsx → use-draggable.ts} +42 -163
  45. package/src/editor/components/use-droppable.ts +135 -0
  46. package/src/editor/create-slate-editor.tsx +0 -3
  47. package/src/editor/sync-machine.ts +1 -0
  48. package/src/index.ts +48 -12
  49. package/src/internal-utils/create-test-snapshot.ts +1 -1
  50. package/src/plugins/plugin.decorator-shortcut.ts +1 -1
  51. package/src/plugins/plugin.markdown.tsx +1 -0
  52. package/src/selectors/index.ts +0 -8
  53. package/src/selectors/selector.get-active-annotations.test.ts +1 -1
  54. package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
  55. package/src/selectors/selector.get-selected-spans.test.ts +2 -1
  56. package/src/selectors/selector.get-selection-end-point.ts +1 -1
  57. package/src/selectors/selector.get-selection-start-point.ts +1 -1
  58. package/src/selectors/selector.get-selection-text.test.ts +1 -1
  59. package/src/selectors/selector.get-selection.ts +2 -1
  60. package/src/selectors/selector.get-value.ts +1 -1
  61. package/src/selectors/selector.is-active-decorator.test.ts +1 -1
  62. package/src/types/editor.ts +6 -16
  63. package/src/types/slate.ts +1 -1
  64. package/src/utils/index.ts +0 -1
  65. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  66. package/src/utils/util.is-span.ts +1 -1
  67. package/src/utils/util.is-text-block.ts +1 -1
  68. package/src/utils/util.merge-text-blocks.ts +1 -1
  69. package/src/utils/util.slice-blocks.ts +1 -1
  70. package/src/utils/util.split-text-block.ts +4 -2
package/lib/index.d.cts CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  } from 'react'
39
39
  import type {Observable, Subject} from 'rxjs'
40
40
  import {Descendant, TextUnit} from 'slate'
41
- import type {Node as Node_2, Operation} from 'slate'
41
+ import type {Operation} from 'slate'
42
42
  import type {DOMNode} from 'slate-dom'
43
43
  import type {ReactEditor} from 'slate-react'
44
44
  import {TextInsertTextOptions} from 'slate/dist/interfaces/transforms/text'
@@ -100,7 +100,7 @@ export declare type BaseDefinition = {
100
100
  /**
101
101
  * @beta
102
102
  */
103
- export declare type Behavior<
103
+ declare type Behavior<
104
104
  TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
105
105
  TGuardResponse = true,
106
106
  TBehaviorEvent extends BehaviorEvent = TBehaviorEventType extends '*'
@@ -126,7 +126,7 @@ export declare type Behavior<
126
126
  /**
127
127
  * @beta
128
128
  */
129
- export declare type BehaviorActionIntend =
129
+ declare type BehaviorActionIntend =
130
130
  | SyntheticBehaviorEvent
131
131
  | {
132
132
  type: 'raise'
@@ -143,7 +143,7 @@ export declare type BehaviorActionIntend =
143
143
  /**
144
144
  * @beta
145
145
  */
146
- export declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
146
+ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
147
147
  payload: {
148
148
  /**
149
149
  * @deprecated
@@ -159,7 +159,7 @@ export declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
159
159
  /**
160
160
  * @beta
161
161
  */
162
- export declare type BehaviorEvent =
162
+ declare type BehaviorEvent =
163
163
  | SyntheticBehaviorEvent
164
164
  | NativeBehaviorEvent
165
165
  | CustomBehaviorEvent
@@ -170,7 +170,7 @@ export declare type BehaviorEvent =
170
170
  /**
171
171
  * @beta
172
172
  */
173
- export declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
173
+ declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
174
174
  /**
175
175
  * @deprecated
176
176
  * Use `snapshot` instead
@@ -19571,12 +19571,6 @@ declare const editorMachine: StateMachine<
19571
19571
  }
19572
19572
  >
19573
19573
 
19574
- /** @internal */
19575
- export declare type EditorNode = Node_2 & {
19576
- _key: string
19577
- _type: string
19578
- }
19579
-
19580
19574
  /**
19581
19575
  * @public
19582
19576
  * The EditorProvider component is used to set up the editor context and configure the Portable Text Editor.
@@ -19705,15 +19699,12 @@ export declare type FocusChange = {
19705
19699
 
19706
19700
  declare type HasTag = ReturnType<EditorActor['getSnapshot']>['hasTag']
19707
19701
 
19708
- /** @internal */
19709
19702
  declare interface History_2 {
19710
19703
  redos: HistoryItem[]
19711
19704
  undos: HistoryItem[]
19712
19705
  }
19713
- export {History_2 as History}
19714
19706
 
19715
- /** @internal */
19716
- export declare type HistoryItem = {
19707
+ declare type HistoryItem = {
19717
19708
  operations: Operation[]
19718
19709
  timestamp: Date
19719
19710
  }
@@ -19820,7 +19811,7 @@ declare type NamespaceEvent<
19820
19811
  /**
19821
19812
  * @beta
19822
19813
  */
19823
- export declare type NativeBehaviorEvent =
19814
+ declare type NativeBehaviorEvent =
19824
19815
  | {
19825
19816
  type: 'copy'
19826
19817
  data: DataTransfer
@@ -19939,7 +19930,7 @@ export {PortableTextChild}
19939
19930
  * @public
19940
19931
  *
19941
19932
  *
19942
- * The core component that renders the editor. Must be placed within the {@link EventProvider} component.
19933
+ * The core component that renders the editor. Must be placed within the {@link EditorProvider} component.
19943
19934
  *
19944
19935
  * @example
19945
19936
  * ```tsx
@@ -20486,7 +20477,7 @@ export declare type PortableTextEditorProps<
20486
20477
  }
20487
20478
  >
20488
20479
 
20489
- /** @internal */
20480
+ /** @beta */
20490
20481
  export declare type PortableTextMemberSchemaTypes = {
20491
20482
  annotations: (ObjectSchemaType & {
20492
20483
  i18nTitleKey?: string
@@ -20501,8 +20492,7 @@ export declare type PortableTextMemberSchemaTypes = {
20501
20492
  lists: BlockListDefinition[]
20502
20493
  }
20503
20494
 
20504
- /** @internal */
20505
- export declare interface PortableTextSlateEditor extends ReactEditor {
20495
+ declare interface PortableTextSlateEditor extends ReactEditor {
20506
20496
  _key: 'editor'
20507
20497
  _type: 'editor'
20508
20498
  createPlaceholderBlock: () => Descendant
@@ -20674,10 +20664,7 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
20674
20664
  'serialization.success' | 'serialization.failure'
20675
20665
  >
20676
20666
 
20677
- /**
20678
- * @internal
20679
- */
20680
- export declare type SlateEditor = {
20667
+ declare type SlateEditor = {
20681
20668
  instance: PortableTextSlateEditor
20682
20669
  initialValue: Array<Descendant>
20683
20670
  }
@@ -20685,7 +20672,7 @@ export declare type SlateEditor = {
20685
20672
  /**
20686
20673
  * @beta
20687
20674
  */
20688
- export declare type SyntheticBehaviorEvent =
20675
+ declare type SyntheticBehaviorEvent =
20689
20676
  | {
20690
20677
  type: 'annotation.add'
20691
20678
  annotation: {
package/lib/index.d.ts CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  } from 'react'
39
39
  import type {Observable, Subject} from 'rxjs'
40
40
  import {Descendant, TextUnit} from 'slate'
41
- import type {Node as Node_2, Operation} from 'slate'
41
+ import type {Operation} from 'slate'
42
42
  import type {DOMNode} from 'slate-dom'
43
43
  import type {ReactEditor} from 'slate-react'
44
44
  import {TextInsertTextOptions} from 'slate/dist/interfaces/transforms/text'
@@ -100,7 +100,7 @@ export declare type BaseDefinition = {
100
100
  /**
101
101
  * @beta
102
102
  */
103
- export declare type Behavior<
103
+ declare type Behavior<
104
104
  TBehaviorEventType extends BehaviorEvent['type'] = BehaviorEvent['type'],
105
105
  TGuardResponse = true,
106
106
  TBehaviorEvent extends BehaviorEvent = TBehaviorEventType extends '*'
@@ -126,7 +126,7 @@ export declare type Behavior<
126
126
  /**
127
127
  * @beta
128
128
  */
129
- export declare type BehaviorActionIntend =
129
+ declare type BehaviorActionIntend =
130
130
  | SyntheticBehaviorEvent
131
131
  | {
132
132
  type: 'raise'
@@ -143,7 +143,7 @@ export declare type BehaviorActionIntend =
143
143
  /**
144
144
  * @beta
145
145
  */
146
- export declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
146
+ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
147
147
  payload: {
148
148
  /**
149
149
  * @deprecated
@@ -159,7 +159,7 @@ export declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
159
159
  /**
160
160
  * @beta
161
161
  */
162
- export declare type BehaviorEvent =
162
+ declare type BehaviorEvent =
163
163
  | SyntheticBehaviorEvent
164
164
  | NativeBehaviorEvent
165
165
  | CustomBehaviorEvent
@@ -170,7 +170,7 @@ export declare type BehaviorEvent =
170
170
  /**
171
171
  * @beta
172
172
  */
173
- export declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
173
+ declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
174
174
  /**
175
175
  * @deprecated
176
176
  * Use `snapshot` instead
@@ -19571,12 +19571,6 @@ declare const editorMachine: StateMachine<
19571
19571
  }
19572
19572
  >
19573
19573
 
19574
- /** @internal */
19575
- export declare type EditorNode = Node_2 & {
19576
- _key: string
19577
- _type: string
19578
- }
19579
-
19580
19574
  /**
19581
19575
  * @public
19582
19576
  * The EditorProvider component is used to set up the editor context and configure the Portable Text Editor.
@@ -19705,15 +19699,12 @@ export declare type FocusChange = {
19705
19699
 
19706
19700
  declare type HasTag = ReturnType<EditorActor['getSnapshot']>['hasTag']
19707
19701
 
19708
- /** @internal */
19709
19702
  declare interface History_2 {
19710
19703
  redos: HistoryItem[]
19711
19704
  undos: HistoryItem[]
19712
19705
  }
19713
- export {History_2 as History}
19714
19706
 
19715
- /** @internal */
19716
- export declare type HistoryItem = {
19707
+ declare type HistoryItem = {
19717
19708
  operations: Operation[]
19718
19709
  timestamp: Date
19719
19710
  }
@@ -19820,7 +19811,7 @@ declare type NamespaceEvent<
19820
19811
  /**
19821
19812
  * @beta
19822
19813
  */
19823
- export declare type NativeBehaviorEvent =
19814
+ declare type NativeBehaviorEvent =
19824
19815
  | {
19825
19816
  type: 'copy'
19826
19817
  data: DataTransfer
@@ -19939,7 +19930,7 @@ export {PortableTextChild}
19939
19930
  * @public
19940
19931
  *
19941
19932
  *
19942
- * The core component that renders the editor. Must be placed within the {@link EventProvider} component.
19933
+ * The core component that renders the editor. Must be placed within the {@link EditorProvider} component.
19943
19934
  *
19944
19935
  * @example
19945
19936
  * ```tsx
@@ -20486,7 +20477,7 @@ export declare type PortableTextEditorProps<
20486
20477
  }
20487
20478
  >
20488
20479
 
20489
- /** @internal */
20480
+ /** @beta */
20490
20481
  export declare type PortableTextMemberSchemaTypes = {
20491
20482
  annotations: (ObjectSchemaType & {
20492
20483
  i18nTitleKey?: string
@@ -20501,8 +20492,7 @@ export declare type PortableTextMemberSchemaTypes = {
20501
20492
  lists: BlockListDefinition[]
20502
20493
  }
20503
20494
 
20504
- /** @internal */
20505
- export declare interface PortableTextSlateEditor extends ReactEditor {
20495
+ declare interface PortableTextSlateEditor extends ReactEditor {
20506
20496
  _key: 'editor'
20507
20497
  _type: 'editor'
20508
20498
  createPlaceholderBlock: () => Descendant
@@ -20674,10 +20664,7 @@ declare type Serializer<TMIMEType extends MIMEType> = ({
20674
20664
  'serialization.success' | 'serialization.failure'
20675
20665
  >
20676
20666
 
20677
- /**
20678
- * @internal
20679
- */
20680
- export declare type SlateEditor = {
20667
+ declare type SlateEditor = {
20681
20668
  instance: PortableTextSlateEditor
20682
20669
  initialValue: Array<Descendant>
20683
20670
  }
@@ -20685,7 +20672,7 @@ export declare type SlateEditor = {
20685
20672
  /**
20686
20673
  * @beta
20687
20674
  */
20688
- export declare type SyntheticBehaviorEvent =
20675
+ declare type SyntheticBehaviorEvent =
20689
20676
  | {
20690
20677
  type: 'annotation.add'
20691
20678
  annotation: {
package/lib/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { debugWithName, IS_DRAGGING_ELEMENT_TARGET, IS_DRAGGING_BLOCK_TARGET_POSITION, IS_DRAGGING_BLOCK_ELEMENT, IS_DRAGGING, fromSlateValue, KEY_TO_VALUE_ELEMENT, usePortableTextEditor, PortableTextEditor, EditorActorContext, toSlateRange, moveRangeByOperation, toPortableTextRange, toSlateValue, isEqualToEmptyEditor, useEditor } from "./_chunks-es/editor-provider.js";
1
+ import { debugWithName, IS_DRAGGING_ELEMENT_TARGET, IS_DRAGGING, IS_DRAGGING_BLOCK_TARGET_POSITION, IS_DRAGGING_BLOCK_ELEMENT, fromSlateValue, KEY_TO_VALUE_ELEMENT, usePortableTextEditor, PortableTextEditor, EditorActorContext, toSlateRange, moveRangeByOperation, toPortableTextRange, toSlateValue, isEqualToEmptyEditor, useEditor } from "./_chunks-es/editor-provider.js";
2
2
  import { EditorProvider, defineSchema, defaultKeyGenerator, useEditorSelector, usePortableTextEditorSelection } from "./_chunks-es/editor-provider.js";
3
3
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
4
4
  import { useSelector } from "@xstate/react";
5
5
  import isEqual from "lodash/isEqual.js";
6
6
  import noop from "lodash/noop.js";
7
7
  import { useRef, useState, useEffect, useMemo, startTransition, useCallback, forwardRef, useImperativeHandle, useContext } from "react";
8
- import { Editor, Path, Transforms, Range, Element as Element$1, Text, Node } from "slate";
8
+ import { Path, Transforms, Range, Editor, Element as Element$1, Text, Node } from "slate";
9
9
  import { useSlateStatic, ReactEditor, useSelected, useSlate, Editable } from "slate-react";
10
10
  import { c } from "react-compiler-runtime";
11
11
  import uniq from "lodash/uniq.js";
@@ -87,136 +87,158 @@ function DefaultInlineObject(props) {
87
87
  "]"
88
88
  ] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
89
89
  }
90
- const debug$3 = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
91
- const $ = c(51), {
92
- children,
93
- element,
94
- readOnly,
95
- blockRef
96
- } = t0, editor = useSlateStatic(), dragGhostRef = useRef(void 0), [isDragOver, setIsDragOver] = useState(!1);
97
- let t1, t2;
98
- $[0] !== editor || $[1] !== element ? (t2 = Editor.isVoid(editor, element), $[0] = editor, $[1] = element, $[2] = t2) : t2 = $[2], t1 = t2;
99
- const isVoid = t1;
100
- let t3, t4;
101
- $[3] !== editor || $[4] !== element ? (t4 = Editor.isInline(editor, element), $[3] = editor, $[4] = element, $[5] = t4) : t4 = $[5], t3 = t4;
102
- const isInline = t3, [blockElement, setBlockElement] = useState(null);
103
- let t5, t6;
104
- $[6] !== blockRef || $[7] !== editor || $[8] !== element ? (t5 = () => setBlockElement(blockRef ? blockRef.current : ReactEditor.toDOMNode(editor, element)), t6 = [editor, element, blockRef], $[6] = blockRef, $[7] = editor, $[8] = element, $[9] = t5, $[10] = t6) : (t5 = $[9], t6 = $[10]), useEffect(t5, t6);
105
- let t7;
106
- $[11] !== blockElement || $[12] !== editor || $[13] !== element ? (t7 = (event) => {
107
- const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor);
108
- if (!isMyDragOver || !blockElement)
109
- return;
110
- event.preventDefault(), event.dataTransfer.dropEffect = "move", IS_DRAGGING_ELEMENT_TARGET.set(editor, element);
111
- const elementRect = blockElement.getBoundingClientRect(), offset = elementRect.top, height = elementRect.height, Y = event.pageY, loc = Math.abs(offset - Y);
112
- if (element === editor.children[0] || (loc < height / 2 ? IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "top") : IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "bottom")), isMyDragOver === element) {
113
- event.dataTransfer.dropEffect = "none";
114
- return;
115
- }
116
- setIsDragOver(!0);
117
- }, $[11] = blockElement, $[12] = editor, $[13] = element, $[14] = t7) : t7 = $[14];
118
- const handleDragOver = t7;
119
- let t8;
120
- $[15] === Symbol.for("react.memo_cache_sentinel") ? (t8 = () => {
121
- setIsDragOver(!1);
122
- }, $[15] = t8) : t8 = $[15];
123
- const handleDragLeave = t8;
124
- let t9;
125
- $[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
90
+ function DropIndicator() {
91
+ const $ = c(1);
92
+ let t0;
93
+ return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("div", { className: "pt-drop-indicator", style: {
94
+ position: "absolute",
95
+ width: "100%",
96
+ height: 1,
97
+ borderBottom: "1px solid currentColor",
98
+ zIndex: 5
99
+ } }), $[0] = t0) : t0 = $[0], t0;
100
+ }
101
+ const debug$4 = debugWithName("useDraggable");
102
+ function useDraggable(props) {
103
+ const $ = c(20), editor = useSlateStatic(), dragGhostRef = useRef(void 0), [blockElement, setBlockElement] = useState(null);
104
+ let t0, t1;
105
+ $[0] !== editor || $[1] !== props.blockRef || $[2] !== props.element ? (t0 = () => setBlockElement(props.blockRef ? props.blockRef.current : ReactEditor.toDOMNode(editor, props.element)), t1 = [editor, props.element, props.blockRef], $[0] = editor, $[1] = props.blockRef, $[2] = props.element, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
106
+ let t2;
107
+ $[5] !== editor || $[6] !== props.element ? (t2 = (event) => {
126
108
  const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
127
109
  if (targetBlock) {
128
- IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$3("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
110
+ IS_DRAGGING.set(editor, !1), event.preventDefault(), event.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$4("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
129
111
  const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
130
112
  IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
131
113
  let targetPath = ReactEditor.findPath(editor, targetBlock);
132
- const myPath = ReactEditor.findPath(editor, element), isBefore = Path.isBefore(myPath, targetPath);
114
+ const myPath = ReactEditor.findPath(editor, props.element), isBefore = Path.isBefore(myPath, targetPath);
133
115
  if (dragPosition === "bottom" && !isBefore) {
134
116
  if (targetPath[0] >= editor.children.length - 1) {
135
- debug$3("target is already at the bottom, not moving");
117
+ debug$4("target is already at the bottom, not moving");
136
118
  return;
137
119
  }
138
120
  const originalPath = targetPath;
139
- targetPath = Path.next(targetPath), debug$3(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
121
+ targetPath = Path.next(targetPath), debug$4(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
140
122
  }
141
123
  if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
142
124
  const originalPath_0 = targetPath;
143
- targetPath = Path.previous(targetPath), debug$3(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
125
+ targetPath = Path.previous(targetPath), debug$4(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
144
126
  }
145
127
  if (Path.equals(targetPath, myPath)) {
146
- event_0.preventDefault(), debug$3("targetPath and myPath is the same, not moving");
128
+ event.preventDefault(), debug$4("targetPath and myPath is the same, not moving");
147
129
  return;
148
130
  }
149
- debug$3(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), Transforms.moveNodes(editor, {
131
+ debug$4(`Moving element ${props.element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), Transforms.moveNodes(editor, {
150
132
  at: myPath,
151
133
  to: targetPath
152
134
  }), editor.onChange();
153
135
  return;
154
136
  }
155
- debug$3("No target element, not doing anything");
156
- }, $[16] = editor, $[17] = element, $[18] = t9) : t9 = $[18];
157
- const handleDragEnd = t9;
158
- let t10;
159
- $[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
160
- IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$3("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
161
- }, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
162
- const handleDrop = t10;
163
- let t11;
164
- $[22] !== editor || $[23] !== element || $[24] !== isVoid ? (t11 = (event_2) => {
165
- if (!isVoid) {
166
- IS_DRAGGING_BLOCK_ELEMENT.delete(editor);
167
- return;
168
- }
169
- IS_DRAGGING.set(editor, !0), IS_DRAGGING_BLOCK_ELEMENT.set(editor, element), event_2.stopPropagation();
170
- const target = event_2.target;
137
+ debug$4("No target element, not doing anything");
138
+ }, $[5] = editor, $[6] = props.element, $[7] = t2) : t2 = $[7];
139
+ const handleDragEnd = t2;
140
+ let t3;
141
+ $[8] !== editor || $[9] !== props.element ? (t3 = (event_0) => {
142
+ IS_DRAGGING.set(editor, !0), IS_DRAGGING_BLOCK_ELEMENT.set(editor, props.element), event_0.stopPropagation();
143
+ const target = event_0.target;
171
144
  target instanceof HTMLElement && (target.style.opacity = "1");
172
- }, $[22] = editor, $[23] = element, $[24] = isVoid, $[25] = t11) : t11 = $[25];
173
- const handleDrag = t11;
174
- let t12;
175
- $[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
176
- if (!isVoid || isInline) {
177
- debug$3("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
178
- return;
179
- }
180
- if (debug$3("Drag start"), IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
145
+ }, $[8] = editor, $[9] = props.element, $[10] = t3) : t3 = $[10];
146
+ const handleDrag = t3;
147
+ let t4;
148
+ $[11] !== blockElement || $[12] !== editor || $[13] !== handleDrag ? (t4 = (event_1) => {
149
+ if (debug$4("Drag start"), IS_DRAGGING.set(editor, !0), event_1.dataTransfer && (event_1.dataTransfer.setData("application/portable-text", "something"), event_1.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
181
150
  let dragGhost = blockElement.cloneNode(!0);
182
151
  const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
183
152
  if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
184
153
  dragGhostRef.current = dragGhost, dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
185
- const rect = blockElement.getBoundingClientRect(), x = event_3.clientX - rect.left, y = event_3.clientY - rect.top;
186
- dragGhost.style.width = `${rect.width}px`, dragGhost.style.height = `${rect.height}px`, event_3.dataTransfer.setDragImage(dragGhost, x, y);
154
+ const rect = blockElement.getBoundingClientRect(), x = event_1.clientX - rect.left, y = event_1.clientY - rect.top;
155
+ dragGhost.style.width = `${rect.width}px`, dragGhost.style.height = `${rect.height}px`, event_1.dataTransfer.setDragImage(dragGhost, x, y);
187
156
  }
188
157
  }
189
- handleDrag(event_3);
190
- }, $[26] = blockElement, $[27] = editor, $[28] = handleDrag, $[29] = isInline, $[30] = isVoid, $[31] = t12) : t12 = $[31];
191
- const handleDragStart = t12;
192
- let t13;
193
- $[32] !== editor || $[33] !== isDragOver ? (t13 = isDragOver && editor.children[0] === IS_DRAGGING_ELEMENT_TARGET.get(editor), $[32] = editor, $[33] = isDragOver, $[34] = t13) : t13 = $[34];
194
- const isDraggingOverFirstBlock = t13;
195
- let t14;
196
- $[35] !== editor || $[36] !== isDragOver ? (t14 = isDragOver && editor.children[editor.children.length - 1] === IS_DRAGGING_ELEMENT_TARGET.get(editor), $[35] = editor, $[36] = isDragOver, $[37] = t14) : t14 = $[37];
197
- const isDraggingOverLastBlock = t14, dragPosition_0 = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor), isDraggingOverTop = isDraggingOverFirstBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition_0 === "top", isDraggingOverBottom = isDraggingOverLastBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition_0 === "bottom";
198
- let t15, t16;
199
- $[38] === Symbol.for("react.memo_cache_sentinel") ? (t16 = /* @__PURE__ */ jsx("div", { className: "pt-drop-indicator", style: {
200
- position: "absolute",
201
- width: "100%",
202
- height: 1,
203
- borderBottom: "1px solid currentColor",
204
- zIndex: 5
205
- } }), $[38] = t16) : t16 = $[38], t15 = t16;
206
- const dropIndicator = t15;
207
- if (readOnly) {
208
- let t172;
209
- return $[39] !== children ? (t172 = /* @__PURE__ */ jsx(Fragment, { children }), $[39] = children, $[40] = t172) : t172 = $[40], t172;
158
+ handleDrag(event_1);
159
+ }, $[11] = blockElement, $[12] = editor, $[13] = handleDrag, $[14] = t4) : t4 = $[14];
160
+ const handleDragStart = t4;
161
+ if (props.readOnly) {
162
+ let t52;
163
+ return $[15] === Symbol.for("react.memo_cache_sentinel") ? (t52 = {
164
+ draggableProps: {
165
+ draggable: !1,
166
+ onDragStart: void 0,
167
+ onDrag: void 0,
168
+ onDragEnd: void 0
169
+ }
170
+ }, $[15] = t52) : t52 = $[15], t52;
210
171
  }
211
- const t17 = isDraggingOverTop && dropIndicator, t18 = isDraggingOverBottom && dropIndicator;
212
- let t19;
213
- return $[41] !== children || $[42] !== handleDrag || $[43] !== handleDragEnd || $[44] !== handleDragOver || $[45] !== handleDragStart || $[46] !== handleDrop || $[47] !== isVoid || $[48] !== t17 || $[49] !== t18 ? (t19 = /* @__PURE__ */ jsxs("div", { draggable: isVoid, onDragStart: handleDragStart, onDrag: handleDrag, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDragEnd: handleDragEnd, onDrop: handleDrop, children: [
214
- t17,
215
- children,
216
- t18
217
- ] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
218
- };
219
- DraggableBlock.displayName = "DraggableBlock";
172
+ let t5;
173
+ return $[16] !== handleDrag || $[17] !== handleDragEnd || $[18] !== handleDragStart ? (t5 = {
174
+ draggableProps: {
175
+ draggable: !0,
176
+ onDragStart: handleDragStart,
177
+ onDrag: handleDrag,
178
+ onDragEnd: handleDragEnd
179
+ }
180
+ }, $[16] = handleDrag, $[17] = handleDragEnd, $[18] = handleDragStart, $[19] = t5) : t5 = $[19], t5;
181
+ }
182
+ const debug$3 = debugWithName("useDroppable");
183
+ function useDroppable(props) {
184
+ const $ = c(27), editor = useSlateStatic(), [isDragOver, setIsDragOver] = useState(!1), [blockElement, setBlockElement] = useState(null);
185
+ let t0, t1;
186
+ $[0] !== editor || $[1] !== props.blockRef || $[2] !== props.element ? (t0 = () => setBlockElement(props.blockRef ? props.blockRef.current : ReactEditor.toDOMNode(editor, props.element)), t1 = [editor, props.element, props.blockRef], $[0] = editor, $[1] = props.blockRef, $[2] = props.element, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
187
+ let t2;
188
+ $[5] !== blockElement || $[6] !== editor || $[7] !== props.element ? (t2 = (event) => {
189
+ const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor);
190
+ if (!isMyDragOver || !blockElement)
191
+ return;
192
+ event.preventDefault(), event.dataTransfer.dropEffect = "move", IS_DRAGGING_ELEMENT_TARGET.set(editor, props.element);
193
+ const elementRect = blockElement.getBoundingClientRect(), offset = elementRect.top, height = elementRect.height, Y = event.pageY, loc = Math.abs(offset - Y);
194
+ if (props.element === editor.children[0] || (loc < height / 2 ? IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "top") : IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "bottom")), isMyDragOver === props.element) {
195
+ event.dataTransfer.dropEffect = "none";
196
+ return;
197
+ }
198
+ setIsDragOver(!0);
199
+ }, $[5] = blockElement, $[6] = editor, $[7] = props.element, $[8] = t2) : t2 = $[8];
200
+ const handleDragOver = t2;
201
+ let t3;
202
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t3 = () => {
203
+ setIsDragOver(!1);
204
+ }, $[9] = t3) : t3 = $[9];
205
+ const handleDragLeave = t3;
206
+ let t4;
207
+ $[10] !== editor || $[11] !== props.element ? (t4 = (event_0) => {
208
+ IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$3("On drop (prevented)", props.element), event_0.preventDefault(), event_0.stopPropagation(), setIsDragOver(!1));
209
+ }, $[10] = editor, $[11] = props.element, $[12] = t4) : t4 = $[12];
210
+ const handleDrop = t4;
211
+ let t5;
212
+ $[13] !== editor || $[14] !== isDragOver ? (t5 = isDragOver && editor.children[0] === IS_DRAGGING_ELEMENT_TARGET.get(editor), $[13] = editor, $[14] = isDragOver, $[15] = t5) : t5 = $[15];
213
+ const isDraggingOverFirstBlock = t5;
214
+ let t6;
215
+ $[16] !== editor || $[17] !== isDragOver ? (t6 = isDragOver && editor.children[editor.children.length - 1] === IS_DRAGGING_ELEMENT_TARGET.get(editor), $[16] = editor, $[17] = isDragOver, $[18] = t6) : t6 = $[18];
216
+ const isDraggingOverLastBlock = t6, dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor), isDraggingOverTop = isDraggingOverFirstBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition === "top", isDraggingOverBottom = isDraggingOverLastBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition === "bottom";
217
+ if (props.readOnly) {
218
+ let t72;
219
+ return $[19] === Symbol.for("react.memo_cache_sentinel") ? (t72 = {
220
+ droppableProps: {
221
+ onDragOver: void 0,
222
+ onDragLeave: void 0,
223
+ onDrop: void 0
224
+ },
225
+ isDraggingOverTop: !1,
226
+ isDraggingOverBottom: !1
227
+ }, $[19] = t72) : t72 = $[19], t72;
228
+ }
229
+ let t7;
230
+ $[20] !== handleDragOver || $[21] !== handleDrop ? (t7 = {
231
+ onDragOver: handleDragOver,
232
+ onDragLeave: handleDragLeave,
233
+ onDrop: handleDrop
234
+ }, $[20] = handleDragOver, $[21] = handleDrop, $[22] = t7) : t7 = $[22];
235
+ let t8;
236
+ return $[23] !== isDraggingOverBottom || $[24] !== isDraggingOverTop || $[25] !== t7 ? (t8 = {
237
+ droppableProps: t7,
238
+ isDraggingOverTop,
239
+ isDraggingOverBottom
240
+ }, $[23] = isDraggingOverBottom, $[24] = isDraggingOverTop, $[25] = t7, $[26] = t8) : t8 = $[26], t8;
241
+ }
220
242
  debugWithName("components:Element");
221
243
  const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
222
244
  display: "inline-block"
@@ -232,7 +254,15 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
232
254
  renderStyle,
233
255
  spellCheck
234
256
  }) => {
235
- const editor = useSlateStatic(), selected = useSelected(), blockRef = useRef(null), inlineBlockObjectRef = useRef(null), focused = selected && editor.selection && Range.isCollapsed(editor.selection) || !1, value = useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0], [editor, element, schemaTypes.block.name]);
257
+ const editor = useSlateStatic(), selected = useSelected(), blockRef = useRef(null), inlineBlockObjectRef = useRef(null), focused = selected && editor.selection && Range.isCollapsed(editor.selection) || !1, droppable = useDroppable({
258
+ element,
259
+ blockRef,
260
+ readOnly
261
+ }), draggable = useDraggable({
262
+ element,
263
+ blockRef,
264
+ readOnly
265
+ }), value = useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0], [editor, element, schemaTypes.block.name]);
236
266
  let renderedBlock = children, className;
237
267
  const blockPath = useMemo(() => [{
238
268
  _key: element._key
@@ -321,7 +351,11 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
321
351
  return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
322
352
  }
323
353
  }), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
324
- return /* @__PURE__ */ jsx("div", { ...attributes, className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }, element._key);
354
+ return /* @__PURE__ */ jsxs("div", { ...attributes, className, spellCheck, ...droppable.droppableProps, children: [
355
+ droppable.isDraggingOverTop ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
356
+ /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }),
357
+ droppable.isDraggingOverBottom ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
358
+ ] }, element._key);
325
359
  }
326
360
  const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
327
361
  if (!schemaType_0)
@@ -346,9 +380,11 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
346
380
  });
347
381
  renderedBlockFromProps = renderBlock(_props);
348
382
  }
349
- return /* @__PURE__ */ jsxs("div", { ...attributes, className, children: [
383
+ return /* @__PURE__ */ jsxs("div", { ...attributes, className, ...droppable.droppableProps, ...draggable.draggableProps, children: [
384
+ droppable.isDraggingOverTop ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
350
385
  children,
351
- /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps || /* @__PURE__ */ jsx(DefaultBlockObject, { value }) }) })
386
+ /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps || /* @__PURE__ */ jsx(DefaultBlockObject, { value }) }),
387
+ droppable.isDraggingOverBottom ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
352
388
  ] }, element._key);
353
389
  };
354
390
  Element.displayName = "Element";