@portabletext/editor 1.53.0 → 1.53.1
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.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +144 -6
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +6 -140
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +148 -10
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +6 -140
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/index.cjs +24 -24
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +2 -2
- package/lib/selectors/index.cjs +10 -10
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +11 -11
- package/lib/selectors/index.d.ts +11 -11
- package/lib/selectors/index.js +4 -4
- package/lib/selectors/index.js.map +1 -1
- package/package.json +13 -13
- package/src/selectors/index.ts +13 -1
- package/src/selectors/selector.get-active-annotations.ts +2 -1
- package/src/selectors/selector.get-active-list-item.ts +1 -1
- package/src/selectors/selector.get-active-style.ts +1 -1
- package/src/selectors/selector.get-caret-word-selection.ts +1 -1
- package/src/selectors/selector.get-first-block.ts +14 -0
- package/src/selectors/selector.get-focus-block-object.ts +18 -0
- package/src/selectors/selector.get-focus-block.ts +23 -0
- package/src/selectors/selector.get-focus-child.ts +39 -0
- package/src/selectors/selector.get-focus-inline-object.ts +1 -1
- package/src/selectors/selector.get-focus-list-block.ts +18 -0
- package/src/selectors/selector.get-focus-span.ts +18 -0
- package/src/selectors/selector.get-focus-text-block.ts +18 -0
- package/src/selectors/selector.get-last-block.ts +16 -0
- package/src/selectors/selector.get-list-state.ts +2 -1
- package/src/selectors/selector.get-next-block.ts +38 -0
- package/src/selectors/selector.get-next-inline-object.ts +1 -1
- package/src/selectors/selector.get-previous-block.ts +35 -0
- package/src/selectors/selector.get-previous-inline-object.ts +1 -1
- package/src/selectors/selector.get-selected-blocks.ts +50 -0
- package/src/selectors/selector.get-selection-end-block.ts +4 -1
- package/src/selectors/selector.get-selection-start-block.ts +4 -1
- package/src/selectors/selector.get-text-before.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.ts +1 -1
- package/src/selectors/selector.is-active-annotation.ts +1 -1
- package/src/selectors/selector.is-selecting-entire-blocks.ts +2 -1
- package/src/selectors/selectors.ts +0 -299
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
const
|
|
4
|
-
if (snapshot.context.selection)
|
|
5
|
-
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
6
|
-
}, 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, getFocusBlock = (snapshot) => {
|
|
2
|
+
var selectionPoint = require("./selection-point.cjs"), types = require("@sanity/types");
|
|
3
|
+
const getFocusBlock = (snapshot) => {
|
|
7
4
|
if (!snapshot.context.selection)
|
|
8
5
|
return;
|
|
9
6
|
const key = selectionPoint.getBlockKeyFromSelectionPoint(snapshot.context.selection.focus), node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
@@ -13,24 +10,12 @@ const getSelectionStartPoint = (snapshot) => {
|
|
|
13
10
|
_key: key
|
|
14
11
|
}]
|
|
15
12
|
} : void 0;
|
|
16
|
-
}, getFocusListBlock = (snapshot) => {
|
|
17
|
-
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
18
|
-
return focusTextBlock && selectionPoint.isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
19
|
-
node: focusTextBlock.node,
|
|
20
|
-
path: focusTextBlock.path
|
|
21
|
-
} : void 0;
|
|
22
13
|
}, getFocusTextBlock = (snapshot) => {
|
|
23
14
|
const focusBlock = getFocusBlock(snapshot);
|
|
24
15
|
return focusBlock && selectionPoint.isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
25
16
|
node: focusBlock.node,
|
|
26
17
|
path: focusBlock.path
|
|
27
18
|
} : void 0;
|
|
28
|
-
}, getFocusBlockObject = (snapshot) => {
|
|
29
|
-
const focusBlock = getFocusBlock(snapshot);
|
|
30
|
-
return focusBlock && !selectionPoint.isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
31
|
-
node: focusBlock.node,
|
|
32
|
-
path: focusBlock.path
|
|
33
|
-
} : void 0;
|
|
34
19
|
}, getFocusChild = (snapshot) => {
|
|
35
20
|
if (!snapshot.context.selection)
|
|
36
21
|
return;
|
|
@@ -50,120 +35,10 @@ const getSelectionStartPoint = (snapshot) => {
|
|
|
50
35
|
node: focusChild.node,
|
|
51
36
|
path: focusChild.path
|
|
52
37
|
} : void 0;
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
path: [{
|
|
58
|
-
_key: node._key
|
|
59
|
-
}]
|
|
60
|
-
} : void 0;
|
|
61
|
-
}, getLastBlock = (snapshot) => {
|
|
62
|
-
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
63
|
-
return node ? {
|
|
64
|
-
node,
|
|
65
|
-
path: [{
|
|
66
|
-
_key: node._key
|
|
67
|
-
}]
|
|
68
|
-
} : void 0;
|
|
69
|
-
}, getSelectedBlocks = (snapshot) => {
|
|
70
|
-
if (!snapshot.context.selection)
|
|
71
|
-
return [];
|
|
72
|
-
const selectedBlocks = [], startPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), endPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection), startKey = selectionPoint.getBlockKeyFromSelectionPoint(startPoint), endKey = selectionPoint.getBlockKeyFromSelectionPoint(endPoint);
|
|
73
|
-
if (!startKey || !endKey)
|
|
74
|
-
return selectedBlocks;
|
|
75
|
-
for (const block of snapshot.context.value) {
|
|
76
|
-
if (block._key === startKey) {
|
|
77
|
-
if (selectedBlocks.push({
|
|
78
|
-
node: block,
|
|
79
|
-
path: [{
|
|
80
|
-
_key: block._key
|
|
81
|
-
}]
|
|
82
|
-
}), startKey === endKey)
|
|
83
|
-
break;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (block._key === endKey) {
|
|
87
|
-
selectedBlocks.push({
|
|
88
|
-
node: block,
|
|
89
|
-
path: [{
|
|
90
|
-
_key: block._key
|
|
91
|
-
}]
|
|
92
|
-
});
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
96
|
-
node: block,
|
|
97
|
-
path: [{
|
|
98
|
-
_key: block._key
|
|
99
|
-
}]
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return selectedBlocks;
|
|
103
|
-
}, getSelectionStartBlock = (snapshot) => {
|
|
104
|
-
if (!snapshot.context.selection)
|
|
105
|
-
return;
|
|
106
|
-
const startPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), key = selectionPoint.getBlockKeyFromSelectionPoint(startPoint), node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
107
|
-
return node && key ? {
|
|
108
|
-
node,
|
|
109
|
-
path: [{
|
|
110
|
-
_key: key
|
|
111
|
-
}]
|
|
112
|
-
} : void 0;
|
|
113
|
-
}, getSelectionEndBlock = (snapshot) => {
|
|
114
|
-
if (!snapshot.context.selection)
|
|
115
|
-
return;
|
|
116
|
-
const endPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection), key = selectionPoint.getBlockKeyFromSelectionPoint(endPoint), node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
117
|
-
return node && key ? {
|
|
118
|
-
node,
|
|
119
|
-
path: [{
|
|
120
|
-
_key: key
|
|
121
|
-
}]
|
|
122
|
-
} : void 0;
|
|
123
|
-
}, getPreviousBlock = (snapshot) => {
|
|
124
|
-
let previousBlock;
|
|
125
|
-
const selectionStartBlock = getSelectionStartBlock(snapshot);
|
|
126
|
-
if (!selectionStartBlock)
|
|
127
|
-
return;
|
|
128
|
-
let foundSelectionStartBlock = !1;
|
|
129
|
-
for (const block of snapshot.context.value) {
|
|
130
|
-
if (block._key === selectionStartBlock.node._key) {
|
|
131
|
-
foundSelectionStartBlock = !0;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
previousBlock = {
|
|
135
|
-
node: block,
|
|
136
|
-
path: [{
|
|
137
|
-
_key: block._key
|
|
138
|
-
}]
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
if (foundSelectionStartBlock && previousBlock)
|
|
142
|
-
return previousBlock;
|
|
143
|
-
}, getNextBlock = (snapshot) => {
|
|
144
|
-
let nextBlock;
|
|
145
|
-
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
146
|
-
if (!selectionEndBlock)
|
|
147
|
-
return;
|
|
148
|
-
let foundSelectionEndBlock = !1;
|
|
149
|
-
for (const block of snapshot.context.value) {
|
|
150
|
-
if (block._key === selectionEndBlock.node._key) {
|
|
151
|
-
foundSelectionEndBlock = !0;
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (foundSelectionEndBlock) {
|
|
155
|
-
nextBlock = {
|
|
156
|
-
node: block,
|
|
157
|
-
path: [{
|
|
158
|
-
_key: block._key
|
|
159
|
-
}]
|
|
160
|
-
};
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (foundSelectionEndBlock && nextBlock)
|
|
165
|
-
return nextBlock;
|
|
166
|
-
}, getPreviousInlineObject = (snapshot) => {
|
|
38
|
+
}, getSelectionStartPoint = (snapshot) => {
|
|
39
|
+
if (snapshot.context.selection)
|
|
40
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
41
|
+
}, 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, getPreviousInlineObject = (snapshot) => {
|
|
167
42
|
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
168
43
|
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
169
44
|
return;
|
|
@@ -183,21 +58,12 @@ const getSelectionStartPoint = (snapshot) => {
|
|
|
183
58
|
context: snapshot.context,
|
|
184
59
|
blocks: snapshot.context.value
|
|
185
60
|
}), getSelectionText = (snapshot) => getSelectedSlice(snapshot).reduce((text, block) => selectionPoint.isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => selectionPoint.isSpan$1(snapshot.context, child) ? text2 + child.text : text2, "") : text, ""), isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot);
|
|
186
|
-
exports.getFirstBlock = getFirstBlock;
|
|
187
61
|
exports.getFocusBlock = getFocusBlock;
|
|
188
|
-
exports.getFocusBlockObject = getFocusBlockObject;
|
|
189
62
|
exports.getFocusChild = getFocusChild;
|
|
190
|
-
exports.getFocusListBlock = getFocusListBlock;
|
|
191
63
|
exports.getFocusSpan = getFocusSpan;
|
|
192
64
|
exports.getFocusTextBlock = getFocusTextBlock;
|
|
193
|
-
exports.getLastBlock = getLastBlock;
|
|
194
|
-
exports.getNextBlock = getNextBlock;
|
|
195
|
-
exports.getPreviousBlock = getPreviousBlock;
|
|
196
65
|
exports.getPreviousInlineObject = getPreviousInlineObject;
|
|
197
|
-
exports.getSelectedBlocks = getSelectedBlocks;
|
|
198
66
|
exports.getSelectedSlice = getSelectedSlice;
|
|
199
|
-
exports.getSelectionEndBlock = getSelectionEndBlock;
|
|
200
|
-
exports.getSelectionStartBlock = getSelectionStartBlock;
|
|
201
67
|
exports.getSelectionStartPoint = getSelectionStartPoint;
|
|
202
68
|
exports.getSelectionText = getSelectionText;
|
|
203
69
|
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-selection-expanded.cjs","sources":["../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-expanded.ts"],"sourcesContent":["import type {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {\n KeyedSegment,\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isListBlock, isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport {getSelectionEndPoint, getSelectionStartPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node)\n ? {node: focusTextBlock.node, path: focusTextBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && !isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[snapshot.context.value.length - 1]\n ? snapshot.context.value[snapshot.context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const startKey = getBlockKeyFromSelectionPoint(startPoint)\n const endKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of snapshot.context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const key = getBlockKeyFromSelectionPoint(startPoint)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const key = getBlockKeyFromSelectionPoint(endPoint)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of snapshot.context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of snapshot.context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return sliceBlocks({\n context: snapshot.context,\n blocks: snapshot.context.value,\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getSelectedSlice} from './selector.get-selected-slice'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedSlice = getSelectedSlice(snapshot)\n\n return selectedSlice.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n"],"names":["getSelectionStartPoint","snapshot","context","selection","backward","focus","anchor","isSelectionCollapsed","JSON","stringify","path","offset","getFocusBlock","key","getBlockKeyFromSelectionPoint","node","value","find","block","_key","undefined","getFocusListBlock","focusTextBlock","getFocusTextBlock","isListBlock","focusBlock","isTextBlock","getFocusBlockObject","getFocusChild","getChildKeyFromSelectionPoint","children","span","getFocusSpan","focusChild","isSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startPoint","endPoint","getSelectionEndPoint","startKey","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getPreviousInlineObject","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectedSlice","sliceBlocks","blocks","getSelectionText","reduce","text","isSelectionExpanded"],"mappings":";;AAMO,MAAMA,yBAERC,CAAa,aAAA;AAChB,MAAKA,SAASC,QAAQC;AAIfF,WAAAA,SAASC,QAAQC,UAAUC,WAC9BH,SAASC,QAAQC,UAAUE,QAC3BJ,SAASC,QAAQC,UAAUG;AACjC,GCXaC,uBAAiDN,CAAAA,aACvDA,SAASC,QAAQC,YAKpBK,KAAKC,UAAUR,SAASC,QAAQC,UAAUG,OAAOI,IAAI,MACnDF,KAAKC,UAAUR,SAASC,QAAQC,UAAUE,MAAMK,IAAI,KACtDT,SAASC,QAAQC,WAAWG,OAAOK,WACjCV,SAASC,QAA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AAuBE,mBAAaF,oBAAoB/C,KAAK,CAAC,CAAC,IAC3D+C,oBAAoB/C,KAAK,CAAC,EAAES,OAC5BC;AAEF,MAAA,CAACE,kBAAkB,CAACoC;AACtB;AAGEE,MAAAA;AAOOC,aAAAA,SAASvC,eAAeP,KAAKe,UAAU;AAChD,QAAI+B,MAAM1C,SAASuC;AACjB;AAGGxB,mBAAAA,OAAOjC,SAASC,SAAS2D,KAAK,MACjCD,eAAe;AAAA,MACb7C,MAAM8C;AAAAA,MACNnD,MAAM,CAAC,GAAGY,eAAeZ,MAAM,YAAY;AAAA,QAACS,MAAM0C,MAAM1C;AAAAA,MAAK,CAAA;AAAA,IAAA;AAAA,EAC/D;AAIGyC,SAAAA;AACT,GC7CaE,mBACX7D,cAEO8D,2BAAY;AAAA,EACjB7D,SAASD,SAASC;AAAAA,EAClB8D,QAAQ/D,SAASC,QAAQc;AAC3B,CAAC,GCNUiD,mBAA4ChE,CAAAA,aACjC6D,iBAAiB7D,QAAQ,EAE1BiE,OAAO,CAACC,MAAMjD,UAC5BQ,eAAAA,YAAYzB,SAASC,SAASgB,KAAK,IAKtCiD,OACAjD,MAAMY,SAASoC,OAAO,CAACC,OAAMN,UACvB3B,eAAAA,SAAOjC,SAASC,SAAS2D,KAAK,IACzBM,QAAON,MAAMM,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE,GCnBMC,sBAAgDnE,CAAAA,aACpD,CAACM,qBAAqBN,QAAQ;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"selector.is-selection-expanded.cjs","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-expanded.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {\n KeyedSegment,\n PortableTextObject,\n PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../internal-utils/parse-blocks'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return sliceBlocks({\n context: snapshot.context,\n blocks: snapshot.context.value,\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getSelectedSlice} from './selector.get-selected-slice'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedSlice = getSelectedSlice(snapshot)\n\n return selectedSlice.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","node","value","find","block","_key","undefined","path","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectedSlice","sliceBlocks","blocks","getSelectionText","reduce","text","isSelectionExpanded"],"mappings":";;AAQO,MAAMA,gBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,eAA8BJ,8BAAAA,SAASC,QAAQC,UAAUG,KAAK,GAEpEC,OAAOH,MACTH,SAASC,QAAQM,MAAMC,KAAMC,WAAUA,MAAMC,SAASP,GAAG,IACzDQ;AAEJ,SAAOL,QAAQH,MAAM;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKQ;AACrD,GCbaE,oBAERb,CAAa,aAAA;AACVc,QAAAA,aAAaf,cAAcC,QAAQ;AAEzC,SAAOc,cAAcC,eAAAA,YAAYf,SAASC,SAASa,WAAWR,IAAI,IAC9D;AAAA,IAACA,MAAMQ,WAAWR;AAAAA,IAAMM,MAAME,WAAWF;AAAAA,EAAAA,IACzCD;AACN,GCLaK,gBAMRhB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGIY,QAAAA,aAAaD,kBAAkBb,QAAQ;AAE7C,MAAI,CAACc;AACH;AAGF,QAAMX,MAAMc,eAA8BjB,8BAAAA,SAASC,QAAQC,UAAUG,KAAK,GAEpEC,OAAOH,MACTW,WAAWR,KAAKY,SAASV,KAAMW,UAASA,KAAKT,SAASP,GAAG,IACzDQ;AAEJ,SAAOL,QAAQH,MACX;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC,GAAGE,WAAWF,MAAM,YAAY;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IACzDQ;AACN,GC9BaS,eAGRpB,CAAa,aAAA;AACVqB,QAAAA,aAAaL,cAAchB,QAAQ;AAEzC,SAAOqB,cAAcC,eAAAA,SA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aACjCqC,iBAAiBrC,QAAQ,EAE1ByC,OAAO,CAACC,MAAMjC,UAC5BM,eAAAA,YAAYf,SAASC,SAASQ,KAAK,IAKtCiC,OACAjC,MAAMS,SAASuB,OAAO,CAACC,OAAMN,UACvBd,eAAAA,SAAOtB,SAASC,SAASmC,KAAK,IACzBM,QAAON,MAAMM,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE,GCnBMC,sBAAgD3C,CAAAA,aACpD,CAAC0B,qBAAqB1B,QAAQ;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-text-before.js","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionStartPoint} from '../utils'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {
|
|
1
|
+
{"version":3,"file":"selector.get-text-before.js","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionStartPoint} from '../utils'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAa,aAAA;AAClE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAGT,QAAMC,aAAaC,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,cAAc;AAAA,IAE1BL,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACI,WAAA;AAGT,QAAMI,eAAeC,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,iBAAiB;AAAA,IAEtBV,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;"}
|
|
@@ -1,14 +1,48 @@
|
|
|
1
|
-
import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, isTextBlock, isSpan$1 as isSpan, isSpan as isSpan$1, spanSelectionPointToBlockOffset, getBlockStartPoint, blockOffsetToSpanSelectionPoint,
|
|
2
|
-
import { getSelectionStartPoint
|
|
1
|
+
import { getBlockKeyFromSelectionPoint, getSelectionStartPoint, getSelectionEndPoint as getSelectionEndPoint$1, getChildKeyFromSelectionPoint, isTextBlock, isSpan$1 as isSpan, isSpan as isSpan$1, spanSelectionPointToBlockOffset, getBlockStartPoint, blockOffsetToSpanSelectionPoint, isListBlock } from "./selection-point.js";
|
|
2
|
+
import { getSelectionStartPoint as getSelectionStartPoint$1, getFocusSpan, isSelectionCollapsed, getFocusTextBlock, getPreviousInlineObject, getSelectionText, isSelectionExpanded, getFocusBlock, getFocusChild } from "./selector.is-selection-expanded.js";
|
|
3
3
|
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./util.is-equal-selection-points.js";
|
|
4
4
|
import { isKeySegment, isPortableTextSpan } from "@sanity/types";
|
|
5
|
-
const
|
|
5
|
+
const getSelectedBlocks = (snapshot) => {
|
|
6
|
+
if (!snapshot.context.selection)
|
|
7
|
+
return [];
|
|
8
|
+
const selectedBlocks = [], startPoint = getSelectionStartPoint(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
9
|
+
if (!startKey || !endKey)
|
|
10
|
+
return selectedBlocks;
|
|
11
|
+
for (const block of snapshot.context.value) {
|
|
12
|
+
if (block._key === startKey) {
|
|
13
|
+
if (selectedBlocks.push({
|
|
14
|
+
node: block,
|
|
15
|
+
path: [{
|
|
16
|
+
_key: block._key
|
|
17
|
+
}]
|
|
18
|
+
}), startKey === endKey)
|
|
19
|
+
break;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (block._key === endKey) {
|
|
23
|
+
selectedBlocks.push({
|
|
24
|
+
node: block,
|
|
25
|
+
path: [{
|
|
26
|
+
_key: block._key
|
|
27
|
+
}]
|
|
28
|
+
});
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
32
|
+
node: block,
|
|
33
|
+
path: [{
|
|
34
|
+
_key: block._key
|
|
35
|
+
}]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return selectedBlocks;
|
|
39
|
+
}, getSelectionEndPoint = (snapshot) => {
|
|
6
40
|
if (snapshot.context.selection)
|
|
7
41
|
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
8
42
|
}, getSelectedSpans = (snapshot) => {
|
|
9
43
|
if (!snapshot.context.selection)
|
|
10
44
|
return [];
|
|
11
|
-
const selectedSpans = [], startPoint = getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
|
|
45
|
+
const selectedSpans = [], startPoint = getSelectionStartPoint$1(snapshot), endPoint = getSelectionEndPoint(snapshot);
|
|
12
46
|
if (!startPoint || !endPoint)
|
|
13
47
|
return selectedSpans;
|
|
14
48
|
const startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
@@ -150,7 +184,7 @@ const getSelectionEndPoint = (snapshot) => {
|
|
|
150
184
|
}, getCaretWordSelection = (snapshot) => {
|
|
151
185
|
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
152
186
|
return null;
|
|
153
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
|
|
187
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint$1(snapshot), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
|
|
154
188
|
context: snapshot.context,
|
|
155
189
|
selectionPoint: selectionStartPoint
|
|
156
190
|
}) : void 0;
|
|
@@ -214,16 +248,111 @@ const getSelectionEndPoint = (snapshot) => {
|
|
|
214
248
|
selection: caretWordSelection
|
|
215
249
|
}
|
|
216
250
|
}) ? caretWordSelection : null;
|
|
251
|
+
}, getFirstBlock = (snapshot) => {
|
|
252
|
+
const node = snapshot.context.value[0];
|
|
253
|
+
return node ? {
|
|
254
|
+
node,
|
|
255
|
+
path: [{
|
|
256
|
+
_key: node._key
|
|
257
|
+
}]
|
|
258
|
+
} : void 0;
|
|
259
|
+
}, getFocusBlockObject = (snapshot) => {
|
|
260
|
+
const focusBlock = getFocusBlock(snapshot);
|
|
261
|
+
return focusBlock && !isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
262
|
+
node: focusBlock.node,
|
|
263
|
+
path: focusBlock.path
|
|
264
|
+
} : void 0;
|
|
217
265
|
}, getFocusInlineObject = (snapshot) => {
|
|
218
266
|
const focusChild = getFocusChild(snapshot);
|
|
219
267
|
return focusChild && !isPortableTextSpan(focusChild.node) ? {
|
|
220
268
|
node: focusChild.node,
|
|
221
269
|
path: focusChild.path
|
|
222
270
|
} : void 0;
|
|
271
|
+
}, getFocusListBlock = (snapshot) => {
|
|
272
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
273
|
+
return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
274
|
+
node: focusTextBlock.node,
|
|
275
|
+
path: focusTextBlock.path
|
|
276
|
+
} : void 0;
|
|
277
|
+
}, getLastBlock = (snapshot) => {
|
|
278
|
+
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
279
|
+
return node ? {
|
|
280
|
+
node,
|
|
281
|
+
path: [{
|
|
282
|
+
_key: node._key
|
|
283
|
+
}]
|
|
284
|
+
} : void 0;
|
|
285
|
+
}, getSelectionStartBlock = (snapshot) => {
|
|
286
|
+
const startPoint = getSelectionStartPoint(snapshot.context.selection);
|
|
287
|
+
if (startPoint)
|
|
288
|
+
return getFocusBlock({
|
|
289
|
+
context: {
|
|
290
|
+
...snapshot.context,
|
|
291
|
+
selection: {
|
|
292
|
+
anchor: startPoint,
|
|
293
|
+
focus: startPoint
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}, getPreviousBlock = (snapshot) => {
|
|
298
|
+
let previousBlock;
|
|
299
|
+
const selectionStartBlock = getSelectionStartBlock(snapshot);
|
|
300
|
+
if (!selectionStartBlock)
|
|
301
|
+
return;
|
|
302
|
+
let foundSelectionStartBlock = !1;
|
|
303
|
+
for (const block of snapshot.context.value) {
|
|
304
|
+
if (block._key === selectionStartBlock.node._key) {
|
|
305
|
+
foundSelectionStartBlock = !0;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
previousBlock = {
|
|
309
|
+
node: block,
|
|
310
|
+
path: [{
|
|
311
|
+
_key: block._key
|
|
312
|
+
}]
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (foundSelectionStartBlock && previousBlock)
|
|
316
|
+
return previousBlock;
|
|
317
|
+
}, getSelectionEndBlock = (snapshot) => {
|
|
318
|
+
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
319
|
+
if (endPoint)
|
|
320
|
+
return getFocusBlock({
|
|
321
|
+
context: {
|
|
322
|
+
...snapshot.context,
|
|
323
|
+
selection: {
|
|
324
|
+
anchor: endPoint,
|
|
325
|
+
focus: endPoint
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}, getNextBlock = (snapshot) => {
|
|
330
|
+
let nextBlock;
|
|
331
|
+
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
332
|
+
if (!selectionEndBlock)
|
|
333
|
+
return;
|
|
334
|
+
let foundSelectionEndBlock = !1;
|
|
335
|
+
for (const block of snapshot.context.value) {
|
|
336
|
+
if (block._key === selectionEndBlock.node._key) {
|
|
337
|
+
foundSelectionEndBlock = !0;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (foundSelectionEndBlock) {
|
|
341
|
+
nextBlock = {
|
|
342
|
+
node: block,
|
|
343
|
+
path: [{
|
|
344
|
+
_key: block._key
|
|
345
|
+
}]
|
|
346
|
+
};
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (foundSelectionEndBlock && nextBlock)
|
|
351
|
+
return nextBlock;
|
|
223
352
|
}, getSelectedTextBlocks = (snapshot) => {
|
|
224
353
|
if (!snapshot.context.selection)
|
|
225
354
|
return [];
|
|
226
|
-
const selectedTextBlocks = [], startPoint = getSelectionStartPoint
|
|
355
|
+
const selectedTextBlocks = [], startPoint = getSelectionStartPoint(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
227
356
|
if (!startBlockKey || !endBlockKey)
|
|
228
357
|
return selectedTextBlocks;
|
|
229
358
|
for (const block of snapshot.context.value) {
|
|
@@ -257,7 +386,7 @@ const getSelectionEndPoint = (snapshot) => {
|
|
|
257
386
|
}, getTrimmedSelection = (snapshot) => {
|
|
258
387
|
if (!snapshot.context.selection)
|
|
259
388
|
return snapshot.context.selection;
|
|
260
|
-
const startPoint = getSelectionStartPoint
|
|
389
|
+
const startPoint = getSelectionStartPoint(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), endBlockKey = getBlockKeyFromSelectionPoint(endPoint), endChildKey = getChildKeyFromSelectionPoint(endPoint);
|
|
261
390
|
if (!startBlockKey || !endBlockKey)
|
|
262
391
|
return snapshot.context.selection;
|
|
263
392
|
let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
|
|
@@ -417,7 +546,7 @@ function isPointBeforeSelection(point) {
|
|
|
417
546
|
return (snapshot) => {
|
|
418
547
|
if (!snapshot.context.selection)
|
|
419
548
|
return !1;
|
|
420
|
-
const startPoint = getSelectionStartPoint
|
|
549
|
+
const startPoint = getSelectionStartPoint(snapshot.context.selection), startBlockKey = getBlockKeyFromSelectionPoint(startPoint), startChildKey = getChildKeyFromSelectionPoint(startPoint), pointBlockKey = getBlockKeyFromSelectionPoint(point), pointChildKey = getChildKeyFromSelectionPoint(point);
|
|
421
550
|
if (!pointBlockKey || !startBlockKey)
|
|
422
551
|
return !1;
|
|
423
552
|
let before = !1;
|
|
@@ -452,7 +581,7 @@ function isOverlappingSelection(selection) {
|
|
|
452
581
|
return (snapshot) => {
|
|
453
582
|
if (!selection || !snapshot.context.selection)
|
|
454
583
|
return !1;
|
|
455
|
-
const selectionStartPoint = getSelectionStartPoint({
|
|
584
|
+
const selectionStartPoint = getSelectionStartPoint$1({
|
|
456
585
|
context: {
|
|
457
586
|
...snapshot.context,
|
|
458
587
|
selection
|
|
@@ -462,7 +591,7 @@ function isOverlappingSelection(selection) {
|
|
|
462
591
|
...snapshot.context,
|
|
463
592
|
selection
|
|
464
593
|
}
|
|
465
|
-
}), originalSelectionStartPoint = getSelectionStartPoint(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
|
|
594
|
+
}), originalSelectionStartPoint = getSelectionStartPoint$1(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
|
|
466
595
|
if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
|
|
467
596
|
return !1;
|
|
468
597
|
const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
|
|
@@ -525,11 +654,20 @@ export {
|
|
|
525
654
|
getActiveListItem,
|
|
526
655
|
getActiveStyle,
|
|
527
656
|
getCaretWordSelection,
|
|
657
|
+
getFirstBlock,
|
|
658
|
+
getFocusBlockObject,
|
|
528
659
|
getFocusInlineObject,
|
|
660
|
+
getFocusListBlock,
|
|
661
|
+
getLastBlock,
|
|
662
|
+
getNextBlock,
|
|
529
663
|
getNextInlineObject,
|
|
664
|
+
getPreviousBlock,
|
|
665
|
+
getSelectedBlocks,
|
|
530
666
|
getSelectedSpans,
|
|
531
667
|
getSelectedTextBlocks,
|
|
668
|
+
getSelectionEndBlock,
|
|
532
669
|
getSelectionEndPoint,
|
|
670
|
+
getSelectionStartBlock,
|
|
533
671
|
getTrimmedSelection,
|
|
534
672
|
isActiveAnnotation,
|
|
535
673
|
isActiveDecorator,
|