@portabletext/editor 2.13.3 → 2.13.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/{selector.is-selection-expanded.cjs → selector.get-selection-text.cjs} +25 -25
- package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +4 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-selecting-entire-blocks.cjs → selector.is-active-style.cjs} +408 -399
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +3 -3
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.slice-blocks.cjs → util.get-text-block-text.cjs} +25 -26
- package/lib/_chunks-cjs/util.get-text-block-text.cjs.map +1 -0
- package/lib/_chunks-cjs/{util.is-selection-collapsed.cjs → util.is-empty-text-block.cjs} +9 -9
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-text-block.cjs +5 -5
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +270 -270
- package/lib/_chunks-dts/behavior.types.action.d.ts +315 -315
- package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-selection-text.js} +20 -20
- package/lib/_chunks-es/selector.get-selection-text.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +2 -2
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/{selector.is-selecting-entire-blocks.js → selector.is-active-style.js} +385 -376
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/{util.slice-blocks.js → util.get-text-block-text.js} +25 -26
- package/lib/_chunks-es/util.get-text-block-text.js.map +1 -0
- package/lib/_chunks-es/{util.is-selection-collapsed.js → util.is-empty-text-block.js} +8 -8
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-text-block.js +1 -1
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/index.cjs +225 -225
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +18 -18
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +21 -21
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +4 -4
- package/lib/plugins/index.d.ts +4 -4
- package/lib/plugins/index.js +3 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +52 -52
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +5 -5
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +14 -14
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2 -2
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +3 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +12 -12
- package/src/behaviors/behavior.abstract.annotation.ts +3 -3
- package/src/behaviors/behavior.abstract.decorator.ts +2 -2
- package/src/behaviors/behavior.abstract.delete.ts +25 -16
- package/src/behaviors/behavior.abstract.deserialize.ts +4 -3
- package/src/behaviors/behavior.abstract.insert.ts +6 -7
- package/src/behaviors/behavior.abstract.keyboard.ts +7 -8
- package/src/behaviors/behavior.abstract.list-item.ts +2 -1
- package/src/behaviors/behavior.abstract.move.ts +2 -1
- package/src/behaviors/behavior.abstract.select.ts +4 -2
- package/src/behaviors/behavior.abstract.split.ts +33 -24
- package/src/behaviors/behavior.abstract.style.ts +2 -1
- package/src/behaviors/behavior.abstract.ts +8 -7
- package/src/behaviors/behavior.core.annotations.ts +8 -7
- package/src/behaviors/behavior.core.block-element.ts +7 -5
- package/src/behaviors/behavior.core.block-objects.ts +25 -27
- package/src/behaviors/behavior.core.dnd.ts +10 -8
- package/src/behaviors/behavior.core.insert-break.ts +45 -36
- package/src/behaviors/behavior.core.lists.ts +31 -25
- package/src/behaviors/behavior.decorator-pair.ts +26 -23
- package/src/behaviors/behavior.markdown.ts +26 -21
- package/src/converters/converter.portable-text.ts +3 -3
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/converters/converter.text-html.ts +3 -3
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +3 -3
- package/src/editor/Editable.tsx +2 -2
- package/src/editor/components/render-span.tsx +3 -5
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/create-slate-editor.tsx +1 -4
- package/src/editor/editor-dom.ts +2 -2
- package/src/editor/plugins/createWithEditableAPI.ts +5 -10
- package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
- package/src/editor/plugins/createWithObjectKeys.ts +2 -2
- package/src/editor/plugins/createWithPatches.ts +3 -10
- package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
- package/src/editor/plugins/createWithUndoRedo.ts +6 -6
- package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
- package/src/editor/sync-machine.ts +2 -5
- package/src/{internal-utils → editor}/weakMaps.ts +1 -1
- package/src/editor/with-undo-step.ts +1 -1
- package/src/index.ts +1 -1
- package/src/internal-utils/applyPatch.ts +2 -2
- package/src/internal-utils/build-index-maps.test.ts +1 -1
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/internal-utils/event-position.ts +11 -9
- package/src/internal-utils/operation-to-patches.test.ts +1 -1
- package/src/internal-utils/portable-text-node.ts +1 -1
- package/src/internal-utils/selection-block-keys.ts +1 -1
- package/src/internal-utils/selection-focus-text.ts +1 -1
- package/src/internal-utils/to-slate-range.ts +4 -4
- package/src/operations/behavior.operation.annotation.add.ts +1 -1
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +2 -2
- package/src/operations/behavior.operation.decorator.add.ts +11 -9
- package/src/operations/behavior.operation.delete.ts +1 -1
- package/src/operations/behavior.operation.insert.block.ts +2 -2
- package/src/operations/behavior.operation.insert.child.ts +1 -1
- package/src/operations/behavior.operation.move.block.ts +1 -1
- package/src/plugins/plugin.behavior.tsx +1 -1
- package/src/plugins/plugin.decorator-shortcut.ts +3 -3
- package/src/plugins/plugin.internal.auto-close-brackets.ts +2 -1
- package/src/plugins/plugin.one-line.tsx +11 -11
- package/src/priority/priority.types.ts +1 -1
- package/src/{internal-utils → selectors}/drag-selection.test.ts +1 -1
- package/src/{internal-utils → selectors}/drag-selection.ts +26 -19
- package/src/selectors/selector.get-anchor-block.ts +1 -1
- package/src/selectors/selector.get-anchor-child.ts +1 -1
- package/src/selectors/selector.get-block-offsets.ts +3 -3
- package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
- package/src/selectors/selector.get-focus-block.ts +1 -1
- package/src/selectors/selector.get-focus-child.ts +1 -1
- package/src/selectors/selector.get-focus-list-block.ts +1 -1
- package/src/selectors/selector.get-list-state.test.ts +1 -1
- package/src/selectors/selector.get-mark-state.ts +1 -1
- package/src/selectors/selector.get-next-inline-object.ts +1 -1
- package/src/selectors/selector.get-next-span.ts +1 -1
- package/src/selectors/selector.get-previous-inline-object.ts +1 -1
- package/src/selectors/selector.get-previous-span.ts +1 -1
- package/src/selectors/selector.get-selected-blocks.ts +1 -1
- package/src/selectors/selector.get-selected-spans.test.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +2 -2
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -2
- package/src/selectors/selector.get-selected-value.test.ts +87 -1
- package/src/selectors/selector.get-selected-value.ts +4 -6
- 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 +1 -1
- package/src/selectors/selector.get-text-before.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.ts +5 -7
- package/src/selectors/selector.is-active-decorator.test.ts +2 -1
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -3
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -3
- package/src/selectors/selector.is-overlapping-selection.test.ts +1 -1
- package/src/selectors/selector.is-overlapping-selection.ts +1 -1
- package/src/selectors/selector.is-point-after-selection.ts +3 -3
- package/src/selectors/selector.is-point-before-selection.ts +3 -3
- package/src/selectors/selector.is-selecting-entire-blocks.ts +7 -5
- package/src/test/gherkin-parameter-types.ts +1 -1
- package/src/test/vitest/step-definitions.tsx +19 -9
- package/src/types/paths.ts +4 -1
- package/src/utils/util.at-the-beginning-of-block.ts +1 -1
- package/src/utils/util.block-offset.ts +4 -4
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +3 -3
- package/src/utils/util.get-selection-end-point.ts +1 -1
- package/src/utils/util.get-selection-start-point.ts +1 -1
- package/src/utils/util.merge-text-blocks.ts +2 -2
- package/src/utils/util.selection-point-to-block-offset.ts +1 -1
- package/src/{selection/selection-point.ts → utils/util.selection-point.ts} +1 -1
- package/src/utils/util.slice-blocks.ts +6 -6
- package/src/utils/util.slice-text-block.test.ts +3 -1
- package/src/utils/util.slice-text-block.ts +3 -3
- package/src/utils/util.split-text-block.ts +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- /package/src/{internal-utils → editor}/withChanges.ts +0 -0
- /package/src/{internal-utils → editor}/withUndoRedo.ts +0 -0
- /package/src/{internal-utils → editor}/withoutPatching.ts +0 -0
- /package/src/{internal-utils → utils}/asserters.ts +0 -0
- /package/src/{editor → utils}/key-generator.ts +0 -0
- /package/src/{internal-utils → utils}/parse-blocks.test.ts +0 -0
- /package/src/{internal-utils → utils}/parse-blocks.ts +0 -0
package/lib/_chunks-es/{selector.is-selecting-entire-blocks.js → selector.is-active-style.js}
RENAMED
|
@@ -1,16 +1,53 @@
|
|
|
1
|
+
import { isPortableTextSpan, isKeySegment } from "@sanity/types";
|
|
2
|
+
import { getFocusChild, getFocusBlock, getSelectionStartPoint as getSelectionStartPoint$1, getFocusTextBlock, getFocusSpan, isSelectionCollapsed as isSelectionCollapsed$1, getPreviousInlineObject, getSelectionText, isSelectionExpanded as isSelectionExpanded$1, getSelectedValue } from "./selector.get-selection-text.js";
|
|
3
|
+
import { isEqualSelectionPoints, getBlockEndPoint, isSelectionCollapsed, isEmptyTextBlock } from "./util.is-empty-text-block.js";
|
|
1
4
|
import { isTextBlock, isSpan } from "@portabletext/schema";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { getBlockKeyFromSelectionPoint, getSelectionStartPoint, getSelectionEndPoint as getSelectionEndPoint$1, getChildKeyFromSelectionPoint, getBlockStartPoint, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isListBlock } from "./util.get-text-block-text.js";
|
|
6
|
+
const getFocusInlineObject = (snapshot) => {
|
|
7
|
+
const focusChild = getFocusChild(snapshot);
|
|
8
|
+
return focusChild && !isPortableTextSpan(focusChild.node) ? {
|
|
9
|
+
node: focusChild.node,
|
|
10
|
+
path: focusChild.path
|
|
11
|
+
} : void 0;
|
|
12
|
+
}, getSelectedBlocks = (snapshot) => {
|
|
13
|
+
if (!snapshot.context.selection)
|
|
14
|
+
return [];
|
|
15
|
+
const selectedBlocks = [], startPoint = getSelectionStartPoint(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
16
|
+
if (!startKey || !endKey)
|
|
17
|
+
return selectedBlocks;
|
|
18
|
+
const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
|
|
19
|
+
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
20
|
+
return selectedBlocks;
|
|
21
|
+
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
22
|
+
for (const block of slicedValue) {
|
|
23
|
+
if (block._key === startKey) {
|
|
24
|
+
if (selectedBlocks.push({
|
|
25
|
+
node: block,
|
|
26
|
+
path: [{
|
|
27
|
+
_key: block._key
|
|
28
|
+
}]
|
|
29
|
+
}), startKey === endKey)
|
|
30
|
+
break;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (block._key === endKey) {
|
|
34
|
+
selectedBlocks.push({
|
|
35
|
+
node: block,
|
|
36
|
+
path: [{
|
|
37
|
+
_key: block._key
|
|
38
|
+
}]
|
|
39
|
+
});
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
43
|
+
node: block,
|
|
44
|
+
path: [{
|
|
45
|
+
_key: block._key
|
|
46
|
+
}]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return selectedBlocks;
|
|
50
|
+
}, getSelectionEndBlock = (snapshot) => {
|
|
14
51
|
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
15
52
|
if (endPoint)
|
|
16
53
|
return getFocusBlock({
|
|
@@ -23,10 +60,163 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
23
60
|
}
|
|
24
61
|
}
|
|
25
62
|
});
|
|
63
|
+
}, getSelectionStartBlock = (snapshot) => {
|
|
64
|
+
const startPoint = getSelectionStartPoint(snapshot.context.selection);
|
|
65
|
+
if (startPoint)
|
|
66
|
+
return getFocusBlock({
|
|
67
|
+
...snapshot,
|
|
68
|
+
context: {
|
|
69
|
+
...snapshot.context,
|
|
70
|
+
selection: {
|
|
71
|
+
anchor: startPoint,
|
|
72
|
+
focus: startPoint
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
26
76
|
}, getSelectionEndPoint = (snapshot) => {
|
|
27
77
|
if (snapshot.context.selection)
|
|
28
78
|
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
29
|
-
}
|
|
79
|
+
};
|
|
80
|
+
function isPointAfterSelection(point) {
|
|
81
|
+
return (snapshot) => {
|
|
82
|
+
if (!snapshot.context.selection)
|
|
83
|
+
return !1;
|
|
84
|
+
const endPoint = getSelectionEndPoint$1(snapshot.context.selection), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint), pointBlockKey = getBlockKeyFromSelectionPoint(point), pointChildKey = getChildKeyFromSelectionPoint(point);
|
|
85
|
+
if (!pointBlockKey || !endBlockKey)
|
|
86
|
+
return !1;
|
|
87
|
+
const pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
88
|
+
if (pointBlockIndex === void 0 || endBlockIndex === void 0)
|
|
89
|
+
return !1;
|
|
90
|
+
if (pointBlockIndex > endBlockIndex)
|
|
91
|
+
return !0;
|
|
92
|
+
if (pointBlockIndex < endBlockIndex)
|
|
93
|
+
return !1;
|
|
94
|
+
const pointBlock = snapshot.context.value.at(pointBlockIndex);
|
|
95
|
+
if (!pointBlock || !isTextBlock(snapshot.context, pointBlock))
|
|
96
|
+
return !1;
|
|
97
|
+
let pointChildIndex, endChildIndex, childIndex = -1;
|
|
98
|
+
for (const child of pointBlock.children) {
|
|
99
|
+
if (childIndex++, child._key === pointChildKey && child._key === endChildKey)
|
|
100
|
+
return point.offset > endPoint.offset;
|
|
101
|
+
if (child._key === pointChildKey && (pointChildIndex = childIndex), child._key === endChildKey && (endChildIndex = childIndex), pointChildIndex !== void 0 && endChildIndex !== void 0)
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return pointChildIndex === void 0 || endChildIndex === void 0 ? !1 : pointChildIndex > endChildIndex;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function isPointBeforeSelection(point) {
|
|
108
|
+
return (snapshot) => {
|
|
109
|
+
if (!snapshot.context.selection)
|
|
110
|
+
return !1;
|
|
111
|
+
const startPoint = getSelectionStartPoint(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), pointBlockKey = getBlockKeyFromSelectionPoint(point), pointChildKey = getChildKeyFromSelectionPoint(point);
|
|
112
|
+
if (!pointBlockKey || !startBlockKey)
|
|
113
|
+
return !1;
|
|
114
|
+
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey);
|
|
115
|
+
if (startBlockIndex === void 0 || pointBlockIndex === void 0)
|
|
116
|
+
return !1;
|
|
117
|
+
if (pointBlockIndex < startBlockIndex)
|
|
118
|
+
return !0;
|
|
119
|
+
if (pointBlockIndex > startBlockIndex)
|
|
120
|
+
return !1;
|
|
121
|
+
const pointBlock = snapshot.context.value.at(pointBlockIndex);
|
|
122
|
+
if (!pointBlock || !isTextBlock(snapshot.context, pointBlock))
|
|
123
|
+
return !1;
|
|
124
|
+
let pointChildIndex, startChildIndex, childIndex = -1;
|
|
125
|
+
for (const child of pointBlock.children) {
|
|
126
|
+
if (childIndex++, child._key === pointChildKey && child._key === startChildKey)
|
|
127
|
+
return point.offset < startPoint.offset;
|
|
128
|
+
if (child._key === pointChildKey && (pointChildIndex = childIndex), child._key === startChildKey && (startChildIndex = childIndex), pointChildIndex !== void 0 && startChildIndex !== void 0)
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return pointChildIndex === void 0 || startChildIndex === void 0 ? !1 : pointChildIndex < startChildIndex;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function isOverlappingSelection(selection) {
|
|
135
|
+
return (snapshot) => {
|
|
136
|
+
if (!selection || !snapshot.context.selection)
|
|
137
|
+
return !1;
|
|
138
|
+
const selectionStartPoint = getSelectionStartPoint$1({
|
|
139
|
+
context: {
|
|
140
|
+
...snapshot.context,
|
|
141
|
+
selection
|
|
142
|
+
}
|
|
143
|
+
}), selectionEndPoint = getSelectionEndPoint({
|
|
144
|
+
context: {
|
|
145
|
+
...snapshot.context,
|
|
146
|
+
selection
|
|
147
|
+
}
|
|
148
|
+
}), originalSelectionStartPoint = getSelectionStartPoint$1(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
|
|
149
|
+
if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
|
|
150
|
+
return !1;
|
|
151
|
+
const startPointEqualToOriginalStartPoint = isEqualSelectionPoints(selectionStartPoint, originalSelectionStartPoint), endPointEqualToOriginalEndPoint = isEqualSelectionPoints(selectionEndPoint, originalSelectionEndPoint);
|
|
152
|
+
if (startPointEqualToOriginalStartPoint && endPointEqualToOriginalEndPoint)
|
|
153
|
+
return !0;
|
|
154
|
+
const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
|
|
155
|
+
...snapshot,
|
|
156
|
+
context: {
|
|
157
|
+
...snapshot.context,
|
|
158
|
+
selection: {
|
|
159
|
+
anchor: selectionStartPoint,
|
|
160
|
+
focus: selectionStartPoint
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}), originalStartPointAfterStartPoint = isPointAfterSelection(originalSelectionStartPoint)({
|
|
164
|
+
...snapshot,
|
|
165
|
+
context: {
|
|
166
|
+
...snapshot.context,
|
|
167
|
+
selection: {
|
|
168
|
+
anchor: selectionStartPoint,
|
|
169
|
+
focus: selectionStartPoint
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}), originalEndPointBeforeEndPoint = isPointBeforeSelection(originalSelectionEndPoint)({
|
|
173
|
+
...snapshot,
|
|
174
|
+
context: {
|
|
175
|
+
...snapshot.context,
|
|
176
|
+
selection: {
|
|
177
|
+
anchor: selectionEndPoint,
|
|
178
|
+
focus: selectionEndPoint
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}), originalEndPointAfterEndPoint = isPointAfterSelection(originalSelectionEndPoint)({
|
|
182
|
+
...snapshot,
|
|
183
|
+
context: {
|
|
184
|
+
...snapshot.context,
|
|
185
|
+
selection: {
|
|
186
|
+
anchor: selectionEndPoint,
|
|
187
|
+
focus: selectionEndPoint
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}), startPointEqualToOriginalEndPoint = isEqualSelectionPoints(selectionStartPoint, originalSelectionEndPoint), endPointEqualToOriginalStartPoint = isEqualSelectionPoints(selectionEndPoint, originalSelectionStartPoint);
|
|
191
|
+
return !endPointEqualToOriginalStartPoint && !startPointEqualToOriginalEndPoint && !originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint || endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const isSelectingEntireBlocks = (snapshot) => {
|
|
195
|
+
if (!snapshot.context.selection)
|
|
196
|
+
return !1;
|
|
197
|
+
const startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
|
|
198
|
+
if (!startBlock || !endBlock)
|
|
199
|
+
return !1;
|
|
200
|
+
const startBlockStartPoint = getBlockStartPoint({
|
|
201
|
+
context: snapshot.context,
|
|
202
|
+
block: startBlock
|
|
203
|
+
}), endBlockEndPoint = getBlockEndPoint({
|
|
204
|
+
context: snapshot.context,
|
|
205
|
+
block: endBlock
|
|
206
|
+
});
|
|
207
|
+
return isEqualSelectionPoints(startBlockStartPoint, startPoint) && isEqualSelectionPoints(endBlockEndPoint, endPoint);
|
|
208
|
+
};
|
|
209
|
+
function isBlockPath(path) {
|
|
210
|
+
const firstSegment = path.at(0);
|
|
211
|
+
return path.length === 1 && firstSegment !== void 0 && isRecord(firstSegment) && "_key" in firstSegment && typeof firstSegment._key == "string";
|
|
212
|
+
}
|
|
213
|
+
function isRecord(value) {
|
|
214
|
+
return !!value && (typeof value == "object" || typeof value == "function");
|
|
215
|
+
}
|
|
216
|
+
function isSelectionExpanded(selection) {
|
|
217
|
+
return selection ? !isSelectionCollapsed(selection) : !1;
|
|
218
|
+
}
|
|
219
|
+
const getNextSpan = (snapshot) => {
|
|
30
220
|
const selectionEndBlock = getSelectionEndBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
|
|
31
221
|
if (!selectionEndBlock || !selectionEndPoint || !isTextBlock(snapshot.context, selectionEndBlock.node))
|
|
32
222
|
return;
|
|
@@ -48,19 +238,6 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
48
238
|
}
|
|
49
239
|
}
|
|
50
240
|
return nextSpan;
|
|
51
|
-
}, getSelectionStartBlock = (snapshot) => {
|
|
52
|
-
const startPoint = getSelectionStartPoint(snapshot.context.selection);
|
|
53
|
-
if (startPoint)
|
|
54
|
-
return getFocusBlock({
|
|
55
|
-
...snapshot,
|
|
56
|
-
context: {
|
|
57
|
-
...snapshot.context,
|
|
58
|
-
selection: {
|
|
59
|
-
anchor: startPoint,
|
|
60
|
-
focus: startPoint
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
241
|
}, getPreviousSpan = (snapshot) => {
|
|
65
242
|
const selectionStartBlock = getSelectionStartBlock(snapshot), selectionStartPoint = getSelectionStartPoint$1(snapshot);
|
|
66
243
|
if (!selectionStartBlock || !selectionStartPoint || !isTextBlock(snapshot.context, selectionStartBlock.node))
|
|
@@ -306,67 +483,102 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
306
483
|
state: "unchanged",
|
|
307
484
|
marks
|
|
308
485
|
};
|
|
309
|
-
}
|
|
486
|
+
};
|
|
487
|
+
function getActiveDecorators(snapshot) {
|
|
488
|
+
const schema = snapshot.context.schema, decoratorState = snapshot.decoratorState, markState = getMarkState(snapshot), decorators = schema.decorators.map((decorator) => decorator.name);
|
|
489
|
+
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
490
|
+
for (const decorator in decoratorState)
|
|
491
|
+
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
492
|
+
return activeDecorators;
|
|
493
|
+
}
|
|
494
|
+
const getTrimmedSelection = (snapshot) => {
|
|
310
495
|
if (!snapshot.context.selection)
|
|
311
|
-
return
|
|
312
|
-
const
|
|
313
|
-
if (!
|
|
314
|
-
return
|
|
315
|
-
const startBlockIndex = snapshot.blockIndexMap.get(
|
|
496
|
+
return snapshot.context.selection;
|
|
497
|
+
const startPoint = getSelectionStartPoint(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
|
|
498
|
+
if (!startBlockKey || !endBlockKey)
|
|
499
|
+
return snapshot.context.selection;
|
|
500
|
+
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
316
501
|
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
317
|
-
return
|
|
502
|
+
return snapshot.context.selection;
|
|
318
503
|
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
504
|
+
let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
|
|
505
|
+
for (const block of slicedValue)
|
|
506
|
+
if (!(block._key === startBlockKey && (startBlockFound = !0, isTextBlock(snapshot.context, block) && isEmptyTextBlock(snapshot.context, block))) && startBlockFound && isTextBlock(snapshot.context, block)) {
|
|
507
|
+
if (block._key === endBlockKey && isEmptyTextBlock(snapshot.context, block))
|
|
508
|
+
break;
|
|
509
|
+
for (const child of block.children) {
|
|
510
|
+
if (child._key === endChildKey && (!isSpan(snapshot.context, child) || endPoint.offset === 0)) {
|
|
511
|
+
adjustedEndPoint = previousPotentialEndpoint ? {
|
|
512
|
+
path: [{
|
|
513
|
+
_key: previousPotentialEndpoint.blockKey
|
|
514
|
+
}, "children", {
|
|
515
|
+
_key: previousPotentialEndpoint.span._key
|
|
516
|
+
}],
|
|
517
|
+
offset: previousPotentialEndpoint.span.text.length
|
|
518
|
+
} : void 0, trimEndPoint = !0;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
if (trimStartPoint) {
|
|
522
|
+
const lonelySpan = isSpan(snapshot.context, child) && block.children.length === 1;
|
|
523
|
+
(isSpan(snapshot.context, child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
|
|
524
|
+
path: [{
|
|
525
|
+
_key: block._key
|
|
526
|
+
}, "children", {
|
|
527
|
+
_key: child._key
|
|
528
|
+
}],
|
|
529
|
+
offset: 0
|
|
530
|
+
}, previousPotentialEndpoint = {
|
|
531
|
+
blockKey: block._key,
|
|
532
|
+
span: child
|
|
533
|
+
}, trimStartPoint = !1);
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
if (child._key === startChildKey) {
|
|
537
|
+
if (!isSpan(snapshot.context, child)) {
|
|
538
|
+
trimStartPoint = !0;
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
if (startPoint.offset === child.text.length) {
|
|
542
|
+
trimStartPoint = !0, previousPotentialEndpoint = child.text.length > 0 ? {
|
|
543
|
+
blockKey: block._key,
|
|
544
|
+
span: child
|
|
545
|
+
} : previousPotentialEndpoint;
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
previousPotentialEndpoint = isSpan(snapshot.context, child) && child.text.length > 0 ? {
|
|
550
|
+
blockKey: block._key,
|
|
551
|
+
span: child
|
|
552
|
+
} : previousPotentialEndpoint;
|
|
553
|
+
}
|
|
554
|
+
if (block._key === endBlockKey)
|
|
327
555
|
break;
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
if (block._key === endKey) {
|
|
331
|
-
selectedBlocks.push({
|
|
332
|
-
node: block,
|
|
333
|
-
path: [{
|
|
334
|
-
_key: block._key
|
|
335
|
-
}]
|
|
336
|
-
});
|
|
337
|
-
break;
|
|
338
556
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
557
|
+
const trimmedSelection = snapshot.context.selection.backward ? {
|
|
558
|
+
anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,
|
|
559
|
+
focus: adjustedStartPoint ?? startPoint,
|
|
560
|
+
backward: !0
|
|
561
|
+
} : {
|
|
562
|
+
anchor: adjustedStartPoint ?? startPoint,
|
|
563
|
+
focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
|
|
564
|
+
};
|
|
565
|
+
if (isSelectionCollapsed$1({
|
|
566
|
+
context: {
|
|
567
|
+
...snapshot.context,
|
|
568
|
+
selection: trimmedSelection
|
|
569
|
+
}
|
|
570
|
+
})) {
|
|
571
|
+
const focusTextBlock = getFocusTextBlock({
|
|
572
|
+
...snapshot,
|
|
573
|
+
context: {
|
|
574
|
+
...snapshot.context,
|
|
575
|
+
selection: trimmedSelection
|
|
576
|
+
}
|
|
344
577
|
});
|
|
578
|
+
if (focusTextBlock && !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
579
|
+
return null;
|
|
345
580
|
}
|
|
346
|
-
return
|
|
347
|
-
}, getActiveAnnotations = (snapshot) => {
|
|
348
|
-
if (!snapshot.context.selection)
|
|
349
|
-
return [];
|
|
350
|
-
const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
351
|
-
return selectedBlocks.flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
|
|
352
|
-
}, getActiveListItem = (snapshot) => {
|
|
353
|
-
if (!snapshot.context.selection)
|
|
354
|
-
return;
|
|
355
|
-
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
356
|
-
if (!firstTextBlock)
|
|
357
|
-
return;
|
|
358
|
-
const firstListItem = firstTextBlock.listItem;
|
|
359
|
-
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
360
|
-
return firstListItem;
|
|
361
|
-
}, getActiveStyle = (snapshot) => {
|
|
362
|
-
if (!snapshot.context.selection)
|
|
363
|
-
return;
|
|
364
|
-
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
365
|
-
if (!firstTextBlock)
|
|
366
|
-
return;
|
|
367
|
-
const firstStyle = firstTextBlock.style;
|
|
368
|
-
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
369
|
-
return firstStyle;
|
|
581
|
+
return trimmedSelection;
|
|
370
582
|
}, getNextInlineObject = (snapshot) => {
|
|
371
583
|
const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
372
584
|
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
@@ -457,40 +669,25 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
457
669
|
selection: caretWordSelection
|
|
458
670
|
}
|
|
459
671
|
}) ? caretWordSelection : null;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
672
|
+
};
|
|
673
|
+
function getActiveAnnotationsMarks(snapshot) {
|
|
674
|
+
const schema = snapshot.context.schema;
|
|
675
|
+
return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
676
|
+
}
|
|
677
|
+
function isActiveAnnotation(annotation, options) {
|
|
678
|
+
return (snapshot) => {
|
|
679
|
+
if ((options?.mode ?? "full") === "partial")
|
|
680
|
+
return getSelectedValue(snapshot).flatMap((block) => isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
|
|
681
|
+
const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
|
|
682
|
+
return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
const getFocusBlockObject = (snapshot) => {
|
|
469
686
|
const focusBlock = getFocusBlock(snapshot);
|
|
470
687
|
return focusBlock && !isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
471
688
|
node: focusBlock.node,
|
|
472
689
|
path: focusBlock.path
|
|
473
690
|
} : void 0;
|
|
474
|
-
}, getFocusInlineObject = (snapshot) => {
|
|
475
|
-
const focusChild = getFocusChild(snapshot);
|
|
476
|
-
return focusChild && !isPortableTextSpan(focusChild.node) ? {
|
|
477
|
-
node: focusChild.node,
|
|
478
|
-
path: focusChild.path
|
|
479
|
-
} : void 0;
|
|
480
|
-
}, getFocusListBlock = (snapshot) => {
|
|
481
|
-
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
482
|
-
return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
483
|
-
node: focusTextBlock.node,
|
|
484
|
-
path: focusTextBlock.path
|
|
485
|
-
} : void 0;
|
|
486
|
-
}, getLastBlock = (snapshot) => {
|
|
487
|
-
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
488
|
-
return node ? {
|
|
489
|
-
node,
|
|
490
|
-
path: [{
|
|
491
|
-
_key: node._key
|
|
492
|
-
}]
|
|
493
|
-
} : void 0;
|
|
494
691
|
}, getNextBlock = (snapshot) => {
|
|
495
692
|
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
496
693
|
if (!selectionEndBlock)
|
|
@@ -519,6 +716,66 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
519
716
|
_key: previousBlock._key
|
|
520
717
|
}]
|
|
521
718
|
} : void 0;
|
|
719
|
+
}, getFirstBlock = (snapshot) => {
|
|
720
|
+
const node = snapshot.context.value[0];
|
|
721
|
+
return node ? {
|
|
722
|
+
node,
|
|
723
|
+
path: [{
|
|
724
|
+
_key: node._key
|
|
725
|
+
}]
|
|
726
|
+
} : void 0;
|
|
727
|
+
}, getLastBlock = (snapshot) => {
|
|
728
|
+
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
729
|
+
return node ? {
|
|
730
|
+
node,
|
|
731
|
+
path: [{
|
|
732
|
+
_key: node._key
|
|
733
|
+
}]
|
|
734
|
+
} : void 0;
|
|
735
|
+
};
|
|
736
|
+
function isAtTheEndOfBlock(block) {
|
|
737
|
+
return (snapshot) => {
|
|
738
|
+
if (!snapshot.context.selection || !isSelectionCollapsed$1(snapshot))
|
|
739
|
+
return !1;
|
|
740
|
+
const blockEndPoint = getBlockEndPoint({
|
|
741
|
+
context: snapshot.context,
|
|
742
|
+
block
|
|
743
|
+
});
|
|
744
|
+
return isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
function isAtTheStartOfBlock(block) {
|
|
748
|
+
return (snapshot) => {
|
|
749
|
+
if (!snapshot.context.selection || !isSelectionCollapsed$1(snapshot))
|
|
750
|
+
return !1;
|
|
751
|
+
const blockStartPoint = getBlockStartPoint({
|
|
752
|
+
context: snapshot.context,
|
|
753
|
+
block
|
|
754
|
+
});
|
|
755
|
+
return isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
const getFocusListBlock = (snapshot) => {
|
|
759
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
760
|
+
return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
761
|
+
node: focusTextBlock.node,
|
|
762
|
+
path: focusTextBlock.path
|
|
763
|
+
} : void 0;
|
|
764
|
+
};
|
|
765
|
+
function isActiveDecorator(decorator) {
|
|
766
|
+
return (snapshot) => {
|
|
767
|
+
if (isSelectionExpanded$1(snapshot)) {
|
|
768
|
+
const selectedSpans = getSelectedSpans(snapshot);
|
|
769
|
+
return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
|
|
770
|
+
}
|
|
771
|
+
return getActiveDecorators(snapshot).includes(decorator);
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
const getActiveAnnotations = (snapshot) => {
|
|
775
|
+
if (!snapshot.context.selection)
|
|
776
|
+
return [];
|
|
777
|
+
const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
778
|
+
return selectedBlocks.flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
|
|
522
779
|
}, getSelectedTextBlocks = (snapshot) => {
|
|
523
780
|
if (!snapshot.context.selection)
|
|
524
781
|
return [];
|
|
@@ -557,280 +814,32 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
557
814
|
});
|
|
558
815
|
}
|
|
559
816
|
return selectedTextBlocks;
|
|
560
|
-
},
|
|
817
|
+
}, getActiveListItem = (snapshot) => {
|
|
561
818
|
if (!snapshot.context.selection)
|
|
562
|
-
return
|
|
563
|
-
const
|
|
564
|
-
if (!
|
|
565
|
-
return
|
|
566
|
-
const
|
|
567
|
-
if (
|
|
568
|
-
return
|
|
569
|
-
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
570
|
-
let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
|
|
571
|
-
for (const block of slicedValue)
|
|
572
|
-
if (!(block._key === startBlockKey && (startBlockFound = !0, isTextBlock(snapshot.context, block) && isEmptyTextBlock(snapshot.context, block))) && startBlockFound && isTextBlock(snapshot.context, block)) {
|
|
573
|
-
if (block._key === endBlockKey && isEmptyTextBlock(snapshot.context, block))
|
|
574
|
-
break;
|
|
575
|
-
for (const child of block.children) {
|
|
576
|
-
if (child._key === endChildKey && (!isSpan(snapshot.context, child) || endPoint.offset === 0)) {
|
|
577
|
-
adjustedEndPoint = previousPotentialEndpoint ? {
|
|
578
|
-
path: [{
|
|
579
|
-
_key: previousPotentialEndpoint.blockKey
|
|
580
|
-
}, "children", {
|
|
581
|
-
_key: previousPotentialEndpoint.span._key
|
|
582
|
-
}],
|
|
583
|
-
offset: previousPotentialEndpoint.span.text.length
|
|
584
|
-
} : void 0, trimEndPoint = !0;
|
|
585
|
-
break;
|
|
586
|
-
}
|
|
587
|
-
if (trimStartPoint) {
|
|
588
|
-
const lonelySpan = isSpan(snapshot.context, child) && block.children.length === 1;
|
|
589
|
-
(isSpan(snapshot.context, child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
|
|
590
|
-
path: [{
|
|
591
|
-
_key: block._key
|
|
592
|
-
}, "children", {
|
|
593
|
-
_key: child._key
|
|
594
|
-
}],
|
|
595
|
-
offset: 0
|
|
596
|
-
}, previousPotentialEndpoint = {
|
|
597
|
-
blockKey: block._key,
|
|
598
|
-
span: child
|
|
599
|
-
}, trimStartPoint = !1);
|
|
600
|
-
continue;
|
|
601
|
-
}
|
|
602
|
-
if (child._key === startChildKey) {
|
|
603
|
-
if (!isSpan(snapshot.context, child)) {
|
|
604
|
-
trimStartPoint = !0;
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
if (startPoint.offset === child.text.length) {
|
|
608
|
-
trimStartPoint = !0, previousPotentialEndpoint = child.text.length > 0 ? {
|
|
609
|
-
blockKey: block._key,
|
|
610
|
-
span: child
|
|
611
|
-
} : previousPotentialEndpoint;
|
|
612
|
-
continue;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
previousPotentialEndpoint = isSpan(snapshot.context, child) && child.text.length > 0 ? {
|
|
616
|
-
blockKey: block._key,
|
|
617
|
-
span: child
|
|
618
|
-
} : previousPotentialEndpoint;
|
|
619
|
-
}
|
|
620
|
-
if (block._key === endBlockKey)
|
|
621
|
-
break;
|
|
622
|
-
}
|
|
623
|
-
const trimmedSelection = snapshot.context.selection.backward ? {
|
|
624
|
-
anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,
|
|
625
|
-
focus: adjustedStartPoint ?? startPoint,
|
|
626
|
-
backward: !0
|
|
627
|
-
} : {
|
|
628
|
-
anchor: adjustedStartPoint ?? startPoint,
|
|
629
|
-
focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
|
|
630
|
-
};
|
|
631
|
-
if (isSelectionCollapsed$1({
|
|
632
|
-
context: {
|
|
633
|
-
...snapshot.context,
|
|
634
|
-
selection: trimmedSelection
|
|
635
|
-
}
|
|
636
|
-
})) {
|
|
637
|
-
const focusTextBlock = getFocusTextBlock({
|
|
638
|
-
...snapshot,
|
|
639
|
-
context: {
|
|
640
|
-
...snapshot.context,
|
|
641
|
-
selection: trimmedSelection
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
if (focusTextBlock && !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
645
|
-
return null;
|
|
646
|
-
}
|
|
647
|
-
return trimmedSelection;
|
|
819
|
+
return;
|
|
820
|
+
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
821
|
+
if (!firstTextBlock)
|
|
822
|
+
return;
|
|
823
|
+
const firstListItem = firstTextBlock.listItem;
|
|
824
|
+
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
825
|
+
return firstListItem;
|
|
648
826
|
};
|
|
649
|
-
function getActiveAnnotationsMarks(snapshot) {
|
|
650
|
-
const schema = snapshot.context.schema;
|
|
651
|
-
return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
652
|
-
}
|
|
653
|
-
function isActiveAnnotation(annotation, options) {
|
|
654
|
-
return (snapshot) => {
|
|
655
|
-
if ((options?.mode ?? "full") === "partial")
|
|
656
|
-
return getSelectedValue(snapshot).flatMap((block) => isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
|
|
657
|
-
const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
|
|
658
|
-
return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
function getActiveDecorators(snapshot) {
|
|
662
|
-
const schema = snapshot.context.schema, decoratorState = snapshot.decoratorState, markState = getMarkState(snapshot), decorators = schema.decorators.map((decorator) => decorator.name);
|
|
663
|
-
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
664
|
-
for (const decorator in decoratorState)
|
|
665
|
-
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
666
|
-
return activeDecorators;
|
|
667
|
-
}
|
|
668
|
-
function isActiveDecorator(decorator) {
|
|
669
|
-
return (snapshot) => {
|
|
670
|
-
if (isSelectionExpanded$1(snapshot)) {
|
|
671
|
-
const selectedSpans = getSelectedSpans(snapshot);
|
|
672
|
-
return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
|
|
673
|
-
}
|
|
674
|
-
return getActiveDecorators(snapshot).includes(decorator);
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
827
|
function isActiveListItem(listItem) {
|
|
678
828
|
return (snapshot) => getActiveListItem(snapshot) === listItem;
|
|
679
829
|
}
|
|
830
|
+
const getActiveStyle = (snapshot) => {
|
|
831
|
+
if (!snapshot.context.selection)
|
|
832
|
+
return;
|
|
833
|
+
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
834
|
+
if (!firstTextBlock)
|
|
835
|
+
return;
|
|
836
|
+
const firstStyle = firstTextBlock.style;
|
|
837
|
+
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
838
|
+
return firstStyle;
|
|
839
|
+
};
|
|
680
840
|
function isActiveStyle(style) {
|
|
681
841
|
return (snapshot) => getActiveStyle(snapshot) === style;
|
|
682
842
|
}
|
|
683
|
-
function isAtTheEndOfBlock(block) {
|
|
684
|
-
return (snapshot) => {
|
|
685
|
-
if (!snapshot.context.selection || !isSelectionCollapsed$1(snapshot))
|
|
686
|
-
return !1;
|
|
687
|
-
const blockEndPoint = getBlockEndPoint({
|
|
688
|
-
context: snapshot.context,
|
|
689
|
-
block
|
|
690
|
-
});
|
|
691
|
-
return isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
692
|
-
};
|
|
693
|
-
}
|
|
694
|
-
function isAtTheStartOfBlock(block) {
|
|
695
|
-
return (snapshot) => {
|
|
696
|
-
if (!snapshot.context.selection || !isSelectionCollapsed$1(snapshot))
|
|
697
|
-
return !1;
|
|
698
|
-
const blockStartPoint = getBlockStartPoint({
|
|
699
|
-
context: snapshot.context,
|
|
700
|
-
block
|
|
701
|
-
});
|
|
702
|
-
return isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
function isPointAfterSelection(point) {
|
|
706
|
-
return (snapshot) => {
|
|
707
|
-
if (!snapshot.context.selection)
|
|
708
|
-
return !1;
|
|
709
|
-
const endPoint = getSelectionEndPoint$1(snapshot.context.selection), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint), pointBlockKey = getBlockKeyFromSelectionPoint(point), pointChildKey = getChildKeyFromSelectionPoint(point);
|
|
710
|
-
if (!pointBlockKey || !endBlockKey)
|
|
711
|
-
return !1;
|
|
712
|
-
const pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
713
|
-
if (pointBlockIndex === void 0 || endBlockIndex === void 0)
|
|
714
|
-
return !1;
|
|
715
|
-
if (pointBlockIndex > endBlockIndex)
|
|
716
|
-
return !0;
|
|
717
|
-
if (pointBlockIndex < endBlockIndex)
|
|
718
|
-
return !1;
|
|
719
|
-
const pointBlock = snapshot.context.value.at(pointBlockIndex);
|
|
720
|
-
if (!pointBlock || !isTextBlock(snapshot.context, pointBlock))
|
|
721
|
-
return !1;
|
|
722
|
-
let pointChildIndex, endChildIndex, childIndex = -1;
|
|
723
|
-
for (const child of pointBlock.children) {
|
|
724
|
-
if (childIndex++, child._key === pointChildKey && child._key === endChildKey)
|
|
725
|
-
return point.offset > endPoint.offset;
|
|
726
|
-
if (child._key === pointChildKey && (pointChildIndex = childIndex), child._key === endChildKey && (endChildIndex = childIndex), pointChildIndex !== void 0 && endChildIndex !== void 0)
|
|
727
|
-
break;
|
|
728
|
-
}
|
|
729
|
-
return pointChildIndex === void 0 || endChildIndex === void 0 ? !1 : pointChildIndex > endChildIndex;
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
function isPointBeforeSelection(point) {
|
|
733
|
-
return (snapshot) => {
|
|
734
|
-
if (!snapshot.context.selection)
|
|
735
|
-
return !1;
|
|
736
|
-
const startPoint = getSelectionStartPoint(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), pointBlockKey = getBlockKeyFromSelectionPoint(point), pointChildKey = getChildKeyFromSelectionPoint(point);
|
|
737
|
-
if (!pointBlockKey || !startBlockKey)
|
|
738
|
-
return !1;
|
|
739
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey);
|
|
740
|
-
if (startBlockIndex === void 0 || pointBlockIndex === void 0)
|
|
741
|
-
return !1;
|
|
742
|
-
if (pointBlockIndex < startBlockIndex)
|
|
743
|
-
return !0;
|
|
744
|
-
if (pointBlockIndex > startBlockIndex)
|
|
745
|
-
return !1;
|
|
746
|
-
const pointBlock = snapshot.context.value.at(pointBlockIndex);
|
|
747
|
-
if (!pointBlock || !isTextBlock(snapshot.context, pointBlock))
|
|
748
|
-
return !1;
|
|
749
|
-
let pointChildIndex, startChildIndex, childIndex = -1;
|
|
750
|
-
for (const child of pointBlock.children) {
|
|
751
|
-
if (childIndex++, child._key === pointChildKey && child._key === startChildKey)
|
|
752
|
-
return point.offset < startPoint.offset;
|
|
753
|
-
if (child._key === pointChildKey && (pointChildIndex = childIndex), child._key === startChildKey && (startChildIndex = childIndex), pointChildIndex !== void 0 && startChildIndex !== void 0)
|
|
754
|
-
break;
|
|
755
|
-
}
|
|
756
|
-
return pointChildIndex === void 0 || startChildIndex === void 0 ? !1 : pointChildIndex < startChildIndex;
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
function isOverlappingSelection(selection) {
|
|
760
|
-
return (snapshot) => {
|
|
761
|
-
if (!selection || !snapshot.context.selection)
|
|
762
|
-
return !1;
|
|
763
|
-
const selectionStartPoint = getSelectionStartPoint$1({
|
|
764
|
-
context: {
|
|
765
|
-
...snapshot.context,
|
|
766
|
-
selection
|
|
767
|
-
}
|
|
768
|
-
}), selectionEndPoint = getSelectionEndPoint({
|
|
769
|
-
context: {
|
|
770
|
-
...snapshot.context,
|
|
771
|
-
selection
|
|
772
|
-
}
|
|
773
|
-
}), originalSelectionStartPoint = getSelectionStartPoint$1(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
|
|
774
|
-
if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
|
|
775
|
-
return !1;
|
|
776
|
-
const startPointEqualToOriginalStartPoint = isEqualSelectionPoints(selectionStartPoint, originalSelectionStartPoint), endPointEqualToOriginalEndPoint = isEqualSelectionPoints(selectionEndPoint, originalSelectionEndPoint);
|
|
777
|
-
if (startPointEqualToOriginalStartPoint && endPointEqualToOriginalEndPoint)
|
|
778
|
-
return !0;
|
|
779
|
-
const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
|
|
780
|
-
...snapshot,
|
|
781
|
-
context: {
|
|
782
|
-
...snapshot.context,
|
|
783
|
-
selection: {
|
|
784
|
-
anchor: selectionStartPoint,
|
|
785
|
-
focus: selectionStartPoint
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}), originalStartPointAfterStartPoint = isPointAfterSelection(originalSelectionStartPoint)({
|
|
789
|
-
...snapshot,
|
|
790
|
-
context: {
|
|
791
|
-
...snapshot.context,
|
|
792
|
-
selection: {
|
|
793
|
-
anchor: selectionStartPoint,
|
|
794
|
-
focus: selectionStartPoint
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}), originalEndPointBeforeEndPoint = isPointBeforeSelection(originalSelectionEndPoint)({
|
|
798
|
-
...snapshot,
|
|
799
|
-
context: {
|
|
800
|
-
...snapshot.context,
|
|
801
|
-
selection: {
|
|
802
|
-
anchor: selectionEndPoint,
|
|
803
|
-
focus: selectionEndPoint
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
}), originalEndPointAfterEndPoint = isPointAfterSelection(originalSelectionEndPoint)({
|
|
807
|
-
...snapshot,
|
|
808
|
-
context: {
|
|
809
|
-
...snapshot.context,
|
|
810
|
-
selection: {
|
|
811
|
-
anchor: selectionEndPoint,
|
|
812
|
-
focus: selectionEndPoint
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}), startPointEqualToOriginalEndPoint = isEqualSelectionPoints(selectionStartPoint, originalSelectionEndPoint), endPointEqualToOriginalStartPoint = isEqualSelectionPoints(selectionEndPoint, originalSelectionStartPoint);
|
|
816
|
-
return !endPointEqualToOriginalStartPoint && !startPointEqualToOriginalEndPoint && !originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint || endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
const isSelectingEntireBlocks = (snapshot) => {
|
|
820
|
-
if (!snapshot.context.selection)
|
|
821
|
-
return !1;
|
|
822
|
-
const startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
|
|
823
|
-
if (!startBlock || !endBlock)
|
|
824
|
-
return !1;
|
|
825
|
-
const startBlockStartPoint = getBlockStartPoint({
|
|
826
|
-
context: snapshot.context,
|
|
827
|
-
block: startBlock
|
|
828
|
-
}), endBlockEndPoint = getBlockEndPoint({
|
|
829
|
-
context: snapshot.context,
|
|
830
|
-
block: endBlock
|
|
831
|
-
});
|
|
832
|
-
return isEqualSelectionPoints(startBlockStartPoint, startPoint) && isEqualSelectionPoints(endBlockEndPoint, endPoint);
|
|
833
|
-
};
|
|
834
843
|
export {
|
|
835
844
|
getActiveAnnotations,
|
|
836
845
|
getActiveAnnotationsMarks,
|
|
@@ -865,4 +874,4 @@ export {
|
|
|
865
874
|
isPointBeforeSelection,
|
|
866
875
|
isSelectingEntireBlocks
|
|
867
876
|
};
|
|
868
|
-
//# sourceMappingURL=selector.is-
|
|
877
|
+
//# sourceMappingURL=selector.is-active-style.js.map
|