@portabletext/editor 1.41.2 → 1.41.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 +52 -28
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +11 -11
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +24 -21
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +11 -0
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +240 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +300 -218
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +27 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +5 -2
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +13 -0
- package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +243 -0
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/selector.is-overlapping-selection.js +298 -217
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/behaviors/index.cjs +9 -9
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +85 -105
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +80 -99
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +6 -6
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +37 -43
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +5 -10
- package/lib/selectors/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.core.dnd.ts +27 -0
- package/src/behaviors/behavior.core.ts +2 -0
- package/src/behaviors/behavior.default.ts +4 -0
- package/src/editor/Editable.tsx +22 -40
- package/src/internal-utils/drag-selection.test.ts +1 -1
- package/src/internal-utils/drag-selection.ts +23 -6
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -322
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +0 -324
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +0 -1
- package/src/internal-utils/dragging-on-drag-origin.ts +0 -22
|
@@ -1,233 +1,299 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var util_sliceBlocks = require("./util.slice-blocks.cjs"),
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
2
|
+
var util_sliceBlocks = require("./util.slice-blocks.cjs"), types = require("@sanity/types");
|
|
3
|
+
function createGuards({
|
|
4
|
+
schema
|
|
5
|
+
}) {
|
|
6
|
+
function isListBlock(block) {
|
|
7
|
+
return types.isPortableTextListBlock(block) && block._type === schema.block.name;
|
|
8
|
+
}
|
|
9
|
+
function isTextBlock(block) {
|
|
10
|
+
return types.isPortableTextTextBlock(block) && block._type === schema.block.name;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
isListBlock,
|
|
14
|
+
isTextBlock
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const getFocusBlock = (snapshot) => {
|
|
18
|
+
const key = snapshot.context.selection && types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
19
|
+
return node && key ? {
|
|
20
|
+
node,
|
|
21
|
+
path: [{
|
|
22
|
+
_key: key
|
|
23
|
+
}]
|
|
24
|
+
} : void 0;
|
|
25
|
+
}, getFocusListBlock = (snapshot) => {
|
|
26
|
+
const guards = createGuards(snapshot.context), focusBlock = getFocusBlock(snapshot);
|
|
27
|
+
return focusBlock && guards.isListBlock(focusBlock.node) ? {
|
|
28
|
+
node: focusBlock.node,
|
|
29
|
+
path: focusBlock.path
|
|
30
|
+
} : void 0;
|
|
31
|
+
}, getFocusTextBlock = (snapshot) => {
|
|
32
|
+
const focusBlock = getFocusBlock(snapshot);
|
|
33
|
+
return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
34
|
+
node: focusBlock.node,
|
|
35
|
+
path: focusBlock.path
|
|
36
|
+
} : void 0;
|
|
37
|
+
}, getFocusBlockObject = (snapshot) => {
|
|
38
|
+
const focusBlock = getFocusBlock(snapshot);
|
|
39
|
+
return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
40
|
+
node: focusBlock.node,
|
|
41
|
+
path: focusBlock.path
|
|
42
|
+
} : void 0;
|
|
43
|
+
}, getFocusChild = (snapshot) => {
|
|
44
|
+
const focusBlock = getFocusTextBlock(snapshot);
|
|
45
|
+
if (!focusBlock)
|
|
46
|
+
return;
|
|
47
|
+
const key = snapshot.context.selection && types.isKeySegment(snapshot.context.selection.focus.path[2]) ? snapshot.context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
48
|
+
return node && key ? {
|
|
49
|
+
node,
|
|
50
|
+
path: [...focusBlock.path, "children", {
|
|
51
|
+
_key: key
|
|
52
|
+
}]
|
|
53
|
+
} : void 0;
|
|
54
|
+
}, getFocusSpan = (snapshot) => {
|
|
55
|
+
const focusChild = getFocusChild(snapshot);
|
|
56
|
+
return focusChild && types.isPortableTextSpan(focusChild.node) ? {
|
|
57
|
+
node: focusChild.node,
|
|
58
|
+
path: focusChild.path
|
|
59
|
+
} : void 0;
|
|
60
|
+
}, getFirstBlock = (snapshot) => {
|
|
61
|
+
const node = snapshot.context.value[0];
|
|
62
|
+
return node ? {
|
|
63
|
+
node,
|
|
64
|
+
path: [{
|
|
65
|
+
_key: node._key
|
|
66
|
+
}]
|
|
67
|
+
} : void 0;
|
|
68
|
+
}, getLastBlock = (snapshot) => {
|
|
69
|
+
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
70
|
+
return node ? {
|
|
71
|
+
node,
|
|
72
|
+
path: [{
|
|
73
|
+
_key: node._key
|
|
74
|
+
}]
|
|
75
|
+
} : void 0;
|
|
76
|
+
}, getSelectedBlocks = (snapshot) => {
|
|
12
77
|
if (!snapshot.context.selection)
|
|
13
78
|
return [];
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (startPoint.offset < child.text.length && selectedSpans.push({
|
|
26
|
-
node: child,
|
|
27
|
-
path: [{
|
|
28
|
-
_key: block._key
|
|
29
|
-
}, "children", {
|
|
30
|
-
_key: child._key
|
|
31
|
-
}]
|
|
32
|
-
}), startSpanKey === endSpanKey)
|
|
33
|
-
break;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
37
|
-
endPoint.offset > 0 && selectedSpans.push({
|
|
38
|
-
node: child,
|
|
39
|
-
path: [{
|
|
40
|
-
_key: block._key
|
|
41
|
-
}, "children", {
|
|
42
|
-
_key: child._key
|
|
43
|
-
}]
|
|
44
|
-
});
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
selectedSpans.length > 0 && selectedSpans.push({
|
|
48
|
-
node: child,
|
|
49
|
-
path: [{
|
|
50
|
-
_key: block._key
|
|
51
|
-
}, "children", {
|
|
52
|
-
_key: child._key
|
|
53
|
-
}]
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (startBlockKey === endBlockKey)
|
|
57
|
-
break;
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (block._key === endBlockKey) {
|
|
61
|
-
for (const child of block.children)
|
|
62
|
-
if (types.isPortableTextSpan(child)) {
|
|
63
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
64
|
-
endPoint.offset > 0 && selectedSpans.push({
|
|
65
|
-
node: child,
|
|
66
|
-
path: [{
|
|
67
|
-
_key: block._key
|
|
68
|
-
}, "children", {
|
|
69
|
-
_key: child._key
|
|
70
|
-
}]
|
|
71
|
-
});
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
selectedSpans.push({
|
|
75
|
-
node: child,
|
|
76
|
-
path: [{
|
|
77
|
-
_key: block._key
|
|
78
|
-
}, "children", {
|
|
79
|
-
_key: child._key
|
|
80
|
-
}]
|
|
81
|
-
});
|
|
82
|
-
}
|
|
79
|
+
const selectedBlocks = [], startKey = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, endKey = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0;
|
|
80
|
+
if (!startKey || !endKey)
|
|
81
|
+
return selectedBlocks;
|
|
82
|
+
for (const block of snapshot.context.value) {
|
|
83
|
+
if (block._key === startKey) {
|
|
84
|
+
if (selectedBlocks.push({
|
|
85
|
+
node: block,
|
|
86
|
+
path: [{
|
|
87
|
+
_key: block._key
|
|
88
|
+
}]
|
|
89
|
+
}), startKey === endKey)
|
|
83
90
|
break;
|
|
84
|
-
|
|
85
|
-
if (startBlockFound)
|
|
86
|
-
for (const child of block.children)
|
|
87
|
-
types.isPortableTextSpan(child) && selectedSpans.push({
|
|
88
|
-
node: child,
|
|
89
|
-
path: [{
|
|
90
|
-
_key: block._key
|
|
91
|
-
}, "children", {
|
|
92
|
-
_key: child._key
|
|
93
|
-
}]
|
|
94
|
-
});
|
|
91
|
+
continue;
|
|
95
92
|
}
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
if (block._key === endKey) {
|
|
94
|
+
selectedBlocks.push({
|
|
95
|
+
node: block,
|
|
96
|
+
path: [{
|
|
97
|
+
_key: block._key
|
|
98
|
+
}]
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
103
|
+
node: block,
|
|
104
|
+
path: [{
|
|
105
|
+
_key: block._key
|
|
106
|
+
}]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return selectedBlocks;
|
|
110
|
+
}, getSelectionStartBlock = (snapshot) => {
|
|
98
111
|
if (!snapshot.context.selection)
|
|
99
112
|
return;
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
113
|
+
const key = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
114
|
+
return node && key ? {
|
|
115
|
+
node,
|
|
116
|
+
path: [{
|
|
117
|
+
_key: key
|
|
118
|
+
}]
|
|
119
|
+
} : void 0;
|
|
120
|
+
}, getSelectionEndBlock = (snapshot) => {
|
|
107
121
|
if (!snapshot.context.selection)
|
|
108
122
|
return;
|
|
109
|
-
const
|
|
110
|
-
|
|
123
|
+
const key = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
124
|
+
return node && key ? {
|
|
125
|
+
node,
|
|
126
|
+
path: [{
|
|
127
|
+
_key: key
|
|
128
|
+
}]
|
|
129
|
+
} : void 0;
|
|
130
|
+
}, getPreviousBlock = (snapshot) => {
|
|
131
|
+
let previousBlock;
|
|
132
|
+
const selectionStartBlock = getSelectionStartBlock(snapshot);
|
|
133
|
+
if (!selectionStartBlock)
|
|
111
134
|
return;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
135
|
+
let foundSelectionStartBlock = !1;
|
|
136
|
+
for (const block of snapshot.context.value) {
|
|
137
|
+
if (block._key === selectionStartBlock.node._key) {
|
|
138
|
+
foundSelectionStartBlock = !0;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
previousBlock = {
|
|
142
|
+
node: block,
|
|
143
|
+
path: [{
|
|
144
|
+
_key: block._key
|
|
145
|
+
}]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (foundSelectionStartBlock && previousBlock)
|
|
149
|
+
return previousBlock;
|
|
150
|
+
}, getNextBlock = (snapshot) => {
|
|
151
|
+
let nextBlock;
|
|
152
|
+
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
153
|
+
if (!selectionEndBlock)
|
|
154
|
+
return;
|
|
155
|
+
let foundSelectionEndBlock = !1;
|
|
156
|
+
for (const block of snapshot.context.value) {
|
|
157
|
+
if (block._key === selectionEndBlock.node._key) {
|
|
158
|
+
foundSelectionEndBlock = !0;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (foundSelectionEndBlock) {
|
|
162
|
+
nextBlock = {
|
|
163
|
+
node: block,
|
|
164
|
+
path: [{
|
|
165
|
+
_key: block._key
|
|
166
|
+
}]
|
|
167
|
+
};
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (foundSelectionEndBlock && nextBlock)
|
|
172
|
+
return nextBlock;
|
|
173
|
+
}, getSelectionEndPoint = (snapshot) => {
|
|
174
|
+
if (snapshot.context.selection)
|
|
175
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
176
|
+
}, getSelectionStartPoint = (snapshot) => {
|
|
177
|
+
if (snapshot.context.selection)
|
|
178
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
179
|
+
}, getNextInlineObject = (snapshot) => {
|
|
180
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
181
|
+
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
182
|
+
return;
|
|
183
|
+
let endPointChildFound = !1, inlineObject;
|
|
184
|
+
for (const child of focusTextBlock.node.children) {
|
|
185
|
+
if (child._key === selectionEndPointChildKey) {
|
|
186
|
+
endPointChildFound = !0;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (!util_sliceBlocks.isSpan(snapshot.context, child) && endPointChildFound) {
|
|
190
|
+
inlineObject = {
|
|
191
|
+
node: child,
|
|
192
|
+
path: [...focusTextBlock.path, "children", {
|
|
193
|
+
_key: child._key
|
|
194
|
+
}]
|
|
195
|
+
};
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return inlineObject;
|
|
200
|
+
}, getPreviousInlineObject = (snapshot) => {
|
|
201
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
202
|
+
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
203
|
+
return;
|
|
204
|
+
let inlineObject;
|
|
205
|
+
for (const child of focusTextBlock.node.children) {
|
|
206
|
+
if (child._key === selectionStartPointChildKey)
|
|
207
|
+
break;
|
|
208
|
+
util_sliceBlocks.isSpan(snapshot.context, child) || (inlineObject = {
|
|
209
|
+
node: child,
|
|
210
|
+
path: [...focusTextBlock.path, "children", {
|
|
211
|
+
_key: child._key
|
|
212
|
+
}]
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return inlineObject;
|
|
216
|
+
}, getSelectedSlice = (snapshot) => util_sliceBlocks.sliceBlocks({
|
|
217
|
+
blocks: snapshot.context.value,
|
|
218
|
+
selection: snapshot.context.selection
|
|
219
|
+
}), getSelectionText = (snapshot) => getSelectedSlice(snapshot).reduce((text, block) => types.isPortableTextTextBlock(block) ? text + block.children.reduce((text2, child) => types.isPortableTextSpan(child) ? text2 + child.text : text2, "") : text, ""), isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getCaretWordSelection = (snapshot) => {
|
|
220
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
221
|
+
return null;
|
|
222
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
223
|
+
value: snapshot.context.value,
|
|
224
|
+
selectionPoint: selectionStartPoint
|
|
225
|
+
}) : void 0;
|
|
226
|
+
if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
|
|
227
|
+
return null;
|
|
228
|
+
const previousInlineObject = getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint(focusTextBlock), textDirectlyBefore = getSelectionText({
|
|
229
|
+
context: {
|
|
230
|
+
...snapshot.context,
|
|
231
|
+
selection: {
|
|
232
|
+
anchor: previousInlineObject ? {
|
|
233
|
+
path: previousInlineObject.path,
|
|
234
|
+
offset: 0
|
|
235
|
+
} : blockStartPoint,
|
|
236
|
+
focus: selectionStartPoint
|
|
173
237
|
}
|
|
174
|
-
if (block._key === endBlockKey)
|
|
175
|
-
break;
|
|
176
238
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
239
|
+
}).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = util_sliceBlocks.getBlockEndPoint(focusTextBlock), textDirectlyAfter = getSelectionText({
|
|
240
|
+
context: {
|
|
241
|
+
...snapshot.context,
|
|
242
|
+
selection: {
|
|
243
|
+
anchor: selectionStartPoint,
|
|
244
|
+
focus: nextInlineObject ? {
|
|
245
|
+
path: nextInlineObject.path,
|
|
246
|
+
offset: 0
|
|
247
|
+
} : blockEndPoint
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}).split(/\s+/).at(0);
|
|
251
|
+
if ((textDirectlyBefore === void 0 || textDirectlyBefore === "") && (textDirectlyAfter === void 0 || textDirectlyAfter === ""))
|
|
252
|
+
return null;
|
|
253
|
+
const caretWordStartOffset = textDirectlyBefore ? {
|
|
254
|
+
...selectionStartOffset,
|
|
255
|
+
offset: selectionStartOffset.offset - textDirectlyBefore.length
|
|
256
|
+
} : selectionStartOffset, caretWordEndOffset = textDirectlyAfter ? {
|
|
257
|
+
...selectionStartOffset,
|
|
258
|
+
offset: selectionStartOffset.offset + textDirectlyAfter.length
|
|
259
|
+
} : selectionStartOffset, caretWordStartSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
260
|
+
value: snapshot.context.value,
|
|
261
|
+
blockOffset: caretWordStartOffset,
|
|
262
|
+
direction: "backward"
|
|
263
|
+
}), caretWordEndSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
264
|
+
value: snapshot.context.value,
|
|
265
|
+
blockOffset: caretWordEndOffset,
|
|
266
|
+
direction: "forward"
|
|
267
|
+
});
|
|
268
|
+
if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint)
|
|
269
|
+
return null;
|
|
270
|
+
const caretWordSelection = {
|
|
271
|
+
anchor: caretWordStartSelectionPoint,
|
|
272
|
+
focus: caretWordEndSelectionPoint
|
|
184
273
|
};
|
|
185
|
-
|
|
274
|
+
return isSelectionExpanded({
|
|
186
275
|
context: {
|
|
187
276
|
...snapshot.context,
|
|
188
|
-
selection:
|
|
277
|
+
selection: caretWordSelection
|
|
189
278
|
}
|
|
190
|
-
})
|
|
191
|
-
const focusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock({
|
|
192
|
-
context: {
|
|
193
|
-
...snapshot.context,
|
|
194
|
-
selection: trimmedSelection
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
if (focusTextBlock && !util_sliceBlocks.isEmptyTextBlock(focusTextBlock.node))
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
return trimmedSelection;
|
|
279
|
+
}) ? caretWordSelection : null;
|
|
201
280
|
};
|
|
202
|
-
function
|
|
281
|
+
function isAtTheEndOfBlock(block) {
|
|
203
282
|
return (snapshot) => {
|
|
204
|
-
if (!snapshot.context.selection)
|
|
283
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
205
284
|
return !1;
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
return !1;
|
|
209
|
-
const selectionMarkDefs = selectedBlocks.flatMap((block) => types.isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []);
|
|
210
|
-
return selectedSpans.every((span) => (span.node.marks?.flatMap((mark) => {
|
|
211
|
-
const markDef = selectionMarkDefs.find((markDef2) => markDef2._key === mark);
|
|
212
|
-
return markDef ? [markDef._type] : [];
|
|
213
|
-
}) ?? []).includes(annotation));
|
|
285
|
+
const blockEndPoint = util_sliceBlocks.getBlockEndPoint(block);
|
|
286
|
+
return util_sliceBlocks.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
214
287
|
};
|
|
215
288
|
}
|
|
216
|
-
function
|
|
289
|
+
function isAtTheStartOfBlock(block) {
|
|
217
290
|
return (snapshot) => {
|
|
218
|
-
if (
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return snapshot.context.activeDecorators.includes(decorator);
|
|
291
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
292
|
+
return !1;
|
|
293
|
+
const blockStartPoint = util_sliceBlocks.getBlockStartPoint(block);
|
|
294
|
+
return util_sliceBlocks.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
223
295
|
};
|
|
224
296
|
}
|
|
225
|
-
function isActiveListItem(listItem) {
|
|
226
|
-
return (snapshot) => getActiveListItem(snapshot) === listItem;
|
|
227
|
-
}
|
|
228
|
-
function isActiveStyle(style) {
|
|
229
|
-
return (snapshot) => getActiveStyle(snapshot) === style;
|
|
230
|
-
}
|
|
231
297
|
function isPointAfterSelection(point) {
|
|
232
298
|
return (snapshot) => {
|
|
233
299
|
if (!snapshot.context.selection)
|
|
@@ -302,17 +368,17 @@ function isOverlappingSelection(selection) {
|
|
|
302
368
|
return (snapshot) => {
|
|
303
369
|
if (!selection || !snapshot.context.selection)
|
|
304
370
|
return !1;
|
|
305
|
-
const selectionStartPoint =
|
|
371
|
+
const selectionStartPoint = getSelectionStartPoint({
|
|
306
372
|
context: {
|
|
307
373
|
...snapshot.context,
|
|
308
374
|
selection
|
|
309
375
|
}
|
|
310
|
-
}), selectionEndPoint =
|
|
376
|
+
}), selectionEndPoint = getSelectionEndPoint({
|
|
311
377
|
context: {
|
|
312
378
|
...snapshot.context,
|
|
313
379
|
selection
|
|
314
380
|
}
|
|
315
|
-
}), originalSelectionStartPoint =
|
|
381
|
+
}), originalSelectionStartPoint = getSelectionStartPoint(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
|
|
316
382
|
if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
|
|
317
383
|
return !1;
|
|
318
384
|
const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
|
|
@@ -355,16 +421,32 @@ function isOverlappingSelection(selection) {
|
|
|
355
421
|
return endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
|
|
356
422
|
};
|
|
357
423
|
}
|
|
358
|
-
exports.
|
|
359
|
-
exports.
|
|
360
|
-
exports.
|
|
361
|
-
exports.
|
|
362
|
-
exports.
|
|
363
|
-
exports.
|
|
364
|
-
exports.
|
|
365
|
-
exports.
|
|
424
|
+
exports.createGuards = createGuards;
|
|
425
|
+
exports.getCaretWordSelection = getCaretWordSelection;
|
|
426
|
+
exports.getFirstBlock = getFirstBlock;
|
|
427
|
+
exports.getFocusBlock = getFocusBlock;
|
|
428
|
+
exports.getFocusBlockObject = getFocusBlockObject;
|
|
429
|
+
exports.getFocusChild = getFocusChild;
|
|
430
|
+
exports.getFocusListBlock = getFocusListBlock;
|
|
431
|
+
exports.getFocusSpan = getFocusSpan;
|
|
432
|
+
exports.getFocusTextBlock = getFocusTextBlock;
|
|
433
|
+
exports.getLastBlock = getLastBlock;
|
|
434
|
+
exports.getNextBlock = getNextBlock;
|
|
435
|
+
exports.getNextInlineObject = getNextInlineObject;
|
|
436
|
+
exports.getPreviousBlock = getPreviousBlock;
|
|
437
|
+
exports.getPreviousInlineObject = getPreviousInlineObject;
|
|
438
|
+
exports.getSelectedBlocks = getSelectedBlocks;
|
|
439
|
+
exports.getSelectedSlice = getSelectedSlice;
|
|
440
|
+
exports.getSelectionEndBlock = getSelectionEndBlock;
|
|
441
|
+
exports.getSelectionEndPoint = getSelectionEndPoint;
|
|
442
|
+
exports.getSelectionStartBlock = getSelectionStartBlock;
|
|
443
|
+
exports.getSelectionStartPoint = getSelectionStartPoint;
|
|
444
|
+
exports.getSelectionText = getSelectionText;
|
|
445
|
+
exports.isAtTheEndOfBlock = isAtTheEndOfBlock;
|
|
446
|
+
exports.isAtTheStartOfBlock = isAtTheStartOfBlock;
|
|
366
447
|
exports.isOverlappingSelection = isOverlappingSelection;
|
|
367
448
|
exports.isPointAfterSelection = isPointAfterSelection;
|
|
368
449
|
exports.isPointBeforeSelection = isPointBeforeSelection;
|
|
369
|
-
exports.
|
|
450
|
+
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
451
|
+
exports.isSelectionExpanded = isSelectionExpanded;
|
|
370
452
|
//# sourceMappingURL=selector.is-overlapping-selection.cjs.map
|