@portabletext/editor 2.13.3 → 2.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/{selector.is-selection-expanded.cjs → selector.get-selection-text.cjs} +25 -25
- package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +4 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-selecting-entire-blocks.cjs → selector.is-active-style.cjs} +408 -399
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +3 -3
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.slice-blocks.cjs → util.get-text-block-text.cjs} +25 -26
- package/lib/_chunks-cjs/util.get-text-block-text.cjs.map +1 -0
- package/lib/_chunks-cjs/{util.is-selection-collapsed.cjs → util.is-empty-text-block.cjs} +9 -9
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-text-block.cjs +5 -5
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +270 -270
- package/lib/_chunks-dts/behavior.types.action.d.ts +315 -315
- package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-selection-text.js} +20 -20
- package/lib/_chunks-es/selector.get-selection-text.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +2 -2
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/{selector.is-selecting-entire-blocks.js → selector.is-active-style.js} +385 -376
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/{util.slice-blocks.js → util.get-text-block-text.js} +25 -26
- package/lib/_chunks-es/util.get-text-block-text.js.map +1 -0
- package/lib/_chunks-es/{util.is-selection-collapsed.js → util.is-empty-text-block.js} +8 -8
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-text-block.js +1 -1
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/index.cjs +225 -225
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +18 -18
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +21 -21
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +4 -4
- package/lib/plugins/index.d.ts +4 -4
- package/lib/plugins/index.js +3 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +52 -52
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +5 -5
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +14 -14
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2 -2
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +3 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +12 -12
- package/src/behaviors/behavior.abstract.annotation.ts +3 -3
- package/src/behaviors/behavior.abstract.decorator.ts +2 -2
- package/src/behaviors/behavior.abstract.delete.ts +25 -16
- package/src/behaviors/behavior.abstract.deserialize.ts +4 -3
- package/src/behaviors/behavior.abstract.insert.ts +6 -7
- package/src/behaviors/behavior.abstract.keyboard.ts +7 -8
- package/src/behaviors/behavior.abstract.list-item.ts +2 -1
- package/src/behaviors/behavior.abstract.move.ts +2 -1
- package/src/behaviors/behavior.abstract.select.ts +4 -2
- package/src/behaviors/behavior.abstract.split.ts +33 -24
- package/src/behaviors/behavior.abstract.style.ts +2 -1
- package/src/behaviors/behavior.abstract.ts +8 -7
- package/src/behaviors/behavior.core.annotations.ts +8 -7
- package/src/behaviors/behavior.core.block-element.ts +7 -5
- package/src/behaviors/behavior.core.block-objects.ts +25 -27
- package/src/behaviors/behavior.core.dnd.ts +10 -8
- package/src/behaviors/behavior.core.insert-break.ts +45 -36
- package/src/behaviors/behavior.core.lists.ts +31 -25
- package/src/behaviors/behavior.decorator-pair.ts +26 -23
- package/src/behaviors/behavior.markdown.ts +26 -21
- package/src/converters/converter.portable-text.ts +3 -3
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/converters/converter.text-html.ts +3 -3
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +3 -3
- package/src/editor/Editable.tsx +2 -2
- package/src/editor/components/render-span.tsx +3 -5
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/create-slate-editor.tsx +1 -4
- package/src/editor/editor-dom.ts +2 -2
- package/src/editor/plugins/createWithEditableAPI.ts +5 -10
- package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
- package/src/editor/plugins/createWithObjectKeys.ts +2 -2
- package/src/editor/plugins/createWithPatches.ts +3 -10
- package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
- package/src/editor/plugins/createWithUndoRedo.ts +6 -6
- package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
- package/src/editor/sync-machine.ts +2 -5
- package/src/{internal-utils → editor}/weakMaps.ts +1 -1
- package/src/editor/with-undo-step.ts +1 -1
- package/src/index.ts +1 -1
- package/src/internal-utils/applyPatch.ts +2 -2
- package/src/internal-utils/build-index-maps.test.ts +1 -1
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/internal-utils/event-position.ts +11 -9
- package/src/internal-utils/operation-to-patches.test.ts +1 -1
- package/src/internal-utils/portable-text-node.ts +1 -1
- package/src/internal-utils/selection-block-keys.ts +1 -1
- package/src/internal-utils/selection-focus-text.ts +1 -1
- package/src/internal-utils/to-slate-range.ts +4 -4
- package/src/operations/behavior.operation.annotation.add.ts +1 -1
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +2 -2
- package/src/operations/behavior.operation.decorator.add.ts +11 -9
- package/src/operations/behavior.operation.delete.ts +1 -1
- package/src/operations/behavior.operation.insert.block.ts +2 -2
- package/src/operations/behavior.operation.insert.child.ts +1 -1
- package/src/operations/behavior.operation.move.block.ts +1 -1
- package/src/plugins/plugin.behavior.tsx +1 -1
- package/src/plugins/plugin.decorator-shortcut.ts +3 -3
- package/src/plugins/plugin.internal.auto-close-brackets.ts +2 -1
- package/src/plugins/plugin.one-line.tsx +11 -11
- package/src/priority/priority.types.ts +1 -1
- package/src/{internal-utils → selectors}/drag-selection.test.ts +1 -1
- package/src/{internal-utils → selectors}/drag-selection.ts +26 -19
- package/src/selectors/selector.get-anchor-block.ts +1 -1
- package/src/selectors/selector.get-anchor-child.ts +1 -1
- package/src/selectors/selector.get-block-offsets.ts +3 -3
- package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
- package/src/selectors/selector.get-focus-block.ts +1 -1
- package/src/selectors/selector.get-focus-child.ts +1 -1
- package/src/selectors/selector.get-focus-list-block.ts +1 -1
- package/src/selectors/selector.get-list-state.test.ts +1 -1
- package/src/selectors/selector.get-mark-state.ts +1 -1
- package/src/selectors/selector.get-next-inline-object.ts +1 -1
- package/src/selectors/selector.get-next-span.ts +1 -1
- package/src/selectors/selector.get-previous-inline-object.ts +1 -1
- package/src/selectors/selector.get-previous-span.ts +1 -1
- package/src/selectors/selector.get-selected-blocks.ts +1 -1
- package/src/selectors/selector.get-selected-spans.test.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +2 -2
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -2
- package/src/selectors/selector.get-selected-value.test.ts +87 -1
- package/src/selectors/selector.get-selected-value.ts +4 -6
- package/src/selectors/selector.get-selection-end-point.ts +1 -1
- package/src/selectors/selector.get-selection-start-point.ts +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +1 -1
- package/src/selectors/selector.get-selection.ts +1 -1
- package/src/selectors/selector.get-text-before.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.ts +5 -7
- package/src/selectors/selector.is-active-decorator.test.ts +2 -1
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -3
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -3
- package/src/selectors/selector.is-overlapping-selection.test.ts +1 -1
- package/src/selectors/selector.is-overlapping-selection.ts +1 -1
- package/src/selectors/selector.is-point-after-selection.ts +3 -3
- package/src/selectors/selector.is-point-before-selection.ts +3 -3
- package/src/selectors/selector.is-selecting-entire-blocks.ts +7 -5
- package/src/test/gherkin-parameter-types.ts +1 -1
- package/src/test/vitest/step-definitions.tsx +19 -9
- package/src/types/paths.ts +4 -1
- package/src/utils/util.at-the-beginning-of-block.ts +1 -1
- package/src/utils/util.block-offset.ts +4 -4
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +3 -3
- package/src/utils/util.get-selection-end-point.ts +1 -1
- package/src/utils/util.get-selection-start-point.ts +1 -1
- package/src/utils/util.merge-text-blocks.ts +2 -2
- package/src/utils/util.selection-point-to-block-offset.ts +1 -1
- package/src/{selection/selection-point.ts → utils/util.selection-point.ts} +1 -1
- package/src/utils/util.slice-blocks.ts +6 -6
- package/src/utils/util.slice-text-block.test.ts +3 -1
- package/src/utils/util.slice-text-block.ts +3 -3
- package/src/utils/util.split-text-block.ts +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- /package/src/{internal-utils → editor}/withChanges.ts +0 -0
- /package/src/{internal-utils → editor}/withUndoRedo.ts +0 -0
- /package/src/{internal-utils → editor}/withoutPatching.ts +0 -0
- /package/src/{internal-utils → utils}/asserters.ts +0 -0
- /package/src/{editor → utils}/key-generator.ts +0 -0
- /package/src/{internal-utils → utils}/parse-blocks.test.ts +0 -0
- /package/src/{internal-utils → utils}/parse-blocks.ts +0 -0
package/lib/_chunks-cjs/{selector.is-selection-expanded.cjs → selector.get-selection-text.cjs}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var schema = require("@portabletext/schema"),
|
|
2
|
+
var schema = require("@portabletext/schema"), util_getTextBlockText = require("./util.get-text-block-text.cjs"), types = require("@sanity/types");
|
|
3
3
|
const getFocusBlock = (snapshot) => {
|
|
4
4
|
if (!snapshot.context.selection)
|
|
5
5
|
return;
|
|
6
|
-
const key =
|
|
6
|
+
const key = util_getTextBlockText.getBlockKeyFromSelectionPoint(snapshot.context.selection.focus), index = key ? snapshot.blockIndexMap.get(key) : void 0, node = index !== void 0 ? snapshot.context.value.at(index) : void 0;
|
|
7
7
|
return node && key ? {
|
|
8
8
|
node,
|
|
9
9
|
path: [{
|
|
@@ -22,7 +22,7 @@ const getFocusBlock = (snapshot) => {
|
|
|
22
22
|
const focusBlock = getFocusTextBlock(snapshot);
|
|
23
23
|
if (!focusBlock)
|
|
24
24
|
return;
|
|
25
|
-
const key =
|
|
25
|
+
const key = util_getTextBlockText.getChildKeyFromSelectionPoint(snapshot.context.selection.focus), node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
26
26
|
return node && key ? {
|
|
27
27
|
node,
|
|
28
28
|
path: [...focusBlock.path, "children", {
|
|
@@ -38,44 +38,44 @@ const getFocusBlock = (snapshot) => {
|
|
|
38
38
|
}, getSelectionStartPoint = (snapshot) => {
|
|
39
39
|
if (snapshot.context.selection)
|
|
40
40
|
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
41
|
-
},
|
|
42
|
-
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
43
|
-
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
44
|
-
return;
|
|
45
|
-
let inlineObject;
|
|
46
|
-
for (const child of focusTextBlock.node.children) {
|
|
47
|
-
if (child._key === selectionStartPointChildKey)
|
|
48
|
-
break;
|
|
49
|
-
schema.isSpan(snapshot.context, child) || (inlineObject = {
|
|
50
|
-
node: child,
|
|
51
|
-
path: [...focusTextBlock.path, "children", {
|
|
52
|
-
_key: child._key
|
|
53
|
-
}]
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return inlineObject;
|
|
57
|
-
}, getSelectedValue = (snapshot) => {
|
|
41
|
+
}, isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getSelectedValue = (snapshot) => {
|
|
58
42
|
const selection = snapshot.context.selection;
|
|
59
43
|
if (!selection)
|
|
60
44
|
return [];
|
|
61
|
-
const startPoint =
|
|
45
|
+
const startPoint = util_getTextBlockText.getSelectionStartPoint(selection), endPoint = util_getTextBlockText.getSelectionEndPoint(selection), startBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_getTextBlockText.getBlockKeyFromSelectionPoint(endPoint);
|
|
62
46
|
if (!startBlockKey || !endBlockKey)
|
|
63
47
|
return [];
|
|
64
48
|
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
65
49
|
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
66
50
|
return [];
|
|
67
|
-
const startBlock = snapshot.context.value.at(startBlockIndex), slicedStartBlock = startBlock ?
|
|
51
|
+
const startBlock = snapshot.context.value.at(startBlockIndex), slicedStartBlock = startBlock ? util_getTextBlockText.sliceBlocks({
|
|
68
52
|
context: snapshot.context,
|
|
69
53
|
blocks: [startBlock]
|
|
70
54
|
}).at(0) : void 0;
|
|
71
55
|
if (startBlockIndex === endBlockIndex)
|
|
72
56
|
return slicedStartBlock ? [slicedStartBlock] : [];
|
|
73
|
-
const endBlock = snapshot.context.value.at(endBlockIndex), slicedEndBlock = endBlock ?
|
|
57
|
+
const endBlock = snapshot.context.value.at(endBlockIndex), slicedEndBlock = endBlock ? util_getTextBlockText.sliceBlocks({
|
|
74
58
|
context: snapshot.context,
|
|
75
59
|
blocks: [endBlock]
|
|
76
60
|
}).at(0) : void 0, middleBlocks = snapshot.context.value.slice(startBlockIndex + 1, endBlockIndex);
|
|
77
61
|
return [...slicedStartBlock ? [slicedStartBlock] : [], ...middleBlocks, ...slicedEndBlock ? [slicedEndBlock] : []];
|
|
78
|
-
},
|
|
62
|
+
}, getPreviousInlineObject = (snapshot) => {
|
|
63
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
64
|
+
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
65
|
+
return;
|
|
66
|
+
let inlineObject;
|
|
67
|
+
for (const child of focusTextBlock.node.children) {
|
|
68
|
+
if (child._key === selectionStartPointChildKey)
|
|
69
|
+
break;
|
|
70
|
+
schema.isSpan(snapshot.context, child) || (inlineObject = {
|
|
71
|
+
node: child,
|
|
72
|
+
path: [...focusTextBlock.path, "children", {
|
|
73
|
+
_key: child._key
|
|
74
|
+
}]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return inlineObject;
|
|
78
|
+
}, getSelectionText = (snapshot) => getSelectedValue(snapshot).reduce((text, block) => schema.isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => schema.isSpan(snapshot.context, child) ? text2 + child.text : text2, "") : text, "");
|
|
79
79
|
exports.getFocusBlock = getFocusBlock;
|
|
80
80
|
exports.getFocusChild = getFocusChild;
|
|
81
81
|
exports.getFocusSpan = getFocusSpan;
|
|
@@ -86,4 +86,4 @@ exports.getSelectionStartPoint = getSelectionStartPoint;
|
|
|
86
86
|
exports.getSelectionText = getSelectionText;
|
|
87
87
|
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
88
88
|
exports.isSelectionExpanded = isSelectionExpanded;
|
|
89
|
-
//# sourceMappingURL=selector.
|
|
89
|
+
//# sourceMappingURL=selector.get-selection-text.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.get-selection-text.cjs","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selection-text.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {sliceBlocks} from '../utils/util.slice-blocks'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return []\n }\n\n const startBlock = snapshot.context.value.at(startBlockIndex)\n const slicedStartBlock = startBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [startBlock],\n }).at(0)\n : undefined\n\n if (startBlockIndex === endBlockIndex) {\n return slicedStartBlock ? [slicedStartBlock] : []\n }\n\n const endBlock = snapshot.context.value.at(endBlockIndex)\n const slicedEndBlock = endBlock\n ? sliceBlocks({\n context: snapshot.context,\n blocks: [endBlock],\n }).at(0)\n : undefined\n\n const middleBlocks = snapshot.context.value.slice(\n startBlockIndex + 1,\n endBlockIndex,\n )\n\n return [\n ...(slicedStartBlock ? [slicedStartBlock] : []),\n ...middleBlocks,\n ...(slicedEndBlock ? [slicedEndBlock] : []),\n ]\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","startBlock","slicedStartBlock","sliceBlocks","blocks","endBlock","slicedEndBlock","middleBlocks","slice","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectionText","reduce","text","block"],"mappings":";;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,sBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,KAAK,GACpEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAEhDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAAC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AmB,CAACA,gBAAgB,IAAI,CAAA,GAC5C,GAAGK,cACH,GAAID,iBAAiB,CAACA,cAAc,IAAI,CAAA,CAAG;AAE/C,GCvDaG,0BAMRlD,CAAAA,aAAa;AAChB,QAAMmD,iBAAiBpC,kBAAkBf,QAAQ,GAC3CoD,sBAAsB1B,uBAAuB1B,QAAQ,GACrDqD,8BACJD,uBAAuBE,MAAAA,aAAaF,oBAAoBvC,KAAK,CAAC,CAAC,IAC3DuC,oBAAoBvC,KAAK,CAAC,EAAEC,OAC5BL;AAEN,MAAI,CAAC0C,kBAAkB,CAACE;AACtB;AAGF,MAAIE;AAOJ,aAAWC,SAASL,eAAezC,KAAKU,UAAU;AAChD,QAAIoC,MAAM1C,SAASuC;AACjB;AAGG5B,WAAAA,OAAOzB,SAASC,SAASuD,KAAK,MACjCD,eAAe;AAAA,MACb7C,MAAM8C;AAAAA,MACN3C,MAAM,CAAC,GAAGsC,eAAetC,MAAM,YAAY;AAAA,QAACC,MAAM0C,MAAM1C;AAAAA,MAAAA,CAAK;AAAA,IAAA;AAAA,EAGnE;AAEA,SAAOyC;AACT,GC1CaE,mBAA4CzD,CAAAA,aACjCkC,iBAAiBlC,QAAQ,EAE1B0D,OAAO,CAACC,MAAMC,UAC5B3C,OAAAA,YAAYjB,SAASC,SAAS2D,KAAK,IAKtCD,OACAC,MAAMxC,SAASsC,OAAO,CAACC,OAAMH,UACvB/B,OAAAA,OAAOzB,SAASC,SAASuD,KAAK,IACzBG,QAAOH,MAAMG,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE;;;;;;;;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var util_getTextBlockText = require("./util.get-text-block-text.cjs"), selector_getSelectionText = require("./selector.get-selection-text.cjs");
|
|
3
3
|
const getBlockTextBefore = (snapshot) => {
|
|
4
4
|
if (!snapshot.context.selection)
|
|
5
5
|
return "";
|
|
6
|
-
const startPoint =
|
|
6
|
+
const startPoint = util_getTextBlockText.getSelectionStartPoint(snapshot.context.selection), block = selector_getSelectionText.getFocusBlock({
|
|
7
7
|
...snapshot,
|
|
8
8
|
context: {
|
|
9
9
|
...snapshot.context,
|
|
@@ -15,11 +15,11 @@ const getBlockTextBefore = (snapshot) => {
|
|
|
15
15
|
});
|
|
16
16
|
if (!block)
|
|
17
17
|
return "";
|
|
18
|
-
const startOfBlock =
|
|
18
|
+
const startOfBlock = util_getTextBlockText.getBlockStartPoint({
|
|
19
19
|
context: snapshot.context,
|
|
20
20
|
block
|
|
21
21
|
});
|
|
22
|
-
return
|
|
22
|
+
return selector_getSelectionText.getSelectionText({
|
|
23
23
|
...snapshot,
|
|
24
24
|
context: {
|
|
25
25
|
...snapshot.context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {
|
|
1
|
+
{"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAAA,aAAa;AACtE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAMC,aAAaC,sBAAAA,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,wCAAc;AAAA,IAC1B,GAAGN;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACH,WAAO;AAGT,QAAMI,eAAeC,sBAAAA,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,2CAAiB;AAAA,IACtB,GAAGX;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}
|