@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.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var editorProvider = require("./_chunks-cjs/editor-provider.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_isOverlappingSelection = require("./_chunks-cjs/selector.is-overlapping-selection.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), useEffectEvent = require("use-effect-event");
|
|
3
|
+
var editorProvider = require("./_chunks-cjs/editor-provider.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_isOverlappingSelection = require("./_chunks-cjs/selector.is-overlapping-selection.cjs"), slateDom = require("slate-dom"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), useEffectEvent = require("use-effect-event");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -44,11 +44,23 @@ function getDragSelection({
|
|
|
44
44
|
focus: util_sliceBlocks.getBlockEndPoint(focusTextBlock)
|
|
45
45
|
});
|
|
46
46
|
const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks(snapshot);
|
|
47
|
-
if (snapshot.context.selection && selector_isAtTheStartOfBlock.isSelectionExpanded(snapshot) &&
|
|
47
|
+
if (snapshot.context.selection && selector_isAtTheStartOfBlock.isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
48
48
|
const selectionStartBlock = selector_isAtTheStartOfBlock.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isAtTheStartOfBlock.getSelectionEndBlock(snapshot);
|
|
49
|
-
selectionStartBlock
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (!selectionStartBlock || !selectionEndBlock)
|
|
50
|
+
return dragSelection;
|
|
51
|
+
const selectionStartPoint = util_sliceBlocks.getBlockStartPoint(selectionStartBlock), selectionEndPoint = util_sliceBlocks.getBlockEndPoint(selectionEndBlock);
|
|
52
|
+
selector_isOverlappingSelection.isOverlappingSelection(eventSelection)({
|
|
53
|
+
...snapshot,
|
|
54
|
+
context: {
|
|
55
|
+
...snapshot.context,
|
|
56
|
+
selection: {
|
|
57
|
+
anchor: selectionStartPoint,
|
|
58
|
+
focus: selectionEndPoint
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}) && (dragSelection = {
|
|
62
|
+
anchor: selectionStartPoint,
|
|
63
|
+
focus: selectionEndPoint
|
|
52
64
|
});
|
|
53
65
|
}
|
|
54
66
|
return dragSelection;
|
|
@@ -64,7 +76,11 @@ function getEventPosition({
|
|
|
64
76
|
});
|
|
65
77
|
if (!node)
|
|
66
78
|
return;
|
|
67
|
-
const
|
|
79
|
+
const block = editorProvider.getNodeBlock({
|
|
80
|
+
editor: slateEditor,
|
|
81
|
+
schema,
|
|
82
|
+
node
|
|
83
|
+
}), positionBlock = getEventPositionBlock({
|
|
68
84
|
node,
|
|
69
85
|
slateEditor,
|
|
70
86
|
event
|
|
@@ -73,9 +89,8 @@ function getEventPosition({
|
|
|
73
89
|
slateEditor,
|
|
74
90
|
event
|
|
75
91
|
});
|
|
76
|
-
if (positionBlock && !selection && !slate.Editor.isEditor(node))
|
|
77
|
-
|
|
78
|
-
return block ? {
|
|
92
|
+
if (block && positionBlock && !selection && !slate.Editor.isEditor(node))
|
|
93
|
+
return {
|
|
79
94
|
block: positionBlock,
|
|
80
95
|
isEditor: !1,
|
|
81
96
|
selection: {
|
|
@@ -92,10 +107,29 @@ function getEventPosition({
|
|
|
92
107
|
}]
|
|
93
108
|
})
|
|
94
109
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
};
|
|
111
|
+
if (!positionBlock || !selection)
|
|
112
|
+
return;
|
|
113
|
+
const focusBlockPath = selection.focus.path.at(0), focusBlockKey = util_sliceBlocks.isKeyedSegment(focusBlockPath) ? focusBlockPath._key : void 0;
|
|
114
|
+
if (focusBlockKey)
|
|
115
|
+
return util_isSelectionCollapsed.isSelectionCollapsed(selection) && block && focusBlockKey !== block._key ? {
|
|
116
|
+
block: positionBlock,
|
|
117
|
+
isEditor: !1,
|
|
118
|
+
selection: {
|
|
119
|
+
anchor: util_sliceBlocks.getBlockStartPoint({
|
|
120
|
+
node: block,
|
|
121
|
+
path: [{
|
|
122
|
+
_key: block._key
|
|
123
|
+
}]
|
|
124
|
+
}),
|
|
125
|
+
focus: util_sliceBlocks.getBlockEndPoint({
|
|
126
|
+
node: block,
|
|
127
|
+
path: [{
|
|
128
|
+
_key: block._key
|
|
129
|
+
}]
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
} : {
|
|
99
133
|
block: positionBlock,
|
|
100
134
|
isEditor: slate.Editor.isEditor(node),
|
|
101
135
|
selection
|