@portabletext/editor 1.26.3 → 1.28.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/README.md +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs +327 -0
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -0
- package/lib/_chunks-cjs/plugin.event-listener.cjs +6827 -0
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +88 -88
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +332 -0
- package/lib/_chunks-es/behavior.markdown.js.map +1 -0
- package/lib/_chunks-es/plugin.event-listener.js +6851 -0
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +88 -88
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/behaviors/index.cjs +2 -325
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +1 -1
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/behaviors/index.js +2 -326
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +261 -6782
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3509 -2161
- package/lib/index.d.ts +3509 -2161
- package/lib/index.js +223 -6761
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +29 -0
- package/lib/plugins/index.cjs.map +1 -0
- package/lib/plugins/index.d.cts +19411 -0
- package/lib/plugins/index.d.ts +19411 -0
- package/lib/plugins/index.js +29 -0
- package/lib/plugins/index.js.map +1 -0
- package/lib/selectors/index.cjs +15 -3
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +19 -1
- package/lib/selectors/index.d.ts +19 -1
- package/lib/selectors/index.js +17 -4
- package/lib/selectors/index.js.map +1 -1
- package/package.json +14 -8
- package/src/behavior-actions/behavior.action.insert-break.ts +93 -83
- package/src/editor/Editable.tsx +6 -6
- package/src/editor/PortableTextEditor.tsx +288 -1
- package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -1
- package/src/editor/components/DefaultObject.tsx +21 -0
- package/src/editor/components/Element.tsx +5 -5
- package/src/editor/components/Leaf.tsx +1 -6
- package/src/editor/components/Synchronizer.tsx +16 -1
- package/src/editor/create-editor.ts +8 -48
- package/src/editor/editor-machine.ts +118 -131
- package/src/editor/plugins/create-with-event-listeners.ts +19 -38
- package/src/editor/plugins/createWithPatches.ts +1 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +2 -2
- package/src/editor/sync-machine.ts +3 -5
- package/src/index.ts +5 -11
- package/src/plugins/_exports/index.ts +1 -0
- package/src/plugins/index.ts +3 -0
- package/src/plugins/plugin.editor-ref.tsx +17 -0
- package/src/{editor/editor-event-listener.tsx → plugins/plugin.event-listener.tsx} +7 -6
- package/src/plugins/plugin.markdown.tsx +70 -0
- package/src/selectors/index.ts +4 -2
- package/src/selectors/selector.get-active-annotations.test.ts +122 -0
- package/src/selectors/selector.get-active-annotations.ts +30 -0
- package/src/selectors/selector.get-selection.ts +8 -0
- package/src/selectors/selector.get-value.ts +11 -0
- package/src/type-utils.ts +12 -2
- package/src/editor/nodes/DefaultAnnotation.tsx +0 -20
- package/src/editor/nodes/DefaultObject.tsx +0 -18
|
@@ -14,7 +14,94 @@ function createGuards({
|
|
|
14
14
|
isTextBlock
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const getSelectedSpans = ({
|
|
18
|
+
context
|
|
19
|
+
}) => {
|
|
20
|
+
if (!context.selection)
|
|
21
|
+
return [];
|
|
22
|
+
const selectedSpans = [], startPoint = context.selection.backward ? context.selection.focus : context.selection.anchor, endPoint = context.selection.backward ? context.selection.anchor : context.selection.focus, startBlockKey = types.isKeySegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = types.isKeySegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0;
|
|
23
|
+
if (!startBlockKey || !endBlockKey)
|
|
24
|
+
return selectedSpans;
|
|
25
|
+
const startSpanKey = types.isKeySegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endSpanKey = types.isKeySegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
|
|
26
|
+
for (const block of context.value)
|
|
27
|
+
if (types.isPortableTextTextBlock(block)) {
|
|
28
|
+
if (block._key === startBlockKey) {
|
|
29
|
+
for (const child of block.children)
|
|
30
|
+
if (types.isPortableTextSpan(child)) {
|
|
31
|
+
if (startSpanKey && child._key === startSpanKey) {
|
|
32
|
+
if (selectedSpans.push({
|
|
33
|
+
node: child,
|
|
34
|
+
path: [{
|
|
35
|
+
_key: block._key
|
|
36
|
+
}, "children", {
|
|
37
|
+
_key: child._key
|
|
38
|
+
}]
|
|
39
|
+
}), startSpanKey === endSpanKey)
|
|
40
|
+
break;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (endSpanKey && child._key === endSpanKey) {
|
|
44
|
+
selectedSpans.push({
|
|
45
|
+
node: child,
|
|
46
|
+
path: [{
|
|
47
|
+
_key: block._key
|
|
48
|
+
}, "children", {
|
|
49
|
+
_key: child._key
|
|
50
|
+
}]
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
selectedSpans.length > 0 && selectedSpans.push({
|
|
55
|
+
node: child,
|
|
56
|
+
path: [{
|
|
57
|
+
_key: block._key
|
|
58
|
+
}, "children", {
|
|
59
|
+
_key: child._key
|
|
60
|
+
}]
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (startBlockKey === endBlockKey)
|
|
64
|
+
break;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (block._key === endBlockKey) {
|
|
68
|
+
for (const child of block.children)
|
|
69
|
+
if (types.isPortableTextSpan(child)) {
|
|
70
|
+
if (endSpanKey && child._key === endSpanKey) {
|
|
71
|
+
selectedSpans.push({
|
|
72
|
+
node: child,
|
|
73
|
+
path: [{
|
|
74
|
+
_key: block._key
|
|
75
|
+
}, "children", {
|
|
76
|
+
_key: child._key
|
|
77
|
+
}]
|
|
78
|
+
});
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
selectedSpans.push({
|
|
82
|
+
node: child,
|
|
83
|
+
path: [{
|
|
84
|
+
_key: block._key
|
|
85
|
+
}, "children", {
|
|
86
|
+
_key: child._key
|
|
87
|
+
}]
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (selectedSpans.length > 0)
|
|
93
|
+
for (const child of block.children)
|
|
94
|
+
types.isPortableTextSpan(child) && selectedSpans.push({
|
|
95
|
+
node: child,
|
|
96
|
+
path: [{
|
|
97
|
+
_key: block._key
|
|
98
|
+
}, "children", {
|
|
99
|
+
_key: child._key
|
|
100
|
+
}]
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return selectedSpans;
|
|
104
|
+
}, getFocusBlock = ({
|
|
18
105
|
context
|
|
19
106
|
}) => {
|
|
20
107
|
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;
|
|
@@ -236,93 +323,6 @@ const getFocusBlock = ({
|
|
|
236
323
|
const firstStyle = firstTextBlock.style;
|
|
237
324
|
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
238
325
|
return firstStyle;
|
|
239
|
-
}, getSelectedSpans = ({
|
|
240
|
-
context
|
|
241
|
-
}) => {
|
|
242
|
-
if (!context.selection)
|
|
243
|
-
return [];
|
|
244
|
-
const selectedSpans = [], startPoint = context.selection.backward ? context.selection.focus : context.selection.anchor, endPoint = context.selection.backward ? context.selection.anchor : context.selection.focus, startBlockKey = types.isKeySegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = types.isKeySegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0;
|
|
245
|
-
if (!startBlockKey || !endBlockKey)
|
|
246
|
-
return selectedSpans;
|
|
247
|
-
const startSpanKey = types.isKeySegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endSpanKey = types.isKeySegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
|
|
248
|
-
for (const block of context.value)
|
|
249
|
-
if (types.isPortableTextTextBlock(block)) {
|
|
250
|
-
if (block._key === startBlockKey) {
|
|
251
|
-
for (const child of block.children)
|
|
252
|
-
if (types.isPortableTextSpan(child)) {
|
|
253
|
-
if (startSpanKey && child._key === startSpanKey) {
|
|
254
|
-
if (selectedSpans.push({
|
|
255
|
-
node: child,
|
|
256
|
-
path: [{
|
|
257
|
-
_key: block._key
|
|
258
|
-
}, "children", {
|
|
259
|
-
_key: child._key
|
|
260
|
-
}]
|
|
261
|
-
}), startSpanKey === endSpanKey)
|
|
262
|
-
break;
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
266
|
-
selectedSpans.push({
|
|
267
|
-
node: child,
|
|
268
|
-
path: [{
|
|
269
|
-
_key: block._key
|
|
270
|
-
}, "children", {
|
|
271
|
-
_key: child._key
|
|
272
|
-
}]
|
|
273
|
-
});
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
selectedSpans.length > 0 && selectedSpans.push({
|
|
277
|
-
node: child,
|
|
278
|
-
path: [{
|
|
279
|
-
_key: block._key
|
|
280
|
-
}, "children", {
|
|
281
|
-
_key: child._key
|
|
282
|
-
}]
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
if (startBlockKey === endBlockKey)
|
|
286
|
-
break;
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
if (block._key === endBlockKey) {
|
|
290
|
-
for (const child of block.children)
|
|
291
|
-
if (types.isPortableTextSpan(child)) {
|
|
292
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
293
|
-
selectedSpans.push({
|
|
294
|
-
node: child,
|
|
295
|
-
path: [{
|
|
296
|
-
_key: block._key
|
|
297
|
-
}, "children", {
|
|
298
|
-
_key: child._key
|
|
299
|
-
}]
|
|
300
|
-
});
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
selectedSpans.push({
|
|
304
|
-
node: child,
|
|
305
|
-
path: [{
|
|
306
|
-
_key: block._key
|
|
307
|
-
}, "children", {
|
|
308
|
-
_key: child._key
|
|
309
|
-
}]
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
if (selectedSpans.length > 0)
|
|
315
|
-
for (const child of block.children)
|
|
316
|
-
types.isPortableTextSpan(child) && selectedSpans.push({
|
|
317
|
-
node: child,
|
|
318
|
-
path: [{
|
|
319
|
-
_key: block._key
|
|
320
|
-
}, "children", {
|
|
321
|
-
_key: child._key
|
|
322
|
-
}]
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
return selectedSpans;
|
|
326
326
|
};
|
|
327
327
|
function isActiveAnnotation(annotation) {
|
|
328
328
|
return (snapshot) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.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 {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n if (!context.selection) {\n return false\n }\n\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","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(context.selection.focus, blockEndPoint)\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n context.selection.focus,\n blockStartPoint,\n )\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","getActiveListItem","selectedTextBlocks","map","filter","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectedSpans","selectedSpans","startPoint","endPoint","startBlockKey","endBlockKey","startSpanKey","endSpanKey","child","isActiveAnnotation","annotation","snapshot","some","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","includes","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","blockEndPoint","utils","getBlockEndPoint","isEqualSelectionPoints","isAtTheStartOfBlock","blockStartPoint","getBlockStartPoint"],"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,aAChBC,MAAAA,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,EAAAA,IACzCE;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AAA,oBAAoBb,QAAQ,GAAG;AAC3BV,YAAAA,gBAAgBD,iBAAiBW,QAAQ;AAG7CV,aAAAA,cAAc/B,SAAS,KACvB+B,cAAcL,MAAOhC,CAASA,SAAAA,KAAKV,KAAK2D,OAAOM,SAASO,SAAS,CAAC;AAAA,IAAA;AAItE,WAAOf,SAASjE,QAAQiF,iBAAiBR,SAASO,SAAS;AAAA,EAC7D;AACF;ACdO,SAASE,iBAAiBjC,UAA2C;AAClEgB,SAAAA,CAAAA,aACiBvB,kBAAkBuB,QAAQ,MAEvBhB;AAE9B;ACNO,SAASkC,cAAc9B,OAAwC;AAC5DY,SAAAA,CAAAA,aACcd,eAAec,QAAQ,MAEpBZ;AAE3B;ACJO,SAAS+B,kBAAkB3F,OAGN;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAACwE,qBAAqB;AAAA,MAAC1E;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGHqF,UAAAA,gBAAgBC,4BAAMC,iBAAiB9F,KAAK;AAElD,WAAO6F,4BAAME,uBAAuBxF,QAAQE,UAAUE,OAAOiF,aAAa;AAAA,EAC5E;AACF;ACbO,SAASI,oBAAoBhG,OAGR;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAACwE,qBAAqB;AAAA,MAAC1E;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGH0F,UAAAA,kBAAkBJ,4BAAMK,mBAAmBlG,KAAK;AAEtD,WAAO6F,4BAAME,uBACXxF,QAAQE,UAAUE,OAClBsF,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.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 PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\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 {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n if (!context.selection) {\n return false\n }\n\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","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(context.selection.focus, blockEndPoint)\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getSelectedSpans","context","selection","selectedSpans","startPoint","backward","focus","anchor","endPoint","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","value","child","children","isPortableTextSpan","push","node","length","getFocusBlock","key","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","span","getFocusSpan","focusChild","getFirstBlock","getLastBlock","getSelectedBlocks","selectedBlocks","startKey","endKey","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getActiveListItem","selectedTextBlocks","map","filter","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","isActiveAnnotation","annotation","snapshot","some","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","includes","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","blockEndPoint","utils","getBlockEndPoint","isEqualSelectionPoints","isAtTheStartOfBlock","blockStartPoint","getBlockStartPoint"],"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;ACXO,MAAME,mBAKTA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX,WAAO,CAAE;AAGLC,QAAAA,gBAGD,IAECC,aAAaH,QAAQC,UAAUG,WACjCJ,QAAQC,UAAUI,QAClBL,QAAQC,UAAUK,QAChBC,WAAWP,QAAQC,UAAUG,WAC/BJ,QAAQC,UAAUK,SAClBN,QAAQC,UAAUI,OAEhBG,gBAAgBC,MAAaN,aAAAA,WAAWO,KAAK,CAAC,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AAa;AACpB,QAAI,CAACA,QAAQC,aAAa,CAACyE,qBAAqB;AAAA,MAAC1E;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGH0F,UAAAA,kBAAkBJ,4BAAMK,mBAAmBlG,KAAK;AAEtD,WAAO6F,4BAAME,uBACXxF,QAAQC,UAAUI,OAClBqF,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { isPortableTextTextBlock } from "@sanity/types";
|
|
2
|
+
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getFocusBlock } from "./selector.is-at-the-start-of-block.js";
|
|
3
|
+
import { spanSelectionPointToBlockOffset, getTextBlockText } from "./util.is-empty-text-block.js";
|
|
4
|
+
import { getBlockTextBefore } from "./selector.get-text-before.js";
|
|
5
|
+
import { defineBehavior } from "./behavior.core.js";
|
|
6
|
+
function createMarkdownBehaviors(config) {
|
|
7
|
+
const automaticBlockquoteOnSpace = defineBehavior({
|
|
8
|
+
on: "insert.text",
|
|
9
|
+
guard: ({
|
|
10
|
+
context,
|
|
11
|
+
event
|
|
12
|
+
}) => {
|
|
13
|
+
if (event.text !== " ")
|
|
14
|
+
return !1;
|
|
15
|
+
const selectionCollapsed = isSelectionCollapsed({
|
|
16
|
+
context
|
|
17
|
+
}), focusTextBlock = getFocusTextBlock({
|
|
18
|
+
context
|
|
19
|
+
}), focusSpan = getFocusSpan({
|
|
20
|
+
context
|
|
21
|
+
});
|
|
22
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
23
|
+
return !1;
|
|
24
|
+
const blockOffset = spanSelectionPointToBlockOffset({
|
|
25
|
+
value: context.value,
|
|
26
|
+
selectionPoint: {
|
|
27
|
+
path: [{
|
|
28
|
+
_key: focusTextBlock.node._key
|
|
29
|
+
}, "children", {
|
|
30
|
+
_key: focusSpan.node._key
|
|
31
|
+
}],
|
|
32
|
+
offset: context.selection?.focus.offset ?? 0
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (!blockOffset)
|
|
36
|
+
return !1;
|
|
37
|
+
const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(context);
|
|
38
|
+
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
39
|
+
focusTextBlock,
|
|
40
|
+
style: blockquoteStyle
|
|
41
|
+
} : !1;
|
|
42
|
+
},
|
|
43
|
+
actions: [() => [{
|
|
44
|
+
type: "insert.text",
|
|
45
|
+
text: " "
|
|
46
|
+
}], (_, {
|
|
47
|
+
focusTextBlock,
|
|
48
|
+
style
|
|
49
|
+
}) => [{
|
|
50
|
+
type: "text block.unset",
|
|
51
|
+
props: ["listItem", "level"],
|
|
52
|
+
at: focusTextBlock.path
|
|
53
|
+
}, {
|
|
54
|
+
type: "text block.set",
|
|
55
|
+
style,
|
|
56
|
+
at: focusTextBlock.path
|
|
57
|
+
}, {
|
|
58
|
+
type: "delete.text",
|
|
59
|
+
anchor: {
|
|
60
|
+
path: focusTextBlock.path,
|
|
61
|
+
offset: 0
|
|
62
|
+
},
|
|
63
|
+
focus: {
|
|
64
|
+
path: focusTextBlock.path,
|
|
65
|
+
offset: 2
|
|
66
|
+
}
|
|
67
|
+
}]]
|
|
68
|
+
}), automaticHr = defineBehavior({
|
|
69
|
+
on: "insert.text",
|
|
70
|
+
guard: ({
|
|
71
|
+
context,
|
|
72
|
+
event
|
|
73
|
+
}) => {
|
|
74
|
+
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
75
|
+
if (hrCharacter === void 0)
|
|
76
|
+
return !1;
|
|
77
|
+
const hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusTextBlock({
|
|
78
|
+
context
|
|
79
|
+
}), selectionCollapsed = isSelectionCollapsed({
|
|
80
|
+
context
|
|
81
|
+
});
|
|
82
|
+
if (!hrObject || !focusBlock || !selectionCollapsed)
|
|
83
|
+
return !1;
|
|
84
|
+
const textBefore = getBlockTextBefore({
|
|
85
|
+
context
|
|
86
|
+
}), hrBlockOffsets = {
|
|
87
|
+
anchor: {
|
|
88
|
+
path: focusBlock.path,
|
|
89
|
+
offset: 0
|
|
90
|
+
},
|
|
91
|
+
focus: {
|
|
92
|
+
path: focusBlock.path,
|
|
93
|
+
offset: 3
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return textBefore === `${hrCharacter}${hrCharacter}` ? {
|
|
97
|
+
hrObject,
|
|
98
|
+
focusBlock,
|
|
99
|
+
hrCharacter,
|
|
100
|
+
hrBlockOffsets
|
|
101
|
+
} : !1;
|
|
102
|
+
},
|
|
103
|
+
actions: [(_, {
|
|
104
|
+
hrCharacter
|
|
105
|
+
}) => [{
|
|
106
|
+
type: "insert.text",
|
|
107
|
+
text: hrCharacter
|
|
108
|
+
}], (_, {
|
|
109
|
+
hrObject,
|
|
110
|
+
hrBlockOffsets
|
|
111
|
+
}) => [{
|
|
112
|
+
type: "insert.block object",
|
|
113
|
+
placement: "before",
|
|
114
|
+
blockObject: hrObject
|
|
115
|
+
}, {
|
|
116
|
+
type: "delete.text",
|
|
117
|
+
...hrBlockOffsets
|
|
118
|
+
}]]
|
|
119
|
+
}), automaticHrOnPaste = defineBehavior({
|
|
120
|
+
on: "paste",
|
|
121
|
+
guard: ({
|
|
122
|
+
context,
|
|
123
|
+
event
|
|
124
|
+
}) => {
|
|
125
|
+
const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusBlock({
|
|
126
|
+
context
|
|
127
|
+
});
|
|
128
|
+
return !hrCharacters || !hrObject || !focusBlock ? !1 : {
|
|
129
|
+
hrCharacters,
|
|
130
|
+
hrObject,
|
|
131
|
+
focusBlock
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
actions: [(_, {
|
|
135
|
+
hrCharacters
|
|
136
|
+
}) => [{
|
|
137
|
+
type: "insert.text",
|
|
138
|
+
text: hrCharacters
|
|
139
|
+
}], (_, {
|
|
140
|
+
hrObject,
|
|
141
|
+
focusBlock
|
|
142
|
+
}) => isPortableTextTextBlock(focusBlock.node) ? [{
|
|
143
|
+
type: "insert.text block",
|
|
144
|
+
textBlock: {
|
|
145
|
+
children: focusBlock.node.children
|
|
146
|
+
},
|
|
147
|
+
placement: "after"
|
|
148
|
+
}, {
|
|
149
|
+
type: "insert.block object",
|
|
150
|
+
blockObject: hrObject,
|
|
151
|
+
placement: "after"
|
|
152
|
+
}, {
|
|
153
|
+
type: "delete.block",
|
|
154
|
+
blockPath: focusBlock.path
|
|
155
|
+
}] : [{
|
|
156
|
+
type: "insert.block object",
|
|
157
|
+
blockObject: hrObject,
|
|
158
|
+
placement: "after"
|
|
159
|
+
}]]
|
|
160
|
+
}), automaticHeadingOnSpace = defineBehavior({
|
|
161
|
+
on: "insert.text",
|
|
162
|
+
guard: ({
|
|
163
|
+
context,
|
|
164
|
+
event
|
|
165
|
+
}) => {
|
|
166
|
+
if (event.text !== " ")
|
|
167
|
+
return !1;
|
|
168
|
+
const selectionCollapsed = isSelectionCollapsed({
|
|
169
|
+
context
|
|
170
|
+
}), focusTextBlock = getFocusTextBlock({
|
|
171
|
+
context
|
|
172
|
+
}), focusSpan = getFocusSpan({
|
|
173
|
+
context
|
|
174
|
+
});
|
|
175
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
176
|
+
return !1;
|
|
177
|
+
const blockOffset = spanSelectionPointToBlockOffset({
|
|
178
|
+
value: context.value,
|
|
179
|
+
selectionPoint: {
|
|
180
|
+
path: [{
|
|
181
|
+
_key: focusTextBlock.node._key
|
|
182
|
+
}, "children", {
|
|
183
|
+
_key: focusSpan.node._key
|
|
184
|
+
}],
|
|
185
|
+
offset: context.selection?.focus.offset ?? 0
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (!blockOffset)
|
|
189
|
+
return !1;
|
|
190
|
+
const blockText = getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
191
|
+
if (blockOffset.offset !== level)
|
|
192
|
+
return !1;
|
|
193
|
+
const style = level !== void 0 ? config.headingStyle?.({
|
|
194
|
+
schema: context.schema,
|
|
195
|
+
level
|
|
196
|
+
}) : void 0;
|
|
197
|
+
return level !== void 0 && style !== void 0 ? {
|
|
198
|
+
focusTextBlock,
|
|
199
|
+
style,
|
|
200
|
+
level
|
|
201
|
+
} : !1;
|
|
202
|
+
},
|
|
203
|
+
actions: [({
|
|
204
|
+
event
|
|
205
|
+
}) => [event], (_, {
|
|
206
|
+
focusTextBlock,
|
|
207
|
+
style,
|
|
208
|
+
level
|
|
209
|
+
}) => [{
|
|
210
|
+
type: "text block.unset",
|
|
211
|
+
props: ["listItem", "level"],
|
|
212
|
+
at: focusTextBlock.path
|
|
213
|
+
}, {
|
|
214
|
+
type: "text block.set",
|
|
215
|
+
style,
|
|
216
|
+
at: focusTextBlock.path
|
|
217
|
+
}, {
|
|
218
|
+
type: "delete.text",
|
|
219
|
+
anchor: {
|
|
220
|
+
path: focusTextBlock.path,
|
|
221
|
+
offset: 0
|
|
222
|
+
},
|
|
223
|
+
focus: {
|
|
224
|
+
path: focusTextBlock.path,
|
|
225
|
+
offset: level + 1
|
|
226
|
+
}
|
|
227
|
+
}]]
|
|
228
|
+
}), clearStyleOnBackspace = defineBehavior({
|
|
229
|
+
on: "delete.backward",
|
|
230
|
+
guard: ({
|
|
231
|
+
context
|
|
232
|
+
}) => {
|
|
233
|
+
const selectionCollapsed = isSelectionCollapsed({
|
|
234
|
+
context
|
|
235
|
+
}), focusTextBlock = getFocusTextBlock({
|
|
236
|
+
context
|
|
237
|
+
}), focusSpan = getFocusSpan({
|
|
238
|
+
context
|
|
239
|
+
});
|
|
240
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
241
|
+
return !1;
|
|
242
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection?.focus.offset === 0, defaultStyle = config.defaultStyle?.(context);
|
|
243
|
+
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
244
|
+
defaultStyle,
|
|
245
|
+
focusTextBlock
|
|
246
|
+
} : !1;
|
|
247
|
+
},
|
|
248
|
+
actions: [(_, {
|
|
249
|
+
defaultStyle,
|
|
250
|
+
focusTextBlock
|
|
251
|
+
}) => [{
|
|
252
|
+
type: "text block.set",
|
|
253
|
+
style: defaultStyle,
|
|
254
|
+
at: focusTextBlock.path
|
|
255
|
+
}]]
|
|
256
|
+
}), automaticListOnSpace = defineBehavior({
|
|
257
|
+
on: "insert.text",
|
|
258
|
+
guard: ({
|
|
259
|
+
context,
|
|
260
|
+
event
|
|
261
|
+
}) => {
|
|
262
|
+
if (event.text !== " ")
|
|
263
|
+
return !1;
|
|
264
|
+
const selectionCollapsed = isSelectionCollapsed({
|
|
265
|
+
context
|
|
266
|
+
}), focusTextBlock = getFocusTextBlock({
|
|
267
|
+
context
|
|
268
|
+
}), focusSpan = getFocusSpan({
|
|
269
|
+
context
|
|
270
|
+
});
|
|
271
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
272
|
+
return !1;
|
|
273
|
+
const blockOffset = spanSelectionPointToBlockOffset({
|
|
274
|
+
value: context.value,
|
|
275
|
+
selectionPoint: {
|
|
276
|
+
path: [{
|
|
277
|
+
_key: focusTextBlock.node._key
|
|
278
|
+
}, "children", {
|
|
279
|
+
_key: focusSpan.node._key
|
|
280
|
+
}],
|
|
281
|
+
offset: context.selection?.focus.offset ?? 0
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
if (!blockOffset)
|
|
285
|
+
return !1;
|
|
286
|
+
const blockText = getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
|
|
287
|
+
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
288
|
+
return {
|
|
289
|
+
focusTextBlock,
|
|
290
|
+
listItem: unorderedListStyle,
|
|
291
|
+
listItemLength: 1,
|
|
292
|
+
style: defaultStyle
|
|
293
|
+
};
|
|
294
|
+
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
295
|
+
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
296
|
+
focusTextBlock,
|
|
297
|
+
listItem: orderedListStyle,
|
|
298
|
+
listItemLength: 2,
|
|
299
|
+
style: defaultStyle
|
|
300
|
+
} : !1;
|
|
301
|
+
},
|
|
302
|
+
actions: [({
|
|
303
|
+
event
|
|
304
|
+
}) => [event], (_, {
|
|
305
|
+
focusTextBlock,
|
|
306
|
+
style,
|
|
307
|
+
listItem,
|
|
308
|
+
listItemLength
|
|
309
|
+
}) => [{
|
|
310
|
+
type: "text block.set",
|
|
311
|
+
listItem,
|
|
312
|
+
level: 1,
|
|
313
|
+
style,
|
|
314
|
+
at: focusTextBlock.path
|
|
315
|
+
}, {
|
|
316
|
+
type: "delete.text",
|
|
317
|
+
anchor: {
|
|
318
|
+
path: focusTextBlock.path,
|
|
319
|
+
offset: 0
|
|
320
|
+
},
|
|
321
|
+
focus: {
|
|
322
|
+
path: focusTextBlock.path,
|
|
323
|
+
offset: listItemLength + 1
|
|
324
|
+
}
|
|
325
|
+
}]]
|
|
326
|
+
});
|
|
327
|
+
return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, automaticHr, automaticHrOnPaste, clearStyleOnBackspace, automaticListOnSpace];
|
|
328
|
+
}
|
|
329
|
+
export {
|
|
330
|
+
createMarkdownBehaviors
|
|
331
|
+
};
|
|
332
|
+
//# sourceMappingURL=behavior.markdown.js.map
|