@portabletext/editor 1.39.0 → 1.40.0
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 +16 -5
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +158 -153
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -3
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +0 -4
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/{parse-blocks.cjs → util.selection-point-to-block-offset.cjs} +74 -4
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.split-text-block.cjs +68 -0
- package/lib/_chunks-cjs/util.split-text-block.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +17 -6
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +155 -150
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +1 -2
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1 -4
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +1 -5
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/{parse-blocks.js → util.selection-point-to-block-offset.js} +76 -5
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/_chunks-es/util.split-text-block.js +70 -0
- package/lib/_chunks-es/util.split-text-block.js.map +1 -0
- package/lib/behaviors/index.d.cts +1516 -911
- package/lib/behaviors/index.d.ts +1516 -911
- package/lib/index.cjs +197 -200
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1247 -717
- package/lib/index.d.ts +1247 -717
- package/lib/index.js +204 -207
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +11 -12
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +1238 -721
- package/lib/plugins/index.d.ts +1238 -721
- package/lib/plugins/index.js +3 -4
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +1237 -710
- package/lib/selectors/index.d.ts +1237 -710
- package/lib/utils/index.cjs +15 -87
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +1290 -713
- package/lib/utils/index.d.ts +1290 -713
- package/lib/utils/index.js +13 -86
- package/lib/utils/index.js.map +1 -1
- package/package.json +10 -10
- package/src/behavior-actions/behavior.action.decorator.add.ts +13 -2
- package/src/behaviors/behavior.core.block-objects.ts +32 -2
- package/src/behaviors/behavior.default.ts +59 -16
- package/src/behaviors/behavior.types.ts +67 -30
- package/src/editor/Editable.tsx +122 -68
- package/src/editor/PortableTextEditor.tsx +8 -8
- package/src/editor/__tests__/self-solving.test.tsx +1 -1
- package/src/editor/components/Element.tsx +1 -3
- package/src/editor/create-editor.ts +13 -5
- package/src/editor/editor-machine.ts +13 -3
- package/src/editor/editor-provider.tsx +11 -7
- package/src/editor/editor-selector.ts +4 -3
- package/src/editor/editor-snapshot.ts +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +18 -3
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -2
- package/src/internal-utils/block-keys.ts +9 -0
- package/src/internal-utils/collapse-selection.ts +36 -0
- package/src/internal-utils/compound-client-rect.ts +28 -0
- package/src/internal-utils/drag-selection.test.ts +507 -0
- package/src/internal-utils/drag-selection.ts +66 -0
- package/src/internal-utils/editor-selection.test.ts +40 -0
- package/src/internal-utils/editor-selection.ts +60 -0
- package/src/internal-utils/event-position.ts +55 -80
- package/src/internal-utils/inline-object-selection.ts +115 -0
- package/src/internal-utils/selection-block-keys.ts +20 -0
- package/src/internal-utils/selection-elements.ts +61 -0
- package/src/internal-utils/selection-focus-text.ts +38 -0
- package/src/internal-utils/selection-text.test.ts +23 -0
- package/src/internal-utils/selection-text.ts +90 -0
- package/src/internal-utils/split-string.ts +12 -0
- package/src/internal-utils/string-overlap.test.ts +14 -0
- package/src/internal-utils/string-overlap.ts +28 -0
- package/src/internal-utils/string-utils.ts +7 -0
- package/src/internal-utils/terse-pt.test.ts +60 -0
- package/src/internal-utils/terse-pt.ts +36 -0
- package/src/internal-utils/text-block-key.test.ts +30 -0
- package/src/internal-utils/text-block-key.ts +30 -0
- package/src/internal-utils/text-marks.test.ts +33 -0
- package/src/internal-utils/text-marks.ts +26 -0
- package/src/internal-utils/text-selection.test.ts +175 -0
- package/src/internal-utils/text-selection.ts +122 -0
- package/src/internal-utils/value-annotations.ts +31 -0
- package/src/internal-utils/values.ts +16 -5
- package/src/utils/index.ts +5 -0
- package/src/utils/util.block-offset-to-block-selection-point.ts +28 -0
- package/src/utils/util.block-offset-to-selection-point.ts +33 -0
- package/src/utils/util.block-offsets-to-selection.ts +3 -3
- package/src/utils/util.is-equal-selections.ts +20 -0
- package/src/utils/util.is-selection-collapsed.ts +15 -0
- package/src/utils/util.reverse-selection.ts +9 -5
- package/src/utils/util.selection-point-to-block-offset.ts +31 -0
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/editor/components/use-draggable.ts +0 -123
package/lib/utils/index.cjs
CHANGED
|
@@ -1,88 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"),
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
selectionPoint
|
|
7
|
-
}) {
|
|
8
|
-
let offset = 0;
|
|
9
|
-
const blockKey = util_sliceBlocks.isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, childKey = util_sliceBlocks.isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
|
|
10
|
-
if (!(!blockKey || !childKey)) {
|
|
11
|
-
for (const block of value)
|
|
12
|
-
if (block._key === blockKey && types.isPortableTextTextBlock(block))
|
|
13
|
-
for (const child of block.children) {
|
|
14
|
-
if (child._key === childKey)
|
|
15
|
-
return {
|
|
16
|
-
path: [{
|
|
17
|
-
_key: block._key
|
|
18
|
-
}],
|
|
19
|
-
offset: offset + selectionPoint.offset
|
|
20
|
-
};
|
|
21
|
-
types.isPortableTextSpan(child) && (offset += child.text.length);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
3
|
+
var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_splitTextBlock = require("../_chunks-cjs/util.split-text-block.cjs");
|
|
4
|
+
function isEqualSelections(a, b) {
|
|
5
|
+
return !a && !b ? !0 : !a || !b ? !1 : util_sliceBlocks.isEqualSelectionPoints(a.anchor, b.anchor) && util_sliceBlocks.isEqualSelectionPoints(a.focus, b.focus);
|
|
24
6
|
}
|
|
25
|
-
function
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
function mergeTextBlocks({
|
|
29
|
-
context,
|
|
30
|
-
targetBlock,
|
|
31
|
-
incomingBlock
|
|
32
|
-
}) {
|
|
33
|
-
const parsedIncomingBlock = parseBlocks.parseBlock({
|
|
34
|
-
context,
|
|
35
|
-
block: incomingBlock,
|
|
36
|
-
options: {
|
|
37
|
-
refreshKeys: !0
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return !parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock) ? targetBlock : {
|
|
41
|
-
...targetBlock,
|
|
42
|
-
children: [...targetBlock.children, ...parsedIncomingBlock.children],
|
|
43
|
-
markDefs: [...targetBlock.markDefs ?? [], ...parsedIncomingBlock.markDefs ?? []]
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function splitTextBlock({
|
|
47
|
-
context,
|
|
48
|
-
block,
|
|
49
|
-
point
|
|
50
|
-
}) {
|
|
51
|
-
const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
|
|
52
|
-
if (!firstChild || !lastChild)
|
|
53
|
-
return;
|
|
54
|
-
const before = util_sliceBlocks.sliceBlocks({
|
|
55
|
-
blocks: [block],
|
|
56
|
-
selection: {
|
|
57
|
-
anchor: {
|
|
58
|
-
path: [{
|
|
59
|
-
_key: block._key
|
|
60
|
-
}, "children", {
|
|
61
|
-
_key: firstChild._key
|
|
62
|
-
}],
|
|
63
|
-
offset: 0
|
|
64
|
-
},
|
|
65
|
-
focus: point
|
|
66
|
-
}
|
|
67
|
-
}).at(0), after = util_sliceBlocks.sliceBlocks({
|
|
68
|
-
blocks: [block],
|
|
69
|
-
selection: {
|
|
70
|
-
anchor: point,
|
|
71
|
-
focus: {
|
|
72
|
-
path: [{
|
|
73
|
-
_key: block._key
|
|
74
|
-
}, "children", {
|
|
75
|
-
_key: lastChild._key
|
|
76
|
-
}],
|
|
77
|
-
offset: util_sliceBlocks.isSpan(context, lastChild) ? lastChild.text.length : 0
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}).at(0);
|
|
81
|
-
if (!(!before || !after) && !(!isTextBlock(context, before) || !isTextBlock(context, after)))
|
|
82
|
-
return {
|
|
83
|
-
before,
|
|
84
|
-
after
|
|
85
|
-
};
|
|
7
|
+
function isSelectionCollapsed(selection) {
|
|
8
|
+
return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
|
|
86
9
|
}
|
|
87
10
|
exports.blockOffsetToSpanSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint;
|
|
88
11
|
exports.getBlockEndPoint = util_sliceBlocks.getBlockEndPoint;
|
|
@@ -95,9 +18,14 @@ exports.isSpan = util_sliceBlocks.isSpan;
|
|
|
95
18
|
exports.reverseSelection = util_sliceBlocks.reverseSelection;
|
|
96
19
|
exports.sliceBlocks = util_sliceBlocks.sliceBlocks;
|
|
97
20
|
exports.spanSelectionPointToBlockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset;
|
|
98
|
-
exports.
|
|
99
|
-
exports.
|
|
100
|
-
exports.
|
|
101
|
-
exports.
|
|
102
|
-
exports.
|
|
21
|
+
exports.blockOffsetToBlockSelectionPoint = util_selectionPointToBlockOffset.blockOffsetToBlockSelectionPoint;
|
|
22
|
+
exports.blockOffsetToSelectionPoint = util_selectionPointToBlockOffset.blockOffsetToSelectionPoint;
|
|
23
|
+
exports.blockOffsetsToSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection;
|
|
24
|
+
exports.childSelectionPointToBlockOffset = util_selectionPointToBlockOffset.childSelectionPointToBlockOffset;
|
|
25
|
+
exports.selectionPointToBlockOffset = util_selectionPointToBlockOffset.selectionPointToBlockOffset;
|
|
26
|
+
exports.isTextBlock = util_splitTextBlock.isTextBlock;
|
|
27
|
+
exports.mergeTextBlocks = util_splitTextBlock.mergeTextBlocks;
|
|
28
|
+
exports.splitTextBlock = util_splitTextBlock.splitTextBlock;
|
|
29
|
+
exports.isEqualSelections = isEqualSelections;
|
|
30
|
+
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
103
31
|
//# sourceMappingURL=index.cjs.map
|
package/lib/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","isSelectionCollapsed","selection","path","join","offset"],"mappings":";;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,wCAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHA,UAAUH,OAAOI,KAAKC,KAAAA,MAAWF,UAAUF,MAAMG,KAAKC,KAAAA,KACtDF,UAAUH,OAAOM,WAAWH,UAAUF,MAAMK,SALrC;AAOX;;;;;;;;;;;;;;;;;;;;;;"}
|