@portabletext/editor 1.23.0 → 1.25.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 +249 -62
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-selection-collapsed.cjs → selector.is-active-style.cjs} +158 -3
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +23 -9
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +225 -38
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/{selector.is-selection-collapsed.js → selector.is-active-style.js} +159 -4
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +23 -9
- package/lib/_chunks-es/util.slice-blocks.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 +2830 -139
- package/lib/behaviors/index.d.ts +2830 -139
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +695 -526
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +8950 -246
- package/lib/index.d.ts +8950 -246
- package/lib/index.js +696 -525
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +24 -171
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +73 -0
- package/lib/selectors/index.d.ts +73 -0
- package/lib/selectors/index.js +3 -151
- package/lib/selectors/index.js.map +1 -1
- package/package.json +11 -10
- package/src/behavior-actions/behavior.action.data-transfer-set.ts +7 -0
- package/src/behavior-actions/behavior.action.insert-blocks.ts +61 -0
- package/src/behavior-actions/behavior.actions.ts +159 -83
- 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.deserialize.ts +46 -0
- package/src/behaviors/behavior.core.lists.ts +57 -23
- package/src/behaviors/behavior.core.serialize.ts +44 -0
- package/src/behaviors/behavior.core.style.ts +19 -0
- package/src/behaviors/behavior.core.ts +19 -0
- package/src/behaviors/behavior.types.ts +126 -89
- package/src/converters/converter.json.ts +53 -0
- package/src/converters/converter.portable-text.deserialize.test.ts +686 -0
- package/src/converters/converter.portable-text.ts +59 -0
- package/src/converters/converter.text-html.deserialize.test.ts +349 -0
- package/src/converters/converter.text-html.serialize.test.ts +233 -0
- package/src/converters/converter.text-html.ts +61 -0
- package/src/converters/converter.text-plain.test.ts +241 -0
- package/src/converters/converter.text-plain.ts +91 -0
- package/src/converters/converter.ts +65 -0
- package/src/converters/converters.ts +11 -0
- package/src/editor/Editable.tsx +3 -13
- package/src/editor/create-editor.ts +48 -6
- package/src/editor/editor-machine.ts +56 -2
- package/src/editor/editor-selector.ts +1 -0
- package/src/editor/editor-snapshot.ts +5 -0
- package/src/editor/plugins/create-with-event-listeners.ts +82 -106
- package/src/internal-utils/asserters.ts +9 -0
- package/src/internal-utils/mime-type.ts +1 -0
- package/src/internal-utils/parse-blocks.ts +136 -0
- package/src/internal-utils/test-key-generator.ts +9 -0
- package/src/selectors/selector.get-selected-spans.test.ts +1 -0
- package/src/selectors/selector.get-selection-text.test.ts +1 -0
- package/src/selectors/selector.is-active-decorator.test.ts +1 -0
- package/src/utils/util.slice-blocks.test.ts +87 -0
- package/src/utils/util.slice-blocks.ts +27 -10
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +0 -181
- package/src/editor/plugins/createWithInsertData.ts +0 -425
|
@@ -209,11 +209,160 @@ const getFocusBlock = ({
|
|
|
209
209
|
}
|
|
210
210
|
if (foundSelectionEndBlock && nextBlock)
|
|
211
211
|
return nextBlock;
|
|
212
|
-
},
|
|
212
|
+
}, getActiveListItem = ({
|
|
213
213
|
context
|
|
214
|
-
}) =>
|
|
214
|
+
}) => {
|
|
215
|
+
if (!context.selection)
|
|
216
|
+
return;
|
|
217
|
+
const guards = createGuards(context), selectedTextBlocks = getSelectedBlocks({
|
|
218
|
+
context
|
|
219
|
+
}).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
|
|
220
|
+
if (!firstTextBlock)
|
|
221
|
+
return;
|
|
222
|
+
const firstListItem = firstTextBlock.listItem;
|
|
223
|
+
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
224
|
+
return firstListItem;
|
|
225
|
+
}, getActiveStyle = ({
|
|
226
|
+
context
|
|
227
|
+
}) => {
|
|
228
|
+
if (!context.selection)
|
|
229
|
+
return;
|
|
230
|
+
const guards = createGuards(context), selectedTextBlocks = getSelectedBlocks({
|
|
231
|
+
context
|
|
232
|
+
}).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
|
|
233
|
+
if (!firstTextBlock)
|
|
234
|
+
return;
|
|
235
|
+
const firstStyle = firstTextBlock.style;
|
|
236
|
+
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
237
|
+
return firstStyle;
|
|
238
|
+
}, getSelectedSpans = ({
|
|
239
|
+
context
|
|
240
|
+
}) => {
|
|
241
|
+
if (!context.selection)
|
|
242
|
+
return [];
|
|
243
|
+
const selectedSpans = [], startPoint = context.selection.backward ? context.selection.focus : context.selection.anchor, endPoint = context.selection.backward ? context.selection.anchor : context.selection.focus, startBlockKey = isKeySegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = isKeySegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0;
|
|
244
|
+
if (!startBlockKey || !endBlockKey)
|
|
245
|
+
return selectedSpans;
|
|
246
|
+
const startSpanKey = isKeySegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endSpanKey = isKeySegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
|
|
247
|
+
for (const block of context.value)
|
|
248
|
+
if (isPortableTextTextBlock(block)) {
|
|
249
|
+
if (block._key === startBlockKey) {
|
|
250
|
+
for (const child of block.children)
|
|
251
|
+
if (isPortableTextSpan(child)) {
|
|
252
|
+
if (startSpanKey && child._key === startSpanKey) {
|
|
253
|
+
if (selectedSpans.push({
|
|
254
|
+
node: child,
|
|
255
|
+
path: [{
|
|
256
|
+
_key: block._key
|
|
257
|
+
}, "children", {
|
|
258
|
+
_key: child._key
|
|
259
|
+
}]
|
|
260
|
+
}), startSpanKey === endSpanKey)
|
|
261
|
+
break;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (endSpanKey && child._key === endSpanKey) {
|
|
265
|
+
selectedSpans.push({
|
|
266
|
+
node: child,
|
|
267
|
+
path: [{
|
|
268
|
+
_key: block._key
|
|
269
|
+
}, "children", {
|
|
270
|
+
_key: child._key
|
|
271
|
+
}]
|
|
272
|
+
});
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
selectedSpans.length > 0 && selectedSpans.push({
|
|
276
|
+
node: child,
|
|
277
|
+
path: [{
|
|
278
|
+
_key: block._key
|
|
279
|
+
}, "children", {
|
|
280
|
+
_key: child._key
|
|
281
|
+
}]
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (startBlockKey === endBlockKey)
|
|
285
|
+
break;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (block._key === endBlockKey) {
|
|
289
|
+
for (const child of block.children)
|
|
290
|
+
if (isPortableTextSpan(child)) {
|
|
291
|
+
if (endSpanKey && child._key === endSpanKey) {
|
|
292
|
+
selectedSpans.push({
|
|
293
|
+
node: child,
|
|
294
|
+
path: [{
|
|
295
|
+
_key: block._key
|
|
296
|
+
}, "children", {
|
|
297
|
+
_key: child._key
|
|
298
|
+
}]
|
|
299
|
+
});
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
selectedSpans.push({
|
|
303
|
+
node: child,
|
|
304
|
+
path: [{
|
|
305
|
+
_key: block._key
|
|
306
|
+
}, "children", {
|
|
307
|
+
_key: child._key
|
|
308
|
+
}]
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
if (selectedSpans.length > 0)
|
|
314
|
+
for (const child of block.children)
|
|
315
|
+
isPortableTextSpan(child) && selectedSpans.push({
|
|
316
|
+
node: child,
|
|
317
|
+
path: [{
|
|
318
|
+
_key: block._key
|
|
319
|
+
}, "children", {
|
|
320
|
+
_key: child._key
|
|
321
|
+
}]
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return selectedSpans;
|
|
325
|
+
};
|
|
326
|
+
function isActiveAnnotation(annotation) {
|
|
327
|
+
return (snapshot) => {
|
|
328
|
+
if (!snapshot.context.selection)
|
|
329
|
+
return !1;
|
|
330
|
+
const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot);
|
|
331
|
+
if (selectedSpans.length === 0 || selectedSpans.some((span) => !span.node.marks || span.node.marks?.length === 0))
|
|
332
|
+
return !1;
|
|
333
|
+
const selectionMarkDefs = selectedBlocks.flatMap((block) => isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []);
|
|
334
|
+
return selectedSpans.every((span) => (span.node.marks?.flatMap((mark) => {
|
|
335
|
+
const markDef = selectionMarkDefs.find((markDef2) => markDef2._key === mark);
|
|
336
|
+
return markDef ? [markDef._type] : [];
|
|
337
|
+
}) ?? []).includes(annotation));
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
const isSelectionCollapsed = ({
|
|
341
|
+
context
|
|
342
|
+
}) => JSON.stringify(context.selection?.anchor.path) === JSON.stringify(context.selection?.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset, isSelectionExpanded = ({
|
|
343
|
+
context
|
|
344
|
+
}) => !isSelectionCollapsed({
|
|
345
|
+
context
|
|
346
|
+
});
|
|
347
|
+
function isActiveDecorator(decorator) {
|
|
348
|
+
return (snapshot) => {
|
|
349
|
+
if (isSelectionExpanded(snapshot)) {
|
|
350
|
+
const selectedSpans = getSelectedSpans(snapshot);
|
|
351
|
+
return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
|
|
352
|
+
}
|
|
353
|
+
return snapshot.context.activeDecorators.includes(decorator);
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function isActiveListItem(listItem) {
|
|
357
|
+
return (snapshot) => getActiveListItem(snapshot) === listItem;
|
|
358
|
+
}
|
|
359
|
+
function isActiveStyle(style) {
|
|
360
|
+
return (snapshot) => getActiveStyle(snapshot) === style;
|
|
361
|
+
}
|
|
215
362
|
export {
|
|
216
363
|
createGuards,
|
|
364
|
+
getActiveListItem,
|
|
365
|
+
getActiveStyle,
|
|
217
366
|
getFirstBlock,
|
|
218
367
|
getFocusBlock,
|
|
219
368
|
getFocusBlockObject,
|
|
@@ -225,8 +374,14 @@ export {
|
|
|
225
374
|
getNextBlock,
|
|
226
375
|
getPreviousBlock,
|
|
227
376
|
getSelectedBlocks,
|
|
377
|
+
getSelectedSpans,
|
|
228
378
|
getSelectionEndBlock,
|
|
229
379
|
getSelectionStartBlock,
|
|
230
|
-
|
|
380
|
+
isActiveAnnotation,
|
|
381
|
+
isActiveDecorator,
|
|
382
|
+
isActiveListItem,
|
|
383
|
+
isActiveStyle,
|
|
384
|
+
isSelectionCollapsed,
|
|
385
|
+
isSelectionExpanded
|
|
231
386
|
};
|
|
232
|
-
//# sourceMappingURL=selector.is-
|
|
387
|
+
//# sourceMappingURL=selector.is-active-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.is-active-style.js","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"],"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 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"],"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"],"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,M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ChC;AAEA,aAAOC,UAAU,CAACA,QAAQ7E,KAAK,IAAI,CAAE;AAAA,IACtC,CAAA,KAAK,CAEY8E,GAAAA,SAAST,UAAU,CACxC;AAAA,EACH;AACF;AC3CO,MAAMU,uBAAgDA,CAAC;AAAA,EAAC1E;AAAO,MAElE2E,KAAKC,UAAU5E,QAAQE,WAAW2B,OAAOxB,IAAI,MAC3CsE,KAAKC,UAAU5E,QAAQE,WAAWE,MAAMC,IAAI,KAC9CL,QAAQE,WAAW2B,OAAOgD,WAAW7E,QAAQE,WAAWE,MAAMyE,QCHrDC,sBAA+CA,CAAC;AAAA,EAAC9E;AAAO,MAC5D,CAAC0E,qBAAqB;AAAA,EAAC1E;AAAO,CAAC;ACAjC,SAAS+E,kBAAkBC,WAA4C;AAC5E,SAAQf,CAAa,aAAA;AACfa,QAAAA,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;"}
|
|
@@ -13,8 +13,16 @@ function sliceBlocks({
|
|
|
13
13
|
if (!startBlockKey || !endBlockKey)
|
|
14
14
|
return slice;
|
|
15
15
|
for (const block of blocks) {
|
|
16
|
+
if (!isPortableTextTextBlock(block) && block._key === startBlockKey && block._key === endBlockKey) {
|
|
17
|
+
startBlock = block;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
16
20
|
if (block._key === startBlockKey) {
|
|
17
|
-
if (isPortableTextTextBlock(block)
|
|
21
|
+
if (!isPortableTextTextBlock(block)) {
|
|
22
|
+
startBlock = block;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (startChildKey) {
|
|
18
26
|
for (const child of block.children) {
|
|
19
27
|
if (child._key === startChildKey) {
|
|
20
28
|
if (isPortableTextSpan(child)) {
|
|
@@ -26,14 +34,16 @@ function sliceBlocks({
|
|
|
26
34
|
text
|
|
27
35
|
}]
|
|
28
36
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
} else
|
|
38
|
+
startBlock = {
|
|
39
|
+
...block,
|
|
40
|
+
children: [child]
|
|
41
|
+
};
|
|
42
|
+
if (startChildKey === endChildKey)
|
|
43
|
+
break;
|
|
44
|
+
continue;
|
|
35
45
|
}
|
|
36
|
-
if (
|
|
46
|
+
if (startBlock && isPortableTextTextBlock(startBlock) && (startBlock.children.push(child), block._key === endBlockKey && endChildKey && child._key === endChildKey))
|
|
37
47
|
break;
|
|
38
48
|
}
|
|
39
49
|
if (startBlockKey === endBlockKey)
|
|
@@ -44,7 +54,11 @@ function sliceBlocks({
|
|
|
44
54
|
break;
|
|
45
55
|
}
|
|
46
56
|
if (block._key === endBlockKey) {
|
|
47
|
-
if (isPortableTextTextBlock(block)
|
|
57
|
+
if (!isPortableTextTextBlock(block)) {
|
|
58
|
+
endBlock = block;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (endChildKey) {
|
|
48
62
|
endBlock = {
|
|
49
63
|
...block,
|
|
50
64
|
children: []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.slice-blocks.js","sources":["../../src/utils/util.slice-blocks.ts"],"sourcesContent":["import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelection} from '../selectors'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n blocks,\n selection,\n}: {\n blocks: Array<PortableTextBlock>\n selection: EditorSelection\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = selection.backward ? selection.focus : selection.anchor\n const endPoint = selection.backward ? selection.anchor : 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 const startChildKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endChildKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (block._key === startBlockKey) {\n if (isPortableTextTextBlock(block)
|
|
1
|
+
{"version":3,"file":"util.slice-blocks.js","sources":["../../src/utils/util.slice-blocks.ts"],"sourcesContent":["import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelection} from '../selectors'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n blocks,\n selection,\n}: {\n blocks: Array<PortableTextBlock>\n selection: EditorSelection\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = selection.backward ? selection.focus : selection.anchor\n const endPoint = selection.backward ? selection.anchor : 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 const startChildKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endChildKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isPortableTextTextBlock(block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isPortableTextTextBlock(block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isPortableTextSpan(child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isPortableTextTextBlock(startBlock)) {\n startBlock.children.push(child)\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isPortableTextTextBlock(block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isPortableTextTextBlock(endBlock)) {\n if (child._key === endChildKey && isPortableTextSpan(child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(block)\n }\n }\n\n return [\n ...(startBlock ? [startBlock] : []),\n ...middleBlocks,\n ...(endBlock ? [endBlock] : []),\n ]\n}\n"],"names":["sliceBlocks","blocks","selection","slice","startBlock","middleBlocks","endBlock","startPoint","backward","focus","anchor","endPoint","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startChildKey","endChildKey","block","isPortableTextTextBlock","child","children","isPortableTextSpan","text","offset","push"],"mappings":";AAWO,SAASA,YAAY;AAAA,EAC1BC;AAAAA,EACAC;AAIF,GAA6B;AAC3B,QAAMC,QAAkC,CAAE;AAE1C,MAAI,CAACD;AACIC,WAAAA;AAGLC,MAAAA;AACJ,QAAMC,eAAoC,CAAE;AACxCC,MAAAA;AAEJ,QAAMC,aAAaL,UAAUM,WAAWN,UAAUO,QAAQP,UAAUQ,QAC9DC,WAAWT,UAAUM,WAAWN,UAAUQ,SAASR,UAAUO,OAE7DG,gBAAgBC,aAAaN,WAAWO,KAAK,CAAC,CAAC,IACjDP,WAAWO,KAAK,CAAC,EAAEC,OACnBC,QACEC,cAAcJ,aAAaF,SAASG,KAAK,CAAC,CAAC,IAC7CH,SAASG,KAAK,CAAC,EAAEC,OACjBC,QACEE,gBAAgBL,aAAaN,WAAWO,KAAK,CAAC,CAAC,IACjDP,WAAWO,KAAK,CAAC,EAAEC,OACnBC,QACEG,cAAcN,aAAaF,SAASG,KAAK,CAAC,CAAC,IAC7CH,SAASG,KAAK,CAAC,EAAEC,OACjBC;AAEA,MAAA,CAACJ,iBAAiB,CAACK;AACdd,WAAAA;AAGT,aAAWiB,SAASnB,QAAQ;AACtB,QAAA,CAACoB,wBAAwBD,KAAK,KAC5BA,MAAML,SAASH,iBAAiBQ,MAAML,SAASE,aAAa;AACjDG,mBAAAA;AACb;AAAA,IAAA;AAIAA,QAAAA,MAAML,SAASH,eAAe;AAC5B,UAAA,CAACS,wBAAwBD,KAAK,GAAG;AACtBA,qBAAAA;AACb;AAAA,MAAA;AAGF,UAAIF,eAAe;AACNI,mBAAAA,SAASF,MAAMG,UAAU;AAC9BD,cAAAA,MAAMP,SAASG,eAAe;AAC5BM,gBAAAA,mBAAmBF,KAAK,GAAG;AAC7B,oBAAMG,OACJH,MAAMP,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C,aAAasB,KAAKP,KAAK;AAAA,EAAA;AAI3B,SAAO,CACL,GAAIhB,aAAa,CAACA,UAAU,IAAI,CAAA,GAChC,GAAGC,cACH,GAAIC,WAAW,CAACA,QAAQ,IAAI,CAAA,CAAG;AAEnC;"}
|
package/lib/behaviors/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var behavior_core = require("../_chunks-cjs/behavior.core.cjs"),
|
|
3
|
+
var behavior_core = require("../_chunks-cjs/behavior.core.cjs"), selector_isActiveStyle = require("../_chunks-cjs/selector.is-active-style.cjs"), xstate = require("xstate"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), types = require("@sanity/types"), util_isEmptyTextBlock = require("../_chunks-cjs/util.is-empty-text-block.cjs");
|
|
4
4
|
function createCodeEditorBehaviors(config) {
|
|
5
5
|
return [behavior_core.defineBehavior({
|
|
6
6
|
on: "key.down",
|
|
@@ -8,9 +8,9 @@ function createCodeEditorBehaviors(config) {
|
|
|
8
8
|
context,
|
|
9
9
|
event
|
|
10
10
|
}) => {
|
|
11
|
-
const isMoveUpShortcut = behavior_core.isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock =
|
|
11
|
+
const isMoveUpShortcut = behavior_core.isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock = selector_isActiveStyle.getFirstBlock({
|
|
12
12
|
context
|
|
13
|
-
}), selectedBlocks =
|
|
13
|
+
}), selectedBlocks = selector_isActiveStyle.getSelectedBlocks({
|
|
14
14
|
context
|
|
15
15
|
}), blocksAbove = firstBlock?.node._key !== selectedBlocks[0]?.node._key;
|
|
16
16
|
return !isMoveUpShortcut || !blocksAbove ? !1 : {
|
|
@@ -29,9 +29,9 @@ function createCodeEditorBehaviors(config) {
|
|
|
29
29
|
context,
|
|
30
30
|
event
|
|
31
31
|
}) => {
|
|
32
|
-
const isMoveDownShortcut = behavior_core.isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock =
|
|
32
|
+
const isMoveDownShortcut = behavior_core.isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock = selector_isActiveStyle.getLastBlock({
|
|
33
33
|
context
|
|
34
|
-
}), selectedBlocks =
|
|
34
|
+
}), selectedBlocks = selector_isActiveStyle.getSelectedBlocks({
|
|
35
35
|
context
|
|
36
36
|
}), blocksBelow = lastBlock?.node._key !== selectedBlocks[selectedBlocks.length - 1]?.node._key;
|
|
37
37
|
return !isMoveDownShortcut || !blocksBelow ? !1 : {
|
|
@@ -67,7 +67,7 @@ function createEmojiPickerBehaviors(config) {
|
|
|
67
67
|
return {
|
|
68
68
|
emojis: []
|
|
69
69
|
};
|
|
70
|
-
const focusBlock =
|
|
70
|
+
const focusBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
71
71
|
context
|
|
72
72
|
}), emojiKeyword = `${selector_getTextBefore.getBlockTextBefore({
|
|
73
73
|
context
|
|
@@ -99,7 +99,7 @@ function createEmojiPickerBehaviors(config) {
|
|
|
99
99
|
return !1;
|
|
100
100
|
const matches = emojiPickerActor.getSnapshot().context.matches, selectedIndex = emojiPickerActor.getSnapshot().context.selectedIndex, emoji = matches[selectedIndex] ? config.parseMatch({
|
|
101
101
|
match: matches[selectedIndex]
|
|
102
|
-
}) : void 0, focusBlock =
|
|
102
|
+
}) : void 0, focusBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
103
103
|
context
|
|
104
104
|
}), textBefore = selector_getTextBefore.getBlockTextBefore({
|
|
105
105
|
context
|
|
@@ -158,7 +158,7 @@ function createEmojiPickerBehaviors(config) {
|
|
|
158
158
|
}) : void 0;
|
|
159
159
|
if (!emoji)
|
|
160
160
|
return !1;
|
|
161
|
-
const focusBlock =
|
|
161
|
+
const focusBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
162
162
|
context
|
|
163
163
|
}), textBefore = selector_getTextBefore.getBlockTextBefore({
|
|
164
164
|
context
|
|
@@ -245,7 +245,7 @@ function createEmojiPickerBehaviors(config) {
|
|
|
245
245
|
}) => {
|
|
246
246
|
if (event.unit !== "character" || emojiPickerActor.getSnapshot().context.matches.length === 0)
|
|
247
247
|
return !1;
|
|
248
|
-
const focusBlock =
|
|
248
|
+
const focusBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
249
249
|
context
|
|
250
250
|
}), textBefore = selector_getTextBefore.getBlockTextBefore({
|
|
251
251
|
context
|
|
@@ -367,7 +367,7 @@ function createLinkBehaviors(config) {
|
|
|
367
367
|
context,
|
|
368
368
|
event
|
|
369
369
|
}) => {
|
|
370
|
-
const selectionCollapsed =
|
|
370
|
+
const selectionCollapsed = selector_isActiveStyle.isSelectionCollapsed({
|
|
371
371
|
context
|
|
372
372
|
}), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
373
373
|
url,
|
|
@@ -389,9 +389,9 @@ function createLinkBehaviors(config) {
|
|
|
389
389
|
context,
|
|
390
390
|
event
|
|
391
391
|
}) => {
|
|
392
|
-
const focusSpan =
|
|
392
|
+
const focusSpan = selector_isActiveStyle.getFocusSpan({
|
|
393
393
|
context
|
|
394
|
-
}), selectionCollapsed =
|
|
394
|
+
}), selectionCollapsed = selector_isActiveStyle.isSelectionCollapsed({
|
|
395
395
|
context
|
|
396
396
|
});
|
|
397
397
|
if (!focusSpan || !selectionCollapsed)
|
|
@@ -426,11 +426,11 @@ function createMarkdownBehaviors(config) {
|
|
|
426
426
|
}) => {
|
|
427
427
|
if (event.text !== " ")
|
|
428
428
|
return !1;
|
|
429
|
-
const selectionCollapsed =
|
|
429
|
+
const selectionCollapsed = selector_isActiveStyle.isSelectionCollapsed({
|
|
430
430
|
context
|
|
431
|
-
}), focusTextBlock =
|
|
431
|
+
}), focusTextBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
432
432
|
context
|
|
433
|
-
}), focusSpan =
|
|
433
|
+
}), focusSpan = selector_isActiveStyle.getFocusSpan({
|
|
434
434
|
context
|
|
435
435
|
});
|
|
436
436
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
@@ -488,9 +488,9 @@ function createMarkdownBehaviors(config) {
|
|
|
488
488
|
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
489
489
|
if (hrCharacter === void 0)
|
|
490
490
|
return !1;
|
|
491
|
-
const hrObject = config.horizontalRuleObject?.(context), focusBlock =
|
|
491
|
+
const hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
492
492
|
context
|
|
493
|
-
}), selectionCollapsed =
|
|
493
|
+
}), selectionCollapsed = selector_isActiveStyle.isSelectionCollapsed({
|
|
494
494
|
context
|
|
495
495
|
});
|
|
496
496
|
if (!hrObject || !focusBlock || !selectionCollapsed)
|
|
@@ -536,7 +536,7 @@ function createMarkdownBehaviors(config) {
|
|
|
536
536
|
context,
|
|
537
537
|
event
|
|
538
538
|
}) => {
|
|
539
|
-
const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock =
|
|
539
|
+
const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_isActiveStyle.getFocusBlock({
|
|
540
540
|
context
|
|
541
541
|
});
|
|
542
542
|
return !hrCharacters || !hrObject || !focusBlock ? !1 : {
|
|
@@ -579,11 +579,11 @@ function createMarkdownBehaviors(config) {
|
|
|
579
579
|
}) => {
|
|
580
580
|
if (event.text !== " ")
|
|
581
581
|
return !1;
|
|
582
|
-
const selectionCollapsed =
|
|
582
|
+
const selectionCollapsed = selector_isActiveStyle.isSelectionCollapsed({
|
|
583
583
|
context
|
|
584
|
-
}), focusTextBlock =
|
|
584
|
+
}), focusTextBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
585
585
|
context
|
|
586
|
-
}), focusSpan =
|
|
586
|
+
}), focusSpan = selector_isActiveStyle.getFocusSpan({
|
|
587
587
|
context
|
|
588
588
|
});
|
|
589
589
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
@@ -644,11 +644,11 @@ function createMarkdownBehaviors(config) {
|
|
|
644
644
|
guard: ({
|
|
645
645
|
context
|
|
646
646
|
}) => {
|
|
647
|
-
const selectionCollapsed =
|
|
647
|
+
const selectionCollapsed = selector_isActiveStyle.isSelectionCollapsed({
|
|
648
648
|
context
|
|
649
|
-
}), focusTextBlock =
|
|
649
|
+
}), focusTextBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
650
650
|
context
|
|
651
|
-
}), focusSpan =
|
|
651
|
+
}), focusSpan = selector_isActiveStyle.getFocusSpan({
|
|
652
652
|
context
|
|
653
653
|
});
|
|
654
654
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
@@ -675,11 +675,11 @@ function createMarkdownBehaviors(config) {
|
|
|
675
675
|
}) => {
|
|
676
676
|
if (event.text !== " ")
|
|
677
677
|
return !1;
|
|
678
|
-
const selectionCollapsed =
|
|
678
|
+
const selectionCollapsed = selector_isActiveStyle.isSelectionCollapsed({
|
|
679
679
|
context
|
|
680
|
-
}), focusTextBlock =
|
|
680
|
+
}), focusTextBlock = selector_isActiveStyle.getFocusTextBlock({
|
|
681
681
|
context
|
|
682
|
-
}), focusSpan =
|
|
682
|
+
}), focusSpan = selector_isActiveStyle.getFocusSpan({
|
|
683
683
|
context
|
|
684
684
|
});
|
|
685
685
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|