@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.
- package/lib/_chunks-cjs/editor-provider.cjs +25 -13
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +25 -13
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +7 -10
- package/lib/behaviors/index.d.ts +7 -10
- package/lib/index.cjs +140 -104
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +13 -26
- package/lib/index.d.ts +13 -26
- package/lib/index.js +142 -106
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +2 -7
- package/lib/plugins/index.d.ts +2 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +8 -13
- package/lib/selectors/index.d.ts +8 -13
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3 -6
- package/lib/utils/index.d.ts +3 -6
- package/lib/utils/index.js.map +1 -1
- package/package.json +14 -13
- package/src/behavior-actions/behavior.actions.ts +2 -2
- package/src/behaviors/behavior.decorator-pair.ts +2 -1
- package/src/behaviors/index.ts +0 -8
- package/src/converters/converter.text-html.deserialize.test.ts +1 -1
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/converters/converter.text-html.ts +8 -0
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +8 -0
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/__tests__/PortableTextEditor.test.tsx +16 -20
- package/src/editor/components/Element.tsx +26 -18
- package/src/editor/components/drop-indicator.tsx +14 -0
- package/src/editor/components/{DraggableBlock.tsx → use-draggable.ts} +42 -163
- package/src/editor/components/use-droppable.ts +135 -0
- package/src/editor/create-slate-editor.tsx +0 -3
- package/src/editor/sync-machine.ts +1 -0
- package/src/index.ts +48 -12
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/plugins/plugin.decorator-shortcut.ts +1 -1
- package/src/plugins/plugin.markdown.tsx +1 -0
- package/src/selectors/index.ts +0 -8
- package/src/selectors/selector.get-active-annotations.test.ts +1 -1
- package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
- package/src/selectors/selector.get-selected-spans.test.ts +2 -1
- package/src/selectors/selector.get-selection-end-point.ts +1 -1
- package/src/selectors/selector.get-selection-start-point.ts +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +1 -1
- package/src/selectors/selector.get-selection.ts +2 -1
- package/src/selectors/selector.get-value.ts +1 -1
- package/src/selectors/selector.is-active-decorator.test.ts +1 -1
- package/src/types/editor.ts +6 -16
- package/src/types/slate.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.is-span.ts +1 -1
- package/src/utils/util.is-text-block.ts +1 -1
- package/src/utils/util.merge-text-blocks.ts +1 -1
- package/src/utils/util.slice-blocks.ts +1 -1
- 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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
/** @
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
/** @
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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 {
|
|
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
|
-
|
|
91
|
-
const $ = c(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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),
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
-
|
|
128
|
+
event.preventDefault(), debug$4("targetPath and myPath is the same, not moving");
|
|
147
129
|
return;
|
|
148
130
|
}
|
|
149
|
-
debug$
|
|
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$
|
|
156
|
-
}, $[
|
|
157
|
-
const handleDragEnd =
|
|
158
|
-
let
|
|
159
|
-
$[
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
}, $[
|
|
173
|
-
const handleDrag =
|
|
174
|
-
let
|
|
175
|
-
$[
|
|
176
|
-
if (!
|
|
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 =
|
|
186
|
-
dragGhost.style.width = `${rect.width}px`, dragGhost.style.height = `${rect.height}px`,
|
|
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(
|
|
190
|
-
}, $[
|
|
191
|
-
const handleDragStart =
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
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,
|
|
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__ */
|
|
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(
|
|
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";
|