@portabletext/editor 1.24.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +283 -64
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +8 -8
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +412 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +2 -2
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +46 -0
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
- package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -16
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +259 -40
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +2 -2
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +414 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/_chunks-es/util.is-empty-text-block.js +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +47 -0
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
- package/lib/_chunks-es/util.reverse-selection.js +0 -16
- package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
- package/lib/behaviors/index.cjs +27 -27
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +2208 -171
- package/lib/behaviors/index.d.ts +2208 -171
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +306 -298
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +10499 -521
- package/lib/index.d.ts +10499 -521
- package/lib/index.js +302 -294
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +26 -171
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +16 -0
- package/lib/selectors/index.d.ts +16 -0
- package/lib/selectors/index.js +5 -151
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -3
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +19 -0
- package/lib/utils/index.d.ts +19 -0
- package/lib/utils/index.js +4 -2
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -3
- package/src/behavior-actions/behavior.action.block.set.ts +23 -0
- package/src/behavior-actions/behavior.action.block.unset.ts +21 -0
- package/src/behavior-actions/behavior.action.insert-break.ts +2 -69
- package/src/behavior-actions/behavior.action.insert.block.ts +29 -0
- package/src/behavior-actions/behavior.actions.ts +116 -96
- package/src/behaviors/behavior.core.annotations.ts +29 -0
- package/src/behaviors/behavior.core.block-objects.ts +13 -13
- package/src/behaviors/behavior.core.decorators.ts +19 -0
- package/src/behaviors/behavior.core.insert-break.ts +122 -0
- package/src/behaviors/behavior.core.lists.ts +57 -23
- package/src/behaviors/behavior.core.style.ts +19 -0
- package/src/behaviors/behavior.core.ts +18 -2
- package/src/behaviors/behavior.types.ts +103 -88
- package/src/converters/converter.json.ts +4 -4
- package/src/converters/converter.portable-text.deserialize.test.ts +1 -1
- package/src/converters/converter.portable-text.ts +4 -4
- package/src/converters/converter.text-html.deserialize.test.ts +1 -1
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/converters/converter.text-html.ts +4 -4
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +3 -3
- package/src/converters/{converter.ts → converter.types.ts} +6 -0
- package/src/editor/create-editor.ts +50 -7
- package/src/editor/editor-machine.ts +46 -3
- package/src/editor/editor-snapshot.ts +1 -1
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +41 -106
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.is-at-the-end-of-block.ts +22 -0
- package/src/selectors/selector.is-at-the-start-of-block.ts +25 -0
- package/src/selectors/selector.is-selection-collapsed.ts +6 -2
- package/src/utils/index.ts +2 -0
- package/src/utils/util.get-block-end-point.ts +34 -0
- package/src/utils/util.is-equal-selection-points.ts +13 -0
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs +0 -231
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs +0 -6
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-collapsed.js +0 -232
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
- package/lib/_chunks-es/util.is-keyed-segment.js +0 -7
- package/lib/_chunks-es/util.is-keyed-segment.js.map +0 -1
- /package/src/converters/{converters.ts → converters.core.ts} +0 -0
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var 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 = ({
|
|
18
|
-
context
|
|
19
|
-
}) => {
|
|
20
|
-
const key = context.selection && types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
21
|
-
return node && key ? {
|
|
22
|
-
node,
|
|
23
|
-
path: [{
|
|
24
|
-
_key: key
|
|
25
|
-
}]
|
|
26
|
-
} : void 0;
|
|
27
|
-
}, getFocusListBlock = ({
|
|
28
|
-
context
|
|
29
|
-
}) => {
|
|
30
|
-
const guards = createGuards(context), focusBlock = getFocusBlock({
|
|
31
|
-
context
|
|
32
|
-
});
|
|
33
|
-
return focusBlock && guards.isListBlock(focusBlock.node) ? {
|
|
34
|
-
node: focusBlock.node,
|
|
35
|
-
path: focusBlock.path
|
|
36
|
-
} : void 0;
|
|
37
|
-
}, getFocusTextBlock = ({
|
|
38
|
-
context
|
|
39
|
-
}) => {
|
|
40
|
-
const focusBlock = getFocusBlock({
|
|
41
|
-
context
|
|
42
|
-
});
|
|
43
|
-
return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
44
|
-
node: focusBlock.node,
|
|
45
|
-
path: focusBlock.path
|
|
46
|
-
} : void 0;
|
|
47
|
-
}, getFocusBlockObject = ({
|
|
48
|
-
context
|
|
49
|
-
}) => {
|
|
50
|
-
const focusBlock = getFocusBlock({
|
|
51
|
-
context
|
|
52
|
-
});
|
|
53
|
-
return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
54
|
-
node: focusBlock.node,
|
|
55
|
-
path: focusBlock.path
|
|
56
|
-
} : void 0;
|
|
57
|
-
}, getFocusChild = ({
|
|
58
|
-
context
|
|
59
|
-
}) => {
|
|
60
|
-
const focusBlock = getFocusTextBlock({
|
|
61
|
-
context
|
|
62
|
-
});
|
|
63
|
-
if (!focusBlock)
|
|
64
|
-
return;
|
|
65
|
-
const key = context.selection && types.isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
66
|
-
return node && key ? {
|
|
67
|
-
node,
|
|
68
|
-
path: [...focusBlock.path, "children", {
|
|
69
|
-
_key: key
|
|
70
|
-
}]
|
|
71
|
-
} : void 0;
|
|
72
|
-
}, getFocusSpan = ({
|
|
73
|
-
context
|
|
74
|
-
}) => {
|
|
75
|
-
const focusChild = getFocusChild({
|
|
76
|
-
context
|
|
77
|
-
});
|
|
78
|
-
return focusChild && types.isPortableTextSpan(focusChild.node) ? {
|
|
79
|
-
node: focusChild.node,
|
|
80
|
-
path: focusChild.path
|
|
81
|
-
} : void 0;
|
|
82
|
-
}, getFirstBlock = ({
|
|
83
|
-
context
|
|
84
|
-
}) => {
|
|
85
|
-
const node = context.value[0];
|
|
86
|
-
return node ? {
|
|
87
|
-
node,
|
|
88
|
-
path: [{
|
|
89
|
-
_key: node._key
|
|
90
|
-
}]
|
|
91
|
-
} : void 0;
|
|
92
|
-
}, getLastBlock = ({
|
|
93
|
-
context
|
|
94
|
-
}) => {
|
|
95
|
-
const node = context.value[context.value.length - 1] ? context.value[context.value.length - 1] : void 0;
|
|
96
|
-
return node ? {
|
|
97
|
-
node,
|
|
98
|
-
path: [{
|
|
99
|
-
_key: node._key
|
|
100
|
-
}]
|
|
101
|
-
} : void 0;
|
|
102
|
-
}, getSelectedBlocks = ({
|
|
103
|
-
context
|
|
104
|
-
}) => {
|
|
105
|
-
if (!context.selection)
|
|
106
|
-
return [];
|
|
107
|
-
const selectedBlocks = [], startKey = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, endKey = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0;
|
|
108
|
-
if (!startKey || !endKey)
|
|
109
|
-
return selectedBlocks;
|
|
110
|
-
for (const block of context.value) {
|
|
111
|
-
if (block._key === startKey) {
|
|
112
|
-
if (selectedBlocks.push({
|
|
113
|
-
node: block,
|
|
114
|
-
path: [{
|
|
115
|
-
_key: block._key
|
|
116
|
-
}]
|
|
117
|
-
}), startKey === endKey)
|
|
118
|
-
break;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (block._key === endKey) {
|
|
122
|
-
selectedBlocks.push({
|
|
123
|
-
node: block,
|
|
124
|
-
path: [{
|
|
125
|
-
_key: block._key
|
|
126
|
-
}]
|
|
127
|
-
});
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
131
|
-
node: block,
|
|
132
|
-
path: [{
|
|
133
|
-
_key: block._key
|
|
134
|
-
}]
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
return selectedBlocks;
|
|
138
|
-
}, getSelectionStartBlock = ({
|
|
139
|
-
context
|
|
140
|
-
}) => {
|
|
141
|
-
if (!context.selection)
|
|
142
|
-
return;
|
|
143
|
-
const key = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
144
|
-
return node && key ? {
|
|
145
|
-
node,
|
|
146
|
-
path: [{
|
|
147
|
-
_key: key
|
|
148
|
-
}]
|
|
149
|
-
} : void 0;
|
|
150
|
-
}, getSelectionEndBlock = ({
|
|
151
|
-
context
|
|
152
|
-
}) => {
|
|
153
|
-
if (!context.selection)
|
|
154
|
-
return;
|
|
155
|
-
const key = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
156
|
-
return node && key ? {
|
|
157
|
-
node,
|
|
158
|
-
path: [{
|
|
159
|
-
_key: key
|
|
160
|
-
}]
|
|
161
|
-
} : void 0;
|
|
162
|
-
}, getPreviousBlock = ({
|
|
163
|
-
context
|
|
164
|
-
}) => {
|
|
165
|
-
let previousBlock;
|
|
166
|
-
const selectionStartBlock = getSelectionStartBlock({
|
|
167
|
-
context
|
|
168
|
-
});
|
|
169
|
-
if (!selectionStartBlock)
|
|
170
|
-
return;
|
|
171
|
-
let foundSelectionStartBlock = !1;
|
|
172
|
-
for (const block of context.value) {
|
|
173
|
-
if (block._key === selectionStartBlock.node._key) {
|
|
174
|
-
foundSelectionStartBlock = !0;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
previousBlock = {
|
|
178
|
-
node: block,
|
|
179
|
-
path: [{
|
|
180
|
-
_key: block._key
|
|
181
|
-
}]
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
if (foundSelectionStartBlock && previousBlock)
|
|
185
|
-
return previousBlock;
|
|
186
|
-
}, getNextBlock = ({
|
|
187
|
-
context
|
|
188
|
-
}) => {
|
|
189
|
-
let nextBlock;
|
|
190
|
-
const selectionEndBlock = getSelectionEndBlock({
|
|
191
|
-
context
|
|
192
|
-
});
|
|
193
|
-
if (!selectionEndBlock)
|
|
194
|
-
return;
|
|
195
|
-
let foundSelectionEndBlock = !1;
|
|
196
|
-
for (const block of context.value) {
|
|
197
|
-
if (block._key === selectionEndBlock.node._key) {
|
|
198
|
-
foundSelectionEndBlock = !0;
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (foundSelectionEndBlock) {
|
|
202
|
-
nextBlock = {
|
|
203
|
-
node: block,
|
|
204
|
-
path: [{
|
|
205
|
-
_key: block._key
|
|
206
|
-
}]
|
|
207
|
-
};
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (foundSelectionEndBlock && nextBlock)
|
|
212
|
-
return nextBlock;
|
|
213
|
-
}, isSelectionCollapsed = ({
|
|
214
|
-
context
|
|
215
|
-
}) => JSON.stringify(context.selection?.anchor.path) === JSON.stringify(context.selection?.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset;
|
|
216
|
-
exports.createGuards = createGuards;
|
|
217
|
-
exports.getFirstBlock = getFirstBlock;
|
|
218
|
-
exports.getFocusBlock = getFocusBlock;
|
|
219
|
-
exports.getFocusBlockObject = getFocusBlockObject;
|
|
220
|
-
exports.getFocusChild = getFocusChild;
|
|
221
|
-
exports.getFocusListBlock = getFocusListBlock;
|
|
222
|
-
exports.getFocusSpan = getFocusSpan;
|
|
223
|
-
exports.getFocusTextBlock = getFocusTextBlock;
|
|
224
|
-
exports.getLastBlock = getLastBlock;
|
|
225
|
-
exports.getNextBlock = getNextBlock;
|
|
226
|
-
exports.getPreviousBlock = getPreviousBlock;
|
|
227
|
-
exports.getSelectedBlocks = getSelectedBlocks;
|
|
228
|
-
exports.getSelectionEndBlock = getSelectionEndBlock;
|
|
229
|
-
exports.getSelectionStartBlock = getSelectionStartBlock;
|
|
230
|
-
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
231
|
-
//# sourceMappingURL=selector.is-selection-collapsed.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-selection-collapsed.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.is-selection-collapsed.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? 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> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(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> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(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> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\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> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(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> = ({context}) => {\n const node = 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> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[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> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of 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> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? 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> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? 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> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of 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> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of 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 type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","context","key","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","isSelectionCollapsed","JSON","stringify","offset"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACNO,MAAME,gBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,QAAMC,MAAMD,QAAQE,aAChB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{KeyedSegment, PathSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n"],"names":["isKeyedSegment","segment"],"mappings":";AAKO,SAASA,eAAeC,SAA+C;AAC5E,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;;"}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { isPortableTextListBlock, isPortableTextTextBlock, isKeySegment, isPortableTextSpan } from "@sanity/types";
|
|
2
|
-
function createGuards({
|
|
3
|
-
schema
|
|
4
|
-
}) {
|
|
5
|
-
function isListBlock(block) {
|
|
6
|
-
return isPortableTextListBlock(block) && block._type === schema.block.name;
|
|
7
|
-
}
|
|
8
|
-
function isTextBlock(block) {
|
|
9
|
-
return isPortableTextTextBlock(block) && block._type === schema.block.name;
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
isListBlock,
|
|
13
|
-
isTextBlock
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const getFocusBlock = ({
|
|
17
|
-
context
|
|
18
|
-
}) => {
|
|
19
|
-
const key = context.selection && isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
20
|
-
return node && key ? {
|
|
21
|
-
node,
|
|
22
|
-
path: [{
|
|
23
|
-
_key: key
|
|
24
|
-
}]
|
|
25
|
-
} : void 0;
|
|
26
|
-
}, getFocusListBlock = ({
|
|
27
|
-
context
|
|
28
|
-
}) => {
|
|
29
|
-
const guards = createGuards(context), focusBlock = getFocusBlock({
|
|
30
|
-
context
|
|
31
|
-
});
|
|
32
|
-
return focusBlock && guards.isListBlock(focusBlock.node) ? {
|
|
33
|
-
node: focusBlock.node,
|
|
34
|
-
path: focusBlock.path
|
|
35
|
-
} : void 0;
|
|
36
|
-
}, getFocusTextBlock = ({
|
|
37
|
-
context
|
|
38
|
-
}) => {
|
|
39
|
-
const focusBlock = getFocusBlock({
|
|
40
|
-
context
|
|
41
|
-
});
|
|
42
|
-
return focusBlock && isPortableTextTextBlock(focusBlock.node) ? {
|
|
43
|
-
node: focusBlock.node,
|
|
44
|
-
path: focusBlock.path
|
|
45
|
-
} : void 0;
|
|
46
|
-
}, getFocusBlockObject = ({
|
|
47
|
-
context
|
|
48
|
-
}) => {
|
|
49
|
-
const focusBlock = getFocusBlock({
|
|
50
|
-
context
|
|
51
|
-
});
|
|
52
|
-
return focusBlock && !isPortableTextTextBlock(focusBlock.node) ? {
|
|
53
|
-
node: focusBlock.node,
|
|
54
|
-
path: focusBlock.path
|
|
55
|
-
} : void 0;
|
|
56
|
-
}, getFocusChild = ({
|
|
57
|
-
context
|
|
58
|
-
}) => {
|
|
59
|
-
const focusBlock = getFocusTextBlock({
|
|
60
|
-
context
|
|
61
|
-
});
|
|
62
|
-
if (!focusBlock)
|
|
63
|
-
return;
|
|
64
|
-
const key = context.selection && isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
65
|
-
return node && key ? {
|
|
66
|
-
node,
|
|
67
|
-
path: [...focusBlock.path, "children", {
|
|
68
|
-
_key: key
|
|
69
|
-
}]
|
|
70
|
-
} : void 0;
|
|
71
|
-
}, getFocusSpan = ({
|
|
72
|
-
context
|
|
73
|
-
}) => {
|
|
74
|
-
const focusChild = getFocusChild({
|
|
75
|
-
context
|
|
76
|
-
});
|
|
77
|
-
return focusChild && isPortableTextSpan(focusChild.node) ? {
|
|
78
|
-
node: focusChild.node,
|
|
79
|
-
path: focusChild.path
|
|
80
|
-
} : void 0;
|
|
81
|
-
}, getFirstBlock = ({
|
|
82
|
-
context
|
|
83
|
-
}) => {
|
|
84
|
-
const node = context.value[0];
|
|
85
|
-
return node ? {
|
|
86
|
-
node,
|
|
87
|
-
path: [{
|
|
88
|
-
_key: node._key
|
|
89
|
-
}]
|
|
90
|
-
} : void 0;
|
|
91
|
-
}, getLastBlock = ({
|
|
92
|
-
context
|
|
93
|
-
}) => {
|
|
94
|
-
const node = context.value[context.value.length - 1] ? context.value[context.value.length - 1] : void 0;
|
|
95
|
-
return node ? {
|
|
96
|
-
node,
|
|
97
|
-
path: [{
|
|
98
|
-
_key: node._key
|
|
99
|
-
}]
|
|
100
|
-
} : void 0;
|
|
101
|
-
}, getSelectedBlocks = ({
|
|
102
|
-
context
|
|
103
|
-
}) => {
|
|
104
|
-
if (!context.selection)
|
|
105
|
-
return [];
|
|
106
|
-
const selectedBlocks = [], startKey = context.selection.backward ? isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, endKey = context.selection.backward ? isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0;
|
|
107
|
-
if (!startKey || !endKey)
|
|
108
|
-
return selectedBlocks;
|
|
109
|
-
for (const block of context.value) {
|
|
110
|
-
if (block._key === startKey) {
|
|
111
|
-
if (selectedBlocks.push({
|
|
112
|
-
node: block,
|
|
113
|
-
path: [{
|
|
114
|
-
_key: block._key
|
|
115
|
-
}]
|
|
116
|
-
}), startKey === endKey)
|
|
117
|
-
break;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (block._key === endKey) {
|
|
121
|
-
selectedBlocks.push({
|
|
122
|
-
node: block,
|
|
123
|
-
path: [{
|
|
124
|
-
_key: block._key
|
|
125
|
-
}]
|
|
126
|
-
});
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
130
|
-
node: block,
|
|
131
|
-
path: [{
|
|
132
|
-
_key: block._key
|
|
133
|
-
}]
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
return selectedBlocks;
|
|
137
|
-
}, getSelectionStartBlock = ({
|
|
138
|
-
context
|
|
139
|
-
}) => {
|
|
140
|
-
if (!context.selection)
|
|
141
|
-
return;
|
|
142
|
-
const key = context.selection.backward ? isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
143
|
-
return node && key ? {
|
|
144
|
-
node,
|
|
145
|
-
path: [{
|
|
146
|
-
_key: key
|
|
147
|
-
}]
|
|
148
|
-
} : void 0;
|
|
149
|
-
}, getSelectionEndBlock = ({
|
|
150
|
-
context
|
|
151
|
-
}) => {
|
|
152
|
-
if (!context.selection)
|
|
153
|
-
return;
|
|
154
|
-
const key = context.selection.backward ? isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
155
|
-
return node && key ? {
|
|
156
|
-
node,
|
|
157
|
-
path: [{
|
|
158
|
-
_key: key
|
|
159
|
-
}]
|
|
160
|
-
} : void 0;
|
|
161
|
-
}, getPreviousBlock = ({
|
|
162
|
-
context
|
|
163
|
-
}) => {
|
|
164
|
-
let previousBlock;
|
|
165
|
-
const selectionStartBlock = getSelectionStartBlock({
|
|
166
|
-
context
|
|
167
|
-
});
|
|
168
|
-
if (!selectionStartBlock)
|
|
169
|
-
return;
|
|
170
|
-
let foundSelectionStartBlock = !1;
|
|
171
|
-
for (const block of context.value) {
|
|
172
|
-
if (block._key === selectionStartBlock.node._key) {
|
|
173
|
-
foundSelectionStartBlock = !0;
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
previousBlock = {
|
|
177
|
-
node: block,
|
|
178
|
-
path: [{
|
|
179
|
-
_key: block._key
|
|
180
|
-
}]
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
if (foundSelectionStartBlock && previousBlock)
|
|
184
|
-
return previousBlock;
|
|
185
|
-
}, getNextBlock = ({
|
|
186
|
-
context
|
|
187
|
-
}) => {
|
|
188
|
-
let nextBlock;
|
|
189
|
-
const selectionEndBlock = getSelectionEndBlock({
|
|
190
|
-
context
|
|
191
|
-
});
|
|
192
|
-
if (!selectionEndBlock)
|
|
193
|
-
return;
|
|
194
|
-
let foundSelectionEndBlock = !1;
|
|
195
|
-
for (const block of context.value) {
|
|
196
|
-
if (block._key === selectionEndBlock.node._key) {
|
|
197
|
-
foundSelectionEndBlock = !0;
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
if (foundSelectionEndBlock) {
|
|
201
|
-
nextBlock = {
|
|
202
|
-
node: block,
|
|
203
|
-
path: [{
|
|
204
|
-
_key: block._key
|
|
205
|
-
}]
|
|
206
|
-
};
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (foundSelectionEndBlock && nextBlock)
|
|
211
|
-
return nextBlock;
|
|
212
|
-
}, isSelectionCollapsed = ({
|
|
213
|
-
context
|
|
214
|
-
}) => JSON.stringify(context.selection?.anchor.path) === JSON.stringify(context.selection?.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset;
|
|
215
|
-
export {
|
|
216
|
-
createGuards,
|
|
217
|
-
getFirstBlock,
|
|
218
|
-
getFocusBlock,
|
|
219
|
-
getFocusBlockObject,
|
|
220
|
-
getFocusChild,
|
|
221
|
-
getFocusListBlock,
|
|
222
|
-
getFocusSpan,
|
|
223
|
-
getFocusTextBlock,
|
|
224
|
-
getLastBlock,
|
|
225
|
-
getNextBlock,
|
|
226
|
-
getPreviousBlock,
|
|
227
|
-
getSelectedBlocks,
|
|
228
|
-
getSelectionEndBlock,
|
|
229
|
-
getSelectionStartBlock,
|
|
230
|
-
isSelectionCollapsed
|
|
231
|
-
};
|
|
232
|
-
//# sourceMappingURL=selector.is-selection-collapsed.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-selection-collapsed.js","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.is-selection-collapsed.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? 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> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(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> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(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> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\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> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(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> = ({context}) => {\n const node = 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> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[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> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of 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> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? 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> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? 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> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of 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> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of 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 type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n return (\n JSON.stringify(context.selection?.anchor.path) ===\n JSON.stringify(context.selection?.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","context","key","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","isSelectionCollapsed","JSON","stringify","offset"],"mappings":";AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACNO,MAAME,gBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,QAAMC,MAAMD,QAAQE,aAChBC,aAAaH,QAAQE,UAAUE,MAAMC,KAAK,CAAC,CAAC,IAC1CL,QAAQE,UAAUE,MAAMC,KAAK,CAAC,EAAEC,OAElCC,QAEEC,OAAOP,MACTD,QAAQS,MAAMC,KAAMjB,CAAUA,UAAAA,MAAMa,SAASL,GAAG,IAChDM;AAEJ,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAML;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKM;AACrD,GAKaI,oBAETA,CAAC;AAAA,EAACX;AAAO,MAAM;AACjB,QAAMY,SAAStB,aAAaU,OAAO,GAC7Ba,aAAad,cAAc;AAAA,IAACC;AAAAA,EAAAA,CAAQ;AAE1C,SAAOa,cAAcD,OAAOpB,YAAYqB,WAAWL,IAAI,IACnD;AAAA,IAACA,MAAMK,WAAWL;AAAAA,IAAMH,MAAMQ,WAAWR;AAAAA,EA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AA;AACzB;AAAA,IAAA;AAGF,QAAImC,wBAAwB;AACd,kBAAA;AAAA,QAACjC,MAAMf;AAAAA,QAAOY,MAAM,CAAC;AAAA,UAACC,MAAMb,MAAMa;AAAAA,QAAK,CAAA;AAAA,MAAC;AACpD;AAAA,IAAA;AAAA,EACF;AAGF,MAAImC,0BAA0BF;AACrBA,WAAAA;AAIX,GCxTaG,uBAAgDA,CAAC;AAAA,EAAC1C;AAAO,MAElE2C,KAAKC,UAAU5C,QAAQE,WAAW2B,OAAOxB,IAAI,MAC3CsC,KAAKC,UAAU5C,QAAQE,WAAWE,MAAMC,IAAI,KAC9CL,QAAQE,WAAW2B,OAAOgB,WAAW7C,QAAQE,WAAWE,MAAMyC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.is-keyed-segment.js","sources":["../../src/utils/util.is-keyed-segment.ts"],"sourcesContent":["import type {KeyedSegment, PathSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n"],"names":["isKeyedSegment","segment"],"mappings":"AAKO,SAASA,eAAeC,SAA+C;AAC5E,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;"}
|
|
File without changes
|