@portabletext/editor 1.40.2 → 1.40.4
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/behavior.core.cjs +37 -16
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +22 -10
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +93 -100
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +6 -0
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +26 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -0
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +37 -16
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +22 -10
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +94 -101
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +7 -0
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js +27 -0
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -0
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -0
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +3881 -5053
- package/lib/behaviors/index.d.ts +3881 -5053
- package/lib/index.cjs +47 -13
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3402 -4440
- package/lib/index.d.ts +3402 -4440
- package/lib/index.js +49 -14
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +9 -127
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3404 -4441
- package/lib/plugins/index.d.ts +3404 -4441
- package/lib/plugins/index.js +11 -129
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +3401 -4440
- package/lib/selectors/index.d.ts +3401 -4440
- package/lib/utils/index.cjs +45 -7
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3403 -4443
- package/lib/utils/index.d.ts +3403 -4443
- package/lib/utils/index.js +45 -5
- package/lib/utils/index.js.map +1 -1
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.delete.block.ts +2 -2
- package/src/behavior-actions/behavior.action.insert-blocks.ts +5 -1
- package/src/behavior-actions/behavior.actions.ts +0 -18
- package/src/behaviors/behavior.core.block-objects.ts +57 -7
- package/src/behaviors/behavior.core.insert-break.ts +0 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +22 -10
- package/src/behaviors/behavior.types.ts +171 -138
- package/src/editor/create-editor.ts +2 -0
- package/src/editor/editor-machine.ts +28 -28
- package/src/editor/plugins/create-with-event-listeners.ts +15 -0
- package/src/editor/plugins/createWithEditableAPI.ts +4 -4
- package/src/internal-utils/drag-selection.test.ts +74 -1
- package/src/internal-utils/drag-selection.ts +20 -4
- package/src/internal-utils/event-position.ts +38 -7
- package/src/internal-utils/slate-utils.ts +60 -1
- package/src/plugins/plugin.one-line.tsx +10 -128
- package/src/types/block-with-optional-key.ts +13 -0
- package/src/utils/util.is-keyed-segment.ts +2 -2
- package/src/utils/util.is-text-block.ts +4 -3
- package/lib/_chunks-cjs/util.split-text-block.cjs +0 -68
- package/lib/_chunks-cjs/util.split-text-block.cjs.map +0 -1
- package/lib/_chunks-es/util.split-text-block.js +0 -70
- package/lib/_chunks-es/util.split-text-block.js.map +0 -1
- package/src/behavior-actions/behavior.action.insert.block-object.ts +0 -20
- package/src/behavior-actions/behavior.action.insert.text-block.ts +0 -33
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getNodeBlock, toPortableTextRange, fromSlateValue, toSlateRange, debugWithName, EditorActorContext, KEY_TO_VALUE_ELEMENT, usePortableTextEditor, PortableTextEditor, moveRangeByOperation, isEqualToEmptyEditor, getEditorSnapshot, 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";
|
|
@@ -7,10 +7,11 @@ import noop from "lodash/noop.js";
|
|
|
7
7
|
import { useContext, useRef, useState, useEffect, useMemo, startTransition, useCallback, forwardRef, useImperativeHandle } from "react";
|
|
8
8
|
import { Editor, Range, Element as Element$2, Text, Transforms, Path } from "slate";
|
|
9
9
|
import { useSlateStatic, useSelected, ReactEditor, useSlate, Editable } from "slate-react";
|
|
10
|
-
import { getBlockEndPoint, getBlockStartPoint } from "./_chunks-es/util.slice-blocks.js";
|
|
10
|
+
import { getBlockEndPoint, getBlockStartPoint, isKeyedSegment } from "./_chunks-es/util.slice-blocks.js";
|
|
11
11
|
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, getFocusBlock } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
12
12
|
import { isOverlappingSelection, isSelectingEntireBlocks } from "./_chunks-es/selector.is-overlapping-selection.js";
|
|
13
13
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
14
|
+
import { isSelectionCollapsed as isSelectionCollapsed$1 } from "./_chunks-es/util.is-selection-collapsed.js";
|
|
14
15
|
import { parseBlocks } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
15
16
|
import { defineBehavior, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
16
17
|
import { c } from "react-compiler-runtime";
|
|
@@ -55,11 +56,23 @@ function getDragSelection({
|
|
|
55
56
|
focus: getBlockEndPoint(focusTextBlock)
|
|
56
57
|
});
|
|
57
58
|
const selectedBlocks = getSelectedBlocks(snapshot);
|
|
58
|
-
if (snapshot.context.selection && isSelectionExpanded(snapshot) &&
|
|
59
|
+
if (snapshot.context.selection && isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
59
60
|
const selectionStartBlock = getSelectionStartBlock(snapshot), selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
60
|
-
selectionStartBlock
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (!selectionStartBlock || !selectionEndBlock)
|
|
62
|
+
return dragSelection;
|
|
63
|
+
const selectionStartPoint = getBlockStartPoint(selectionStartBlock), selectionEndPoint = getBlockEndPoint(selectionEndBlock);
|
|
64
|
+
isOverlappingSelection(eventSelection)({
|
|
65
|
+
...snapshot,
|
|
66
|
+
context: {
|
|
67
|
+
...snapshot.context,
|
|
68
|
+
selection: {
|
|
69
|
+
anchor: selectionStartPoint,
|
|
70
|
+
focus: selectionEndPoint
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}) && (dragSelection = {
|
|
74
|
+
anchor: selectionStartPoint,
|
|
75
|
+
focus: selectionEndPoint
|
|
63
76
|
});
|
|
64
77
|
}
|
|
65
78
|
return dragSelection;
|
|
@@ -75,7 +88,11 @@ function getEventPosition({
|
|
|
75
88
|
});
|
|
76
89
|
if (!node)
|
|
77
90
|
return;
|
|
78
|
-
const
|
|
91
|
+
const block = getNodeBlock({
|
|
92
|
+
editor: slateEditor,
|
|
93
|
+
schema,
|
|
94
|
+
node
|
|
95
|
+
}), positionBlock = getEventPositionBlock({
|
|
79
96
|
node,
|
|
80
97
|
slateEditor,
|
|
81
98
|
event
|
|
@@ -84,9 +101,8 @@ function getEventPosition({
|
|
|
84
101
|
slateEditor,
|
|
85
102
|
event
|
|
86
103
|
});
|
|
87
|
-
if (positionBlock && !selection && !Editor.isEditor(node))
|
|
88
|
-
|
|
89
|
-
return block ? {
|
|
104
|
+
if (block && positionBlock && !selection && !Editor.isEditor(node))
|
|
105
|
+
return {
|
|
90
106
|
block: positionBlock,
|
|
91
107
|
isEditor: !1,
|
|
92
108
|
selection: {
|
|
@@ -103,10 +119,29 @@ function getEventPosition({
|
|
|
103
119
|
}]
|
|
104
120
|
})
|
|
105
121
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
};
|
|
123
|
+
if (!positionBlock || !selection)
|
|
124
|
+
return;
|
|
125
|
+
const focusBlockPath = selection.focus.path.at(0), focusBlockKey = isKeyedSegment(focusBlockPath) ? focusBlockPath._key : void 0;
|
|
126
|
+
if (focusBlockKey)
|
|
127
|
+
return isSelectionCollapsed$1(selection) && block && focusBlockKey !== block._key ? {
|
|
128
|
+
block: positionBlock,
|
|
129
|
+
isEditor: !1,
|
|
130
|
+
selection: {
|
|
131
|
+
anchor: getBlockStartPoint({
|
|
132
|
+
node: block,
|
|
133
|
+
path: [{
|
|
134
|
+
_key: block._key
|
|
135
|
+
}]
|
|
136
|
+
}),
|
|
137
|
+
focus: getBlockEndPoint({
|
|
138
|
+
node: block,
|
|
139
|
+
path: [{
|
|
140
|
+
_key: block._key
|
|
141
|
+
}]
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
} : {
|
|
110
145
|
block: positionBlock,
|
|
111
146
|
isEditor: Editor.isEditor(node),
|
|
112
147
|
selection
|